Paulo Soares wrote:
PdfContentByte.saveState() saves everything including the font, matrix,
colors, etc.

Hmm... ok, I get unexpected output (when viewed from Acrobat 7.0.7) if I don't explicitly reset the PdfContentByte.setFontAndSize() at a point I expected restoreState() to have reset the font back to what is was before.


My innerMethod function is actually an implementation of SMALL CAPS for lowercased characters of the passed string, but I have simplified it in this example.


Code goes something like:


public void outerMethod(PdfContentByte cb, BaseFont font) {
 cb.setFontAndSize(font.getBaseFont(), 8);

innerMethod(cb, font.getBaseFont(), PdfContentByte.ALIGN_RIGHT, 8, 6, "abcDEF", colOneIndentX, thisLineY, 0); cb.setFontAndSize(font.getBaseFont(), 8); // Restore font info from calling #innerMethod() this is the call I'm not expecting to need to make

 cb.beginText();
// This is the text that which ends up in the wrong place, by around 6pts east when a 6pt/smallSize font got selected inside innerMethod cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "Some Data", colTwoIndentX, thisLineY, 0);
 cb.endText();
}


public void innerMethod(PdfContentByte cb, BaseFont baseFont, int align, float bigSize, float smallSize, String s, float x, float y, float a) {
 cb.saveState();
 cb.beginText();
 float fontSize = bigSize;
 if(Ctype.islower(s.charAt(0)))
  fontSize = smallSize;
 float charSpacing = 1.0f;
 cb.moveText(x, y);     // Simplyfied example of ALIGN_LEFT
 cb.setFontAndSize(baseFont, fontSize);
 cb.setCharacterSpacing(charSpacing);
 cb.showText(s.charAt(0));
 cb.endText();
 cb.restoreState();
}


Maybe there is somewhere I can attach a test case if anyone is interested. For now I just make the extra call to cb.setFontAndSize() after any call to innerMethod().



Adding:

cb.beginText();
cb.endText();

after the first cb.setFontAndSize() also fixes the output to what I expect. I can't do saveState() after beginText() I get an error/warning in acrobat.

Maybe a "setfont" isn't called until cb.beginText(), which means the graphics state is not setup. I'm not sure what iText's goals are aligning with PDF/PS syntax or being programtically intuitive.


Thanks for your clarification,

Darryl


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to