Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 'integration' to 'rc/1.26' #630

Merged
merged 8 commits into from
Mar 28, 2024
Merged
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
13 changes: 8 additions & 5 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ on:
jobs:
build:
name: Checkout and Build
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

continue-on-error: true

strategy:
fail-fast: false
matrix:
java-version: [8, 11, 16, 17]
java-version: [8, 11, 16, 17, 21]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: JDK setup
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
Expand All @@ -31,7 +34,7 @@ jobs:
path: target/site/jacoco/
coverage:
name: Quality Assurance
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs: [ build ]

steps:
Expand Down
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Quick Start

In order to build the parser you'll need:

* Java 8 - 17, which can be downloaded [from Oracle](https://www.oracle.com/technetwork/java/javase/downloads/index.html), or for Linux users [OpenJDK](http://openjdk.java.net/install/index.html).
* Java 8 - 21, which can be downloaded [from Oracle](https://www.oracle.com/technetwork/java/javase/downloads/index.html), or for Linux users [OpenJDK](http://openjdk.java.net/install/index.html).
* [Maven v3+](https://maven.apache.org/)

### Building the veraPDF Parser
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/verapdf/parser/COSParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import org.verapdf.as.exceptions.StringExceptions;
import org.verapdf.cos.*;
import org.verapdf.parser.postscript.PSObject;
import org.verapdf.pd.encryption.StandardSecurityHandler;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.logging.Level;
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/org/verapdf/pd/PDNameTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.verapdf.cos.COSObjType;
import org.verapdf.cos.COSObject;
import org.verapdf.exceptions.LoopedException;
import org.verapdf.pd.structure.NameTreeIterator;

import java.util.*;

Expand Down Expand Up @@ -165,14 +164,22 @@ private COSObject getObject(String key, Set<COSKey> visitedKeys) {
return null;
}

private List<COSObject> getObjects() {
List<COSObject> result = new LinkedList<>(getNames().values());
for (PDNameTreeNode kid : getKids()) {
result.addAll(kid.getObjects());
}
return result;
}

@Override
public NameTreeIterator iterator() {
return new NameTreeIterator(this);
public Iterator<COSObject> iterator() {
return getObjects().iterator();
}

public Long size() {
long i = 0;
NameTreeIterator iterator = iterator();
Iterator<COSObject> iterator = iterator();
for (; iterator.hasNext(); i++) {
iterator.next();
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/verapdf/pd/font/PDCIDFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,15 @@ public FontProgram getFontProgram() {
this.isFontParsed = true;

if (fontDescriptor.canParseFontFile(ASAtom.FONT_FILE2) &&
this.getSubtype() == ASAtom.CID_FONT_TYPE2) {
this.getSubtypeEntryValue() == ASAtom.CID_FONT_TYPE2) {
COSStream trueTypeFontFile = fontDescriptor.getFontFile2();
COSKey key = trueTypeFontFile.getObjectKey();
COSObject cidToGIDMap = this.getCIDToGIDMap();
String fontProgramID = FontProgramIDGenerator.getCIDFontType2ProgramID(key, this.cMap, cidToGIDMap);
this.fontProgram = StaticResources.getCachedFont(fontProgramID);
if (fontProgram == null) {
try (ASInputStream fontData = trueTypeFontFile.getData(COSStream.FilterFlags.DECODE)) {
this.fontProgram = new CIDFontType2Program(
fontData, this.cMap, cidToGIDMap);
this.fontProgram = new CIDFontType2Program(fontData, this.cMap, cidToGIDMap);
StaticResources.cacheFontProgram(fontProgramID, this.fontProgram);
} catch (IOException e) {
LOGGER.log(Level.FINE, "Can't read TrueType font program.", e);
Expand All @@ -193,17 +192,18 @@ public FontProgram getFontProgram() {
}
}
} else if (ASAtom.OPEN_TYPE == subtype.getName()) {
ASAtom fontName = ASAtom.getASAtom(this.getName());
boolean isCFF = fontName != ASAtom.TRUE_TYPE && fontName != ASAtom.CID_FONT_TYPE2;
boolean isCFF = this.getSubtypeEntryValue() != ASAtom.TRUE_TYPE && this.getSubtypeEntryValue() != ASAtom.CID_FONT_TYPE2;
boolean isCIDFontType2 = this.getSubtypeEntryValue() == ASAtom.CID_FONT_TYPE2;
boolean isSymbolic = this.isSymbolic();
COSObject encoding = this.getEncoding();
String fontProgramID = FontProgramIDGenerator.getOpenTypeFontProgramID(key, isCFF, isSymbolic, encoding, this.cMap, isSubset);
this.fontProgram = StaticResources.getCachedFont(fontProgramID);
if (fontProgram == null) {
COSObject cidToGIDMap = this.getCIDToGIDMap();
try (ASInputStream fontData = fontFile.getData(COSStream.FilterFlags.DECODE)) {
this.fontProgram = new OpenTypeFontProgram(
fontData, isCFF, isSymbolic, encoding,
this.cMap, isSubset);
fontData, isCFF, isCIDFontType2, isSymbolic, encoding,
this.cMap, isSubset, cidToGIDMap);
StaticResources.cacheFontProgram(fontProgramID, this.fontProgram);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/verapdf/pd/font/PDFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public String getType() {
public ASAtom getSubtype() {
return this.subtype;
}

public ASAtom getSubtypeEntryValue() {
return this.subtype;
}

/**
* @return true if the font flags in the font descriptor dictionary mark
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/verapdf/pd/font/cff/CFFCIDFontProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@ public class CFFCIDFontProgram extends CFFFontBaseParser implements FontProgram
CFFCIDFontProgram(SeekableInputStream stream, CFFIndex definedNames, CFFIndex globalSubrs,
long topDictBeginOffset, long topDictEndOffset, CMap externalCMap,
boolean isSubset) {
super(stream);
this.definedNames = definedNames;
this.globalSubrs = globalSubrs;
this.topDictBeginOffset = topDictBeginOffset;
this.topDictEndOffset = topDictEndOffset;
super(stream, definedNames, globalSubrs, topDictBeginOffset, topDictEndOffset, isSubset);
this.externalCMap = externalCMap;
this.isSubset = isSubset;
}

/**
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/org/verapdf/pd/font/cff/CFFFontBaseParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @author Sergey Shemyakov
*/
abstract class CFFFontBaseParser extends CFFFileBaseParser {
class CFFFontBaseParser extends CFFFileBaseParser {

private static final Logger LOGGER = Logger.getLogger(CFFFontBaseParser.class.getCanonicalName());

Expand Down Expand Up @@ -72,13 +72,39 @@ abstract class CFFFontBaseParser extends CFFFileBaseParser {
//Subrs
protected long subrsOffset = -1;

private boolean containsROS = false;

public CFFFontBaseParser(SeekableInputStream source) {
super(source);
stack = new ArrayList<>(48);
this.charStringType = 2;
this.charSetOffset = 0; // default
}

public CFFFontBaseParser(SeekableInputStream stream, CFFIndex definedNames, CFFIndex globalSubrs,
long topDictBeginOffset, long topDictEndOffset, boolean isSubset) {
this(stream);
this.definedNames = definedNames;
this.globalSubrs = globalSubrs;
this.topDictBeginOffset = topDictBeginOffset;
this.topDictEndOffset = topDictEndOffset;
this.isSubset = isSubset;
}

protected boolean containsROS() {
try {
this.source.seek(topDictBeginOffset);
while (this.source.getOffset() < topDictEndOffset) {
readTopDictUnit();
}
if (containsROS) {
return true;
}
} catch (IOException ignored) {
}
return false;
}

protected void readTopDictUnit() throws IOException {
try {
int next = this.source.peek();
Expand Down Expand Up @@ -125,6 +151,9 @@ protected void readTopDictUnit() throws IOException {
this.stack.get(this.stack.size() - 1).getInteger();
this.stack.clear();
break;
case 30:
this.containsROS = true;
break;
default:
readTopDictTwoByteOps(next);
}
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/verapdf/pd/font/cff/CFFFontProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void parseFont() throws IOException {
}
this.definedNames = this.readIndex();
CFFIndex globalSubrs = this.readIndex();
if (isCIDFont(top.get(0))) {
if (isCIDFont(top, globalSubrs, topOffset)) {
font = new CFFCIDFontProgram(this.source, this.definedNames, globalSubrs,
topOffset + top.getOffset(0) - 1 + top.getOffsetShift(),
topOffset + top.getOffset(1) - 1 + top.getOffsetShift(),
Expand All @@ -91,9 +91,10 @@ public void parseFont() throws IOException {
}
}

private boolean isCIDFont(byte[] topDict) {
private boolean isCIDFont(CFFIndex top, CFFIndex globalSubrs, long topOffset) {
try {
byte rosOffset;
byte[] topDict = top.get(0);
int supplementFirstByte = topDict[4] & 0xFF; // checking if first operator is really ROS
if (supplementFirstByte < 247 && supplementFirstByte > 31) {
rosOffset = 5;
Expand All @@ -104,25 +105,25 @@ private boolean isCIDFont(byte[] topDict) {
} else if (supplementFirstByte == 29) {
rosOffset = 9;
} else {
return isContainsROS(topDict);
return containsROS(top, globalSubrs, topOffset);
}
if (topDict[rosOffset] == 12 && topDict[rosOffset + 1] == 30) {
isCIDFont = true;
return true;
}
return isContainsROS(topDict);
return containsROS(top, globalSubrs, topOffset);
} catch (ArrayIndexOutOfBoundsException ex) {
return isContainsROS(topDict);
return containsROS(top, globalSubrs, topOffset);
}
}

private boolean isContainsROS(byte[] topDict) {
for (int rosOffset = 0; rosOffset < topDict.length - 2; rosOffset++) {
if (topDict[rosOffset] == 12 && topDict[rosOffset + 1] == 30) {
LOGGER.log(Level.WARNING, "The Top DICT does not begin with ROS operator");
isCIDFont = true;
return true;
}
private boolean containsROS(CFFIndex top, CFFIndex globalSubrs, long topOffset) {
if (new CFFFontBaseParser(this.source, this.definedNames, globalSubrs,
topOffset + top.getOffset(0) - 1 + top.getOffsetShift(),
topOffset + top.getOffset(1) - 1 + top.getOffsetShift(),
this.isSubset).containsROS()) {
LOGGER.log(Level.WARNING, "The Top DICT does not begin with ROS operator");
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ public class CFFType1FontProgram extends CFFFontBaseParser implements FontProgra
CFFType1FontProgram(SeekableInputStream stream, CFFIndex definedNames, CFFIndex globalSubrs,
long topDictBeginOffset, long topDictEndOffset,
CMap externalCMap, boolean isSubset) {
super(stream);
super(stream, definedNames, globalSubrs, topDictBeginOffset, topDictEndOffset, isSubset);
encodingOffset = 0;
encoding = new int[256];
this.definedNames = definedNames;
this.globalSubrs = globalSubrs;
this.topDictBeginOffset = topDictBeginOffset;
this.topDictEndOffset = topDictEndOffset;
this.externalCMap = externalCMap;
this.isSubset = isSubset;
fontMatrix = new float[6];
System.arraycopy(DEFAULT_FONT_MATRIX, 0, this.fontMatrix, 0,
DEFAULT_FONT_MATRIX.length);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/verapdf/pd/font/cmap/CMapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public void parse() throws IOException, PostScriptException {
getBaseParser().initializeToken();
//Skipping starting comments
getBaseParser().skipSpaces(true);
COSObject nextObject = nextObject();
while (getBaseParser().getToken().type != Token.Type.TT_EOF) {
COSObject nextObject = nextObject();
processObject(nextObject);
nextObject = nextObject();
}
} finally {
this.getSource().close(); // We close stream after first reading attempt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.verapdf.pd.font.FontProgram;
import org.verapdf.pd.font.cff.CFFFontProgram;
import org.verapdf.pd.font.cmap.CMap;
import org.verapdf.pd.font.truetype.CIDFontType2Program;
import org.verapdf.pd.font.truetype.TrueTypeFontProgram;
import org.verapdf.tools.StaticResources;
import org.verapdf.tools.resource.ASFileStreamCloser;
Expand All @@ -45,6 +46,7 @@ public class OpenTypeFontProgram implements FontProgram {
// See TrueTypeFontParser table logic

private final boolean isCFF;
private final boolean isCIDFontType2;
private final boolean isSymbolic;
private final boolean isSubset;
private final COSObject encoding;
Expand All @@ -54,6 +56,7 @@ public class OpenTypeFontProgram implements FontProgram {
private boolean attemptedParsing = false;
private boolean successfullyParsed = false;
private final CMap externalCMap;
private final COSObject cidToGIDMap;

/**
* Constructor from stream, containing font data, and encoding details.
Expand All @@ -62,14 +65,16 @@ public class OpenTypeFontProgram implements FontProgram {
* @param isSymbolic is true if font is marked as symbolic.
* @param encoding is value of /Encoding in font dictionary.
*/
public OpenTypeFontProgram(ASInputStream source, boolean isCFF, boolean isSymbolic,
COSObject encoding, CMap externalCMap, boolean isSubset) {
public OpenTypeFontProgram(ASInputStream source, boolean isCFF, boolean isCIDFontType2, boolean isSymbolic,
COSObject encoding, CMap externalCMap, boolean isSubset, COSObject cidToGIDMap) {
this.source = source;
this.isCFF = isCFF;
this.isCIDFontType2 = isCIDFontType2;
this.isSymbolic = isSymbolic;
this.encoding = encoding;
this.externalCMap = externalCMap;
this.isSubset = isSubset;
this.cidToGIDMap = cidToGIDMap;
}

/**
Expand Down Expand Up @@ -134,14 +139,17 @@ public boolean isSuccessfulParsing() {
public void parseFont() throws IOException {
if (!attemptedParsing) {
attemptedParsing = true;
if (!isCFF) {
this.font = new TrueTypeFontProgram(source, isSymbolic, encoding);
if (isCIDFontType2) {
this.font = new CIDFontType2Program(source, externalCMap, cidToGIDMap);
this.font.parseFont();
} else {
} else if (isCFF) {
try (ASInputStream cffTable = getCFFTable()) {
this.font = new CFFFontProgram(cffTable, externalCMap, isSubset);
this.font.parseFont();
}
} else {
this.font = new TrueTypeFontProgram(source, isSymbolic, encoding);
this.font.parseFont();
}
StaticResources.cacheFontProgram(null, this.font);
this.successfullyParsed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void parseFont() throws IOException {
* this True Type font.
*/
public int getNrOfCMaps() {
if(this.parser.getCmapParser() != null) {
if (this.parser.getCmapParser() != null) {
return this.parser.getCmapParser().getCmapInfos().length;
} else {
return 0;
Expand Down
Loading
Loading