Commit Graph

191 Commits

Author SHA1 Message Date
Sam Atkins
dcbe302f83 LibGfx: Remove bit casting in OpenType Head table after construction 2023-11-08 09:34:09 +01:00
Sam Atkins
72483673d2 LibGfx: Use ErrorOr to report failure to load OpenFont tables 2023-11-08 09:34:09 +01:00
Sam Atkins
1ab03ff963 LibGfx: Read OpenType table directory using structs and streams 2023-11-08 09:34:09 +01:00
Sam Atkins
5455ecf650 LibGfx: Remove OpenType::Font::m_buffer
At first glance this looks like it holds the memory that the various
slices point into... but it actually doesn't own that memory. Nobody
uses m_buffer, so it serves no purpose.
2023-11-08 09:34:09 +01:00
Sam Atkins
984a2c314b LibGfx: Read OpenType TTCHeaderV1 as a struct
Also check that the requested font index actually exists in the font
collection.
2023-11-08 09:34:09 +01:00
Sam Atkins
1a6da4fbf2 LibGfx: Mark OpenType file data structs as packed, and assert sizes
Some of these are odd sizes. We managed not to insert padding because
BigEndian is itself marked as packed, but let's be explicit instead of
relying on that. :^)
2023-11-08 09:34:09 +01:00
Sam Atkins
dfa79ba6d8 LibGfx: Move implementation code for Tables.h into Tables.cpp 2023-11-08 09:34:09 +01:00
MacDue
50d33f79fa LibGfx: Allow extracting paths from fonts and add Gfx::Path::text()
This updates fonts so rather than rastering directly to a bitmap, you
can extract paths for glyphs. This is then used to implement a
Gfx::Path::text("some text", font) API, that if given a vector font
appends the path of the text to your Gfx::Path. This then allows
arbitrary manipulation of the text (rotation, skewing, etc), paving the
way for Word Art in Serenity.
2023-11-05 02:46:46 +01:00
Tim Ledbetter
a6f9ad6012 LibGfx/OpenType: Ensure offsets are strictly less than the file size
Previously, an offset that was equal to the size of the file would
cause a crash.
2023-10-31 14:15:24 +01:00
Andrew Kaster
86ce502ae2 LibGfx+Utilities: Add helpers to load vector fonts from Core::Resources 2023-10-29 13:12:28 -06:00
Andrew Kaster
286dc6df7f LibGfx: Remove ability to load fonts directly from a file path
Users must now either pass a Core::Resource, a resource:// URI, or
a Core::MappedFile
2023-10-29 13:12:28 -06:00
Andrew Kaster
1567332e34 Userland+Tests: Remove uses of direct file loading for BitmapFont
Route them through Core::Resource APIs instead.
2023-10-29 13:12:28 -06:00
Andrew Kaster
d587bd0a04 LibGfx: Add helpers to load BitmapFont from Core::Resource 2023-10-29 13:12:28 -06:00
Andrew Kaster
897f4d05eb LibGfx: Add abstraction to load BitmapFont from a FixedMemoryStream
We'll use this to load from a Core::Resource in a later commit.
2023-10-29 13:12:28 -06:00
Tim Ledbetter
4b5b8fc564 LibGfx: Use safe version of count_leading_zeroes() in WOFF parsers
This guards against undefined behavior when zero is given as an
argument.
2023-10-27 07:13:51 +02:00
Nico Weber
88bd7d83ad LibGfx: Fix off-by-one in opentype cmap format 6 parsing
Fixes asserts when rendering 0000037.pdf, 0000116.pdf, 0000463.pdf,
0000483.pdf, 0000506.pdf, and 0000938.pdf in 0000.zip from the
pdfa dataset.
2023-10-27 07:13:19 +02:00
Nico Weber
2ef24e883c LibGfx: Add spec links for cmap table formats 2023-10-27 07:13:19 +02:00
Nico Weber
864172084b LibGfx: Call dbgln() on unimplemented cmap format 2023-10-27 07:13:19 +02:00
Tim Ledbetter
7096ea82f9 LibGfx: Use count_leading_zeroes to calculate nearest power of 2
This removes the possibility of an infinite loop.
2023-10-26 08:39:26 +02:00
Tim Ledbetter
6e4c97a328 LibGfx/WOFF: Return error if numTables is 0
This is consistent with WOFF2.
2023-10-26 08:39:26 +02:00
Tim Ledbetter
52f78d07b8 LibGfx/WOFF2: Ensure numTables is within expected range
An error is now returned if `numTables` is zero or greater than 4096.
While this isn't explicitly mentioned in the specification, subsequent
calculations will be incorrect if the value falls outside this range.
2023-10-26 08:39:26 +02:00
Tim Ledbetter
e9be1bcd09 LibGfx/WOFF2: Reject fonts with a compressed size larger than 10MiB
This prevents a potential OOM condition when the header is malformed.
2023-10-24 13:45:01 +02:00
Tim Ledbetter
af633523af LibGfx/WOFF2: Tolerate incorrect totalSfntSize in WOFF2 header
The specification says that this value is for reference only, so we
should be able to load a file where this value is incorrect.
2023-10-24 13:45:01 +02:00
Tim Ledbetter
c2112cde76 LibGfx/WOFF: Ensure header totalSfntSize matches expected value 2023-10-24 07:29:09 +02:00
Tim Ledbetter
7ee09ca49d LibGfx/WOFF: Avoid overflow in table directory search range
This commit limits `WOFF::Header::num_tables` to 4096. This limitation
is not explicitly mentioned in the specification, but allowing numbers
larger than this results in an overflow when calculating
`search_range` and `range_shift`.
2023-10-24 07:29:09 +02:00
Sam Atkins
e108f394bf LibGfx: Replace manual offsets when producing WOFF2 loca table 2023-10-22 19:42:22 +02:00
Sam Atkins
885665b3a6 LibGfx: Simplify writing to WOFF2 reconstructed glyf table 2023-10-22 19:42:22 +02:00
Sam Atkins
ad717af63d LibGfx: Read WOFF2 transformed GLYF table buffers in-place
This saves us from having to allocate a buffer and copying the data,
when it's already available to us. Also, less code. :^)
2023-10-22 19:42:22 +02:00
Sam Atkins
9642a0f43a LibGfx: Use a struct for reading WOFF2 transformed GLYF table 2023-10-22 19:42:22 +02:00
Sam Atkins
8e96902c75 LibGfx: Use OpenType offset table structs when reading WOFF2 font data 2023-10-22 19:42:22 +02:00
Sam Atkins
b73b434f80 LibGfx: Use a Header struct when reading WOFF2 font data 2023-10-22 19:42:22 +02:00
Sam Atkins
9f93ae4bfc LibGfx: Use offset table structs when reading WOFF font data 2023-10-22 19:42:22 +02:00
Sam Atkins
d80c528eb4 LibGfx: Add structs for OpenType offset table 2023-10-22 19:42:22 +02:00
Sam Atkins
e7fe377501 LibGfx: Use a Stream to read WOFF font data
This lets us read structs directly from the data, instead of having to
construct them from manual offsets.
2023-10-22 19:42:22 +02:00
Aliaksandr Kalenik
c2eaa0eb1c LibGfx: Fix crash during rasterizing glyphs containing only one point
Fixes https://github.com/SerenityOS/serenity/issues/20179
2023-10-18 01:16:21 +02:00
Andrew Kaster
639051d34e LibGfx: Inspect font paths using LexicalPath::has_extension()
This prevents us from trying to load a file named "fonts/.font"
2023-10-17 11:02:01 -06:00
Andrew Kaster
21d027129d LibGfx: Remove the ability to load fonts from a path directly 2023-10-17 11:02:01 -06:00
Andrew Kaster
e03357308c LibGfx: Load fonts with new Resource API instead of filesystem paths
The old API is in place until we remove all the users.
2023-10-17 11:02:01 -06:00
Sam Atkins
18dfc61280 LibGfx: Expose BitmapFont glyph data as Spans instead of raw pointers 2023-10-10 14:36:25 +02:00
Sam Atkins
80e756daef LibGfx: Load BitmapFont data more safely
Previously, `load_from_memory()` just took a raw pointer to the data,
and then manually calculated offsets from that pointer. Instead, let's
use the MappedFile we already have, to stream in the data, to make
things a bit safer. We also now check that the entire file's data was
read, since if there was data left over, then either the file is bad or
we've done something wrong.

