|
OpenTTD Source 20260218-master-g2123fca5ea
|
The layouter performs all the layout work. More...
#include <gfx_layout.h>
Data Structures | |
| struct | LineCacheKey |
| Key into the linecache. More... | |
| struct | LineCacheQuery |
| struct | LineCacheEqualTo |
| struct | LineCacheItem |
| Item in the linecache. More... | |
| struct | LineCacheHash |
Public Member Functions | |
| Layouter (std::string_view str, int maxw=INT32_MAX, FontSize fontsize=FS_NORMAL) | |
| Create a new layouter. | |
| Dimension | GetBounds () |
| Get the boundaries of this paragraph. | |
| ParagraphLayouter::Position | GetCharPosition (std::string_view::const_iterator ch) const |
| Get the position of a character in the layout. | |
| 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. | |
Static Public Member Functions | |
| static Font * | GetFont (FontSize size, TextColour colour) |
| Get a static font instance. | |
| static void | Initialize () |
| Perform initialization of layout engine. | |
| static void | ResetFontCache (FontSize size) |
| Reset cached font information. | |
| static void | ResetLineCache () |
| Clear line cache. | |
Private Types | |
| using | LineCache = LRUCache<LineCacheKey, LineCacheItem, LineCacheHash, LineCacheEqualTo> |
| using | FontColourMap = std::map<TextColour, std::unique_ptr<Font>> |
Static Private Member Functions | |
| static LineCacheItem & | GetCachedParagraphLayout (std::string_view str, const FontState &state) |
| Get reference to cache item. | |
Private Attributes | |
| std::string_view | string |
| Pointer to the original string. | |
Static Private Attributes | |
| static std::unique_ptr< LineCache > | linecache |
| Cache of ParagraphLayout lines. | |
| static FontColourMap | fonts [FS_END] |
| Cache of Font instances. | |
Friends | |
| struct | std::hash< Layouter::LineCacheQuery > |
The layouter performs all the layout work.
It also accounts for the memory allocations and frees.
Definition at line 230 of file gfx_layout.h.
|
private |
Definition at line 278 of file gfx_layout.h.
|
private |
Definition at line 273 of file gfx_layout.h.
Create a new layouter.
| str | The string to create the layout for. |
| maxw | The maximum width. |
| fontsize | The size of font to use. |
Definition at line 129 of file gfx_layout.cpp.
References Layouter::LineCacheItem::cached_layout, Layouter::LineCacheItem::cached_width, GetCachedParagraphLayout(), GetLayouter(), Layouter::LineCacheItem::layout, Layouter::LineCacheItem::state_after, and string.
| Dimension Layouter::GetBounds | ( | ) |
Get the boundaries of this paragraph.
Definition at line 208 of file gfx_layout.cpp.
Referenced by DrawStringMultiLine(), GetStringBoundingBox(), and GetStringHeight().
|
staticprivate |
Get reference to cache item.
If the item does not exist yet, it is default constructed.
| str | Source string of the line (including colour and font size codes). |
| state | State of the font at the beginning of the line. |
Definition at line 394 of file gfx_layout.cpp.
References linecache, Layouter::LineCacheKey::state_before, and Layouter::LineCacheKey::str.
Referenced by Layouter().
| ptrdiff_t Layouter::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.
| x | Position in the string. |
| line_index | Which line of the layout to search |
Definition at line 305 of file gfx_layout.cpp.
References ParagraphLayouter::VisualRun::GetGlyphCount(), ParagraphLayouter::VisualRun::GetGlyphs(), ParagraphLayouter::VisualRun::GetGlyphToCharMap(), ParagraphLayouter::VisualRun::GetPositions(), IsConsumedFormattingCode(), and IsInsideMM().
Referenced by GetCharAtPosition(), and TextfileWindow::GetHyperlink().
| ParagraphLayouter::Position Layouter::GetCharPosition | ( | std::string_view::const_iterator | ch | ) | const |
Get the position of a character in the layout.
| ch | Character to get the position of. Must be an iterator of the string passed to the constructor. |
Definition at line 239 of file gfx_layout.cpp.
References _current_text_dir, ParagraphLayouter::VisualRun::GetGlyphToCharMap(), Utf8View::GetIterAtByte(), ParagraphLayouter::VisualRun::GetPositions(), IsConsumedFormattingCode(), Point, and TD_LTR.
Referenced by GetCharPosInString().
|
static |
Get a static font instance.
| size | The size of font. |
| colour | The font's colour. |
Definition at line 349 of file gfx_layout.cpp.
References fonts.
Referenced by GetLayouter().
|
static |
Perform initialization of layout engine.
Definition at line 361 of file gfx_layout.cpp.
References ICUParagraphLayoutFactory::InitializeLayouter().
Referenced by ReadLanguagePack().
|
static |
Reset cached font information.
| size | Font size to reset. |
Definition at line 372 of file gfx_layout.cpp.
References fonts, MacOSResetScriptCache(), and ResetLineCache().
Referenced by SpriteFontCache::ClearFontCache(), TrueTypeFontCache::ClearFontCache(), and FontCache::LoadFontCaches().
|
static |
Clear line cache.
Definition at line 417 of file gfx_layout.cpp.
References linecache.
Referenced by ResetFontCache().
|
friend |
Definition at line 231 of file gfx_layout.h.
|
staticprivate |
Cache of Font instances.
Definition at line 279 of file gfx_layout.h.
Referenced by GetFont(), and ResetFontCache().
|
staticprivate |
Cache of ParagraphLayout lines.
Definition at line 274 of file gfx_layout.h.
Referenced by GetCachedParagraphLayout(), and ResetLineCache().
|
private |
Pointer to the original string.
Definition at line 231 of file gfx_layout.h.
Referenced by Layouter().