jdk/src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java
author dav
Mon, 07 Apr 2008 14:53:51 +0400
changeset 438 2ae294e4518c
parent 2 90ce3da70b43
child 3928 be186a33df9b
permissions -rw-r--r--
6613529: Avoid duplicate object creation within JDK packages Summary: avoid using constructors when unique values are not necessary Reviewed-by: volk, igor, peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.font.FontManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Shannon Hickey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class PangoFonts {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static final String CHARS_DIGITS = "0123456789";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Calculate a default scale factor for fonts in this L&F to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * the reported resolution of the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Java 2D specified a default user-space scale of 72dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * This is unlikely to correspond to that of the real screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * The Xserver reports a value which may be used to adjust for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * and Java 2D exposes it via a normalizing transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * However many Xservers report a hard-coded 90dpi whilst others report a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * calculated value based on possibly incorrect data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * That is something that must be solved at the X11 level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Note that in an X11 multi-screen environment, the default screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * is the one used by the JRE so it is safe to use it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static double fontScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        fontScale = 1.0d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
           GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (!ge.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            GraphicsConfiguration gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                ge.getDefaultScreenDevice().getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            AffineTransform at = gc.getNormalizingTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            fontScale = at.getScaleY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
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
     * Parses a String containing a pango font description and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * a Font object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param pangoName a String describing a pango font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *                  e.g. "Sans Italic 10"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return a Font object as a FontUIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *         or null if no suitable font could be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static Font lookupFont(String pangoName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        String family = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int size = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        StringTokenizer tok = new StringTokenizer(pangoName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            String word = tok.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (word.equalsIgnoreCase("italic")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                style |= Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            } else if (word.equalsIgnoreCase("bold")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                style |= Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            } else if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    size = Integer.parseInt(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                if (family.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    family += " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                family += word;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         * Java 2D font point sizes are in a user-space scale of 72dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * GTK allows a user to configure a "dpi" property used to scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * the fonts used to match a user's preference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * To match the font size of GTK apps we need to obtain this DPI and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * adjust as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * Some versions of GTK use XSETTINGS if available to dynamically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * monitor user-initiated changes in the DPI to be used by GTK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * apps. This value is also made available as the Xft.dpi X resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * This is presumably a function of the font preferences API and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * the manner in which it requests the toolkit to update the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * for the desktop. This dual approach is probably necessary since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * other versions of GTK - or perhaps some apps - determine the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * to use only at start-up from that X resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * If that resource is not set then GTK scales for the DPI resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * reported by the Xserver using the formula
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * DisplayHeight(dpy, screen) / DisplayHeightMM(dpy, screen) * 25.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * (25.4mm == 1 inch).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * JDK tracks the Xft.dpi XSETTINGS property directly so it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * dynamically change font size by tracking just that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * If that resource is not available use the same fall back formula
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * as GTK (see calculation for fontScale).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         * GTK's default setting for Xft.dpi is 96 dpi (and it seems -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * apparently also can mean that "default"). However this default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * isn't used if there's no property set. The real default in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         * absence of a resource is the Xserver reported dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * Finally this DPI is used to calculate the nearest Java 2D font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * 72 dpi font size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         * There are cases in which JDK behaviour may not exactly mimic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         * GTK native app behaviour :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         * 1) When a GTK app is not able to dynamically track the changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * (does not use XSETTINGS), JDK will resize but other apps will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * not. This is OK as JDK is exhibiting preferred behaviour and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * this is probably how all later GTK apps will behave
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * 2) When a GTK app does not use XSETTINGS and for some reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * the XRDB property is not present. JDK will pick up XSETTINGS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * and the GTK app will use the Xserver default. Since its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * impossible for JDK to know that some other GTK app is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * using XSETTINGS its impossible to account for this and in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * case for it to be a problem the values would have to be different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * It also seems unlikely to arise except when a user explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * deletes the X resource database entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * 3) Because of rounding errors sizes may differ very slightly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * between JDK and GTK. To fix that would at the very least require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * Swing to specify floating pt font sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * Eg "10 pts" for GTK at 96 dpi to get the same size at Java 2D's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * 72 dpi you'd need to specify exactly 13.33.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * There also some other issues to be aware of for the future:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * GTK specifies the Xft.dpi value as server-wide which when used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * on systems with 2 distinct X screens with different physical DPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * the font sizes will inevitably appear different. It would have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * been a more user-friendly design to further adjust that one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * setting depending on the screen resolution to achieve perceived
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * equivalent sizes. If such a change were ever to be made in GTK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * we would need to update for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        double dsize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int dpi = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Object value =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            dpi = ((Integer)value).intValue() / 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (dpi == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              dpi = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (dpi < 50) { /* 50 dpi is the minimum value gnome allows */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                dpi = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            /* The Java rasteriser assumes pts are in a user space of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             * 72 dpi, so we need to adjust for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            dsize = ((double)(dpi * size)/ 72.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            /* If there's no property, GTK scales for the resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             * reported by the Xserver using the formula listed above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             * fontScale already accounts for the 72 dpi Java 2D space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            dsize = size * fontScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /* Round size to nearest integer pt size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        size = (int)(dsize + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            size = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        String fcFamilyLC = family.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (FontManager.mapFcName(fcFamilyLC) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            /* family is a Fc/Pango logical font which we need to expand. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
           return FontManager.getFontConfigFUIR(fcFamilyLC, style, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            /* It's a physical font which we will create with a fallback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            Font font = new FontUIResource(family, style, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return FontManager.getCompositeFontUIResource(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Parses a String containing a pango font description and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * the (unscaled) font size as an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param pangoName a String describing a pango font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the size of the font described by pangoName (e.g. if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *         pangoName is "Sans Italic 10", then this method returns 10)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    static int getFontSize(String pangoName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int size = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        StringTokenizer tok = new StringTokenizer(pangoName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            String word = tok.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    size = Integer.parseInt(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}