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
cxfa_textparser.h
Go to the documentation of this file.
1// Copyright 2017 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#ifndef XFA_FXFA_CXFA_TEXTPARSER_H_
8#define XFA_FXFA_CXFA_TEXTPARSER_H_
9
10#include <stdint.h>
11
12#include <map>
13#include <memory>
14#include <vector>
15
16#include "core/fxcrt/css/cfx_css.h"
17#include "core/fxcrt/css/cfx_csscomputedstyle.h"
18#include "core/fxcrt/css/cfx_cssdeclaration.h"
19#include "core/fxcrt/retain_ptr.h"
20#include "core/fxcrt/widestring.h"
21#include "core/fxge/dib/fx_dib.h"
22#include "fxjs/gc/heap.h"
23#include "third_party/abseil-cpp/absl/types/optional.h"
24#include "v8/include/cppgc/garbage-collected.h"
25#include "xfa/fxfa/fxfa_basic.h"
26
27class CFGAS_GEFont;
30class CFX_XMLNode;
31class CXFA_FFDoc;
34
36 public:
37 class Context {
38 public:
41
42 void SetParentStyle(RetainPtr<const CFX_CSSComputedStyle> style);
43 RetainPtr<const CFX_CSSComputedStyle> GetParentStyle() const {
44 return m_pParentStyle;
45 }
46
47 void SetDisplay(CFX_CSSDisplay eDisplay) { m_eDisplay = eDisplay; }
48 CFX_CSSDisplay GetDisplay() const { return m_eDisplay; }
49
50 void SetDecls(std::vector<const CFX_CSSDeclaration*>&& decl);
51 const std::vector<const CFX_CSSDeclaration*>& GetDecls() const {
52 return decls_;
53 }
54
55 private:
56 RetainPtr<const CFX_CSSComputedStyle> m_pParentStyle;
58 std::vector<const CFX_CSSDeclaration*> decls_;
59 };
60
62 virtual ~CXFA_TextParser();
63
64 void Trace(cppgc::Visitor* visitor) const {}
65
66 void Reset();
67 void DoParse(const CFX_XMLNode* pXMLContainer,
68 CXFA_TextProvider* pTextProvider);
69
70 RetainPtr<CFX_CSSComputedStyle> CreateRootStyle(
71 CXFA_TextProvider* pTextProvider);
72 RetainPtr<CFX_CSSComputedStyle> ComputeStyle(
73 const CFX_XMLNode* pXMLNode,
74 RetainPtr<const CFX_CSSComputedStyle> pParentStyle);
75
76 bool IsParsed() const { return m_bParsed; }
77
79
80 float GetTabInterval(const CFX_CSSComputedStyle* pStyle) const;
81 int32_t CountTabs(const CFX_CSSComputedStyle* pStyle) const;
82
83 bool IsSpaceRun(const CFX_CSSComputedStyle* pStyle) const;
84 bool GetTabstops(const CFX_CSSComputedStyle* pStyle,
85 CXFA_TextTabstopsContext* pTabstopContext);
86
87 RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* doc,
88 CXFA_TextProvider* pTextProvider,
89 const CFX_CSSComputedStyle* pStyle) const;
90 float GetFontSize(CXFA_TextProvider* pTextProvider,
91 const CFX_CSSComputedStyle* pStyle) const;
92 int32_t GetHorScale(CXFA_TextProvider* pTextProvider,
93 const CFX_CSSComputedStyle* pStyle,
94 const CFX_XMLNode* pXMLNode) const;
95 int32_t GetVerScale(CXFA_TextProvider* pTextProvider,
96 const CFX_CSSComputedStyle* pStyle) const;
97 int32_t GetUnderline(CXFA_TextProvider* pTextProvider,
98 const CFX_CSSComputedStyle* pStyle) const;
100 CXFA_TextProvider* pTextProvider,
101 const CFX_CSSComputedStyle* pStyle) const;
102 int32_t GetLinethrough(CXFA_TextProvider* pTextProvider,
103 const CFX_CSSComputedStyle* pStyle) const;
104 FX_ARGB GetColor(CXFA_TextProvider* pTextProvider,
105 const CFX_CSSComputedStyle* pStyle) const;
106 float GetBaseline(CXFA_TextProvider* pTextProvider,
107 const CFX_CSSComputedStyle* pStyle) const;
108 float GetLineHeight(CXFA_TextProvider* pTextProvider,
109 const CFX_CSSComputedStyle* pStyle,
110 bool bFirst,
111 float fVerScale) const;
112
114 const CXFA_TextProvider* pTextProvider,
115 const CFX_XMLNode* pXMLNode);
117
118 protected:
120
121 bool TagValidate(const WideString& str) const;
122
123 private:
124 class TagProvider {
125 public:
126 TagProvider();
127 ~TagProvider();
128
129 WideString GetTagName() { return m_wsTagName; }
130
131 void SetTagName(const WideString& wsName) { m_wsTagName = wsName; }
132 void SetAttribute(const WideString& wsAttr, const WideString& wsValue) {
133 m_Attributes.insert({wsAttr, wsValue});
134 }
135
136 WideString GetAttribute(const WideString& wsAttr) {
137 return m_Attributes[wsAttr];
138 }
139
140 bool m_bTagAvailable = false;
141 bool m_bContent = false;
142
143 private:
144 WideString m_wsTagName;
145 std::map<WideString, WideString> m_Attributes;
146 };
147
148 // static
149 std::unique_ptr<TagProvider> ParseTagInfo(const CFX_XMLNode* pXMLNode);
150
151 void InitCSSData(CXFA_TextProvider* pTextProvider);
152 void ParseRichText(const CFX_XMLNode* pXMLNode,
153 const CFX_CSSComputedStyle* pParentStyle);
154 std::unique_ptr<CFX_CSSStyleSheet> LoadDefaultSheetStyle();
155 RetainPtr<CFX_CSSComputedStyle> CreateStyle(
156 const CFX_CSSComputedStyle* pParentStyle);
157
158 bool m_bParsed = false;
159 bool m_cssInitialized = false;
160 std::unique_ptr<CFX_CSSStyleSelector> m_pSelector;
161 std::map<const CFX_XMLNode*, std::unique_ptr<Context>>
162 m_mapXMLNodeToParseContext;
163};
164
165#endif // XFA_FXFA_CXFA_TEXTPARSER_H_
CFX_CSSDisplay
Definition cfx_css.h:48
CFX_CSSTextAlign
Definition cfx_css.h:62
CFX_CSSLengthUnit
Definition cfx_css.h:40
CFX_XMLElement * ToXMLElement(CFX_XMLNode *pNode)
const CFX_XMLText * ToXMLText(const CFX_XMLNode *pNode)
Definition cfx_xmltext.h:42
static bool DrawString(CFX_RenderDevice *device, FX_ARGB color, const RetainPtr< CFGAS_GEFont > &pFont, pdfium::span< TextCharPos > pCharPos, float fFontSize, const CFX_Matrix &matrix)
int32_t GetHorizontalScale() const
int32_t GetFontSize() const
int32_t GetCharCount() const
int32_t GetStartPos() const
const CFGAS_TextUserData * GetUserData() const
int32_t GetVerticalScale() const
int32_t GetBidiLevel() const
WideString GetString() const
int32_t GetWidth() const
void SetMarginWidth(const CFX_CSSRect &rect)
const CFX_CSSLength & GetTextIndent() const
const CFX_CSSRect * GetMarginWidth() const
CFX_CSSTextAlign GetTextAlign() const
const CFX_CSSRect * GetPaddingWidth() const
float GetValue() const
Definition cfx_css.h:116
CFX_CSSLength & Set(CFX_CSSLengthUnit eUnit, float fValue)
Definition cfx_css.h:108
CFX_CSSLength right
Definition cfx_css.h:151
CFX_CSSLength top
Definition cfx_css.h:150
CFX_CSSLength bottom
Definition cfx_css.h:152
CFX_CSSLength left
Definition cfx_css.h:149
void AppendLine(const CFX_PointF &pt1, const CFX_PointF &pt2)
Definition cfx_path.cpp:297
FX_RECT GetOuterRect() const
float right() const
bool SetClip_Rect(const FX_RECT &pRect)
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
void RestoreState(bool bKeepSaved)
WideString GetLocalTagName() const
WideString GetAttribute(const WideString &name) const
virtual Type GetType() const =0
const WideString & GetText() const
Definition cfx_xmltext.h:25
float GetMarginLeft()
Definition cxfa_para.cpp:73
float GetTextIndent()
Definition cxfa_para.cpp:89
float GetSpaceAbove()
Definition cxfa_para.cpp:81
float GetMarginRight()
Definition cxfa_para.cpp:77
XFA_AttributeValue GetHorizontalAlign()
Definition cxfa_para.cpp:57
XFA_AttributeValue GetVerticalAlign()
Definition cxfa_para.cpp:63
float GetSpaceBelow()
Definition cxfa_para.cpp:85
float StartLayout(float fWidth)
WideString GetLinkURLAtPoint(const CFX_PointF &point)
CFX_SizeF CalcSize(const CFX_SizeF &minSize, const CFX_SizeF &maxSize)
bool DrawString(CFX_RenderDevice *pFxDevice, const CFX_Matrix &mtDoc2Device, const CFX_RectF &rtClip, size_t szBlockIndex)
float DoLayout(float fTextHeight)
float DoSplitLayout(size_t szBlockIndex, float fCalcHeight, float fTextHeight)
float Layout(const CFX_SizeF &size)
void ItemBlocks(const CFX_RectF &rtText, size_t szBlockIndex)
void SetDecls(std::vector< const CFX_CSSDeclaration * > &&decl)
void SetDisplay(CFX_CSSDisplay eDisplay)
void SetParentStyle(RetainPtr< const CFX_CSSComputedStyle > style)
RetainPtr< const CFX_CSSComputedStyle > GetParentStyle() const
CFX_CSSDisplay GetDisplay() const
const std::vector< const CFX_CSSDeclaration * > & GetDecls() const
int32_t GetUnderline(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
float GetFontSize(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
float GetTabInterval(const CFX_CSSComputedStyle *pStyle) const
bool GetTabstops(const CFX_CSSComputedStyle *pStyle, CXFA_TextTabstopsContext *pTabstopContext)
bool IsParsed() const
Context * GetParseContextFromMap(const CFX_XMLNode *pXMLNode)
XFA_AttributeValue GetUnderlinePeriod(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
XFA_AttributeValue GetVAlign(CXFA_TextProvider *pTextProvider) const
int32_t CountTabs(const CFX_CSSComputedStyle *pStyle) const
float GetBaseline(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
virtual ~CXFA_TextParser()
float GetLineHeight(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle, bool bFirst, float fVerScale) const
bool TagValidate(const WideString &str) const
int32_t GetHorScale(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle, const CFX_XMLNode *pXMLNode) const
RetainPtr< CFX_CSSComputedStyle > CreateRootStyle(CXFA_TextProvider *pTextProvider)
bool IsSpaceRun(const CFX_CSSComputedStyle *pStyle) const
RetainPtr< CFGAS_GEFont > GetFont(CXFA_FFDoc *doc, CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
int32_t GetLinethrough(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
void DoParse(const CFX_XMLNode *pXMLContainer, CXFA_TextProvider *pTextProvider)
FX_ARGB GetColor(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
int32_t GetVerScale(CXFA_TextProvider *pTextProvider, const CFX_CSSComputedStyle *pStyle) const
absl::optional< WideString > GetEmbeddedObj(const CXFA_TextProvider *pTextProvider, const CFX_XMLNode *pXMLNode)
void Trace(cppgc::Visitor *visitor) const
RetainPtr< CFX_CSSComputedStyle > ComputeStyle(const CFX_XMLNode *pXMLNode, RetainPtr< const CFX_CSSComputedStyle > pParentStyle)
WideString(wchar_t ch)
static WideString Format(const wchar_t *pFormat,...)
WideString & operator=(WideString &&that) noexcept
WideString & operator+=(wchar_t ch)
bool IsEmpty() const
Definition widestring.h:118
WideString & operator=(const WideString &that)
CharType Back() const
Definition widestring.h:152
bool EqualsASCII(ByteStringView that) const
Definition widestring.h:216
XFA_AttributeValue
Definition fxfa_basic.h:60
#define CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED
Definition heap.h:32
Definition heap.h:12