All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pdfjet.Cell Maven / Gradle / Ivy

/*     */ package com.pdfjet;
/*     */ 
/*     */ public class Cell
/*     */ {
/*     */   protected Font font;
/*     */   protected Font fallbackFont;
/*     */   protected String text;
/*     */   protected Image image;
/*     */   protected Point point;
/*     */   protected CompositeTextLine compositeTextLine;
/*  49 */   protected float width = 70.0F;
/*  50 */   protected float top_padding = 2.0F;
/*  51 */   protected float bottom_padding = 2.0F;
/*  52 */   protected float left_padding = 2.0F;
/*  53 */   protected float right_padding = 2.0F;
/*  54 */   protected float lineWidth = 0.2F;
/*     */ 
/*  56 */   private int background = -1;
/*  57 */   private int pen = 0;
/*  58 */   private int brush = 0;
/*     */ 
/*  76 */   private int properties = 983041;
/*     */   private String uri;
/*  79 */   private int valign = 4194304;
/*     */ 
/*     */   public Cell(Font paramFont)
/*     */   {
/*  88 */     this.font = paramFont;
/*     */   }
/*     */ 
/*     */   public Cell(Font paramFont, String paramString)
/*     */   {
/*  99 */     this.font = paramFont;
/* 100 */     this.text = paramString;
/*     */   }
/*     */ 
/*     */   public Cell(Font paramFont1, Font paramFont2, String paramString)
/*     */   {
/* 112 */     this.font = paramFont1;
/* 113 */     this.fallbackFont = paramFont2;
/* 114 */     this.text = paramString;
/*     */   }
/*     */ 
/*     */   public void setFont(Font paramFont)
/*     */   {
/* 124 */     this.font = paramFont;
/*     */   }
/*     */ 
/*     */   public void setFallbackFont(Font paramFont)
/*     */   {
/* 134 */     this.fallbackFont = paramFont;
/*     */   }
/*     */ 
/*     */   public Font getFont()
/*     */   {
/* 144 */     return this.font;
/*     */   }
/*     */ 
/*     */   public Font getFallbackFont()
/*     */   {
/* 154 */     return this.fallbackFont;
/*     */   }
/*     */ 
/*     */   public void setText(String paramString)
/*     */   {
/* 164 */     this.text = paramString;
/*     */   }
/*     */ 
/*     */   public String getText()
/*     */   {
/* 174 */     return this.text;
/*     */   }
/*     */ 
/*     */   public void setImage(Image paramImage)
/*     */   {
/* 184 */     this.image = paramImage;
/*     */   }
/*     */ 
/*     */   public Image getImage()
/*     */   {
/* 194 */     return this.image;
/*     */   }
/*     */ 
/*     */   public void setPoint(Point paramPoint)
/*     */   {
/* 205 */     this.point = paramPoint;
/*     */   }
/*     */ 
/*     */   public Point getPoint()
/*     */   {
/* 215 */     return this.point;
/*     */   }
/*     */ 
/*     */   public void setCompositeTextLine(CompositeTextLine paramCompositeTextLine)
/*     */   {
/* 225 */     this.compositeTextLine = paramCompositeTextLine;
/*     */   }
/*     */ 
/*     */   public CompositeTextLine getCompositeTextLine()
/*     */   {
/* 235 */     return this.compositeTextLine;
/*     */   }
/*     */ 
/*     */   public void setWidth(float paramFloat)
/*     */   {
/* 245 */     this.width = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getWidth()
/*     */   {
/* 255 */     return this.width;
/*     */   }
/*     */ 
/*     */   public void setTopPadding(float paramFloat)
/*     */   {
/* 265 */     this.top_padding = paramFloat;
/*     */   }
/*     */ 
/*     */   public void setBottomPadding(float paramFloat)
/*     */   {
/* 275 */     this.bottom_padding = paramFloat;
/*     */   }
/*     */ 
/*     */   public void setLeftPadding(float paramFloat)
/*     */   {
/* 285 */     this.left_padding = paramFloat;
/*     */   }
/*     */ 
/*     */   public void setRightPadding(float paramFloat)
/*     */   {
/* 295 */     this.right_padding = paramFloat;
/*     */   }
/*     */ 
/*     */   public void setPadding(float paramFloat)
/*     */   {
/* 305 */     this.top_padding = paramFloat;
/* 306 */     this.bottom_padding = paramFloat;
/* 307 */     this.left_padding = paramFloat;
/* 308 */     this.right_padding = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getHeight()
/*     */   {
/* 318 */     if (this.image != null) {
/* 319 */       return this.image.getHeight() + this.top_padding + this.bottom_padding;
/*     */     }
/* 321 */     return this.font.body_height + this.top_padding + this.bottom_padding;
/*     */   }
/*     */ 
/*     */   public void setLineWidth(float paramFloat)
/*     */   {
/* 331 */     this.lineWidth = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getLineWidth()
/*     */   {
/* 341 */     return this.lineWidth;
/*     */   }
/*     */ 
/*     */   public void setBgColor(int paramInt)
/*     */   {
/* 351 */     this.background = paramInt;
/*     */   }
/*     */ 
/*     */   public int getBgColor()
/*     */   {
/* 360 */     return this.background;
/*     */   }
/*     */ 
/*     */   public void setPenColor(int paramInt)
/*     */   {
/* 370 */     this.pen = paramInt;
/*     */   }
/*     */ 
/*     */   public int getPenColor()
/*     */   {
/* 379 */     return this.pen;
/*     */   }
/*     */ 
/*     */   public void setBrushColor(int paramInt)
/*     */   {
/* 389 */     this.brush = paramInt;
/*     */   }
/*     */ 
/*     */   public int getBrushColor()
/*     */   {
/* 399 */     return this.brush;
/*     */   }
/*     */ 
/*     */   public void setFgColor(int paramInt)
/*     */   {
/* 409 */     this.pen = paramInt;
/* 410 */     this.brush = paramInt;
/*     */   }
/*     */ 
/*     */   protected void setProperties(int paramInt)
/*     */   {
/* 415 */     this.properties = paramInt;
/*     */   }
/*     */ 
/*     */   protected int getProperties()
/*     */   {
/* 420 */     return this.properties;
/*     */   }
/*     */ 
/*     */   public void setColSpan(int paramInt)
/*     */   {
/* 430 */     this.properties &= 16711680;
/* 431 */     this.properties |= paramInt & 0xFFFF;
/*     */   }
/*     */ 
/*     */   public int getColSpan()
/*     */   {
/* 441 */     return this.properties & 0xFFFF;
/*     */   }
/*     */ 
/*     */   public void setBorder(int paramInt, boolean paramBoolean)
/*     */   {
/* 451 */     if (paramBoolean) {
/* 452 */       this.properties |= paramInt;
/*     */     }
/*     */     else
/* 455 */       this.properties &= (paramInt ^ 0xFFFFFFFF) & 0xFFFFFF;
/*     */   }
/*     */ 
/*     */   public boolean getBorder(int paramInt)
/*     */   {
/* 466 */     return (this.properties & paramInt) != 0;
/*     */   }
/*     */ 
/*     */   public void setNoBorders()
/*     */   {
/* 475 */     this.properties &= 15794175;
/*     */   }
/*     */ 
/*     */   public void setTextAlignment(int paramInt)
/*     */   {
/* 486 */     this.properties &= 13631487;
/* 487 */     this.properties |= paramInt & 0x300000;
/*     */   }
/*     */ 
/*     */   public int getTextAlignment()
/*     */   {
/* 497 */     return this.properties & 0x300000;
/*     */   }
/*     */ 
/*     */   public void setVerTextAlignment(int paramInt)
/*     */   {
/* 508 */     this.valign = paramInt;
/*     */   }
/*     */ 
/*     */   public int getVerTextAlignment()
/*     */   {
/* 518 */     return this.valign;
/*     */   }
/*     */ 
/*     */   public void setUnderline(boolean paramBoolean)
/*     */   {
/* 529 */     if (paramBoolean) {
/* 530 */       this.properties |= 4194304;
/*     */     }
/*     */     else
/* 533 */       this.properties &= 12582911;
/*     */   }
/*     */ 
/*     */   public boolean getUnderline()
/*     */   {
/* 544 */     return (this.properties & 0x400000) != 0;
/*     */   }
/*     */ 
/*     */   public void setStrikeout(boolean paramBoolean)
/*     */   {
/* 554 */     if (paramBoolean) {
/* 555 */       this.properties |= 8388608;
/*     */     }
/*     */     else
/* 558 */       this.properties &= 8388607;
/*     */   }
/*     */ 
/*     */   public boolean getStrikeout()
/*     */   {
/* 569 */     return (this.properties & 0x800000) != 0;
/*     */   }
/*     */ 
/*     */   public void setURIAction(String paramString)
/*     */   {
/* 574 */     this.uri = paramString;
/*     */   }
/*     */ 
/*     */   protected void paint(Page paramPage, float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
/*     */     throws Exception
/*     */   {
/* 588 */     if (this.background != -1) {
/* 589 */       drawBackground(paramPage, paramFloat1, paramFloat2, paramFloat3, paramFloat4);
/*     */     }
/* 591 */     if (this.image != null) {
/* 592 */       this.image.setLocation(paramFloat1 + this.left_padding, paramFloat2 + this.top_padding);
/* 593 */       this.image.drawOn(paramPage);
/*     */     }
/* 595 */     drawBorders(paramPage, paramFloat1, paramFloat2, paramFloat3, paramFloat4);
/* 596 */     if (this.text != null) {
/* 597 */       drawText(paramPage, paramFloat1, paramFloat2, paramFloat3, paramFloat4);
/*     */     }
/* 599 */     if (this.point != null) {
/* 600 */       if (this.point.align == 0) {
/* 601 */         this.point.x = (paramFloat1 + 2.0F * this.point.r);
/*     */       }
/* 603 */       else if (this.point.align == 2097152) {
/* 604 */         this.point.x = (paramFloat1 + paramFloat3 - this.right_padding / 2.0F);
/*     */       }
/* 606 */       this.point.y = (paramFloat2 + paramFloat4 / 2.0F);
/* 607 */       paramPage.setBrushColor(this.point.getColor());
/* 608 */       if (this.point.getURIAction() != null) {
/* 609 */         paramPage.addAnnotation(new Annotation(this.point.getURIAction(), null, this.point.x - this.point.r, paramPage.height - (this.point.y - this.point.r), this.point.x + this.point.r, paramPage.height - (this.point.y + this.point.r), null, null, null));
/*     */       }
/*     */ 
/* 620 */       paramPage.drawPoint(this.point);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void drawBackground(Page paramPage, float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
/*     */     throws Exception
/*     */   {
/* 631 */     paramPage.setBrushColor(this.background);
/* 632 */     paramPage.fillRect(paramFloat1, paramFloat2 + this.lineWidth / 2.0F, paramFloat3, paramFloat4 + this.lineWidth);
/*     */   }
/*     */ 
/*     */   private void drawBorders(Page paramPage, float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
/*     */     throws Exception
/*     */   {
/* 643 */     paramPage.setPenColor(this.pen);
/* 644 */     paramPage.setPenWidth(this.lineWidth);
/*     */ 
/* 646 */     if ((getBorder(65536)) && (getBorder(131072)) && (getBorder(262144)) && (getBorder(524288)))
/*     */     {
/* 650 */       paramPage.addBMC("Span", " ", " ");
/* 651 */       paramPage.drawRect(paramFloat1, paramFloat2, paramFloat3, paramFloat4);
/* 652 */       paramPage.addEMC();
/*     */     }
/*     */     else {
/* 655 */       float f = this.lineWidth / 4.0F;
/* 656 */       if (getBorder(65536)) {
/* 657 */         paramPage.addBMC("Span", " ", " ");
/* 658 */         paramPage.moveTo(paramFloat1 - f, paramFloat2);
/* 659 */         paramPage.lineTo(paramFloat1 + paramFloat3, paramFloat2);
/* 660 */         paramPage.strokePath();
/* 661 */         paramPage.addEMC();
/*     */       }
/* 663 */       if (getBorder(131072)) {
/* 664 */         paramPage.addBMC("Span", " ", " ");
/* 665 */         paramPage.moveTo(paramFloat1 - f, paramFloat2 + paramFloat4);
/* 666 */         paramPage.lineTo(paramFloat1 + paramFloat3, paramFloat2 + paramFloat4);
/* 667 */         paramPage.strokePath();
/* 668 */         paramPage.addEMC();
/*     */       }
/* 670 */       if (getBorder(262144)) {
/* 671 */         paramPage.addBMC("Span", " ", " ");
/* 672 */         paramPage.moveTo(paramFloat1, paramFloat2 - f);
/* 673 */         paramPage.lineTo(paramFloat1, paramFloat2 + paramFloat4 + f);
/* 674 */         paramPage.strokePath();
/* 675 */         paramPage.addEMC();
/*     */       }
/* 677 */       if (getBorder(524288)) {
/* 678 */         paramPage.addBMC("Span", " ", " ");
/* 679 */         paramPage.moveTo(paramFloat1 + paramFloat3, paramFloat2 - f);
/* 680 */         paramPage.lineTo(paramFloat1 + paramFloat3, paramFloat2 + paramFloat4 + f);
/* 681 */         paramPage.strokePath();
/* 682 */         paramPage.addEMC();
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void drawText(Page paramPage, float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
/*     */     throws Exception
/*     */   {
/*     */     float f2;
/* 698 */     if (this.valign == 4194304) {
/* 699 */       f2 = paramFloat2 + this.font.ascent + this.top_padding;
/*     */     }
/* 701 */     else if (this.valign == 1048576) {
/* 702 */       f2 = paramFloat2 + paramFloat4 / 2.0F + this.font.ascent / 2.0F;
/*     */     }
/* 704 */     else if (this.valign == 5242880) {
/* 705 */       f2 = paramFloat2 + paramFloat4 - this.bottom_padding;
/*     */     }
/*     */     else {
/* 708 */       throw new Exception("Invalid vertical text alignment option.");
/*     */     }
/*     */ 
/* 711 */     paramPage.setPenColor(this.pen);
/* 712 */     paramPage.setBrushColor(this.brush);
/*     */     float f1;
/* 714 */     if (getTextAlignment() == 2097152) {
/* 715 */       if (this.compositeTextLine == null) {
/* 716 */         f1 = paramFloat1 + paramFloat3 - (this.font.stringWidth(this.text) + this.right_padding);
/* 717 */         paramPage.addBMC("Span", this.text, this.text);
/* 718 */         paramPage.drawString(this.font, this.fallbackFont, this.text, f1, f2);
/* 719 */         paramPage.addEMC();
/* 720 */         if (getUnderline()) {
/* 721 */           underlineText(paramPage, this.font, this.text, f1, f2);
/*     */         }
/* 723 */         if (getStrikeout())
/* 724 */           strikeoutText(paramPage, this.font, this.text, f1, f2);
/*     */       }
/*     */       else
/*     */       {
/* 728 */         f1 = paramFloat1 + paramFloat3 - (this.compositeTextLine.getWidth() + this.right_padding);
/* 729 */         this.compositeTextLine.setPosition(f1, f2);
/* 730 */         paramPage.addBMC("Span", this.text, this.text);
/* 731 */         this.compositeTextLine.drawOn(paramPage);
/* 732 */         paramPage.addEMC();
/*     */       }
/*     */     }
/* 735 */     else if (getTextAlignment() == 1048576) {
/* 736 */       if (this.compositeTextLine == null) {
/* 737 */         f1 = paramFloat1 + this.left_padding + (paramFloat3 - (this.left_padding + this.right_padding) - this.font.stringWidth(this.text)) / 2.0F;
/*     */ 
/* 739 */         paramPage.addBMC("Span", this.text, this.text);
/* 740 */         paramPage.drawString(this.font, this.fallbackFont, this.text, f1, f2);
/* 741 */         paramPage.addEMC();
/* 742 */         if (getUnderline()) {
/* 743 */           underlineText(paramPage, this.font, this.text, f1, f2);
/*     */         }
/* 745 */         if (getStrikeout())
/* 746 */           strikeoutText(paramPage, this.font, this.text, f1, f2);
/*     */       }
/*     */       else
/*     */       {
/* 750 */         f1 = paramFloat1 + this.left_padding + (paramFloat3 - (this.left_padding + this.right_padding) - this.compositeTextLine.getWidth()) / 2.0F;
/*     */ 
/* 752 */         this.compositeTextLine.setPosition(f1, f2);
/* 753 */         paramPage.addBMC("Span", this.text, this.text);
/* 754 */         this.compositeTextLine.drawOn(paramPage);
/* 755 */         paramPage.addEMC();
/*     */       }
/*     */     }
/* 758 */     else if (getTextAlignment() == 0) {
/* 759 */       f1 = paramFloat1 + this.left_padding;
/* 760 */       if (this.compositeTextLine == null) {
/* 761 */         paramPage.addBMC("Span", this.text, this.text);
/* 762 */         paramPage.drawString(this.font, this.fallbackFont, this.text, f1, f2);
/* 763 */         paramPage.addEMC();
/* 764 */         if (getUnderline()) {
/* 765 */           underlineText(paramPage, this.font, this.text, f1, f2);
/*     */         }
/* 767 */         if (getStrikeout())
/* 768 */           strikeoutText(paramPage, this.font, this.text, f1, f2);
/*     */       }
/*     */       else
/*     */       {
/* 772 */         this.compositeTextLine.setPosition(f1, f2);
/* 773 */         paramPage.addBMC("Span", this.text, this.text);
/* 774 */         this.compositeTextLine.drawOn(paramPage);
/* 775 */         paramPage.addEMC();
/*     */       }
/*     */     }
/*     */     else {
/* 779 */       throw new Exception("Invalid Text Alignment!");
/*     */     }
/*     */ 
/* 782 */     if (this.uri != null) {
/* 783 */       float f3 = this.compositeTextLine != null ? this.compositeTextLine.getWidth() : this.font.stringWidth(this.text);
/*     */ 
/* 786 */       paramPage.addAnnotation(new Annotation(this.uri, null, f1, paramPage.height - f2 + this.font.descent, f1 + f3, paramPage.height - f2 + this.font.ascent, null, null, null));
/*     */     }
/*     */   }
/*     */ 
/*     */   private void underlineText(Page paramPage, Font paramFont, String paramString, float paramFloat1, float paramFloat2)
/*     */     throws Exception
/*     */   {
/* 802 */     paramPage.addBMC("Span", "underline", "underline");
/* 803 */     float f = paramFont.getDescent();
/* 804 */     paramPage.setPenWidth(paramFont.underlineThickness);
/* 805 */     paramPage.moveTo(paramFloat1, paramFloat2 + f);
/* 806 */     paramPage.lineTo(paramFloat1 + paramFont.stringWidth(paramString), paramFloat2 + f);
/* 807 */     paramPage.strokePath();
/* 808 */     paramPage.addEMC();
/*     */   }
/*     */ 
/*     */   private void strikeoutText(Page paramPage, Font paramFont, String paramString, float paramFloat1, float paramFloat2)
/*     */     throws Exception
/*     */   {
/* 814 */     paramPage.addBMC("Span", "strike out", "strike out");
/* 815 */     paramPage.setPenWidth(paramFont.underlineThickness);
/* 816 */     paramPage.moveTo(paramFloat1, paramFloat2 - paramFont.getAscent() / 3.0F);
/* 817 */     paramPage.lineTo(paramFloat1 + paramFont.stringWidth(paramString), paramFloat2 - paramFont.getAscent() / 3.0F);
/* 818 */     paramPage.strokePath();
/* 819 */     paramPage.addEMC();
/*     */   }
/*     */ 
/*     */   public int getNumVerCells()
/*     */   {
/* 829 */     int i = 1;
/* 830 */     if (getText() == null) {
/* 831 */       return i;
/*     */     }
/*     */ 
/* 834 */     String[] arrayOfString1 = getText().split("\\r?\\n");
/* 835 */     if (arrayOfString1.length == 0) {
/* 836 */       return i;
/*     */     }
/*     */ 
/* 839 */     i = 0;
/* 840 */     for (String str1 : arrayOfString1) {
/* 841 */       String[] arrayOfString3 = str1.split("\\s+");
/* 842 */       StringBuilder localStringBuilder = new StringBuilder();
/* 843 */       if (arrayOfString3.length > 1) {
/* 844 */         for (int m = 0; m < arrayOfString3.length; m++) {
/* 845 */           String str2 = arrayOfString3[m];
/* 846 */           if (this.font.stringWidth(localStringBuilder.toString() + " " + str2) > getWidth() - (this.left_padding + this.right_padding))
/*     */           {
/* 848 */             localStringBuilder = new StringBuilder(str2);
/* 849 */             i++;
/*     */           }
/*     */           else {
/* 852 */             if (m > 0) {
/* 853 */               localStringBuilder.append(" ");
/*     */             }
/* 855 */             localStringBuilder.append(str2);
/*     */           }
/*     */         }
/*     */       }
/* 859 */       i++;
/*     */     }
/*     */ 
/* 862 */     return i;
/*     */   }
/*     */ 
/*     */   public int getNumVerCells2()
/*     */   {
/* 872 */     int i = 1;
/* 873 */     if (getText() == null) {
/* 874 */       return i;
/*     */     }
/* 876 */     StringBuilder localStringBuilder = new StringBuilder();
/* 877 */     for (int j = 0; j < this.text.length(); j++) {
/* 878 */       String str = new String(new char[] { this.text.charAt(j) });
/* 879 */       if (this.font.stringWidth(localStringBuilder.toString() + str) > getWidth() - (this.left_padding + this.right_padding))
/*     */       {
/* 881 */         i++;
/* 882 */         localStringBuilder.setLength(0);
/*     */       }
/* 884 */       localStringBuilder.append(str);
/*     */     }
/* 886 */     return i;
/*     */   }
/*     */ }

/* Location:           E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
 * Qualified Name:     com.pdfjet.Cell
 * JD-Core Version:    0.6.2
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy