0N/A/*
2362N/A * Copyright (c) 1998, 2000, 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.print;
0N/A
0N/Aimport java.awt.AlphaComposite;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Composite;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.Image;
0N/Aimport java.awt.Paint;
0N/A
0N/Aimport java.awt.font.TextLayout;
0N/A
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.awt.image.renderable.RenderableImage;
0N/A
0N/A/**
0N/A * Maintain information about the type of drawing
0N/A * performed by a printing application.
0N/A */
0N/Apublic class PeekMetrics {
0N/A
0N/A private boolean mHasNonSolidColors;
0N/A
0N/A private boolean mHasCompositing;
0N/A
0N/A private boolean mHasText;
0N/A
0N/A private boolean mHasImages;
0N/A
0N/A /**
0N/A * Return <code>true</code> if the application
0N/A * has done any drawing with a Paint that
0N/A * is not an instance of <code>Color</code>
0N/A */
0N/A public boolean hasNonSolidColors() {
0N/A return mHasNonSolidColors;
0N/A }
0N/A
0N/A /**
0N/A * Return true if the application has
0N/A * done any drawing with an alpha other
0N/A * than 1.0.
0N/A */
0N/A public boolean hasCompositing() {
0N/A return mHasCompositing;
0N/A }
0N/A
0N/A /**
0N/A * Return true if the application has
0N/A * drawn any text.
0N/A */
0N/A public boolean hasText() {
0N/A return mHasText;
0N/A }
0N/A
0N/A /**
0N/A * Return true if the application has
0N/A * drawn any images.
0N/A */
0N/A public boolean hasImages() {
0N/A return mHasImages;
0N/A }
0N/A
0N/A /**
0N/A * The application is performing a fill
0N/A * so record the needed information.
0N/A */
0N/A public void fill(Graphics2D g) {
0N/A checkDrawingMode(g);
0N/A }
0N/A
0N/A /**
0N/A * The application is performing a draw
0N/A * so record the needed information.
0N/A */
0N/A public void draw(Graphics2D g) {
0N/A checkDrawingMode(g);
0N/A }
0N/A
0N/A /**
0N/A * The application is performing a clearRect
0N/A * so record the needed information.
0N/A */
0N/A public void clear(Graphics2D g) {
0N/A checkPaint(g.getBackground());
0N/A }
0N/A /**
0N/A * The application is drawing text
0N/A * so record the needed information.
0N/A */
0N/A public void drawText(Graphics2D g) {
0N/A mHasText = true;
0N/A checkDrawingMode(g);
0N/A }
0N/A
0N/A /**
0N/A * The application is drawing text
0N/A * defined by <code>TextLayout</code>
0N/A * so record the needed information.
0N/A */
0N/A public void drawText(Graphics2D g, TextLayout textLayout) {
0N/A mHasText = true;
0N/A checkDrawingMode(g);
0N/A }
0N/A
0N/A /**
0N/A * The application is drawing the passed
0N/A * in image.
0N/A */
0N/A public void drawImage(Graphics2D g, Image image) {
0N/A mHasImages = true;
0N/A }
0N/A
0N/A /**
0N/A * The application is drawing the passed
0N/A * in image.
0N/A */
0N/A public void drawImage(Graphics2D g, RenderedImage image) {
0N/A mHasImages = true;
0N/A }
0N/A
0N/A /**
0N/A * The application is drawing the passed
0N/A * in image.
0N/A */
0N/A public void drawImage(Graphics2D g, RenderableImage image) {
0N/A mHasImages = true;
0N/A }
0N/A
0N/A /**
0N/A * Record information about the current paint
0N/A * and composite.
0N/A */
0N/A private void checkDrawingMode(Graphics2D g) {
0N/A
0N/A checkPaint(g.getPaint());
0N/A checkAlpha(g.getComposite());
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Record information about drawing done
0N/A * with the supplied <code>Paint</code>.
0N/A */
0N/A private void checkPaint(Paint paint) {
0N/A
0N/A if (paint instanceof Color) {
0N/A if (((Color)paint).getAlpha() < 255) {
0N/A mHasNonSolidColors = true;
0N/A }
0N/A } else {
0N/A mHasNonSolidColors = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Record information about drawing done
0N/A * with the supplied <code>Composite</code>.
0N/A */
0N/A private void checkAlpha(Composite composite) {
0N/A
0N/A if (composite instanceof AlphaComposite) {
0N/A AlphaComposite alphaComposite = (AlphaComposite) composite;
0N/A float alpha = alphaComposite.getAlpha();
0N/A int rule = alphaComposite.getRule();
0N/A
0N/A if (alpha != 1.0
0N/A || (rule != AlphaComposite.SRC
0N/A && rule != AlphaComposite.SRC_OVER)) {
0N/A
0N/A mHasCompositing = true;
0N/A }
0N/A
0N/A } else {
0N/A mHasCompositing = true;
0N/A }
0N/A
0N/A }
0N/A
0N/A}