I forgot that Phrases could contain multiple chunks, which could use different 
fonts.  That being said, I found it strange that

phrase.getFont().getBaseFont()
phrase.getFont().getSize()

both return something, while phrase.getFont().getColor() returns null

Regardless, it's a moot point and I'll modify my code to use 

ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, Phrase, x, y, 0);

thanks for the tip

Jason



-----Original Message-----
From: 1T3XT info [mailto:[email protected]]
Sent: Wed 9/15/2010 1:52 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] get font color from phrase
 
On 14/09/2010 22:14, Jason Berk wrote:
> How do I get the color of a font used to create a phrase?

I can't think of any reason why you'd need to do that.

The code snippet you provide is... very awkward.
I don't see how that would ever work.

> // in the statement decorator
> Phrase footer = new Phrase(String.format(FOOTER, phone, email),
> Fonts.RED);
> statement.addPhrase(footer, 130, 275f);
>
> // in the statement class
> public void addPhrase(Phrase phrase, float x, float y) {
>       String text = phrase.getContent();
>       canvas.saveState();
>       canvas.setColorStroke(Colors.BLACK);
>       // fails - canvas.setColorStroke(phrase.getFont().getColor());  
>       // phrase.getFont().getColor() returns null
>       canvas.beginText();
>       canvas.moveText(x, y);
>       canvas.setFontAndSize(phrase.getFont().getBaseFont(),
> phrase.getFont().getSize());
>       canvas.showText(text);
>       canvas.endText();
>       canvas.restoreState();
> }

What do you do if the phrase has different fonts in
different color? This is a very complicated way to
achieve something that can be done using only one line:

ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, Phrase, x, y, 0);

See chapter 3 of the second edition of "iText in Action".
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
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/



***This is a transmission from Purdue Employees Federal Credit
Union (PEFCU) and is intended solely for its authorized
recipient(s), and may contain information that is confidential
and or legally privileged.  If you are not an addressee, or the
employee or agent responsible for delivering it to an addressee,
you are hereby notified that any use, dissemination,
distribution, publication or copying of the information 
contained
in this email is strictly prohibited. If you have received this
transmission in error, please notify us by telephoning (765)
497-3328 or returning the email. You are then instructed to
delete the information from your computer.  Thank you for your
cooperation.***

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
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