Example #1
0
 public static void insertStyle(HashMap h) {
   String style = (String) h.get("style");
   if (style == null) return;
   Properties prop = MarkupParser.parseAttributes(style);
   for (Iterator it = prop.keySet().iterator(); it.hasNext(); ) {
     String key = (String) it.next();
     if (key.equals(MarkupTags.CSS_KEY_FONTFAMILY)) {
       h.put("face", prop.getProperty(key));
     } else if (key.equals(MarkupTags.CSS_KEY_FONTSIZE)) {
       h.put("size", Float.toString(MarkupParser.parseLength(prop.getProperty(key))) + "px");
     } else if (key.equals(MarkupTags.CSS_KEY_FONTSTYLE)) {
       String ss = prop.getProperty(key).trim().toLowerCase();
       if (ss.equals("italic") || ss.equals("oblique")) h.put("i", null);
     } else if (key.equals(MarkupTags.CSS_KEY_FONTWEIGHT)) {
       String ss = prop.getProperty(key).trim().toLowerCase();
       if (ss.equals("bold") || ss.equals("700") || ss.equals("800") || ss.equals("900"))
         h.put("b", null);
     } else if (key.equals(MarkupTags.CSS_KEY_FONTWEIGHT)) {
       String ss = prop.getProperty(key).trim().toLowerCase();
       if (ss.equals("underline")) h.put("u", null);
     } else if (key.equals(MarkupTags.CSS_KEY_COLOR)) {
       Color c = MarkupParser.decodeColor(prop.getProperty(key));
       if (c != null) {
         int hh = c.getRGB();
         String hs = Integer.toHexString(hh);
         hs = "000000" + hs;
         hs = "#" + hs.substring(hs.length() - 6);
         h.put("color", hs);
       }
     } else if (key.equals(MarkupTags.CSS_KEY_LINEHEIGHT)) {
       String ss = prop.getProperty(key).trim();
       float v = MarkupParser.parseLength(prop.getProperty(key));
       if (ss.endsWith("%")) {
         h.put("leading", "0," + (v / 100));
       } else {
         h.put("leading", v + ",0");
       }
     } else if (key.equals(MarkupTags.CSS_KEY_TEXTALIGN)) {
       String ss = prop.getProperty(key).trim().toLowerCase();
       h.put("align", ss);
     }
   }
 }
Example #2
0
 public Font getFont(ChainedProperties props) {
   String face = props.getProperty("face");
   if (face != null) {
     StringTokenizer tok = new StringTokenizer(face, ",");
     while (tok.hasMoreTokens()) {
       face = tok.nextToken().trim();
       if (face.startsWith("\"")) face = face.substring(1);
       if (face.endsWith("\"")) face = face.substring(0, face.length() - 1);
       if (fontImp.isRegistered(face)) break;
     }
   }
   int style = 0;
   if (props.hasProperty("i")) style |= Font.ITALIC;
   if (props.hasProperty("b")) style |= Font.BOLD;
   if (props.hasProperty("u")) style |= Font.UNDERLINE;
   String value = props.getProperty("size");
   float size = 12;
   if (value != null) size = Float.valueOf(value).floatValue();
   Color color = MarkupParser.decodeColor(props.getProperty("color"));
   String encoding = props.getProperty("encoding");
   if (encoding == null) encoding = BaseFont.WINANSI;
   return fontImp.getFont(face, encoding, true, size, style, color);
 }