Skip to content

Commit d62c97a

Browse files
committed
review document
1 parent 99a8c5b commit d62c97a

3 files changed

Lines changed: 100 additions & 115 deletions

File tree

src/site/xdoc/frame-howto.xml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,56 @@
55
<properties>
66
<title>Frames Tutorial</title>
77
<author>Ahmed Ashour</author>
8+
<author>RBRi</author>
89
</properties>
910

1011
<body>
11-
<section name="Example I">
12+
13+
<macro name="toc"/>
14+
15+
<section name="Example I" id="example_1">
16+
<p>
17+
Accessing the page enclosed inside a <code>&lt;frame&gt;</code> or <code>&lt;iframe&gt;</code> element
18+
can be done by calling <code>HtmlPage.getFrames()</code>.
19+
</p>
1220
<p>
13-
Getting the page inside &lt;frame&gt; element or &lt;iframe&gt; element can be done by using
14-
HtmlPage.getFrames().<br/>
15-
Suppose you have the following page:
21+
Suppose you have the following HTML page:
1622
</p>
17-
<source><![CDATA[
18-
<html>
23+
<source><![CDATA[<html>
1924
<body>
20-
<iframe src="two.html">
25+
<iframe src="two.html"></iframe>
2126
</body>
2227
</html>]]></source>
2328
<p>
24-
You can use the following code to get the content of <tt>two.html</tt>:
29+
You can use the following code to retrieve the content of <code>two.html</code>:
2530
</p>
26-
<source><![CDATA[
27-
final List<FrameWindow> window = page.getFrames();
31+
<source><![CDATA[final List<FrameWindow> window = page.getFrames();
2832
final HtmlPage pageTwo = (HtmlPage) window.get(0).getEnclosedPage();]]></source>
2933
</section>
3034

31-
<section name="Example II">
35+
<section name="Example II" id="example_2">
3236
<p>
33-
Another example that navigates API docs to get a desired page of a class:
37+
The following example navigates API documentation frames to access a specific class page:
3438
</p>
35-
<source><![CDATA[
36-
final WebClient client = new WebClient();
39+
<source><![CDATA[final WebClient client = new WebClient();
3740
final HtmlPage mainPage = client.getPage("https://www.htmlunit.org/apidocs/index.html");]]></source>
3841

3942
<p>
40-
To get the page of the first frame (at upper left) and click the sixth link:
43+
To access the page in the first frame (upper left) and click the sixth link:
4144
</p>
42-
<source><![CDATA[
43-
final HtmlPage packageListPage = (HtmlPage) mainPage.getFrames().get(0).getEnclosedPage();
45+
<source><![CDATA[final HtmlPage packageListPage = (HtmlPage) mainPage.getFrames().get(0).getEnclosedPage();
4446
packageListPage.getAnchors().get(5).click();]]></source>
4547

4648
<p>
47-
To get the page of the frame named 'packageFrame' (at lower left) and click the second link:
49+
To access the page in the frame named <code>packageFrame</code> (lower left) and click the second link:
4850
</p>
49-
<source><![CDATA[
50-
final HtmlPage packagePage = (HtmlPage) mainPage.getFrameByName("packageFrame").getEnclosedPage();
51+
<source><![CDATA[final HtmlPage packagePage = (HtmlPage) mainPage.getFrameByName("packageFrame").getEnclosedPage();
5152
packagePage.getAnchors().get(1).click();]]></source>
52-
53+
5354
<p>
54-
To get the page of the frame named 'classFrame' (at right):
55+
To access the page in the frame named <code>classFrame</code> (right main pane):
5556
</p>
56-
<source><![CDATA[
57-
final HtmlPage classPage = (HtmlPage) mainPage.getFrameByName("classFrame").getEnclosedPage();]]></source>
57+
<source><![CDATA[final HtmlPage classPage = (HtmlPage) mainPage.getFrameByName("classFrame").getEnclosedPage();]]></source>
5858
</section>
5959
</body>
60-
</document>
61-
60+
</document>

src/site/xdoc/images-howto.xml

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
11
<?xml version="1.0"?>
2-
<document>
2+
<document xmlns="http://maven.apache.org/XDOC/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://maven.apache.org/XDOC/2.0 https://maven.apache.org/xsd/xdoc-2.0.xsd">
34

45
<properties>
56
<title>Image format support</title>
7+
<author>RBRi</author>
68
</properties>
79

810
<body>
9-
<section name="General">
11+
12+
<macro name="toc"/>
13+
14+
<section name="General" id="general">
1015
<p>
11-
Because HtmlUnit is a headless browsers you might think HtmlUnit can be agnostic to image formats.
12-
This is in general true but not if you look at the details. Even if HtmlUnit is headless there is
13-
still support for layout related methods like Element.getBoundingClientRect(). A second case is
14-
Canvas.drawImage(). To support this HtmlUnit has to be able to determine the dimensions of a given
15-
image (for the first case) and produce a raster version (for the second case).
16+
Because HtmlUnit is a headless browser, you might think HtmlUnit can be agnostic to image formats[cite: 13].
17+
This is generally true, but not when inspecting layout-related details[cite: 13]. Even though HtmlUnit
18+
is headless, there is still support for layout-related methods like <code>Element.getBoundingClientRect()</code>.
19+
A second case is <code>Canvas.drawImage()</code>.
20+
To support these, HtmlUnit must determine the dimensions of a given image (for layout calculations) and render
21+
a rasterized version (for canvas operations).
1622
</p>
1723
<p>
18-
For this HtmlUnit uses <a href="https://docs.oracle.com/javase/8/docs/api/javax/imageio/package-summary.html">ImageIO</a>.
19-
Sadly there is only support for JPEG, PNG, BMP, WBMP and GIF.
24+
For image processing, HtmlUnit uses Java's <a href="https://docs.oracle.com/javase/8/docs/api/javax/imageio/package-summary.html">ImageIO</a>.
25+
Out of the box, standard ImageIO only supports JPEG, PNG, BMP, WBMP, and GIF.
2026
</p>
2127
<p>
22-
If HtmlUnit has to deal with the details of an unsupported image format a message is shown in the log and
23-
the image is (more or less) ignored.
28+
When HtmlUnit encounters an unsupported image format, a warning is recorded in the log and
29+
the image is generally ignored.
2430
</p>
2531
<p>
26-
To overcome this limitation you have to install support for more file formats from
27-
<a href="https://github.com/haraldk/TwelveMonkeys">TwelveMonkeys</a>
32+
To overcome this limitation, you can install additional format plugins, such as those provided by
33+
<a href="https://github.com/haraldk/TwelveMonkeys">TwelveMonkeys</a>.
2834
</p>
29-
<subsection name="Example">
35+
36+
<subsection name="Example" id="example">
3037
<p>
31-
Add svg support to be able to include SVG images into your canvas drawings<br/>
32-
This is simply done by adding some dependencies to your project:
38+
To enable SVG support for drawing SVG images onto HTML5 canvases, add the required dependencies
39+
to your project's <code>pom.xml</code> file:
3340
</p>
34-
<source>
35-
<![CDATA[ <dependency>
41+
<source><![CDATA[<dependency>
3642
<groupId>com.twelvemonkeys.imageio</groupId>
3743
<artifactId>imageio-batik</artifactId>
38-
<version>3.6.4</version>
44+
<version>3.14.0</version>
3945
</dependency>
4046
<dependency>
4147
<groupId>org.apache.xmlgraphics</groupId>
4248
<artifactId>batik-transcoder</artifactId>
43-
<version>1.17</version>
49+
<version>1.19</version>
4450
<exclusions>
4551
<exclusion>
4652
<groupId>commons-logging</groupId>
@@ -54,16 +60,15 @@
5460
</dependency>
5561
]]></source>
5662
<p>
57-
To make sure everything is working you can execute this code and check if you get a BufferedImage.
63+
To verify that image decoding works as expected, run this snippet to confirm a valid <code>BufferedImage</code> is created[cite: 13]:
5864
</p>
59-
<source>
60-
<![CDATA[ final String svg = "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\">"
61-
+ "<circle cx=\"5\" cy=\"5\" r=\"4\" stroke=\"black\" stroke-width=\"1\" fill=\"red\" />"
62-
+ "</svg>";
63-
BufferedImage img = ImageIO.read(new ByteArrayInputStream(svg.getBytes(StandardCharsets.US_ASCII)));
64-
System.out.println(img);]]></source>
65+
<source><![CDATA[final String svg = "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\">"
66+
+ "<circle cx=\"5\" cy=\"5\" r=\"4\" stroke=\"black\" stroke-width=\"1\" fill=\"red\" />"
67+
+ "</svg>";
68+
BufferedImage img = ImageIO.read(new ByteArrayInputStream(svg.getBytes(StandardCharsets.US_ASCII)));
69+
System.out.println(img);
70+
]]></source>
6571
</subsection>
6672
</section>
6773
</body>
6874
</document>
69-

0 commit comments

Comments
 (0)