-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#736 Example of converting unsupported font tag attribute to CSS.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.83 KB
...tmltopdf-examples/src/main/resources/visualtest/expected/issue-736-font-tag-converter.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
openhtmltopdf-examples/src/main/resources/visualtest/html/issue-736-font-tag-converter.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,15 @@ | ||
<html> | ||
<head> | ||
<style> | ||
@page { | ||
size: 300px 300px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<font>Black text</font> | ||
<font color="#ff0000">Red text</font> | ||
<font color="#00ff00" style="background-color: red">Green text on red</font> | ||
<font color="#0000ff" style="background-color: orange;">Blue text on orange</font> | ||
</body> | ||
</html> |
74 changes: 74 additions & 0 deletions
74
...test/java/com/openhtmltopdf/visualregressiontests/DOMManipulatorVisualRegressionTest.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,74 @@ | ||
package com.openhtmltopdf.visualregressiontests; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NodeList; | ||
|
||
import com.openhtmltopdf.extend.FSDOMMutator; | ||
import com.openhtmltopdf.testlistener.PrintingRunner; | ||
import com.openhtmltopdf.visualtest.TestSupport; | ||
import com.openhtmltopdf.visualtest.VisualTester; | ||
|
||
@RunWith(PrintingRunner.class) | ||
public class DOMManipulatorVisualRegressionTest { | ||
private VisualTester vt; | ||
|
||
@BeforeClass | ||
public static void configureTests() throws IOException { | ||
TestSupport.quietLogs(); | ||
TestSupport.makeFontFiles(); | ||
} | ||
|
||
@Before | ||
public void configureTester() { | ||
File outputDirectory = new File("target/test/visual-tests/test-output/"); | ||
|
||
outputDirectory.mkdirs(); | ||
|
||
vt = new VisualTester( | ||
"/visualtest/html/", /* Resource path. */ | ||
"/visualtest/expected/", /* Expected resource path */ | ||
outputDirectory | ||
); | ||
} | ||
|
||
/** | ||
* Tests an example of converting font tags with color attributes to CSS | ||
* style attributes. | ||
*/ | ||
@Test | ||
public void testIssue736FontTagConverter() throws IOException { | ||
FSDOMMutator domChanger = (doc) -> { | ||
NodeList fontTags = doc.getElementsByTagName("font"); | ||
|
||
for (int i = 0; i < fontTags.getLength(); i++) { | ||
Element fontTag = (Element) fontTags.item(i); | ||
|
||
if (fontTag.hasAttribute("color")) { | ||
String color = fontTag.getAttribute("color"); | ||
|
||
if (!fontTag.hasAttribute("style")) { | ||
fontTag.setAttribute("style", "color: " + color + ';'); | ||
} else { | ||
String oldStyle = fontTag.getAttribute("style"); | ||
String newStyle = oldStyle + "; color: " + color + ';'; | ||
|
||
fontTag.setAttribute("style", newStyle); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
assertTrue(vt.runTest("issue-736-font-tag-converter", (builder) -> { | ||
builder.addDOMMutator(domChanger); | ||
})); | ||
} | ||
} |