Git Product home page Git Product logo

crawdad's Introduction

Crawdad: Knuth-Plass linebreaking for Ruby

Crawdad is a basic implementation of the Knuth-Plass linebreaking algorithm for breaking paragraphs of text into lines. It uses a total-fit method to ensure consistency across the entire paragraph at once. The algorithm is a simplified version of the one used in the TeX typesetting system.

References

The canonical reference for this algorithm is "Breaking Paragraphs Into Lines", by Donald E. Knuth and Michael F. Plass, originally published in Software Practice and Experience 11 (1981), pp. 1119-1184. It is reprinted in the excellent monograph Digital Typography (Knuth 1999).

This implementation was inspired by Bram Stein's TypeSet project, an implementation of Knuth-Plass in Javascript that uses HTML5 Canvas.

http://www.bramstein.com/projects/typeset/

To Do

Short-Term

  • Collect all of our constants and magic numbers and expose them somewhat to the user. Survey other software (TeX?) to harvest good starting values for these parameters.

  • Fix the demerits calculation to the TeX "improved" formula (Digital Typography p. 154). Thanks to Bram Stein for pointing this out.

  • Implement the looseness parameter q (algorithm "Choose the appropriate active node", Digital Typography p. 120).

Long-Term

  • Bring this into Prawn, and integrate (if possible) with the Text::Box API.

  • The tokenizer could be smarter; it should recognize more than just low-ASCII hyphens as hyphens / dashes, and it can get confused when whitespace and hyphens interact.

  • Automatically relax the thresholds when the constraints cannot be satisfied? Or we could look into TeX's two-pass method (pp. 121-122).

Acknowledgements

Thanks are due to the following individuals:

  • Donald Knuth and Michael Plass created the original algorithm and data structures.

  • Bram Stein wrote the aforementioned Javascript implementation of the Knuth-Plass algorithm. His code was helpful in exposing some of the darker corners of the original authors' description of the method.

License

Crawdad is copyrighted free software, written by Brad Ediger. See the LICENSE file for details.

crawdad's People

Contributors

bradediger avatar

Stargazers

Michael Plass avatar zuo avatar  avatar Devon Govett avatar Ben Woodward avatar Claudia Doppioslash avatar Bram Stein avatar Andrew Lazarus avatar Gregory Brown avatar  avatar Bryce Mecum avatar

Watchers

 avatar Gregory Brown avatar  avatar Madriska Media Group, Inc. open-source projects avatar evandrix avatar James Cloos avatar Shunsaku Hirata avatar Michael Plass avatar

Forkers

unicornrainbow

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.