Top Description Fields Constructors Methods
com.openhtmltopdf.layout

public Class SharedContext

extends Object
Class Inheritance
Imports
com.openhtmltopdf.context.StyleReference, com.openhtmltopdf.css.style.CalculatedStyle, .EmptyStyle, com.openhtmltopdf.css.value.FontSpecification, com.openhtmltopdf.extend.*, com.openhtmltopdf.layout.counter.RootCounterContext, com.openhtmltopdf.render.Box, .FSFont, .FSFontMetrics, .RenderingContext, com.openhtmltopdf.swing.AWTFontResolver, com.openhtmltopdf.util.ThreadCtx, org.w3c.dom.Document, .Element, .Node, java.awt.*, java.text.BreakIterator, java.util.HashMap, .Locale, .Map

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 Summary

Modifier and TypeField and Description
public String
public String
private final RootCounterContext
private FSTextTransformer
private FSTextTransformer
private FSTextTransformer
protected FSCanvas
private FSTextBreaker
private static final float
protected StyleReference
protected boolean
protected boolean
protected boolean
protected boolean
private static final int
DEFAULT_DOTS_PER_PIXEL

Deprecated Belongs in Java2D renderer.
private static final float
DEFAULT_DPI

Deprecated Belongs in Java2D renderer.
private static final boolean
DEFAULT_INTERACTIVE

Deprecated Belongs in Java2D renderer.
private Float
private boolean
private Float
private int
dotsPerPixel

Internal program dots per pixel.

private float
dpi

Used to adjust fonts, ems, points, into screen resolution.

protected FontResolver
private Map<String, Box>
private boolean
private FSTextBreaker
private String
private static final int
private float
mmPerDot

dpi in a more usable way Internal program dots per mm (probably a fraction).

private NamespaceHandler
private boolean
private ReplacedElementFactory
private String
private final Map<Element, CalculatedStyle>
private Rectangle
private TextRenderer
private UserAgentCallback

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addBoxId(String id, Box box)

public boolean
public boolean
public boolean
public boolean
public String

Returns:

The baseURL value
getBaseURL
()

Gets the baseURL attribute of the RenderingContext object

public Box
public FSCanvas
public FSTextBreaker
public StyleReference
public Float

Returns:

default page height or null.
getDefaultPageHeight
()

Stores a default page height.

public Float

Returns:

default page width or null.
getDefaultPageWidth
()

Stores a default page width.

public int
getDotsPerPixel()

Get the internal dots measurement per CSS pixel.

public float

Returns:

The dPI value
getDPI
()

Gets the dPI attribute of the RenderingContext object

public Rectangle
public FSFont
public FontResolver

Returns:

The fontResolver value
getFontResolver
()

Gets the fontResolver attribute of the Context object

public RootCounterContext
public Map<String, Box>
public FSTextBreaker
public String
getMedia()

The media for this context

public float

Returns:

The dPI value
getMmPerDotParent
()

Gets the dPI attribute in a more useful form of the RenderingContext object

public NamespaceHandler
public ReplacedElementFactory
public String

Returns:

the current replacement text, "#" by default
getReplacementText
()

The replacement text to be used if a character cannot be renderered by the current or fallback fonts.

public CalculatedStyle
getStyle(Element e)

Gets the resolved style for an element.

public TextRenderer
public UserAgentCallback

Returns:

The uac value (user agent).
getUac
()
Deprecated Use getUserAgentCallback instead for clearer code.

Gets the uac attribute of the RenderingContext object

public FSTextTransformer
public FSTextTransformer
public FSTextTransformer
public UserAgentCallback
public float
public boolean

Returns:

true if the page size is in inches, false if it is in mm.
isDefaultPageSizeInches
()

If not, consider it as mm.

public boolean
public boolean

Returns:

The paged value
isPaged
()

Returns true if the currently set media type is paged.

public boolean
public LayoutContext
public RenderingContext
public void
registerWithThread()

This registers the shared context with a thread local so it can be used anywhere.

public void
public void
removeFromThread()

This removes the shared context from a thread local to avoid memory leaks.

public void
setBaseURL(String
The new baseURL value
url
)

Sets the baseURL attribute of the RenderingContext object

public void
public void
public void
public void
setDebug_draw_boxes(boolean debug_draw_boxes)

public void
setDebug_draw_font_metrics(boolean debug_draw_font_metrics)

public void
setDebug_draw_inline_boxes(boolean debug_draw_inline_boxes)

public void
setDebug_draw_line_boxes(boolean debug_draw_line_boxes)

public void
setDefaultPageSize(Float pageWidth, Float pageHeight, boolean isInches)

Set the default page dimensions.

public void
setDotsPerPixel(int dotsPerPixel)

Set the internal dots measurement per CSS pixel.

public void
setDPI(float
The new dPI value
dpi
)

Sets the effective DPI (Dots Per Inch) of the screen.

