Giter Club home page Giter Club logo

font-rs's People

Contributors

adelarsq avatar alexheretic avatar codri avatar glowcoil avatar golddranks avatar hadronized avatar kpp avatar llogiq avatar mason-bially avatar raphlinus avatar rtsuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

font-rs's Issues

f32 -> u8 conversion should multiply by 256-ε instead of by 255

The Rust code has SIMD and non-SIMD versions of this conversion
(255.0 * y) as u8
from an f32 in the range [0.0, 1.0] to a u8 in the range [0, 255].

Due to rounding errors, this sometimes means that a pixel well inside a glyph ends up with an 0xfe value instead of 0xff, since its floating point value is slightly less than 1.

In my Go port, I embiggened the constant from 255.0 to 255.99998, or 0x437fffff as a float32 bit pattern, which eliminated these central "0xfe"s. See the comment at the bottom of google/font-go@7c31afd

I think that the Rust code should do the same.

Make font-rs production ready

It has been more or less often been stated that font-rs is capable of doing benchmarks, but still not production ready.
Many people are interested in font-rs and you called for participation.

What are the necessary steps to make font-rs production ready?

IIRC, there is rgb subpixeling and other issues to get around inadquate resolution on low-dpi displays. It would be nice if you could provide a Task List.

First thing i noticed is accessing the charmap of a font is not supported yet.

Integrate with Unicode’s text rendering tests

Would you be interested in testing font.rs through Unicode text rendering tests?

I’d volunteer to do the integration into the test suite on the Unicode side, if somebody familiar with Rust writes a command-line tool that can be called like this:

path/to/some-command --font=fonts/TestCMAP14.otf --testcase=Foo-5/6 --render=≩≩

writing an SVG file to stdout like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    viewBox="0 -120 1446 1200">
  <symbol id="Foo-5/6.uni2269" overflow="visible"><path d="M100,334 L623,563 L623,619 L100,880 L100,793 L518,594 L100,420 Z M100,208 L622,208 L622,287 L100,287 Z M100,38 L622,38 L622,117 L100,117 Z M282,-93 L508,379 L436,413 L211,-59 Z"/></symbol>
  <use xlink:href="#Foo-5/6.uni2269" x="0" y="0"/>
  <use xlink:href="#Foo-5/6.uni2269" x="723" y="0"/>
</svg>

For test cases on variable fonts, your tool would be called with an additional argument for the variation settings, such as --variation=wght:481.3;wdth:70. Initially, you could ignore this.

The test fonts are here. If you write a command-line tool that can be called as described, the generated test report will look like this, this, this, or this.

Potential wrapping add

self.a[linestart + x0i as usize] += d * a0;

x0i can be -1 in this case, and casting it to usize will give usize max. The addition with linestart will cause an arithmetic overflow. Wrapping add should be used.

Out-of-bounds path nodes shouldn't panic.

For well formed TrueType glyph data, the bounding box should contain all of the nodes. However, malicious data might lead to out-of-bounds nodes, so more bounds checking is necessary for a production quality rasterizer.

Even with well formed data, I suspect (based on my Go port) that the Rust version will panic at a line like

self.a[linestart + (x0i + 1) as usize]

when the glyph being rendered has an on-curve point at the bottom right corner of the rasterization buffer. You should be able to see this with the capital-'I' glyph from a sans-serif font.

In my Go port, I tightened this up in google/font-go@568cda6

Test fails with Roboto-Regular.ttf

When the CMap tests are run against Roboto-Regular.ttf from fuchsia/garnet/bin/fonts/third_party fails with the following message:

---- font::tests::test_cmap_format_4 stdout ----
thread 'font::tests::test_cmap_format_4' panicked at 'assertion failed: `(left == right)`
  left: `37`,
 right: `36`', src/font.rs:1073:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

A rounding bug with glyph id search

I'm getting a bug where the lookup_glyph_id function can't find a glyph even if it exists.
Here's a "trace" of the binary search it performs:

code point dec: 36196 hex: 8d64 char: 赤
size: 4247, index: 2123, end value: 29650
size: 2123, index: 4246, end value: 65509
size: 1061, index: 3185, end value: 34851
size: 530, index: 3715, end value: 37587
size: 265, index: 3450, end value: 36118
size: 132, index: 3582, end value: 36921
size: 66, index: 3516, end value: 36557
size: 33, index: 3483, end value: 36362
size: 16, index: 3467, end value: 36290
size: 8, index: 3459, end value: 36229
size: 4, index: 3455, end value: 36209
size: 2, index: 3453, end value: 36203
size: 1, index: 3452, end value: 36199
Error: StringError("Glyph doesn\'t exist")

The actual range that includes the glyph is in index 3451, so it's off by one. It's still in the range when the size is 33: 3483-33 = 3450, but drops from the range the next step: 3467-16 = 3451 (this is non-inclusive, as the size printed here was the size of the last step).

We can see that the the correrct result is excluded from the range because of a rounding error: Rust rounds always towards zero so 33/2 becomes 16, which makes it here lose enough of it's "jumping power" for it not to reach the correct range.

It seems to me that the correct thing to do is to ensure that the result is always rounded up.

Binary?

What should I do with the output of cargo build --release? I only get a libfont_rs.rlib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.