From 5b590337e0778b49dd7092af4a283ed0f9c5a2e9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 10 May 2017 13:59:14 -0400 Subject: Store the offset in the archive buffer This Cl moves the implementation of the archive buffer behind an IFX_ArchiveStream interface. The buffer holds the current offset and the offset parameter is removed from the CPDF_Creator and various other methods. Change-Id: Ia54e803b58bbfb6ef03fec4a940d2c056d541356 Reviewed-on: https://pdfium-review.googlesource.com/5255 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fpdfapi/parser/cpdf_dictionary.cpp | 37 +++++++++++---------------------- 1 file changed, 12 insertions(+), 25 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_dictionary.cpp') diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 7d84083829..cbefb5d56d 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -239,40 +239,27 @@ CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { return m_pPool ? m_pPool->Intern(str) : str; } -bool CPDF_Dictionary::WriteTo(CFX_FileBufferArchive* archive, - FX_FILESIZE* offset) const { - if (archive->AppendString("<<") < 0) +bool CPDF_Dictionary::WriteTo(IFX_ArchiveStream* archive) const { + if (!archive->WriteString("<<")) return false; - *offset += 2; for (const auto& it : *this) { const CFX_ByteString& key = it.first; CPDF_Object* pValue = it.second.get(); - if (archive->AppendString("/") < 0) + if (!archive->WriteString("/") || + !archive->WriteString(PDF_NameEncode(key).AsStringC())) { return false; - - int32_t len = archive->AppendString(PDF_NameEncode(key).AsStringC()); - if (len < 0) - return false; - *offset += len + 1; + } if (!pValue->IsInline()) { - if (archive->AppendString(" ") < 0) - return false; - - len = archive->AppendDWord(pValue->GetObjNum()); - if (len < 0) - return false; - if (archive->AppendString(" 0 R") < 0) - return false; - *offset += len + 5; - } else { - if (!pValue->WriteTo(archive, offset)) + if (!archive->WriteString(" ") || + !archive->WriteDWord(pValue->GetObjNum()) || + !archive->WriteString(" 0 R")) { return false; + } + } else if (!pValue->WriteTo(archive)) { + return false; } } - if (archive->AppendString(">>") < 0) - return false; - *offset += 2; - return true; + return archive->WriteString(">>"); } -- cgit v1.2.3