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

Wrong letter space after patching Korean font #522

Closed
dhnam opened this issue Sep 3, 2020 · 19 comments · Fixed by #1167
Closed

Wrong letter space after patching Korean font #522

dhnam opened this issue Sep 3, 2020 · 19 comments · Fixed by #1167

Comments

@dhnam
Copy link

dhnam commented Sep 3, 2020

🎯 Subject of the issue

Patched D2Coding font with patcher in Windows 10.
When patched, letter space of Korean charactors are getting weird.
Screenshot is attached in 'optional'.

🔧 Your Setup

  • Using D2Coding with patcher.
  • Now using window CMD, but it is not about patched letters.
  • Now using Windows 10, and Nerd Fonts ver. 2.1.0.

★ Optional

d2-before
This is what originally looks like;
d2-after
This is how it looks like after patch.
And if I patch it in single-width, it looks like:
d2-mono

Not sure it is same with other fullwidth characters(like Chinese or Japanese).

@dhnam
Copy link
Author

dhnam commented Sep 4, 2020

Looks like it is own problem of FontForge.
I opened ttf file of D2Coding and directly made font out of it, and it gave me same problem.

@Finii
Copy link
Collaborator

Finii commented Feb 21, 2023

Maybe this can be solved by patching with --variable-width-glyphs.
But the patched font then does probably not work in 'all' terminals anymore.

Closing this now. If you still have problems, reopen. I would need a link to the problematic font for testing in that case.

@Finii Finii closed this as completed Feb 21, 2023
@kimwonj77
Copy link

I have same issue. With same font, both with/without --variable-width-glyphs, both mono and non-mono.
Original font is on https://github.com/naver/d2codingfont/releases/tag/VER1.3.2
Patched font is without --variable-width-glyphs and with --variable-width-glyphs

Build script is here: https://github.com/kimwonj77/d2coding-nerdfonts/blob/master/build.sh

Also, I'm not a original author of this issue. So I ping you, @Finii. Sorry about this.

@Finii Finii reopened this Apr 10, 2023
@Finii
Copy link
Collaborator

Finii commented Apr 10, 2023

@kimwonj77 Can you show an image were I can see the problem?
If it contains Korean text it would be good to have the text also as text in the comment so that I can try it out.

@dhnam
Copy link
Author

dhnam commented Apr 10, 2023

Original author here.

As far as I remember (It has been three years since I found this issue) it was problem of D2Coding font.

As said I exported D2Coding directly from FontForge, but not only that, but I also tried doing same thing with FontLab and python library (as far as remember, as said), and same thing happened.

(I also uploaded same issue at naver/d2codingfont#84 too, which shows attempt to open and re-export the font cause total breakdown of what is written in Korean.)

Never tested with other Korean-based font, but guess it won't break with other fonts. (Guess it's worth try.)

Guess it's better ping @kimwonj77 . Sorry if this bothered you.

@kimwonj77
Copy link

First, It's same as original author's image. 다람쥐 헌 쳇바퀴에 타고파.

ApplicationFrameHost_VKgjpl39zp
mono on windows 11 settings.

ApplicationFrameHost_Jai9iucMXz
double width on windows 11 settings. but...

Notepad_mb12W9fgo8
it's still broken on notepad.

@Finii
Copy link
Collaborator

Finii commented Apr 11, 2023

Thank you. I believe I see the problem now. Trying to fix...

@Finii
Copy link
Collaborator

Finii commented Apr 11, 2023

다람쥐 헌 쳇바퀴에 타고파 = b2e4 b78c c950 20 d5cc 20 ccc7 bc14 d034 c5d0 20 d0c0 ace0 d30c

Choose for research

image

Looks ok, width is maintained.

Hmm, testing in tilix

image

Looks ok. Maybe it is a Windows problem. (Comment will be continued on Windows box)

@Finii
Copy link
Collaborator

Finii commented Apr 11, 2023

Looks ok in windows (so far)

grafik

Windows Terminal

grafik

