Skip to content

Commit e00c7af

Browse files
author
Open Lowcode SAS
committed
Close #41
1 parent 9ba696e commit e00c7af

File tree

2 files changed

+79
-31
lines changed

2 files changed

+79
-31
lines changed

src/org/openlowcode/tools/pdf/PDFMultiPageTable.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public String getText() {
7878
private float[] columnrelativewidth;
7979
private String[] headertexts;
8080
private ArrayList<CellText[]> cellscontent;
81+
private ArrayList<Boolean> linehasbarabove;
8182
protected float[] columnwidthinmm;
8283
private int columnnumber;
8384
private int indexlastlineprinted;
@@ -164,6 +165,7 @@ private void constructorcontent(float leftmargin, float rightmargin, float[] col
164165
throw new RuntimeException("Column Relative Width should be strictly positive");
165166
this.columnnumber = columnrelativewidth.length;
166167
this.cellscontent = new ArrayList<CellText[]>();
168+
this.linehasbarabove = new ArrayList<Boolean>();
167169
this.indexlastlineprinted = -1;
168170

169171
}
@@ -207,16 +209,26 @@ public void addOneLineContent(String[] linecontent) {
207209
}
208210
this.cellscontent.add(celltexts);
209211
}
210-
212+
211213
/**
212214
* Creates a new line without content. Content can then be added by
213-
* setCellContent
214-
*/
215-
public void addBlankLine() {
215+
* setCellContent. The new line is created with or without a
216+
* bar above
217+
*/
218+
public void addBlankLine(boolean drawlineabove) {
216219
CellText[] blankline = new CellText[columnnumber];
217220
for (int i = 0; i < blankline.length; i++)
218221
blankline[i] = new CellText("");
219222
this.cellscontent.add(blankline);
223+
this.linehasbarabove.add(new Boolean(drawlineabove));
224+
}
225+
226+
/**
227+
* Creates a new line without content. Content can then be added by
228+
* setCellContent. The new line is created with a bar above
229+
*/
230+
public void addBlankLine() {
231+
addBlankLine(true);
220232
}
221233

222234
/**
@@ -344,8 +356,12 @@ private float printOneRow(PDFPage currentpage, int rowindex, float mmfromtopfors
344356
float currentleft = leftinmm;
345357
for (int i = 0; i < columnwidthinmm.length; i++) {
346358
float currentcolumnwidth = columnwidthinmm[i];
359+
boolean drawtop=this.linehasbarabove.get(rowindex).booleanValue();
360+
boolean drawbottom=true;
361+
if (rowindex+1<this.linehasbarabove.size()) drawbottom = this.linehasbarabove.get(rowindex+1).booleanValue();
362+
347363
currentpage.drawBoxWithWidthAndHeight(false, currentleft, mmfromtopforsection, currentcolumnwidth,
348-
rowheight);
364+
rowheight,drawtop,drawbottom,true,true);
349365
printOneCell(currentpage, rowindex, i, mmfromtopforsection, currentleft, currentcolumnwidth);
350366
currentleft += currentcolumnwidth;
351367

src/org/openlowcode/tools/pdf/PDFPage.java

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,33 @@ protected void print(PDDocument document) throws IOException {
420420

421421
}
422422

423+
/**
424+
* @param fatline fatline true if line is fat, false if line is standard
425+
* (thinner)
426+
* @param left left coordinates in mm (note: in PDF, left starts at zero)
427+
* @param top top coordinates in mm (note: in PDF, bottom starts at zero
428+
* except if topatzero is set)
429+
* @param width width in mm, a positive number
430+
* @param height height in mm, a positive number
431+
* @param drawtop if true, draw the top line
432+
* @param drawbottom if true, draw the bottom line
433+
* @param drawleft if true, draw the left line
434+
* @param drawright if true, draw the right line
435+
* @throws IOException
436+
*/
437+
438+
public void drawBoxWithWidthAndHeight(boolean fatline, float left, float top, float width, float height,
439+
boolean drawtop,boolean drawbottom,boolean drawleft,boolean drawright)
440+
throws IOException {
441+
442+
float right = left + width;
443+
float bottom = top - height;
444+
if (this.topatzero) {
445+
bottom = top + height;
446+
}
447+
drawBox(fatline, left, top, right, bottom,Color.BLACK,drawtop,drawbottom,drawleft,drawright);
448+
}
449+
423450
/**
424451
* @param fatline fatline true if line is fat, false if line is standard
425452
* (thinner)
@@ -489,37 +516,42 @@ public void drawCircle(Color bordercolor, Color fillcolor, float centerx, float
489516
* @param bottom bottom coordinates in mm (note: in PDF, bottom starts at zero
490517
* except if topatzero is set)
491518
* @param color color of the box.
492-
* @throws IOException
519+
* @param drawtop if true, draw the top line of the box
520+
* @param drawbottom if bottom, draw the bottom line of the box
521+
* @param drawleft if left ... well, draw the left line of the box
522+
* @param drawright if right (I think you got it) draw the right line of the box
523+
* @throws IOException if anything bad happens with the file being printed
493524
*/
494-
public void drawBox(boolean fatline, float left, float top, float right, float bottom, Color color)
525+
526+
public void drawBox(boolean fatline, float left, float top, float right, float bottom, Color color,
527+
boolean drawtop,boolean drawbottom,boolean drawleft,boolean drawright)
495528
throws IOException {
496529
this.widgetstoprint.add(() -> {
497-
contentStream.setStrokingColor(color);
498-
contentStream.setNonStrokingColor(color);
499-
500-
if (!fatline)
501-
contentStream.setLineWidth(NORMAL_LINE_WIDTH);
502-
if (fatline)
503-
contentStream.setLineWidth(FAT_LINE_WIDTH);
504-
505-
float newtop = top;
506-
float newbottom = bottom;
507-
if (this.topatzero) {
508-
newtop = height - top;
509-
newbottom = height - bottom;
510-
}
511-
512-
contentStream.moveTo(left * MM_TO_POINT, newtop * MM_TO_POINT);
513-
contentStream.lineTo(right * MM_TO_POINT, newtop * MM_TO_POINT);
514-
contentStream.lineTo(right * MM_TO_POINT, newbottom * MM_TO_POINT);
515-
contentStream.lineTo(left * MM_TO_POINT, newbottom * MM_TO_POINT);
516-
contentStream.lineTo(left * MM_TO_POINT, newtop * MM_TO_POINT);
517-
contentStream.closeAndStroke();
518-
contentStream.setStrokingColor(Color.BLACK);
519-
contentStream.setNonStrokingColor(Color.BLACK);
530+
531+
if (drawtop) this.drawLine(fatline, left,top, right,top, color);
532+
if (drawbottom) this.drawLine(fatline, left,bottom, right,bottom, color);
533+
if (drawleft) this.drawLine(fatline, left,top,left,bottom, color);
534+
if (drawright) this.drawLine(fatline, right,top,right,bottom, color);
520535
});
521536

522537
}
538+
539+
/**
540+
* @param fatline true if line is fat, false if line is standard (thinner)
541+
* @param left left coordinates in mm (note: in PDF, left starts at zero)
542+
* @param top top coordinates in mm (note: in PDF, bottom starts at zero
543+
* except if topatzero is set)
544+
* @param right right coordinates in mm (note: in PDF, left starts at zero)
545+
* @param bottom bottom coordinates in mm (note: in PDF, bottom starts at zero
546+
* except if topatzero is set)
547+
* @param color color of the box.
548+
* @throws IOException
549+
*/
550+
public void drawBox(boolean fatline, float left, float top, float right, float bottom, Color color)
551+
throws IOException {
552+
drawBox(fatline,left,top,right,bottom,color,true,true,true,true);
553+
554+
}
523555

524556
/**
525557
* Draws a rectangular box
@@ -1164,7 +1196,7 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(float left, float top
11641196
if (i > 0)
11651197
currentsplitparagraph = false;
11661198
String paragraphtext = paragraphs[i];
1167-
logger.severe("audit on line "+paragraphtext);
1199+
logger.finest("audit on line "+paragraphtext);
11681200
ArrayList<String> paragraphlines = new ArrayList<String>();
11691201
int lastspace = -1;
11701202
// in this version, tab is treated as any other space

0 commit comments

Comments
 (0)