1 package com.lowagie.text.rtf.graphic; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.IOException ; 5 import java.io.OutputStream ; 6 7 import com.lowagie.text.rtf.RtfAddableElement; 8 9 17 public class RtfShapePosition extends RtfAddableElement { 18 21 public static final int POSITION_X_RELATIVE_PAGE = 0; 22 25 public static final int POSITION_X_RELATIVE_MARGIN = 1; 26 29 public static final int POSITION_X_RELATIVE_COLUMN = 2; 30 33 public static final int POSITION_Y_RELATIVE_PAGE = 0; 34 37 public static final int POSITION_Y_RELATIVE_MARGIN = 1; 38 41 public static final int POSITION_Y_RELATIVE_PARAGRAPH = 2; 42 43 46 private int top = 0; 47 50 private int left = 0; 51 54 private int right = 0; 55 58 private int bottom = 0; 59 62 private int zOrder = 0; 63 66 private int xRelativePos = POSITION_X_RELATIVE_PAGE; 67 70 private int yRelativePos = POSITION_Y_RELATIVE_PAGE; 71 74 private boolean ignoreXRelative = false; 75 78 private boolean ignoreYRelative = false; 79 82 private boolean shapeBelowText = false; 83 84 92 public RtfShapePosition(int top, int left, int right, int bottom) { 93 this.top = top; 94 this.left = left; 95 this.right = right; 96 this.bottom = bottom; 97 } 98 99 104 public boolean isShapeBelowText() { 105 return shapeBelowText; 106 } 107 108 113 public void setShapeBelowText(boolean shapeBelowText) { 114 this.shapeBelowText = shapeBelowText; 115 } 116 117 123 public void setXRelativePos(int relativePos) { 124 xRelativePos = relativePos; 125 } 126 127 133 public void setYRelativePos(int relativePos) { 134 yRelativePos = relativePos; 135 } 136 137 142 public void setZOrder(int order) { 143 zOrder = order; 144 } 145 146 151 protected void setIgnoreXRelative(boolean ignoreXRelative) { 152 this.ignoreXRelative = ignoreXRelative; 153 } 154 155 160 protected void setIgnoreYRelative(boolean ignoreYRelative) { 161 this.ignoreYRelative = ignoreYRelative; 162 } 163 164 168 public byte[] write() 169 { 170 ByteArrayOutputStream result = new ByteArrayOutputStream (); 171 try { 172 writeContent(result); 173 } catch(IOException ioe) { 174 ioe.printStackTrace(); 175 } 176 return result.toByteArray(); 177 } 178 181 public void writeContent(final OutputStream result) throws IOException 182 { 183 result.write("\\shpleft".getBytes()); 184 result.write(intToByteArray(this.left)); 185 result.write("\\shptop".getBytes()); 186 result.write(intToByteArray(this.top)); 187 result.write("\\shpright".getBytes()); 188 result.write(intToByteArray(this.right)); 189 result.write("\\shpbottom".getBytes()); 190 result.write(intToByteArray(this.bottom)); 191 result.write("\\shpz".getBytes()); 192 result.write(intToByteArray(this.zOrder)); 193 switch(this.xRelativePos) { 194 case POSITION_X_RELATIVE_PAGE: result.write("\\shpbxpage".getBytes()); break; 195 case POSITION_X_RELATIVE_MARGIN: result.write("\\shpbxmargin".getBytes()); break; 196 case POSITION_X_RELATIVE_COLUMN: result.write("\\shpbxcolumn".getBytes()); break; 197 } 198 if(this.ignoreXRelative) { 199 result.write("\\shpbxignore".getBytes()); 200 } 201 switch(this.yRelativePos) { 202 case POSITION_Y_RELATIVE_PAGE: result.write("\\shpbypage".getBytes()); break; 203 case POSITION_Y_RELATIVE_MARGIN: result.write("\\shpbymargin".getBytes()); break; 204 case POSITION_Y_RELATIVE_PARAGRAPH: result.write("\\shpbypara".getBytes()); break; 205 } 206 if(this.ignoreYRelative) { 207 result.write("\\shpbyignore".getBytes()); 208 } 209 if(this.shapeBelowText) { 210 result.write("\\shpfblwtxt1".getBytes()); 211 } else { 212 result.write("\\shpfblwtxt0".getBytes()); 213 } 214 } 215 216 } 217 | Popular Tags |