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

text alignment seems a bit off #2082

Closed
doutriaux1 opened this Issue Aug 9, 2016 · 13 comments

Comments

Projects
None yet
5 participants
@doutriaux1
Member

doutriaux1 commented Aug 9, 2016

One would expect the cross to be drawn exactly in the center of the middle H it is instead a bit off to the left and down

import vcs
x=vcs.init()
t = vcs.createtext()
t.x=[.8]
t.y=[.8]
t.string = "HHHHH"
t.valign = "half"
t.halign="center"
x.plot(t)
l=vcs.createline()
l.color=["red"]
l.x=[.1,.9]
l.y=[t.y,t.y]
x.plot(l)
l=vcs.createline()
l.color=["blue"]
l.y=[.1,.9]
l.x=[t.x,t.x]
x.plot(l)
x.png("blah")
raw_input("Blah")

blah

@doutriaux1 doutriaux1 added this to the 3.0 milestone Aug 9, 2016

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Aug 9, 2016

@dlonie what do you think. The screen, png and svg reflect tihs behaviour.

@allisonvacanti

This comment has been minimized.

Contributor

allisonvacanti commented Aug 10, 2016

VTK always includes the descenders (e.g. the 'tail' on letters like 'j', 'q', 'p', etc) when computing vertical alignment. This prevents the text from jumping around when the string changes during animations, etc. Fixing this would require adding some new options to vtkTextProperty that instruct the text renderer to compute a tight bounding box.

Not sure what's up with the horizontal alignment.

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Aug 10, 2016

thanks @dlonie but that is annoying for our end users, they want the text "halved" on the tick marks the appear a bit off as a result. Couldn't VTK only use the descender space only there is need to?
In the mean time is there a way to know the descender space, so I can compensate for this in VCS.

@allisonvacanti

This comment has been minimized.

Contributor

allisonvacanti commented Aug 10, 2016

Not currently.

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Aug 10, 2016

@dlonie @aashish24 @danlipsa we really need to have these additional VTKProperties:
TOP/CAP/HALF/BASELINE/BOTTOM

Form what @dlonie described it looks like right now "HALF" might be actually baseline?

Any idea of how long it would take to implement these in VTK?

@doutriaux1 doutriaux1 added the Critical label Aug 23, 2016

@aashish24 aashish24 assigned sankhesh and unassigned danlipsa Aug 25, 2016

@aashish24

This comment has been minimized.

Contributor

aashish24 commented Aug 25, 2016

@sankhesh with help from @dlonie will look into it.

@allisonvacanti

This comment has been minimized.

Contributor

allisonvacanti commented Aug 25, 2016

@doutriaux1 We don't want to always align to the drawn pixels as this causes issues when text changes over time (the strings jump around as descenders come and go). I think it'd be great to have as an option, though.

Talked with @sankhesh, here's what I suggest:

  • Add a UseTightBoundingBox property to vtkTextProperty that means something like "align to drawn pixels, not font metrics".
  • Update the alignment code in vtkFreeTypeTools and vtkMathTextUtilities to handle this option (also update any methods that return bounds information).

That will add support for vtkTextActor, vtkTextMapper, vtkTextActor3D, and some of the annotation classes.

Then VCS can set this property on it's text properties to get the desired alignment.

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Aug 25, 2016

@aashish24 I think all we need is the base/cap alignement, that should cover everything will not be jumping around.

Not sure if it helps or makes things more confused but here are a few links:
https://medium.com/written-in-code/aligning-type-to-baseline-the-right-way-using-sass-e258fce47a9b#.8pga6uz1x
http://christopheraue.net/2014/03/05/vertical-align/

@danlipsa

This comment has been minimized.

Contributor

danlipsa commented Aug 26, 2016

@doutriaux1 We already have the cap alignment: SetVerticalJustificationToTop(). I think we could add another justification to be baseline - this would work only for one line text.
What is the use case for this problem? I want to make sure we are solving the right problem: making this particular example look right might not help the actual use case.

@danlipsa

This comment has been minimized.

Contributor

danlipsa commented Aug 26, 2016

@doutriaux1 Adding a new justification baseline would not help this example, but might solve the use case.

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Aug 29, 2016

@danlipsa the issue is that that when the user selects centered for the vertical alignement, it was expecting the tick marks to be at the center of the text. There are actually 5 possible vertical alignements, I'm not sure which VTK implements: bottom, baseline, center, cap and top. I think we need them all.

@danlipsa

This comment has been minimized.

Contributor

danlipsa commented Aug 30, 2016

@doutriaux1 In VTK we have bottom, center and top. What is the difference between cap and top?
Indeed, center would not be centered on every letter - but rather centered on every possible text that can be in that string - as @dlonie said, this is for avoiding text movement for animation when the text changes. Maybe implementing baseline would be the easiest and will solve the problem. Doing the computation for the actual string will not look right (centered) if we have letters such as p or q that extend bellow the baseline.

@danlipsa

This comment has been minimized.

Contributor

danlipsa commented Apr 7, 2017

This was solved/improved with VTK fixes contained in the current VTK used by vcs: 73fb094d17ccdd594a6abf9ff8732149c88dc2e6. Note the corresponding vcs bug was already closed.

@danlipsa danlipsa closed this Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment