Package com.pd4ml
Class CustomTag
- java.lang.Object
-
- com.pd4ml.util.Base
-
- com.pd4ml.CustomTag
-
- Direct Known Subclasses:
BatikSvgCustomTag,MathMLCustomTag,ORCodeCustomTag,PD4MLSvgCustomTag
public class CustomTag extends com.pd4ml.util.BaseBase class for handlers of custom HTML tags, which render content PD4ML does not support natively, for example charts or barcodes. Register a handler withPD4ML.addCustomTagHandler(String, CustomTag).The registered object serves as a factory: for each occurrence of the tag in the document PD4ML calls
getInstance(String, FontCache), and the returned instance reports the size of the element (getWidth(int),getHeight(int)) and draws it (paint(float, float, float, float, float, float, Graphics2D)). The element is laid out as an inline replaced element, like an image; CSSwidthandheighton the tag override the reported size.A subclass typically overrides
getInstance(String, FontCache)to return a new instance of itself, parses its parameters fromgetInnerCode(), and overrides the size and paint methods. The default implementation draws a placeholder box.
-
-
Constructor Summary
Constructors Constructor Description CustomTag()Creates the handler object to register withPD4ML.addCustomTagHandler(String, CustomTag).CustomTag(java.lang.String code, com.pd4ml.fonts.FontCache fontCache, CustomTag prime)Creates the handler instance for one occurrence of the tag; used bygetInstance(String, FontCache).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetHeight(int base)Returns the natural height of the element.java.lang.StringgetInnerCode()Returns the source code of the tag occurrence: the complete element as it appears in the document, including the opening tag with its attributes, the content and the closing tag, for example<chart type="pie">...</chart>.CustomTaggetInstance(java.lang.String code, com.pd4ml.fonts.FontCache fontCache)Creates the handler instance for one occurrence of the tag.intgetWidth(int base)Returns the natural width of the element.booleanisEmptyTag()Tells the parser whether the tag is an empty element without content or closing tag, like<br>.voidpaint(float x, float y, float width, float height, float containerWidth, float containerHeight, java.awt.Graphics2D g)Draws the element.voidpaint(float x, float y, java.awt.Graphics2D g)Draws the element at the given position, at its natural size.voidsetElement(com.pd4ml.html.doc.elements.Element element)Called by PD4ML to pass the document element of this tag occurrence, for example to read its computed style.voidsetHeight(int height)Sets the height the defaultgetHeight(int)reports.voidsetInnerCode(java.lang.String code)Replaces the source code of the tag occurrence.voidsetWidth(int width)Sets the width the defaultgetWidth(int)reports.
-
-
-
Constructor Detail
-
CustomTag
public CustomTag()
Creates the handler object to register withPD4ML.addCustomTagHandler(String, CustomTag).
-
CustomTag
public CustomTag(java.lang.String code, com.pd4ml.fonts.FontCache fontCache, CustomTag prime)Creates the handler instance for one occurrence of the tag; used bygetInstance(String, FontCache).- Parameters:
code- the source code of the tag occurrencefontCache- the font cache of the conversionprime- the registered handler that creates this instance
-
-
Method Detail
-
getInstance
public CustomTag getInstance(java.lang.String code, com.pd4ml.fonts.FontCache fontCache)
Creates the handler instance for one occurrence of the tag. PD4ML calls it on the registered handler while parsing the document. Subclasses override it to return an instance of themselves, typically created withCustomTag(String, FontCache, CustomTag).- Parameters:
code- the source code of the tag occurrence; seegetInnerCode()fontCache- the font cache of the conversion- Returns:
- the handler instance for this occurrence
-
setElement
public void setElement(com.pd4ml.html.doc.elements.Element element)
Called by PD4ML to pass the document element of this tag occurrence, for example to read its computed style.- Parameters:
element- the element
-
getInnerCode
public java.lang.String getInnerCode()
Returns the source code of the tag occurrence: the complete element as it appears in the document, including the opening tag with its attributes, the content and the closing tag, for example<chart type="pie">...</chart>.- Returns:
- the source code
-
setInnerCode
public void setInnerCode(java.lang.String code)
Replaces the source code of the tag occurrence.- Parameters:
code- the new source code
-
getWidth
public int getWidth(int base) throws java.io.IOExceptionReturns the natural width of the element. The default implementation returns the value set withsetWidth(int).- Parameters:
base- the width available in the containing block, in pixels, for handlers that adapt their size to it- Returns:
- the width in pixels
- Throws:
java.io.IOException- if the size cannot be determined
-
getHeight
public int getHeight(int base) throws java.io.IOExceptionReturns the natural height of the element. The default implementation returns the value set withsetHeight(int).- Parameters:
base- the width available in the containing block, in pixels- Returns:
- the height in pixels
- Throws:
java.io.IOException- if the size cannot be determined
-
setWidth
public void setWidth(int width)
Sets the width the defaultgetWidth(int)reports.- Parameters:
width- the width in pixels
-
setHeight
public void setHeight(int height)
Sets the height the defaultgetHeight(int)reports.- Parameters:
height- the height in pixels
-
paint
public void paint(float x, float y, float width, float height, float containerWidth, float containerHeight, java.awt.Graphics2D g) throws java.io.IOExceptionDraws the element. PD4ML calls this method for each output page the element appears on. The default implementation callspaint(float, float, Graphics2D).- Parameters:
x- the left edge of the element box in the coordinate system ofgy- the top edge of the element boxwidth- the width of the element box, after CSS sizingheight- the height of the element box, after CSS sizingcontainerWidth- the width of the area the element is placed incontainerHeight- the height of the area the element is placed ing- the graphics context to draw on; for PDF output, a PDF-generating implementation- Throws:
java.io.IOException- if drawing fails
-
paint
public void paint(float x, float y, java.awt.Graphics2D g) throws java.io.IOExceptionDraws the element at the given position, at its natural size. The default implementation draws a placeholder box labeled "DUMMY".- Parameters:
x- the left edge of the element box in the coordinate system ofgy- the top edge of the element boxg- the graphics context to draw on- Throws:
java.io.IOException- if drawing fails
-
isEmptyTag
public boolean isEmptyTag()
Tells the parser whether the tag is an empty element without content or closing tag, like<br>. The default implementation returnsfalse: the parser reads everything up to the matching closing tag as part of the element.- Returns:
trueif the tag has no content and no closing tag
-
-