1 17 18 19 20 package org.apache.fop.render.afp.modca; 21 22 import java.awt.Color ; 23 import java.io.UnsupportedEncodingException ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.fop.render.afp.fonts.AFPFont; 28 import org.apache.fop.render.afp.tools.StringUtils; 29 30 50 public abstract class AbstractPageObject extends AbstractNamedAFPObject { 51 52 55 protected ActiveEnvironmentGroup _activeEnvironmentGroup = null; 56 57 60 private PresentationTextObject _presentationTextObject = null; 61 62 65 protected List _objects = new ArrayList (); 66 67 70 protected ArrayList _tagLogicalElements = new ArrayList (); 71 72 75 protected ArrayList _segments = new ArrayList (); 76 77 80 private int _width; 81 82 85 private int _height; 86 87 90 private int _rotation = 0; 91 92 95 private boolean _complete = false; 96 97 110 public AbstractPageObject(String name, int width, int height, int rotation) { 111 112 super(name); 113 114 _name = name; 115 116 _rotation = rotation; 117 _width = width; 118 _height = height; 119 120 123 _activeEnvironmentGroup = new ActiveEnvironmentGroup(_width, _height); 124 125 if (_rotation != 0) { 126 switch (_rotation) { 127 case 90: 128 _activeEnvironmentGroup.setPosition(_width, 0, _rotation); 129 break; 130 case 180: 131 _activeEnvironmentGroup.setPosition(_width, _height, _rotation); 132 break; 133 case 270: 134 _activeEnvironmentGroup.setPosition(0, _height, _rotation); 135 break; 136 } 137 } 138 139 142 _presentationTextObject = new PresentationTextObject(); 143 _objects.add(_presentationTextObject); 144 145 } 146 147 159 public void createFont(byte fontReference, AFPFont font, int size) { 160 161 _activeEnvironmentGroup.createFont(fontReference, font, size, 0); 162 163 } 164 165 184 public void createLine(int x1, int y1, int x2, int y2, int thickness, int rotation, Color col) { 185 186 if (_presentationTextObject == null) { 187 _presentationTextObject = new PresentationTextObject(); 188 _objects.add(_presentationTextObject); 189 } 190 _presentationTextObject.createLineData(x1, y1, x2, y2, thickness, rotation, col); 191 192 } 193 194 215 public void createText(int fontNumber, int x, int y, int rotation, Color col, int vsci, int ica, byte[] data) { 216 217 if (_presentationTextObject == null) { 218 _presentationTextObject = new PresentationTextObject(); 219 _objects.add(_presentationTextObject); 220 } 221 _presentationTextObject.createTextData(fontNumber, x, y, rotation, col, vsci, ica, data); 222 223 } 224 225 229 public void endPage() { 230 231 if (_presentationTextObject != null) { 232 _presentationTextObject.endControlSequence(); 233 } 234 235 _complete = true; 236 237 } 238 239 259 public void createShading(int x, int y, int w, int h, int red, int green, 260 int blue) { 261 262 int xCoord = 0; 263 int yCoord = 0; 264 int width = 0; 265 int height = 0; 266 267 switch (_rotation) { 268 case 90: 269 xCoord = _width - y - h; 270 yCoord = x; 271 width = h; 272 height = w; 273 break; 274 case 180: 275 xCoord = _width - x - w; 276 yCoord = _height - y - h; 277 width = w; 278 height = h; 279 break; 280 case 270: 281 xCoord = y; 282 yCoord = _height - x - w; 283 width = h; 284 height = w; 285 break; 286 default: 287 xCoord = x; 288 yCoord = y; 289 width = w; 290 height = h; 291 break; 292 } 293 294 float shade = (float) ((red * 0.3) + (green * 0.59) + (blue * 0.11)); 296 297 int greyscale = Math.round((shade / 255) * 16); 298 299 String imageName = "IMG" 300 + StringUtils.lpad(String.valueOf(_objects.size() + 1), 301 '0', 5); 302 303 IMImageObject io = new IMImageObject(imageName); 304 ImageOutputControl ioc = new ImageOutputControl(0, 0); 305 ImageInputDescriptor iid = new ImageInputDescriptor(); 306 ImageCellPosition icp = new ImageCellPosition(xCoord, yCoord); 307 icp.setXFillSize(width); 308 icp.setYFillSize(height); 309 icp.setXSize(64); 310 icp.setYSize(8); 311 312 ImageRasterData ird = new ImageRasterData(ImageRasterPattern 314 .getRasterData(greyscale)); 315 316 io.setImageOutputControl(ioc); 317 io.setImageInputDescriptor(iid); 318 io.setImageCellPosition(icp); 319 io.setImageRasterData(ird); 320 _objects.add(io); 321 322 } 323 324 328 public ImageObject getImageObject() { 329 330 if (_presentationTextObject != null) { 331 _presentationTextObject.endControlSequence(); 332 } 333 _presentationTextObject = null; 334 335 String imageName = "IMG" 336 + StringUtils.lpad(String.valueOf(_objects.size() + 1), 337 '0', 5); 338 339 ImageObject io = new ImageObject(imageName); 340 _objects.add(io); 341 return io; 342 } 343 344 352 public void createTagLogicalElement(String name, String value) { 353 354 TagLogicalElement tle = new TagLogicalElement(name, value); 355 _tagLogicalElements.add(tle); 356 357 } 358 359 369 public void createIncludePageSegment(String name, int xCoor, int yCoor) { 370 371 IncludePageSegment ips = new IncludePageSegment(name, xCoor, yCoor); 372 _segments.add(ips); 373 374 } 375 376 381 public ActiveEnvironmentGroup getActiveEnvironmentGroup() { 382 return _activeEnvironmentGroup; 383 } 384 385 388 public boolean isComplete() { 389 return _complete; 390 } 391 392 395 public int getHeight() { 396 return _height; 397 } 398 399 402 public int getWidth() { 403 return _width; 404 } 405 406 409 public int getRotation() { 410 return _rotation; 411 } 412 413 } | Popular Tags |