Skip to content

Commit

Permalink
Implemented: [LVGL] Include font fallback #620
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 9, 2024
1 parent 9804d22 commit 8178e78
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 189 deletions.
2 changes: 1 addition & 1 deletion packages/eez-studio-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ export interface IWasmFlowRuntime {
_lvglGetObjRelY(obj: number): number;
_lvglGetObjWidth(obj: number): number;
_lvglGetObjHeight(obj: number): number;
_lvglLoadFont(font_file_path: number): number;
_lvglLoadFont(font_file_path: number, fallback_user_font: number, fallback_builtin_font: number): number;
_lvglFreeFont(font_ptr: number): void;
_lvglAddObjectFlowCallback(obj: number, filter: number, flow_state: number, component_index: number, output_or_property_index: number, userDataValuePtr: number): void;
_lvglSetImgbuttonImageSrc(obj: number, statE: number, img_src: number): void;
Expand Down
108 changes: 3 additions & 105 deletions packages/project-editor/features/font/FontEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ import { showGenericDialog } from "project-editor/core/util";
import { GlyphSelectFieldType } from "project-editor/features/font/GlyphSelectFieldType";
import {
Font,
getEncodings,
Glyph,
GlyphSource,
removeDuplicates,
requiredRangesOrSymbols,
validateRanges
onEditGlyphs
} from "project-editor/features/font/font";

import {
Expand All @@ -65,8 +62,7 @@ export const FontEditor = observer(
makeObservable(this, {
onSelectGlyph: action.bound,
onAddGlyph: action.bound,
onDeleteGlyph: action.bound,
onEditGlyphs: action.bound
onDeleteGlyph: action.bound
});
}

Expand Down Expand Up @@ -405,104 +401,6 @@ export const FontEditor = observer(
}
}

async onEditGlyphs() {
const result = await showGenericDialog(this.context, {
dialogDefinition: {
title: "Add or Remove Characters",
fields: [
{
name: "ranges",
type: "string",
validators: [
validateRanges,
requiredRangesOrSymbols
],
formText:
"Ranges and/or characters to include. Example: 32-127,140,160-170,200,210-255"
},
{
name: "symbols",
type: "string",
validators: [requiredRangesOrSymbols],
formText:
"List of characters to include. Example: abc01234äöüčćšđ"
}
]
},
values: {
ranges: this.font.lvglRanges,
symbols: this.font.lvglSymbols
}
});

try {
let relativeFilePath = this.font.source!.filePath;
let absoluteFilePath =
this.context.getAbsoluteFilePath(relativeFilePath);

const encodingsBeforeDeduplication = getEncodings(
result.values.ranges
)!;

const { encodings, symbols } = removeDuplicates(
encodingsBeforeDeduplication,
result.values.symbols
);
result.values.symbols = symbols;

const fontProperties = await extractFont({
name: this.font.name,
absoluteFilePath,
embeddedFontFile: this.font.embeddedFontFile,
relativeFilePath,
renderingEngine: "LVGL",
bpp: this.font.bpp,
size: this.font.source!.size!,
threshold: 128,
createGlyphs: true,
encodings,
symbols: result.values.symbols,
createBlankGlyphs: false,
doNotAddGlyphIfNotFound: false,
lvglVersion:
this.context.project.settings.general.lvglVersion,
lvglInclude: this.context.project.settings.build.lvglInclude
});

this.context.updateObject(this.font, {
lvglBinFile: fontProperties.lvglBinFile,
lvglSourceFile: fontProperties.lvglSourceFile,
lvglGlyphs: {
encodings,
symbols: result.values.symbols
}
});

this.font.loadLvglGlyphs(this.context);

notification.info(
`Font ${this.font.name} successfully modified.`
);
} catch (err) {
let errorMessage;
if (err) {
if (err.message) {
errorMessage = err.message;
} else {
errorMessage = err.toString();
}
}

if (errorMessage) {
notification.error(
`Modifying ${Font.name} failed: ${errorMessage}!`
);
} else {
notification.error(`Modifying ${Font.name} failed!`);
}
}
}

onCreateShadow = async () => {
const result = await dialog.showOpenDialog(getCurrentWindow(), {
properties: ["openFile"],
Expand Down Expand Up @@ -678,7 +576,7 @@ export const FontEditor = observer(
onAddGlyph={this.onAddGlyph}
onEditGlyphs={
this.context.projectTypeTraits.isLVGL
? this.onEditGlyphs
? () => onEditGlyphs(this.font)
: undefined
}
onDeleteGlyph={this.onDeleteGlyph}
Expand Down
2 changes: 0 additions & 2 deletions packages/project-editor/features/font/Glyphs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ export const GlyphComponent = observer(
refDiv = React.createRef<HTMLDivElement>();

setCanvas() {
console.log("setCanvas");

const { glyph } = this.props;

const canvas = document.createElement("canvas");
Expand Down
2 changes: 2 additions & 0 deletions packages/project-editor/features/font/font-extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export interface Params {
getAllGlyphs?: boolean;
lvglVersion?: string;
lvglInclude?: string;
opts_string?: string;
lv_fallback?: string;
}

export interface IFontExtract {
Expand Down
6 changes: 5 additions & 1 deletion packages/project-editor/features/font/font-extract/lvgl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export class ExtractFont implements IFontExtract {
lv_include: this.params.lvglInclude,
no_kerning: false,
no_prefilter: false,
fast_kerning: false
fast_kerning: false,
opts_string: this.params.opts_string,
lv_fallback: this.params.lv_fallback
? this.params.lv_fallback
: undefined
};

// wait for !extractBusy
Expand Down
Loading

0 comments on commit 8178e78

Please sign in to comment.