< prev index next >

src/java.desktop/share/classes/sun/font/Font2D.java

Print this page


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


 388             if (o == null) {
 389                 strikeCache.remove(desc);
 390             }
 391         }
 392     }
 393 
 394     /**
 395      * The length of the metrics array must be >= 8.  This method will
 396      * store the following elements in that array before returning:
 397      *    metrics[0]: ascent
 398      *    metrics[1]: descent
 399      *    metrics[2]: leading
 400      *    metrics[3]: max advance
 401      *    metrics[4]: strikethrough offset
 402      *    metrics[5]: strikethrough thickness
 403      *    metrics[6]: underline offset
 404      *    metrics[7]: underline thickness
 405      */
 406     public void getFontMetrics(Font font, AffineTransform at,
 407                                Object aaHint, Object fmHint,
 408                                float metrics[]) {
 409         /* This is called in just one place in Font with "at" == identity.
 410          * Perhaps this can be eliminated.
 411          */
 412         int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, font.getSize());
 413         int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
 414         FontStrike strike = getStrike(font, at, aa, fm);
 415         StrikeMetrics strikeMetrics = strike.getFontMetrics();
 416         metrics[0] = strikeMetrics.getAscent();
 417         metrics[1] = strikeMetrics.getDescent();
 418         metrics[2] = strikeMetrics.getLeading();
 419         metrics[3] = strikeMetrics.getMaxAdvance();
 420 
 421         getStyleMetrics(font.getSize2D(), metrics, 4);
 422     }
 423 
 424     /**
 425      * The length of the metrics array must be >= offset+4, and offset must be
 426      * >= 0.  Typically offset is 4.  This method will
 427      * store the following elements in that array before returning:
 428      *    metrics[off+0]: strikethrough offset


 432      *
 433      * Note that this implementation simply returns default values;
 434      * subclasses can override this method to provide more accurate values.
 435      */
 436     public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
 437         metrics[offset] = -metrics[0] / 2.5f;
 438         metrics[offset+1] = pointSize / 12;
 439         metrics[offset+2] = metrics[offset+1] / 1.5f;
 440         metrics[offset+3] = metrics[offset+1];
 441     }
 442 
 443     /**
 444      * The length of the metrics array must be >= 4.  This method will
 445      * store the following elements in that array before returning:
 446      *    metrics[0]: ascent
 447      *    metrics[1]: descent
 448      *    metrics[2]: leading
 449      *    metrics[3]: max advance
 450      */
 451     public void getFontMetrics(Font font, FontRenderContext frc,
 452                                float metrics[]) {
 453         StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
 454         metrics[0] = strikeMetrics.getAscent();
 455         metrics[1] = strikeMetrics.getDescent();
 456         metrics[2] = strikeMetrics.getLeading();
 457         metrics[3] = strikeMetrics.getMaxAdvance();
 458     }
 459 
 460     /* Currently the layout code calls this. May be better for layout code
 461      * to check the font class before attempting to run, rather than needing
 462      * to promote this method up from TrueTypeFont
 463      */
 464     protected byte[] getTableBytes(int tag) {
 465         return null;
 466     }
 467 
 468     /* implemented for fonts backed by an sfnt that has
 469      * OpenType or AAT layout tables.
 470      */
 471     protected long getLayoutTableCache() {
 472         return 0L;


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


 388             if (o == null) {
 389                 strikeCache.remove(desc);
 390             }
 391         }
 392     }
 393 
 394     /**
 395      * The length of the metrics array must be >= 8.  This method will
 396      * store the following elements in that array before returning:
 397      *    metrics[0]: ascent
 398      *    metrics[1]: descent
 399      *    metrics[2]: leading
 400      *    metrics[3]: max advance
 401      *    metrics[4]: strikethrough offset
 402      *    metrics[5]: strikethrough thickness
 403      *    metrics[6]: underline offset
 404      *    metrics[7]: underline thickness
 405      */
 406     public void getFontMetrics(Font font, AffineTransform at,
 407                                Object aaHint, Object fmHint,
 408                                float[] metrics) {
 409         /* This is called in just one place in Font with "at" == identity.
 410          * Perhaps this can be eliminated.
 411          */
 412         int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, font.getSize());
 413         int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
 414         FontStrike strike = getStrike(font, at, aa, fm);
 415         StrikeMetrics strikeMetrics = strike.getFontMetrics();
 416         metrics[0] = strikeMetrics.getAscent();
 417         metrics[1] = strikeMetrics.getDescent();
 418         metrics[2] = strikeMetrics.getLeading();
 419         metrics[3] = strikeMetrics.getMaxAdvance();
 420 
 421         getStyleMetrics(font.getSize2D(), metrics, 4);
 422     }
 423 
 424     /**
 425      * The length of the metrics array must be >= offset+4, and offset must be
 426      * >= 0.  Typically offset is 4.  This method will
 427      * store the following elements in that array before returning:
 428      *    metrics[off+0]: strikethrough offset


 432      *
 433      * Note that this implementation simply returns default values;
 434      * subclasses can override this method to provide more accurate values.
 435      */
 436     public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
 437         metrics[offset] = -metrics[0] / 2.5f;
 438         metrics[offset+1] = pointSize / 12;
 439         metrics[offset+2] = metrics[offset+1] / 1.5f;
 440         metrics[offset+3] = metrics[offset+1];
 441     }
 442 
 443     /**
 444      * The length of the metrics array must be >= 4.  This method will
 445      * store the following elements in that array before returning:
 446      *    metrics[0]: ascent
 447      *    metrics[1]: descent
 448      *    metrics[2]: leading
 449      *    metrics[3]: max advance
 450      */
 451     public void getFontMetrics(Font font, FontRenderContext frc,
 452                                float[] metrics) {
 453         StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
 454         metrics[0] = strikeMetrics.getAscent();
 455         metrics[1] = strikeMetrics.getDescent();
 456         metrics[2] = strikeMetrics.getLeading();
 457         metrics[3] = strikeMetrics.getMaxAdvance();
 458     }
 459 
 460     /* Currently the layout code calls this. May be better for layout code
 461      * to check the font class before attempting to run, rather than needing
 462      * to promote this method up from TrueTypeFont
 463      */
 464     protected byte[] getTableBytes(int tag) {
 465         return null;
 466     }
 467 
 468     /* implemented for fonts backed by an sfnt that has
 469      * OpenType or AAT layout tables.
 470      */
 471     protected long getLayoutTableCache() {
 472         return 0L;


< prev index next >