summaryrefslogtreecommitdiff
path: root/xfa/fde/css/fde_cssdatatable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde/css/fde_cssdatatable.cpp')
-rw-r--r--xfa/fde/css/fde_cssdatatable.cpp218
1 files changed, 1 insertions, 217 deletions
diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp
index d645e2e508..fd4ef6bffb 100644
--- a/xfa/fde/css/fde_cssdatatable.cpp
+++ b/xfa/fde/css/fde_cssdatatable.cpp
@@ -9,104 +9,10 @@
#include <utility>
#include "core/fxcrt/fx_ext.h"
+#include "xfa/fde/css/cfde_cssstyleselector.h"
#include "xfa/fde/css/cfde_cssvaluelistparser.h"
-#include "xfa/fde/css/fde_cssstyleselector.h"
#include "xfa/fgas/crt/fgas_codepage.h"
-namespace {
-
-uint8_t Hex2Dec(uint8_t hexHigh, uint8_t hexLow) {
- return (FXSYS_toHexDigit(hexHigh) << 4) + FXSYS_toHexDigit(hexLow);
-}
-
-} // namespace
-
-bool FDE_CSSLengthToFloat(const FDE_CSSLength& len,
- FX_FLOAT fPercentBase,
- FX_FLOAT& fResult) {
- switch (len.GetUnit()) {
- case FDE_CSSLengthUnit::Point:
- fResult = len.GetValue();
- return true;
- case FDE_CSSLengthUnit::Percent:
- fResult = len.GetValue() * fPercentBase;
- return true;
- default:
- return false;
- }
-}
-CFX_FloatRect FDE_CSSBoundaryToRect(CFDE_CSSComputedStyle* pBoundStyle,
- FX_FLOAT fContainerWidth,
- bool bPadding,
- bool bBorder,
- bool bMargin) {
- FX_FLOAT fResult;
- const FDE_CSSRect* pRect;
- CFX_FloatRect rect(0, 0, 0, 0);
- if (bPadding) {
- pRect = pBoundStyle->GetPaddingWidth();
- if (pRect) {
- if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) {
- rect.left += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->top, fContainerWidth, fResult)) {
- rect.top += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->right, fContainerWidth, fResult)) {
- rect.right += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->bottom, fContainerWidth, fResult)) {
- rect.bottom += fResult;
- }
- }
- }
- if (bBorder) {
- pRect = pBoundStyle->GetBorderWidth();
- if (pRect) {
- if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) {
- rect.left += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->top, fContainerWidth, fResult)) {
- rect.top += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->right, fContainerWidth, fResult)) {
- rect.right += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->bottom, fContainerWidth, fResult)) {
- rect.bottom += fResult;
- }
- }
- }
- if (bMargin) {
- pRect = pBoundStyle->GetMarginWidth();
- if (pRect) {
- if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) {
- rect.left += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->top, fContainerWidth, fResult)) {
- rect.top += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->right, fContainerWidth, fResult)) {
- rect.right += fResult;
- }
- if (FDE_CSSLengthToFloat(pRect->bottom, fContainerWidth, fResult)) {
- rect.bottom += fResult;
- }
- }
- }
- return rect;
-}
-uint32_t FDE_CSSFontStyleToFDE(CFDE_CSSComputedStyle* pFontStyle) {
- uint32_t dwFontStyle = FX_FONTSTYLE_Normal;
- if (pFontStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) {
- dwFontStyle |= FX_FONTSTYLE_Italic;
- }
- if (pFontStyle->GetFontWeight() >= 700) {
- dwFontStyle |= FX_FONTSTYLE_Bold;
- }
- return dwFontStyle;
-}
-
static const FDE_CSSPropertyTable g_FDE_CSSProperties[] = {
{FDE_CSSProperty::BorderLeft, L"border-left", 0x04080036,
FDE_CSSVALUETYPE_Shorthand},
@@ -353,11 +259,6 @@ const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByName(
return nullptr;
}
-const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByEnum(
- FDE_CSSPropertyValue eName) {
- return g_FDE_CSSPropertyValues + static_cast<int>(eName);
-}
-
const FDE_CSSMEDIATYPETABLE* FDE_GetCSSMediaTypeByName(
const CFX_WideStringC& wsName) {
ASSERT(!wsName.IsEmpty());
@@ -421,120 +322,3 @@ const FDE_CSSCOLORTABLE* FDE_GetCSSColorByName(const CFX_WideStringC& wsName) {
} while (iStart <= iEnd);
return nullptr;
}
-
-bool FDE_ParseCSSNumber(const FX_WCHAR* pszValue,
- int32_t iValueLen,
- FX_FLOAT& fValue,
- FDE_CSSNumberType& eUnit) {
- ASSERT(pszValue && iValueLen > 0);
- int32_t iUsedLen = 0;
- fValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen);
- if (iUsedLen <= 0)
- return false;
-
- iValueLen -= iUsedLen;
- pszValue += iUsedLen;
- eUnit = FDE_CSSNumberType::Number;
- if (iValueLen >= 1 && *pszValue == '%') {
- eUnit = FDE_CSSNumberType::Percent;
- } else if (iValueLen == 2) {
- const FDE_CSSLengthUnitTable* pUnit =
- FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2));
- if (pUnit)
- eUnit = pUnit->wValue;
- }
- return true;
-}
-
-bool FDE_ParseCSSString(const FX_WCHAR* pszValue,
- int32_t iValueLen,
- int32_t* iOffset,
- int32_t* iLength) {
- ASSERT(pszValue && iValueLen > 0);
- *iOffset = 0;
- *iLength = iValueLen;
- if (iValueLen >= 2) {
- FX_WCHAR first = pszValue[0], last = pszValue[iValueLen - 1];
- if ((first == '\"' && last == '\"') || (first == '\'' && last == '\'')) {
- *iOffset = 1;
- *iLength -= 2;
- }
- }
- return iValueLen > 0;
-}
-
-bool FDE_ParseCSSURI(const FX_WCHAR* pszValue,
- int32_t* iOffset,
- int32_t* iLength) {
- ASSERT(pszValue && *iLength > 0);
- if (*iLength < 6 || pszValue[*iLength - 1] != ')' ||
- FXSYS_wcsnicmp(L"url(", pszValue, 4)) {
- return false;
- }
- if (FDE_ParseCSSString(pszValue + 4, *iLength - 5, iOffset, iLength)) {
- *iOffset += 4;
- return true;
- }
- return false;
-}
-
-bool FDE_ParseCSSColor(const FX_WCHAR* pszValue,
- int32_t iValueLen,
- FX_ARGB& dwColor) {
- ASSERT(pszValue && iValueLen > 0);
-
- if (*pszValue == '#') {
- switch (iValueLen) {
- case 4: {
- uint8_t red = Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[1]);
- uint8_t green = Hex2Dec((uint8_t)pszValue[2], (uint8_t)pszValue[2]);
- uint8_t blue = Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[3]);
- dwColor = ArgbEncode(255, red, green, blue);
- return true;
- }
- case 7: {
- uint8_t red = Hex2Dec((uint8_t)pszValue[1], (uint8_t)pszValue[2]);
- uint8_t green = Hex2Dec((uint8_t)pszValue[3], (uint8_t)pszValue[4]);
- uint8_t blue = Hex2Dec((uint8_t)pszValue[5], (uint8_t)pszValue[6]);
- dwColor = ArgbEncode(255, red, green, blue);
- return true;
- }
- default:
- return false;
- }
- }
-
- if (iValueLen >= 10) {
- if (pszValue[iValueLen - 1] != ')' || FXSYS_wcsnicmp(L"rgb(", pszValue, 4))
- return false;
-
- uint8_t rgb[3] = {0};
- FX_FLOAT fValue;
- FDE_CSSPrimitiveType eType;
- CFDE_CSSValueListParser list(pszValue + 4, iValueLen - 5, ',');
- for (int32_t i = 0; i < 3; ++i) {
- if (!list.NextValue(eType, pszValue, iValueLen))
- return false;
- if (eType != FDE_CSSPrimitiveType::Number)
- return false;
- FDE_CSSNumberType eNumType;
- if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eNumType))
- return false;
-
- rgb[i] = eNumType == FDE_CSSNumberType::Percent
- ? FXSYS_round(fValue * 2.55f)
- : FXSYS_round(fValue);
- }
- dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]);
- return true;
- }
-
- const FDE_CSSCOLORTABLE* pColor =
- FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen));
- if (!pColor)
- return false;
-
- dwColor = pColor->dwValue;
- return true;
-}
-