1 3 package org.faceless.pdf; 4 5 import java.util.*; 6 import java.awt.Color ; 7 import java.awt.Paint ; 8 import java.awt.GradientPaint ; 9 10 69 public class PDFStyle extends PeeredObject implements Cloneable 70 { 71 74 public static final int TEXTALIGN_LEFT = 1; 75 76 79 public static final int TEXTALIGN_RIGHT = 2; 80 81 84 public static final int TEXTALIGN_CENTER = 4; 85 86 92 public static final int TEXTALIGN_JUSTIFY = 8; 93 94 97 public static final int TEXTALIGN_BASELINE = 0; 98 99 102 public static final int TEXTALIGN_TOP = 16; 103 104 107 public static final int TEXTALIGN_MIDDLE = 32; 108 109 112 public static final int TEXTALIGN_BOTTOM = 64; 113 114 118 public static final int LINECAP_BUTT = 0; 119 120 124 public static final int LINECAP_ROUND = 1; 125 126 130 public static final int LINECAP_SQUARE = 2; 131 132 137 public static final int LINEJOIN_MITER = 0; 138 139 143 public static final int LINEJOIN_ROUND = 1; 144 145 150 public static final int LINEJOIN_BEVEL = 2; 151 152 156 public static final int FONTSTYLE_FILLED = 0; 157 158 162 public static final int FONTSTYLE_OUTLINE = 1; 163 164 168 public static final int FONTSTYLE_FILLEDOUTLINE = 2; 169 170 176 public static final int FONTSTYLE_INVISIBLE = 3; 177 178 183 public static final int PAINTMETHOD_NONZEROWINDING = 0; 184 185 190 public static final int PAINTMETHOD_EVENODD = 1; 191 192 193 final org.faceless.pdf2.PDFStyle style; 194 195 Object getPeer() 196 { 197 return style; 198 } 199 200 PDFStyle(org.faceless.pdf2.PDFStyle style) 201 { 202 this.style=style; 203 } 204 205 209 public static final PDFStyle LINKSTYLE; 210 211 static { 212 LINKSTYLE = new PDFStyle(); 213 LINKSTYLE.setTextUnderline(true); 214 } 215 216 230 public PDFStyle() 231 { 232 style = new org.faceless.pdf2.PDFStyle(); 233 } 234 235 244 public void setTextJustificationRatio(float in) 245 { 246 style.setTextJustificationRatio(in); 247 } 248 249 255 public void setTextUnderline(boolean on) 256 { 257 style.setTextUnderline(on); 258 } 259 260 265 public void setTextStrikeOut(boolean on) 266 { 267 style.setTextStrikeOut(on); 268 } 269 270 278 public void setLineCap(int type) 279 { 280 style.setLineCap(type); 281 } 282 283 291 public void setLineJoin(int type) 292 { 293 style.setLineJoin(type); 294 } 295 296 318 public void setLineDash(float on, float off, float phase) 319 { 320 style.setLineDash(on,off,phase); 321 } 322 323 336 public void setLineWeighting(float thickness) 337 { 338 style.setLineWeighting(thickness); 339 } 340 341 362 public void setTextLineSpacing(float factor) 363 { 364 style.setTextLineSpacing(factor); 365 } 366 367 371 public void setTextAlign(int align) 372 { 373 style.setTextAlign(align); 374 } 375 376 390 public void setTextRise(float offset) 391 { 392 style.setTextRise(offset); 393 } 394 395 411 public void setFillColor(Paint paint) 412 { 413 if (paint!=null && paint instanceof ColorPattern) { 414 paint = ((ColorPattern)paint).pattern; 415 } 416 style.setFillColor(paint); 417 } 418 419 427 public void setLineColor(Color color) 428 { 429 style.setLineColor(color); 430 } 431 432 444 public void setPaintMethod(int method) 445 { 446 int newmethod = style.PAINTMETHOD_EVENODD; 447 if (method==PAINTMETHOD_NONZEROWINDING) newmethod = style.PAINTMETHOD_NONZEROWINDING; 448 style.setPaintMethod(newmethod); 449 } 450 451 456 public void setFont(PDFFont font, float size) 457 { 458 style.setFont(font==null ? null : font.font, size); 459 } 460 461 470 public void addBackupFont(PDFFont font) 471 { 472 style.addBackupFont(font==null ? null : font.font); 473 } 474 475 484 public PDFFont getBackupFont(int i) 485 { 486 return (PDFFont)PeeredObject.getPeer(style.getBackupFont(i)); 487 } 488 489 495 public void setFontStyle(int fontstyle) 496 { 497 int newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLED; 498 if (fontstyle==FONTSTYLE_OUTLINE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_OUTLINE; 499 else if (fontstyle==FONTSTYLE_FILLEDOUTLINE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLEDOUTLINE; 500 else if (fontstyle==FONTSTYLE_INVISIBLE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_INVISIBLE; 501 style.setFontStyle(newfontstyle); 502 } 503 504 517 public void setTextIndent(float indent) 518 { 519 style.setTextIndent(indent); 520 } 521 522 529 public float getTextLength(String s) 530 { 531 return style.getTextLength(s); 532 } 533 534 541 public float getTextLength(char[] c, int off, int len) 542 { 543 return style.getTextLength(c,off,len); 544 } 545 546 552 public float getTextLeft(String s) 553 { 554 return style.getTextLeft(s); 555 } 556 557 563 public float getTextRight(String s) 564 { 565 return style.getTextRight(s); 566 } 567 568 574 public float getTextTop(String s) 575 { 576 return style.getTextTop(s); 577 } 578 579 585 public float getTextBottom(String s) 586 { 587 return style.getTextBottom(s); 588 } 589 590 596 public float getFontLeading() 597 { 598 return style.getFontLeading(); 599 } 600 601 604 public float getLineWeighting() 605 { 606 return style.getLineWeighting(); 607 } 608 609 612 public int getPaintMethod() 613 { 614 return PAINTMETHOD_EVENODD; 615 } 616 617 622 public float getTextLineSpacing() 623 { 624 return style.getTextLineSpacing(); 625 } 626 627 630 public float getTextJustificationRatio() 631 { 632 return 0.5f; 633 } 634 635 638 public boolean getTextUnderline() 639 { 640 return false; 641 } 642 643 646 public boolean getTextStrikeOut() 647 { 648 return false; 649 } 650 651 655 public Paint getFillColor() 656 { 657 return style.getFillColor(); 658 } 659 660 663 public Color getLineColor() 664 { 665 return (Color )style.getLineColor(); 666 } 667 668 671 public PDFFont getFont() 672 { 673 return (PDFFont)PeeredObject.getPeer(style.getFont()); 674 } 675 676 679 public float getFontSize() 680 { 681 return style.getFontSize(); 682 } 683 684 687 public int getLineJoin() 688 { 689 return style.getLineJoin(); 690 } 691 692 695 public int getLineCap() 696 { 697 return style.getLineCap(); 698 } 699 700 705 public float[] getLineDashPattern() 706 { 707 float[] f = new float[2]; 708 f[0] = style.getLineDashOn(); 709 f[1] = style.getLineDashOff(); 710 return f; 711 } 712 713 717 public float getLineDashPhase() 718 { 719 return style.getLineDashPhase(); 720 } 721 722 725 public int getTextAlign() 726 { 727 return 0; 728 } 729 730 733 public int getFontStyle() 734 { 735 int newfontstyle=style.getFontStyle(); 736 if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_OUTLINE) return FONTSTYLE_OUTLINE; 737 else if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLEDOUTLINE) return FONTSTYLE_FILLEDOUTLINE; 738 else if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_INVISIBLE) return FONTSTYLE_INVISIBLE; 739 return FONTSTYLE_FILLED; 740 } 741 742 745 public float getTextRise() 746 { 747 return 0; 748 } 749 750 754 public float getTrackKern() 755 { 756 return 0; 757 } 758 759 763 public float getTextIndent() 764 { 765 return style.getTextIndent(); 766 } 767 768 771 public Object clone() 772 { 773 return PeeredObject.getPeer(style.clone()); 774 } 775 776 779 public PDFStyle styleClone() 780 { 781 return (PDFStyle)clone(); 782 } 783 784 789 public PDFStyle superscriptClone() 790 { 791 return new PDFStyle(style.superscriptClone()); 792 } 793 794 799 public PDFStyle subscriptClone() 800 { 801 return new PDFStyle(style.subscriptClone()); 802 } 803 804 825 public void setTrackKerning(float millipoints) 826 { 827 style.setTrackKerning(millipoints); 828 } 829 830 834 public static final int FORMSTYLE_SOLID=0; 835 836 840 public static final int FORMSTYLE_INSET=1; 841 842 846 public static final int FORMSTYLE_BEVEL=2; 847 848 852 public static final int FORMSTYLE_UNDERLINE=3; 853 854 864 public void setFormStyle(int formstyle) 865 { 866 int newstyle=style.FORMSTYLE_SOLID; 867 if (formstyle==FORMSTYLE_SOLID) newstyle=style.FORMSTYLE_SOLID; 868 else if (formstyle==FORMSTYLE_BEVEL) newstyle=style.FORMSTYLE_BEVEL; 869 else if (formstyle==FORMSTYLE_INSET) newstyle=style.FORMSTYLE_INSET; 870 else if (formstyle==FORMSTYLE_UNDERLINE) newstyle=style.FORMSTYLE_UNDERLINE; 871 style.setFormStyle(newstyle); 872 } 873 874 878 public int getFormStyle() 879 { 880 int formstyle = style.getFormStyle(); 881 int newstyle=FORMSTYLE_SOLID; 882 if (formstyle==style.FORMSTYLE_SOLID) newstyle=FORMSTYLE_SOLID; 883 else if (formstyle==style.FORMSTYLE_BEVEL) newstyle=FORMSTYLE_BEVEL; 884 else if (formstyle==style.FORMSTYLE_INSET) newstyle=FORMSTYLE_INSET; 885 else if (formstyle==style.FORMSTYLE_UNDERLINE) newstyle=FORMSTYLE_UNDERLINE; 886 887 return newstyle; 888 } 889 } 890 | Popular Tags |