ScummVM API documentation
bdf.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_BDF_H
23 #define GRAPHICS_FONTS_BDF_H
24 
25 #include "common/system.h"
26 #include "common/types.h"
27 
28 #include "graphics/font.h"
29 
30 namespace Common {
31 class SeekableReadStream;
32 }
33 
34 namespace Graphics {
35 
37  uint8 width, height;
38  int8 xOffset, yOffset;
39 };
40 
41 struct BdfFontData {
42  const char *familyName;
43  const char *slant;
44 
45  int maxAdvance;
46  int height;
47  int size;
48  BdfBoundingBox defaultBox;
49  int ascent;
50 
51  int firstCharacter;
52  int defaultCharacter;
53  int numCharacters;
54 
55  const byte *const *bitmaps;
56  const byte *advances;
57  const BdfBoundingBox *boxes;
58 };
59 
60 class BdfFont : public Font {
61 public:
62  BdfFont(const BdfFontData &data, DisposeAfterUse::Flag dispose);
63  ~BdfFont();
64 
65  virtual int getFontHeight() const;
66  virtual int getFontAscent() const;
67  virtual int getMaxCharWidth() const;
68 
69  virtual int getCharWidth(uint32 chr) const;
70  virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
71 
72  const char *getFamilyName() const;
73  const char *getFontSlant() const;
74  int getFontSize() const;
75 
76  static BdfFont *loadFont(Common::SeekableReadStream &stream);
77  static bool cacheFontData(const BdfFont &font, const Common::Path &filename);
78  static BdfFont *loadFromCache(Common::SeekableReadStream &stream);
79  static BdfFont *scaleFont(const BdfFont *src, int newSize);
80 private:
81  int mapToIndex(uint32 ch) const;
82 
83  const BdfFontData _data;
84  const DisposeAfterUse::Flag _dispose;
85 };
86 
87 #define DEFINE_FONT(n) \
88  const BdfFont *n = 0; \
89  void create_##n() { \
90  n = new BdfFont(desc, DisposeAfterUse::NO); \
91  }
92 
93 #define FORWARD_DECLARE_FONT(n) \
94  extern const BdfFont *n; \
95  extern void create_##n()
96 
97 #define INIT_FONT(n) \
98  create_##n()
99 
100 } // End of namespace Graphics
101 
102 #endif
Definition: bdf.h:41
Definition: font.h:82
Definition: surface.h:66
Definition: path.h:52
Definition: stream.h:745
Definition: bdf.h:36
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: bdf.h:60