1 17 18 19 20 package org.apache.fop.render.afp.modca; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.io.UnsupportedEncodingException ; 24 25 35 public class ImageSegment extends AbstractAFPObject { 36 37 40 private static final String DEFAULT_NAME = "IS01"; 41 42 45 private String _name; 46 47 50 private byte[] _nameBytes; 51 52 55 private ImageContent _imageContent = null; 56 57 60 public ImageSegment() { 61 62 this(DEFAULT_NAME); 63 64 } 65 66 71 public ImageSegment(String name) { 72 73 if (name.length() != 4) { 74 String msg = "Image segment name must be 4 characters long " + name; 75 log.error("Constructor:: " + msg); 76 throw new IllegalArgumentException (msg); 77 } 78 79 _name = name; 80 81 try { 82 83 _nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); 84 85 } catch (UnsupportedEncodingException usee) { 86 87 _nameBytes = name.getBytes(); 88 log.warn( 89 "Constructor:: UnsupportedEncodingException translating the name " 90 + name); 91 92 } 93 94 } 95 96 104 public void setImageSize(int hresol, int vresol, int hsize, int vsize) { 105 if (_imageContent == null) { 106 _imageContent = new ImageContent(); 107 } 108 _imageContent.setImageSize(hresol, vresol, hsize, vsize); 109 } 110 111 115 public void setImageEncoding(byte encoding) { 116 if (_imageContent == null) { 117 _imageContent = new ImageContent(); 118 } 119 _imageContent.setImageEncoding(encoding); 120 } 121 122 126 public void setImageCompression(byte compression) { 127 if (_imageContent == null) { 128 _imageContent = new ImageContent(); 129 } 130 _imageContent.setImageCompression(compression); 131 } 132 133 137 public void setImageIDESize(byte size) { 138 if (_imageContent == null) { 139 _imageContent = new ImageContent(); 140 } 141 _imageContent.setImageIDESize(size); 142 } 143 144 148 public void setImageIDEColorModel(byte colorModel) { 149 if (_imageContent == null) { 150 _imageContent = new ImageContent(); 151 } 152 _imageContent.setImageIDEColorModel(colorModel); 153 } 154 155 159 public void setImageData(byte data[]) { 160 if (_imageContent == null) { 161 _imageContent = new ImageContent(); 162 } 163 _imageContent.setImageData(data); 164 } 165 166 171 public void writeDataStream(OutputStream os) 172 throws IOException { 173 174 writeStart(os); 175 176 if (_imageContent != null) { 177 _imageContent.writeDataStream(os); 178 } 179 180 writeEnd(os); 181 182 } 183 184 188 private void writeStart(OutputStream os) 189 throws IOException { 190 191 byte[] data = new byte[] { 192 0x70, 0x04, 0x00, 0x00, 0x00, 0x00, }; 199 200 for (int i = 0; i < _nameBytes.length; i++) { 201 202 data[2 + i] = _nameBytes[i]; 203 204 } 205 206 os.write(data); 207 208 } 209 210 214 private void writeEnd(OutputStream os) 215 throws IOException { 216 217 byte[] data = new byte[] { 218 0x71, 0x00, }; 221 222 os.write(data); 223 224 } 225 226 } 227 | Popular Tags |