Skip to content

Commit 00c6ec1

Browse files
committedMar 16, 2025
1 parent 9c522de commit 00c6ec1

File tree

3 files changed

+159
-34
lines changed

3 files changed

+159
-34
lines changed
 

‎packages/project-editor/lvgl/build.ts

+135-30
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import { Project, findAction } from "project-editor/project/project";
1414
import { Section, getAncestorOfType } from "project-editor/store";
1515
import type { LVGLWidget } from "./widgets";
1616
import type { Assets } from "project-editor/build/assets";
17-
import { isDev, writeTextFile } from "eez-studio-shared/util-electron";
17+
import {
18+
isDev,
19+
writeBinaryData,
20+
writeTextFile
21+
} from "eez-studio-shared/util-electron";
1822
import type { LVGLStyle } from "project-editor/lvgl/style";
1923
import {
2024
isEnumType,
@@ -677,6 +681,13 @@ export class LVGLBuild extends Build {
677681
return "ui_font_" + this.fontNames.get(font.objID)!;
678682
}
679683

684+
getFontAccessor(font: Font) {
685+
const variableName = this.getFontVariableName(font);
686+
return this.project.settings.build.fontsAreStoredInFilesystem
687+
? variableName
688+
: `&${variableName}`;
689+
}
690+
680691
getAddStyleFunctionName(style: LVGLStyle) {
681692
return "add_style_" + this.styleNames.get(style.objID)!;
682693
}
@@ -1680,9 +1691,55 @@ export class LVGLBuild extends Build {
16801691

16811692
build.line("");
16821693

1694+
//
1695+
1696+
if (
1697+
this.project.settings.build.fontsAreStoredInFilesystem &&
1698+
this.fonts.length > 0
1699+
) {
1700+
for (const font of this.fonts) {
1701+
build.line(`lv_font_t *${this.getFontVariableName(font)};`);
1702+
}
1703+
1704+
build.line("");
1705+
}
1706+
16831707
//
16841708
build.blockStart("void create_screens() {");
16851709

1710+
if (
1711+
this.project.settings.build.fontsAreStoredInFilesystem &&
1712+
this.fonts.length > 0
1713+
) {
1714+
let path = this.project.settings.build.fontsFilesystemPath;
1715+
if (!path.endsWith("/")) {
1716+
path += "/";
1717+
}
1718+
1719+
for (const font of this.fonts) {
1720+
const output = getName(
1721+
"ui_font_",
1722+
font.name || "",
1723+
NamingConvention.UnderscoreLowerCase
1724+
);
1725+
1726+
build.line(
1727+
`lv_font_t *${this.getFontVariableName(
1728+
font
1729+
)} = lv_binfont_create("${path}${output}.bin");`
1730+
);
1731+
if (font.lvglFallbackFont) {
1732+
build.line(
1733+
`${this.getFontVariableName(font)}->fallback = &${
1734+
font.lvglFallbackFont
1735+
};`
1736+
);
1737+
}
1738+
}
1739+
1740+
build.line("");
1741+
}
1742+
16861743
if (this.project.lvglGroups.groups.length > 0) {
16871744
build.line("ui_create_groups();");
16881745
build.line("");
@@ -1809,9 +1866,15 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
18091866
const build = this;
18101867

18111868
for (const font of this.fonts) {
1812-
build.line(
1813-
`extern const lv_font_t ${this.getFontVariableName(font)};`
1814-
);
1869+
if (this.project.settings.build.fontsAreStoredInFilesystem) {
1870+
build.line(
1871+
`extern lv_font_t *${this.getFontVariableName(font)};`
1872+
);
1873+
} else {
1874+
build.line(
1875+
`extern const lv_font_t ${this.getFontVariableName(font)};`
1876+
);
1877+
}
18151878
}
18161879

18171880
return this.result;
@@ -2115,6 +2178,8 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
21152178
)}(lv_obj_t *obj) {`
21162179
);
21172180

2181+
build.line(`(void)obj;`);
2182+
21182183
if (definition) {
21192184
Object.keys(definition).forEach(part => {
21202185
Object.keys(definition[part]).forEach(state => {
@@ -2143,6 +2208,8 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
21432208
)}(lv_obj_t *obj) {`
21442209
);
21452210

2211+
build.line(`(void)obj;`);
2212+
21462213
if (definition) {
21472214
Object.keys(definition).forEach(part => {
21482215
Object.keys(definition[part]).forEach(state => {
@@ -2292,34 +2359,72 @@ ${source}`;
22922359
await Promise.all(
22932360
this.fonts.map(font =>
22942361
(async () => {
2295-
const lvglSourceFile = await font.getLvglSourceFile();
2296-
if (lvglSourceFile) {
2297-
const output = getName(
2298-
"ui_font_",
2299-
font.name || "",
2300-
NamingConvention.UnderscoreLowerCase
2301-
);
2302-
2303-
try {
2304-
await writeTextFile(
2305-
this.project._store.getAbsoluteFilePath(
2306-
destinationFolder
2307-
) +
2308-
"/" +
2309-
(this.project.settings.build
2310-
.separateFolderForImagesAndFonts
2311-
? "fonts/"
2312-
: "") +
2313-
output +
2314-
".c",
2315-
lvglSourceFile
2362+
if (
2363+
this.project.settings.build.fontsAreStoredInFilesystem
2364+
) {
2365+
const lvglBinaryFileBase64 = font.lvglBinFile;
2366+
const lvglBinaryFile = lvglBinaryFileBase64
2367+
? Buffer.from(lvglBinaryFileBase64, "base64")
2368+
: undefined;
2369+
if (lvglBinaryFile) {
2370+
const output = getName(
2371+
"ui_font_",
2372+
font.name || "",
2373+
NamingConvention.UnderscoreLowerCase
23162374
);
2317-
} catch (err) {
2318-
this.project._store.outputSectionsStore.write(
2319-
Section.OUTPUT,
2320-
MessageType.ERROR,
2321-
`Error writing font file '${output}.c': ${err}`
2375+
2376+
try {
2377+
await writeBinaryData(
2378+
this.project._store.getAbsoluteFilePath(
2379+
destinationFolder
2380+
) +
2381+
"/" +
2382+
(this.project.settings.build
2383+
.separateFolderForImagesAndFonts
2384+
? "fonts/"
2385+
: "") +
2386+
output +
2387+
".bin",
2388+
lvglBinaryFile
2389+
);
2390+
} catch (err) {
2391+
this.project._store.outputSectionsStore.write(
2392+
Section.OUTPUT,
2393+
MessageType.ERROR,
2394+
`Error writing font file '${output}.bin': ${err}`
2395+
);
2396+
}
2397+
}
2398+
} else {
2399+
const lvglSourceFile = await font.getLvglSourceFile();
2400+
if (lvglSourceFile) {
2401+
const output = getName(
2402+
"ui_font_",
2403+
font.name || "",
2404+
NamingConvention.UnderscoreLowerCase
23222405
);
2406+
2407+
try {
2408+
await writeTextFile(
2409+
this.project._store.getAbsoluteFilePath(
2410+
destinationFolder
2411+
) +
2412+
"/" +
2413+
(this.project.settings.build
2414+
.separateFolderForImagesAndFonts
2415+
? "fonts/"
2416+
: "") +
2417+
output +
2418+
".c",
2419+
lvglSourceFile
2420+
);
2421+
} catch (err) {
2422+
this.project._store.outputSectionsStore.write(
2423+
Section.OUTPUT,
2424+
MessageType.ERROR,
2425+
`Error writing font file '${output}.c': ${err}`
2426+
);
2427+
}
23232428
}
23242429
}
23252430
})()

‎packages/project-editor/lvgl/style-definition.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ export class LVGLStylesDefinition extends EezObject {
688688
build.line(
689689
`lv_obj_set_style_${build.getStylePropName(
690690
propertyInfo.name
691-
)}(obj, &${build.getFontVariableName(
691+
)}(obj, ${build.getFontAccessor(
692692
font
693693
)}, ${selectorCode});`
694694
);
@@ -821,9 +821,7 @@ export class LVGLStylesDefinition extends EezObject {
821821
build.line(
822822
`lv_style_set_${build.getStylePropName(
823823
propertyInfo.name
824-
)}(style, &${build.getFontVariableName(
825-
font
826-
)});`
824+
)}(style, ${build.getFontAccessor(font)});`
827825
);
828826
}
829827
}

‎packages/project-editor/project/project.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ export class Build extends EezObject {
278278
compressFlowDefinition: boolean;
279279
executionQueueSize: number;
280280
expressionEvaluatorStackSize: number;
281+
fontsAreStoredInFilesystem: boolean;
282+
fontsFilesystemPath: string;
281283

282284
static classInfo: ClassInfo = {
283285
label: () => "Build",
@@ -309,6 +311,19 @@ export class Build extends EezObject {
309311
type: PropertyType.Boolean,
310312
disabled: isNotLVGLProject
311313
},
314+
{
315+
name: "storeFontsInFilesystem",
316+
type: PropertyType.Boolean,
317+
disabled: (object: Build) => isNotLVGLProject(object),
318+
checkboxStyleSwitch: true
319+
},
320+
{
321+
name: "fontsFilesystemPath",
322+
type: PropertyType.String,
323+
disabled: (object: Build) =>
324+
isNotLVGLProject(object) ||
325+
!object.fontsAreStoredInFilesystem
326+
},
312327
{
313328
name: "lvglInclude",
314329
displayName: "LVGL include",
@@ -386,6 +401,11 @@ export class Build extends EezObject {
386401
if (jsObject.screensLifetimeSupport == undefined) {
387402
jsObject.screensLifetimeSupport = false;
388403
}
404+
405+
if (jsObject.fontsAreStoredInFilesystem == undefined) {
406+
jsObject.fontsAreStoredInFilesystem = false;
407+
jsObject.fontsFilesystemPath = "";
408+
}
389409
},
390410

391411
updateObjectValueHook: (build: Build, values: Partial<Build>) => {
@@ -412,6 +432,8 @@ export class Build extends EezObject {
412432
files: observable,
413433
destinationFolder: observable,
414434
separateFolderForImagesAndFonts: observable,
435+
storeFontsInFilesystem: observable,
436+
fontsFilesystemPath: observable,
415437
lvglInclude: observable,
416438
screensLifetimeSupport: observable,
417439
generateSourceCodeForEezFramework: observable,

0 commit comments

Comments
 (0)
Failed to load comments.