Cinder-SdfText Measure Inconsistencies with Trailing Spaces


#1

Hi All,

I’m working on inline styling with the Cinder-SdfText block (Paul’s fork) and am running into issues where measureStringImpl() returns inconsistent results for trailing spaces. It seems that whenever there is a trailing space, it gets clipped, but not entirely trimmed since it still adds a few pixels.

I tried isolating the issue and it appears that results coming from measureGlyphs() are consistent, and that measureStringImpl() is the place where the last space measurements are changed.

I’m not a typography expert and am not 100% sure what the different measurement stages are for, but tried isolating things in a simple test case. I logged out the width of the measured Rectf as characters were added to the same SdfText instance:

|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a": 14.835000
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a ": 16.334991
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a  ": 23.054993
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a   ": 29.774994
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a    ": 36.494995
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a    a": 56.174995

So measurements are basically:

  • Single a: 14.835
  • Trailing space: 1.499991
  • Non-trailing space: 6.720001
  • Trailing a: 19.68

The trailing a wider than the single a, but the difference doesn’t add up to the same difference as between trailing and non-trailing spaces (4.845 difference between the as, but 5.22001 between the spaces).

Can anybody here shed some light on what might be happening? Is this a kerning issue and I’m chasing a red herring or is there a way to force SdfText to consistently measure trailing spaces?

Thanks!
Ben


#2

spolier: I haven’t used the SDFText block, but I may be helpful on the typography part.

I’m wondering if your font is Monospace font? Or can you explicitly disable ligature in the block?

The fact that only the first space returns different value makes think thats just how it should be treated.

Also if you are not using a monospace font, normally every letter will have different width - there is no guarantee that ‘a’ has same width with space.

-seph


#3

Good questions. I tried this with two non-monospace fonts (OpenSans and Din) and am getting similar results for the last space. I think it’s just the last space actually, that gets clipped and not the first one, necessarily.

SdfText does allow you to disable ligatures, but it doesn’t seem to change the result with varying widths for spaces. When you mentioned it I also thought it might just be the combo of a + space, but since this happened for multiple fonts my hunch is that it’s something in the library itself and (hopefully) not font related.

The really suspicious thing to me is that the two a's result in different widths. BTW when I swap the last a and space, I get another width again:

|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a    a": 56.174995
|debug  | cinder::gl::SdfText::measureStringImpl[2427] "a   a ": 50.954987