This class represents a CMap file.
Method from org.apache.fontbox.cmap.CMap Detail: |
public void addCodespaceRange(CodespaceRange range) {
codeSpaceRanges.add( range );
}
This will add a codespace range. |
public void addMapping(byte[] src,
String dest) throws IOException {
if( src.length == 1 )
{
singleByteMappings.put( new Integer( 0xFF & src[0] ), dest );
}
else if( src.length == 2 )
{
int intSrc = src[0]&0xFF;
intSrc < < = 8;
intSrc |= (src[1]&0xFF);
doubleByteMappings.put( new Integer( intSrc ), dest );
}
else
{
throw new IOException( "Mapping code should be 1 or two bytes and not " + src.length );
}
}
|
public List<CodespaceRange> getCodeSpaceRanges() {
return codeSpaceRanges;
}
Getter for property codeSpaceRanges. |
public boolean hasOneByteMappings() {
return singleByteMappings.size() > 0;
}
This will tell if this cmap has any one byte mappings. |
public boolean hasTwoByteMappings() {
return doubleByteMappings.size() > 0;
}
This will tell if this cmap has any two byte mappings. |
public boolean isInCodeSpaceRanges(byte[] code) {
return isInCodeSpaceRanges(code, 0, code.length);
}
Check whether the given byte array is in codespace ranges or not. |
public boolean isInCodeSpaceRanges(byte[] code,
int offset,
int length) {
Iterator< CodespaceRange > it = codeSpaceRanges.iterator();
while ( it.hasNext() )
{
CodespaceRange range = it.next();
if ( range != null && range.isInRange(code, offset, length) )
{
return true;
}
}
return false;
}
Check whether the given byte array is in codespace ranges or not. |
public String lookup(byte[] code,
int offset,
int length) {
String result = null;
Integer key = null;
if( length == 1 )
{
key = new Integer( (code[offset]+256)%256 );
result = singleByteMappings.get( key );
}
else if( length == 2 )
{
int intKey = (code[offset]+256)%256;
intKey < < = 8;
intKey += (code[offset+1]+256)%256;
key = new Integer( intKey );
result = doubleByteMappings.get( key );
}
return result;
}
This will perform a lookup into the map. |
public void useCmap(CMap cmap) {
this.codeSpaceRanges.addAll( cmap.codeSpaceRanges );
this.singleByteMappings.putAll( cmap.singleByteMappings );
this.doubleByteMappings.putAll( cmap.doubleByteMappings );
}
Implementation of the usecmap operator. This will
copy all of the mappings from one cmap to another. |