Added a getter for a static pango_text object
The reason I added this was so I can refactor some temporary pango_text objects out of the display class. styled_widget doesn't use this for reasons explained in the comment.
This commit is contained in:
parent
2dca404a63
commit
770664d1f3
4 changed files with 20 additions and 4 deletions
|
@ -866,4 +866,10 @@ void pango_text::copy_layout_properties(PangoLayout& src, PangoLayout& dst)
|
|||
pango_layout_set_ellipsize(&dst, pango_layout_get_ellipsize(&src));
|
||||
}
|
||||
|
||||
pango_text& get_text_renderer()
|
||||
{
|
||||
static pango_text text_renderer;
|
||||
return text_renderer;
|
||||
}
|
||||
|
||||
} // namespace font
|
||||
|
|
|
@ -447,4 +447,13 @@ private:
|
|||
void format_links(std::string& text, const std::vector<std::string>& links) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a reference to a static pango_text object.
|
||||
*
|
||||
* Since the class is essentially a render pipeline, there's no need for individual
|
||||
* areas of the game to own their own renderers. Not to mention it isn't a trivial
|
||||
* class; constructing one is likely to be expensive.
|
||||
*/
|
||||
pango_text& get_text_renderer();
|
||||
|
||||
} // namespace font
|
||||
|
|
|
@ -1274,7 +1274,7 @@ void text_shape::draw(
|
|||
return;
|
||||
}
|
||||
|
||||
static font::pango_text text_renderer;
|
||||
font::pango_text& text_renderer = font::get_text_renderer();
|
||||
|
||||
text_renderer
|
||||
.set_link_aware(link_aware_(variables))
|
||||
|
|
|
@ -445,10 +445,11 @@ private:
|
|||
}
|
||||
|
||||
/**
|
||||
* Contains a helper cache for the rendering.
|
||||
* Text renderer object used for size calculations.
|
||||
*
|
||||
* Creating a pango_text object is quite expensive and is done on various
|
||||
* occasions so it's cached here.
|
||||
* Note this is *not* used to actually render any text, only to get the dimensions of the text for
|
||||
* layout purposes. The actual text rendering happens in the canvas. This is kept as a class member
|
||||
* since creating a pango_text object is quite expensive.
|
||||
*
|
||||
* @todo Maybe if still too slow we might also copy this cache to the
|
||||
* canvas so it can reuse our results, but for now it seems fast enough.
|
||||
|
|
Loading…
Add table
Reference in a new issue