From c336063b65caa390758aa68ddb3e2cafbd414605 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 5 Feb 2017 20:26:59 -0500 Subject: [PATCH] Decided what I need to do. --- darwin/drawtext.m | 8 ++++++-- examples/drawtext/hittest.c | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/darwin/drawtext.m b/darwin/drawtext.m index a84b68b5..fb9e3133 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -276,6 +276,8 @@ void uiDrawTextLayoutLineGetMetrics(uiDrawTextLayout *tl, int line, uiDrawTextLa *m = tl->lineMetrics[line]; } +// TODO note that in some cases lines can overlap slightly +// in our case, we read lines first to last and use their bottommost point (Y + Height) to determine where the next line should start for hit-testing void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTextLayoutHitTestResult *result) { CFIndex i; @@ -288,7 +290,8 @@ void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTex ltop = tl->lineMetrics[i].Y; lbottom = ltop + tl->lineMetrics[i].Height; - if (y >= ltop && y < lbottom) + // y will already >= ltop at this point since the past lbottom should == (or at least >=, see above) ltop + if (y < lbottom) break; } result->YPosition = uiDrawTextLayoutHitTestPositionInside; @@ -298,6 +301,7 @@ void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTex } } else { i = 0; + // TODO what if the first line crosses into the negatives? result->YPosition = uiDrawTextLayoutHitTestPositionBefore; } result->Line = i; @@ -314,7 +318,7 @@ void uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, uiDrawTex } line = (CTLineRef) CFArrayGetValueAtIndex(tl->lines, i); - // TODO copy the part from the docs about this point + // TODO copy the part from the docs about this point (TODO what point?) pos = CTLineGetStringIndexForPosition(line, CGPointMake(x, 0)); if (pos == kCFNotFound) { // TODO diff --git a/examples/drawtext/hittest.c b/examples/drawtext/hittest.c index a2454549..dc1f9dce 100644 --- a/examples/drawtext/hittest.c +++ b/examples/drawtext/hittest.c @@ -3,8 +3,8 @@ static const char *text = "Each of the glyphs an end user interacts with are called graphemes. " -//TODO "If you enter a byte range in the text boxes below and click the button, you can see the blue box move to surround that byte range, as well as what the actual byte range necessary is. " -//TODO "You'll also see the index of the first grapheme; uiAttributedString has facilities for converting between UTF-8 code points and grapheme indices. " + "If you enter a byte range in the text boxes below and click the button, you can see the blue box move to surround that byte range, as well as what the actual byte range necessary is. " + "You'll also see the index of the first grapheme; uiAttributedString has facilities for converting between UTF-8 code points and grapheme indices. " "Additionally, click on the string to move the caret. Watch the status text at the bottom change too. " "That being said: " "\xC3\x93O\xCC\x81 (combining accents) "