# Cinder-SdfText Measure Inconsistencies with Trailing Spaces

**URL:** <https://discourse.libcinder.org/t/cinder-sdftext-measure-inconsistencies-with-trailing-spaces/1260>\
**Category:** CinderBlocks\
**Created:** [August 17, 2018, 4:15pm UTC](https://discourse.libcinder.org/t/cinder-sdftext-measure-inconsistencies-with-trailing-spaces/1260 "2018-08-17T16:15:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjaminbojko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/benjaminbojko/32/591_2.png) [@benjaminbojko](https://discourse.libcinder.org/u/benjaminbojko)\
**Post date:** [August 17, 2018, 4:15pm UTC](https://discourse.libcinder.org/t/cinder-sdftext-measure-inconsistencies-with-trailing-spaces/1260/1 "2018-08-17T16:15:25Z")

</div>

Hi All,

I’m working on inline styling with the [Cinder-SdfText](https://github.com/paulhoux/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:

```auto
|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 `a`s, 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

---

<div class="post-metadata">

**Author:** ![seph](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@seph](https://discourse.libcinder.org/u/seph)\
**Post date:** [August 17, 2018, 5:13pm UTC](https://discourse.libcinder.org/t/cinder-sdftext-measure-inconsistencies-with-trailing-spaces/1260/2 "2018-08-17T17:13:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benjaminbojko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/benjaminbojko/32/591_2.png) [@benjaminbojko](https://discourse.libcinder.org/u/benjaminbojko)\
**Post date:** [August 17, 2018, 5:37pm UTC](https://discourse.libcinder.org/t/cinder-sdftext-measure-inconsistencies-with-trailing-spaces/1260/3 "2018-08-17T17:37:40Z")

</div>

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:

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

```
