Skip to content

Commit cddee6d

Browse files
author
Daniel Gredler
committed
8380028: Fix Page8 of manual test java/awt/print/PrinterJob/PrintTextTest.java on macOS
Reviewed-by: prr, psadhukhan
1 parent ce9b3b5 commit cddee6d

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

src/java.desktop/macosx/classes/sun/lwawt/macosx/CTextPipe.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -25,7 +25,6 @@
2525

2626
package sun.lwawt.macosx;
2727

28-
2928
import java.awt.*;
3029
import 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
}

src/java.desktop/share/classes/java/awt/geom/AffineTransform.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 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
@@ -1137,7 +1137,7 @@ private void stateError() {
11371137
* The values are stored in the array as
11381138
* { m00 m10 m01 m11 m02 m12 }.
11391139
* An array of 4 doubles can also be specified, in which case only the
1140-
* first four elements representing the non-transform
1140+
* first four elements representing the non-translation
11411141
* parts of the array are retrieved and the values are stored into
11421142
* the array as { m00 m10 m01 m11 }
11431143
* @param flatmatrix the double array used to store the returned

src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ public FontInfo checkFontInfo(FontInfo info, Font font,
596596
textAt.scale(ptSize, ptSize);
597597
info.originX = (float)textAt.getTranslateX();
598598
info.originY = (float)textAt.getTranslateY();
599-
textAt.translate(-info.originX, -info.originY);
599+
textAt.setTransform(textAt.getScaleX(), textAt.getShearY(),
600+
textAt.getShearX(), textAt.getScaleY(),
601+
0, 0);
600602
if (transformState >= TRANSFORM_TRANSLATESCALE) {
601603
transform.getMatrix(info.devTx = new double[4]);
602604
devAt = new AffineTransform(info.devTx);

test/jdk/java/awt/print/PrinterJob/PrintTextTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 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
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 6425068 7156751 7157659 8029204 8132890 8148334 8344637 8368702
26+
* @bug 6425068 7156751 7157659 8029204 8132890 8148334 8344637 8368702 8380028
2727
* @key printer
2828
* @summary Confirm that text prints where we expect to the length we expect.
2929
* @library /java/awt/regtesthelpers

0 commit comments

Comments
 (0)