*
* @throws IOException If there is an error reading from the stream.
*/
private CharMetric parseCharMetric() throws IOException
{
CharMetric result = new CharMetric();
String metrics = readLine();
StringTokenizer metricsTokenizer = new StringTokenizer( metrics );
try
{
while( metricsTokenizer.hasMoreTokens() )
{
String nextCommand = metricsTokenizer.nextToken();
if( nextCommand.equals( CHARMETRICS_C ) )
{
String charCode = metricsTokenizer.nextToken();
result.setCharacterCode( Integer.parseInt( charCode ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_CH ) )
{
//Is the hex string <FF> or FF, the spec is a little
//unclear, wait and see if it breaks anything.
String charCode = metricsTokenizer.nextToken();
result.setCharacterCode( Integer.parseInt( charCode, 16 ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_WX ) )
{
String wx = metricsTokenizer.nextToken();
result.setWx( Float.parseFloat( wx ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W0X ) )
{
String w0x = metricsTokenizer.nextToken();
result.setW0x( Float.parseFloat( w0x ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W1X ) )
{
String w1x = metricsTokenizer.nextToken();
result.setW0x( Float.parseFloat( w1x ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_WY ) )
{
String wy = metricsTokenizer.nextToken();
result.setWy( Float.parseFloat( wy ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W0Y ) )
{
String w0y = metricsTokenizer.nextToken();
result.setW0y( Float.parseFloat( w0y ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W1Y ) )
{
String w1y = metricsTokenizer.nextToken();
result.setW0y( Float.parseFloat( w1y ) );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W ) )
{
String w0 = metricsTokenizer.nextToken();
String w1 = metricsTokenizer.nextToken();
float[] w = new float[2];
w[0] = Float.parseFloat( w0 );
w[1] = Float.parseFloat( w1 );
result.setW( w );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W0 ) )
{
String w00 = metricsTokenizer.nextToken();
String w01 = metricsTokenizer.nextToken();
float[] w0 = new float[2];
w0[0] = Float.parseFloat( w00 );
w0[1] = Float.parseFloat( w01 );
result.setW0( w0 );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_W1 ) )
{
String w10 = metricsTokenizer.nextToken();
String w11 = metricsTokenizer.nextToken();
float[] w1 = new float[2];
w1[0] = Float.parseFloat( w10 );
w1[1] = Float.parseFloat( w11 );
result.setW1( w1 );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_VV ) )
{
String vv0 = metricsTokenizer.nextToken();
String vv1 = metricsTokenizer.nextToken();
float[] vv = new float[2];
vv[0] = Float.parseFloat( vv0 );
vv[1] = Float.parseFloat( vv1 );
result.setVv( vv );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_N ) )
{
String name = metricsTokenizer.nextToken();
result.setName( name );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_B ) )
{
String llx = metricsTokenizer.nextToken();
String lly = metricsTokenizer.nextToken();
String urx = metricsTokenizer.nextToken();
String ury = metricsTokenizer.nextToken();
BoundingBox box = new BoundingBox();
box.setLowerLeftX( Float.parseFloat( llx ) );
box.setLowerLeftY( Float.parseFloat( lly ) );
box.setUpperRightX( Float.parseFloat( urx ) );
box.setUpperRightY( Float.parseFloat( ury ) );
result.setBoundingBox( box );
verifySemicolon( metricsTokenizer );
}
else if( nextCommand.equals( CHARMETRICS_L ) )
{
String successor = metricsTokenizer.nextToken();
String ligature = metricsTokenizer.nextToken();
Ligature lig = new Ligature();
lig.setSuccessor( successor );
lig.setLigature( ligature );
result.addLigature( lig );
verifySemicolon( metricsTokenizer );
}
else
{
throw new IOException( "Unknown CharMetrics command '" + nextCommand + "'" );