org.allcolor.yahp.cl.converter.swing
Class CSwingHtmlRenderer

java.lang.Object
  extended by org.allcolor.yahp.cl.converter.swing.CSwingHtmlRenderer

public final class CSwingHtmlRenderer
extends java.lang.Object

This class render an HTML document in a pdf graphics 2D. It use a JTextPane for html rendering.

Version:
0.98
Author:
Quentin Anciaux

Nested Class Summary
static class CSwingHtmlRenderer.CFormView
          This class is used to render Form components.
static class CSwingHtmlRenderer.CImageView
          This class extends ImageView and prevent images to be painted while painting root container, thus letting YaHP calculates correct page cutting.
static class CSwingHtmlRenderer.CInlineView
          This class extends InlineView and prevent text to be painted while painting root container, thus letting YaHP calculates correct page cutting.
private static class CSwingHtmlRenderer.CInputButtonRenderer
          Render a button
private static class CSwingHtmlRenderer.CInputCheckBoxRenderer
          Render a checkbox
private static class CSwingHtmlRenderer.CInputRadioRenderer
          Render a radio button
private static class CSwingHtmlRenderer.CInputTextFieldRenderer
          Render an input text field
private static class CSwingHtmlRenderer.CSelectComboBoxRenderer
          Render a combobox
private static class CSwingHtmlRenderer.CSelectListBoxRenderer
          Render a list box
private static class CSwingHtmlRenderer.CTextareaRenderer
          Render a textarea
static class CSwingHtmlRenderer.CView
          DOCUMENT ME!
private static class CSwingHtmlRenderer.SynchronousEditorKit
          An html editor kit which load images synchronously.
private static class CSwingHtmlRenderer.SynchronousViewFactory
          A view factory for the synchronous editor kit.
 
Field Summary
private static java.util.Map loadedFont
           
private static org.apache.log4j.Logger log
          Use for logging
private  javax.swing.JTextPane panel
          The panel to render the html doc
 
Constructor Summary
private CSwingHtmlRenderer()
          Constructor for the CSwingHtmlRenderer object
 
Method Summary
private  java.awt.Rectangle getMinimumSize(int width)
          return the size image needed to render the document without anything going off the side. could be different than the dimensions passed into layout because of text that couldn't break or a table that's set to be too big
private static void initFont(org.apache.fop.fonts.FontInfo info, java.util.Map properties)
          Init font embedding for fop
private  boolean isInBody(org.w3c.dom.Node fnode)
          Return true if node is in the body section
private  void layout(java.awt.Dimension dim)
          Layout the document
private static CTextPanePrinter layoutDocument(org.w3c.dom.Document doc, java.lang.String base_url, int[] wh, int width)
           
private static void registerTTFFile(java.util.List fonts, java.io.File f)
           
private static void renderHeaderFooter(java.lang.String urlForBase, java.util.List hf, java.awt.Graphics2D g, int pagenum, int pagetotal, IHtmlToPdfTransformer.PageSize size)
          Render the header/footer on the current page
static void renderToPDF(IHtmlToPdfTransformer.PageSize size, org.w3c.dom.Document node, java.lang.String fbase_url, java.util.List hf, java.util.Map properties, java.io.OutputStream out)
          Render the document in a pdf.
private  void setDocument(org.w3c.dom.Document node, java.lang.String base_url)
          Sets the document attribute
private  void validateForSwingHtmlComponent(org.w3c.dom.Node fnode, java.lang.String fbase_url, org.allcolor.css.parser.CStyler styler)
          Remove problematic node, translate img uri to absolute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.log4j.Logger log
Use for logging


loadedFont

private static final java.util.Map loadedFont

panel

private javax.swing.JTextPane panel
The panel to render the html doc

Constructor Detail

CSwingHtmlRenderer

private CSwingHtmlRenderer()
Constructor for the CSwingHtmlRenderer object

Method Detail

layoutDocument

private static CTextPanePrinter layoutDocument(org.w3c.dom.Document doc,
                                               java.lang.String base_url,
                                               int[] wh,
                                               int width)

renderToPDF

public static final void renderToPDF(IHtmlToPdfTransformer.PageSize size,
                                     org.w3c.dom.Document node,
                                     java.lang.String fbase_url,
                                     java.util.List hf,
                                     java.util.Map properties,
                                     java.io.OutputStream out)
                              throws IHtmlToPdfTransformer.CConvertException
Render the document in a pdf.

Parameters:
size - page size
node - document
fbase_url - base url of the document
hf - headers footers list
properties - transform properties
out - outputstream to write into
Throws:
IHtmlToPdfTransformer.CConvertException - if an error occurs while rendering

registerTTFFile

private static void registerTTFFile(java.util.List fonts,
                                    java.io.File f)

initFont

private static void initFont(org.apache.fop.fonts.FontInfo info,
                             java.util.Map properties)
Init font embedding for fop

Parameters:
info - PDF fop font info object.

setDocument

private final void setDocument(org.w3c.dom.Document node,
                               java.lang.String base_url)
Sets the document attribute

Parameters:
node - The new document value
base_url - The base uri value

isInBody

private final boolean isInBody(org.w3c.dom.Node fnode)
Return true if node is in the body section

Parameters:
fnode - node to check
Returns:
true if node is in the body section

getMinimumSize

private final java.awt.Rectangle getMinimumSize(int width)
return the size image needed to render the document without anything going off the side. could be different than the dimensions passed into layout because of text that couldn't break or a table that's set to be too big

Parameters:
width - page with
Returns:
The minimumSize value

layout

private final void layout(java.awt.Dimension dim)
Layout the document

Parameters:
dim - page size

renderHeaderFooter

private static final void renderHeaderFooter(java.lang.String urlForBase,
                                             java.util.List hf,
                                             java.awt.Graphics2D g,
                                             int pagenum,
                                             int pagetotal,
                                             IHtmlToPdfTransformer.PageSize size)
Render the header/footer on the current page

Parameters:
urlForBase - base url of the html document
hf - header-footer list
g - pdf graphics2d
pagenum - current page number
pagetotal - total page
size - pdf page size

validateForSwingHtmlComponent

private final void validateForSwingHtmlComponent(org.w3c.dom.Node fnode,
                                                 java.lang.String fbase_url,
                                                 org.allcolor.css.parser.CStyler styler)
Remove problematic node, translate img uri to absolute. Getting style attribute for element node

Parameters:
fnode - current node
fbase_url - document base url