Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to detect sans-serif font #1240

Closed
theduke opened this issue May 5, 2022 · 9 comments · Fixed by #1245
Closed

Failure to detect sans-serif font #1240

theduke opened this issue May 5, 2022 · 9 comments · Fixed by #1245
Labels
a:text Text rendering, fonts, Text input (mS,bF)

Comments

@theduke
Copy link
Contributor

theduke commented May 5, 2022

Slint apparently fails to detect fonts on my system, even though there are definitely sans-serif fonts installed.

Error: thread 'main' panicked at 'there must be a sans-serif font face registered', /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/fonts.rs:273:14

Backtrace
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/sysman`
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoWaylandLib X11 status: LibraryOpenError(OpenError { kind: Library, detail: "opening library failed (libX11.so.6: cannot open shared object file: No such file or directory); opening library failed (libX11.so: cannot open shared object file: No such file or directory)" })', /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:619:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/core/src/panicking.rs:142:14
   2: winit::platform_impl::platform::EventLoop::new_any_thread
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:619:9
   3: winit::platform_impl::platform::EventLoop::new
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:574:9
   4: winit::event_loop::EventLoop::with_user_event
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/event_loop.rs:134:25
   5: i_slint_backend_gl::event_loop::NotRunningEventLoop::new
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/event_loop.rs:163:24
   6: i_slint_backend_gl::event_loop::MAYBE_LOOP_INSTANCE::__init
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/event_loop.rs:201:90
   7: i_slint_backend_gl::event_loop::MAYBE_LOOP_INSTANCE::__getit::{{closure}}
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:353:25
   8: std::thread::local::lazy::LazyKeyInner::initialize
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:809:25
   9: std::thread::local::fast::Key::try_initialize
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:987:31
  10: std::thread::local::fast::Key::get
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:970:29
  11: i_slint_backend_gl::event_loop::MAYBE_LOOP_INSTANCE::__getit
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:345:21
  12: std::thread::local::LocalKey::try_with
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:444:32
  13: std::thread::local::LocalKey::with
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/std/src/thread/local.rs:421:9
  14: i_slint_backend_gl::event_loop::with_window_target
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/event_loop.rs:254:9
  15: i_slint_backend_gl::glcontext::OpenGLContext::new_context_and_renderer
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/glcontext.rs:108:36
  16: ::show
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-gl-0.2.2/glwindow.rs:459:13
  17: i_slint_core::window::Window::show
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-core-0.2.2/window.rs:529:9
  18: i_slint_core::api::Window::show
             at /home/theduke/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-core-0.2.2/api.rs:122:9
  19: ::show
             at ./src/main.rs:5:1
  20: ::run
             at ./src/main.rs:5:1
  21: sysman::main
             at ./src/main.rs:2:5
  22: core::ops::function::FnOnce::call_once
             at /rustc/e1b71feb592ba64805689e2b15b9fa570182c442/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I have a custom fontconfig at ~/.config/fontconfig/conf.d/10-hm-fonts.conf.

Maybe servo-fontconfig fails to parse that?

<?xml version='1.0'?>

<!-- Generated by Home Manager. -->

<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
  <include ignore_missing="yes">/nix/store/l32dq2s60hfzz1wiqsgnca9bwz3w1aqm-home-manager-path/etc/fonts/conf.d</include>
  <include ignore_missing="yes">/nix/store/l32dq2s60hfzz1wiqsgnca9bwz3w1aqm-home-manager-path/etc/fonts/fonts.conf</include>

  <dir>/nix/store/l32dq2s60hfzz1wiqsgnca9bwz3w1aqm-home-manager-path/lib/X11/fonts</dir>
  <dir>/nix/store/l32dq2s60hfzz1wiqsgnca9bwz3w1aqm-home-manager-path/share/fonts</dir>
  <dir>/etc/profiles/per-user/theduke/lib/X11/fonts</dir>
  <dir>/etc/profiles/per-user/theduke/share/fonts</dir>

  <cachedir>/nix/store/l32dq2s60hfzz1wiqsgnca9bwz3w1aqm-home-manager-path/lib/fontconfig/cache</cachedir>
</fontconfig>

Environment

Linux / NixOS
(WM: Sway / Wayland)

@tronical
Copy link
Member

tronical commented May 6, 2022

Interesting! In this environment, what do you get as output when you run fc-match sans-serif?

@ogoffart ogoffart added the a:text Text rendering, fonts, Text input (mS,bF) label May 6, 2022
@theduke
Copy link
Contributor Author

theduke commented May 6, 2022

> fc-match sans-serif
DejaVuSans.ttf: "DejaVu Sans" "Book"

@theduke
Copy link
Contributor Author

theduke commented May 6, 2022

I also tried copying a font into '~/.local/share/fonts` and cleaning the cache, but that did not help.