I've moved the code directly into `try_load_from_mapped_file()` since
`load_from_memory()` was only called from there. The extra indirection
wasn't adding anything.
2023-10-10 14:36:25 +02:00
Sam Atkins
8e51c7112c LibGfx: Store BitmapFont glyph widths as a Span<u8>
More raw pointer removal.
2023-10-10 14:36:25 +02:00
Sam Atkins
f6c40abdb1 LibGfx: Give GlyphBitmap its rows data as Bytes
Instead of giving it a raw pointer to the start of the font's rows data
and an offset, give it the Bytes for its rows only.
2023-10-10 14:36:25 +02:00
Sam Atkins
a3b91378df LibGfx: Store BitmapFont rows data as Bytes 2023-10-10 14:36:25 +02:00
Sam Atkins
415a024bc8 LibGfx: Store BitmapFont range mask as Bytes instead of pointer and size 2023-10-10 14:36:25 +02:00
Sam Atkins
533ec5a06f LibGfx: Use Core::System helper for BitmapFont memory allocation 2023-10-10 14:36:25 +02:00
Sam Atkins
89ef3ed4ce LibGfx: Mark BitmapFont::try_clone() as virtual 2023-10-10 14:36:25 +02:00
Sam Atkins
a1c24ef3ad LibGfx: Remove infallible BitmapFont::create() factory function
This was only used in TestFontHandling. So, let's remove it, and use
the "create" name for the fallible one.
2023-10-10 14:36:25 +02:00
kleines Filmröllchen
062e0db46c LibCore: Make MappedFile OwnPtr-based
Since it will become a stream in a little bit, it should behave like all
non-trivial stream classes, who are not primarily intended to have
shared ownership to make closing behavior more predictable. Across all
uses of MappedFile, there is only one use case of shared mapped files in
LibVideo, which now uses the thin SharedMappedFile wrapper.
2023-09-27 03:22:56 +02:00
Gabriel Nava Marino
3a071bc4dd AK: Replace unsafe offset_pointer usage in OpenType code
In OpenType code, replace unsafe Span::offset_pointer with Span::offset,
which includes bounds checks.
2023-09-25 00:19:38 +02:00
Andreas Kling
13db3c5ce0 LibGfx: Convert FontDatabase APIs to use FlyString 2023-09-06 11:29:03 -04:00