diff --git a/darwin/drawtext.m b/darwin/drawtext.m index 1272b1da..8d5c400d 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -119,12 +119,16 @@ void uiDrawFreeTextLayout(uiDrawTextLayout *tl) uiFree(tl); } +// TODO what is y, the top-left corner, bottom-left corner, topmost baseline, or bottommost baseline? void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y) { } void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height) { + // TODO how exactly do we adjust this by CGPathGetPathBoundingBox(tl->path)? + *width = tl->size.width; + *height = tl->size.height; } int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) @@ -157,13 +161,12 @@ void uiDrawTextLayoutLineGetMetrics(uiDrawTextLayout *tl, int line, uiDrawTextLa CTFrameGetLineOrigins(tl->frame, range, &origin); // TODO how exactly do we adjust this by CGPathGetPathBoundingBox(tl->path)? m->X = origin.x; - m->Y = origin.y; - // TODO is m->Y the baseline position? - // TODO is m->Y flipped? + m->BaselineY = origin.y; + // TODO m->Y is flipped lr = getline(tl, line); // though CTLineGetTypographicBounds() returns 0 on error, it also returns 0 on an empty string, so we can't reasonably check for error - m->Width = CTLineGetTypographicBounds(lr, ascent, descent, leading); + m->Width = CTLineGetTypographicBounds(lr, &ascent, &descent, &leading); m->Ascent = ascent; m->Descent = descent; m->Leading = leading; diff --git a/ui_attrstr.h b/ui_attrstr.h index 4cf7d761..1d0c4696 100644 --- a/ui_attrstr.h +++ b/ui_attrstr.h @@ -90,10 +90,12 @@ typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics; typedef struct uiDrawTextLayoutByteRangeRectangle uiDrawTextLayoutByteRangeRectangle; struct uiDrawTextLayoutLineMetrics { + // TODO figure out if this is correct regardless of both alignment and writing direction double X; - double Y; + double BaselineY; double Width; - // height = ascent + descent + leading (TODO formally document) + // top-left Y = baseline Y - ascent + // height = ascent + descent + leading (TODO formally document all this) double Ascent; double Descent; double Leading;