Index: Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java,v retrieving revision 1.238 diff -u -r1.238 GC.java --- Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java 22 Jul 2008 16:47:15 -0000 1.238 +++ Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java 27 Aug 2008 14:41:44 -0000 @@ -80,9 +80,8 @@ static final int PEN = 1 << 11; static final int NULL_BRUSH = 1 << 12; static final int NULL_PEN = 1 << 13; - static final int DRAW_OFFSET = 1 << 14; - static final int DRAW = FOREGROUND | LINE_STYLE | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | PEN | NULL_BRUSH | DRAW_OFFSET; + static final int DRAW = FOREGROUND | LINE_STYLE | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | PEN | NULL_BRUSH; static final int FILL = BACKGROUND | BRUSH | NULL_PEN; static final float[] LINE_DOT_ZERO = new float[]{3, 3}; @@ -299,26 +298,6 @@ if (data.gdipFont != 0) Gdip.Font_delete(data.gdipFont); data.gdipFont = gdipFont; } - if ((state & DRAW_OFFSET) != 0) { - data.gdipXOffset = data.gdipYOffset = 0; - int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); - float[] point = new float[]{1, 1}; - Gdip.Graphics_GetTransform(gdipGraphics, matrix); - Gdip.Matrix_TransformPoints(matrix, point, 1); - Gdip.Matrix_delete(matrix); - float scaling = point[0]; - if (scaling < 0) scaling = -scaling; - float penWidth = data.lineWidth * scaling; - if (penWidth == 0 || ((int)penWidth % 2) == 1) { - data.gdipXOffset = 0.5f / scaling; - } - scaling = point[1]; - if (scaling < 0) scaling = -scaling; - penWidth = data.lineWidth * scaling; - if (penWidth == 0 || ((int)penWidth % 2) == 1) { - data.gdipYOffset = 0.5f / scaling; - } - } return; } if ((state & (FOREGROUND | LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) != 0) { @@ -692,7 +671,6 @@ if (width == 0 || height == 0 || arcAngle == 0) return; int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); if (width == height) { Gdip.Graphics_DrawArc(gdipGraphics, data.gdipPen, x, y, width, height, -startAngle, -arcAngle); } else { @@ -706,7 +684,6 @@ Gdip.Matrix_delete(matrix); Gdip.GraphicsPath_delete(path); } - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -785,7 +762,6 @@ int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { int /*long*/ clipRgn = 0; - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); int /*long*/ rgn = Gdip.Region_new(); if (rgn == 0) SWT.error(SWT.ERROR_NO_HANDLES); Gdip.Graphics_GetClip(gdipGraphics, rgn); @@ -793,7 +769,6 @@ clipRgn = Gdip.Region_GetHRGN(rgn, gdipGraphics); } Gdip.Region_delete(rgn); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); float[] lpXform = null; int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES); @@ -1615,9 +1590,7 @@ checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawLine(gdipGraphics, data.gdipPen, x1, y1, x2, y2); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -1664,9 +1637,7 @@ checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawEllipse(gdipGraphics, data.gdipPen, x, y, width, height); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -1705,9 +1676,7 @@ initGdip(); checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path.handle); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); } /** @@ -1760,9 +1729,7 @@ checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -1805,9 +1772,7 @@ checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -1861,9 +1826,7 @@ y = y + height; height = -height; } - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } if ((data.style & SWT.MIRRORED) != 0) { @@ -1998,7 +1961,6 @@ if (nah < 0) nah = 0 - nah; - Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); if (naw == 0 || nah == 0) { Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); } else { @@ -2026,7 +1988,6 @@ Gdip.Graphics_DrawPath(gdipGraphics, pen, path); Gdip.GraphicsPath_delete(path); } - Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); } /** @@ -2090,7 +2051,9 @@ if (!isTransparent) { RectF bounds = new RectF(); Gdip.Graphics_MeasureString(gdipGraphics, buffer, length, data.gdipFont, pt, format, bounds); + gdiFillPrepare(); Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height)); + gdiFillRestore(); } int gstate = 0; int /*long*/ brush = getFgBrush(); @@ -2111,7 +2074,9 @@ } pt.X = x; pt.Y = y; + gdiFillPrepare(); Gdip.Graphics_DrawString(gdipGraphics, buffer, length, data.gdipFont, pt, format, brush); + gdiFillRestore(); if ((data.style & SWT.MIRRORED) != 0) { switch (Gdip.Brush_GetType(brush)) { case Gdip.BrushTypeLinearGradient: @@ -2289,7 +2254,9 @@ if ((flags & SWT.DRAW_TRANSPARENT) == 0) { RectF bounds = new RectF(); Gdip.Graphics_MeasureString(gdipGraphics, buffer, length, data.gdipFont, pt, format, bounds); + gdiFillPrepare(); Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height)); + gdiFillRestore(); } int gstate = 0; int /*long*/ brush = getFgBrush(); @@ -2449,6 +2416,7 @@ if (width == 0 || height == 0 || arcAngle == 0) return; int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { + gdiFillPrepare(); if (width == height) { Gdip.Graphics_FillPie(gdipGraphics, data.gdipBrush, x, y, width, height, -startAngle, -arcAngle); } else { @@ -2458,6 +2426,7 @@ Gdip.Graphics_FillPie(gdipGraphics, data.gdipBrush, 0, 0, 1, 1, -startAngle, -arcAngle); Gdip.Graphics_Restore(gdipGraphics, state); } + gdiFillRestore(); return; } @@ -2584,7 +2553,9 @@ int /*long*/ toGpColor = Gdip.Color_new(data.alpha << 24 | rgb); if (toGpColor == 0) SWT.error(SWT.ERROR_NO_HANDLES); int /*long*/ brush = Gdip.LinearGradientBrush_new(p1, p2, fromGpColor, toGpColor); + gdiFillPrepare(); Gdip.Graphics_FillRectangle(data.gdipGraphics, brush, x, y, width, height); + gdiFillRestore(); Gdip.LinearGradientBrush_delete(brush); Gdip.Color_delete(fromGpColor); Gdip.Color_delete(toGpColor); @@ -2661,12 +2632,14 @@ * * * @see #drawOval - */ + */ public void fillOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.gdipGraphics != 0) { + gdiFillPrepare(); Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height); + gdiFillRestore(); return; } if ((data.style & SWT.MIRRORED) != 0) x--; @@ -2766,7 +2739,8 @@ public void fillRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); - if (data.gdipGraphics != 0) { + int gdipGraphics = data.gdipGraphics; + if (gdipGraphics != 0) { if (width < 0) { x = x + width; width = -width; @@ -2775,7 +2749,9 @@ y = y + height; height = -height; } - Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); + gdiFillPrepare(); + Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, width, height); + gdiFillRestore(); return; } int rop2 = 0; @@ -2859,7 +2835,9 @@ nah = 0 - nah; if (naw == 0 || nah == 0) { + gdiFillPrepare(); Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); + gdiFillRestore(); } else { int /*long*/ path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES); @@ -2882,7 +2860,9 @@ } } Gdip.GraphicsPath_CloseFigure(path); + gdiFillPrepare(); Gdip.Graphics_FillPath(gdipGraphics, brush, path); + gdiFillRestore(); Gdip.GraphicsPath_delete(path); } } @@ -2900,6 +2880,33 @@ } } +void gdiFillRestore() { + Gdip.Graphics_TranslateTransform(data.gdipGraphics, 0.5f, 0.5f, Gdip.MatrixOrderPrepend); + if (data.backgroundPattern != null) { + switch (Gdip.Brush_GetType(data.gdipBrush)) { + case Gdip.BrushTypeTextureFill: + Gdip.TextureBrush_TranslateTransform(data.gdipBrush, -0.5f, -0.5f, Gdip.MatrixOrderPrepend); + break; + case Gdip.BrushTypeLinearGradient: + Gdip.LinearGradientBrush_TranslateTransform(data.gdipBrush, -0.5f, -0.5f, Gdip.MatrixOrderPrepend); + } + } +} + +void gdiFillPrepare() { + Gdip.Graphics_TranslateTransform(data.gdipGraphics, -0.5f, -0.5f, Gdip.MatrixOrderPrepend); + if (data.backgroundPattern != null) { + switch (Gdip.Brush_GetType(data.gdipBrush)) { + case Gdip.BrushTypeTextureFill: + Gdip.TextureBrush_TranslateTransform(data.gdipBrush, 0.5f, 0.5f, Gdip.MatrixOrderPrepend); + break; + case Gdip.BrushTypeLinearGradient: + Gdip.LinearGradientBrush_TranslateTransform(data.gdipBrush, 0.5f, 0.5f, Gdip.MatrixOrderPrepend); + break; + } + } +} + /** * Returns the advance width of the specified character in * the font which is currently selected into the receiver. @@ -3102,9 +3109,7 @@ int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { Rect rect = new Rect(); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); } RECT rect = new RECT(); @@ -3136,9 +3141,7 @@ Gdip.Graphics_GetClip(data.gdipGraphics, rgn); if (Gdip.Region_IsInfinite(rgn, gdipGraphics)) { Rect rect = new Rect(); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); OS.SetRectRgn(region.handle, rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); } else { int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); @@ -3610,7 +3613,7 @@ gdipGraphics = data.gdipGraphics = Gdip.Graphics_new(handle); if (gdipGraphics == 0) SWT.error(SWT.ERROR_NO_HANDLES); Gdip.Graphics_SetPageUnit(gdipGraphics, Gdip.UnitPixel); - Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); + Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); if ((data.style & SWT.MIRRORED) != 0) { int /*long*/ matrix = identity(); Gdip.Graphics_SetTransform(gdipGraphics, matrix); @@ -4287,7 +4290,7 @@ int mask = 0; float lineWidth = attributes.width; if (lineWidth != data.lineWidth) { - mask |= LINE_WIDTH | DRAW_OFFSET; + mask |= LINE_WIDTH; } int lineStyle = attributes.style; if (lineStyle != data.lineStyle) { @@ -4534,7 +4537,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.lineWidth == lineWidth) return; data.lineWidth = lineWidth; - data.state &= ~(LINE_WIDTH | DRAW_OFFSET); + data.state &= ~(LINE_WIDTH); } /** @@ -4600,15 +4603,15 @@ textMode = Gdip.TextRenderingHintSystemDefault; break; case SWT.OFF: - textMode = Gdip.TextRenderingHintSingleBitPerPixelGridFit; + textMode = Gdip.TextRenderingHintSingleBitPerPixel; break; case SWT.ON: int[] type = new int[1]; OS.SystemParametersInfo(OS.SPI_GETFONTSMOOTHINGTYPE, 0, type, 0); if (type[0] == OS.FE_FONTSMOOTHINGCLEARTYPE) { - textMode = Gdip.TextRenderingHintClearTypeGridFit; + textMode = Gdip.TextRenderingHintAntiAlias; } else { - textMode = Gdip.TextRenderingHintAntiAliasGridFit; + textMode = Gdip.TextRenderingHintAntiAlias; } break; default: @@ -4655,7 +4658,6 @@ } Gdip.Graphics_SetTransform(data.gdipGraphics, identity); Gdip.Matrix_delete(identity); - data.state &= ~DRAW_OFFSET; } /** Index: Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java,v retrieving revision 1.26 diff -u -r1.26 GCData.java --- Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java 5 Jun 2008 17:31:50 -0000 1.26 +++ Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java 27 Aug 2008 14:41:44 -0000 @@ -56,7 +56,6 @@ public int /*long*/ gdipFgBrush; public int /*long*/ gdipBgBrush; public int /*long*/ gdipFont; - public float gdipXOffset, gdipYOffset; public int uiState = 0; public boolean focusDrawn; }