diff --git a/_wip/attrstr_metrics/numlinesbyterange b/_wip/attrstr_metrics/numlinesbyterange new file mode 100644 index 00000000..46a7ba21 --- /dev/null +++ b/_wip/attrstr_metrics/numlinesbyterange @@ -0,0 +1,60 @@ +darwin +int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) +{ + return CFArrayGetCount([tl->forLines lines]); +} + +void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) +{ + CTLineRef lr; + CFRange range; + + lr = (CTLineRef) CFArrayGetValueAtIndex([tl->forLines lines], line); + range = CTLineGetStringRange(lr); + *start = tl->u16tou8[range.location]; + if (tl->empty) + *end = *start; + else + *end = tl->u16tou8[range.location + range.length]; +} + + +unix +int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) +{ + return pango_layout_get_line_count(tl->layout); +} + +void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) +{ + PangoLayoutLine *pll; + + pll = pango_layout_get_line_readonly(tl->layout, line); + *start = pll->start_index; + *end = pll->start_index + pll->length; + // TODO unref pll? +} + + +windows +int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) +{ +return 0; +#if 0 +TODO + return tl->nLines; +#endif +} + +// DirectWrite doesn't provide a direct way to do this, so we have to do this manually +// TODO does that comment still apply here or to the code at the top of this file? +void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) +{ +#if 0 +TODO + *start = tl->lineInfo[line].startPos; + *start = tl->u16tou8[*start]; + *end = tl->lineInfo[line].endPos - tl->lineInfo[line].newlineCount; + *end = tl->u16tou8[*end]; +#endif +} diff --git a/old_ui_attrstr.h b/_wip/attrstr_metrics/old_ui_attrstr.h similarity index 85% rename from old_ui_attrstr.h rename to _wip/attrstr_metrics/old_ui_attrstr.h index 75df996d..ebe9308d 100644 --- a/old_ui_attrstr.h +++ b/_wip/attrstr_metrics/old_ui_attrstr.h @@ -31,6 +31,15 @@ struct uiDrawTextLayoutLineMetrics { // TODO trailing whitespace? }; +// uiDrawTextLayoutNumLines() returns the number of lines in tl. +// This number will always be greater than or equal to 1; a text +// layout with no text only has one line. +_UI_EXTERN int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl); + +// uiDrawTextLayoutLineByteRange() returns the byte indices of the +// text that falls into the given line of tl as [start, end). +_UI_EXTERN void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end); + _UI_EXTERN void uiDrawTextLayoutLineGetMetrics(uiDrawTextLayout *tl, int line, uiDrawTextLayoutLineMetrics *m); // TODO rewrite this documentation diff --git a/darwin/drawtext.m b/darwin/drawtext.m index 5406617c..c04b402b 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -212,22 +212,3 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height [tl->frame returnWidth:width height:NULL]; [tl->forLines returnWidth:NULL height:height]; } - -int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) -{ - return CFArrayGetCount([tl->forLines lines]); -} - -void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) -{ - CTLineRef lr; - CFRange range; - - lr = (CTLineRef) CFArrayGetValueAtIndex([tl->forLines lines], line); - range = CTLineGetStringRange(lr); - *start = tl->u16tou8[range.location]; - if (tl->empty) - *end = *start; - else - *end = tl->u16tou8[range.location + range.length]; -} diff --git a/ui_attrstr.h b/ui_attrstr.h index 66b0fb4b..f4302cd5 100644 --- a/ui_attrstr.h +++ b/ui_attrstr.h @@ -484,15 +484,6 @@ _UI_EXTERN void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, dou // function to get the actual size of the text layout. _UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height); -// uiDrawTextLayoutNumLines() returns the number of lines in tl. -// This number will always be greater than or equal to 1; a text -// layout with no text only has one line. -_UI_EXTERN int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl); - -// uiDrawTextLayoutLineByteRange() returns the byte indices of the -// text that falls into the given line of tl as [start, end). -_UI_EXTERN void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end); - // TODO metrics functions // TODO number of lines visible for clipping rect, range visible for clipping rect? diff --git a/unix/drawtext.c b/unix/drawtext.c index 5792f9e0..477e9ca3 100644 --- a/unix/drawtext.c +++ b/unix/drawtext.c @@ -79,18 +79,3 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height *width = pangoToCairo(logical.width); *height = pangoToCairo(logical.height); } - -int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) -{ - return pango_layout_get_line_count(tl->layout); -} - -void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) -{ - PangoLayoutLine *pll; - - pll = pango_layout_get_line_readonly(tl->layout, line); - *start = pll->start_index; - *end = pll->start_index + pll->length; - // TODO unref pll? -} diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp index 56a7dfbb..85accab1 100644 --- a/windows/drawtext.cpp +++ b/windows/drawtext.cpp @@ -534,25 +534,3 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height // TODO make sure the behavior of this on empty strings is the same on all platforms (ideally should be 0-width, line height-height; TODO note this in the docs too) *height = metrics.height; } - -int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl) -{ -return 0; -#if 0 -TODO - return tl->nLines; -#endif -} - -// DirectWrite doesn't provide a direct way to do this, so we have to do this manually -// TODO does that comment still apply here or to the code at the top of this file? -void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end) -{ -#if 0 -TODO - *start = tl->lineInfo[line].startPos; - *start = tl->u16tou8[*start]; - *end = tl->lineInfo[line].endPos - tl->lineInfo[line].newlineCount; - *end = tl->u16tou8[*end]; -#endif -}