Community
Participate
Working Groups
Run the test case below. It renders and measures character using a non True Type font (MS Sans Serif). gc.stringExtent returns a width of 8 for the regular font which matches the rendered glyph width. When I render the same character using the bold version of the font stringExtent returns a width of 9 but the rendered glyph is actually 10 pixels wide. This only appears to happen with non True Type fonts and causes problems in the bidi StyledText. Bidi StyledText doesn't use gc.stringExtent but instead GetCharacterPlacement. GetCharacterPlacement also returns the wrong width. import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class PR_1GI7ALA { Shell shell; Canvas canvas; Font boldFont; Font normalFont; public void create() { shell = new Shell(); Display display = shell.getDisplay(); normalFont = new Font(display, "MS Sans Serif", 10, SWT.NORMAL); boldFont = new Font(display, "MS Sans Serif", 10, SWT.BOLD); shell.setFont(normalFont); shell.setBackground(new Color(display, 155, 0, 0)); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { String text = "s"; event.gc.setBackground(new Color(shell.getDisplay(), 255, 255, 255)); event.gc.drawLine(9, 0, 9, 40); event.gc.drawString(text, 0, 0); System.out.println("regular font " + event.gc.stringExtent(text)); event.gc.setFont(boldFont); event.gc.drawString(text, 0, 20); System.out.println("bold font " + event.gc.stringExtent(text)); } }); shell.open(); shell.setSize(300, 200); } public static void main(String[] args) { PR_1GI7ALA test = new PR_1GI7ALA(); test.create(); test.run(); } public void run() { Display display = shell.getDisplay (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } } } NOTES: KR (8/9/01 1:15:47 PM) We'd like to know if this is an SWT bug or if the platform is just plain not doing the right thing. If it's the latter we'd have to work around it in StyledText (which would require non-trivial changes). An actual fix is not particularly urgent (i.e., the problem only causes cheese, not a crash). KR (8/20/01 2:20:29 PM) A similar problem occurs with True Type fonts in certain sizes. For example Times New Roman 10 regular (non-bold) is measured correctly as being 11 pixels wide. Times New Roman 12, regular is measured incorrectly as 13 pixels wide when it really is 14 pixels wide. This is on Arabic NT and with an Arabic 's' instead of the Latin 's' in the test case above. KR (8/20/01 3:38:08 PM) Wordpad has problems with Times New Roman in sizes > 10 as well. The cursor is not placed correctly. It overlaps the last pixel of the (logical) first character like we do. However if I then add a space it doesn't overlap that pixel. This only happens on Arabic. I haven't seen this on Hebrew. Perhaps the Arabic TrueType fonts are just bad?
PRODUCT VERSION: 2.002
In order for the StyledText widget to be appropriately bidi enabled, this PR needs to be fixed. The incorrect measuring leads to cheese on Arabic platforms. Can you have someone look into this?
It may be that we simply do not get correct measuring information from the o/s for non-truetype fonts. If that is true, then we will be unable to fix this problem. We'll look at it again however.
Cheese does not happen on Win2k. However, the test case above still fails on 2k. Cheese does happen on NT. We may be able to work arround the cheese by rendering text transparent. We already do this in the non-bidi case. Need to investigate how/where the unselected/uncolored background is rendered. This seems to work on non-bidi platforms.
Does not work on 2K. The problem is font-specific, not just true-type specific. On 2K works with Microsoft Sans Serif (not MS Sans Serif).
Revisit post v2
Post 2.0. Re-opening bug reports for review.
Lynne, Silenio and I agreed back in February that StyledText should try to workaround by rendering transparent text. SWT probably can't fix this because the OS is returning bad values.
*** Bug 34571 has been marked as a duplicate of this bug. ***
*** Bug 34570 has been marked as a duplicate of this bug. ***
Released a workaround as part of fixing bug 30434. The workaround currently only applies to bidi scripts or RIGHT_TO_LEFT widget. Bug 31385 may be a duplicate. Should always use the workaround if we find it is the same measuring problem.
This should be marked as fixed. I think bug 40019 is a duplicate or at least related and was fixed, too. Bug 40006 has a patch that implements transparent rendering. I can not reproduce the problem the patch was intended to fix (and the problem is different from the one the bug 40006 was opened for). Should open a separate bug when this is reproducable.
The fix for bug 40019 makes the +1 workaround in StyledText.redraw unnecessary. There is no longer selection cheese when mouse drag selecting. There is still a pixel wide selection cheese when the drag select triggers autoscroll. That in turn is fixed by the transparent rendering suggested in bug 40006. If we release both fixes we can get rid of the workaround in StyledText.redraw.
Removed workaround in StyledText.redraw.