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

com.pdfjet.TextBlock Maven / Gradle / Ivy

/*     */ package com.pdfjet;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class TextBlock
/*     */ {
/*  40 */   private Font font = null;
/*  41 */   private Font fallbackFont = null;
/*     */ 
/*  43 */   private String text = null;
/*  44 */   private float space = 0.0F;
/*  45 */   private int textAlign = 0;
/*     */   private float x;
/*     */   private float y;
/*  49 */   private float w = 300.0F;
/*  50 */   private float h = 200.0F;
/*     */ 
/*  52 */   private int background = 16777215;
/*  53 */   private int brush = 0;
/*     */ 
/*     */   public TextBlock(Font paramFont)
/*     */   {
/*  62 */     this.font = paramFont;
/*  63 */     this.space = this.font.getDescent();
/*     */   }
/*     */ 
/*     */   public TextBlock setFallbackFont(Font paramFont)
/*     */   {
/*  74 */     this.fallbackFont = paramFont;
/*  75 */     return this;
/*     */   }
/*     */ 
/*     */   public TextBlock setText(String paramString)
/*     */   {
/*  86 */     this.text = paramString;
/*  87 */     return this;
/*     */   }
/*     */ 
/*     */   public TextBlock setLocation(float paramFloat1, float paramFloat2)
/*     */   {
/*  99 */     this.x = paramFloat1;
/* 100 */     this.y = paramFloat2;
/* 101 */     return this;
/*     */   }
/*     */ 
/*     */   public TextBlock setWidth(float paramFloat)
/*     */   {
/* 112 */     this.w = paramFloat;
/* 113 */     return this;
/*     */   }
/*     */ 
/*     */   public float getWidth()
/*     */   {
/* 123 */     return this.w;
/*     */   }
/*     */ 
/*     */   public TextBlock setHeight(float paramFloat)
/*     */   {
/* 134 */     this.h = paramFloat;
/* 135 */     return this;
/*     */   }
/*     */ 
/*     */   public float getHeight()
/*     */     throws Exception
/*     */   {
/* 145 */     return drawOn(null).h;
/*     */   }
/*     */ 
/*     */   public TextBlock setSpaceBetweenLines(float paramFloat)
/*     */   {
/* 156 */     this.space = paramFloat;
/* 157 */     return this;
/*     */   }
/*     */ 
/*     */   public float getSpaceBetweenLines()
/*     */   {
/* 167 */     return this.space;
/*     */   }
/*     */ 
/*     */   public TextBlock setTextAlignment(int paramInt)
/*     */   {
/* 178 */     this.textAlign = paramInt;
/* 179 */     return this;
/*     */   }
/*     */ 
/*     */   public int getTextAlignment()
/*     */   {
/* 189 */     return this.textAlign;
/*     */   }
/*     */ 
/*     */   public TextBlock setBgColor(int paramInt)
/*     */   {
/* 200 */     this.background = paramInt;
/* 201 */     return this;
/*     */   }
/*     */ 
/*     */   public int getBgColor()
/*     */   {
/* 211 */     return this.background;
/*     */   }
/*     */ 
/*     */   public TextBlock setBrushColor(int paramInt)
/*     */   {
/* 222 */     this.brush = paramInt;
/* 223 */     return this;
/*     */   }
/*     */ 
/*     */   public int getBrushColor()
/*     */   {
/* 233 */     return this.brush;
/*     */   }
/*     */ 
/*     */   public TextBlock drawOn(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 244 */     if (paramPage != null) {
/* 245 */       if (getBgColor() != 16777215) {
/* 246 */         paramPage.setBrushColor(this.background);
/* 247 */         paramPage.fillRect(this.x, this.y, this.w, this.h);
/*     */       }
/* 249 */       paramPage.setBrushColor(this.brush);
/*     */     }
/* 251 */     return drawText(paramPage);
/*     */   }
/*     */ 
/*     */   private TextBlock drawText(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 257 */     ArrayList localArrayList = new ArrayList();
/* 258 */     StringBuilder localStringBuilder = new StringBuilder();
/* 259 */     String[] arrayOfString1 = this.text.split("\\r?\\n");
/* 260 */     for (String str1 : arrayOfString1) {
/* 261 */       if (this.font.stringWidth(str1) < this.w) {
/* 262 */         localArrayList.add(str1);
/*     */       }
/*     */       else {
/* 265 */         localStringBuilder.setLength(0);
/* 266 */         String[] arrayOfString3 = str1.split("\\s+");
/* 267 */         for (String str2 : arrayOfString3) {
/* 268 */           if (this.font.stringWidth(localStringBuilder.toString() + " " + str2) < this.w)
/*     */           {
/* 270 */             localStringBuilder.append(" " + str2);
/*     */           }
/*     */           else {
/* 273 */             localArrayList.add(localStringBuilder.toString().trim());
/* 274 */             localStringBuilder.setLength(0);
/* 275 */             localStringBuilder.append(str2);
/*     */           }
/*     */         }
/*     */ 
/* 279 */         if (!localStringBuilder.toString().trim().equals("")) {
/* 280 */           localArrayList.add(localStringBuilder.toString().trim());
/*     */         }
/*     */       }
/*     */     }
/* 284 */     arrayOfString1 = (String[])localArrayList.toArray(new String[0]);
/*     */ 
/* 287 */     float f2 = this.y + this.font.getAscent();
/*     */ 
/* 289 */     for (??? = 0; ??? < arrayOfString1.length; ???++)
/*     */     {
/*     */       float f1;
/* 290 */       if (this.textAlign == 0) {
/* 291 */         f1 = this.x;
/*     */       }
/* 293 */       else if (this.textAlign == 2097152) {
/* 294 */         f1 = this.x + this.w - this.font.stringWidth(arrayOfString1[???]);
/*     */       }
/* 296 */       else if (this.textAlign == 1048576) {
/* 297 */         f1 = this.x + (this.w - this.font.stringWidth(arrayOfString1[???])) / 2.0F;
/*     */       }
/*     */       else {
/* 300 */         throw new Exception("Invalid text alignment option.");
/*     */       }
/*     */ 
/* 303 */       if (paramPage != null) {
/* 304 */         paramPage.drawString(this.font, this.fallbackFont, arrayOfString1[???], f1, f2);
/*     */       }
/*     */ 
/* 308 */       if (??? < arrayOfString1.length - 1) {
/* 309 */         f2 += this.font.getBodyHeight() + this.space;
/*     */       }
/*     */       else {
/* 312 */         f2 += this.font.getDescent() + this.space;
/*     */       }
/*     */     }
/*     */ 
/* 316 */     this.h = (f2 - this.y);
/*     */ 
/* 318 */     return this;
/*     */   }
/*     */ }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy