No getTextTracking in C SDK?

Hi, I'm working in the C SDK, trying to do some text layout and use the graphics->getTextWidth() function. The last argument to the function is an int, "tracking". After searching through the docs, I see a setTextTracking() function in C, but the getTextTracking() seems to only be exposed via lua. Is that a bug? Is there a default value I can assume?

Docs for getTextWidth:

Docs for setTextTracking:

Thanks!

I got interested, and generally never need much of an excuse to go poking into code, so took a look... all this should be taken with a very large grain of salt :wink: .

but the getTextTracking() seems to only be exposed via lua.

That seems to be the case (../PlaydateSDK/C_API/pd_api/pd_api_gfx.h):

However:

From the various docs, it looks like there are two sorts of 'tracking' values - the first is a global value not related to any specific font (from what I can tell the default value is 0.0), which gets added to an (optional) font-specific tracking value (can be specified in the font file itself, or can be set on a per-font basis in Lua via font:setFontTracking()).

So, it looks like C and Lua are (functionally? indirectly?) nearly equivalent, just not quite the same.

You can set the global 'tracking' in C via setTextTracking(), and you can 'set' (in effect, in terms of results) the additional tracking for the font used with each getTextWidth() invocation via the 'tracking' parm in its signature.

The difference between the two APIs seems to be that there's no way in C to query a font for its (optional) tracking value. I'm assuming that that information is tucked away in either the font's LCDFont struct or its internal LCDFontData struct, but since there's no definition of those structs in the SDK headers it looks like you're not meant to know, meaning that from the perspective of the SDK user those are just opaque pointers to be passed around and the SDK internals handle the details.

So, summary:

The global default 'tracking' value seems to be 0.0. So, if it's going to be anything besides that it's because you set it yourself via 'setTextTracking()', so you should know what it is without a direct 'getTextTracking()' query for the global value.

For any particular font, in C there's no way to know what (if any) its internal tracking value is, but you get to set the tracking with each individual invocation of 'getTextWidth' (which is a transient sorta-equivalent of the Lua font:setTracking() method).

A bit more detail:

All of the fonts shipped with the SDK have tracking values (when there are any specified at all) between 0 (which would mean tracking is pretty much cooked into the glyph widths/painting themselves) and 4 (for really large characters, like the ones used for the clockface).

Is that a bug?

If you're talking about on a per-font basis, perhaps more of an 'oversight'? Maybe something for a feature request :slight_smile: .

Is there a default value I can assume?

For individual fonts, there doesn't seem to be one (it's likely '0' if not defined in the font, but you can't know that... though since you know the path to the font you could roll your own way to find out, processing the font file as text and looking for a line that begins with 'tracking='. And if that's something you need to do for whatever reason I'd say that was pretty good justification for asking for a font-specific tracking query method for enhancement for C).

For the global tracking value, from what I could tell (a mixed Lua/C project):

print("tracking:")
print(tostring(playdate.graphics.getFontTracking()))

image

the default value is 0, and if it's anything else than that it's because you set it, so you should know what it is :wink: .

I don't know if this was helpful at all, but thanks for an excuse to look over some code during lunch :smiley: .

I guess the broader statement for your situation(?) would be:

'I want to invoke the C API 'getTextWidth' and there's a 'tracking' parm, what value do I use?'

From looking at the headers, I can't tell either. The docs/headers do have the parm just before 'tracking' defined (PDStringEncoding), but there's no place in the docs where I can see what value to specify for tracking, and the tracking parm isn't optional (and there is no definition of something like 'use -1 to use the font's internally specified tracking if there is one').

And there's no 'getTextWidth' calls in the SDK C examples that I can see to use as an invocation example, either.

This looks like (at least) a documentation deficiency, and possibly an oversight (bug?).

Thanks for digging into this! I had originally guessed a tracking value of "1" but then switched it to 0. I don't know if it made a difference. I've found a smattering of other functions missing from the C SDK, too. I guess I'll post about them as well, not sure what the right venue for noting these things is!

'SDK Get Help' is probably not a bad place to start :wink: .

If it then turns out to look like a bug, then posting the issue (preferably with a repro testcase attached and/or steps showing the issue) under 'SDK Bug Reports' will auto-magically get the issue 'into the bug tracking system', from what I understand.

Poof, auto-magically added to our tracker. :slight_smile: Thanks for the report!

2 Likes

Don't forget you can set your own tracking value on custom fonts, if you need control.

Wanted to add that getTextLeading is missing too!

1 Like