[iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Christian Lauer
Hi Paulo,

an UJAC user had a interesting question about vertical alignment in
PdfPCells. The problem he discovered is that you can't really perform a
top or middle alignment, not even with fixed leading set to zero and
multiplied leading set to 1.0. There will always be a little extra space
between the top of the cell and the contents.

And the workaround by manipulating the paddingTop attribute is no ideal
solution too because it depends on the font size that's used. 

Is there a real solution for that problem?

I've attached an test programm, which produces the problem.

Best regards,
Christian

-- 
Christian Lauer [EMAIL PROTECTED]
package ujac.test.itext;

import java.io.FileOutputStream;

import com.lowagie.text.Document;

import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;

import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class AlignmentTest {
  
  public static void main(String[] args) {

try {
  FileOutputStream os = new FileOutputStream(test.pdf);
  Document document = new Document(PageSize.A4, 25, 25, 25, 25);
  PdfWriter documentWriter = PdfWriter.getInstance(document, os);
  
  document.open();
  Font font = new Font(Font.HELVETICA, 10);

  PdfPTable tab = new PdfPTable(1);
  PdfPCell c = new PdfPCell(new Phrase([middle], font));
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_MIDDLE);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);

  c = new PdfPCell(new Phrase([top], font));
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_TOP);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  c = new PdfPCell(new Phrase([bottom], font));
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_BOTTOM);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  document.add(tab);

  document.add(new Paragraph( ));

  
  tab = new PdfPTable(1);
  c = new PdfPCell(new Phrase([middle paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_MIDDLE);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  c = new PdfPCell(new Phrase([top paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_TOP);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  c = new PdfPCell(new Phrase([bottom paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_BOTTOM);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);

  document.add(tab);

  
  font = new Font(Font.HELVETICA, 16);

  document.add(new Paragraph( ));

  
  tab = new PdfPTable(1);
  c = new PdfPCell(new Phrase([middle paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_MIDDLE);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  c = new PdfPCell(new Phrase([top paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_TOP);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);
  
  c = new PdfPCell(new Phrase([bottom paddingTop=-3], font));
  c.setPaddingTop(-3.0F);
  c.setLeading(0.0F, 1.0F);
  c.setVerticalAlignment(Element.ALIGN_BOTTOM);
  c.setBorderWidth(0.5F);
  c.setBorder(Rectangle.BOX);
  c.setFixedHeight(30.0F);
  tab.addCell(c);

  document.add(tab);

  document.close();
  documentWriter.close();
  
} catch (Exception ex) {
  ex.printStackTrace();
}
  }
  
}


test.pdf
Description: Adobe PDF document


RE: [iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Paulo Soares
That's not a problem, just an option. Let's analyze the options:

1 - leading space between the top padding and the baseline (as it's
now). Pros, all the chars will fit. Cons, space between the ascender and
the top padding for most of the chars.

2 - ascender space between the top padding and the baseline. Pros, looks
better for capitals. Cons, lower case will still have space and some
characters will be clipped.

3 - lower case height between the top padding and the baseline. Pros,
looks better for lower case. Cons, all the characters except lower case
will be clipped.

4 - space based on bbox of characters in the line. Pros, no character is
clipped and space is the minimum. Cons, bbox analysis on each char,
baseline may be different even with same font and size, iText doesn't
gather the bbox information.

Option 2 may be possible, I'll have to think about it.

Best Regards,
Paulo Soares

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On 
 Behalf Of Christian Lauer
 Sent: Tuesday, September 21, 2004 7:20 AM
 To: iText Mailing List
 Subject: [iText-questions] Vertical alignment in PdfPCells
 
 Hi Paulo,
 
 an UJAC user had a interesting question about vertical alignment in
 PdfPCells. The problem he discovered is that you can't really 
 perform a
 top or middle alignment, not even with fixed leading set to zero and
 multiplied leading set to 1.0. There will always be a little 
 extra space
 between the top of the cell and the contents.
 
 And the workaround by manipulating the paddingTop attribute 
 is no ideal
 solution too because it depends on the font size that's used. 
 
 Is there a real solution for that problem?
 
 I've attached an test programm, which produces the problem.
 
 Best regards,
 Christian
 
 -- 
 Christian Lauer [EMAIL PROTECTED]
 


---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions


RE: [iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Paulo Soares
Good work. It needs some changes to support composite elements, though.

Best Regards,
Paulo Soares

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On 
 Behalf Of Steve Appling
 Sent: Tuesday, September 21, 2004 1:51 PM
 To: iText Mailing List
 Subject: Re: [iText-questions] Vertical alignment in PdfPCells
 
 I'll try this again - the mailing list rejected my first 
 email because it
 had a zip in it.  The attached file is really a zip, rename 
 it and change
 the extension to zip.
 
 I encountered a similar problem and added setUseAscender to 
 PdfPCell and
 ColumnText.  This allows you to have appropriate vertical alignment
 regardless of font.  I have a few other changes including
 setUseBorderPadding (which adjusts the padding based on 
 border widths) and
 support for variable color / width borders on each side of a PdfPCell.
 
 I have attached my changed source as a zip that can be 
 applied on top of
 itext-paulo-138.
 
 If you only want the useAscender part, you only need the useAscender
 setter/getter from PdfPCell, and the updated ColumnText and PdfLine.
 
 Enjoy!
 
 - Original Message - 
 From: Christian Lauer [EMAIL PROTECTED]
 To: iText Mailing List [EMAIL PROTECTED]
 Sent: Tuesday, September 21, 2004 2:20 AM
 Subject: [iText-questions] Vertical alignment in PdfPCells
 
 
  Hi Paulo,
 
  an UJAC user had a interesting question about vertical alignment in
  PdfPCells. The problem he discovered is that you can't 
 really perform a
  top or middle alignment, not even with fixed leading set to zero and
  multiplied leading set to 1.0. There will always be a 
 little extra space
  between the top of the cell and the contents.
 
  And the workaround by manipulating the paddingTop attribute 
 is no ideal
  solution too because it depends on the font size that's used.
 
  Is there a real solution for that problem?
 
  I've attached an test programm, which produces the problem.
 
  Best regards,
  Christian
 
  -- 
  Christian Lauer [EMAIL PROTECTED]
 
 


---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions


Re: [iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Steve Appling
I'll be glad to try fix any problems with this, but I'm not sure exactly
what you mean by composite elements (which is probably why I didn't handle
it right originally :).  If you can describe the problem condition enough
for me to make a test case, I'll work on it.

 - Original Message - 
 From: Paulo Soares [EMAIL PROTECTED]
 To: Steve Appling [EMAIL PROTECTED]; iText Mailing List
[EMAIL PROTECTED]
 Sent: Tuesday, September 21, 2004 9:51 AM
Subject: RE: [iText-questions] Vertical alignment in PdfPCells


 Good work. It needs some changes to support composite elements, though.

 Best Regards,
 Paulo Soares




---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions


RE: [iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Paulo Soares
A composite element is an element added with ColumntText.addElement(),
it's the same with PdfPCell. The processing is done in
ColumnText.goComposite(). If firstPass == true and it's a Paragraph or a
List you'll have to pass to the constructed ColumnText the Ascent flag.

Best Regards,
Paulo Soares 

 -Original Message-
 From: Steve Appling [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, September 21, 2004 3:51 PM
 To: Paulo Soares; iText Mailing List
 Subject: Re: [iText-questions] Vertical alignment in PdfPCells
 
 I'll be glad to try fix any problems with this, but I'm not 
 sure exactly
 what you mean by composite elements (which is probably why I 
 didn't handle
 it right originally :).  If you can describe the problem 
 condition enough
 for me to make a test case, I'll work on it.
 
  - Original Message - 
  From: Paulo Soares [EMAIL PROTECTED]
  To: Steve Appling [EMAIL PROTECTED]; iText Mailing List
 [EMAIL PROTECTED]
  Sent: Tuesday, September 21, 2004 9:51 AM
 Subject: RE: [iText-questions] Vertical alignment in PdfPCells
 
 
  Good work. It needs some changes to support composite 
 elements, though.
 
  Best Regards,
  Paulo Soares
 
 
 


---
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions


Re: [iText-questions] Vertical alignment in PdfPCells

2004-09-21 Thread Steve Appling
Thanks for catching that bug, Paulo.  Here is a revised version of
ColumnText that handles composite elements correctly (I think :).  At least
I have a simple test case that failed before and now works.  I also changed
ColumnText.duplicate to use setACopy (just avoiding a small amount of code
duplication).

I added the code to copy the useAscender flag directly to the goComposite
method since that is how everything else is copied.  Would it be better to
use setACopy to copy all of the ColumnText fields, then override a few with
parameters from the added Element?  It would be nice to have the bulk of
parameter copying in one place.

Thanks again for pointing out the problem.

- Original Message - 
From: Paulo Soares [EMAIL PROTECTED]
To: Steve Appling [EMAIL PROTECTED]; iText Mailing List
[EMAIL PROTECTED]
Sent: Tuesday, September 21, 2004 11:38 AM
Subject: RE: [iText-questions] Vertical alignment in PdfPCells


A composite element is an element added with ColumntText.addElement(),
it's the same with PdfPCell. The processing is done in
ColumnText.goComposite(). If firstPass == true and it's a Paragraph or a
List you'll have to pass to the constructed ColumnText the Ascent flag.

Best Regards,
Paulo Soares

 -Original Message-
 From: Steve Appling [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, September 21, 2004 3:51 PM
 To: Paulo Soares; iText Mailing List
 Subject: Re: [iText-questions] Vertical alignment in PdfPCells

 I'll be glad to try fix any problems with this, but I'm not
 sure exactly
 what you mean by composite elements (which is probably why I
 didn't handle
 it right originally :).  If you can describe the problem
 condition enough
 for me to make a test case, I'll work on it.

  - Original Message - 
  From: Paulo Soares [EMAIL PROTECTED]
  To: Steve Appling [EMAIL PROTECTED]; iText Mailing List
 [EMAIL PROTECTED]
  Sent: Tuesday, September 21, 2004 9:51 AM
 Subject: RE: [iText-questions] Vertical alignment in PdfPCells
 

  Good work. It needs some changes to support composite
 elements, though.
 
  Best Regards,
  Paulo Soares





ColumnText.java
Description: java/