modules/graphics/src/main/java/javafx/css/SizeUnits.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
   1 /*
   2  * Copyright (c) 2008, 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 com.sun.javafx.css;
  27 
  28 import javafx.scene.text.Font;
  29 
  30 /**
  31  * Represents a size specified in a particular unit, such as 14px or 0.2em.


  32  */
  33 public enum SizeUnits {
  34     
  35     PERCENT(false) {
  36 
  37         @Override
  38         public String toString() { return "%"; }
  39 
  40         @Override
  41         public double points(double value, double multiplier, Font font_not_used) {
  42             return (value/100.0) * multiplier;
  43         }
  44 
  45         @Override
  46         public double pixels(double value, double multiplier, Font font_not_used) {
  47             return (value/100.0) * multiplier;
  48         }
  49 
  50     },
  51     IN(true) {


 266 
 267     },
 268 
 269     MS(true) {
 270 
 271         @Override
 272         public String toString() { return "ms"; }
 273 
 274         @Override
 275         public double points(double value, double multiplier_not_used, Font font_not_used) {
 276             return value;
 277         }
 278 
 279         @Override
 280         public double pixels(double value, double multiplier_not_used, Font font_not_used) {
 281             return value;
 282         }
 283 
 284     };
 285 
 286     abstract double points(double value, double multiplier, Font font);
 287     abstract double pixels(double value, double multiplier, Font font);
 288 
 289     private SizeUnits(boolean absolute) {
 290         this.absolute = absolute;
 291     }
 292 
 293     private final boolean absolute;
 294     public boolean isAbsolute() {
 295         return absolute;
 296     }
 297 
 298     // RT-14711: The spec says 1px is equal to 0.75pt
 299     //           72 / 0.75 = 96
 300     static final private double DOTS_PER_INCH = 96.0;
 301     static final private double POINTS_PER_INCH = 72.0;
 302     static final private double CM_PER_INCH = 2.54;
 303     static final private double MM_PER_INCH = CM_PER_INCH * 10;
 304     static final private double POINTS_PER_PICA = 12.0;
 305 
 306     /* Get the font size in points */
 307     private static double pointSize(Font font) {
   1 /*
   2  * Copyright (c) 2008, 2015, 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 javafx.css;
  27 
  28 import javafx.scene.text.Font;
  29 
  30 /**
  31  * Represents a size specified in a particular unit, such as 14px or 0.2em.
  32  *
  33  * @since 9
  34  */
  35 public enum SizeUnits {
  36     
  37     PERCENT(false) {
  38 
  39         @Override
  40         public String toString() { return "%"; }
  41 
  42         @Override
  43         public double points(double value, double multiplier, Font font_not_used) {
  44             return (value/100.0) * multiplier;
  45         }
  46 
  47         @Override
  48         public double pixels(double value, double multiplier, Font font_not_used) {
  49             return (value/100.0) * multiplier;
  50         }
  51 
  52     },
  53     IN(true) {


 268 
 269     },
 270 
 271     MS(true) {
 272 
 273         @Override
 274         public String toString() { return "ms"; }
 275 
 276         @Override
 277         public double points(double value, double multiplier_not_used, Font font_not_used) {
 278             return value;
 279         }
 280 
 281         @Override
 282         public double pixels(double value, double multiplier_not_used, Font font_not_used) {
 283             return value;
 284         }
 285 
 286     };
 287 
 288     public abstract double points(double value, double multiplier, Font font);
 289     public abstract double pixels(double value, double multiplier, Font font);
 290 
 291     private SizeUnits(boolean absolute) {
 292         this.absolute = absolute;
 293     }
 294 
 295     private final boolean absolute;
 296     public boolean isAbsolute() {
 297         return absolute;
 298     }
 299 
 300     // RT-14711: The spec says 1px is equal to 0.75pt
 301     //           72 / 0.75 = 96
 302     static final private double DOTS_PER_INCH = 96.0;
 303     static final private double POINTS_PER_INCH = 72.0;
 304     static final private double CM_PER_INCH = 2.54;
 305     static final private double MM_PER_INCH = CM_PER_INCH * 10;
 306     static final private double POINTS_PER_PICA = 12.0;
 307 
 308     /* Get the font size in points */
 309     private static double pointSize(Font font) {