ScummVM API documentation
macfont.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GRAPHICS_FONTS_MACFONT_H
23 #define GRAPHICS_FONTS_MACFONT_H
24 
25 #include "common/array.h"
26 #include "common/hashmap.h"
27 #include "common/stream.h"
28 #include "graphics/font.h"
29 
30 namespace Graphics {
31 
32 #define SLANTDEEP 2
33 
35 public:
36  MacFontFamily(const Common::String &name);
37  ~MacFontFamily();
38 
39  bool load(Common::SeekableReadStream &stream);
40  int getKerningOffset(uint style, int32 left, uint32 right) const;
41  int getGlyphWidth(uint style, uint c);
42 
43  struct AsscEntry {
44  uint16 _fontSize;
45  uint16 _fontStyle;
46  uint16 _fontID;
47  };
48 
49  const Common::String &getName() { return _name; }
50  uint16 getFontFamilyId() { return _ffFamID; }
51  Common::Array<AsscEntry> *getAssocTable() { return &_ffAssocEntries; }
52 
53 private:
54  Common::String _name;
55 
56  // FOND
57  uint16 _ffFlags;
58  uint16 _ffFamID;
59  uint16 _ffFirstChar;
60  uint16 _ffLastChar;
61  int16 _ffAscent;
62  int16 _ffDescent;
63  int16 _ffLeading;
64  int16 _ffWidMax;
65  uint32 _ffWTabOff;
66  uint32 _ffKernOff;
67  uint32 _ffStylOff;
68  uint16 _ffProperty[9];
69  uint16 _ffIntl[2];
70  uint16 _ffVersion;
71 
72  uint16 _ffNumAssoc;
73  Common::Array<AsscEntry> _ffAssocEntries;
74 
75  uint16 _ffNumOffsets;
76  uint32 *_ffOffsets;
77 
78  struct BBoxEntry {
79  uint16 _style;
80  int16 _left;
81  int16 _bottom;
82  int16 _right;
83  int16 _top;
84  };
85 
86  uint16 _ffNumBBoxes;
87  Common::Array<BBoxEntry> _ffBBoxes;
88 
89  struct KernPair {
90  byte _firstChar;
91  byte _secondChar;
92  uint16 _distance;
93  };
94 
95  struct KernEntry {
96  uint16 _style;
97  uint16 _entryLength;
98  Common::Array<KernPair> _kernPairs;
99 
101  };
102 
103  uint16 _ffNumKerns;
104  Common::Array<KernEntry> _ffKernEntries;
105 
106  struct StyleWidthEntry {
107  uint16 _style;
108  Common::Array<uint16> _widths;
109  };
110 
111  uint16 _ffNumStyleWidths;
112  Common::Array<StyleWidthEntry> _ffStyleWidths;
113 };
114 
115 struct MacGlyph {
116  void clear() {
117  bitmapOffset = 0;
118  width1 = 0;
119  height = 0;
120  bitmapWidth = 0;
121  kerningOffset = 0;
122  width = 0;
123  }
124 
125  uint16 bitmapOffset;
126  uint16 height;
127  uint16 bitmapWidth;
128  uint16 width1; // this width is from glyph-table, which has the higher priority
129  byte width; // this width is from width/offset table
130  int kerningOffset;
131 };
132 
133 struct MacFONTdata {
134  uint16 _fontType;
135  uint16 _firstChar;
136  uint16 _lastChar;
137  uint16 _maxWidth;
138  int16 _kernMax;
139  int16 _nDescent;
140  uint16 _fRectWidth;
141  uint16 _fRectHeight;
142  uint32 _owTLoc;
143  uint16 _ascent;
144  uint16 _descent;
145  uint16 _leading;
146  uint16 _rowWords;
147  uint16 _surfHeight;
148 
149  byte *_bitImage;
150 
151  Common::Array<MacGlyph> _glyphs;
152  MacGlyph _defaultChar;
153 
154  MacFontFamily *_family;
155  int _size;
156  int _style;
157 
158  // currently only available in generated fonts
159  int _slant;
160 };
161 
165 class MacFONTFont : public Font {
166 public:
167  MacFONTFont();
168  MacFONTFont(const MacFONTdata &data);
169  virtual ~MacFONTFont();
170 
171  virtual int getFontHeight() const { return _data._fRectHeight + getFontLeading(); }
172  virtual int getFontAscent() const { return _data._ascent; }
173  virtual int getFontDescent() const { return _data._descent; }
174  virtual int getFontLeading() const { return _data._leading; }
175  virtual int getMaxCharWidth() const { return _data._maxWidth; }
176  virtual int getCharWidth(uint32 chr) const;
177  virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
178 
179  bool loadFont(Common::SeekableReadStream &stream, MacFontFamily *family = nullptr, int size = 12, int style = 0);
180 
181  virtual int getKerningOffset(uint32 left, uint32 right) const;
182 
183  int getFontSize() const { return _data._size; }
184 
185  static MacFONTFont *scaleFont(const MacFONTFont *src, int newSize, int slant);
186  static void testBlit(const MacFONTFont *src, ManagedSurface *dst, int color, int x0, int y0, int width);
187 
188 private:
189  MacFONTdata _data;
190 
191  const MacGlyph *findGlyph(uint32 c) const;
192 };
193 
194 } // End of namespace Graphics
195 
196 #endif
Definition: managed_surface.h:51
Definition: macfont.h:43
virtual int getFontAscent() const
Definition: macfont.h:172
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
virtual int getFontLeading() const
Definition: macfont.h:174
Definition: array.h:52
Definition: macfont.h:115
Definition: macfont.h:165
virtual int getMaxCharWidth() const
Definition: macfont.h:175
Definition: stream.h:745
Definition: formatinfo.h:28
virtual int getFontDescent() const
Definition: macfont.h:173
virtual int getFontHeight() const
Definition: macfont.h:171
Definition: macfont.h:34
Definition: macfont.h:133