ScummVM API documentation
font_manager.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 CRYOMNI3D_FONT_MANAGER_H
23 #define CRYOMNI3D_FONT_MANAGER_H
24 
25 #include "common/array.h"
26 #include "common/path.h"
27 #include "common/str.h"
28 #include "common/str-enc.h"
29 #include "common/ustr.h"
30 #include "common/rect.h"
31 
32 #include "graphics/font.h"
33 
34 namespace Graphics {
35 class ManagedSurface;
36 }
37 
38 namespace CryOmni3D {
39 
40 class FontManager {
41 public:
42  FontManager();
43  virtual ~FontManager();
44 
45  void loadFonts(const Common::Array<Common::Path> &fontFiles, Common::CodePage codepage);
46  void loadTTFList(const Common::Path &listFile, Common::CodePage codepage);
47  void setCurrentFont(int currentFont);
48  uint getCurrentFont() { return _currentFontId; }
49  void setTransparentBackground(bool transparent) { _transparentBackground = transparent; }
50  void setSpaceWidth(uint additionalSpace);
51  void setForeColor(byte color) { _foreColor = color; }
52  void setLineHeight(int h) { _lineHeight = h; }
53  int lineHeight() { return _lineHeight; }
54  void setCharSpacing(uint w) { _charSpacing = w; }
55  void setSurface(Graphics::ManagedSurface *surface) { _currentSurface = surface; }
56 
57  int getFontMaxHeight() { return _currentFont->getFontHeight(); }
58 
59  void displayInt(uint x, uint y, int value) const {
60  displayStr_(x, y,
61  toU32(Common::String::format("%d", value)));
62  }
63  void displayStr(uint x, uint y, const Common::String &text) const { displayStr_(x, y, toU32(text)); }
64  void displayStr(uint x, uint y, const Common::U32String &text) const { displayStr_(x, y, text); }
65  uint getStrWidth(const Common::String &text) const { return getStrWidth(toU32(text)); }
66  uint getStrWidth(const Common::U32String &text) const;
67 
68  uint getLinesCount(const Common::String &text, uint width) { return getLinesCount(toU32(text), width); }
69 
70  void setupBlock(const Common::Rect &block, bool justifyText = false) {
71  _blockRect = block;
72  _blockPos.x = block.left;
73  _blockPos.y = block.top;
74  _justifyText = justifyText;
75  }
76  bool displayBlockText(const Common::String &text) {
77  _blockTextStr = toU32(text);
78  return displayBlockText(_blockTextStr, _blockTextStr.begin());
79  }
80  bool displayBlockTextContinue() { return displayBlockText(_blockTextStr, _blockTextRemaining); }
81  Common::Point blockTextLastPos() { return _blockPos; }
82 
83 private:
84  Common::U32String toU32(const Common::String &text) const;
85 
86  uint displayStr_(uint x, uint y, const Common::U32String &text) const;
87  uint getLinesCount(const Common::U32String &text, uint width);
88  bool displayBlockText(const Common::U32String &text, Common::U32String::const_iterator begin);
89  void calculateWordWrap(const Common::U32String &text, Common::U32String::const_iterator *position,
90  uint *finalPos, bool *has_br, Common::Array<Common::U32String> &words) const;
91 
92  Common::CodePage _codepage;
93  bool _toUnicode;
95  const Graphics::Font *_currentFont;
96  uint _currentFontId;
97  bool _transparentBackground;
98  uint _spaceWidth;
99  uint _charSpacing;
100 
101  byte _foreColor;
102 
103  Graphics::ManagedSurface *_currentSurface;
104 
105  Common::Rect _blockRect;
106  Common::Point _blockPos;
107  int _lineHeight;
108  bool _justifyText;
109  Common::U32String _blockTextStr;
110  Common::U32String::const_iterator _blockTextRemaining;
111 
112  // Specific parameters for non alphabetic languages
113  void setupWrapParameters();
114  bool _useSpaceDelimiter;
115  bool _keepASCIIjoined;
116 };
117 
118 } // End of namespace CryOmni3D
119 
120 #endif
Definition: managed_surface.h:51
Definition: cryomni3d.h:62
Definition: str.h:59
Definition: font.h:83
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: rect.h:144
Definition: font_manager.h:40
Definition: path.h:52
Definition: ustr.h:57
Definition: formatinfo.h:28
Definition: rect.h:45
int16 left
Definition: rect.h:145