Class SharedContext

java.lang.Object
com.openhtmltopdf.layout.SharedContext

public class SharedContext extends 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 Details

    • DEFAULT_DPI

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

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

      @Deprecated private static final boolean DEFAULT_INTERACTIVE
      Deprecated.
      Belongs in Java2D renderer.
      See Also:
    • MM__PER__CM

      private static final int MM__PER__CM
      See Also:
    • CM__PER__IN

      private static final float CM__PER__IN
      See Also:
    • textRenderer

      private TextRenderer textRenderer
    • media

      private String media
    • uac

      private UserAgentCallback uac
    • interactive

      private boolean interactive
    • idMap

      private Map<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 Map<Element,CalculatedStyle> styleMap
    • replacedElementFactory

      private ReplacedElementFactory replacedElementFactory
    • tempCanvas

      private Rectangle tempCanvas
    • fontResolver

      protected FontResolver fontResolver
    • css

      protected StyleReference css
    • 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
    • canvas

      protected FSCanvas canvas
    • namespaceHandler

      private NamespaceHandler namespaceHandler
    • defaultPageHeight

      private Float defaultPageHeight
    • defaultPageWidth

      private Float defaultPageWidth
    • defaultPageSizeIsInches

      private boolean defaultPageSizeIsInches
    • replacementText

      private String replacementText
    • lineBreaker

      private FSTextBreaker lineBreaker
    • characterBreaker

      private FSTextBreaker characterBreaker
    • _unicodeToLowerTransformer

      private FSTextTransformer _unicodeToLowerTransformer
    • _unicodeToUpperTransformer

      private FSTextTransformer _unicodeToUpperTransformer
    • _unicodeToTitleTransformer

      private FSTextTransformer _unicodeToTitleTransformer
    • _preferredTransformerFactoryImplementationClass

      public String _preferredTransformerFactoryImplementationClass
    • _preferredDocumentBuilderFactoryImplementationClass

      public String _preferredDocumentBuilderFactoryImplementationClass
    • _rootCounterContext

      private final RootCounterContext _rootCounterContext
  • Constructor Details

    • SharedContext

      public SharedContext()
  • Method Details

    • 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 String getMedia()
      The media for this context
    • getTextRenderer

      public TextRenderer getTextRenderer()
    • 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)
    • getCss

      public StyleReference getCss()
    • setCss

      public void setCss(StyleReference css)
    • getCanvas

      public FSCanvas getCanvas()
    • setCanvas

      public void setCanvas(FSCanvas canvas)
    • setTempCanvas

      public void setTempCanvas(Rectangle rect)
    • getFixedRectangle

      public Rectangle getFixedRectangle()
    • setNamespaceHandler

      public void setNamespaceHandler(NamespaceHandler nh)
    • getNamespaceHandler

      public NamespaceHandler getNamespaceHandler()
    • addBoxId

      public void addBoxId(String id, Box box)
    • getBoxById

      public Box getBoxById(String id)
    • removeBoxId

      public void removeBoxId(String id)
    • getIdMap

      public Map<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(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).
    • getUserAgentCallback

      public UserAgentCallback getUserAgentCallback()
    • 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
    • getFont

      public FSFont getFont(FontSpecification spec)
    • getXHeight

      public float getXHeight(FontContext fontContext, FontSpecification fs)
    • getBaseURL

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

      public void setBaseURL(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(String name, 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(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.
    • getReplacedElementFactory

      public ReplacedElementFactory getReplacedElementFactory()
    • setReplacedElementFactory

      public void setReplacedElementFactory(ReplacedElementFactory ref)
    • getDefaultPageWidth

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

      public Float getDefaultPageHeight()
      Stores a default page height.
      Returns:
      default page height or null.
      See Also:
    • 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 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(String replacement)
    • setDefaultPageSize

      public void setDefaultPageSize(Float pageWidth, 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 -
    • getLineBreaker

      public FSTextBreaker getLineBreaker()
    • 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)
    • getGlobalCounterContext

      public RootCounterContext getGlobalCounterContext()