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

Add support for Memory Mapping and HPGL2 un-terminated commands #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ subprojects {
apply plugin: 'com.jfrog.bintray'
apply plugin: 'net.researchgate.release'

version = "2.3"
version = "2.5"

check.dependsOn jacocoTestReport

bintrayUpload.dependsOn 'jar', 'sourceJar', 'javadocJar'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

javadoc {
Expand Down
3 changes: 3 additions & 0 deletions pclbox/src/main/java/de/textmode/pclbox/HpglCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class HpglCommands {
MAPPINGS.put("AP", "Automatic Pen Operations");
MAPPINGS.put("AR", "Arc Relative Three Point");
MAPPINGS.put("AS", "Acceleration Select");
MAPPINGS.put("AT", "Arc through three points");
MAPPINGS.put("BF", "Buffer Plot");
MAPPINGS.put("BL", "Buffer Label");
MAPPINGS.put("BP", "Begin Plot");
Expand Down Expand Up @@ -117,6 +118,8 @@ final class HpglCommands {
MAPPINGS.put("PS", "Plot Size");
MAPPINGS.put("PT", "Pen Thickness");
MAPPINGS.put("PU", "Pen Up");
MAPPINGS.put("PW", "Pen Width");
MAPPINGS.put("QL", "Quality Level");
MAPPINGS.put("RA", "Fill Rectangle Absolute");
MAPPINGS.put("RO", "Rotate Coordinate System");
MAPPINGS.put("RP", "Replot");
Expand Down
12 changes: 7 additions & 5 deletions pclbox/src/main/java/de/textmode/pclbox/HpglParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ final class HpglParser extends DataStreamParser {

private static final int END_OF_STREAM = -1;
private static final int ESCAPE = 0x1B;

//this is not a guaranteed terminator.
private static final int TERMINATOR = ';';
private static final int DOUBLE_QUOTES = '\"';

Expand Down Expand Up @@ -88,17 +90,17 @@ private int parseCommand(final long offset, final String command) throws IOExcep
// terminator..... Then... the HP/GL command "CO" (Comment) requires that the comment is placed in quotes
// and the last quotes are the terminator). But of course in the wild you'll find HP/GL files where the comment
// is not put in double quotes....
//
// Currently we only support commands that are terminated with the default terminator ";". Nowadays this is
// by convention the way HP/GL is included in PCL... At least I've never seen HP/GL (embedded in PCL) that
// does not follow this convention...

final StringBuilder sb = new StringBuilder();
boolean inQuotedString = false;
int readByte = this.getInputStream().read();

while (readByte != END_OF_STREAM) {

if (readByte == TERMINATOR && !inQuotedString) {
//Deal with fact the ';' terminator character is optional for the command. This means the command may
//terminate with the sequence to return to PCL mode, which always starts with an escape character.
//Escape character is always reserved within HPGL for a command, so this should be safe without quote check.
if ((readByte == TERMINATOR && !inQuotedString) || readByte == ESCAPE) {
this.getPrinterCommandHandler().handlePrinterCommand(
new HpglCommand(offset, command, sb.toString().trim()));

Expand Down
3 changes: 2 additions & 1 deletion pclbox/src/main/java/de/textmode/pclbox/Pcl5Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ private PrinterCommand parseOceImageStreamDataContainer(final long offset) throw
do {
readByte = this.getInputStream().read();
sb.append(Character.toString((char) readByte));
} while (readByte != '>');
}
while (readByte != '>');

readByte = this.getInputStream().read();
if (readByte != 'A') {
Expand Down
Loading