Commit Graph

323 Commits

Author SHA1 Message Date
Laurenz e65c2b949c Remove resource abstraction and handle images natively 2021-05-14 11:14:28 +02:00
Laurenz 6292d25afb Reengineer font and resource loading 🏞 2021-04-23 17:46:14 +02:00
Laurenz 72478946c2 Make frames serializable 📚
This also makes serialization support non-optional since it's too much feature-management for too little benefit.
2021-04-21 21:17:25 +02:00
Laurenz 3d2ee54848 Refactor and comment ♻ 2021-04-07 01:08:07 +02:00
Laurenz 076e767b0e Do binary search and find the outermost glyph with the text index 🔍
Co-Authored-By: Martin <mhaug@live.de>
2021-04-07 00:24:42 +02:00
Laurenz 464a6ff75e Deduplicate ttf-parser and rustybuzz face 🥞 2021-04-06 15:13:20 +02:00
Laurenz de20a21a58 Reshaping with unsafe-to-break
Co-Authored-By: Martin <mhaug@live.de>
2021-04-05 22:32:09 +02:00
Laurenz 9014e83478 Fix multi-page paragraph bugs 🐞 2021-04-03 21:12:32 +02:00
Laurenz d74c9378b8 New paragraph layout 🚀
The previous paragraph layout algorithm had a couple of flaws:
- It always produced line break opportunities between runs although on
  the textual level there might have been none.
- It didn't handle trailing spacing correctly in some cases.
- It wouldn't have been easily adaptable to Knuth-Plass style optimal
  line breaking because it was fundamentally structured first-fit
  run-by-run.

The new paragraph layout algorithm fixes these flaws. It proceeds
roughly in the following stages:
1. Collect all text in the paragraph.
2. Compute BiDi embedding levels.
3. Shape all runs, layout all children and store the resulting items in
   a reusable (possibly even cacheable) `ParLayout`.
3. Iterate over all line breaks in the concatenated text.
4. Construct lightweight `LineLayout` objects for full lines instead of
   runs. These mostly borrow from the `ParLayout` and only reshape the
   first and last run if necessary. The design allows to use Harfbuzz's
   UNSAFE_TO_BREAK mechanism to make reshaping more efficient. The size
   of a `LineLayout` can be measured without building the line's frame.
5. Build only the selected line's frames and stack them.
2021-04-03 21:09:17 +02:00
Laurenz 8245b7b736 Baseline alignment ⏏ 2021-03-30 21:43:12 +02:00
Laurenz c00cca3677 Refactor ♻ 2021-03-30 16:19:16 +02:00
Laurenz 79948c0c5e BiDi reordering 🔃
Co-Authored-By: Martin <mhaug@live.de>
2021-03-30 14:31:50 +02:00
Laurenz c393eccd36 Fix space/newline trimming 🐞
Co-Authored-By: Martin <mhaug@live.de>
2021-03-30 14:31:46 +02:00
Laurenz 652986fd58 Fix double leading 🐞 2021-03-30 14:31:39 +02:00
Laurenz 88da325c7d Fixed par layouter directions 🗜 2021-03-29 15:02:15 +02:00
Laurenz 309b8f20a8 Line break iterating run shaper 🌵
Co-Authored-By: Martin <mhaug@live.de>
2021-03-29 15:02:15 +02:00
Laurenz 8c27dc1010 Write spaces and linebreaks into text runs ✒ 2021-03-29 15:02:15 +02:00
Laurenz 57ca9628c1 Better space coalescing logic 🌧
This creates a smaller state machine helper type for softness coalescing, which does not own the resulting nodes. While this creates a bit more duplication in stack and par builder, it makes it a lot easier to integrate additional logic into the paragraph builder.

