summaryrefslogtreecommitdiff
path: root/src/drivers/Cairo
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/Cairo')
-rw-r--r--src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index c7e2c2ae3..6433cf5c1 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -1,7 +1,7 @@
//
// Support for Cairo graphics for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2021-2022 by Bill Spitzak and others.
+// Copyright 2021-2023 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -1012,14 +1012,17 @@ void Fl_Cairo_Graphics_Driver::init_built_in_fonts() {
}
+// FIXME: this (static) function should likely be in Fl_Graphics_Driver.
+// The code is the same as in src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
+
static int font_name_process(const char *name, char &face) {
int l = strlen(name);
face = ' ';
- if (!memcmp(name + l - 8, " Regular", 8)) l -= 8;
- else if (!memcmp(name + l - 6, " Plain", 6)) l -= 6;
- else if (!memcmp(name + l - 12, " Bold Italic", 12)) {l -= 12; face='P';}
- else if (!memcmp(name + l - 7, " Italic", 7)) {l -= 7; face='I';}
- else if (!memcmp(name + l - 5, " Bold", 5)) {l -= 5; face='B';}
+ if (l > 8 && !memcmp(name + l - 8, " Regular", 8)) l -= 8;
+ else if (l > 6 && !memcmp(name + l - 6, " Plain", 6)) l -= 6;
+ else if (l > 12 && !memcmp(name + l - 12, " Bold Italic", 12)) {l -= 12; face = 'P';}
+ else if (l > 7 && !memcmp(name + l - 7, " Italic", 7)) {l -= 7; face = 'I';}
+ else if (l > 5 && !memcmp(name + l - 5, " Bold", 5)) {l -= 5; face = 'B';}
return l;
}
@@ -1047,14 +1050,14 @@ Fl_Font Fl_Cairo_Graphics_Driver::set_fonts(const char* /*pattern_name*/)
PangoFontFace **faces;
int n_faces;
const char *fam_name = pango_font_family_get_name (families[fam]);
- int l = strlen(fam_name);
+ int lfam = strlen(fam_name);
pango_font_family_list_faces(families[fam], &faces, &n_faces);
for (int j = 0; j < n_faces; j++) {
const char *p = pango_font_face_get_face_name(faces[j]);
// build the font's FLTK name
- l += strlen(p) + 2;
- char *q = new char[l];
- snprintf(q, l, "%s %s", fam_name, p);
+ int lfont = lfam + strlen(p) + 2;
+ char *q = new char[lfont];
+ snprintf(q, lfont, "%s %s", fam_name, p);
Fl::set_font((Fl_Font)(count++ + FL_FREE_FONT), q);
}
/*g_*/free(faces); // glib source code shows that g_free is equivalent to free