1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DGDS_FONT_H
#define DGDS_FONT_H
#include "common/scummsys.h"
#include "common/hashmap.h"
#include "common/func.h"
#include "graphics/font.h"
#include "dgds/dgds.h"
namespace Graphics {
class Font;
struct Surface;
}
namespace Common {
class SeekableReadStream;
}
namespace Dgds {
class ResourceManager;
class Decompressor;
class DgdsFont : public Graphics::Font {
public:
DgdsFont(byte w, byte h, byte start, byte count, const byte *glyphs);
virtual ~DgdsFont();
virtual int getFontHeight() const override { return _h; }
virtual int getMaxCharWidth() const override { return _w; }
virtual int getCharWidth(uint32 chr) const override = 0;
static DgdsFont *load(const Common::String &filename, ResourceManager *resourceManager, Decompressor *decompressor);
protected:
byte _w;
byte _h;
byte _start;
byte _count;
const byte *_glyphs;
void drawDgdsChar(Graphics::Surface* dst, int pos, int x, int y, int w, uint32 color) const;
bool hasChar(byte chr) const;
virtual int charOffset(byte chr) const = 0;
};
/* Proportional font (each char has its own width and so data is a different size) */
class PFont : public DgdsFont {
public:
PFont(byte w, byte h, byte start, byte count, byte *data);
~PFont();
int getCharWidth(uint32 chr) const override;
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
static PFont *load(Common::SeekableReadStream &input, Decompressor *decompressor);
protected:
const uint16 *_offsets;
const byte *_widths;
byte *_rawData;
int charOffset(byte chr) const override;
};
/* Fixed-width font */
class FFont : public DgdsFont {
public:
FFont(byte w, byte h, byte start, byte count, byte *data);
~FFont();
int getCharWidth(uint32 chr) const override { return _w; }
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
static FFont *load(Common::SeekableReadStream &input);
protected:
byte *_rawData;
int charOffset(byte chr) const override;
};
class FontManager {
public:
enum FontType {
kDefaultFont = 0,
k8x8Font,
k6x6Font,
k4x5Font,
kGameFont, // DRAGON for Rise of the Dragon, WILLY for Willy Beamish, HOC for Heart of China.
kGameDlgFont, // P6x6 for Rise of the Dragon, COMIX_16 for Willy Beamish, CHINESE for Heart of China
k7x8Font, // Rise of the Dragon only
kVCRFont, // Willy Beamish only
kChinaFont, // Heart of China only
};
FontManager() {}
~FontManager();
const DgdsFont *getFont(FontType) const;
FontType fontTypeByName(const Common::String &filename) const;
void loadFonts(DgdsGameId gameId, ResourceManager *resourceManager, Decompressor *decompressor);
private:
void tryLoadFont(const char *filename, ResourceManager *resourceManager, Decompressor *decompressor);
struct FontTypeHash {
Common::Hash<const char *> hash;
uint operator()(FontType val) const {
return (uint)val;
}
};
Common::HashMap<FontType, DgdsFont*, FontTypeHash> _fonts;
};
} // End of namespace Dgds
#endif // DGDS_FONT_H
|