Skip to content

Commit 9b80ea7

Browse files
committed
JBR-1945 Backport JDK-8223558 from OpenJDK
apply fix from OpenJDK
1 parent 58bad34 commit 9b80ea7

File tree

4 files changed

+217
-3
lines changed

4 files changed

+217
-3
lines changed

make/data/fontconfig/windows.fontconfig.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
#
3-
# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
44
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
#
66
# This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@ allfonts.chinese-hkscs=MingLiU_HKSCS
3838
allfonts.chinese-ms950-extb=MingLiU-ExtB
3939
allfonts.devanagari=Mangal
4040
allfonts.kannada=Tunga
41+
allfonts.myanmar=Myanmar Text
4142
allfonts.dingbats=Wingdings
4243
allfonts.symbol=Symbol
4344
allfonts.symbols=Segoe UI Symbol
@@ -239,7 +240,8 @@ sequence.allfonts.x-windows-874=alphabetic,thai,dingbats,symbol
239240

240241
sequence.fallback=symbols,\
241242
chinese-ms950,chinese-hkscs,chinese-ms936,chinese-gb18030,\
242-
japanese,korean,chinese-ms950-extb,chinese-ms936-extb,georgian,kannada
243+
japanese,korean,chinese-ms950-extb,chinese-ms936-extb,\
244+
georgian,kannada,myanmar
243245

244246
# Exclusion Ranges
245247

@@ -296,6 +298,7 @@ filename.GulimChe=gulim.TTC
296298
filename.DokChampa=dokchamp.ttf
297299
filename.Mangal=MANGAL.TTF
298300
filename.Tunga=TUNGA.TTF
301+
filename.Myanmar_Text=mmrtext.ttf
299302
filename.Symbol=SYMBOL.TTF
300303
filename.Wingdings=WINGDING.TTF
301304

