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

September improvements by @backslash47 #143

Closed
wants to merge 10 commits into from
7 changes: 4 additions & 3 deletions 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-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-core</artifactId>
Expand All @@ -21,8 +21,9 @@

<distributionManagement>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/danfickle/maven/com.openhtmltopdf:openhtmltopdf-parent</url>
<id>nexus.inqool.cz</id>
<name>nexus.inqool.cz</name>
<url>http://nexus.inqool.cz/repository/maven-releases/</url>
</repository>
</distributionManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,18 @@ public final class CSSName implements Comparable {
NOT_INHERITED,
new SizePropertyBuilder()
);

/**
* Unique CSSName instance for CSS2 property.
*/
public final static CSSName BOX_SIZING =
addProperty(
"box-sizing",
PRIMITIVE,
"content-box",
NOT_INHERITED,
new PrimitivePropertyBuilders.BoxSizing()
);

/**
* Unique CSSName instance for CSS3 property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ public class IdentValue implements FSDerivedValue {
public static final IdentValue SKEW_X = addValue("skewX");
public static final IdentValue SKEW_Y = addValue("skewY");

/*
* Box-sizing
*/
public static final IdentValue BORDER_BOX = addValue("border-box");
public static final IdentValue CONTENT_BOX = addValue("content-box");


/**
* Description of the Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,17 @@ protected BitSet getAllowed() {
}
}

public static class BoxSizing extends SingleIdent {
// border-box | content-box
private static final BitSet ALLOWED = setFor(
new IdentValue[] {
IdentValue.BORDER_BOX, IdentValue.CONTENT_BOX});

protected BitSet getAllowed() {
return ALLOWED;
}
}


public static class Widows extends PlainInteger {
protected boolean isNegativeValuesAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
* this for class instantiation externally.
*/
protected CalculatedStyle() {
_derivedValuesById = new FSDerivedValue[CSSName.countCSSPrimitiveNames()];
_derivedValuesById = new FSDerivedValue[CSSName.countCSSNames()];
}


Expand Down Expand Up @@ -1140,6 +1140,10 @@ public boolean isMaxHeightNone() {
return isIdent(CSSName.MAX_HEIGHT, IdentValue.NONE);
}

public boolean isBorderBox() {
return isIdent(CSSName.BOX_SIZING, IdentValue.BORDER_BOX);
}

