• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
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 #include "third_party/base/ptr_util.h"
13 
CPDF_Name(WeakPtr<ByteStringPool> pPool,const ByteString & str)14 CPDF_Name::CPDF_Name(WeakPtr<ByteStringPool> pPool, const ByteString& str)
15     : m_Name(str) {
16   if (pPool)
17     m_Name = pPool->Intern(m_Name);
18 }
19 
~CPDF_Name()20 CPDF_Name::~CPDF_Name() {}
21 
GetType() const22 CPDF_Object::Type CPDF_Name::GetType() const {
23   return kName;
24 }
25 
Clone() const26 RetainPtr<CPDF_Object> CPDF_Name::Clone() const {
27   return pdfium::MakeRetain<CPDF_Name>(nullptr, m_Name);
28 }
29 
GetString() const30 ByteString CPDF_Name::GetString() const {
31   return m_Name;
32 }
33 
SetString(const ByteString & str)34 void CPDF_Name::SetString(const ByteString& str) {
35   m_Name = str;
36 }
37 
IsName() const38 bool CPDF_Name::IsName() const {
39   return true;
40 }
41 
AsName()42 CPDF_Name* CPDF_Name::AsName() {
43   return this;
44 }
45 
AsName() const46 const CPDF_Name* CPDF_Name::AsName() const {
47   return this;
48 }
49 
GetUnicodeText() const50 WideString CPDF_Name::GetUnicodeText() const {
51   return PDF_DecodeText(m_Name.raw_span());
52 }
53 
WriteTo(IFX_ArchiveStream * archive,const CPDF_Encryptor * encryptor) const54 bool CPDF_Name::WriteTo(IFX_ArchiveStream* archive,
55                         const CPDF_Encryptor* encryptor) const {
56   return archive->WriteString("/") &&
57          archive->WriteString(PDF_NameEncode(GetString()).AsStringView());
58 }
59