Repository navigation
Conversation
|
i would propose it differently: lets keep an option that make simple things simple but still allows complex behavior: for "bool" case
this is actually a weak case and could be dropped entirely by using the case below. for the string/enum casesimple "left", "right", "both", "default", and "none" overhang layout with whatever characters agreed as the default. for the dict casethis follows the proposal of the OP but more refined: what do you think ? |
|
Thanks for the suggestions! My thoughts on this:
With this, the API for the dict case may look like the following: #set text(overhang: (
map: (
"«": (100%, 100%),
"»": (100%, 100%),
"”": (100%, 100%),
"“": (100%, 100%),
// Enable overhang only for the left margin.
"A": (10%, 0%),
// Customize protrusion only for the left margin,
// use default values for the right one.
"-": (100%, auto),
),
// Use built-in values for other characters on the right margin
// (could be `left`, `right`, `true` or `false`).
// If omitted, results in `false`.
rest: right,
)) |
|
I'm not yet ready to comment on this at large, but still wanted to add three points to the discussion:
|
|
You could use the alignment type, i.e. |
|
unfortunately, adding |
I think that we should not deprecate
That is quite an interesting idea! The question now what signature should this function have. I see two options:
Currently, I'm leaning more towards the first option. |
02cb067 to
07d3704
Compare
|
The situation is as follows.
|
|
As I read in Hàn Thế Thành's dissertation, this PR implements so-called "level 1 character protruding" (pp. 41-43), when "margin kerning" is used when lines are already laid. "Level 2", on the other hand, incorporates margin kerning into the layout algorithm. Since very good results were obtained in #6161 when character-level justification was included in the layout algorithm without much changes, I think we can do this too. I will study this in more detail. See the comparison between level 1 and level 2 character protruding from Hàn Thế Thành dissertation (p. 47) below:
|
|
Hi! I see that
Is that an essential limitation of the current design, or merely a superficial restriction of the interface (or data types)? Besides, I suggest updating the PR description or at least adding a note. The current version is outdated and misleading. |
Hi! Yes, this is a current limitation of the interface, but not a technical one. I just haven't had time to think about how to describe the protrusions for several characters, but at the same time to disallow, for example,
Also thought of this, will change it in a minute. UPD: done. |
overhang configurable, add overhanging to the left margin…ert `overhang` value from function to dictionary
With time have passed and a bit of experiments, I think that is the essential limitation of the current design. But the specified issue is resolved via another (more robust) way, see #8131 and comments in the TODO section of the current PR description. With that additional PR you can specify exact glyph that will visually appear in the document by its UTF-8 character. So if you specify The only glyphs that cannot be accessed by UTF-8 characters are ligatures. I think that we should adapt |
# Conflicts: # crates/typst-layout/src/inline/line.rs # tests/ref/pdf/hashes.txt # tests/ref/svg/hashes.txt
Added exactly this, also merged #8131. The PR description is also updated. The PR is ready for review. I don't think I'll progress any further without additional help. |
|
This would solve a case I'm hitting: optical margin alignment of capitals (W/A/V/T) at flush-left line starts, which the current punctuation-only overhang table doesn't cover. |
# Conflicts: # tests/ref/pdf/hashes.txt # tests/ref/svg/hashes.txt
# Conflicts: # crates/typst-layout/src/inline/line.rs # crates/typst-layout/src/lists.rs # tests/ref/pdf/hashes.txt # tests/ref/svg/hashes.txt
# Conflicts: # crates/typst-layout/src/inline/line.rs # tests/ref/pdf/hashes.txt # tests/ref/svg/hashes.txt # tests/suite/layout/inline/overhang.typ
|
I've merged current main with #8131, PR is no longer blocked and is ready for review. |
There was a problem hiding this comment.
Thanks for the work you've put into this far. I've finally had time to consider this in more depth together with @reknih. The big picture of the code changes seems fine, but before diving into that, I would like to address some final API design concerns. I think the building blocks of the API are going into a good direction, but there are still some concerns and suggestions I have:
-
Most importantly, the dissonance between the
defaultandmapAPIs. The APIs cover two complementary parts of the glyph space and need to describe similar options, but their shape is completely different. The type ofdefaultisstart | end | left | right | false | truewhile a map entry is(auto | relative, auto | relative)). However, thedefaultAPI can mostly be expressed in terms of themapone:falseis equivalent to(0pt, 0pt)trueis equivalent to(auto, auto)startis equivalent to(auto, 0pt)- ...
For consistency, I would thus suggest adopting the map model for both. To make the common cases more convenient for both, I would additionally suggest allowing a single value instead of an array to have both uniform, e.g.
autoinstead of(auto, auto)and0ptinstead of(0pt, 0pt).If we think it's too awkward for something like
overhang: 10ptto overhang everything (a pretty useless operation which we probably want to avoid exposing), we could addnoneas an alternative to0ptand make the default API a subset of the map API that only allows combinations ofnoneandauto, not concrete values.As far as I understand, the array form only supports start/end, not left/right, but that seems sufficient to me.
-
I also don't really like the
defaultandmapnames structure in general. It creates a lot of nesting and names aren't immediately clear. Perhaps we could rather have the map top-level, with arestkey for the default?#set text(overhang: ( "-": (none, 50%), "W": 20%, rest: none, ))
As with
defaultin your PR, the value of therestkey could also be specified top-level onoverhangas a short form. And that in turn could be shortened again if both sides are symmetric, so bothoverhang: noneandoverhang: autowould work for the currentfalseandtrue. The compatibility behavior forfalseandtrueshould remain, but give a deprecation warning that you should usenoneandauto, respectively. -
The PR is missing documentation for the
overhangfield. The docs should describe the expected structure in detail since the signature itself is not enough (it just saysdictionary). -
I am not 100% sure about exposing the PostScript names, but I think I can see it. However, if we keep this, it would need to be well-documented with an explanation how to determine these names.1
-
If we ever add optical margin overhang, we could migrate
autoto this smarter default.
Footnotes
-
One alternative would be to allow multi-letter strings in the overhang map, shape them and see which glyph they result in. Though maybe that's a bit extreme and it would probably still not allow selecting every possible glyph. It would also introduce a collision with
rest, which is currently non-colliding since it's neither a single char nor starts with a slash. ↩
|
@sicikh Any thoughts on the points above? I think the PR is in a fairly good state already, so if you'd want to finish it, that would be great. Otherwise, I would probably try to finish it myself at some point. |


