Repository: flxzt/rnote (language: rust)

Issue:
Bundle a Handwrite-y Font
Hi all, 

my understanding is, that the text fonts, that I can choose from here  

![grafik](https://github.com/flxzt/rnote/assets/36572014/730aa1d6-0b33-499e-987d-99ca195bd0be)


are those from my system - correct me, if I am wrong. 

If so, I do lack a nice looking handwrite-y font, that blends in well with the idea of a note taking app;
like in may case, I'd imagine that many people don't really know how to install an additional font, or if they could learn, 
are too lazy for it.
 
Therefore, in order to improve the default experience,  I would suggest to 

* bundle at least one handwrite-y font with flathub
* set it by default

Personally I like the [Virgil](https://virgil.excalidraw.com/) font that's used by Excalidraw. Tldraw uses [Shantellsans](https://shantellsans.com/).





Discussion / hints:
Just for fun: Cantarell vs Virgil

![grafik](https://github.com/flxzt/rnote/assets/36572014/1dd80dfe-bffb-4a8c-b3e3-53a097207d85)


Just to show off.. 

![grafik](https://github.com/flxzt/rnote/assets/36572014/24ce2f17-f8ca-47b9-9ce5-71534a5a7460)

I like it! it would complement the handwriting very well. I'll see if we can include this in the next release
@dehesselle what would be the best way to bundle a font on MacOS, or do you know how Inkscape will do it in v1.3? Unfortunately I could not find a good way to load in a custom font programmatically, so I think we have to install it to the system on all platforms.
I think I'll add it to the application bundle and add the path so that fontconfig finds it. I'll need to run some tests to confirm.
I've figured it out. (And I noticed "I've done this before" somewhere 😆.) It's an easy setting, doesn't involve fontconfig.
I can move forward anytime, I just need to know which font to bundle.
One more thing: this feature has an impact on export formats like PDF. The font needs to be embedded during export, otherwise Rnote will create PDFs that don't look like the original drawing.

Fix patch:
diff --git a/README.md b/README.md
index e6d15e26e4..1f209d8ce5 100644
--- a/README.md
+++ b/README.md
@@ -147,6 +147,17 @@ A great way to contribute to the project without writing code is adding a new or
 - take the `rnote.pot` file and generate a new `.po` translation file from it, for example with "Poedit". Add the new translation language to `LINGUAS` and submit a PR with the changed files.
 - use [weblate](https://hosted.weblate.org/projects/rnote/repo/) for an easy way to translate in the browser without having to deal with git.
 
+## Fonts
+
+The following fonts are bundled with the application:
+
+- [Grape Nuts](https://fonts.google.com/specimen/Grape+Nuts): Grape Nuts is a simple handwritten casual font.
+- [OpenDyslexic-Regular](https://github.com/antijingoist/opendyslexic): OpenDyslexic is a typeface designed against some
+    common symptoms of dyslexia.
+- [TT2020Base-Regular](https://github.com/ctrlcctrlv/TT2020): TT2020 is an advanced, open source, hyperrealistic,
+    multilingual typewriter font for a new decade.
+- [Virgil](https://virgil.excalidraw.com/): The font that powers Excalidraw.
+
 ## File Format
 
 The `.rnote` file format is a gzipped json file.
diff --git a/build-aux/meson_post_install.py b/build-aux/meson_post_install.py
index 2b628dba21..ed7769cb22 100644
--- a/build-aux/meson_post_install.py
+++ b/build-aux/meson_post_install.py
@@ -10,24 +10,28 @@
 bindir = sys.argv[2]
 app_bin = sys.argv[3]
 
-if not os.environ.get('DESTDIR', ''):
-    if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
-        print('Updating icon cache...', file=sys.stderr)
-        call(['gtk4-update-icon-cache', '-qtf', os.path.join(datadir, 'icons/hicolor')])
+if not os.environ.get("DESTDIR", ""):
+    if sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
+        print("Updating icon cache...", file=sys.stderr)
+        call(["gtk4-update-icon-cache", "-qtf", os.path.join(datadir, "icons/hicolor")])
         print("Compiling new schemas...", file=sys.stderr)
-        call(["glib-compile-schemas", os.path.join(datadir, 'glib-2.0/schemas')])
+        call(["glib-compile-schemas", os.path.join(datadir, "glib-2.0/schemas")])
         print("Updating desktop database...", file=sys.stderr)
-        call(["update-desktop-database", os.path.join(datadir, 'applications')])
+        call(["update-desktop-database", os.path.join(datadir, "applications")])
         print("Updating MIME-type database...", file=sys.stderr)
-        call(["update-mime-database", os.path.join(datadir, 'mime')])
+        call(["update-mime-database", os.path.join(datadir, "mime")])
+        print("Rebuilding font cache...", file=sys.stderr)
+        call(["fc-cache", "-v", "-f"])
     elif sys.platform == "win32":
-        print('Updating icon cache...', file=sys.stderr)
-        call(['gtk-update-icon-cache.exe', '-qtf', os.path.join(datadir, 'icons/hicolor')])
+        print("Updating icon cache...", file=sys.stderr)
+        call(["gtk-update-icon-cache.exe", "-qtf", os.path.join(datadir, "icons/hicolor")])
         print("Compiling new schemas...", file=sys.stderr)
-        call(["glib-compile-schemas.exe", os.path.join(datadir, 'glib-2.0/schemas')])
+        call(["glib-compile-schemas.exe", os.path.join(datadir, "glib-2.0/schemas")])
         print("Updating desktop database...", file=sys.stderr)
-        call(["update-desktop-database.exe", os.path.join(datadir, 'applications')])
+        call(["update-desktop-database.exe", os.path.join(datadir, "applications")])
         print("Updating MIME-type database...", file=sys.stderr)
-        call(["update-mime-database.exe", os.path.join(datadir, 'mime')])
+        call(["update-mime-database.exe", os.path.join(datadir, "mime")])
+        print("Rebuilding font cache...", file=sys.stderr)
+        call(["fc-cache.exe", "-v", "-f"])
     else:
         print(f"[WARNING] \"meson_post_install.py\" is not configured to run on platform: {sys.platform}", file=sys.stderr)
diff --git a/build-aux/rnote_inno.iss.in b/build-aux/rnote_inno.iss.in
index 1a2ee757ed..40664acbb0 100644
--- a/build-aux/rnote_inno.iss.in
+++ b/build-aux/rnote_inno.iss.in
@@ -72,7 +72,12 @@ Source: "{#meson_source_root}\crates\rnote-ui\data\icons\application-rnote.ico";
 Source: "{#meson_source_root}\crates\rnote-ui\data\icons\scalable\apps\{#app_name}.svg"; DestDir: "{app}\share\icons\hicolor\scalable\apps"; Flags: ignoreversion recursesubdirs createallsubdirs
 ; Locale
 Source: "{#meson_build_root}\locale\*"; DestDir: "{app}\share\locale"; Flags: ignoreversion recursesubdirs createallsubdirs
-; data files (that go into pkg-data-dir)
+; Fonts
+Source: "{#meson_source_root}\crates\rnote-engine\data\fonts\GrapeNuts-Regular.ttf"; DestDir: "{autofonts}"; FontInstall: "Grape Nuts"; Flags: onlyifdoesntexist uninsneveruninstall
+Source: "{#meson_source_root}\crates\rnote-engine\data\fonts\OpenDyslexic-Regular.ttf"; DestDir: "{autofonts}"; FontInstall: "OpenDyslexic"; Flags: onlyifdoesntexist uninsneveruninstall
+Source: "{#meson_source_root}\crates\rnote-engine\data\fonts\TT2020Base-Regular.ttf"; DestDir: "{autofonts}"; FontInstall: "TT2020Base"; Flags: onlyifdoesntexist uninsneveruninstall
+Source: "{#meson_source_root}\crates\rnote-engine\data\fonts\Virgil.ttf"; DestDir: "{autofonts}"; FontInstall: "Virgil"; Flags: onlyifdoesntexist uninsneveruninstall
+; app data (that goes to pkg-data-dir)
 Source: "{#meson_build_root}\crates\rnote-ui\data\resources.gresource"; DestDir: "{app}\share\rnote"; Flags: ignoreversion recursesubdirs createallsubdirs
 Source: "{#meson_source_root}\crates\rnote-engine\data\sounds\*"; DestDir: "{app}\share\rnote\sounds"; Flags: ignoreversion recursesubdirs createallsubdirs
 ; Binary
diff --git a/crates/rnote-engine/data/09-fc.conf.in b/crates/rnote-engine/data/09-fc.conf.in
new file mode 100644
index 0000000000..b4370182a3
--- /dev/null
+++ b/crates/rnote-engine/data/09-fc.conf.in
@@ -0,0 +1,4 @@
+<!DOCTYPE fontconfig SYSTEM 'urn::fontconfig::fonts.dtd'>
+<fontconfig>
+ <dir>@PKG_DATA_DIR@/fonts</dir>
+</fontconfig>
\ No newline at end of file
diff --git a/crates/rnote-engine/data/fonts/GrapeNuts-Regular.ttf b/crates/rnote-engine/data/fonts/GrapeNuts-Regular.ttf
new file mode 100644
index 0000000000..d2db834994
Binary files /dev/null and b/crates/rnote-engine/data/fonts/GrapeNuts-Regular.ttf differ
diff --git a/crates/rnote-engine/data/fonts/LICENSES.md b/crates/rnote-engine/data/fonts/LICENSES.md
new file mode 100644
index 0000000000..411490b8a2
--- /dev/null
+++ b/crates/rnote-engine/data/fonts/LICENSES.md
@@ -0,0 +1,25 @@
+# Font Licenses
+
+**GrapeNuts-Regular**
+Creator: Robert Leuschke
+Description: "Grape Nuts is a simple handwritten casual font."
+Source: [https://fonts.google.com/specimen/Grape+Nuts](https://fonts.google.com/specimen/Grape+Nuts)
+License: [OFL-1.1](https://spdx.org/licenses/OFL-1.1.html)  
+
+**OpenDyslexic-Regular**
+Creator: [antijingoist](https://github.com/antijingoist)
+Description: "OpenDyslexic is a typeface designed against some common symptoms of dyslexia."
+Source: [https://github.com/antijingoist/opendyslexic](https://github.com/antijingoist/opendyslexic)
+License: [OFL-1.1](https://spdx.org/licenses/OFL-1.1.html)  
+
+**TT2020Base-Regular**
+Creator: Fredrick R. Brennan
+Description: "TT2020 is an advanced, open source, hyperrealistic, multilingual typewriter font for a new decade."
+Source: [https://github.com/ctrlcctrlv/TT2020](https://github.com/ctrlcctrlv/TT2020)
+License: [OFL-1.1](https://spdx.org/licenses/OFL-1.1.html)  
+
+**Virgil**  
+Creator: [Excalidraw](https://github.com/excalidraw)  
+Description: "The font that powers Excalidraw."
+Source: [https://github.com/excalidraw/virgil](https://github.com/excalidraw/virgil)  
+License: [OFL-1.1](https://spdx.org/licenses/OFL-1.1.html)  
diff --git a/crates/rnote-engine/data/fonts/OpenDyslexic-Regular.ttf b/crates/rnote-engine/data/fonts/OpenDyslexic-Regular.ttf
new file mode 100644
index 0000000000..b0177d2266
Binary files /dev/null and b/crates/rnote-engine/data/fonts/OpenDyslexic-Regular.ttf differ
diff --git a/crates/rnote-engine/data/fonts/TT2020Base-Regular.ttf b/crates/rnote-engine/data/fonts/TT2020Base-Regular.ttf
new file mode 100644
index 0000000000..625aa8df54
Binary files /dev/null and b/crates/rnote-engine/data/fonts/TT2020Base-Regular.ttf differ
diff --git a/crates/rnote-engine/data/fonts/Virgil.ttf b/crates/rnote-engine/data/fonts/Virgil.ttf
new file mode 100644
index 0000000000..e2e6e1cee8
Binary files /dev/null and b/crates/rnote-engine/data/fonts/Virgil.ttf differ
diff --git a/crates/rnote-engine/data/meson.build b/crates/rnote-engine/data/meson.build
index 144c36d9f3..7e6cbdaa55 100644
--- a/crates/rnote-engine/data/meson.build
+++ b/crates/rnote-engine/data/meson.build
@@ -52,5 +52,33 @@ sounds_files = files(
     'sounds/typewriter/typewriter_thump.wav',
 )
 
-# install flat in one directory
+# install sounds flat in one directory
 install_data(sounds_files, install_dir: pkgdatadir / 'sounds')
+
+
+# fonts
+fonts_files = files(
+    'fonts/GrapeNuts-Regular.ttf',
+    'fonts/OpenDyslexic-Regular.ttf',
+    'fonts/TT2020Base-Regular.ttf',
+    'fonts/Virgil.ttf',
+)
+
+# install fonts
+install_data(fonts_files, install_dir: pkgdatadir / 'fonts')
+
+# fontconfig file
+message('Configuring fontconfig file')
+
+fc_conf = configuration_data()
+fc_conf.set('APP_ID', app_id)
+fc_conf.set('APP_NAME', app_name)
+fc_conf.set('APP_NAME_CAPITALIZED', app_name_capitalized)
+fc_conf.set('PKG_DATA_DIR', pkgdatadir)
+fc_file_in = configure_file(
+    input: '09-fc.conf.in',
+    output: '09-' + app_name + '.conf',
+    configuration: fc_conf,
+    install: true,
+    install_dir: sysconfdir / 'fonts/conf.d',
+)
diff --git a/crates/rnote-engine/data/sounds/Licenses.md b/crates/rnote-engine/data/sounds/LICENSES.md
similarity index 98%
rename from crates/rnote-engine/data/sounds/Licenses.md
rename to crates/rnote-engine/data/sounds/LICENSES.md
index 7d368eb10d..1480782f13 100644
--- a/crates/rnote-engine/data/sounds/Licenses.md
+++ b/crates/rnote-engine/data/sounds/LICENSES.md
@@ -1,4 +1,4 @@
-Licenses:
+# Sounds Licenses
 
 **marker.wav** + **marker_<i>.wav**  
 License: [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/legalcode)  
diff --git a/meson.build b/meson.build
index 3a06cc42ce..d94379a014 100644
--- a/meson.build
+++ b/meson.build
@@ -18,6 +18,7 @@ bindir = prefix / get_option('bindir')
 datadir = prefix / get_option('datadir')
 libdir = prefix / get_option('libdir')
 localedir = prefix / get_option('localedir')
+sysconfdir = prefix / get_option('sysconfdir')
 profile = get_option('profile')
 build_cli = get_option('cli')
 msys_path = get_option('msys-path')
@@ -81,6 +82,7 @@ glib_compile_resources = find_program('glib-compile-resources', required: true)
 glib_compile_schemas = find_program('glib-compile-schemas', required: true)
 desktop_file_validate = find_program('desktop-file-validate', required: false)
 appstream_util = find_program('appstream-util', required: false)
+fc_cache = find_program('fc-cache', required: false)
 update_mime_database = find_program('update-mime-database', required: false)
 cargo_build_script = find_program('build-aux/cargo_build.py')
 inno_build_script = find_program('build-aux/inno_build.py', required: true)


Test patch: