1 /*
2 * Copyright (c) 2003, 2014, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
597 }
598 if (familyName == null || fullName == null) {
599 throw new FontFormatException("Font name not found");
600 }
601 /* The os2_Table is needed to gather some info, but we don't
602 * want to keep it around (as a field) so obtain it once and
603 * pass it to the code that needs it.
604 */
605 ByteBuffer os2_Table = getTableBuffer(os_2Tag);
606 setStyle(os2_Table);
607 setCJKSupport(os2_Table);
608 }
609
610 /* The array index corresponds to a bit offset in the TrueType
611 * font's OS/2 compatibility table's code page ranges fields.
612 * These are two 32 bit unsigned int fields at offsets 78 and 82.
613 * We are only interested in determining if the font supports
614 * the windows encodings we expect as the default encoding in
615 * supported locales, so we only map the first of these fields.
616 */
617 static final String encoding_mapping[] = {
618 "cp1252", /* 0:Latin 1 */
619 "cp1250", /* 1:Latin 2 */
620 "cp1251", /* 2:Cyrillic */
621 "cp1253", /* 3:Greek */
622 "cp1254", /* 4:Turkish/Latin 5 */
623 "cp1255", /* 5:Hebrew */
624 "cp1256", /* 6:Arabic */
625 "cp1257", /* 7:Windows Baltic */
626 "", /* 8:reserved for alternate ANSI */
627 "", /* 9:reserved for alternate ANSI */
628 "", /* 10:reserved for alternate ANSI */
629 "", /* 11:reserved for alternate ANSI */
630 "", /* 12:reserved for alternate ANSI */
631 "", /* 13:reserved for alternate ANSI */
632 "", /* 14:reserved for alternate ANSI */
633 "", /* 15:reserved for alternate ANSI */
634 "ms874", /* 16:Thai */
635 "ms932", /* 17:JIS/Japanese */
636 "gbk", /* 18:PRC GBK Cp950 */
637 "ms949", /* 19:Korean Extended Wansung */
645 "", /* 27 */
646 "", /* 28 */
647 "", /* 29 */
648 "", /* 30 */
649 "", /* 31 */
650 };
651
652 /* This maps two letter language codes to a Windows code page.
653 * Note that eg Cp1252 (the first subarray) is not exactly the same as
654 * Latin-1 since Windows code pages are do not necessarily correspond.
655 * There are two codepages for zh and ko so if a font supports
656 * only one of these ranges then we need to distinguish based on
657 * country. So far this only seems to matter for zh.
658 * REMIND: Unicode locales such as Hindi do not have a code page so
659 * this whole mechanism needs to be revised to map languages to
660 * the Unicode ranges either when this fails, or as an additional
661 * validating test. Basing it on Unicode ranges should get us away
662 * from needing to map to this small and incomplete set of Windows
663 * code pages which looks odd on non-Windows platforms.
664 */
665 private static final String languages[][] = {
666
667 /* cp1252/Latin 1 */
668 { "en", "ca", "da", "de", "es", "fi", "fr", "is", "it",
669 "nl", "no", "pt", "sq", "sv", },
670
671 /* cp1250/Latin2 */
672 { "cs", "cz", "et", "hr", "hu", "nr", "pl", "ro", "sk",
673 "sl", "sq", "sr", },
674
675 /* cp1251/Cyrillic */
676 { "bg", "mk", "ru", "sh", "uk" },
677
678 /* cp1253/Greek*/
679 { "el" },
680
681 /* cp1254/Turkish,Latin 5 */
682 { "tr" },
683
684 /* cp1255/Hebrew */
685 { "he" },
692
693 /* ms874/Thai */
694 { "th" },
695
696 /* ms932/Japanese */
697 { "ja" },
698
699 /* gbk/Chinese (PRC GBK Cp950) */
700 { "zh", "zh_CN", },
701
702 /* ms949/Korean Extended Wansung */
703 { "ko" },
704
705 /* ms950/Chinese (Taiwan, Hongkong, Macau) */
706 { "zh_HK", "zh_TW", },
707
708 /* ms1361/Korean Johab */
709 { "ko" },
710 };
711
712 private static final String codePages[] = {
713 "cp1252",
714 "cp1250",
715 "cp1251",
716 "cp1253",
717 "cp1254",
718 "cp1255",
719 "cp1256",
720 "cp1257",
721 "ms874",
722 "ms932",
723 "gbk",
724 "ms949",
725 "ms950",
726 "ms1361",
727 };
728
729 private static String defaultCodePage = null;
730 static String getCodePage() {
731
732 if (defaultCodePage != null) {
|
1 /*
2 * Copyright (c) 2003, 2018, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
597 }
598 if (familyName == null || fullName == null) {
599 throw new FontFormatException("Font name not found");
600 }
601 /* The os2_Table is needed to gather some info, but we don't
602 * want to keep it around (as a field) so obtain it once and
603 * pass it to the code that needs it.
604 */
605 ByteBuffer os2_Table = getTableBuffer(os_2Tag);
606 setStyle(os2_Table);
607 setCJKSupport(os2_Table);
608 }
609
610 /* The array index corresponds to a bit offset in the TrueType
611 * font's OS/2 compatibility table's code page ranges fields.
612 * These are two 32 bit unsigned int fields at offsets 78 and 82.
613 * We are only interested in determining if the font supports
614 * the windows encodings we expect as the default encoding in
615 * supported locales, so we only map the first of these fields.
616 */
617 static final String[] encoding_mapping = {
618 "cp1252", /* 0:Latin 1 */
619 "cp1250", /* 1:Latin 2 */
620 "cp1251", /* 2:Cyrillic */
621 "cp1253", /* 3:Greek */
622 "cp1254", /* 4:Turkish/Latin 5 */
623 "cp1255", /* 5:Hebrew */
624 "cp1256", /* 6:Arabic */
625 "cp1257", /* 7:Windows Baltic */
626 "", /* 8:reserved for alternate ANSI */
627 "", /* 9:reserved for alternate ANSI */
628 "", /* 10:reserved for alternate ANSI */
629 "", /* 11:reserved for alternate ANSI */
630 "", /* 12:reserved for alternate ANSI */
631 "", /* 13:reserved for alternate ANSI */
632 "", /* 14:reserved for alternate ANSI */
633 "", /* 15:reserved for alternate ANSI */
634 "ms874", /* 16:Thai */
635 "ms932", /* 17:JIS/Japanese */
636 "gbk", /* 18:PRC GBK Cp950 */
637 "ms949", /* 19:Korean Extended Wansung */
645 "", /* 27 */
646 "", /* 28 */
647 "", /* 29 */
648 "", /* 30 */
649 "", /* 31 */
650 };
651
652 /* This maps two letter language codes to a Windows code page.
653 * Note that eg Cp1252 (the first subarray) is not exactly the same as
654 * Latin-1 since Windows code pages are do not necessarily correspond.
655 * There are two codepages for zh and ko so if a font supports
656 * only one of these ranges then we need to distinguish based on
657 * country. So far this only seems to matter for zh.
658 * REMIND: Unicode locales such as Hindi do not have a code page so
659 * this whole mechanism needs to be revised to map languages to
660 * the Unicode ranges either when this fails, or as an additional
661 * validating test. Basing it on Unicode ranges should get us away
662 * from needing to map to this small and incomplete set of Windows
663 * code pages which looks odd on non-Windows platforms.
664 */
665 private static final String[][] languages = {
666
667 /* cp1252/Latin 1 */
668 { "en", "ca", "da", "de", "es", "fi", "fr", "is", "it",
669 "nl", "no", "pt", "sq", "sv", },
670
671 /* cp1250/Latin2 */
672 { "cs", "cz", "et", "hr", "hu", "nr", "pl", "ro", "sk",
673 "sl", "sq", "sr", },
674
675 /* cp1251/Cyrillic */
676 { "bg", "mk", "ru", "sh", "uk" },
677
678 /* cp1253/Greek*/
679 { "el" },
680
681 /* cp1254/Turkish,Latin 5 */
682 { "tr" },
683
684 /* cp1255/Hebrew */
685 { "he" },
692
693 /* ms874/Thai */
694 { "th" },
695
696 /* ms932/Japanese */
697 { "ja" },
698
699 /* gbk/Chinese (PRC GBK Cp950) */
700 { "zh", "zh_CN", },
701
702 /* ms949/Korean Extended Wansung */
703 { "ko" },
704
705 /* ms950/Chinese (Taiwan, Hongkong, Macau) */
706 { "zh_HK", "zh_TW", },
707
708 /* ms1361/Korean Johab */
709 { "ko" },
710 };
711
712 private static final String[] codePages = {
713 "cp1252",
714 "cp1250",
715 "cp1251",
716 "cp1253",
717 "cp1254",
718 "cp1255",
719 "cp1256",
720 "cp1257",
721 "ms874",
722 "ms932",
723 "gbk",
724 "ms949",
725 "ms950",
726 "ms1361",
727 };
728
729 private static String defaultCodePage = null;
730 static String getCodePage() {
731
732 if (defaultCodePage != null) {
|