Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: xfa/fxfa/app/xfa_textlayout.cpp

Issue 1996623002: Remove CFX_DSPATemplate usage in CXFA_TextParser (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/app/xfa_textlayout.h ('k') | xfa/fxfa/app/xfa_textlayout_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/app/xfa_textlayout.h" 7 #include "xfa/fxfa/app/xfa_textlayout.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 213 }
214 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, 32, 214 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, 32,
215 sizeof(CXFA_CSSTagProvider)); 215 sizeof(CXFA_CSSTagProvider));
216 InitCSSData(pTextProvider); 216 InitCSSData(pTextProvider);
217 IFDE_CSSComputedStyle* pRootStyle = CreateRootStyle(pTextProvider); 217 IFDE_CSSComputedStyle* pRootStyle = CreateRootStyle(pTextProvider);
218 ParseRichText(pXMLContainer, pRootStyle); 218 ParseRichText(pXMLContainer, pRootStyle);
219 pRootStyle->Release(); 219 pRootStyle->Release();
220 } 220 }
221 void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, 221 void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
222 IFDE_CSSComputedStyle* pParentStyle) { 222 IFDE_CSSComputedStyle* pParentStyle) {
223 if (pXMLNode == NULL) { 223 if (!pXMLNode)
224 return; 224 return;
225 } 225
226 CXFA_CSSTagProvider tagProvider; 226 CXFA_CSSTagProvider tagProvider;
227 ParseTagInfo(pXMLNode, tagProvider); 227 ParseTagInfo(pXMLNode, tagProvider);
228 if (!tagProvider.m_bTagAviliable) { 228 if (!tagProvider.m_bTagAvailable)
229 return; 229 return;
230 } 230
231 IFDE_CSSComputedStyle* pNewStyle = NULL; 231 IFDE_CSSComputedStyle* pNewStyle = NULL;
232 if ((tagProvider.GetTagName() != FX_WSTRC(L"body")) || 232 if ((tagProvider.GetTagName() != FX_WSTRC(L"body")) ||
233 (tagProvider.GetTagName() != FX_WSTRC(L"html"))) { 233 (tagProvider.GetTagName() != FX_WSTRC(L"html"))) {
234 CXFA_TextParseContext* pTextContext = 234 CXFA_TextParseContext* pTextContext =
235 FXTARGET_NewWith(m_pAllocator) CXFA_TextParseContext; 235 FXTARGET_NewWith(m_pAllocator) CXFA_TextParseContext;
236 FDE_CSSDISPLAY eDisplay = FDE_CSSDISPLAY_Inline; 236 FDE_CSSDISPLAY eDisplay = FDE_CSSDISPLAY_Inline;
237 if (!tagProvider.m_bContent) { 237 if (!tagProvider.m_bContent) {
238 pNewStyle = CreateStyle(pParentStyle); 238 pNewStyle = CreateStyle(pParentStyle);
239 CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator(); 239 CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator();
240 pCSSAccel->OnEnterTag(&tagProvider); 240 pCSSAccel->OnEnterTag(&tagProvider);
(...skipping 15 matching lines...) Expand all
256 } 256 }
257 for (CFDE_XMLNode* pXMLChild = 257 for (CFDE_XMLNode* pXMLChild =
258 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); 258 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
259 pXMLChild; 259 pXMLChild;
260 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { 260 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) {
261 ParseRichText(pXMLChild, pNewStyle); 261 ParseRichText(pXMLChild, pNewStyle);
262 } 262 }
263 if (pNewStyle) 263 if (pNewStyle)
264 pNewStyle->Release(); 264 pNewStyle->Release();
265 } 265 }
266
267 bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const {
268 static const uint32_t s_XFATagName[] = {
269 0x61, // a
270 0x62, // b
271 0x69, // i
272 0x70, // p
273 0x0001f714, // br
274 0x00022a55, // li
275 0x000239bb, // ol
276 0x00025881, // ul
277 0x0bd37faa, // sub
278 0x0bd37fb8, // sup
279 0xa73e3af2, // span
280 0xb182eaae, // body
281 0xdb8ac455, // html
282 };
283 static const int32_t s_iCount = FX_ArraySize(s_XFATagName);
284
285 return std::binary_search(s_XFATagName, s_XFATagName + s_iCount,
286 FX_HashCode_GetW(wsName.AsStringC(), true));
287 }
288
266 void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode, 289 void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode,
267 CXFA_CSSTagProvider& tagProvider) { 290 CXFA_CSSTagProvider& tagProvider) {
268 static const uint32_t s_XFATagName[] = {
269 0x61, 0x62, 0x69, 0x70, 0x0001f714,
270 0x00022a55, 0x000239bb, 0x00025881, 0x0bd37faa, 0x0bd37fb8,
271 0xa73e3af2, 0xb182eaae, 0xdb8ac455,
272 };
273 CFX_WideString wsName; 291 CFX_WideString wsName;
274 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { 292 if (pXMLNode->GetType() == FDE_XMLNODE_Element) {
275 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); 293 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
276 pXMLElement->GetLocalTagName(wsName); 294 pXMLElement->GetLocalTagName(wsName);
277 tagProvider.SetTagNameObj(wsName); 295 tagProvider.SetTagNameObj(wsName);
278 uint32_t dwHashCode = FX_HashCode_GetW(wsName.AsStringC(), true); 296 tagProvider.m_bTagAvailable = TagValidate(wsName);
279 static const int32_t s_iCount = sizeof(s_XFATagName) / sizeof(uint32_t); 297
280 CFX_DSPATemplate<uint32_t> lookup;
281 tagProvider.m_bTagAviliable =
282 lookup.Lookup(dwHashCode, s_XFATagName, s_iCount) > -1;
283 CFX_WideString wsValue; 298 CFX_WideString wsValue;
284 pXMLElement->GetString(L"style", wsValue); 299 pXMLElement->GetString(L"style", wsValue);
285 if (!wsValue.IsEmpty()) { 300 if (!wsValue.IsEmpty()) {
286 tagProvider.SetAttribute(L"style", wsValue); 301 tagProvider.SetAttribute(L"style", wsValue);
287 } 302 }
288 } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { 303 } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) {
289 tagProvider.m_bTagAviliable = TRUE; 304 tagProvider.m_bTagAvailable = TRUE;
290 tagProvider.m_bContent = TRUE; 305 tagProvider.m_bContent = TRUE;
291 } 306 }
292 } 307 }
293 308
294 int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { 309 int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const {
295 CXFA_Para para = pTextProvider->GetParaNode(); 310 CXFA_Para para = pTextProvider->GetParaNode();
296 return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; 311 return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top;
297 } 312 }
298 313
299 FX_FLOAT CXFA_TextParser::GetTabInterval(IFDE_CSSComputedStyle* pStyle) const { 314 FX_FLOAT CXFA_TextParser::GetTabInterval(IFDE_CSSComputedStyle* pStyle) const {
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 tr.iLength = iLength; 1970 tr.iLength = iLength;
1956 tr.fFontSize = pPiece->fFontSize; 1971 tr.fFontSize = pPiece->fFontSize;
1957 tr.iBidiLevel = pPiece->iBidiLevel; 1972 tr.iBidiLevel = pPiece->iBidiLevel;
1958 tr.iCharRotation = 0; 1973 tr.iCharRotation = 0;
1959 tr.wLineBreakChar = L'\n'; 1974 tr.wLineBreakChar = L'\n';
1960 tr.iVerticalScale = pPiece->iVerScale; 1975 tr.iVerticalScale = pPiece->iVerScale;
1961 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; 1976 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab;
1962 tr.iHorizontalScale = pPiece->iHorScale; 1977 tr.iHorizontalScale = pPiece->iHorScale;
1963 return TRUE; 1978 return TRUE;
1964 } 1979 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_textlayout.h ('k') | xfa/fxfa/app/xfa_textlayout_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698