Go to the documentation of this file.
20 #include <string_view>
21 #include <type_traits>
25 #include "layout/ParagraphLayout.h"
26 #define ICU_FONTINSTANCE : public icu::LEFontInstance
28 #define ICU_FONTINSTANCE
52 if ((this->cur_colour &
TC_FORCED) == 0) this->cur_colour = c;
96 le_int32 getUnitsPerEM()
const;
97 le_int32 getAscent()
const;
98 le_int32 getDescent()
const;
99 le_int32 getLeading()
const;
100 float getXPixelsPerEm()
const;
101 float getYPixelsPerEm()
const;
102 float getScaleFactorX()
const;
103 float getScaleFactorY()
const;
104 const void *getFontTable(LETag tableTag)
const;
105 const void *getFontTable(LETag tableTag,
size_t &length)
const;
106 LEGlyphID mapCharToGlyph(LEUnicode32 ch)
const;
107 void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance)
const;
108 le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point)
const;
126 virtual const Font *GetFont()
const = 0;
127 virtual int GetGlyphCount()
const = 0;
128 virtual const GlyphID *GetGlyphs()
const = 0;
129 virtual const float *GetPositions()
const = 0;
130 virtual int GetLeading()
const = 0;
131 virtual const int *GetGlyphToCharMap()
const = 0;
138 virtual int GetLeading()
const = 0;
139 virtual int GetWidth()
const = 0;
140 virtual int CountRuns()
const = 0;
141 virtual const VisualRun &GetVisualRun(
int run)
const = 0;
142 virtual int GetInternalCharLength(
WChar c)
const = 0;
145 virtual void Reflow() = 0;
146 virtual std::unique_ptr<const Line> NextLine(
int max_width) = 0;
154 class Layouter :
public std::vector<std::unique_ptr<const ParagraphLayouter::Line>> {
173 template<
typename Key1,
typename Key2>
176 if (lhs.state_before.fontsize != rhs.state_before.fontsize)
return lhs.state_before.fontsize < rhs.state_before.fontsize;
177 if (lhs.state_before.cur_colour != rhs.state_before.cur_colour)
return lhs.state_before.cur_colour < rhs.state_before.cur_colour;
178 if (lhs.state_before.colour_stack != rhs.state_before.colour_stack)
return lhs.state_before.colour_stack < rhs.state_before.colour_stack;
179 return lhs.str < rhs.str;
196 typedef std::map<LineCacheKey, LineCacheItem, LineCacheCompare> LineCache;
@ TC_FORCED
Ignore colour changes from strings.
uint32 GlyphID
Glyphs are characters from a font.
char32_t WChar
Type for wide characters, i.e.
Dimensions (a width and height) of a rectangle in 2D.
std::string_view str
Source string of the line (including colour and font size codes).
void PopColour()
Switch to and pop the last saved colour on the stack.
const char * string
Pointer to the original string.
static LineCache * linecache
Cache of ParagraphLayout lines.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Point GetCharPosition(const char *ch) const
Get the position of a character in the layout.
static void ResetFontCache(FontSize size)
Reset cached font information.
FontCache * fc
The font we are using.
Interface to glue fallback and normal layouter into one.
ParagraphLayouter * layout
Layout of the line.
void is_transparent
Enable map queries with various key types.
SmallMap< int, Font * > FontMap
Mapping from index to font.
A single line worth of VisualRuns.
std::string str
Source string of the line (including colour and font size codes).
Container with information about a font.
static FontColourMap fonts[FS_END]
Cache of Font instances.
FontState state_before
Font state at the beginning of the line.
@ FS_NORMAL
Index of the normal font in the font tables.
FontMap runs
Accessed by our ParagraphLayout::nextLine.
FontSize fontsize
Current font size.
bool operator()(const Key1 &lhs, const Key2 &rhs) const
Comparison operator for LineCacheKey and LineCacheQuery.
Dimension GetBounds()
Get the boundaries of this paragraph.
Layouter(const char *str, int maxw=INT32_MAX, TextColour colour=TC_FROMSTRING, FontSize fontsize=FS_NORMAL)
Create a new layouter.
The layouter performs all the layout work.
FontState state_before
Font state at the beginning of the line.
static Font * GetFont(FontSize size, TextColour colour)
Get a static font instance.
Coordinates of a point in 2D.
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Visual run contains data about the bit of text with the same font.
std::stack< TextColour, std::vector< TextColour > > colour_stack
Stack of colours to assist with colour switching.
TextColour cur_colour
Current text colour.
Font cache for basic fonts.
const char * GetCharAtPosition(int x) const
Get the character that is at a position.
void SetColour(TextColour c)
Switch to new colour c.
@ TC_FLAGS_MASK
Mask to test if TextColour (with flags) is within limits.
FontState state_after
Font state after the line.
static LineCacheItem & GetCachedParagraphLayout(const char *str, size_t len, const FontState &state)
Get reference to cache item.
void SetFontSize(FontSize f)
Switch to using a new font f.
Text drawing parameters, which can change while drawing a line, but are kept between multiple parts o...
static void ResetLineCache()
Clear line cache.
FontSize
Available font sizes.
@ TC_COLOUR_MASK
Mask to test if TextColour (without flags) is within limits.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void PushColour()
Push the current colour on to the stack.
TextColour colour
The colour this font has to be.
void * buffer
Accessed by both ICU's and our ParagraphLayout::nextLine.