dk / Prima

prima.eu.org
Other
106 stars 27 forks source link

East Asian languages appear incorrectly in some widgets #82

Closed hbasrc closed 1 year ago

hbasrc commented 1 year ago

OS: Win7 perl: v5.16.3 MSWin32-x86-multi-thread

Since v1.59, east Asian languages appear incorrectly in some widgets, such as Chinese

2023-02-19_172515

dk commented 1 year ago

Hi,

I'd gladly help but I'm afraid I need help - I cannot for the life of me reproduce chinese months in the calendar, either broken or not. The code that does it boils down to this:

perl -MPOSIX=strftime -le "print strftime(q(%B),0,0,0,1,1,0)"

where no matter I try (I've set chinese as default language, console etc, and my console mode is 936), I still get this line printing "February".

So I should very much like to know what's your setup here.

Also, you're mentioning "other widgets" behaving badly - how do I reproduce these problems?

It looks that at least month names are stripped of a utf8 flag, and that could very much be true for result of strftime - but what about the other widgets?

dk commented 1 year ago

(meanwhile you're welcome to check the latest snaphot and see if it works for you)

hbasrc commented 1 year ago

Hi Dimity, Here is some debug info...

$> perl -MPOSIX=strftime -le "print strftime(q(%B),0,0,0,1,1,0)" 二月 $> perl -MPOSIX=strftime -le "print strftime(q(%a),localtime)" 周一

$cal = $w-> insert( Calendar =>
    ...
);

p $cal;
p $cal->make_months, as => 'make_months =';

output: Prima::Calendar { Parents Prima::Widget public methods (32) : can_use_locale, date, date_as_string, date_from_time, day, Day_Enter, Day_FontChanged, Day_KeyDown, Day_Leave, Day_MouseDown, Day_MouseLeave, Day_MouseMove, Day_MouseUp, Day_MouseWheel, day_of_week, Day_Paint, day_reset, Day_Size, day2xy, firstDayOfWeek, init, make_months, month, Month_Change, month2str, profile_check_in, profile_default, reset_days, useLocale, xy2day, year, Year_Change private methods (0) internals: { CMATE 54997916, date [ [0] 20, [1] 1, [2] 123 ], day 0, days [ [0] "周日", [1] "周一", [2] "周二", [3] "周三", [4] "周四", [5] "周五", [6] "周六" ], firstDayOfWeek 0, month 0, useLocale 1, year 0 } } make_months = \ [ [0] "一月", [1] "二月", [2] "三月", [3] "四月", [4] "五月", [5] "六月", [6] "七月", [7] "八月", [8] "九月", [9] "十月", [10] "十一月", [11] "十二月" ]

From above output, it can be seen that there is no problem with the date data obtained. It should be that Prima did not convert the character encoding.

Other problem is that the Prima::Edit widget cannot input Chinese, but InputLine can

hbasrc commented 1 year ago

Hi Dimity,

I tested the latest snaphot, and the Chinese in the Calendar widget has been displayed normally. Thank you very much for your fast answera nd commit.

02-20_084336

PS: Can the font of widgets be preset as the default GUI font of the system?

In addition, when compiling on my platform since Prima v1.61, the following error is reported,

win32\files.c: In function 'win32_set_errno': win32\files.c:974:25: error: 'EDQUOT' undeclared (first use in this function) 974 | errno = EDQUOT; | ^~ win32\files.c:974:25: note: each undeclared identifier is reported only once for each function it appears in dmake: Error code 129, while making 'win32\files.o'

I just simply add the following lines to the win32\files.c file to solve the problem, not necessarily correct.

#define WSAEDQUOT                        10069L
#define EDQUOT                  WSAEDQUOT
dk commented 1 year ago

yes, both of these should be fixed now, please check

dk commented 1 year ago

Also, I"m not sure I understand this: "Can the font of widgets be preset as the default GUI font of the system?" -- could you possibly rephrase and/or describe a use case?

hbasrc commented 1 year ago

The Chinese font in the native Windows GUI should be the default value set by the system theme, such as "Microsoft YaHei" (微软雅黑) on my box.

However, the current font used by Prima does not follow the system settings, It looks like it used a font called Fangsong(仿宋).

dk commented 1 year ago

Ah okay got it thank you. But now I again have a problem - either I"m stupid, or there's no such thing as default font on windows 7. F ex following this article https://www.wikihow.com/Change-the-Default-Font-on-Windows-7 I can change fonts on message boxes, menus, title bars etc but NOT in the window interior. Could you possibly tell me how do you know that the default font on your installation is ms yahei??

dk commented 1 year ago

possibly related - Prima uses its own algorithm for font substitution, so when there is a situation that a particular font doesn't have a glyph needed, Prima scans the available fonts, and in case on win32, in random order. Now I just changed that algorithm a bit that the priority of user-selected message,caption,menu fonts (but again, NOT window font!) is bumped up, and if f ex your setup has ms yahei as one of these, chances are that the substitution will use it and not some other font. As usual, please check the snapshot and see if it changes anything on your setup (and if not, I'll need to ask you to add #define _DEBUG in the start of class/Drawable/mapper.c and see if Prima will produce messages such as "add polyfont Fangsong for chr(4e00)", - that's the substitution at heart.

hbasrc commented 1 year ago

Hi Dimity,

I also couldn't find the font settings in the window interior, Only the following font options are found in the registry.

HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
"CaptionFont"=
"IconFont"=
"MenuFont"=
"MessageFont"=
"SmCaptionFont"=
"StatusFont"=

Prima chose to inherit one of the above font options, which I think works. Thank you very much.

dk commented 1 year ago

Exactly, yes - no window font there either. To my best knowledge, the default font for windows is just "Segoe UI" whatever that is internally mapped to, hardcoded. But since segoe*.ttf don't have Chinese block, these are mapped to some other font, and which exactly font that is, can be quite challenging to find - although I agree, google says that it is Ms Yahei.

So now I'm thinking, since there's no way you can select the window font, I can just hardcode Ms Yahei as a priority for the Chinese substitution block, can be done. But now the big question for you - would you think this would be a reasonable behavior for an average Chinese windows user?

dk commented 1 year ago

Here's a patch to test - it prioritizes 微软雅黑 if found. Is this better that way?

yahei.patch

hbasrc commented 1 year ago

Hardcoding to find 'ms Yahei' is unnecessary, It's not universal, which is not useful for other non-latin language users. lol The current approach is acceptable.

$>perl -Mblib examples\calendar.pl window_font Segoe UI menu_font 微软雅黑 msg_font 微软雅黑 cap_font 微软雅黑 add polyfont Segoe UI for chr(4d) add polyfont 微软雅黑 for chr(4e00)

3

dk commented 1 year ago

Great! Should we close it then?

hbasrc commented 1 year ago

another question

Under the default behavior of Prima::Edit, the Del/Back key cannot delete line break See screenshot: gif

dk commented 1 year ago

oh yeah this is a stupid bug -- thank you very much for pointing it out! fixed now

hbasrc commented 1 year ago

It all works fine now, Thanks again for your contribution.