grafik

Looks good.

Ah, you use notepad, lets see

grafik

Ah!

grafik

Looks good in writer...

So this is a wordpad notepad problem?

Edit: Mixed note- and wordpad 🙄

@Finii
Copy link
Collaborator

Finii commented Apr 11, 2023

Original font looks good in notepad

grafik

@kimwonj77
Copy link

It's bit difficult to explain, But seem like the rendering method of notepad, and some other programs are using old-school character render system. and it causes the issue. (And also, it only happens on korean character. not english.)

It's also same on fontview.exe with korean locale (fontview.exe' is locked by windows locale.). Like og author's image.

Also Eclipse
image

@Finii
Copy link
Collaborator

Finii commented Apr 12, 2023

I found the problem.

The issue is with the OS/2 xAvgCharWidth data in the font.
(OS/2 is the name of one data table within a open type font (for example .ttf))

  • For OS/2 version 0 to 2 the number is the average width of the lowercase latin letters (weighted) [1][2]
  • For OS/2 version 3+ it is the average width of all glyphs

Unfortunately there are multiple bugs here in parallel so I do not really know how to proceed here.

  • notepad determines the advance width from xAvgCharWidth and uses double that value for Korean glyphs (2 cell width) regardless of OS/2 version 😞
  • The D2Coding font says it has an OS/2 version 3 (!) table but fills the number as version 2 would (probably to circumvent the notepad bug 🙄
  • fontforge always fills the version 3+ number, even if instructed to create the font with a version 2 OS/2 table 😠

Possible actions

  • Fix fontforge's OS/2 table version 0-2 (will not help because font says it uses version 3)
  • Add option to font-patcher to create version 2 xAvgCharWidth table entry
  • Add special rule in font-patcher to specific font name to create for this font only a version 2 xAvgCharWidth

I do not really like to add options to font-patcher if it can be avoided.

Are there other - possibly Korean - fonts affected or is that only D2Coding?

[1] https://learn.microsoft.com/en-us/typography/opentype/spec/os2#xavgcharwidth
[2] https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html


Fix snippet

diff --git a/font-patcher b/font-patcher
index 01e144e4c..a82e6f8c5 100755
--- a/font-patcher
+++ b/font-patcher
@@ -135,6 +135,7 @@ class TableHEADWriter:
             positions = {'checksumAdjustment': 2+2+4,
                          'flags': 2+2+4+4+4,
                          'lowestRecPPEM': 2+2+4+4+4+2+2+8+8+2+2+2+2+2,
+                         'avgWidth': 2,
                 }
             where = self.tab_offset + positions[where]
         self.f.seek(where)
@@ -421,6 +422,10 @@ class font_patcher:
                 for idx in range(source_font.num_fonts):
                     if not self.args.quiet:
                         print("{}: Tweaking {}/{}".format(projectName, idx + 1, source_font.num_fonts))
+                    source_font.find_table([b'OS/2'], idx)
+                    dest_font.find_table([b'OS/2'], idx)
+                    dest_font.putshort(source_font.getshort('avgWidth'), 'avgWidth')
+                    dest_font.reset_table_checksum()
                     source_font.find_head_table(idx)
                     dest_font.find_head_table(idx)
                     if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:

This does not calculate the version 2 number but just copies over the value from the source font. Which would be ok if we just want to fix D2Coding I guess. The code is minimal, just what I used to prove that this is the issue's cause.

Edit: Typo fix

@Finii
Copy link
Collaborator

Finii commented Apr 12, 2023

Even Glyphs3 does not allow to produce notepad compatible fonts...

https://forum.glyphsapp.com/t/font-custom-parameters/1174

@kimwonj77
Copy link

kimwonj77 commented Apr 12, 2023

Maybe the Nanum-font series has this problem too. (D2Coding is one of them). But I'm not tested.
https://hangeul.naver.com/font/nanum - All "Nanum" series fonts (for basic usage.) (in Korean)
https://github.com/naver/nanumfont - "Nanum Gothic Coding", an old version of D2 coding.

Finii added a commit that referenced this issue Apr 12, 2023
[why]
Some old applications seem to depend on obsolete xAvgCharWidth values to
show two-cell glyphs correctly. Fontforge can only generate OS/2 tables
version 4, but these applications need 2 or less. In fact they seem to
not look up the version number, but rely on the value being like it
always has been ;-)

