summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-15 12:50:15 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-15 12:50:21 +0300
commit95a189a3be787687113b14d66b607716dd642c8a (patch)
tree2513301e0b576fe79b53918ab898dc5c0cc27774 /src
parentb683afe31852914ce1792582fa67e4330ee386e1 (diff)
GmDocument: Right-align RTL decorations
Diffstat (limited to 'src')
-rw-r--r--src/gmdocument.c35
-rw-r--r--src/ui/text.c4
-rw-r--r--src/ui/text.h1
3 files changed, 28 insertions, 12 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 639ddbfb..5034373d 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -822,16 +822,33 @@ static void doLayout_GmDocument_(iGmDocument *d) {
822 } 822 }
823 for (;;) { /* may need to retry */ 823 for (;;) { /* may need to retry */
824 rts.run.flags |= startOfLine_GmRunFlag; 824 rts.run.flags |= startOfLine_GmRunFlag;
825 measure_WrapText(&(iWrapText){ .text = line, 825 iWrapText wrapText = { .text = line,
826 .maxWidth = rts.isWordWrapped 826 .maxWidth = rts.isWordWrapped
827 ? d->size.x - run.bounds.pos.x - 827 ? d->size.x - run.bounds.pos.x -
828 rts.indent - rts.rightMargin 828 rts.indent - rts.rightMargin
829 : 0 /* unlimited */, 829 : 0 /* unlimited */,
830 .mode = word_WrapTextMode, 830 .mode = word_WrapTextMode,
831 .wrapFunc = typesetOneLine_RunTypesetter_, 831 .wrapFunc = typesetOneLine_RunTypesetter_,
832 .context = &rts }, 832 .context = &rts };
833 rts.run.textParams.font); 833 measure_WrapText(&wrapText, rts.run.textParams.font);
834 if (!isLedeParagraph || size_Array(&rts.layout) <= maxLedeLines_) { 834 if (!isLedeParagraph || size_Array(&rts.layout) <= maxLedeLines_) {
835 if (wrapText.baseDir < 0) {
836 /* Right-aligned paragraphs need margins and decorations to be flipped. */
837 iForEach(Array, pr, &rts.layout) {
838 iGmRun *prun = pr.value;
839 const int offset = rts.rightMargin - rts.indent;
840 prun->bounds.pos.x += offset;
841 prun->visBounds.pos.x += offset;
842 }
843 if (type == bullet_GmLineType || type == link_GmLineType ||
844 type == quote_GmLineType) {
845 iGmRun *decor = back_Array(&d->layout);
846 iAssert(decor->flags & decoration_GmRunFlag);
847 decor->visBounds.pos.x = d->size.x - width_Rect(decor->visBounds) -
848 decor->visBounds.pos.x + gap_Text *
849 (type == bullet_GmLineType ? 1.5f : 1);
850 }
851 }
835 commit_RunTypesetter_(&rts, d); 852 commit_RunTypesetter_(&rts, d);
836 break; 853 break;
837 } 854 }
diff --git a/src/ui/text.c b/src/ui/text.c
index 01a9d606..0a3b7b2e 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -1382,9 +1382,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1382 float xCursorMax = 0.0f; 1382 float xCursorMax = 0.0f;
1383 const iBool isMonospaced = d->isMonospaced; 1383 const iBool isMonospaced = d->isMonospaced;
1384 iAssert(args->text.end >= args->text.start); 1384 iAssert(args->text.end >= args->text.start);
1385// if (args->continueFrom_out) {
1386// *args->continueFrom_out = args->text.end;
1387// }
1388 /* Split the text into a number of attributed runs that specify exactly which 1385 /* Split the text into a number of attributed runs that specify exactly which
1389 font is used and other attributes such as color. (HarfBuzz shaping is done 1386 font is used and other attributes such as color. (HarfBuzz shaping is done
1390 with one specific font.) */ 1387 with one specific font.) */
@@ -1392,6 +1389,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1392 init_AttributedText(&attrText, args->text, args->maxLen, d, get_Color(args->color), 1389 init_AttributedText(&attrText, args->text, args->maxLen, d, get_Color(args->color),
1393 args->baseDir); 1390 args->baseDir);
1394 if (args->wrap) { 1391 if (args->wrap) {
1392 args->wrap->baseDir = attrText.isBaseRTL ? -1 : +1;
1395 /* TODO: Duplicated args? */ 1393 /* TODO: Duplicated args? */
1396 iAssert(equalRange_Rangecc(args->wrap->text, args->text)); 1394 iAssert(equalRange_Rangecc(args->wrap->text, args->text));
1397 /* Initialize the wrap range. */ 1395 /* Initialize the wrap range. */
diff --git a/src/ui/text.h b/src/ui/text.h
index d3a9f844..41e7671e 100644
--- a/src/ui/text.h
+++ b/src/ui/text.h
@@ -207,6 +207,7 @@ struct Impl_WrapText {
207 enum iWrapTextMode mode; 207 enum iWrapTextMode mode;
208 iBool (*wrapFunc)(iWrapText *, iRangecc wrappedText, int origin, int advance, iBool isBaseRTL); 208 iBool (*wrapFunc)(iWrapText *, iRangecc wrappedText, int origin, int advance, iBool isBaseRTL);
209 void * context; 209 void * context;
210 int baseDir; /* set to +1 for LTR, -1 for RTL
210 /* internal */ 211 /* internal */
211 iRangecc wrapRange_; 212 iRangecc wrapRange_;
212}; 213};