src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2010, 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


  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.
  56      */
  57     private static double fontScale;
  58 
  59     static {
  60         fontScale = 1.0d;
  61         GraphicsEnvironment ge =
  62            GraphicsEnvironment.getLocalGraphicsEnvironment();
  63 
  64         if (!ge.isHeadless()) {
  65             GraphicsConfiguration gc =
  66                 ge.getDefaultScreenDevice().getDefaultConfiguration();
  67             AffineTransform at = gc.getNormalizingTransform();
  68             fontScale = at.getScaleY();
  69         }
  70     }
  71 
  72 
  73     /**
  74      * Parses a String containing a pango font description and returns
  75      * a Font object.
  76      *
  77      * @param pangoName a String describing a pango font
  78      *                  e.g. "Sans Italic 10"
  79      * @return a Font object as a FontUIResource
  80      *         or null if no suitable font could be created.
  81      */
  82     static Font lookupFont(String pangoName) {
  83         String family = "";
  84         int style = Font.PLAIN;


   1 /*
   2  * Copyright (c) 2002, 2014, 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


  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.
  56      */
  57     private static double fontScale;
  58 
  59     static {
  60         fontScale = 1.0d;
  61         GraphicsEnvironment ge =
  62            GraphicsEnvironment.getLocalGraphicsEnvironment();
  63 
  64         if (!GraphicsEnvironment.isHeadless()) {
  65             GraphicsConfiguration gc =
  66                 ge.getDefaultScreenDevice().getDefaultConfiguration();
  67             AffineTransform at = gc.getNormalizingTransform();
  68             fontScale = at.getScaleY();
  69         }
  70     }
  71 
  72 
  73     /**
  74      * Parses a String containing a pango font description and returns
  75      * a Font object.
  76      *
  77      * @param pangoName a String describing a pango font
  78      *                  e.g. "Sans Italic 10"
  79      * @return a Font object as a FontUIResource
  80      *         or null if no suitable font could be created.
  81      */
  82     static Font lookupFont(String pangoName) {
  83         String family = "";
  84         int style = Font.PLAIN;