< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2019, 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.security.AccessController;
  43 import java.util.Locale;
  44 import java.util.TreeMap;
  45 
  46 import sun.awt.DisplayChangedListener;
  47 import sun.awt.SunDisplayChanger;
  48 import sun.font.FontManager;
  49 import sun.font.FontManagerFactory;
  50 import sun.font.FontManagerForSGE;
  51 import sun.java2d.pipe.Region;
  52 import sun.security.action.GetPropertyAction;
  53 
  54 /**
  55  * This is an implementation of a GraphicsEnvironment object for the
  56  * default local GraphicsEnvironment.
  57  *
  58  * @see GraphicsDevice
  59  * @see GraphicsConfiguration
  60  */
  61 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
  62     implements DisplayChangedListener {
  63 
  64     /** Establish the default font to be used by SG2D. */
  65     private final Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
  66 
  67     private static final boolean uiScaleEnabled;
  68     private static final double debugScale;
  69 
  70     static {
  71         uiScaleEnabled = "true".equals(AccessController.doPrivileged(
  72                 new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
  73         debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1;
















































  74     }
  75 
  76     protected GraphicsDevice[] screens;
  77 
  78     /**
  79      * Returns an array of all of the screen devices.
  80      */
  81     public synchronized GraphicsDevice[] getScreenDevices() {
  82         GraphicsDevice[] ret = screens;
  83         if (ret == null) {
  84             int num = getNumScreens();
  85             ret = new GraphicsDevice[num];
  86             for (int i = 0; i < num; i++) {
  87                 ret[i] = makeScreenDevice(i);
  88             }
  89             screens = ret;
  90         }
  91         return ret;
  92     }
  93 


   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(
  76                 new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
  77         debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1;
  78     }
  79 
  80     public SunGraphicsEnvironment() {
  81         java.security.AccessController.doPrivileged(
  82                                     new java.security.PrivilegedAction<Object>() {
  83             public Object run() {
  84                 String osName = System.getProperty("os.name");
  85                 if ("SunOS".equals(osName)) {
  86                     String version = System.getProperty("os.version", "0.0");
  87                     try {
  88                         float ver = Float.parseFloat(version);
  89                         if (ver > 5.10f) {
  90                             File f = new File("/etc/release");
  91                             FileInputStream fis = new FileInputStream(f);
  92                             InputStreamReader isr
  93                                 = new InputStreamReader(fis, "ISO-8859-1");
  94                             BufferedReader br = new BufferedReader(isr);
  95                             String line = br.readLine();
  96                             if (line.indexOf("OpenSolaris") >= 0) {
  97                                 isOpenSolaris = true;
  98                             } else {
  99                                 /* We are using isOpenSolaris as meaning
 100                                  * we know the Solaris commercial fonts aren't
 101                                  * present. "Solaris Next" (03/10) did not
 102                                  * include these even though its was not
 103                                  * OpenSolaris. Need to revisit how this is
 104                                  * handled but for now as in 6ux, we'll use
 105                                  * the test for a standard font resource as
 106                                  * being an indicator as to whether we need
 107                                  * to treat this as OpenSolaris from a font
 108                                  * config perspective.
 109                                  */
 110                                 String courierNew =
 111                                     "/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf";
 112                                 File courierFile = new File(courierNew);
 113                                 isOpenSolaris = !courierFile.exists();
 114                             }
 115                             fis.close();
 116                         }
 117                     } catch (Exception e) {
 118                     }
 119                 }
 120                 /* Establish the default font to be used by SG2D etc */
 121                 defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
 122 
 123                 return null;
 124             }
 125         });
 126     }
 127 
 128     protected GraphicsDevice[] screens;
 129 
 130     /**
 131      * Returns an array of all of the screen devices.
 132      */
 133     public synchronized GraphicsDevice[] getScreenDevices() {
 134         GraphicsDevice[] ret = screens;
 135         if (ret == null) {
 136             int num = getNumScreens();
 137             ret = new GraphicsDevice[num];
 138             for (int i = 0; i < num; i++) {
 139                 ret[i] = makeScreenDevice(i);
 140             }
 141             screens = ret;
 142         }
 143         return ret;
 144     }
 145 


< prev index next >