Methods Summary |
---|
public void | addChar(char c, int width)
charWidths.put(new Character(c), new Integer(width));
|
public void | addChars(char[] characters, int[] widths)
for ( int i = 0; i < characters.length; i++ )
{
charWidths.put( new Character(characters[i]), new Integer(widths[i]));
}
|
public static org.apache.poi.hssf.usermodel.FontDetails | create(java.lang.String fontName, java.util.Properties fontMetricsProps)Create an instance of FontDetails by loading them from the
provided property object.
String heightStr = fontMetricsProps.getProperty( "font." + fontName + ".height");
String widthsStr = fontMetricsProps.getProperty( "font." + fontName + ".widths");
String charactersStr = fontMetricsProps.getProperty( "font." + fontName + ".characters");
int height = Integer.parseInt(heightStr);
FontDetails d = new FontDetails(fontName, height);
String[] charactersStrArray = split(charactersStr, ",", -1);
String[] widthsStrArray = split(widthsStr, ",", -1);
if (charactersStrArray.length != widthsStrArray.length)
throw new RuntimeException("Number of characters does not number of widths for font " + fontName);
for ( int i = 0; i < widthsStrArray.length; i++ )
{
if (charactersStrArray[i].length() != 0)
d.addChar(charactersStrArray[i].charAt(0), Integer.parseInt(widthsStrArray[i]));
}
return d;
|
public int | getCharWidth(char c)Retrieves the width of the specified character. If the metrics for
a particular character are not available it defaults to returning the
width for the 'W' character.
Integer widthInteger = (Integer)(charWidths.get(new Character(c)));
if (widthInteger == null && c != 'W")
return getCharWidth('W");
else
return widthInteger.intValue();
|
public java.lang.String | getFontName()
return fontName;
|
public int | getHeight()
return height;
|
public int | getStringWidth(java.lang.String str)Gets the width of all characters in a string.
int width = 0;
for (int i = 0; i < str.length(); i++)
{
width += getCharWidth(str.charAt(i));
}
return width;
|
private static java.lang.String[] | split(java.lang.String text, java.lang.String separator, int max)Split the given string into an array of strings using the given
delimiter.
StringTokenizer tok = new StringTokenizer(text, separator);
int listSize = tok.countTokens();
if(max != -1 && listSize > max)
listSize = max;
String list[] = new String[listSize];
for(int i = 0; tok.hasMoreTokens(); i++)
{
if(max != -1 && i == listSize - 1)
{
StringBuffer buf = new StringBuffer((text.length() * (listSize - i)) / listSize);
while(tok.hasMoreTokens())
{
buf.append(tok.nextToken());
if(tok.hasMoreTokens())
buf.append(separator);
}
list[i] = buf.toString().trim();
break;
}
list[i] = tok.nextToken().trim();
}
return list;
|