OLD | NEW |
(Empty) | |
| 1 package org.chromium.distiller.webdocument; |
| 2 |
| 3 import com.google.gwt.dom.client.Document; |
| 4 import com.google.gwt.dom.client.Element; |
| 5 import org.chromium.distiller.DomUtil; |
| 6 |
| 7 /** |
| 8 * WebFigure represents a figure element, containing an image and optionally a c
aption. |
| 9 */ |
| 10 public class WebFigure extends WebImage { |
| 11 |
| 12 private Element figCaption; |
| 13 |
| 14 /** |
| 15 * Build a figure element. |
| 16 * @param e The element detected as an image. |
| 17 * @param w The original width of the image. |
| 18 * @param h The original height of the image. |
| 19 * @param src The source URL of the image being extracted. |
| 20 * @param caption The element containing the caption of the image. |
| 21 */ |
| 22 public WebFigure(Element e, int w, int h, String src, Element caption) { |
| 23 super(e, w, h, src); |
| 24 figCaption = caption; |
| 25 } |
| 26 |
| 27 /** |
| 28 * WebFigure extends WebImage so it can use WebImage generated output |
| 29 * and just handle the caption since an html figure is basically a |
| 30 * placeholder for an image and a caption. |
| 31 */ |
| 32 @Override |
| 33 public String generateOutput(boolean textOnly) { |
| 34 Element figcaption = DomUtil.cloneAndProcessTree(figCaption); |
| 35 if (textOnly) return figcaption.getInnerText(); |
| 36 |
| 37 Element figure = Document.get().createElement("FIGURE"); |
| 38 figure.appendChild(getProcessedNode()); |
| 39 if (!figCaption.getInnerHTML().isEmpty()) { |
| 40 figure.appendChild(figcaption); |
| 41 } |
| 42 return figure.getString(); |
| 43 } |
| 44 } |
OLD | NEW |