summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-20 14:57:09 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-20 14:57:09 +0300
commit5f9685010addd4a0f04c13f889856084381dd1c6 (patch)
treec29aecfd36da1ac0c3608fe9969841643ed5ca95 /src/gmdocument.c
parentb8c07107fa332651cf2281fe8d2f90dfc122b588 (diff)
Added GmTypesetter
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 67adb9cc..f8d41172 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -21,6 +21,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 21SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#include "gmdocument.h" 23#include "gmdocument.h"
24#include "gmtypesetter.h"
24#include "gmutil.h" 25#include "gmutil.h"
25#include "lang.h" 26#include "lang.h"
26#include "ui/color.h" 27#include "ui/color.h"
@@ -73,7 +74,7 @@ iDefineTypeConstruction(GmLink)
73 74
74struct Impl_GmDocument { 75struct Impl_GmDocument {
75 iObject object; 76 iObject object;
76 enum iGmDocumentFormat format; 77 enum iSourceFormat format;
77 iString unormSource; /* unnormalized source */ 78 iString unormSource; /* unnormalized source */
78 iString source; /* normalized source */ 79 iString source; /* normalized source */
79 iString url; /* for resolving relative links */ 80 iString url; /* for resolving relative links */
@@ -95,7 +96,7 @@ struct Impl_GmDocument {
95iDefineObjectConstruction(GmDocument) 96iDefineObjectConstruction(GmDocument)
96 97
97static enum iGmLineType lineType_GmDocument_(const iGmDocument *d, const iRangecc line) { 98static enum iGmLineType lineType_GmDocument_(const iGmDocument *d, const iRangecc line) {
98 if (d->format == plainText_GmDocumentFormat) { 99 if (d->format == plainText_SourceFormat) {
99 return text_GmLineType; 100 return text_GmLineType;
100 } 101 }
101 return lineType_Rangecc(line); 102 return lineType_Rangecc(line);
@@ -305,7 +306,7 @@ static void linkContentWasLaidOut_GmDocument_(iGmDocument *d, const iGmMediaInfo
305 306
306static iBool isNormalized_GmDocument_(const iGmDocument *d) { 307static iBool isNormalized_GmDocument_(const iGmDocument *d) {
307 const iPrefs *prefs = prefs_App(); 308 const iPrefs *prefs = prefs_App();
308 if (d->format == plainText_GmDocumentFormat) { 309 if (d->format == plainText_SourceFormat) {
309 return iTrue; /* tabs are always normalized in plain text */ 310 return iTrue; /* tabs are always normalized in plain text */
310 } 311 }
311 if (startsWithCase_String(&d->url, "gemini:") && prefs->monospaceGemini) { 312 if (startsWithCase_String(&d->url, "gemini:") && prefs->monospaceGemini) {
@@ -433,7 +434,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
433 enum iGmLineType prevType = text_GmLineType; 434 enum iGmLineType prevType = text_GmLineType;
434 enum iGmLineType prevNonBlankType = text_GmLineType; 435 enum iGmLineType prevNonBlankType = text_GmLineType;
435 iBool followsBlank = iFalse; 436 iBool followsBlank = iFalse;
436 if (d->format == plainText_GmDocumentFormat) { 437 if (d->format == plainText_SourceFormat) {
437 isPreformat = iTrue; 438 isPreformat = iTrue;
438 isFirstText = iFalse; 439 isFirstText = iFalse;
439 } 440 }
@@ -502,14 +503,14 @@ static void doLayout_GmDocument_(iGmDocument *d) {
502 if (contentLine.start == content.start) { 503 if (contentLine.start == content.start) {
503 prevType = type; 504 prevType = type;
504 } 505 }
505 if (d->format == gemini_GmDocumentFormat && 506 if (d->format == gemini_SourceFormat &&
506 startsWithSc_Rangecc(line, "```", &iCaseSensitive)) { 507 startsWithSc_Rangecc(line, "```", &iCaseSensitive)) {
507 isPreformat = iFalse; 508 isPreformat = iFalse;
508 addSiteBanner = iFalse; /* overrides the banner */ 509 addSiteBanner = iFalse; /* overrides the banner */
509 continue; 510 continue;
510 } 511 }
511 run.preId = preId; 512 run.preId = preId;
512 run.font = (d->format == plainText_GmDocumentFormat ? regularMonospace_FontId : preFont); 513 run.font = (d->format == plainText_SourceFormat ? regularMonospace_FontId : preFont);
513 indent = indents[type]; 514 indent = indents[type];
514 } 515 }
515 if (addSiteBanner) { 516 if (addSiteBanner) {
@@ -582,7 +583,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
582 } 583 }
583 } 584 }
584 /* Folded blocks are represented by a single run with the alt text. */ 585 /* Folded blocks are represented by a single run with the alt text. */
585 if (isPreformat && d->format != plainText_GmDocumentFormat) { 586 if (isPreformat && d->format != plainText_SourceFormat) {
586 const iGmPreMeta *meta = constAt_Array(&d->preMeta, preId - 1); 587 const iGmPreMeta *meta = constAt_Array(&d->preMeta, preId - 1);
587 if (meta->flags & folded_GmPreMetaFlag) { 588 if (meta->flags & folded_GmPreMetaFlag) {
588 const iBool isBlank = isEmpty_Range(&meta->altText); 589 const iBool isBlank = isEmpty_Range(&meta->altText);
@@ -678,7 +679,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
678 pushBack_Array(&d->layout, &icon); 679 pushBack_Array(&d->layout, &icon);
679 } 680 }
680 run.color = colors[type]; 681 run.color = colors[type];
681 if (d->format == plainText_GmDocumentFormat) { 682 if (d->format == plainText_SourceFormat) {
682 run.color = colors[text_GmLineType]; 683 run.color = colors[text_GmLineType];
683 } 684 }
684 /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */ 685 /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */
@@ -707,8 +708,8 @@ static void doLayout_GmDocument_(iGmDocument *d) {
707 type == quote_GmLineType ? 4 : 0); 708 type == quote_GmLineType ? 4 : 0);
708 } 709 }
709 const iBool isWordWrapped = 710 const iBool isWordWrapped =
710 (d->format == plainText_GmDocumentFormat ? prefs->plainTextWrap : !isPreformat); 711 (d->format == plainText_SourceFormat ? prefs->plainTextWrap : !isPreformat);
711 if (isPreformat && d->format != plainText_GmDocumentFormat) { 712 if (isPreformat && d->format != plainText_SourceFormat) {
712 /* Remember the top left coordinates of the block (first line of block). */ 713 /* Remember the top left coordinates of the block (first line of block). */
713 iGmPreMeta *meta = at_Array(&d->preMeta, preId - 1); 714 iGmPreMeta *meta = at_Array(&d->preMeta, preId - 1);
714 if (~meta->flags & topLeft_GmPreMetaFlag) { 715 if (~meta->flags & topLeft_GmPreMetaFlag) {
@@ -866,7 +867,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
866} 867}
867 868
868void init_GmDocument(iGmDocument *d) { 869void init_GmDocument(iGmDocument *d) {
869 d->format = gemini_GmDocumentFormat; 870 d->format = gemini_SourceFormat;
870 init_String(&d->unormSource); 871 init_String(&d->unormSource);
871 init_String(&d->source); 872 init_String(&d->source);
872 init_String(&d->url); 873 init_String(&d->url);
@@ -1397,7 +1398,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
1397#endif 1398#endif
1398} 1399}
1399 1400
1400void setFormat_GmDocument(iGmDocument *d, enum iGmDocumentFormat format) { 1401void setFormat_GmDocument(iGmDocument *d, enum iSourceFormat format) {
1401 d->format = format; 1402 d->format = format;
1402} 1403}
1403 1404
@@ -1439,7 +1440,7 @@ static void normalize_GmDocument(iGmDocument *d) {
1439 iRangecc src = range_String(&d->source); 1440 iRangecc src = range_String(&d->source);
1440 iRangecc line = iNullRange; 1441 iRangecc line = iNullRange;
1441 iBool isPreformat = iFalse; 1442 iBool isPreformat = iFalse;
1442 if (d->format == plainText_GmDocumentFormat) { 1443 if (d->format == plainText_SourceFormat) {
1443 isPreformat = iTrue; /* Cannot be turned off. */ 1444 isPreformat = iTrue; /* Cannot be turned off. */
1444 } 1445 }
1445 const int preTabWidth = 4; /* TODO: user-configurable parameter */ 1446 const int preTabWidth = 4; /* TODO: user-configurable parameter */
@@ -1467,7 +1468,7 @@ static void normalize_GmDocument(iGmDocument *d) {
1467 } 1468 }
1468 } 1469 }
1469 appendCStr_String(normalized, "\n"); 1470 appendCStr_String(normalized, "\n");
1470 if (d->format == gemini_GmDocumentFormat && 1471 if (d->format == gemini_SourceFormat &&
1471 lineType_GmDocument_(d, line) == preformatted_GmLineType) { 1472 lineType_GmDocument_(d, line) == preformatted_GmLineType) {
1472 isPreformat = iFalse; 1473 isPreformat = iFalse;
1473 } 1474 }