Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_number.cpp
Go to the documentation of this file.
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_number.h"
8
9#include "core/fxcrt/fx_stream.h"
10
11CPDF_Number::CPDF_Number() = default;
12
13CPDF_Number::CPDF_Number(int value) : m_Number(value) {}
14
15CPDF_Number::CPDF_Number(float value) : m_Number(value) {}
16
17CPDF_Number::CPDF_Number(ByteStringView str) : m_Number(str) {}
18
19CPDF_Number::~CPDF_Number() = default;
20
21CPDF_Object::Type CPDF_Number::GetType() const {
22 return kNumber;
23}
24
25RetainPtr<CPDF_Object> CPDF_Number::Clone() const {
26 return m_Number.IsInteger()
27 ? pdfium::MakeRetain<CPDF_Number>(m_Number.GetSigned())
28 : pdfium::MakeRetain<CPDF_Number>(m_Number.GetFloat());
29}
30
31float CPDF_Number::GetNumber() const {
32 return m_Number.GetFloat();
33}
34
35int CPDF_Number::GetInteger() const {
36 return m_Number.GetSigned();
37}
38
39CPDF_Number* CPDF_Number::AsMutableNumber() {
40 return this;
41}
42
43void CPDF_Number::SetString(const ByteString& str) {
44 m_Number = FX_Number(str.AsStringView());
45}
46
47ByteString CPDF_Number::GetString() const {
48 return m_Number.IsInteger() ? ByteString::FormatInteger(m_Number.GetSigned())
49 : ByteString::FormatFloat(m_Number.GetFloat());
50}
51
52bool CPDF_Number::WriteTo(IFX_ArchiveStream* archive,
53 const CPDF_Encryptor* encryptor) const {
54 return archive->WriteString(" ") &&
55 archive->WriteString(GetString().AsStringView());
56}
bool WriteTo(IFX_ArchiveStream *archive, const CPDF_Encryptor *encryptor) const override
float GetNumber() const override
int GetInteger() const override
RetainPtr< CPDF_Object > Clone() const override
void SetString(const ByteString &str) override
~CPDF_Number() override
ByteString GetString() const override
CPDF_Number * AsMutableNumber() override
Type GetType() const override
bool WriteString(ByteStringView str)
Definition fx_stream.cpp:47