< prev index next >

src/java.desktop/share/classes/java/awt/Font.java

Print this page


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


 478             AttributeValues valuesTmp = new AttributeValues();
 479             valuesTmp.setFamily(name);
 480             valuesTmp.setSize(pointSize); // expects the float value.
 481 
 482             if ((style & BOLD) != 0) {
 483                 valuesTmp.setWeight(2); // WEIGHT_BOLD
 484             }
 485 
 486             if ((style & ITALIC) != 0) {
 487                 valuesTmp.setPosture(.2f); // POSTURE_OBLIQUE
 488             }
 489             valuesTmp.defineAll(PRIMARY_MASK); // for streaming compatibility
 490             values = valuesTmp;
 491         }
 492 
 493         return values;
 494     }
 495 
 496     private Font2D getFont2D() {
 497         FontManager fm = FontManagerFactory.getInstance();
 498         if (fm.usingPerAppContextComposites() &&
 499             font2DHandle != null &&
 500             font2DHandle.font2D instanceof CompositeFont &&
 501             ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
 502             return fm.findFont2D(name, style,
 503                                           FontManager.LOGICAL_FALLBACK);
 504         } else if (font2DHandle == null) {
 505             font2DHandle =
 506                 fm.findFont2D(name, style,
 507                               FontManager.LOGICAL_FALLBACK).handle;
 508         }
 509         /* Do not cache the de-referenced font2D. It must be explicitly
 510          * de-referenced to pick up a valid font in the event that the
 511          * original one is marked invalid
 512          */
 513         return font2DHandle.font2D;
 514     }
 515 
 516     /**
 517      * Creates a new {@code Font} from the specified name, style and
 518      * point size.
 519      * <p>
 520      * The font name can be a font face name or a font family name.
 521      * It is used together with the style to find an appropriate font face.
 522      * When a font family name is specified, the style argument is used to
 523      * select the most appropriate face from the family. When a font face
 524      * name is specified, the face's style and the style argument are


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


 478             AttributeValues valuesTmp = new AttributeValues();
 479             valuesTmp.setFamily(name);
 480             valuesTmp.setSize(pointSize); // expects the float value.
 481 
 482             if ((style & BOLD) != 0) {
 483                 valuesTmp.setWeight(2); // WEIGHT_BOLD
 484             }
 485 
 486             if ((style & ITALIC) != 0) {
 487                 valuesTmp.setPosture(.2f); // POSTURE_OBLIQUE
 488             }
 489             valuesTmp.defineAll(PRIMARY_MASK); // for streaming compatibility
 490             values = valuesTmp;
 491         }
 492 
 493         return values;
 494     }
 495 
 496     private Font2D getFont2D() {
 497         FontManager fm = FontManagerFactory.getInstance();
 498         if (font2DHandle == null) {






 499             font2DHandle =
 500                 fm.findFont2D(name, style,
 501                               FontManager.LOGICAL_FALLBACK).handle;
 502         }
 503         /* Do not cache the de-referenced font2D. It must be explicitly
 504          * de-referenced to pick up a valid font in the event that the
 505          * original one is marked invalid
 506          */
 507         return font2DHandle.font2D;
 508     }
 509 
 510     /**
 511      * Creates a new {@code Font} from the specified name, style and
 512      * point size.
 513      * <p>
 514      * The font name can be a font face name or a font family name.
 515      * It is used together with the style to find an appropriate font face.
 516      * When a font family name is specified, the style argument is used to
 517      * select the most appropriate face from the family. When a font face
 518      * name is specified, the face's style and the style argument are


< prev index next >