Commit Graph

32151 Commits

Author SHA1 Message Date
Nico Weber
bc42144642 LibGfx/JBIG2: Start implementing the generic region decoding procedure
If the "MMR" bit is set, the generic region decoding procedure just
uses ITU-T T.6 (2D CCITT), which we already have an implementation of.
In practice, this is used almost never in .jbig2 files and in none of
the PDFs I have.

The two files that do use MMR are:

1.) JBIG2_ConformanceData-A20180829/F01_200_TT9.jb2
2) 042_3.jb2 from the ghostpdl tests

The first uses an immediate _lossless_ generic region, which we don't
implement yet (but I think it should just forward to the normal
immediate generic region code? Not in this commit, though). The second
uses a regular immediate generic region, and we can decode it now:

    Build/lagom/bin/image -o out.png \
        path/to/ghostpdl/tests/jbig2/042_3.jb2
2024-03-11 16:48:57 +01:00
Nico Weber
e0af3ae8d9 LibGfx/JBIG2: Implement decode_end_of_file() 2024-03-11 16:48:57 +01:00
Nico Weber
323cacc593 LibGfx/JBIG2: Implement decode_end_of_page() 2024-03-11 16:48:57 +01:00
Aliaksandr Kalenik
ecce570cb7 LibWeb: Stop animation driver timer after document becomes inactive 2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
fd63ffb8c3 LibWeb: Use Core::Timer instead for animation driver timer
Platform::Timer uses JS::SafeFunction that prevents document from ever
being deallocated because of strong reference.
2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
2129c5d8b0 LibWeb: Unregister AnimationTimeline from document in finalize()
...instead of destructor because by the time it is executed, document
could already be destroyed.
2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
bcdf4a375d LibWeb: Use resolve_grid_position for abspos boxes layout in GFC
Removes duplicated code that resolves position based on computed
values.

No behaviour change intended.
2024-03-11 15:20:58 +01:00
Bastiaan van der Plaat
bd86beb7e4 Maps: Add FavoritesModel and remove hacky misusage of JSONArrayModel 2024-03-11 10:40:23 +00:00
Bastiaan van der Plaat
29026ce965 Maps: Move TileProviders.json to user independent folder 2024-03-11 10:40:23 +00:00
implicitfield
5da9f52b1f LibWeb: Use the parent container's y offset when finding static position
Fixes #18819.
2024-03-10 18:10:01 +01:00
Lucas CHOLLET
2b8594dc85 LibGfx: Replace FLATTEN with ALWAYS_INLINE for draw_glyph() overload
While IMO, the change makes sense on its own as flattening this function
will just duplicate the code from `draw_glyph()` with no benefits, this
is not what motivated this patch.

When compiling with debug information and ASAN, GCC 13.2 would issue
this warning:

Userland/Libraries/LibGfx/Painter.cpp: In member function ‘void Gfx::Pai
nter::draw_glyph(Gfx::FloatPoint, u32, Gfx::Color)’:
Userland/Libraries/LibGfx/Painter.cpp:1354:14: note: variable tracking s
ize limit exceeded with ‘-fvar-tracking-assignments’, retrying without
 1354 | FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_poin
t, Color color)
      |              ^~~~~~~

From what I've read online, this is caused by some limit on the number
of symbols in the compiler's internal data structures. People at Google
have fixed this warning by splitting functions:
https://codereview.chromium.org/1164893003

