123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /* ====================================================================
- 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.
- ==================================================================== */
-
- package org.apache.poi.hwmf.draw;
-
- import java.awt.Color;
- import java.awt.Shape;
- import java.awt.geom.AffineTransform;
- import java.awt.geom.Area;
- import java.awt.geom.Path2D;
- import java.awt.geom.Point2D;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.BufferedImage;
- import java.util.List;
-
- import org.apache.poi.hwmf.draw.HwmfGraphics.BufferedImageRenderer;
- import org.apache.poi.hwmf.record.HwmfBinaryRasterOp;
- import org.apache.poi.hwmf.record.HwmfBrushStyle;
- import org.apache.poi.hwmf.record.HwmfColorRef;
- import org.apache.poi.hwmf.record.HwmfFill.WmfSetPolyfillMode.HwmfPolyfillMode;
- import org.apache.poi.hwmf.record.HwmfFont;
- import org.apache.poi.hwmf.record.HwmfHatchStyle;
- import org.apache.poi.hwmf.record.HwmfMapMode;
- import org.apache.poi.hwmf.record.HwmfMisc.WmfSetBkMode.HwmfBkMode;
- import org.apache.poi.hwmf.record.HwmfPalette.PaletteEntry;
- import org.apache.poi.hwmf.record.HwmfPenStyle;
- import org.apache.poi.hwmf.record.HwmfTernaryRasterOp;
- import org.apache.poi.hwmf.record.HwmfText.HwmfTextAlignment;
- import org.apache.poi.hwmf.record.HwmfText.HwmfTextVerticalAlignment;
- import org.apache.poi.sl.draw.ImageRenderer;
-
- public class HwmfDrawProperties {
- private final Rectangle2D window;
- private Rectangle2D viewport;
- private final Point2D location;
- private HwmfMapMode mapMode;
- private HwmfColorRef backgroundColor;
- private HwmfBrushStyle brushStyle;
- private HwmfColorRef brushColor;
- private HwmfHatchStyle brushHatch;
- private ImageRenderer brushBitmap;
- private final AffineTransform brushTransform = new AffineTransform();
- private double penWidth;
- private HwmfPenStyle penStyle;
- private HwmfColorRef penColor;
- private double penMiterLimit;
- private HwmfBkMode bkMode;
- private HwmfPolyfillMode polyfillMode;
- private Shape region;
- private List<PaletteEntry> palette;
- private int paletteOffset;
- private HwmfFont font;
- private HwmfColorRef textColor;
- private HwmfTextAlignment textAlignLatin;
- private HwmfTextVerticalAlignment textVAlignLatin;
- private HwmfTextAlignment textAlignAsian;
- private HwmfTextVerticalAlignment textVAlignAsian;
- private HwmfBinaryRasterOp rasterOp2;
- private HwmfTernaryRasterOp rasterOp3;
- protected Shape clip;
- protected final AffineTransform transform = new AffineTransform();
-
- public HwmfDrawProperties() {
- window = new Rectangle2D.Double(0, 0, 1, 1);
- viewport = null;
- location = new Point2D.Double(0,0);
- mapMode = HwmfMapMode.MM_ANISOTROPIC;
- backgroundColor = new HwmfColorRef(Color.BLACK);
- brushStyle = HwmfBrushStyle.BS_SOLID;
- brushColor = new HwmfColorRef(Color.BLACK);
- brushHatch = HwmfHatchStyle.HS_HORIZONTAL;
- penWidth = 1;
- penStyle = HwmfPenStyle.valueOf(0);
- penColor = new HwmfColorRef(Color.BLACK);
- penMiterLimit = 10;
- bkMode = HwmfBkMode.OPAQUE;
- polyfillMode = HwmfPolyfillMode.WINDING;
- textColor = new HwmfColorRef(Color.BLACK);
- textAlignLatin = HwmfTextAlignment.LEFT;
- textVAlignLatin = HwmfTextVerticalAlignment.TOP;
- textAlignAsian = HwmfTextAlignment.RIGHT;
- textVAlignAsian = HwmfTextVerticalAlignment.TOP;
- rasterOp2 = HwmfBinaryRasterOp.R2_COPYPEN;
- rasterOp3 = null; // default: PATCOPY?
- clip = null;
- font = new HwmfFont();
- font.initDefaults();
- }
-
- public HwmfDrawProperties(HwmfDrawProperties other) {
- this.window = (other.window == null) ? null : (Rectangle2D)other.window.clone();
- this.viewport = (other.viewport == null) ? null : (Rectangle2D)other.viewport.clone();
- this.location = (Point2D)other.location.clone();
- this.mapMode = other.mapMode;
- this.backgroundColor = (other.backgroundColor == null) ? null : other.backgroundColor.copy();
- this.brushStyle = other.brushStyle;
- this.brushColor = other.brushColor.copy();
- this.brushHatch = other.brushHatch;
- this.brushBitmap = other.brushBitmap;
- this.brushTransform.setTransform(other.brushTransform);
- this.penWidth = other.penWidth;
- this.penStyle = (other.penStyle == null) ? null : other.penStyle.copy();
- this.penColor = (other.penColor == null) ? null : other.penColor.copy();
- this.penMiterLimit = other.penMiterLimit;
- this.bkMode = other.bkMode;
- this.polyfillMode = other.polyfillMode;
- if (other.region instanceof Rectangle2D) {
- this.region = other.region.getBounds2D();
- } else if (other.region instanceof Area) {
- this.region = new Area(other.region);
- }
- this.palette = other.palette;
- this.paletteOffset = other.paletteOffset;
- this.font = other.font;
- this.textColor = (other.textColor == null) ? null : other.textColor.copy();
- this.textAlignLatin = other.textAlignLatin;
- this.textVAlignLatin = other.textVAlignLatin;
- this.textAlignAsian = other.textAlignAsian;
- this.textVAlignAsian = other.textVAlignAsian;
- this.rasterOp2 = other.rasterOp2;
- this.rasterOp3 = other.rasterOp3;
- this.transform.setTransform(other.transform);
- this.clip = other.clip;
- }
-
- public void setViewportExt(double width, double height) {
- if (viewport == null) {
- viewport = (Rectangle2D)window.clone();
- }
- double x = viewport.getX();
- double y = viewport.getY();
- double w = (width != 0) ? width : viewport.getWidth();
- double h = (height != 0) ? height : viewport.getHeight();
- viewport.setRect(x, y, w, h);
- }
-
- public void setViewportOrg(double x, double y) {
- if (viewport == null) {
- viewport = (Rectangle2D)window.clone();
- }
- double w = viewport.getWidth();
- double h = viewport.getHeight();
- viewport.setRect(x, y, w, h);
- }
-
- public Rectangle2D getViewport() {
- return (viewport == null) ? null : (Rectangle2D)viewport.clone();
- }
-
- public void setWindowExt(double width, double height) {
- double x = window.getX();
- double y = window.getY();
- double w = (width != 0) ? width : window.getWidth();
- double h = (height != 0) ? height : window.getHeight();
- window.setRect(x, y, w, h);
- }
-
- public void setWindowOrg(double x, double y) {
- double w = window.getWidth();
- double h = window.getHeight();
- window.setRect(x, y, w, h);
- }
-
- public Rectangle2D getWindow() {
- return (Rectangle2D)window.clone();
- }
-
- public void setLocation(double x, double y) {
- location.setLocation(x, y);
- }
-
- public void setLocation(Point2D point) {
- location.setLocation(point);
- }
-
- public Point2D getLocation() {
- return (Point2D)location.clone();
- }
-
- public void setMapMode(HwmfMapMode mapMode) {
- this.mapMode = mapMode;
- }
-
- public HwmfMapMode getMapMode() {
- return mapMode;
- }
-
- public HwmfBrushStyle getBrushStyle() {
- return brushStyle;
- }
-
- public void setBrushStyle(HwmfBrushStyle brushStyle) {
- this.brushStyle = brushStyle;
- }
-
- public HwmfHatchStyle getBrushHatch() {
- return brushHatch;
- }
-
- public void setBrushHatch(HwmfHatchStyle brushHatch) {
- this.brushHatch = brushHatch;
- }
-
- public HwmfColorRef getBrushColor() {
- return brushColor;
- }
-
- public void setBrushColor(HwmfColorRef brushColor) {
- this.brushColor = brushColor;
- }
-
- public HwmfBkMode getBkMode() {
- return bkMode;
- }
-
- public void setBkMode(HwmfBkMode bkMode) {
- this.bkMode = bkMode;
- }
-
- public HwmfPenStyle getPenStyle() {
- return penStyle;
- }
-
- public void setPenStyle(HwmfPenStyle penStyle) {
- this.penStyle = penStyle;
- }
-
- public HwmfColorRef getPenColor() {
- return penColor;
- }
-
- public void setPenColor(HwmfColorRef penColor) {
- this.penColor = penColor;
- }
-
- public double getPenWidth() {
- return penWidth;
- }
-
- public void setPenWidth(double penWidth) {
- this.penWidth = penWidth;
- }
-
- public double getPenMiterLimit() {
- return penMiterLimit;
- }
-
- public void setPenMiterLimit(double penMiterLimit) {
- this.penMiterLimit = penMiterLimit;
- }
-
- public HwmfColorRef getBackgroundColor() {
- return backgroundColor;
- }
-
- public void setBackgroundColor(HwmfColorRef backgroundColor) {
- this.backgroundColor = backgroundColor;
- }
-
- public HwmfPolyfillMode getPolyfillMode() {
- return polyfillMode;
- }
-
- public void setPolyfillMode(HwmfPolyfillMode polyfillMode) {
- this.polyfillMode = polyfillMode;
- }
-
- public ImageRenderer getBrushBitmap() {
- return brushBitmap;
- }
-
- public void setBrushBitmap(ImageRenderer brushBitmap) {
- this.brushBitmap = brushBitmap;
- }
-
- public void setBrushBitmap(BufferedImage brushBitmap) {
- this.brushBitmap = (brushBitmap == null) ? null : new BufferedImageRenderer(brushBitmap);
- }
-
- /**
- * Gets the last stored region
- *
- * @return the last stored region
- */
- public Shape getRegion() {
- return region;
- }
-
- /**
- * Sets a region for further usage
- *
- * @param region a region object which is usually a rectangle
- */
- public void setRegion(Shape region) {
- this.region = region;
- }
-
- /**
- * Returns the current palette.
- * Callers may modify the palette.
- *
- * @return the current palette or null, if it hasn't been set
- */
- public List<PaletteEntry> getPalette() {
- return palette;
- }
-
- /**
- * Sets the current palette.
- * It's the callers duty to set a modifiable copy of the palette.
- */
- public void setPalette(List<PaletteEntry> palette) {
- this.palette = palette;
- }
-
- public int getPaletteOffset() {
- return paletteOffset;
- }
-
- public void setPaletteOffset(int paletteOffset) {
- this.paletteOffset = paletteOffset;
- }
-
- public HwmfColorRef getTextColor() {
- return textColor;
- }
-
- public void setTextColor(HwmfColorRef textColor) {
- this.textColor = textColor;
- }
-
- public HwmfFont getFont() {
- return font;
- }
-
- public void setFont(HwmfFont font) {
- this.font = font;
- }
-
- public HwmfTextAlignment getTextAlignLatin() {
- return textAlignLatin;
- }
-
- public void setTextAlignLatin(HwmfTextAlignment textAlignLatin) {
- this.textAlignLatin = textAlignLatin;
- }
-
- public HwmfTextVerticalAlignment getTextVAlignLatin() {
- return textVAlignLatin;
- }
-
- public void setTextVAlignLatin(HwmfTextVerticalAlignment textVAlignLatin) {
- this.textVAlignLatin = textVAlignLatin;
- }
-
- public HwmfTextAlignment getTextAlignAsian() {
- return textAlignAsian;
- }
-
- public void setTextAlignAsian(HwmfTextAlignment textAlignAsian) {
- this.textAlignAsian = textAlignAsian;
- }
-
- public HwmfTextVerticalAlignment getTextVAlignAsian() {
- return textVAlignAsian;
- }
-
- public void setTextVAlignAsian(HwmfTextVerticalAlignment textVAlignAsian) {
- this.textVAlignAsian = textVAlignAsian;
- }
-
- /**
- * @return the current active winding rule ({@link Path2D#WIND_EVEN_ODD} or {@link Path2D#WIND_NON_ZERO})
- */
- public int getWindingRule() {
- return getPolyfillMode().awtFlag;
- }
-
- public HwmfTernaryRasterOp getRasterOp3() {
- return rasterOp3;
- }
-
- public void setRasterOp3(HwmfTernaryRasterOp rasterOp3) {
- this.rasterOp3 = rasterOp3;
- }
-
- public AffineTransform getTransform() {
- return transform;
- }
-
- public void setTransform(AffineTransform transform) {
- this.transform.setTransform(transform);
- }
-
- public Shape getClip() {
- return clip;
- }
-
- public void setClip(Shape clip) {
- this.clip = clip;
- }
-
- public AffineTransform getBrushTransform() {
- return brushTransform;
- }
-
- public void setBrushTransform(AffineTransform brushTransform) {
- if (brushTransform == null) {
- this.brushTransform.setToIdentity();
- } else {
- this.brushTransform.setTransform(brushTransform);
- }
- }
- public HwmfBinaryRasterOp getRasterOp2() {
- return rasterOp2;
- }
-
- public void setRasterOp2(HwmfBinaryRasterOp rasterOp2) {
- this.rasterOp2 = rasterOp2;
- }
- }
|