Bug 63571 - TextLayout: font substitution support
Summary: TextLayout: font substitution support
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 70322 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-05-23 01:59 EDT by Hiroyuki Okamoto CLA
Modified: 2004-08-25 11:50 EDT (History)
6 users (show)

See Also:


Attachments
Proposed additional fix for font substitution by MSIE MLang (39.95 KB, application/octet-stream)
2004-08-09 10:40 EDT, Hiroyuki Okamoto CLA
no flags Details
TextLayout new version (61.06 KB, text/plain)
2004-08-12 16:37 EDT, Felipe Heidrich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hiroyuki Okamoto CLA 2004-05-23 01:59:10 EDT
On Windows, org.eclipse.swt.graphics.TextLayout should support font 
substitution.
If the user types any text not supported by the current font on StyledText 
which calls TextLayout, the text becomes blank (in Eclipse3.0M9) on Windows. 
For Example, if the user selects "Microsoft Sans Serif" font on Windows, and 
type Japanese text which "Microsoft Sans Serif" font does not contain, then 
notepad.exe still can display Japanese text. It is because notepad.exe supports 
font substitution and finds Japanese "MS Gothic" or something like that. (maybe 
because notepad.exe may simply call TextOutW(), though.)
Since StyledText/TextLayout is implemented by Uniscribe, TextLayout should 
support font substitution.
Comment 1 Felipe Heidrich CLA 2004-05-26 11:36:27 EDT
TextLayout does perform font substitution.

BTW, do you know how/if Uniscribe has any support to help the application to 
implement font substitution ? The only think I found is the HRESULT with the 
SCRIPT_NOT_IN_FONT when the ScriptShape fails. The hard part is how to select a 
different font, and for doing this I didn't find any help on the MSDN.
Comment 2 Felipe Heidrich CLA 2004-05-26 11:37:33 EDT
If you have a case where font substitution doesn't work please let me wich font 
and wich text (in Unicode) I should use to reproduce the problem.
Comment 3 Hiroyuki Okamoto CLA 2004-06-29 23:49:20 EDT
Sorry I did not reply for a long time...

I was checking the code in Eclipse3.0M8 when I wrote this report. 
At that time there was no implementation for the font substitution in 
TextLayout class in Eclipse3.0M8
Nice to see the font substitution code in Eclipse3.0!

Currently I still have the problem on Eclipse3.0. 
I cannot display Japanese Hiragana character in my environment, when I select 
Tahoma. 
This is because EnumFontFamilyEx picks up "IBMLogo" (Type1) font and the 
Hiragana characters are defined as blank characters in "IBMLogo" font...
Basically EnumFontFamilyEx picks up any font which TextLayout finds at first.
This causes the user see the strange font by accident.
It would be nice if TextLayout picked up the user's preferrable font according 
to the locale.
(MS UI Gothic in Japanese, SimSun in Chinese, Gulim in Korean so on)

So to do this,
I think, maybe, we can use IMLangFontLink or IMLangFontLink2 in MLang:

http://msdn.microsoft.com/workshop/misc/mlang/tutorials/fontlinking.asp

then TextLayout can get the substitute font, without checking the fontlink 
entry directly in:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows 
NT\CurrentVersion\FontLink\SystemLink

What do you think ?
Comment 4 Steven Wasleski CLA 2004-08-06 18:53:28 EDT
Sounds like this should be reopened.
Comment 5 Hiroyuki Okamoto CLA 2004-08-09 10:40:40 EDT
Created attachment 13820 [details]
Proposed additional fix for font substitution by MSIE MLang

This is my proposal to provide additional font substitution code by MLang
included in MSIE. This fix will substitute better fonts, such as  MS PGothic
for Japanese, Gulim for Korean Hungle, when Tahoma is set on TextLayout.
Regarding MLang, please see
http://msdn.microsoft.com/workshop/misc/mlang/mlang.asp
This fix is based on Eclipse3.0GA code.
Comment 6 Felipe Heidrich CLA 2004-08-09 13:56:24 EDT
Hiroyuki Okamoto:
Do you have a T-Chinese machine available for testing ? Pls, see bug62435.
Comment 7 Hiroyuki Okamoto CLA 2004-08-09 16:28:46 EDT
I don't have Traditional Chinese localized version of Windows, 
but I tried my fix after swithcing the *system* language to Chinese(Taiwan) in 
English WinXP.
Basically MLang did not pick up PMingLiU in Chinese (Taiwan) locale.

