| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
package tsukuba_bunko.peko.resource; |
| 10 |
|
|
| 11 |
|
import java.awt.font.TextAttribute; |
| 12 |
|
|
| 13 |
|
import java.util.Map; |
| 14 |
|
|
| 15 |
|
import org.xml.sax.Attributes; |
| 16 |
|
import org.xml.sax.SAXException; |
| 17 |
|
|
| 18 |
|
import tsukuba_bunko.peko.Logger; |
| 19 |
|
|
| 20 |
|
import tsukuba_bunko.peko.resource.FontManager; |
| 21 |
|
|
| 22 |
|
import tsukuba_bunko.resource.BasicDeserializer; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
public class FontDeserializer extends BasicDeserializer { |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
0 |
protected Map _fontAttributes = null; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
0 |
protected StringBuffer _text = null; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
public FontDeserializer() |
| 46 |
|
{ |
| 47 |
0 |
super(); |
| 48 |
0 |
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
public void startDocument() |
| 55 |
|
{ |
| 56 |
0 |
_fontAttributes = new java.util.HashMap(); |
| 57 |
0 |
_fontAttributes.put( TextAttribute.FAMILY, "Serif" ); |
| 58 |
0 |
_fontAttributes.put( TextAttribute.SIZE, new Float(20f) ); |
| 59 |
0 |
_fontAttributes.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR ); |
| 60 |
0 |
_fontAttributes.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR ); |
| 61 |
0 |
} |
| 62 |
|
|
| 63 |
|
public void endDocument() |
| 64 |
|
{ |
| 65 |
0 |
FontManager fonts = FontManager.getInstance(); |
| 66 |
0 |
setValue( fonts.getFont(_fontAttributes) ); |
| 67 |
0 |
} |
| 68 |
|
|
| 69 |
|
public void startElement( String namespaceURI, String localName, String qName, Attributes attrs ) |
| 70 |
|
{ |
| 71 |
0 |
_text = new StringBuffer(); |
| 72 |
0 |
} |
| 73 |
|
|
| 74 |
|
public void endElement( String namespaceURI, String localName, String qName ) |
| 75 |
|
throws SAXException |
| 76 |
|
{ |
| 77 |
0 |
if( qName.equals("family") ) { |
| 78 |
0 |
_fontAttributes.put( TextAttribute.FAMILY, new String(_text) ); |
| 79 |
0 |
} |
| 80 |
0 |
else if( qName.equals("size") ) { |
| 81 |
|
try { |
| 82 |
0 |
_fontAttributes.put( TextAttribute.SIZE, Float.valueOf(new String(_text)) ); |
| 83 |
|
} |
| 84 |
0 |
catch( Exception e ) { |
| 85 |
0 |
Logger.warn( "[resource.font] invalid font size is specified :" + _text, e ); |
| 86 |
0 |
} |
| 87 |
0 |
} |
| 88 |
0 |
else if( qName.equals("style") ) { |
| 89 |
0 |
String style = new String( _text ); |
| 90 |
0 |
if( "italic".equals(style) ) { |
| 91 |
0 |
_fontAttributes.put( TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE ); |
| 92 |
|
} |
| 93 |
0 |
} |
| 94 |
0 |
else if( qName.equals("weight") ) { |
| 95 |
0 |
String weight = new String( _text ); |
| 96 |
0 |
if( "bold".equals(weight) ) { |
| 97 |
0 |
_fontAttributes.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD ); |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
0 |
_text = null; |
| 101 |
0 |
} |
| 102 |
|
|
| 103 |
|
public void characters( char[] ch, int begin, class="keyword">int length ) |
| 104 |
|
{ |
| 105 |
0 |
if( _text != null ) { |
| 106 |
0 |
_text.append( ch, begin, length ); |
| 107 |
|
} |
| 108 |
0 |
} |
| 109 |
|
} |