1 17 18 19 20 package org.apache.fop.render.afp.fonts; 21 22 import java.io.UnsupportedEncodingException ; 23 import java.util.HashMap ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.fop.render.afp.modca.AFPConstants; 28 import org.apache.fop.render.afp.tools.StringUtils; 29 30 47 public class CharacterSet { 48 49 52 protected static final Log log = LogFactory.getLog(CharacterSet.class.getName()); 53 54 57 protected String _codePage; 58 59 62 protected String _encoding; 63 64 67 protected String _name; 68 69 72 private byte[] _nameBytes; 73 74 77 protected String _path; 78 79 82 private boolean _isMetricsLoaded = false; 83 84 87 private String _currentOrientation = "0"; 88 89 92 private HashMap _characterSetOrientations; 93 94 102 public CharacterSet( 103 String codePage, 104 String encoding, 105 String name, 106 String path) { 107 108 if (name.length() > 8) { 109 String msg = "Character set name must be a maximum of 8 characters " + name; 110 log.error("Constructor:: " + msg); 111 throw new IllegalArgumentException (msg); 112 } 113 114 if (name.length() < 8) { 115 _name = StringUtils.rpad(name, ' ', 8); 116 } else { 117 _name = name; 118 } 119 120 try { 121 122 _nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); 123 124 } catch (UnsupportedEncodingException usee) { 125 126 _nameBytes = name.getBytes(); 127 log.warn( 128 "Constructor:: UnsupportedEncodingException translating the name " 129 + name); 130 131 } 132 133 _codePage = codePage; 134 _encoding = encoding; 135 _path = path; 136 _characterSetOrientations = new HashMap (4); 137 138 } 139 140 144 public void addCharacterSetOrientation(CharacterSetOrientation cso) { 145 146 _characterSetOrientations.put( 147 String.valueOf(cso.getOrientation()), 148 cso); 149 150 } 151 152 164 public int getAscender() { 165 load(); 166 return getCharacterSetOrientation().getAscender(); 167 } 168 169 175 public int getCapHeight() { 176 load(); 177 return getCharacterSetOrientation().getCapHeight(); 178 } 179 180 186 public int getDescender() { 187 load(); 188 return getCharacterSetOrientation().getDescender(); 189 } 190 191 195 public int getFirstChar() { 196 load(); 197 return getCharacterSetOrientation().getFirstChar(); 198 } 199 200 204 public int getLastChar() { 205 load(); 206 return getCharacterSetOrientation().getLastChar(); 207 } 208 209 212 public String getPath() { 213 return _path; 214 } 215 216 220 public int[] getWidths() { 221 load(); 222 return getCharacterSetOrientation().getWidths(); 223 } 224 225 229 public int getXHeight() { 230 load(); 231 return getCharacterSetOrientation().getXHeight(); 232 } 233 234 240 public int width(int character) { 241 load(); 242 return getCharacterSetOrientation().width(character); 243 } 244 245 249 private void load() { 250 251 if (!_isMetricsLoaded) { 252 253 AFPFontReader.loadCharacterSetMetric(this); 254 _isMetricsLoaded = true; 255 256 } 257 258 } 259 260 264 public String getName() { 265 return _name; 266 } 267 268 272 public byte[] getNameBytes() { 273 return _nameBytes; 274 } 275 276 280 public String getCodePage() { 281 return _codePage; 282 } 283 284 288 public String getEncoding() { 289 return _encoding; 290 } 291 292 303 private CharacterSetOrientation getCharacterSetOrientation() { 304 305 CharacterSetOrientation c = 306 (CharacterSetOrientation) _characterSetOrientations.get( 307 _currentOrientation); 308 return c; 309 310 } 311 312 319 public char mapChar(char c) { 320 return c; 321 } 322 323 } 324 | Popular Tags |