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_textstate.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/page/cpdf_textstate.h"
8
9#include <math.h>
10
11#include <utility>
12
13#include "core/fpdfapi/font/cpdf_font.h"
14#include "core/fpdfapi/page/cpdf_docpagedata.h"
15
17
19
21
22CPDF_TextState::~CPDF_TextState() = default;
23
25 m_Ref.Emplace();
26}
27
29 return m_Ref.GetObject()->font_;
30}
31
33 m_Ref.GetPrivateCopy()->SetFont(std::move(pFont));
34}
35
37 return m_Ref.GetObject()->font_size_;
38}
39
40void CPDF_TextState::SetFontSize(float size) {
41 if (!m_Ref || GetFontSize() != size) {
42 m_Ref.GetPrivateCopy()->font_size_ = size;
43 }
44}
45
46pdfium::span<const float> CPDF_TextState::GetMatrix() const {
47 return m_Ref.GetObject()->matrix_;
48}
49
51 return m_Ref.GetPrivateCopy()->matrix_;
52}
53
55 return m_Ref.GetObject()->char_space_;
56}
57
59 if (!m_Ref || GetCharSpace() != sp) {
60 m_Ref.GetPrivateCopy()->char_space_ = sp;
61 }
62}
63
65 return m_Ref.GetObject()->word_space_;
66}
67
69 if (!m_Ref || GetWordSpace() != sp) {
70 m_Ref.GetPrivateCopy()->word_space_ = sp;
71 }
72}
73
75 return m_Ref.GetObject()->GetFontSizeH();
76}
77
79 return m_Ref.GetObject()->text_rendering_mode_;
80}
81
83 if (!m_Ref || GetTextMode() != mode) {
84 m_Ref.GetPrivateCopy()->text_rendering_mode_ = mode;
85 }
86}
87
88pdfium::span<const float> CPDF_TextState::GetCTM() const {
89 return m_Ref.GetObject()->ctm_;
90}
91
93 return m_Ref.GetPrivateCopy()->ctm_;
94}
95
96CPDF_TextState::TextData::TextData() = default;
97
98CPDF_TextState::TextData::TextData(const TextData& that)
99 : font_(that.font_),
100 document_(that.document_),
101 font_size_(that.font_size_),
102 char_space_(that.char_space_),
103 word_space_(that.word_space_),
104 text_rendering_mode_(that.text_rendering_mode_),
105 matrix_(that.matrix_),
106 ctm_(that.ctm_) {
107 if (document_ && font_) {
108 auto* page_data = CPDF_DocPageData::FromDocument(document_);
109 font_ = page_data->GetFont(font_->GetMutableFontDict());
110 }
111}
112
113CPDF_TextState::TextData::~TextData() = default;
114
115RetainPtr<CPDF_TextState::TextData> CPDF_TextState::TextData::Clone() const {
116 return pdfium::MakeRetain<CPDF_TextState::TextData>(*this);
117}
118
119void CPDF_TextState::TextData::SetFont(RetainPtr<CPDF_Font> pFont) {
120 document_ = pFont ? pFont->GetDocument() : nullptr;
121 font_ = std::move(pFont);
122}
123
124float CPDF_TextState::TextData::GetFontSizeH() const {
125 return fabs(hypotf(matrix_[0], matrix_[2]) * font_size_);
126}
127
129 if (iMode < 0 || iMode > 7)
130 return false;
131 *mode = static_cast<TextRenderingMode>(iMode);
132 return true;
133}
134
136 switch (mode) {
141 return true;
142 default:
143 return false;
144 }
145}
146
148 switch (mode) {
153 return true;
154 default:
155 return false;
156 }
157}
pdfium::span< float > GetMutableMatrix()
TextRenderingMode GetTextMode() const
CPDF_TextState(const CPDF_TextState &that)
RetainPtr< CPDF_Font > GetFont() const
float GetWordSpace() const
float GetFontSize() const
float GetCharSpace() const
void SetTextMode(TextRenderingMode mode)
void SetWordSpace(float sp)
void SetFont(RetainPtr< CPDF_Font > pFont)
float GetFontSizeH() const
void SetFontSize(float size)
void SetCharSpace(float sp)
pdfium::span< float > GetMutableCTM()
CPDF_TextState & operator=(const CPDF_TextState &that)
pdfium::span< const float > GetMatrix() const
pdfium::span< const float > GetCTM() const
bool TextRenderingModeIsStrokeMode(const TextRenderingMode &mode)
bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode *mode)
bool TextRenderingModeIsClipMode(const TextRenderingMode &mode)
TextRenderingMode