While getting us rid of the warning, it also drastically improves
compilation time. Going from 1min27 to 59s on my machine.
2024-03-10 10:18:36 -04:00
Matthew Olsson
e91f4dcd79 LibWeb: Use Performance for animation time instead of MonotonicTime
Performance handles the document origin time correctly, and prevents
these times from being unusually large. Also initialize the
DocumentTimeline time in the constructor, since these can be created
from JS.
2024-03-10 15:13:47 +01:00
Nico Weber
bdbc21c52d LibGfx/JBIG2: Implement conversion to Gfx::Bitmap and ByteBuffer
With this, `image` can convert any jbig2 file, as long as it's
black (or white), and LibPDF can draw jbig2 files (again, as long
as they only contain a single color stored in just a
PageInformation segment).
2024-03-10 10:10:55 -04:00
Nico Weber
be9a6caa0a LibPDF: In Filter::decode_jbig2(), invert bits
See included comment.
2024-03-10 10:10:55 -04:00
Nico Weber
54982857bd LibGfx/JBIG2: Implement decode_page_information()
Also make scan_for_page_size() not early return, so that it has the
same behavior as the main decoding look. (Multiple page information
segments for a single page are likely invalid and don't happen in
practice, so this is mostly an academic change.)

Add a BitBuffer class to store the bit image data, and introduce a
Page struct for storing data associated with a page. We currently
only handle a single page, but a) this makes it easier to decode
multiple pages in the future if we want b) it makes the code easier
to understand.
2024-03-10 10:10:55 -04:00
Nico Weber
4b01f2f158 LibGfx/JBIG2: Implement decode_extension()
Only logs the data to dbgln().

All jb2 files in ghostpdl/tests start with this segment.
2024-03-10 10:10:55 -04:00
Nico Weber
9cd0c5658e LibGfx/JBIG2: Reject files with delayed height information for now
7.4.8.2 Page bitmap height:
"In some cases, this value may not be known at the time that the page
information segment is written. In this case, this field must contain
0xFFFFFFFF, and the actual page height may be communicated later, once
it is known."
2024-03-10 10:10:55 -04:00
Nico Weber
f592a2ac72 LibPDF/JBIG2: Print a warning on files with more than one page 2024-03-10 10:10:55 -04:00
Nico Weber
2caf603836 LibGfx/JBIG2: Add scaffolding for interpreting segment data 2024-03-10 10:10:55 -04:00
Nico Weber
af20ebe4a0 LibGfx/JBIG2: Scan for page size of page "1"
Sounds like the spec guarantees that that's the number of the first
page.

(In practice, all but one of all jbig2 files I've found contain just
page 1. PDFs almost always contain just page 1, and very rarely a
page 0 for globally shared parameters.)
2024-03-10 10:10:55 -04:00
Timothy Flynn
842caf5e8c LibWeb: Do not shrink the CPU painter's corner clipping vector
If the provided ID is smaller than the corner clipping vector, we would
shrink the vector to match. This causes a crash when we have nested
PaintContext instances (as these IDs are allocated by PaintContext),
each of which perform radius painting.

This is seen on https://www.strava.com/login when it loads a reCAPTCHA.
The outer div has a border radius, which contains the reCAPTCHA in an
iframe. That iframe contains an SVG which also has a border radius.
2024-03-10 00:39:49 +01:00
Aliaksandr Kalenik
33294aea86 LibWeb: Apply shadow root style sheets in StyleComputer
Now, if an element belongs to a shadow tree, we use only the style
sheets from the corresponding shadow root during style computation,
instead of using all available style sheets as was the case
previously.

The only exception is the user agent style sheets, which are still
taken into account for all elements.

