1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 02:05:07 +00:00
Commit graph

349 commits

Author SHA1 Message Date
Sam Atkins
21b65de1ec LibGfx+LibWeb: Move "transparent" keyword into Color::from_string()
It seemed odd to have this one color handled separately, when
`Color::from_string()` implements all other CSS colors.
2021-10-23 18:53:17 +02:00
Ben Wiederhake
1bc4a0d822 LibGfx: Restrict cleared area to GIF framebuffer
Found by OSS Fuzz, long-standing issue
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34824

The discovered testcase attempts to clear the framebuffer of size
1056x32 from the previous image, which has size 16416x32.
2021-10-22 20:37:27 +01:00
Ben Wiederhake
ee18912373 LibGfx: Implement copy-assign for Matrix
This used to generate a warning about using a deprecated copy-assign,
default-generated by the compiler, and deprecated because we hand-
implement the copy-constructor. This warning is correct, since the
default-generated copy-assign may or may not be as efficient as memcpy.

This patch gets rid of the warning, and has either no performance impact
or a slightly positive one. If this turns out to be wrong, we should
probably also fix the copy-constructor.
2021-10-10 21:03:27 +01:00
Nico Weber
b8dc3661ac Libraries: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Ben Wiederhake
9d2e06b039 LibGUI: Add missing headers 2021-10-06 23:52:40 +01:00
Tim Schumacher
7af7fc8c16 Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
Gal Horowitz
aa180c821d LibGFX: Draw the ends of lines with non-standard thickness
Lines are drawn using squares the size of the thickness, so if the
length of the line was not a multiple of the thickness, the end of the
line was not drawn correctly.
2021-10-02 20:54:47 +02:00
Nico Weber
de72332920 Libraries: Fix typos 2021-10-01 01:06:40 +01:00
Andreas Kling
73fe6c541a LibGfx: Forward declare Gfx::FontMetrics as a struct 2021-09-24 19:03:46 +02:00
Andreas Kling
30979c1956 LibGfx: Remove debug spam about not having some font installed 2021-09-24 15:01:49 +02:00
Andreas Kling
d7586aff53 LibGfx: Add a simple Gfx::FontMetrics and Gfx::Font::metrics(code_point)
This is used to get a handy set of glyph metrics.
2021-09-24 15:01:49 +02:00
thankyouverycool
84ce923850 LibGfx: Make BitmapFont::variant() report a complete typeface 2021-09-24 14:59:39 +02:00
thankyouverycool
39484fc02c LibGfx: Get weight from tables for TrueTypeFonts
First, try to find detailed weight metrics in the OS/2 table;
barring that, fall back to the font header table.
2021-09-24 14:59:39 +02:00
thankyouverycool
fff89ad769 LibGfx: Support italic BitmapFonts
BitmapFont header now contains a slope byte. Slope is used to
indicate slant style and is mapped in LibGfx/FontStyleMapping.h
2021-09-24 14:59:39 +02:00
Sam Atkins
0b7eefd4e5 LibGfx: Add rounded_int_rect() function for Rects
We were seeing a problem in LibWeb, where layout elements would be 1px
larger than they should be, due to layout positions using float values,
and then converting using `enclosing_int_rect()`. `rounded_int_rect()`
replaces that use, by maintaining the original rect's size.
2021-09-21 16:53:46 +02:00
Sam Atkins
1c807410cd LibGfx: Add optional bilinear filtering to draw_scaled_bitmap()
The algorithm is quite simple: You grab a 2x2 area of pixels around the
point you want from the source bitmap, and then linearly interpolate
between them based on how far they are from that point.

This works well when scaling up images, and moderately well when scaling
down - small details may get skipped over. The way GPUs solve this is
with mipmaps, which is not something I want to get into right now. (And
increases the memory usage per bitmap by 50%.)

