summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--res/KosugiMaru-Regular.ttfbin0 -> 2558264 bytes
-rw-r--r--res/LICENSE_KosugiMaru.txt202
-rw-r--r--res/LICENSE_Nunito.txt (renamed from res/OFL.txt)0
-rw-r--r--res/about/help.gmi1
-rw-r--r--src/ui/text.c55
-rw-r--r--src/ui/text.h13
7 files changed, 259 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f0968831..2d7128ed 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ set (EMBED_RESOURCES
41 res/FiraSans-Italic.ttf 41 res/FiraSans-Italic.ttf
42 res/FiraSans-Light.ttf 42 res/FiraSans-Light.ttf
43 res/FiraSans-Regular.ttf 43 res/FiraSans-Regular.ttf
44 res/KosugiMaru-Regular.ttf
44 res/NotoEmoji-Regular.ttf 45 res/NotoEmoji-Regular.ttf
45 res/Nunito-ExtraBold.ttf 46 res/Nunito-ExtraBold.ttf
46 res/Nunito-ExtraLight.ttf 47 res/Nunito-ExtraLight.ttf
diff --git a/res/KosugiMaru-Regular.ttf b/res/KosugiMaru-Regular.ttf
new file mode 100644
index 00000000..44dcbff6
--- /dev/null
+++ b/res/KosugiMaru-Regular.ttf
Binary files differ
diff --git a/res/LICENSE_KosugiMaru.txt b/res/LICENSE_KosugiMaru.txt
new file mode 100644
index 00000000..75b52484
--- /dev/null
+++ b/res/LICENSE_KosugiMaru.txt
@@ -0,0 +1,202 @@
1
2 Apache License
3 Version 2.0, January 2004
4 http://www.apache.org/licenses/
5
6 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
8 1. Definitions.
9
10 "License" shall mean the terms and conditions for use, reproduction,
11 and distribution as defined by Sections 1 through 9 of this document.
12
13 "Licensor" shall mean the copyright owner or entity authorized by
14 the copyright owner that is granting the License.
15
16 "Legal Entity" shall mean the union of the acting entity and all
17 other entities that control, are controlled by, or are under common
18 control with that entity. For the purposes of this definition,
19 "control" means (i) the power, direct or indirect, to cause the
20 direction or management of such entity, whether by contract or
21 otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 outstanding shares, or (iii) beneficial ownership of such entity.
23
24 "You" (or "Your") shall mean an individual or Legal Entity
25 exercising permissions granted by this License.
26
27 "Source" form shall mean the preferred form for making modifications,
28 including but not limited to software source code, documentation
29 source, and configuration files.
30
31 "Object" form shall mean any form resulting from mechanical
32 transformation or translation of a Source form, including but
33 not limited to compiled object code, generated documentation,
34 and conversions to other media types.
35
36 "Work" shall mean the work of authorship, whether in Source or
37 Object form, made available under the License, as indicated by a
38 copyright notice that is included in or attached to the work
39 (an example is provided in the Appendix below).
40
41 "Derivative Works" shall mean any work, whether in Source or Object
42 form, that is based on (or derived from) the Work and for which the
43 editorial revisions, annotations, elaborations, or other modifications
44 represent, as a whole, an original work of authorship. For the purposes
45 of this License, Derivative Works shall not include works that remain
46 separable from, or merely link (or bind by name) to the interfaces of,
47 the Work and Derivative Works thereof.
48
49 "Contribution" shall mean any work of authorship, including
50 the original version of the Work and any modifications or additions
51 to that Work or Derivative Works thereof, that is intentionally
52 submitted to Licensor for inclusion in the Work by the copyright owner
53 or by an individual or Legal Entity authorized to submit on behalf of
54 the copyright owner. For the purposes of this definition, "submitted"
55 means any form of electronic, verbal, or written communication sent
56 to the Licensor or its representatives, including but not limited to
57 communication on electronic mailing lists, source code control systems,
58 and issue tracking systems that are managed by, or on behalf of, the
59 Licensor for the purpose of discussing and improving the Work, but
60 excluding communication that is conspicuously marked or otherwise
61 designated in writing by the copyright owner as "Not a Contribution."
62
63 "Contributor" shall mean Licensor and any individual or Legal Entity
64 on behalf of whom a Contribution has been received by Licensor and
65 subsequently incorporated within the Work.
66
67 2. Grant of Copyright License. Subject to the terms and conditions of
68 this License, each Contributor hereby grants to You a perpetual,
69 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 copyright license to reproduce, prepare Derivative Works of,
71 publicly display, publicly perform, sublicense, and distribute the
72 Work and such Derivative Works in Source or Object form.
73
74 3. Grant of Patent License. Subject to the terms and conditions of
75 this License, each Contributor hereby grants to You a perpetual,
76 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 (except as stated in this section) patent license to make, have made,
78 use, offer to sell, sell, import, and otherwise transfer the Work,
79 where such license applies only to those patent claims licensable
80 by such Contributor that are necessarily infringed by their
81 Contribution(s) alone or by combination of their Contribution(s)
82 with the Work to which such Contribution(s) was submitted. If You
83 institute patent litigation against any entity (including a
84 cross-claim or counterclaim in a lawsuit) alleging that the Work
85 or a Contribution incorporated within the Work constitutes direct
86 or contributory patent infringement, then any patent licenses
87 granted to You under this License for that Work shall terminate
88 as of the date such litigation is filed.
89
90 4. Redistribution. You may reproduce and distribute copies of the
91 Work or Derivative Works thereof in any medium, with or without
92 modifications, and in Source or Object form, provided that You
93 meet the following conditions:
94
95 (a) You must give any other recipients of the Work or
96 Derivative Works a copy of this License; and
97
98 (b) You must cause any modified files to carry prominent notices
99 stating that You changed the files; and
100
101 (c) You must retain, in the Source form of any Derivative Works
102 that You distribute, all copyright, patent, trademark, and
103 attribution notices from the Source form of the Work,
104 excluding those notices that do not pertain to any part of
105 the Derivative Works; and
106
107 (d) If the Work includes a "NOTICE" text file as part of its
108 distribution, then any Derivative Works that You distribute must
109 include a readable copy of the attribution notices contained
110 within such NOTICE file, excluding those notices that do not
111 pertain to any part of the Derivative Works, in at least one
112 of the following places: within a NOTICE text file distributed
113 as part of the Derivative Works; within the Source form or
114 documentation, if provided along with the Derivative Works; or,
115 within a display generated by the Derivative Works, if and
116 wherever such third-party notices normally appear. The contents
117 of the NOTICE file are for informational purposes only and
118 do not modify the License. You may add Your own attribution
119 notices within Derivative Works that You distribute, alongside
120 or as an addendum to the NOTICE text from the Work, provided
121 that such additional attribution notices cannot be construed
122 as modifying the License.
123
124 You may add Your own copyright statement to Your modifications and
125 may provide additional or different license terms and conditions
126 for use, reproduction, or distribution of Your modifications, or
127 for any such Derivative Works as a whole, provided Your use,
128 reproduction, and distribution of the Work otherwise complies with
129 the conditions stated in this License.
130
131 5. Submission of Contributions. Unless You explicitly state otherwise,
132 any Contribution intentionally submitted for inclusion in the Work
133 by You to the Licensor shall be under the terms and conditions of
134 this License, without any additional terms or conditions.
135 Notwithstanding the above, nothing herein shall supersede or modify
136 the terms of any separate license agreement you may have executed
137 with Licensor regarding such Contributions.
138
139 6. Trademarks. This License does not grant permission to use the trade
140 names, trademarks, service marks, or product names of the Licensor,
141 except as required for reasonable and customary use in describing the
142 origin of the Work and reproducing the content of the NOTICE file.
143
144 7. Disclaimer of Warranty. Unless required by applicable law or
145 agreed to in writing, Licensor provides the Work (and each
146 Contributor provides its Contributions) on an "AS IS" BASIS,
147 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 implied, including, without limitation, any warranties or conditions
149 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 PARTICULAR PURPOSE. You are solely responsible for determining the
151 appropriateness of using or redistributing the Work and assume any
152 risks associated with Your exercise of permissions under this License.
153
154 8. Limitation of Liability. In no event and under no legal theory,
155 whether in tort (including negligence), contract, or otherwise,
156 unless required by applicable law (such as deliberate and grossly
157 negligent acts) or agreed to in writing, shall any Contributor be
158 liable to You for damages, including any direct, indirect, special,
159 incidental, or consequential damages of any character arising as a
160 result of this License or out of the use or inability to use the
161 Work (including but not limited to damages for loss of goodwill,
162 work stoppage, computer failure or malfunction, or any and all
163 other commercial damages or losses), even if such Contributor
164 has been advised of the possibility of such damages.
165
166 9. Accepting Warranty or Additional Liability. While redistributing
167 the Work or Derivative Works thereof, You may choose to offer,
168 and charge a fee for, acceptance of support, warranty, indemnity,
169 or other liability obligations and/or rights consistent with this
170 License. However, in accepting such obligations, You may act only
171 on Your own behalf and on Your sole responsibility, not on behalf
172 of any other Contributor, and only if You agree to indemnify,
173 defend, and hold each Contributor harmless for any liability
174 incurred by, or claims asserted against, such Contributor by reason
175 of your accepting any such warranty or additional liability.
176
177 END OF TERMS AND CONDITIONS
178
179 APPENDIX: How to apply the Apache License to your work.
180
181 To apply the Apache License to your work, attach the following
182 boilerplate notice, with the fields enclosed by brackets "[]"
183 replaced with your own identifying information. (Don't include
184 the brackets!) The text should be enclosed in the appropriate
185 comment syntax for the file format. We also recommend that a
186 file or class name and description of purpose be included on the
187 same "printed page" as the copyright notice for easier
188 identification within third-party archives.
189
190 Copyright [yyyy] [name of copyright owner]
191
192 Licensed under the Apache License, Version 2.0 (the "License");
193 you may not use this file except in compliance with the License.
194 You may obtain a copy of the License at
195
196 http://www.apache.org/licenses/LICENSE-2.0
197
198 Unless required by applicable law or agreed to in writing, software
199 distributed under the License is distributed on an "AS IS" BASIS,
200 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 See the License for the specific language governing permissions and
202 limitations under the License.
diff --git a/res/OFL.txt b/res/LICENSE_Nunito.txt
index 165d2489..165d2489 100644
--- a/res/OFL.txt
+++ b/res/LICENSE_Nunito.txt
diff --git a/res/about/help.gmi b/res/about/help.gmi
index 1be94132..9f394e5a 100644
--- a/res/about/help.gmi
+++ b/res/about/help.gmi
@@ -199,5 +199,6 @@ This application uses fonts licensed under the Open Font License.
199 199
200Additional fonts: 200Additional fonts:
201 201
202=> https://fonts.google.com/specimen/Kosugi+Maru#license Kosugi Maru (Apache License 2.0)
202=> https://github.com/googlefonts/noto-emoji/blob/master/LICENSE Noto Emoji (Apache License 2.0) 203=> https://github.com/googlefonts/noto-emoji/blob/master/LICENSE Noto Emoji (Apache License 2.0)
203=> https://dn-works.com/ufas/ Symbola (Public Domain) \ No newline at end of file 204=> https://dn-works.com/ufas/ Symbola (Public Domain) \ No newline at end of file
diff --git a/src/ui/text.c b/src/ui/text.c
index 3de1c83b..a48d0e0e 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -92,6 +92,7 @@ struct Impl_Font {
92 iBool isMonospaced; 92 iBool isMonospaced;
93 iBool manualKernOnly; 93 iBool manualKernOnly;
94 enum iFontId symbolsFont; /* font to use for symbols */ 94 enum iFontId symbolsFont; /* font to use for symbols */
95 enum iFontId japaneseFont; /* font to use for Japanese glyphs */
95 uint32_t indexTable[128 - 32]; 96 uint32_t indexTable[128 - 32];
96}; 97};
97 98
@@ -108,6 +109,7 @@ static void init_Font(iFont *d, const iBlock *data, int height, enum iFontId sym
108 stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL); 109 stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL);
109 d->baseline = (int) ascent * d->scale; 110 d->baseline = (int) ascent * d->scale;
110 d->symbolsFont = symbolsFont; 111 d->symbolsFont = symbolsFont;
112 d->japaneseFont = regularJapanese_FontId;
111 d->isMonospaced = iFalse; 113 d->isMonospaced = iFalse;
112 memset(d->indexTable, 0xff, sizeof(d->indexTable)); 114 memset(d->indexTable, 0xff, sizeof(d->indexTable));
113} 115}
@@ -189,6 +191,11 @@ static void initFonts_Text_(iText *d) {
189 { &fontNotoEmojiRegular_Embedded, textSize * 1.666f, largeSymbols_FontId }, 191 { &fontNotoEmojiRegular_Embedded, textSize * 1.666f, largeSymbols_FontId },
190 { &fontNotoEmojiRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId }, 192 { &fontNotoEmojiRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId },
191 { &fontNotoEmojiRegular_Embedded, textSize * 0.866f, smallSymbols_FontId }, 193 { &fontNotoEmojiRegular_Embedded, textSize * 0.866f, smallSymbols_FontId },
194 { &fontKosugiMaruRegular_Embedded, textSize * 0.666f, smallSymbols_FontId },
195 { &fontKosugiMaruRegular_Embedded, textSize, symbols_FontId },
196 { &fontKosugiMaruRegular_Embedded, textSize * 1.333f, mediumSymbols_FontId },
197 { &fontKosugiMaruRegular_Embedded, textSize * 1.666f, largeSymbols_FontId },
198 { &fontKosugiMaruRegular_Embedded, textSize * 2.000f, hugeSymbols_FontId },
192 }; 199 };
193 iForIndices(i, fontData) { 200 iForIndices(i, fontData) {
194 iFont *font = &d->fonts[i]; 201 iFont *font = &d->fonts[i];
@@ -200,6 +207,18 @@ static void initFonts_Text_(iText *d) {
200 font->manualKernOnly = iTrue; 207 font->manualKernOnly = iTrue;
201 } 208 }
202 } 209 }
210 /* Japanese script. */ {
211 /* Everything defaults to the regular sized japanese font, so these are just
212 the other sizes. */
213 /* TODO: Add these to the table above... */
214 font_Text_(monospace_FontId)->japaneseFont = smallJapanese_FontId;
215 font_Text_(monospaceSmall_FontId)->japaneseFont = smallJapanese_FontId;
216 font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId;
217 font_Text_(mediumBold_FontId)->japaneseFont = mediumJapanese_FontId;
218 font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId;
219 font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId;
220 font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId;
221 }
203 gap_Text = iRound(gap_UI * d->contentFontSize); 222 gap_Text = iRound(gap_UI * d->contentFontSize);
204} 223}
205 224
@@ -344,13 +363,19 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) {
344 SDL_Renderer *render = txt->render; 363 SDL_Renderer *render = txt->render;
345 SDL_Texture *tex = NULL; 364 SDL_Texture *tex = NULL;
346 SDL_Surface *surface = NULL; 365 SDL_Surface *surface = NULL;
347 const iChar ch = char_Glyph(glyph);
348 iRect *glRect = &glyph->rect[hoff]; 366 iRect *glRect = &glyph->rect[hoff];
349 /* Rasterize the glyph using stbtt. */ { 367 /* Rasterize the glyph using stbtt. */ {
350 surface = rasterizeGlyph_Font_(d, glyph->glyphIndex, hoff * 0.5f); 368 surface = rasterizeGlyph_Font_(d, glyph->glyphIndex, hoff * 0.5f);
351 if (hoff == 0) { 369 if (hoff == 0) {
352 int adv; 370 int adv;
353 stbtt_GetGlyphHMetrics(&d->font, glyph->glyphIndex, &adv, NULL); 371 const uint32_t gIndex = glyph->glyphIndex;
372// float advScale = d->scale;
373// if (isJapanese_FontId(d - text_.fonts)) {
374 /* Treat as monospace. */
375// gIndex = stbtt_FindGlyphIndex(&d->font, 0x5712);
376// advScale *= 2.0f;
377// }
378 stbtt_GetGlyphHMetrics(&d->font, gIndex, &adv, NULL);
354 glyph->advance = d->scale * adv; 379 glyph->advance = d->scale * adv;
355 } 380 }
356 stbtt_GetGlyphBitmapBoxSubpixel(&d->font, 381 stbtt_GetGlyphBitmapBoxSubpixel(&d->font,
@@ -389,6 +414,13 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) {
389 return emoji; 414 return emoji;
390 } 415 }
391 } 416 }
417 /* Japanese perhaps? */
418 if (ch > 0x3040) {
419 iFont *japanese = font_Text_(d->japaneseFont);
420 if (japanese != d && (*glyphIndex = glyphIndex_Font_(japanese, ch)) != 0) {
421 return japanese;
422 }
423 }
392 /* Fall back to Symbola for anything else. */ 424 /* Fall back to Symbola for anything else. */
393 iFont *font = font_Text_(d->symbolsFont); 425 iFont *font = font_Text_(d->symbolsFont);
394 *glyphIndex = glyphIndex_Font_(font, ch); 426 *glyphIndex = glyphIndex_Font_(font, ch);
@@ -437,6 +469,10 @@ static iChar nextChar_(const char **chPos, const char *end) {
437 return ch; 469 return ch;
438} 470}
439 471
472static enum iFontId fontId_Text_(const iFont *font) {
473 return font - text_.fonts;
474}
475
440iLocalDef iBool isWrapBoundary_(iChar a, iChar b) { 476iLocalDef iBool isWrapBoundary_(iChar a, iChar b) {
441 if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':') { 477 if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':') {
442 return iTrue; 478 return iTrue;
@@ -540,29 +576,24 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
540 SDL_RenderCopy(text_.render, text_.cache, (const SDL_Rect *) &glyph->rect[hoff], &dst); 576 SDL_RenderCopy(text_.render, text_.cache, (const SDL_Rect *) &glyph->rect[hoff], &dst);
541 } 577 }
542 /* Symbols and emojis are NOT monospaced, so must conform when the primary font 578 /* Symbols and emojis are NOT monospaced, so must conform when the primary font
543 is monospaced. */ 579 is monospaced. Except with Japanese script, that's larger than the normal monospace. */
544 xpos += (d->isMonospaced && glyph->font != d ? monoAdvance : glyph->advance); 580 xpos += (monoAdvance > 0 && !isJapanese_FontId(fontId_Text_(glyph->font)) ? monoAdvance
581 : glyph->advance);
545 xposMax = iMax(xposMax, xpos); 582 xposMax = iMax(xposMax, xpos);
546 if (continueFrom_out && (mode == measureNoWrap_RunMode || isWrapBoundary_(prevCh, ch))) { 583 if (continueFrom_out && (mode == measureNoWrap_RunMode || isWrapBoundary_(prevCh, ch))) {
547 lastWordEnd = chPos; 584 lastWordEnd = chPos;
548 } 585 }
586#if defined (LAGRANGE_ENABLE_KERNING)
549 /* Check the next character. */ 587 /* Check the next character. */
550 if (!d->isMonospaced && glyph->font == d) { 588 if (!d->isMonospaced && glyph->font == d) {
551 /* TODO: No need to decode the next char twice; check this on the next iteration. */ 589 /* TODO: No need to decode the next char twice; check this on the next iteration. */
552 const char *peek = chPos; 590 const char *peek = chPos;
553 const iChar next = nextChar_(&peek, text.end); 591 const iChar next = nextChar_(&peek, text.end);
554#if 0
555 if (ch == '/' && next == '/') {
556 /* Manual kerning for double-slash. */
557 xpos -= glyph->rect[hoff].size.x * 0.5f;
558 } else
559#endif
560#if defined (LAGRANGE_ENABLE_KERNING)
561 if (enableKerning_Text && !d->manualKernOnly && next) { 592 if (enableKerning_Text && !d->manualKernOnly && next) {
562 xpos += d->scale * stbtt_GetGlyphKernAdvance(&d->font, glyph->glyphIndex, next); 593 xpos += d->scale * stbtt_GetGlyphKernAdvance(&d->font, glyph->glyphIndex, next);
563 } 594 }
564#endif
565 } 595 }
596#endif
566 prevCh = ch; 597 prevCh = ch;
567 if (--maxLen == 0) { 598 if (--maxLen == 0) {
568 break; 599 break;
diff --git a/src/ui/text.h b/src/ui/text.h
index 2b4ec5c3..9a22620f 100644
--- a/src/ui/text.h
+++ b/src/ui/text.h
@@ -40,7 +40,7 @@ enum iFontId {
40 mediumBold_FontId, 40 mediumBold_FontId,
41 largeBold_FontId, 41 largeBold_FontId,
42 hugeBold_FontId, 42 hugeBold_FontId,
43 largeLight_FontId, 43 largeLight_FontId,
44 /* symbol fonts */ 44 /* symbol fonts */
45 defaultSymbols_FontId, 45 defaultSymbols_FontId,
46 defaultMediumSymbols_FontId, 46 defaultMediumSymbols_FontId,
@@ -57,10 +57,17 @@ enum iFontId {
57 largeEmoji_FontId, 57 largeEmoji_FontId,
58 hugeEmoji_FontId, 58 hugeEmoji_FontId,
59 smallEmoji_FontId, 59 smallEmoji_FontId,
60 /* japanese script */
61 smallJapanese_FontId,
62 regularJapanese_FontId,
63 mediumJapanese_FontId,
64 largeJapanese_FontId,
65 hugeJapanese_FontId,
60 max_FontId, 66 max_FontId,
61 67
62 /* Meta: */ 68 /* Meta: */
63 fromSymbolsToEmojiOffset_FontId = 7, 69 fromSymbolsToEmojiOffset_FontId = 7,
70
64 /* UI fonts: */ 71 /* UI fonts: */
65 uiLabel_FontId = default_FontId, 72 uiLabel_FontId = default_FontId,
66 uiShortcuts_FontId = default_FontId, 73 uiShortcuts_FontId = default_FontId,
@@ -78,6 +85,10 @@ enum iFontId {
78 banner_FontId = largeLight_FontId, 85 banner_FontId = largeLight_FontId,
79}; 86};
80 87
88iLocalDef iBool isJapanese_FontId(enum iFontId id) {
89 return id >= smallJapanese_FontId && id <= hugeJapanese_FontId;
90}
91
81#define variationSelectorEmoji_Char ((iChar) 0xfe0f) 92#define variationSelectorEmoji_Char ((iChar) 0xfe0f)
82 93
83extern int gap_Text; /* affected by content font size */ 94extern int gap_Text; /* affected by content font size */