Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions fontbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<additionalOptions>
<additionalOption>&#45;&#45;allow-script-in-comments</additionalOption>
</additionalOptions>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
2 changes: 1 addition & 1 deletion fontbox/src/main/java/org/apache/fontbox/ttf/CFFTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CFFTable extends TTFTable
* @throws java.io.IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
byte[] bytes = data.read((int)getLength());

Expand Down
16 changes: 16 additions & 0 deletions fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,22 @@ private int getCharCode(int gid)
return glyphIdToCharacterCode[gid];
}

/**
* Returns the character code for the given GID, or null if there is none.
*
* @param gid glyph id
* @return character code
*/
public Integer getCharacterCode(int gid)
{
int code = getCharCode(gid);
if (code == -1)
{
return null;
}
return Integer.valueOf(code);
}

/**
* Returns all possible character codes for the given gid, or null if there is none.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class CmapTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
@SuppressWarnings({"unused", "squid:S1854", "squid:S1481"})
int version = data.readUnsignedShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class GlyphSubstitutionTable extends TTFTable

@Override
@SuppressWarnings({"squid:S1854"})
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
long start = data.getCurrentPosition();
@SuppressWarnings({"unused"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class GlyphTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
loca = ttf.getIndexToLocation();
numGlyphs = ttf.getNumberOfGlyphs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class HeaderTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
version = data.read32Fixed();
fontRevision = data.read32Fixed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class HorizontalHeaderTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
version = data.read32Fixed();
ascender = data.readSignedShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class HorizontalMetricsTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
if (hHeader == null)
Expand Down Expand Up @@ -114,6 +114,15 @@ public int getAdvanceWidth(int gid)
}
}

/**
* Returns array of advance widths.
* @return array of advance widths
*/
public int[] getAdvanceWidths()
{
return advanceWidth;
}

/**
* Returns the left side bearing for the given GID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class IndexToLocationTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
HeaderTable head = ttf.getHeader();
if (head == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class KerningTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
int version = data.readUnsignedShort();
if (version != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void setVersion(float versionValue)
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
version = data.read32Fixed();
numGlyphs = data.readUnsignedShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class NamingTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
int formatSelector = data.readUnsignedShort();
int numberOfNameRecords = data.readUnsignedShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public int getMaxContext()
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
version = data.readUnsignedShort();
averageCharWidth = data.readSignedShort();
Expand Down
26 changes: 21 additions & 5 deletions fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class OTFParser extends TTFParser
*/
public OTFParser()
{
super();
this(false);
}

/**
Expand All @@ -52,7 +52,19 @@ public OTFParser(boolean isEmbedded)
*/
public OTFParser(boolean isEmbedded, boolean parseOnDemand)
{
super(isEmbedded, parseOnDemand);
this(isEmbedded, parseOnDemand, false);
}

/**
* Constructor.
*
* @param isEmbedded true if the font is embedded in PDF
* @param parseOnDemand true if the tables of the font should be parsed on demand
* @param useAlternateATT true if using alternate ATT (advanced typograph tables) implementation
*/
public OTFParser(boolean isEmbedded, boolean parseOnDemand, boolean useAlternateATT)
{
super(isEmbedded, parseOnDemand, useAlternateATT);
}

@Override
Expand Down Expand Up @@ -82,21 +94,25 @@ OpenTypeFont parse(TTFDataStream raf) throws IOException
@Override
OpenTypeFont newFont(TTFDataStream raf)
{
return new OpenTypeFont(raf);
return new OpenTypeFont(raf, useAlternateATT);
}

