Code Monkey home page Code Monkey logo

Comments (4)

rnkn avatar rnkn commented on July 20, 2024

Are you doing hyphenation? Might be better to save your time if you are. As far as I'm aware hyphenation is avoided in scripts (I think because it'd make for stilted line readings).

from wrap.

eprovst avatar eprovst commented on July 20, 2024

Yes and no.

Currently Wrap breaks lines by a greedy algorithm (at some point I might look at something similar to TeX's algorithm but screenplays are very constrained so I'm guessing that wouldn't give much better results).

First we collect cells (which are parts of the source text with certain markup, and are already grouped into lines as in the source file) until the line is full.

If there are too many characters on the line we search for a breakpoint in the last cell. A breakpoint is a Unicode space or a hyphen.

If we don't find a breakpoint we break at the upper limit the line length allows. If there are two letters here we insert a hyphen (most likely in a place where we shoudn't), otherwise we don't (but we probably broke a number in two).

There's a number of issues here:

  1. The best point to break is often in the cell before the current cell, cases like:
    ... end of long line compound_word._ where the ideal breakpoint is between line and compoundword but Wrap breaks compound and word in two, which might even be a mistake in some cases.
    #36 was a special case of this problem, where the last cell had length one. Wrap now backtracks one cell in that case, but ideally we would look to see if the start of the cell is a valid breakpoint before we break there and backtrack as needed.
  2. The current break possibilities are incomplete and even plain wrong (a non-breaking space is also a Unicode space).
  3. Currently we don't support different line lengths throughout a set of lines. Not a big issue but it does mean that the first line of a parenthetical currently get one character less than it should because of it's indentation.
  4. When we're forced to break the line at the limit a thing that could be checked first, is if there is another 'less ideal' breakpoint, eg. the first non letter from the right.

A similar set of issues exist for page breaks. Although we don't do anything wrong there, there are only better selection criteria which would try harder to avoid page breaks which break within an element, etc. (see #38)

from wrap.

rnkn avatar rnkn commented on July 20, 2024

Thanks, that’s an impressively comprehensive overview!

from wrap.

eprovst avatar eprovst commented on July 20, 2024

Started working on this on the linewrap branch. As of now only 3. is fixed.

from wrap.

Related Issues (20)

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.