servo / font-kit

A cross-platform font loading library written in Rust
Apache License 2.0
660 stars 98 forks source link

Cannot access source error on macOS #231

Open shanecelis opened 6 months ago

shanecelis commented 6 months ago

I get the following error when I run the latest commit on master (6dbec44). I had a font use issue using the plotters crate, which I submitted here. Then I figured I'd check font kit.

❯ RUST_BACKTRACE=1 cargo test --all
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
   --> src/loaders/core_text.rs:318:17
    |
318 |                 drop(self.typographic_bounds(glyph_id)?);
    |                 ^^^^^----------------------------------^
    |                      |
    |                      argument has type `RectF`
    |
    = note: use `let _ = ...` to ignore the expression or result
    = note: `#[warn(dropping_copy_types)]` on by default

warning: `font-kit` (lib) generated 1 warning
warning: `font-kit` (lib test) generated 1 warning (1 duplicate)
warning: function `check_filename` is never used
  --> tests/select_font.rs:52:4
   |
52 | fn check_filename(handle: &Handle, filename: &str) {
   |    ^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `font-kit` (test "select_font") generated 1 warning
    Finished test [unoptimized + debuginfo] target(s) in 0.05s
     Running unittests src/lib.rs (target/debug/deps/font_kit-e862f2696a9109b9)

running 5 tests
test loaders::core_text::test::test_core_text_to_css_font_stretch ... ok
test loaders::core_text::test::test_core_text_to_css_font_weight ... ok
test sources::core_text::test::test_css_to_core_text_font_stretch ... ok
test sources::core_text::test::test_css_to_core_text_font_weight ... ok
test loaders::core_text::test::test_from_core_graphics_font ... FAILED

failures:

---- loaders::core_text::test::test_from_core_graphics_font stdout ----
thread 'loaders::core_text::test::test_from_core_graphics_font' panicked at src/loaders/core_text.rs:940:14:
called `Result::unwrap()` on an `Err` value: CannotAccessSource
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1077:23
   4: font_kit::loaders::core_text::test::test_from_core_graphics_font
             at ./src/loaders/core_text.rs:938:21
   5: font_kit::loaders::core_text::test::test_from_core_graphics_font::{{closure}}
             at ./src/loaders/core_text.rs:937:38
   6: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

failures:
    loaders::core_text::test::test_from_core_graphics_font

test result: FAILED. 4 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

error: test failed, to rerun pass `--lib`

Version Information

I'm on macOS 14.0, x86; rustc 1.75.0.

shanecelis commented 6 months ago

The list-fonts example works.

> cargo run --example list-fonts | wc -l
1593
shanecelis commented 6 months ago

I did track down the issue. I had an extra Arial font file located in ~/Library/Fonts that the parser did not like. I removed that, and everything appears to be working now.

The error happened at this line. It would be nice if it had relayed some diagnostic information. I had to add the following before I could figure out what was going on.

        // Err(e) => Err(SelectionError::CannotAccessSource),
        Err(e) => {
            eprintln!("error {:?} path {:?}", e, font_path);
            Err(SelectionError::CannotAccessSource)
        },
shanecelis commented 5 months ago

Arial.zip

Here is the font file that was causing the issue. It looks like it's one of those weird files with a resource fork because it's empty according to the terminal but isn't empty according to the Finder or the zipfile.

❯ ls -l Arial
-rwxr-xr-x@ 1 shane  staff  0 Apr  8  2004 Arial
❯ xattr -l Arial
com.apple.FinderInfo: FFILDMOV
com.apple.ResourceFork:
com.apple.lastuseddate#PS: ��e