-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Realign foreignObject to its rightful position #2488
base: master
Are you sure you want to change the base?
Conversation
Very exciting work! @brucemiller please help :> |
47c0673
to
bfb3aeb
Compare
df24b87
to
b6fcdc4
Compare
$node->setAttribute(style => "line-height:${h}px"); | ||
$node->setAttribute(width => $w->pxValue) unless $node->hasAttribute('width'); | ||
$node->setAttribute(height => $ht) unless $node->hasAttribute('height'); | ||
$node->setAttribute(transform => "matrix(1 0 0 -1 0 $h)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This took a few tries. Shifting by height only mimics better the behaviour of the depth, but it's not enough on its own. The additional line-height
ensures that boxes with same horizontal coordinate and font size get the same baseline (this is noticeable when an arrow has multiple labels in tikzcd).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite possibly (or even probably) recording @rowdepths
is a good thing, but it would be useful to have in its own PR, without the flex & div wrappers (I'd like to explore alternatives for that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: line-height
is just a mirage. I got good results using text-box
which is very new CSS, not yet supported by Firefox. It might resolve that 'maths too high' issue you were mentioning.
I couldn't find any other way of aligning the blocks by baseline, unfortunately. I suggest we use text-box
as the reference starting point and once it looks convincing, work on a fallback for older browsers.
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:element> | ||
</xsl:element> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This obscures the previous branch of foreignObject
(from non svg namespace), with the side effect of also wrapping those cases with a pair of div
s. The new code should have been its own branch below, before the otherwise
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hindsight, I actually don't understand the test not(namespace-uri(child::*) = $SVG_NAMESPACE)
. This is checking whether the first child is not in SVG namespace. I think that maybe you want to check whether any child is not SVG and if there are non-trivial text nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that xpath test tries to say "not any", but ends up saying "not first".
Probably should be closer to:
count(child::*[namespace-uri(self) = $SVG_NAMESPACE]) = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And text nodes. Maybe latexml never produces text there, but in principle foreignObject can contain character data.
b6fcdc4
to
318ba9f
Compare
This is how it looks in Chrome as of 318ba9f. |
I should summarize what 318ba9f is doing:
I am inclined to say that this is the correct approach. The rules are sound and predictable, and the output looks good in the early tests. PS: text-box can make titled frames much more similar to the LaTeX ones. |
@xworld21 I assume you are aware of the limited availability of CSS text-box today? I wonder if we're risking breaking too much on Firefox if we use it for v0.8.9. |
Yes, that is a major problem. I have a reasonable mitigation in mind though. I think my general idea here is that text-box is correct, so we might as well start with text-box as our baseline (no pun intended). I will add some extra CSS gated behind I wouldn't say it breaks Firefox, it's more that it breaks it differently compared to now. |
This is the kind of comment I like to make. I like your plan. |
Most of your latest examples, above, look pretty good, but I'm not getting as good results from your branch on the collection of tikz tests; Maybe I've screwed something up in comparison? |
The big difficulty I'm having is figuring out where xy, respectively pgf, "think they are" when they drop a Of course, both systems rely completely on TeX's measurements to place things, put boxes around them, etc. But then the browsers use different fonts, and multiline text comes out particularly mismatched (eg the I was surprised to see how LaTeXML's too-crude sizing of sub/superscripts threw |
8401556
to
017bbf7
Compare
I have implemented a hasty fallback for browsers not implementing text-box. It's not enough! Comments on the fallback:
Talking of the foundations behind this PR, I should restate the principle, for clarity. TeX creates a box with a certain height, width, baseline; CSS creates a block with similar measures. What I am trying hard to do is to make the centre point of the baseline to be the same in TeX and in CSS. This is easy with text-box and flex; it kind of works with line-height for Blink/WebKit. Without those adjustments, the two boxes are attached at the northeast corner instead (and actually LaTeXML fudges that with an extra |
PS: also, my additional |
But also, help! This started as an easy fix, and ended up touching alignment code. I think it is correct, but I'd rather have some comments now, before spending more time on it. I really hope I am right, because it improves the TikZ output in a small but quite substantial way.
The aim is to align foreign objects properly inside SVGs.
Flip
svg:foreignObject
around its center, instead of the center of an imaginary line of height 16.6px (the hardcoded global value of\baselineskip
). Compare with equivalent code inPost::SVG::convertNode
. I have concluded that\baselineskip
was just a mistake.Add a CSS flex wrapper to
svg:foreignObject
, so that the foreignObject box and its content share the same center, instead of the content being anchored north east, which looks bad in most situations.(1) and (2) make normal TikZ figures (with no halign) perfect, modulo font metric errors. For instance,


becomes
Small difference, but the equal sign is where it should be. I have played with other figures and they all look better this way.
Example: before



after
which is much closer to the PDF