ScummVM API documentation
mactext-canvas.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_MACGUI_MACTEXTCANVAS_H
23 #define GRAPHICS_MACGUI_MACTEXTCANVAS_H
24 
25 #include "graphics/macgui/macwindowmanager.h"
26 #include "graphics/image-archive.h"
27 
28 namespace Graphics {
29 
30 class MacText;
31 
32 struct MacFontRun {
33  Common::U32String text;
34 
35  uint16 fontId;
36  byte textSlant;
37  uint16 fontSize;
38  uint16 palinfo1;
39  uint16 palinfo2;
40  uint16 palinfo3;
41  uint32 fgcolor;
42  const Font *font;
43  MacWindowManager *wm;
44  Common::String link; // Substitute to return when hover or click
45 
46  MacFontRun() {
47  wm = nullptr;
48  fontId = textSlant = fontSize = 0;
49  palinfo1 = palinfo2 = palinfo3 = 0;
50  fgcolor = 0;
51  font = nullptr;
52  }
53 
55  wm = wm_;
56  fontId = textSlant = fontSize = 0;
57  palinfo1 = palinfo2 = palinfo3 = 0;
58  fgcolor = 0;
59  font = nullptr;
60  }
61 
62  MacFontRun(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
63  uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
64  setValues(wm_, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
65  }
66 
67  MacFontRun(MacWindowManager *wm_, const Font *font_, byte textSlant_, uint16 fontSize_,
68  uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
69  setValues(wm_, 0, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
70  font = font_;
71  }
72 
73  void setValues(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
74  uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
75  wm = wm_;
76  fontId = fontId_;
77  textSlant = textSlant_;
78  fontSize = fontSize_;
79  palinfo1 = palinfo1_;
80  palinfo2 = palinfo2_;
81  palinfo3 = palinfo3_;
82  fgcolor = wm_->findBestColor(palinfo1_ & 0xff, palinfo2_ & 0xff, palinfo3_ & 0xff);
83  font = nullptr;
84  }
85 
86  const Font *getFont();
87 
88  const Common::String toString();
89  bool equals(MacFontRun &to);
90 
91  Common::CodePage getEncoding();
92  bool plainByteMode();
93  Common::String getEncodedText();
94 
95  bool equals(const MacFontRun *y) {
96  return (fontId == y->fontId &&
97  textSlant == y->textSlant &&
98  fontSize == y->fontSize &&
99  palinfo1 == y->palinfo1 &&
100  palinfo2 == y->palinfo2 &&
101  palinfo3 == y->palinfo3 &&
102  fgcolor == y->fgcolor);
103  }
104 
105  void debugPrint();
106 };
107 
108 struct MacTextLine;
109 
111 public:
113  ManagedSurface *_surface = nullptr, *_shadowSurface = nullptr;
114  ManagedSurface *_glyphMask = nullptr, *_charBoxMask = nullptr;
115  int _maxWidth = 0;
116  int _textMaxWidth = 0;
117  int _textMaxHeight = 0;
118  TextAlign _textAlignment = kTextAlignLeft;
119  int _interLinear = 0;
120  int _textShadow = 0;
121  MacWindowManager *_wm = nullptr;
122  uint32 _tfgcolor = 0;
123  uint32 _tbgcolor = 0;
124  bool _macFontMode = true;
125  MacText *_macText;
126  MacFontRun _defaultFormatting;
127  ImageArchive _imageArchive;
128 
129 public:
130  ~MacTextCanvas();
131 
132  void recalcDims();
133  void reallocSurface();
134  void render(int from, int to);
135  void render(int from, int to, ManagedSurface *targeet, uint32 fillColor = 0, bool bboxesOnly = false);
136  int getAlignOffset(int row);
137 
148  int getLineWidth(int line, bool enforce = false, int col = -1);
149  int getLineHeight(int line);
150  int getLineCharWidth(int line, bool enforce = false);
151 
152  void splitString(const Common::U32String &str, int curLine, MacFontRun &defaultFormatting);
153  const Common::U32String::value_type *splitString(const Common::U32String::value_type *s, int curLine, MacFontRun &defaultFormatting);
154 
155  void chopChunk(const Common::U32String &str, int *curLinePtr, int indent, int maxWidth);
156  Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
157 
163  void reshuffleParagraph(int *row, int *col, MacFontRun &defaultFormatting);
164  void setMaxWidth(int maxWidth, MacFontRun &defaultFormatting);
165 
166  void debugPrint(const char *prefix = nullptr);
167 
168 private:
169  void processTable(int line, int maxWidth);
170  void parsePicExt(const Common::U32String &ext, uint16 &w, uint16 &h, int defpercent);
171 };
172 
175  int heght = -1;
176 };
177 
178 struct MacTextLine {
179  int width = -1;
180  int height = -1;
181  int minWidth = -1;
182  int y = 0;
183  int charwidth = -1;
184  bool paragraphEnd = false;
185  bool wordContinuation = false;
186  int indent = 0; // in units
187  int firstLineIndent = 0; // in pixels
188  Common::Path picfname;
189  Common::U32String picalt, pictitle, picext;
190  uint16 picpercent = 50;
191  Common::Array<MacTextTableRow> *table = nullptr;
192  ManagedSurface *tableSurface = nullptr;
193 
195 
196  MacFontRun &firstChunk() { return chunks[0]; }
197  MacFontRun &lastChunk() { return chunks[chunks.size() - 1]; }
198 
207  uint getChunkNum(int *col);
208 };
209 
210 } // End of namespace Graphics
211 
212 #endif
Definition: managed_surface.h:51
Definition: mactext-canvas.h:178
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: array.h:52
Definition: mactext.h:47
Align the text to the left.
Definition: font.h:51
Definition: path.h:52
Definition: mactext-canvas.h:173
Definition: mactext-canvas.h:32
Definition: macwindowmanager.h:147
Definition: mactext-canvas.h:110
Definition: ustr.h:57
Definition: formatinfo.h:28
size_type size() const
Definition: array.h:316
Definition: image-archive.h:38