jdk/src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6509 ea7fb80902b3
child 22567 5816a47fa4dd
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6509
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.gtk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.FontUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.StringTokenizer;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    32
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    33
import sun.font.FontConfigManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    34
import sun.font.FontUtilities;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Shannon Hickey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class PangoFonts {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static final String CHARS_DIGITS = "0123456789";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Calculate a default scale factor for fonts in this L&F to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * the reported resolution of the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Java 2D specified a default user-space scale of 72dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * This is unlikely to correspond to that of the real screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * The Xserver reports a value which may be used to adjust for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * and Java 2D exposes it via a normalizing transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * However many Xservers report a hard-coded 90dpi whilst others report a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * calculated value based on possibly incorrect data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * That is something that must be solved at the X11 level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Note that in an X11 multi-screen environment, the default screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * is the one used by the JRE so it is safe to use it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static double fontScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        fontScale = 1.0d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
           GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (!ge.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            GraphicsConfiguration gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                ge.getDefaultScreenDevice().getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            AffineTransform at = gc.getNormalizingTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            fontScale = at.getScaleY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Parses a String containing a pango font description and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * a Font object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param pangoName a String describing a pango font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *                  e.g. "Sans Italic 10"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return a Font object as a FontUIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *         or null if no suitable font could be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    static Font lookupFont(String pangoName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String family = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int size = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        StringTokenizer tok = new StringTokenizer(pangoName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            String word = tok.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (word.equalsIgnoreCase("italic")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                style |= Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            } else if (word.equalsIgnoreCase("bold")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                style |= Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } else if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    size = Integer.parseInt(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                if (family.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    family += " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                family += word;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * Java 2D font point sizes are in a user-space scale of 72dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * GTK allows a user to configure a "dpi" property used to scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * the fonts used to match a user's preference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * To match the font size of GTK apps we need to obtain this DPI and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * adjust as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * Some versions of GTK use XSETTINGS if available to dynamically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * monitor user-initiated changes in the DPI to be used by GTK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * apps. This value is also made available as the Xft.dpi X resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * This is presumably a function of the font preferences API and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * the manner in which it requests the toolkit to update the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * for the desktop. This dual approach is probably necessary since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * other versions of GTK - or perhaps some apps - determine the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * to use only at start-up from that X resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * If that resource is not set then GTK scales for the DPI resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * reported by the Xserver using the formula
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * DisplayHeight(dpy, screen) / DisplayHeightMM(dpy, screen) * 25.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * (25.4mm == 1 inch).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * JDK tracks the Xft.dpi XSETTINGS property directly so it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * dynamically change font size by tracking just that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * If that resource is not available use the same fall back formula
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         * as GTK (see calculation for fontScale).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * GTK's default setting for Xft.dpi is 96 dpi (and it seems -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         * apparently also can mean that "default"). However this default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * isn't used if there's no property set. The real default in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * absence of a resource is the Xserver reported dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         * Finally this DPI is used to calculate the nearest Java 2D font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         * 72 dpi font size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         * There are cases in which JDK behaviour may not exactly mimic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * GTK native app behaviour :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * 1) When a GTK app is not able to dynamically track the changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * (does not use XSETTINGS), JDK will resize but other apps will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * not. This is OK as JDK is exhibiting preferred behaviour and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * this is probably how all later GTK apps will behave
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * 2) When a GTK app does not use XSETTINGS and for some reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * the XRDB property is not present. JDK will pick up XSETTINGS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * and the GTK app will use the Xserver default. Since its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * impossible for JDK to know that some other GTK app is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * using XSETTINGS its impossible to account for this and in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * case for it to be a problem the values would have to be different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * It also seems unlikely to arise except when a user explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * deletes the X resource database entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * There also some other issues to be aware of for the future:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * GTK specifies the Xft.dpi value as server-wide which when used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * on systems with 2 distinct X screens with different physical DPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * the font sizes will inevitably appear different. It would have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * been a more user-friendly design to further adjust that one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * setting depending on the screen resolution to achieve perceived
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * equivalent sizes. If such a change were ever to be made in GTK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * we would need to update for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        double dsize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int dpi = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Object value =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            dpi = ((Integer)value).intValue() / 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (dpi == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
              dpi = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (dpi < 50) { /* 50 dpi is the minimum value gnome allows */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                dpi = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            /* The Java rasteriser assumes pts are in a user space of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
             * 72 dpi, so we need to adjust for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            dsize = ((double)(dpi * size)/ 72.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            /* If there's no property, GTK scales for the resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
             * reported by the Xserver using the formula listed above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             * fontScale already accounts for the 72 dpi Java 2D space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            dsize = size * fontScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /* Round size to nearest integer pt size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        size = (int)(dsize + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            size = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        String fcFamilyLC = family.toLowerCase();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   193
        if (FontUtilities.mapFcName(fcFamilyLC) != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            /* family is a Fc/Pango logical font which we need to expand. */
6509
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   195
            Font font =  FontUtilities.getFontConfigFUIR(fcFamilyLC, style, size);
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   196
            font = font.deriveFont(style, (float)dsize);
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   197
            return new FontUIResource(font);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            /* It's a physical font which we will create with a fallback */
6509
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   200
            Font font = new Font(family, style, size);
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   201
            /* a roundabout way to set the font size in floating points */
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   202
            font = font.deriveFont(style, (float)dsize);
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   203
            FontUIResource fuir = new FontUIResource(font);
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5506
diff changeset
   204
            return FontUtilities.getCompositeFontUIResource(fuir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Parses a String containing a pango font description and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * the (unscaled) font size as an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param pangoName a String describing a pango font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return the size of the font described by pangoName (e.g. if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *         pangoName is "Sans Italic 10", then this method returns 10)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    static int getFontSize(String pangoName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int size = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        StringTokenizer tok = new StringTokenizer(pangoName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            String word = tok.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    size = Integer.parseInt(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}