24 #include <pango/pangocairo.h>
139 unsigned insert_text(
const unsigned offset,
const std::string&
text,
const bool use_markup =
false);
173 const unsigned column,
const unsigned line = 0)
const;
205 std::string
get_token(
const point & position,
const char * delimiters =
" \n\r\t")
const;
238 std::vector<std::string>
get_lines()
const;
287 bool set_text(
const std::string&
text,
const bool markedup);
331 void add_attribute_weight(
const unsigned start_offset,
const unsigned end_offset, PangoWeight weight);
339 void add_attribute_style(
const unsigned start_offset,
const unsigned end_offset, PangoStyle style);
348 void add_attribute_underline(
const unsigned start_offset,
const unsigned end_offset, PangoUnderline underline);
393 std::unique_ptr<PangoContext, std::function<void(
void*)>>
context_;
394 std::unique_ptr<PangoLayout, std::function<void(
void*)>>
layout_;
534 void render(PangoLayout&
layout,
const SDL_Rect& viewport,
const unsigned stride);
560 bool validate_markup(std::string_view
text,
char** raw_text, std::string& semi_escaped)
const;
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.
void add_attribute_weight(const unsigned start_offset, const unsigned end_offset, PangoWeight weight)
Add pango font weight attribute to a specific portion of text.
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.
void add_attribute_font_family(const unsigned start_offset, const unsigned end_offset, std::string family)
Add pango font family attribute to a specific portion of text.
pango_text & set_family_class(font::family_class fclass)
font::family_class font_class_
The font family class used.
std::vector< std::string > get_lines() const
Retrieves a list of strings with contents for each rendered line.
void add_attribute_fg_color(const unsigned start_offset, const unsigned end_offset, const color_t &color)
Add pango fg color attribute to a specific portion of text.
void update_pixel_scale()
Update pixel scale, if necessary.
unsigned font_size_
The font size to draw.
void add_attribute_size(const unsigned start_offset, const unsigned end_offset, int size)
Add pango font size attribute to a specific portion of text.
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)
unsigned attribute_end_offset_
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
void add_attribute_bg_color(const unsigned start_offset, const unsigned end_offset, const color_t &color)
Mark a specific portion of text for highlighting.
PangoRectangle calculate_size(PangoLayout &layout) const
Calculates surface size.
void add_attribute_underline(const unsigned start_offset, const unsigned end_offset, PangoUnderline underline)
Add pango underline attribute to a specific portion of text.
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.
unsigned attribute_start_offset_
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.
void add_attribute_style(const unsigned start_offset, const unsigned end_offset, PangoStyle style)
Add pango font style attribute to a specific portion of text, used to set italic/oblique text.
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.
PangoAttrList * global_attribute_list_
Global pango attribute list.
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...
void clear_attribute_list()
Clears all attributes from the global attribute list.
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()
void flush_texture_cache()
Flush the rendered text cache.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::size_t size(const std::string &str)
Length in characters of 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