1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fpdfapi/parser/cpdf_name.h" 8 9 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 10 #include "core/fpdfapi/parser/fpdf_parser_utility.h" 11 #include "core/fxcrt/fx_stream.h" 12 CPDF_Name(WeakPtr<ByteStringPool> pPool,const ByteString & str)13CPDF_Name::CPDF_Name(WeakPtr<ByteStringPool> pPool, const ByteString& str) 14 : m_Name(str) { 15 if (pPool) 16 m_Name = pPool->Intern(m_Name); 17 } 18 19 CPDF_Name::~CPDF_Name() = default; 20 GetType() const21CPDF_Object::Type CPDF_Name::GetType() const { 22 return kName; 23 } 24 Clone() const25RetainPtr<CPDF_Object> CPDF_Name::Clone() const { 26 return pdfium::MakeRetain<CPDF_Name>(nullptr, m_Name); 27 } 28 GetString() const29ByteString CPDF_Name::GetString() const { 30 return m_Name; 31 } 32 SetString(const ByteString & str)33void CPDF_Name::SetString(const ByteString& str) { 34 m_Name = str; 35 } 36 AsMutableName()37CPDF_Name* CPDF_Name::AsMutableName() { 38 return this; 39 } 40 GetUnicodeText() const41WideString CPDF_Name::GetUnicodeText() const { 42 return PDF_DecodeText(m_Name.raw_span()); 43 } 44 WriteTo(IFX_ArchiveStream * archive,const CPDF_Encryptor * encryptor) const45bool CPDF_Name::WriteTo(IFX_ArchiveStream* archive, 46 const CPDF_Encryptor* encryptor) const { 47 if (!archive->WriteString("/")) 48 return false; 49 50 const ByteString name = PDF_NameEncode(GetString()); 51 return name.IsEmpty() || archive->WriteString(name.AsStringView()); 52 } 53