Package com.openhtmltopdf.layout
Class SharedContext
java.lang.Object
com.openhtmltopdf.layout.SharedContext
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
FieldsModifier and TypeFieldDescriptionprivate final RootCounterContextprivate FSTextTransformerprivate FSTextTransformerprivate FSTextTransformerprotected FSCanvasprivate FSTextBreakerprivate static final floatprotected StyleReferenceprotected booleanprotected booleanprotected booleanprotected booleanprivate static final intDeprecated.Belongs in Java2D renderer.private static final floatDeprecated.Belongs in Java2D renderer.private static final booleanDeprecated.Belongs in Java2D renderer.private Floatprivate booleanprivate Floatprivate intInternal program dots per pixel.private floatUsed to adjust fonts, ems, points, into screen resolution.protected FontResolverprivate booleanprivate FSTextBreakerprivate Stringprivate static final intprivate floatdpi in a more usable way Internal program dots per mm (probably a fraction).private NamespaceHandlerprivate booleanprivate ReplacedElementFactoryprivate Stringprivate final Map<Element, CalculatedStyle> private Rectangleprivate TextRendererprivate UserAgentCallback -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanbooleanbooleanGets the baseURL attribute of the RenderingContext objectgetBoxById(String id) getCss()Stores a default page height.Stores a default page width.intGet the internal dots measurement per CSS pixel.floatgetDPI()Gets the dPI attribute of the RenderingContext objectgetFont(FontSpecification spec) Gets the fontResolver attribute of the Context objectgetIdMap()getMedia()The media for this contextfloatGets the dPI attribute in a more useful form of the RenderingContext objectThe replacement text to be used if a character cannot be renderered by the current or fallback fonts.Gets the resolved style for an element.getUac()Deprecated.Use getUserAgentCallback instead for clearer code.floatgetXHeight(FontContext fontContext, FontSpecification fs) booleanIf not, consider it as mm.booleanbooleanisPaged()Returns true if the currently set media type is paged.booleanisPrint()voidThis registers the shared context with a thread local so it can be used anywhere.voidremoveBoxId(String id) voidThis removes the shared context from a thread local to avoid memory leaks.voidsetBaseURL(String url) Sets the baseURL attribute of the RenderingContext objectvoidvoidsetCharacterBreaker(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) voidSet the current media type.voidvoidsetPrint(boolean print) voidvoidsetReplacementText(String replacement) voidsetTempCanvas(Rectangle rect) voidsetTextRenderer(TextRenderer textRenderer) Sets the textRenderer attribute of the RenderingContext objectvoidvoidvoidvoidsetUserAgentCallback(UserAgentCallback userAgentCallback)
-
Field Details
-
DEFAULT_DPI
Deprecated.Belongs in Java2D renderer.- See Also:
-
DEFAULT_DOTS_PER_PIXEL
Deprecated.Belongs in Java2D renderer.- See Also:
-
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
-
media
-
uac
-
interactive
private boolean interactive -
idMap
-
dpi
private float dpiUsed to adjust fonts, ems, points, into screen resolution. Internal program dots per inch. -
dotsPerPixel
private int dotsPerPixelInternal program dots per pixel. -
mmPerDot
private float mmPerDotdpi in a more usable way Internal program dots per mm (probably a fraction). -
print
private boolean print -
styleMap
-
replacedElementFactory
-
tempCanvas
-
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
-
namespaceHandler
-
defaultPageHeight
-
defaultPageWidth
-
defaultPageSizeIsInches
private boolean defaultPageSizeIsInches -
replacementText
-
lineBreaker
-
characterBreaker
-
_unicodeToLowerTransformer
-
_unicodeToUpperTransformer
-
_unicodeToTitleTransformer
-
_preferredTransformerFactoryImplementationClass
-
_preferredDocumentBuilderFactoryImplementationClass
-
_rootCounterContext
-
-
Constructor Details
-
SharedContext
public SharedContext()
-
-
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. -
setDotsPerPixel
public void setDotsPerPixel(int dotsPerPixel) Set the internal dots measurement per CSS pixel.- Parameters:
dotsPerPixel-
-
getStyle
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
-
setReplacedElementFactory
-
getDefaultPageWidth
Stores a default page width.- Returns:
- default page width or null.
- See Also:
-
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
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
-
getGlobalCounterContext
-