Boilerplate needed for implementing range-to-rect.
This commit is contained in:
parent
c336063b65
commit
b18cc88dce
|
@ -315,11 +315,24 @@ size_t attrstrUTF16Len(uiAttributedString *s)
|
|||
return s->u16len;
|
||||
}
|
||||
|
||||
// TODO is this still needed given the below?
|
||||
size_t attrstrUTF8ToUTF16(uiAttributedString *s, size_t n)
|
||||
{
|
||||
return s->u8tou16[n];
|
||||
}
|
||||
|
||||
size_t *attrstrCopyUTF8ToUTF16(uiAttributedString *s, size_t *n)
|
||||
{
|
||||
size_t *out;
|
||||
size_t nbytes;
|
||||
|
||||
nbytes = (s->len + 1) * sizeof (size_t);
|
||||
*n = s->len;
|
||||
out = (size_t *) uiAlloc(nbytes, "size_t[] (uiAttributedString)");
|
||||
memmove(out, s->u8tou16, nbytes);
|
||||
return out;
|
||||
}
|
||||
|
||||
size_t *attrstrCopyUTF16ToUTF8(uiAttributedString *s, size_t *n)
|
||||
{
|
||||
size_t *out;
|
||||
|
|
|
@ -73,6 +73,7 @@ extern struct graphemes *graphemes(void *s, size_t len);
|
|||
extern const uint16_t *attrstrUTF16(uiAttributedString *s);
|
||||
extern size_t attrstrUTF16Len(uiAttributedString *s);
|
||||
extern size_t attrstrUTF8ToUTF16(uiAttributedString *s, size_t n);
|
||||
extern size_t *attrstrCopyUTF8ToUTF16(uiAttributedString *s, size_t *n);
|
||||
extern size_t *attrstrCopyUTF16ToUTF8(uiAttributedString *s, size_t *n);
|
||||
|
||||
// attrlist.c
|
||||
|
|
|
@ -28,9 +28,11 @@ struct uiDrawTextLayout {
|
|||
// we compute this once when first creating the layout
|
||||
uiDrawTextLayoutLineMetrics *lineMetrics;
|
||||
|
||||
// for converting CFAttributedString indices to byte offsets
|
||||
// for converting CFAttributedString indices from/to byte offsets
|
||||
size_t *u8tou16;
|
||||
size_t nUTF8;
|
||||
size_t *u16tou8;
|
||||
size_t nu16tou8; // TODO I don't like the casing of this name
|
||||
size_t nUTF16;
|
||||
};
|
||||
|
||||
static CTFontRef fontdescToCTFont(uiDrawFontDescriptor *fd)
|
||||
|
@ -201,8 +203,9 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
|||
tl->nLines = CFArrayGetCount(tl->lines);
|
||||
tl->lineMetrics = computeLineMetrics(tl->frame, tl->size);
|
||||
|
||||
// and finally copy the UTF-16 to UTF-8 index conversion table
|
||||
tl->u16tou8 = attrstrCopyUTF16ToUTF8(s, &(tl->nu16tou8));
|
||||
// and finally copy the UTF-8/UTF-16 conversion tables
|
||||
tl->u8tou16 = attrstrCopyUTF8ToUTF16(s, &(tl->nUTF8));
|
||||
tl->u16tou8 = attrstrCopyUTF16ToUTF8(s, &(tl->nUTF16));
|
||||
|
||||
return tl;
|
||||
}
|
||||
|
@ -210,6 +213,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
|||
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
||||
{
|
||||
uiFree(tl->u16tou8);
|
||||
uiFree(tl->u8tou16);
|
||||
uiFree(tl->lineMetrics);
|
||||
// TODO release tl->lines?
|
||||
CFRelease(tl->frame);
|
||||
|
|
Loading…
Reference in New Issue