Skip to content

Commit 472bc36

Browse files
nicotrflynn89
authored andcommitted
LibPDF: Do not have redundant variables for image size
This way, the size of the bitmap cannot become out of sync with these variables. No behavior change.
1 parent c7c4987 commit 472bc36

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Userland/Libraries/LibPDF/Renderer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,24 +1205,24 @@ PDFErrorOr<Renderer::LoadedImage> Renderer::load_image(NonnullRefPtr<StreamObjec
12051205
return LoadedImage { bitmap, is_image_mask };
12061206
}
12071207

1208-
Gfx::AffineTransform Renderer::calculate_image_space_transformation(int width, int height)
1208+
Gfx::AffineTransform Renderer::calculate_image_space_transformation(Gfx::IntSize size)
12091209
{
12101210
// Image space maps to a 1x1 unit of user space and starts at the top-left
12111211
auto image_space = state().ctm;
12121212
image_space.multiply(Gfx::AffineTransform(
1213-
1.0f / width,
1213+
1.0f / size.width(),
12141214
0.0f,
12151215
0.0f,
1216-
-1.0f / height,
1216+
-1.0f / size.height(),
12171217
0.0f,
12181218
1.0f));
12191219
return image_space;
12201220
}
12211221

1222-
void Renderer::show_empty_image(int width, int height)
1222+
void Renderer::show_empty_image(Gfx::IntSize size)
12231223
{
1224-
auto image_space_transformation = calculate_image_space_transformation(width, height);
1225-
auto image_border = image_space_transformation.map(Gfx::IntRect { 0, 0, width, height });
1224+
auto image_space_transformation = calculate_image_space_transformation(size);
1225+
auto image_border = image_space_transformation.map(Gfx::IntRect { {}, size });
12261226
m_painter.stroke_path(rect_path(image_border), Color::Black, 1);
12271227
}
12281228

@@ -1247,15 +1247,15 @@ static ErrorOr<void> apply_alpha_channel(NonnullRefPtr<Gfx::Bitmap> image_bitmap
12471247
PDFErrorOr<void> Renderer::show_image(NonnullRefPtr<StreamObject> image)
12481248
{
12491249
auto image_dict = image->dict();
1250-
auto width = TRY(m_document->resolve_to<int>(image_dict->get_value(CommonNames::Width)));
1251-
auto height = TRY(m_document->resolve_to<int>(image_dict->get_value(CommonNames::Height)));
12521250

12531251
OwnPtr<ClipRAII> clip_raii;
12541252
if (m_rendering_preferences.clip_images)
12551253
clip_raii = make<ClipRAII>(*this);
12561254

12571255
if (!m_rendering_preferences.show_images) {
1258-
show_empty_image(width, height);
1256+
auto width = TRY(m_document->resolve_to<int>(image_dict->get_value(CommonNames::Width)));
1257+
auto height = TRY(m_document->resolve_to<int>(image_dict->get_value(CommonNames::Height)));
1258+
show_empty_image({ width, height });
12591259
return {};
12601260
}
12611261
auto image_bitmap = TRY(load_image(image));
@@ -1285,8 +1285,8 @@ PDFErrorOr<void> Renderer::show_image(NonnullRefPtr<StreamObject> image)
12851285
}
12861286
}
12871287

1288-
auto image_space = calculate_image_space_transformation(width, height);
1289-
auto image_rect = Gfx::FloatRect { 0, 0, width, height };
1288+
auto image_space = calculate_image_space_transformation(image_bitmap.bitmap->size());
1289+
auto image_rect = Gfx::FloatRect { image_bitmap.bitmap->rect() };
12901290
m_painter.draw_scaled_bitmap_with_transform(image_bitmap.bitmap->rect(), image_bitmap.bitmap, image_rect, image_space);
12911291
return {};
12921292
}

Userland/Libraries/LibPDF/Renderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class Renderer {
160160
PDFErrorOr<LoadedImage> load_image(NonnullRefPtr<StreamObject>);
161161

162162
PDFErrorOr<void> show_image(NonnullRefPtr<StreamObject>);
163-
void show_empty_image(int width, int height);
163+
void show_empty_image(Gfx::IntSize);
164164
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space_from_resources(Value const&, NonnullRefPtr<DictObject>);
165165
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space_from_document(NonnullRefPtr<Object>);
166166

@@ -180,7 +180,7 @@ class Renderer {
180180

181181
float line_width() const;
182182

183-
Gfx::AffineTransform calculate_image_space_transformation(int width, int height);
183+
Gfx::AffineTransform calculate_image_space_transformation(Gfx::IntSize);
184184

185185
PDFErrorOr<NonnullRefPtr<PDFFont>> get_font(FontCacheKey const&);
186186

0 commit comments

Comments
 (0)