Skip to content

Commit f6c729c

Browse files
committed
Merge master HEAD into openj9-staging
Signed-off-by: J9 Build <j9build@ca.ibm.com>
2 parents cb8229f + 4f59ba7 commit f6c729c

File tree

21 files changed

+1200
-88
lines changed

21 files changed

+1200
-88
lines changed

make/Docs.gmk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ define SetupApiDocsGenerationBody
291291
$1_INDIRECT_EXPORTS := $$(call FindTransitiveIndirectDepsForModules, $$($1_MODULES))
292292
$1_ALL_MODULES := $$(sort $$($1_MODULES) $$($1_INDIRECT_EXPORTS))
293293

294-
$1_JAVA_ARGS := -Dextlink.spec.version=$$(VERSION_SPECIFICATION) \
295-
-Djspec.version=$$(VERSION_SPECIFICATION)
294+
$1_JAVA_ARGS := -Dextlink.spec.version=$$(VERSION_SPECIFICATION)
296295

297296
ifeq ($$(ENABLE_FULL_DOCS), true)
298297
$1_SEALED_GRAPHS_DIR := $$(SUPPORT_OUTPUTDIR)/docs/$1-sealed-graphs

make/jdk/src/classes/build/tools/taglet/JSpec.java

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.stream.Collectors;
3434

3535
import javax.lang.model.element.Element;
36+
import javax.lang.model.element.PackageElement;
37+
import javax.lang.model.element.TypeElement;
3638

3739
import com.sun.source.doctree.DocTree;
3840
import com.sun.source.doctree.LiteralTree;
@@ -44,7 +46,7 @@
4446
import static com.sun.source.doctree.DocTree.Kind.*;
4547

4648
/**
47-
* A base class for block tags to insert a link to an external copy of JLS or JVMS.
49+
* A base class for block tags to insert a link to a local copy of JLS or JVMS.
4850
* The tags can be used as follows:
4951
*
5052
* <pre>
@@ -57,30 +59,23 @@
5759
* &commat;jls 3.4 Line Terminators
5860
* </pre>
5961
*
60-
* will produce the following HTML for a docs build configured for Java SE 12.
62+
* will produce the following HTML, depending on the file containing
63+
* the tag.
6164
*
6265
* <pre>{@code
6366
* <dt>See <i>Java Language Specification</i>:
64-
* <dd><a href="https://docs.oracle.com/javase/specs/jls/se12/html/jls-3.html#jls-3.4">3.4 Line terminators</a>
67+
* <dd><a href="../../specs/jls/jls-3.html#jls-3.4">3.4 Line terminators</a>
6568
* }</pre>
6669
*
67-
* The version of the spec must be set in the jspec.version system property.
70+
* Copies of JLS and JVMS are expected to have been placed in the {@code specs}
71+
* folder. These documents are not included in open-source repositories.
6872
*/
6973
public class JSpec implements Taglet {
70-
static final String SPEC_VERSION;
71-
72-
static {
73-
SPEC_VERSION = System.getProperty("jspec.version");
74-
if (SPEC_VERSION == null) {
75-
throw new RuntimeException("jspec.version property not set");
76-
}
77-
}
7874

7975
public static class JLS extends JSpec {
8076
public JLS() {
8177
super("jls",
8278
"Java Language Specification",
83-
"https://docs.oracle.com/javase/specs/jls/se" + SPEC_VERSION + "/html",
8479
"jls");
8580
}
8681
}
@@ -89,20 +84,17 @@ public static class JVMS extends JSpec {
8984
public JVMS() {
9085
super("jvms",
9186
"Java Virtual Machine Specification",
92-
"https://docs.oracle.com/javase/specs/jvms/se" + SPEC_VERSION + "/html",
9387
"jvms");
9488
}
9589
}
9690

9791
private String tagName;
9892
private String specTitle;
99-
private String baseURL;
10093
private String idPrefix;
10194

102-
JSpec(String tagName, String specTitle, String baseURL, String idPrefix) {
95+
JSpec(String tagName, String specTitle, String idPrefix) {
10396
this.tagName = tagName;
10497
this.specTitle = specTitle;
105-
this.baseURL = baseURL;
10698
this.idPrefix = idPrefix;
10799
}
108100

@@ -169,8 +161,8 @@ public String toString(List<? extends DocTree> tags, Element elem) {
169161
String chapter = m.group("chapter");
170162
String section = m.group("section");
171163

172-
String url = String.format("%1$s/%2$s-%3$s.html#%2$s-%3$s%4$s",
173-
baseURL, idPrefix, chapter, section);
164+
String url = String.format("%1$s/../specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s",
165+
docRoot(elem), idPrefix, chapter, section);
174166

175167
sb.append("<a href=\"")
176168
.append(url)
@@ -216,4 +208,35 @@ private String escape(String s) {
216208
}
217209
}).visit(trees, new StringBuilder()).toString();
218210
}
211+
212+
private String docRoot(Element elem) {
213+
switch (elem.getKind()) {
214+
case MODULE:
215+
return "..";
216+
217+
case PACKAGE:
218+
PackageElement pe = (PackageElement)elem;
219+
String pkgPart = pe.getQualifiedName()
220+
.toString()
221+
.replace('.', '/')
222+
.replaceAll("[^/]+", "..");
223+
return pe.getEnclosingElement() != null
224+
? "../" + pkgPart
225+
: pkgPart;
226+
227+
case CLASS, ENUM, RECORD, INTERFACE, ANNOTATION_TYPE:
228+
TypeElement te = (TypeElement)elem;
229+
return te.getQualifiedName()
230+
.toString()
231+
.replace('.', '/')
232+
.replaceAll("[^/]+", "..");
233+
234+
default:
235+
var enclosing = elem.getEnclosingElement();
236+
if (enclosing == null)
237+
throw new IllegalArgumentException(elem.getKind().toString());
238+
return docRoot(enclosing);
239+
}
240+
}
241+
219242
}

