forked from danfickle/openhtmltopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
danfickle#549 Fix soft hyphen characters are visible
- Loading branch information
schrader
committed
Oct 9, 2020
1 parent
83ae4e9
commit e8db381
Showing
10 changed files
with
256 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
openhtmltopdf-core/src/test/java/com/openhtmltopdf/util/OpenUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.openhtmltopdf.util; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author schrader | ||
*/ | ||
public class OpenUtilTest { | ||
|
||
@Test | ||
public void areAllCharactersPrintable() { | ||
String text = "abc 123 \uD844\uDCC1"; | ||
boolean printable = OpenUtil.areAllCharactersPrintable(text); | ||
assertThat(printable, is(true)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
openhtmltopdf-examples/src/main/java/com/openhtmltopdf/benchmark/NoopLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.openhtmltopdf.benchmark; | ||
|
||
import com.openhtmltopdf.util.Diagnostic; | ||
import com.openhtmltopdf.util.XRLogger; | ||
|
||
import java.util.logging.Level; | ||
|
||
/** | ||
* @author schrader | ||
*/ | ||
class NoopLogger implements XRLogger { | ||
@Override | ||
public void log(String where, Level level, String msg) { | ||
|
||
} | ||
|
||
@Override | ||
public void log(String where, Level level, String msg, Throwable th) { | ||
|
||
} | ||
|
||
@Override | ||
public void setLevel(String logger, Level level) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isLogLevelEnabled(Diagnostic diagnostic) { | ||
return false; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
openhtmltopdf-examples/src/main/java/com/openhtmltopdf/benchmark/RenderTextBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.openhtmltopdf.benchmark; | ||
|
||
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; | ||
import com.openhtmltopdf.util.XRLog; | ||
import org.apache.pdfbox.io.IOUtils; | ||
import org.apache.pdfbox.util.Charsets; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author schrader | ||
*/ | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Thread) | ||
public class RenderTextBenchmark { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Options opt = new OptionsBuilder() | ||
.include(RenderTextBenchmark.class.getSimpleName()) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
private Map<String, String> contents = new HashMap<>(); | ||
|
||
@Setup | ||
public void setUp() { | ||
XRLog.setLoggerImpl(new NoopLogger()); | ||
|
||
Arrays.asList( | ||
"/benchmark/render-text-plain.html", | ||
"/benchmark/render-text-soft-hyphens.html" | ||
).forEach(path -> contents.put(path, readContent(path))); | ||
} | ||
|
||
@Benchmark | ||
public void renderText_Plain() throws Exception { | ||
runRenderer(contents.get("/benchmark/render-text-plain.html")); | ||
} | ||
|
||
@Benchmark | ||
public void renderText_SoftHyphens() throws Exception { | ||
runRenderer(contents.get("/benchmark/render-text-soft-hyphens.html")); | ||
} | ||
|
||
private void runRenderer(String html) throws IOException { | ||
ByteArrayOutputStream actual = new ByteArrayOutputStream(); | ||
|
||
PdfRendererBuilder builder = new PdfRendererBuilder(); | ||
builder.withHtmlContent(html, null); | ||
builder.toStream(actual); | ||
builder.useFastMode(); | ||
builder.testMode(true); | ||
|
||
builder.run(); | ||
} | ||
|
||
private String readContent(String path) { | ||
try (InputStream htmlIs = RenderTextBenchmark.class.getResourceAsStream(path)) { | ||
byte[] htmlBytes = IOUtils.toByteArray(htmlIs); | ||
return new String(htmlBytes, Charsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
openhtmltopdf-examples/src/main/resources/benchmark/render-text-plain.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html PUBLIC | ||
"-//OPENHTMLTOPDF//DOC XHTML Character Entities Only 1.0//EN" ""> | ||
<html> | ||
<head> | ||
<style> | ||
</style> | ||
</head> | ||
<body> | ||
<p>Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc, litot Europa usa li sam vocabular.</p> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
openhtmltopdf-examples/src/main/resources/benchmark/render-text-soft-hyphens.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html PUBLIC | ||
"-//OPENHTMLTOPDF//DOC XHTML Character Entities Only 1.0//EN" ""> | ||
<html> | ||
<head> | ||
<style> | ||
</style> | ||
</head> | ||
<body> | ||
<p>Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.