View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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          // extended here !!
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  }