Furthermore:
- Line breaks are now "hard", that is, not coalesced with each other.
- Text nodes with equal style are now merged allowing for example `f{}i` to form a ligature.
2021-03-27 21:52:39 +01:00
Laurenz 76fc4cca62 Refactor alignments & directions 📐
- Adds lang function
- Refactors execution context
- Adds StackChild and ParChild enums
2021-03-25 21:32:33 +01:00
Laurenz e8057a5385 Make pdf module top-level 🧱 2021-03-24 21:48:25 +01:00
Laurenz 73615f7e3c Text shaping 🚀
- Shapes text with rustybuzz
- Font fallback with family list
- Tofus are shown in the first font

Co-Authored-By: Martin <mhaug@live.de>
2021-03-24 17:12:34 +01:00
Laurenz 98336bfafb Better font family definitions ✒ 2021-03-22 14:08:50 +01:00
Laurenz 898728f260 Square, circle and ellipse 🔵 2021-03-20 20:19:30 +01:00
Martin 6cb9fe9064
Text colors 🦩 (#18) 2021-03-19 22:36:13 +01:00
Laurenz 898dc38ec1 Better debug representations 💻 2021-03-19 21:23:03 +01:00
Laurenz 264a7dedd4 Scheduled maintenance 🔨
- New naming scheme
  - TextNode instead of NodeText
  - CallExpr instead of ExprCall
  - ...
- Less glob imports
- Removes Value::Args variant
- Removes prelude
- Renames Layouted to Fragment
- Moves font into env
- Moves shaping into layout
- Moves frame into separate module
2021-03-19 17:57:31 +01:00
Laurenz 54a9ccb1a5 Configurable font edges ⚙
Adds top-edge and bottom-edge parameters to the font function. These define how
the box around a word is computed. The possible values are:
- ascender
- cap-height (default top edge)
- x-height
- baseline (default bottom edge)
- descender

The defaults are chosen so that it's easy to create good-looking designs with
vertical alignment. Since they are much tighter than what most other software
uses by default, the default leading had to be increased to 50% of the font size
and paragraph spacing to 100% of the font size.

The values cap-height and x-height fall back to ascender in case they are zero
because this value may occur in fonts that don't have glyphs with cap- or
x-height (like Twitter Color Emoji). Since cap-height is the default top edge,
doing no fallback would break things badly.

Removes softness in favor of a simple boolean for pages and a more finegread u8
for spacing. This is needed to make paragraph spacing consume line spacing
created by hard line breaks.
2021-03-19 13:20:58 +01:00
Laurenz ceb00a2e77 Factor out alignment deduplication into separate function ♻ 2021-03-13 16:57:15 +01:00
Laurenz 584a43277d Rename ChildAlign to LayoutAligns ✏ 2021-03-12 14:12:30 +01:00
Laurenz c1b1dbcc09 Better expansion behaviour 🐪
This makes expansion behaviour inheritable by placing it into the area and passing it down during layouting instead of computing some approximation of what we want during execution.
2021-03-11 10:48:29 +01:00
Laurenz bbb9ed07ff Better line spacing calculations ↕
- Only add line spacing between lines. Previously, line spacing was added below
  every line, making `#box[word]` higher than just `word`.
- Compute box height of text as `ascender - descender` so that the full word is
  contained in the box.
2021-03-10 10:20:01 +01:00
Laurenz b2b8d37ce0 Rename run to line and add some explanatory comments ✏
The name run was a relict of the time where a line consisted of a set of runs with same alignment. While these runs still exist conceptually, they are all stored flatly together in what was now renamed from `run`  to `line`.
2021-03-09 17:25:25 +01:00
Laurenz 790dc9e667 Cleaning 🧹 2021-02-12 22:55:26 +01:00
Laurenz 06ca740d01 Split evaluation and execution 🔪 2021-02-09 19:46:57 +01:00
Martin Haug a6cae89b47 Generalize child of NodeBackground 🍼 2021-02-06 12:54:44 +01:00
Martin Haug 80e076814d Merge `rect` and `box` 🦚 2021-02-06 12:30:44 +01:00
Martin Haug 8469bad748 Add rectangle function 🎛 2021-02-04 21:30:18 +01:00
Laurenz 84ba547c7c If expressions 🔀 2021-01-20 21:33:13 +01:00
Laurenz d763f0f5a6 Split state and scopes, less ref-counting 🔀 2021-01-15 16:53:02 +01:00
Laurenz cfcb36b159 Move test files into category subfolders 🚚 2021-01-14 16:47:29 +01:00
Laurenz 272a4c2289 Unbounded pages 🌌 2021-01-13 23:19:44 +01:00
Laurenz 1b53e27f27 Some minor improvements ♻ 2021-01-13 21:33:22 +01:00
Laurenz 2e77b1c836 Better value representations, type function 🌐 2021-01-04 21:29:15 +01:00
Laurenz aae67bd572 Move and rename many things 🚛 2021-01-03 00:12:09 +01:00
Laurenz 8cad78481c A few small improvements ♻ 2021-01-01 17:54:31 +01:00
Laurenz 81e80ecfba Test [page] function 📕
- Make page break behaviour more consistent
- Allow skipping reference image testing for single tests with `// compare-ref: false` (useful for tests which only check error messages)
2020-12-17 00:20:27 +01:00
Laurenz 21857064db Export alpha channel into PDF 🧊 2020-11-28 00:04:40 +01:00
Laurenz 475ca7a62e Basic environment and resource loader 🏞 2020-11-27 22:35:42 +01:00
Laurenz bc997b7c33 Export images in PDF 🖼 2020-11-27 20:01:54 +01:00
Laurenz 11e44516fa Merge some modules 🥞 2020-11-25 16:56:29 +01:00
Laurenz 761931405c Use newly stabilized intra doc links ↩ 2020-11-24 16:12:41 +01:00
Laurenz f105663037 Basic image support 🖼
- [image] function
- Image rendering in tests
- Supports JPEG and PNG
- No PDF export so far
2020-11-20 16:36:22 +01:00
Laurenz 91e5120693 BoxAlign and Flow aliases ✏ 2020-10-13 13:51:58 +02:00
Laurenz 8680fcd490 Rename geometric eval and apply to resolve ✏ 2020-10-13 13:24:33 +02:00
Laurenz 1a70cb6a33 Naming and grammar ✔ 2020-10-12 18:01:22 +02:00
Laurenz 5243878d81 Less vecs in layouting 2020-10-12 17:29:01 +02:00
Laurenz 38157b0e0c Synchronous layout 🪀 2020-10-12 17:10:01 +02:00
Laurenz e94627721d Adapt to fontdock 🔼 2020-10-12 16:59:21 +02:00
Laurenz a2a68106c0 Evaluation benchmark 🔋 2020-10-11 23:18:00 +02:00
Laurenz 1b3eb42003 Refactor paragraph layout 📰 2020-10-11 22:41:21 +02:00
Laurenz 607f4395f9 Refactor stack layout again 🧣 2020-10-11 22:38:34 +02:00
Laurenz d3bc4ec073 Refactor layouting base 🪁 2020-10-11 22:38:30 +02:00
Laurenz f04ad0ffa5 Rename LayoutItem to Layouted ✏ 2020-10-11 13:08:27 +02:00
Laurenz 51bf3268dd Refactor text state 🆎 2020-10-10 22:35:24 +02:00
Laurenz 92c01da360 Switch back to custom geometry types, unified with layout primitives 🏞 2020-10-10 22:19:36 +02:00
Laurenz 42500d5ed8 Refactor stack ♻ 2020-10-10 12:40:11 +02:00
Laurenz 13230db68c Fix some clippy warnings ✔ 2020-10-07 19:28:34 +02:00
Laurenz d2e220245d Move deco, pass and feedback into diagnostics module ↩ 2020-10-07 18:24:47 +02:00
Laurenz 537545e7f8 Evaluation and node-based layouting 🚀 2020-10-07 17:07:44 +02:00
Laurenz ca1256c924 Remove obsolete extra variable in stack layouter 2020-10-06 20:40:37 +02:00
Laurenz 4252f959f7 Typesafe conversions in stack & line layouters 🍮 2020-10-06 18:27:00 +02:00
Laurenz 985fe28166 Fix bug in line layouter ✔ 2020-10-06 14:44:58 +02:00
Laurenz ef410f6877 Move multi-dir support in stack layouter 🍁 2020-10-06 14:20:28 +02:00
Laurenz c6a6870978 Rename secondary/primary to main/cross ✏ 2020-10-06 13:13:18 +02:00
Laurenz 5a7a32a9ba Streamline generic layouting primitives 🛫 2020-10-05 16:44:35 +02:00
Laurenz fa3e2920c0 Remove @ syntax in diagnostics macros 🗑 2020-10-05 15:45:45 +02:00
Laurenz 2df8b964d0 Simplify shaping 🌱 2020-10-05 15:35:55 +02:00
Laurenz d1c07260c0 Move align out of BoxLayout 🍫 2020-10-05 13:39:33 +02:00
Laurenz 335fa2d118 Small improvements 🍪 2020-10-04 23:31:35 +02:00
Laurenz ef8aa763fa Shorten some names ↔ 2020-10-04 20:22:11 +02:00
Laurenz a41d7ab47d Expression evaluation with Eval trait 🧮 2020-10-04 20:07:01 +02:00
Laurenz c1dd872b34 Remove unncessary wrappers and typedefs 🛑 2020-10-04 19:57:39 +02:00
Laurenz 0f7c70fd93 Separate state and constraints 🧶 2020-10-04 19:06:20 +02:00
Laurenz 6672f8f7df Remove Typesetter in favor of typeset function 🎯 2020-10-04 18:18:55 +02:00
Laurenz 262a8fa36a Refactor and move shaping out of the layout module 2020-10-04 18:01:56 +02:00
Laurenz 95bae5725c Int, Float, Relative and Linear values 🍉 2020-10-03 15:07:57 +02:00
Laurenz 0fc25d732d Port to kurbo 🎋 2020-10-03 13:23:59 +02:00
Laurenz 75e6dbfbe6 Rename bold/italic to strong/emph ✏ 2020-10-03 11:18:25 +02:00
Laurenz 730715c064 Rename text layouting to shaping ✏ 2020-10-03 11:09:32 +02:00
Laurenz 904bc392ab Remove spans from token iterator 🧽 2020-10-02 19:17:47 +02:00
Laurenz 3533268b1f Refactor parser 🏞 2020-10-02 15:43:29 +02:00
Laurenz f8770d2b2a Generalize layouting primitives 🛤 2020-10-01 15:35:09 +02:00
Laurenz e676ab53dd Rename compute to eval ✏ 2020-10-01 15:13:04 +02:00
Laurenz 7c12f0c07f Flatten compute module 2020-10-01 15:10:35 +02:00
Laurenz 7fcad452b8 Reorganize ast types 🏕 2020-10-01 15:03:37 +02:00
Laurenz 4077a7c11e Refactor raw blocks 💱 2020-09-30 18:59:33 +02:00
Laurenz 3c3730425f SpanWith trait ↔ 2020-09-30 14:38:46 +02:00
Laurenz 7143e10afc Streamline font handling a bit 📜 2020-09-30 13:18:42 +02:00
Laurenz bc1b4216a8 Reorganize syntax types into two modules 📦 2020-09-30 12:45:33 +02:00
Laurenz dcf1d09d39 Fix for updated fontdock ✔ 2020-09-27 14:26:50 +02:00
Martin Haug d986bc4b0a Add section headings 👨‍🦲
Co-authored-by: Laurenz Mädje <laurmaedje@gmail.com>
2020-09-01 13:10:48 +02:00
Laurenz 181f756a9e Format everything with rustfmt! 💚 2020-08-30 22:18:55 +02:00
Laurenz fe51ad2e7c Fix different-fonts-in-text bug ✔ 2020-08-30 15:32:52 +02:00
Martin Haug d68367f32a Newlines are complicated, y'all 😱
Co-authored-by: laurmaedje@outlook.de <laurmaedje@outlook.de>
2020-08-29 17:20:04 +02:00
Martin 5e1fd35926
Merge branch 'master' into code-blocks 2020-08-29 13:58:30 +02:00
Martin Haug c2b6f2dc35 Added code blocks 🚟 2020-08-29 13:53:59 +02:00
Laurenz 236750c35f Remove par nodes in favor of parbreaks 🔄
This basically reverts the earlier change from parbreaks to par nodes because:
- It is simpler and less nested
- It works way better with functions that layout their body inline like `font`, which where buggy before, previously

The original reasons for changing to par nodes were:
- the envisioned design of the layouter at that time (based on dynamic nodes etc.), which is not relevant anymore
- possibly existing benefits with regards to incremental compilation, which are unsure and outweighed by the immediate benefits of the parbreak-representation
2020-08-29 12:02:07 +02:00
Laurenz 77dac270a8 Make compute functions possible 💻
Ships with the amazing new `rgb` function!
2020-08-19 20:49:01 +02:00
Laurenz 6d7e7d945b Tidy up library functions 🧺 2020-08-17 23:45:03 +02:00
Laurenz 3cbca56a71 Parse braced expressions and bracketed calls in headers 🗳
- Refactors the tokenizer to be lazy: It does not emit pre-parsed function tokens, but instead allows it's mode to be changed. The modes are tracked on a stack to allow nested compute/typesetting (pop/push).
- Introduces delimited groups into the parser, which make it easy to parse delimited expressions without handling the delimiters in the parsing code for the group's content. A group is started with `start_group`. When reaching the group's end (matching delimiter) the eat and peek methods will simply return `None` instead of the delimiter, stopping the content parser and bubbling up the call stack until `end_group` is called to clear up the situation.
2020-08-17 16:25:09 +02:00
Laurenz 30f16bbf64 Add Value type and replace dyn-nodes with call-exprs 🏗
- In addition to syntax trees there are now `Value`s, which syntax trees can be evaluated into (e.g. the tree is `5+5` and the value is `10`)
- Parsing is completely pure, function calls are not parsed into nodes, but into simple call expressions, which are resolved later
- Functions aren't dynamic nodes anymore, but simply functions which receive their arguments as a table and the layouting context
- Functions may return any `Value`
- Layouting is powered by functions which return the new `Commands` value, which informs the layouting engine what to do
- When a function returns a non-`Commands` value, the layouter simply dumps the value into the document in monospace
2020-08-16 22:39:21 +02:00
Laurenz 2467cd6272 Refactor function parsing ♻ 2020-08-04 13:48:07 +02:00
Laurenz ed4fdcb0ad Par nodes 🧳 2020-08-04 11:46:04 +02:00
Laurenz dbfb3d2ced Formatting, documentation and small improvements 🧽 2020-08-03 16:04:55 +02:00
Laurenz 266d457292 Refactor model into tree 🛒 2020-08-02 22:05:49 +02:00
Laurenz cbbc46215f Layout elements and pure rust rendering 🥏 2020-08-02 21:17:42 +02:00
Laurenz d5ff97f42e Move binary into separate crate and tidy dependencies 🎭 2020-08-02 16:56:14 +02:00
Laurenz 533374db14 Refactor argument parsing 🔬 2020-08-02 16:31:34 +02:00
Laurenz 659248d52f Raw lengths 🚲
Replace unitless length with raw f64 and introduce length type with unit.
2020-08-01 19:15:55 +02:00
Laurenz 06dbac6efd Port font handling to fontdock and ttf-parser 🛳
- Use fontdock for indexing fonts and querying
- Typst binary now automatically indexes and uses system fonts in addition to a fixed font folder!
- Removes subsetting support for now (was half-finished anyways, plan is to use harfbuzz for subsetting in the future)
- Adds font width configuration support
2020-08-01 00:10:54 +02:00
Laurenz bbcdeb128c Move, rename and switch some things (boring) 🚚
- Problems -> Diagnostics
- Position -> Pos
- offset_spans -> Offset trait
- Size -> Length (and some more size types renamed)
- Paper into its own module
- scope::Parser -> parsing::CallParser
- Create `Decorations` alias
- Remove lots of double newlines
- Switch from f32 to f64
2020-07-29 18:09:51 +02:00
Laurenz 53ca5a7fc5 Refactor parser 🚇 2020-07-27 13:47:29 +02:00
Laurenz e2ef4f64e7 Rename errors to problems and make error! macro more ergonomic 🧼
Also adds a `warning!` macro.
2020-07-26 17:28:43 +02:00
Laurenz 1658b00282 New syntax features 👔
- Forced line breaks with backslash followed by whitespace
- (Multline) raw text in backticks
- Set font class fallbacks with [font.family] (e.g. [font.family: monospace=("CMU Typewriter Text")])
- More sophisticated procedure to find end of function, which accounts for comments, strings, raw text and nested functions (this is a mix of a feature and a bug fix)
2020-02-13 21:58:49 +01:00
Laurenz 5badb4e8ff Write lots of parser tests 🌪 2020-02-09 14:14:32 +01:00
Laurenz 02dc29d18a Highlight bold / italic / monospace 🎨 2020-02-06 11:15:48 +01:00
Laurenz 751812f451 Serialize layouts with serde 🔠 2020-02-04 21:36:29 +01:00
Laurenz e63ce52ae0 Merge `Parsed` and `Layouted` types into `Pass` with `Feedback` 🌝🎢🌚 2020-02-04 19:22:23 +01:00
Laurenz 3150fd5643 Better Debug/Display and Derives 🧽 2020-02-03 12:22:02 +01:00
Laurenz 40ea35cbe7 Upgrade to new toddle interface 🐳 2020-02-03 10:37:50 +01:00
Laurenz 20fb4e7c37 Document everything 📜 2020-01-26 15:51:13 +01:00
Laurenz 0a087cd28b Reorganize modules 🧱 2020-01-24 16:23:57 +01:00
Laurenz 03fddaf3ae Non-fatal argument parsing 🌋 2020-01-24 12:44:04 +01:00
Laurenz 78da2bdd5d Decoupled function parser 🔗 [WIP] 2020-01-21 17:09:31 +01:00
Laurenz 95e6b078fe Move to non-fatal errors 🪂 [WIP]
- Dynamic models instead of SyntaxTrees
- No more ParseResult/LayoutResult
- Errors and Decorations which are propagated to parent contexts
- Models are finally clonable
2020-01-19 21:53:24 +01:00
Laurenz a8f711d49a Checkpoint 🏁 2020-01-13 11:26:42 +01:00
Laurenz a93b1ab003 Formatting 🛀 2020-01-06 12:50:20 +01:00
Laurenz 2ee5810fec Asyncify font loading 🪐 2020-01-06 12:41:42 +01:00
Laurenz bd384a2a63 Re-enable *, _ and `. 2020-01-05 11:18:13 +01:00
Laurenz 7b84f3b553 Adopt new font loading engine ⚙ 2020-01-04 22:43:26 +01:00
Laurenz 63b8ccba95 Fix looping bug 🚧 2019-12-30 23:39:10 +01:00
Laurenz 269f069a4d Simple line layouter 🧾 2019-12-30 22:28:56 +01:00
Laurenz f3e461b27c Paper styles and scalable+default margins 📜 2019-12-15 15:09:09 +01:00
Laurenz 3677e4a97d Fix padding-top bug 🏗 2019-12-15 00:30:00 +01:00
Laurenz 665b4d2aca More consistent library code and functions 🎄 2019-12-13 23:59:01 +01:00
Laurenz f549914ff8 Refine and rename layouting types 🛀 2019-12-12 23:33:26 +01:00
Laurenz ff107cf3e7 Tidying up 🧹 2019-12-12 22:19:38 +01:00
Laurenz 3c0496bb61 Refactor size module ♻ 2019-12-12 20:17:35 +01:00
Laurenz a791ef1628 Pretty good stack layouter ✈ 2019-12-11 22:06:54 +01:00
Laurenz d34707a6ae Not too shabby stack layouter 🚆 2019-12-11 17:34:25 +01:00