servo / font-kit

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

Clipped rendering on Windows #85

Closed RazrFalcon closed 5 years ago

RazrFalcon commented 5 years ago

Looks like a rendering canvas doesn't have an enough space.

>cargo run --example render-glyph -- ArialMT { 32
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target\debug\examples\render-glyph.exe ArialMT { 32`
glyph 94:

            ▓▓██████
          ██████████
        ▒▒████▒▒
        ▓▓██▓▓
        ▓▓██▓▓
        ▓▓██▓▓
        ▓▓██▓▓
        ▓▓██▓▓
        ▓▓██▓▓
        ████▓▓
        ████▒▒
      ▒▒████▒▒
    ▒▒████▓▓
░░████████
░░████▒▒
░░████████
    ▒▒████▓▓
      ▒▒████▒▒
      ░░████▒▒
        ████▓▓
        ▓▓██▓▓
        ▓▓██▓▓
        ▓▓██▓▓

Works correctly on Linux. Not sure about macOS.

@pcwalton I'm not familiar with dwrite. Can you take a look?

kud1ing commented 5 years ago

Not sure about macOS.

Seems to be complete on macOS, but more blurry:

glyph 94:
          ░░▒▒▓▓▓▓▓▓
        ░░▓▓████████
        ▒▒██████████
        ▓▓████▓▓░░░░
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░████▓▓      
      ▒▒████▓▓      
    ░░▓▓████▒▒      
░░▒▒▓▓██████░░      
▒▒██████▓▓▒▒        
▒▒██████▓▓░░        
▒▒████████▒▒        
░░░░▓▓██████░░      
    ░░▓▓████▒▒      
      ▒▒████▓▓      
      ░░████▓▓      
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████░░    
      ░░██████▒▒    
        ▓▓████▓▓▒▒▒▒
        ▒▒██████████
        ░░▓▓████████
          ░░▒▒▒▒▓▓▓▓
idursun commented 5 years ago

A little bit input about the issue:

Clipping is occurring because dwrite_analysis.get_alpha_texture_bounds is returning negative top values for char {.

Changing the following line https://github.com/pcwalton/font-kit/blob/2fd68a8e932d43d498d58021d6fc78c0c0eef81f/src/loaders/directwrite.rs#L481 to

point2(0,0)

is fixing the clipping in the example but messing up the baselining. (I am not sure if this is the right term to use)

I have tried silicon with the modified local version of font-kit and this is how it renders after the change.

image