devkitPro / 3ds-hbmenu

The 3DS Homebrew Menu (∩ ͡° ͜ʖ ͡°)⊃━☆゚
725 stars 76 forks source link

Text is too small in CHT devices #35

Closed roytam1 closed 6 years ago

roytam1 commented 6 years ago

CHT devices(Sell officially in Hong Kong and Taiwan) has smaller font size (20x24px) than others (25x30px) for more spaces to contain larger amount characters. (Source: converted bitmap from official cbf_zh-Hant-TW.bcfnt / cbf_std.bcfnt with ctr_FontConverter)

Possible solution to deal with such situation: check width of "あ" with fontGetCharWidthInfo, CHT devices will return smaller value. Since ideograph is square, so normally width == height. (CHECK: does it return "24" in C/J/U/E? and does it return "19" in T?) and then adjust scale factor before print.

Cross-post: https://github.com/BernardoGiordano/PKSM/issues/654 https://github.com/Steveice10/FBI/issues/423

2018-01-08_23-53-39 846_top 2018-01-08_23-53-39 846_bot

fincs commented 6 years ago

Thank you for the report. I'll work on a fix.

I just have a question. Does the "あ" character exist in KOR/TWN system fonts as well? (I doubt so since that's hiragana "a", which is a Japanese character)

roytam1 commented 6 years ago

I just have a question. Does the "あ" character exist in KOR/TWN system fonts as well?

checked and it exists in all variants of default 3DS system font.

fincs commented 6 years ago

Perfect.

fincs commented 6 years ago

I've added some font scaling code, which should fix this problem. I've also realized that the traditional Chinese translation tends to overflow text boundaries, and some characters are missing altogether (with TWN font). If you are able to, could you send a PR fixing these issues?

roytam1 commented 6 years ago

Fix confirmed! Thanks! Font is now bigger! but it seem even bigger than in other devices?

2018-01-14_08-28-58 035_top 2018-01-14_08-28-58 035_bot

roytam1 commented 6 years ago

It seems that baselinePos doesn't work as expected in T machines. While charWidth works as my expectation.

EDIT: maybe use glyphInfo->cellHeight? untested. EDIT2: J/U/E cellHeight=30, cellWidth=24, T cellHeight=20, cellWidth=20 EDIT3: So by ratio, scaling by glyphWidth ratio gives better result.

J/U/E: j_top

T: t_top

roytam1 commented 6 years ago

with modification:

        // Load the glyph texture sheets
        int i;
        TGLP_s* glyphInfo = fontGetGlyphInfo();
+       charWidthInfo_s* cwi = fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(0x3042));
        s_glyphSheets = malloc(sizeof(C3D_Tex)*glyphInfo->nSheets);
-       s_textScale = 25.0f / glyphInfo->baselinePos;
+       s_textScale = 20.0f / (cwi->glyphWidth); // 20 is glyphWidth in J machines
        for (i = 0; i < glyphInfo->nSheets; i ++)
        {
                C3D_Tex* tex = &s_glyphSheets[i];

It shows same size:

J/U/E: j_atop j_bot

T: t_atop t_bot

fincs commented 6 years ago

I've tested your algorithm, and it results in correct font size for TWN and KOR, but small font size for CHN. Do you have any further suggestions?

roytam1 commented 6 years ago

I've tested your algorithm, and it results in correct font size for TWN and KOR, but small font size for CHN. Do you have any further suggestions?

Since I don't own CHN machine, I can't tell. whats inside cwi and glyphInfo struct in CHN machine?

fincs commented 6 years ago

Funnily enough, CHN metrics read: glyphWidth: 20, charWidth: 24 (same as E/U/J font)

EDIT: I've done some measurements:

int idx = fontGlyphIndexFromCodePoint(0x3042);
charWidthInfo_s* info = fontGetCharWidthInfo(idx);
FINF_s* fontInfo = fontGetInfo();
TGLP_s* glyphInfo = fontGetGlyphInfo();
sprintf(buf, "font(%dx%d) glyph(%dx%d) baseline(%d) maxWidth(%d)\ndefault(%d,%d) a(%d,%d)",
    fontInfo->width, fontInfo->height, glyphInfo->cellWidth, glyphInfo->cellHeight, glyphInfo->baselinePos, glyphInfo->maxCharWidth,
    fontInfo->defaultWidth.glyphWidth, fontInfo->defaultWidth.charWidth, info->glyphWidth, info->charWidth);

results in this:

EUR/USA/JPN:

font(25x30) glyph(24x30) baseline(25) maxWidth(24)
default(24,24) a(20,24)

CHN:

font(25x30) glyph(24x26) baseline(21) maxWidth(24)
default(24,24) a(20,24)

KOR:

font(25x30) glyph(24x26) baseline(21) maxWidth(24)
default(24,24) a(18,24)

TWN:

font(20x24) glyph(20x20) baseline(14) maxWidth(19)
default(20,20) a(14,19)
roytam1 commented 6 years ago

Funnily enough, CHN metrics read: glyphWidth: 20, charWidth: 24 (same as E/U/J font)

Then it show be shown as non-preScaled (i.e. like before the commit) And from what I know is that, only TWN machines font have smaller font metrics due to file size limitation.

fincs commented 6 years ago

Looks like I have found a possible sweet spot:

s_textScale = 30.0f / fontGetGlyphInfo()->cellHeight;

Can you confirm this gives desirable results on TWN?

roytam1 commented 6 years ago

s_textScale = 30.0f / fontGetGlyphInfo()->cellHeight; Can you confirm this gives desirable results on TWN?

It is a bit bigger than my mod, but still looks quite well.

t_cw_atop t_cw_bot

fincs commented 6 years ago

I'd say that looks nice as well. I'm commiting the fix. https://github.com/fincs/new-hbmenu/commit/1197d56ea7d3cfa440abbabec7916c708b515238