summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gmdocument.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 2c12a5a9..67dcf555 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -12,6 +12,42 @@ struct Impl_GmDocument {
12 12
13iDefineObjectConstruction(GmDocument) 13iDefineObjectConstruction(GmDocument)
14 14
15enum iGmLineType {
16 text_GmLineType,
17 bullet_GmLineType,
18 preformatted_GmLineType,
19 quote_GmLineType,
20 header1_GmLineType,
21 header2_GmLineType,
22 header3_GmLineType,
23 max_GmLineType,
24};
25
26static enum iGmLineType lineType_Rangecc_(const iRangecc *line) {
27 if (isEmpty_Range(line)) {
28 return text_GmLineType;
29 }
30 if (startsWithSc_Rangecc(line, "###", &iCaseSensitive)) {
31 return header3_GmLineType;
32 }
33 if (startsWithSc_Rangecc(line, "##", &iCaseSensitive)) {
34 return header2_GmLineType;
35 }
36 if (startsWithSc_Rangecc(line, "#", &iCaseSensitive)) {
37 return header1_GmLineType;
38 }
39 if (startsWithSc_Rangecc(line, "```", &iCaseSensitive)) {
40 return preformatted_GmLineType;
41 }
42 if (*line->start == '>') {
43 return quote_GmLineType;
44 }
45 if (size_Range(line) >= 2 && line->start[0] == '*' && isspace(line->start[1])) {
46 return bullet_GmLineType;
47 }
48 return text_GmLineType;
49}
50
15static void doLayout_GmDocument_(iGmDocument *d) { 51static void doLayout_GmDocument_(iGmDocument *d) {
16 if (d->size.x <= 0 || isEmpty_String(&d->source)) { 52 if (d->size.x <= 0 || isEmpty_String(&d->source)) {
17 return; 53 return;
@@ -21,10 +57,20 @@ static void doLayout_GmDocument_(iGmDocument *d) {
21 iInt2 pos = zero_I2(); 57 iInt2 pos = zero_I2();
22 const iRangecc content = range_String(&d->source); 58 const iRangecc content = range_String(&d->source);
23 iRangecc line = iNullRange; 59 iRangecc line = iNullRange;
60 const int fonts[max_GmLineType] = {
61 paragraph_FontId,
62 paragraph_FontId,
63 preformatted_FontId,
64 quote_FontId,
65 header1_FontId,
66 header2_FontId,
67 header3_FontId
68 };
24 while (nextSplit_Rangecc(&content, "\n", &line)) { 69 while (nextSplit_Rangecc(&content, "\n", &line)) {
70 enum iGmLineType type = lineType_Rangecc_(&line);
25 iGmRun run; 71 iGmRun run;
26 run.text = line; 72 run.text = line;
27 run.font = paragraph_FontId; 73 run.font = fonts[type];
28 run.color = white_ColorId; 74 run.color = white_ColorId;
29 run.bounds.pos = pos; 75 run.bounds.pos = pos;
30 run.bounds.size = advanceN_Text(run.font, line.start, size_Range(&line)); 76 run.bounds.size = advanceN_Text(run.font, line.start, size_Range(&line));