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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package com.sun.java.swing.plaf.gtk;
27
28 import java.awt.*;
29 import java.awt.geom.AffineTransform;
30 import javax.swing.plaf.FontUIResource;
31 import java.util.StringTokenizer;
32 import sun.font.FontManager;
33
34 /**
35 * @author Shannon Hickey
36 * @author Leif Samuelsson
37 */
38 class PangoFonts {
39
40 public static final String CHARS_DIGITS = "0123456789";
41
42 /**
43 * Calculate a default scale factor for fonts in this L&F to match
44 * the reported resolution of the screen.
45 * Java 2D specified a default user-space scale of 72dpi.
46 * This is unlikely to correspond to that of the real screen.
47 * The Xserver reports a value which may be used to adjust for this.
48 * and Java 2D exposes it via a normalizing transform.
49 * However many Xservers report a hard-coded 90dpi whilst others report a
50 * calculated value based on possibly incorrect data.
51 * That is something that must be solved at the X11 level
52 * Note that in an X11 multi-screen environment, the default screen
53 * is the one used by the JRE so it is safe to use it here.
176 }
177 /* The Java rasteriser assumes pts are in a user space of
178 * 72 dpi, so we need to adjust for that.
179 */
180 dsize = ((double)(dpi * size)/ 72.0);
181 } else {
182 /* If there's no property, GTK scales for the resolution
183 * reported by the Xserver using the formula listed above.
184 * fontScale already accounts for the 72 dpi Java 2D space.
185 */
186 dsize = size * fontScale;
187 }
188
189 /* Round size to nearest integer pt size */
190 size = (int)(dsize + 0.5);
191 if (size < 1) {
192 size = 1;
193 }
194
195 String fcFamilyLC = family.toLowerCase();
196 if (FontManager.mapFcName(fcFamilyLC) != null) {
197 /* family is a Fc/Pango logical font which we need to expand. */
198 return FontManager.getFontConfigFUIR(fcFamilyLC, style, size);
199 } else {
200 /* It's a physical font which we will create with a fallback */
201 Font font = new FontUIResource(family, style, size);
202 return FontManager.getCompositeFontUIResource(font);
203 }
204 }
205
206 /**
207 * Parses a String containing a pango font description and returns
208 * the (unscaled) font size as an integer.
209 *
210 * @param pangoName a String describing a pango font
211 * @return the size of the font described by pangoName (e.g. if
212 * pangoName is "Sans Italic 10", then this method returns 10)
213 */
214 static int getFontSize(String pangoName) {
215 int size = 10;
216
217 StringTokenizer tok = new StringTokenizer(pangoName);
218 while (tok.hasMoreTokens()) {
219 String word = tok.nextToken();
220
221 if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
222 try {
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package com.sun.java.swing.plaf.gtk;
27
28 import java.awt.*;
29 import java.awt.geom.AffineTransform;
30 import javax.swing.plaf.FontUIResource;
31 import java.util.StringTokenizer;
32
33 import sun.font.FontConfigManager;
34 import sun.font.FontUtilities;
35
36 /**
37 * @author Shannon Hickey
38 * @author Leif Samuelsson
39 */
40 class PangoFonts {
41
42 public static final String CHARS_DIGITS = "0123456789";
43
44 /**
45 * Calculate a default scale factor for fonts in this L&F to match
46 * the reported resolution of the screen.
47 * Java 2D specified a default user-space scale of 72dpi.
48 * This is unlikely to correspond to that of the real screen.
49 * The Xserver reports a value which may be used to adjust for this.
50 * and Java 2D exposes it via a normalizing transform.
51 * However many Xservers report a hard-coded 90dpi whilst others report a
52 * calculated value based on possibly incorrect data.
53 * That is something that must be solved at the X11 level
54 * Note that in an X11 multi-screen environment, the default screen
55 * is the one used by the JRE so it is safe to use it here.
178 }
179 /* The Java rasteriser assumes pts are in a user space of
180 * 72 dpi, so we need to adjust for that.
181 */
182 dsize = ((double)(dpi * size)/ 72.0);
183 } else {
184 /* If there's no property, GTK scales for the resolution
185 * reported by the Xserver using the formula listed above.
186 * fontScale already accounts for the 72 dpi Java 2D space.
187 */
188 dsize = size * fontScale;
189 }
190
191 /* Round size to nearest integer pt size */
192 size = (int)(dsize + 0.5);
193 if (size < 1) {
194 size = 1;
195 }
196
197 String fcFamilyLC = family.toLowerCase();
198 if (FontConfigManager.mapFcName(fcFamilyLC) != null) {
199 /* family is a Fc/Pango logical font which we need to expand. */
200 return FontUtilities.getFontConfigFUIR(fcFamilyLC, style, size);
201 } else {
202 /* It's a physical font which we will create with a fallback */
203 Font font = new FontUIResource(family, style, size);
204 return FontUtilities.getCompositeFontUIResource(font);
205 }
206 }
207
208 /**
209 * Parses a String containing a pango font description and returns
210 * the (unscaled) font size as an integer.
211 *
212 * @param pangoName a String describing a pango font
213 * @return the size of the font described by pangoName (e.g. if
214 * pangoName is "Sans Italic 10", then this method returns 10)
215 */
216 static int getFontSize(String pangoName) {
217 int size = 10;
218
219 StringTokenizer tok = new StringTokenizer(pangoName);
220 while (tok.hasMoreTokens()) {
221 String word = tok.nextToken();
222
223 if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
224 try {
|