1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxfa/cxfa_textprovider.h"
#include <algorithm>
#include <memory>
#include <vector>
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "fxjs/cfxjse_engine.h"
#include "fxjs/cfxjse_value.h"
#include "fxjs/xfa/cjx_object.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/cxfa_ffapp.h"
#include "xfa/fxfa/cxfa_ffcheckbutton.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
#include "xfa/fxfa/cxfa_ffdocview.h"
#include "xfa/fxfa/cxfa_fffield.h"
#include "xfa/fxfa/cxfa_ffpageview.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
#include "xfa/fxfa/cxfa_fontmgr.h"
#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
#include "xfa/fxfa/parser/cxfa_caption.h"
#include "xfa/fxfa/parser/cxfa_font.h"
#include "xfa/fxfa/parser/cxfa_items.h"
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
#include "xfa/fxfa/parser/cxfa_localevalue.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_para.h"
#include "xfa/fxfa/parser/cxfa_value.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
#include "xfa/fxfa/parser/xfa_utils.h"
CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) {
bRichText = false;
if (m_eType == XFA_TEXTPROVIDERTYPE_Text) {
CXFA_Value* pValueNode =
m_pNode->GetChild<CXFA_Value>(0, XFA_Element::Value, false);
if (!pValueNode)
return nullptr;
CXFA_Node* pChildNode = pValueNode->GetFirstChild();
if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) {
Optional<WideString> contentType = pChildNode->JSObject()->TryAttribute(
XFA_Attribute::ContentType, false);
if (contentType && *contentType == L"text/html")
bRichText = true;
}
return pChildNode;
}
if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) {
CXFA_Node* pBind = m_pNode->GetBindData();
CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode();
ASSERT(pXMLNode);
for (CFX_XMLNode* pXMLChild =
pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild);
pXMLChild;
pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) {
if (pXMLChild->GetType() == FX_XMLNODE_Element) {
CFX_XMLElement* pElement = static_cast<CFX_XMLElement*>(pXMLChild);
if (XFA_RecognizeRichText(pElement))
bRichText = true;
}
}
return pBind;
}
if (m_eType == XFA_TEXTPROVIDERTYPE_Caption) {
CXFA_Caption* pCaptionNode =
m_pNode->GetChild<CXFA_Caption>(0, XFA_Element::Caption, false);
if (!pCaptionNode)
return nullptr;
CXFA_Value* pValueNode =
pCaptionNode->GetChild<CXFA_Value>(0, XFA_Element::Value, false);
if (!pValueNode)
return nullptr;
CXFA_Node* pChildNode = pValueNode->GetFirstChild();
if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) {
Optional<WideString> contentType = pChildNode->JSObject()->TryAttribute(
XFA_Attribute::ContentType, false);
if (contentType && *contentType == L"text/html")
bRichText = true;
}
return pChildNode;
}
CXFA_Items* pItemNode =
m_pNode->GetChild<CXFA_Items>(0, XFA_Element::Items, false);
if (!pItemNode)
return nullptr;
CXFA_Node* pNode = pItemNode->GetFirstChild();
while (pNode) {
WideString wsName = pNode->JSObject()->GetCData(XFA_Attribute::Name);
if (m_eType == XFA_TEXTPROVIDERTYPE_Rollover && wsName == L"rollover")
return pNode;
if (m_eType == XFA_TEXTPROVIDERTYPE_Down && wsName == L"down")
return pNode;
pNode = pNode->GetNextSibling();
}
return nullptr;
}
CXFA_Para* CXFA_TextProvider::GetParaIfExists() {
if (m_eType == XFA_TEXTPROVIDERTYPE_Text)
return m_pNode->GetParaIfExists();
CXFA_Caption* pNode =
m_pNode->GetChild<CXFA_Caption>(0, XFA_Element::Caption, false);
return pNode->GetChild<CXFA_Para>(0, XFA_Element::Para, false);
}
CXFA_Font* CXFA_TextProvider::GetFontIfExists() {
if (m_eType == XFA_TEXTPROVIDERTYPE_Text)
return m_pNode->GetFontIfExists();
CXFA_Caption* pNode =
m_pNode->GetChild<CXFA_Caption>(0, XFA_Element::Caption, false);
CXFA_Font* font = pNode->GetChild<CXFA_Font>(0, XFA_Element::Font, false);
return font ? font : m_pNode->GetFontIfExists();
}
bool CXFA_TextProvider::IsCheckButtonAndAutoWidth() {
if (m_pNode->GetFFWidgetType() != XFA_FFWidgetType::kCheckButton)
return false;
return !m_pNode->TryWidth();
}
bool CXFA_TextProvider::GetEmbbedObj(bool bURI,
bool bRaw,
const WideString& wsAttr,
WideString& wsValue) {
if (m_eType != XFA_TEXTPROVIDERTYPE_Text)
return false;
if (!bURI)
return false;
CXFA_Node* pParent = m_pNode->GetParent();
CXFA_Document* pDocument = m_pNode->GetDocument();
CXFA_Node* pIDNode = nullptr;
if (pParent)
pIDNode = pDocument->GetNodeByID(pParent, wsAttr.AsStringView());
if (!pIDNode) {
pIDNode = pDocument->GetNodeByID(
ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Form)),
wsAttr.AsStringView());
}
if (!pIDNode || !pIDNode->IsWidgetReady())
return false;
wsValue = pIDNode->GetValue(XFA_VALUEPICTURE_Display);
return true;
}
|