@@ -14,7 +14,11 @@ import { Project, findAction } from "project-editor/project/project";
14
14
import { Section , getAncestorOfType } from "project-editor/store" ;
15
15
import type { LVGLWidget } from "./widgets" ;
16
16
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" ;
18
22
import type { LVGLStyle } from "project-editor/lvgl/style" ;
19
23
import {
20
24
isEnumType ,
@@ -677,6 +681,13 @@ export class LVGLBuild extends Build {
677
681
return "ui_font_" + this . fontNames . get ( font . objID ) ! ;
678
682
}
679
683
684
+ getFontAccessor ( font : Font ) {
685
+ const variableName = this . getFontVariableName ( font ) ;
686
+ return this . project . settings . build . fontsAreStoredInFilesystem
687
+ ? variableName
688
+ : `&${ variableName } ` ;
689
+ }
690
+
680
691
getAddStyleFunctionName ( style : LVGLStyle ) {
681
692
return "add_style_" + this . styleNames . get ( style . objID ) ! ;
682
693
}
@@ -1680,9 +1691,55 @@ export class LVGLBuild extends Build {
1680
1691
1681
1692
build . line ( "" ) ;
1682
1693
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
+
1683
1707
//
1684
1708
build . blockStart ( "void create_screens() {" ) ;
1685
1709
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
+
1686
1743
if ( this . project . lvglGroups . groups . length > 0 ) {
1687
1744
build . line ( "ui_create_groups();" ) ;
1688
1745
build . line ( "" ) ;
@@ -1809,9 +1866,15 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
1809
1866
const build = this ;
1810
1867
1811
1868
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
+ }
1815
1878
}
1816
1879
1817
1880
return this . result ;
@@ -2115,6 +2178,8 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
2115
2178
) } (lv_obj_t *obj) {`
2116
2179
) ;
2117
2180
2181
+ build . line ( `(void)obj;` ) ;
2182
+
2118
2183
if ( definition ) {
2119
2184
Object . keys ( definition ) . forEach ( part => {
2120
2185
Object . keys ( definition [ part ] ) . forEach ( state => {
@@ -2143,6 +2208,8 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
2143
2208
) } (lv_obj_t *obj) {`
2144
2209
) ;
2145
2210
2211
+ build . line ( `(void)obj;` ) ;
2212
+
2146
2213
if ( definition ) {
2147
2214
Object . keys ( definition ) . forEach ( part => {
2148
2215
Object . keys ( definition [ part ] ) . forEach ( state => {
@@ -2292,34 +2359,72 @@ ${source}`;
2292
2359
await Promise . all (
2293
2360
this . fonts . map ( font =>
2294
2361
( 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
2316
2374
) ;
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
2322
2405
) ;
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
+ }
2323
2428
}
2324
2429
}
2325
2430
} ) ( )
0 commit comments