[webkit-dev] Rendering Help with MathML for mfenced

Alex Milowski alex at milowski.com
Tue Aug 25 21:42:20 PDT 2009


I'm working on a MathML implementation for WebKit and I've had some success but
I'm a bit stuck with the approach I'm using for mfenced.  This element wraps a
sequence of expressions in brackets (or some other paired symbol).  The brackets
need to scale to the maximum height of the contained objects.

I decided that the best approach was to let the container layout the
contents and
then inspect the box heights.  This approach has worked well when you render
MathML via Javascript.

The problem I'm having is that I adjust the opening and closing fencing symbols
via the font size.  This causes their box size to change but the whole construct
(which is an inline-block container) doesn't get reflowed.  As such, the opening
fence (defaults to a '{' bracket) overflows onto the first item in the
fenced content.

What I want to do is tell the renderer that the contents all need to be reflowed
because the size of the first and last object has changed.  I haven't succeeded
in doing this yet although the resizing of the open and close fencing does
work quite well.

Any ideas as to what I need to do would help.

Here's the layout code for the rendered for the mfenced element:

void RenderFenced::layout() {
	if (isEmpty()) {
		makeFences();
	}
    RenderBlock::layout();
	RenderBoxModelObject *open = (RenderBoxModelObject *)firstChild();
	RenderBoxModelObject *close = (RenderBoxModelObject *)lastChild();
	int maxHeight = 0;
	RenderObject *current = open->nextSibling();
	while (current!=close) {
	    if (current->isBoxModelObject()) {
		    RenderBoxModelObject *box = (RenderBoxModelObject *)current;
			if (box->offsetHeight()>maxHeight) {
				maxHeight = box->offsetHeight();
			}
		}
		current = current->nextSibling();
	}
	if (maxHeight>0) {
		bool doLayoutAgain = false;
		if (open->offsetHeight()<maxHeight) {
			const FontDescription oldDesc = open->style()->font().fontDescription();
			FontDescription *desc = new FontDescription();
			desc->setIsAbsoluteSize(true);
			desc->setGenericFamily(oldDesc.genericFamily());
			desc->setWeight(oldDesc.weight());
			desc->setSmallCaps(oldDesc.smallCaps());
			desc->setItalic(oldDesc.italic());
			desc->setSpecifiedSize(maxHeight);
			desc->setComputedSize(maxHeight);
			open->style()->setFontDescription(*desc);
			open->style()->font().update(open->style()->font().fontSelector());
			open->setNeedsLayoutAndPrefWidthsRecalc();
			doLayoutAgain = true;
		}
		if (close->offsetHeight()<maxHeight) {
			const FontDescription oldDesc = close->style()->font().fontDescription();
			FontDescription *desc = new FontDescription();
			desc->setIsAbsoluteSize(true);
			desc->setGenericFamily(oldDesc.genericFamily());
			desc->setWeight(oldDesc.weight());
			desc->setSmallCaps(oldDesc.smallCaps());
			desc->setItalic(oldDesc.italic());
			desc->setSpecifiedSize(maxHeight);
			desc->setComputedSize(maxHeight);
			close->style()->setFontDescription(*desc);
			close->style()->font().update(open->style()->font().fontSelector());
			close->setNeedsLayoutAndPrefWidthsRecalc();
			doLayoutAgain = true;
		}
		if (doLayoutAgain) {
			setNeedsLayout(true);
			RenderObject *current = firstChild();
			while (current) {
				current->setNeedsLayoutAndPrefWidthsRecalc();
				current = current->nextSibling();
			}
			layout();
		}
	}
}


-- 
--Alex Milowski
"The excellence of grammar as a guide is proportional to the paucity of the
inflexions, i.e. to the degree of analysis effected by the language
considered."

Bertrand Russell in a footnote of Principles of Mathematics


More information about the webkit-dev mailing list