Text layout is a loose hierarchy of segmentation (2020)
raphlinus.github.io
raphlinus.github.io
- https://github.com/pop-os/cosmic-text/ - which is still has a way to go but already complex scenarios involving asian and arabic scripts, which is impressive considering it's only a couple of months old. This one is backed by System76 for use in their new desktop environment
- And https://github.com/dfrg/parley which looks abandoned but is already impressively complete and the author has signalled they intend to revisit at the start of this year. This one is being used in the Druid toolkit mentioned in the article (and it's successor Xilem) and also the text editor https://github.com/lapce/lapce which is based on that toolkit.
It does look like a very good year coming up! I'm writing a reflection/wishes post as we speak.
Doubtless, enormous brilliance went into Symbolics OS and UI code, all washed away when Symbolics tanked. On the up side, untold gigabytes of bad Java code were flushed in the big tech meltdown of 2000. When Twitter and Facebook go flat like inflatable lawn decorations in a cold snap, will much of anything be lost? (Anyway zstd and lz4 will survive.) How much stuff is coded in Wolfram?
Obscure code today goes onto GitHub repositories rather that just evaporating, but it is more manual labor to find and transcribe to a live language than can usually be mustered.
width(A) + width(B) != width(A+B)
...which some basic text layout engines assume. The post touches on this, and is one reason why line-breaking is so difficult.
If you add some text to a line, the width of the line may be longer or shorter(!) than if you measured (shaped) the parts separately.This occurs for many reasons, the post mentions splitting a ligature, can also happen with kerning (spaces can have kerning applied for example).
E.g. many text layout engines will incrementally "add" to a line. However to do this correctly for all cases you need to re-shape (measure) the entire line (or from a known "safe to break" point in the shape result see: https://github.com/harfbuzz/harfbuzz/issues/224 ). This is typically fine for latin cases, but begins to become slow for more complex scripts (Thai).
Chromium kinda works backwards. It tries to fit everything in the paragraph on a single line, shapes (measures), then finds a line-break opportunity within the (potentially large) shape result which would "fit" on the line without re-shaping. Then given that line-break will reshape the entire line (using the "safe to break" API), (and remaining content for the next line), see if it will fit and repeats the process[1].
By always "removing" content from the line you end up with a correct implementation which works for all the crazy things which can happen with text rendering.
[1] The content in the line may become bigger after taking a line-break, hence this needs to happen in a loop until there is one "unbreakable" piece of content in the line. This loop typically only goes through one iteration.
The first system I know of that does solve this very well is DirectWrite. Sergey Malkin describes the solution here: https://github.com/harfbuzz/harfbuzz/issues/1463#issuecommen...
It sounds like Chromium has since also adapted the "safe to break" API. Great to see people engaging these hard problems!
I'm curious what you mean regarding complex shapes across spaces. If it is related to the displayed bug regarding how words like "office" would be split, I don't think TeX ever had the bug as described. Though, I could be wrong, easily. (Incidentally, what a fun bug. Kudos to who found that one!)
Edit: I also had the impression that TeX would adjust intercharacter spacing as a whole to keep things looking a bit more uniform. Essentially, the goal was to act a lot like a human would when setting out the characters. If needed, you could adjust spacing on all characters within a margin of "not going to be noticed" so that you could expand a line of text to take up the full width. Without just having more space between a few words.
Some fonts have the space character in the kerning table, and possibly (although super rare) in the "ligature" table (gsub). (https://www.sansbullshitsans.com/ is an example of a font with a space in gsub, "paradigm shift" maps to a single glyph).
If you want to go really deep on how complex some scripts are take a look at: https://r12a.github.io/scripts/arabic/arb.html#shaping
That said, my understanding is that there really was no "optimal" for the best way to arrange text. You can, effectively, make an objective function that you can optimize on; but there is no global "this will make text look good" algorithm.
Indeed, even ligatures are... debatable in utility. I personally like them; but I would scoff at any claims for any objective superiority of them. They are fun and a bit of a "flex" for laying out text on a computer. Any other claim is going to be tough to hold up.
This is not conceptually a difficult problem, you can just shape all possible substrings between candidate line breaks to get their widths, at which point Knuth-Plass will give the optimal line breaks (relative to your objective function). But given that shaping is expensive, you really want to avoid that in the 99.99% or so cases where the width of the word isn't altered by other words beyond space boundaries. That's what the "safe to break" logic is about - letting you know when you can make that assumption, as opposed to needing to reshape to get the precise metrics.
[1]: https://en.wikipedia.org/wiki/Nastaliq#/media/File:Khatt-e_N...
Also, the original HTML tables algorithm was evidently meant for hardcopy output and not relayout-upon-typed-input, as it was horrendously slow without making some safe to break optimisations.
That said, logos are a good example where TeX is not suited. Odds are high that it will not help stack words in a way that works for slogans and such.
Though I think the main reason would be limited horizontal space, e.g. a table cell or narrow newspaper column.
And I only used "record" as it was the example given to me. I'm sure there are others. Is a good example for how/why counting syllables can be harder than folks think. Well, kind of a good example; since you will get the right count, regardless.
This is a common trend I keep seeing in technical blogs, and I don't understand why they do it.
Look, it's not that. It's just a series of small problems. Solve each problem one at a time, and you'll approximate a complete solution as you iterate further and further. Your first iteration will not be perfect, but so what?
In some cases this is just an unspoken assumption because the blog posts are looking at, say, Firefox, and Firefox supports a lot of languages. In other cases, it's framed as a moral or professional imperative -- you're a bad developer if you don't consider the needs of Arabic users, if not a bad person. (I'm not sure how I feel about the globalist/colonialist worldview that seems to drive this idea that Arabic users won't have any software if Silicon Valley doesn't write it for them. I guess if you work at a big global megacorporation, it's your job to write big global megasoftware.)
But yeah, if you aren't trying to do that, then text is a much easier problem than these posts describe. Tons and tons of embedded devices, video games, and so on get away with having much simpler text rendering and layout code that only supports a few languages. In English, you really can start with a very simple layout system, then add features like kerning and ligatures and hyphenation and watch the text get progressively nicer-looking!
Is there an Obsidian plugin for using this kind of structure? I know there’s the graph view for seeing how notes are linked together