@tronical
Copy link
Member

tronical commented May 7, 2022

Darn, that looks correct. Would it be possible for you to share your nix config in a way that I could try to reproduce this?

@tronical
Copy link
Member

tronical commented May 7, 2022

I think I know what the issue might be. We do find the font that aliases sans-serif, but the fontdb implementation fails to locate the files.

@tronical
Copy link
Member

tronical commented May 7, 2022

Could you try this patch?

diff --git a/internal/backends/gl/Cargo.toml b/internal/backends/gl/Cargo.toml
index 93f941e2f..f9842412a 100644
--- a/internal/backends/gl/Cargo.toml
+++ b/internal/backends/gl/Cargo.toml
@@ -60,7 +60,7 @@ web-sys = { version = "0.3", features=["console", "WebGlContextAttributes", "Can
 wasm-bindgen = { version = "0.2" }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-fontdb = { version = "0.9.0", features = ["memmap"] }
+fontdb = { version = "0.9.0", features = ["memmap", "fontconfig"] }
 glutin = { version = "0.28", default-features = false }
 usvg = { version= "0.22", optional = true, default-features = false, features = ["text", "memmap-fonts"] }
 
diff --git a/internal/compiler/Cargo.toml b/internal/compiler/Cargo.toml
index 27237c94c..f908a05a1 100644
--- a/internal/compiler/Cargo.toml
+++ b/internal/compiler/Cargo.toml
@@ -49,7 +49,7 @@ once_cell = "1"
 url = "2.2.1"
 dunce = "1.0.1"
 linked_hash_set = "0.1.4"
-fontdb = { version = "0.9.0" }
+fontdb = { version = "0.9.0", features = ["fontconfig"] }
 fontdue = { version = "0.7.1" }
 
 # for processing and embedding the rendered image (texture)

@theduke
Copy link
Contributor Author

theduke commented May 7, 2022

Could you try this patch?

Yes, that did indeed do the trick.
Thanks!

@theduke
Copy link
Contributor Author

theduke commented May 7, 2022

As a point of reference, here is the flake.nix file I needed to get Slint running in a devshell on Nix + Wayland.

Maybe it will help out others (and could be included somewhere in the docs).

{
  description = "app";

  inputs = {
    flakeutils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flakeutils }:
    flakeutils.lib.eachDefaultSystem (system:
      let
        NAME = "app";
        VERSION = "0.1";

        pkgs = import nixpkgs {
          inherit system;
        };

      in
      rec {

        packages.${NAME} = pkgs.stdenv.mkDerivation {
          pname = NAME;
          version = VERSION;

          buildPhase = "echo 'no-build'";
        };

        defaultPackage = packages.${NAME};

        # For `nix run`.
        apps.${NAME} = flakeutils.lib.mkApp {
          drv = packages.${NAME};
        };
        defaultApp = apps.${NAME};

        devShell = pkgs.stdenv.mkDerivation {
          name = NAME;
          src = self;
          buildInputs = with pkgs; [
            pkgconfig
            cmake
            xorg.libxcb
            xorg.libXfixes
            libxkbcommon
            fontconfig
            wayland
            libGL
            # egl-wayland
          ];
          runtimeDependencies = with pkgs; [ ];

          shellHook = ''
            export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath (with pkgs; [
              xorg.libxcb
              xorg.libXfixes
              libxkbcommon
              fontconfig
              wayland
              libGL
            ])}";
          '';
        };
      }
    );
}

tronical added a commit that referenced this issue May 7, 2022
…nments

Enable fontdb's fontconfig feature to parse fontconfig files to locate
the directories where truetype fonts are located. This helps in system
setups that differ from the defaults that fontdb uses otherwise.

Fixes #1240
tronical added a commit that referenced this issue May 7, 2022
…nments

Enable fontdb's fontconfig feature to parse fontconfig files to locate
the directories where truetype fonts are located. This helps in system
setups that differ from the defaults that fontdb uses otherwise.

Fixes #1240
@tronical
Copy link
Member

tronical commented May 7, 2022

Could you try this patch?

Yes, that did indeed do the trick. Thanks!

Thanks for checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:text Text rendering, fonts, Text input (mS,bF)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants