summaryrefslogtreecommitdiff
path: root/src/fontpack.h
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-05 06:55:51 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-05 06:55:51 +0300
commit827951d2807b031d131b7fc05b1596550d258676 (patch)
tree836a6a1ceb07cfbc1867ef65fcc30331b0ad33ba /src/fontpack.h
parent88993e95e5ff9fecc5980b25e1778053ca23afe0 (diff)
Started working on font packs
Diffstat (limited to 'src/fontpack.h')
-rw-r--r--src/fontpack.h107
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
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are met:
5
61. Redistributions of source code must retain the above copyright notice, this
7 list of conditions and the following disclaimer.
82. 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
12THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19ANY 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
21SOFTWARE, 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
33files. The fontpack format is used instead of plain TTF/OTF because the text renderer
34uses additional metadata about each font.
35
36All the available fontpacks are loaded and used for looking up glyphs for rendering.
37The user may install new fontpacks via the GUI. The user's fontpacks are stored inside
38the config directory. There may also be fontpacks available from system-wide locations. */
39
40enum 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
57enum iFontStyle {
58 regular_FontStyle,
59 italic_FontStyle,
60 light_FontStyle,
61 semiBold_FontStyle,
62 bold_FontStyle,
63 max_FontStyle
64};
65
66iLocalDef 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
73iDeclareType(FontSpec)
74iDeclareTypeConstruction(FontSpec)
75
76enum 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
82iDeclareType(FontFile)
83iDeclareTypeConstruction(FontFile)
84
85struct 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
96struct 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
105void init_Fonts (const char *userDir);
106void deinit_Fonts (void);
107