< prev index next >

src/java.desktop/share/classes/sun/java2d/pipe/OutlineTextRenderer.java

Print this page


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


  47  * filling path, an anti-aliasing fill pipe needs to
  48  * be invoked.
  49  * This involves making some of the same decisions as in the
  50  * validatePipe call, which may be in a SurfaceData subclass, so
  51  * its awkward to always ensure that the correct pipe is used.
  52  * The easiest thing, rather than reproducing much of that logic
  53  * is to call validatePipe() which works but is expensive, although
  54  * probably not compared to the cost of filling the path.
  55  * Note if AA hint is ON but text-AA hint is OFF this logic will
  56  * produce AA text which perhaps isn't what the user expected.
  57  * Note that the glyphvector obeys its FRC, not the G2D.
  58  */
  59 
  60 public class OutlineTextRenderer implements TextPipe {
  61 
  62     // Text with a height greater than the threshhold will be
  63     // drawn via this pipe.
  64     public static final int THRESHHOLD = 100;
  65 
  66     public void drawChars(SunGraphics2D g2d,
  67                           char data[], int offset, int length,
  68                           int x, int y) {
  69 
  70         String s = new String(data, offset, length);
  71         drawString(g2d, s, x, y);
  72     }
  73 
  74     public void drawString(SunGraphics2D g2d, String str, double x, double y) {
  75 
  76         if ("".equals(str)) {
  77             return; // TextLayout constructor throws IAE on "".
  78         }
  79         TextLayout tl = new TextLayout(str, g2d.getFont(),
  80                                        g2d.getFontRenderContext());
  81         Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
  82 
  83         int textAAHint = g2d.getFontInfo().aaHint;
  84 
  85         int prevaaHint = - 1;
  86         if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
  87             g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {


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


  47  * filling path, an anti-aliasing fill pipe needs to
  48  * be invoked.
  49  * This involves making some of the same decisions as in the
  50  * validatePipe call, which may be in a SurfaceData subclass, so
  51  * its awkward to always ensure that the correct pipe is used.
  52  * The easiest thing, rather than reproducing much of that logic
  53  * is to call validatePipe() which works but is expensive, although
  54  * probably not compared to the cost of filling the path.
  55  * Note if AA hint is ON but text-AA hint is OFF this logic will
  56  * produce AA text which perhaps isn't what the user expected.
  57  * Note that the glyphvector obeys its FRC, not the G2D.
  58  */
  59 
  60 public class OutlineTextRenderer implements TextPipe {
  61 
  62     // Text with a height greater than the threshhold will be
  63     // drawn via this pipe.
  64     public static final int THRESHHOLD = 100;
  65 
  66     public void drawChars(SunGraphics2D g2d,
  67                           char[] data, int offset, int length,
  68                           int x, int y) {
  69 
  70         String s = new String(data, offset, length);
  71         drawString(g2d, s, x, y);
  72     }
  73 
  74     public void drawString(SunGraphics2D g2d, String str, double x, double y) {
  75 
  76         if ("".equals(str)) {
  77             return; // TextLayout constructor throws IAE on "".
  78         }
  79         TextLayout tl = new TextLayout(str, g2d.getFont(),
  80                                        g2d.getFontRenderContext());
  81         Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
  82 
  83         int textAAHint = g2d.getFontInfo().aaHint;
  84 
  85         int prevaaHint = - 1;
  86         if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
  87             g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {


< prev index next >