From 367ed462b51799c008795b19e886ccbed221b9be Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 23 Aug 2018 23:52:53 +0000 Subject: Use pdfium::span<> in CPDF_Stream::SetData(). Conversion to span makes this more elegant in a number of places, owing to std::vector directly converting to span, and the bytestring's ToRawSpan(). Disambiguate single-argument forms to allow passing {} as an argument. Change-Id: Ibd5eaadca8d8cbbd589338f375c7ee8439fd3eb2 Reviewed-on: https://pdfium-review.googlesource.com/41272 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/formfiller/cba_fontmap.cpp | 2 +- fpdfsdk/fpdf_annot.cpp | 4 ++-- fpdfsdk/fpdf_edittext.cpp | 4 ++-- fpdfsdk/fpdf_flatten.cpp | 7 +++---- fpdfsdk/fpdf_ppo.cpp | 9 +++------ fpdfsdk/fpdf_transformpage.cpp | 6 +++--- fpdfsdk/pwl/cpwl_appstream.cpp | 4 ++-- 7 files changed, 16 insertions(+), 20 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 577f1e0638..2c549d8c90 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -168,7 +168,7 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, auto pOwnedDict = pdfium::MakeUnique(m_pDocument->GetByteStringPool()); pStreamDict = pOwnedDict.get(); - pStream->InitStream(nullptr, 0, std::move(pOwnedDict)); + pStream->InitStream({}, std::move(pOwnedDict)); } CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp index 070a7fd78e..b20e5c87dc 100644 --- a/fpdfsdk/fpdf_annot.cpp +++ b/fpdfsdk/fpdf_annot.cpp @@ -153,7 +153,7 @@ void UpdateContentStream(CPDF_Form* pForm, CPDF_Stream* pStream) { CPDF_PageContentGenerator generator(pForm); std::ostringstream buf; generator.ProcessPageObjects(&buf); - pStream->SetDataAndRemoveFilter(&buf); + pStream->SetDataFromStringstreamAndRemoveFilter(&buf); } void SetQuadPointsAtIndex(CPDF_Array* array, @@ -784,7 +784,7 @@ FPDFAnnot_SetAP(FPDF_ANNOTATION annot, ByteString newValue = CFXByteStringFromFPDFWideString(value); auto pNewApStream = pdfium::MakeUnique(); - pNewApStream->SetData(newValue.raw_str(), newValue.GetLength()); + pNewApStream->SetData(newValue.AsRawSpan()); pApDict->SetFor(modeKey, std::move(pNewApStream)); } else { if (pApDict) { diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp index 2773763b9a..4dc293be8a 100644 --- a/fpdfsdk/fpdf_edittext.cpp +++ b/fpdfsdk/fpdf_edittext.cpp @@ -94,7 +94,7 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc, pFontDesc->SetNewFor("StemV", pFont->IsBold() ? 120 : 70); CPDF_Stream* pStream = pDoc->NewIndirect(); - pStream->SetData(data, size); + pStream->SetData({data, size}); // TODO(npm): Lengths for Type1 fonts. if (font_type == FPDF_FONT_TRUETYPE) { pStream->GetDict()->SetNewFor("Length1", @@ -256,7 +256,7 @@ CPDF_Stream* LoadUnicode(CPDF_Document* pDoc, buffer << ToUnicodeEnd; // TODO(npm): Encrypt / Compress? CPDF_Stream* stream = pDoc->NewIndirect(); - stream->SetData(&buffer); + stream->SetDataFromStringstream(&buffer); return stream; } diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index b9e29be8b4..7ea49cfddf 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -176,7 +176,7 @@ CPDF_Object* NewIndirectContentsStream(const ByteString& key, pdfium::MakeUnique(pDocument->GetByteStringPool())); ByteString sStream = ByteString::Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); - pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); + pNewContents->SetData(sStream.AsRawSpan()); return pNewContents; } @@ -205,8 +205,7 @@ void SetPageContents(const ByteString& key, ByteString sStream = "q\n"; ByteString sBody = ByteString(pAcc->GetData(), pAcc->GetSize()); sStream = sStream + sBody + "\nQ"; - pContentsStream->SetDataAndRemoveFilter(sStream.raw_str(), - sStream.GetLength()); + pContentsStream->SetDataAndRemoveFilter(sStream.AsRawSpan()); pContentsArray->Add(pContentsStream->MakeReference(pDocument)); pPage->SetFor(pdfium::page_object::kContents, pContentsArray->MakeReference(pDocument)); @@ -394,7 +393,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); sStream += ByteString::Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str()); - pNewXObject->SetDataAndRemoveFilter(sStream.raw_str(), sStream.GetLength()); + pNewXObject->SetDataAndRemoveFilter(sStream.AsRawSpan()); } pPageDict->RemoveFor("Annots"); return FLATTEN_SUCCESS; diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 722070547f..3c99304a98 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -715,17 +715,14 @@ uint32_t CPDF_NPageToOneExporter::MakeXObject( bsSrcContentStream += bsStream; bsSrcContentStream += "\n"; } - pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.raw_str(), - bsSrcContentStream.GetLength()); + pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.AsRawSpan()); } else { const CPDF_Stream* pStream = pSrcContentObj->AsStream(); auto pAcc = pdfium::MakeRetain(pStream); pAcc->LoadAllDataFiltered(); ByteString bsStream(pAcc->GetData(), pAcc->GetSize()); - pNewXObject->SetDataAndRemoveFilter(bsStream.raw_str(), - bsStream.GetLength()); + pNewXObject->SetDataAndRemoveFilter(bsStream.AsRawSpan()); } - return pNewXObject->GetObjNum(); } @@ -752,7 +749,7 @@ void CPDF_NPageToOneExporter::FinishPage( auto pDict = pdfium::MakeUnique(dest()->GetByteStringPool()); CPDF_Stream* pStream = dest()->NewIndirect(nullptr, 0, std::move(pDict)); - pStream->SetData(bsContent.raw_str(), bsContent.GetLength()); + pStream->SetData(bsContent.AsRawSpan()); pDestPageDict->SetFor(pdfium::page_object::kContents, pStream->MakeReference(dest())); } diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 2458e939d2..52b9fd41df 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -136,12 +136,12 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, CPDF_Stream* pStream = pDoc->NewIndirect( nullptr, 0, pdfium::MakeUnique(pDoc->GetByteStringPool())); - pStream->SetData(&textBuf); + pStream->SetDataFromStringstream(&textBuf); CPDF_Stream* pEndStream = pDoc->NewIndirect( nullptr, 0, pdfium::MakeUnique(pDoc->GetByteStringPool())); - pEndStream->SetData((const uint8_t*)" Q", 2); + pEndStream->SetData(ByteStringView(" Q").span()); if (CPDF_Array* pContentArray = ToArray(pContentObj)) { pContentArray->InsertAt(0, pStream->MakeReference(pDoc)); @@ -295,7 +295,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, CPDF_Stream* pStream = pDoc->NewIndirect( nullptr, 0, pdfium::MakeUnique(pDoc->GetByteStringPool())); - pStream->SetData(&strClip); + pStream->SetDataFromStringstream(&strClip); if (CPDF_Array* pArray = ToArray(pContentObj)) { pArray->InsertAt(0, pStream->MakeReference(pDoc)); diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp index 512af1437a..7d7f710f03 100644 --- a/fpdfsdk/pwl/cpwl_appstream.cpp +++ b/fpdfsdk/pwl/cpwl_appstream.cpp @@ -1948,11 +1948,11 @@ void CPWL_AppStream::Write(const ByteString& sAPType, pStreamDict->SetNewFor("Type", "XObject"); pStreamDict->SetNewFor("Subtype", "Form"); pStreamDict->SetNewFor("FormType", 1); - pStream->InitStream(nullptr, 0, std::move(pNewDict)); + pStream->InitStream({}, std::move(pNewDict)); } pStreamDict->SetMatrixFor("Matrix", widget_->GetMatrix()); pStreamDict->SetRectFor("BBox", widget_->GetRotatedRect()); - pStream->SetDataAndRemoveFilter(sContents.raw_str(), sContents.GetLength()); + pStream->SetDataAndRemoveFilter(sContents.AsRawSpan()); } void CPWL_AppStream::Remove(const ByteString& sAPType) { -- cgit v1.2.3