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_cssdatatable.h" | 7 #include "xfa/fde/css/fde_cssdatatable.h" |
8 | 8 |
9 #include "core/fxcrt/fx_ext.h" | 9 #include "core/fxcrt/fx_ext.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 {0x031B47FE, 0xff000080}, {0x0BB8DF5B, 0xffff0000}, | 546 {0x031B47FE, 0xff000080}, {0x0BB8DF5B, 0xffff0000}, |
547 {0x0D82A78C, 0xff800000}, {0x2ACC82E8, 0xff00ffff}, | 547 {0x0D82A78C, 0xff800000}, {0x2ACC82E8, 0xff00ffff}, |
548 {0x2D083986, 0xff008080}, {0x4A6A6195, 0xffc0c0c0}, | 548 {0x2D083986, 0xff008080}, {0x4A6A6195, 0xffc0c0c0}, |
549 {0x546A8EF3, 0xff808080}, {0x65C9169C, 0xffffa500}, | 549 {0x546A8EF3, 0xff808080}, {0x65C9169C, 0xffffa500}, |
550 {0x8422BB61, 0xffffffff}, {0x9271A558, 0xff800080}, | 550 {0x8422BB61, 0xffffffff}, {0x9271A558, 0xff800080}, |
551 {0xA65A3EE3, 0xffff00ff}, {0xB1345708, 0xff0000ff}, | 551 {0xA65A3EE3, 0xffff00ff}, {0xB1345708, 0xff0000ff}, |
552 {0xB6D2CF1F, 0xff808000}, {0xD19B5E1C, 0xffffff00}, | 552 {0xB6D2CF1F, 0xff808000}, {0xD19B5E1C, 0xffffff00}, |
553 {0xDB64391D, 0xff000000}, {0xF616D507, 0xff00ff00}, | 553 {0xDB64391D, 0xff000000}, {0xF616D507, 0xff00ff00}, |
554 {0xF6EFFF31, 0xff008000}, | 554 {0xF6EFFF31, 0xff008000}, |
555 }; | 555 }; |
556 static const FDE_CSSPERSUDOTABLE g_FDE_CSSPersudoType[] = { | 556 static const FDE_CSSPSEUDOTABLE g_FDE_CSSPseudoType[] = { |
557 {FDE_CSSPERSUDO_After, L":after", 0x16EE1FEC}, | 557 {FDE_CSSPSEUDO_After, L":after", 0x16EE1FEC}, |
558 {FDE_CSSPERSUDO_Before, L":before", 0x7DCDDE2D}, | 558 {FDE_CSSPSEUDO_Before, L":before", 0x7DCDDE2D}, |
559 }; | 559 }; |
560 FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo) { | 560 const FDE_CSSPSEUDOTABLE* FDE_GetCSSPseudoByEnum(FDE_CSSPSEUDO ePseudo) { |
561 return (ePersudo < FDE_CSSPERSUDO_NONE) ? (g_FDE_CSSPersudoType + ePersudo) | 561 return ePseudo < FDE_CSSPSEUDO_NONE ? g_FDE_CSSPseudoType + ePseudo : nullptr; |
562 : nullptr; | |
563 } | 562 } |
564 const FDE_CSSPROPERTYTABLE* FDE_GetCSSPropertyByName( | 563 const FDE_CSSPROPERTYTABLE* FDE_GetCSSPropertyByName( |
565 const CFX_WideStringC& wsName) { | 564 const CFX_WideStringC& wsName) { |
566 ASSERT(!wsName.IsEmpty()); | 565 ASSERT(!wsName.IsEmpty()); |
567 uint32_t dwHash = FX_HashCode_GetW(wsName, true); | 566 uint32_t dwHash = FX_HashCode_GetW(wsName, true); |
568 int32_t iEnd = FDE_CSSPROPERTY_MAX - 1; | 567 int32_t iEnd = FDE_CSSPROPERTY_MAX - 1; |
569 int32_t iMid, iStart = 0; | 568 int32_t iMid, iStart = 0; |
570 uint32_t dwMid; | 569 uint32_t dwMid; |
571 do { | 570 do { |
572 iMid = (iStart + iEnd) / 2; | 571 iMid = (iStart + iEnd) / 2; |
(...skipping 30 matching lines...) Expand all Loading... |
603 iEnd = iMid - 1; | 602 iEnd = iMid - 1; |
604 } | 603 } |
605 } while (iStart <= iEnd); | 604 } while (iStart <= iEnd); |
606 return nullptr; | 605 return nullptr; |
607 } | 606 } |
608 const FDE_CSSPROPERTYVALUETABLE* FDE_GetCSSPropertyValueByEnum( | 607 const FDE_CSSPROPERTYVALUETABLE* FDE_GetCSSPropertyValueByEnum( |
609 FDE_CSSPROPERTYVALUE eName) { | 608 FDE_CSSPROPERTYVALUE eName) { |
610 return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) | 609 return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) |
611 : nullptr; | 610 : nullptr; |
612 } | 611 } |
613 FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( | 612 const FDE_CSSMEDIATYPETABLE* FDE_GetCSSMediaTypeByName( |
614 const CFX_WideStringC& wsName) { | 613 const CFX_WideStringC& wsName) { |
615 ASSERT(!wsName.IsEmpty()); | 614 ASSERT(!wsName.IsEmpty()); |
616 uint16_t wHash = FX_HashCode_GetW(wsName, true); | 615 uint16_t wHash = FX_HashCode_GetW(wsName, true); |
617 int32_t iEnd = | 616 int32_t iEnd = |
618 sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1; | 617 sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1; |
619 int32_t iMid, iStart = 0; | 618 int32_t iMid, iStart = 0; |
620 uint16_t uMid; | 619 uint16_t uMid; |
621 do { | 620 do { |
622 iMid = (iStart + iEnd) / 2; | 621 iMid = (iStart + iEnd) / 2; |
623 uMid = g_FDE_CSSMediaTypes[iMid].wHash; | 622 uMid = g_FDE_CSSMediaTypes[iMid].wHash; |
624 if (wHash == uMid) { | 623 if (wHash == uMid) { |
625 return g_FDE_CSSMediaTypes + iMid; | 624 return g_FDE_CSSMediaTypes + iMid; |
626 } else if (wHash > uMid) { | 625 } else if (wHash > uMid) { |
627 iStart = iMid + 1; | 626 iStart = iMid + 1; |
628 } else { | 627 } else { |
629 iEnd = iMid - 1; | 628 iEnd = iMid - 1; |
630 } | 629 } |
631 } while (iStart <= iEnd); | 630 } while (iStart <= iEnd); |
632 return nullptr; | 631 return nullptr; |
633 } | 632 } |
634 FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( | 633 |
| 634 const FDE_CSSLENGTHUNITTABLE* FDE_GetCSSLengthUnitByName( |
635 const CFX_WideStringC& wsName) { | 635 const CFX_WideStringC& wsName) { |
636 ASSERT(!wsName.IsEmpty()); | 636 ASSERT(!wsName.IsEmpty()); |
637 uint16_t wHash = FX_HashCode_GetW(wsName, true); | 637 uint16_t wHash = FX_HashCode_GetW(wsName, true); |
638 int32_t iEnd = | 638 int32_t iEnd = |
639 sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLENGTHUNITTABLE) - 1; | 639 sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLENGTHUNITTABLE) - 1; |
640 int32_t iMid, iStart = 0; | 640 int32_t iMid, iStart = 0; |
641 uint16_t wMid; | 641 uint16_t wMid; |
642 do { | 642 do { |
643 iMid = (iStart + iEnd) / 2; | 643 iMid = (iStart + iEnd) / 2; |
644 wMid = g_FDE_CSSLengthUnits[iMid].wHash; | 644 wMid = g_FDE_CSSLengthUnits[iMid].wHash; |
645 if (wHash == wMid) { | 645 if (wHash == wMid) { |
646 return g_FDE_CSSLengthUnits + iMid; | 646 return g_FDE_CSSLengthUnits + iMid; |
647 } else if (wHash > wMid) { | 647 } else if (wHash > wMid) { |
648 iStart = iMid + 1; | 648 iStart = iMid + 1; |
649 } else { | 649 } else { |
650 iEnd = iMid - 1; | 650 iEnd = iMid - 1; |
651 } | 651 } |
652 } while (iStart <= iEnd); | 652 } while (iStart <= iEnd); |
653 return nullptr; | 653 return nullptr; |
654 } | 654 } |
655 FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { | 655 |
| 656 const FDE_CSSCOLORTABLE* FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { |
656 ASSERT(!wsName.IsEmpty()); | 657 ASSERT(!wsName.IsEmpty()); |
657 uint32_t dwHash = FX_HashCode_GetW(wsName, true); | 658 uint32_t dwHash = FX_HashCode_GetW(wsName, true); |
658 int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; | 659 int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; |
659 int32_t iMid, iStart = 0; | 660 int32_t iMid, iStart = 0; |
660 uint32_t dwMid; | 661 uint32_t dwMid; |
661 do { | 662 do { |
662 iMid = (iStart + iEnd) / 2; | 663 iMid = (iStart + iEnd) / 2; |
663 dwMid = g_FDE_CSSColors[iMid].dwHash; | 664 dwMid = g_FDE_CSSColors[iMid].dwHash; |
664 if (dwHash == dwMid) { | 665 if (dwHash == dwMid) { |
665 return g_FDE_CSSColors + iMid; | 666 return g_FDE_CSSColors + iMid; |
(...skipping 15 matching lines...) Expand all Loading... |
681 fValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen); | 682 fValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen); |
682 if (iUsedLen <= 0) | 683 if (iUsedLen <= 0) |
683 return false; | 684 return false; |
684 | 685 |
685 iValueLen -= iUsedLen; | 686 iValueLen -= iUsedLen; |
686 pszValue += iUsedLen; | 687 pszValue += iUsedLen; |
687 eUnit = FDE_CSSPRIMITIVETYPE_Number; | 688 eUnit = FDE_CSSPRIMITIVETYPE_Number; |
688 if (iValueLen >= 1 && *pszValue == '%') { | 689 if (iValueLen >= 1 && *pszValue == '%') { |
689 eUnit = FDE_CSSPRIMITIVETYPE_Percent; | 690 eUnit = FDE_CSSPRIMITIVETYPE_Percent; |
690 } else if (iValueLen == 2) { | 691 } else if (iValueLen == 2) { |
691 FDE_LPCCSSLENGTHUNITTABLE pUnit = | 692 const FDE_CSSLENGTHUNITTABLE* pUnit = |
692 FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); | 693 FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); |
693 if (pUnit) | 694 if (pUnit) |
694 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; | 695 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; |
695 } | 696 } |
696 return true; | 697 return true; |
697 } | 698 } |
698 | 699 |
699 bool FDE_ParseCSSString(const FX_WCHAR* pszValue, | 700 bool FDE_ParseCSSString(const FX_WCHAR* pszValue, |
700 int32_t iValueLen, | 701 int32_t iValueLen, |
701 int32_t* iOffset, | 702 int32_t* iOffset, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 return false; | 772 return false; |
772 | 773 |
773 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent | 774 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent |
774 ? FXSYS_round(fValue * 2.55f) | 775 ? FXSYS_round(fValue * 2.55f) |
775 : FXSYS_round(fValue); | 776 : FXSYS_round(fValue); |
776 } | 777 } |
777 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); | 778 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); |
778 return true; | 779 return true; |
779 } | 780 } |
780 | 781 |
781 FDE_LPCCSSCOLORTABLE pColor = | 782 const FDE_CSSCOLORTABLE* pColor = |
782 FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); | 783 FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); |
783 if (!pColor) | 784 if (!pColor) |
784 return false; | 785 return false; |
785 | 786 |
786 dwColor = pColor->dwValue; | 787 dwColor = pColor->dwValue; |
787 return true; | 788 return true; |
788 } | 789 } |
789 | 790 |
790 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore, | 791 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore, |
791 const CFDE_CSSValueArray& list) { | 792 const CFDE_CSSValueArray& list) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 | 961 |
961 int32_t CFDE_CSSPrimitiveValue::CountArgs() const { | 962 int32_t CFDE_CSSPrimitiveValue::CountArgs() const { |
962 ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); | 963 ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); |
963 return m_pFunction->CountArgs(); | 964 return m_pFunction->CountArgs(); |
964 } | 965 } |
965 | 966 |
966 IFDE_CSSValue* CFDE_CSSPrimitiveValue::GetArgs(int32_t index) const { | 967 IFDE_CSSValue* CFDE_CSSPrimitiveValue::GetArgs(int32_t index) const { |
967 ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); | 968 ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); |
968 return m_pFunction->GetArgs(index); | 969 return m_pFunction->GetArgs(index); |
969 } | 970 } |
OLD | NEW |