UserAgentCallback uac
src/java/org/xhtmlrenderer/layout/SharedContext.java
setMedia("screen");
        this.uac = uac;
        setCss(new StyleReference(uac));
        XRLog.render("Using CSS implementation from: " + getCss().getClass().getName());
        setTextRenderer(new Java2DTextRenderer());
        try {
            setDPI(Toolkit.getDefaultToolkit().getScreenResolution());
public SharedContext(UserAgentCallback uac)
Rectangle extents
src/java/org/xhtmlrenderer/layout/SharedContext.java
LayoutContext c = new LayoutContext(this, extents);
        c.initializeStyles(new EmptyStyle());
        return c;
LayoutContext newLayoutContextInstance(Rectangle extents)
Rectangle extents
src/java/org/xhtmlrenderer/layout/SharedContext.java
RenderingContext c = new RenderingContext(this, extents);
        return media;
        return text_renderer;

            //Uu.p("upping max height to : " + max_height);

    private Map id_map;

    public void addIDBox(String id, Box box) {
        if (id_map == null) {
            id_map = new HashMap();
RenderingContext newRenderingContextInstance(Rectangle extents)
String id
src/java/org/xhtmlrenderer/layout/SharedContext.java
if (id_map == null) {
            id_map = new HashMap();
Box getIDBox(String id)
TextRenderer text_renderer
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.text_renderer = text_renderer;
void setTextRenderer(TextRenderer text_renderer)
String media
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.media = media;
void setMedia(String media)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return uac;
UserAgentCallback getUac()
src/java/org/xhtmlrenderer/layout/SharedContext.java
return this.dpi;
float getDPI()
float dpi
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.dpi = dpi;
        this.mm_per_px = (CM__PER__IN * MM__PER__CM) / dpi;
void setDPI(float dpi)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return this.mm_per_px;
float getMmPerPx()
FontSpecification parent  FontSpecification desired  float xHeight  Graphics2D g2
src/java/org/xhtmlrenderer/layout/SharedContext.java
float bestGuess = getFontSize2D(parent);
        float bestHeight = getXHeight(parent, g2);
        float nextGuess = bestGuess * xHeight / bestHeight;
        while (true) {
            desired.size = nextGuess;
            float nextHeight = getXHeight(desired, g2);
            //this check is needed in cases where the iteration can hop back and forth between two values
            if (Math.abs(nextHeight - xHeight) < Math.abs(bestHeight - xHeight)) {
                bestGuess = nextGuess;
                bestHeight = nextHeight;
                nextGuess = bestGuess * xHeight / nextHeight;
float getFontSizeForXHeight(FontSpecification parent, FontSpecification desired, float xHeight, Graphics2D g2)
FontSpecification fs  Graphics2D g2
src/java/org/xhtmlrenderer/layout/SharedContext.java
Font f = getFontResolver().resolveFont(this, fs.families, fs.size, fs.fontWeight, fs.fontStyle, fs.variant);
        float sto = getTextRenderer().getLineMetrics(g2, f, " ").getStrikethroughOffset();
        return 2 * Math.abs(sto);
float getXHeight(FontSpecification fs, Graphics2D g2)
FontSpecification font
src/java/org/xhtmlrenderer/layout/SharedContext.java
return getFontResolver().resolveFont(this, font).getSize2D();
float getFontSize2D(FontSpecification font)
FontSpecification font
src/java/org/xhtmlrenderer/layout/SharedContext.java
return getFontResolver().resolveFont(this, font);
Font getFont(FontSpecification font)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return uac.getBaseURL();
String getBaseURL()
String url
src/java/org/xhtmlrenderer/layout/SharedContext.java
uac.setBaseURL(url);
void setBaseURL(String url)
src/java/org/xhtmlrenderer/layout/SharedContext.java
if (media.equals("print")) {
            return true;
boolean isPaged()
src/java/org/xhtmlrenderer/layout/SharedContext.java
return interactive;
boolean isInteractive()
boolean interactive
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.interactive = interactive;
void setInteractive(boolean interactive)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return print;
boolean isPrint()
boolean print
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.print = print;
void setPrint(boolean print)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return pageSize;
PageInfo getPageInfo()
String name  Font font
src/java/org/xhtmlrenderer/layout/SharedContext.java
getFontResolver().setFontMapping(name, font);
void setFontMapping(String name, Font font)
RenderingContext c  CalculatedStyle activeStyle  boolean rendering
src/java/org/xhtmlrenderer/layout/block/Relative.java
topLeft = extractLeftTopRelative(c, c.getBlockFormattingContext(), activeStyle);
    public static void translateRelative(LayoutContext c, CalculatedStyle activeStyle, boolean rendering) {
        topLeft = extractLeftTopRelative(c, c.getBlockFormattingContext(), activeStyle);
        if (topLeft != null) {
            top = topLeft[0];
            left = topLeft[1];
            c.translate(left, top);
            if (rendering) {
                c.getGraphics().translate(left, top);
void translateRelative(RenderingContext c, CalculatedStyle activeStyle, boolean rendering)
RenderingContext c  CalculatedStyle activeStyle  boolean rendering
src/java/org/xhtmlrenderer/layout/block/Relative.java
int top = 0;
        int left = 0;
        int topLeft[] = null;
        topLeft = extractLeftTopRelative(c, c.getBlockFormattingContext(), activeStyle);
        if (topLeft != null) {
            top = topLeft[0];
            left = topLeft[1];
            c.translate(-left, -top);
            if (rendering) {
                c.getGraphics().translate(-left, -top);
void untranslateRelative(RenderingContext c, CalculatedStyle activeStyle, boolean rendering)
Box box
src/java/org/xhtmlrenderer/swing/HoverListener.java
if (box == null) {
            return null;
Box getDeepestHover(Box box)
src/java/org/xhtmlrenderer/swing/RootPanel.java
return sharedContext;
    protected SharedContext sharedContext;
    //TODO: layout_context should not be stored!
    protected volatile LayoutContext layout_context;
        getSharedContext().setBaseURL(url);
        getSharedContext().setNamespaceHandler(nsh);
        getSharedContext().setMedia(pageInfo == null ? "screen" : "print");
        getSharedContext().getCss().setDocumentContext(getSharedContext(), getSharedContext().getNamespaceHandler(), doc, this);



    protected RenderingContext newRenderingContext(PageInfo pageInfo, Graphics2D g) {
        getSharedContext().setCanvas(this);
        getSharedContext().setMaxWidth(0);
        //getSharedContext().setMaxHeight(0);
        RenderingContext result = getSharedContext().newRenderingContextInstance(extents);
        result.setGraphics(g);
        result.setPrint(pageInfo != null);
        result.setInteractive(pageInfo == null);

        return result;
SharedContext getSharedContext()
PageInfo pageInfo  Graphics2D g
src/java/org/xhtmlrenderer/swing/RootPanel.java
XRLog.layout(Level.FINEST, "new context begin");

        getSharedContext().setCanvas(this);

        Rectangle extents;

        if (pageInfo != null) {
            extents = new Rectangle(0, 0,
                    (int) pageInfo.getContentWidth(), (int) pageInfo.getContentHeight());
LayoutContext newLayoutContext(PageInfo pageInfo, Graphics2D g)
enclosingScrollPane != null
src/java/org/xhtmlrenderer/swing/RootPanel.java
Rectangle bnds = enclosingScrollPane.getViewportBorderBounds();
            extents = new Rectangle(0, 0, bnds.width, bnds.height);
            //Uu.p("bnds = " + bnds);
else if (enclosingScrollPane != null)
RenderingContext ctx  String[] families  float size  IdentValue weight  IdentValue style  IdentValue variant
src/java/org/xhtmlrenderer/context/FontResolver.java
try {
            Font fnt = createFont(ctx, (Font) available_fonts_hash.get(family), size, weight, style, variant);
            instance_hash.put(getFontInstanceHashName(family, size, weight, style, variant), fnt);
            //Uu.p("subbing in base sans : " + fnt);
            return fnt;
Font resolveFont(RenderingContext ctx, String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
src/java/org/xhtmlrenderer/layout/SharedContext.java
public Context newContextInstance(Rectangle extents) {
        Context c = new ContextImpl(this, extents);
    /**
     * Description of the Field
     */
    protected Graphics2D graphics;

    /**
     * Gets the graphics attribute of the Context object
     *
     * @return The graphics value
     */
    public Graphics2D getGraphics() {
        return graphics;
public SharedContext()
Graphics2D graphics
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.graphics = graphics;
void setGraphics(Graphics2D graphics)
src/java/org/xhtmlrenderer/layout/SharedContext.java
return getCtx();
RenderingContext getRenderingContext()
src/java/org/xhtmlrenderer/layout/SharedContext.java
return ctx;
RenderingContext getCtx()
RenderingContext ctx
src/java/org/xhtmlrenderer/layout/SharedContext.java
this.ctx = ctx;
void setCtx(RenderingContext ctx)
String id  Box box
src/java/org/xhtmlrenderer/layout/SharedContext.java
if(id_map == null) {
			id_map = new HashMap();
void addIDBox(String id, Box box)
String id
src/java/org/xhtmlrenderer/layout/SharedContext.java
if(id_map == null) {
			id_map = new HashMap();
Box getIDBox(String id)
Context c
src/java/org/xhtmlrenderer/render/Box.java
double absTop = getAbsY(c);
    protected double getAbsY(Context c) {
        return c.getOriginOffset().y;
boolean crossesPageBreak(Context c)
Context c  InlineBox ib
src/java/org/xhtmlrenderer/render/LineBox.java
public void moveToNextPage(Context c, Rectangle bounds) {
    protected double getAbsY(Context c) {
        return c.getOriginOffset().y + y;
void addInlineChild(Context c, InlineBox ib)
Context c  Box root
src/java/org/xhtmlrenderer/swing/BasicPanel.java
return getPageCount(layout_context);
    private int getPageCount(Context c) {
    private void renderPagedView(Context c, Box box) {
        int pageCount = getPageCount(c);
        setPreferredSize(new Dimension(c.getMaxWidth(),
    public void setRenderingContext(RenderingContext ctx) {
        this.ctx = ctx;
        String url = getRenderingContext().getUac().resolveURI(filename);
            Box bxx = getContext().getIDBox(id);
        getRenderingContext().getStyleReference().flushStyleSheets();
        setDocument(this.doc, getRenderingContext().getBaseURL(), getContext().getNamespaceHandler());
            base = new URL(getRenderingContext().getUac().getBaseURL());
        return getContext().getNamespaceHandler().getDocumentTitle(doc);
        return ctx.getUac().getXMLResource(uri).getDocument();
    /**
     * Gets the renderingContext attribute of the BasicPanel object
     *
     * @return The renderingContext value
     */
    public RenderingContext getRenderingContext() {
        return ctx;
void executeRenderThread(Context c, Box root)
Box box
src/java/org/xhtmlrenderer/swing/HoverListener.java
if(box == null) {
			return null;
Box getDeepestHover(Box box)
src/java/org/xhtmlrenderer/swing/RootPanel.java
return getRenderingContext().getContext();
    protected RenderingContext ctx;
    /**
     * Gets the renderingContext attribute of the BasicPanel object
     *
     * @return The renderingContext value
     */
    public RenderingContext getRenderingContext() {
        return ctx;
SharedContext getContext()