11/*
2- * Copyright (c) 2011, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2011, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525
2626package sun .lwawt .macosx ;
2727
28-
2928import java .awt .*;
3029import java .awt .font .*;
3130
@@ -73,12 +72,17 @@ void drawTextAsShape(final SunGraphics2D sg2d, final String s, final double x, f
7372
7473 @ Override
7574 public void drawString (final SunGraphics2D sg2d , final String s , final double x , final double y ) {
75+
76+ FontInfo info = sg2d .getFontInfo ();
77+ double dx = x + info .originX ;
78+ double dy = y + info .originY ;
79+
7680 final long nativeStrikePtr = getNativeStrikePtr (sg2d );
7781 if (OSXSurfaceData .IsSimpleColor (sg2d .paint ) && nativeStrikePtr != 0 ) {
7882 final OSXSurfaceData surfaceData = (OSXSurfaceData )sg2d .getSurfaceData ();
79- surfaceData .drawString (this , sg2d , nativeStrikePtr , s , x , y );
83+ surfaceData .drawString (this , sg2d , nativeStrikePtr , s , dx , dy );
8084 } else {
81- drawTextAsShape (sg2d , s , x , y );
85+ drawTextAsShape (sg2d , s , dx , dy );
8286 }
8387 }
8488
@@ -153,6 +157,15 @@ public void drawGlyphVector(final SunGraphics2D sg2d, final GlyphVector gV, fina
153157 final Font prevFont = sg2d .getFont ();
154158 sg2d .setFont (gV .getFont ());
155159
160+ int flags = gV .getLayoutFlags ();
161+ boolean positionAdjustments = (flags & GlyphVector .FLAG_HAS_POSITION_ADJUSTMENTS ) != 0 ;
162+ if (positionAdjustments ) {
163+ // make sure GV positions are initialized, so they are available later in native code; this
164+ // will already be the case if the user explicitly set the glyph positions, but not if the
165+ // position adjustment flag was set because of a font translation transform or font tracking
166+ gV .getGlyphPosition (0 );
167+ }
168+
156169 if (hasSlotData (gV )) {
157170 final int length = gV .getNumGlyphs ();
158171 float [] positions = gV .getGlyphPositions (0 , length , null );
@@ -177,12 +190,17 @@ public void drawGlyphVector(final SunGraphics2D sg2d, final GlyphVector gV, fina
177190
178191 @ Override
179192 public void drawChars (final SunGraphics2D sg2d , final char [] data , final int offset , final int length , final int x , final int y ) {
193+
194+ FontInfo info = sg2d .getFontInfo ();
195+ double dx = x + info .originX ;
196+ double dy = y + info .originY ;
197+
180198 final long nativeStrikePtr = getNativeStrikePtr (sg2d );
181199 if (OSXSurfaceData .IsSimpleColor (sg2d .paint ) && nativeStrikePtr != 0 ) {
182200 final OSXSurfaceData surfaceData = (OSXSurfaceData )sg2d .getSurfaceData ();
183- surfaceData .drawUnicodes (this , sg2d , nativeStrikePtr , data , offset , length , x , y );
201+ surfaceData .drawUnicodes (this , sg2d , nativeStrikePtr , data , offset , length , ( float ) dx , ( float ) dy );
184202 } else {
185- drawTextAsShape (sg2d , new String (data , offset , length ), x , y );
203+ drawTextAsShape (sg2d , new String (data , offset , length ), dx , dy );
186204 }
187205 }
188206
@@ -191,7 +209,8 @@ public CTextPipe traceWrap() {
191209 }
192210
193211 public static final class Tracer extends CTextPipe {
194- void doDrawString (final SurfaceData sData , final long nativeStrikePtr , final String s , final float x , final float y ) {
212+ @ Override
213+ public void doDrawString (final SurfaceData sData , final long nativeStrikePtr , final String s , final double x , final double y ) {
195214 GraphicsPrimitive .tracePrimitive ("QuartzDrawString" );
196215 super .doDrawString (sData , nativeStrikePtr , s , x , y );
197216 }
0 commit comments