Hi Bruno,
First off, thanks for the lightning quick response!
That fix solves the problem as described for sure. I've just noticed
though that com.lowagie.text.Phrase#add(int, Object) would have to be
updated with a similar fix.
The only potential issue I can see is that a Phrase (or subclass) no
longer guarantees that all its contained Chunk elements have a
HYPHENATION attribute that matches the Phrase's.
Scenario 1: Add an 'empty' Chunk to a Phrase with a non-null hyphenation
field. Later add content/attributes to the Chunk: we now have a
'non-empty' Chunk whose hyphenation property doesn't (necessarily) match
its containing Phrase's.
Scenario 2: Add a Chunk ('empty' or 'non-empty') to a Phrase with a null
hyphenation field. Later set the hyphenation property of the Phrase.
None of the contained Chunks match the hyphenation property of the
containing Phrase. (Potential solution: have Phrase#setHyphenation()
update all 'non-empty' Chunks in the Phrase with its hyphenation value.)
Now I've just started looking at iText yesterday, so I'm obviously not
qualified to judge the seriousness of the above scenarios. Maybe it
isn't vital that a Phrase's contained Chunks always match the
hyphenation property of the Phrase.
What if the problem was examined from a different angle? What if the
definition of 'empty' in a Chunk is too strict? Is it necessary that a
Chunk's attributes field be null for a Chunk to be 'empty', or is empty
content all that's required? If this is the case, you'd only have to
update Chunk#isEmpty() (and potentially Phrase#setHyphenation() as per
Scenario 2 above).
Jeff
Bruno Lowagie wrote:
> Jeff Kelm wrote:
>
>> Hi,
>>
>> com.lowagie.text.Phrase#add(Object) invokes
>> com.lowagie.text.Phrase#addChunk(Chunk) when adding a Chunk. addChunk()
>> sets a com.lowagie.text.Chunk.HYPHENATION attribute to the Chunk being
>> added if the Chunk was missing this attribute. As one of its conditions
>> for returning 'true', com.lowagie.text.Chunk#isEmpty() specifies that
>> its 'attributes' field be null. An 'empty' Chunk (as defined by
>> com.lowagie.text.Chunk#isEmpty()) added to a Phrase (or one of its
>> subclasses) will no longer have a null attributes field, so will no
>> longer be 'empty'.
>>
>> I came across this problem when running a
>> com.lowagie.text.Paragraph#isEmpty() on a Paragraph to which an 'empty'
>> Chunk had been added. Paragraph#isEmpty() returned false because the
>> formerly 'empty' Chunk was being evaluated as 'not empty' because of the
>> addition of the HYPHENATION attribute.
>>
>> Thoughts?
>>
>
> Would this change solve the problem?
>
> Modified: trunk/src/core/com/lowagie/text/Phrase.java
> ===================================================================
> --- trunk/src/core/com/lowagie/text/Phrase.java 2009-05-27 13:09:45 UTC
> (rev 3939)
> +++ trunk/src/core/com/lowagie/text/Phrase.java 2009-05-28 14:28:39 UTC
> (rev 3940)
> @@ -400,7 +400,7 @@
> }
> Chunk newChunk = new Chunk(c, f);
> newChunk.setAttributes(chunk.getAttributes());
> - if (newChunk.getHyphenation() == null) {
> + if (hyphenation != null && newChunk.getHyphenation() == null &&
> !newChunk.isEmpty()) {
> newChunk.setHyphenation(hyphenation);
> }
> return super.add(newChunk);
>
>
> best regards,
> Bruno
>
> ------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
> is a gathering of tech-side developers & brand creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity, Processing, &
> iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> 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/
>
>
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
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/