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;
 }