Menu

#2310 Chinese characters are only properly monospaced when font size is a multiple of 6

Bug
closed-fixed
nobody
5
2022-02-09
2022-01-25
David Yang
No

Using a custom font, variants of sarasa and noto, Chinese characters in Chinese monospaced fonts only line up with letters of the alphabet and other characters when the font size is a multiple of 6. A font where this occurs is attached. Unable to find a font unaffected by this.

Found in and tested from Geany.

gtk4-4.4.1-1.fc35.x86_64
Also installed, gtk3-3.24.31-2.fc35.x86_64
Fedora 35

1 Attachments

Discussion

  • David Yang

    David Yang - 2022-01-25

    Also confirmed on noto variant Noto Sans Mono CJK TC. Also some chinese text, 半角中文對齊, that we were able to produce this bug with.

     
  • David Yang

    David Yang - 2022-01-25

    Issue is still present in ubuntu mono.

    I was a little impatient with my earlier testing, after some more thorough but tedious testing found that it's actually font sizes that are multiples of 3 that are monospaced correctly, not multiples of 6.

     
  • Neil Hodgson

    Neil Hodgson - 2022-01-26
    • labels: monospaced font, internationalization --> monospaced font, internationalization, scintilla, gtk
    • status: open --> open-invalid
     
  • Neil Hodgson

    Neil Hodgson - 2022-01-26

    I don't see this as a Scintilla bug as it is system behaviour shared with, for example, gedit the system "Text Editor" which uses GtkSourceView, not Scintilla.

    With SciTE and "font.base=font:Sarasa Mono Slab SC", for a file containing

    字母
    abcd
    

    Pango (the system library which determines text drawing) returns these character widths at increasing sizes (9,10,11,12):

    MeasureWidths [6] '字母' 12 24
    MeasureWidths [4] 'abcd' 6 12 18 24
    
    MeasureWidths [6] '字母' 13 26
    MeasureWidths [4] 'abcd' 7 14 21 28
    
    MeasureWidths [6] '字母' 15 30
    MeasureWidths [4] 'abcd' 7 14 21 28
    
    MeasureWidths [6] '字母' 16 32
    MeasureWidths [4] 'abcd' 8 16 24 32
    

    (edit: wrong examples; added 9 case and removed 13 case)

    Pango used to return fractional character positions but it appears that no longer occurs on current Linux distributions - also tried Ubuntu 21.10.

     

    Last edit: Neil Hodgson 2022-01-26
  • David Yang

    David Yang - 2022-01-26

    Alright, I'll take this another step up to pango then

     
  • David Yang

    David Yang - 2022-01-27

    Tested, patch resolves the issue, closing and going back down to geany with the fix.

     
  • David Yang

    David Yang - 2022-01-27

    Well, can't find the close button but something in the spirit of it.

     
  • David Yang

    David Yang - 2022-01-28

    Oh, I neglected to ask but probably should, will this patch be incorporated into mainline scintilla, or should Geany patch it in independently? I did attempt to add it when the patch worked, but it failed build because pango is pinned to an older version on guake CI and I wrote it off to being solved by the next scintilla merge.

     
  • David Yang

    David Yang - 2022-01-28

    Oh, nevermind, clicked around to the front page and saw the commit from three hours ago.

     
  • Neil Hodgson

    Neil Hodgson - 2022-01-28
    • status: open-invalid --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2022-01-28

    The [c69263] commit is slightly different from the patch shown earlier. The issue is that, using the commit, positions are slightly less than integer pixels at 9, 12 and other divisible-by-3 points:

    MeasureWidths [6] '字母' 11.999 23.998
    MeasureWidths [4] 'abcd' 5.99902 11.998 17.9971 23.9961
    
    MeasureWidths [6] '字母' 13.332 26.6641
    MeasureWidths [4] 'abcd' 6.66602 13.332 19.998 26.6641
    
    MeasureWidths [6] '字母' 14.666 29.332
    MeasureWidths [4] 'abcd' 7.33301 14.666 21.999 29.332
    
    MeasureWidths [6] '字母' 15.999 31.998
    MeasureWidths [4] 'abcd' 7.99902 15.998 23.9971 31.9961
    

    The earlier patch tweaked the font size up by a single Pango unit which resulted in the 9 point characters being exactly 12.0 or 6.0 pixels wide.

    Switched to Pango calls for calculations with [47d2b7] instead of Scintilla's custom scaling code but that has the same effect.

    It is unlikely there will be much difference with just less than whole pixels but such issues are more likely with very long lines.

     

    Related

    Commit: [47d2b7]
    Commit: [c69263]

  • David Yang

    David Yang - 2022-01-29

    Oh, probably fine, people aren't programming horizontally anyways where they'll use monospace. Some floating point nonsense I presume

     
  • Neil Hodgson

    Neil Hodgson - 2022-02-09
    • status: open-fixed --> closed-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2022-02-09

    The [c69263] commit is slightly different from the patch shown earlier. The issue is that, using the commit, positions are slightly less than integer pixels at 9, 12 and other divisible-by-3 points:

    MeasureWidths [6] '字母' 11.999 23.998
    MeasureWidths [4] 'abcd' 5.99902 11.998 17.9971 23.9961
    
    MeasureWidths [6] '字母' 13.332 26.6641
    MeasureWidths [4] 'abcd' 6.66602 13.332 19.998 26.6641
    
    MeasureWidths [6] '字母' 14.666 29.332
    MeasureWidths [4] 'abcd' 7.33301 14.666 21.999 29.332
    
    MeasureWidths [6] '字母' 15.999 31.998
    MeasureWidths [4] 'abcd' 7.99902 15.998 23.9971 31.9961
    

    The earlier patch tweaked the font size up by a single Pango unit which resulted in the 9 point characters being exactly 12.0 or 6.0 pixels wide.

    Switched to Pango calls for calculations with [47d2b7] in case there was a bug in Scintilla's custom code but that has the same effect.

     

    Related

    Commit: [47d2b7]
    Commit: [c69263]


Log in to post a comment.