1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
Commit graph

499 commits

Author SHA1 Message Date
Sam Atkins
5a1c73d7e2 LibGfx+LibWeb: Update definitions of supported font formats and features
Based very scientifically on what's listed here:
https://harfbuzz.github.io/what-does-harfbuzz-do.html

I've moved the code into LibGfx because including a HarfBuzz header
directly from LibWeb is a little unpleasant. But the Gfx::FontTech enum
follows the CSS definitions for font features for simplicity.

TrueType collections are supported. SVG and Embedded OpenType are not,
but they're not widely supported by other browsers so that's fine.

Most of the features are completely supported by HarfBuzz, so we can
just return true. Graphite support is optional (and it appears we use a
build of HarfBuzz without it) but there's a define we can check.
Incremental Font Transfer is a whole separate thing that we definitely
don't support yet.
2025-06-05 12:10:29 +01:00
Lucien Fiorini
0fcb574041 LibGfx+LibWeb: Turn Gfx::Filter into a SkImageFilter wrapper 2025-06-01 23:22:10 +02:00
Andrew Kaster
6f9e56870e CMake: Exclude GlobalFontConfig.h from autogenerated clang module
This header file is never included by any other headers, and including
it would require adding the fontconfig include paths to the swift
interop header generation, which is not desirable.
2025-05-30 15:21:17 -06:00
Andrew Kaster
17b7f192c4 LibGfx: Add a strict CMake check for the libpng apng patch 2025-05-30 15:21:07 -06:00
blukai
3ab50be36a LibGfx: Improve logical separation of font_directories' ifdefs
in addition to what was proposed in
https://github.com/LadybirdBrowser/ladybird/pull/4830#discussion_r2101301978
2025-05-26 12:14:29 -06:00
blukai
e356a4bd01 LibGfx: Rely on fontconfig(if enabled) for font directory resolution
this commit also introduces GlobalFontConfig class that is now
responsible for fontconfig initialization. it seems sane, even thought
FcInit's docs state that if the default configuration has already been
loaded, this routine does nothing.
2025-05-26 12:14:29 -06:00
blukai
4b3691ff39 LibCore+LibGfx: Move font_directories from LibCore to LibGfx
the goal is to rely on fontconfig for font directory resolution. it
doesn't seem like it would be appropritate to call to fontconfig funcs
from within the LibCore.

i'm not 100% confident that FontDatabase is the correct place.. seems
okay?
2025-05-26 12:14:29 -06:00
blukai
6e00a38099 LibGfx: Enable otf fonts 2025-05-26 12:14:29 -06:00
Timothy Flynn
2f9957c618 Everywhere: Format all python files with black 2025-05-22 16:21:42 +02:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
aplefull
7da2339c89 LibGfx: Properly skip IDAT chunks without fcTL in APNG files
In the previous fix, we were still drawing IDAT data to the reference
frame even when no fcTL was present. This would cause rendering issues
when subsequent frames use APNG_BLEND_OP_OVER blending mode, as they
would composite over the incorrect reference frame. This commit adds a
simple check to properly skip any frame without an fcTL chunk.
2025-05-09 21:45:29 +02:00
aplefull
e5944a4d9e LibGfx: Correctly handle OS/2 BMPs with 3-byte color entries
We now properly handle OS/2 format BMPs that use 3 bytes per color
entry instead of 4. While OS/2 2.x officially specified 4 bytes per
color, some tools still produce files with 3-byte entries. We can
identify such files by checking the available color table space.
2025-05-09 21:45:29 +02:00
aplefull
4d8717fa3a LibGfx: Add .cur file support to ICO loader
This extends ICO loader to support Windows cursor files. There is no
point in creating a separate loader for this, as the ICO format is
very similar to the CUR format. The only differences are bytes used to
identify the file and a presence of a hotspot in the CUR header.
2025-05-09 21:45:29 +02:00
aplefull
48ca895f5f LibGfx: Properly skip color masks in BMP V2+ headers
Color masks should only be used when the compression type is either
BITFIELDS or ALPHABITFIELDS. They were always read before and produced
corrupted images when there was random data in the mask fields.
2025-05-09 21:45:29 +02:00
aplefull
c908c14aac LibGfx: Clamp BMP color palette to 1024
Other browsers don't think that BMP files with more than 1024 colors are
invalid. They clamp the palette instead, and now we do the same. This
allows us to load more BMPs.
2025-05-09 21:45:29 +02:00
Sam Atkins
1967d5bc75 LibGfx: Add a helper for constructing a TTF font from temporary bytes
Once we switch from ResourceLoader to Fetch, nobody is going to be
holding onto the downloaded data, so we need to make a permanent copy
of it.
2025-05-03 12:01:43 +01:00
Sam Atkins
6b762331df LibGfx: Rename WOFF[2]::try_load_from_externally_owned_memory()
Typeface::try_load_from_externally_owned_memory() relies on that
external owner keeping the memory around. However, neither WOFF nor
WOFF2 do so - they both create separate ByteBuffers to hold the TTF
data. So, rename them to make it clearer that they don't have any
requirements on the byte owner.
2025-05-03 12:01:43 +01:00
aplefull
71a4e18bf8 LibGfx: Only include frames with fcTL chunks in the animation
Before this change, IDAT data was mistakenly always included in the
animation. Now we only include frames with explicit fcTL chunks.

As per the PNG spec (third edition):
"The static image may be included as the first frame of the animation
by the presence of a single fcTL chunk before IDAT. Otherwise, the
static image is not part of the animation."

We also fall back to the IDAT data when APNG has acTL but no fcTL
chunks. Test image is 062.png from fDAT-inherits-cICP.html from WPT.
2025-05-01 10:30:00 +02:00
Jelle Raaijmakers
35efd4d14b LibWeb+LibGfx: Support alpha in CanvasRenderingContext2D
This is implemented by these related changes:

  * The Skia alpha type 'Opaque' is selected for surfaces that were
    created with the intention of not having an alpha channel.
    Previously we were simply creating one with alpha.

  * Clearing now happens through Skia's `clear()` which always uses the
    source color's value for the result, instead of setting all values
    to 0.

  * CanvasRenderingContext2D selects a different clearing color based on
    the `alpha` context attribute's value.
2025-04-29 13:51:23 +02:00
aplefull
e0ceb66580 LibGfx: Fix incorrect colors in ICO-embedded BMPs 2025-04-24 13:46:54 +01:00
Aliaksandr Kalenik
8f20899533 LibGfx: Make Bitmap atomic ref-counted
Fixes race condition when rendering thread runs destructor for
Gfx::Bitmap owned by PaintingSurface, which was not thread-safe.
2025-04-24 03:12:19 +02:00
Timothy Flynn
094e00caef LibGfx: Add a helper to create Ladybird-branded colors 2025-04-23 13:22:56 +02:00
InvalidUsernameException
84ff18b6ac LibGfx: Assert on out-of-bounds y-value
The reduced amount of indirections from the previous commit made it
obvious that a range check on the y-value was missing.
2025-04-23 09:26:45 +02:00
InvalidUsernameException
7568ea3160 LibGfx: Simplify get_pixel()
There appears to be no reason for Bitmap::get_pixel() to be split into
three layers of methods. Make the code simpler by inlining everything
into a single method.
2025-04-23 09:26:45 +02:00
InvalidUsernameException
578a3af87d LibGfx: Support missing pixel formats in get_pixel()
Bitmap::get_pixel() was only handling two out of the four possible pixel
formats, asserting when called with the other two. The asserting code
path was triggered when loading JPEG XL images, causing crashes on pages
like https://jpegxl.info/resources/jpeg-xl-test-page or
https://html5test.co/.
2025-04-23 09:26:45 +02:00
Aliaksandr Kalenik
f6b0851c38 LibGfx+LibWeb: Support per-glyph font fallbacks in canvas text painting
Instead of using the first font from the FontCascadeList for all glyphs
in a text, we perform a text shaping process that finds a suitable font
for each glyph and returns a list of glyph runs, where each glyph run
represents consecutive glyphs using the same font.
2025-04-21 09:51:16 +02:00
Aliaksandr Kalenik
1e7922fac8 LibGfx+LibWeb: Add Path::glyph_run() and use in canvas
Canvas text painting needs to support per-glyph font fallbacks, which
means we can't hand over responsibility for text shaping to Skia and
instead need to extract glyph paths from our own shaped GlyphRun.
2025-04-21 09:51:16 +02:00
Aliaksandr Kalenik
455700d379 LibGfx: Join SkiaFont.cpp into Font
No need to keep this function in a separate file.
2025-04-21 09:51:16 +02:00
Aliaksandr Kalenik
8e2d1559ec LibGfx: Join ScaledFont into Font
Since ScaledFont is the only class inherited from Font we could simply
merge them.
2025-04-21 09:51:16 +02:00
Aliaksandr Kalenik
16e883a9a3 LibGfx+LibWeb: Don't include start.x in GlyphRun width
For some reason we were including x offset of start position into glyph
run width. This is not correct and would be revealed by the upcoming
changes.
2025-04-21 09:51:16 +02:00
Andreas Kling
ed5ad267c7 LibWeb: Keep harfbuzz hb_buffer instead of reallocating every time
Easy 1% speed-up on Speedometer 3.
2025-04-19 01:14:02 +02:00
Andrew Kaster
5e1b3cdeb9 LibGfx: Pass MetalContext in an NNRP in SkiaBackendContext
Previously we were move()-ing an lvalue reference, which causes
issues with upcoming RefPtr const correctness changes.
2025-04-16 10:41:44 -06:00
Andrew Kaster
91b549f797 LibGfx+LibWebView+UI: Store Gfx::Bitmap in RefPtr to const 2025-04-16 10:41:44 -06:00
Andrew Kaster
be2dd91289 LibGfx+LibWeb: Store Typeface and Font-related types in RefPtr to const 2025-04-16 10:41:44 -06:00
Andrew Kaster
ffd0259bef LibGfx: Store Core::Resources in RefPtr to const 2025-04-16 10:41:44 -06:00
Aliaksandr Kalenik
a4cc0703d1 LibGfx: Make Skia surface construction/destruction thread-safe
With this change we ensure that Skia surfaces are allowed to be created
or destroyed only by one thread at a time. Not enforcing this before
resulted in "Single owner failure." assertion crashes in debug mode on
pages with canvas elements.
2025-04-15 02:33:32 +02:00
Mehran Kamal
6ba60188b4 LibWeb+LibGfx: Paint dash array and offset for SVG and Canvas 2025-04-14 18:00:38 +01:00
Mehran Kamal
a64902ba25 LibWeb+LibGfx: Paint miter_limit for SVG and Canvas 2025-04-14 18:00:38 +01:00
Timothy Flynn
f070264800 Everywhere: Remove sv suffix from format string literals
This prevents the compile-time checks that would catch errors in the
format invocation (which would usually lead to a runtime crash).
2025-04-08 20:00:18 -04:00
Sam Atkins
3288c71953 LibGfx: Serialize unicode-ranges in uppercase
This matches the behavior of other browsers.
2025-04-07 10:00:21 +01:00
Aliaksandr Kalenik
12a2aebeb6 LibWeb: Move painting surface allocation into rendering thread
Skia has a check in debug mode to verify that surface is only used
within one thread. Before this change we were violating this by
allocating surfaces on the main thread while using and destructing them
on the rendering thread.
2025-04-03 22:01:43 +02:00
Aliaksandr Kalenik
fd147e6be0 LibWeb: Protect SkiaBackendContext with a mutex
The Skia Ganesh backend we currently use doesn't support painting from
multiple threads, which could happen before this change when the main
thread used Skia to paint on the HTML canvas while the rendering thread
was working on display list rasterization.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4172
2025-04-01 23:39:05 +02:00
Aliaksandr Kalenik
24e2c402f5 LibWeb+WebContent: Move display list rasterization off the main thread
The display list is an immutable data structure, so once it's created,
rasterization can be moved to a separate thread. This allows more room
for performing other tasks between processing HTML rendering tasks.

This change makes PaintingSurface, ImmutableBitmap, and GlyphRun atomic
ref-counted, as they are shared between the main and rendering threads
by being included in the display list.
2025-03-31 15:58:15 +01:00
Sam Atkins
e0a03147c6 LibGfx: Make UnicodeRange comparable 2025-03-28 09:15:02 +00:00
Jelle Raaijmakers
bf517f9ac2 LibGfx+LibWeb: Convert bitmap alpha type when creating ImmutableBitmaps
When decoding data into bitmaps, we end up with different alpha types
(premultiplied vs. unpremultiplied color data). Unfortunately, Skia only
seems to handle premultiplied color data well when scaling bitmaps with
an alpha channel. This might be due to Skia historically only supporting
premultiplied color blending, with unpremultiplied support having been
added more recently.

When using Skia to blend bitmaps, we need the color data to be
premultiplied. ImmutableBitmap gains a new method to enforce the alpha
type to be used, which is now used by SharedResourceRequest and
CanvasRenderingContext2D to enforce the right alpha type.

Our LibWeb tests actually had a couple of screenshot tests that exposed
the graphical glitches caused by Skia; see the big smiley faces in the
CSS backgrounds tests for example. The failing tests are now updated to
accommodate the new behavior.

Chromium and Firefox both seem to apply the same behavior; e.g. they
actively decode PNGs (which are unpremultiplied in nature) to a
premultiplied bitmap.

Fixes #3691.
2025-03-22 17:49:38 +01:00
Jelle Raaijmakers
c6644c92e7 LibGfx: Factor out PNG frame decoding logic
The logic for decoding APNGs and single-frame PNGs had some duplicated
code. No functional changes.
2025-03-22 17:49:38 +01:00
Jelle Raaijmakers
e4a5be0206 LibGfx+ImageDecoder: Use RefPtr<Bitmap> instead of optional
Simplify the list of bitmaps a bit by changing
`Optional<NonnullRefPtr<Bitmap>>` into `RefPtr<Bitmap>`. No functional
changes.
2025-03-22 17:49:38 +01:00
aplefull
19bee8393d LibGfx: Add support for YCCK jpeg files 2025-03-22 17:35:29 +01:00
aplefull
57d0c563e0 LibGfx: Fix handling of partially corrupt GIFs
GIF loader was completely failing when encountering errors with
frame descriptors or individual frames, even when some frames were
successfully loaded. Now we attempt to decode at least some frames
and fail only when no frames can be decoded at all.
2025-03-20 16:12:53 +01:00
devgianlu
1c2b373e9c LibCompress: Refactor deflate de/compressor using zlib
Also remove two crash tests that are not relevant anymore because the
implementation changed substantially.
2025-03-19 13:46:50 +01:00