diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-17 18:12:38 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-17 18:12:38 +0000 |
commit | bc069b7a855998ab28f487d2f09152851dddb16a (patch) | |
tree | b50e3713a80177034a3fc7a2c12920c15aeb7056 /core/fxcrt | |
parent | 8b4a3c7ef32b2ffb4874e4cc65b38ee555d8806e (diff) | |
download | pdfium-bc069b7a855998ab28f487d2f09152851dddb16a.tar.xz |
Use an IFX_SeekableStream for XML saving
This CL converts the CFX_XML Save methods to take an IFX_SeekableStream instead
of a CFX_SeekableStreamProxy.
Change-Id: I6b3f6acc9f51e73b3c863b965b4dcdcbd25ba949
Reviewed-on: https://pdfium-review.googlesource.com/30850
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/cfx_blockbuffer.h | 1 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlchardata.cpp | 10 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlchardata.h | 2 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 21 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.h | 2 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlinstruction.cpp | 27 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlinstruction.h | 2 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlnode.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlnode.h | 4 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmltext.cpp | 5 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmltext.h | 2 |
11 files changed, 33 insertions, 45 deletions
diff --git a/core/fxcrt/cfx_blockbuffer.h b/core/fxcrt/cfx_blockbuffer.h index 423aa6820b..1673136643 100644 --- a/core/fxcrt/cfx_blockbuffer.h +++ b/core/fxcrt/cfx_blockbuffer.h @@ -21,7 +21,6 @@ class CFX_BlockBuffer { ~CFX_BlockBuffer(); bool InitBuffer(); - bool IsInitialized() { return m_BufferSize / GetAllocStep() >= 1; } std::pair<wchar_t*, size_t> GetAvailableBlock(); size_t GetAllocStep() const; diff --git a/core/fxcrt/xml/cfx_xmlchardata.cpp b/core/fxcrt/xml/cfx_xmlchardata.cpp index 7712b30dfe..b613b15d00 100644 --- a/core/fxcrt/xml/cfx_xmlchardata.cpp +++ b/core/fxcrt/xml/cfx_xmlchardata.cpp @@ -21,10 +21,8 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLCharData::Clone() { return pdfium::MakeUnique<CFX_XMLCharData>(GetText()); } -void CFX_XMLCharData::Save( - const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) { - WideString ws = L"<![CDATA["; - ws += GetText(); - ws += L"]]>"; - pXMLStream->WriteString(ws.AsStringView()); +void CFX_XMLCharData::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { + pXMLStream->WriteString("<![CDATA["); + pXMLStream->WriteString(GetText().UTF8Encode().AsStringView()); + pXMLStream->WriteString("]]>"); } diff --git a/core/fxcrt/xml/cfx_xmlchardata.h b/core/fxcrt/xml/cfx_xmlchardata.h index c702d9636f..5b00597955 100644 --- a/core/fxcrt/xml/cfx_xmlchardata.h +++ b/core/fxcrt/xml/cfx_xmlchardata.h @@ -20,7 +20,7 @@ class CFX_XMLCharData : public CFX_XMLText { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr<CFX_XMLNode> Clone() override; - void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override; }; #endif // CORE_FXCRT_XML_CFX_XMLCHARDATA_H_ diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 42588c6393..c54d8488a3 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -93,30 +93,31 @@ void CFX_XMLElement::SetTextData(const WideString& wsText) { AppendChild(new CFX_XMLText(wsText)); } -void CFX_XMLElement::Save( - const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) { - pXMLStream->WriteString(L"<"); - pXMLStream->WriteString(name_.AsStringView()); +void CFX_XMLElement::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { + ByteStringView name_encoded = name_.UTF8Encode().AsStringView(); + + pXMLStream->WriteString("<"); + pXMLStream->WriteString(name_encoded); for (auto it : attrs_) { pXMLStream->WriteString( - AttributeToString(it.first, it.second).AsStringView()); + AttributeToString(it.first, it.second).UTF8Encode().AsStringView()); } if (!GetFirstChild()) { - pXMLStream->WriteString(L" />"); + pXMLStream->WriteString(" />\n"); return; } - pXMLStream->WriteString(L">"); + pXMLStream->WriteString(">\n"); for (CFX_XMLNode* pChild = GetFirstChild(); pChild; pChild = pChild->GetNextSibling()) { pChild->Save(pXMLStream); } - pXMLStream->WriteString(L"</"); - pXMLStream->WriteString(name_.AsStringView()); - pXMLStream->WriteString(L"\n>"); + pXMLStream->WriteString("</"); + pXMLStream->WriteString(name_encoded); + pXMLStream->WriteString(">\n"); } CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed( diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h index f8533a1445..c1d9fea3f0 100644 --- a/core/fxcrt/xml/cfx_xmlelement.h +++ b/core/fxcrt/xml/cfx_xmlelement.h @@ -22,7 +22,7 @@ class CFX_XMLElement : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr<CFX_XMLNode> Clone() override; - void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override; WideString GetName() const { return name_; } diff --git a/core/fxcrt/xml/cfx_xmlinstruction.cpp b/core/fxcrt/xml/cfx_xmlinstruction.cpp index f3185fbf5b..7b844e6808 100644 --- a/core/fxcrt/xml/cfx_xmlinstruction.cpp +++ b/core/fxcrt/xml/cfx_xmlinstruction.cpp @@ -40,31 +40,20 @@ bool CFX_XMLInstruction::IsAcrobat() const { return name_ == L"acrobat"; } -void CFX_XMLInstruction::Save( - const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) { +void CFX_XMLInstruction::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { if (name_.CompareNoCase(L"xml") == 0) { - WideString ws = L"<?xml version=\"1.0\" encoding=\""; - uint16_t wCodePage = pXMLStream->GetCodePage(); - if (wCodePage == FX_CODEPAGE_UTF16LE) - ws += L"UTF-16"; - else if (wCodePage == FX_CODEPAGE_UTF16BE) - ws += L"UTF-16be"; - else - ws += L"UTF-8"; - - ws += L"\"?>"; - pXMLStream->WriteString(ws.AsStringView()); + pXMLStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); return; } - pXMLStream->WriteString( - WideString::Format(L"<?%ls", name_.c_str()).AsStringView()); + pXMLStream->WriteString("<?"); + pXMLStream->WriteString(name_.UTF8Encode().AsStringView()); for (const WideString& target : m_TargetData) { - pXMLStream->WriteString(L"\""); - pXMLStream->WriteString(target.AsStringView()); - pXMLStream->WriteString(L"\""); + pXMLStream->WriteString("\""); + pXMLStream->WriteString(target.UTF8Encode().AsStringView()); + pXMLStream->WriteString("\""); } - pXMLStream->WriteString(WideStringView(L"?>")); + pXMLStream->WriteString("?>"); } diff --git a/core/fxcrt/xml/cfx_xmlinstruction.h b/core/fxcrt/xml/cfx_xmlinstruction.h index 7cee1d4fc0..045610bd8a 100644 --- a/core/fxcrt/xml/cfx_xmlinstruction.h +++ b/core/fxcrt/xml/cfx_xmlinstruction.h @@ -21,7 +21,7 @@ class CFX_XMLInstruction : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr<CFX_XMLNode> Clone() override; - void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override; bool IsOriginalXFAVersion() const; bool IsAcrobat() const; diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp index 540b20e721..6303615d01 100644 --- a/core/fxcrt/xml/cfx_xmlnode.cpp +++ b/core/fxcrt/xml/cfx_xmlnode.cpp @@ -108,7 +108,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLNode::Clone() { return nullptr; } -void CFX_XMLNode::Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {} +void CFX_XMLNode::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {} WideString CFX_XMLNode::EncodeEntities(const WideString& value) { WideString ret = value; diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h index 7278d2b4ca..86b5e998e6 100644 --- a/core/fxcrt/xml/cfx_xmlnode.h +++ b/core/fxcrt/xml/cfx_xmlnode.h @@ -9,7 +9,7 @@ #include <memory> -#include "core/fxcrt/cfx_seekablestreamproxy.h" +#include "core/fxcrt/fx_stream.h" #include "core/fxcrt/retain_ptr.h" enum FX_XMLNODETYPE { @@ -32,7 +32,7 @@ class CFX_XMLNode { virtual FX_XMLNODETYPE GetType() const; virtual std::unique_ptr<CFX_XMLNode> Clone(); - virtual void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream); + virtual void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream); CFX_XMLNode* GetRoot(); CFX_XMLNode* GetParent() const { return parent_; } diff --git a/core/fxcrt/xml/cfx_xmltext.cpp b/core/fxcrt/xml/cfx_xmltext.cpp index 05e2935440..74d0a501eb 100644 --- a/core/fxcrt/xml/cfx_xmltext.cpp +++ b/core/fxcrt/xml/cfx_xmltext.cpp @@ -21,6 +21,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLText::Clone() { return pdfium::MakeUnique<CFX_XMLText>(m_wsText); } -void CFX_XMLText::Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) { - pXMLStream->WriteString(EncodeEntities(GetText()).AsStringView()); +void CFX_XMLText::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { + pXMLStream->WriteString( + EncodeEntities(GetText()).UTF8Encode().AsStringView()); } diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h index b26eef14ac..bbf14be257 100644 --- a/core/fxcrt/xml/cfx_xmltext.h +++ b/core/fxcrt/xml/cfx_xmltext.h @@ -20,7 +20,7 @@ class CFX_XMLText : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr<CFX_XMLNode> Clone() override; - void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override; WideString GetText() const { return m_wsText; } void SetText(const WideString& wsText) { m_wsText = wsText; } |