All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lowagie.text.rtf.graphic.RtfShapeProperty Maven / Gradle / Ivy

Go to download

RTF generation library derived from iText-2.1.7. All PDF features and RTF parsing are removed. Code is modernized for Java 8.

There is a newer version: 1.0.5
Show newest version
package com.lowagie.text.rtf.graphic;

import com.lowagie.text.DocWriter;
import com.lowagie.text.DocumentException;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Image;
import com.lowagie.text.rtf.RtfAddableElement;

import java.awt.Color;
import java.awt.Point;
import java.io.IOException;
import java.io.OutputStream;

/**
 * The RtfShapeProperty stores all shape properties that are
 * not handled by the RtfShape and RtfShapePosition.

*

* There is a huge selection of properties that can be set. For * the most important properites there are constants for the * property name, for all others you must find the correct * property name in the RTF specification (version 1.6).

*

* The following types of property values are supported: *

    *
  • long
  • *
  • double
  • *
  • boolean
  • *
  • Color
  • *
  • int[]
  • *
  • Point[]
  • *
* * @author Mark Hall ([email protected]) * @author Thomas Bickel ([email protected]) * @version $Id: RtfShapeProperty.java 3580 2008-08-06 15:52:00Z howard_s $ */ public class RtfShapeProperty extends RtfAddableElement { /** * Property for defining an image. */ public static final String PROPERTY_IMAGE = "pib"; /** * Property for defining vertices in freeform shapes. Requires a * Point array as the value. */ public static final String PROPERTY_VERTICIES = "pVerticies"; /** * Property for defining the minimum vertical coordinate that is * visible. Requires a long value. */ public static final String PROPERTY_GEO_TOP = "geoTop"; /** * Property for defining the minimum horizontal coordinate that is * visible. Requires a long value. */ public static final String PROPERTY_GEO_LEFT = "geoLeft"; /** * Property for defining the maximum horizontal coordinate that is * visible. Requires a long value. */ public static final String PROPERTY_GEO_RIGHT = "geoRight"; /** * Property for defining the maximum vertical coordinate that is * visible. Requires a long value. */ public static final String PROPERTY_GEO_BOTTOM = "geoBottom"; /** * Property for defining that the shape is in a table cell. Requires * a boolean value. */ public static final String PROPERTY_LAYOUT_IN_CELL = "fLayoutInCell"; /** * Property for signaling a vertical flip of the shape. Requires a * boolean value. */ public static final String PROPERTY_FLIP_V = "fFlipV"; /** * Property for signaling a horizontal flip of the shape. Requires a * boolean value. */ public static final String PROPERTY_FLIP_H = "fFlipH"; /** * Property for defining the fill color of the shape. Requires a * Color value. */ public static final String PROPERTY_FILL_COLOR = "fillColor"; /** * Property for defining the line color of the shape. Requires a * Color value. */ public static final String PROPERTY_LINE_COLOR = "lineColor"; /** * Property for defining the first adjust handle for shapes. Used * with the rounded rectangle. Requires a long value. */ public static final String PROPERTY_ADJUST_VALUE = "adjustValue"; /** * The stored value is a long. */ private static final int PROPERTY_TYPE_LONG = 1; /** * The stored value is boolean. */ private static final int PROPERTY_TYPE_BOOLEAN = 2; /** * The stored value is a double. */ private static final int PROPERTY_TYPE_DOUBLE = 3; /** * The stored value is a Color. */ private static final int PROPERTY_TYPE_COLOR = 4; /** * The stored value is either an int or a Point array. */ private static final int PROPERTY_TYPE_ARRAY = 5; /** * The stored value is an Image. */ private static final int PROPERTY_TYPE_IMAGE = 6; /** * The value type. */ private final int type; /** * The RtfShapeProperty name. */ private final String name; /** * The RtfShapeProperty value. */ private final Object value; /** * Internally used to create the RtfShape. * * @param name The property name to use. * @param value The property value to use. */ private RtfShapeProperty(int type, String name, Object value) { this.type = type; this.name = name; this.value = value; } /** * Constructs a RtfShapeProperty with a long value. * * @param name The property name to use. * @param value The long value to use. */ public RtfShapeProperty(String name, long value) { this(PROPERTY_TYPE_LONG, name, value); } /** * Constructs a RtfShapeProperty with a double value. * * @param name The property name to use. * @param value The double value to use. */ public RtfShapeProperty(String name, double value) { this(PROPERTY_TYPE_DOUBLE, name, value); } /** * Constructs a RtfShapeProperty with a boolean value. * * @param name The property name to use. * @param value The boolean value to use. */ public RtfShapeProperty(String name, boolean value) { this(PROPERTY_TYPE_BOOLEAN, name, value); } /** * Constructs a RtfShapeProperty with a Color value. * * @param name The property name to use. * @param value The Color value to use. */ public RtfShapeProperty(String name, Color value) { this(PROPERTY_TYPE_COLOR, name, value); } /** * Constructs a RtfShapeProperty with an int array value. * * @param name The property name to use. * @param value The int array to use. */ public RtfShapeProperty(String name, int[] value) { this(PROPERTY_TYPE_ARRAY, name, value); } /** * Constructs a RtfShapeProperty with a Point array value. * * @param name The property name to use. * @param value The Point array to use. */ public RtfShapeProperty(String name, Point[] value) { this(PROPERTY_TYPE_ARRAY, name, value); } /** * Constructs a RtfShapeProperty with an Image value. * * @param name The property name to use. * @param value The Image to use. */ public RtfShapeProperty(String name, Image value) { this(PROPERTY_TYPE_IMAGE, name, value); } /** * Gets the name of this RtfShapeProperty. * * @return The name of this RtfShapeProperty. */ public String getName() { return this.name; } /** * Writes the property definition. How the property * is written depends on the property type. */ @Override public void writeContent(OutputStream result) throws IOException { result.write(OPEN_GROUP); result.write(DocWriter.getISOBytes("\\sp")); result.write(OPEN_GROUP); result.write(DocWriter.getISOBytes("\\sn")); result.write(DELIMITER); result.write(DocWriter.getISOBytes(this.name)); result.write(CLOSE_GROUP); result.write(OPEN_GROUP); result.write(DocWriter.getISOBytes("\\sv")); result.write(DELIMITER); switch (this.type) { case PROPERTY_TYPE_LONG: case PROPERTY_TYPE_DOUBLE: result.write(DocWriter.getISOBytes(this.value.toString())); break; case PROPERTY_TYPE_BOOLEAN: if (((Boolean) this.value).booleanValue()) { result.write(DocWriter.getISOBytes("1")); } else { result.write(DocWriter.getISOBytes("0")); } break; case PROPERTY_TYPE_COLOR: Color color = (Color) this.value; result.write(intToByteArray(color.getRed() | (color.getGreen() << 8) | (color.getBlue() << 16))); break; case PROPERTY_TYPE_ARRAY: if (this.value instanceof int[]) { int[] values = (int[]) this.value; result.write(DocWriter.getISOBytes("4;")); result.write(intToByteArray(values.length)); result.write(COMMA_DELIMITER); for (int i = 0; i < values.length; i++) { result.write(intToByteArray(values[i])); if (i < values.length - 1) { result.write(COMMA_DELIMITER); } } } else if (this.value instanceof Point[]) { Point[] values = (Point[]) this.value; result.write(DocWriter.getISOBytes("8;")); result.write(intToByteArray(values.length)); result.write(COMMA_DELIMITER); for (int i = 0; i < values.length; i++) { result.write(DocWriter.getISOBytes("(")); result.write(intToByteArray(values[i].x)); result.write(DocWriter.getISOBytes(",")); result.write(intToByteArray(values[i].y)); result.write(DocWriter.getISOBytes(")")); if (i < values.length - 1) { result.write(COMMA_DELIMITER); } } } break; case PROPERTY_TYPE_IMAGE: Image image = (Image) this.value; RtfImage img; try { img = new RtfImage(this.doc, image); } catch (DocumentException de) { throw new ExceptionConverter(de); } img.setTopLevelElement(true); result.write(OPEN_GROUP); img.writeContent(result); result.write(CLOSE_GROUP); break; } result.write(CLOSE_GROUP); result.write(CLOSE_GROUP); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy