Commit graph

19 commits

Author SHA1 Message Date
Simon Wülker
3d320fa96a
Update rustfmt to the 2024 style edition (#35764)
* Use 2024 style edition

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Reformat all code

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-03-03 11:26:53 +00:00
Martin Robinson
f949d2adc8
fonts: Remove the per-FontGroup cached fallback font (#35705)
Instead of keeping a per-FontGroup cache of the previously used fallback
font, cache this value in the caller of `FontGroup::find_by_codepoint`.
The problem with caching this value in the `FontGroup` is that it can
make one layout different from the next.

Still, it is important to cache the value somewhere so that, for
instance, Chinese character don't have to continuously walk through the
entire fallback list when laying out. The heuristic here is to try to
last used font first if the `Script`s match. At the very least this
should make one layout consistent with the next.

Fixes #35704.
Fixes #35697.
Fixes #35689.
Fixes #35679.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-02-28 14:33:21 +00:00
Delan Azabani
d65a2e9797
Additional tracing for flex layout, inline layout, and fonts (#34392)
Signed-off-by: Delan Azabani <dazabani@igalia.com>
2024-11-27 02:44:06 +00:00
Martin Robinson
30abb99287
clippy: Add safety documentation and clean up unsafe methods (#33748)
This change:

1. Adds safety documentation where it was missing.
2. Limits the scope of unsafe code in some cases to where it is actually
   unsafe.
3. Converts some free functions to associated functions and methods,
   thereby making them more likely to be called safely.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-10-16 08:11:31 +00:00
Martin Robinson
0553789d48
fonts: Instantiate system fonts using system font loaders (#33747)
System fonts used to be instantiated using the system font loader and
this change restores that behavior. In addition, on macOS and FreeType
platforms font data for system fonts is loaded using memory mapping. The
benefit is that system font loaders typically are able to cache fonts in
system memory (using memory mapping, for instance) and we'd like to load
them in a the way most compatible with other applications.

On my Linux system, this manages to get the overhead of loading a very
large font down from 10ms to approximately 1ms. Subsequent runs show
even less overhead. We've measured similar gains on macOS systems.

Currently, system font data must be loaded into memory manually for
canvas and this is unlikely to change even with a switch to `vello`. The
use of explicit memmory mapping should help in this case -- though it
probably won't be possible to use this properly on macOS and Windows if
we ever want to load fonts from TTCs properly.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-10-10 23:09:51 +00:00
birdbrained
a591778a25
Improve Au(0) constructions (#33709)
This replaces `Au(0)` with `Au::zero()` and other utility functions when possible.

Signed-off-by: hackerbirds <120066692+hackerbirds@users.noreply.github.com>
2024-10-10 16:45:18 +00:00
Martin Robinson
abad89a49c
fonts: Make FontKey and FontInstanceKey generation asynchronous (#33600)
Instead of a blocking a layout thread on the generation of WebRender
`FontKey`s and `FontInstanceKey`s, generate the keys ahead of time and
send the font data to WebRender asynchronously. This has the benefit of
allowing use of the font much more quickly in layout, though blocking
display list sending itself on the font data upload.

In order to make this work for web fonts, `FontContext` now asks the
`SystemFontService` for a `FontKey`s and `FontInstanceKey`s for new web
fonts. This should happen much more quickly as the `SystemFontService`
is only blocking in order to load system fonts into memory now. In
practice this still drops layout thread blocking to fractions of a
millisecond instead of multiple milliseconds as before.

In addition, ensure that we don't send font data or generate keys for
fonts that are used in layout but never added to display lists. This
should help to reduce memory usage and increase performance.

Performance of this change was verified by putting a microbenchmark
around `FontContext::create_font` which is what triggered font key
generation.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-10-01 15:31:26 +00:00
Martin Robinson
ac567645a7
fonts: Simplify FontContext in two ways that affect the unit test (#33541)
This is done by no longer forwarding compositor-bound messages through
SystemFontService and making `FontContext` non-generic:

- Messages from the `FontContext` to the `Compositor` no longer need to be
  forwarded through the `SystemFontService`. Instead send these messages
  directly through the script IPC channel to the `Compositor`.

- Instead of adding a mock `SystemFontServiceProxy`, simply implement a
  mock `SystemFontService` on the other side of an IPC channel in the
  `font_context` unit test. This allows making `FontContext`
  non-generic, greatly simplifying the code. The extra complexity moves
  into the unit test.

These changes necessitate adding a new kind of `FontIdentifier`,
`FontIdentifier::Mock` due to the fact that local fonts have
platform-specific identifiers. This avoids having to pretend like the
system font service can have web fonts -- which was always a bit of a
hack.

These two changes are combined into one PR because they both require
extensive and similar chages in the font_context unit test which
dependended on the details of both of them.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-09-25 20:15:47 +00:00
Martin Robinson
64f32f7ab3
fonts: Make fast shaping determination platform-independent (#33540)
This makes the determination of whether or not to use fast shaping
platform independent. Previously it was less stringent for Windows,
leading to using it in cases where a font had a GSUB or GPOS table --
which broke proper shaping.

In addition, the test is made platform independent and expanded to be
more complete.

Finally, comments are added indicating that "fast shaping" will be
removed.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-09-25 10:00:36 +00:00
Martin Robinson
ade902207f
fonts: Use IpcSharedMemory to send font data (#33530)
This changes modifes the way that font data is sent over IPC channels.
Instead of serializing the data or sending it via IPC byte senders, font
data is copied into shared memory and a copy of the handle is sent over
the channel.

There is also the idea of sending the file handle of the on disk data of
system fonts. This could be implemented as a further followup once there
is an abstraction in `ipc-channel` over file handles.

To accomplish this, a `FontData` abstraction is added, which also allows
caching an in-memory shared `Arc<Vec<u8>>` version of the data (neeeded
by some APIs). This could also be a place for caching font tables in the
future.

Finally, the `FontCacheThread` is renamed to the `SystemFontService`
while the proxy for this is now named `SystemFontServiceProxy`.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-09-25 07:31:55 +00:00
Oriol Brufau
d9be9d6bd4
Handle all white-space values when intrinsically sizing an IFC (#33343)
There were various cases like `text-wrap-mode: nowrap` and
`white-space-collapse: break-spaces` that weren't handled well.

Fixes #33335

flexbox_flex-formatting-interop.html fails now because we don't support
`table-layout: fixed`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-11 23:50:45 +00:00
Martin Robinson
312cf0df08
script: Create a CrossProcessInstant to enable serializable monotonic time (#33282)
Up until now, Servo was using a very old version of time to get a
cross-process monotonic timestamp (using `time::precise_time_ns()`).
This change replaces the usage of old time with a new serializable
monotonic time called `CrossProcessInstant` and uses it where `u64`
timestamps were stored before. The standard library doesn't provide this
functionality because it isn't something you can do reliably on all
platforms. The idea is that we do our best and then fall back
gracefully.

This is a big change, because Servo was using `u64` timestamps all over
the place some as raw values taken from `time::precise_time_ns()` and
some as relative offsets from the "navigation start," which is a concept
similar to DOM's `timeOrigin` (but not exactly the same). It's very
difficult to fix this situation without fixing it everywhere as the
`Instant` concept is supposed to be opaque. The good thing is that this
change clears up all ambiguity when passing times as a `time::Duration`
is unit agnostic and a `CrossProcessInstant` represents an absolute
moment in time.

The `time` version of `Duration` is used because it can both be negative
and is also serializable.

Good things:
 - No need too pass around `time` and `time_precise` any longer.
   `CrossProcessInstant` is also precise and monotonic.
 - The distinction between a time that is unset or at `0` (at some kind
   of timer epoch) is now gone.

There still a lot of work to do to clean up timing, but this is the
first step. In general, I've tried to preserve existing behavior, even
when not spec compliant, as much as possible. I plan to submit followup
PRs fixing some of the issues I've noticed.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-09-05 18:50:09 +00:00
Cristian Brinza
4ae2610c24
fonts: Enable fast text shaping on Windows (#33123)
* Use patched dwrote

Signed-off-by: crbrz <cristianb@gmail.com>

* Enable fast text shaping

Signed-off-by: crbrz <cristianb@gmail.com>

* Add fast text shape test

Signed-off-by: crbrz <cristianb@gmail.com>

* Update dwrote to 0.11.1

Signed-off-by: crbrz <cristianb@gmail.com>

---------

Signed-off-by: crbrz <cristianb@gmail.com>
2024-08-30 23:16:26 +00:00
Martin Robinson
78e2691d3f
shaping: Don't assume there's a space glyph when rendering tabs (#32979)
Previously if a font didn't have a space advance and it was needed to
make advances for tabs, Servo would try to read the advance from the
font. If the font didn't have a space glyph, Servo would panic. This
fixes that issue by making the space advance part of the `FontMetrics`
of a font (like Gecko) and falling back properly if that glyph doesn't
exist. The rendered glyph is still the "space" glyph, but we make
sure to select a font that supports that glyph explicitly.

This prevents a crash, but tabs still aren't handled properly. In
reality, tab stops should be calculated in layout and the size of
the space character of the current font shouldn't come into play.
The addition of the space advance metric will make this easier.

Fixes #32970.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-08-23 11:17:44 +00:00
Chocolate Pie
1223335547
enhance: Implement CanvasRenderingContext2D.measureText (#32704)
Signed-off-by: Chocolate Pie <106949016+chocolate-pie@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-07-17 19:20:18 +00:00
Martin Robinson
4907e89656
canvas: Remove as much usage of font-kit as possible (#32758)
Do font selection using Servo's font backend, which is shared with the
rest of layout. In addition, delay the creation of the `font-kit` font
until just before rendering with `raqote`. The idea is that when
`raqote` is no longer used, we can drop the `font-kit` dependency.

This change has the side-effect of fixing text rendering in canvas,
adding support for font fallback in canvas, and also correcting a bug in
font selection with size overrides.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-07-11 04:25:38 +00:00
Martin Robinson
77e9e3deba
fonts: Add support for generic font families and font size configuration (#32673)
This adds support for generic font families in Servo and allows for
configuration of them as well as their default font sizes. One
interesting fix here is that now monospace default to 13px, like it does
in other browsers.

In addition to that, this exposes a new interface in Stylo which allows
setting a default style. This is quite useful for fonts, but also for
other kinds of default style settings -- like text zoom.

Fixes #8371.
Fixes #14773.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-07-08 17:17:48 +00:00
Martin Robinson
4b63043c6a
clippy: Fix warnings in shared and config, fonts, layout, and layout_2020 components (#32674) 2024-07-04 14:18:58 +00:00
Martin Robinson
cd2ab36759
Rename gfx to fonts (#32556)
This crate only takes care of fonts now as graphics related things are
split into other crates. In addition, this exposes data structures at
the top of the crate, hiding the implementation details and making it
simpler to import them.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-06-19 20:26:19 +00:00
Renamed from components/gfx/font.rs (Browse further)