-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Support for Font Ligatures using Harfbuzz on Linux #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Doesn't render properly yet, though.
CI and everything should now work.
…t all share the same renderablecell except for (column, chars)
…hape one level deeper. Aim to move call into glyph_cache and expose through some API.
… method. Still not ideal as better use can probably be made of glyph_positions returned by harfbuzz but it will be involved to work those down to the Batch that renders cells at gl float values.
…inimal state needed.
…_run when hb-ft is on.
…used as glyph keys with hb-ft on. Clean up more extraneous changes.
…critty into font-ligatures
My comment was in reference to @chrisduerr landing a large window rework in master that I needed to merge in this PR. I believe I have that merging done. However since this PR has been sitting stagnant there is still plenty of merging to be done if you'd like to take a look. The next merge on my stack is to look at the new urls.rs file and add a method to it to work with TextRuns. |
Oh I see; you meant support for the updated windowing system, not the Windows OS! 😄 Once this PR lands I would be interested in attempting support for Windows. Perhaps using the allsorts crate (which might also work for macOS). |
I'm taking a look at the URL stuff wrt to TextRuns and wanted to ask, can a URL span a change in color/font/metadata (essentially span two or more text runs). At the very least it appears they can span multiple lines which means they can be at least two runs in that regard, but wanted to clarify the other semantics. |
A URL is in the following format: https://github.com/jwilm/alacritty/blob/master/alacritty/src/url.rs#L18-L23 As you can see, the Each of these |
had a quick go at merging master to this branch... tests pass, the terminal shows up and I can work in it, but have not tested much more: thunderseethe#1 |
I guess this branch needs rebase from master as I have lots of merge conflicts and in order to keep a clean history .. instead of merging master into this branch, good to know that way works tho. |
Hi, looking forward to this, wouldn’t mind helping but I am a total rust newbie. Can I ask a noob question, why only linux? |
Due to use of hardbuzz library, which is used primary on linux, for macOS we should like use CoreText and for Windows DirectWrite. |
Do people anticipate that this will be merged in the near future? If not, I'd be interested in packaging this branch for the AUR. |
This branch is severely outdated and requires some significant work just to get it back up to date. |
I am not a rust dev but I'm willing to volunteer to update the branch if the maintainer keeps MIA? ping @thunderseethe ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder how you consider @wezm 's library
//} | ||
|
||
// Since shaping is not available on Windows/Mac OSX, text run glyphs are rasterized one by one | ||
// as characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're open to it if the performance works well and it properly supports all necessary features on the platforms it could be used for.
However someone would actually have to do the work to try that out of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please, avoid pinging folks without a reason for it. thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that Weslay, if I recall correctly, had offered working together with anyone who would want to pick this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, and if anyone had a code with the mentioned lib and they had problems with it then maybe it might be something where pinging could make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or when trying to summon the wizards before the raid, but that arguably doesn't always work 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello all, I would be happy to answer any allsorts related queries. There should be no cross-platform issues — there are no OS dependencies except libc. We ship builds of Prince, which uses allsorts on at least Linux, macOS, Windows, and FreeBSD. I will admit the the API is currently quite low level, we hope to eventually add an easier to use higher-level API, but have not had a chance to do that yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allsorts is certainly looking like a great solution for supporting all platforms at the same time. So the primary question would be how well it performs and how nicely the API integrates with Alacritty, but I think generally a lower level API should be a pretty good fit for Alacritty.
Since you're already around @wezm, I'd imagine you might be aware of how allsorts compares to harfbuzz in performance? Specifically for running relatively simple combination of characters like ligatures on short-ish strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd imagine you might be aware of how allsorts compares to harfbuzz in performance? Specifically for running relatively simple combination of characters like ligatures on short-ish strings.
We have not done a lot of comparison with Harfbuzz at this point as the primary focus was accurate shaping, and matching or exceeding the performance of our previous shaping engine. There is an open issue to explore this further yeslogic/allsorts#2
Whilst quite fast, it's probably safe to assume that Allsorts is not as fast as Harfbuzz, as Harfbuzz has been optimised for performance over many years. That is not to say we ignored performance though. We have profiled and optimised it in order to meet, and then exceed the performance of shaping engine it replaced in Prince.
@thunderseethe I made a patch between your branch and @zenixls2 's fork which is reported to work atop recent versions. Hope it helps: Since his version is heavily inspired by this PR, the relevant diffs should be easy to consume. (hopefully) Within the root of the workdir of your branch: (After that you should be able to squash all your commits and cleanly rebase onto current master without a single merge conflict... I assume here - since this is a WIP branch - the detailed commit history can be forgone.) Or just continue as if you where on current master... Note: I haven't taken an involved look at the relevant diffs between your's and zneixls2's. Just thought this triangulation might save you some hours.
|
You (@thunderseethe) might want to have a look at this changeset: |
👋 , what are the things we need to do in order to merge this pr? |
@felippemr Check the previous comments please. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fucking awesome
This comment has been minimized.
This comment has been minimized.
Has anybody a newer rebase than zenixls2@126093a ? |
Hi! This seems to be quite near to be possible to merge. I am not rust dev, but I would use ligatures quite a lot. |
This revives alacritty/alacritty#2677 changes specifically for the old `font` crate.
Initial support for font ligatures using harfbuzz and free type on linux.
This builds on the work done by @anirudhb in [WIP] Basic text shaping and rendering using Harfbuzz
Step in the direction towards closing #50 .
This is relatively early in it's implementation but I wanted to get some eyes on it as changes past this point will start to effect core pieces of infrastructure (rendering etc.).
Currently code will render ligatures on linux with a monospace font (I've only tested with Fira Code).
Major Changes
Support for font ligatures is enabled by changing the base rendering unit from a RenderableCell to a TextRun (name flexible). A TextRun bundles a series of RenderableCells that share the same render properties (line, fg, bg, etc.) into one unit. Each TextRun gets shaped by harfbuzz returning the glyph indices for each character. From here each glyph is rasterized as normal through the glyph cache.
Changes are guarded behind the
hb-ft
feature inalacritty_terminal
.Along with adding new code under this feature, some code is removed when this feature is turned on. Mainly code dealing with rendering RenderableCell's (and GlyphKey's c member).
The idea behind this is to ensure that there aren't any unknown uses of RenderableCell in the codebase. Once the code is free of RenderableCell when hb-ft is on, more intrusive changes can be made to rendering that break the conventions set by RenderableCell.
Caveats
freetype::Face
, this doesn't seem hugely problematic but is should definitely be noted.load_face_with_glyph
as we don't have a char available to guess at the font. This functionality can be recovered by keeping the char stored with it's indice however this meansGlyphKey
would no longer fit in au64
.Questions
Vec<RenderableCell>
fromgrid
and wraps that as aTextRunIter
to produceTextRun
s. Would it make more sense forgrid
to directly produce aTextRunIter
and avoid the unecessary middle allocation (hopefully)?TextRun
completely replaceRenderabelCell
?GlyphKey
(instead of char)?Remaining Work
GlyphIndex(u32)
similar to Line and Column.I'm relatively new to the open source community so my apologies if something is out of place or I've missed a process I should've completed.
I initially ran my code through
cargo fmt
however it changed a ton of the codebase that I hadn't touched so I undid those changes. Is there a commonrustfmt.toml
config the repo uses?