OpenTTD Source: src/gfx_layout.cpp File Reference

OpenTTD Source 15.3

Functions
gfx_layout.cpp File Reference

Handling of laying out text. More...

`#include "stdafx.h"`
`#include "core/math_func.hpp"`
`#include "gfx_layout.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "core/utf8.hpp"`
`#include "debug.h"`
`#include "table/control_codes.h"`
`#include "gfx_layout_fallback.h"`
`#include "gfx_layout_icu.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
template<typename T >
static void | GetLayouter (Layouter::LineCacheItem &line, std::string_view str, FontState &state)
| Helper for getting a ParagraphLayouter of the given type.
static bool | IsConsumedFormattingCode (char32_t ch)
| Test whether a character is a non-printable formatting code.
ParagraphLayouter::Position | GetCharPosInString (std::string_view str, size_t pos, FontSize start_fontsize)
| Get the leading corner of a character in a single-line string relative to the start of the string.
ptrdiff_t | GetCharAtPosition (std::string_view str, int x, FontSize start_fontsize)
| Get the character from a string that is drawn at a specific position.

## Detailed Description

Handling of laying out text.

Definition in file gfx_layout.cpp.

## Function Documentation

## ◆ GetCharAtPosition()

ptrdiff_t GetCharAtPosition | ( | std::string_view | str,
|  | int | x,
|  | FontSize | start_fontsize
| ) |  |

Get the character from a string that is drawn at a specific position.

Parameters

  str | String to test.
  x | Position relative to the start of the string.
  start_fontsize | Font size to start the text with.

Returns
  Index of the character position or -1 if there is no character at the position.

Definition at line 441 of file gfx_layout.cpp.

References Layouter::GetCharAtPosition().

Referenced by IConsoleWindow::GetTextCharacterAtPosition().

## ◆ GetCharPosInString()

ParagraphLayouter::Position GetCharPosInString | ( | std::string_view | str,
|  | size_t | pos,
|  | FontSize | start_fontsize
| ) |  |

Get the leading corner of a character in a single-line string relative to the start of the string.

Parameters

  str | String containing the character.
  pos | Index to the character in the string.
  start_fontsize | Font size to start the text with.

Returns
  Upper left corner of the glyph associated with the character.

Definition at line 425 of file gfx_layout.cpp.

References Layouter::GetCharPosition().

Referenced by QueryString::GetBoundingRect(), IConsoleWindow::GetTextBoundingRect(), Textbuf::UpdateCaretPosition(), and Textbuf::UpdateMarkedText().

## ◆ GetLayouter()

template<typename T >

static void GetLayouter | ( | Layouter::LineCacheItem & | line,
|  | std::string_view | str,
|  | FontState & | state
| ) |  |
| inlinestatic

Helper for getting a ParagraphLayouter of the given type.

Note
  In case no ParagraphLayouter could be constructed, line.layout will be nullptr.

Parameters

  line | The cache item to store our layouter in.
  str | The string to create a layouter for.
  state | The state of the font and colour.

Template Parameters

  T | The type of layouter we want.

Definition at line 65 of file gfx_layout.cpp.

References Layouter::LineCacheItem::buffer, FontState::cur_colour, FontState::fontsize, Layouter::GetFont(), IsTextDirectionChar(), Layouter::LineCacheItem::layout, FontState::PopColour(), FontState::PushColour(), Layouter::LineCacheItem::runs, FontState::SetColour(), FontState::SetFontSize(), and Layouter::LineCacheItem::state_after.

## ◆ IsConsumedFormattingCode()

static bool IsConsumedFormattingCode | ( | char32_t | ch | ) |
| static

Test whether a character is a non-printable formatting code.

Definition at line 221 of file gfx_layout.cpp.

Referenced by Layouter::GetCharAtPosition(), and Layouter::GetCharPosition().