summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gmdocument.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index d0420c9a..4870094d 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -430,13 +430,7 @@ static iBool typesetOneLine_RunTypesetter_(iWrapText *wrap, iRangecc wrapRange,
430 d->run.visBounds.size.x = dims.x; 430 d->run.visBounds.size.x = dims.x;
431 pushBack_Array(&d->layout, &d->run); 431 pushBack_Array(&d->layout, &d->run);
432 d->run.flags &= ~startOfLine_GmRunFlag; 432 d->run.flags &= ~startOfLine_GmRunFlag;
433// runLine.start = contPos;
434// trimStart_Rangecc(&runLine);
435 d->pos.y += lineHeight_Text(fontId) * prefs_App()->lineSpacing; 433 d->pos.y += lineHeight_Text(fontId) * prefs_App()->lineSpacing;
436// if (--d->bigCount == 0) {
437// d->run.font = d->fonts[text_GmLineType];
438// d->run.color = colors[text_GmLineType];
439// }
440 return iTrue; /* continue to next wrapped line */ 434 return iTrue; /* continue to next wrapped line */
441} 435}
442 436
@@ -526,7 +520,6 @@ static void doLayout_GmDocument_(iGmDocument *d) {
526 iGmRun run = { .color = white_ColorId }; 520 iGmRun run = { .color = white_ColorId };
527 enum iGmLineType type; 521 enum iGmLineType type;
528 float indent = 0.0f; 522 float indent = 0.0f;
529 int rightMargin = 0;
530 /* Detect the type of the line. */ 523 /* Detect the type of the line. */
531 if (!isPreformat) { 524 if (!isPreformat) {
532 type = lineType_GmDocument_(d, line); 525 type = lineType_GmDocument_(d, line);
@@ -776,22 +769,6 @@ static void doLayout_GmDocument_(iGmDocument *d) {
776 else if (type != heading1_GmLineType) { 769 else if (type != heading1_GmLineType) {
777 isFirstText = iFalse; 770 isFirstText = iFalse;
778 } 771 }
779 iRangecc runLine = line;
780 /* Create one or more text runs for this line. */
781 run.flags |= startOfLine_GmRunFlag;
782 if (!prefs->quoteIcon && type == quote_GmLineType) {
783 run.flags |= quoteBorder_GmRunFlag;
784 }
785 /* The right margin is used for balancing lines horizontally. */
786 if (isVeryNarrow) {
787 rightMargin = 0;
788 }
789 else {
790 rightMargin = (type == text_GmLineType || type == bullet_GmLineType ||
791 type == quote_GmLineType ? 4 : 0);
792 }
793 const iBool isWordWrapped =
794 (d->format == plainText_SourceFormat ? prefs->plainTextWrap : !isPreformat);
795 if (isPreformat && d->format != plainText_SourceFormat) { 772 if (isPreformat && d->format != plainText_SourceFormat) {
796 /* Remember the top left coordinates of the block (first line of block). */ 773 /* Remember the top left coordinates of the block (first line of block). */
797 iGmPreMeta *meta = at_Array(&d->preMeta, preId - 1); 774 iGmPreMeta *meta = at_Array(&d->preMeta, preId - 1);
@@ -800,18 +777,27 @@ static void doLayout_GmDocument_(iGmDocument *d) {
800 meta->flags |= topLeft_GmPreMetaFlag; 777 meta->flags |= topLeft_GmPreMetaFlag;
801 } 778 }
802 } 779 }
803 iAssert(!isEmpty_Range(&runLine)); /* must have something at this point */ 780 iAssert(!isEmpty_Range(&line)); /* must have something at this point */
804 /* Typeset the paragraph. */ { 781 /* Typeset the paragraph. */ {
805 iRunTypesetter rts; 782 iRunTypesetter rts;
806 init_RunTypesetter_(&rts); 783 init_RunTypesetter_(&rts);
807 rts.run = run; 784 rts.run = run;
808 rts.pos = pos; 785 rts.pos = pos;
809 rts.fonts = fonts; 786 rts.fonts = fonts;
810 rts.isWordWrapped = isWordWrapped; 787 rts.isWordWrapped = (d->format == plainText_SourceFormat ? prefs->plainTextWrap
788 : !isPreformat);
811 rts.isPreformat = isPreformat; 789 rts.isPreformat = isPreformat;
812 rts.layoutWidth = d->size.x; 790 rts.layoutWidth = d->size.x;
813 rts.indent = indent * gap_Text; 791 rts.indent = indent * gap_Text;
814 rts.rightMargin = rightMargin * gap_Text; 792 /* The right margin is used for balancing lines horizontally. */
793 if (isVeryNarrow) {
794 rts.rightMargin = 0;
795 }
796 else {
797 rts.rightMargin = (type == text_GmLineType || type == bullet_GmLineType ||
798 type == quote_GmLineType
799 ? 4 : 0) * gap_Text;
800 }
815 if (!isMono) { 801 if (!isMono) {
816 /* Upper-level headings are typeset a bit tighter. */ 802 /* Upper-level headings are typeset a bit tighter. */
817 if (type == heading1_GmLineType) { 803 if (type == heading1_GmLineType) {
@@ -825,14 +811,18 @@ static void doLayout_GmDocument_(iGmDocument *d) {
825 rts.run.font = paragraph_FontId; 811 rts.run.font = paragraph_FontId;
826 } 812 }
827 } 813 }
828 iWrapText wrapText = { .text = runLine, 814 if (!prefs->quoteIcon && type == quote_GmLineType) {
829 .maxWidth = isWordWrapped ? d->size.x - run.bounds.pos.x - 815 rts.run.flags |= quoteBorder_GmRunFlag;
830 rts.indent - rts.rightMargin 816 }
831 : 0 /* unlimited */, 817 iWrapText wrapText = { .text = line,
818 .maxWidth = rts.isWordWrapped ? d->size.x - run.bounds.pos.x -
819 rts.indent - rts.rightMargin
820 : 0 /* unlimited */,
832 .mode = word_WrapTextMode, 821 .mode = word_WrapTextMode,
833 .wrapFunc = typesetOneLine_RunTypesetter_, 822 .wrapFunc = typesetOneLine_RunTypesetter_,
834 .context = &rts }; 823 .context = &rts };
835 for (;;) { /* may need to retry */ 824 for (;;) { /* may need to retry */
825 rts.run.flags |= startOfLine_GmRunFlag;
836 measure_WrapText(&wrapText, run.font); 826 measure_WrapText(&wrapText, run.font);
837 if (!isLedeParagraph || size_Array(&rts.layout) <= maxLedeLines_) { 827 if (!isLedeParagraph || size_Array(&rts.layout) <= maxLedeLines_) {
838 commit_RunTypesetter_(&rts, d); 828 commit_RunTypesetter_(&rts, d);