Commit Graph

58718 Commits

Author SHA1 Message Date
Kemal Zebari
dbb3c07e56 LibWeb/HTML: Sniff text or binary resources in HTMLObjectElement 2024-02-02 14:34:17 -05:00
Kemal Zebari
8e5410347b LibWeb/MimeSniff: Add non-standard text or binary context sniffing
This is used in cases where the spec expects us to only run the
"rules for distinguishing if a resource is a text or binary" algo.
2024-02-02 14:34:17 -05:00
Sam Atkins
8a974ca91a SystemServer: Correct logic for services exiting successfully
WIFEXITED() returns a bool, so previously we were setting
exited_successfully to true when the service was terminated by a signal,
and false if it exited, regardless of the exit status. To test the exit
status, we have to use WEXITSTATUS() instead.

This causes us to correctly use the "3 tries then give up" logic for
services that crash, instead of infinitely attempting to respawn them.
2024-02-02 16:08:23 +00:00
Nico Weber
e269526020 LibGfx/PNM: Remove two fixmes
bab2113ec1 made read_whitespace() return ErrorOr, which makes this
easy to do.

(7cafd7d177, which added the fixmes, landed slightly after bab2113ec1,
so not quite sure why it wasn't like this immediately. Maybe commit
order got changed during review; both commits were in #17831.)

No behavior change.
2024-02-02 08:26:40 +00:00
Nico Weber
eeb0d6f52b image: Remove "do_" prefix on two function names
These were here due to the prefix-less name conflicting with a local
bool, but now that options are in a struct that's no longer a problem.

No behavior change.
2024-02-02 07:20:02 +01:00
Nico Weber
d575d4fb9b image: Extract option parsing to separate function
No behavior change.
2024-02-02 07:20:02 +01:00
Nico Weber
6dc5608d95 image: Allow saving CMYK jpegs
`image` can't transform from RGB to CMYK yet, so the only way to
do this is by having a CMYK input.

For example, this works now (and it does a full decode and re-encode):

    Build/lagom/bin/image -o out.jpg \
        Tests/LibGfx/test-inputs/jpg/buggie-cmyk.jpg

Using this to convert `.pam` files written by `mutool extract`
to jpegs is a somewhat convenient method of looking at these
.pam files.
2024-02-02 07:19:18 +01:00
Nico Weber
2298aac1d1 image: Only create output file for known extensions
Previously `image -o foo.asdf foo.png` would create a 0-byte foo.asdf
before complaining that it doesn't know how to write .asdf images.

(Lifetimes of temporaries are extended to the end of the full
expresion, so this is fine.)
2024-02-02 07:19:18 +01:00
Nico Weber
1dfd68c798 LibGfx/JPEGWriter: Make it possible to write CMYKBitmaps
We always store CMYK data as YCCK, for two reasons:

1. If we ever want to do subsampling, then doing 2111 or
   2112 makes sense with YCCK, while it doesn't make sense
   if we store CMYK directly.
2. It forces us to write a color transform header. With a color
   transform header, everyone agrees that the CMYK channels should
   be stored inverted, while without it behavior between decoders
   is inconsistent. (We could write an explicit  color transform header
   for CMYK too though, but with YCCK it's harder to forget since the
   output will look wrong everywhere without it.)

initialize_mcu() grows a full CMYKBitmap override. Some of the
macroblock traversal could probably shared with some kind of
for_all_macroblocks() type function in the future, but the color
conversion math is different enough that this should be a separate
function.

Other than that, we pass around a mode parameter and make a few fuctions
write 4 instead of 3 channels, and that's it.

We use the luminance quantization and huffman tables for the K
channel.
2024-02-02 07:19:18 +01:00
Nico Weber
e8788d4023 LibGfx/JPEGWriter: Move image data writing into new add_image() function
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
e449dba85b LibGfx/JPEGWriter: Move header writing into new add_headers() function
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
4e637fa1d2 LibGfx/JPEGWriter: Pass IntSize instead of Bitmap to add_frame_header()
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
38526414b0 LibGfx/JPEGWriter: Add a named constant in add_scan_header()
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
4a8e7f44dc LibGfx/JPEGWriter: Add a named constant in add_frame_header()
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
ad7d25f089 LibGfx/JPEGWriter: Make vertical_macroblocks a local
It's only used in one function.

No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
8964a52fe0 LibGfx/JPEGWriter: Use ceil_div()
No behavior change.
2024-02-02 07:19:18 +01:00
Nico Weber
d60758a947 LibGfx: Remove now-unused Color::from_cmyk()
`CMYKBitmap::to_low_quality_rgb()` morally still does the same thing,
but it has a slightly more scary name, and it doesn't use this exact
function. So let's toss it :^)
2024-02-01 13:42:04 -07:00
Nico Weber
9c762b9650 LibPDF+Meta: Use a CMYK ICC profile to convert CMYK to RGB
CMYK data describes which inks a printer should use to print a color.
If a screen should display a color that's supposed to look similar
to what the printer produces, it results in a color very different
to what Color::from_cmyk() produces. (It's also printer-dependent.)

There are many ICC profiles describing printing processes. It doesn't
matter too much which one we use -- most of them look somewhat
similar, and they all look dramatically better than Color::from_cmyk().

This patch adds a function to download a zip file that Adobe offers
on their web site. They even have a page for redistribution:
https://www.adobe.com/support/downloads/iccprofiles/icc_eula_win_dist.html

(That one leads to a broken download though, so this downloads the
end-user version.)

In case we have to move off this download at some point, there are also
a whole bunch of profiles at https://www.color.org/registry/index.xalter
that "may be used, embedded, exchanged, and shared without restriction".

The adobe zip contains a whole bunch of other useful and fun profiles,
so I went with it.

For now, this only unzips the USWebCoatedSWOP.icc file though, and
installs it in ${CMAKE_BINARY_DIR}/Root/res/icc/Adobe/CMYK/. In
Serenity builds, this will make it to /res/icc/Adobe/CMYK in the
disk image. And in lagom build, after #23016 this is the
lagom res staging directory that tools can install via
Core::ResourceImplementation. `pdf` and `MacPDF` already do that,
`TestPDF` now does it too.

The final piece is that LibPDF then loads the profile from there
and uses it for DeviceCMYK color conversions.

(Doing file access from the bowels of a library is a bit weird,
especially in a system that has sandboxing built in. But LibGfx does
that in FontDatabase too already, and LibPDF uses that, so it's not a
new problem.)
2024-02-01 13:42:04 -07:00
Nico Weber
f840fb6b4e LibPDF: Make DeviceCMYKColorSpace::the() fallible
No behavior change.
2024-02-01 13:42:04 -07:00
Aliaksandr Kalenik
79b73b7fbb LibWeb: Use Window::scroll() in Element::set_scroll_top()
Now when Window::scroll() could do actual scrolling we can remove
this FIXME.
2024-02-01 09:23:48 -05:00
Aliaksandr Kalenik
a4d78c7df9 LibWeb: Use Window::scroll() in Element::set_scroll_left()
Now when Window::scroll() could do actual scrolling we can remove
this FIXME.
2024-02-01 09:23:48 -05:00
Aliaksandr Kalenik
5484062095 LibWeb: Apply scroll offset to PushStackingContext command
In cases where the stacking context painting requires a separate
bitmap, the destination position needs to be translated by the
scrolling offset to ensure it ends up in the correct position.
2024-02-01 13:38:45 +01:00
Nico Weber
384c6cf0f9 LibPDF: Tweak vertical position of truetype fonts again
See #22821 for a previous attempt. This attempt should settle
things once and for all.

The opentype render path adjusts by `-font_ascender * -y_scale` in
Glyf::Glyph::append_simple_path(), so that's what we need to undo
to draw at the font's baseline.

(OpenType::Font::metrics() returns ascender scaled by y_scale already,
so no need to have the scale here where we undo the shift.)

Previously, we called `baseline()` which just returns the font's
font size, which is pretty meaningless:

https://tonsky.me/blog/font-size/
https://simoncozens.github.io/fonts-and-layout/opentype.html#vertical-metrics-hhea-and-os2

Also, conceptually it makes sense to translate up by the ascender
to get from the upper edge of the glyph to the baseline.
2024-02-01 10:05:40 +01:00
Sam Atkins
d930ea1242 HexEditor: Add an option to load an annotations file on startup 2024-01-31 17:38:56 +00:00
Sam Atkins
4cef57a021 HexEditor: Parse arguments using ArgsParser 2024-01-31 17:38:56 +00:00
Sam Atkins
56caee44e3 HexEditor: Save and load annotations to/from JSON files
This is a fairly simple JSON format: A single array, containing objects,
with the Annotation fields as key:value pairs.

When reading a file, we let invalid or missing keys fall back to the
default values. This is mostly intended to set a pattern so that if we
add new fields in the future, we won't fail to load old annotations
files. If loading the file fails though, we keep the previously loaded
set of annotations.
2024-01-31 17:38:56 +00:00
Brad Parbs
b2bb7d919d Documentation: Update link to Default.css in LibWeb docs 2024-01-31 12:34:16 -05:00
Xexxa
43fe7af35e Base: Add more emoji
🦻 - U+1F9BB EAR WITH HEARING AID
👯 - U+1F46F PEOPLE WITH BUNNY EARS
🐅 - U+1F405 TIGER
🐆 - U+1F406 LEOPARD
🕷️ - U+1F577 SPIDER
🏴󠁮󠁺󠁡󠁵󠁫󠁿 - U+1F3F4 U+E006E U+E007A U+E0061 U+E0075 U+E006B U+E007F
NZ-AUK Auckland
🏴󠁮󠁺󠁮󠁳󠁮󠁿 - U+1F3F4 U+E006E U+E007A U+E006E U+E0073 U+E006E U+E007F
NZ-NSN Nelson
🏴󠁮󠁺󠁷󠁧󠁮󠁿 - U+1F3F4 U+E006E U+E007A U+E0077 U+E0067 U+E006E U+E007F
NZ-WGN Wellington
🏴󠁰󠁡󠀱󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0031 U+E007F
PA-1 Bocas del Toro
🏴󠁰󠁡󠀲󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0032 U+E007F
PA-2 Coclé
🏴󠁰󠁡󠀳󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0033 U+E007F
PA-3 Colón
🏴󠁰󠁡󠀴󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0034 U+E007F
PA-4 Chiriquí
🏴󠁰󠁡󠀵󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0035 U+E007F
PA-5 Darién
🏴󠁰󠁡󠀶󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0036 U+E007F
PA-6 Herrera
🏴󠁰󠁡󠀷󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0037 U+E007F
PA-7 Los Santos
🏴󠁰󠁡󠀹󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0039 U+E007F
PA-9 Veraguas
🏴󠁰󠁡󠀱󠀰󠁿 - U+1F3F4 U+E0070 U+E0061 U+E0031 U+E0030 U+E007F
PA-10 West Panamá
🏴󠁰󠁡󠁫󠁹󠁿 - U+1F3F4 U+E0070 U+E0061 U+E006B U+E0079 U+E007F
PA-KY Guna Yala
🏴󠁰󠁡󠁮󠁢󠁿 - U+1F3F4 U+E0070 U+E0061 U+E006E U+E0062 U+E007F
PA-NB Ngöbe-Buglé
🏴󠁮󠁺󠁯󠁴󠁡󠁿 - U+1F3F4 U+E006E U+E007A U+E006F U+E0074 U+E0061 U+E007F
NZ-OTA Otago
2024-01-31 12:12:37 -05:00
Xexxa
cb63263551 Base: Modify emoji
👡 - U+1F461 WOMAN’S SANDAL

Add some shadow for more of a 3d-feeling.
2024-01-31 12:12:37 -05:00
Nico Weber
87112dcbdc LibPDF: Return null for invalid refs, tolerate null objects as outline
https://llvm.org/devmtg/2022-11/slides/TechTalk5-WhatDoesItTakeToRunLLVMBuildbots.pdf
has an xref table that starts like so:

```
xref
0 214
0000000002 65535 f
0000924663 00000 n
0000000003 00000 f
0000000000 00000 f
0000000016 00000 n
0000000160 00000 n
0000000263 00000 n
```

This is a list of objects in the PDF file. The lines ending with 'f'
mean that this object is "free", that is it's not stored in the file.
In this file, objects 0, 2, 3 are free. For free objects, the first
number is the offset of the next free object: Object 0 refers to object
2, 2 to 3, and 3 back to 0 (since it's the last free object).
The lines ending with "n" are actual objects; here the first number is
a byte offset to where that object is stored in the file.

Furthermore, the file contains

```
/Outlines
2
0
R
```

in its root object, meaning that object 2 stores the page outlines.

Since object 2 is set as free, there is no object 2. But the spec
says that an invalid object reference is just the null object.

This patch makes us return null objects for references to free
objects, and it also makes us treat a null object as /Outlines value
the same as not having /Outlines in the first place.

Fixes #23023 -- we can now open that file. (We don't render it super
well, but only for already-known reasons.)

Since I found it a bit confusing: XRefTable has two related methods
here:

1. has_object() returns if an object was explicitly listed in an
   xref table. The first number right after `xref` is the start
   index. So if an xref table were to start with `10`, we'd implicitly
   create 10 trailing objects for which has_object() would return false
2. is_object_in_use() returns true if an object that was in a table
   (i.e. one where has_object() returns true) was listed with 'n' and
   false if it was listed with 'f'.

DocumentParser::parse_object_with_index() should probably return a null
object for the `!has_object()` case as well instead of VERIFY()ing
that has_object() is true. But I haven't seen this in the wild yet,
so keeping as-is for now.
2024-01-31 12:10:19 -05:00
Aliaksandr Kalenik
dc47d01fdc LibWeb: Remove contained_by_inline_node flag in PaintableFragment
No longer used after we made inline paintables own their fragments.
2024-01-31 07:15:49 +01:00
Aliaksandr Kalenik
9dddd6b028 LibWeb: Account for scroll offset in overflow clip rect calculation
This change addresses an issue with overflow clipping in scenarios
where `overflow: hidden` is applied to boxes nested within elements
with `overflow: scroll`.

Fixes https://github.com/SerenityOS/serenity/issues/22733
2024-01-31 07:15:25 +01:00
Dan Klishch
4330cdee74 Tests/Kernel: Properly synchronize threads in TestTCPSocket
We should wait for a server thread to actually listen(2) a server socket
before trying to connect to it. This hopefully should make the test less
flaky.
2024-01-30 18:46:37 -07:00
nyyakko
e981197ee3 Userland/TaskbarWindow: Show context menu on right click 2024-01-30 18:45:19 -07:00
Nico Weber
70eac0fbe8 pdf+MacPDF: Use new Build/Root/lagom/res directory 2024-01-30 18:43:06 -07:00
Nico Weber
d1036c915d Meta: Create Build/lagom/Root/res with resources for lagom binaries
This way, build files can install things into
`${CMAKE_BINARY_DIR}/Root/res/` and it'll work in both serenity and
lagom builds.

It allows using a single `Core::ResourceImplementation::install()`
call to install both checked-in and generated files (as long as both
get copied into this new build-time staging dir).

No behavior change.
2024-01-30 18:43:06 -07:00
Sam Atkins
aa07c232f1 HexEditor: Optionally display annotations in the side panel 2024-01-30 23:34:49 +00:00
Sam Atkins
8cac2e89a9 HexEditor: Store annotations in a Model
A model is necessary for displaying a list of them in the UI. We might
as well make that their home.
2024-01-30 23:34:49 +00:00
Sam Atkins
a54952795a HexEditor: Add comments to annotations
The comment appears as a tooltip when hovering over the annotation.

A couple of properties of the TextEditor would ideally be set in GML,
but either don't have a setter exposed, or the GML compiler doesn't
recognise the enum. I'll fix those up after the current big GML
compiler PR gets merged.
2024-01-30 23:34:49 +00:00
Sam Atkins
4b1c7533f5 HackStudio: Fuzzy-match Locator suggestions
This also sorts them to put better results first. Currently the
fuzzy-match algorithm gets a little confused, but as that improves, so
will this.
2024-01-30 23:34:21 +00:00
Sam Atkins
85101c6626 HackStudio: Keep the DeclarationsModel around, and use a filtering proxy
Rather than construct a new DeclarationsModel each time the user types
something in the Locator, keep a single one around permanently in the
ProjectDeclarations, and then use a FilteringProxyModel over it for the
suggestions.
2024-01-30 23:34:21 +00:00
Sam Atkins
e72b14ef1d HackStudio: Correct DeclarationsModel::row_count() calculation
No indices contain other indices, so the row count is 0 if the index is
valid. This stops us infinitely recursing into non-existent indices.
2024-01-30 23:34:21 +00:00
Sam Atkins
44033415bc HackStudio: Rename & move DeclarationsModel::Suggestion -> Declaration 2024-01-30 23:34:21 +00:00
Sam Atkins
28e4e351cb HackStudio: Extract and rename the Locator's suggestions model
No code changes besides moving and renaming it.
2024-01-30 23:34:21 +00:00
Sam Atkins
a805cbc5ab HackStudio: Remove Locator log spam
This doesn't seem useful enough to keep behind a flag.
2024-01-30 23:34:21 +00:00
Bastiaan van der Plaat
706a741053 Taskbar: Fix bug where dropping item in quick launch widget would crash 2024-01-30 22:39:52 +00:00
Brendan Kelly
00ab8e0a14 Maps: Add massage_for_display for lat and long
This prevents a crash when attempting to add a
favorite or load favorites list in Maps application
2024-01-30 21:07:37 +00:00
Nico Weber
69964e10f4 LibGfx+Tests: Improve calculation of restart interval
JPEGs can store a `restart_interval`, which controls how many
minimum coded units (MCUs) apart the stream state resets.
This can be used for error correction, decoding parts of a jpeg
in parallel, etc.

We tried to use

    u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor;
    i % (context.dc_restart_interval *
         context.sampling_factors.vertical *
         context.sampling_factors.horizontal) == 0

to check if we hit a multiple of an MCU.

`hcursor` is the horizontal offset into 8x8 blocks, vcursor the
vertical offset, and hpadded_count stores how many 8x8 blocks
we have per row, padded to a multiple of the sampling factor.

This isn't quite right if hcursor isn't divisible by both
the vertical and horizontal sampling factor. Tweak things so
that they work.

Also rename `i` to `number_of_mcus_decoded_so_far` since that
what it is, at least now.

For the test case, I converted an existing image to a ppm:

    Build/lagom/bin/image -o out.ppm \
        Tests/LibGfx/test-inputs/jpg/12-bit.jpg

Then I resized it to 102x77px in Photoshop and saved it again.
Then I turned it into a jpeg like so:

    path/to/cjpeg \
        -outfile Tests/LibGfx/test-inputs/jpg/odd-restart.jpg \
        -sample 2x2,1x1,1x1 -quality 5 -restart 3B out.ppm

The trick here is to:

a) Pick a size that's not divisible by the data size width (8),
   and that when rounded to a block size (13) still isn't divisible
   by the subsample factor -- done by picking a width of 102.
b) Pick a huffman table that doesn't happen to contain the bit
   pattern for a restart marker, so that reading a restart marker
   from the bitstream as data causes a failure (-quality 5 happens
   to do this)
c) Pick a restart interval where we fail to skip it if our calculation
   is off (-restart 3B)

Together with #22987, fixes #22780.
2024-01-30 14:50:43 +01:00
Aliaksandr Kalenik
fb2166f19c LibWeb: Account for CSS transform in Element::getClientRects() 2024-01-30 14:50:25 +01:00
Aliaksandr Kalenik
96d5f555e1 LibWeb: Simplify InlinePaintable::bounding_rect() implementation
No behavior change expected.
2024-01-30 14:50:25 +01:00