1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.cms.core.pdf;
17
18 import java.awt.Color;
19 import java.util.StringTokenizer;
20
21 import com.lowagie.text.Chunk;
22 import com.lowagie.text.Font;
23 import com.lowagie.text.FontFactory;
24 import com.lowagie.text.html.simpleparser.ChainedProperties;
25 import com.lowagie.text.html.simpleparser.FactoryProperties;
26 import com.lowagie.text.pdf.BaseFont;
27
28 /***
29 * @author someda
30 */
31 public class CJKFactoryProperties extends FactoryProperties {
32
33 public CJKFactoryProperties(){
34 super();
35 }
36
37 public static Chunk createChunk(String text, ChainedProperties props) {
38 Chunk ck = new Chunk(text, getFont(props));
39 if (props.hasProperty("sub"))
40 ck.setTextRise(-6);
41 else if (props.hasProperty("sup"))
42 ck.setTextRise(6);
43 return ck;
44 }
45
46 public static Font getFont(ChainedProperties props) {
47 String face = props.getProperty("face");
48 if (face != null) {
49 StringTokenizer tok = new StringTokenizer(face, ",");
50 while (tok.hasMoreTokens()) {
51 face = tok.nextToken().trim();
52 if (FontFactory.isRegistered(face))
53 break;
54 }
55 }
56 int style = 0;
57 if (props.hasProperty("i"))
58 style |= Font.ITALIC;
59 if (props.hasProperty("b"))
60 style |= Font.BOLD;
61 if (props.hasProperty("u"))
62 style |= Font.UNDERLINE;
63 String value = props.getProperty("size");
64 float size = 12;
65 if (value != null)
66 size = Float.valueOf(value).floatValue();
67 Color color = decodeColor(props.getProperty("color"));
68
69
70 String encoding = props.getProperty("cjk_encoding");
71 String embededstr = props.getProperty("cjk_embeded");
72 if(encoding == null || encoding.equals(""))
73 encoding = BaseFont.WINANSI;
74
75 boolean embeded = true;
76 if(embededstr != null)
77 embeded = Boolean.valueOf(embededstr).booleanValue();
78
79 return FontFactory.getFont(face, encoding, embeded, size, style, color);
80 }
81
82 }