< prev index next >

src/java.desktop/share/classes/sun/java2d/SunGraphicsEnvironment.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 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
  23  * questions.
  24  */
  25 
  26 package sun.java2d;
  27 
  28 import java.awt.AWTError;
  29 import java.awt.Color;
  30 import java.awt.Font;
  31 import java.awt.Graphics2D;
  32 import java.awt.GraphicsConfiguration;
  33 import java.awt.GraphicsDevice;
  34 import java.awt.GraphicsEnvironment;
  35 import java.awt.Insets;

  36 import java.awt.Rectangle;
  37 import java.awt.Toolkit;
  38 import java.awt.font.TextAttribute;
  39 import java.awt.image.BufferedImage;
  40 import java.awt.peer.ComponentPeer;
  41 import java.io.BufferedReader;
  42 import java.io.File;
  43 import java.io.FileInputStream;
  44 import java.io.FilenameFilter;
  45 import java.io.InputStreamReader;
  46 import java.io.IOException;
  47 import java.text.AttributedCharacterIterator;
  48 import java.util.ArrayList;
  49 import java.util.HashSet;
  50 import java.util.Iterator;
  51 import java.util.Locale;
  52 import java.util.Map;
  53 import java.util.NoSuchElementException;
  54 import java.util.Set;
  55 import java.util.StringTokenizer;
  56 import java.util.TreeMap;
  57 import java.util.Vector;
  58 import java.util.concurrent.ConcurrentHashMap;
  59 import sun.awt.AppContext;
  60 import sun.awt.DisplayChangedListener;
  61 import sun.awt.FontConfiguration;
  62 import sun.awt.SunDisplayChanger;
  63 import sun.font.CompositeFontDescriptor;
  64 import sun.font.Font2D;
  65 import sun.font.FontManager;
  66 import sun.font.FontManagerFactory;
  67 import sun.font.FontManagerForSGE;
  68 import sun.font.NativeFont;
  69 import java.security.AccessController;
  70 import sun.security.action.GetPropertyAction;
  71 
  72 /**
  73  * This is an implementation of a GraphicsEnvironment object for the
  74  * default local GraphicsEnvironment.
  75  *
  76  * @see GraphicsDevice
  77  * @see GraphicsConfiguration
  78  */
  79 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
  80     implements DisplayChangedListener {
  81 
  82     public static boolean isOpenSolaris;
  83     private static Font defaultFont;
  84 
  85     private static final boolean uiScaleEnabled;
  86     private static final double debugScale;
  87 
  88     static {
  89         uiScaleEnabled = "true".equals(AccessController.doPrivileged(


 372 
 373         try {
 374             double units = 1.0;
 375 
 376             if (scaleFactor.endsWith("x")) {
 377                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
 378             } else if (scaleFactor.endsWith("dpi")) {
 379                 units = 96;
 380                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
 381             } else if (scaleFactor.endsWith("%")) {
 382                 units = 100;
 383                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
 384             }
 385 
 386             double scale = Double.parseDouble(scaleFactor);
 387             return scale <= 0 ? -1 : scale / units;
 388         } catch (NumberFormatException ignored) {
 389             return -1;
 390         }
 391     }












































 392 }
   1 /*
   2  * Copyright (c) 1997, 2018, 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
  23  * questions.
  24  */
  25 
  26 package sun.java2d;
  27 
  28 import java.awt.AWTError;
  29 import java.awt.Color;
  30 import java.awt.Font;
  31 import java.awt.Graphics2D;
  32 import java.awt.GraphicsConfiguration;
  33 import java.awt.GraphicsDevice;
  34 import java.awt.GraphicsEnvironment;
  35 import java.awt.Insets;
  36 import java.awt.Point;
  37 import java.awt.Rectangle;
  38 import java.awt.Toolkit;
  39 import java.awt.geom.AffineTransform;
  40 import java.awt.image.BufferedImage;
  41 import java.awt.peer.ComponentPeer;
  42 import java.io.BufferedReader;
  43 import java.io.File;
  44 import java.io.FileInputStream;

  45 import java.io.InputStreamReader;
  46 import java.security.AccessController;




  47 import java.util.Locale;




  48 import java.util.TreeMap;
  49 


  50 import sun.awt.DisplayChangedListener;

  51 import sun.awt.SunDisplayChanger;


  52 import sun.font.FontManager;
  53 import sun.font.FontManagerFactory;
  54 import sun.font.FontManagerForSGE;
  55 import sun.java2d.pipe.Region;

  56 import sun.security.action.GetPropertyAction;
  57 
  58 /**
  59  * This is an implementation of a GraphicsEnvironment object for the
  60  * default local GraphicsEnvironment.
  61  *
  62  * @see GraphicsDevice
  63  * @see GraphicsConfiguration
  64  */
  65 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
  66     implements DisplayChangedListener {
  67 
  68     public static boolean isOpenSolaris;
  69     private static Font defaultFont;
  70 
  71     private static final boolean uiScaleEnabled;
  72     private static final double debugScale;
  73 
  74     static {
  75         uiScaleEnabled = "true".equals(AccessController.doPrivileged(


 358 
 359         try {
 360             double units = 1.0;
 361 
 362             if (scaleFactor.endsWith("x")) {
 363                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
 364             } else if (scaleFactor.endsWith("dpi")) {
 365                 units = 96;
 366                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
 367             } else if (scaleFactor.endsWith("%")) {
 368                 units = 100;
 369                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
 370             }
 371 
 372             double scale = Double.parseDouble(scaleFactor);
 373             return scale <= 0 ? -1 : scale / units;
 374         } catch (NumberFormatException ignored) {
 375             return -1;
 376         }
 377     }
 378 
 379     /**
 380      * Returns the graphics configuration which bounds contain the given point.
 381      *
 382      * @param  current the default configuration which is checked in the first
 383      *         place
 384      * @param  x the x coordinate of the given point
 385      * @param  y the y coordinate of the given point
 386      * @return the graphics configuration
 387      */
 388     public static GraphicsConfiguration getGraphicsConfigurationAtPoint(
 389             GraphicsConfiguration current, double x, double y) {
 390         if (current.getBounds().contains(x, y)) {
 391             return current;
 392         }
 393         GraphicsEnvironment env = getLocalGraphicsEnvironment();
 394         for (GraphicsDevice device : env.getScreenDevices()) {
 395             GraphicsConfiguration config = device.getDefaultConfiguration();
 396             if (config.getBounds().contains(x, y)) {
 397                 return config;
 398             }
 399         }
 400         return current;
 401     }
 402 
 403     /**
 404      * Converts coordinates from the user's space to the device space using
 405      * appropriate device transformation.
 406      *
 407      * @param  x coordinate in the user space
 408      * @param  y coordinate in the user space
 409      * @return the point which uses device space(pixels)
 410      */
 411     public static Point convertToDeviceSpace(double x, double y) {
 412         GraphicsConfiguration gc = getLocalGraphicsEnvironment()
 413                         .getDefaultScreenDevice().getDefaultConfiguration();
 414         gc = getGraphicsConfigurationAtPoint(gc, x, y);
 415 
 416         AffineTransform tx = gc.getDefaultTransform();
 417         x = Region.clipRound(x * tx.getScaleX());
 418         y = Region.clipRound(y * tx.getScaleY());
 419 
 420         return new Point((int) x, (int) y);
 421     }
 422 }
< prev index next >