Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341958 - Arabic: SWT (version 3.659) ignores the font set over style ranges
Summary: Arabic: SWT (version 3.659) ignores the font set over style ranges
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-05 15:22 EDT by Irina CLA
Modified: 2011-04-28 11:04 EDT (History)
2 users (show)

See Also:


Attachments
Snippet (4.10 KB, text/plain)
2011-04-05 15:25 EDT, Irina CLA
no flags Details
Picture (16.53 KB, image/png)
2011-04-05 15:49 EDT, Irina CLA
no flags Details
UnicodeBMPFallback51 (510.17 KB, application/x-zip-compressed)
2011-04-06 11:33 EDT, Irina CLA
no flags Details
SWT 3.7M6; incorrect behaviour verified (12.46 KB, image/png)
2011-04-07 04:14 EDT, Andre Saibel CLA
no flags Details
patch (1.89 KB, patch)
2011-04-11 11:46 EDT, Felipe Heidrich CLA
no flags Details | Diff
Test with Nightly Build N20110411-2000 (6.01 KB, image/png)
2011-04-12 05:15 EDT, Irina CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Irina CLA 2011-04-05 15:22:26 EDT
Build Identifier: M20110210-1200

By every other word written in arabic letters, SWT ignores the fallback font I set over the style ranges to display the not ASCII-characters in a styled text, when the font used by widget doesn't contain the arabic glyphs. 

Reproducible: Always
Comment 1 Irina CLA 2011-04-05 15:25:11 EDT
Created attachment 192591 [details]
Snippet
Comment 2 Irina CLA 2011-04-05 15:49:16 EDT
Created attachment 192594 [details]
Picture

A snapshot of application, which consists of two StyledText-Widgets with fonts, whose names and properties are shown in the labels above them.
Comment 3 Irina CLA 2011-04-06 00:25:44 EDT
The behaviour occurs on Windows XP too, wenn LEFT_TO_RIGHT style is set.
Comment 4 Andre Saibel CLA 2011-04-06 06:14:41 EDT
When the font info lines are removed in the snippet, the behaviour is fixed.
For me it seems to be setFont() that corrupts the internal state in any way(?)

It also seems to be not only a Windows 7 problem: on my WinXP machine it's also currupt. I'm curious how it behaves on Linux.
Comment 5 Felipe Heidrich CLA 2011-04-06 10:22:41 EDT
I do not have this fonts/UnicodeBMPFallback51.ttf font, but it works for me using a different font.
Comment 6 Irina CLA 2011-04-06 11:33:04 EDT
Created attachment 192656 [details]
UnicodeBMPFallback51

Please find attached the missing font.
Comment 7 Felipe Heidrich CLA 2011-04-06 12:13:57 EDT
works for me on Windows 7 running SWT from HEAD:
http://www.eclipse.org/swt/cvs.php
Comment 8 Andre Saibel CLA 2011-04-07 04:14:18 EDT
Created attachment 192701 [details]
SWT 3.7M6; incorrect behaviour verified

@ Felipe: for me - beeing beyond a firewall - it's a little difficult to use the CVS. But I tried it with the latest 3.7 Stream Stable Build (see the shell text in the attached snapshot). 
On my XP machine it doesn't work, when I type in an "a" and a space.. alternating.

@Irina: thank you for the font. I tried something similar some time ago.. and failed ;(
Comment 9 Irina CLA 2011-04-08 05:22:59 EDT
For the same reason I cannot use the SWT out of CVS too. So I've changed to the SWT 3.7M6 and it still doesn't work. While debugging, I can see that in the method computeRuns() the TextLayout uses a fallback font to shape the arabic letters and takes no notice of the font I set in its style range, if the previous whitespace couldn't be shaped.
Comment 10 Felipe Heidrich CLA 2011-04-11 11:32:10 EDT
I can reproduce the problem, working on the fix.
Comment 11 Felipe Heidrich CLA 2011-04-11 11:41:20 EDT
Simplified test case:

public static void main(String[] args) {
	Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.RIGHT_TO_LEFT);
	final Font f1 = new Font(display, "Verdana", 14, SWT.NORMAL); 
	display.loadFont("JavaCode\\UnicodeBMPFallback51.ttf");
	FontData[] fd = display.getFontList("Unicode BMP Fallback SIL", true);
	System.out.println("loaded " + fd[0]);
	fd[0].setStyle(SWT.BOLD);
	fd[0].setHeight(13);
	final Font f2 = new Font(display, fd[0]);

	shell.addListener(SWT.Paint, new Listener() {
		public void handleEvent(Event e) {
			TextLayout layout = new TextLayout(display);
			layout.setOrientation(e.gc.getStyle());
			layout.setFont(f1);
			layout.setText(" \u0634");
			TextStyle style = new TextStyle();
			style.font = f2;
			layout.setStyle(style, 1, 1);
			layout.draw(e.gc, 10, 10);
			layout.dispose();
		}
	});

	shell.open();

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.dispose();
}
Comment 12 Felipe Heidrich CLA 2011-04-11 11:46:40 EDT
Created attachment 192942 [details]
patch

