summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index a48d0e0e..8d4661ac 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -167,33 +167,45 @@ static void initFonts_Text_(iText *d) {
167 { &fontSourceSansProRegular_Embedded, fontSize_UI, defaultSymbols_FontId }, 167 { &fontSourceSansProRegular_Embedded, fontSize_UI, defaultSymbols_FontId },
168 { &fontSourceSansProRegular_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId }, 168 { &fontSourceSansProRegular_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId },
169 { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.866f, defaultSymbols_FontId }, 169 { &fontFiraMonoRegular_Embedded, fontSize_UI * 0.866f, defaultSymbols_FontId },
170 /* content fonts */
170 { &fontNunitoRegular_Embedded, textSize, symbols_FontId }, 171 { &fontNunitoRegular_Embedded, textSize, symbols_FontId },
171 { &fontFiraMonoRegular_Embedded, monoSize, smallSymbols_FontId }, 172 { &fontFiraMonoRegular_Embedded, monoSize, monospaceSymbols_FontId },
172 { &fontFiraMonoRegular_Embedded, monoSize * 0.750f, smallSymbols_FontId }, 173 { &fontFiraMonoRegular_Embedded, monoSize * 0.750f, monospaceSmallSymbols_FontId },
173 { &fontNunitoRegular_Embedded, textSize * 1.333f, mediumSymbols_FontId }, 174 { &fontNunitoRegular_Embedded, textSize * 1.200f, mediumSymbols_FontId },
175 { &fontNunitoRegular_Embedded, textSize * 1.333f, bigSymbols_FontId },
174 { &fontNunitoLightItalic_Embedded, textSize, symbols_FontId }, 176 { &fontNunitoLightItalic_Embedded, textSize, symbols_FontId },
175 { &fontNunitoExtraBold_Embedded, textSize, symbols_FontId }, 177 { &fontNunitoExtraBold_Embedded, textSize, symbols_FontId },
176 { &fontNunitoExtraBold_Embedded, textSize * 1.333f, mediumSymbols_FontId }, 178 { &fontNunitoExtraBold_Embedded, textSize * 1.333f, mediumSymbols_FontId },
177 { &fontNunitoExtraBold_Embedded, textSize * 1.666f, largeSymbols_FontId }, 179 { &fontNunitoExtraBold_Embedded, textSize * 1.666f, largeSymbols_FontId },
178 { &fontNunitoExtraBold_Embedded, textSize * 2.000f, hugeSymbols_FontId }, 180 { &fontNunitoExtraBold_Embedded, textSize * 2.000f, hugeSymbols_FontId },
179 { &fontNunitoExtraLight_Embedded, textSize * 1.666f, largeSymbols_FontId }, 181 { &fontNunitoExtraLight_Embedded, textSize * 1.666f, largeSymbols_FontId },
182 /* symbol fonts */
180 { &fontSymbola_Embedded, fontSize_UI, defaultSymbols_FontId }, 183 { &fontSymbola_Embedded, fontSize_UI, defaultSymbols_FontId },
181 { &fontSymbola_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId }, 184 { &fontSymbola_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId },
182 { &fontSymbola_Embedded, textSize, symbols_FontId }, 185 { &fontSymbola_Embedded, textSize, symbols_FontId },
183 { &fontSymbola_Embedded, textSize * 1.333f, mediumSymbols_FontId }, 186 { &fontSymbola_Embedded, textSize * 1.200f, mediumSymbols_FontId },
187 { &fontSymbola_Embedded, textSize * 1.333f, bigSymbols_FontId },
184 { &fontSymbola_Embedded, textSize * 1.666f, largeSymbols_FontId }, 188 { &fontSymbola_Embedded, textSize * 1.666f, largeSymbols_FontId },
185 { &fontSymbola_Embedded, textSize * 2.000f, hugeSymbols_FontId }, 189 { &fontSymbola_Embedded, textSize * 2.000f, hugeSymbols_FontId },
186 { &fontSymbola_Embedded, textSize * 0.866f, smallSymbols_FontId }, 190 { &fontSymbola_Embedded, monoSize, monospaceSymbols_FontId },
191 { &fontSymbola_Embedded, monoSize * 0.750f, monospaceSmallSymbols_FontId },
192 /* emoji fonts */
187 { &fontNotoEmojiRegular_Embedded, fontSize_UI, defaultSymbols_FontId }, 193 { &fontNotoEmojiRegular_Embedded, fontSize_UI, defaultSymbols_FontId },
188 { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId }, 194 { &fontNotoEmojiRegular_Embedded, fontSize_UI * 1.125f, defaultMediumSymbols_FontId },
189 { &fontNotoEmojiRegular_Embedded, textSize, symbols_FontId }, 195 { &fontNotoEmojiRegular_Embedded, textSize, symbols_FontId },
190 { &fontNotoEmojiRegular_Embedded, textSize * 1.333f, mediumSymbols_FontId }, 196 { &fontNotoEmojiRegular_Embedded, textSize * 1.200f, mediumSymbols_FontId },
197 { &fontNotoEmojiRegular_Embedded, textSize * 1.333f, bigSymbols_FontId },
191 { &fontNotoEmojiRegular_Embedded, textSize * 1.666f, largeSymbols_FontId }, 198 { &fontNotoEmojiRegular_Embedded, textSize * 1.666f, largeSymbols_FontId },
192 { &fontNotoEmojiRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId }, 199 { &fontNotoEmojiRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId },
193 { &fontNotoEmojiRegular_Embedded, textSize * 0.866f, smallSymbols_FontId }, 200 { &fontNotoEmojiRegular_Embedded, monoSize, monospaceSymbols_FontId },
194 { &fontKosugiMaruRegular_Embedded, textSize * 0.666f, smallSymbols_FontId }, 201 { &fontNotoEmojiRegular_Embedded, monoSize * 0.750f, monospaceSmallSymbols_FontId },
202 /* japanese fonts */
203 { &fontKosugiMaruRegular_Embedded, fontSize_UI, defaultSymbols_FontId },
204 { &fontKosugiMaruRegular_Embedded, monoSize * 0.750, monospaceSmallSymbols_FontId },
205 { &fontKosugiMaruRegular_Embedded, monoSize, monospaceSymbols_FontId },
195 { &fontKosugiMaruRegular_Embedded, textSize, symbols_FontId }, 206 { &fontKosugiMaruRegular_Embedded, textSize, symbols_FontId },
196 { &fontKosugiMaruRegular_Embedded, textSize * 1.333f, mediumSymbols_FontId }, 207 { &fontKosugiMaruRegular_Embedded, textSize * 1.200f, mediumSymbols_FontId },
208 { &fontKosugiMaruRegular_Embedded, textSize * 1.333f, bigSymbols_FontId },
197 { &fontKosugiMaruRegular_Embedded, textSize * 1.666f, largeSymbols_FontId }, 209 { &fontKosugiMaruRegular_Embedded, textSize * 1.666f, largeSymbols_FontId },
198 { &fontKosugiMaruRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId }, 210 { &fontKosugiMaruRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId },
199 }; 211 };
@@ -211,13 +223,17 @@ static void initFonts_Text_(iText *d) {
211 /* Everything defaults to the regular sized japanese font, so these are just 223 /* Everything defaults to the regular sized japanese font, so these are just
212 the other sizes. */ 224 the other sizes. */
213 /* TODO: Add these to the table above... */ 225 /* TODO: Add these to the table above... */
214 font_Text_(monospace_FontId)->japaneseFont = smallJapanese_FontId; 226 font_Text_(default_FontId)->japaneseFont = defaultJapanese_FontId;
215 font_Text_(monospaceSmall_FontId)->japaneseFont = smallJapanese_FontId; 227 font_Text_(defaultMedium_FontId)->japaneseFont = defaultJapanese_FontId;
216 font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId; 228 font_Text_(defaultMonospace_FontId)->japaneseFont = defaultJapanese_FontId;
217 font_Text_(mediumBold_FontId)->japaneseFont = mediumJapanese_FontId; 229 font_Text_(monospaceSmall_FontId)->japaneseFont = monospaceSmallJapanese_FontId;
218 font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId; 230 font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId;
219 font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId; 231 font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId;
220 font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId; 232 font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId;
233 font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId;
234 font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId;
235 font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId;
236 font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId;
221 } 237 }
222 gap_Text = iRound(gap_UI * d->contentFontSize); 238 gap_Text = iRound(gap_UI * d->contentFontSize);
223} 239}
@@ -520,8 +536,8 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
520 } 536 }
521 } 537 }
522 iChar ch = nextChar_(&chPos, text.end); 538 iChar ch = nextChar_(&chPos, text.end);
523 if (ch == variationSelectorEmoji_Char) { 539 if (isVariationSelector_Char(ch)) {
524 /* TODO: Should peek ahead for this and prefer the Emoji font. */ 540 /* TODO: VS15: Should peek ahead for this and prefer the Emoji font. */
525 ch = nextChar_(&chPos, text.end); /* just ignore */ 541 ch = nextChar_(&chPos, text.end); /* just ignore */
526 } 542 }
527 /* Special instructions. */ { 543 /* Special instructions. */ {
@@ -555,10 +571,10 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
555 } 571 }
556 break; 572 break;
557 } 573 }
558 const SDL_Rect dst = { x1 + glyph->d[hoff].x, 574 SDL_Rect dst = { x1 + glyph->d[hoff].x,
559 pos.y + glyph->font->baseline + glyph->d[hoff].y, 575 pos.y + glyph->font->baseline + glyph->d[hoff].y,
560 glyph->rect[hoff].size.x, 576 glyph->rect[hoff].size.x,
561 glyph->rect[hoff].size.y }; 577 glyph->rect[hoff].size.y };
562 /* Update the bounding box. */ 578 /* Update the bounding box. */
563 if (mode == measureVisual_RunMode) { 579 if (mode == measureVisual_RunMode) {
564 if (isEmpty_Rect(bounds)) { 580 if (isEmpty_Rect(bounds)) {
@@ -572,13 +588,19 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
572 bounds.size.x = iMax(bounds.size.x, x2 - orig.x); 588 bounds.size.x = iMax(bounds.size.x, x2 - orig.x);
573 bounds.size.y = iMax(bounds.size.y, pos.y + glyph->font->height - orig.y); 589 bounds.size.y = iMax(bounds.size.y, pos.y + glyph->font->height - orig.y);
574 } 590 }
591 const iBool useMonoAdvance =
592 monoAdvance > 0 && !isJapanese_FontId(fontId_Text_(glyph->font));
593 const float advance = (useMonoAdvance ? monoAdvance : glyph->advance);
575 if (!isMeasuring_(mode)) { 594 if (!isMeasuring_(mode)) {
595 if (useMonoAdvance && dst.w > advance) {
596 dst.x -= (dst.w - advance) / 2;
597
598 }
576 SDL_RenderCopy(text_.render, text_.cache, (const SDL_Rect *) &glyph->rect[hoff], &dst); 599 SDL_RenderCopy(text_.render, text_.cache, (const SDL_Rect *) &glyph->rect[hoff], &dst);
577 } 600 }
578 /* Symbols and emojis are NOT monospaced, so must conform when the primary font 601 /* Symbols and emojis are NOT monospaced, so must conform when the primary font
579 is monospaced. Except with Japanese script, that's larger than the normal monospace. */ 602 is monospaced. Except with Japanese script, that's larger than the normal monospace. */
580 xpos += (monoAdvance > 0 && !isJapanese_FontId(fontId_Text_(glyph->font)) ? monoAdvance 603 xpos += advance;
581 : glyph->advance);
582 xposMax = iMax(xposMax, xpos); 604 xposMax = iMax(xposMax, xpos);
583 if (continueFrom_out && (mode == measureNoWrap_RunMode || isWrapBoundary_(prevCh, ch))) { 605 if (continueFrom_out && (mode == measureNoWrap_RunMode || isWrapBoundary_(prevCh, ch))) {
584 lastWordEnd = chPos; 606 lastWordEnd = chPos;