MFEK / stroke

A utility for stroking paths in font glyphs (UFO .glif) written in Rust.
Apache License 2.0
22 stars 0 forks source link

constant-width-stroking fails on simple closed contour, blames MFEKmath::variable_width_stroking #11

Closed ctrlcctrlv closed 3 years ago

ctrlcctrlv commented 3 years ago

Crash

[fred@laptop MFEKstroke]$ RUST_BACKTRACE=1 target/release/MFEKstroke cws -i ~/Workspace/FRBAmericanCursive/FRBAmericanCursive-SOURCE.ufo/glyphs/i.glif -w 9 -o /tmp/i.glif
thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', /home/fred/.cargo/git/checkouts/math.rlib-d2c76c88b18fa5ee/d3b705e/src/variable_width_stroking.rs:144:28
stack backtrace:
   0: rust_begin_unwind
             at /rustc/b1af43bc63bc7417938df056f7f25d456cc11b0e/library/std/src/panicking.rs:483:5
   1: core::panicking::panic_fmt
             at /rustc/b1af43bc63bc7417938df056f7f25d456cc11b0e/library/core/src/panicking.rs:85:14
   2: core::panicking::panic_bounds_check
             at /rustc/b1af43bc63bc7417938df056f7f25d456cc11b0e/library/core/src/panicking.rs:62:5
   3: MFEKmath::variable_width_stroking::variable_width_stroke
   4: MFEKstroke::constant_width_stroke::cws_cli
   5: MFEKstroke::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Glif

image

<?xml version="1.0" encoding="UTF-8"?>
<glyph name="i" format="2">
  <advance width="441"/>
  <unicode hex="0069"/>
  <outline>
    <contour>
      <point x="400" y="414" type="curve" smooth="yes"/>
      <point x="400" y="424"/>
      <point x="408" y="432"/>
      <point x="418" y="432" type="curve" smooth="yes"/>
      <point x="428" y="432"/>
      <point x="436" y="424"/>
      <point x="436" y="414" type="curve" smooth="yes"/>
      <point x="436" y="404"/>
      <point x="428" y="396"/>
      <point x="418" y="396" type="curve" smooth="yes"/>
      <point x="408" y="396"/>
      <point x="400" y="404"/>
    </contour>
    <contour>
      <point x="0" y="-2" type="move" smooth="yes"/>
      <point x="0" y="-2"/>
      <point x="228" y="115"/>
      <point x="325" y="255" type="curve"/>
      <point x="325" y="255"/>
      <point x="218.201" y="86.5527"/>
      <point x="218.201" y="32.8374" type="curve" smooth="yes"/>
      <point x="218.201" y="28.907"/>
      <point x="218.773" y="25.5909"/>
      <point x="220" y="23" type="curve"/>
      <point x="220" y="23"/>
      <point x="228.846" y="-7.76738"/>
      <point x="271.342" y="-7.76738" type="curve" smooth="yes"/>
      <point x="307.241" y="-7.76738"/>
      <point x="395.095" y="44.8568"/>
      <point x="441" y="77" type="curve" smooth="yes"/>
    </contour>
  </outline>
  <lib>
    <dict>
      <key>com.fontlab.hintData</key>
      <dict>
        <key>hhints</key>
        <array>
          <dict>
            <key>position</key>
            <integer>396</integer>
            <key>width</key>
            <integer>36</integer>
          </dict>
        </array>
        <key>vhints</key>
        <array>
          <dict>
            <key>position</key>
            <integer>400</integer>
            <key>width</key>
            <integer>36</integer>
          </dict>
        </array>
      </dict>
    </dict>
  </lib>
</glyph>

Misc

The line failed on in MFEKmath variable_width_stroking.rs is:

    let next_handle = &stroke_handles[i+1];