|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
18 #include <string_view>
41 if ((this->cur_colour &
TC_FORCED) == 0) this->cur_colour = c;
97 virtual const Font *GetFont()
const = 0;
98 virtual int GetGlyphCount()
const = 0;
99 virtual const std::vector<GlyphID> &GetGlyphs()
const = 0;
100 virtual const std::vector<Point> &GetPositions()
const = 0;
101 virtual int GetLeading()
const = 0;
102 virtual const std::vector<int> &GetGlyphToCharMap()
const = 0;
108 virtual ~
Line() =
default;
109 virtual int GetLeading()
const = 0;
110 virtual int GetWidth()
const = 0;
111 virtual int CountRuns()
const = 0;
112 virtual const VisualRun &GetVisualRun(
int run)
const = 0;
113 virtual int GetInternalCharLength(char32_t c)
const = 0;
116 virtual void Reflow() = 0;
117 virtual std::unique_ptr<const Line> NextLine(
int max_width) = 0;
125 class Layouter :
public std::vector<std::unique_ptr<const ParagraphLayouter::Line>> {
144 template<
typename Key1,
typename Key2>
147 if (lhs.state_before.fontsize != rhs.state_before.fontsize)
return lhs.state_before.fontsize < rhs.state_before.fontsize;
148 if (lhs.state_before.cur_colour != rhs.state_before.cur_colour)
return lhs.state_before.cur_colour < rhs.state_before.cur_colour;
149 if (lhs.state_before.colour_stack != rhs.state_before.colour_stack)
return lhs.state_before.colour_stack < rhs.state_before.colour_stack;
150 return lhs.str < rhs.str;
167 typedef std::map<LineCacheKey, LineCacheItem, LineCacheCompare> LineCache;
172 using FontColourMap = std::map<TextColour, std::unique_ptr<Font>>;
@ TC_FORCED
Ignore colour changes from strings.
std::string_view string
Pointer to the original string.
Dimensions (a width and height) of a rectangle in 2D.
FontCache * fc
The font we are using.
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.
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...
static void ResetFontCache(FontSize size)
Reset cached font information.
static LineCacheItem & GetCachedParagraphLayout(std::string_view str, const FontState &state)
Get reference to cache item.
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.
A single line worth of VisualRuns.
std::string str
Source string of the line (including colour and font size codes).
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.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool operator()(const Key1 &lhs, const Key2 &rhs) const
Comparison operator for LineCacheKey and LineCacheQuery.
Dimension GetBounds()
Get the boundaries of this paragraph.
The layouter performs all the layout work.
Font(FontSize size, TextColour colour)
Construct a new font.
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.
Container with information about a font.
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 colour
The colour this font has to be.
TextColour cur_colour
Current text colour.
Font cache for basic fonts.
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.
Layouter(std::string_view str, int maxw=INT32_MAX, TextColour colour=TC_FROMSTRING, FontSize fontsize=FS_NORMAL)
Create a new layouter.
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.
Point GetCharPosition(std::string_view::const_iterator ch) const
Get the position of a character in the layout.
FontSize
Available font sizes.
@ TC_COLOUR_MASK
Mask to test if TextColour (without flags) is within limits.
std::map< int, Font * > FontMap
Mapping from index to font.
static void Initialize()
Perform initialization of layout engine.
void PushColour()
Push the current colour on to the stack.
void * buffer
Accessed by our ParagraphLayout::nextLine.
ptrdiff_t GetCharAtPosition(int x, size_t line_index) const
Get the character that is at a pixel position in the first line of the layouted text.