Skip to content

Add emoji fonts support #289

@cppHusky

Description

@cppHusky

I found emoji fonts cannot be loaded by freetype-rs correctly, for example, when I try to load Noto Color Emoji,

$ cargo r --example single_glyph /usr/share/fonts/noto/NotoColorEmoji.ttf 🙂
warning: creating a mutable reference to mutable static is discouraged
  --> src/library.rs:53:48
   |
53 |         let err = unsafe { ffi::FT_New_Library(&mut MEMORY, &mut raw) };
   |                                                ^^^^^^^^^^^ mutable reference to mutable static
   |
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
   = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives
   = note: `#[warn(static_mut_refs)]` on by default
help: use `&raw mut` instead to create a raw pointer
   |
53 |         let err = unsafe { ffi::FT_New_Library(&raw mut MEMORY, &mut raw) };
   |                                                 +++

warning: `freetype-rs` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/single_glyph /usr/share/fonts/noto/NotoColorEmoji.ttf '🙂'`

thread 'main' panicked at examples/single_glyph.rs:40:43:
called `Result::unwrap()` on an `Err` value: InvalidPixelSize
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
   2: core::result::unwrap_failed
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1704:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1109:23
   4: single_glyph::main
             at ./examples/single_glyph.rs:40:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

However, if I load Noto Sans it works well. (but without glyph in this font it displays a tofu)

$ cargo r --example single_glyph /usr/share/fonts/noto/NotoSans-Regular.ttf 🙂
warning: creating a mutable reference to mutable static is discouraged
  --> src/library.rs:53:48
   |
53 |         let err = unsafe { ffi::FT_New_Library(&mut MEMORY, &mut raw) };
   |                                                ^^^^^^^^^^^ mutable reference to mutable static
   |
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
   = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives
   = note: `#[warn(static_mut_refs)]` on by default
help: use `&raw mut` instead to create a raw pointer
   |
53 |         let err = unsafe { ffi::FT_New_Library(&raw mut MEMORY, &mut raw) };
   |                                                 +++

warning: `freetype-rs` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/examples/single_glyph /usr/share/fonts/noto/NotoSans-Regular.ttf '🙂'`




  *************
  *+++++++++++*
  *+********++*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*       *+*
  *+*********+*
  *+++++++++++*

Will you consider supporting emoji fonts? Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions