summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-05-30 15:28:08 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-05-30 15:28:08 +0200
commite6bccc081f651a87bba58235e8c28c3fdfae5607 (patch)
tree17457740d8b4c53959565f9f2a011fab89dc2388 /src/drivers
parent7c4239915f818ff26309ed6a638871ea284a82e9 (diff)
X11+Pango: call pango_font_description_from_string() less often
Previously, each time fl_font(fnum, fsize) was called, functions pango_font_description_free() and pango_font_description_from_string() would be called. Now, pango_font_description_from_string() is called only once, the first time an Fl_Font is used.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H3
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx16
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx25
3 files changed, 30 insertions, 14 deletions
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 66b47edb0..784bc8d02 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -84,7 +84,8 @@ protected:
static PangoContext *pctxt_;
static PangoFontMap *pfmap_;
static PangoLayout *playout_;
- PangoFontDescription *pfd_;
+ static PangoFontDescription **pfd_array; // one array element for each Fl_Font
+ static int pfd_array_length;
void do_draw(int from_right, const char *str, int n, int x, int y);
static PangoContext *context();
static void init_built_in_fonts();
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
index d01d1156b..3a1ff8361 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
@@ -54,7 +54,6 @@ Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
p = NULL;
line_delta_ = 0;
#if USE_PANGO
- pfd_ = pango_font_description_new();
Fl_Graphics_Driver::font(0, 0);
#endif
offset_x_ = 0; offset_y_ = 0;
@@ -64,9 +63,6 @@ Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
Fl_Xlib_Graphics_Driver::~Fl_Xlib_Graphics_Driver() {
if (p) free(p);
-#if USE_PANGO
- pango_font_description_free(pfd_);
-#endif
}
@@ -216,7 +212,11 @@ const char *Fl_Xlib_Graphics_Driver::font_name(int num) {
void Fl_Xlib_Graphics_Driver::font_name(int num, const char *name) {
#if USE_XFT
# if USE_PANGO
- init_built_in_fonts();
+ init_built_in_fonts();
+ if (pfd_array_length > num && pfd_array[num]) {
+ pango_font_description_free(pfd_array[num]);
+ pfd_array[num] = NULL;
+ }
# endif
Fl_Fontdesc *s = fl_fonts + num;
#else
@@ -287,6 +287,12 @@ void Fl_Xlib_Graphics_Driver::set_current_() {
restore_clip();
}
+#if USE_PANGO
+int Fl_Xlib_Graphics_Driver::pfd_array_length = FL_FREE_FONT;
+
+PangoFontDescription **Fl_Xlib_Graphics_Driver::pfd_array = (PangoFontDescription**)calloc(pfd_array_length, sizeof(PangoFontDescription*));
+#endif
+
//
// End of "$Id$".
//
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
index 932a0e9ef..cdad1a2d9 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
@@ -1208,13 +1208,22 @@ void Fl_Xlib_Graphics_Driver::font_unscaled(Fl_Font fnum, Fl_Fontsize size) {
if (this->Fl_Graphics_Driver::font() == fnum && this->size_unscaled() == size && this->font_descriptor()) return;
fl_xft_font(this, fnum, size, 0);
init_built_in_fonts();
- if (pfd_) pango_font_description_free(pfd_);
- pfd_ = pango_font_description_from_string(Fl::get_font_name(fnum));
- pango_font_description_set_absolute_size(pfd_, size*PANGO_SCALE); // 1.8
+ if (fnum >= pfd_array_length) {
+ int new_length = fnum + 10;
+ PangoFontDescription **data = (PangoFontDescription**)calloc(new_length, sizeof(PangoFontDescription*));
+ memcpy(data, pfd_array, pfd_array_length*sizeof(PangoFontDescription*));
+ free(pfd_array);
+ pfd_array = data;
+ pfd_array_length = new_length;
+ }
+ if (!pfd_array[fnum]) {
+ pfd_array[fnum] = pango_font_description_from_string(Fl::get_font_name(fnum));
+ }
+ pango_font_description_set_absolute_size(pfd_array[fnum], size*PANGO_SCALE); // 1.8
if (!pctxt_) context();
Fl_Xlib_Font_Descriptor *fd = (Fl_Xlib_Font_Descriptor*)font_descriptor();
if (!fd->height_) {
- PangoFont *pfont = pango_font_map_load_font(pfmap_, pctxt_, pfd_);
+ PangoFont *pfont = pango_font_map_load_font(pfmap_, pctxt_, pfd_array[fnum]);
PangoRectangle logical_rect;
pango_font_get_glyph_extents(pfont, /*PangoGlyph glyph*/'p', NULL, &logical_rect);
fd->descent_ = PANGO_DESCENT(logical_rect)/PANGO_SCALE;
@@ -1273,7 +1282,7 @@ void Fl_Xlib_Graphics_Driver::do_draw(int from_right, const char *str, int n, in
if (--n == 0) return;
tmpv = NULL;
}
- pango_layout_set_font_description(playout_, pfd_);
+ pango_layout_set_font_description(playout_, pfd_array[font_]);
if (tmpv) { // replace newlines by spaces in a copy of str
str2 = (char*)malloc(n);
memcpy(str2, str, n);
@@ -1319,7 +1328,7 @@ double Fl_Xlib_Graphics_Driver::width_unscaled(const char* str, int n) {
if (!fl_display || size_ == 0) return -1;
if (!playout_) context();
int width, height;
- pango_layout_set_font_description(playout_, pfd_);
+ pango_layout_set_font_description(playout_, pfd_array[font_]);
pango_layout_set_text(playout_, str, n);
pango_layout_get_pixel_size(playout_, &width, &height);
return (double)width;
@@ -1327,7 +1336,7 @@ double Fl_Xlib_Graphics_Driver::width_unscaled(const char* str, int n) {
void Fl_Xlib_Graphics_Driver::text_extents_unscaled(const char *str, int n, int &dx, int &dy, int &w, int &h) {
if (!playout_) context();
- pango_layout_set_font_description(playout_, pfd_);
+ pango_layout_set_font_description(playout_, pfd_array[font_]);
pango_layout_set_text(playout_, str, n);
int y_correction;
fl_pango_layout_get_pixel_extents(playout_, dx, dy, w, h, descent_unscaled(), height_unscaled(), y_correction);
@@ -1395,7 +1404,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name)
*(p+lp-4) = 0; prefix = 'B';
}
char *q = p + strlen(p) - 1;
- while (*q == ' ' && q > p) q--;
+ while (q > p && *q == ' ') {*q = 0; q--;}
int lq = l+2;
if (*p) lq += strlen(p) + 1;
q = new char[lq];