make/jdk/src/classes/build/tools/taglet/ToolGuide.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,19 @@ private String docRoot(Element elem) {
156156
return pe.getEnclosingElement() != null
157157
? "../" + pkgPart
158158
: pkgPart;
159-
case CLASS:
159+
160+
case CLASS, ENUM, RECORD, INTERFACE, ANNOTATION_TYPE:
160161
TypeElement te = (TypeElement)elem;
161162
return te.getQualifiedName()
162163
.toString()
163164
.replace('.', '/')
164165
.replaceAll("[^/]+", "..");
165166

166167
default:
167-
throw new IllegalArgumentException(elem.getKind().toString());
168+
var enclosing = elem.getEnclosingElement();
169+
if (enclosing == null)
170+
throw new IllegalArgumentException(elem.getKind().toString());
171+
return docRoot(enclosing);
168172
}
169173
}
170174
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -32,6 +32,7 @@
3232
import java.awt.Rectangle;
3333
import java.awt.Transparency;
3434
import java.awt.geom.AffineTransform;
35+
import java.awt.geom.Point2D;
3536
import java.awt.image.BufferedImage;
3637
import java.awt.image.ColorModel;
3738
import java.awt.image.VolatileImage;
@@ -45,10 +46,16 @@ public static CPrinterGraphicsConfig getConfig(PageFormat pf) {
4546

4647
private final GraphicsDevice device;
4748
private final PageFormat pf;
49+
private final AffineTransform deviceTransform;
4850

4951
public CPrinterGraphicsConfig(PageFormat pf) {
52+
this(pf, null);
53+
}
54+
55+
CPrinterGraphicsConfig(PageFormat pf, AffineTransform deviceTransform) {
5056
this.device = new CPrinterDevice(this);
5157
this.pf = pf;
58+
this.deviceTransform = deviceTransform;
5259
}
5360

5461
public PageFormat getPageFormat() {
@@ -178,7 +185,8 @@ public ColorModel getColorModel(int transparency) {
178185
*/
179186
@Override
180187
public AffineTransform getDefaultTransform() {
181-
return new AffineTransform();
188+
return deviceTransform == null ?
189+
new AffineTransform() : new AffineTransform(deviceTransform);
182190
}
183191

184192
/**
@@ -224,6 +232,10 @@ public AffineTransform getNormalizingTransform() {
224232
*/
225233
@Override
226234
public Rectangle getBounds() {
227-
return new Rectangle(0, 0, (int)pf.getWidth(), (int)pf.getHeight());
235+
Point2D.Double pt = new Point2D.Double(pf.getWidth(), pf.getHeight());
236+
Point2D.Double transformedPt = new Point2D.Double();
237+
getDefaultTransform().transform(pt, transformedPt);
238+
return new Rectangle(0, 0,
239+
(int)transformedPt.getX(), (int)transformedPt.getY());
228240
}
229241
}

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

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.awt.GraphicsEnvironment;
3636
import java.awt.SecondaryLoop;
3737
import java.awt.Toolkit;
38+
import java.awt.geom.AffineTransform;
3839
import java.awt.geom.Rectangle2D;
3940
import java.awt.image.BufferedImage;
4041
import java.awt.print.Pageable;
@@ -85,6 +86,9 @@ public final class CPrinterJob extends RasterPrinterJob {
8586
// future compatibility and the state keeping that it handles.
8687

8788
private static String sShouldNotReachHere = "Should not reach here.";
89+
private static final double USER_SPACE_DPI = 72.0;
90+
private static final int DEFAULT_DOC_DPI_X = 300;
91+
private static final int DEFAULT_DOC_DPI_Y = 300;
8892

8993
private volatile SecondaryLoop printingLoop;
9094
private AtomicReference<Throwable> printErrorRef = new AtomicReference<>();
@@ -110,6 +114,9 @@ public final class CPrinterJob extends RasterPrinterJob {
110114
private final Object fNSPrintInfoLock = new Object();
111115
private final Object disposerReferent = new Object();
112116

117+
private double hRes = DEFAULT_DOC_DPI_X;
118+
private double vRes = DEFAULT_DOC_DPI_Y;
119+
113120
static {
114121
// AWT has to be initialized for the native code to function correctly.
115122
Toolkit.getDefaultToolkit();
@@ -461,8 +468,7 @@ public void print(PrintRequestAttributeSet attributes) throws PrinterException {
461468
*/
462469
@Override
463470
protected double getXRes() {
464-
// NOTE: This is not used in the CPrinterJob code path.
465-
return 0;
471+
return hRes;
466472
}
467473

468474
/**
@@ -471,8 +477,31 @@ protected double getXRes() {
471477
*/
472478
@Override
473479
protected double getYRes() {
474-
// NOTE: This is not used in the CPrinterJob code path.
475-
return 0;
480+
return vRes;
481+
}
482+
483+
@Override
484+
protected void setXYRes(double x, double y) {
485+
hRes = x;
486+
vRes = y;
487+
}
488+
489+
/**
490+
* Returns the resolution in dots per inch across the width
491+
* of the page. This method take into account the page orientation.
492+
*/
493+
private double getXRes(PageFormat pageFormat) {
494+
return pageFormat.getOrientation() == PageFormat.PORTRAIT ?
495+
getXRes() : getYRes();
496+
}
497+
498+
/**
499+
* Returns the resolution in dots per inch across the height
500+
* of the page. This method take into account the page orientation.
501+
*/
502+
private double getYRes(PageFormat pageFormat) {
503+
return pageFormat.getOrientation() == PageFormat.PORTRAIT ?
504+
getYRes() : getXRes();
476505
}
477506

478507
/**
@@ -817,7 +846,11 @@ private void printToPathGraphics( final PeekGraphics graphics, // Always an a
817846
// This is called from the native side.
818847
Runnable r = new Runnable() { public void run() {
819848
try {
820-
SurfaceData sd = CPrinterSurfaceData.createData(page, context); // Just stores page into an ivar
849+
AffineTransform deviceTransform = new AffineTransform(
850+
getXRes(page) / USER_SPACE_DPI, 0, 0,
851+
getYRes(page) / USER_SPACE_DPI, 0, 0);
852+
SurfaceData sd = CPrinterSurfaceData
853+
.createData(page, deviceTransform, context); // Just stores page into an ivar
821854
if (defaultFont == null) {
822855
defaultFont = new Font("Dialog", Font.PLAIN, 12);
823856
}
@@ -873,6 +906,9 @@ private Object[] getPageformatPrintablePeekgraphics(final int pageIndex) {
873906
Rectangle2D pageFormatArea =
874907
getPageFormatArea(pageFormat);
875908
initPrinterGraphics(peekGraphics, pageFormatArea);
909+
double scaleX = getXRes(pageFormat) / USER_SPACE_DPI;
910+
double scaleY = getYRes(pageFormat) / USER_SPACE_DPI;
911+
peekGraphics.scale(scaleX, scaleY);
876912

877913
// Do the assignment here!
878914
ret[0] = pageFormat;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -26,6 +26,7 @@
2626
package sun.lwawt.macosx;
2727

2828
import java.awt.*;
29+
import java.awt.geom.AffineTransform;
2930
import java.awt.image.*;
3031
import java.awt.print.PageFormat;
3132
import java.nio.ByteBuffer;
@@ -40,8 +41,8 @@ public final class CPrinterSurfaceData extends OSXSurfaceData{
4041
// public static final SurfaceType IntArgbPQ = SurfaceType.IntArgb.deriveSubType(DESC_INT_ARGB_PQ);
4142
public static final SurfaceType IntRgbPQ = SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_PQ);
4243

43-
static SurfaceData createData(PageFormat pf, long context) {
44-
return new CPrinterSurfaceData(CPrinterGraphicsConfig.getConfig(pf), context);
44+
static SurfaceData createData(PageFormat pf, AffineTransform deviceTransform, long context) {
45+
return new CPrinterSurfaceData(new CPrinterGraphicsConfig(pf, deviceTransform), context);
4546
}
4647

4748
private CPrinterSurfaceData(GraphicsConfiguration gc, long context) {

src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, 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
@@ -86,6 +86,8 @@ - (void)drawRect:(NSRect)aRect
8686
GET_CPRINTERJOB_CLASS();
8787
DECLARE_METHOD(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics",
8888
"(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V");
89+
DECLARE_METHOD(jm_getXRes, sjc_CPrinterJob, "getXRes", "(Ljava/awt/print/PageFormat;)D");
90+
DECLARE_METHOD(jm_getYRes, sjc_CPrinterJob, "getYRes", "(Ljava/awt/print/PageFormat;)D");
8991

9092
// Create and draw into a new CPrinterGraphics with the current Context.
9193
assert(fCurPageFormat != NULL);
@@ -103,6 +105,21 @@ - (void)drawRect:(NSRect)aRect
103105

104106
jlong context = ptr_to_jlong([printLoop context]);
105107
CGContextRef cgRef = (CGContextRef)[[printLoop context] graphicsPort];
108+
109+
// Scale from the java document DPI to the user space DPI
110+
jdouble hRes = (*env)->CallDoubleMethod(env, fPrinterJob, jm_getXRes, fCurPageFormat);
111+
CHECK_EXCEPTION();
112+
jdouble vRes = (*env)->CallDoubleMethod(env, fPrinterJob, jm_getYRes, fCurPageFormat);
113+
CHECK_EXCEPTION();
114+
if (hRes > 0 && vRes > 0) {
115+
double defaultDeviceDPI = 72;
116+
double scaleX = defaultDeviceDPI / hRes;
117+
double scaleY = defaultDeviceDPI / vRes;
118+
if (scaleX != 1 || scaleY != 1) {
119+
CGContextScaleCTM(cgRef, scaleX, scaleY);
120+
}
121+
}
122+
106123
CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management
107124

108125
(*env)->CallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob,

0 commit comments

Comments
 (0)