FileDocCategorySizeDatePackage
FontEntityAtom.javaAPI DocApache Poi 3.0.14420Mon Jan 01 18:55:34 GMT 2007org.apache.poi.hslf.record

FontEntityAtom

public class FontEntityAtom extends RecordAtom
This atom corresponds exactly to a Windows Logical Font (LOGFONT) structure. It keeps all the information needed to define the attributes of a font, such as height, width, etc. For more information, consult the Windows API Programmer's reference.
author
Yegor Kozlov

Fields Summary
private byte[]
_header
record header
private byte[]
_recdata
record data
Constructors Summary
protected FontEntityAtom(byte[] source, int start, int len)
Build an instance of FontEntityAtom from on-disk data

		// Get the header
		_header = new byte[8];
		System.arraycopy(source,start,_header,0,8);

		// Grab the record data
		_recdata = new byte[len-8];
		System.arraycopy(source,start+8,_recdata,0,len-8);
	
protected FontEntityAtom()
Create a new instance of FontEntityAtom

        _recdata = new byte[68];

        _header = new byte[8];
        LittleEndian.putShort(_header, 2, (short)getRecordType());
        LittleEndian.putInt(_header, 4, _recdata.length);
    
Methods Summary
protected intgetFontIndex()

        return LittleEndian.getShort(_header, 0);
    
public java.lang.StringgetFontName()
A null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters including the null terminator.

return
font name

        String name = null;
        try {
            int i = 0;
            while(i < 64){
                //loop until find null-terminated end of the font name
                if(_recdata[i] == 0 && _recdata[i + 1] == 0) {
                    name = new String(_recdata, 0, i, "UTF-16LE");
                    break;
                }
                i += 2;
            }
        } catch (UnsupportedEncodingException e){
            throw new RuntimeException(e.getMessage(), e);
        }
        return name;
    
public longgetRecordType()

        return RecordTypes.FontEntityAtom.typeID;
    
protected voidsetFontIndex(int idx)

        LittleEndian.putShort(_header, 0, (short)idx);
    
public voidsetFontName(java.lang.String name)
Set the name of the font. The length of this string must not exceed 32 characters including the null terminator. Will be converted to null-terminated if not already

param
name of the font

		// Add a null termination if required
		if(! name.endsWith("\000")) {
			name = name + "\000";
		}

		// Ensure it's not now too long
		if(name.length() > 32) {
			throw new RuntimeException("The length of the font name, including null termination, must not exceed 32 characters");
		}

		// Everything's happy, so save the name
        try {
            byte[] bytes = name.getBytes("UTF-16LE");
            System.arraycopy(bytes, 0, _recdata, 0, bytes.length);
        } catch (UnsupportedEncodingException e){
            throw new RuntimeException(e.getMessage(), e);
        }
    
public voidwriteOut(java.io.OutputStream out)
Write the contents of the record back, so it can be written to disk

		out.write(_header);
		out.write(_recdata);