Beispiel #1
0
 /**
  * Adds a Chunk.
  *
  * <p>This method is a hack to solve a problem I had with phrases that were split between chunks
  * in the wrong place.
  *
  * @param chunk a Chunk to add to the Phrase
  * @return true if adding the Chunk succeeded
  */
 protected boolean addChunk(Chunk chunk) {
   Font f = chunk.getFont();
   String c = chunk.getContent();
   if (font != null && !font.isStandardFont()) {
     f = font.difference(chunk.getFont());
   }
   if (size() > 0 && !chunk.hasAttributes()) {
     try {
       Chunk previous = (Chunk) get(size() - 1);
       if (!previous.hasAttributes()
           && (f == null || f.compareTo(previous.getFont()) == 0)
           && !"".equals(previous.getContent().trim())
           && !"".equals(c.trim())) {
         previous.append(c);
         return true;
       }
     } catch (ClassCastException cce) {
     }
   }
   Chunk newChunk = new Chunk(c, f);
   newChunk.setAttributes(chunk.getAttributes());
   if (newChunk.getHyphenation() == null) {
     newChunk.setHyphenation(hyphenation);
   }
   return super.add(newChunk);
 }
Beispiel #2
0
 /**
  * Constructs a <CODE>Phrase</CODE> with a certain <CODE>Chunk</CODE> and a certain leading.
  *
  * @param leading the leading
  * @param chunk a <CODE>Chunk</CODE>
  */
 public Phrase(float leading, Chunk chunk) {
   this.leading = leading;
   super.add(chunk);
   font = chunk.getFont();
   setHyphenation(chunk.getHyphenation());
 }
Beispiel #3
0
 /**
  * Constructs a <CODE>Phrase</CODE> with a certain <CODE>Chunk</CODE>.
  *
  * @param chunk a <CODE>Chunk</CODE>
  */
 public Phrase(Chunk chunk) {
   super.add(chunk);
   font = chunk.getFont();
   setHyphenation(chunk.getHyphenation());
 }