Package org.xhtmlrenderer.layout
Class SharedContext
java.lang.Object
org.xhtmlrenderer.layout.SharedContext
The SharedContext is that which is kept between successive layout and render runs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @Nullable FSCanvas
private static final float
private StyleReference
private boolean
private boolean
private boolean
private boolean
private static final float
private int
private float
private FontResolver
private boolean
private LineBreakingStrategy
private String
private static final int
private float
dpi in a more usable wayprivate @Nullable NamespaceHandler
private boolean
private ReplacedElementFactory
private @Nullable Map<Element,
CalculatedStyle> private @Nullable Rectangle
private TextRenderer
private UserAgentCallback
-
Constructor Summary
ConstructorsConstructorDescriptionSharedContext
(UserAgentCallback uac, float dpi, int pixelsPerDot) SharedContext
(UserAgentCallback uac, FontResolver fr, ReplacedElementFactory ref, TextRenderer tr, float dpi) SharedContext
(UserAgentCallback userAgent, FontResolver fontResolver, ReplacedElementFactory replacedElementFactory, TextRenderer textRenderer, float dpi, int dotsPerPixel) -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
boolean
boolean
void
Gets the baseURL attribute of the RenderingContext object@Nullable Box
getBoxById
(String id) @Nullable FSCanvas
getCss()
int
float
getDPI()
Gets the dPI attribute of the RenderingContext object@Nullable Rectangle
@Nullable FSFont
getFont
(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 object@Nullable NamespaceHandler
getUac()
Gets the uac attribute of the RenderingContext objectfloat
getXHeight
(FontContext fontContext, FontSpecification fs) boolean
boolean
isPaged()
Returns true if the currently set media type is paged.boolean
isPrint()
newLayoutContextInstance
(FontContext fontContext) newRenderingContextInstance
(OutputDevice outputDevice, FontContext fontContext) newRenderingContextInstance
(OutputDevice outputDevice, FontContext fontContext, @Nullable Layer rootLayer, int initialPageNo) void
removeBoxId
(String id) void
reset()
void
setBaseURL
(@Nullable String url) Sets the baseURL attribute of the RenderingContext objectvoid
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
setDotsPerPixel
(int pixelsPerDot) void
setDPI
(float dpi) Sets the effective DPI (Dots Per Inch) of the screen.void
setFontMapping
(String name, Font font) Adds or overrides a font mapping, meaning you can associate a particular font with a particular string.void
setFontResolver
(FontResolver resolver) Deprecated.pass textRenderer to a constructor instead of using settervoid
void
setInteractive
(boolean interactive) void
setLineBreakingStrategy
(LineBreakingStrategy lineBreakingStrategy) void
Set the current media type.void
void
setPrint
(boolean print) void
void
setTemporaryCanvas
(Rectangle rect) void
setTextRenderer
(TextRenderer textRenderer) Deprecated.pass textRenderer to a constructor instead of using settervoid
setUserAgentCallback
(UserAgentCallback userAgentCallback)
-
Field Details
-
PAGED_MEDIA_TYPES
-
textRenderer
-
media
-
uac
-
interactive
private boolean interactive -
idMap
-
dpi
private float dpi -
MM__PER__CM
private static final int MM__PER__CM- See Also:
-
CM__PER__IN
private static final float CM__PER__IN- See Also:
-
mm_per_dot
private float mm_per_dotdpi in a more usable way -
DEFAULT_DPI
private static final float DEFAULT_DPI- See Also:
-
print
private boolean print -
dotsPerPixel
private int dotsPerPixel -
styleMap
-
replacedElementFactory
-
temporaryCanvas
-
lineBreakingStrategy
-
fontResolver
-
css
-
debug_draw_boxes
private boolean debug_draw_boxes -
debug_draw_line_boxes
private boolean debug_draw_line_boxes -
debug_draw_inline_boxes
private boolean debug_draw_inline_boxes -
debug_draw_font_metrics
private boolean debug_draw_font_metrics -
canvas
-
namespaceHandler
-
-
Constructor Details
-
SharedContext
public SharedContext() -
SharedContext
public SharedContext(UserAgentCallback userAgent, FontResolver fontResolver, ReplacedElementFactory replacedElementFactory, TextRenderer textRenderer, float dpi, int dotsPerPixel) -
SharedContext
-
SharedContext
-
SharedContext
public SharedContext(UserAgentCallback uac, FontResolver fr, ReplacedElementFactory ref, TextRenderer tr, float dpi)
-
-
Method Details
-
setFormSubmissionListener
-
newLayoutContextInstance
-
newRenderingContextInstance
public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext) -
newRenderingContextInstance
public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext, @Nullable Layer rootLayer, int initialPageNo) -
getFontResolver
Gets the fontResolver attribute of the Context object- Returns:
- The fontResolver value
-
flushFonts
public void flushFonts() -
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
-
setTemporaryCanvas
-
getFixedRectangle
-
setNamespaceHandler
-
getNamespaceHandler
-
addBoxId
-
getBoxById
-
removeBoxId
-
getIdMap
-
setTextRenderer
Deprecated.pass textRenderer to a constructor instead of using setterSets 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
Gets the uac attribute of the RenderingContext object- Returns:
- The uac value
-
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 the fonts for accessibility or printing purposes. Currently, the DPI setting only affects font sizing.- Parameters:
dpi
- The new dPI value
-
getMmPerPx
public float getMmPerPx()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
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 namefont
- The actual Font to map
-
setFontResolver
Deprecated.pass textRenderer to a constructor instead of using setter -
getDotsPerPixel
public int getDotsPerPixel() -
setDotsPerPixel
public void setDotsPerPixel(int pixelsPerDot) -
getStyle
-
getStyle
-
reset
public void reset() -
getReplacedElementFactory
-
setReplacedElementFactory
-
getLineBreakingStrategy
-
setLineBreakingStrategy
-