Skip to content

Commit

Permalink
Merge pull request #4 from danfickle/open-dev-v1
Browse files Browse the repository at this point in the history
Update to latest official
  • Loading branch information
DSW-PS authored Sep 6, 2019
2 parents c16e049 + 69d767a commit e0bb3a8
Show file tree
Hide file tree
Showing 121 changed files with 3,293 additions and 685 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: java
jdk:
- openjdk8
- oraclejdk8
- openjdk11
- oraclejdk11
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
## CHANGELOG

### head - 0.0.1-RC18-SNAPSHOT
### head - 1.0.1-SNAPSHOT

### 1.0.0 (2019-July-23)
+ [#372](https://github.com/danfickle/openhtmltopdf/pull/372) Much improved sizing support for `img`, `svg` and `math` elements.
+ [#344](https://github.com/danfickle/openhtmltopdf/issues/344) Use PDFs in `img` tag: `<img src="some.pdf" page="1" alt="Some alt text" />`.

### 0.0.1-RC21 (2019-June-29)
+ [#361](https://github.com/danfickle/openhtmltopdf/issues/361) The SVG renderer now uses Batik in a more secure mode (no scripts, no external resource requests) by default. If you need the old behavior that allowed external resource requests and possibly scripts, please see the new BatikSVGDrawer constructor (only for trusted SVGs). Thanks @krabbenpuler.
+ [#363](https://github.com/danfickle/openhtmltopdf/pull/363) Upgrade PDFBOX to 2.0.16. Thanks @rototor.
+ [#353](https://github.com/danfickle/openhtmltopdf/issues/353) Better error handling around SVGs linked from `img` tag. Thanks @ieugen.
+ [#342](https://github.com/danfickle/openhtmltopdf/issues/342) Fixed text-justification/letter-spacing when fallback fonts are in use. Thanks @daliuss.
+ [#351](https://github.com/danfickle/openhtmltopdf/issues/351) Improved text-justification by removing spaces at ends of lines. Thanks @halcsi.


### 0.0.1-RC20 (2019-April-26)
**IMPORTANT:** This release was brought forward due to a CVE in PDFBOX. While not directly affecting this project (it affects parsing of untrusted PDFs), it is better not to have a vulnerable library on your classpath.
+ [#349](https://github.com/danfickle/openhtmltopdf/issues/349) Upgrade PDF-BOX to 2.0.15 to avoid CVE in 2.0.14. Thanks @BryceMehring.
+ [#347](https://github.com/danfickle/openhtmltopdf/issues/347) Add document language and title preference for PDF/A documents to satisfy Acrobat Pro validator. Thanks @mattstjean.
+ [#339](https://github.com/danfickle/openhtmltopdf/issues/339) Mark Jsoup DOM converter module as deprecated (for removal). Please see integration guide for replacement. This module may also pull in an insecure version of Guava so please migrate now.

### 0.0.1-RC19 (2019-March-18)
+ [#336](https://github.com/danfickle/openhtmltopdf/issues/336) Fix for broken image links causing an NPE. Thanks @svenfrauen.
+ [#334](https://github.com/danfickle/openhtmltopdf/pull/334) Allow the user to supply `PDPage` objects via page supplier. Thanks @DSW-PS.

### 0.0.1-RC18 (2019-March-10)
+ Please start using the fast renderer (`builder.useFastMode()`) as the old renderer will be removed in a future version.
+ [#180](https://github.com/danfickle/openhtmltopdf/issues/180) Fast renderer is finally ready for production. The fast renderer comes with:
+ Nearly 150 automated end-to-end regression tests. This is about 150 more than the old renderer.
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# OPEN HTML TO PDF

## CURRENTY SEEKING FEEDBACK
+ [Roadmap for version 1](https://github.com/danfickle/openhtmltopdf/issues/170)

## OVERVIEW
Open HTML to PDF is a pure-Java library for rendering arbitrary well-formed XML/XHTML (and even HTML5)
using CSS 2.1 for layout and formatting, outputting to PDF or images.
Expand Down Expand Up @@ -55,7 +52,7 @@ of these can be found in the [dependency graph](https://github.com/danfickle/ope
Open HTML to PDF is based on [Flying-saucer](https://github.com/flyingsaucerproject/flyingsaucer). Credit goes to the contributors of that project. Code will also be used from [neoFlyingSaucer](https://github.com/danfickle/neoflyingsaucer)

## FAQ
+ OPEN HTML TO PDF is tested with OpenJDK 8 and 11, Oracle JDK 8 and 11. As of RC18, it requires at least Java 8 to run.
+ OPEN HTML TO PDF is tested with OpenJDK 8 and 11. We are [not currently testing with Oracle JDKs](https://github.com/travis-ci/travis-ci/issues/10290). As of RC18, it requires at least Java 8 to run.
+ No, you can not use it on Android.
+ You should be able to use it on Google App Engine (Java 8 or greater environment). [Let us know your experience](https://github.com/danfickle/openhtmltopdf/issues/179).
+ <s>Flowing columns are not implemented.</s> Implemented in RC12.
Expand All @@ -69,7 +66,31 @@ from ````/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/Testc

## CHANGELOG

### head - 0.0.1-RC19-SNAPSHOT
### head - 1.0.1-SNAPSHOT


### 1.0.0 (2019-July-23)
+ [#372](https://github.com/danfickle/openhtmltopdf/pull/372) Much improved sizing support for `img`, `svg` and `math` elements.
+ [#344](https://github.com/danfickle/openhtmltopdf/issues/344) Use PDFs in `img` tag: `<img src="some.pdf" page="1" alt="Some alt text" />`.

### 0.0.1-RC21 (2019-June-29)
+ [#361](https://github.com/danfickle/openhtmltopdf/issues/361) The SVG renderer now uses Batik in a more secure mode (no scripts, no external resource requests) by default. If you need the old behavior that allowed external resource requests and possibly scripts, please see the new BatikSVGDrawer constructor (only for trusted SVGs). Thanks @krabbenpuler.
+ [#363](https://github.com/danfickle/openhtmltopdf/pull/363) Upgrade PDFBOX to 2.0.16. Thanks @rototor.
+ [#353](https://github.com/danfickle/openhtmltopdf/issues/353) Better error handling around SVGs linked from `img` tag. Thanks @ieugen.
+ [#342](https://github.com/danfickle/openhtmltopdf/issues/342) Fixed text-justification/letter-spacing when fallback fonts are in use. Thanks @daliuss.
+ [#351](https://github.com/danfickle/openhtmltopdf/issues/351) Improved text-justification by removing spaces at ends of lines. Thanks @halcsi.


### 0.0.1-RC20 (2019-April-26)
**IMPORTANT:** This release was brought forward due to a CVE in PDFBOX. While not directly affecting this project (it affects parsing of untrusted PDFs), it is better not to have a vulnerable library on your classpath.
+ [#349](https://github.com/danfickle/openhtmltopdf/issues/349) Upgrade PDF-BOX to 2.0.15 to avoid CVE in 2.0.14. Thanks @BryceMehring.
+ [#347](https://github.com/danfickle/openhtmltopdf/issues/347) Add document language and title preference for PDF/A documents to satisfy Acrobat Pro validator. Thanks @mattstjean.
+ [#339](https://github.com/danfickle/openhtmltopdf/issues/339) Mark Jsoup DOM converter module as deprecated (for removal). Please see integration guide for replacement. This module may also pull in an insecure version of Guava so please migrate now.

### 0.0.1-RC19 (2019-March-18)
+ [#336](https://github.com/danfickle/openhtmltopdf/issues/336) Fix for broken image links causing an NPE. Thanks @svenfrauen.
+ [#334](https://github.com/danfickle/openhtmltopdf/pull/334) Allow the user to supply `PDPage` objects via page supplier. Thanks @DSW-PS.


### 0.0.1-RC18 (2019-March-10)
+ Please start using the fast renderer (`builder.useFastMode()`) as the old renderer will be removed in a future version.
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-parent</artifactId>
<version>0.0.1-RC19-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</parent>

<artifactId>openhtmltopdf-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/
package com.openhtmltopdf.css.constants;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

import java.util.Objects;
import com.openhtmltopdf.css.parser.CSSErrorHandler;
import com.openhtmltopdf.css.parser.CSSParser;
import com.openhtmltopdf.css.parser.PropertyValue;
Expand Down Expand Up @@ -55,7 +55,7 @@
*
* @author Patrick Wright
*/
public final class CSSName implements Comparable {
public final class CSSName implements Comparable<CSSName> {
/**
* marker var, used for initialization
*/
Expand Down Expand Up @@ -115,12 +115,12 @@ public final class CSSName implements Comparable {
/**
* Map of all CSS properties
*/
private static final Map ALL_PROPERTY_NAMES = new TreeMap();
private static final Map<String, CSSName> ALL_PROPERTY_NAMES = new HashMap<>();

/**
* Map of all non-shorthand CSS properties
*/
private static final Map ALL_PRIMITIVE_PROPERTY_NAMES = new TreeMap();
private static final Map<String, CSSName> ALL_PRIMITIVE_PROPERTY_NAMES = new HashMap<>();

/**
* Unique CSSName instance for CSS2 property.
Expand Down Expand Up @@ -915,6 +915,24 @@ public final class CSSName implements Comparable {
INHERITS,
new PrimitivePropertyBuilders.PageBreakInside()
);

public final static CSSName BREAK_AFTER =
addProperty(
"break-after",
PRIMITIVE,
"auto",
NOT_INHERITED,
new PrimitivePropertyBuilders.BreakAfter()
);

public final static CSSName BREAK_BEFORE =
addProperty(
"break-before",
PRIMITIVE,
"auto",
NOT_INHERITED,
new PrimitivePropertyBuilders.BreakBefore()
);

/**
* Unique CSSName instance for CSS2 property.
Expand Down Expand Up @@ -1815,24 +1833,6 @@ public static int countCSSPrimitiveNames() {
return ALL_PRIMITIVE_PROPERTY_NAMES.size();
}

/**
* Iterator of ALL CSS 2 visual property names.
*
* @return Returns
*/
public static Iterator allCSS2PropertyNames() {
return ALL_PROPERTY_NAMES.keySet().iterator();
}

/**
* Iterator of ALL primitive (non-shorthand) CSS 2 visual property names.
*
* @return Returns
*/
public static Iterator allCSS2PrimitivePropertyNames() {
return ALL_PRIMITIVE_PROPERTY_NAMES.keySet().iterator();
}

/**
* Returns true if the named property inherits by default, according to the
* CSS2 spec.
Expand Down Expand Up @@ -1877,8 +1877,7 @@ public static PropertyBuilder getPropertyBuilder(CSSName cssName) {
* @return The byPropertyName value
*/
public static CSSName getByPropertyName(String propName) {

return (CSSName) ALL_PROPERTY_NAMES.get(propName);
return ALL_PROPERTY_NAMES.get(propName);
}

public static CSSName getByID(int id) {
Expand Down Expand Up @@ -1927,10 +1926,10 @@ private static synchronized CSSName addProperty(
}

static {
Iterator iter = ALL_PROPERTY_NAMES.values().iterator();
Iterator<CSSName> iter = ALL_PROPERTY_NAMES.values().iterator();
ALL_PROPERTIES = new CSSName[ALL_PROPERTY_NAMES.size()];
while (iter.hasNext()) {
CSSName name = (CSSName) iter.next();
CSSName name = iter.next();
ALL_PROPERTIES[name.FS_ID] = name;
}
}
Expand All @@ -1941,8 +1940,8 @@ public void error(String uri, String message) {
XRLog.cssParse("(" + uri + ") " + message);
}
});
for (Iterator i = ALL_PRIMITIVE_PROPERTY_NAMES.values().iterator(); i.hasNext(); ) {
CSSName cssName = (CSSName)i.next();
for (Iterator<CSSName> i = ALL_PRIMITIVE_PROPERTY_NAMES.values().iterator(); i.hasNext(); ) {
CSSName cssName = i.next();
if (cssName.initialValue.charAt(0) != '=' && cssName.implemented) {
PropertyValue value = parser.parsePropertyValue(
cssName, StylesheetInfo.USER_AGENT, cssName.initialValue);
Expand All @@ -1959,14 +1958,14 @@ public void error(String uri, String message) {
}
}

//Assumed to be consistent with equals because CSSName is in essence an enum
public int compareTo(Object object) {
if (object == null) throw new NullPointerException();//required by Comparable
return FS_ID - ((CSSName) object).FS_ID;//will throw ClassCastException according to Comparable if not a CSSName
// Assumed to be consistent with equals because CSSName is in essence an enum
@Override
public int compareTo(CSSName object) {
Objects.requireNonNull(object);
return this.FS_ID - object.FS_ID;
}

// FIXME equals, hashcode

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CSSName)) return false;
Expand All @@ -1976,6 +1975,7 @@ public boolean equals(Object o) {
return FS_ID == cssName.FS_ID;
}

@Override
public int hashCode() {
return FS_ID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@
*/
public class IdentValue implements FSDerivedValue {
private static int maxAssigned = 0;
private static final Map<String, IdentValue> ALL_IDENT_VALUES = new HashMap<>();

/**
* Description of the Field
*/
private final String ident;

public final int FS_ID;

public final static IdentValue ABSOLUTE = addValue("absolute");
Expand Down Expand Up @@ -254,11 +251,10 @@ public class IdentValue implements FSDerivedValue {
public static final IdentValue BORDER_BOX = addValue("border-box");
public static final IdentValue CONTENT_BOX = addValue("content-box");


/**
* Description of the Field
/*
* Column break.
*/
private static Map<String, IdentValue> ALL_IDENT_VALUES;
public static final IdentValue COLUMN = addValue("column");

/**
* Constructor for the IdentValue object
Expand All @@ -276,6 +272,7 @@ private IdentValue(String ident) {
*
* @return a string representation of the object.
*/
@Override
public String toString() {
return ident;
}
Expand All @@ -290,22 +287,19 @@ public String toString() {
* @return see desc.
*/
public static IdentValue getByIdentString(String ident) {
IdentValue val = (IdentValue) ALL_IDENT_VALUES.get(ident);
IdentValue val = ALL_IDENT_VALUES.get(ident);
if (val == null) {
throw new XRRuntimeException("Ident named " + ident + " has no IdentValue instance assigned to it.");
}
return val;
}

/**
* TODO: doc
*/
public static boolean looksLikeIdent(String ident) {
return (IdentValue) ALL_IDENT_VALUES.get(ident) != null;
return ALL_IDENT_VALUES.get(ident) != null;
}

public static IdentValue valueOf(String ident) {
return (IdentValue)ALL_IDENT_VALUES.get(ident);
return ALL_IDENT_VALUES.get(ident);
}

public static int getIdentCount() {
Expand All @@ -318,10 +312,7 @@ public static int getIdentCount() {
* @param ident The feature to be added to the Value attribute
* @return Returns
*/
private final static synchronized IdentValue addValue(String ident) {
if (ALL_IDENT_VALUES == null) {
ALL_IDENT_VALUES = new HashMap<String, IdentValue>();
}
private final static IdentValue addValue(String ident) {
IdentValue val = new IdentValue(ident);
ALL_IDENT_VALUES.put(ident, val);
return val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,25 @@ protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class BreakBefore extends SingleIdent {
private static final BitSet ALLOWED = setFor(
new IdentValue[] { IdentValue.AUTO, IdentValue.COLUMN });

protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class BreakAfter extends SingleIdent {
private static final BitSet ALLOWED = setFor(
new IdentValue[] { IdentValue.AUTO, IdentValue.COLUMN });

protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class Page extends AbstractPropertyBuilder {
public List buildDeclarations(
CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ public boolean isAutoZIndex() {
}

public boolean establishesBFC() {
if (hasColumns()) {
return true;
}

FSDerivedValue value = valueByName(CSSName.POSITION);

if (value instanceof FunctionValue) { // running(header)
Expand Down Expand Up @@ -1031,7 +1035,7 @@ public boolean isListItem() {
}

public boolean hasColumns() {
return !isIdent(CSSName.COLUMN_COUNT, IdentValue.AUTO) && asFloat(CSSName.COLUMN_COUNT) > 1;
return !isIdent(CSSName.COLUMN_COUNT, IdentValue.AUTO) && asFloat(CSSName.COLUMN_COUNT) > 1;
}

public int columnCount() {
Expand Down Expand Up @@ -1091,6 +1095,14 @@ public boolean isForcePageBreakAfter() {
return val == IdentValue.ALWAYS || val == IdentValue.LEFT
|| val == IdentValue.RIGHT;
}

public boolean isColumnBreakBefore() {
return isIdent(CSSName.BREAK_BEFORE, IdentValue.COLUMN);
}

public boolean isColumnBreakAfter() {
return isIdent(CSSName.BREAK_AFTER, IdentValue.COLUMN);
}

public boolean isAvoidPageBreakInside() {
return isIdent(CSSName.PAGE_BREAK_INSIDE, IdentValue.AVOID);
Expand Down
Loading

0 comments on commit e0bb3a8

Please # to comment.