| OLD | NEW |
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 FXSYS_memcpy(m_ppMatchedDecls, ppDeclArray, | 59 FXSYS_memcpy(m_ppMatchedDecls, ppDeclArray, |
| 60 iDeclCount * sizeof(CFDE_CSSDeclaration*)); | 60 iDeclCount * sizeof(CFDE_CSSDeclaration*)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 CXFA_TextParser::CXFA_TextParser() : m_pUASheet(nullptr) {} | 63 CXFA_TextParser::CXFA_TextParser() : m_pUASheet(nullptr) {} |
| 64 | 64 |
| 65 CXFA_TextParser::~CXFA_TextParser() { | 65 CXFA_TextParser::~CXFA_TextParser() { |
| 66 if (m_pUASheet) | 66 if (m_pUASheet) |
| 67 m_pUASheet->Release(); | 67 m_pUASheet->Release(); |
| 68 | 68 |
| 69 FX_POSITION ps = m_mapXMLNodeToParseContext.GetStartPosition(); | 69 for (auto& pair : m_mapXMLNodeToParseContext) { |
| 70 while (ps) { | 70 if (pair.second) { |
| 71 CFDE_XMLNode* pXMLNode; | |
| 72 CXFA_TextParseContext* pParseContext; | |
| 73 m_mapXMLNodeToParseContext.GetNextAssoc(ps, pXMLNode, pParseContext); | |
| 74 if (pParseContext) | |
| 75 FXTARGET_DeleteWith(CXFA_TextParseContext, m_pAllocator.get(), | 71 FXTARGET_DeleteWith(CXFA_TextParseContext, m_pAllocator.get(), |
| 76 pParseContext); | 72 pair.second); |
| 73 } |
| 77 } | 74 } |
| 78 m_mapXMLNodeToParseContext.RemoveAll(); | |
| 79 } | 75 } |
| 76 |
| 80 void CXFA_TextParser::Reset() { | 77 void CXFA_TextParser::Reset() { |
| 81 FX_POSITION ps = m_mapXMLNodeToParseContext.GetStartPosition(); | 78 for (auto& pair : m_mapXMLNodeToParseContext) { |
| 82 while (ps) { | 79 if (pair.second) { |
| 83 CFDE_XMLNode* pXMLNode; | |
| 84 CXFA_TextParseContext* pParseContext; | |
| 85 m_mapXMLNodeToParseContext.GetNextAssoc(ps, pXMLNode, pParseContext); | |
| 86 if (pParseContext) | |
| 87 FXTARGET_DeleteWith(CXFA_TextParseContext, m_pAllocator.get(), | 80 FXTARGET_DeleteWith(CXFA_TextParseContext, m_pAllocator.get(), |
| 88 pParseContext); | 81 pair.second); |
| 82 } |
| 89 } | 83 } |
| 90 m_mapXMLNodeToParseContext.RemoveAll(); | 84 m_mapXMLNodeToParseContext.clear(); |
| 91 m_pAllocator.reset(); | 85 m_pAllocator.reset(); |
| 92 } | 86 } |
| 93 void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { | 87 void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { |
| 94 if (!pTextProvider) | 88 if (!pTextProvider) |
| 95 return; | 89 return; |
| 96 | 90 |
| 97 if (!m_pSelector) { | 91 if (!m_pSelector) { |
| 98 CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); | 92 CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); |
| 99 CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); | 93 CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); |
| 100 ASSERT(pFontMgr); | 94 ASSERT(pFontMgr); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 pParaStyle->SetNumberVerticalAlign(fBaseLine); | 214 pParaStyle->SetNumberVerticalAlign(fBaseLine); |
| 221 IFDE_CSSBoundaryStyle* pBoundarytyle = pParentStyle->GetBoundaryStyles(); | 215 IFDE_CSSBoundaryStyle* pBoundarytyle = pParentStyle->GetBoundaryStyles(); |
| 222 const FDE_CSSRECT* pRect = pBoundarytyle->GetMarginWidth(); | 216 const FDE_CSSRECT* pRect = pBoundarytyle->GetMarginWidth(); |
| 223 if (pRect) { | 217 if (pRect) { |
| 224 pBoundarytyle = pNewStyle->GetBoundaryStyles(); | 218 pBoundarytyle = pNewStyle->GetBoundaryStyles(); |
| 225 pBoundarytyle->SetMarginWidth(*pRect); | 219 pBoundarytyle->SetMarginWidth(*pRect); |
| 226 } | 220 } |
| 227 } | 221 } |
| 228 return pNewStyle; | 222 return pNewStyle; |
| 229 } | 223 } |
| 224 |
| 230 IFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle( | 225 IFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle( |
| 231 CFDE_XMLNode* pXMLNode, | 226 CFDE_XMLNode* pXMLNode, |
| 232 IFDE_CSSComputedStyle* pParentStyle) { | 227 IFDE_CSSComputedStyle* pParentStyle) { |
| 233 CXFA_TextParseContext* pContext = static_cast<CXFA_TextParseContext*>( | 228 auto it = m_mapXMLNodeToParseContext.find(pXMLNode); |
| 234 m_mapXMLNodeToParseContext.GetValueAt(pXMLNode)); | 229 if (it == m_mapXMLNodeToParseContext.end()) |
| 230 return nullptr; |
| 231 |
| 232 CXFA_TextParseContext* pContext = it->second; |
| 235 if (!pContext) | 233 if (!pContext) |
| 236 return nullptr; | 234 return nullptr; |
| 235 |
| 237 pContext->m_pParentStyle = pParentStyle; | 236 pContext->m_pParentStyle = pParentStyle; |
| 238 pParentStyle->Retain(); | 237 pParentStyle->Retain(); |
| 238 |
| 239 CXFA_CSSTagProvider tagProvider; | 239 CXFA_CSSTagProvider tagProvider; |
| 240 ParseTagInfo(pXMLNode, tagProvider); | 240 ParseTagInfo(pXMLNode, tagProvider); |
| 241 if (tagProvider.m_bContent) | 241 if (tagProvider.m_bContent) |
| 242 return nullptr; | 242 return nullptr; |
| 243 |
| 243 IFDE_CSSComputedStyle* pStyle = CreateStyle(pParentStyle); | 244 IFDE_CSSComputedStyle* pStyle = CreateStyle(pParentStyle); |
| 244 CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator(); | 245 CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator(); |
| 245 pCSSAccel->OnEnterTag(&tagProvider); | 246 pCSSAccel->OnEnterTag(&tagProvider); |
| 246 m_pSelector->ComputeStyle(&tagProvider, pContext->GetDecls(), | 247 m_pSelector->ComputeStyle(&tagProvider, pContext->GetDecls(), |
| 247 pContext->CountDecls(), pStyle); | 248 pContext->CountDecls(), pStyle); |
| 248 pCSSAccel->OnLeaveTag(&tagProvider); | 249 pCSSAccel->OnLeaveTag(&tagProvider); |
| 249 return pStyle; | 250 return pStyle; |
| 250 } | 251 } |
| 251 void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer, | 252 void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer, |
| 252 CXFA_TextProvider* pTextProvider) { | 253 CXFA_TextProvider* pTextProvider) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 const_cast<const CFDE_CSSDeclaration**>(DeclArray.GetData()); | 288 const_cast<const CFDE_CSSDeclaration**>(DeclArray.GetData()); |
| 288 m_pSelector->ComputeStyle(&tagProvider, ppMatchDecls, iMatchedDecls, | 289 m_pSelector->ComputeStyle(&tagProvider, ppMatchDecls, iMatchedDecls, |
| 289 pNewStyle); | 290 pNewStyle); |
| 290 pCSSAccel->OnLeaveTag(&tagProvider); | 291 pCSSAccel->OnLeaveTag(&tagProvider); |
| 291 if (iMatchedDecls > 0) { | 292 if (iMatchedDecls > 0) { |
| 292 pTextContext->SetDecls(ppMatchDecls, iMatchedDecls); | 293 pTextContext->SetDecls(ppMatchDecls, iMatchedDecls); |
| 293 } | 294 } |
| 294 eDisplay = pNewStyle->GetPositionStyles()->GetDisplay(); | 295 eDisplay = pNewStyle->GetPositionStyles()->GetDisplay(); |
| 295 } | 296 } |
| 296 pTextContext->SetDisplay(eDisplay); | 297 pTextContext->SetDisplay(eDisplay); |
| 297 m_mapXMLNodeToParseContext.SetAt(pXMLNode, pTextContext); | 298 m_mapXMLNodeToParseContext[pXMLNode] = pTextContext; |
| 298 } | 299 } |
| 299 for (CFDE_XMLNode* pXMLChild = | 300 for (CFDE_XMLNode* pXMLChild = |
| 300 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 301 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 301 pXMLChild; | 302 pXMLChild; |
| 302 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 303 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 303 ParseRichText(pXMLChild, pNewStyle); | 304 ParseRichText(pXMLChild, pNewStyle); |
| 304 } | 305 } |
| 305 if (pNewStyle) | 306 if (pNewStyle) |
| 306 pNewStyle->Release(); | 307 pNewStyle->Release(); |
| 307 } | 308 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (font) { | 417 if (font) { |
| 417 return font.GetFontSize(); | 418 return font.GetFontSize(); |
| 418 } | 419 } |
| 419 return 10; | 420 return 10; |
| 420 } | 421 } |
| 421 int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, | 422 int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, |
| 422 IFDE_CSSComputedStyle* pStyle, | 423 IFDE_CSSComputedStyle* pStyle, |
| 423 CFDE_XMLNode* pXMLNode) const { | 424 CFDE_XMLNode* pXMLNode) const { |
| 424 if (pStyle) { | 425 if (pStyle) { |
| 425 CFX_WideString wsValue; | 426 CFX_WideString wsValue; |
| 426 if (pStyle->GetCustomStyle(FX_WSTRC(L"xfa-font-horizontal-scale"), | 427 if (pStyle->GetCustomStyle(L"xfa-font-horizontal-scale", wsValue)) { |
| 427 wsValue)) { | |
| 428 return wsValue.GetInteger(); | 428 return wsValue.GetInteger(); |
| 429 } | 429 } |
| 430 while (pXMLNode) { | 430 while (pXMLNode) { |
| 431 CXFA_TextParseContext* pContext = static_cast<CXFA_TextParseContext*>( | 431 auto it = m_mapXMLNodeToParseContext.find(pXMLNode); |
| 432 m_mapXMLNodeToParseContext.GetValueAt(pXMLNode)); | 432 if (it != m_mapXMLNodeToParseContext.end()) { |
| 433 if (pContext && pContext->m_pParentStyle && | 433 CXFA_TextParseContext* pContext = it->second; |
| 434 pContext->m_pParentStyle->GetCustomStyle( | 434 if (pContext && pContext->m_pParentStyle && |
| 435 FX_WSTRC(L"xfa-font-horizontal-scale"), wsValue)) { | 435 pContext->m_pParentStyle->GetCustomStyle( |
| 436 return wsValue.GetInteger(); | 436 L"xfa-font-horizontal-scale", wsValue)) { |
| 437 return wsValue.GetInteger(); |
| 438 } |
| 437 } | 439 } |
| 438 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); | 440 pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
| 439 } | 441 } |
| 440 } | 442 } |
| 441 if (CXFA_Font font = pTextProvider->GetFontNode()) { | 443 if (CXFA_Font font = pTextProvider->GetFontNode()) { |
| 442 return static_cast<int32_t>(font.GetHorizontalScale()); | 444 return static_cast<int32_t>(font.GetHorizontalScale()); |
| 443 } | 445 } |
| 444 return 100; | 446 return 100; |
| 445 } | 447 } |
| 446 int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, | 448 int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 ws.MakeLower(); | 582 ws.MakeLower(); |
| 581 } | 583 } |
| 582 bool bRaw = (ws == FX_WSTRC(L"raw")); | 584 bool bRaw = (ws == FX_WSTRC(L"raw")); |
| 583 if (!bRaw && ws != FX_WSTRC(L"formatted")) { | 585 if (!bRaw && ws != FX_WSTRC(L"formatted")) { |
| 584 return false; | 586 return false; |
| 585 } | 587 } |
| 586 bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); | 588 bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); |
| 587 } | 589 } |
| 588 return bRet; | 590 return bRet; |
| 589 } | 591 } |
| 592 |
| 590 CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( | 593 CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( |
| 591 CFDE_XMLNode* pXMLNode) { | 594 CFDE_XMLNode* pXMLNode) { |
| 592 return (CXFA_TextParseContext*)m_mapXMLNodeToParseContext.GetValueAt( | 595 auto it = m_mapXMLNodeToParseContext.find(pXMLNode); |
| 593 pXMLNode); | 596 return it != m_mapXMLNodeToParseContext.end() ? it->second : nullptr; |
| 594 } | 597 } |
| 598 |
| 595 enum XFA_TABSTOPSSTATUS { | 599 enum XFA_TABSTOPSSTATUS { |
| 596 XFA_TABSTOPSSTATUS_Error, | 600 XFA_TABSTOPSSTATUS_Error, |
| 597 XFA_TABSTOPSSTATUS_EOS, | 601 XFA_TABSTOPSSTATUS_EOS, |
| 598 XFA_TABSTOPSSTATUS_None, | 602 XFA_TABSTOPSSTATUS_None, |
| 599 XFA_TABSTOPSSTATUS_Alignment, | 603 XFA_TABSTOPSSTATUS_Alignment, |
| 600 XFA_TABSTOPSSTATUS_StartLeader, | 604 XFA_TABSTOPSSTATUS_StartLeader, |
| 601 XFA_TABSTOPSSTATUS_Leader, | 605 XFA_TABSTOPSSTATUS_Leader, |
| 602 XFA_TABSTOPSSTATUS_Location, | 606 XFA_TABSTOPSSTATUS_Location, |
| 603 }; | 607 }; |
| 604 bool CXFA_TextParser::GetTabstops(IFDE_CSSComputedStyle* pStyle, | 608 bool CXFA_TextParser::GetTabstops(IFDE_CSSComputedStyle* pStyle, |
| (...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 m_tabstops.RemoveAll(); | 2100 m_tabstops.RemoveAll(); |
| 2097 m_iTabCount = 0; | 2101 m_iTabCount = 0; |
| 2098 } | 2102 } |
| 2099 | 2103 |
| 2100 void CXFA_TextTabstopsContext::Reset() { | 2104 void CXFA_TextTabstopsContext::Reset() { |
| 2101 m_iTabIndex = -1; | 2105 m_iTabIndex = -1; |
| 2102 m_bTabstops = false; | 2106 m_bTabstops = false; |
| 2103 m_fTabWidth = 0; | 2107 m_fTabWidth = 0; |
| 2104 m_fLeft = 0; | 2108 m_fLeft = 0; |
| 2105 } | 2109 } |
| OLD | NEW |