Skip to content

v1: Loading fonts from assets doesn't work #5425

@mfxbe

Description

@mfxbe

Duplicate Check

Describe the bug

Loading a font from the assets folder doesn't work. Flet does not find the font. Works nether with flet run nor with the executable from flet build linux

Code sample

Code
import flet as ft

def main(page: ft.Page):
	# Custom Serif Font (for easy distinction)
	page.fonts = {
		"DM Serif Text": "fonts/DMSerifText-Regular.ttf",
	}
	
	text = ft.Text("Test", font_family="DM Serif Text")
	page.controls.append(text)

	# Image to show that other assets are working
	text = ft.Image(src="images/placeholder.jpg")
	page.controls.append(text)
	
ft.run(main, assets_dir="assets")

Full example with assets: ex.zip

To reproduce

  1. Run Code
  2. Font does not load
  3. Text not displayed with specified font

Expected behavior

The text being rendered with the specified font

Screenshots / Videos

Captures Image

Operating System

Linux

Operating system details

Debian Trixie

Flet version

0.70.0.dev5066

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs

Logs from flet run

** (flet:19397): CRITICAL **: 11:23:55.378: Failed to create AudioController: Unable to find mixer control: Master
hideWindowOnStart: null
Flet View is running in Desktop mode
Args contain a path to PID file: /tmp/W19LLKsfhWF3UCSvIgn5}
Args contain a path assets directory: /home/manuel/Schreibtisch/dBox/ex/assets}
Page URL: /tmp/AvRxKXnDqO
Page updated: TargetPlatform.linux TargetPlatform.linux
Page.initState: 1
Page.didChangeDependencies: 1
Page.build: 1
Page navigator build: 1
Route changed: /
Page navigator build: 1
Platform brightness updated: Brightness.light
Page media updated: PageMediaData
Page size updated: Instance of 'Size'
Window state updated: {maximized: false, minimized: false, full_screen: false, always_on_top: false, focused: false, visible: true, minimizable: true, maximizable: true, resizable: true, prevent_close: false, skip_task_bar: false, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, opacity: 1.0}
Notify Page(1)
Page updated: TargetPlatform.linux TargetPlatform.linux
Registering web client with route: /
Connecting to Flet backend /tmp/AvRxKXnDqO...
Connecting to Socket /tmp/AvRxKXnDqO...
Connected to: InternetAddress('/tmp/AvRxKXnDqO', Unix)
_send: MessageAction.registerClient {session_id: null, page_name: tmp/AvRxKXnDqO, page: {route: /, pwa: false, web: false, debug: false, wasm: false, multi_view: false, platform_brightness: light, width: 1280.0, height: 720.0, platform: linux, window: {maximized: false, minimized: false, full_screen: false, always_on_top: false, focused: false, visible: true, minimizable: true, maximizable: true, resizable: true, prevent_close: false, skip_task_bar: false, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, opacity: 1.0}, media: {padding: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}, view_padding: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}, view_insets: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}}}}
Received packet: 909
Received message: [1, {session_id: t8CSV7NKAwbzccfF, page_patch: {_i: 1, _c: Page, views: [{_i: 5, _c: View}], _overlay: {_i: 6, _c: Overlay}, _dialogs: {_i: 7, _c: Dialogs}, width: 1280.0, height: 720.0, media: {padding: {left: 0.0, top: 0.0, right: 0.0, bottom: 0.0}, view_padding: {left: 0.0, top: 0.0, right: 0.0, bottom: 0.0}, view_insets: {left: 0.0, top: 0.0, right: 0.0, bottom: 0.0}}, window: {_i: 2, _c: Window, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, focused: false}, browser_context_menu: {_i: 9, _c: BrowserContextMenu}, shared_preferences: {_i: 10, _c: SharedPreferences}, clipboard: {_i: 11, _c: Clipboard}, storage_paths: {_i: 12, _c: StoragePaths}, url_launcher: {_i: 13, _c: UrlLauncher}, _user_services: {_i: 14, _c: ServiceRegistry}, _page_services: {_i: 15, _c: ServiceRegistry, services: [{_i: 9, _c: BrowserContextMenu}, {_i: 10, _c: SharedPreferences}, {_i: 11, _c: Clipboard}, {_i: 13, _c: UrlLauncher}, {_i: 12, _c: StoragePaths}]}, route: /, platform: linux, platform_brightness: light}, error: }]
Do not set cookie!
Notify Page(1)
Page updated: TargetPlatform.linux TargetPlatform.linux
Send queue: 4
_send: MessageAction.updateControl {id: 1, props: {platform_brightness: light}}
_send: MessageAction.updateControl {id: 1, props: {media: {padding: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}, view_padding: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}, view_insets: {top: 0.0, right: 0.0, bottom: 0.0, left: 0.0}}}}
_send: MessageAction.updateControl {id: 1, props: {width: 1280.0, height: 720.0}}
_send: MessageAction.updateControl {id: 2, props: {maximized: false, minimized: false, full_screen: false, always_on_top: false, focused: false, visible: true, minimizable: true, maximizable: true, resizable: true, prevent_close: false, skip_task_bar: false, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, opacity: 1.0}}
Received packet: 187
Received message: [2, {id: 1, patch: [[0, {views: [1, {0: [2]}]}], [0, 0, fonts, {DM Serif Text: fonts/DMSerifText-Regular.ttf}], [0, 2, controls, [{_i: 17, _c: Text, value: Test, font_family: DM Serif Text}, {_i: 18, _c: Image, src: images/placeholder.jpg}]]]}]
Control(1).applyPatch: [[0, {views: [1, {0: [2]}]}], [0, 0, fonts, {DM Serif Text: fonts/DMSerifText-Regular.ttf}], [0, 2, controls, [{_i: 17, _c: Text, value: Test, font_family: DM Serif Text}, {_i: 18, _c: Image, src: images/placeholder.jpg}]]], shouldNotify = true
Notify Page(1)
Page updated: TargetPlatform.linux TargetPlatform.linux
Notify View(5)
Page.didUpdateWidget: 1
Init service registry: 15
_onServicesUpdated(5)
BrowserContextMenuService(9).init: {}
SharedPreferencesService(10).init: {}
ClipboardService(11).init: {}
UrlLauncherService(13).init: {}
StoragePaths(12).init: {}
Init service registry: 14
_onServicesUpdated(0)
Load font from file: fonts/DMSerifText-Regular.ttf
Page.build: 1
Page navigator build: 1
View.initState: 5
View.build: 5
ScrollableControl build: 5
Text build: 17
Image build: 18
Window.initState()
Window.didChangeDependencies: 2
Error loading font DM Serif Text: PathNotFoundException: Cannot open file, path = 'fonts/DMSerifText-Regular.ttf' (OS Error: Datei oder Verzeichnis nicht gefunden, errno = 2)
Window event - blur: {maximized: false, minimized: false, full_screen: false, always_on_top: false, focused: false, visible: true, minimizable: true, maximizable: true, resizable: true, prevent_close: false, skip_task_bar: false, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, opacity: 1.0}
_send: MessageAction.updateControl {id: 2, props: {maximized: false, minimized: false, full_screen: false, always_on_top: false, focused: false, visible: true, minimizable: true, maximizable: true, resizable: true, prevent_close: false, skip_task_bar: false, width: 1280.0, height: 720.0, top: 23.0, left: 26.0, opacity: 1.0}}

Additional details

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions