mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibPDF: Parse page crop box and user units
This commit is contained in:
parent
43724ac282
commit
d6a9b41bac
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 raw_page_object = resolve_to<DictObject>(get_or_load_value(page_object_index));
|
||||||
|
|
||||||
auto resources = raw_page_object->get_dict(this, "Resources");
|
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_array = raw_page_object->get_array(this, "MediaBox");
|
||||||
auto media_box = Rectangle {
|
auto media_box = Rectangle {
|
||||||
media_box_array->at(0).to_float(),
|
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(2).to_float(),
|
||||||
media_box_array->at(3).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);
|
m_pages.set(index, page);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,10 @@ struct Rectangle {
|
||||||
|
|
||||||
struct Page {
|
struct Page {
|
||||||
NonnullRefPtr<DictObject> resources;
|
NonnullRefPtr<DictObject> resources;
|
||||||
Rectangle media_box;
|
|
||||||
NonnullRefPtr<Object> contents;
|
NonnullRefPtr<Object> contents;
|
||||||
|
Rectangle media_box;
|
||||||
|
Rectangle crop_box;
|
||||||
|
float user_unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Document final : public RefCounted<Document> {
|
class Document final : public RefCounted<Document> {
|
||||||
|
@ -105,8 +107,13 @@ template<>
|
||||||
struct Formatter<PDF::Page> : Formatter<StringView> {
|
struct Formatter<PDF::Page> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const PDF::Page& page)
|
void format(FormatBuilder& builder, const PDF::Page& page)
|
||||||
{
|
{
|
||||||
constexpr auto fmt_string = "Page {{\n resources={}\n contents={}\n media_box={}\n}}";
|
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);
|
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);
|
Formatter<StringView>::format(builder, str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue