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/fde/css/fde_cssstyleselector.h" | 7 #include "xfa/fde/css/fde_cssstyleselector.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 void CFDE_CSSStyleSelector::ComputeStyle( | 419 void CFDE_CSSStyleSelector::ComputeStyle( |
420 CXFA_CSSTagProvider* pTag, | 420 CXFA_CSSTagProvider* pTag, |
421 const IFDE_CSSDeclaration** ppDeclArray, | 421 const IFDE_CSSDeclaration** ppDeclArray, |
422 int32_t iDeclCount, | 422 int32_t iDeclCount, |
423 IFDE_CSSComputedStyle* pDestStyle) { | 423 IFDE_CSSComputedStyle* pDestStyle) { |
424 FXSYS_assert(iDeclCount >= 0); | 424 FXSYS_assert(iDeclCount >= 0); |
425 FXSYS_assert(pDestStyle); | 425 FXSYS_assert(pDestStyle); |
426 | 426 |
427 static const uint32_t s_dwStyleHash = | 427 static const uint32_t s_dwStyleHash = FX_HashCode_GetW(L"style", true); |
428 FX_HashCode_String_GetW(L"style", 5, TRUE); | 428 static const uint32_t s_dwAlignHash = FX_HashCode_GetW(L"align", true); |
429 static const uint32_t s_dwAlignHash = | |
430 FX_HashCode_String_GetW(L"align", 5, TRUE); | |
431 | 429 |
432 if (!pTag->empty()) { | 430 if (!pTag->empty()) { |
433 if (!m_pInlineStyleStore) | 431 if (!m_pInlineStyleStore) |
434 m_pInlineStyleStore = FX_CreateAllocator(FX_ALLOCTYPE_Static, 2048, 0); | 432 m_pInlineStyleStore = FX_CreateAllocator(FX_ALLOCTYPE_Static, 2048, 0); |
435 | 433 |
436 CFDE_CSSDeclaration* pDecl = nullptr; | 434 CFDE_CSSDeclaration* pDecl = nullptr; |
437 for (auto it : *pTag) { | 435 for (auto it : *pTag) { |
438 CFX_WideString wsAttri = it.first; | 436 CFX_WideString wsAttri = it.first; |
439 CFX_WideString wsValue = it.second; | 437 CFX_WideString wsValue = it.second; |
440 | 438 uint32_t dwAttriHash = FX_HashCode_GetW(wsAttri.AsStringC(), true); |
441 uint32_t dwAttriHash = | |
442 FX_HashCode_String_GetW(wsAttri.c_str(), wsAttri.GetLength(), TRUE); | |
443 if (dwAttriHash == s_dwStyleHash) { | 439 if (dwAttriHash == s_dwStyleHash) { |
444 if (!pDecl) | 440 if (!pDecl) |
445 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; | 441 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; |
446 | 442 |
447 AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength()); | 443 AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength()); |
448 } else if (dwAttriHash == s_dwAlignHash) { | 444 } else if (dwAttriHash == s_dwAlignHash) { |
449 if (!pDecl) | 445 if (!pDecl) |
450 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; | 446 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; |
451 | 447 |
452 FDE_CSSPROPERTYARGS args; | 448 FDE_CSSPROPERTYARGS args; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 const FX_WCHAR* psz; | 554 const FX_WCHAR* psz; |
559 FDE_CSSPROPERTYARGS args; | 555 FDE_CSSPROPERTYARGS args; |
560 args.pStringCache = NULL; | 556 args.pStringCache = NULL; |
561 args.pStaticStore = m_pInlineStyleStore; | 557 args.pStaticStore = m_pInlineStyleStore; |
562 args.pProperty = NULL; | 558 args.pProperty = NULL; |
563 CFX_WideString wsName; | 559 CFX_WideString wsName; |
564 for (;;) { | 560 for (;;) { |
565 FDE_CSSSYNTAXSTATUS eStatus = pSyntax->DoSyntaxParse(); | 561 FDE_CSSSYNTAXSTATUS eStatus = pSyntax->DoSyntaxParse(); |
566 if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyName) { | 562 if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyName) { |
567 psz = pSyntax->GetCurrentString(iLen); | 563 psz = pSyntax->GetCurrentString(iLen); |
568 args.pProperty = FDE_GetCSSPropertyByName(psz, iLen); | 564 args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz, iLen)); |
569 if (args.pProperty == NULL) { | 565 if (args.pProperty == NULL) { |
570 wsName = CFX_WideStringC(psz, iLen); | 566 wsName = CFX_WideStringC(psz, iLen); |
571 } | 567 } |
572 } else if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyValue) { | 568 } else if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyValue) { |
573 if (args.pProperty != NULL) { | 569 if (args.pProperty != NULL) { |
574 psz = pSyntax->GetCurrentString(iLen); | 570 psz = pSyntax->GetCurrentString(iLen); |
575 if (iLen > 0) { | 571 if (iLen > 0) { |
576 pDecl->AddProperty(&args, psz, iLen); | 572 pDecl->AddProperty(&args, psz, iLen); |
577 } | 573 } |
578 } else if (iLen > 0) { | 574 } else if (iLen > 0) { |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 return FDE_CSSTEXTTRANSFORM_LowerCase; | 1784 return FDE_CSSTEXTTRANSFORM_LowerCase; |
1789 default: | 1785 default: |
1790 return FDE_CSSTEXTTRANSFORM_None; | 1786 return FDE_CSSTEXTTRANSFORM_None; |
1791 } | 1787 } |
1792 } | 1788 } |
1793 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant( | 1789 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant( |
1794 FDE_CSSPROPERTYVALUE eValue) { | 1790 FDE_CSSPROPERTYVALUE eValue) { |
1795 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps | 1791 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps |
1796 : FDE_CSSFONTVARIANT_Normal; | 1792 : FDE_CSSFONTVARIANT_Normal; |
1797 } | 1793 } |
OLD | NEW |