diff options
author | Lei Zhang <thestig@chromium.org> | 2018-02-09 22:28:49 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-09 22:28:49 +0000 |
commit | 257900b6dae0fe8d82d48ecc91d92e5dbb3a28bf (patch) | |
tree | e3b53963f47cb34166baafb5eb17b07d1c66c9fe | |
parent | bc5dd9e7901ee56e0db66e76bf2e4903ab3d3fcd (diff) | |
download | pdfium-257900b6dae0fe8d82d48ecc91d92e5dbb3a28bf.tar.xz |
Use CPDF_Dictionary::SetRectFor() when appropriate.
Change-Id: I4ced221fb5691927485deceb7002dac880c2c210
Reviewed-on: https://pdfium-review.googlesource.com/26110
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_flatten.cpp | 18 | ||||
-rw-r--r-- | fpdfsdk/fpdf_ppo.cpp | 24 | ||||
-rw-r--r-- | fpdfsdk/fpdf_transformpage.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/fpdfeditpage.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/fpdfedittext.cpp | 37 |
5 files changed, 30 insertions, 70 deletions
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 4d06693006..299318bd08 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -269,21 +269,11 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { else rcOriginalCB = rcOriginalMB; - if (!rcOriginalMB.IsEmpty()) { - CPDF_Array* pMediaBox = pPageDict->SetNewFor<CPDF_Array>("MediaBox"); - pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.left); - pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.bottom); - pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.right); - pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.top); - } + if (!rcOriginalMB.IsEmpty()) + pPageDict->SetRectFor("MediaBox", rcOriginalMB); - if (!rcOriginalCB.IsEmpty()) { - CPDF_Array* pCropBox = pPageDict->SetNewFor<CPDF_Array>("ArtBox"); - pCropBox->AddNew<CPDF_Number>(rcOriginalCB.left); - pCropBox->AddNew<CPDF_Number>(rcOriginalCB.bottom); - pCropBox->AddNew<CPDF_Number>(rcOriginalCB.right); - pCropBox->AddNew<CPDF_Number>(rcOriginalCB.top); - } + if (!rcOriginalCB.IsEmpty()) + pPageDict->SetRectFor("ArtBox", rcOriginalCB); CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); if (!pRes) diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 5499ecc222..ac60a3af3a 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -490,11 +490,8 @@ bool CPDF_PageExporter::ExportPage(const std::vector<uint32_t>& pageNums, pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); } else { // Make the default size letter size (8.5"x11") - CPDF_Array* pArray = pCurPageDict->SetNewFor<CPDF_Array>("MediaBox"); - pArray->AddNew<CPDF_Number>(0); - pArray->AddNew<CPDF_Number>(0); - pArray->AddNew<CPDF_Number>(612); - pArray->AddNew<CPDF_Number>(792); + static const CFX_FloatRect kDefaultLetterRect(0, 0, 612, 792); + pCurPageDict->SetRectFor("MediaBox", kDefaultLetterRect); } } @@ -547,9 +544,6 @@ class CPDF_NPageToOneExporter : public CPDF_PageOrganizer { // Map XObject's object name to it's object number. using XObjectNameNumberMap = std::map<ByteString, uint32_t>; - static void SetMediaBox(CPDF_Dictionary* pDestPageDict, - const CFX_SizeF& pagesize); - // Creates a xobject from the source page dictionary, and appends the // bsContent string with the xobject reference surrounded by the // transformation matrix. @@ -602,6 +596,8 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( NupState nupState(destPageSize, numPagesOnXAxis, numPagesOnYAxis); size_t curpage = 0; + const CFX_FloatRect destPageRect(0, 0, destPageSize.width, + destPageSize.height); for (size_t outerPage = 0; outerPage < pageNums.size(); outerPage += numPagesPerSheet) { // Create a new page @@ -609,7 +605,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( if (!pCurPageDict) return false; - SetMediaBox(pCurPageDict, destPageSize); + pCurPageDict->SetRectFor("MediaBox", destPageRect); ByteString bsContent; size_t innerPageMax = std::min(outerPage + numPagesPerSheet, pageNums.size()); @@ -635,16 +631,6 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( return true; } -// static -void CPDF_NPageToOneExporter::SetMediaBox(CPDF_Dictionary* pDestPageDict, - const CFX_SizeF& pagesize) { - CPDF_Array* pArray = pDestPageDict->SetNewFor<CPDF_Array>("MediaBox"); - pArray->AddNew<CPDF_Number>(0); - pArray->AddNew<CPDF_Number>(0); - pArray->AddNew<CPDF_Number>(pagesize.width); - pArray->AddNew<CPDF_Number>(pagesize.height); -} - void CPDF_NPageToOneExporter::AddSubPage( CPDF_Dictionary* pPageDict, const NupPageSettings& settings, diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 565d90be4c..5a7e094b07 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -26,15 +26,8 @@ namespace { void SetBoundingBox(CPDF_Page* page, const ByteString& key, - float left, - float bottom, - float right, - float top) { - CPDF_Array* pBoundingBoxArray = page->m_pFormDict->SetNewFor<CPDF_Array>(key); - pBoundingBoxArray->AddNew<CPDF_Number>(left); - pBoundingBoxArray->AddNew<CPDF_Number>(bottom); - pBoundingBoxArray->AddNew<CPDF_Number>(right); - pBoundingBoxArray->AddNew<CPDF_Number>(top); + const CFX_FloatRect& rect) { + page->m_pFormDict->SetRectFor(key, rect); } bool GetBoundingBox(CPDF_Page* page, @@ -69,7 +62,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, if (!pPage) return; - SetBoundingBox(pPage, "MediaBox", left, bottom, right, top); + SetBoundingBox(pPage, "MediaBox", CFX_FloatRect(left, bottom, right, top)); } FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, @@ -81,7 +74,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, if (!pPage) return; - SetBoundingBox(pPage, "CropBox", left, bottom, right, top); + SetBoundingBox(pPage, "CropBox", CFX_FloatRect(left, bottom, right, top)); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index a032bf6607..ca2cf3fb6e 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -142,11 +142,7 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, if (!pPageDict) return nullptr; - CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox"); - pMediaBoxArray->AddNew<CPDF_Number>(0); - pMediaBoxArray->AddNew<CPDF_Number>(0); - pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(width)); - pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(height)); + pPageDict->SetRectFor("MediaBox", CFX_FloatRect(0, 0, width, height)); pPageDict->SetNewFor<CPDF_Number>("Rotate", 0); pPageDict->SetNewFor<CPDF_Dictionary>("Resources"); diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp index 7bbb6a857c..460e852eaa 100644 --- a/fpdfsdk/fpdfedittext.cpp +++ b/fpdfsdk/fpdfedittext.cpp @@ -35,9 +35,9 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc, const uint8_t* data, uint32_t size, int font_type) { - CPDF_Dictionary* fontDesc = pDoc->NewIndirect<CPDF_Dictionary>(); - fontDesc->SetNewFor<CPDF_Name>("Type", "FontDescriptor"); - fontDesc->SetNewFor<CPDF_Name>("FontName", font_name); + CPDF_Dictionary* pFontDesc = pDoc->NewIndirect<CPDF_Dictionary>(); + pFontDesc->SetNewFor<CPDF_Name>("Type", "FontDescriptor"); + pFontDesc->SetNewFor<CPDF_Name>("FontName", font_name); int flags = 0; if (FXFT_Is_Face_fixedwidth(pFont->GetFace())) flags |= FXFONT_FIXED_PITCH; @@ -51,25 +51,20 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc, // TODO(npm): How do I know if a font is symbolic, script, allcap, smallcap flags |= FXFONT_NONSYMBOLIC; - fontDesc->SetNewFor<CPDF_Number>("Flags", flags); + pFontDesc->SetNewFor<CPDF_Number>("Flags", flags); FX_RECT bbox; pFont->GetBBox(bbox); - auto pBBox = pdfium::MakeUnique<CPDF_Array>(); - pBBox->AddNew<CPDF_Number>(bbox.left); - pBBox->AddNew<CPDF_Number>(bbox.top); - pBBox->AddNew<CPDF_Number>(bbox.right); - pBBox->AddNew<CPDF_Number>(bbox.bottom); - fontDesc->SetFor("FontBBox", std::move(pBBox)); + pFontDesc->SetRectFor("FontBBox", CFX_FloatRect(bbox)); // TODO(npm): calculate italic angle correctly - fontDesc->SetNewFor<CPDF_Number>("ItalicAngle", pFont->IsItalic() ? -12 : 0); + pFontDesc->SetNewFor<CPDF_Number>("ItalicAngle", pFont->IsItalic() ? -12 : 0); - fontDesc->SetNewFor<CPDF_Number>("Ascent", pFont->GetAscent()); - fontDesc->SetNewFor<CPDF_Number>("Descent", pFont->GetDescent()); + pFontDesc->SetNewFor<CPDF_Number>("Ascent", pFont->GetAscent()); + pFontDesc->SetNewFor<CPDF_Number>("Descent", pFont->GetDescent()); // TODO(npm): calculate the capheight, stemV correctly - fontDesc->SetNewFor<CPDF_Number>("CapHeight", pFont->GetAscent()); - fontDesc->SetNewFor<CPDF_Number>("StemV", pFont->IsBold() ? 120 : 70); + pFontDesc->SetNewFor<CPDF_Number>("CapHeight", pFont->GetAscent()); + pFontDesc->SetNewFor<CPDF_Number>("StemV", pFont->IsBold() ? 120 : 70); CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(); pStream->SetData(data, size); @@ -79,8 +74,8 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc, static_cast<int>(size)); } ByteString fontFile = font_type == FPDF_FONT_TYPE1 ? "FontFile" : "FontFile2"; - fontDesc->SetNewFor<CPDF_Reference>(fontFile, pDoc, pStream->GetObjNum()); - return fontDesc; + pFontDesc->SetNewFor<CPDF_Reference>(fontFile, pDoc, pStream->GetObjNum()); + return pFontDesc; } const char ToUnicodeStart[] = @@ -276,11 +271,11 @@ void* LoadSimpleFont(CPDF_Document* pDoc, } fontDict->SetNewFor<CPDF_Number>("LastChar", static_cast<int>(currentChar)); fontDict->SetNewFor<CPDF_Reference>("Widths", pDoc, widthsArray->GetObjNum()); - CPDF_Dictionary* fontDesc = + CPDF_Dictionary* pFontDesc = LoadFontDesc(pDoc, name, pFont.get(), data, size, font_type); fontDict->SetNewFor<CPDF_Reference>("FontDescriptor", pDoc, - fontDesc->GetObjNum()); + pFontDesc->GetObjNum()); return pDoc->LoadFont(fontDict); } @@ -319,10 +314,10 @@ void* LoadCompositeFont(CPDF_Document* pDoc, pCIDFont->SetNewFor<CPDF_Reference>("CIDSystemInfo", pDoc, pCIDSystemInfo->GetObjNum()); - CPDF_Dictionary* fontDesc = + CPDF_Dictionary* pFontDesc = LoadFontDesc(pDoc, name, pFont.get(), data, size, font_type); pCIDFont->SetNewFor<CPDF_Reference>("FontDescriptor", pDoc, - fontDesc->GetObjNum()); + pFontDesc->GetObjNum()); uint32_t glyphIndex; uint32_t currentChar = FXFT_Get_First_Char(pFont->GetFace(), &glyphIndex); |