-
Notifications
You must be signed in to change notification settings - Fork 106
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).
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