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()->m_pFont;
30}
31
33 m_Ref.GetPrivateCopy()->SetFont(std::move(pFont));
34}
35
37 return m_Ref.GetObject()->m_FontSize;
38}
39
40void CPDF_TextState::SetFontSize(float size) {
41 if (!m_Ref || GetFontSize() != size) {
42 m_Ref.GetPrivateCopy()->m_FontSize = size;
43 }
44}
45
46pdfium::span<const float> CPDF_TextState::GetMatrix() const {
47 return m_Ref.GetObject()->m_Matrix;
48}
49
50pdfium::span<float> CPDF_TextState::GetMutableMatrix() {
51 return m_Ref.GetPrivateCopy()->m_Matrix;
52}
53
55 return m_Ref.GetObject()->m_CharSpace;
56}
57
59 if (!m_Ref || GetCharSpace() != sp) {
60 m_Ref.GetPrivateCopy()->m_CharSpace = sp;
61 }
62}
63
65 return m_Ref.GetObject()->m_WordSpace;
66}
67
69 if (!m_Ref || GetWordSpace() != sp) {
70 m_Ref.GetPrivateCopy()->m_WordSpace = sp;
71 }
72}
73
75 return m_Ref.GetObject()->GetFontSizeH();
76}
77
79 return m_Ref.GetObject()->m_TextMode;
80}
81
83 if (!m_Ref || GetTextMode() != mode) {
84 m_Ref.GetPrivateCopy()->m_TextMode = mode;
85 }
86}
87
88pdfium::span<const float> CPDF_TextState::GetCTM() const {
89 return m_Ref.GetObject()->m_CTM;
90}
91
92pdfium::span<float> CPDF_TextState::GetMutableCTM() {
93 return m_Ref.GetPrivateCopy()->m_CTM;
94}
95
96CPDF_TextState::TextData::TextData() = default;
97
98CPDF_TextState::TextData::TextData(const TextData& that)
99 : m_pFont(that.m_pFont),
100 m_pDocument(that.m_pDocument),
101 m_FontSize(that.m_FontSize),
102 m_CharSpace(that.m_CharSpace),
103 m_WordSpace(that.m_WordSpace),
104 m_TextMode(that.m_TextMode) {
105 for (int i = 0; i < 4; ++i)
106 m_Matrix[i] = that.m_Matrix[i];
107
108 for (int i = 0; i < 4; ++i)
109 m_CTM[i] = that.m_CTM[i];
110
111 if (m_pDocument && m_pFont) {
112 auto* pPageData = CPDF_DocPageData::FromDocument(m_pDocument);
113 m_pFont = pPageData->GetFont(m_pFont->GetMutableFontDict());
114 }
115}
116
117CPDF_TextState::TextData::~TextData() = default;
118
119RetainPtr<CPDF_TextState::TextData> CPDF_TextState::TextData::Clone() const {
120 return pdfium::MakeRetain<CPDF_TextState::TextData>(*this);
121}
122
123void CPDF_TextState::TextData::SetFont(RetainPtr<CPDF_Font> pFont) {
124 m_pDocument = pFont ? pFont->GetDocument() : nullptr;
125 m_pFont = std::move(pFont);
126}
127
128float CPDF_TextState::TextData::GetFontSizeH() const {
129 return fabs(FXSYS_sqrt2(m_Matrix[0], m_Matrix[2]) * m_FontSize);
130}
131
133 if (iMode < 0 || iMode > 7)
134 return false;
135 *mode = static_cast<TextRenderingMode>(iMode);
136 return true;
137}
138
140 switch (mode) {
145 return true;
146 default:
147 return false;
148 }
149}
150
152 switch (mode) {
157 return true;
158 default:
159 return false;
160 }
161}
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
float FXSYS_sqrt2(float a, float b)