@@ -182,6 +182,8 @@ static class State extends LazyState implements Cloneable {
182182 Pattern bgPattern ;
183183 int dx ;
184184 int dy ;
185+ float sx ;
186+ float sy ;
185187
186188 Pattern fgPattern ;
187189
@@ -203,6 +205,8 @@ public void copyFrom(State state) {
203205 lineAttributes = SWTGraphics .clone (state .lineAttributes );
204206 dx = state .dx ;
205207 dy = state .dy ;
208+ sx = state .sx ;
209+ sy = state .sy ;
206210 bgPattern = state .bgPattern ;
207211 fgPattern = state .fgPattern ;
208212 font = state .font ;
@@ -254,15 +258,17 @@ public void copyFrom(State state) {
254258 | ((SWT .DEFAULT + INTERPOLATION_WHOLE_NUMBER ) << INTERPOLATION_SHIFT );
255259 }
256260
257- private static MethodHandle DRAW_IMAGE_HANDLE ;
258- static {
261+ private static final MethodHandle DRAW_IMAGE_HANDLE = getDrawImageHandle ();
262+
263+ private static MethodHandle getDrawImageHandle () {
259264 try {
260265 // Introduced with SWT 3.132
261266 MethodType mt = MethodType .methodType (void .class , Image .class , int .class , int .class , int .class , int .class );
262- DRAW_IMAGE_HANDLE = MethodHandles .publicLookup ().findVirtual (GC .class , "drawImage" , mt ); //$NON-NLS-1$
267+ return MethodHandles .publicLookup ().findVirtual (GC .class , "drawImage" , mt ); //$NON-NLS-1$
263268 } catch (IllegalAccessException | NoSuchMethodException e ) {
264269 // ignore
265270 }
271+ return null ;
266272 }
267273
268274 private final LazyState appliedState = new LazyState ();
@@ -325,7 +331,8 @@ protected final void checkGC() {
325331 protected final void checkPaint () {
326332 checkGC ();
327333 if (!currentState .fgColor .equals (appliedState .fgColor ) && currentState .fgPattern == null ) {
328- gc .setForeground (appliedState .fgColor = currentState .fgColor );
334+ appliedState .fgColor = currentState .fgColor ;
335+ gc .setForeground (appliedState .fgColor );
329336 }
330337
331338 LineAttributes lineAttributes = currentState .lineAttributes ;
@@ -713,14 +720,19 @@ public int getAntialias() {
713720 private final float [] transformElements = new float [6 ];
714721
715722 /**
716- * Returns a stable, direction-independent estimate of the current graphics
717- * scaling, computed as the square root of the absolute determinant of the
718- * transformation matrix.
723+ * If scale value in x and y is the same this is returned. Otherwise it returns
724+ * a stable, direction-independent estimate of the current graphics scaling,
725+ * computed as the square root of the absolute determinant of the transformation
726+ * matrix.
719727 *
720728 * @see org.eclipse.draw2d.Graphics#getAbsoluteScale()
721729 */
722730 @ Override
723731 public double getAbsoluteScale () {
732+ if (currentState .sx == currentState .sy ) {
733+ return currentState .sx ;
734+ }
735+
724736 if (transform == null ) {
725737 return super .getAbsoluteScale ();
726738 }
@@ -892,6 +904,7 @@ protected void init() {
892904
893905 currentState .relativeClip = new RectangleClipping (gc .getClipping ());
894906 currentState .alpha = gc .getAlpha ();
907+ currentState .sx = currentState .sy = 1.0f ;
895908 }
896909
897910 private void initTransform (boolean force ) {
@@ -1037,6 +1050,9 @@ protected void restoreState(State s) {
10371050
10381051 translateX = currentState .dx = s .dx ;
10391052 translateY = currentState .dy = s .dy ;
1053+
1054+ currentState .sx = s .sx ;
1055+ currentState .sy = s .sy ;
10401056 }
10411057
10421058 /**
@@ -1081,6 +1097,8 @@ public void scale(float horizontal, float vertical) {
10811097
10821098 initTransform (true );
10831099 transform .scale (horizontal , vertical );
1100+ currentState .sx *= horizontal ;
1101+ currentState .sy *= vertical ;
10841102 gc .setTransform (transform );
10851103 elementsNeedUpdate = true ;
10861104
0 commit comments