Tests/LibWeb/Layout/input/input-element-with-display-inline.html
is affected because style of document no longer affects shadow tree
of input element, like it is supposed to be.

Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
91ec1d6f95 LibWeb: Maintain list of allocated shadow roots in Document
Doing that will allow us to get a list of style sheets for each shadow
root from StyleComputer without having to traverse the entire tree in
upcoming changes.
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
c6e69d501f LibWeb: Add style sheets to the shadow root if applicable
If a style element belongs to a shadow tree, its CSSStyleSheet is now
added to the corresponding ShadowRoot instead of the document.

Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
8ce8697a66 LibWeb: Add styleSheets and adoptedStyleSheets attributes in ShadowRoot
Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
f19c92d78e LibWeb: Add ObservableArray::for_each() 2024-03-09 16:13:32 +01:00
implicitfield
54d8e58a68 LibWeb: Account for margin and padding of justified abspos flex items 2024-03-09 16:02:17 +01:00
implicitfield
3888a91c5b LibWeb: Account for margin and padding of aligned abspos flex items
This patch also makes FlexFormattingContext::calculate_static_position
use computed values for margins and borders, since this function may be
called before the box's state has been finalized.
2024-03-09 16:02:17 +01:00
implicitfield
e3b1d4a141 LibWeb: Compute content width before static position for abspos elements
In some scenarios, correctly computing the static position may depend on
the content width having been calculated beforehand.
2024-03-09 16:02:17 +01:00
implicitfield
18fe86adc3 LibWeb: Add support for the inline-size CSS property 2024-03-09 16:02:17 +01:00
Nico Weber
dd593d16c4 Fuzzers: Add JBIG2 fuzzer 2024-03-09 16:01:22 +01:00
Nico Weber
8f4930f2df LibGfx/JBIG2: Scan for the first PageInformation segment and decode it
This allows `file` to correctly print the dimensions of a .jbig2 file,
and it allows us to write a test that covers much of all the code
written so far.
2024-03-09 16:01:22 +01:00
Nico Weber
1eaaa8c3e9 LibPDF+LibGfx: Support JBIG2s with /JBIG2Globals set
Several ramifications:

* /JBIG2Globals is an indirect reference, which means we now need
  a Document for unfiltering. (Technically, other decode parameters
  can also be indirect objects and we should use the Document to
  resolve() those too, but in practice it only seems to be needed
  for /JBIG2Globals.)

* Since /JBIG2Globals are so rare, we just parse once for each
  image that use them, and decode_embedded() now receives a
  Vector<ReadonlyBytes> with all sections of sequences of
  segments.

* Internally, decode_segment_headers() is now called several times
  for embedded JBIG2s with multiple such sections (e.g. PDFs with
  /JBIG2Globals).

* That means `data` is now no longer part of JBIG2LoadingContext
  and things get slightly reshuffled due to this.

This completes the LibPDF part of JBIG2 support. Once LibGfx
implements actual decoding of JBIG2s, things should start to
Just Work in PDFs.
2024-03-09 16:01:22 +01:00
Nico Weber
09ca66cb8b LibGfx/JBIG2: Scan for end of immediate generic regions of unknown size
Found e.g. in 0000033.pdf (both pages).
2024-03-09 16:01:22 +01:00
Nico Weber
379ef45688 LibGfx/JBIG2: Store location of segment data bodies
They're in different places for Sequential/Embedded (right after
the header) and RandomAccess (which has all headers first, followed
by all data bits next).

We don't do anything with the data yet, but now everything's in
place to actually process segment data.
2024-03-09 16:01:22 +01:00
Nico Weber
953f6c5d9b LibPDF+LibGfx: Pass jbig2-filtered data to JBIG2ImageDecoderPlugin
Except for /JBIG2Globals, which we bail out on for now. In my 1000
files, 13 use JBIG2, and of those, 2 use JBIG2Globals (0000372.pdf e.g.
page 11 and 0000857.pdf e.g. page 1), and only one (the latter) of the
two uses the same JBIG2Globals stream for more than a single image.

JBIG2ImageDecoderPlugin cannot decode the data yet, so no behavior
change, but with `#define JBIG2_DEBUG 1` at the top of that file,
it now prints segment header info for PDFs containing JBIG2 data :^)
2024-03-09 16:01:22 +01:00
Nico Weber
b1fdc33a22 LibGfx/JBIG2: Decode all segment headers
With `#define JBIG2_DEBUG 1` at the top of the file:

    % Build/lagom/bin/image --no-output \
       .../JBIG2_ConformanceData-A20180829/F01_200_TT10.jb2
    JBIG2LoadingContext: Organization: 0 (Sequential)
    JBIG2LoadingContext: Number of pages: 1
    Segment number: 0
    Segment type: 48
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 19
    Segment number: 1
    Segment type: 39
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 12666
    Segment number: 2
    Segment type: 49
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 0
    Runtime error: JBIG2ImageDecoderPlugin: Draw the rest of the owl
