Package com.openhtmltopdf.layout
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 Summary
Fields Modifier and Type Field Description String_preferredDocumentBuilderFactoryImplementationClassString_preferredTransformerFactoryImplementationClassprotected FSCanvascanvasprotected StyleReferencecssprotected booleandebug_draw_boxesprotected booleandebug_draw_font_metricsprotected booleandebug_draw_inline_boxesprotected booleandebug_draw_line_boxesprotected FontResolverfontResolver -
Constructor Summary
Constructors Constructor Description SharedContext()SharedContext(UserAgentCallback uac, FontResolver fr, ReplacedElementFactory ref, TextRenderer tr, float dpi)Deprecated.This stuff should go in the renderers of a specific device. -
Method Summary
Modifier and Type Method Description voidaddBoxId(String id, Box box)booleandebugDrawBoxes()booleandebugDrawFontMetrics()booleandebugDrawInlineBoxes()booleandebugDrawLineBoxes()StringgetBaseURL()Gets the baseURL attribute of the RenderingContext objectBoxgetBoxById(String id)FSCanvasgetCanvas()FSTextBreakergetCharacterBreaker()StyleReferencegetCss()FloatgetDefaultPageHeight()Stores a default page height.FloatgetDefaultPageWidth()Stores a default page width.intgetDotsPerPixel()Get the internal dots measurement per CSS pixel.floatgetDPI()Gets the dPI attribute of the RenderingContext objectRectanglegetFixedRectangle()FSFontgetFont(FontSpecification spec)FontResolvergetFontResolver()Gets the fontResolver attribute of the Context objectMap<String,Box>getIdMap()FSTextBreakergetLineBreaker()StringgetMedia()The media for this contextfloatgetMmPerDotParent()Gets the dPI attribute in a more useful form of the RenderingContext objectNamespaceHandlergetNamespaceHandler()ReplacedElementFactorygetReplacedElementFactory()StringgetReplacementText()The replacement text to be used if a character cannot be renderered by the current or fallback fonts.CalculatedStylegetStyle(Element e)CalculatedStylegetStyle(Element e, boolean restyle)TextRenderergetTextRenderer()UserAgentCallbackgetUac()Deprecated.Use getUserAgentCallback instead for clearer code.FSTextTransformergetUnicodeToLowerTransformer()FSTextTransformergetUnicodeToTitleTransformer()FSTextTransformergetUnicodeToUpperTransformer()UserAgentCallbackgetUserAgentCallback()floatgetXHeight(FontContext fontContext, FontSpecification fs)booleanisDefaultPageSizeInches()If not, consider it as mm.booleanisInteractive()booleanisPaged()Returns true if the currently set media type is paged.booleanisPrint()LayoutContextnewLayoutContextInstance()RenderingContextnewRenderingContextInstance()voidregisterWithThread()This registers the shared context with a thread local so it can be used anywhere.voidremoveBoxId(String id)voidremoveFromThread()This removes the shared context from a thread local to avoid memory leaks.voidsetBaseURL(String url)Sets the baseURL attribute of the RenderingContext objectvoidsetCanvas(FSCanvas canvas)voidsetCharacterBreaker(FSTextBreaker breaker)voidsetCss(StyleReference css)voidsetDebug_draw_boxes(boolean debug_draw_boxes)voidsetDebug_draw_font_metrics(boolean debug_draw_font_metrics)voidsetDebug_draw_inline_boxes(boolean debug_draw_inline_boxes)voidsetDebug_draw_line_boxes(boolean debug_draw_line_boxes)voidsetDefaultPageSize(Float pageWidth, Float pageHeight, boolean isInches)Set the default page dimensions.voidsetDotsPerPixel(int dotsPerPixel)Set the internal dots measurement per CSS pixel.voidsetDPI(float dpi)Sets the effective DPI (Dots Per Inch) of the screen.voidsetFontMapping(String name, Font font)Deprecated.Definitely shouldn't use this method as it only applies for Java2D font resolver.voidsetFontResolver(FontResolver resolver)voidsetInteractive(boolean interactive)voidsetLineBreaker(FSTextBreaker breaker)voidsetMedia(String media)Set the current media type.voidsetNamespaceHandler(NamespaceHandler nh)voidsetPrint(boolean print)voidsetReplacedElementFactory(ReplacedElementFactory ref)voidsetReplacementText(String replacement)voidsetTempCanvas(Rectangle rect)voidsetTextRenderer(TextRenderer textRenderer)Sets the textRenderer attribute of the RenderingContext objectvoidsetUnicodeToLowerTransformer(FSTextTransformer tr)voidsetUnicodeToTitleTransformer(FSTextTransformer tr)voidsetUnicodeToUpperTransformer(FSTextTransformer tr)voidsetUserAgentCallback(UserAgentCallback userAgentCallback)
-
Field Details
-
fontResolver
-
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
-
_preferredTransformerFactoryImplementationClass
-
_preferredDocumentBuilderFactoryImplementationClass
-
-
Constructor Details
-
SharedContext
public SharedContext() -
SharedContext
@Deprecated public SharedContext(UserAgentCallback uac, FontResolver fr, ReplacedElementFactory ref, TextRenderer tr, float dpi)Deprecated.This stuff should go in the renderers of a specific device.Constructor for the Context object
-
-
Method Details
-
newLayoutContextInstance
-
newRenderingContextInstance
-
getFontResolver
Gets the fontResolver attribute of the Context object- Returns:
- The fontResolver value
-
getMedia
The media for this context -
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
-
setCss
-
getCanvas
-
setCanvas
-
setTempCanvas
-
getFixedRectangle
-
setNamespaceHandler
-
getNamespaceHandler
-
addBoxId
-
getBoxById
-
removeBoxId
-
getIdMap
-
setTextRenderer
Sets the textRenderer attribute of the RenderingContext object- Parameters:
textRenderer- The new textRenderer value
-
setMedia
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.Use getUserAgentCallback instead for clearer code.Gets the uac attribute of the RenderingContext object- Returns:
- The uac value (user agent).
-
getUserAgentCallback
-
setUserAgentCallback
-
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 byToolkit.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
-
getXHeight
-
getBaseURL
Gets the baseURL attribute of the RenderingContext object- Returns:
- The baseURL value
-
setBaseURL
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.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 pagep { font-family: CoolFont Arial sans-serif; }You can also override existing font mappings, like replacing Arial with Helvetica.- Parameters:
name- The new font namefont- The actual Font to map
-
setFontResolver
-
getDotsPerPixel
public int getDotsPerPixel()Get the internal dots measurement per CSS pixel.- Returns:
-
setDotsPerPixel
public void setDotsPerPixel(int dotsPerPixel)Set the internal dots measurement per CSS pixel.- Parameters:
dotsPerPixel-
-
getStyle
-
getStyle
-
getReplacedElementFactory
-
setReplacedElementFactory
-
getDefaultPageWidth
Stores a default page width.- Returns:
- default page width or null.
- See Also:
isDefaultPageSizeInches()
-
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
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
-
setDefaultPageSize
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
-
setLineBreaker
-
getCharacterBreaker
-
setCharacterBreaker
-
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 toremoveFromThread()when the run is complete. -
removeFromThread
public void removeFromThread()This removes the shared context from a thread local to avoid memory leaks. -
getUnicodeToLowerTransformer
-
getUnicodeToUpperTransformer
-
getUnicodeToTitleTransformer
-
setUnicodeToLowerTransformer
-
setUnicodeToUpperTransformer
-
setUnicodeToTitleTransformer
-