src/share/classes/sun/font/FileFontStrike.java

Print this page


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


 711 
 712         topLeftX = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftXOffset);
 713         topLeftY = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftYOffset);
 714 
 715         result.x = (int)Math.floor(pt.x + topLeftX);
 716         result.y = (int)Math.floor(pt.y + topLeftY);
 717         result.width =
 718             StrikeCache.unsafe.getShort(ptr+StrikeCache.widthOffset)  &0x0ffff;
 719         result.height =
 720             StrikeCache.unsafe.getShort(ptr+StrikeCache.heightOffset) &0x0ffff;
 721 
 722         /* HRGB LCD text may have padding that is empty. This is almost always
 723          * going to be when topLeftX is -2 or less.
 724          * Try to return a tighter bounding box in that case.
 725          * If the first three bytes of every row are all zero, then
 726          * add 1 to "x" and reduce "width" by 1.
 727          */
 728         if ((desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HRGB ||
 729              desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR)
 730             && topLeftX <= -2.0f) {
 731             int minx = getGlyphImageMinX(ptr, (int)result.x);
 732             if (minx > result.x) {
 733                 result.x += 1;
 734                 result.width -=1;
 735             }
 736         }
 737     }
 738 
 739     private int getGlyphImageMinX(long ptr, int origMinX) {
 740 
 741         int width = StrikeCache.unsafe.getChar(ptr+StrikeCache.widthOffset);
 742         int height = StrikeCache.unsafe.getChar(ptr+StrikeCache.heightOffset);
 743         int rowBytes =
 744             StrikeCache.unsafe.getChar(ptr+StrikeCache.rowBytesOffset);
 745 
 746         if (rowBytes == width) {
 747             return origMinX;
 748         }
 749 
 750         long pixelData =
 751             StrikeCache.unsafe.getAddress(ptr + StrikeCache.pixelDataOffset);


 895             boundsMap.put(key, bounds);
 896         }
 897         return bounds;
 898     }
 899 
 900     public Rectangle2D getOutlineBounds(int glyphCode) {
 901         return fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
 902     }
 903 
 904     private
 905         WeakReference<ConcurrentHashMap<Integer,GeneralPath>> outlineMapRef;
 906 
 907     GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
 908 
 909         GeneralPath gp = null;
 910         ConcurrentHashMap<Integer, GeneralPath> outlineMap = null;
 911 
 912         if (outlineMapRef != null) {
 913             outlineMap = outlineMapRef.get();
 914             if (outlineMap != null) {
 915                 gp = (GeneralPath)outlineMap.get(glyphCode);
 916             }
 917         }
 918 
 919         if (gp == null) {
 920             gp = fileFont.getGlyphOutline(pScalerContext, glyphCode, 0, 0);
 921             if (outlineMap == null) {
 922                 outlineMap = new ConcurrentHashMap<Integer, GeneralPath>();
 923                 outlineMapRef =
 924                    new WeakReference
 925                        <ConcurrentHashMap<Integer,GeneralPath>>(outlineMap);
 926             }
 927             outlineMap.put(glyphCode, gp);
 928         }
 929         gp = (GeneralPath)gp.clone(); // mutable!
 930         if (x != 0f || y != 0f) {
 931             gp.transform(AffineTransform.getTranslateInstance(x, y));
 932         }
 933         return gp;
 934     }
 935 
   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


 711 
 712         topLeftX = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftXOffset);
 713         topLeftY = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftYOffset);
 714 
 715         result.x = (int)Math.floor(pt.x + topLeftX);
 716         result.y = (int)Math.floor(pt.y + topLeftY);
 717         result.width =
 718             StrikeCache.unsafe.getShort(ptr+StrikeCache.widthOffset)  &0x0ffff;
 719         result.height =
 720             StrikeCache.unsafe.getShort(ptr+StrikeCache.heightOffset) &0x0ffff;
 721 
 722         /* HRGB LCD text may have padding that is empty. This is almost always
 723          * going to be when topLeftX is -2 or less.
 724          * Try to return a tighter bounding box in that case.
 725          * If the first three bytes of every row are all zero, then
 726          * add 1 to "x" and reduce "width" by 1.
 727          */
 728         if ((desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HRGB ||
 729              desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR)
 730             && topLeftX <= -2.0f) {
 731             int minx = getGlyphImageMinX(ptr, result.x);
 732             if (minx > result.x) {
 733                 result.x += 1;
 734                 result.width -=1;
 735             }
 736         }
 737     }
 738 
 739     private int getGlyphImageMinX(long ptr, int origMinX) {
 740 
 741         int width = StrikeCache.unsafe.getChar(ptr+StrikeCache.widthOffset);
 742         int height = StrikeCache.unsafe.getChar(ptr+StrikeCache.heightOffset);
 743         int rowBytes =
 744             StrikeCache.unsafe.getChar(ptr+StrikeCache.rowBytesOffset);
 745 
 746         if (rowBytes == width) {
 747             return origMinX;
 748         }
 749 
 750         long pixelData =
 751             StrikeCache.unsafe.getAddress(ptr + StrikeCache.pixelDataOffset);


 895             boundsMap.put(key, bounds);
 896         }
 897         return bounds;
 898     }
 899 
 900     public Rectangle2D getOutlineBounds(int glyphCode) {
 901         return fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
 902     }
 903 
 904     private
 905         WeakReference<ConcurrentHashMap<Integer,GeneralPath>> outlineMapRef;
 906 
 907     GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
 908 
 909         GeneralPath gp = null;
 910         ConcurrentHashMap<Integer, GeneralPath> outlineMap = null;
 911 
 912         if (outlineMapRef != null) {
 913             outlineMap = outlineMapRef.get();
 914             if (outlineMap != null) {
 915                 gp = outlineMap.get(glyphCode);
 916             }
 917         }
 918 
 919         if (gp == null) {
 920             gp = fileFont.getGlyphOutline(pScalerContext, glyphCode, 0, 0);
 921             if (outlineMap == null) {
 922                 outlineMap = new ConcurrentHashMap<Integer, GeneralPath>();
 923                 outlineMapRef =
 924                    new WeakReference
 925                        <ConcurrentHashMap<Integer,GeneralPath>>(outlineMap);
 926             }
 927             outlineMap.put(glyphCode, gp);
 928         }
 929         gp = (GeneralPath)gp.clone(); // mutable!
 930         if (x != 0f || y != 0f) {
 931             gp.transform(AffineTransform.getTranslateInstance(x, y));
 932         }
 933         return gp;
 934     }
 935