KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joshy > html > css > FontResolver


1 package org.joshy.html.css;
2
3 import java.awt.Font JavaDoc;
4 import org.joshy.html.Context;
5 import org.joshy.u;
6
7 public class FontResolver {
8
9     public Font JavaDoc resolveFont(Context c, String JavaDoc[] families, float size, String JavaDoc weight, String JavaDoc style) {
10         Font JavaDoc f = c.getGraphics().getFont();
11         f = f.deriveFont((float)size);
12
13         if(weight.equals("bold")) {
14             f = f.deriveFont(Font.BOLD);
15         }
16    
17         String JavaDoc family = families[0];
18         
19         String JavaDoc fontname = "SansSerif";
20         //u.p("family: " + family);
21
if(family.equals("serif")) {
22             fontname = "Serif";
23         }
24         if(family.equals("sans-serif")) {
25             fontname = "SansSerif";
26         }
27         if(family.equals("monospace")) {
28             fontname = "Monospaced";
29         }
30
31         
32         f = new Font JavaDoc(fontname,f.getStyle(),f.getSize());
33                 
34         if(style != null) {
35             if(style.equals("italic")) {
36                 f = f.deriveFont(Font.ITALIC|f.getStyle());//.deriveFont(Font.BOLD);
37
//c.getGraphics().setFont(c.getGraphics().getFont().deriveFont(Font.ITALIC));
38

39             }
40         }
41         return f;
42     }
43     
44 }
45
Popular Tags