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

GH-79 improved content parser #164

Merged
merged 2 commits into from
Dec 29, 2020
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defaultTasks 'taskReport', 'dependencyReport', 'sourcesJar', 'genPomFileForCoreJ
// Main distribution for os bundle
distributions {
os {
distributionBaseName.set("icepdf-os")
distributionBaseName.set("icepdf")
version "${VERSION + (RELEASE_TYPE?.trim()? '-' + RELEASE_TYPE:'')}"
contents {
duplicatesStrategy = 'exclude'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.icepdf.core.pobjects.graphics.Shapes;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
Expand Down Expand Up @@ -185,8 +184,7 @@ public synchronized void init() throws InterruptedException {
}
// Build a new content parser for the content streams and apply the
// content stream of the calling content stream.
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, leafResources);
ContentParser cp = new ContentParser(library, leafResources);
cp.setGraphicsState(graphicsState);
byte[] in = getDecodedStreamBytes();
if (in != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
import org.icepdf.core.pobjects.graphics.text.WordText;
import org.icepdf.core.util.*;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.*;
import java.awt.geom.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -420,8 +419,7 @@ public synchronized void init() throws InterruptedException {
notifyPageInitializationStarted();
if (contents != null) {
try {
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
byte[][] streams = new byte[contents.size()][];
byte[] stream;
for (int i = 0, max = contents.size(); i < max; i++) {
Expand Down Expand Up @@ -1603,8 +1601,7 @@ public synchronized PageText getText() throws InterruptedException {
if (contents != null) {
try {

ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
byte[][] streams = new byte[contents.size()][];
for (int i = 0, max = contents.size(); i < max; i++) {
streams[i] = contents.get(i).getDecodedStreamBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public byte[] getDecodedStreamBytes(int presize) {
// decompress the stream
if (compressed) {
try {
// todo, could nio all a little speed up here.
ByteArrayInputStream streamInput = new ByteArrayInputStream(rawBytes);
long rawStreamLength = rawBytes.length;
InputStream input = getDecodedInputStream(streamInput, rawStreamLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.icepdf.core.util.Library;
import org.icepdf.core.util.Utils;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.*;
import java.util.HashMap;
Expand Down Expand Up @@ -136,8 +135,7 @@ public VariableTextFieldDictionary(Library library, HashMap entries) {
// the font and colour information we need to generate a new content stream
if (resources != null) {
try {
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
cp.parseTextBlocks(new byte[][]{defaultAppearance.getBytes()});
GraphicsState gs = cp.getGraphicsState();
if (gs != null) {
Expand Down Expand Up @@ -178,8 +176,7 @@ public String generateDefaultAppearance(String content, Resources resources) {
if (resources == null) {
resources = library.getCatalog().getInteractiveForm().getResources();
}
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
// use full parser so we parse the font color.
cp.parse(new byte[][]{possibleContent.getBytes()}, null);
GraphicsState gs = cp.getGraphicsState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.icepdf.core.pobjects.graphics.Shapes;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
Expand Down Expand Up @@ -77,8 +76,7 @@ public AppearanceState(Library library, HashMap entries, Object streamOrDictiona
matrix = new AffineTransform();
originalContentStream = new String(stream.getDecodedStreamBytes());
try {
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
shapes = cp.parse(new byte[][]{stream.getDecodedStreamBytes()}, null).getShapes();
} catch (Exception e) {
shapes = new Shapes();
Expand Down Expand Up @@ -139,8 +137,7 @@ public String getOriginalContentStream() {

public void setContentStream(byte[] contentBytes){
try {
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
shapes = cp.parse(new byte[][]{contentBytes}, null).getShapes();
} catch (Exception e) {
shapes = new Shapes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.icepdf.core.pobjects.graphics.Shapes;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.*;
import java.awt.geom.AffineTransform;
Expand Down Expand Up @@ -277,7 +276,7 @@ public void resetAppearanceStream(double dx, double dy, AffineTransform pageTran
// parse the shapes and assign to this instance
try {
Resources resources = form.getResources();
ContentParser cp = ContentParserFactory.getInstance().getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
shapes = cp.parse(new byte[][]{iconContentString.getBytes()}, null).getShapes();
} catch (Exception e) {
shapes = new Shapes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.icepdf.core.util.Defs;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.content.ContentParser;
import org.icepdf.core.util.content.ContentParserFactory;

import java.awt.*;
import java.awt.geom.AffineTransform;
Expand Down Expand Up @@ -287,8 +286,7 @@ public synchronized void init(GraphicsState graphicsState) {

// Build a new content parser for the content streams and apply the
// content stream of the calling content stream.
ContentParser cp = ContentParserFactory.getInstance()
.getContentParser(library, resources);
ContentParser cp = new ContentParser(library, resources);
cp.setGraphicsState(parentGraphicState);
try {
shapes = cp.parse(new byte[][]{getDecodedStreamBytes()}, null).getShapes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Library {
static {
try {
commonPoolThreads =
Defs.intProperty("org.icepdf.core.library.threadPoolSize", 2);
Defs.intProperty("org.icepdf.core.library.threadPoolSize", 4);
if (commonPoolThreads < 1) {
commonPoolThreads = 2;
}
Expand Down
Loading