| 1 | /** |
| 2 | * SPDX-FileCopyrightText: (C) 2010 Pierre Marchand <[email protected]> |
| 3 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #include "boxsetter.h" |
| 7 | |
| 8 | using namespace std; |
| 9 | using namespace PoDoFo; |
| 10 | |
| 11 | BoxSetter::BoxSetter(const string_view& in, const string_view& out, const string_view& box, const Rect& rect) |
| 12 | : m_box(box), m_rect(rect) |
| 13 | { |
| 14 | PdfMemDocument source; |
| 15 | source.Load(in); |
| 16 | int pcount(source.GetPages().GetCount()); |
| 17 | for (int i = 0; i < pcount; ++i) |
| 18 | SetBox(source.GetPages().GetPageAt(i)); |
| 19 | |
| 20 | source.Save(out); |
| 21 | } |
| 22 | |
| 23 | void BoxSetter::SetBox(PdfPage& page) |
| 24 | { |
| 25 | PdfArray r; |
| 26 | m_rect.ToArray(r); |
| 27 | if (m_box.find("media") != string::npos) |
| 28 | page.GetObject().GetDictionary().AddKey("MediaBox", r); |
| 29 | else if (m_box.find("crop") != string::npos) |
| 30 | page.GetObject().GetDictionary().AddKey("CropBox", r); |
| 31 | else if (m_box.find("bleed") != string::npos) |
| 32 | page.GetObject().GetDictionary().AddKey("BleedBox", r); |
| 33 | else if (m_box.find("trim") != string::npos) |
| 34 | page.GetObject().GetDictionary().AddKey("TrimBox", r); |
| 35 | else if (m_box.find("art") != string::npos) |
| 36 | page.GetObject().GetDictionary().AddKey("ArtBox", r); |
| 37 | |
| 38 | // TODO check that box sizes are ordered |
| 39 | } |
| 40 | |
| 41 | bool BoxSetter::CompareBox(const Rect &rect1, const Rect &rect2) |
| 42 | { |
| 43 | return rect1.ToString() == rect2.ToString(); |
| 44 | } |