Coverage report

  %line %branch
tsukuba_bunko.peko.resource.FontDeserializer
0% 
0% 

 1  
 /*
 2  
  * "Peko" Visual Novel System
 3  
  *
 4  
  * All Rights Reserved.
 5  
  * Copyright (c) 1999-2003 Tsukuba Bunko.
 6  
  *
 7  
  * $Id: FontDeserializer.java,v 1.1 2005/07/11 12:49:18 ppoi Exp $
 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  
  * {@link java.awt.Font} 型のリソースに対する {@link tsukuba_bunko.resource.ResourceDeserializer} 実装です。
 27  
  * @author	$Author: ppoi $
 28  
  * @version	$Revision: 1.1 $
 29  
  * @see <a href="http://softlab.tsukuba-bunko.org/peko/userguide/resource.html#type-peko:font">peko:font 型のリソース</a>
 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  
 	 * <code>FontDeserializer</code> のインスタンスを生成します。
 44  
 	 */
 45  
 	public FontDeserializer()
 46  
 	{
 47  0
 		super();
 48  0
 	}
 49  
 
 50  
 
 51  
 //
 52  
 //	ContentHandler の実装
 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  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.