Inconsistent text-width results for UTF8 encoding

Two functions calculates text-layout/shaping and returns its width.

  • playdate->graphics->getTextWidth

  • playdate->graphics->drawText

And they return different results. Why? I suppose that it's a bug.

Os: macOS 14.x on M1.
SDK: reproducible with 2.7.2-2.7.3-beta.2 and maybe earlier :man_shrugging:t2:

Steps to reproduce

Pre: do not set font, tracking and any other options, just "clean 'n' cold setup".

  1. get current text-tracking via playdate->graphics->getTextTracking (it's zero)

  2. call playdate->graphics->getTextWidth(NULL, {STR}, {STRLEN}, kUTF8Encoding, 0 /* tracking from prev step */ ), where {STR}, {STRLEN} is:

  • "你好", 2

  • "Dobrý den", 9

  • "Hello \xf0\x90\x80World", 14

  1. call playdate->graphics->drawText({STR}, {STRLEN}, kUTF8Encoding, 0, 0) and compare results with prev step

Inconsistent results:

  • 32 != 21 for "你好" in kUTF8Encoding

  • 83 != 3 for "Dobrý den" in kUTF8Encoding

  • 37 != 32 for "Hello \xf0\x90\x80World" in kUTF8Encoding

I know that "Hello \xf0\x90\x80World" is not valid UTF8, but that is not cancels the calculation method inconsistency and this bug.