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
23 * questions.
24 */
25
26 package sun.font;
27
28 import java.awt.Font;
29 import java.util.HashMap;
30 import java.util.concurrent.ConcurrentHashMap;
31 import java.util.Locale;
32
33 public class FontFamily {
34
35 private static ConcurrentHashMap<String, FontFamily>
36 familyNameMap = new ConcurrentHashMap<String, FontFamily>();
37 private static HashMap<String, FontFamily> allLocaleNames;
38
39 protected String familyName;
40 protected Font2D plain;
41 protected Font2D bold;
42 protected Font2D italic;
43 protected Font2D bolditalic;
44 protected boolean logicalFont = false;
45 protected int familyRank;
46
47 public static FontFamily getFamily(String name) {
88 familyNameMap.put(name.toLowerCase(Locale.ENGLISH), this);
89 }
90
91 /* Create a family for created fonts which aren't listed in the
92 * main map.
93 */
94 FontFamily(String name) {
95 logicalFont = false;
96 familyName = name;
97 familyRank = Font2D.DEFAULT_RANK;
98 }
99
100 public String getFamilyName() {
101 return familyName;
102 }
103
104 public int getRank() {
105 return familyRank;
106 }
107
108 public void setFont(Font2D font, int style) {
109 if (font.getRank() > familyRank) {
110 if (FontUtilities.isLogging()) {
111 FontUtilities.getLogger()
112 .warning("Rejecting adding " + font +
113 " of lower rank " + font.getRank() +
114 " to family " + this +
115 " of rank " + familyRank);
116 }
117 return;
118 }
119
120 switch (style) {
121
122 case Font.PLAIN:
123 plain = font;
124 break;
125
126 case Font.BOLD:
127 bold = font;
128 break;
129
|
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
23 * questions.
24 */
25
26 package sun.font;
27
28 import java.io.File;
29 import java.awt.Font;
30 import java.util.HashMap;
31 import java.util.concurrent.ConcurrentHashMap;
32 import java.util.Locale;
33
34 public class FontFamily {
35
36 private static ConcurrentHashMap<String, FontFamily>
37 familyNameMap = new ConcurrentHashMap<String, FontFamily>();
38 private static HashMap<String, FontFamily> allLocaleNames;
39
40 protected String familyName;
41 protected Font2D plain;
42 protected Font2D bold;
43 protected Font2D italic;
44 protected Font2D bolditalic;
45 protected boolean logicalFont = false;
46 protected int familyRank;
47
48 public static FontFamily getFamily(String name) {
89 familyNameMap.put(name.toLowerCase(Locale.ENGLISH), this);
90 }
91
92 /* Create a family for created fonts which aren't listed in the
93 * main map.
94 */
95 FontFamily(String name) {
96 logicalFont = false;
97 familyName = name;
98 familyRank = Font2D.DEFAULT_RANK;
99 }
100
101 public String getFamilyName() {
102 return familyName;
103 }
104
105 public int getRank() {
106 return familyRank;
107 }
108
109 private boolean isFromSameSource(Font2D font) {
110 if (!(font instanceof FileFont)) {
111 return false;
112 }
113
114 FileFont existingFont = null;
115 if (plain instanceof FileFont) {
116 existingFont = (FileFont)plain;
117 } else if (bold instanceof FileFont) {
118 existingFont = (FileFont)bold;
119 } else if (italic instanceof FileFont) {
120 existingFont = (FileFont)italic;
121 } else if (bolditalic instanceof FileFont) {
122 existingFont = (FileFont)bolditalic;
123 }
124 // A family isn't created until there's a font.
125 // So if we didn't find a file font it means this
126 // isn't a file-based family.
127 if (existingFont == null) {
128 return false;
129 }
130 File existDir = (new File(existingFont.platName)).getParentFile();
131
132 FileFont newFont = (FileFont)font;
133 File newDir = (new File(newFont.platName)).getParentFile();
134 return java.util.Objects.equals(newDir, existDir);
135 }
136
137 public void setFont(Font2D font, int style) {
138 /* Allow a lower-rank font only if its a file font
139 * from the exact same source as any previous font.
140 */
141 if ((font.getRank() > familyRank) && !isFromSameSource(font)) {
142 if (FontUtilities.isLogging()) {
143 FontUtilities.getLogger()
144 .warning("Rejecting adding " + font +
145 " of lower rank " + font.getRank() +
146 " to family " + this +
147 " of rank " + familyRank);
148 }
149 return;
150 }
151
152 switch (style) {
153
154 case Font.PLAIN:
155 plain = font;
156 break;
157
158 case Font.BOLD:
159 bold = font;
160 break;
161
|