public int getMinWidth(CssContext c, int cbWidth) {
return (int) getFloatPropertyProportionalTo(CSSName.MIN_WIDTH, cbWidth, c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static String createCounterText(IdentValue listStyle, int listCounter) {
text = toRoman(listCounter).toUpperCase();
} else if (listStyle == IdentValue.DECIMAL_LEADING_ZERO) {
text = (listCounter >= 10 ? "" : "0") + listCounter;
} else if (listStyle == IdentValue.DISC) {
text = "\u2022";
} else { // listStyle == IdentValue.DECIMAL or anything else
text = Integer.toString(listCounter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ public void calcDimensions(LayoutContext c) {
protected void calcDimensions(LayoutContext c, int cssWidth) {
if (! isDimensionsCalculated()) {
CalculatedStyle style = getStyle();
boolean borderBox = style.isBorderBox();

RectPropertySet padding = getPadding(c);
BorderPropertySet border = getBorder(c);
Expand All @@ -707,16 +708,21 @@ protected void calcDimensions(LayoutContext c, int cssWidth) {
if (c.isPrint() && getStyle().isDynamicAutoWidth()) {
setContentWidth(calcEffPageRelativeWidth(c));
} else {
setContentWidth((getContainingBlockWidth() - getLeftMBP() - getRightMBP()));
int proporcionalContainingBlockWidth = cssWidth != -1 ? cssWidth : getContainingBlockWidth();

if (borderBox) {
setContentWidth((proporcionalContainingBlockWidth - (int)border.width() - (int)padding.width()));
} else {
setContentWidth((proporcionalContainingBlockWidth) - getLeftMBP() - getRightMBP());
}

}
setHeight(0);

if (! isAnonymous() || (isFromCaptionedTable() && isFloated())) {
int pinnedContentWidth = -1;

if (cssWidth != -1) {
setContentWidth(cssWidth);
} else if (getStyle().isAbsolute() || getStyle().isFixed()) {
if (getStyle().isAbsolute() || getStyle().isFixed()) {
pinnedContentWidth = calcPinnedContentWidth(c);
if (pinnedContentWidth != -1) {
setContentWidth(pinnedContentWidth);
Expand All @@ -725,7 +731,13 @@ protected void calcDimensions(LayoutContext c, int cssWidth) {

int cssHeight = getCSSHeight(c);
if (cssHeight != -1) {
setHeight(cssHeight);
if (borderBox) {
setHeight(cssHeight - (int)padding.height() - (int)border.height());
} else {
setHeight(cssHeight);
}


}

//check if replaced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,25 @@ protected InputStream openStream(String uri) {
java.io.InputStream is = null;

try {
URL urlObj = new URL(uri);

if (urlObj.getProtocol().equalsIgnoreCase("http") ||
urlObj.getProtocol().equalsIgnoreCase("https")) {
return _streamFactory.getUrl(uri).getStream();
}
else {
try {
is = new URL(uri).openStream();
} catch (java.net.MalformedURLException e) {
XRLog.exception("bad URL given: " + uri, e);
} catch (java.io.FileNotFoundException e) {
XRLog.exception("item at URI " + uri + " not found");
} catch (java.io.IOException e) {
XRLog.exception("IO problem for " + uri, e);
}
if (uri.startsWith("classpath:")) {
is = NaiveUserAgent.class.getResourceAsStream(uri.substring("classpath:".length()));
} else {
URL urlObj = new URL(uri);

if (urlObj.getProtocol().equalsIgnoreCase("http") ||
urlObj.getProtocol().equalsIgnoreCase("https")) {
return _streamFactory.getUrl(uri).getStream();
} else {
try {
is = new URL(uri).openStream();
} catch (java.net.MalformedURLException e) {
XRLog.exception("bad URL given: " + uri, e);
} catch (java.io.FileNotFoundException e) {
XRLog.exception("item at URI " + uri + " not found");
} catch (java.io.IOException e) {
XRLog.exception("IO problem for " + uri, e);
}
}
}
} catch (MalformedURLException e2) {
XRLog.exception("bad URL given: " + uri, e2);
Expand All @@ -210,22 +213,25 @@ protected Reader openReader(String uri) {
InputStream is = null;

try {
URL urlObj = new URL(uri);

if (urlObj.getProtocol().equalsIgnoreCase("http") ||
urlObj.getProtocol().equalsIgnoreCase("https")) {
return _streamFactory.getUrl(uri).getReader();
}
else {
try {
is = new URL(uri).openStream();
} catch (java.net.MalformedURLException e) {
XRLog.exception("bad URL given: " + uri, e);
} catch (java.io.FileNotFoundException e) {
XRLog.exception("item at URI " + uri + " not found");
} catch (java.io.IOException e) {
XRLog.exception("IO problem for " + uri, e);
}
if (uri.startsWith("classpath:")) {
is = NaiveUserAgent.class.getResourceAsStream(uri.substring("classpath:".length()));
} else {
URL urlObj = new URL(uri);

if (urlObj.getProtocol().equalsIgnoreCase("http") ||
urlObj.getProtocol().equalsIgnoreCase("https")) {
return _streamFactory.getUrl(uri).getReader();
} else {
try {
is = new URL(uri).openStream();
} catch (java.net.MalformedURLException e) {
XRLog.exception("bad URL given: " + uri, e);
} catch (java.io.FileNotFoundException e) {
XRLog.exception("item at URI " + uri + " not found");
} catch (java.io.IOException e) {
XRLog.exception("IO problem for " + uri, e);
}
}
}
} catch (MalformedURLException e2) {
XRLog.exception("bad URL given: " + uri, e2);
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-examples/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-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-examples</artifactId>
Expand Down
11 changes: 6 additions & 5 deletions openhtmltopdf-java2d/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-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-java2d</artifactId>
Expand All @@ -23,10 +23,11 @@
</license>
</licenses>
<distributionManagement>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/danfickle/maven/com.openhtmltopdf:openhtmltopdf-parent</url>
</repository>
<repository>
<id>nexus.inqool.cz</id>
<name>nexus.inqool.cz</name>
<url>http://nexus.inqool.cz/repository/maven-releases/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
Expand Down
11 changes: 6 additions & 5 deletions openhtmltopdf-jsoup-dom-converter/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-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-jsoup-dom-converter</artifactId>
Expand All @@ -24,10 +24,11 @@
</licenses>

<distributionManagement>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/danfickle/maven/com.openhtmltopdf:openhtmltopdf-parent</url>
</repository>
<repository>
<id>nexus.inqool.cz</id>
<name>nexus.inqool.cz</name>
<url>http://nexus.inqool.cz/repository/maven-releases/</url>
</repository>
</distributionManagement>

<dependencies>
Expand Down
11 changes: 6 additions & 5 deletions openhtmltopdf-log4j/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-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-log4j</artifactId>
Expand All @@ -24,10 +24,11 @@
</licenses>

<distributionManagement>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/danfickle/maven/com.openhtmltopdf:openhtmltopdf-parent</url>
</repository>
<repository>
<id>nexus.inqool.cz</id>
<name>nexus.inqool.cz</name>
<url>http://nexus.inqool.cz/repository/maven-releases/</url>
</repository>
</distributionManagement>

<dependencies>
Expand Down
19 changes: 13 additions & 6 deletions openhtmltopdf-pdfbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-parent</artifactId>
<version>0.0.1-RC12-SNAPSHOT</version>
<version>0.0.1-RC12-inqool</version>
</parent>

<artifactId>openhtmltopdf-pdfbox</artifactId>
Expand All @@ -35,10 +35,11 @@
</license>
</licenses>
<distributionManagement>
<repository>
<id>bintray</id>
<url>https://api.bintray.com/maven/danfickle/maven/com.openhtmltopdf:openhtmltopdf-parent</url>
</repository>
<repository>
<id>nexus.inqool.cz</id>
<name>nexus.inqool.cz</name>
<url>http://nexus.inqool.cz/repository/maven-releases/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
Expand All @@ -50,8 +51,14 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.7</version>
<!-- reverted back because of custom changes -->
<version>2.0.5-inqool</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>xmpbox</artifactId>
<version>2.0.5-inqool</version>
</dependency>
<dependency>
<groupId>com.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-core</artifactId>
Expand Down
Loading