123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.render.afp;
-
- import java.awt.Color;
- import java.util.Arrays;
-
- /**
- * This keeps information about the current state when writing to pdf.
- */
- public class AFPState {
- /**
- * The current color
- */
- private Color color = null;
-
- /**
- * The current background color
- */
- private Color backColor = null;
-
- /**
- * The current font name
- */
- private String fontName = null;
-
- /**
- * The current font size
- */
- private int fontSize = 0;
-
- /**
- * The current line width
- */
- private float lineWidth = 0;
-
- /**
- * The dash array for the current basic stroke (line type)
- */
- private float[] dashArray = null;
-
- /**
- * The current fill status
- */
- private boolean filled = false;
-
- /**
- * The fonts on the current page
- */
- private AFPPageFonts pageFonts = null;
-
- /**
- * Set the current color.
- * Check if the new color is a change and then set the current color.
- *
- * @param col the color to set
- * @return true if the color has changed
- */
- protected boolean setColor(Color col) {
- if (!col.equals(this.color)) {
- this.color = col;
- return true;
- }
- return false;
- }
-
- /**
- * Sets if the current painted shape is to be filled
- * @param fill true if the current painted shape is to be filled
- * @return true if the fill value has changed
- */
- protected boolean setFill(boolean fill) {
- if (fill != this.filled) {
- this.filled = fill;
- return true;
- }
- return false;
- }
-
- /**
- * Get the color.
- * @return the color
- */
- protected Color getColor() {
- if (this.color == null) {
- this.color = Color.black;
- }
- return this.color;
- }
-
- /**
- * Set the current line width.
- * @param width the line width in points
- * @return true if the line width has changed
- */
- protected boolean setLineWidth(float width) {
- if (this.lineWidth != width) {
- this.lineWidth = width;
- return true;
- }
- return false;
- }
-
- /**
- * Sets the dash array (line type) for the current basic stroke
- * @param dash the line dash array
- * @return true if the dash array has changed
- */
- public boolean setDashArray(float[] dash) {
- if (!Arrays.equals(dash, this.dashArray)) {
- this.dashArray = dash;
- return true;
- }
- return false;
- }
-
- /**
- * Gets the current line width
- * @return the current line width
- */
- protected float getLineWidth() {
- return lineWidth;
- }
-
- /**
- * Get the background color.
- * @return the background color
- */
- protected Color getBackColor() {
- if (this.backColor == null) {
- this.backColor = Color.white;
- }
- return backColor;
- }
-
- /**
- * Set the current background color.
- * Check if the new background color is a change and then set the current background color.
- *
- * @param col the background color to set
- * @return true if the color has changed
- */
- protected boolean setBackColor(Color col) {
- if (!col.equals(this.backColor)) {
- this.backColor = col;
- return true;
- }
- return false;
- }
-
- /**
- * Set the current font name
- * @param internalFontName the internal font name
- * @return true if the font name has changed
- */
- protected boolean setFontName(String internalFontName) {
- if (!internalFontName.equals(this.fontName)) {
- this.fontName = internalFontName;
- return true;
- }
- return false;
- }
-
- /**
- * Gets the current font name
- * @return the current font name
- */
- protected String getFontName() {
- return this.fontName;
- }
-
- /**
- * Gets the current font size
- * @return the current font size
- */
- protected int getFontSize() {
- return this.fontSize;
- }
-
- /**
- * Set the current font size.
- * Check if the font size is a change and then set the current font size.
- *
- * @param size the font size to set
- * @return true if the font size has changed
- */
- protected boolean setFontSize(int size) {
- if (size != this.fontSize) {
- this.fontSize = size;
- return true;
- }
- return false;
- }
-
- /**
- * Gets the current page fonts
- * @return the current page fonts
- */
- protected AFPPageFonts getPageFonts() {
- if (this.pageFonts == null) {
- this.pageFonts = new AFPPageFonts();
- }
- return this.pageFonts;
- }
-
- /**
- * Resets the current state
- */
- protected void reset() {
- this.color = null;
- this.backColor = null;
- this.fontName = null;
- this.fontSize = 0;
- this.lineWidth = 0;
- this.dashArray = null;
- this.filled = false;
- if (this.pageFonts != null) {
- this.pageFonts.clear();
- }
- }
- }
|