0N/A/*
2362N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.pipe;
0N/A
0N/Aimport java.awt.font.FontRenderContext;
0N/Aimport java.awt.font.GlyphVector;
0N/Aimport java.awt.font.TextLayout;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.font.GlyphList;
0N/Aimport sun.awt.SunHints;
0N/A
0N/Aimport java.awt.Shape;
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.font.TextLayout;
0N/A
0N/A/**
0N/A * A delegate pipe of SG2D for drawing "large" text with
0N/A * a solid source colour to an opaque destination.
0N/A * The text is drawn as a filled outline.
0N/A * Since the developer is not explicitly requesting this way of
0N/A * rendering, this should not be used if the current paint is not
0N/A * a solid colour.
0N/A *
0N/A * If text anti-aliasing is requested by the application, and
0N/A * filling path, an anti-aliasing fill pipe needs to
0N/A * be invoked.
0N/A * This involves making some of the same decisions as in the
0N/A * validatePipe call, which may be in a SurfaceData subclass, so
0N/A * its awkward to always ensure that the correct pipe is used.
0N/A * The easiest thing, rather than reproducing much of that logic
0N/A * is to call validatePipe() which works but is expensive, although
0N/A * probably not compared to the cost of filling the path.
0N/A * Note if AA hint is ON but text-AA hint is OFF this logic will
0N/A * produce AA text which perhaps isn't what the user expected.
0N/A * Note that the glyphvector obeys its FRC, not the G2D.
0N/A */
0N/A
0N/Apublic class OutlineTextRenderer implements TextPipe {
0N/A
0N/A // Text with a height greater than the threshhold will be
0N/A // drawn via this pipe.
0N/A public static final int THRESHHOLD = 100;
0N/A
0N/A public void drawChars(SunGraphics2D g2d,
0N/A char data[], int offset, int length,
0N/A int x, int y) {
0N/A
0N/A String s = new String(data, offset, length);
0N/A drawString(g2d, s, x, y);
0N/A }
0N/A
0N/A public void drawString(SunGraphics2D g2d, String str, double x, double y) {
0N/A
0N/A if ("".equals(str)) {
0N/A return; // TextLayout constructor throws IAE on "".
0N/A }
0N/A TextLayout tl = new TextLayout(str, g2d.getFont(),
0N/A g2d.getFontRenderContext());
0N/A Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
0N/A
0N/A int textAAHint = g2d.getFontInfo().aaHint;
0N/A
0N/A int prevaaHint = - 1;
0N/A if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
0N/A g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
0N/A prevaaHint = g2d.antialiasHint;
0N/A g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
0N/A g2d.validatePipe();
0N/A } else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
0N/A && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
0N/A prevaaHint = g2d.antialiasHint;
0N/A g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
0N/A g2d.validatePipe();
0N/A }
0N/A
0N/A g2d.fill(s);
0N/A
0N/A if (prevaaHint != -1) {
0N/A g2d.antialiasHint = prevaaHint;
0N/A g2d.validatePipe();
0N/A }
0N/A }
0N/A
0N/A public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv,
0N/A float x, float y) {
0N/A
0N/A
0N/A Shape s = gv.getOutline(x, y);
0N/A int prevaaHint = - 1;
0N/A FontRenderContext frc = gv.getFontRenderContext();
0N/A boolean aa = frc.isAntiAliased();
0N/A
0N/A /* aa will be true if any AA mode has been specified.
0N/A * ie for LCD and 'gasp' modes too.
0N/A * We will check if 'gasp' has resolved AA to be "OFF", and
0N/A * in all other cases (ie AA ON and all LCD modes) use AA outlines.
0N/A */
0N/A if (aa) {
0N/A if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint ==
0N/A SunHints.INTVAL_TEXT_ANTIALIAS_OFF) {
0N/A aa = false;
0N/A }
0N/A }
0N/A
0N/A if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
0N/A prevaaHint = g2d.antialiasHint;
0N/A g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
0N/A g2d.validatePipe();
0N/A } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
0N/A prevaaHint = g2d.antialiasHint;
0N/A g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
0N/A g2d.validatePipe();
0N/A }
0N/A
0N/A g2d.fill(s);
0N/A
0N/A if (prevaaHint != -1) {
0N/A g2d.antialiasHint = prevaaHint;
0N/A g2d.validatePipe();
0N/A }
0N/A }
0N/A}