1 #include "../Common/Common.h"
3 #include "PangoCache.h"
6 CPangoCache::CPangoCache(const std::string
&strFontName
) {
7 font
= pango_font_description_from_string(strFontName
.c_str());
10 void CPangoCache::ChangeFont(const std::string
&strFontName
) {
11 pango_font_description_free(font
);
12 font
= pango_font_description_from_string(strFontName
.c_str());
14 // FIXME - probably need to free the pango layouts, but I can't find a function to do this.
20 PangoLayout
*CPangoCache::GetLayout(cairo_t
*cr
, std::string sDisplayText
, int iSize
) {
22 PangoLayout
*CPangoCache::GetLayout(GtkWidget
*pCanvas
, std::string sDisplayText
, int iSize
) {
25 // Calculate the name of the pango layout in the cache - this
26 // includes the display text and the size.
28 char buffer
[128]; // FIXME - what if we exceed this?
30 snprintf(buffer
, 128, "%d_%s", iSize
, sDisplayText
.c_str());
31 // // std::stringstream sCacheName;
32 // //sCacheName << iSize << "_" << sDisplayText;
34 std::string
sCacheName(buffer
);
36 // TODO: This is blatantly not going to work for unicode
37 // int iCacheIndex(iSize + 256 * sDisplayText[0]);
39 // If we haven't got a cached pango layout for this string/size yet,
42 std::map
<std::string
, PangoLayout
*>::iterator
it(oPangoCache
.find(sCacheName
));
44 if(it
!= oPangoCache
.end())
49 PangoLayout
*pNewPangoLayout(pango_cairo_create_layout(cr
));
51 PangoLayout
*pNewPangoLayout(gtk_widget_create_pango_layout(pCanvas
, ""));
54 pango_font_description_set_size(font
, iSize
* PANGO_SCALE
);
55 pango_layout_set_font_description(pNewPangoLayout
, font
);
56 pango_layout_set_text(pNewPangoLayout
, sDisplayText
.c_str(), -1);
58 oPangoCache
[sCacheName
] = pNewPangoLayout
;
60 return pNewPangoLayout
;