src/java.desktop/share/classes/sun/font/FontUtilities.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2019, 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
@@ -272,6 +272,9 @@ else if (code < 0x0f00) {
272272
else if (code <= 0x0fff) { // U+0F00 - U+0FFF Tibetan
273273
return true;
274274
}
275+
else if (code < 0x10A0) { // U+1000 - U+109F Myanmar
276+
return true;
277+
}
275278
else if (code < 0x1100) {
276279
return false;
277280
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2019, 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 8223558
27+
* @summary Verifies Dialog logical font falls back to "Myanmar Text"
28+
* @requires (os.family == "windows")
29+
*/
30+
31+
import java.awt.Font;
32+
import java.awt.GraphicsEnvironment;
33+
import java.util.Arrays;
34+
35+
public class MyanmarFallbackTest {
36+
37+
public static void main(String[] args) {
38+
if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
39+
System.err.println("This test is for Windows only");
40+
return;
41+
}
42+
43+
String[] fontFamilyNames = GraphicsEnvironment
44+
.getLocalGraphicsEnvironment()
45+
.getAvailableFontFamilyNames();
46+
if (Arrays.stream(fontFamilyNames)
47+
.noneMatch("Myanmar Text"::equals)) {
48+
System.err.println("Myanmar Text font is not installed");
49+
return;
50+
}
51+
52+
Font dialog = new Font(Font.DIALOG, Font.PLAIN, 12);
53+
if (-1 != dialog.canDisplayUpTo("\u1000\u103C")) {
54+
throw new RuntimeException("Cannot display Myanmar characters");
55+
}
56+
}
57+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2019, 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 8223558
27+
* @key headful
28+
* @summary Verifies that Myanmar script is rendered correctly:
29+
* two characters combined into one glyph
30+
* @run main MyanmarTextTest
31+
*/
32+
33+
import java.awt.Font;
34+
import java.awt.GraphicsEnvironment;
35+
import java.util.Arrays;
36+
import javax.swing.BorderFactory;
37+
import javax.swing.BoxLayout;
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.JTextField;
41+
import javax.swing.SwingConstants;
42+
import javax.swing.SwingUtilities;
43+
import javax.swing.WindowConstants;
44+
import javax.swing.plaf.TextUI;
45+
import javax.swing.text.BadLocationException;
46+
import javax.swing.text.Position;
47+
48+
public class MyanmarTextTest {
49+
private static final String TEXT = "\u1000\u103C";
50+
51+
private static final String FONT_WINDOWS = "Myanmar Text";
52+
private static final String FONT_LINUX = "Padauk";
53+
private static final String FONT_MACOS = "Myanmar MN";
54+
55+
private static final String FONT_NAME = selectFontName();
56+
57+
private final JFrame frame;
58+
private final JTextField myanmarTF;
59+
60+
private static volatile MyanmarTextTest mtt;
61+
62+
public static void main(String[] args) throws Exception {
63+
if (FONT_NAME == null) {
64+
System.err.println("Unsupported OS: exiting");
65+
return;
66+
}
67+
if (!fontExists()) {
68+
System.err.println("Required font is not installed: " + FONT_NAME);
69+
return;
70+
}
71+
72+
try {
73+
SwingUtilities.invokeAndWait(MyanmarTextTest::createUI);
74+
SwingUtilities.invokeAndWait(mtt::checkPositions);
75+
} finally {
76+
SwingUtilities.invokeAndWait(mtt::dispose);
77+
}
78+
}
79+
80+
private static void createUI() {
81+
mtt = new MyanmarTextTest();
82+
mtt.show();
83+
}
84+
85+
private MyanmarTextTest() {
86+
frame = new JFrame("Myanmar Text");
87+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
88+
89+
myanmarTF = new JTextField(TEXT);
90+
myanmarTF.setFont(new Font(FONT_NAME, Font.PLAIN, 40));
91+
92+
JPanel main = new JPanel();
93+
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
94+
main.add(myanmarTF);
95+
96+
main.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
97+
98+
frame.getContentPane().add(main);
99+
}
100+
101+
private void show() {
102+
frame.pack();
103+
frame.setLocationByPlatform(true);
104+
frame.setVisible(true);
105+
}
106+
107+
private void dispose() {
108+
frame.dispose();
109+
}
110+
111+
private void checkPositions() {
112+
final TextUI ui = myanmarTF.getUI();
113+
final Position.Bias[] biasRet = new Position.Bias[1];
114+
try {
115+
if (2 != ui.getNextVisualPositionFrom(myanmarTF, 0,
116+
Position.Bias.Forward, SwingConstants.EAST, biasRet)) {
117+
throw new RuntimeException("For 0, next position should be 2");
118+
}
119+
if (2 != ui.getNextVisualPositionFrom(myanmarTF, 1,
120+
Position.Bias.Forward, SwingConstants.EAST, biasRet)) {
121+
throw new RuntimeException("For 1, next position should be 2");
122+
}
123+
if (0 != ui.getNextVisualPositionFrom(myanmarTF, 2,
124+
Position.Bias.Forward, SwingConstants.WEST, biasRet)) {
125+
throw new RuntimeException("For 2, prev position should be 0");
126+
}
127+
} catch (BadLocationException e) {
128+
throw new RuntimeException(e);
129+
}
130+
}
131+
132+
private static String selectFontName() {
133+
String osName = System.getProperty("os.name").toLowerCase();
134+
if (osName.contains("windows")) {
135+
return FONT_WINDOWS;
136+
} else if (osName.contains("linux")) {
137+
return FONT_LINUX;
138+
} else if (osName.contains("mac")) {
139+
return FONT_MACOS;
140+
} else {
141+
return null;
142+
}
143+
}
144+
145+
private static boolean fontExists() {
146+
String[] fontFamilyNames = GraphicsEnvironment
147+
.getLocalGraphicsEnvironment()
148+
.getAvailableFontFamilyNames();
149+
return Arrays.asList(fontFamilyNames).contains(FONT_NAME);
150+
}
151+
}

0 commit comments

Comments
 (0)