Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit def1d5a

Browse files
committedApr 20, 2020
8242004: TextLayout throws Exception with a non-invertible transform
Reviewed-by: serb, jdv
1 parent 9ad3939 commit def1d5a

File tree

6 files changed

+87
-40
lines changed

6 files changed

+87
-40
lines changed
 

‎src/java.desktop/share/classes/sun/font/GlyphLayout.java

-17
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ private static final class SDCache {
213213
public FontRenderContext key_frc;
214214

215215
public AffineTransform dtx;
216-
public AffineTransform invdtx;
217216
public AffineTransform gtx;
218217
public Point2D.Float delta;
219218
public FontStrikeDesc sd;
@@ -229,14 +228,6 @@ private SDCache(Font font, FontRenderContext frc) {
229228
dtx.setTransform(dtx.getScaleX(), dtx.getShearY(),
230229
dtx.getShearX(), dtx.getScaleY(),
231230
0, 0);
232-
if (!dtx.isIdentity()) {
233-
try {
234-
invdtx = dtx.createInverse();
235-
}
236-
catch (NoninvertibleTransformException e) {
237-
throw new InternalError(e);
238-
}
239-
}
240231

241232
float ptSize = font.getSize2D();
242233
if (font.isTransformed()) {
@@ -480,10 +471,6 @@ public StandardGlyphVector layout(Font font, FontRenderContext frc,
480471
}
481472
}
482473

483-
// if (txinfo.invdtx != null) {
484-
// _gvdata.adjustPositions(txinfo.invdtx);
485-
// }
486-
487474
// If layout fails (negative glyph count) create an un-laid out GV instead.
488475
// ie default positions. This will be a lot better than the alternative of
489476
// a complete blank layout.
@@ -579,10 +566,6 @@ public void grow(int delta) {
579566
_indices = nindices;
580567
}
581568

582-
public void adjustPositions(AffineTransform invdtx) {
583-
invdtx.transform(_positions, 0, _positions, 0, _count);
584-
}
585-
586569
public StandardGlyphVector createGlyphVector(Font font, FontRenderContext frc, StandardGlyphVector result) {
587570

588571
// !!! default initialization until we let layout engines do it

‎src/java.desktop/share/classes/sun/font/StandardGlyphVector.java

-23
Original file line numberDiff line numberDiff line change
@@ -876,29 +876,6 @@ public float[] getGlyphInfo() {
876876
return result;
877877
}
878878

879-
/**
880-
* !!! not used currently, but might be by getPixelbounds?
881-
*/
882-
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
883-
if (renderFRC == null) {
884-
renderFRC = frc;
885-
}
886-
887-
// it is a total pain that you have to copy the transform.
888-
889-
AffineTransform at = renderFRC.getTransform();
890-
at.transform(loc, loc);
891-
pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
892-
pxResult.y = (int)loc.getY();
893-
loc.setLocation(pxResult.x, pxResult.y);
894-
try {
895-
at.inverseTransform(loc, loc);
896-
}
897-
catch (NoninvertibleTransformException e) {
898-
throw new IllegalArgumentException("must be able to invert frc transform");
899-
}
900-
}
901-
902879
//////////////////////
903880
// StandardGlyphVector package private methods
904881
/////////////////////

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

+3
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ public FontInfo checkFontInfo(FontInfo info, Font font,
667667
}
668668
}
669669

670+
info.nonInvertibleTx =
671+
(Math.abs(textAt.getDeterminant()) <= Double.MIN_VALUE);
672+
670673
info.font2D = FontUtilities.getFont2D(font);
671674

672675
int fmhint = fractionalMetricsHint;

‎src/java.desktop/share/classes/sun/java2d/loops/FontInfo.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class FontInfo implements Cloneable {
4747
public FontStrike fontStrike;
4848
public double[] devTx;
4949
public double[] glyphTx;
50+
public boolean nonInvertibleTx;
5051
public int pixelHeight;
5152
public float originX;
5253
public float originY;

‎src/java.desktop/share/classes/sun/java2d/pipe/GlyphListPipe.java

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public void drawString(SunGraphics2D sg2d, String s,
4444
double x, double y)
4545
{
4646
FontInfo info = sg2d.getFontInfo();
47+
if (info.nonInvertibleTx) {
48+
return;
49+
}
4750
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
4851
SurfaceData.outlineTextRenderer.drawString(sg2d, s, x, y);
4952
return;
@@ -80,6 +83,9 @@ public void drawChars(SunGraphics2D sg2d,
8083
int ix, int iy)
8184
{
8285
FontInfo info = sg2d.getFontInfo();
86+
if (info.nonInvertibleTx) {
87+
return;
88+
}
8389
float x, y;
8490
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
8591
SurfaceData.outlineTextRenderer.drawChars(
@@ -114,6 +120,9 @@ public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector gv,
114120
{
115121
FontRenderContext frc = gv.getFontRenderContext();
116122
FontInfo info = sg2d.getGVFontInfo(gv.getFont(), frc);
123+
if (info.nonInvertibleTx) {
124+
return;
125+
}
117126
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
118127
SurfaceData.outlineTextRenderer.drawGlyphVector(sg2d, gv, x, y);
119128
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8242004
27+
* @summary Font/Text APIs should handle a non-invertible transform.
28+
*/
29+
30+
import java.awt.Color;
31+
import java.awt.Font;
32+
import java.awt.Graphics2D;
33+
import java.awt.font.FontRenderContext;
34+
import java.awt.font.GlyphVector;
35+
import java.awt.font.TextLayout;
36+
import java.awt.geom.AffineTransform;
37+
import java.awt.image.BufferedImage;
38+
39+
public class NonInvertibleTransformTextTest {
40+
41+
public static void main(String[] args) {
42+
43+
// Create a non-invertible transform
44+
AffineTransform at = new AffineTransform(1f, 0.0f, -15, 0.0, -1, -30);
45+
46+
// Test creating a text layout
47+
FontRenderContext frc = new FontRenderContext(at, false, false);
48+
Font font = new Font(Font.DIALOG, Font.PLAIN, 12);
49+
TextLayout tl = new TextLayout("ABC", font, frc);
50+
tl.getOutline(new AffineTransform());
51+
52+
// Test rendering text
53+
BufferedImage bi = new BufferedImage(100, 100,
54+
BufferedImage.TYPE_INT_RGB);
55+
Graphics2D g2d = bi.createGraphics();
56+
g2d.setColor(Color.white);
57+
g2d.fillRect(0,0,100,100);
58+
g2d.setColor(Color.red);
59+
tl.draw(g2d, 50, 50); // first the TextLayout created above
60+
61+
// Now a laid out GlyphVector
62+
Font f = g2d.getFont();
63+
char[] chs = { 'A', 'B', 'C' };
64+
GlyphVector gv = f.layoutGlyphVector(frc, chs, 0, chs.length, 0);
65+
g2d.drawGlyphVector(gv, 20, 20);
66+
67+
// Now under the transform, the basic text drawing calls.
68+
g2d.setTransform(at);
69+
g2d.drawString("ABC", 20, 20);
70+
g2d.drawChars(chs, 0, chs.length, 20, 20);
71+
// And TextLayout again.
72+
tl.draw(g2d, 50, 50);
73+
}
74+
}

0 commit comments

Comments
 (0)
This repository has been archived.