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

Side by Side Diff: xfa/fde/css/fde_cssdatatable.cpp

Issue 1992033002: fgas/ code cleanup. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master 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
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/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"
11 #include "xfa/fgas/crt/fgas_codepage.h" 11 #include "xfa/fgas/crt/fgas_codepage.h"
12 #include "xfa/fgas/crt/fgas_system.h" 12 #include "xfa/fgas/crt/fgas_system.h"
13 13
14 namespace {
15
16 uint8_t Hex2Dec(uint8_t hexHigh, uint8_t hexLow) {
17 return (FXSYS_toHexDigit(hexHigh) << 4) + FXSYS_toHexDigit(hexLow);
18 }
19
20 } // namespace
21
14 FX_BOOL FDE_CSSLengthToFloat(const FDE_CSSLENGTH& len, 22 FX_BOOL FDE_CSSLengthToFloat(const FDE_CSSLENGTH& len,
15 FX_FLOAT fPercentBase, 23 FX_FLOAT fPercentBase,
16 FX_FLOAT& fResult) { 24 FX_FLOAT& fResult) {
17 switch (len.GetUnit()) { 25 switch (len.GetUnit()) {
18 case FDE_CSSLENGTHUNIT_Point: 26 case FDE_CSSLENGTHUNIT_Point:
19 fResult = len.GetValue(); 27 fResult = len.GetValue();
20 return TRUE; 28 return TRUE;
21 case FDE_CSSLENGTHUNIT_Percent: 29 case FDE_CSSLENGTHUNIT_Percent:
22 fResult = len.GetValue() * fPercentBase; 30 fResult = len.GetValue() * fPercentBase;
23 return TRUE; 31 return TRUE;
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 if (dwHash == dwMid) { 667 if (dwHash == dwMid) {
660 return g_FDE_CSSColors + iMid; 668 return g_FDE_CSSColors + iMid;
661 } else if (dwHash > dwMid) { 669 } else if (dwHash > dwMid) {
662 iStart = iMid + 1; 670 iStart = iMid + 1;
663 } else { 671 } else {
664 iEnd = iMid - 1; 672 iEnd = iMid - 1;
665 } 673 }
666 } while (iStart <= iEnd); 674 } while (iStart <= iEnd);
667 return NULL; 675 return NULL;
668 } 676 }
677
669 FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue, 678 FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue,
670 int32_t iValueLen, 679 int32_t iValueLen,
671 FX_FLOAT& fValue, 680 FX_FLOAT& fValue,
672 FDE_CSSPRIMITIVETYPE& eUnit) { 681 FDE_CSSPRIMITIVETYPE& eUnit) {
673 ASSERT(pszValue != NULL && iValueLen > 0); 682 ASSERT(pszValue && iValueLen > 0);
674 int32_t iUsedLen = 0; 683 int32_t iUsedLen = 0;
675 fValue = FX_wcstof(pszValue, iValueLen, &iUsedLen); 684 fValue = FX_wcstof(pszValue, iValueLen, &iUsedLen);
676 if (iUsedLen <= 0) { 685 if (iUsedLen <= 0)
677 return FALSE; 686 return FALSE;
678 } 687
679 iValueLen -= iUsedLen; 688 iValueLen -= iUsedLen;
680 pszValue += iUsedLen; 689 pszValue += iUsedLen;
681 eUnit = FDE_CSSPRIMITIVETYPE_Number; 690 eUnit = FDE_CSSPRIMITIVETYPE_Number;
682 if (iValueLen >= 1 && *pszValue == '%') { 691 if (iValueLen >= 1 && *pszValue == '%') {
683 eUnit = FDE_CSSPRIMITIVETYPE_Percent; 692 eUnit = FDE_CSSPRIMITIVETYPE_Percent;
684 } else if (iValueLen == 2) { 693 } else if (iValueLen == 2) {
685 FDE_LPCCSSLENGTHUNITTABLE pUnit = 694 FDE_LPCCSSLENGTHUNITTABLE pUnit =
686 FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); 695 FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2));
687 if (pUnit != NULL) { 696 if (pUnit)
688 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; 697 eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue;
689 }
690 } 698 }
691 return TRUE; 699 return TRUE;
692 } 700 }
693 701
694 FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue, 702 FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue,
695 int32_t iValueLen, 703 int32_t iValueLen,
696 int32_t& iOffset, 704 int32_t& iOffset,
697 int32_t& iLength) { 705 int32_t& iLength) {
698 ASSERT(pszValue != NULL && iValueLen > 0); 706 ASSERT(pszValue != NULL && iValueLen > 0);
699 iOffset = 0; 707 iOffset = 0;
(...skipping 19 matching lines...) Expand all
719 if (FDE_ParseCSSString(pszValue + 4, iValueLen - 5, iOffset, iLength)) { 727 if (FDE_ParseCSSString(pszValue + 4, iValueLen - 5, iOffset, iLength)) {
720 iOffset += 4; 728 iOffset += 4;
721 return TRUE; 729 return TRUE;
722 } 730 }
723 return FALSE; 731 return FALSE;
724 } 732 }
725 733
726 FX_BOOL FDE_ParseCSSColor(const FX_WCHAR* pszValue, 734 FX_BOOL FDE_ParseCSSColor(const FX_WCHAR* pszValue,
727 int32_t iValueLen, 735 int32_t iValueLen,
728 FX_ARGB& dwColor) { 736 FX_ARGB& dwColor) {
729 ASSERT(pszValue != NULL && iValueLen > 0); 737 ASSERT(pszValue && iValueLen > 0);
738
730 if (*pszValue == '#') { 739 if (*pszValue == '#') {
731 switch (iValueLen) { 740 switch (iValueLen) {
732 case 4: { 741 case 4: {
733 uint8_t red = FX_Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[1]); 742 uint8_t red = Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[1]);
734 uint8_t green = FX_Hex2Dec((uint8_t)pszValue[2], (uint8_t)pszValue[2]); 743 uint8_t green = Hex2Dec((uint8_t)pszValue[2], (uint8_t)pszValue[2]);
735 uint8_t blue = FX_Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[3]); 744 uint8_t blue = Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[3]);
736 dwColor = ArgbEncode(255, red, green, blue); 745 dwColor = ArgbEncode(255, red, green, blue);
746 return TRUE;
737 } 747 }
748 case 7: {
749 uint8_t red = Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[2]);
750 uint8_t green = Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[4]);
751 uint8_t blue = Hex2Dec((uint8_t)pszValue[5], (uint8_t)pszValue[6]);
752 dwColor = ArgbEncode(255, red, green, blue);
738 return TRUE; 753 return TRUE;
739 case 7: {
740 uint8_t red = FX_Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[2]);
741 uint8_t green = FX_Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[4]);
742 uint8_t blue = FX_Hex2Dec((uint8_t)pszValue[5], (uint8_t)pszValue[6]);
743 dwColor = ArgbEncode(255, red, green, blue);
744 } 754 }
745 return TRUE; 755 default:
756 return FALSE;
746 } 757 }
747 } else if (iValueLen >= 10) { 758 }
748 if (pszValue[iValueLen - 1] != ')' || FX_wcsnicmp(L"rgb(", pszValue, 4)) { 759
760 if (iValueLen >= 10) {
761 if (pszValue[iValueLen - 1] != ')' || FX_wcsnicmp(L"rgb(", pszValue, 4))
749 return FALSE; 762 return FALSE;
750 } 763
751 uint8_t rgb[3] = {0}; 764 uint8_t rgb[3] = {0};
752 FX_FLOAT fValue; 765 FX_FLOAT fValue;
753 FDE_CSSPRIMITIVETYPE eType; 766 FDE_CSSPRIMITIVETYPE eType;
754 CFDE_CSSValueListParser list(pszValue + 4, iValueLen - 5, ','); 767 CFDE_CSSValueListParser list(pszValue + 4, iValueLen - 5, ',');
755 for (int32_t i = 0; i < 3; ++i) { 768 for (int32_t i = 0; i < 3; ++i) {
756 if (!list.NextValue(eType, pszValue, iValueLen)) { 769 if (!list.NextValue(eType, pszValue, iValueLen))
757 return FALSE; 770 return FALSE;
758 } 771 if (eType != FDE_CSSPRIMITIVETYPE_Number)
759 if (eType != FDE_CSSPRIMITIVETYPE_Number) {
760 return FALSE; 772 return FALSE;
761 } 773 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType))
762 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
763 return FALSE; 774 return FALSE;
764 } 775
765 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent 776 rgb[i] = eType == FDE_CSSPRIMITIVETYPE_Percent
766 ? FXSYS_round(fValue * 2.55f) 777 ? FXSYS_round(fValue * 2.55f)
767 : FXSYS_round(fValue); 778 : FXSYS_round(fValue);
768 } 779 }
769 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); 780 dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]);
770 return TRUE; 781 return TRUE;
771 } else {
772 FDE_LPCCSSCOLORTABLE pColor =
773 FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen));
774 if (pColor != NULL) {
775 dwColor = pColor->dwValue;
776 return TRUE;
777 }
778 } 782 }
779 return FALSE; 783
784 FDE_LPCCSSCOLORTABLE pColor =
785 FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen));
786 if (!pColor)
787 return FALSE;
788
789 dwColor = pColor->dwValue;
790 return TRUE;
780 } 791 }
781 792
782 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore, 793 CFDE_CSSValueList::CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore,
783 const CFDE_CSSValueArray& list) { 794 const CFDE_CSSValueArray& list) {
784 m_iCount = list.GetSize(); 795 m_iCount = list.GetSize();
785 int32_t iByteCount = m_iCount * sizeof(IFDE_CSSValue*); 796 int32_t iByteCount = m_iCount * sizeof(IFDE_CSSValue*);
786 m_ppList = (IFDE_CSSValue**)pStaticStore->Alloc(iByteCount); 797 m_ppList = (IFDE_CSSValue**)pStaticStore->Alloc(iByteCount);
787 FXSYS_memcpy(m_ppList, list.GetData(), iByteCount); 798 FXSYS_memcpy(m_ppList, list.GetData(), iByteCount);
788 } 799 }
789 FX_BOOL CFDE_CSSValueListParser::NextValue(FDE_CSSPRIMITIVETYPE& eType, 800 FX_BOOL CFDE_CSSValueListParser::NextValue(FDE_CSSPRIMITIVETYPE& eType,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 } 891 }
881 while (iBracketCount > 0 && m_pCur < m_pEnd) { 892 while (iBracketCount > 0 && m_pCur < m_pEnd) {
882 if (*m_pCur == ')') { 893 if (*m_pCur == ')') {
883 iBracketCount--; 894 iBracketCount--;
884 } 895 }
885 m_pCur++; 896 m_pCur++;
886 } 897 }
887 } 898 }
888 return m_pCur - pStart; 899 return m_pCur - pStart;
889 } 900 }
OLDNEW
« no previous file with comments | « xfa.gyp ('k') | xfa/fde/css/fde_cssdatatable_unittest.cpp » ('j') | xfa/fxfa/app/xfa_ffdoc.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698