ScummVM API documentation
base_font_truetype.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  * This file is based on WME Lite.
24  * http://dead-code.org/redir.php?target=wmelite
25  * Copyright (c) 2011 Jan Nedoma
26  */
27 
28 #ifndef WINTERMUTE_BASE_FONTTT_H
29 #define WINTERMUTE_BASE_FONTTT_H
30 
31 #include "engines/wintermute/base/font/base_font_storage.h"
32 #include "engines/wintermute/base/font/base_font.h"
33 #include "engines/wintermute/base/gfx/base_surface.h"
34 #include "common/rect.h"
35 #include "graphics/surface.h"
36 #include "graphics/font.h"
37 
38 #define NUM_CACHED_TEXTS 30
39 
40 namespace Wintermute {
41 
42 class BaseFontTT : public BaseFont {
43 private:
45  class BaseCachedTTFontText {
46  public:
47  WideString _text;
48  int32 _width;
49  TTextAlign _align;
50  int32 _maxHeight;
51  int32 _maxLength;
52  BaseSurface *_surface;
53  //int32 _priority;
54  int32 _textOffset;
55  bool _marked;
56  uint32 _lastUsed;
57 
58  BaseCachedTTFontText() : _text() {
59  //_text = L"";
60  _width = _maxHeight = _maxLength = -1;
61  _align = TAL_LEFT;
62  _surface = nullptr;
63  //_priority = -1;
64  _textOffset = 0;
65  _lastUsed = 0;
66  _marked = false;
67  }
68 
69  virtual ~BaseCachedTTFontText() {
70  if (_surface) {
71  delete _surface;
72  }
73  }
74  };
75 
76 public:
79  public:
80  BaseTTFontLayer() {
81  _offsetX = _offsetY = 0;
82  _color = 0x00000000;
83  }
84 
85  bool persist(BasePersistenceManager *persistMgr) {
86  persistMgr->transferSint32(TMEMBER(_offsetX));
87  persistMgr->transferSint32(TMEMBER(_offsetY));
88  persistMgr->transferUint32(TMEMBER(_color));
89  return STATUS_OK;
90  }
91 
92  int32 _offsetX;
93  int32 _offsetY;
94  uint32 _color;
95  };
96 
97 public:
98  DECLARE_PERSISTENT(BaseFontTT, BaseFont)
99  BaseFontTT(BaseGame *inGame);
100  ~BaseFontTT() override;
101 
102  int getTextWidth(const byte *text, int maxLength = -1) override;
103  int getTextHeight(const byte *text, int width) override;
104  void drawText(const byte *text, int x, int y, int width, TTextAlign align = TAL_LEFT, int max_height = -1, int maxLength = -1) override;
105  int getLetterHeight() override;
106 
107  bool loadBuffer(char *buffer);
108  bool loadFile(const Common::String &filename);
109 
110  void afterLoad() override;
111  void initLoop() override;
112 
113 private:
114  bool parseLayer(BaseTTFontLayer *layer, char *buffer);
115 
116  void measureText(const WideString &text, int maxWidth, int maxHeight, int &textWidth, int &textHeight);
117 
118  BaseSurface *renderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset);
119 
120  BaseCachedTTFontText *_cachedTexts[NUM_CACHED_TEXTS];
121 
122  bool initFont();
123 
124  Graphics::Font *_deletableFont;
125  const Graphics::Font *_font;
126  const Graphics::Font *_fallbackFont;
127 
128  float _lineHeight;
129 
130  size_t _maxCharWidth;
131  size_t _maxCharHeight;
132 
133 private:
134  bool _isBold;
135  bool _isItalic;
136  bool _isUnderline;
137  bool _isStriked;
138  int32 _fontHeight;
139  char *_fontFile;
140  TTextCharset _charset;
141 
143  void clearCache();
144 
145 };
146 
147 } // End of namespace Wintermute
148 
149 #endif
Definition: base_game.h:75
Definition: str.h:59
Definition: font.h:83
Definition: base_persistence_manager.h:55
Definition: base_font_truetype.h:42
Definition: ustr.h:57
Definition: base_surface.h:37
Definition: base_font_truetype.h:78
Definition: coll_templ.h:347
Definition: base_font.h:37
Definition: achievements_tables.h:27