mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 01:40:36 +00:00
LibPDF: Add parameter for background color of render
This commit is contained in:
parent
60c4803dd3
commit
8191f2b47a
Notes:
sideshowbarker
2024-07-17 22:01:16 +09:00
Author: https://github.com/X-yl Commit: https://github.com/SerenityOS/serenity/commit/8191f2b47a Pull-request: https://github.com/SerenityOS/serenity/pull/22197 Reviewed-by: https://github.com/nico ✅
5 changed files with 10 additions and 10 deletions
|
@ -29,7 +29,7 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& documen
|
|||
|
||||
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
|
||||
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, PDF::RenderingPreferences {});
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {});
|
||||
if (errors.is_error()) {
|
||||
for (auto const& error : errors.error().errors())
|
||||
NSLog(@"warning: %@", @(error.message().characters()));
|
||||
|
|
|
@ -319,7 +319,7 @@ PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> PDFViewer::render_page(u32 page_inde
|
|||
auto& page_size = m_page_dimension_cache.render_info[page_index].size;
|
||||
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, page_size.to_type<int>()));
|
||||
|
||||
auto maybe_errors = PDF::Renderer::render(*m_document, page, bitmap, m_rendering_preferences);
|
||||
auto maybe_errors = PDF::Renderer::render(*m_document, page, bitmap, Color::White, m_rendering_preferences);
|
||||
if (maybe_errors.is_error()) {
|
||||
auto errors = maybe_errors.release_error();
|
||||
on_render_errors(page_index, errors);
|
||||
|
|
|
@ -45,9 +45,9 @@ private:
|
|||
size_t m_starting_stack_depth;
|
||||
};
|
||||
|
||||
PDFErrorsOr<void> Renderer::render(Document& document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, RenderingPreferences rendering_preferences)
|
||||
PDFErrorsOr<void> Renderer::render(Document& document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, Color background_color, RenderingPreferences rendering_preferences)
|
||||
{
|
||||
return Renderer(document, page, bitmap, rendering_preferences).render();
|
||||
return Renderer(document, page, bitmap, background_color, rendering_preferences).render();
|
||||
}
|
||||
|
||||
static void rect_path(Gfx::Path& path, float x, float y, float width, float height)
|
||||
|
@ -73,7 +73,7 @@ static Gfx::Path rect_path(Gfx::Rect<T> const& rect)
|
|||
return path;
|
||||
}
|
||||
|
||||
Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, RenderingPreferences rendering_preferences)
|
||||
Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, Color background_color, RenderingPreferences rendering_preferences)
|
||||
: m_document(document)
|
||||
, m_bitmap(bitmap)
|
||||
, m_page(page)
|
||||
|
@ -104,7 +104,7 @@ Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitm
|
|||
auto initial_clipping_path = rect_path(userspace_matrix.map(Gfx::FloatRect(0, 0, width, height)));
|
||||
m_graphics_state_stack.append(GraphicsState { userspace_matrix, { initial_clipping_path, initial_clipping_path } });
|
||||
|
||||
m_bitmap->fill(Gfx::Color::NamedColor::White);
|
||||
m_bitmap->fill(background_color);
|
||||
}
|
||||
|
||||
PDFErrorsOr<void> Renderer::render()
|
||||
|
|
|
@ -98,7 +98,7 @@ struct RenderingPreferences {
|
|||
|
||||
class Renderer {
|
||||
public:
|
||||
static PDFErrorsOr<void> render(Document&, Page const&, RefPtr<Gfx::Bitmap>, RenderingPreferences preferences);
|
||||
static PDFErrorsOr<void> render(Document&, Page const&, RefPtr<Gfx::Bitmap>, Color background_color, RenderingPreferences preferences);
|
||||
|
||||
struct FontCacheKey {
|
||||
NonnullRefPtr<DictObject> font_dictionary;
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
PDFErrorOr<void> render_type3_glyph(Gfx::FloatPoint, StreamObject const&, Gfx::AffineTransform const&, Optional<NonnullRefPtr<DictObject>>);
|
||||
|
||||
private:
|
||||
Renderer(RefPtr<Document>, Page const&, RefPtr<Gfx::Bitmap>, RenderingPreferences);
|
||||
Renderer(RefPtr<Document>, Page const&, RefPtr<Gfx::Bitmap>, Color background_color, RenderingPreferences);
|
||||
|
||||
PDFErrorsOr<void> render();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render_page(PDF::Document& do
|
|||
|
||||
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
|
||||
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, PDF::RenderingPreferences {});
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {});
|
||||
if (errors.is_error()) {
|
||||
for (auto const& error : errors.error().errors())
|
||||
warnln("warning: {}", error.message());
|
||||
|
@ -128,7 +128,7 @@ static PDF::PDFErrorOr<void> print_debugging_stats(PDF::Document& document, bool
|
|||
auto page = TRY(document.get_page(page_number - 1));
|
||||
auto page_size = Gfx::IntSize { 200, round_to<int>(200 * page.media_box.height() / page.media_box.width()) };
|
||||
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, PDF::RenderingPreferences {});
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {});
|
||||
if (errors.is_error()) {
|
||||
for (auto const& error : errors.error().errors())
|
||||
diags_to_pages.ensure(error.message()).append(page_number);
|
||||
|
|
Loading…
Reference in a new issue