diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-05 06:55:51 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-05 06:55:51 +0300 |
commit | 827951d2807b031d131b7fc05b1596550d258676 (patch) | |
tree | 836a6a1ceb07cfbc1867ef65fcc30331b0ad33ba /src/fontpack.h | |
parent | 88993e95e5ff9fecc5980b25e1778053ca23afe0 (diff) |
Started working on font packs
Diffstat (limited to 'src/fontpack.h')
-rw-r--r-- | src/fontpack.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/fontpack.h b/src/fontpack.h new file mode 100644 index 00000000..7e78071f --- /dev/null +++ b/src/fontpack.h | |||
@@ -0,0 +1,107 @@ | |||
1 | /* Copyright 2021 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
2 | |||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions are met: | ||
5 | |||
6 | 1. Redistributions of source code must retain the above copyright notice, this | ||
7 | list of conditions and the following disclaimer. | ||
8 | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
9 | this list of conditions and the following disclaimer in the documentation | ||
10 | and/or other materials provided with the distribution. | ||
11 | |||
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | ||
22 | |||
23 | #pragma once | ||
24 | |||
25 | #include <the_Foundation/archive.h> | ||
26 | #include "stb_truetype.h" | ||
27 | |||
28 | #if defined (LAGRANGE_ENABLE_HARFBUZZ) | ||
29 | # include <hb.h> | ||
30 | #endif | ||
31 | |||
32 | /* Fontpacks are ZIP archives that contain a configuration file and one of more font | ||
33 | files. The fontpack format is used instead of plain TTF/OTF because the text renderer | ||
34 | uses additional metadata about each font. | ||
35 | |||
36 | All the available fontpacks are loaded and used for looking up glyphs for rendering. | ||
37 | The user may install new fontpacks via the GUI. The user's fontpacks are stored inside | ||
38 | the config directory. There may also be fontpacks available from system-wide locations. */ | ||
39 | |||
40 | enum iFontSize { | ||
41 | uiTiny_FontSize, /* 0.800 */ | ||
42 | uiSmall_FontSize, /* 0.900 */ | ||
43 | uiNormal_FontSize, /* 1.000 */ | ||
44 | uiMedium_FontSize, /* 1.125 */ | ||
45 | uiBig_FontSize, /* 1.333 */ | ||
46 | uiLarge_FontSize, /* 1.666 */ | ||
47 | contentRegular_FontSize, | ||
48 | contentMedium_FontSize, | ||
49 | contentBig_FontSize, | ||
50 | contentLarge_FontSize, | ||
51 | contentHuge_FontSize, | ||
52 | contentMonoSmall_FontSize, | ||
53 | contentMono_FontSize, | ||
54 | max_FontSize | ||
55 | }; | ||
56 | |||
57 | enum iFontStyle { | ||
58 | regular_FontStyle, | ||
59 | italic_FontStyle, | ||
60 | light_FontStyle, | ||
61 | semiBold_FontStyle, | ||
62 | bold_FontStyle, | ||
63 | max_FontStyle | ||
64 | }; | ||
65 | |||
66 | iLocalDef enum iFontSize larger_FontSize(enum iFontSize size) { | ||
67 | if (size == uiLarge_FontSize || size == contentHuge_FontSize || size == contentMono_FontSize) { | ||
68 | return size; /* largest available */ | ||
69 | } | ||
70 | return size + 1; | ||
71 | } | ||
72 | |||
73 | iDeclareType(FontSpec) | ||
74 | iDeclareTypeConstruction(FontSpec) | ||
75 | |||
76 | enum iFontSpecFlags { | ||
77 | monospace_FontSpecFlag = iBit(1), /* can be used in preformatted content */ | ||
78 | auxiliary_FontSpecFlag = iBit(2), /* only used for looking up glyphs missing from other fonts */ | ||
79 | arabic_FontSpecFlag = iBit(3), | ||
80 | }; | ||
81 | |||
82 | iDeclareType(FontFile) | ||
83 | iDeclareTypeConstruction(FontFile) | ||
84 | |||
85 | struct Impl_FontFile { | ||
86 | enum iFontStyle style; | ||
87 | iBlock sourceData; | ||
88 | stbtt_fontinfo stbInfo; | ||
89 | #if defined (LAGRANGE_ENABLE_HARFBUZZ) | ||
90 | hb_blob_t *hbBlob; | ||
91 | hb_face_t *hbFace; | ||
92 | hb_font_t *hbFont; | ||
93 | #endif | ||
94 | }; | ||
95 | |||
96 | struct Impl_FontSpec { | ||
97 | iString id; /* unique ID */ | ||
98 | iString name; /* human-readable label */ | ||
99 | int flags; | ||
100 | int priority; | ||
101 | float scaling; | ||
102 | const iFontFile *styles[max_FontSize]; | ||
103 | }; | ||
104 | |||
105 | void init_Fonts (const char *userDir); | ||
106 | void deinit_Fonts (void); | ||
107 | |||