Skip to content

kiichi/stretch-paper-converter

Repository files navigation

Totally Unofficial Rendering Experiment of StretchPaper on Browser

Attempt to render StretchPaper App's drawing data on web browser (this is an awesome app if you have invested on Apple pencil 2 and iPad Pro, Good-Bye Dry Erase Board). This web conversion project is Totally Experimental and Unofficial.

Screenshots

Very simple Drawing

References

Full Credits and respects to the app develoepr + all those library + article authors:

Process

(my notes)

  1. Export StretchPaper raw data (.stretch)
  2. This is Base64 MessagePack format and it contains another binary plist contents for points
  3. Load the .stretch file using MessagePack
  4. Split by the new line char
  5. Decode Base64 each line
  6. Parse the line in MessagePack format (manually).
  7. There are some Uint16 chunk at offset 105. next byte is the length.
  8. Decode Base64 for the next n bytes.
  9. Get binary array into binary plist parser
  10. Get array of array which contains points data
  11. Each points consists of 5 values, and they repeats. [x, y, (z or inc counter), (pressure or stroke width), (0.25 something not sure)...]
  12. Translate them into SVG. Using line / polyline function for now. For smoothing effect, Bezier in path should be ideal (?) Smooth a Svg path with cubic bezier curves | by François Romain | Medium

Other Notes

Maybe just use SigPad?

My thought process:

  1. looks like base64 lines
  2. decoded
  3. Got hint "MessagePack"
  4. library didn't work but got "marker" information for each chunk
  5. simple format, so parse it out manually from the library soruce code
  6. look for useful chunk. found a string sequence "points"
  7. looks like another base64 chunk
  8. decoded, then found "bplist" sequence
  9. it make sense to have Uint16 (xcode is all 16bits), iOS info.plist format probably quick and easy way to save from NSData like serialization
  10. found bplist-parser library, but it's written in Node.js
  11. Tried browserify but no luck since Buffer object is native to OS
  12. Found ported browser version
  13. Tested import and figured it out to pass ArrayBuffer instead of native Node.js Buffer
  14. Got structured json (array) of floats.
  15. Saw the patter that every 5 elements seems to be repeating. Assume some structure start with x,y, etc...
  16. Search for svg rendering library
  17. Kind ok drawing using svg.line funciton. polyline should be faster but can not figure out dynamic width for each part
  18. figured out command + - either collapse or keep them so that we can do redo on web

Notes about command

  • Offset = 1 is command. + means added points and - means erased object(s)
  • If it's added, the GUID is stored in Offset 5 - 41.
  • If it's -, then one eraser stroken can erase multiple GUID(s)
  • Need collapse those before render, or it might be fun to do undo - redo stack on browser?

TODO

  • Parse other parts like meta information
  • figure out smooth curve with proper thickness
  • collapse original lines so that subtract erased lines

About

Attempt to render StretchPaper App's drawing data on web browser. Totally Experimental and Unofficial.

Topics

Resources

Stars

Watchers

Forks

Contributors