mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 14:55:07 +00:00
LibWeb: Support more CSS image-rendering values
This patch adds support for "crisp-edges", "high-quality" and "smooth" for the CSS image-rendering property. "crisp-edges" maps to nearest-neighbor scaling for <canvas> and <img> elements, while "high-quality" and "smooth" both use bilinear blending.
This commit is contained in:
parent
fe52ee2f8e
commit
6d1a9672a4
7 changed files with 42 additions and 9 deletions
|
@ -86,6 +86,7 @@
|
||||||
"context-menu",
|
"context-menu",
|
||||||
"copy",
|
"copy",
|
||||||
"cover",
|
"cover",
|
||||||
|
"crisp-edges",
|
||||||
"crosshair",
|
"crosshair",
|
||||||
"currentcolor",
|
"currentcolor",
|
||||||
"cursive",
|
"cursive",
|
||||||
|
@ -114,6 +115,7 @@
|
||||||
"groove",
|
"groove",
|
||||||
"help",
|
"help",
|
||||||
"hidden",
|
"hidden",
|
||||||
|
"high-quality",
|
||||||
"inline",
|
"inline",
|
||||||
"inline-block",
|
"inline-block",
|
||||||
"inline-flex",
|
"inline-flex",
|
||||||
|
@ -187,6 +189,7 @@
|
||||||
"small",
|
"small",
|
||||||
"small-caps",
|
"small-caps",
|
||||||
"smaller",
|
"smaller",
|
||||||
|
"smooth",
|
||||||
"solid",
|
"solid",
|
||||||
"space",
|
"space",
|
||||||
"space-around",
|
"space-around",
|
||||||
|
|
|
@ -765,7 +765,10 @@
|
||||||
"initial": "auto",
|
"initial": "auto",
|
||||||
"valid-identifiers": [
|
"valid-identifiers": [
|
||||||
"auto",
|
"auto",
|
||||||
"pixelated"
|
"crisp-edges",
|
||||||
|
"high-quality",
|
||||||
|
"pixelated",
|
||||||
|
"smooth"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"justify-content": {
|
"justify-content": {
|
||||||
|
|
|
@ -363,8 +363,14 @@ static CSS::ValueID to_css_value_id(CSS::ImageRendering value)
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case ImageRendering::Auto:
|
case ImageRendering::Auto:
|
||||||
return CSS::ValueID::Auto;
|
return CSS::ValueID::Auto;
|
||||||
|
case ImageRendering::CrispEdges:
|
||||||
|
return CSS::ValueID::CrispEdges;
|
||||||
|
case ImageRendering::HighQuality:
|
||||||
|
return CSS::ValueID::HighQuality;
|
||||||
case ImageRendering::Pixelated:
|
case ImageRendering::Pixelated:
|
||||||
return CSS::ValueID::Pixelated;
|
return CSS::ValueID::Pixelated;
|
||||||
|
case ImageRendering::Smooth:
|
||||||
|
return CSS::ValueID::Smooth;
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,8 +277,14 @@ Optional<CSS::ImageRendering> StyleProperties::image_rendering() const
|
||||||
switch (value.value()->to_identifier()) {
|
switch (value.value()->to_identifier()) {
|
||||||
case CSS::ValueID::Auto:
|
case CSS::ValueID::Auto:
|
||||||
return CSS::ImageRendering::Auto;
|
return CSS::ImageRendering::Auto;
|
||||||
|
case CSS::ValueID::CrispEdges:
|
||||||
|
return CSS::ImageRendering::CrispEdges;
|
||||||
|
case CSS::ValueID::HighQuality:
|
||||||
|
return CSS::ImageRendering::HighQuality;
|
||||||
case CSS::ValueID::Pixelated:
|
case CSS::ValueID::Pixelated:
|
||||||
return CSS::ImageRendering::Pixelated;
|
return CSS::ImageRendering::Pixelated;
|
||||||
|
case CSS::ValueID::Smooth:
|
||||||
|
return CSS::ImageRendering::Smooth;
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibWeb/CSS/Angle.h>
|
#include <LibWeb/CSS/Angle.h>
|
||||||
#include <LibWeb/CSS/Display.h>
|
#include <LibWeb/CSS/Display.h>
|
||||||
#include <LibWeb/CSS/Frequency.h>
|
#include <LibWeb/CSS/Frequency.h>
|
||||||
|
@ -146,9 +147,27 @@ enum class Float {
|
||||||
|
|
||||||
enum class ImageRendering {
|
enum class ImageRendering {
|
||||||
Auto,
|
Auto,
|
||||||
Pixelated
|
CrispEdges,
|
||||||
|
HighQuality,
|
||||||
|
Pixelated,
|
||||||
|
Smooth,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: Find a better place for this helper.
|
||||||
|
inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value)
|
||||||
|
{
|
||||||
|
switch (css_value) {
|
||||||
|
case CSS::ImageRendering::Auto:
|
||||||
|
case CSS::ImageRendering::HighQuality:
|
||||||
|
case CSS::ImageRendering::Smooth:
|
||||||
|
return Gfx::Painter::ScalingMode::BilinearBlend;
|
||||||
|
case CSS::ImageRendering::CrispEdges:
|
||||||
|
case CSS::ImageRendering::Pixelated:
|
||||||
|
return Gfx::Painter::ScalingMode::NearestNeighbor;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
enum class JustifyContent {
|
enum class JustifyContent {
|
||||||
FlexStart,
|
FlexStart,
|
||||||
FlexEnd,
|
FlexEnd,
|
||||||
|
|
|
@ -36,10 +36,8 @@ void CanvasBox::paint(PaintContext& context, PaintPhase phase)
|
||||||
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
|
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (dom_node().bitmap()) {
|
if (dom_node().bitmap())
|
||||||
auto scaling_mode = computed_values().image_rendering() == CSS::ImageRendering::Pixelated ? Gfx::Painter::ScalingMode::NearestNeighbor : Gfx::Painter::ScalingMode::BilinearBlend;
|
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||||
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect(), 1.0f, scaling_mode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase)
|
||||||
alt = image_element.src();
|
alt = image_element.src();
|
||||||
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right);
|
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right);
|
||||||
} else if (auto bitmap = m_image_loader.bitmap(m_image_loader.current_frame_index())) {
|
} else if (auto bitmap = m_image_loader.bitmap(m_image_loader.current_frame_index())) {
|
||||||
// FIXME: Support 'crisp-edges', 'smooth' and 'high-quality'
|
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *bitmap, bitmap->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
|
||||||
auto scaling_mode = computed_values().image_rendering() == CSS::ImageRendering::Pixelated ? Gfx::Painter::ScalingMode::NearestNeighbor : Gfx::Painter::ScalingMode::BilinearBlend;
|
|
||||||
context.painter().draw_scaled_bitmap(rounded_int_rect(absolute_rect()), *bitmap, bitmap->rect(), 1.0f, scaling_mode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue