24 #include <pango/pangocairo.h>
138 unsigned insert_text(
const unsigned offset,
const std::string&
text,
const bool use_markup =
false);
172 const unsigned column,
const unsigned line = 0)
const;
204 std::string
get_token(
const point & position,
const char * delimiters =
" \n\r\t")
const;
237 std::vector<std::string>
get_lines()
const;
286 bool set_text(
const std::string&
text,
const bool markedup);
326 std::unique_ptr<PangoContext, std::function<void(
void*)>>
context_;
327 std::unique_ptr<PangoLayout, std::function<void(
void*)>>
layout_;
457 void render(PangoLayout&
layout,
const SDL_Rect& viewport,
const unsigned stride);
483 bool validate_markup(std::string_view
text,
char** raw_text, std::string& semi_escaped)
const;
Helper class to encapsulate the management of a PangoAttrList.
unsigned get_lines_count() const
Get number of lines in the text.
int pixel_scale_
The pixel scale, used to render high-DPI text.
int xy_to_index(const point &position) const
pango_text & operator=(const pango_text &)=delete
pango_text & set_font_style(const FONT_STYLE font_style)
PangoEllipsizeMode ellipse_mode_
The way too long text is shown depends on this mode.
static void copy_layout_properties(PangoLayout &src, PangoLayout &dst)
bool add_outline_
Whether to add an outline effect.
bool validate_markup(std::string_view text, char **raw_text, std::string &semi_escaped) const
bool set_markup(std::string_view text, PangoLayout &layout)
Sets the markup'ed text.
std::size_t get_length() const
Gets the length of the text in bytes.
pango_text & set_maximum_length(const std::size_t maximum_length)
void render(PangoLayout &layout, const SDL_Rect &viewport, const unsigned stride)
This is part of create_surface(viewport).
surface create_surface()
Equivalent to create_surface(viewport), where the viewport's top-left is at (0,0) and the area is lar...
PangoAlignment alignment_
The alignment of the text.
int maximum_height_
The maximum height of the text.
point get_size()
Returns the size of the text, in drawing coordinates.
pango_text & set_characters_per_line(const unsigned characters_per_line)
color_t link_color_
The color to render links in.
unsigned insert_text(const unsigned offset, const std::string &text, const bool use_markup=false)
Inserts UTF-8 text.
int get_line_num_from_offset(const unsigned offset)
Given a byte index, find out at which line the corresponding character is located.
void recalculate() const
Recalculates the text layout.
color_t foreground_color_
The foreground color.
point get_column_line(const point &position) const
Gets the column of line of the character at the position.
std::unique_ptr< PangoContext, std::function< void(void *)> > context_
bool link_aware_
Are hyperlinks in the text marked-up, and will get_link return them.
pango_text & set_foreground_color(const color_t &color)
int to_draw_scale(int s) const
Scale the given render-space size to draw-space, rounding up.
std::string format_links(std::string_view text) const
Replaces all instances of URLs in a given string with formatted links and returns the result.
pango_text(const pango_text &)=delete
PangoLayoutLine * get_line(int index)
Get a specific line from the pango layout.
unsigned characters_per_line_
The number of characters per line.
bool markedup_text_
Does the text contain pango markup? If different render routines must be used.
pango_text & set_family_class(font::family_class fclass)
font::family_class font_class_
The font family class used.
void apply_attributes(const font::attribute_list &attrs)
std::vector< std::string > get_lines() const
Retrieves a list of strings with contents for each rendered line.
void update_pixel_scale()
Update pixel scale, if necessary.
unsigned font_size_
The font size to draw.
texture render_texture(const SDL_Rect &viewport)
Wrapper around render_surface which sets texture::w() and texture::h() in the same way that render_an...
surface render_surface(const SDL_Rect &viewport)
Returns the rendered text.
std::vector< uint8_t > surface_buffer_
Buffer to store the image on.
pango_text & set_add_outline(bool do_add)
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
PangoRectangle calculate_size(PangoLayout &layout) const
Calculates surface size.
pango_text & set_alignment(const PangoAlignment alignment)
std::string text_
The text to draw (stored as UTF-8).
point get_cursor_position(const unsigned column, const unsigned line=0) const
Gets the location for the cursor, in drawing coordinates.
bool calculation_dirty_
The text has two dirty states:
std::unique_ptr< PangoLayout, std::function< void(void *)> > layout_
pango_text & set_font_size(unsigned font_size)
pango_text & set_link_aware(bool b)
FONT_STYLE font_style_
The style of the font, this is an orred mask of the font flags.
std::string get_token(const point &position, const char *delimiters=" \n\r\t") const
Gets the largest collection of characters, including the token at position, and not including any cha...
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
bool is_truncated() const
Has the text been truncated? This happens if it exceeds max width or height.
texture with_draw_scale(const texture &t) const
Adjust a texture's draw-width and height according to pixel scale.
std::size_t maximum_length_
The maximum length of the text.
point get_cursor_pos_from_index(const unsigned offset) const
Gets the location for the cursor, in drawing coordinates.
pango_text & set_maximum_height(int height, bool multiline)
pango_text & set_maximum_width(int width)
std::size_t get_maximum_length() const
Get maximum length.
texture render_and_get_texture()
Returns the cached texture, or creates a new one otherwise.
pango_text & set_link_color(const color_t &color)
std::string get_link(const point &position) const
Checks if position points to a character in a link in the text, returns it if so, empty string otherw...
const std::string & text() const
std::size_t length_
Length of the text.
int get_max_glyph_height() const
Returns the maximum glyph height of a font, in drawing coordinates.
int maximum_width_
The maximum width of the text.
Wrapper class to encapsulate creation and management of an SDL_Texture.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
family_class
Font classes for get_font_families().
int get_max_height(unsigned size, font::family_class fclass, pango_text::FONT_STYLE style)
Returns the maximum glyph height of a font, in pixels.
pango_text & get_text_renderer()
Returns a reference to a static pango_text object.
constexpr float get_line_spacing_factor()
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
The basic class for representing 8-bit RGB or RGBA colour values.
static map_location::direction s