this bug was introduced by the fix for Bug 272075 & bug 239556
Comment 13 Felipe Heidrich CLA 2011-04-11 11:50:37 EDT
Fixed in HEAD
Note the behaviour is different when Verdana and Tahoma are used.
Verdana can't be used to draw whitespaces in Arabic, so the fallback font of the next run is used.
Comment 14 Irina CLA 2011-04-12 05:15:10 EDT
Created attachment 193015 [details]
Test with Nightly Build N20110411-2000

Using Nightly Build N20110411-2000 of SWT I see, that the font the application sets using style ranges to draw invalid letters is used by SWT to draw the whitespaces too.

Is it impossible to use the system font as a fallback for the letters, that cannot be shaped by the font of the widget and have no alternative font set using a style range? I mean, the font the application sets using style ranges for the invalid letters is not intended to be a fallback font for the other letters. 

Apart from that, could you please explain to me, why Verdana can't be used to draw whitespaces in Arabic?
Comment 15 Irina CLA 2011-04-12 05:18:37 EDT
Reopend because of the explanation in my previous comment.
Comment 16 Felipe Heidrich CLA 2011-04-12 10:01:36 EDT
(In reply to comment #14)
> Is it impossible to use the system font as a fallback for the letters, that
> cannot be shaped by the font of the widget and have no alternative font set
> using a style range? I mean, the font the application sets using style ranges
> for the invalid letters is not intended to be a fallback font for the other
> letters. 

the code that finds the fallback font is complex. It tries different methods to find a good font. In this case it detects that the current run is the same script as the surrondings runs and uses the font from them. It is the right thing to do.

> Apart from that, could you please explain to me, why Verdana can't be used to
> draw whitespaces in Arabic?

You need to ask Microsoft that, but the simple answer is: Verdana does not support Arabic. Note that altough whitespace does not have a glyph it still has metrics (width). The width of a whitespace in a Japanese font is much bigger than the width of a whitespace in an English font.

You can fix this problem on your code by setting the font in whitepaces too.

closing.
Comment 17 Andre Saibel CLA 2011-04-13 01:44:15 EDT
@Felipe:

> the code that finds the fallback font is complex. It tries different methods > to find a good font. In this case it detects that the current run is the same
> script as the surrondings runs and uses the font from them. 

I agree with you, the whole topic is highly complex and the implementation pretty tricky. But I do not agree with your statement that the current run (whitespace, ascii 0x20) is the same script as the surrounding runs (arabic characters). As I have seen, the SWT implementation for Linux does it a little bit different - I do not mean the underlying font rendering engine but the SWT code itself. 

> It is the right thing to do.

At least, there is an explicit directive to use StyleRanges for some parts of the string and not to do it for the others! 
IMO here, in the fallback case the whitespace (characters in general) should be handled separated from the surrounding StyleRanges and tried be drawn with the font that is set for the widget.. and if that attempt fails, to use the regular system fallback font. 

> You need to ask Microsoft that, but the simple answer is: Verdana does not
> support Arabic. Note that altough whitespace does not have a glyph it still has
> metrics (width). The width of a whitespace in a Japanese font is much bigger
> than the width of a whitespace in an English font.
 
Do you mean, it's "just" the existence of the arabic page within the font that is responsible for the ability of printing the other glyphs?
And: is it still the same whitespace codepoint in English and Japanese texts?


@Irina: Is it possible for you re-open again and to provide a patch?