I have not focused on performance, but this does reuse much of the
existing fixed-point calculation, and uses constexpr so that the
performance for nearest-neighbor should be the same as it was
previously.
2021-09-20 22:18:20 +02:00
Sam Atkins
eb07668589 LibGfx: Add per-side overloads of Rect::inflate() and ::shrink()
These are in CSS order (top, right, bottom, left) since LibWeb is the
reason I'm adding these. :^)
2021-09-19 22:53:35 +02:00
thankyouverycool
ae59d8a728 LibGfx: Paint replacement character, 0xFFFD, for unknown glyphs
Note: most systems now use a font's .notdef character for unknown
glyphs (commonly the tofu box) and reserve 0xFFFD for encoding
errors. Until Serenity supports tofu, 0xFFFD is a preferable, if
deprecated, alternative to '?' to reduce ambiguity.
2021-09-19 00:58:59 +02:00
thankyouverycool
bb592aef8a LibGfx: Extend Unicode support for BitmapFonts
Removes the concept of Type enumeration in favor of a bitmask which
represents 544 potential byte ranges of 256 characters per bit,
supporting the current unicode code point set (0x0000-0x10FFFF).
Range positions are indexed in a vector for code point lookup and
conversion.

Co-authored-by: Lynn <lynn@foldr.moe>
2021-09-19 00:58:59 +02:00
Andreas Kling
f6a2d6af0b LibGfx: Add Point<T>::to_rounded<U>() 2021-09-18 12:21:42 +02:00
Ali Mohammad Pur
433725fef2 LibGfx: Implement cubic bezier curves by splitting them to subcurves
This makes them significantly more nicer-looking, and fixes a FIXME :^)
2021-09-18 02:12:38 +04:30
Ali Mohammad Pur
02d949cfb6 LibGfx: Switch Painter.{h,cpp} to use east-const 2021-09-18 02:12:38 +04:30
Ali Mohammad Pur
5a2e7d30ce LibWeb: Use Gfx::AntiAliasingPainter to draw SVG paths
This is still quite bad, but it's much more pleasing to look at when
drawing random SVGs :^)
2021-09-18 02:12:38 +04:30
Ali Mohammad Pur
e2cd558101 LibGfx: Start a very basic anti-aliased Painter implementation
This can currently draw AA lines (and by proxy, AA paths), and passes
all its output through a 2D affine transform to an underlying
Gfx::Painter.
2021-09-18 02:12:38 +04:30
Andreas Kling
c8c3828b59 LibGfx: Avoid invalidation when Path::close() is a no-op
If the path is already closed, calling close() is a no-op, and we don't
need to invalidate the split lines cache.
2021-09-17 13:41:34 +02:00
Andreas Kling
32b9d80ee5 LibGfx: Make Painter::fill_path() take Path by const reference
Taking a mutable reference here made the API look very strange.
2021-09-17 13:41:03 +02:00
Andreas Kling
8c863ad959 LibGfx: Make Path::bounding_box() and Path::split_lines() const
Use a const_cast internally when segmentizing. As far as clients are
concerned, these are const operations.
2021-09-17 13:40:34 +02:00
Andreas Kling
5726017414 LibGfx: Move FastBoxBlurFilter to its own .cpp file 2021-09-17 13:20:18 +02:00
Andreas Kling
f9a38fa693 LibGfx: Don't use unbounded VLA's in FastBoxBlurFilter
These would cause the stack to overflow when LibWeb tried rendering a
CSS box-shadow for a large enough element.

Use Vector (with *some* inline capacity for smaller images) to avoid
this issue. If these heap allocations turn out to be too much work,
we can add something like a persistent scratch buffer cache.
2021-09-17 13:20:18 +02:00
Andreas Kling
850795e088 LibGfx: Make some coding style fixes to FastBoxBlurFilter 2021-09-17 13:20:18 +02:00
Mustafa Quraish
f14c891ba5 LibGfx+PixelPaint: Add Point::end_point_for_aspect_ratio method
Previously we only had `Point::end_point_for_square_aspect_ratio`,
which was convenient for PixelPaint but assumed the aspect ratio
was always fixed at 1. This patch replaces it with a new mthod that
takes in an arbitrary aspect ratio and computes the end point based
off that.

