/* * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 8224109 * @summary test for consistent text rotation.
*/
/* * First verify we have rotation by checking for text colored pixels * several lines below the baseline of the text. * Then for subsequent images, check that they are identical to the * the previous image. * Do this for both FM on and off.
*/ int x = 100; int y = 10;
AffineTransform gtx = new AffineTransform();
/* Use monospaced because otherwise an API like TextLayout which * lays out in a horizontal direction with hints applied might * sometimes result in a pixel or so difference and cause a * failure but an effect is not actually a failure of rotation. * Monospaced needs to be monospaced for this to work, and there * is also still some risk of this but we can try it. * This - and fractional metrics is why we use a short string * and count errors. A long string might have a small difference * early on that causes a lot of subsequent pixels to be off-by-one. * This isn't just theoretical. Despite best efforts the test can * fail like this.
*/
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 20);
String os = System.getProperty("os.name").toLowerCase(); if (os.startsWith("mac")) { // Avoid a bug with AAT fonts on macos.
font = new Font("Courier New", Font.PLAIN, 20);
}
System.out.println(font);
AffineTransform at = AffineTransform.getRotateInstance(Math.PI / 2);
at.scale(2.0, 1.5);
Font rotFont = font.deriveFont(at);
test(FM_OFF, x, y, rotFont, gtx, "font-rotation-fm-off.png");
test(FM_ON, x, y, rotFont, gtx, "font-rotation-fm-on.png");
// Repeat with rotated graphics, unrotated font
gtx = at;
x = 10;
y = -100;
test(FM_OFF, x, y, font, gtx, "gx-rotation-fm-off.png");
test(FM_ON, x, y, font, gtx, "gx-rotation-fm-on.png");
// Repeat with rotated graphics, rotated font
gtx = AffineTransform.getRotateInstance(Math.PI / 4);
at = AffineTransform.getRotateInstance(Math.PI / 4);
at.scale(2.0, 1.5);
rotFont = font.deriveFont(at);
x = 140;
y = -100;
test(FM_OFF, x, y, rotFont, gtx, "gx-and-font-rotation-fm-off.png");
test(FM_ON, x, y, rotFont, gtx, "gx-and-font-rotation-fm-on.png");
}
staticvoid test(Object fm, int x, int y, Font font,
AffineTransform gtx, String fileName) throws Exception {
draw(img, TEXTLAYOUT, TEXT, x, y, font, gtx, fm);
compareImages(imageCopy, img);
draw(img, GLYPHVECTOR, TEXT, x, y, font, gtx, fm);
compareImages(imageCopy, img); /* This case needs to be fixed before the test can be enabled. See bug 8236451. draw(img, LAYEDOUT_GLYPHVECTOR, TEXT, x, y, font, gtx, fm); compareImages(imageCopy, img);
*/
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.