@@ -114,8 +114,7 @@ private interface PageExecutable {
114114 private PDPageContentStream contentStream ;
115115 private PDDocument document ;
116116 private ArrayList <PagedLabel > toclabelsforpage ;
117-
118-
117+
119118 /**
120119 * This method should only be called during the final layout. Please use the
121120 * method PDFPage.drawCalculatedText
@@ -984,6 +983,12 @@ public void drawSimpleTextAt(boolean label, float left, float top, int linenumbe
984983 drawSimpleTextAt (label , left , top , linenumber , paragraphnumber , "" , true );
985984 }
986985
986+ public static float getTextVerticalOffsetInMM ( int linenumber , int paragraphnumber ) {
987+ return (PARAGRAPH_MARGIN_VERTICAL + linenumber * LINE_SPACING_NORMAL_TEXT
988+ + (linenumber + 1 ) * LINE_HEIGHT_NORMAL_TEXT + (paragraphnumber ) * PARAGRAPH_SPACING_NORMAL_TEXT )
989+ / MM_TO_POINT ;
990+ }
991+
987992 /**
988993 * Draws a single text from the point of origin (adding necessary margins).
989994 * Typically, the function is used entering directly in left and top the
@@ -1024,9 +1029,7 @@ public void drawSimpleTextAt(
10241029 contentStream .beginText ();
10251030 contentStream .newLineAtOffset (
10261031 left * MM_TO_POINT + (horizontalparagraphmargin ? PARAGRAPH_MARGIN_HORIZONTAL : 0 ),
1027- newtop * MM_TO_POINT - PARAGRAPH_MARGIN_VERTICAL - (linenumber ) * (LINE_SPACING_NORMAL_TEXT )
1028- - LINE_HEIGHT_NORMAL_TEXT * (linenumber + 1 )
1029- - (paragraphnumber ) * PARAGRAPH_SPACING_NORMAL_TEXT );
1032+ newtop * MM_TO_POINT - getTextVerticalOffsetInMM (linenumber ,paragraphnumber )*MM_TO_POINT );
10301033 if (label )
10311034 contentStream .setFont (labelfont , LINE_HEIGHT_NORMAL_TEXT * LABEL_SIZE_REDUCTION );
10321035 if (!label )
@@ -1136,7 +1139,7 @@ public float drawLeftPaddedTextAt(
11361139
11371140 logger .finest (" - drawLeftPaddedTextAt (" + texttype + ") ---> " + compactprint + " ||" + text + " Color "
11381141 + color );
1139- contentStream .setNonStrokingColor ((color == null ? Color .BLACK : color ));
1142+ contentStream .setNonStrokingColor ((color == null ? Color .BLACK : color ));
11401143 contentStream .beginText ();
11411144 float yinpoint = newtop * MM_TO_POINT - (PARAGRAPH_MARGIN_VERTICAL * (compactprint ? 0 : 1 ))
11421145 - (linenumber ) * (PDFPage .getLineSpacing (texttype ))
@@ -1150,7 +1153,7 @@ public float drawLeftPaddedTextAt(
11501153 contentStream .endText ();
11511154 contentStream .setNonStrokingColor (Color .BLACK );
11521155 if (underline ) {
1153- contentStream .setStrokingColor ((color == null ? Color .BLACK : color ));
1156+ contentStream .setStrokingColor ((color == null ? Color .BLACK : color ));
11541157 contentStream .setLineWidth (PARAGRAPH_HEADER_UNDERLINE_WIDTH );
11551158
11561159 contentStream .moveTo (left * MM_TO_POINT + PARAGRAPH_MARGIN_HORIZONTAL ,
@@ -1385,8 +1388,9 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(
13851388 int startatline ,
13861389 int startatparagraph ) throws IOException {
13871390 float lastlineinmm = 0f ;
1388- logger .finest ("Starting Paragraph print at " +startatline +" lines, " +startatparagraph +" paragraphes, offset in mm = " +startfirstlineoffset );
1389-
1391+ logger .finest ("Starting Paragraph print at " + startatline + " lines, " + startatparagraph
1392+ + " paragraphes, offset in mm = " + startfirstlineoffset );
1393+
13901394 boolean currentsplitparagraph = splitparagraph ;
13911395 if (write )
13921396 if (page == null )
@@ -1448,18 +1452,20 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(
14481452 if (i == paragraphs .getNumberOfSections () - 1 )
14491453 if (j == paragraphlines .size () - 1 ) {
14501454 lastlineinmm = PDFPage .getTextSize (new String [] { paragraphlines .get (j ) }, texttype );
1451- logger .finest (" ---> calculate lastlineinmm " +lastlineinmm +" for i=" +i +", j=" +j +" text =" +paragraphlines .get (j ));
1455+ logger .finest (" ---> calculate lastlineinmm " + lastlineinmm + " for i=" + i
1456+ + ", j=" + j + " text =" + paragraphlines .get (j ));
14521457 }
1453-
1458+
14541459 if (i == 0 )
14551460 if (j == 0 ) {
14561461 specialoffset = startfirstlineoffset ;
1457- lastlineinmm += specialoffset ;
1462+ lastlineinmm += specialoffset ;
14581463 }
14591464
14601465 if (write ) {
14611466 if (!partial ) {
1462- logger .finest (" -----> draw with offset (!partial): " +specialoffset +" left = " +(newleft +specialoffset ));
1467+ logger .finest (" -----> draw with offset (!partial): " + specialoffset
1468+ + " left = " + (newleft + specialoffset ));
14631469 page .drawLeftPaddedTextAt (texttype , newleft + specialoffset , top ,
14641470 totallinecounter + j + startatline , totalparagraphcounter + startatparagraph ,
14651471 paragraphlines .get (j ), compactprint , color );
@@ -1483,13 +1489,14 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(
14831489 }
14841490 } else {
14851491 // check if still in box
1486- int partialparagraphcount = i + 1 + startatparagraph ;
1487- int partiallinecount = totallinecounter + j + 1 + startatline ;
1492+ int partialparagraphcount = i + 1 + startatparagraph ;
1493+ int partiallinecount = totallinecounter + j + 1 + startatline ;
14881494 float heightsofar = new BoxTextContent (partiallinecount , partialparagraphcount , texttype ,
14891495 compactprint ).getHeight ();
14901496 if (heightsofar <= maxheight ) {
14911497 // if so, print
1492- logger .finest (" -----> draw with offset (partial): " +specialoffset +" left = " +(newleft +specialoffset ));
1498+ logger .finest (" -----> draw with offset (partial): " + specialoffset
1499+ + " left = " + (newleft + specialoffset ));
14931500 page .drawLeftPaddedTextAt (texttype , newleft + specialoffset , top ,
14941501 totallinecounter + j + startatline , totalparagraphcounter + startatparagraph ,
14951502 paragraphlines .get (j ), compactprint , color );
@@ -1524,7 +1531,8 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(
15241531 }
15251532 }
15261533 totallinecounter += paragraphlines .size ();
1527- if (paragraphlines .size ()==0 ) totallinecounter +=1 ;
1534+ if (paragraphlines .size () == 0 )
1535+ totallinecounter += 1 ;
15281536
15291537 }
15301538 return new BoxTextContent (totallinecounter + startatline , totalparagraphcounter + 1 + startatparagraph ,
@@ -1851,8 +1859,6 @@ public float getHeightWithoutFinalSpacing() {
18511859 return getHeight (false );
18521860 }
18531861
1854-
1855-
18561862 private float getHeight (boolean finalspacing ) {
18571863 if ((texttype == PDFPage .TEXTTYPE_PLAIN ) || (texttype == PDFPage .TEXTTYPE_PLAIN_ITALIC )
18581864 || (texttype == PDFPage .TEXTTYPE_PLAIN_BOLD ) || (texttype == PDFPage .TEXTTYPE_PLAIN_BOLD_ITALIC )
@@ -1893,7 +1899,6 @@ public float getHeight() {
18931899
18941900 }
18951901
1896-
18971902 }
18981903
18991904 /**
@@ -2126,17 +2131,17 @@ public static void securedShowText(PDPageContentStream contentStream, String tex
21262131 public PagedLabel [] getTOCLabelsForPage () {
21272132 return toclabelsforpage .toArray (new PagedLabel [0 ]);
21282133 }
2129-
2134+
21302135 /**
21312136 * Adds a label for this page to be added in table of content
21322137 *
2133- * @param label text of the label
2138+ * @param label text of the label
21342139 * @param offset offset in mm
21352140 */
2136- public void setTOCLabelForPage (String label ,float offset ) {
2137- toclabelsforpage .add (new PagedLabelInPage (label ,offset ));
2141+ public void setTOCLabelForPage (String label , float offset ) {
2142+ toclabelsforpage .add (new PagedLabelInPage (label , offset ));
21382143 }
2139-
2144+
21402145 @ Override
21412146 protected int getPageNumber () {
21422147 // only a page is used by a PDFPage
@@ -2154,17 +2159,19 @@ protected void layoutPages(int pagesbefore) {
21542159 this .pageindex = pagesbefore + 1 ;
21552160
21562161 }
2157-
2158- private class PagedLabelInPage implements PagedLabel {
2162+
2163+ private class PagedLabelInPage
2164+ implements
2165+ PagedLabel {
21592166
21602167 private String label ;
21612168 private float offset ;
21622169
2163- public PagedLabelInPage (String label ,float offset ) {
2170+ public PagedLabelInPage (String label , float offset ) {
21642171 this .label = label ;
21652172 this .offset = offset ;
21662173 }
2167-
2174+
21682175 @ Override
21692176 public String getLabel () {
21702177 return label ;
@@ -2179,8 +2186,7 @@ public int getPageNumber() {
21792186 public float getOriginalOffset () {
21802187 return offset ;
21812188 }
2182-
2189+
21832190 }
2184-
21852191
21862192}
0 commit comments