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

Some CJK characters don't follow the FontChoice option #1271

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

k-takata
Copy link
Contributor

The characters listed here (e.g. "「" (U 300C)) don't follow the FontChoice option:

mintty/src/termout.c

Lines 5224 to 5225 in 78c7d20

// && wcschr(W("〈〉《》「」『』【】〒〓〔〕〖〗〘〙〚〛"), wc)
&& wc >= 0x3008 && wc <= 0x301B && (wc | 1) != 0x3013

Consider the following settings:

Font=Anonymous Pro  # ASCII font
FontChoice=CJK:1
Font1=IPAGothic     # Japanese font

U 300C is a double width CJK character so win_char_width() should return 2 here:

mintty/src/termout.c

Lines 5222 to 5231 in 78c7d20

// Auto-expanded glyphs
if (width == 2
// && wcschr(W("〈〉《》「」『』【】〒〓〔〕〖〗〘〙〚〛"), wc)
&& wc >= 0x3008 && wc <= 0x301B && (wc | 1) != 0x3013
&& win_char_width(wc, term.curs.attr.attr) < 2
// ensure symmetric handling of matching brackets
&& win_char_width(wc ^ 1, term.curs.attr.attr) < 2)
{
term.curs.attr.attr |= TATTR_EXPAND;
}

However, FONTFAM is not set to term.curs.attr.attr at this point, then win_char_width() returns 1 and the TATTR_EXPAND flag is unintentionally set. As the result, U 300C is not shown correctly. (The left half of the glyph of U 300C is expanded.)

FONTFAM should be set before calling win_char_width().

src/termout.c Outdated
Comment on lines 4990 to 4992
uchar cf = scriptfont(wc);
if (cf && cf <= 10 && !(asav & FONTFAM_MASK))
term.curs.attr.attr = asav | ((cattrflags)cf << ATTR_FONTFAM_SHIFT);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If not sure if this is the best place to set FONTFAM, though.)

@k-takata
Copy link
Contributor Author

BTW, should this commented line

// && wcschr(W("〈〉《》「」『』【】〒〓〔〕〖〗〘〙〚〛"), wc)

be as follows (to make it consistent with line 5225)?

            // && wcschr(W("〈〉《》「」『』【】〔〕〖〗〘〙〚〛"), wc)

The characters "〒" and "〓" are not a pair.

@mintty
Copy link
Owner

mintty commented Jun 20, 2024

Thanks for the analysis. Before I try to understand it, let's set up a common test case: I could not reproduce this with a Windows preinstalled CJK font - which of them are actually Japanese?
The primary ("ASCII") font does not matter, I assume.
After downloading IPAGothic, the character does not show up at all with unpatched mintty. With the patch, it displays but is not expanded. I guess that's not what you observed.

@k-takata
Copy link
Contributor Author

I could not reproduce this with a Windows preinstalled CJK font - which of them are actually Japanese?

It can be also reproduced with "MS Gothic".

the character does not show up at all with unpatched mintty.

Yes, it is the same in my side. Because the left half of the "「" glyph is blank. The blank part is expanded and shown as a double-width blank.
You can also test with "」" (U 300D). The left half of this glyph is not blank, so you might be able to see the issue more clearly.

With the patch, it displays but is not expanded.

Yes, it is the expected behavior.

@mintty
Copy link
Owner

mintty commented Jun 20, 2024

(If not sure if this is the best place to set FONTFAM, though.)

scriptfont is called again in write_ucschar so it appears to be a bit redundant (although it does not impose measurable slowdown).
Maybe the whole TATTR_EXPAND check and setting should be moved down into write_ucschar. I'll try that tomorrow.

@mintty mintty changed the title Some CLK characters don't follow the FontChoice option Some CJK characters don't follow the FontChoice option Jun 20, 2024
The characters listed here (e.g. "「" (U 300C)) don't follow the
FontChoice option:
https://github.com/mintty/mintty/blob/78c7d205d586ed87c946b00dc62034ea54c96e7b/src/termout.c#L5224-L5225

Consider the following settings:
```
Font=Anonymous Pro  # ASCII font
FontChoice=CJK:1
Font1=IPAGothic     # Japanese font
```

U 300C is a double width character so `win_char_width()` should return 2
here:
https://github.com/mintty/mintty/blob/78c7d205d586ed87c946b00dc62034ea54c96e7b/src/termout.c#L5222-L5231

However, FONTFAM is not set to `term.curs.attr.attr` at this point, then
`win_char_width()` returns 1 and the `TATTR_EXPAND` flag is
unintentionally set.  As the result, U 300C is not shown correctly. (The
left half of the glyph of U 300C is expanded.)

FONTFAM should be set before calling `win_char_width()`.
@mintty
Copy link
Owner

mintty commented Jun 21, 2024

I'll try that tomorrow.

as attached:
1271.patch

Feel free to convert your PR accordingly.

Import the suggested changes.

Co-authored-by: Thomas Wolff <[email protected]>
@k-takata k-takata force-pushed the fix-cjk-fontchoice branch from cc3e3f8 to 4129d4e Compare June 21, 2024 10:52
@k-takata
Copy link
Contributor Author

Thank you. I've confirmed that your patch works fine.

@mintty mintty merged commit deb9391 into mintty:master Jun 21, 2024
1 check passed
mintty added a commit that referenced this pull request Jun 21, 2024
@k-takata k-takata deleted the fix-cjk-fontchoice branch June 21, 2024 14:08
@mintty
Copy link
Owner

mintty commented Jun 26, 2024

Released 3.7.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants