4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file gfx_layout.h Functions related to laying out the texts. */
17 #include "core/pointer.h"
18 #include "fontcache.h"
21 /** Common information about a font. */
23 FontCache
*fc
; ///< The font we are using.
24 TextColour colour
; ///< The colour this font has to be.
26 FontBase (FontSize size
, TextColour colour
);
29 /** Namespace for paragraph layout-related types. */
30 namespace ParagraphLayouter
{
31 /** Visual run contains data about the bit of text with the same font. */
34 virtual ~VisualRun() {}
35 virtual const FontBase
*GetFont() const = 0;
36 virtual int GetGlyphCount() const = 0;
37 virtual const GlyphID
*GetGlyphs() const = 0;
38 virtual const float *GetPositions() const = 0;
39 virtual int GetLeading() const = 0;
40 virtual const int *GetGlyphToCharMap() const = 0;
43 /** A single line worth of VisualRuns. */
47 virtual int GetLeading() const = 0;
48 virtual int GetWidth() const = 0;
49 virtual int CountRuns() const = 0;
50 virtual const VisualRun
*GetVisualRun(int run
) const = 0;
51 virtual int GetInternalCharLength(WChar c
) const = 0;
52 int GetCharPosition (const char *str
, const char *ch
) const;
53 const char *GetCharAtPosition (const char *str
, int x
) const;
58 * The layouter performs all the layout work.
60 * It also accounts for the memory allocations and frees.
62 class Layouter
: public std::vector
<ttd_unique_ptr
<const ParagraphLayouter::Line
> > {
64 Layouter(const char *str
, int maxw
= INT32_MAX
, TextColour colour
= TC_FROMSTRING
, FontSize fontsize
= FS_NORMAL
);
65 Dimension
GetBounds();
67 static void ResetFontCache(FontSize size
);
68 static void ReduceLineCache();
71 #endif /* GFX_LAYOUT_H */