mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibPDF: Parse page crop box and user units
This commit is contained in:
parent
43724ac282
commit
d6a9b41bac
Notes:
sideshowbarker
2024-07-18 17:51:17 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/d6a9b41bacc Pull-request: https://github.com/SerenityOS/serenity/pull/7018 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/bcoles Reviewed-by: https://github.com/tomuta
2 changed files with 28 additions and 5 deletions
|
@ -63,6 +63,8 @@ Page Document::get_page(u32 index)
|
|||
auto raw_page_object = resolve_to<DictObject>(get_or_load_value(page_object_index));
|
||||
|
||||
auto resources = raw_page_object->get_dict(this, "Resources");
|
||||
auto contents = raw_page_object->get_object(this, "Contents");
|
||||
|
||||
auto media_box_array = raw_page_object->get_array(this, "MediaBox");
|
||||
auto media_box = Rectangle {
|
||||
media_box_array->at(0).to_float(),
|
||||
|
@ -70,9 +72,23 @@ Page Document::get_page(u32 index)
|
|||
media_box_array->at(2).to_float(),
|
||||
media_box_array->at(3).to_float(),
|
||||
};
|
||||
auto contents = raw_page_object->get_object(this, "Contents");
|
||||
|
||||
Page page { resources, media_box, contents };
|
||||
auto crop_box = media_box;
|
||||
if (raw_page_object->contains("CropBox")) {
|
||||
auto crop_box_array = raw_page_object->get_array(this, "CropBox");
|
||||
crop_box = Rectangle {
|
||||
crop_box_array->at(0).to_float(),
|
||||
crop_box_array->at(1).to_float(),
|
||||
crop_box_array->at(2).to_float(),
|
||||
crop_box_array->at(3).to_float(),
|
||||
};
|
||||
}
|
||||
|
||||
float user_unit = 1.0f;
|
||||
if (raw_page_object->contains("UserUnit"))
|
||||
user_unit = raw_page_object->get_value("UserUnit").to_float();
|
||||
|
||||
Page page { move(resources), move(contents), media_box, crop_box, user_unit };
|
||||
m_pages.set(index, page);
|
||||
return page;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,10 @@ struct Rectangle {
|
|||
|
||||
struct Page {
|
||||
NonnullRefPtr<DictObject> resources;
|
||||
Rectangle media_box;
|
||||
NonnullRefPtr<Object> contents;
|
||||
Rectangle media_box;
|
||||
Rectangle crop_box;
|
||||
float user_unit;
|
||||
};
|
||||
|
||||
class Document final : public RefCounted<Document> {
|
||||
|
@ -105,8 +107,13 @@ template<>
|
|||
struct Formatter<PDF::Page> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, const PDF::Page& page)
|
||||
{
|
||||
constexpr auto fmt_string = "Page {{\n resources={}\n contents={}\n media_box={}\n}}";
|
||||
auto str = String::formatted(fmt_string, page.resources->to_string(1), page.contents->to_string(1), page.media_box);
|
||||
constexpr auto fmt_string = "Page {{\n resources={}\n contents={}\n media_box={}\n crop_box={}\n user_unit={}\n}}";
|
||||
auto str = String::formatted(fmt_string,
|
||||
page.resources->to_string(1),
|
||||
page.contents->to_string(1),
|
||||
page.media_box,
|
||||
page.crop_box,
|
||||
page.user_unit);
|
||||
Formatter<StringView>::format(builder, str);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue