1 /*
2 * Copyright (c) 2011, 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. 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
79 {
80 return registerGenericFont(f, false);
81 }
82 public Font2D registerGenericFont(Font2D f, boolean logicalFont)
83 {
84 int rank = 4;
85
86 String fontName = f.fullName;
87 String familyName = f.familyName;
88
89 if (fontName == null || fontName.isEmpty()) {
90 return null;
91 }
92
93 // logical fonts always need to be added to the family
94 // plus they never need to be added to the generic font list
95 // or the fullNameToFont table since they are covers for
96 // already existing fonts in this list
97 if (logicalFont || !genericFonts.containsKey(fontName)) {
98 if (FontUtilities.debugFonts()) {
99 FontUtilities.getLogger().info("Add to Family "+familyName +
100 ", Font " + fontName + " rank="+rank);
101 }
102 FontFamily family = FontFamily.getFamily(familyName);
103 if (family == null) {
104 family = new FontFamily(familyName, false, rank);
105 family.setFont(f, f.style);
106 } else if (family.getRank() >= rank) {
107 family.setFont(f, f.style);
108 }
109 if (!logicalFont)
110 {
111 genericFonts.put(fontName, f);
112 fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
113 }
114 return f;
115 } else {
116 return genericFonts.get(fontName);
117 }
118 }
119
120 @Override
|
1 /*
2 * Copyright (c) 2011, 2020, 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
79 {
80 return registerGenericFont(f, false);
81 }
82 public Font2D registerGenericFont(Font2D f, boolean logicalFont)
83 {
84 int rank = 4;
85
86 String fontName = f.fullName;
87 String familyName = f.familyName;
88
89 if (fontName == null || fontName.isEmpty()) {
90 return null;
91 }
92
93 // logical fonts always need to be added to the family
94 // plus they never need to be added to the generic font list
95 // or the fullNameToFont table since they are covers for
96 // already existing fonts in this list
97 if (logicalFont || !genericFonts.containsKey(fontName)) {
98 if (FontUtilities.debugFonts()) {
99 FontUtilities.logInfo("Add to Family " + familyName +
100 ", Font " + fontName + " rank=" + rank);
101 }
102 FontFamily family = FontFamily.getFamily(familyName);
103 if (family == null) {
104 family = new FontFamily(familyName, false, rank);
105 family.setFont(f, f.style);
106 } else if (family.getRank() >= rank) {
107 family.setFont(f, f.style);
108 }
109 if (!logicalFont)
110 {
111 genericFonts.put(fontName, f);
112 fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
113 }
114 return f;
115 } else {
116 return genericFonts.get(fontName);
117 }
118 }
119
120 @Override
|