when TextLayout class displays some Han character such as in CJK Unified 
Ideographs,
Seems MLang tries to assign Japanese "MS PGothic" first, then Chinese 
Simplified "SimSun" or Korean "Gulim" even in Chinese Taiwan locale... 
(Actually it does not seem different order from fontlink entry in Registry...)
Comment 8 Hiroyuki Okamoto CLA 2004-08-09 16:31:15 EDT
Sorry.
I did not mean:
(Actually it does not seem different order from fontlink entry in Registry...)
I meant:
(Actually it seems different order from fontlink entry in Registry...)

Comment 9 Mike Wilson CLA 2004-08-10 13:15:44 EDT
Currently being investigated. SN to decide if fix is too scary for R3.0.1.
Comment 10 Felipe Heidrich CLA 2004-08-10 15:16:05 EDT
Hiroyuki Okamoto:
- It fail cause your machine is not a 'real' t-chinese machine, the only way 
to be sure is running on the real machine.

- Question about the patch (I'm not familiar with MLang)
a) Why do you need mLangFontLink2 and mLangFontLink. During my tests they 
returned always the same results. Having both just makes the code complex.
From the doc I think the only advantage of mLangFontLink2 is that you can call 
MapFont() passing the char array instead of the codepage set, saving the call 
to GetStrCodePages. In our code you always call GetStrCodePages anyway.
b) Why do you need to release the font and the font cache after shape ? Looks 
wrong cause the font is still in use. Wouldn't be safer to delete the font 
when the run is disposed ? Wouldn't be better to removed the SWT cache and use 
the MLang cache instead ? I tested performance of MLang I think it needs any 
addition cache. The SWT cache that is there is because our implementation of 
font substitution is too slow.

Maybe it would be good to have a phone call to discuss the code, sometime 
problem report is not good for that.
Comment 11 Felipe Heidrich CLA 2004-08-10 15:17:11 EDT
Probably a good idea to have VI checking all the OLE/COM code before releasing 
any code.
Comment 12 Felipe Heidrich CLA 2004-08-12 11:28:15 EDT
Hiroyuki: would you know if your patch also fixes Bug63793 ?
Comment 13 Hiroyuki Okamoto CLA 2004-08-12 13:01:22 EDT
I tried https://bugs.eclipse.org/bugs/attachment.cgi?id=11190&action=view 
in Bug63793 with my patch + Felipe's modification. 
Seems like, the characters in pr63793-MS932.txt and pr63793-utf8.txt are 
displayed correctly at first...
but when I scroll the text, some characters change to whitebox characters.

I also see the similar problem on StyledText sample in SWT Custom Controls 
plugin. when I type some characters not included in Tahoma, then BackSpace some 
characters, then some of characters change to whitebox sometimes...

My evironmet is WinXP English
Changed system language to Japanese, User language to Japanese.
Comment 14 Hiroyuki Okamoto CLA 2004-08-12 15:46:14 EDT
Another additional idea is to call GetStockObject(DEFAULT_GUI_FONT) and shape
(), the first time shape() fails, before trying MLang font substitution. 
I tested GetStockObject(DEFAULT_GUI_FONT) on Korean localized Win2000, then 
GetStockObject(DEFAULT_GUI_FONT) returned Gulim.
so I expect GetStockObject(DEFAULT_GUI_FONT) should return PMingLiU on  
Taiwanese localized Windows. This may fix bug62435.
Comment 15 Felipe Heidrich CLA 2004-08-12 16:37:04 EDT
Created attachment 13929 [details]
TextLayout new version

This version of TextLayout replaces the one inside the zipfile attached by
Hiroyuki. It contains some important bug fixes.
Fuse-san: use this to test bug 63793.
Comment 16 Felipe Heidrich CLA 2004-08-13 13:43:13 EDT
fixed > 20040813 in HEAD
Comment 17 Felipe Heidrich CLA 2004-08-13 13:43:54 EDT
Hiroyuki: I had to change the code cause in graphics we can not have 
references to OLE.
Comment 18 Steven Wasleski CLA 2004-08-18 17:29:46 EDT
To follow up on comment #9, will this also be fixed in 3.0.1?
Comment 19 Felipe Heidrich CLA 2004-08-19 11:31:11 EDT
No - We think the code is too risk to be backported into 3.0.1. The fix 
invalidades the TVT testing that was performed before 3.0.
Comment 20 Grant Gayed CLA 2004-08-25 11:50:38 EDT
*** Bug 70322 has been marked as a duplicate of this bug. ***