diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gmdocument.c | 35 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 4 | ||||
-rw-r--r-- | src/ui/text.c | 11 | ||||
-rw-r--r-- | src/ui/text.h | 2 |
4 files changed, 35 insertions, 17 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 6c66451c..4132a15e 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -22,6 +22,7 @@ enum iGmLineType { | |||
22 | header1_GmLineType, | 22 | header1_GmLineType, |
23 | header2_GmLineType, | 23 | header2_GmLineType, |
24 | header3_GmLineType, | 24 | header3_GmLineType, |
25 | link_GmLineType, | ||
25 | max_GmLineType, | 26 | max_GmLineType, |
26 | }; | 27 | }; |
27 | 28 | ||
@@ -29,16 +30,19 @@ static enum iGmLineType lineType_Rangecc_(const iRangecc *line) { | |||
29 | if (isEmpty_Range(line)) { | 30 | if (isEmpty_Range(line)) { |
30 | return text_GmLineType; | 31 | return text_GmLineType; |
31 | } | 32 | } |
32 | if (startsWithSc_Rangecc(line, "###", &iCaseSensitive)) { | 33 | if (startsWith_Rangecc(line, "=>")) { |
34 | return link_GmLineType; | ||
35 | } | ||
36 | if (startsWith_Rangecc(line, "###")) { | ||
33 | return header3_GmLineType; | 37 | return header3_GmLineType; |
34 | } | 38 | } |
35 | if (startsWithSc_Rangecc(line, "##", &iCaseSensitive)) { | 39 | if (startsWith_Rangecc(line, "##")) { |
36 | return header2_GmLineType; | 40 | return header2_GmLineType; |
37 | } | 41 | } |
38 | if (startsWithSc_Rangecc(line, "#", &iCaseSensitive)) { | 42 | if (startsWith_Rangecc(line, "#")) { |
39 | return header1_GmLineType; | 43 | return header1_GmLineType; |
40 | } | 44 | } |
41 | if (startsWithSc_Rangecc(line, "```", &iCaseSensitive)) { | 45 | if (startsWith_Rangecc(line, "```")) { |
42 | return preformatted_GmLineType; | 46 | return preformatted_GmLineType; |
43 | } | 47 | } |
44 | if (*line->start == '>') { | 48 | if (*line->start == '>') { |
@@ -51,7 +55,7 @@ static enum iGmLineType lineType_Rangecc_(const iRangecc *line) { | |||
51 | } | 55 | } |
52 | 56 | ||
53 | static void trimLine_Rangecc_(iRangecc *line, enum iGmLineType type) { | 57 | static void trimLine_Rangecc_(iRangecc *line, enum iGmLineType type) { |
54 | static const unsigned int skip[max_GmLineType] = { 0, 2, 3, 1, 1, 2, 3 }; | 58 | static const unsigned int skip[max_GmLineType] = { 0, 2, 3, 1, 1, 2, 3, 0 }; |
55 | line->start += skip[type]; | 59 | line->start += skip[type]; |
56 | trim_Rangecc(line); | 60 | trim_Rangecc(line); |
57 | } | 61 | } |
@@ -98,16 +102,27 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
98 | quote_FontId, | 102 | quote_FontId, |
99 | header1_FontId, | 103 | header1_FontId, |
100 | header2_FontId, | 104 | header2_FontId, |
101 | header3_FontId | 105 | header3_FontId, |
106 | default_FontId, | ||
107 | }; | ||
108 | static const int colors[max_GmLineType] = { | ||
109 | gray75_ColorId, | ||
110 | gray75_ColorId, | ||
111 | orange_ColorId, | ||
112 | orange_ColorId, | ||
113 | white_ColorId, | ||
114 | white_ColorId, | ||
115 | white_ColorId, | ||
116 | white_ColorId, | ||
102 | }; | 117 | }; |
103 | static const int indents[max_GmLineType] = { | 118 | static const int indents[max_GmLineType] = { |
104 | 4, 10, 4, 10, 0, 0, 0 | 119 | 4, 10, 4, 10, 0, 0, 0, 0 |
105 | }; | 120 | }; |
106 | static const float topMargin[max_GmLineType] = { | 121 | static const float topMargin[max_GmLineType] = { |
107 | 0.0f, 0.5f, 1.0f, 0.5f, 2.0f, 1.5f, 1.0f | 122 | 0.0f, 0.5f, 1.0f, 0.5f, 2.0f, 2.0f, 1.5f, 1.0f |
108 | }; | 123 | }; |
109 | static const float bottomMargin[max_GmLineType] = { | 124 | static const float bottomMargin[max_GmLineType] = { |
110 | 0.0f, 0.5f, 1.0f, 0.5f, 1.0f, 1.0f, 1.0f | 125 | 0.0f, 0.5f, 1.0f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f |
111 | }; | 126 | }; |
112 | static const char *bullet = "\u2022"; | 127 | static const char *bullet = "\u2022"; |
113 | iRangecc preAltText = iNullRange; | 128 | iRangecc preAltText = iNullRange; |
@@ -169,6 +184,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
169 | } | 184 | } |
170 | } | 185 | } |
171 | /* List bullet. */ | 186 | /* List bullet. */ |
187 | run.color = colors[type]; | ||
172 | if (type == bullet_GmLineType) { | 188 | if (type == bullet_GmLineType) { |
173 | run.bounds.pos = addX_I2(pos, indent * gap_UI); | 189 | run.bounds.pos = addX_I2(pos, indent * gap_UI); |
174 | run.bounds.size = advance_Text(run.font, bullet); | 190 | run.bounds.size = advance_Text(run.font, bullet); |
@@ -179,6 +195,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
179 | /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */ | 195 | /* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */ |
180 | if (type == text_GmLineType && isFirstText) { | 196 | if (type == text_GmLineType && isFirstText) { |
181 | run.font = firstParagraph_FontId; | 197 | run.font = firstParagraph_FontId; |
198 | run.color = orange_ColorId; | ||
182 | isFirstText = iFalse; | 199 | isFirstText = iFalse; |
183 | } | 200 | } |
184 | else if (type != header1_GmLineType) { | 201 | else if (type != header1_GmLineType) { |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index eae7c00a..56726320 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -195,7 +195,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
195 | d->scrollY = 0; | 195 | d->scrollY = 0; |
196 | } | 196 | } |
197 | const int scrollMax = | 197 | const int scrollMax = |
198 | size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + d->pageMargin * gap_UI; | 198 | size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + 2 * d->pageMargin * gap_UI; |
199 | if (scrollMax > 0) { | 199 | if (scrollMax > 0) { |
200 | d->scrollY = iMin(d->scrollY, scrollMax); | 200 | d->scrollY = iMin(d->scrollY, scrollMax); |
201 | } | 201 | } |
@@ -245,7 +245,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
245 | ctx.bounds.size.x = documentWidth_DocumentWidget_(d); | 245 | ctx.bounds.size.x = documentWidth_DocumentWidget_(d); |
246 | ctx.bounds.pos.x = bounds_Widget(w).size.x / 2 - ctx.bounds.size.x / 2; | 246 | ctx.bounds.pos.x = bounds_Widget(w).size.x / 2 - ctx.bounds.size.x / 2; |
247 | init_Paint(&ctx.paint); | 247 | init_Paint(&ctx.paint); |
248 | drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); | 248 | // drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); |
249 | render_GmDocument( | 249 | render_GmDocument( |
250 | d->doc, | 250 | d->doc, |
251 | (iRangei){ d->scrollY - margin, d->scrollY + height_Rect(ctx.bounds) + margin }, | 251 | (iRangei){ d->scrollY - margin, d->scrollY + height_Rect(ctx.bounds) + margin }, |
diff --git a/src/ui/text.c b/src/ui/text.c index e5045899..d4f46116 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -118,13 +118,13 @@ void init_Text(SDL_Renderer *render) { | |||
118 | /* Load the fonts. */ { | 118 | /* Load the fonts. */ { |
119 | const struct { const iBlock *ttf; int size; } fontData[max_FontId] = { | 119 | const struct { const iBlock *ttf; int size; } fontData[max_FontId] = { |
120 | { &fontFiraSansRegular_Embedded, fontSize_UI }, | 120 | { &fontFiraSansRegular_Embedded, fontSize_UI }, |
121 | { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.85f }, | 121 | { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.866f }, |
122 | { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.65f }, | 122 | { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.666f }, |
123 | { &fontFiraSansRegular_Embedded, fontSize_UI * 1.35f }, | 123 | { &fontFiraSansRegular_Embedded, fontSize_UI * 1.333f }, |
124 | { &fontFiraSansLightItalic_Embedded, fontSize_UI }, | 124 | { &fontFiraSansLightItalic_Embedded, fontSize_UI }, |
125 | { &fontFiraSansBold_Embedded, fontSize_UI }, | 125 | { &fontFiraSansBold_Embedded, fontSize_UI }, |
126 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.35f }, | 126 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.333f }, |
127 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.7f }, | 127 | { &fontFiraSansBold_Embedded, fontSize_UI * 1.666f }, |
128 | { &fontFiraSansBold_Embedded, fontSize_UI * 2.0f }, | 128 | { &fontFiraSansBold_Embedded, fontSize_UI * 2.0f }, |
129 | }; | 129 | }; |
130 | iForIndices(i, fontData) { | 130 | iForIndices(i, fontData) { |
@@ -366,6 +366,7 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
366 | /* Update cache cursor. */ | 366 | /* Update cache cursor. */ |
367 | txt->cachePos.x += glRect->size.x; | 367 | txt->cachePos.x += glRect->size.x; |
368 | txt->cacheRowHeight = iMax(txt->cacheRowHeight, glRect->size.y); | 368 | txt->cacheRowHeight = iMax(txt->cacheRowHeight, glRect->size.y); |
369 | iAssert(txt->cachePos.y + txt->cacheRowHeight <= txt->cacheSize.y); | ||
369 | } | 370 | } |
370 | 371 | ||
371 | static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | 372 | static const iGlyph *glyph_Font_(iFont *d, iChar ch) { |
diff --git a/src/ui/text.h b/src/ui/text.h index 29fc34a4..2181fa34 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -26,7 +26,7 @@ enum iFontId { | |||
26 | quote_FontId = italic_FontId, | 26 | quote_FontId = italic_FontId, |
27 | header1_FontId = hugeBold_FontId, | 27 | header1_FontId = hugeBold_FontId, |
28 | header2_FontId = largeBold_FontId, | 28 | header2_FontId = largeBold_FontId, |
29 | header3_FontId = mediumBold_FontId, | 29 | header3_FontId = medium_FontId, |
30 | uiShortcuts_FontId = default_FontId, | 30 | uiShortcuts_FontId = default_FontId, |
31 | }; | 31 | }; |
32 | 32 | ||