Exemplo n.º 1
0
 /**
  * Gets a special kind of Phrase that changes some characters into corresponding symbols.
  *
  * @param leading
  * @param string
  * @param font
  * @return a newly constructed Phrase
  */
 public static final Phrase getInstance(int leading, String string, Font font) {
   Phrase p = new Phrase(true);
   p.setLeading(leading);
   p.font = font;
   if (font.getFamily() != Font.SYMBOL
       && font.getFamily() != Font.ZAPFDINGBATS
       && font.getBaseFont() == null) {
     int index;
     while ((index = SpecialSymbol.index(string)) > -1) {
       if (index > 0) {
         String firstPart = string.substring(0, index);
         ((ArrayList) p).add(new Chunk(firstPart, font));
         string = string.substring(index);
       }
       Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
       StringBuffer buf = new StringBuffer();
       buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
       string = string.substring(1);
       while (SpecialSymbol.index(string) == 0) {
         buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
         string = string.substring(1);
       }
       ((ArrayList) p).add(new Chunk(buf.toString(), symbol));
     }
   }
   if (string != null && string.length() != 0) {
     ((ArrayList) p).add(new Chunk(string, font));
   }
   return p;
 }
Exemplo n.º 2
0
 /** Copy constructor for <CODE>Phrase</CODE>. */
 public Phrase(Phrase phrase) {
   super();
   this.addAll(phrase);
   leading = phrase.getLeading();
   font = phrase.getFont();
   setHyphenation(phrase.getHyphenation());
 }
Exemplo n.º 3
0
 /**
  * Adds a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or another <CODE>Phrase</CODE> to this <CODE>
  * Phrase</CODE>.
  *
  * @param o an object of type <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
  * @return a boolean
  * @throws ClassCastException when you try to add something that isn't a <CODE>Chunk</CODE>,
  *     <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
  */
 public boolean add(Object o) {
   if (o == null) return false;
   if (o instanceof String) {
     return super.add(new Chunk((String) o, font));
   }
   if (o instanceof RtfElementInterface) {
     return super.add(o);
   }
   try {
     Element element = (Element) o;
     switch (element.type()) {
       case Element.CHUNK:
         return addChunk((Chunk) o);
       case Element.PHRASE:
       case Element.PARAGRAPH:
         Phrase phrase = (Phrase) o;
         boolean success = true;
         Element e;
         for (Iterator i = phrase.iterator(); i.hasNext(); ) {
           e = (Element) i.next();
           if (e instanceof Chunk) {
             success &= addChunk((Chunk) e);
           } else {
             success &= this.add(e);
           }
         }
         return success;
       case Element.MARKED:
       case Element.ANCHOR:
       case Element.ANNOTATION:
       case Element.TABLE: // case added by David Freels
       case Element.PTABLE: // case added by mr. Karen Vardanyan
         // This will only work for PDF!!! Not for RTF/HTML
       case Element.LIST:
       case Element.YMARK:
         return super.add(o);
       default:
         throw new ClassCastException(String.valueOf(element.type()));
     }
   } catch (ClassCastException cce) {
     throw new ClassCastException("Insertion of illegal Element: " + cce.getMessage());
   }
 }