Fix "Fl::get_font_name() with Pango is inconsistent" (#732)

This commit is contained in:
ManoloFLTK 2023-06-05 16:05:27 +02:00
parent 5be3fbf913
commit 64eafbefd6
2 changed files with 16 additions and 0 deletions

View File

@ -1053,6 +1053,8 @@ struct fl_wld_buffer {
struct wl_callback *cb; // non-NULL while Wayland buffer is being committed
bool draw_buffer_needs_commit; // true when draw_buffer has been modified but not yet committed
cairo_t *cairo_; // used when drawing to the Cairo image surface
struct wl_shm_pool *shm_pool; // pter to wl_shm_pool from which this wl_buffer comes
struct wl_list link; // links all buffers from the same wl_shm_pool
};
</pre>

View File

@ -25,6 +25,7 @@
#include "../../Fl_Screen_Driver.H"
#include <FL/platform.H>
#include <FL/fl_draw.H>
#include <FL/fl_utf8.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#if ! PANGO_VERSION_CHECK(1,16,0)
@ -1068,6 +1069,15 @@ Fl_Font Fl_Cairo_Graphics_Driver::set_fonts(const char* /*pattern_name*/)
fl_open_display();
int n_families, count = 0;
PangoFontFamily **families;
char *saved_lang = fl_getenv("LANG");
const char *Clang = "LANG=C";
if (saved_lang && strcmp(saved_lang, Clang)) {
// Force LANG=C to prevent pango_font_face_get_face_name() below from returning
// translated versions of Bold, Italic, etc… (see issue #732).
// Unfortunately, using setlocale() doesn't do the job.
saved_lang = strdup(saved_lang);
fl_putenv(Clang);
} else saved_lang = NULL;
static PangoFontMap *pfmap_ = pango_cairo_font_map_get_default(); // 1.10
Fl_Cairo_Graphics_Driver::init_built_in_fonts();
pango_font_map_list_families(pfmap_, &families, &n_families);
@ -1088,6 +1098,10 @@ Fl_Font Fl_Cairo_Graphics_Driver::set_fonts(const char* /*pattern_name*/)
/*g_*/free(faces); // glib source code shows that g_free is equivalent to free
}
/*g_*/free(families);
if (saved_lang) {
fl_putenv(saved_lang);
free(saved_lang);
}
// Sort the list into alphabetic order
qsort(fl_fonts + FL_FREE_FONT, count, sizeof(Fl_Fontdesc), (sort_f_type)font_sort);
return FL_FREE_FONT + count;