ScummVM API documentation
font_data.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 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_FONTDATA_H
29 #define HPL_FONTDATA_H
30 
31 #include "common/array.h"
32 #include "common/ptr.h"
33 #include "hpl1/engine/graphics/GraphicsTypes.h"
34 #include "hpl1/engine/math/MathTypes.h"
35 #include "hpl1/engine/resources/ResourceBase.h"
36 #include "hpl1/engine/resources/low_level_resources.h"
37 #include "hpl1/engine/system/SystemTypes.h"
38 
39 class TiXmlElement;
40 
41 namespace hpl {
42 
43 class ImageManager;
44 class iLowLevelGraphics;
45 class cGraphicsDrawer;
46 class cGfxObject;
47 class Bitmap2D;
48 class cGuiGfxElement;
49 class cGui;
50 
51 class Glyph {
52 public:
53  Glyph(cGfxObject *apObject, cGuiGfxElement *apGuiGfx, const cVector2f &avOffset,
54  const cVector2f &avSize, float afAdvance);
55  ~Glyph();
56 
57  cGfxObject *_gfxObject;
58  cGuiGfxElement *_guiGfx;
59  cVector2f _offset;
60  cVector2f _size;
61  float _advance;
62 };
63 
65 typedef tGlyphVec::iterator tGlyphVecIt;
66 
67 class FontData : public iResourceBase {
68 public:
69  FontData(const tString &asName, iLowLevelGraphics *apLowLevelGraphics);
70  ~FontData();
71 
72  bool createFromFontFile(const tString &asFileName, int alSize, unsigned short alFirstChar,
73  unsigned short alLastChar);
74 
75  bool createFromBitmapFile(const tString &asFileName);
76 
77  bool reload() { return false; }
78  void unload() {}
79  void destroy() {}
80 
84  void setUp(cGraphicsDrawer *apGraphicsDrawer, LowLevelResources *apLowLevelResources,
85  cGui *apGui) {
86  _graphicsDrawer = apGraphicsDrawer;
87  _lowLevelResources = apLowLevelResources;
88  _gui = apGui;
89  }
90 
96  inline Glyph *getGlyph(int alNum) const { return _glyphs[alNum]; }
97 
98  inline unsigned short getFirstChar() { return _firstChar; }
99  inline unsigned short getLastChar() { return _lastChar; }
100 
101  inline const cVector2f &getSizeRatio() const { return _sizeRatio; }
102 
112  void draw(const cVector3f &avPos, const cVector2f &avSize, const cColor &aCol, eFontAlign mAlign,
113  const tWString &text);
125  int drawWordWrap(cVector3f avPos, float afLength, float afFontHeight, cVector2f avSize, const cColor &aCol,
126  eFontAlign aAlign, const tWString &asString);
127 
128  void getWordWrapRows(float afLength, float afFontHeight, cVector2f avSize, const tWString &asString,
129  tWStringVec *apRowVec);
130 
135  inline float getHeight() const { return _height; }
136 
143  float getLength(const cVector2f &avSize, const char32_t *sText);
144 
145 private:
146  iLowLevelGraphics *_lowLevelGraphics;
147  LowLevelResources *_lowLevelResources;
148  cGraphicsDrawer *_graphicsDrawer;
149  cGui *_gui;
150 
151  tGlyphVec _glyphs;
152 
153  float _height;
154  unsigned short _firstChar;
155  unsigned short _lastChar;
156 
157  cVector2f _sizeRatio;
158 
159  Glyph *createGlyph(Bitmap2D *apBmp, const cVector2l &avOffset, const cVector2l &avSize,
160  const cVector2l &avFontSize, int alAdvance);
161  void addGlyph(Glyph *apGlyph);
162  void loadGlyphs(const TiXmlElement *charsRoot, Common::Array<Common::SharedPtr<Bitmap2D> > &bitmaps, const cVector2l &fontSize);
163  void loadNextGlyph(const TiXmlElement *charIt, Common::Array<Common::SharedPtr<Bitmap2D> > &bitmaps, const cVector2l &fontSize);
164 };
165 
166 } // namespace hpl
167 
168 #endif // HPL_FONTDATA_H
Definition: AI.h:36
Definition: Gui.h:73
Definition: GuiGfxElement.h:72
Definition: str.h:59
void unload()
Definition: font_data.h:78
Definition: ResourceBase.h:36
void destroy()
Definition: font_data.h:79
Definition: bitmap2D.h:42
Definition: font_data.h:67
T * iterator
Definition: array.h:54
void setUp(cGraphicsDrawer *apGraphicsDrawer, LowLevelResources *apLowLevelResources, cGui *apGui)
Definition: font_data.h:84
bool reload()
Definition: font_data.h:77
Definition: GraphicsDrawer.h:77
Definition: low_level_resources.h:40
Definition: ustr.h:57
Definition: GfxObject.h:38
Definition: font_data.h:51
Definition: Color.h:37
Definition: tinyxml.h:864
Definition: ptr.h:159
Definition: LowLevelGraphics.h:200
Glyph * getGlyph(int alNum) const
Definition: font_data.h:96
float getHeight() const
Definition: font_data.h:135