ScummVM API documentation
winfont.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_WINFONT_H
23 #define GRAPHICS_WINFONT_H
24 
25 #include "common/str.h"
26 #include "graphics/font.h"
27 
28 namespace Common {
29 class SeekableReadStream;
30 class WinResources;
31 }
32 
33 namespace Graphics {
34 
36  WinFontDirEntry() : points(0) {}
37  WinFontDirEntry(const Common::String &name, uint16 p) : faceName(name), points(p) {}
38 
39  // This is really just a simple identifier to match a directory entry with
40  // If need-be, we can add other things to check such as italics and strikethrough, etc.
41  Common::String faceName;
42  uint16 points;
43 };
44 
45 class WinFont : public Font {
46 public:
47  WinFont();
48  ~WinFont();
49 
55  bool loadFromFON(const Common::Path &fileName, const WinFontDirEntry &dirEntry = WinFontDirEntry());
56  bool loadFromFON(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry = WinFontDirEntry());
57 
59  bool loadFromFNT(const Common::Path &fileName);
60 
62  void close();
63 
64  // Font API
65  int getFontHeight() const { return _pixHeight; }
66  int getFontAscent() const { return _ascent; }
67  int getMaxCharWidth() const { return _maxWidth; }
68  Common::String getName() const { return _name; }
69  int getCharWidth(uint32 chr) const;
70  void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
71  int getStyle() const;
72 
73  static WinFont *scaleFont(const WinFont *src, int newSize);
74 private:
75  bool loadFromEXE(Common::WinResources *exe, const Common::Path &fileName, const WinFontDirEntry &dirEntry);
76 
77  uint32 getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry);
78  Common::String getFONFontName(Common::SeekableReadStream &stream);
79  bool loadFromFNT(Common::SeekableReadStream &stream);
80  char indexToCharacter(uint16 index) const;
81  uint16 characterToIndex(uint32 character) const;
82 
83  uint16 _pixHeight;
84  uint16 _maxWidth;
85  uint16 _ascent;
86  byte _firstChar;
87  byte _lastChar;
88  byte _defaultChar;
89  bool _italic;
90  bool _strikethrough;
91  bool _underline;
92  uint16 _weight;
93  Common::String _name;
94 
95  enum {
96  kFontStyleRegular,
97  kFontStyleBold = 1,
98  kFontStyleItalic = 2,
99  kFontStyleUnderline = 4,
100  };
101 
102  uint16 _glyphCount;
103  struct GlyphEntry {
104  GlyphEntry() { bitmap = 0; charWidth = 0; offset = 0; }
105  ~GlyphEntry() { delete[] bitmap; }
106 
107  uint16 charWidth;
108  uint32 offset;
109  byte *bitmap;
110  } *_glyphs;
111 };
112 
113 } // End of namespace Graphics
114 
115 #endif
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
Definition: winfont.h:45
int getFontHeight() const
Definition: winfont.h:65
Definition: path.h:52
Definition: stream.h:745
Definition: winfont.h:35
int getFontAscent() const
Definition: winfont.h:66
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: winexe.h:110
int getMaxCharWidth() const
Definition: winfont.h:67