Depends on #8131.Closes #261, closes #6582, closes #7231.
This PR changes the behaviour of the
text.overhangproperty, such that:Left and right margins can be used for overhang characters for LTR and RTL languages accordingly.
Users can now specify where overhang characters should happen:
trueorfalse),leftorright),startorend),Old values
overhang: falseandoverhang: truestay, buttruechanges its meaning from "enable default overhang punctuation only for the end margin" to "enable default protrusions for both margins".The default value changes from
truetoend, that works as previoustrue.Most beneficial result is that overhang punctuation is now considered when paragraph is being laid out, what leads to better linebreaks and hyphenation. Now documents, that were using default values (and that will continue to use them), will benefit from this PR without additional changes from their side.
For the results see below:
Code
API
Rationale
As written in #7231 (comment), the main problem for this functionality is the API. #7231 (comment) proposes some kind of automatic calculation for the amount of protrusion for characters.
Main argument against disabling the possibility for customizing protrusions is that such algorithm, that can be implemented in the future, may yield suboptimal results. In some circumstances users may want to customize behaviour per character or per margin basis (see #7231 (comment) and #6582).
Thus, the API should take into account, that such algorithm for calculating protrusions by default may be implemented later, but also should give users a possibility to directly adjust values.
Another option was considered to rather recieve function
(char, side) => protrusion, but it has some technical limitations (see #7782 (comment)). Also manipulating dictionaries from the user-side is better than with the black-box functions (think of possible typst's "microtype" package with those protrusion tables). More importantly, is that compiler needs to see keys of the table for identifying glyphs ids (see #8131).With all of this, the design space is limited only by such protrusion table.
TODO
Improve API such that table may contain keys for the characters, consisting of multiple UTF-8 characters (see Configurable character protrusion for both margins #7782 (comment)), while disallowing incorrect usage.Not needed anymore, since More robust overhang #8131 fixes overhang glyphs that are shaped from multiple characters.The only case when we can not refer to a font's glyph via UTF-8 characters are ligatures. We should decide how to refer to them (see: https://tex.stackexchange.com/questions/235994/microtype-customizing-protrusion-for-ellipsis-and-multiplication-symbols/236661#236661 for howDone in 10edfe9.microtypedoes it).Improve error handling (nested dictionaries have bad ergonomics...).
Design and implement folding for
text.overhang.