diff options
-rw-r--r-- | test/jb/java/awt/Font/Font426.java | 77 | ||||
-rw-r--r-- | test/jb/java/awt/Font/font426.sh | 66 | ||||
-rw-r--r-- | test/jb/java/awt/Font/fonts/DFCaiDai.ttf | bin | 0 -> 5677956 bytes |
3 files changed, 143 insertions, 0 deletions
diff --git a/test/jb/java/awt/Font/Font426.java b/test/jb/java/awt/Font/Font426.java new file mode 100644 index 0000000000..dd44b66592 --- /dev/null +++ b/test/jb/java/awt/Font/Font426.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.font.FontRenderContext; + +/* + * @test + * @summary regression test on JRE-426 Crash after launching Rider for a few seconds + * @run main/othervm Font426 + */ + +/* + * Description: The test copies the font 华康彩带t.ttf into the folder containing System fonts. Then it get all fonts + * and tries to get <code>getCharWidth</code> for the characters <code>" "</code>, <code>"l"</code> and <code>"W"</code>. + * + * Please note if the font was created via <code>Font.createFont(fontFormat, fontFile)</code> then + * <code>getCharWidth</code> for this font does not reproduce the bug JRE-426. + * + */ +public class Font426 { + + private static final int DEFAULT_SIZE = 12; + private static final FontRenderContext DEFAULT_CONTEXT = new FontRenderContext(null, false, false); + + private static int getCharWidth(Font font, char ch) { + if (font.canDisplay(ch)) { + Rectangle bounds = font.getStringBounds(new char[]{ch}, 0, 1, DEFAULT_CONTEXT).getBounds(); + if (!bounds.isEmpty()) return bounds.width; + } + return 0; + } + + private static int getFontWidth(Font font, int mask) { + if (mask != Font.PLAIN) { + //noinspection MagicConstant + font = font.deriveFont(mask ^ font.getStyle()); + System.out.println("noinspection MagicConstant"); + } + int width_ = getCharWidth(font, ' '); + int width_l = getCharWidth(font, 'l'); + int width_W = getCharWidth(font, 'W'); + System.out.print("\twidth \" \":" + width_ + " \"l\":" + width_l + " \"W\":" + width_W); + return width_ == width_l && width_ == width_W ? width_ : 0; + } + + private static void getFontInfo(Font font) { + Font derivedFont = font.deriveFont((float) DEFAULT_SIZE); + System.out.print("\t" + derivedFont.getFontName() + " - "); + getFontWidth(derivedFont, Font.PLAIN); + + } + + public static void main(String[] args) throws Exception { + Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); + + for (Font font : fonts) { + getFontInfo(font); + System.out.println(); + } + } +}
\ No newline at end of file diff --git a/test/jb/java/awt/Font/font426.sh b/test/jb/java/awt/Font/font426.sh new file mode 100644 index 0000000000..cca85ba269 --- /dev/null +++ b/test/jb/java/awt/Font/font426.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# +# Copyright 2000-2017 JetBrains s.r.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# @test +# @summary font426.sh checks the Chinese font 华康彩带 (DFCaiDai) +# @run shell font426.sh + +OS=`uname -s` +case "$OS" in + Darwin) + echo "Detected OS $OS" + FONT_DIR="~/Library/Fonts" + ;; + * ) + echo "PASSED: The test is valid for MacOSX" + exit 0; + ;; +esac + +if [ -z "${TESTSRC}" ]; then + echo "TESTSRC undefined: set to ." + TESTSRC=. +fi + +cp -r ${TESTSRC}/fonts/DFCaiDai.ttf ${FONT_DIR} + +if [ -z "${TESTCLASSES}" ]; then + echo "TESTCLASSES undefined: set to ." + TESTCLASSES=. +fi + +if [ -z "${TESTJAVA}" ]; then + echo "TESTJAVA undefined: testing cancelled" + exit 1 +fi + +cd ${TESTSRC} +${TESTJAVA}/bin/javac -d ${TESTCLASSES} Font426.java + +${TESTJAVA}/bin/java -cp ${TESTCLASSES} Font426 + +exit_code=$? + +case $exit_code in +0) echo "PASSED" + ;; +*) echo "FAILED: $exit_code" + exit 1 + ;; +esac +exit 0 diff --git a/test/jb/java/awt/Font/fonts/DFCaiDai.ttf b/test/jb/java/awt/Font/fonts/DFCaiDai.ttf Binary files differnew file mode 100644 index 0000000000..b89e3a8112 --- /dev/null +++ b/test/jb/java/awt/Font/fonts/DFCaiDai.ttf |