Community
Participate
Working Groups
Build Identifier: Version: 3.6.0 Build id: I20100608-0911 I just upgraded to Eclipse 3.6.0 and my code started behaving strangely. Diagnostics are show only when data is "12" so diagnostics are not excessive. I do not know how to get this to repeat in a small sample. The code is from SiteElement.drawLineText if (data.compareTo("12") == 0) { System.out.println("SiteElement.drawLineText b pixelHeight " + gc.getFontMetrics().getHeight()); //$NON-NLS-1$ System.out.printin("SiteElement.drawLineText b font " + gc.getFont()); //$NON-NLS-1$ System.out.println("SiteElement.drawLineText b metrics " + gc.getFontMetrics()); //$NON-NLS-1$ } org.eclipse.swt.graphics.Point dataSize = gc.textExtent(data); if (data.compareTo("12") == 0) { System.out.println("SiteElement.drawLineText b2 pixelHeight " + gc.getFontMetrics().getHeight()); //$NON-NLS-1$ System.out.println("SiteElement.drawLineText b2 font " + gc.getFont()); //$NON-NLS-1$ System.out.println("SiteElement.drawLineText b2 metrics " + gc.getFontMetrics()); //$NON-NLS-1$ } First drawing pass (to screen), everything is fine SiteElement.drawLabel gc GC {-100595411} SiteElement.drawLabel font.fontData 1|Times New Roman|26.25|1|WINDOWS|1|-35|0|0|0|700|0|0|0|1|0|0|0|0|Times New Roman SiteElement.drawLabel pixelHeight 40 SiteElement.drawText pixelHeight 40 SiteElement.drawLineText top pixelHeight 40 SiteElement.drawLineText b pixelHeight 40 SiteElement.drawLineText b font Font {1544167548} SiteElement.drawLineText b metrics org.eclipse.swt.graphics.FontMetrics@2fa SiteElement.drawLineText b2 pixelHeight 40 SiteElement.drawLineText b2 font Font {1544167548} SiteElement.drawLineText b2 metrics SiteElement.drawLineText b2 metrics org.eclipse.swt.graphics.FontMetrics@2fa SiteElement.drawLineText c pixelHeight 40 SiteElement.drawLineText gc GC {-100595411} Second drawing pass (to image buffer), immediately after the first pass, SiteElement.drawLabel gc GC {-1174337614} SiteElement.drawLabel font.fontData 1|Times New Roman|26.25|1|WINDOWS|1|-35|0|0|0|700|0|0|0|1|0|0|0|0|Times New Roman SiteElement.drawLabel pixelHeight 40 SiteElement.drawText pixelHeight 40 SiteElement.drawLineText top pixelHeight 40 SiteElement.drawLineText b pixelHeight 40 SiteElement.drawLineText b font Font {-536206755} SiteElement.drawLineText b metrics org.eclipse.swt.graphics.FontMetrics@2fa SiteElement.drawLineText b2 pixelHeight 16 SiteElement.drawLineText b2 font Font {-536206755} SiteElement.drawLineText b2 metrics org.eclipse.swt.graphics.FontMetrics@289 SiteElement.drawLineText c pixelHeight 16 SiteElement.drawLineText gc GC {-1174337614} You can see that in the second pass, after gc.getTextExtent(), gc does not change, gc.getFont() does not change, but gc.getFontMetrics () does change. Reproducible: Always
Please, provide a small snippet that we can run here to reproduce the problem. Thank you
Created attachment 198832 [details] Small Eclipse plugin / SWT app demonstrating the issue Sample output (Eclipse 3.7 win64): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GC FONT Font {-1408622859} Arial 60 metrics: 35 41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GC FONT Font {-1408622859} Arial 60 metrics: 7 8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I reduced your testcase to this: import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.Display; public class PR319125 { public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 100, 100); GC gc = new GC(image); gc.setAdvanced(true); gc.fillRectangle(0, 0, 100, 100); Font fFont1 = new Font(display, new FontData("Arial", 60, SWT.NORMAL)); gc.setFont(fFont1); FontMetrics fontMetrics = gc.getFontMetrics(); System.out.println("metrics: " + fontMetrics.getAverageCharWidth() + " " + gc.getAdvanceWidth('x')); gc.stringExtent("m"); fontMetrics = gc.getFontMetrics(); System.out.println("metrics: " + fontMetrics.getAverageCharWidth() + " " + gc.getAdvanceWidth('x')); gc.dispose(); image.dispose(); display.dispose(); } }
The problem is that the HDC returned by Graphics_GetHDC() does not have the font set in it. But when we switch the font in the HDC is also switches the font in the GC.handle. The code in drawText() has some code that goes like this: int /*long*/ hdc = Gdip.Graphics_GetHDC(gdipGraphics); int /*long*/ hFont = data.hGDIFont;//this is NULL if (hFont == 0 && data.font != null) hFont = data.font.handle;//Arial 60 int /*long*/ oldFont = 0; if (hFont != 0) oldFont = OS.SelectObject(hdc, hFont);//oldFont=System 9 //do some work if (hFont != 0) OS.SelectObject(hdc, oldFont);//sets System 9 in hdc and handle Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); Silenio, do you remember what is the relation between handle and hdc (returned by Graphics_GetHDC()) ? Apparently switching the font in handle does not affect hdc, but switching the font in hdc does affect handle.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
The problem still occurs in SWT 3.118.0.