Package com.pd4ml

Class CustomTag

    • Field Summary

      • Fields inherited from class com.pd4ml.util.Base

        AES_128BIT, AES_256BIT, LOG_ALL, LOG_CACHE, LOG_CSS, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_FONTS, LOG_INFO, LOG_MINIMAL, LOG_PARSE, LOG_TRACE, LOG_USAGE, LOG_VERBOSE, LOG_WARN, NO_LOG, PD4ML_LOG_LEVEL, RC4_128BIT, RC4_40BIT
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getHeight​(int base)
      Returns the natural height of the element.
      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>.
      CustomTag getInstance​(java.lang.String code, com.pd4ml.fonts.FontCache fontCache)
      Creates the handler instance for one occurrence of the tag.
      int getWidth​(int base)
      Returns the natural width of the element.
      boolean isEmptyTag()
      Tells the parser whether the tag is an empty element without content or closing tag, like <br>.
      void paint​(float x, float y, float width, float height, float containerWidth, float containerHeight, java.awt.Graphics2D g)
      Draws the element.
      void paint​(float x, float y, java.awt.Graphics2D g)
      Draws the element at the given position, at its natural size.
      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.
      void setHeight​(int height)
      Sets the height the default getHeight(int) reports.
      void setInnerCode​(java.lang.String code)
      Replaces the source code of the tag occurrence.
      void setWidth​(int width)
      Sets the width the default getWidth(int) reports.
      • Methods inherited from class com.pd4ml.util.Base

        log, log2, printLog, shouldForceException
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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 by getInstance(String, FontCache).
        Parameters:
        code - the source code of the tag occurrence
        fontCache - the font cache of the conversion
        prime - 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 with CustomTag(String, FontCache, CustomTag).
        Parameters:
        code - the source code of the tag occurrence; see getInnerCode()
        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.IOException
        Returns the natural width of the element. The default implementation returns the value set with setWidth(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.IOException
        Returns the natural height of the element. The default implementation returns the value set with setHeight(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 default getWidth(int) reports.
        Parameters:
        width - the width in pixels
      • setHeight

        public void setHeight​(int height)
        Sets the height the default getHeight(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.IOException
        Draws the element. PD4ML calls this method for each output page the element appears on. The default implementation calls paint(float, float, Graphics2D).
        Parameters:
        x - the left edge of the element box in the coordinate system of g
        y - the top edge of the element box
        width - the width of the element box, after CSS sizing
        height - the height of the element box, after CSS sizing
        containerWidth - the width of the area the element is placed in
        containerHeight - the height of the area the element is placed in
        g - 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.IOException
        Draws 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 of g
        y - the top edge of the element box
        g - 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 returns false: the parser reads everything up to the matching closing tag as part of the element.
        Returns:
        true if the tag has no content and no closing tag