diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2017-06-09 15:37:45 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-13 16:20:17 +0000 |
commit | 8f38e4fff7e80e676c1c7747634d6d4648688afc (patch) | |
tree | d372d186135c677ab26b98821d874fd26721e96f /core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | |
parent | 2de070304a510be679c7f1d706812263ecd4a1bb (diff) | |
download | pdfium-8f38e4fff7e80e676c1c7747634d6d4648688afc.tar.xz |
Converting CFX_ByteTextBuf to ostringstream in cpdf_pagecontentgenerator.
Bug: pdfium:731
Change-Id: If606359bd9264a6f440871ab824ab54a4efae901
Reviewed-on: https://pdfium-review.googlesource.com/6450
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp')
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 2f00c7db09..e06c28d7ae 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -28,7 +28,7 @@ namespace { -CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, const CFX_Matrix& matrix) { +std::ostream& operator<<(std::ostream& ar, const CFX_Matrix& matrix) { ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " " << matrix.e << " " << matrix.f; return ar; @@ -61,7 +61,7 @@ CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} void CPDF_PageContentGenerator::GenerateContent() { CPDF_Document* pDoc = m_pDocument.Get(); - CFX_ByteTextBuf buf; + std::ostringstream buf; if (!ProcessPageObjects(&buf)) return; @@ -69,7 +69,8 @@ void CPDF_PageContentGenerator::GenerateContent() { CPDF_Object* pContent = pPageDict ? pPageDict->GetObjectFor("Contents") : nullptr; CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(); - pStream->SetData(buf.GetBuffer(), buf.GetLength()); + pStream->SetData(reinterpret_cast<const uint8_t*>(buf.str().c_str()), + buf.tellp()); if (pContent) { CPDF_Array* pArray = ToArray(pContent); if (pArray) { @@ -133,7 +134,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( return name; } -bool CPDF_PageContentGenerator::ProcessPageObjects(CFX_ByteTextBuf* buf) { +bool CPDF_PageContentGenerator::ProcessPageObjects(std::ostringstream* buf) { bool bDirty = false; for (auto& pPageObj : m_pageObjects) { if (!pPageObj->IsDirty()) @@ -150,7 +151,7 @@ bool CPDF_PageContentGenerator::ProcessPageObjects(CFX_ByteTextBuf* buf) { return bDirty; } -void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessImage(std::ostringstream* buf, CPDF_ImageObject* pImageObj) { if ((pImageObj->matrix().a == 0 && pImageObj->matrix().b == 0) || (pImageObj->matrix().c == 0 && pImageObj->matrix().d == 0)) { @@ -175,7 +176,7 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf, if (bWasInline) pImageObj->SetImage(m_pDocument->GetPageData()->GetImage(dwObjNum)); - *buf << "/" << PDF_NameEncode(name) << " Do Q\n"; + *buf << "/" << PDF_NameEncode(name).c_str() << " Do Q\n"; } // Processing path with operators from Tables 4.9 and 4.10 of PDF spec 1.7: @@ -189,7 +190,7 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf, // Path painting operators: "S", "n", "B", "f", "B*", "f*", depending on // the filling mode and whether we want stroking the path or not. // "Q" restores the graphics state imposed by the ProcessGraphics method. -void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessPath(std::ostringstream* buf, CPDF_PathObject* pPathObj) { ProcessGraphics(buf, pPathObj); auto& pPoints = pPathObj->m_Path.GetPoints(); @@ -242,7 +243,7 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, // "w" sets the stroke line width. // "ca" sets the fill alpha, "CA" sets the stroke alpha. // "q" saves the graphics state, so that the settings can later be reversed -void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj) { *buf << "q "; float fillColor[3]; @@ -297,14 +298,14 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, name = RealizeResource(dwObjNum, "ExtGState"); m_pPage->m_GraphicsMap[graphD] = name; } - *buf << "/" << PDF_NameEncode(name) << " gs "; + *buf << "/" << PDF_NameEncode(name).c_str() << " gs "; } // This method adds text to the buffer, BT begins the text object, ET ends it. // Tm sets the text matrix (allows positioning and transforming text). // Tf sets the font name (from Font in Resources) and font size. // Tj sets the actual text, <####...> is used when specifying charcodes. -void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj) { *buf << "BT " << pTextObj->GetTextMatrix() << " Tm "; CPDF_Font* pFont = pTextObj->GetFont(); @@ -338,14 +339,14 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, dictName = RealizeResource(dwObjNum, "Font"); m_pPage->m_FontsMap[fontD] = dictName; } - *buf << "/" << PDF_NameEncode(dictName) << " " << pTextObj->GetFontSize() - << " Tf "; + *buf << "/" << PDF_NameEncode(dictName).c_str() << " " + << pTextObj->GetFontSize() << " Tf "; CFX_ByteString text; for (uint32_t charcode : pTextObj->m_CharCodes) { if (charcode != CPDF_Font::kInvalidCharCode) pFont->AppendChar(&text, charcode); } ProcessGraphics(buf, pTextObj); - *buf << PDF_EncodeString(text, true) << " Tj ET"; + *buf << PDF_EncodeString(text, true).c_str() << " Tj ET"; *buf << " Q\n"; } |