There's some explicit casting going on in `Point.cpp` to ensure that
the types line up, since we're templating Point based on `T`.`
2021-09-17 11:54:13 +02:00
Sam Atkins
6c992e5dce LibGfx: Don't try to paint 0px-wide lines
In some cases, we were infinite-looping when asked to paint something
with a thickness of '0', so now every Painter method that takes a
thickness, does a check for a thickness <= 0 and bails early. After all,
you can't draw something that's 0px wide. :^)
2021-09-16 22:30:33 +02:00
Brian Gianforcaro
fda48d7a6b LibGfx: Use move to avoid unnecessary ref/unref of network device RefPtr
Flagged by pvs-studio as a potential perf optimization.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
f327f54399 LibGfx: Use default instead of an empty constructor/destructor
Default implementations allow for more optimizations.
See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-16 17:17:13 +02:00
Karol Kosek
d1e1096bc0 LibGfx: Enumerate metric theme roles
This change does practically nothing except that you no longer have to
put new roles there, as they are now automatically read from the enum
list.
2021-09-16 16:52:55 +02:00
Karol Kosek
6f4333fca7 LibGfx: Add support for enumerating by Metric and Path roles
For Theme Editor.
2021-09-16 16:52:55 +02:00
Andreas Kling
09d13e437b LibGfx: Add Path::cubic_bezier_curve_to()
This is pretty unsophisticated as it will simply add a fixed number of
of line segments approximating the curve. Still better than nothing.
2021-09-15 20:57:43 +02:00
Andreas Kling
139fdcc2cf LibGfx: Add some interpolation helpers for Gfx::Point<T>
- linear_interpolate
- quadratic_interpolate
- cubic_interpolate
2021-09-15 20:57:43 +02:00
Zyper
12e76bb3df LibGfx: Add method for calculating square aspect ratio end point 2021-09-15 00:10:14 +00:00
Mustafa Quraish
0f749681a9 Everywhere: Use my fancy new serenityos.org email :^) 2021-09-13 20:51:50 +00:00
Andreas Kling
daead75e9c LibGfx/TTF: Ignore unsupported composite glyph flags
Replace some program-stopping TODO()'s with FIXME comments, since many
fonts actually render mostly fine without support for all features.
2021-09-13 20:12:58 +02:00
Karol Kosek
f878e4464f LibGfx: Add SystemTheme::load_system_theme(Core::ConfigFile const&)
This makes loading system themes possible via FileSystemAccessClient
(needed for the Theme Editor). :^)
2021-09-12 11:49:52 +02:00
David Isaksson
242acfcbae LibGfx: Apply translation and scale to Painter::draw_triangle() 2021-09-11 19:16:29 +02:00
Tobias Christiansen
de0791b0a1 LibGfx: Increase bit-width of variables used in do_draw_scaled_bitmap
To avoid expensive floating point operations the values are put in the
upper half of an integer which is then used for calculations.
When the src_rect is sufficiently large (when, say, PixelPaint is zoomed
in x100), the precision provided by this strategy with regular
32-bit-long ints  is no longer enough.
This patch changes the used types to i64, which are 64 bits wide and the
shifting is increased to 32 bits.
On the 32-bit-arch a i64 doesn't fit in a single register anymore but
it's probably okay to trust the compiler to do clever stuff around this
issue.
2021-09-11 00:09:33 +02:00
Mustafa Quraish
522f0841fd LibGfx/Point: Add hash trait for Point<T> 2021-09-09 11:27:48 +02:00
Timothy
b953588e0e LibGfx: Add method to load bitmap from fd 2021-09-09 02:34:29 +02:00
Timothy
c966c32571 LibGfx: Move common loader functionality to load from memory functions
This will share functionality between the load from path and load from
memory functions.
2021-09-09 02:34:29 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
Brian Gianforcaro
3e45c3ed90 Userland: Switch static_assert of type sizes to AK::AssertSize 2021-09-05 20:08:57 +02:00