RealyUniqueName / StablexUI

UI engine for Haxe OpenFL designed to give as much freedom as possible in customizing UI
http://ui.stablex.ru/doc
Other
337 stars 80 forks source link

Chinese characters are not correctly processed #17

Closed rockswang closed 11 years ago

rockswang commented 11 years ago

Hi, I've just tried to put some Chinese characters in a ui xml, e.g. as the button text, however they are not correctly displayed in the final ui (on both flash & windows targets). I then opened "saveCodeTo" and checked generated haxe source and found that the Chinese characters are good there with UTF-8 encoding. So it looks the most suspicious place might be Context.parseInlineString(), it's probably not handling UTF-8 encoded string correctly like the haxe compiler does.

RealyUniqueName commented 11 years ago

That's strange. Cyrillic UTF8 characters processed correctly. Could you provide example xml?

rockswang commented 11 years ago

Please download it here: https://github.com/rs2013/wp1301/blob/master/upload/stablexui_genCode_.zip?raw=true It's based on demo/ui/main.xml, and ui_index_xml.hx is the saved haxe source. BTW, I have to made some change on UIBuilder.hx to make the function "saveCodeTo" works, it seems in Windows, FileSystem does not treat a slash-ended string as a valid directory path: var endSlash : EReg = ~/(\/|)$/; if( !endSlash.match(dir) ){ //dir += '/'; } if( !FileSystem.exists(dir) || !FileSystem.isDirectory(dir) ){ Err.trigger('Path does not exist or is not a directory: ' + dir); } UIBuilder._generatedCodeDir = dir + '/';

rockswang commented 11 years ago

Hi, I've just got some progress on this, it's because the embeded asset font "ui/android/fonts/regular.ttf" does not contains Chinese characters. So, here come two solutions:

  1. replace regular.ttf with a Chinese ture-type font file, this works in all targets (I believe), the disadvantage is the Chinese font file are always very huge (~10M) in comparison to English one (~0.5M), and the compiling of flash target becomes very slow (is it because of the nme installer doing some sorts of preprocessing on font file?)
  2. remove the default font definations in ui/android/defaults.xml, so that I expect the system default font will be used. i.e.: // format-font = "$Assets.getFont('ui/android/fonts/regular.ttf').fontName" // label-embedFonts = "true" However this only works in flash target, on Windows I got some squres at where Chinese characters should be.
RealyUniqueName commented 11 years ago

Are you compiling to neko target? On neko 1.8.2 cyrillic characters are shown as rectangles too, while targeting cpp works fine.

RealyUniqueName commented 11 years ago

As for regular.ttf in android demo, i took this font from android web site. It was bundled with android theme psd. I don't know whether NME does any fonts preprocessing for flash target, but i know it does for html5.

rockswang commented 11 years ago

Hi, Eventually I found the third solution, it's not perfect but works for my very object.

  1. Make changes in defaults.xml, replace: format-font = "$Assets.getFont('ui/android/fonts/regular.ttf').fontName" -> format-font = "$Main.fontName()" remove: label-embedFonts = "true"
  2. Then add a static method in Main.hx, if it's possible using conditional compiling in ui-xml's, maybe this can be merged to xml as well: public static function fontName() : String { return #if android '/system/fonts/DroidSansFallback.ttf' #elseif windows 'C:/WINDOWS/Fonts/MSYH.TTF' #else null #end; } This solution does not need embedding huge Chinese font file into app package, and works for flash, android & windows. In windows, the hardcoded font path are not always correct, but it meets my purpose since I just use windows as quick tests.
RealyUniqueName commented 11 years ago

Yes, you can use conditional compilation in xml. You need to typ # twice:

if adnroid

elseif windows

end