Class SharedContext


  • public class SharedContext
    extends java.lang.Object
    The SharedContext stores pseudo global variables. Originally, it was reusable, but it is now recommended that the developer use a new instance for every run.
    • Field Detail

      • DEFAULT_DPI

        @Deprecated
        private static final float DEFAULT_DPI
        Deprecated.
        Belongs in Java2D renderer.
        See Also:
        Constant Field Values
      • DEFAULT_DOTS_PER_PIXEL

        @Deprecated
        private static final int DEFAULT_DOTS_PER_PIXEL
        Deprecated.
        Belongs in Java2D renderer.
        See Also:
        Constant Field Values
      • DEFAULT_INTERACTIVE

        @Deprecated
        private static final boolean DEFAULT_INTERACTIVE
        Deprecated.
        Belongs in Java2D renderer.
        See Also:
        Constant Field Values
      • media

        private java.lang.String media
      • interactive

        private boolean interactive
      • idMap

        private java.util.Map<java.lang.String,​Box> idMap
      • dpi

        private float dpi
        Used to adjust fonts, ems, points, into screen resolution. Internal program dots per inch.
      • dotsPerPixel

        private int dotsPerPixel
        Internal program dots per pixel.
      • mmPerDot

        private float mmPerDot
        dpi in a more usable way Internal program dots per mm (probably a fraction).
      • print

        private boolean print
      • styleMap

        private final java.util.Map<org.w3c.dom.Element,​CalculatedStyle> styleMap
      • tempCanvas

        private java.awt.Rectangle tempCanvas
      • debug_draw_boxes

        protected boolean debug_draw_boxes
      • debug_draw_line_boxes

        protected boolean debug_draw_line_boxes
      • debug_draw_inline_boxes

        protected boolean debug_draw_inline_boxes
      • debug_draw_font_metrics

        protected boolean debug_draw_font_metrics
      • defaultPageHeight

        private java.lang.Float defaultPageHeight
      • defaultPageWidth

        private java.lang.Float defaultPageWidth
      • defaultPageSizeIsInches

        private boolean defaultPageSizeIsInches
      • replacementText

        private java.lang.String replacementText
      • _preferredTransformerFactoryImplementationClass

        public java.lang.String _preferredTransformerFactoryImplementationClass
      • _preferredDocumentBuilderFactoryImplementationClass

        public java.lang.String _preferredDocumentBuilderFactoryImplementationClass
    • Constructor Detail

      • SharedContext

        public SharedContext()
    • Method Detail

      • newLayoutContextInstance

        public LayoutContext newLayoutContextInstance()
      • newRenderingContextInstance

        public RenderingContext newRenderingContextInstance()
      • getFontResolver

        public FontResolver getFontResolver()
        Gets the fontResolver attribute of the Context object
        Returns:
        The fontResolver value
      • getMedia

        public java.lang.String getMedia()
        The media for this context
      • debugDrawBoxes

        public boolean debugDrawBoxes()
      • debugDrawLineBoxes

        public boolean debugDrawLineBoxes()
      • debugDrawInlineBoxes

        public boolean debugDrawInlineBoxes()
      • debugDrawFontMetrics

        public boolean debugDrawFontMetrics()
      • setDebug_draw_boxes

        public void setDebug_draw_boxes​(boolean debug_draw_boxes)
      • setDebug_draw_line_boxes

        public void setDebug_draw_line_boxes​(boolean debug_draw_line_boxes)
      • setDebug_draw_inline_boxes

        public void setDebug_draw_inline_boxes​(boolean debug_draw_inline_boxes)
      • setDebug_draw_font_metrics

        public void setDebug_draw_font_metrics​(boolean debug_draw_font_metrics)
      • getCanvas

        public FSCanvas getCanvas()
      • setCanvas

        public void setCanvas​(FSCanvas canvas)
      • setTempCanvas

        public void setTempCanvas​(java.awt.Rectangle rect)
      • getFixedRectangle

        public java.awt.Rectangle getFixedRectangle()
      • setNamespaceHandler

        public void setNamespaceHandler​(NamespaceHandler nh)
      • addBoxId

        public void addBoxId​(java.lang.String id,
                             Box box)
      • getBoxById

        public Box getBoxById​(java.lang.String id)
      • removeBoxId

        public void removeBoxId​(java.lang.String id)
      • getIdMap

        public java.util.Map<java.lang.String,​Box> getIdMap()
      • setTextRenderer

        public void setTextRenderer​(TextRenderer textRenderer)
        Sets the textRenderer attribute of the RenderingContext object
        Parameters:
        textRenderer - The new textRenderer value
      • setMedia

        public void setMedia​(java.lang.String media)
        Set the current media type. This is usually something like screen or print . See the media section of the CSS 2.1 spec for more information on media types.
        Parameters:
        media - The new media value
      • getUac

        @Deprecated
        public UserAgentCallback getUac()
        Deprecated.
        Use getUserAgentCallback instead for clearer code.
        Gets the uac attribute of the RenderingContext object
        Returns:
        The uac value (user agent).
      • setUserAgentCallback

        public void setUserAgentCallback​(UserAgentCallback userAgentCallback)
      • getDPI

        public float getDPI()
        Gets the dPI attribute of the RenderingContext object
        Returns:
        The dPI value
      • setDPI

        public void setDPI​(float dpi)
        Sets the effective DPI (Dots Per Inch) of the screen. You should normally never need to override the dpi, as it is already set to the system default by Toolkit.getDefaultToolkit().getScreenResolution() You can override the value if you want to scale EVERYTHING.
        Parameters:
        dpi - The new dPI value
      • getMmPerDotParent

        public float getMmPerDotParent()
        Gets the dPI attribute in a more useful form of the RenderingContext object
        Returns:
        The dPI value
      • getBaseURL

        public java.lang.String getBaseURL()
        Gets the baseURL attribute of the RenderingContext object
        Returns:
        The baseURL value
      • setBaseURL

        public void setBaseURL​(java.lang.String url)
        Sets the baseURL attribute of the RenderingContext object
        Parameters:
        url - The new baseURL value
      • isPaged

        public boolean isPaged()
        Returns true if the currently set media type is paged. Currently returns true only for print , projection , and embossed , handheld , and tv . See the media section of the CSS 2.1 spec for more information on media types.
        Returns:
        The paged value
      • isInteractive

        public boolean isInteractive()
      • setInteractive

        public void setInteractive​(boolean interactive)
      • isPrint

        public boolean isPrint()
      • setPrint

        public void setPrint​(boolean print)
      • setFontMapping

        @Deprecated
        public void setFontMapping​(java.lang.String name,
                                   java.awt.Font font)
        Deprecated.
        Definitely shouldn't use this method as it only applies for Java2D font resolver. Instead call getFontResolver, cast and use font adding methods on that.
        Adds or overrides a font mapping, meaning you can associate a particular font with a particular string. For example, the following would load a font out of the cool.ttf file and associate it with the name CoolFont :
           Font font = Font.createFont(Font.TRUETYPE_FONT,
           new FileInputStream("cool.ttf");
           setFontMapping("CoolFont", font);
         
        You could then put the following css in your page
           p { font-family: CoolFont Arial sans-serif; }
         
        You can also override existing font mappings, like replacing Arial with Helvetica.
        Parameters:
        name - The new font name
        font - The actual Font to map
      • setFontResolver

        public void setFontResolver​(FontResolver resolver)
      • getDotsPerPixel

        public int getDotsPerPixel()
        Get the internal dots measurement per CSS pixel.
      • setDotsPerPixel

        public void setDotsPerPixel​(int dotsPerPixel)
        Set the internal dots measurement per CSS pixel.
        Parameters:
        dotsPerPixel -
      • getStyle

        public CalculatedStyle getStyle​(org.w3c.dom.Element e)
        Gets the resolved style for an element. All primitive properties will have values.

        This method uses a cache.

        If the parent element's style is not cached this method will recursively work up the ancestor list until it styles the document with the initial values of CSS properties.
      • getDefaultPageWidth

        public java.lang.Float getDefaultPageWidth()
        Stores a default page width.
        Returns:
        default page width or null.
        See Also:
        isDefaultPageSizeInches()
      • getDefaultPageHeight

        public java.lang.Float getDefaultPageHeight()
        Stores a default page height.
        Returns:
        default page height or null.
        See Also:
        isDefaultPageSizeInches()
      • isDefaultPageSizeInches

        public boolean isDefaultPageSizeInches()
        If not, consider it as mm.
        Returns:
        true if the page size is in inches, false if it is in mm.
      • getReplacementText

        public java.lang.String getReplacementText()
        The replacement text to be used if a character cannot be renderered by the current or fallback fonts.
        Returns:
        the current replacement text, "#" by default
      • setReplacementText

        public void setReplacementText​(java.lang.String replacement)
      • setDefaultPageSize

        public void setDefaultPageSize​(java.lang.Float pageWidth,
                                       java.lang.Float pageHeight,
                                       boolean isInches)
        Set the default page dimensions. These may be overridden in CSS. If not set in CSS and null here, A4 will be used.
        Parameters:
        pageWidth -
        pageHeight -
      • setLineBreaker

        public void setLineBreaker​(FSTextBreaker breaker)
      • getCharacterBreaker

        public FSTextBreaker getCharacterBreaker()
      • setCharacterBreaker

        public void setCharacterBreaker​(FSTextBreaker breaker)
      • registerWithThread

        public void registerWithThread()
        This registers the shared context with a thread local so it can be used anywhere. It should be matched with a call to removeFromThread() when the run is complete.
      • removeFromThread

        public void removeFromThread()
        This removes the shared context from a thread local to avoid memory leaks.
      • getUnicodeToLowerTransformer

        public FSTextTransformer getUnicodeToLowerTransformer()
      • getUnicodeToUpperTransformer

        public FSTextTransformer getUnicodeToUpperTransformer()
      • getUnicodeToTitleTransformer

        public FSTextTransformer getUnicodeToTitleTransformer()
      • setUnicodeToLowerTransformer

        public void setUnicodeToLowerTransformer​(FSTextTransformer tr)
      • setUnicodeToUpperTransformer

        public void setUnicodeToUpperTransformer​(FSTextTransformer tr)
      • setUnicodeToTitleTransformer

        public void setUnicodeToTitleTransformer​(FSTextTransformer tr)