File: RtfShapePosition.java

package info (click to toggle)
libitext-java 1.4.5-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,748 kB
  • ctags: 12,714
  • sloc: java: 88,264; xml: 305; makefile: 19
file content (205 lines) | stat: -rw-r--r-- 6,482 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package com.lowagie.text.rtf.graphic;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import com.lowagie.text.rtf.RtfAddableElement;

/**
 * The RtfShapePosition stores position and ordering
 * information for one RtfShape.
 * 
 * @version $Revision: 1.2 $
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
 */
public class RtfShapePosition extends RtfAddableElement {
    /**
     * Constant for horizontal positioning relative to the page.
     */
	public static final int POSITION_X_RELATIVE_PAGE = 0;
    /**
     * Constant for horizontal positioning relative to the margin.
     */
	public static final int POSITION_X_RELATIVE_MARGIN = 1;
    /**
     * Constant for horizontal positioning relative to the column.
     */
	public static final int POSITION_X_RELATIVE_COLUMN = 2;
    /**
     * Constant for vertical positioning relative to the page.
     */
	public static final int POSITION_Y_RELATIVE_PAGE = 0;
    /**
     * Constant for vertical positioning relative to the margin.
     */
	public static final int POSITION_Y_RELATIVE_MARGIN = 1;
    /**
     * Constant for vertical positioning relative to the paragraph.
     */
	public static final int POSITION_Y_RELATIVE_PARAGRAPH = 2;
	
    /**
     * The top coordinate of this RtfShapePosition.
     */
	private int top = 0;
    /**
     * The left coordinate of this RtfShapePosition.
     */
	private int left = 0;
    /**
     * The right coordinate of this RtfShapePosition.
     */
	private int right = 0;
    /**
     * The bottom coordinate of this RtfShapePosition.
     */
	private int bottom = 0;
    /**
     * The z order of this RtfShapePosition.
     */
	private int zOrder = 0;
    /**
     * The horizontal relative position.
     */
	private int xRelativePos = POSITION_X_RELATIVE_PAGE;
    /**
     * The vertical relative position.
     */
	private int yRelativePos = POSITION_Y_RELATIVE_PAGE;
    /**
     * Whether to ignore the horizontal relative position.
     */
	private boolean ignoreXRelative = false;
    /**
     * Whether to ignore the vertical relative position.
     */
	private boolean ignoreYRelative = false;
    /**
     * Whether the shape is below the text.
     */
	private boolean shapeBelowText = false;

    /**
     * Constructs a new RtfShapePosition with the four bounding coordinates.
     * 
     * @param top The top coordinate.
     * @param left The left coordinate.
     * @param right The right coordinate.
     * @param bottom The bottom coordinate.
     */
	public RtfShapePosition(int top, int left, int right, int bottom) {
		this.top = top;
		this.left = left;
		this.right = right;
		this.bottom = bottom;
	}
	
    /**
     * Gets whether the shape is below the text.
     * 
     * @return <code>True</code> if the shape is below, <code>false</code> if the text is below.
     */
	public boolean isShapeBelowText() {
		return shapeBelowText;
	}

    /**
     * Sets whether the shape is below the text.
     * 
     * @param shapeBelowText <code>True</code> if the shape is below, <code>false</code> if the text is below.
     */
	public void setShapeBelowText(boolean shapeBelowText) {
		this.shapeBelowText = shapeBelowText;
	}

    /**
     * Sets the relative horizontal position. Use one of the constants
     * provided in this class.
     * 
     * @param relativePos The relative horizontal position to use.
     */
	public void setXRelativePos(int relativePos) {
		xRelativePos = relativePos;
	}

    /**
     * Sets the relative vertical position. Use one of the constants
     * provides in this class.
     * 
     * @param relativePos The relative vertical position to use.
     */
	public void setYRelativePos(int relativePos) {
		yRelativePos = relativePos;
	}

    /**
     * Sets the z order to use.
     * 
     * @param order The z order to use.
     */
	public void setZOrder(int order) {
		zOrder = order;
	}

    /**
     * Set whether to ignore the horizontal relative position.
     * 
     * @param ignoreXRelative <code>True</code> to ignore the horizontal relative position, <code>false</code> otherwise.
     */
	protected void setIgnoreXRelative(boolean ignoreXRelative) {
		this.ignoreXRelative = ignoreXRelative;
	}

    /**
     * Set whether to ignore the vertical relative position.
     * 
     * @param ignoreYRelative <code>True</code> to ignore the vertical relative position, <code>false</code> otherwise.
     */
	protected void setIgnoreYRelative(boolean ignoreYRelative) {
		this.ignoreYRelative = ignoreYRelative;
	}

    /**
     * Write this RtfShapePosition.
     */
	public byte[] write() {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
        	result.write("\\shpleft".getBytes());
        	result.write(intToByteArray(this.left));
        	result.write("\\shptop".getBytes());
        	result.write(intToByteArray(this.top));
        	result.write("\\shpright".getBytes());
        	result.write(intToByteArray(this.right));
        	result.write("\\shpbottom".getBytes());
        	result.write(intToByteArray(this.bottom));
        	result.write("\\shpz".getBytes());
        	result.write(intToByteArray(this.zOrder));
        	switch(this.xRelativePos) {
        	case POSITION_X_RELATIVE_PAGE: result.write("\\shpbxpage".getBytes()); break;
        	case POSITION_X_RELATIVE_MARGIN: result.write("\\shpbxmargin".getBytes()); break;
        	case POSITION_X_RELATIVE_COLUMN: result.write("\\shpbxcolumn".getBytes()); break;
        	}
        	if(this.ignoreXRelative) {
        		result.write("\\shpbxignore".getBytes());
        	}
        	switch(this.yRelativePos) {
        	case POSITION_Y_RELATIVE_PAGE: result.write("\\shpbypage".getBytes()); break;
        	case POSITION_Y_RELATIVE_MARGIN: result.write("\\shpbymargin".getBytes()); break;
        	case POSITION_Y_RELATIVE_PARAGRAPH: result.write("\\shpbypara".getBytes()); break;
        	}
        	if(this.ignoreYRelative) {
        		result.write("\\shpbyignore".getBytes());
        	}
        	if(this.shapeBelowText) {
        		result.write("\\shpfblwtxt1".getBytes());
        	} else {
        		result.write("\\shpfblwtxt0".getBytes());
        	}
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return result.toByteArray();
	}

}