2024-03-09 16:01:22 +01:00
Nico Weber
177664cfae LibGfx/JBIG2: Add an initial decode_segment_header()
With `#define JBIG2_DEBUG 1` at the top of the file:

    % Build/lagom/bin/image --no-output \
        .../JBIG2_ConformanceData-A20180829/F01_200_TT10.jb2
    JBIG2LoadingContext: Organization: 0 (Sequential)
    JBIG2LoadingContext: Number of pages: 1
    Segment number: 0
    Segment type: 48
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 19
    Runtime error: JBIG2ImageDecoderPlugin: Draw the rest of the owl
2024-03-09 16:01:22 +01:00
Nico Weber
5cefcad2fe LibGfx/JBIG2: Decode the file header
Running `image` with `#define JBIG2_DEBUG 1` now prints number of pages.
2024-03-09 16:01:22 +01:00
Nico Weber
58838db445 LibGfx: Add the start of a JBIG2 loader
JBIG2 is infamous for two things:

1. It's used in xerox scanners were it falsifies scanned numbers:

https://www.dkriesel.com/en/blog/2013/0802_xerox-workcentres_are_switching_written_numbers_when_scanning

2. It was allegedly used in an iOS zero day, in a very cool way:

https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-into-nso-zero-click.html

Needless to say, we need support for it in Serenity. (...because it's
used in PDF files.)

This adds all the scaffolding, but no actual implementation yet.

It's enough for `file` to print the mime type of .jb2 files, but `image`
can't do anything with the files yet.
2024-03-09 16:01:22 +01:00
Matthew Olsson
d76c2d45c4 LibWeb: Remove scopes for execution contexts in Animation finish steps 2024-03-09 15:34:27 +01:00
Matthew Olsson
fc6a6d29ec LibWeb: Ensure m_is_finished is false after cancelling Animation 2024-03-09 15:34:27 +01:00
Matthew Olsson
e11b9658ed LibWeb: Disassociate animations from Animatables when setting effects 2024-03-09 15:34:27 +01:00
Matthew Olsson
90290eb985 LibWeb: Store Animations in Animatable instead of AnimationEffects
This is closer to what the spec instructs us to do, and matches how
associations are maintained in the timelines. Also note that the removed
destructor logic is not necessary since we visit the associated
animations anyways.
2024-03-09 15:34:27 +01:00
Matthew Olsson
f386c01ae1 LibWeb: Use the correct start time when pausing/playing animations 2024-03-09 15:34:27 +01:00
Matthew Olsson
24ec5838ba LibWeb: Visit Animatable::m_associated_effects 2024-03-09 15:34:27 +01:00
Timothy Flynn
2a021a35fc LibGUI: Consider carriage returns when counting lines in a label
We create labels in the Browser from text on web documents, which may
use carriage returns. LibGfx will split lines on CR already, but LibGUI
would not consider CRs when computing the height of the containing
widget. The result was text that would not fit in the label's box.
2024-03-08 14:43:33 -05:00
Timothy Flynn
07a27b2ec0 AK: Replace the boolean parameter of StringView::lines with a named enum 2024-03-08 14:43:33 -05:00
Timothy Flynn
d9349f1510 LibGfx: Treat "\r\n" as a single line break during text layout
We currently insert two line breaks for this sequence. This Windows-
style of line breaking can be seen in documents on the web.
2024-03-08 14:43:33 -05:00
Sam Atkins
4bdb7dba8c LibWeb: Add and use a helper to reject a promise with an exception 2024-03-08 14:14:57 -05:00