Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wcout opened this issue Jun 5, 2023 · 11 comments
Closed

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

wcout opened this issue Jun 5, 2023 · 11 comments
Assignees
Labels
fixed The issue or PR was fixed. Platform: Wayland platform specific (Unix/Wayland) Platform: X11 platform specific (Unix/X11))

Comments

@wcout
Copy link
Contributor

wcout commented Jun 5, 2023

Describe the bug
When building FLTK with Pango (either Xft+Pango or Wayland/Cairo+Pango) some fonts are not with correct style information.
I am observing this in special with the msttcorefonts.

To Reproduce

  1. Have the msttcorefont package installed with your system. You will get the additional true type fonts Arial, Courier New, Verdana, ...
  2. Compile FLTK with pango support.
  3. Start test/fonts and look at e.g. the Ariel font
  4. The name is displayed in dependency of the current LANG setting. And it does not correctly find the style (even if the font is bold it is not displayed in bold).

Expected behavior
The name should be consistent/independent from LANG and/or the style information should be correct.
Fl::get_font_name(name, &attr) should fill the attr information correctly.

An additional minor difference to the Xft version is (even when LANG is changed to an english one), that the name of the normal font is given as e.g. "Arial Regular" (Xft version gives just "Arial"). This makes it difficult to use Fl::set_font(Fl_Font, const char *name) consistently across platforms (though this could be worked around at application level, if attr would be correct from Fl::get_font()).

Screenshots
This is e.g. when LANG is set to 'fr':
grafik

FLTK Version
Git current.

FLTK Configure / Build Options

  • ./configure --enable-pango ...

Operating System / Platform:
Linux: Ubuntu 20.04

Linux/Unix Runtime, if applicable:

  • Wayland
  • X11
@ManoloFLTK
Copy link
Contributor

The commit mentionned above should fix the issue.

@wcout Please, close issue if you confirm it's fixed.

@ManoloFLTK ManoloFLTK self-assigned this Jun 5, 2023
@ManoloFLTK ManoloFLTK added Platform: X11 platform specific (Unix/X11)) Platform: Wayland platform specific (Unix/Wayland) labels Jun 5, 2023
@wcout
Copy link
Contributor Author

wcout commented Jun 5, 2023

Yes that fixes it, but only partially.

  1. The fix is only for the Cairo+Pango version, not for the Xft+Pango case.
  2. What about the 'Regular' problem mentioned in the issue description (under "Expected behaviour")?

I tried (for Cairo+Pango) the following change to remove the "Regular" from the name, and I can see no side effects. This would make the Pango version behave like the non-Pango (Xft only) version:

diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index fcc83dc5b..1720b569d 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -1089,10 +1089,15 @@ Fl_Font Fl_Cairo_Graphics_Driver::set_fonts(const char* /*pattern_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]);
+      if (!strcasecmp(p, "regular"))
+        p = "";
       // build the font's FLTK name
       int lfont = lfam + strlen(p) + 2;
       char *q = new char[lfont];
-      snprintf(q, lfont, "%s %s", fam_name, p);
+      if (*p)
+        snprintf(q, lfont, "%s %s", fam_name, p);
+      else
+        snprintf(q, lfont, "%s", fam_name);
       Fl::set_font((Fl_Font)(count++ + FL_FREE_FONT), q);
     }
     /*g_*/free(faces); // glib source code shows that g_free is equivalent to free

Note: This also fixes the name of fonts that don't have a 'Regular' string in it, these are currently created with a space at the end, like here (excerpt from a debug output of fonts list):

Font 346: 'Mitra Mono '
Font 347: 'Mitra Mono Bold'
Font 348: 'Mitra Mono Italic'
Font 349: 'Mitra Mono Bold Italic'
Font 350: 'Monospace '

@ManoloFLTK
Copy link
Contributor

The Xft+Pango case should be fixed now.

I'm not keen to remove the Regular suffix from Pango font names because Pango can put many suffixes besides Regular, Bold and Italic: Normal, Oblique, Medium, Roman, Light, Demi, Sans, SemiCondensed, SuperBold, Book, etc... Thus, I see Regular as part of the font names rather than as an annoying suffix.

@wcout
Copy link
Contributor Author

wcout commented Jun 5, 2023

I see only this problem for an application:
Setting a custom font, lets say 'Ariel' (name read perhaps from a config file) through Fl::set_font(FL_FREE_FONT, "Arial") will not work with Pango, but it will work with Xft. How should an application find out which Arial font name is the right one to use, when iterating through the list of fonts, searching for an Arial font, that has no style, as e.g. both 'Arial Regular' and 'Arial Black' don't have a bold or italic attribute set when queried with Fl::get_font(name, &attr)?

@ManoloFLTK
Copy link
Contributor

There are many differences in font names between the Xft and the Pango setups, besides presence or absence of the " Regular" suffix. I would believe it's not correct to expect a config file containing font names prepared under Xft to work in a Pango setup.

@wcout
Copy link
Contributor Author

wcout commented Jun 6, 2023

The fix for Xft does not work.
It works if moving the change of the language before the pango_font_map_list_families call.

But there is something wrong fundamentally here: fl_getenv() is returning just the language string e.g. "de_DE.UTF-8", but is then compared with "LANG=C" and afterwards set with fl_putenv() e.g. putenv("de_DE-UTF8"), which will not reset the LANG variable, but is an error.

@wcout
Copy link
Contributor Author

wcout commented Jun 6, 2023

JFYI: I see now, why the Xft-version does not produce font names containing "Regular": It is effectively filtered out by FLTK here:

// Read the "pretty" name we have derived from fontconfig then convert

@ManoloFLTK
Copy link
Contributor

Oops. The fixes should work after the last 2 commits mentionned above.

@wcout
Copy link
Contributor Author

wcout commented Jun 6, 2023

Ok - checked both - working!

I assume the argument about the Xft case actively suppressing the "Regular" string didn't make you rethink :(

So will close though this leaves some inconsistency in the behaviour...

@ManoloFLTK
Copy link
Contributor

OK. The last commit removes all " Regular" suffixes from font names for the sake of compatibility with Xft before Pango, even if I believe it's not as clean a way to present font names as with the suffix.

@wcout
Copy link
Contributor Author

wcout commented Jun 6, 2023

Great, thanks!
Change looks good and works.
I believe this sort of consistency will aid to a painless transition from FLKT 1.3 to 1.4.

@wcout wcout closed this as completed Jun 6, 2023
@ManoloFLTK ManoloFLTK added the fixed The issue or PR was fixed. label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed The issue or PR was fixed. Platform: Wayland platform specific (Unix/Wayland) Platform: X11 platform specific (Unix/X11))
Projects
None yet
Development

No branches or pull requests

2 participants