-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#409 convert unused "main" method in QuotingExample to QuotingExample…
…Test this test still doesn't verify anything, but at least it's a working sample of html with quotes.
- Loading branch information
Showing
1 changed file
with
47 additions
and
55 deletions.
There are no files selected for viewing
102 changes: 47 additions & 55 deletions
102
...xamples/src/main/java/QuotingExample.java → ...tmlrenderer/swing/QuotingExampleTest.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 |
---|---|---|
@@ -1,55 +1,47 @@ | ||
import org.xhtmlrenderer.simple.XHTMLPanel; | ||
import org.xhtmlrenderer.util.XMLUtil; | ||
|
||
import javax.swing.*; | ||
|
||
import static javax.swing.SwingUtilities.invokeLater; | ||
|
||
|
||
public class QuotingExample extends JFrame { | ||
//currently we cannot display different quotes based on depth | ||
private static final String DOCUMENT = | ||
""" | ||
<html> | ||
<head> | ||
<style type='text/css'><![CDATA[ | ||
* { quotes: '"' '"' "'" "'" } | ||
q:before { content: open-quote } | ||
q:after { content: close-quote } | ||
blockquote p:before { content: open-quote } | ||
blockquote p:after { content: no-close-quote } | ||
blockquote p.last:after { content: close-quote } | ||
]]></style> | ||
</head> | ||
<body> | ||
<blockquote> | ||
<p>This is just a test of the emergency <q>quoting</q> system.</p> | ||
<p>This is only a test.</p> | ||
<p class='last'>Thank you for your cooperation during this <q>test.</q></p> | ||
</blockquote> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
protected void frameInit() { | ||
super.frameInit(); | ||
|
||
setTitle("CSS Quoting Example"); | ||
setDefaultCloseOperation(EXIT_ON_CLOSE); | ||
|
||
XHTMLPanel xr = new XHTMLPanel(); | ||
try { | ||
xr.setDocument(XMLUtil.documentFromString(DOCUMENT)); | ||
} catch (Exception e) { | ||
throw new ExceptionInInitializerError(e); | ||
} | ||
|
||
add(xr); | ||
|
||
setSize(500, 300); | ||
} | ||
|
||
public static void main(String[] args) { | ||
invokeLater(() -> new QuotingExample().setVisible(true)); | ||
} | ||
} | ||
package org.xhtmlrenderer.swing; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
|
||
import static org.xhtmlrenderer.swing.Java2DRenderer.htmlAsImage; | ||
|
||
public class QuotingExampleTest { | ||
private static final Logger log = LoggerFactory.getLogger(QuotingExampleTest.class); | ||
|
||
//currently we cannot display different quotes based on depth | ||
private static final String DOCUMENT = | ||
""" | ||
<html> | ||
<head> | ||
<style type='text/css'><![CDATA[ | ||
* { quotes: '"' '"' "'" "'" } | ||
q:before { content: open-quote } | ||
q:after { content: close-quote } | ||
blockquote p:before { content: open-quote } | ||
blockquote p:after { content: no-close-quote } | ||
blockquote p.last:after { content: close-quote } | ||
]]></style> | ||
</head> | ||
<body> | ||
<blockquote> | ||
<p>This is just a test of the emergency <q>quoting</q> system.</p> | ||
<p>This is only a test.</p> | ||
<p class='last'>Thank you for your cooperation during this <q>test.</q></p> | ||
</blockquote> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
@Test | ||
public void exampleWithQuotes() throws Exception { | ||
BufferedImage image = htmlAsImage(DOCUMENT, 600); | ||
File result = new File("target/%s.png".formatted(getClass().getSimpleName())); | ||
ImageIO.write(image, "png", result); | ||
log.info("Generated image from html: {}", result.getAbsolutePath()); | ||
} | ||
} |