One example is Windows notepad, that takes the xAvgCharWidth as base for
the cell size and draws the two-cell chars in a cell twice that size -
without any regard to glyph width.

[how]
These issue seems to be encountered rather seldom and only with some
obscure (grin) applications. There is also no good way to handle this
automatically. So we add a command line option that allows the user to
tweak the value after patched-font generation.

The option is called `--xavgcharwidth`:
* If not specified the behavior of the patcher does not change
* If just given the xAvgCharWidth is copied over from the source
* If a number is added that number is used as xAvgCharWidth
* If the number added is zero we will calculate the old style xAvgCharWidth

Fixes: #522

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii
Copy link
Collaborator

Finii commented Apr 12, 2023

If you use font-patcher in-parens-version 3.7.0 or later you can now add --xavgcharwidth to copy the value and create a font usable in notepad:

image


For your (@kimwonj77) project:
If you specify --complete you do not need to add all these specific glyphs sets, so it would be sufficient to

--complete --makegroups --xavgcharwidth --also-windows --careful --no-progressbars

Finii added a commit that referenced this issue Apr 12, 2023
[why]
Some old applications seem to depend on obsolete xAvgCharWidth values to
show two-cell glyphs correctly. Fontforge can only generate OS/2 tables
version 4, but these applications need 2 or less. In fact they seem to
not look up the version number, but rely on the value being like it
always has been ;-)

One example is Windows notepad, that takes the xAvgCharWidth as base for
the cell size and draws the two-cell chars in a cell twice that size -
without any regard to glyph width.

[how]
These issue seems to be encountered rather seldom and only with some
obscure (grin) applications. There is also no good way to handle this
automatically. So we add a command line option that allows the user to
tweak the value after patched-font generation.

The option is called `--xavgcharwidth`:
* If not specified the behavior of the patcher does not change
* If just given the xAvgCharWidth is copied over from the source
* If a number is added that number is used as xAvgCharWidth
* If the number added is zero we will calculate the old style xAvgCharWidth

Fixes: #522

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@kimwonj77
Copy link

Thank you for response! Now I can be happy with Korean font! D2Coding is (if I remember correctly) one and only Korean-Code font since the release...

Also, thank you for reviewing my script! I added it for test just in case.

@dhnam
Copy link
Author

dhnam commented Apr 13, 2023

Never expected this issue to be corrected! I just gave up using D2Coding patched with nerd font. But looks like I also can be happy with Korean font!

Huge thanks to both of you, Finni and Kimwonj77!

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a new issue, complete the issue template with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2023
LNKLEO pushed a commit to LNKLEO/Nerd that referenced this issue Nov 24, 2023
[why]
Some old applications seem to depend on obsolete xAvgCharWidth values to
show two-cell glyphs correctly. Fontforge can only generate OS/2 tables
version 4, but these applications need 2 or less. In fact they seem to
not look up the version number, but rely on the value being like it
always has been ;-)

One example is Windows notepad, that takes the xAvgCharWidth as base for
the cell size and draws the two-cell chars in a cell twice that size -
without any regard to glyph width.

[how]
These issue seems to be encountered rather seldom and only with some
obscure (grin) applications. There is also no good way to handle this
automatically. So we add a command line option that allows the user to
tweak the value after patched-font generation.

The option is called `--xavgcharwidth`:
* If not specified the behavior of the patcher does not change
* If just given the xAvgCharWidth is copied over from the source
* If a number is added that number is used as xAvgCharWidth
* If the number added is zero we will calculate the old style xAvgCharWidth

Fixes: ryanoasis#522

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants