1 31 package org.pdfbox.cos; 32 33 import java.io.IOException ; 34 import java.io.OutputStream ; 35 36 import java.util.Collections ; 37 import java.util.HashMap ; 38 import java.util.Map ; 39 40 import org.pdfbox.exceptions.COSVisitorException; 41 import org.pdfbox.persistence.util.COSHEXTable; 42 43 44 50 public final class COSName extends COSBase implements Comparable 51 { 52 56 private static Map nameMap = Collections.synchronizedMap( new HashMap (8192) ); 57 58 59 62 public static final COSName A = new COSName( "A" ); 63 66 public static final COSName AA = new COSName( "AA" ); 67 70 public static final COSName ACRO_FORM = new COSName( "AcroForm" ); 71 74 public static final COSName ANNOTS = new COSName( "Annots" ); 75 78 public static final COSName ART_BOX = new COSName("ArtBox" ); 79 82 public static final COSName ASCII85_DECODE = new COSName( "ASCII85Decode" ); 83 86 public static final COSName ASCII85_DECODE_ABBREVIATION = new COSName( "A85" ); 87 90 public static final COSName ASCII_HEX_DECODE = new COSName( "ASCIIHexDecode" ); 91 94 public static final COSName ASCII_HEX_DECODE_ABBREVIATION = new COSName( "AHx" ); 95 98 public static final COSName AP = new COSName( "AP" ); 99 102 public static final COSName B = new COSName( "B" ); 103 106 public static final COSName BASE_ENCODING = new COSName( "BaseEncoding" ); 107 110 public static final COSName BASE_FONT = new COSName( "BaseFont" ); 111 114 public static final COSName BBOX = new COSName( "BBox" ); 115 118 public static final COSName BLEED_BOX = new COSName("BleedBox" ); 119 122 public static final COSName CATALOG = new COSName( "Catalog" ); 123 126 public static final COSName CALGRAY = new COSName( "CalGray" ); 127 130 public static final COSName CALRGB = new COSName( "CalRGB" ); 131 134 public static final COSName CCITTFAX_DECODE = new COSName( "CCITTFaxDecode" ); 135 138 public static final COSName CCITTFAX_DECODE_ABBREVIATION = new COSName( "CCF" ); 139 142 public static final COSName COLORSPACE = new COSName( "ColorSpace" ); 143 146 public static final COSName CONTENTS = new COSName( "Contents" ); 147 150 public static final COSName COUNT = new COSName( "Count" ); 151 154 public static final COSName CROP_BOX = new COSName( "CropBox" ); 155 158 public static final COSName DCT_DECODE = new COSName( "DCTDecode" ); 159 162 public static final COSName DCT_DECODE_ABBREVIATION = new COSName( "DCT" ); 163 166 public static final COSName DESCENDANT_FONTS = new COSName( "DescendantFonts" ); 167 170 public static final COSName DEST = new COSName( "Dest" ); 171 174 public static final COSName DEVICECMYK = new COSName( "DeviceCMYK" ); 175 178 public static final COSName DEVICEGRAY = new COSName( "DeviceGray" ); 179 182 public static final COSName DEVICEN = new COSName( "DeviceN" ); 183 186 public static final COSName DEVICERGB = new COSName( "DeviceRGB" ); 187 190 public static final COSName DIFFERENCES = new COSName( "Differences" ); 191 194 public static final COSName DV = new COSName( "DV" ); 195 198 public static final COSName ENCODING = new COSName( "Encoding" ); 199 202 public static final COSName ENCODING_90MS_RKSJ_H = new COSName( "90ms-RKSJ-H" ); 203 206 public static final COSName ENCODING_90MS_RKSJ_V = new COSName( "90ms-RKSJ-V" ); 207 210 public static final COSName ENCODING_ETEN_B5_H = new COSName( "ETen?B5?H" ); 211 214 public static final COSName ENCODING_ETEN_B5_V = new COSName( "ETen?B5?V" ); 215 218 public static final COSName FIELDS = new COSName( "Fields" ); 219 222 public static final COSName FILTER = new COSName( "Filter" ); 223 226 public static final COSName FIRST_CHAR = new COSName( "FirstChar" ); 227 230 public static final COSName FLATE_DECODE = new COSName( "FlateDecode" ); 231 234 public static final COSName FLATE_DECODE_ABBREVIATION = new COSName( "Fl" ); 235 238 public static final COSName FONT = new COSName( "Font" ); 239 242 public static final COSName FONT_FILE = new COSName("FontFile"); 243 246 public static final COSName FONT_FILE2 = new COSName("FontFile2"); 247 250 public static final COSName FONT_FILE3 = new COSName("FontFile3"); 251 254 public static final COSName FONT_DESC = new COSName("FontDescriptor"); 255 258 public static final COSName FONT_MATRIX = new COSName("FontMatrix" ); 259 262 public static final COSName FORMTYPE = new COSName( "FormType" ); 263 266 public static final COSName FRM = new COSName( "FRM" ); 267 270 public static final COSName H = new COSName( "H" ); 271 274 public static final COSName HEIGHT = new COSName( "Height" ); 275 278 public static final COSName ICCBASED = new COSName( "ICCBased" ); 279 282 public static final COSName IDENTITY_H = new COSName( "Identity-H" ); 283 286 public static final COSName IMAGE = new COSName( "Image" ); 287 290 public static final COSName INDEXED = new COSName( "Indexed" ); 291 294 public static final COSName INFO = new COSName( "Info" ); 295 298 public static final COSName JPX_DECODE = new COSName( "JPXDecode" ); 299 302 public static final COSName KIDS = new COSName( "Kids" ); 303 306 public static final COSName LAB = new COSName( "Lab" ); 307 310 public static final COSName LAST_CHAR = new COSName( "LastChar" ); 311 314 public static final COSName LENGTH = new COSName( "Length" ); 315 318 public static final COSName LENGTH1 = new COSName( "Length1" ); 319 322 public static final COSName LZW_DECODE = new COSName( "LZWDecode" ); 323 326 public static final COSName LZW_DECODE_ABBREVIATION = new COSName( "LZW" ); 327 330 public static final COSName MAC_ROMAN_ENCODING = new COSName( "MacRomanEncoding" ); 331 334 public static final COSName MATRIX = new COSName( "Matrix" ); 335 338 public static final COSName MEDIA_BOX = new COSName( "MediaBox" ); 339 342 public static final COSName METADATA = new COSName( "Metadata" ); 343 346 public static final COSName N = new COSName( "N" ); 347 350 public static final COSName NAME = new COSName( "Name" ); 351 354 public static final COSName P = new COSName( "P" ); 355 358 public static final COSName PAGE = new COSName( "Page" ); 359 362 public static final COSName PAGES = new COSName( "Pages" ); 363 366 public static final COSName PARENT = new COSName( "Parent" ); 367 370 public static final COSName PATTERN = new COSName( "Pattern" ); 371 374 public static final COSName PDF_DOC_ENCODING = new COSName( "PDFDocEncoding" ); 375 378 public static final COSName PREV = new COSName( "Prev" ); 379 382 public static final COSName R = new COSName( "R" ); 383 386 public static final COSName RESOURCES = new COSName( "Resources" ); 387 390 public static final COSName ROOT = new COSName( "Root" ); 391 394 public static final COSName ROTATE = new COSName( "Rotate" ); 395 398 public static final COSName RUN_LENGTH_DECODE = new COSName( "RunLengthDecode" ); 399 402 public static final COSName RUN_LENGTH_DECODE_ABBREVIATION = new COSName( "RL" ); 403 406 public static final COSName SEPARATION = new COSName( "Separation" ); 407 410 public static final COSName STANDARD_ENCODING = new COSName( "StandardEncoding" ); 411 414 public static final COSName SUBTYPE = new COSName( "Subtype" ); 415 418 public static final COSName TRIM_BOX = new COSName("TrimBox" ); 419 422 public static final COSName TRUE_TYPE = new COSName("TrueType" ); 423 426 public static final COSName TO_UNICODE = new COSName( "ToUnicode" ); 427 430 public static final COSName TYPE = new COSName( "Type" ); 431 434 public static final COSName TYPE0 = new COSName( "Type0" ); 435 438 public static final COSName V = new COSName( "V" ); 439 442 public static final COSName VERSION = new COSName( "Version" ); 443 446 public static final COSName WIDTHS = new COSName( "Widths" ); 447 450 public static final COSName WIN_ANSI_ENCODING = new COSName( "WinAnsiEncoding" ); 451 454 public static final COSName XOBJECT = new COSName( "XObject" ); 455 456 459 public static final byte[] NAME_PREFIX = new byte[] { 47 }; 463 public static final byte[] NAME_ESCAPE = new byte[] { 35 }; 465 private String name; 466 private int hashCode; 467 468 475 public static final COSName getPDFName( String aName ) 476 { 477 COSName name = null; 478 if( aName != null ) 479 { 480 name = (COSName)nameMap.get( aName ); 481 if( name == null ) 482 { 483 name = new COSName( aName ); 485 } 486 } 487 return name; 488 } 489 490 496 private COSName( String aName ) 497 { 498 name = aName; 499 nameMap.put( aName, this ); 500 hashCode = name.hashCode(); 501 } 502 503 508 public String getName() 509 { 510 return name; 511 } 512 513 516 public String toString() 517 { 518 return "COSName{" + name + "}"; 519 } 520 521 524 public boolean equals( Object o ) 525 { 526 boolean retval = this == o; 527 if( !retval && o instanceof COSName ) 528 { 529 COSName other = (COSName)o; 530 retval = name == other.name || name.equals( other.name ); 531 } 532 return retval; 533 } 534 535 538 public int hashCode() 539 { 540 return hashCode; 541 } 542 543 546 public int compareTo(Object o) 547 { 548 COSName other = (COSName)o; 549 return this.name.compareTo( other.name ); 550 } 551 552 553 554 561 public Object accept(ICOSVisitor visitor) throws COSVisitorException 562 { 563 return visitor.visitFromName(this); 564 } 565 566 572 public void writePDF( OutputStream output ) throws IOException 573 { 574 output.write(NAME_PREFIX); 575 byte[] bytes = getName().getBytes(); 576 for (int i = 0; i < bytes.length;i++) 577 { 578 int current = ((bytes[i]+256)%256); 579 580 if(current <= 32 || current >= 127 || 581 current == '(' || 582 current == ')' || 583 current == '[' || 584 current == ']' || 585 current == '/' || 586 current == '%' || 587 current == '<' || 588 current == '>' || 589 current == NAME_ESCAPE[0] ) 590 { 591 output.write(NAME_ESCAPE); 592 output.write(COSHEXTable.TABLE[current]); 593 } 594 else 595 { 596 output.write(current); 597 } 598 } 599 } 600 } | Popular Tags |