peter.henning...@wcenter.de wrote:
> 
> Hi,
> 
> Thanks. I will not look at this again before some time next week.
> 
> I had a look at the methods you mentioned, and this stuff looks a lot 
> more complicated than I thought. I could not quite make the connection
> from ColumnText to PdfLine. Anyway, I try again next week.

The changes that were just uploaded to the SVN repository work with the 
simple test samples I made. Please check if the patch works for you.

Log Message:
-----------
ColumnText returns the last X position after a non-simulated go().

Modified Paths:
--------------
     trunk/src/core/com/itextpdf/text/pdf/ColumnText.java
     trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java
     trunk/src/core/com/itextpdf/text/pdf/PdfLine.java

Modified: trunk/src/core/com/itextpdf/text/pdf/ColumnText.java
===================================================================
--- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java        2010-04-25 
09:50:40 UTC (rev 4490)
+++ trunk/src/core/com/itextpdf/text/pdf/ColumnText.java        2010-04-25 
11:04:50 UTC (rev 4491)
@@ -179,6 +179,12 @@

      /** The current y line location. Text will be written at this line 
minus the leading. */
      protected float yLine;
+
+    /**
+     * The X position after the last line that has been written.
+     * @since 5.0.3
+     */
+    protected float lastX;

      /** The leading for the current line. */
      protected float currentLeading = 16;
@@ -793,6 +799,7 @@
              return NO_MORE_TEXT;
          descender = 0;
          linesWritten = 0;
+        lastX = 0;
          boolean dirty = false;
          float ratio = spaceCharRatio;
          Object currentValues[] = new Object[2];
@@ -894,7 +901,7 @@
                  if (!simulate) {
                      currentValues[0] = currentFont;
                      text.setTextMatrix(x1 + (line.isRTL() ? 
rightIndent : firstIndent) + line.indentLeft(), yLine);
-                    pdf.writeLineToContent(line, text, graphics, 
currentValues, ratio);
+                    lastX = pdf.writeLineToContent(line, text, 
graphics, currentValues, ratio);
                      currentFont = (PdfFont)currentValues[0];
                  }
                  lastWasNewline = line.isNewlineSplit();
@@ -987,6 +994,15 @@
      public int getLinesWritten() {
          return this.linesWritten;
      }
+
+    /**
+     * Gets the X position of the end of the last line that has been 
written
+     * (will not work in simulation mode!).
+     * @since 5.0.3
+     */
+    public float getLastX() {
+       return lastX;
+    }

      /**
       * Gets the arabic shaping options.

Modified: trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java
===================================================================
--- trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java       2010-04-25 
09:50:40 UTC (rev 4490)
+++ trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java       2010-04-25 
11:04:50 UTC (rev 4491)
@@ -1252,8 +1252,9 @@
       * @param currentValues the current font and extra spacing values
       * @param ratio
       * @throws DocumentException on error
+     * @since 5.0.3 returns a float instead of void
       */
-    void writeLineToContent(PdfLine line, PdfContentByte text, 
PdfContentByte graphics, Object currentValues[], float ratio)  throws 
DocumentException {
+    float writeLineToContent(PdfLine line, PdfContentByte text, 
PdfContentByte graphics, Object currentValues[], float ratio)  throws 
DocumentException {
          PdfFont currentFont = (PdfFont)currentValues[0];
          float lastBaseFactor = ((Float)currentValues[1]).floatValue();
          PdfChunk chunk;
@@ -1266,9 +1267,9 @@
          float baseWordSpacing = 0;
          float baseCharacterSpacing = 0;
          float glueWidth = 0;
-
+        float lastX = text.getXTLM() + line.getOriginalWidth();
          numberOfSpaces = line.numberOfSpaces();
-        lineLen = line.GetLineLengthUtf32();
+        lineLen = line.getLineLengthUtf32();
          // does the line need to be justified?
          isJustified = line.hasToBeJustified() && (numberOfSpaces != 0 
|| lineLen > 1);
          int separatorCount = line.getSeparatorCount();
@@ -1301,6 +1302,9 @@
                  lastBaseFactor = baseFactor;
              }
          }
+        else if (line.alignment == Element.ALIGN_LEFT) {
+               lastX -= line.widthLeft();
+        }

          int lastChunkStroke = line.getLastStrokeChunk();
          int chunkStrokeIdx = 0;
@@ -1593,6 +1597,7 @@
              text.moveText(baseXMarker - text.getXTLM(), 0);
          currentValues[0] = currentFont;
          currentValues[1] = new Float(lastBaseFactor);
+        return lastX;
      }

      protected Indentation indentation = new Indentation();

Modified: trunk/src/core/com/itextpdf/text/pdf/PdfLine.java
===================================================================
--- trunk/src/core/com/itextpdf/text/pdf/PdfLine.java   2010-04-25 
09:50:40 UTC (rev 4490)
+++ trunk/src/core/com/itextpdf/text/pdf/PdfLine.java   2010-04-25 
11:04:50 UTC (rev 4491)
@@ -365,9 +365,9 @@
      /**
       * Returns the length of a line in UTF32 characters
       * @return        the length in UTF32 characters
-     * @since  2.1.2
+     * @since  2.1.2; Get changed into get in 5.0.2
       */
-    public int GetLineLengthUtf32() {
+    public int getLineLengthUtf32() {
          int total = 0;
          for (Object element : line) {
              total += ((PdfChunk)element).lengthUtf32();


-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to