Skip to content

gedit-pango.c: Quote font-family CSS string

lxylxy123456 requested to merge lxylxy123456/gedit:courier10pitch into master

Currently the css string generated by gedit_pango_font_description_to_css() does not quote the font-family string. If the font family name contains space, gtk may fail to parse the css string correctly (e.g. "Courier 10 Pitch").

To fix this issue, simly add double quotes to the font name. This fix should work for font names that do not contain special character (e.g. quotation marks, backslashes, etc.)

See also the discussion in https://discourse.gnome.org/t/gedit-cannot-use-courier-10-pitch/6362/3

For example, the original CSS string is (the first line only):

textview { font-family: Courier 10 Pitch; font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 16pt;  }
---------------------------------------------------
0         1         2         3         4         5
012345678901234567890123456789012345678901234567890

The warning message printed by gtk to the terminal is:

Theme parsing error: <data>:1:32: Junk at end of value for font-family

After the fix, the CSS string will be:

textview { font-family: "Courier 10 Pitch"; font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 16pt;  }

I tested on Fedora 34, built gedit with Builder. Courier 10 Pitch can be displayed correctly.

Closes #435 (closed)

Edited by lxylxy123456

Merge request reports