@Override
protected TTFTable readTable(TrueTypeFont font, String tag)
{
// todo: this is a stub, a full implementation is needed
assert font instanceof OpenTypeFont;
switch (tag)
{
case "BASE":
case "JSTF":
return new OTLTable(font);
case "GDEF":
return new org.apache.fontbox.ttf.advanced.GlyphDefinitionTable((OpenTypeFont) font);
case "GPOS":
return new org.apache.fontbox.ttf.advanced.GlyphPositioningTable((OpenTypeFont) font);
case "GSUB":
case "JSTF":
return new OTLTable(font);
return new org.apache.fontbox.ttf.advanced.GlyphSubstitutionTable((OpenTypeFont) font);
case "CFF ":
return new CFFTable(font);
default:
Expand Down
53 changes: 52 additions & 1 deletion fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ public class OpenTypeFont extends TrueTypeFont
*/
OpenTypeFont(TTFDataStream fontData)
{
super(fontData);
this(fontData, false);
}

/**
* Constructor. Clients should use the OTFParser to create a new OpenTypeFont object.
*
* @param fontData The font data.
* @param useAlternateATT true if using alternate ATT (advanced typograph tables) implementation.
*/
OpenTypeFont(TTFDataStream fontData, boolean useAlternateATT)
{
super(fontData, useAlternateATT);
}

@Override
Expand Down Expand Up @@ -94,4 +105,44 @@ public boolean hasLayoutTables()
tables.containsKey("GSUB") ||
tables.containsKey("JSTF");
}

/**
* Get the "GDEF" table for this OTF.
*
* @return The "GDEF" table.
*/
public org.apache.fontbox.ttf.advanced.GlyphDefinitionTable getGDEF() throws IOException
{
if (useAlternateATT)
return (org.apache.fontbox.ttf.advanced.GlyphDefinitionTable) getTable(org.apache.fontbox.ttf.advanced.GlyphDefinitionTable.TAG);
else
return null;
}

/**
* Get the "GSUB" table for this OTF.
*
* @return The "GSUB" table.
*/
public org.apache.fontbox.ttf.advanced.GlyphSubstitutionTable getGSUB() throws IOException
{
if (useAlternateATT)
return (org.apache.fontbox.ttf.advanced.GlyphSubstitutionTable) getTable(org.apache.fontbox.ttf.advanced.GlyphSubstitutionTable.TAG);
else
return null;
}

/**
* Get the "GPOS" table for this OTF.
*
* @return The "GPOS" table.
*/
public org.apache.fontbox.ttf.advanced.GlyphPositioningTable getGPOS() throws IOException
{
if (useAlternateATT)
return (org.apache.fontbox.ttf.advanced.GlyphPositioningTable) getTable(org.apache.fontbox.ttf.advanced.GlyphPositioningTable.TAG);
else
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class PostScriptTable extends TTFTable
* @throws IOException If there is an error reading the data.
*/
@Override
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
protected void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
formatType = data.read32Fixed();
italicAngle = data.read32Fixed();
Expand Down
13 changes: 11 additions & 2 deletions fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author Ben Litchfield
*/
abstract class TTFDataStream implements Closeable
public abstract class TTFDataStream implements Closeable
{
TTFDataStream()
{
Expand Down Expand Up @@ -96,6 +96,16 @@ public String readString(int length, Charset charset) throws IOException
*/
public abstract int read() throws IOException;

/**
* Skip bytes.
*
* @throws IOException If there is an error reading the data.
*/
public void skip(int count) throws IOException {
while (count-- > 0)
read();
}

/**
* Read an unsigned byte.
*
Expand Down Expand Up @@ -297,7 +307,6 @@ public byte[] read(int numberOfBytes) throws IOException
* This will get the original data size that was used for this stream.
*
* @return The size of the original data.
* @throws IOException If there is an issue reading the data.
*/
public abstract long getOriginalDataSize();
}
26 changes: 21 additions & 5 deletions fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class TTFParser
{
private boolean isEmbedded = false;
private boolean parseOnDemandOnly = false;
protected boolean useAlternateATT = false;

/**
* Constructor.
Expand All @@ -55,9 +56,22 @@ public TTFParser(boolean isEmbedded)
* @param parseOnDemand true if the tables of the font should be parsed on demand
*/
public TTFParser(boolean isEmbedded, boolean parseOnDemand)
{
this(isEmbedded, parseOnDemand, false);
}

/**
* Constructor.
*
* @param isEmbedded true if the font is embedded in PDF
* @param parseOnDemand true if the tables of the font should be parsed on demand
* @param useAlternateATT true if using alternate ATT (advanced typograph tables) implementation
*/
public TTFParser(boolean isEmbedded, boolean parseOnDemand, boolean useAlternateATT)
{
this.isEmbedded = isEmbedded;
parseOnDemandOnly = parseOnDemand;
this.parseOnDemandOnly = parseOnDemand;
this.useAlternateATT = useAlternateATT;
}

/**
Expand Down Expand Up @@ -155,7 +169,7 @@ TrueTypeFont parse(TTFDataStream raf) throws IOException

TrueTypeFont newFont(TTFDataStream raf)
{
return new TrueTypeFont(raf);
return new TrueTypeFont(raf, useAlternateATT);
}

/**
Expand Down Expand Up @@ -238,7 +252,7 @@ protected boolean allowCFF()

private TTFTable readTableDirectory(TrueTypeFont font, TTFDataStream raf) throws IOException
{
TTFTable table;
TTFTable table = null;
String tag = raf.readString(4);
switch (tag)
{
Expand Down Expand Up @@ -288,12 +302,14 @@ private TTFTable readTableDirectory(TrueTypeFont font, TTFDataStream raf) throws
table = new VerticalOriginTable(font);
break;
case GlyphSubstitutionTable.TAG:
table = new GlyphSubstitutionTable(font);
if (!useAlternateATT)
table = new GlyphSubstitutionTable(font);
break;
default:
table = readTable(font, tag);
break;
}
if (table == null)
table = readTable(font, tag);
table.setTag(tag);
table.setCheckSum(raf.readUnsignedInt());
table.setOffset(raf.readUnsignedInt());
Expand Down
Loading