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  int _maxWidth = 0;
115  int _textMaxWidth = 0;
116  int _textMaxHeight = 0;
117  TextAlign _textAlignment = kTextAlignLeft;
118  int _interLinear = 0;
119  int _textShadow = 0;
120  MacWindowManager *_wm = nullptr;
121  uint32 _tfgcolor = 0;
122  uint32 _tbgcolor = 0;
123  bool _macFontMode = true;
124  MacText *_macText;
125  MacFontRun _defaultFormatting;
126  ImageArchive _imageArchive;
127 
128 public:
129  ~MacTextCanvas();
130 
131  void recalcDims();
132  void reallocSurface();
133  void render(int from, int to);
134  void render(int from, int to, int shadow);
135  int getAlignOffset(int row);
136 
147  int getLineWidth(int line, bool enforce = false, int col = -1);
148  int getLineHeight(int line);
149  int getLineCharWidth(int line, bool enforce = false);
150 
151  void splitString(const Common::U32String &str, int curLine, MacFontRun &defaultFormatting);
152  const Common::U32String::value_type *splitString(const Common::U32String::value_type *s, int curLine, MacFontRun &defaultFormatting);
153 
154  void chopChunk(const Common::U32String &str, int *curLinePtr, int indent, int maxWidth);
155  Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
156 
162  void reshuffleParagraph(int *row, int *col, MacFontRun &defaultFormatting);
163  void setMaxWidth(int maxWidth, MacFontRun &defaultFormatting);
164 
165  void debugPrint(const char *prefix = nullptr);
166 
167 private:
168  void processTable(int line, int maxWidth);
169  void parsePicExt(const Common::U32String &ext, uint16 &w, uint16 &h, int defpercent);
170 };
171 
174  int heght = -1;
175 };
176 
177 struct MacTextLine {
178  int width = -1;
179  int height = -1;
180  int minWidth = -1;
181  int y = 0;
182  int charwidth = -1;
183  bool paragraphEnd = false;
184  bool wordContinuation = false;
185  int indent = 0; // in units
186  int firstLineIndent = 0; // in pixels
187  Common::Path picfname;
188  Common::U32String picalt, pictitle, picext;
189  uint16 picpercent = 50;
190  Common::Array<MacTextTableRow> *table = nullptr;
191  ManagedSurface *tableSurface = nullptr;
192 
194 
195  MacFontRun &firstChunk() { return chunks[0]; }
196  MacFontRun &lastChunk() { return chunks[chunks.size() - 1]; }
197 
206  uint getChunkNum(int *col);
207 };
208 
209 } // End of namespace Graphics
210 
211 #endif
Definition: managed_surface.h:51
Definition: mactext-canvas.h:177
Definition: str.h:59
Definition: font.h:82
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:172
Definition: mactext-canvas.h:32
Definition: macwindowmanager.h:148
Definition: mactext-canvas.h:110
Definition: ustr.h:57
Definition: formatinfo.h:28
size_type size() const
Definition: array.h:315
Definition: image-archive.h:38