public void
setFontMapping(String
The new font name
name
,
Font
The actual Font to map
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.

public void
public void
setInteractive(boolean interactive)

public void
public void
setMedia(String
The new media value
media
)

Set the current media type.

public void
public void
setPrint(boolean print)

public void
public void
public void
public void
setTextRenderer(TextRenderer
The new textRenderer value
textRenderer
)

Sets the textRenderer attribute of the RenderingContext object

public void
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_preferredDocumentBuilderFactoryImplementationClassback to summary
public String _preferredDocumentBuilderFactoryImplementationClass
_preferredTransformerFactoryImplementationClassback to summary
public String _preferredTransformerFactoryImplementationClass
_rootCounterContextback to summary
private final RootCounterContext _rootCounterContext
_unicodeToLowerTransformerback to summary
private FSTextTransformer _unicodeToLowerTransformer
_unicodeToTitleTransformerback to summary
private FSTextTransformer _unicodeToTitleTransformer
_unicodeToUpperTransformerback to summary
private FSTextTransformer _unicodeToUpperTransformer
canvasback to summary
protected FSCanvas canvas
characterBreakerback to summary
private FSTextBreaker characterBreaker
CM__PER__INback to summary
private static final float CM__PER__IN
cssback to summary
protected StyleReference css
debug_draw_boxesback to summary
protected boolean debug_draw_boxes
debug_draw_font_metricsback to summary
protected boolean debug_draw_font_metrics
debug_draw_inline_boxesback to summary
protected boolean debug_draw_inline_boxes
debug_draw_line_boxesback to summary
protected boolean debug_draw_line_boxes
DEFAULT_DOTS_PER_PIXELback to summary
private static final int DEFAULT_DOTS_PER_PIXEL

Deprecated

Belongs in Java2D renderer.

Annotations
@Deprecated
DEFAULT_DPIback to summary
private static final float DEFAULT_DPI

Deprecated

Belongs in Java2D renderer.

Annotations
@Deprecated
DEFAULT_INTERACTIVEback to summary
private static final boolean DEFAULT_INTERACTIVE

Deprecated

Belongs in Java2D renderer.

Annotations
@Deprecated
defaultPageHeightback to summary
private Float defaultPageHeight
defaultPageSizeIsInchesback to summary
private boolean defaultPageSizeIsInches
defaultPageWidthback to summary
private Float defaultPageWidth
dotsPerPixelback to summary
private int dotsPerPixel

Internal program dots per pixel.

dpiback to summary
private float dpi

Used to adjust fonts, ems, points, into screen resolution. Internal program dots per inch.

fontResolverback to summary
protected FontResolver fontResolver
idMapback to summary
private Map<String, Box> idMap
interactiveback to summary
private boolean interactive
lineBreakerback to summary
private FSTextBreaker lineBreaker
mediaback to summary
private String media
MM__PER__CMback to summary
private static final int MM__PER__CM
mmPerDotback to summary
private float mmPerDot

dpi in a more usable way Internal program dots per mm (probably a fraction).

namespaceHandlerback to summary
private NamespaceHandler namespaceHandler
printback to summary
private boolean print
replacedElementFactoryback to summary
private ReplacedElementFactory replacedElementFactory
replacementTextback to summary
private String replacementText
styleMapback to summary
private final Map<Element, CalculatedStyle> styleMap
tempCanvasback to summary
private Rectangle tempCanvas
textRendererback to summary
private TextRenderer textRenderer
uacback to summary
private UserAgentCallback uac

Constructor Detail

SharedContextback to summary
public SharedContext()

Method Detail

addBoxIdback to summary
public void addBoxId(String id, Box box)
debugDrawBoxesback to summary
public boolean debugDrawBoxes()
debugDrawFontMetricsback to summary
public boolean debugDrawFontMetrics()
debugDrawInlineBoxesback to summary
public boolean debugDrawInlineBoxes()
debugDrawLineBoxesback to summary
public boolean debugDrawLineBoxes()
getBaseURLback to summary
public String getBaseURL()

Gets the baseURL attribute of the RenderingContext object

Returns:String

The baseURL value

getBoxByIdback to summary
public Box getBoxById(String id)
getCanvasback to summary
public FSCanvas getCanvas()
getCharacterBreakerback to summary
public FSTextBreaker getCharacterBreaker()
getCssback to summary
public StyleReference getCss()
getDefaultPageHeightback to summary
public Float getDefaultPageHeight()

Stores a default page height.

Returns:Float

default page height or null.

See Also
isDefaultPageSizeInches()
getDefaultPageWidthback to summary
public Float getDefaultPageWidth()

Stores a default page width.

Returns:Float

default page width or null.

See Also
isDefaultPageSizeInches()
getDotsPerPixelback to summary
public int getDotsPerPixel()

Get the internal dots measurement per CSS pixel.

getDPIback to summary
public float getDPI()

Gets the dPI attribute of the RenderingContext object

Returns:float

The dPI value

getFixedRectangleback to summary
public Rectangle getFixedRectangle()
getFontback to summary
public FSFont getFont(FontSpecification spec)
getFontResolverback to summary
public FontResolver getFontResolver()

Gets the fontResolver attribute of the Context object

Returns:FontResolver

The fontResolver value

getGlobalCounterContextback to summary
public RootCounterContext getGlobalCounterContext()
getIdMapback to summary
public Map<String, Box> getIdMap()
getLineBreakerback to summary
public FSTextBreaker getLineBreaker()
getMediaback to summary
public String getMedia()

The media for this context

getMmPerDotParentback to summary
public float getMmPerDotParent()

Gets the dPI attribute in a more useful form of the RenderingContext object

Returns:float

The dPI value

getNamespaceHandlerback to summary
public NamespaceHandler getNamespaceHandler()
getReplacedElementFactoryback to summary
public ReplacedElementFactory getReplacedElementFactory()
getReplacementTextback to summary
public String getReplacementText()

The replacement text to be used if a character cannot be renderered by the current or fallback fonts.

Returns:String

the current replacement text, "#" by default

getStyleback to summary
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.

getTextRendererback to summary
public TextRenderer getTextRenderer()
getUacback to summary
public UserAgentCallback getUac()

Deprecated

Use getUserAgentCallback instead for clearer code.

Gets the uac attribute of the RenderingContext object

Returns:UserAgentCallback

The uac value (user agent).

Annotations
@Deprecated
getUnicodeToLowerTransformerback to summary
public FSTextTransformer getUnicodeToLowerTransformer()
getUnicodeToTitleTransformerback to summary
public FSTextTransformer getUnicodeToTitleTransformer()
getUnicodeToUpperTransformerback to summary
public FSTextTransformer getUnicodeToUpperTransformer()
getUserAgentCallbackback to summary
public UserAgentCallback getUserAgentCallback()
getXHeightback to summary
public float getXHeight(FontContext fontContext, FontSpecification fs)
isDefaultPageSizeInchesback to summary
public boolean isDefaultPageSizeInches()

If not, consider it as mm.

Returns:boolean

true if the page size is in inches, false if it is in mm.

isInteractiveback to summary
public boolean isInteractive()
isPagedback to summary
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:boolean

The paged value

isPrintback to summary
public boolean isPrint()
newLayoutContextInstanceback to summary
public LayoutContext newLayoutContextInstance()
newRenderingContextInstanceback to summary
public RenderingContext newRenderingContextInstance()
registerWithThreadback to summary
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.

removeBoxIdback to summary
public void removeBoxId(String id)
removeFromThreadback to summary
public void removeFromThread()

This removes the shared context from a thread local to avoid memory leaks.

setBaseURLback to summary
public void setBaseURL(String url)

Sets the baseURL attribute of the RenderingContext object

Parameters
url:String

The new baseURL value

setCanvasback to summary
public void setCanvas(FSCanvas canvas)
setCharacterBreakerback to summary
public void setCharacterBreaker(FSTextBreaker breaker)
setCssback to summary
public void setCss(StyleReference css)
setDebug_draw_boxesback to summary
public void setDebug_draw_boxes(boolean debug_draw_boxes)
setDebug_draw_font_metricsback to summary
public void setDebug_draw_font_metrics(boolean debug_draw_font_metrics)
setDebug_draw_inline_boxesback to summary
public void setDebug_draw_inline_boxes(boolean debug_draw_inline_boxes)
setDebug_draw_line_boxesback to summary
public void setDebug_draw_line_boxes(boolean debug_draw_line_boxes)
setDefaultPageSizeback to summary
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.

setDotsPerPixelback to summary
public void setDotsPerPixel(int dotsPerPixel)

Set the internal dots measurement per CSS pixel.

setDPIback to summary
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:float

The new dPI value

setFontMappingback to summary
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:String

The new font name

font:Font

The actual Font to map

Annotations
@Deprecated
setFontResolverback to summary
public void setFontResolver(FontResolver resolver)
setInteractiveback to summary
public void setInteractive(boolean interactive)
setLineBreakerback to summary
public void setLineBreaker(FSTextBreaker breaker)
setMediaback to summary
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:String

The new media value

setNamespaceHandlerback to summary
public void setNamespaceHandler(NamespaceHandler nh)
setPrintback to summary
public void setPrint(boolean print)
setReplacedElementFactoryback to summary
public void setReplacedElementFactory(ReplacedElementFactory ref)
setReplacementTextback to summary
public void setReplacementText(String replacement)
setTempCanvasback to summary
public void setTempCanvas(Rectangle rect)
setTextRendererback to summary
public void setTextRenderer(TextRenderer textRenderer)

Sets the textRenderer attribute of the RenderingContext object

Parameters
textRenderer:TextRenderer

The new textRenderer value

setUnicodeToLowerTransformerback to summary
public void setUnicodeToLowerTransformer(FSTextTransformer tr)
setUnicodeToTitleTransformerback to summary
public void setUnicodeToTitleTransformer(FSTextTransformer tr)
setUnicodeToUpperTransformerback to summary
public void setUnicodeToUpperTransformer(FSTextTransformer tr)
setUserAgentCallbackback to summary
public void setUserAgentCallback(UserAgentCallback userAgentCallback)