diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 07:02:33 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 07:02:33 +0300 |
commit | aa50c1e0028c6cb08524dcdfb7188906c817e46f (patch) | |
tree | 1f5d91bef261612680d589e0481dad99ef189619 /src/gmdocument.c | |
parent | de53b815e09a1004b8fb70706199fb840f53514a (diff) |
Option to force break very long lines
Even preformatted lines may need to be wrapped so the content remains visible, since there is no horizontal scrolling. However, this is off by default so ASCII art isn't broken in narrow windows.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 924eee32..e4ae03a8 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -104,6 +104,7 @@ struct Impl_GmDocument { | |||
104 | iString source; | 104 | iString source; |
105 | iString url; /* for resolving relative links */ | 105 | iString url; /* for resolving relative links */ |
106 | iString localHost; | 106 | iString localHost; |
107 | int forceBreakWidth; /* force breaks on very long preformatted lines */ | ||
107 | iInt2 size; | 108 | iInt2 size; |
108 | iArray layout; /* contents of source, laid out in document space */ | 109 | iArray layout; /* contents of source, laid out in document space */ |
109 | iPtrArray links; | 110 | iPtrArray links; |
@@ -506,12 +507,11 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
506 | } | 507 | } |
507 | run.bounds.pos = addX_I2(pos, indent * gap_Text); | 508 | run.bounds.pos = addX_I2(pos, indent * gap_Text); |
508 | const char *contPos; | 509 | const char *contPos; |
509 | const int avail = d->size.x - run.bounds.pos.x; | 510 | const int avail = (isPreformat ? d->forceBreakWidth : d->size.x) - run.bounds.pos.x; |
510 | const iInt2 dims = | 511 | const iInt2 dims = tryAdvance_Text(run.font, runLine, avail, &contPos); |
511 | tryAdvance_Text(run.font, runLine, isPreformat ? 0 : avail, &contPos); | ||
512 | run.bounds.size.x = iMax(avail, dims.x); /* Extends to the right edge for selection. */ | 512 | run.bounds.size.x = iMax(avail, dims.x); /* Extends to the right edge for selection. */ |
513 | run.bounds.size.y = dims.y; | 513 | run.bounds.size.y = dims.y; |
514 | run.visBounds = run.bounds; | 514 | run.visBounds = run.bounds; |
515 | run.visBounds.size.x = dims.x; | 515 | run.visBounds.size.x = dims.x; |
516 | if (contPos > runLine.start) { | 516 | if (contPos > runLine.start) { |
517 | run.text = (iRangecc){ runLine.start, contPos }; | 517 | run.text = (iRangecc){ runLine.start, contPos }; |
@@ -866,7 +866,8 @@ void setFormat_GmDocument(iGmDocument *d, enum iGmDocumentFormat format) { | |||
866 | d->format = format; | 866 | d->format = format; |
867 | } | 867 | } |
868 | 868 | ||
869 | void setWidth_GmDocument(iGmDocument *d, int width) { | 869 | void setWidth_GmDocument(iGmDocument *d, int width, int forceBreakWidth) { |
870 | d->forceBreakWidth = forceBreakWidth; | ||
870 | d->size.x = width; | 871 | d->size.x = width; |
871 | doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ | 872 | doLayout_GmDocument_(d); /* TODO: just flag need-layout and do it later */ |
872 | } | 873 | } |
@@ -939,11 +940,10 @@ void setUrl_GmDocument(iGmDocument *d, const iString *url) { | |||
939 | setRange_String(&d->localHost, parts.host); | 940 | setRange_String(&d->localHost, parts.host); |
940 | } | 941 | } |
941 | 942 | ||
942 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width) { | 943 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width, int forceBreakWidth) { |
943 | set_String(&d->source, source); | 944 | set_String(&d->source, source); |
944 | normalize_GmDocument(d); | 945 | normalize_GmDocument(d); |
945 | setWidth_GmDocument(d, width); | 946 | setWidth_GmDocument(d, width, forceBreakWidth); /* re-do layout */ |
946 | /* TODO: just flag need-layout and do it later */ | ||
947 | } | 947 | } |
948 | 948 | ||
949 | void setImage_GmDocument(iGmDocument *d, iGmLinkId linkId, const iString *mime, const iBlock *data) { | 949 | void setImage_GmDocument(iGmDocument *d, iGmLinkId linkId, const iString *mime, const iBlock *data) { |