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 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
Deprecated.Belongs in Java2D renderer.private static final float
Deprecated.Belongs in Java2D renderer.private static final boolean
Deprecated.Belongs in Java2D renderer.private Float
private boolean
private Float
private int
Internal program dots per pixel.private float
Used to adjust fonts, ems, points, into screen resolution.protected FontResolver
private boolean
private FSTextBreaker
private String
private static final int
private float
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
boolean
boolean
Gets the baseURL attribute of the RenderingContext objectgetBoxById
(String id) getCss()
Stores a default page height.Stores a default page width.int
Get the internal dots measurement per CSS pixel.float
getDPI()
Gets the dPI attribute of the RenderingContext objectgetFont
(FontSpecification spec) Gets the fontResolver attribute of the Context objectgetIdMap()
getMedia()
The media for this contextfloat
Gets 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.float
getXHeight
(FontContext fontContext, FontSpecification fs) boolean
If not, consider it as mm.boolean
boolean
isPaged()
Returns true if the currently set media type is paged.boolean
isPrint()
void
This registers the shared context with a thread local so it can be used anywhere.void
removeBoxId
(String id) void
This removes the shared context from a thread local to avoid memory leaks.void
setBaseURL
(String url) Sets the baseURL attribute of the RenderingContext objectvoid
void
setCharacterBreaker
(FSTextBreaker breaker) void
setCss
(StyleReference css) void
setDebug_draw_boxes
(boolean debug_draw_boxes) void
setDebug_draw_font_metrics
(boolean debug_draw_font_metrics) void
setDebug_draw_inline_boxes
(boolean debug_draw_inline_boxes) void
setDebug_draw_line_boxes
(boolean debug_draw_line_boxes) void
setDefaultPageSize
(Float pageWidth, Float pageHeight, boolean isInches) Set the default page dimensions.void
setDotsPerPixel
(int dotsPerPixel) Set the internal dots measurement per CSS pixel.void
setDPI
(float dpi) Sets the effective DPI (Dots Per Inch) of the screen.void
setFontMapping
(String name, Font font) Deprecated.Definitely shouldn't use this method as it only applies for Java2D font resolver.void
setFontResolver
(FontResolver resolver) void
setInteractive
(boolean interactive) void
setLineBreaker
(FSTextBreaker breaker) void
Set the current media type.void
void
setPrint
(boolean print) void
void
setReplacementText
(String replacement) void
setTempCanvas
(Rectangle rect) void
setTextRenderer
(TextRenderer textRenderer) Sets the textRenderer attribute of the RenderingContext objectvoid
void
void
void
setUserAgentCallback
(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
-