Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.pdfjet.TextColumn Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.util.ArrayList;
/* */ import java.util.List;
/* */
/* */ public class TextColumn
/* */ {
/* 20 */ protected int alignment = 0;
/* */ protected int rotate;
/* */ private float x;
/* */ private float y;
/* */ private float w;
/* */ private float h;
/* */ private float x1;
/* */ private float y1;
/* */ private float line_height;
/* 31 */ private float space_between_lines = 1.0F;
/* 32 */ private float space_between_paragraphs = 2.0F;
/* */ private List paragraphs;
/* 36 */ private boolean lineBetweenParagraphs = false;
/* */
/* */ public TextColumn()
/* */ {
/* 44 */ this.paragraphs = new ArrayList();
/* */ }
/* */
/* */ public TextColumn(int paramInt)
/* */ throws Exception
/* */ {
/* 54 */ this.rotate = paramInt;
/* 55 */ if ((this.rotate != 0) && (this.rotate != 90) && (this.rotate != 270))
/* */ {
/* 58 */ throw new Exception("Invalid rotation angle. Please use 0, 90 or 270 degrees.");
/* */ }
/* */
/* 61 */ this.paragraphs = new ArrayList();
/* */ }
/* */
/* */ public void setLineBetweenParagraphs(boolean paramBoolean)
/* */ {
/* 72 */ this.lineBetweenParagraphs = paramBoolean;
/* */ }
/* */
/* */ public void setSpaceBetweenLines(float paramFloat)
/* */ {
/* 77 */ this.space_between_lines = paramFloat;
/* */ }
/* */
/* */ public void setSpaceBetweenParagraphs(float paramFloat)
/* */ {
/* 82 */ this.space_between_paragraphs = paramFloat;
/* */ }
/* */
/* */ public void setPosition(double paramDouble1, double paramDouble2)
/* */ {
/* 93 */ setPosition((float)paramDouble1, (float)paramDouble2);
/* */ }
/* */
/* */ public void setPosition(float paramFloat1, float paramFloat2)
/* */ {
/* 104 */ setLocation(paramFloat1, paramFloat2);
/* */ }
/* */
/* */ public void setLocation(float paramFloat1, float paramFloat2)
/* */ {
/* 115 */ this.x = paramFloat1;
/* 116 */ this.y = paramFloat2;
/* 117 */ this.x1 = paramFloat1;
/* 118 */ this.y1 = paramFloat2;
/* */ }
/* */
/* */ public void setSize(double paramDouble1, double paramDouble2)
/* */ {
/* 129 */ setSize((float)paramDouble1, (float)paramDouble2);
/* */ }
/* */
/* */ public void setSize(float paramFloat1, float paramFloat2)
/* */ {
/* 140 */ this.w = paramFloat1;
/* 141 */ this.h = paramFloat2;
/* */ }
/* */
/* */ public void setWidth(float paramFloat)
/* */ {
/* 151 */ this.w = paramFloat;
/* */ }
/* */
/* */ public void setAlignment(int paramInt)
/* */ {
/* 161 */ this.alignment = paramInt;
/* */ }
/* */
/* */ public void setLineSpacing(double paramDouble)
/* */ {
/* 171 */ this.space_between_lines = ((float)paramDouble);
/* */ }
/* */
/* */ public void setLineSpacing(float paramFloat)
/* */ {
/* 181 */ this.space_between_lines = paramFloat;
/* */ }
/* */
/* */ public void addParagraph(Paragraph paramParagraph)
/* */ {
/* 191 */ this.paragraphs.add(paramParagraph);
/* */ }
/* */
/* */ public void removeLastParagraph()
/* */ {
/* 200 */ if (this.paragraphs.size() >= 1)
/* 201 */ this.paragraphs.remove(this.paragraphs.size() - 1);
/* */ }
/* */
/* */ public Dimension getSize()
/* */ throws Exception
/* */ {
/* 213 */ Point localPoint = drawOn(null, false);
/* 214 */ return new Dimension(this.w, localPoint.y - this.y);
/* */ }
/* */
/* */ public Point drawOn(Page paramPage)
/* */ throws Exception
/* */ {
/* 225 */ return drawOn(paramPage, true);
/* */ }
/* */
/* */ public Point drawOn(Page paramPage, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 237 */ Point localPoint = null;
/* 238 */ for (int i = 0; i < this.paragraphs.size(); i++) {
/* 239 */ Paragraph localParagraph = (Paragraph)this.paragraphs.get(i);
/* 240 */ this.alignment = localParagraph.alignment;
/* 241 */ localPoint = drawParagraphOn(paramPage, localParagraph, paramBoolean);
/* */ }
/* */
/* 244 */ setLocation(this.x, this.y);
/* 245 */ return localPoint;
/* */ }
/* */
/* */ private Point drawParagraphOn(Page paramPage, Paragraph paramParagraph, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 252 */ ArrayList localArrayList = new ArrayList();
/* 253 */ float f = 0.0F;
/* 254 */ for (int i = 0; i < paramParagraph.list.size(); i++) {
/* 255 */ TextLine localTextLine1 = (TextLine)paramParagraph.list.get(i);
/* 256 */ if (i == 0) {
/* 257 */ this.line_height = (localTextLine1.font.body_height + this.space_between_lines);
/* 258 */ if (this.rotate == 0) {
/* 259 */ this.y1 += localTextLine1.font.ascent;
/* */ }
/* 261 */ else if (this.rotate == 90) {
/* 262 */ this.x1 += localTextLine1.font.ascent;
/* */ }
/* 264 */ else if (this.rotate == 270) {
/* 265 */ this.x1 -= localTextLine1.font.ascent;
/* */ }
/* */ }
/* */
/* 269 */ String[] arrayOfString = localTextLine1.str.split("\\s+");
/* 270 */ TextLine localTextLine2 = null;
/* 271 */ for (int j = 0; j < arrayOfString.length; j++) {
/* 272 */ String str = arrayOfString[j];
/* 273 */ localTextLine2 = new TextLine(localTextLine1.font, str);
/* 274 */ localTextLine2.setColor(localTextLine1.getColor());
/* 275 */ localTextLine2.setUnderline(localTextLine1.getUnderline());
/* 276 */ localTextLine2.setStrikeout(localTextLine1.getStrikeout());
/* 277 */ localTextLine2.setVerticalOffset(localTextLine1.getVerticalOffset());
/* 278 */ localTextLine2.setURIAction(localTextLine1.getURIAction());
/* 279 */ localTextLine2.setGoToAction(localTextLine1.getGoToAction());
/* 280 */ localTextLine2.setFallbackFont(localTextLine1.getFallbackFont());
/* 281 */ f += localTextLine1.font.stringWidth(localTextLine1.getFallbackFont(), str);
/* 282 */ if (f < this.w) {
/* 283 */ localArrayList.add(localTextLine2);
/* 284 */ f += localTextLine1.font.stringWidth(localTextLine1.getFallbackFont(), " ");
/* */ }
/* */ else {
/* 287 */ drawLineOfText(paramPage, localArrayList, paramBoolean);
/* 288 */ moveToNextLine();
/* 289 */ localArrayList.clear();
/* 290 */ localArrayList.add(localTextLine2);
/* 291 */ f = localTextLine1.font.stringWidth(localTextLine1.getFallbackFont(), str + " ");
/* */ }
/* */ }
/* 294 */ if (!localTextLine1.getTrailingSpace()) {
/* 295 */ f -= localTextLine1.font.stringWidth(localTextLine1.getFallbackFont(), " ");
/* 296 */ localTextLine2.setTrailingSpace(false);
/* */ }
/* */ }
/* 299 */ drawNonJustifiedLine(paramPage, localArrayList, paramBoolean);
/* */
/* 301 */ if (this.lineBetweenParagraphs) {
/* 302 */ return moveToNextLine();
/* */ }
/* */
/* 305 */ return moveToNextParagraph(this.space_between_paragraphs);
/* */ }
/* */
/* */ private Point moveToNextLine()
/* */ {
/* 310 */ if (this.rotate == 0) {
/* 311 */ this.x1 = this.x;
/* 312 */ this.y1 += this.line_height;
/* */ }
/* 314 */ else if (this.rotate == 90) {
/* 315 */ this.x1 += this.line_height;
/* 316 */ this.y1 = this.y;
/* */ }
/* 318 */ else if (this.rotate == 270) {
/* 319 */ this.x1 -= this.line_height;
/* 320 */ this.y1 = this.y;
/* */ }
/* 322 */ return new Point(this.x1, this.y1);
/* */ }
/* */
/* */ private Point moveToNextParagraph(float paramFloat)
/* */ {
/* 327 */ if (this.rotate == 0) {
/* 328 */ this.x1 = this.x;
/* 329 */ this.y1 += paramFloat;
/* */ }
/* 331 */ else if (this.rotate == 90) {
/* 332 */ this.x1 += paramFloat;
/* 333 */ this.y1 = this.y;
/* */ }
/* 335 */ else if (this.rotate == 270) {
/* 336 */ this.x1 -= paramFloat;
/* 337 */ this.y1 = this.y;
/* */ }
/* 339 */ return new Point(this.x1, this.y1);
/* */ }
/* */
/* */ private void drawLineOfText(Page paramPage, List paramList, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 345 */ if (this.alignment == 3145728) {
/* 346 */ float f1 = 0.0F;
/* 347 */ for (int i = 0; i < paramList.size(); i++) {
/* 348 */ TextLine localTextLine1 = (TextLine)paramList.get(i);
/* 349 */ f1 += localTextLine1.font.stringWidth(localTextLine1.getFallbackFont(), localTextLine1.str);
/* */ }
/* 351 */ float f2 = (this.w - f1) / (paramList.size() - 1);
/* 352 */ for (int j = 0; j < paramList.size(); j++) {
/* 353 */ TextLine localTextLine2 = (TextLine)paramList.get(j);
/* 354 */ localTextLine2.setLocation(this.x1, this.y1 + localTextLine2.getVerticalOffset());
/* */
/* 356 */ if (localTextLine2.getGoToAction() != null) {
/* 357 */ paramPage.addAnnotation(new Annotation(null, localTextLine2.getGoToAction(), this.x, paramPage.height - (this.y - localTextLine2.font.ascent), this.x + localTextLine2.font.stringWidth(localTextLine2.getFallbackFont(), localTextLine2.getText()), paramPage.height - (this.y - localTextLine2.font.descent), null, null, null));
/* */ }
/* */
/* 369 */ if (this.rotate == 0) {
/* 370 */ localTextLine2.setTextDirection(0);
/* 371 */ localTextLine2.drawOn(paramPage, paramBoolean);
/* 372 */ this.x1 += localTextLine2.font.stringWidth(localTextLine2.getFallbackFont(), localTextLine2.str) + f2;
/* */ }
/* 374 */ else if (this.rotate == 90) {
/* 375 */ localTextLine2.setTextDirection(90);
/* 376 */ localTextLine2.drawOn(paramPage, paramBoolean);
/* 377 */ this.y1 -= localTextLine2.font.stringWidth(localTextLine2.getFallbackFont(), localTextLine2.str) + f2;
/* */ }
/* 379 */ else if (this.rotate == 270) {
/* 380 */ localTextLine2.setTextDirection(270);
/* 381 */ localTextLine2.drawOn(paramPage, paramBoolean);
/* 382 */ this.y1 += localTextLine2.font.stringWidth(localTextLine2.getFallbackFont(), localTextLine2.str) + f2;
/* */ }
/* */ }
/* */ }
/* */ else {
/* 387 */ drawNonJustifiedLine(paramPage, paramList, paramBoolean);
/* */ }
/* */ }
/* */
/* */ private void drawNonJustifiedLine(Page paramPage, List paramList, boolean paramBoolean)
/* */ throws Exception
/* */ {
/* 394 */ float f = 0.0F;
/* */ TextLine localTextLine;
/* 395 */ for (int i = 0; i < paramList.size(); i++) {
/* 396 */ localTextLine = (TextLine)paramList.get(i);
/* 397 */ if ((i < paramList.size() - 1) &&
/* 398 */ (localTextLine.getTrailingSpace())) {
/* 399 */ localTextLine.str += " ";
/* */ }
/* */
/* 402 */ f += localTextLine.font.stringWidth(localTextLine.getFallbackFont(), localTextLine.str);
/* */ }
/* */
/* 405 */ if (this.alignment == 1048576) {
/* 406 */ if (this.rotate == 0) {
/* 407 */ this.x1 = (this.x + (this.w - f) / 2.0F);
/* */ }
/* 409 */ else if (this.rotate == 90) {
/* 410 */ this.y1 = (this.y - (this.w - f) / 2.0F);
/* */ }
/* 412 */ else if (this.rotate == 270) {
/* 413 */ this.y1 = (this.y + (this.w - f) / 2.0F);
/* */ }
/* */ }
/* 416 */ else if (this.alignment == 2097152) {
/* 417 */ if (this.rotate == 0) {
/* 418 */ this.x1 = (this.x + (this.w - f));
/* */ }
/* 420 */ else if (this.rotate == 90) {
/* 421 */ this.y1 = (this.y - (this.w - f));
/* */ }
/* 423 */ else if (this.rotate == 270) {
/* 424 */ this.y1 = (this.y + (this.w - f));
/* */ }
/* */ }
/* */
/* 428 */ for (i = 0; i < paramList.size(); i++) {
/* 429 */ localTextLine = (TextLine)paramList.get(i);
/* 430 */ localTextLine.setLocation(this.x1, this.y1 + localTextLine.getVerticalOffset());
/* */
/* 432 */ if (localTextLine.getGoToAction() != null) {
/* 433 */ paramPage.addAnnotation(new Annotation(null, localTextLine.getGoToAction(), this.x, paramPage.height - (this.y - localTextLine.font.ascent), this.x + localTextLine.font.stringWidth(localTextLine.getFallbackFont(), localTextLine.getText()), paramPage.height - (this.y - localTextLine.font.descent), null, null, null));
/* */ }
/* */
/* 445 */ if (this.rotate == 0) {
/* 446 */ localTextLine.setTextDirection(0);
/* 447 */ localTextLine.drawOn(paramPage, paramBoolean);
/* 448 */ this.x1 += localTextLine.font.stringWidth(localTextLine.getFallbackFont(), localTextLine.str);
/* */ }
/* 450 */ else if (this.rotate == 90) {
/* 451 */ localTextLine.setTextDirection(90);
/* 452 */ localTextLine.drawOn(paramPage, paramBoolean);
/* 453 */ this.y1 -= localTextLine.font.stringWidth(localTextLine.getFallbackFont(), localTextLine.str);
/* */ }
/* 455 */ else if (this.rotate == 270) {
/* 456 */ localTextLine.setTextDirection(270);
/* 457 */ localTextLine.drawOn(paramPage, paramBoolean);
/* 458 */ this.y1 += localTextLine.font.stringWidth(localTextLine.getFallbackFont(), localTextLine.str);
/* */ }
/* */ }
/* */ }
/* */
/* */ public void addChineseParagraph(Font paramFont, String paramString)
/* */ throws Exception
/* */ {
/* 471 */ Paragraph localParagraph = null;
/* 472 */ StringBuilder localStringBuilder = new StringBuilder();
/* 473 */ for (int i = 0; i < paramString.length(); i++) {
/* 474 */ char c = paramString.charAt(i);
/* 475 */ if (paramFont.stringWidth(localStringBuilder.toString() + c) > this.w) {
/* 476 */ localParagraph = new Paragraph();
/* 477 */ localParagraph.add(new TextLine(paramFont, localStringBuilder.toString()));
/* 478 */ addParagraph(localParagraph);
/* 479 */ localStringBuilder.setLength(0);
/* */ }
/* 481 */ localStringBuilder.append(c);
/* */ }
/* 483 */ localParagraph = new Paragraph();
/* 484 */ localParagraph.add(new TextLine(paramFont, localStringBuilder.toString()));
/* 485 */ addParagraph(localParagraph);
/* */ }
/* */
/* */ public void addJapaneseParagraph(Font paramFont, String paramString)
/* */ throws Exception
/* */ {
/* 496 */ addChineseParagraph(paramFont, paramString);
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.TextColumn
* JD-Core Version: 0.6.2
*/