embedded-react 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/aot/compile.mjs +1 -1
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/check.mjs +1 -1
- package/aot/compiler/collect.mjs +1 -1
- package/aot/compiler/elements/button.mjs +3 -3
- package/aot/compiler/elements/image-background.mjs +1 -1
- package/aot/compiler/elements/props.mjs +10 -6
- package/aot/compiler/elements/section-list.mjs +1 -1
- package/aot/compiler/expressions.mjs +29 -2
- package/aot/compiler/handlers.mjs +73 -16
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/lower.mjs +12 -0
- package/aot/compiler/nodes.mjs +17 -9
- package/aot/compiler/out.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +36 -2
- package/aot/compiler/package/format.mjs +5 -3
- package/aot/compiler/package/lower.mjs +53 -19
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/style-text.mjs +2 -2
- package/aot/compiler/svg.mjs +6 -3
- package/aot/compiler/updaters.mjs +1 -0
- package/aot/style-map.mjs +44 -1
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +84 -101
- package/cli.mjs +482 -621
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +144 -200
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +93 -123
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +155 -2
- package/src/embedded-react/index.js +26 -19
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -146
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/nativeModule.js +0 -462
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// Regenerates the engine's built-in font (engine/font/font_data.c) from assets/fonts/Inter-Regular.ttf
|
|
18
17
|
// using the same JS bakers as app assets — this is the single source of truth for the built-in font
|
|
19
18
|
// (there is no Python step). font_registry.c falls back to g_inter_sizes[] for any text without a
|
|
@@ -23,40 +22,28 @@
|
|
|
23
22
|
//
|
|
24
23
|
// Regenerating changes glyph metrics slightly vs a prior rasterizer, so re-run the engine text tests
|
|
25
24
|
// (test_text, yoga_parity) and re-flash to eyeball on-device after changing it.
|
|
26
|
-
import {resolve, dirname} from 'node:path';
|
|
27
|
-
import {fileURLToPath} from 'node:url';
|
|
28
|
-
import {writeFileSync} from 'node:fs';
|
|
29
|
-
import {bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES} from './bake-font.mjs';
|
|
30
|
-
import {emitBuiltinFont} from './emit-c.mjs';
|
|
31
|
-
|
|
25
|
+
import { resolve, dirname } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
import { writeFileSync } from 'node:fs';
|
|
28
|
+
import { bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES } from './bake-font.mjs';
|
|
29
|
+
import { emitBuiltinFont } from './emit-c.mjs';
|
|
32
30
|
const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/assets
|
|
33
31
|
const repoRoot = resolve(here, '../../..');
|
|
34
32
|
const FONT_PATH = resolve(repoRoot, 'assets/fonts/Inter-Regular.ttf');
|
|
35
33
|
const OUTPUT_PATH = resolve(repoRoot, 'engine/font/font_data.c');
|
|
36
34
|
const BITS_PER_PIXEL = 4;
|
|
37
|
-
|
|
38
35
|
// The built-in covers printable ASCII plus a fixed set of common symbols (degrees, arrows, math,
|
|
39
36
|
// punctuation, etc.) the UI components rely on — kept stable across regenerations. The set lives in
|
|
40
|
-
// bake-font.
|
|
37
|
+
// bake-font.mts as BUILTIN_EXTRAS — with BUILTIN_SIZES alongside it — so the build-time coverage
|
|
41
38
|
// checks report against what is actually baked here.
|
|
42
39
|
const SIZES = BUILTIN_SIZES;
|
|
43
|
-
|
|
44
40
|
const font = bakeFont({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
path: FONT_PATH,
|
|
42
|
+
family: 'Inter',
|
|
43
|
+
sizes: SIZES,
|
|
44
|
+
bpp: BITS_PER_PIXEL,
|
|
45
|
+
glyphs: BUILTIN_EXTRAS,
|
|
50
46
|
});
|
|
51
|
-
writeFileSync(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const bitmapBytes = font.sizes.reduce(
|
|
57
|
-
(total, size) => total + size.bitmap.length,
|
|
58
|
-
0,
|
|
59
|
-
);
|
|
60
|
-
console.log(
|
|
61
|
-
`Regenerated ${OUTPUT_PATH}\n ${SIZES.length} sizes [${SIZES.join(',')}], bpp ${BITS_PER_PIXEL}, ${font.sizes[0].extras.length} extra glyphs, ${bitmapBytes} bitmap bytes`,
|
|
62
|
-
);
|
|
47
|
+
writeFileSync(OUTPUT_PATH, emitBuiltinFont({ font, symbol: 'inter', sourceName: 'Inter-Regular.ttf' }));
|
|
48
|
+
const bitmapBytes = font.sizes.reduce((total, size) => total + size.bitmap.length, 0);
|
|
49
|
+
console.log(`Regenerated ${OUTPUT_PATH}\n ${SIZES.length} sizes [${SIZES.join(',')}], bpp ${BITS_PER_PIXEL}, ${font.sizes[0].extras.length} extra glyphs, ${bitmapBytes} bitmap bytes`);
|
package/assets/emit-c.mjs
CHANGED
|
@@ -13,12 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
// Emits the generated C for baked assets: one .c with the image pixel arrays + font BitmapFont data,
|
|
18
|
-
// and one .h declaring er_register_assets(). The .c depends only on the public engine header
|
|
19
|
-
// (er_scene.h, which exposes both er_image_load/er_font_register and the BitmapFont format), so it
|
|
20
|
-
// drops into any target's build the same way the bundle does.
|
|
21
|
-
|
|
22
16
|
const ARGB8888_HEX_DIGITS = 8;
|
|
23
17
|
const RGB565_HEX_DIGITS = 4;
|
|
24
18
|
const BYTE_HEX_DIGITS = 2;
|
|
@@ -26,228 +20,154 @@ const ARGB8888_WORDS_PER_LINE = 8;
|
|
|
26
20
|
const RGB565_WORDS_PER_LINE = 12;
|
|
27
21
|
const BITMAP_BYTES_PER_LINE = 16;
|
|
28
22
|
const DEFAULT_BPP = 4;
|
|
29
|
-
|
|
30
23
|
/** Sanitizes an asset/family name into a C identifier fragment. */
|
|
31
24
|
function cIdent(name) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
let identifier = String(name).replace(/[^0-9a-zA-Z_]/g, '_');
|
|
26
|
+
if (identifier && /[0-9]/.test(identifier[0]))
|
|
27
|
+
identifier = '_' + identifier;
|
|
28
|
+
return identifier || '_asset';
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
/** Formats an array of byte/word strings into wrapped C initializer lines. */
|
|
38
31
|
function rows(values, perLine, indent = ' ') {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
const lines = [];
|
|
33
|
+
for (let start = 0; start < values.length; start += perLine) {
|
|
34
|
+
lines.push(indent + values.slice(start, start + perLine).join(', ') + ',');
|
|
35
|
+
}
|
|
36
|
+
return lines.join('\n');
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
/** Emits the GlyphInfo designated-initializer for one glyph. */
|
|
47
39
|
function glyphInit(glyph) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`.x_offset = ${glyph.xOffset}, .y_offset = ${glyph.yOffset}, .advance = ${glyph.advance} }`
|
|
51
|
-
);
|
|
40
|
+
return (`{ .bitmap_offset = ${glyph.bitmapOffset}, .width = ${glyph.width}, .height = ${glyph.height}, ` +
|
|
41
|
+
`.x_offset = ${glyph.xOffset}, .y_offset = ${glyph.yOffset}, .advance = ${glyph.advance} }`);
|
|
52
42
|
}
|
|
53
|
-
|
|
54
43
|
/**
|
|
55
44
|
* Builds the .c and .h text for a set of baked images and fonts.
|
|
56
45
|
*
|
|
57
|
-
*
|
|
58
|
-
* @param {string} opts.headerName Basename of the .h (for the .c's #include).
|
|
59
|
-
* @param {Array<object>} [opts.images] Results from bakeImage().
|
|
60
|
-
* @param {Array<object>} [opts.fonts] Results from bakeFont().
|
|
61
|
-
* @returns {{c:string, h:string}}
|
|
46
|
+
* headerName is the basename of the .h, for the .c's #include.
|
|
62
47
|
*/
|
|
63
|
-
export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
lines.push(
|
|
77
|
-
`/* Generated by packages/embedded-react/assets — DO NOT EDIT. */`,
|
|
78
|
-
);
|
|
79
|
-
lines.push(
|
|
80
|
-
`/* Images: premultiplied ARGB8888 (or RGB565 when baked 16-bit), referenced by pointer. Fonts: baked BitmapFont per size. */`,
|
|
81
|
-
);
|
|
82
|
-
lines.push(``);
|
|
83
|
-
lines.push(`#include "${headerName}"`);
|
|
84
|
-
lines.push(
|
|
85
|
-
`#include "er_scene.h" /* er_image_load, er_font_register, BitmapFont */`,
|
|
86
|
-
);
|
|
87
|
-
lines.push(`#include <stddef.h>`);
|
|
88
|
-
lines.push(`#include <stdint.h>`);
|
|
89
|
-
lines.push(``);
|
|
90
|
-
|
|
91
|
-
// --- Images ---------------------------------------------------------------------------------
|
|
92
|
-
for (const image of images) {
|
|
93
|
-
const identifier = cIdent(image.name);
|
|
94
|
-
const is565 = image.format === 'rgb565';
|
|
95
|
-
const hex = Array.from(
|
|
96
|
-
image.pixels,
|
|
97
|
-
pixel =>
|
|
98
|
-
'0x' +
|
|
99
|
-
pixel
|
|
100
|
-
.toString(16)
|
|
101
|
-
.toUpperCase()
|
|
102
|
-
.padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
|
|
103
|
-
'u',
|
|
104
|
-
);
|
|
105
|
-
lines.push(
|
|
106
|
-
`/* image "${image.name}" — ${image.width}x${image.height}${is565 ? ' (RGB565)' : ''} */`,
|
|
107
|
-
);
|
|
108
|
-
lines.push(
|
|
109
|
-
`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${identifier}_px[] = {`,
|
|
110
|
-
);
|
|
111
|
-
lines.push(
|
|
112
|
-
rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE),
|
|
113
|
-
);
|
|
114
|
-
lines.push(`};`);
|
|
48
|
+
export function emitAssetsC({ headerName, images = [], fonts = [], }) {
|
|
49
|
+
const guard = 'ER_' + cIdent(headerName).toUpperCase();
|
|
50
|
+
const header = `/* Generated by packages/embedded-react/assets — DO NOT EDIT. */\n` +
|
|
51
|
+
`#ifndef ${guard}\n#define ${guard}\n\n` +
|
|
52
|
+
`#ifdef __cplusplus\nextern "C"\n{\n#endif\n\n` +
|
|
53
|
+
` /** @brief Registers every baked image and font with the engine (call once at boot, after\n` +
|
|
54
|
+
` * embedded_renderer_set_backend()). */\n` +
|
|
55
|
+
` void er_register_assets(void);\n\n` +
|
|
56
|
+
`#ifdef __cplusplus\n}\n#endif\n\n` +
|
|
57
|
+
`#endif\n`;
|
|
58
|
+
const lines = [];
|
|
59
|
+
lines.push(`/* Generated by packages/embedded-react/assets — DO NOT EDIT. */`);
|
|
60
|
+
lines.push(`/* Images: premultiplied ARGB8888 (or RGB565 when baked 16-bit), referenced by pointer. Fonts: baked BitmapFont per size. */`);
|
|
115
61
|
lines.push(``);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
62
|
+
lines.push(`#include "${headerName}"`);
|
|
63
|
+
lines.push(`#include "er_scene.h" /* er_image_load, er_font_register, BitmapFont */`);
|
|
64
|
+
lines.push(`#include <stddef.h>`);
|
|
65
|
+
lines.push(`#include <stdint.h>`);
|
|
66
|
+
lines.push(``);
|
|
67
|
+
// --- Images ---------------------------------------------------------------------------------
|
|
68
|
+
for (const image of images) {
|
|
69
|
+
const identifier = cIdent(image.name);
|
|
70
|
+
const is565 = image.format === 'rgb565';
|
|
71
|
+
const hex = Array.from(image.pixels, pixel => '0x' +
|
|
72
|
+
pixel
|
|
73
|
+
.toString(16)
|
|
74
|
+
.toUpperCase()
|
|
75
|
+
.padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
|
|
76
|
+
'u');
|
|
77
|
+
lines.push(`/* image "${image.name}" — ${image.width}x${image.height}${is565 ? ' (RGB565)' : ''} */`);
|
|
78
|
+
lines.push(`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${identifier}_px[] = {`);
|
|
79
|
+
lines.push(rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE));
|
|
80
|
+
lines.push(`};`);
|
|
81
|
+
lines.push(``);
|
|
82
|
+
}
|
|
83
|
+
// --- Fonts ----------------------------------------------------------------------------------
|
|
84
|
+
const fontRegistrations = [];
|
|
85
|
+
for (const font of fonts) {
|
|
86
|
+
const familyIdentifier = cIdent(font.family);
|
|
87
|
+
lines.push(`/* font "${font.family}" — ${font.sizes.map(size => `${size.pixelSize}px`).join(', ')} */`);
|
|
88
|
+
emitFontSizes(lines, font, familyIdentifier, 'static const '); // file-local: only er_register_assets refers to these
|
|
89
|
+
for (const size of font.sizes) {
|
|
90
|
+
fontRegistrations.push(` er_font_register(${JSON.stringify(font.family)}, &g_font_${familyIdentifier}_${size.pixelSize});`);
|
|
91
|
+
}
|
|
130
92
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
lines.
|
|
146
|
-
}
|
|
147
|
-
lines.push(`}`);
|
|
148
|
-
lines.push(``);
|
|
149
|
-
|
|
150
|
-
return {c: lines.join('\n'), h: header};
|
|
93
|
+
// --- Registration entry point ---------------------------------------------------------------
|
|
94
|
+
lines.push(`void er_register_assets(void)`);
|
|
95
|
+
lines.push(`{`);
|
|
96
|
+
for (const image of images) {
|
|
97
|
+
const loadFunction = image.format === 'rgb565' ? 'er_image_load_rgb565' : 'er_image_load';
|
|
98
|
+
lines.push(` ${loadFunction}(${JSON.stringify(image.name)}, ${cIdent(image.name)}_px, ${image.width}, ${image.height});`);
|
|
99
|
+
}
|
|
100
|
+
for (const registration of fontRegistrations)
|
|
101
|
+
lines.push(registration);
|
|
102
|
+
if (images.length === 0 && fontRegistrations.length === 0) {
|
|
103
|
+
lines.push(` /* no baked assets */`);
|
|
104
|
+
}
|
|
105
|
+
lines.push(`}`);
|
|
106
|
+
lines.push(``);
|
|
107
|
+
return { c: lines.join('\n'), h: header };
|
|
151
108
|
}
|
|
152
|
-
|
|
153
109
|
/** Emits the per-size BitmapFont blocks (bitmap + glyphs + extras + struct) for one font. */
|
|
154
110
|
function emitFontSizes(lines, font, symbol, fontStorage) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
`
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
lines.push(
|
|
183
|
-
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
111
|
+
for (const size of font.sizes) {
|
|
112
|
+
const prefix = `s_${symbol}_${size.pixelSize}`;
|
|
113
|
+
const hex = size.bitmap.map(byte => '0x' + byte.toString(16).toUpperCase().padStart(BYTE_HEX_DIGITS, '0'));
|
|
114
|
+
lines.push(`static const uint8_t ${prefix}_bitmap[${size.bitmap.length || 1}] = {`);
|
|
115
|
+
lines.push(size.bitmap.length ? rows(hex, BITMAP_BYTES_PER_LINE) : ' 0x00,');
|
|
116
|
+
lines.push(`};`);
|
|
117
|
+
lines.push(``);
|
|
118
|
+
lines.push(`static const GlyphInfo ${prefix}_glyphs[${size.dense.length}] = {`);
|
|
119
|
+
for (const glyph of size.dense)
|
|
120
|
+
lines.push(` ${glyphInit(glyph)},`);
|
|
121
|
+
lines.push(`};`);
|
|
122
|
+
lines.push(``);
|
|
123
|
+
if (size.extras.length) {
|
|
124
|
+
lines.push(`static const ExtraGlyph ${prefix}_extras[${size.extras.length}] = {`);
|
|
125
|
+
for (const extra of size.extras) {
|
|
126
|
+
lines.push(` { .codepoint = 0x${extra.codepoint.toString(16).toUpperCase()}, .info = ${glyphInit(extra.info)} },`);
|
|
127
|
+
}
|
|
128
|
+
lines.push(`};`);
|
|
129
|
+
lines.push(``);
|
|
130
|
+
}
|
|
131
|
+
lines.push(`${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`);
|
|
132
|
+
lines.push(` .bitmap = ${prefix}_bitmap,`);
|
|
133
|
+
lines.push(` .glyphs = ${prefix}_glyphs,`);
|
|
134
|
+
lines.push(` .extras = ${size.extras.length ? `${prefix}_extras` : 'NULL'},`);
|
|
135
|
+
lines.push(` .extras_count = ${size.extras.length},`);
|
|
136
|
+
lines.push(` .first = 0x${size.first.toString(16).toUpperCase()},`);
|
|
137
|
+
lines.push(` .last = 0x${size.last.toString(16).toUpperCase()},`);
|
|
138
|
+
lines.push(` .pixel_size = ${size.pixelSize},`);
|
|
139
|
+
lines.push(` .line_height = ${size.lineHeight},`);
|
|
140
|
+
lines.push(` .baseline = ${size.baseline},`);
|
|
141
|
+
lines.push(` .format = ${size.bpp},`);
|
|
142
|
+
lines.push(`};`);
|
|
143
|
+
lines.push(``);
|
|
188
144
|
}
|
|
189
|
-
|
|
190
|
-
lines.push(
|
|
191
|
-
`${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`,
|
|
192
|
-
);
|
|
193
|
-
lines.push(` .bitmap = ${prefix}_bitmap,`);
|
|
194
|
-
lines.push(` .glyphs = ${prefix}_glyphs,`);
|
|
195
|
-
lines.push(
|
|
196
|
-
` .extras = ${size.extras.length ? `${prefix}_extras` : 'NULL'},`,
|
|
197
|
-
);
|
|
198
|
-
lines.push(` .extras_count = ${size.extras.length},`);
|
|
199
|
-
lines.push(
|
|
200
|
-
` .first = 0x${size.first.toString(16).toUpperCase()},`,
|
|
201
|
-
);
|
|
202
|
-
lines.push(
|
|
203
|
-
` .last = 0x${size.last.toString(16).toUpperCase()},`,
|
|
204
|
-
);
|
|
205
|
-
lines.push(` .pixel_size = ${size.pixelSize},`);
|
|
206
|
-
lines.push(` .line_height = ${size.lineHeight},`);
|
|
207
|
-
lines.push(` .baseline = ${size.baseline},`);
|
|
208
|
-
lines.push(` .format = ${size.bpp},`);
|
|
209
|
-
lines.push(`};`);
|
|
210
|
-
lines.push(``);
|
|
211
|
-
}
|
|
212
145
|
}
|
|
213
|
-
|
|
214
146
|
/**
|
|
215
147
|
* Emits the engine's built-in font translation unit (font_data.c format): the per-size BitmapFont
|
|
216
148
|
* structs plus the `g_<symbol>_sizes[]` array + `_count` that font_registry.c falls back to. Depends
|
|
217
149
|
* only on font_bitmap.h. Symbol must be 'inter' to satisfy the extern decls in font_bitmap.h.
|
|
218
150
|
*
|
|
219
|
-
* @
|
|
220
|
-
* @param {object} opts.font Result of bakeFont().
|
|
221
|
-
* @param {string} [opts.symbol] C symbol prefix (default 'inter').
|
|
222
|
-
* @param {string} [opts.sourceName] Source font filename, for the header comment.
|
|
223
|
-
* @returns {string} The .c source text.
|
|
151
|
+
* @returns The .c source text.
|
|
224
152
|
*/
|
|
225
|
-
export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
for (const size of font.sizes)
|
|
246
|
-
lines.push(` &g_font_${symbol}_${size.pixelSize},`);
|
|
247
|
-
lines.push(`};`);
|
|
248
|
-
lines.push(
|
|
249
|
-
`const size_t g_${symbol}_sizes_count = sizeof(g_${symbol}_sizes) / sizeof(g_${symbol}_sizes[0]);`,
|
|
250
|
-
);
|
|
251
|
-
lines.push(``);
|
|
252
|
-
return lines.join('\n');
|
|
153
|
+
export function emitBuiltinFont({ font, symbol = 'inter', sourceName = '', }) {
|
|
154
|
+
const sizeList = font.sizes.map(size => size.pixelSize).join(',');
|
|
155
|
+
const bpp = font.sizes[0] ? font.sizes[0].bpp : DEFAULT_BPP;
|
|
156
|
+
const lines = [];
|
|
157
|
+
lines.push(`/* AUTO-GENERATED by packages/embedded-react/assets/build-builtin-font.mts — do not edit by hand.`);
|
|
158
|
+
lines.push(` * Source : ${sourceName}`);
|
|
159
|
+
lines.push(` * Sizes : ${sizeList} (bpp ${bpp}, family "${font.family}")`);
|
|
160
|
+
lines.push(` * Regenerate: cd packages/embedded-react && npm run build:builtin-font`);
|
|
161
|
+
lines.push(` */`);
|
|
162
|
+
lines.push(`#include "font_bitmap.h"`);
|
|
163
|
+
lines.push(`#include <stddef.h>`);
|
|
164
|
+
lines.push(``);
|
|
165
|
+
emitFontSizes(lines, font, symbol, 'const '); // file-scope const: referenced by g_<symbol>_sizes
|
|
166
|
+
lines.push(`const BitmapFont *const g_${symbol}_sizes[] = {`);
|
|
167
|
+
for (const size of font.sizes)
|
|
168
|
+
lines.push(` &g_font_${symbol}_${size.pixelSize},`);
|
|
169
|
+
lines.push(`};`);
|
|
170
|
+
lines.push(`const size_t g_${symbol}_sizes_count = sizeof(g_${symbol}_sizes) / sizeof(g_${symbol}_sizes[0]);`);
|
|
171
|
+
lines.push(``);
|
|
172
|
+
return lines.join('\n');
|
|
253
173
|
}
|