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/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fgas/crt/fgas_algorithm.h" | 10 #include "xfa/fgas/crt/fgas_algorithm.h" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 {0xF6EFFF31, 0xff008000}, | 550 {0xF6EFFF31, 0xff008000}, |
551 }; | 551 }; |
552 static const FDE_CSSPERSUDOTABLE g_FDE_CSSPersudoType[] = { | 552 static const FDE_CSSPERSUDOTABLE g_FDE_CSSPersudoType[] = { |
553 {FDE_CSSPERSUDO_After, L":after", 0x16EE1FEC}, | 553 {FDE_CSSPERSUDO_After, L":after", 0x16EE1FEC}, |
554 {FDE_CSSPERSUDO_Before, L":before", 0x7DCDDE2D}, | 554 {FDE_CSSPERSUDO_Before, L":before", 0x7DCDDE2D}, |
555 }; | 555 }; |
556 FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo) { | 556 FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo) { |
557 return (ePersudo < FDE_CSSPERSUDO_NONE) ? (g_FDE_CSSPersudoType + ePersudo) | 557 return (ePersudo < FDE_CSSPERSUDO_NONE) ? (g_FDE_CSSPersudoType + ePersudo) |
558 : NULL; | 558 : NULL; |
559 } | 559 } |
560 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const FX_WCHAR* pszName, | 560 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName( |
561 int32_t iLength) { | 561 const CFX_WideStringC& wsName) { |
562 FXSYS_assert(pszName != NULL && iLength > 0); | 562 FXSYS_assert(!wsName.IsEmpty()); |
563 uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); | 563 uint32_t dwHash = FX_HashCode_GetW(wsName, true); |
564 int32_t iEnd = FDE_CSSPROPERTY_MAX - 1; | 564 int32_t iEnd = FDE_CSSPROPERTY_MAX - 1; |
565 int32_t iMid, iStart = 0; | 565 int32_t iMid, iStart = 0; |
566 uint32_t dwMid; | 566 uint32_t dwMid; |
567 do { | 567 do { |
568 iMid = (iStart + iEnd) / 2; | 568 iMid = (iStart + iEnd) / 2; |
569 dwMid = g_FDE_CSSProperties[iMid].dwHash; | 569 dwMid = g_FDE_CSSProperties[iMid].dwHash; |
570 if (dwHash == dwMid) { | 570 if (dwHash == dwMid) { |
571 return g_FDE_CSSProperties + iMid; | 571 return g_FDE_CSSProperties + iMid; |
572 } else if (dwHash > dwMid) { | 572 } else if (dwHash > dwMid) { |
573 iStart = iMid + 1; | 573 iStart = iMid + 1; |
574 } else { | 574 } else { |
575 iEnd = iMid - 1; | 575 iEnd = iMid - 1; |
576 } | 576 } |
577 } while (iStart <= iEnd); | 577 } while (iStart <= iEnd); |
578 return NULL; | 578 return NULL; |
579 } | 579 } |
580 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName) { | 580 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName) { |
581 return (eName < FDE_CSSPROPERTY_MAX) ? (g_FDE_CSSProperties + eName) : NULL; | 581 return (eName < FDE_CSSPROPERTY_MAX) ? (g_FDE_CSSProperties + eName) : NULL; |
582 } | 582 } |
583 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName( | 583 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName( |
584 const FX_WCHAR* pszName, | 584 const CFX_WideStringC& wsName) { |
585 int32_t iLength) { | 585 FXSYS_assert(!wsName.IsEmpty()); |
586 FXSYS_assert(pszName != NULL && iLength > 0); | 586 uint32_t dwHash = FX_HashCode_GetW(wsName, true); |
587 uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); | |
588 int32_t iEnd = FDE_CSSPROPERTYVALUE_MAX - 1; | 587 int32_t iEnd = FDE_CSSPROPERTYVALUE_MAX - 1; |
589 int32_t iMid, iStart = 0; | 588 int32_t iMid, iStart = 0; |
590 uint32_t dwMid; | 589 uint32_t dwMid; |
591 do { | 590 do { |
592 iMid = (iStart + iEnd) / 2; | 591 iMid = (iStart + iEnd) / 2; |
593 dwMid = g_FDE_CSSPropertyValues[iMid].dwHash; | 592 dwMid = g_FDE_CSSPropertyValues[iMid].dwHash; |
594 if (dwHash == dwMid) { | 593 if (dwHash == dwMid) { |
595 return g_FDE_CSSPropertyValues + iMid; | 594 return g_FDE_CSSPropertyValues + iMid; |
596 } else if (dwHash > dwMid) { | 595 } else if (dwHash > dwMid) { |
597 iStart = iMid + 1; | 596 iStart = iMid + 1; |
598 } else { | 597 } else { |
599 iEnd = iMid - 1; | 598 iEnd = iMid - 1; |
600 } | 599 } |
601 } while (iStart <= iEnd); | 600 } while (iStart <= iEnd); |
602 return NULL; | 601 return NULL; |
603 } | 602 } |
604 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum( | 603 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum( |
605 FDE_CSSPROPERTYVALUE eName) { | 604 FDE_CSSPROPERTYVALUE eName) { |
606 return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) | 605 return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) |
607 : NULL; | 606 : NULL; |
608 } | 607 } |
609 FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName, | 608 FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( |
610 int32_t iLength) { | 609 const CFX_WideStringC& wsName) { |
611 FXSYS_assert(pszName != NULL && iLength > 0); | 610 FXSYS_assert(!wsName.IsEmpty()); |
612 uint16_t wHash = (uint16_t)FX_HashCode_String_GetW(pszName, iLength, TRUE); | 611 uint16_t wHash = FX_HashCode_GetW(wsName, true); |
613 int32_t iEnd = | 612 int32_t iEnd = |
614 sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1; | 613 sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1; |
615 int32_t iMid, iStart = 0; | 614 int32_t iMid, iStart = 0; |
616 uint16_t uMid; | 615 uint16_t uMid; |
617 do { | 616 do { |
618 iMid = (iStart + iEnd) / 2; | 617 iMid = (iStart + iEnd) / 2; |
619 uMid = g_FDE_CSSMediaTypes[iMid].wHash; | 618 uMid = g_FDE_CSSMediaTypes[iMid].wHash; |
620 if (wHash == uMid) { | 619 if (wHash == uMid) { |
621 return g_FDE_CSSMediaTypes + iMid; | 620 return g_FDE_CSSMediaTypes + iMid; |
622 } else if (wHash > uMid) { | 621 } else if (wHash > uMid) { |
623 iStart = iMid + 1; | 622 iStart = iMid + 1; |
624 } else { | 623 } else { |
625 iEnd = iMid - 1; | 624 iEnd = iMid - 1; |
626 } | 625 } |
627 } while (iStart <= iEnd); | 626 } while (iStart <= iEnd); |
628 return NULL; | 627 return NULL; |
629 } | 628 } |
630 FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName, | 629 FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( |
631 int32_t iLength) { | 630 const CFX_WideStringC& wsName) { |
632 FXSYS_assert(pszName != NULL && iLength > 0); | 631 FXSYS_assert(!wsName.IsEmpty()); |
633 uint16_t wHash = (uint16_t)FX_HashCode_String_GetW(pszName, iLength, TRUE); | 632 uint16_t wHash = FX_HashCode_GetW(wsName, true); |
634 int32_t iEnd = | 633 int32_t iEnd = |
635 sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLENGTHUNITTABLE) - 1; | 634 sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLENGTHUNITTABLE) - 1; |
636 int32_t iMid, iStart = 0; | 635 int32_t iMid, iStart = 0; |
637 uint16_t wMid; | 636 uint16_t wMid; |
638 do { | 637 do { |
639 iMid = (iStart + iEnd) / 2; | 638 iMid = (iStart + iEnd) / 2; |
640 wMid = g_FDE_CSSLengthUnits[iMid].wHash; | 639 wMid = g_FDE_CSSLengthUnits[iMid].wHash; |
641 if (wHash == wMid) { | 640 if (wHash == wMid) { |
642 return g_FDE_CSSLengthUnits + iMid; | 641 return g_FDE_CSSLengthUnits + iMid; |
643 } else if (wHash > wMid) { | 642 } else if (wHash > wMid) { |
644 iStart = iMid + 1; | 643 iStart = iMid + 1; |
645 } else { | 644 } else { |
646 iEnd = iMid - 1; | 645 iEnd = iMid - 1; |
647 } | 646 } |
648 } while (iStart <= iEnd); | 647 } while (iStart <= iEnd); |
649 return NULL; | 648 return NULL; |
650 } | 649 } |
651 FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const FX_WCHAR* pszName, | 650 FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { |
652 int32_t iLength) { | 651 FXSYS_assert(!wsName.IsEmpty()); |
653 FXSYS_assert(pszName != NULL && iLength > 0); | 652 uint32_t dwHash = FX_HashCode_GetW(wsName, true); |
654 uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); | |
655 int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; | 653 int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; |
656 int32_t iMid, iStart = 0; | 654 int32_t iMid, iStart = 0; |
657 uint32_t dwMid; | 655 uint32_t dwMid; |
658 do { | 656 do { |
659 iMid = (iStart + iEnd) / 2; | 657 iMid = (iStart + iEnd) / 2; |
660 dwMid = g_FDE_CSSColors[iMid].dwHash; | 658 dwMid = g_FDE_CSSColors[iMid].dwHash; |
661 if (dwHash == dwMid) { | 659 if (dwHash == dwMid) { |
662 return g_FDE_CSSColors + iMid; | 660 return g_FDE_CSSColors + iMid; |
663 } else if (dwHash > dwMid) { | 661 } else if (dwHash > dwMid) { |
664 iStart = iMid + 1; | 662 iStart = iMid + 1; |
(...skipping 12 matching lines...) Expand all Loading... |
677 fValue = FX_wcstof(pszValue, iValueLen, &iUsedLen); | 675 fValue = FX_wcstof(pszValue, iValueLen, &iUsedLen); |
678 if (iUsedLen <= 0) { | 676 if (iUsedLen <= 0) { |
679 return FALSE; | 677 return FALSE; |
680 } | 678 } |
681 iValueLen -= iUsedLen; | 679 iValueLen -= iUsedLen; |
682 pszValue += iUsedLen; | 680 pszValue += iUsedLen; |
683 eUnit = FDE_CSSPRIMITIVETYPE_Number; | 681 eUnit = FDE_CSSPRIMITIVETYPE_Number; |
684 if (iValueLen >= 1 && *pszValue == '%') { | 682 if (iValueLen >= 1 && *pszValue == '%') { |
685 eUnit = FDE_CSSPRIMITIVETYPE_Percent; | 683 eUnit = FDE_CSSPRIMITIVETYPE_Percent; |
686 } else if (iValueLen == 2) { | 684 } else if (iValueLen == 2) { |
687 FDE_LPCCSSLENGTHUNITTABLE pUnit = FDE_GetCSSLengthUnitByName(pszValue, 2); | 685 FDE_LPCCSSLENGTHUNITTABLE pUnit = |
| 686 FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); |
688 if (pUnit != NULL) { | 687 if (pUnit != NULL) { |
689 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; | 688 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; |
690 } | 689 } |
691 } | 690 } |
692 return TRUE; | 691 return TRUE; |
693 } | 692 } |
694 | 693 |
695 FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue, | 694 FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue, |
696 int32_t iValueLen, | 695 int32_t iValueLen, |
697 int32_t& iOffset, | 696 int32_t& iOffset, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) { | 762 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) { |
764 return FALSE; | 763 return FALSE; |
765 } | 764 } |
766 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent | 765 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent |
767 ? FXSYS_round(fValue * 2.55f) | 766 ? FXSYS_round(fValue * 2.55f) |
768 : FXSYS_round(fValue); | 767 : FXSYS_round(fValue); |
769 } | 768 } |
770 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); | 769 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); |
771 return TRUE; | 770 return TRUE; |
772 } else { | 771 } else { |
773 FDE_LPCCSSCOLORTABLE pColor = FDE_GetCSSColorByName(pszValue, iValueLen); | 772 FDE_LPCCSSCOLORTABLE pColor = |
| 773 FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); |
774 if (pColor != NULL) { | 774 if (pColor != NULL) { |
775 dwColor = pColor->dwValue; | 775 dwColor = pColor->dwValue; |
776 return TRUE; | 776 return TRUE; |
777 } | 777 } |
778 } | 778 } |
779 return FALSE; | 779 return FALSE; |
780 } | 780 } |
781 | 781 |
782 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MEMAllocator* pStaticStore, | 782 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MEMAllocator* pStaticStore, |
783 const CFDE_CSSValueArray& list) { | 783 const CFDE_CSSValueArray& list) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 } | 880 } |
881 while (iBracketCount > 0 && m_pCur < m_pEnd) { | 881 while (iBracketCount > 0 && m_pCur < m_pEnd) { |
882 if (*m_pCur == ')') { | 882 if (*m_pCur == ')') { |
883 iBracketCount--; | 883 iBracketCount--; |
884 } | 884 } |
885 m_pCur++; | 885 m_pCur++; |
886 } | 886 } |
887 } | 887 } |
888 return m_pCur - pStart; | 888 return m_pCur - pStart; |
889 } | 889 } |
OLD | NEW |