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

com.pdfjet.TextBox Maven / Gradle / Ivy

/*     */ package com.pdfjet;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ public class TextBox
/*     */   implements Drawable
/*     */ {
/*     */   protected Font font;
/*     */   protected String text;
/*     */   protected float x;
/*     */   protected float y;
/*  58 */   protected float width = 300.0F;
/*  59 */   protected float height = 0.0F;
/*  60 */   protected float spacing = 3.0F;
/*  61 */   protected float margin = 1.0F;
/*  62 */   private float lineWidth = 0.0F;
/*     */ 
/*  64 */   private int background = 16777215;
/*  65 */   private int pen = 0;
/*  66 */   private int brush = 0;
/*  67 */   private int valign = 0;
/*     */   private Font fallbackFont;
/*  69 */   private Map colors = null;
/*     */ 
/*  87 */   private int properties = 983041;
/*     */ 
/*     */   public TextBox(Font paramFont)
/*     */   {
/*  96 */     this.font = paramFont;
/*     */   }
/*     */ 
/*     */   public TextBox(Font paramFont, String paramString)
/*     */   {
/* 107 */     this.font = paramFont;
/* 108 */     this.text = paramString;
/*     */   }
/*     */ 
/*     */   public TextBox(Font paramFont, String paramString, double paramDouble1, double paramDouble2)
/*     */   {
/* 121 */     this(paramFont, paramString, (float)paramDouble1, (float)paramDouble2);
/*     */   }
/*     */ 
/*     */   public TextBox(Font paramFont, String paramString, float paramFloat1, float paramFloat2)
/*     */   {
/* 134 */     this.font = paramFont;
/* 135 */     this.text = paramString;
/* 136 */     this.width = paramFloat1;
/* 137 */     this.height = paramFloat2;
/*     */   }
/*     */ 
/*     */   public void setFont(Font paramFont)
/*     */   {
/* 147 */     this.font = paramFont;
/*     */   }
/*     */ 
/*     */   public Font getFont()
/*     */   {
/* 157 */     return this.font;
/*     */   }
/*     */ 
/*     */   public void setText(String paramString)
/*     */   {
/* 167 */     this.text = paramString;
/*     */   }
/*     */ 
/*     */   public String getText()
/*     */   {
/* 177 */     return this.text;
/*     */   }
/*     */ 
/*     */   public void setPosition(double paramDouble1, double paramDouble2)
/*     */   {
/* 188 */     setPosition((float)paramDouble1, (float)paramDouble2);
/*     */   }
/*     */ 
/*     */   public void setPosition(float paramFloat1, float paramFloat2)
/*     */   {
/* 199 */     setLocation(paramFloat1, paramFloat2);
/*     */   }
/*     */ 
/*     */   public void setLocation(float paramFloat1, float paramFloat2)
/*     */   {
/* 210 */     this.x = paramFloat1;
/* 211 */     this.y = paramFloat2;
/*     */   }
/*     */ 
/*     */   public float getX()
/*     */   {
/* 221 */     return this.x;
/*     */   }
/*     */ 
/*     */   public float getY()
/*     */   {
/* 231 */     return this.y;
/*     */   }
/*     */ 
/*     */   public void setWidth(double paramDouble)
/*     */   {
/* 241 */     this.width = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setWidth(float paramFloat)
/*     */   {
/* 251 */     this.width = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getWidth()
/*     */   {
/* 261 */     return this.width;
/*     */   }
/*     */ 
/*     */   public void setHeight(double paramDouble)
/*     */   {
/* 271 */     this.height = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setHeight(float paramFloat)
/*     */   {
/* 281 */     this.height = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getHeight()
/*     */   {
/* 291 */     return this.height;
/*     */   }
/*     */ 
/*     */   public void setMargin(double paramDouble)
/*     */   {
/* 301 */     this.margin = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setMargin(float paramFloat)
/*     */   {
/* 311 */     this.margin = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getMargin()
/*     */   {
/* 321 */     return this.margin;
/*     */   }
/*     */ 
/*     */   public void setLineWidth(double paramDouble)
/*     */   {
/* 331 */     this.lineWidth = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setLineWidth(float paramFloat)
/*     */   {
/* 341 */     this.lineWidth = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getLineWidth()
/*     */   {
/* 351 */     return this.lineWidth;
/*     */   }
/*     */ 
/*     */   public void setSpacing(double paramDouble)
/*     */   {
/* 361 */     this.spacing = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setSpacing(float paramFloat)
/*     */   {
/* 371 */     this.spacing = paramFloat;
/*     */   }
/*     */ 
/*     */   public float getSpacing()
/*     */   {
/* 381 */     return this.spacing;
/*     */   }
/*     */ 
/*     */   public void setBgColor(int paramInt)
/*     */   {
/* 391 */     this.background = paramInt;
/*     */   }
/*     */ 
/*     */   public void setBgColor(int[] paramArrayOfInt)
/*     */   {
/* 401 */     this.background = (paramArrayOfInt[0] << 16 | paramArrayOfInt[1] << 8 | paramArrayOfInt[2]);
/*     */   }
/*     */ 
/*     */   public void setBgColor(double[] paramArrayOfDouble)
/*     */   {
/* 411 */     setBgColor(new int[] { (int)paramArrayOfDouble[0], (int)paramArrayOfDouble[1], (int)paramArrayOfDouble[2] });
/*     */   }
/*     */ 
/*     */   public int getBgColor()
/*     */   {
/* 421 */     return this.background;
/*     */   }
/*     */ 
/*     */   public void setFgColor(int paramInt)
/*     */   {
/* 431 */     this.pen = paramInt;
/* 432 */     this.brush = paramInt;
/*     */   }
/*     */ 
/*     */   public void setFgColor(int[] paramArrayOfInt)
/*     */   {
/* 442 */     this.pen = (paramArrayOfInt[0] << 16 | paramArrayOfInt[1] << 8 | paramArrayOfInt[2]);
/* 443 */     this.brush = this.pen;
/*     */   }
/*     */ 
/*     */   public void setFgColor(double[] paramArrayOfDouble)
/*     */   {
/* 453 */     setPenColor(new int[] { (int)paramArrayOfDouble[0], (int)paramArrayOfDouble[1], (int)paramArrayOfDouble[2] });
/* 454 */     setBrushColor(this.pen);
/*     */   }
/*     */ 
/*     */   public void setPenColor(int paramInt)
/*     */   {
/* 464 */     this.pen = paramInt;
/*     */   }
/*     */ 
/*     */   public void setPenColor(int[] paramArrayOfInt)
/*     */   {
/* 474 */     this.pen = (paramArrayOfInt[0] << 16 | paramArrayOfInt[1] << 8 | paramArrayOfInt[2]);
/*     */   }
/*     */ 
/*     */   public void setPenColor(double[] paramArrayOfDouble)
/*     */   {
/* 484 */     setPenColor(new int[] { (int)paramArrayOfDouble[0], (int)paramArrayOfDouble[1], (int)paramArrayOfDouble[2] });
/*     */   }
/*     */ 
/*     */   public int getPenColor()
/*     */   {
/* 494 */     return this.pen;
/*     */   }
/*     */ 
/*     */   public void setBrushColor(int paramInt)
/*     */   {
/* 504 */     this.brush = paramInt;
/*     */   }
/*     */ 
/*     */   public void setBrushColor(int[] paramArrayOfInt)
/*     */   {
/* 514 */     this.brush = (paramArrayOfInt[0] << 16 | paramArrayOfInt[1] << 8 | paramArrayOfInt[2]);
/*     */   }
/*     */ 
/*     */   public void setBrushColor(double[] paramArrayOfDouble)
/*     */   {
/* 524 */     setBrushColor(new int[] { (int)paramArrayOfDouble[0], (int)paramArrayOfDouble[1], (int)paramArrayOfDouble[2] });
/*     */   }
/*     */ 
/*     */   public int getBrushColor()
/*     */   {
/* 534 */     return this.brush;
/*     */   }
/*     */ 
/*     */   public void setBorder(int paramInt, boolean paramBoolean)
/*     */   {
/* 544 */     if (paramBoolean) {
/* 545 */       this.properties |= paramInt;
/*     */     }
/*     */     else
/* 548 */       this.properties &= (paramInt ^ 0xFFFFFFFF) & 0xFFFFFF;
/*     */   }
/*     */ 
/*     */   public boolean getBorder(int paramInt)
/*     */   {
/* 559 */     return (this.properties & paramInt) != 0;
/*     */   }
/*     */ 
/*     */   public void setNoBorders()
/*     */   {
/* 568 */     this.properties &= 15794175;
/*     */   }
/*     */ 
/*     */   public void setTextAlignment(int paramInt)
/*     */   {
/* 579 */     this.properties &= 13631487;
/* 580 */     this.properties |= paramInt & 0x300000;
/*     */   }
/*     */ 
/*     */   public int getTextAlignment()
/*     */   {
/* 590 */     return this.properties & 0x300000;
/*     */   }
/*     */ 
/*     */   public void setUnderline(boolean paramBoolean)
/*     */   {
/* 601 */     if (paramBoolean) {
/* 602 */       this.properties |= 4194304;
/*     */     }
/*     */     else
/* 605 */       this.properties &= 12582911;
/*     */   }
/*     */ 
/*     */   public boolean getUnderline()
/*     */   {
/* 616 */     return (this.properties & 0x400000) != 0;
/*     */   }
/*     */ 
/*     */   public void setStrikeout(boolean paramBoolean)
/*     */   {
/* 627 */     if (paramBoolean) {
/* 628 */       this.properties |= 8388608;
/*     */     }
/*     */     else
/* 631 */       this.properties &= 8388607;
/*     */   }
/*     */ 
/*     */   public boolean getStrikeout()
/*     */   {
/* 642 */     return (this.properties & 0x800000) != 0;
/*     */   }
/*     */ 
/*     */   public void setFallbackFont(Font paramFont)
/*     */   {
/* 647 */     this.fallbackFont = paramFont;
/*     */   }
/*     */ 
/*     */   public Font getFallbackFont()
/*     */   {
/* 652 */     return this.fallbackFont;
/*     */   }
/*     */ 
/*     */   public void setVerticalAlignment(int paramInt)
/*     */   {
/* 662 */     this.valign = paramInt;
/*     */   }
/*     */ 
/*     */   public int getVerticalAlignment()
/*     */   {
/* 667 */     return this.valign;
/*     */   }
/*     */ 
/*     */   public void setTextColors(Map paramMap)
/*     */   {
/* 672 */     this.colors = paramMap;
/*     */   }
/*     */ 
/*     */   public Map getTextColors()
/*     */   {
/* 677 */     return this.colors;
/*     */   }
/*     */ 
/*     */   public float[] drawOn(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 689 */     return drawOn(paramPage, true);
/*     */   }
/*     */ 
/*     */   public float[] drawOn(Page paramPage, boolean paramBoolean)
/*     */     throws Exception
/*     */   {
/* 702 */     return drawTextAndBorders(paramPage, paramBoolean);
/*     */   }
/*     */ 
/*     */   private void drawBackground(Page paramPage) throws Exception
/*     */   {
/* 707 */     paramPage.setBrushColor(this.background);
/* 708 */     paramPage.fillRect(this.x, this.y, this.width, this.height);
/*     */   }
/*     */ 
/*     */   private void drawBorders(Page paramPage) throws Exception
/*     */   {
/* 713 */     paramPage.setPenColor(this.pen);
/* 714 */     paramPage.setPenWidth(this.lineWidth);
/*     */ 
/* 716 */     if ((getBorder(65536)) && (getBorder(131072)) && (getBorder(262144)) && (getBorder(524288)))
/*     */     {
/* 720 */       paramPage.drawRect(this.x, this.y, this.width, this.height);
/*     */     }
/*     */     else {
/* 723 */       if (getBorder(65536)) {
/* 724 */         paramPage.moveTo(this.x, this.y);
/* 725 */         paramPage.lineTo(this.x + this.width, this.y);
/* 726 */         paramPage.strokePath();
/*     */       }
/* 728 */       if (getBorder(131072)) {
/* 729 */         paramPage.moveTo(this.x, this.y + this.height);
/* 730 */         paramPage.lineTo(this.x + this.width, this.y + this.height);
/* 731 */         paramPage.strokePath();
/*     */       }
/* 733 */       if (getBorder(262144)) {
/* 734 */         paramPage.moveTo(this.x, this.y);
/* 735 */         paramPage.lineTo(this.x, this.y + this.height);
/* 736 */         paramPage.strokePath();
/*     */       }
/* 738 */       if (getBorder(524288)) {
/* 739 */         paramPage.moveTo(this.x + this.width, this.y);
/* 740 */         paramPage.lineTo(this.x + this.width, this.y + this.height);
/* 741 */         paramPage.strokePath();
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private float[] drawTextAndBorders(Page paramPage, boolean paramBoolean)
/*     */     throws Exception
/*     */   {
/* 749 */     if (paramBoolean) {
/* 750 */       if (getBgColor() != 16777215) {
/* 751 */         drawBackground(paramPage);
/*     */       }
/*     */ 
/* 754 */       paramPage.setPenColor(this.pen);
/* 755 */       paramPage.setBrushColor(this.brush);
/* 756 */       paramPage.setPenWidth(this.font.underlineThickness);
/*     */     }
/*     */ 
/* 759 */     float f1 = this.width - 2.0F * this.margin;
/* 760 */     ArrayList localArrayList = new ArrayList();
/* 761 */     StringBuilder localStringBuilder = new StringBuilder();
/* 762 */     String[] arrayOfString = this.text.split("\\r?\\n");
/*     */     int j;
/*     */     String str3;
/* 763 */     for (int i = 0; i < arrayOfString.length; i++) {
/* 764 */       String str1 = arrayOfString[i];
/*     */ 
/* 787 */       String str2 = "  ";
/* 788 */       if (this.font.stringWidth(str1) < f1 - this.font.stringWidth(str2)) {
/* 789 */         localArrayList.add(str1);
/*     */       }
/*     */       else {
/* 792 */         localStringBuilder.setLength(0);
/* 793 */         for (j = 0; j < str1.length(); j++) {
/* 794 */           localStringBuilder.append(str1.charAt(j));
/* 795 */           if (this.font.stringWidth(localStringBuilder.toString()) >= f1 - this.font.stringWidth(str2)) {
/* 796 */             while ((j > 0) && (str1.charAt(j) != ' ')) {
/* 797 */               j--;
/*     */             }
/* 799 */             str3 = str1.substring(0, j).replaceAll("\\s+$", "");
/* 800 */             localArrayList.add(str3);
/* 801 */             localStringBuilder.setLength(0);
/* 802 */             while ((j < str1.length()) && (str1.charAt(j) == ' ')) {
/* 803 */               j++;
/*     */             }
/* 805 */             str1 = str1.substring(j);
/* 806 */             j = 0;
/*     */           }
/*     */         }
/* 809 */         if (!str1.equals("")) {
/* 810 */           localArrayList.add(str1);
/*     */         }
/*     */       }
/*     */     }
/* 814 */     arrayOfString = (String[])localArrayList.toArray(new String[0]);
/*     */ 
/* 816 */     float f2 = this.font.getBodyHeight() + this.spacing;
/*     */ 
/* 818 */     float f4 = this.y + this.font.ascent + this.margin;
/*     */     float f3;
/* 820 */     if (this.height > 0.0F)
/*     */     {
/* 822 */       if (this.valign == 5242880) {
/* 823 */         f4 += this.height - arrayOfString.length * f2;
/*     */       }
/* 825 */       else if (this.valign == 1048576) {
/* 826 */         f4 += (this.height - arrayOfString.length * f2) / 2.0F;
/*     */       }
/*     */ 
/* 829 */       for (j = 0; j < arrayOfString.length; j++)
/*     */       {
/* 831 */         if (getTextAlignment() == 2097152) {
/* 832 */           f3 = this.x + this.width - (this.font.stringWidth(arrayOfString[j]) + this.margin);
/*     */         }
/* 834 */         else if (getTextAlignment() == 1048576) {
/* 835 */           f3 = this.x + (this.width - this.font.stringWidth(arrayOfString[j])) / 2.0F;
/*     */         }
/*     */         else
/*     */         {
/* 839 */           f3 = this.x + this.margin;
/*     */         }
/*     */ 
/* 842 */         if ((f4 + this.font.getBodyHeight() + this.spacing + this.font.getDescent() >= this.y + this.height) && (j < arrayOfString.length - 1))
/*     */         {
/* 844 */           str3 = arrayOfString[j];
/* 845 */           int k = str3.lastIndexOf(' ');
/* 846 */           if (k != -1) {
/* 847 */             arrayOfString[j] = (str3.substring(0, k) + " ...");
/*     */           }
/*     */           else {
/* 850 */             arrayOfString[j] = (str3 + " ...");
/*     */           }
/*     */         }
/*     */ 
/* 854 */         if (f4 + this.font.getDescent() < this.y + this.height) {
/* 855 */           if (paramBoolean) {
/* 856 */             drawText(paramPage, this.font, this.fallbackFont, arrayOfString[j], f3, f4, this.colors);
/*     */           }
/* 858 */           f4 += this.font.getBodyHeight() + this.spacing;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */     else
/*     */     {
/* 866 */       for (j = 0; j < arrayOfString.length; j++)
/*     */       {
/* 868 */         if (getTextAlignment() == 2097152) {
/* 869 */           f3 = this.x + this.width - (this.font.stringWidth(arrayOfString[j]) + this.margin);
/*     */         }
/* 871 */         else if (getTextAlignment() == 1048576) {
/* 872 */           f3 = this.x + (this.width - this.font.stringWidth(arrayOfString[j])) / 2.0F;
/*     */         }
/*     */         else
/*     */         {
/* 876 */           f3 = this.x + this.margin;
/*     */         }
/*     */ 
/* 879 */         if (paramBoolean) {
/* 880 */           drawText(paramPage, this.font, this.fallbackFont, arrayOfString[j], f3, f4, this.colors);
/*     */         }
/*     */ 
/* 883 */         f4 += this.font.getBodyHeight() + this.spacing;
/*     */       }
/*     */ 
/* 886 */       this.height = (f4 - (this.y + this.font.ascent + this.margin));
/*     */     }
/*     */ 
/* 889 */     if (paramBoolean) {
/* 890 */       drawBorders(paramPage);
/*     */     }
/*     */ 
/* 893 */     return new float[] { this.x + this.width, this.y + this.height };
/*     */   }
/*     */ 
/*     */   private void drawText(Page paramPage, Font paramFont1, Font paramFont2, String paramString, float paramFloat1, float paramFloat2, Map paramMap)
/*     */     throws Exception
/*     */   {
/* 905 */     if (paramFont2 == null) {
/* 906 */       if (paramMap == null) {
/* 907 */         paramPage.drawString(paramFont1, paramString, paramFloat1, paramFloat2);
/*     */       }
/*     */       else {
/* 910 */         paramPage.drawString(paramFont1, paramString, paramFloat1, paramFloat2, paramMap);
/*     */       }
/*     */     }
/*     */     else {
/* 914 */       paramPage.drawString(paramFont1, paramFont2, paramString, paramFloat1, paramFloat2);
/*     */     }
/*     */ 
/* 917 */     float f1 = paramFont1.stringWidth(paramString);
/*     */     float f2;
/* 918 */     if (getUnderline()) {
/* 919 */       f2 = paramFont1.underlinePosition;
/* 920 */       paramPage.moveTo(paramFloat1, paramFloat2 + f2);
/* 921 */       paramPage.lineTo(paramFloat1 + f1, paramFloat2 + f2);
/* 922 */       paramPage.strokePath();
/*     */     }
/* 924 */     if (getStrikeout()) {
/* 925 */       f2 = paramFont1.body_height / 4.0F;
/* 926 */       paramPage.moveTo(paramFloat1, paramFloat2 - f2);
/* 927 */       paramPage.lineTo(paramFloat1 + f1, paramFloat2 - f2);
/* 928 */       paramPage.strokePath();
/*     */     }
/*     */   }
/*     */ }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy