C5: XLFD font resolution skips two-byte fonts; labels no longer vanish at size 16
A wildcard XLFD pattern can match a two-byte font first (e.g. a JIS fixed font at size 16, which has no misc twin). XDrawString with 1-byte Latin text draws nothing with such a font, so widget labels vanished whenever the font size resolved to one (size 16 confirmed: JIS min_byte1=33; Sony and misc 1-byte fonts render fine). Both font-resolution paths now list every match per pattern and return the full XLFD name of the first single-byte font (min_byte1 == max_byte1 == 0): font_xlfd_for (designer canvas) and the emitted lightgui_pick_font helper (generated apps). Also silences the -Wmissing-field-initializers warning on the Placed aggregate init and adds the missing <cstdio> include to the shared core header.
This commit is contained in:
1 parent
de855e3ebe
commit
4912457fd3
3 files changed
+40
-10
No files matched your search
+19
-4
@@ -1097,6 +1097,12 @@ static std::string widget_font_expr(const Widget& w) {
|
||||
static const char* kLightguiPickFont = R"GEN(// Pick a loadable XLFD for a per-widget font (Phase 1, Flag 2):
|
||||
// family/size/bold/italic, then oblique for italic, then plain, then
|
||||
// fixed at the requested size, then the fixed 13 default.
|
||||
// A wildcard pattern can match a two-byte font first (e.g. a JIS fixed
|
||||
// font at size 16, which has no misc twin). XDrawString with 1-byte
|
||||
// Latin text draws nothing with such a font, so every match is listed
|
||||
// and the first SINGLE-BYTE font (min_byte1 == max_byte1 == 0) wins;
|
||||
// its full XLFD name is returned, since the pattern itself would
|
||||
// re-resolve to the two-byte font.
|
||||
static std::string lightgui_pick_font(Display* display,
|
||||
const std::string& family, int size,
|
||||
bool bold, bool italic) {
|
||||
@@ -1122,11 +1128,20 @@ static std::string lightgui_pick_font(Display* display,
|
||||
cands.push_back("-misc-fixed-medium-r-normal--13-*");
|
||||
for (const std::string& pat : cands) {
|
||||
int count = 0;
|
||||
char** list = XListFonts(display, pat.c_str(), 1, &count);
|
||||
if (list) {
|
||||
XFreeFontNames(list);
|
||||
if (count > 0) return pat;
|
||||
char** list = XListFonts(display, pat.c_str(), 64, &count);
|
||||
if (!list) continue;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
XFontStruct* f = XLoadQueryFont(display, list[i]);
|
||||
if (!f) continue;
|
||||
bool single_byte = (f->min_byte1 == 0 && f->max_byte1 == 0);
|
||||
XFreeFont(display, f);
|
||||
if (single_byte) {
|
||||
std::string hit = list[i];
|
||||
XFreeFontNames(list);
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
XFreeFontNames(list);
|
||||
}
|
||||
return "-misc-fixed-medium-r-normal--13-*";
|
||||
}
|
||||
|
||||
@@ -203,6 +203,12 @@ void clamp_to_constraints(const XFrameCanvasCore::Placed* p, int& w,
|
||||
// bold/italic, then oblique for italic, then plain, then fixed at the
|
||||
// requested size, then the fixed 13 default. A family starting with
|
||||
// '-' is a full XLFD pattern and is tried verbatim first.
|
||||
// A wildcard pattern can match a two-byte font first (e.g. a JIS fixed
|
||||
// font at size 16, which has no misc twin). XDrawString with 1-byte
|
||||
// Latin text draws nothing with such a font, so every match is listed
|
||||
// and the first SINGLE-BYTE font (min_byte1 == max_byte1 == 0) wins;
|
||||
// its full XLFD name is returned, since the pattern itself would
|
||||
// re-resolve to the two-byte font.
|
||||
std::string font_xlfd_for(Display* dpy, const std::string& family,
|
||||
int size, bool bold, bool italic) {
|
||||
if (size < 6) size = 6;
|
||||
@@ -232,11 +238,20 @@ std::string font_xlfd_for(Display* dpy, const std::string& family,
|
||||
cands.push_back("-misc-fixed-medium-r-normal--13-*");
|
||||
for (const auto& pat : cands) {
|
||||
int count = 0;
|
||||
char** list = XListFonts(dpy, pat.c_str(), 1, &count);
|
||||
if (list) {
|
||||
XFreeFontNames(list);
|
||||
if (count > 0) return pat;
|
||||
char** list = XListFonts(dpy, pat.c_str(), 64, &count);
|
||||
if (!list) continue;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
XFontStruct* f = XLoadQueryFont(dpy, list[i]);
|
||||
if (!f) continue;
|
||||
bool single_byte = (f->min_byte1 == 0 && f->max_byte1 == 0);
|
||||
XFreeFont(dpy, f);
|
||||
if (single_byte) {
|
||||
std::string hit = list[i];
|
||||
XFreeFontNames(list);
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
XFreeFontNames(list);
|
||||
}
|
||||
return "-misc-fixed-medium-r-normal--13-*";
|
||||
}
|
||||
@@ -541,8 +556,7 @@ int xframe_core_place(XFrameCanvasCore* c, int type, int x, int y, int w,
|
||||
c->last_placed_id = id;
|
||||
c->placed.push_back({id, type, x, y, w, h, c->border_width,
|
||||
c->border_color, c->border_radius,
|
||||
std::move(wdg), {}, {}});
|
||||
c->placed.back().has_border_style = had_border;
|
||||
std::move(wdg), {}, {}, "", had_border});
|
||||
c->selected_id = id;
|
||||
c->handles_on = false;
|
||||
write_state(c);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
//
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
|
||||
Reference in new issue
Block a user