diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-21 08:55:12 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-21 08:55:12 +0300 |
commit | 9ab619bd3c57d681a3906abf0dc10d5376d01319 (patch) | |
tree | 664d546bb36cd24afcf6d5fec2d0d7289b1f97aa /src/ui/text.c | |
parent | aaa5d18c3f1540c18bb9dae80927df2803c42049 (diff) |
Text: Finding the advance position of a character
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index d6a45c69..ce383ccf 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -1380,8 +1380,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1380 | /* TODO: Duplicated args? */ | 1380 | /* TODO: Duplicated args? */ |
1381 | iAssert(equalRange_Rangecc(wrap->text, args->text)); | 1381 | iAssert(equalRange_Rangecc(wrap->text, args->text)); |
1382 | /* Initialize the wrap range. */ | 1382 | /* Initialize the wrap range. */ |
1383 | wrap->wrapRange_ = args->text; | 1383 | wrap->wrapRange_ = args->text; |
1384 | wrap->hitChar_out = NULL; | 1384 | wrap->hitAdvance_out = zero_I2(); |
1385 | wrap->hitChar_out = NULL; | ||
1385 | wrap->hitGlyphNormX_out = 0.0f; | 1386 | wrap->hitGlyphNormX_out = 0.0f; |
1386 | } | 1387 | } |
1387 | const iChar *logicalText = constData_Array(&attrText.logical); | 1388 | const iChar *logicalText = constData_Array(&attrText.logical); |
@@ -1427,6 +1428,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1427 | const int layoutBound = (wrap ? wrap->maxWidth : 0); | 1428 | const int layoutBound = (wrap ? wrap->maxWidth : 0); |
1428 | iBool isFirst = iTrue; | 1429 | iBool isFirst = iTrue; |
1429 | const iBool checkHitPoint = wrap && !isEqual_I2(wrap->hitPoint, zero_I2()); | 1430 | const iBool checkHitPoint = wrap && !isEqual_I2(wrap->hitPoint, zero_I2()); |
1431 | const iBool checkHitChar = wrap && wrap->hitChar; | ||
1430 | while (!isEmpty_Range(&wrapRuns)) { | 1432 | while (!isEmpty_Range(&wrapRuns)) { |
1431 | if (isFirst) { | 1433 | if (isFirst) { |
1432 | isFirst = iFalse; | 1434 | isFirst = iFalse; |
@@ -1446,6 +1448,11 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1446 | for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { | 1448 | for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { |
1447 | const iAttributedRun *run = at_Array(&attrText.runs, runIndex); | 1449 | const iAttributedRun *run = at_Array(&attrText.runs, runIndex); |
1448 | if (run->flags.isLineBreak) { | 1450 | if (run->flags.isLineBreak) { |
1451 | if (checkHitChar) { | ||
1452 | if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, run->logical.start)) { | ||
1453 | wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); | ||
1454 | } | ||
1455 | } | ||
1449 | wrapPosRange.end = run->logical.start; | 1456 | wrapPosRange.end = run->logical.start; |
1450 | wrapResumePos = run->logical.end; | 1457 | wrapResumePos = run->logical.end; |
1451 | wrapRuns.end = runIndex; | 1458 | wrapRuns.end = runIndex; |
@@ -1468,6 +1475,11 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1468 | if (logPos < wrapPosRange.start || logPos >= wrapPosRange.end) { | 1475 | if (logPos < wrapPosRange.start || logPos >= wrapPosRange.end) { |
1469 | continue; | 1476 | continue; |
1470 | } | 1477 | } |
1478 | if (checkHitChar) { | ||
1479 | if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, logPos)) { | ||
1480 | wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); | ||
1481 | } | ||
1482 | } | ||
1471 | /* Check if the hit point is on the left side of this line. */ | 1483 | /* Check if the hit point is on the left side of this line. */ |
1472 | if (isHitPointOnThisLine && !wrap->hitChar_out && wrap->hitPoint.x < orig.x) { | 1484 | if (isHitPointOnThisLine && !wrap->hitChar_out && wrap->hitPoint.x < orig.x) { |
1473 | wrap->hitChar_out = sourcePtr_AttributedText_(&attrText, logPos); | 1485 | wrap->hitChar_out = sourcePtr_AttributedText_(&attrText, logPos); |
@@ -1723,6 +1735,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1723 | wrapPosRange.start = wrapResumePos; | 1735 | wrapPosRange.start = wrapResumePos; |
1724 | wrapPosRange.end = textLen; | 1736 | wrapPosRange.end = textLen; |
1725 | } | 1737 | } |
1738 | if (checkHitChar && wrap->hitChar == args->text.end) { | ||
1739 | wrap->hitAdvance_out = init_I2(xCursor, yCursor); | ||
1740 | } | ||
1726 | if (endsWith_Rangecc(args->text, "\n")) { | 1741 | if (endsWith_Rangecc(args->text, "\n")) { |
1727 | /* FIXME: This is a kludge, the wrap loop should handle this case, too. */ | 1742 | /* FIXME: This is a kludge, the wrap loop should handle this case, too. */ |
1728 | /* The last wrap is an empty newline wrap. */ | 1743 | /* The last wrap is an empty newline wrap. */ |