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  _textOffset = 0;
64  _lastUsed = 0;
65  _marked = false;
66  }
67 
68  virtual ~BaseCachedTTFontText() {
69  if (_surface) {
70  delete _surface;
71  }
72  }
73  };
74 
75 public:
78  public:
79  BaseTTFontLayer() {
80  _offsetX = _offsetY = 0;
81  _color = 0x00000000;
82  }
83 
84  bool persist(BasePersistenceManager *persistMgr) {
85  persistMgr->transferSint32(TMEMBER(_offsetX));
86  persistMgr->transferSint32(TMEMBER(_offsetY));
87  persistMgr->transferUint32(TMEMBER(_color));
88  return STATUS_OK;
89  }
90 
91  int32 _offsetX;
92  int32 _offsetY;
93  uint32 _color;
94  };
95 
96 public:
97  DECLARE_PERSISTENT(BaseFontTT, BaseFont)
98  BaseFontTT(BaseGame *inGame);
99  ~BaseFontTT() override;
100 
101  int getTextWidth(const byte *text, int maxLength = -1) override;
102  int getTextHeight(const byte *text, int width) override;
103  void drawText(const byte *text, int x, int y, int width, TTextAlign align = TAL_LEFT, int max_height = -1, int maxLength = -1) override;
104  int getLetterHeight() override;
105 
106  bool loadBuffer(char *buffer);
107  bool loadFile(const Common::String &filename);
108 
109  float getLineHeight() const {
110  return _lineHeight;
111  }
112 
113  void afterLoad() override;
114  void initLoop() override;
115 
116 private:
117  bool parseLayer(BaseTTFontLayer *layer, char *buffer);
118 
119  void measureText(const WideString &text, int maxWidth, int maxHeight, int &textWidth, int &textHeight);
120 
121  BaseSurface *renderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset);
122 
123  BaseCachedTTFontText *_cachedTexts[NUM_CACHED_TEXTS];
124 
125  bool initFont();
126 
127  Graphics::Font *_deletableFont;
128  const Graphics::Font *_font;
129  const Graphics::Font *_fallbackFont;
130 
131  float _lineHeight;
132 
133  size_t _maxCharWidth;
134  size_t _maxCharHeight;
135 
136 private:
137  bool _isBold;
138  bool _isItalic;
139  bool _isUnderline;
140  bool _isStriked;
141  int32 _fontHeight;
142  char *_fontFile;
143  TTextCharset _charset;
144 
146  void clearCache();
147 
148 };
149 
150 } // End of namespace Wintermute
151 
152 #endif
Definition: base_game.h:76
Definition: str.h:59
Definition: font.h:83
Definition: base_persistence_manager.h:56
Definition: base_font_truetype.h:42
Definition: ustr.h:57
Definition: base_surface.h:38
Definition: base_font_truetype.h:77
Definition: coll_templ.h:63
Definition: base_font.h:37
Definition: achievements_tables.h:27