Resolved Core Text pain by not even thinking about lines in terms of boxes.

This commit is contained in:
Pietro Gagliardi 2017-01-05 17:55:05 -05:00
parent dfaf640101
commit 3910ff1a13
2 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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;