Refactoring

This commit is contained in:
Kirill Poljakov
2023-07-11 21:49:10 +03:00
parent e354b3b3d5
commit 0e1a1ca586
20 changed files with 829 additions and 4783 deletions

View File

@ -13,6 +13,8 @@ css_calculator_without_xhtml {
SOURCES += $$PWD/src/CCssCalculator_Private.cpp \
$$PWD/src/CElement.cpp \
$$PWD/src/CNode.cpp \
$$PWD/src/ConstValues.cpp \
$$PWD/src/StyleProperties.cpp \
$$PWD/src/CUnitMeasureConverter.cpp
} else {

View File

@ -119,7 +119,6 @@ namespace NSCSS
void CCompiledStyle::AddStyle(const std::map<std::wstring, std::wstring>& mStyle, const unsigned int unLevel, const bool& bHardMode)
{
const bool bIsThereBorder = (m_oBorder.Empty()) ? false : true;
const double dSize = m_oFont.GetSize().ToDouble();
for (std::pair<std::wstring, std::wstring> pPropertie : mStyle)
{
@ -129,13 +128,13 @@ namespace NSCSS
//FONT
CASE(L"font"):
{
m_oFont.SetValue(ConvertUnitMeasure(pPropertie.second.c_str(), dSize), unLevel, bHardMode);
m_oFont.SetValue(pPropertie.second.c_str(), unLevel, bHardMode);
break;
}
CASE(L"font-size"):
CASE(L"font-size-adjust"):
{
m_oFont.SetSize(ConvertUnitMeasure(pPropertie.second, dSize), unLevel, bHardMode);
m_oFont.SetSize(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"font-stretch"):
@ -174,7 +173,7 @@ namespace NSCSS
if (bIsThereBorder)
break;
m_oMargin.AddValue(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oMargin.AddValue(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"margin-top"):
@ -182,7 +181,7 @@ namespace NSCSS
if (bIsThereBorder)
break;
m_oMargin.AddTop(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY), unLevel, bHardMode);
m_oMargin.AddTop(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"margin-right"):
@ -191,7 +190,7 @@ namespace NSCSS
if (bIsThereBorder)
break;
m_oMargin.AddRight(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oMargin.AddRight(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"margin-bottom"):
@ -199,7 +198,7 @@ namespace NSCSS
if (bIsThereBorder)
break;
m_oMargin.AddBottom(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY), unLevel, bHardMode);
m_oMargin.AddBottom(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"margin-left"):
@ -208,38 +207,38 @@ namespace NSCSS
if (bIsThereBorder)
break;
m_oMargin.AddLeft(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oMargin.AddLeft(pPropertie.second, unLevel, bHardMode);
break;
}
//PADDING
CASE(L"padding"):
CASE(L"mso-padding-alt"):
{
m_oPadding.AddValue(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oPadding.AddValue(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"padding-top"):
CASE(L"mso-padding-top-alt"):
{
m_oPadding.AddTop(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY), unLevel, bHardMode);
m_oPadding.AddTop(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"padding-right"):
CASE(L"mso-padding-right-alt"):
{
m_oPadding.AddRight(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oPadding.AddRight(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"padding-bottom"):
CASE(L"mso-padding-bottom-alt"):
{
m_oPadding.AddBottom(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY), unLevel, bHardMode);
m_oPadding.AddBottom(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"padding-left"):
CASE(L"mso-padding-left-alt"):
{
m_oPadding.AddLeft(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oPadding.AddLeft(pPropertie.second, unLevel, bHardMode);
break;
}
// TEXT
@ -250,7 +249,7 @@ namespace NSCSS
}
CASE(L"text-indent"):
{
m_oText.SetIndent(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
m_oText.SetIndent(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"text-decoration"):
@ -268,12 +267,12 @@ namespace NSCSS
CASE(L"border"):
CASE(L"mso-border-alt"):
{
m_oBorder.SetSides(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetSides(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-width"):
{
m_oBorder.SetWidth(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetWidth(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-style"):
@ -289,12 +288,12 @@ namespace NSCSS
//BORDER TOP
CASE(L"border-top"):
{
m_oBorder.SetTopSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetTopSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-top-width"):
{
m_oBorder.SetWidthTopSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetWidthTopSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-top-style"):
@ -310,12 +309,12 @@ namespace NSCSS
//BORDER RIGHT
CASE(L"border-right"):
{
m_oBorder.SetRightSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetRightSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-right-width"):
{
m_oBorder.SetWidthRightSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetWidthRightSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-right-style"):
@ -331,12 +330,12 @@ namespace NSCSS
//BORDER bottom
CASE(L"border-bottom"):
{
m_oBorder.SetBottomSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetBottomSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-bottom-width"):
{
m_oBorder.SetWidthBottomSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetWidthBottomSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-bottom-style"):
@ -352,12 +351,12 @@ namespace NSCSS
//BORDER LEFT
CASE(L"border-left"):
{
m_oBorder.SetLeftSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetLeftSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-left-width"):
{
m_oBorder.SetWidthLeftSide(ConvertUnitMeasure(pPropertie.second, 0.0f), unLevel, bHardMode);
m_oBorder.SetWidthLeftSide(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"border-left-style"):
@ -397,22 +396,12 @@ namespace NSCSS
}
CASE(L"width"):
{
double dParentValue = m_oDisplay.GetWidth().ToDouble();
if (0 >= dParentValue)
dParentValue = m_oDeviceWindow.m_ushWidth;
m_oDisplay.SetWidth(ConvertUnitMeasure(pPropertie.second, dParentValue, ScalingDirectionX), unLevel, bHardMode);
m_oDisplay.SetWidth(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"height"):
{
double dParentValue = m_oDisplay.GetHeight().ToDouble();
if (0 >= dParentValue)
dParentValue = m_oDeviceWindow.m_ushHeight;
m_oDisplay.SetHeight(ConvertUnitMeasure(pPropertie.second, dParentValue, ScalingDirectionY), unLevel, bHardMode);
m_oDisplay.SetHeight(pPropertie.second, unLevel, bHardMode);
break;
}
CASE(L"align"):
@ -435,7 +424,7 @@ namespace NSCSS
if (sStyle.empty())
return;
const std::vector<std::wstring> arWords = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sStyle, L":;");
const std::vector<std::wstring> arWords = NS_STATIC_FUNCTIONS::GetWordsW(sStyle, true, L":;");
std::wstring sProperty, sValue;
@ -499,487 +488,5 @@ namespace NSCSS
{
return m_sId;
}
std::wstring CCompiledStyle::ConvertUnitMeasure(const std::wstring &sValue, const float& fPreviousValue, ScalingDirection enScalingDirection) const
{
if (sValue.empty())
return sValue;
std::vector<std::wstring> arValues = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sValue);
std::wstring sValueString;
for (std::wstring& sValueTemp : arValues)
{
std::transform(sValueTemp.begin(), sValueTemp.end(), sValueTemp.begin(), tolower);
if (sValueTemp == L"important")
{
sValueString += L"!important";
continue;
}
size_t nPosGrid = sValueTemp.find(L'#');
if (nPosGrid != std::wstring::npos || !NS_STATIC_FUNCTIONS::NumberInWString(sValueTemp))
{
if (!NS_STATIC_FUNCTIONS::ConvertAbsoluteValue(sValueTemp, fPreviousValue))
{
sValueString += sValueTemp;
continue;
}
}
const size_t posPercent = sValueTemp.find(L'%');
if (posPercent != std::wstring::npos)
{
const float dValue = wcstof(sValueTemp.substr(0, posPercent).c_str(), NULL) * fPreviousValue / 100;
sValueString += std::to_wstring(static_cast<short int>(dValue + 0.5f));
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"px") != std::wstring::npos)
{
int nValue = ConvertPx(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"cm") != std::wstring::npos)
{
int nValue = ConvertCm(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"mm") != std::wstring::npos)
{
int nValue = ConvertMm(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"in") != std::wstring::npos)
{
int nValue = ConvertIn(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"pt") != std::wstring::npos)
{
int nValue = ConvertPt(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"pc") != std::wstring::npos)
{
int nValue = ConvertPc(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else if (sValueTemp.find(L"em") != std::wstring::npos)
{
const float fValue = wcstof(sValueTemp.c_str(), NULL) * m_oFont.GetSize().ToDouble();
sValueString += std::to_wstring(static_cast<short int>(fValue + 0.5f));
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
else if (arValues.size() > 1 && sValueTemp.find(L':') == std::wstring::npos)
sValueString += L' ';
}
else
{
if (iswdigit(sValueTemp[0]))
{
int nValue = static_cast<int>(wcstof(sValueTemp.c_str(), NULL) + 0.5f);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
}
else
sValueString += sValueTemp;
if (sValueTemp.find(L";") != std::wstring::npos)
sValueString += L';';
continue;
}
if (sValueTemp.back() != L';' && sValueTemp.back() != L':' && sValueTemp.back() != L' ')
sValueTemp += L' ';
}
return sValueString;
}
void CCompiledStyle::Scale(int &nValue, ScalingDirection enScalingDirection) const
{
if (ScalingDirectionNone == enScalingDirection)
return;
else if (ScalingDirectionX == enScalingDirection && 0 != m_oSourceWindow.m_ushWidth &&
0 != m_oDeviceWindow.m_ushWidth && m_oSourceWindow.m_ushWidth != m_oDeviceWindow.m_ushWidth)
{
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushWidth * m_oDeviceWindow.m_ushWidth + 0.5f);
}
else if (ScalingDirectionY == enScalingDirection && 0 != m_oSourceWindow.m_ushHeight &&
0 != m_oDeviceWindow.m_ushHeight && m_oSourceWindow.m_ushHeight != m_oDeviceWindow.m_ushHeight)
{
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushHeight * m_oDeviceWindow.m_ushHeight + 0.5f);
}
}
inline int CCompiledStyle::ConvertPx(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"px") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Pixel:
return static_cast<int>(dValue);
case Point:
return ConvertPxToPt(dValue);
case Cantimeter:
return ConvertPxToCm(dValue);
case Millimeter:
return ConvertPxToMm(dValue);
case Inch:
return ConvertPxToIn(dValue);
case Peak:
return ConvertPxToPc(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertPxToCm(const float& dValue) const
{
return static_cast<int>(dValue / m_nDpi * 2.54f);
}
inline int CCompiledStyle::ConvertPxToIn(const float& dValue) const
{
return static_cast<int>(1.0f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertPxToMm(const float& dValue) const
{
return static_cast<int>(dValue / static_cast<float>(m_nDpi) * 25.4f + 0.5f);
}
inline int CCompiledStyle::ConvertPxToPc(const float& dValue) const
{
return static_cast<int>(0.16667f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertPxToPt(const float& dValue) const
{
return static_cast<int>(72.0f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertCm(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"cm") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Point:
return ConvertCmToPt(dValue);
case Pixel:
return ConvertCmToPx(dValue);
case Cantimeter:
return static_cast<int>(dValue);
case Millimeter:
return ConvertCmToMm(dValue);
case Inch:
return ConvertCmToIn(dValue);
case Peak:
return ConvertCmToPc(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertCmToIn(const float& dValue) const
{
return static_cast<int>(dValue / 2.54f + 0.5f);
}
inline int CCompiledStyle::ConvertCmToMm(const float& dValue) const
{
return static_cast<int>(dValue * 10.0f + 0.5f);
}
inline int CCompiledStyle::ConvertCmToPc(const float& dValue) const
{
return static_cast<int>(2.36f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertCmToPt(const float& dValue) const
{
return static_cast<int>(28.35f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertCmToPx(const float& dValue) const
{
return static_cast<int>(static_cast<float>(m_nDpi) / 2.54f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertMm(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"mm") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Pixel:
return ConvertMmToPx(dValue);
case Point:
return ConvertMmToPt(dValue);
case Cantimeter:
return ConvertMmToCm(dValue);
case Millimeter:
return static_cast< int>(dValue);
case Inch:
return ConvertMmToIn(dValue);
case Peak:
return ConvertMmToPc(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertMmToIn(const float& dValue) const
{
return static_cast<int>(dValue / 25.4f + 0.5f);
}
inline int CCompiledStyle::ConvertMmToCm(const float& dValue) const
{
return static_cast<int>(dValue / 10.0f + 0.5f);
}
inline int CCompiledStyle::ConvertMmToPc(const float& dValue) const
{
return static_cast<int>(0.236f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertMmToPt(const float& dValue) const
{
return static_cast<int>(2.835f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertMmToPx(const float& dValue) const
{
return static_cast<int>(static_cast<float>(m_nDpi) / 25.4f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertIn(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"in") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Pixel:
return ConvertInToPx(dValue);
case Point:
return ConvertInToPt(dValue);
case Cantimeter:
return ConvertInToCm(dValue);
case Millimeter:
return ConvertInToMm(dValue);
case Inch:
return static_cast<int>(dValue);
case Peak:
return ConvertInToPc(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertInToMm(const float& dValue) const
{
return static_cast<int>(dValue * 25.4f + 0.5f);
}
inline int CCompiledStyle::ConvertInToCm(const float& dValue) const
{
return static_cast<int>(dValue * 2.54f + 0.5f);
}
inline int CCompiledStyle::ConvertInToPc(const float& dValue) const
{
return static_cast<int>(dValue / 72.0f + 0.5f);
}
inline int CCompiledStyle::ConvertInToPt(const float& dValue) const
{
return static_cast<int>(dValue / 6.0f + 0.5f);
}
inline int CCompiledStyle::ConvertInToPx(const float& dValue) const
{
return static_cast<short int>(dValue * static_cast<float>(m_nDpi) + 0.5f);
}
inline int CCompiledStyle::ConvertPt(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"pt") - 1);
float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Pixel:
return ConvertPtToPx(dValue);
case Point:
return static_cast<int>(dValue + 0.5f);
case Cantimeter:
return ConvertPtToCm(dValue);
case Millimeter:
return ConvertPtToMm(dValue);
case Inch:
return ConvertPtToIn(dValue);
case Peak:
return ConvertPtToPc(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertPtToIn(const float& dValue) const
{
return static_cast<int>(dValue / 72.0f + 0.5f);
}
inline int CCompiledStyle::ConvertPtToCm(const float& dValue) const
{
return static_cast<int>(dValue * 0.03528f + 0.5f);
}
inline int CCompiledStyle::ConvertPtToPc(const float& dValue) const
{
return static_cast<int>(dValue / 12.0f + 0.5f);
}
inline int CCompiledStyle::ConvertPtToMm(const float& dValue) const
{
return static_cast<int>(dValue * 0.3528f + 0.5f);
}
inline int CCompiledStyle::ConvertPtToPx(const float& dValue) const
{
return static_cast<short int>(static_cast<float>(m_nDpi) / 72.0f * dValue + 0.5f);
}
inline int CCompiledStyle::ConvertPc(const std::wstring& sValue) const
{
if (sValue.empty())
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"pc") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL);
switch (m_UnitMeasure)
{
case Pixel:
return ConvertPcToPx(dValue);
case Point:
return ConvertPcToPt(dValue);
case Cantimeter:
return ConvertPcToCm(dValue);
case Millimeter:
return ConvertPcToMm(dValue);
case Inch:
return ConvertPcToIn(dValue);
case Peak:
return static_cast<int>(dValue);
}
return 0;
}
inline int CCompiledStyle::ConvertPcToIn(const float& dValue) const
{
return static_cast<int>(dValue / 6.0f + 0.5f);
}
inline int CCompiledStyle::ConvertPcToCm(const float& dValue) const
{
return static_cast<int>(dValue * 0.423f + 0.5f);
}
inline int CCompiledStyle::ConvertPcToPt(const float& dValue) const
{
return static_cast<int>(dValue * 12.0f + 0.5f);
}
inline int CCompiledStyle::ConvertPcToMm(const float& dValue) const
{
return static_cast<int>(dValue * 4.23f + 0.5f);
}
inline int CCompiledStyle::ConvertPcToPx(const float& dValue) const
{
return static_cast<int>(static_cast<float>(m_nDpi) / 6.0f * dValue + 0.5f);
}
}

View File

@ -25,50 +25,6 @@ namespace NSCSS
CSizeWindow m_oSourceWindow;
CSizeWindow m_oDeviceWindow;
void Scale(int &nValue, ScalingDirection enScalingDirection) const;
int ConvertPx(const std::wstring& sValue) const;
int ConvertPxToCm(const float& dValue) const;
int ConvertPxToIn(const float& dValue) const;
int ConvertPxToMm(const float& dValue) const;
int ConvertPxToPt(const float& dValue) const;
int ConvertPxToPc(const float& dValue) const;
int ConvertCm(const std::wstring& sValue) const;
int ConvertCmToPx(const float& dValue) const;
int ConvertCmToIn(const float& dValue) const;
int ConvertCmToMm(const float& dValue) const;
int ConvertCmToPt(const float& dValue) const;
int ConvertCmToPc(const float& dValue) const;
int ConvertMm(const std::wstring& sValue) const;
int ConvertMmToPx(const float& dValue) const;
int ConvertMmToIn(const float& dValue) const;
int ConvertMmToCm(const float& dValue) const;
int ConvertMmToPt(const float& dValue) const;
int ConvertMmToPc(const float& dValue) const;
int ConvertIn(const std::wstring& sValue) const;
int ConvertInToPx(const float& dValue) const;
int ConvertInToMm(const float& dValue) const;
int ConvertInToCm(const float& dValue) const;
int ConvertInToPt(const float& dValue) const;
int ConvertInToPc(const float& dValue) const;
int ConvertPt(const std::wstring& sValue) const;
int ConvertPtToPx(const float& dValue) const;
int ConvertPtToMm(const float& dValue) const;
int ConvertPtToCm(const float& dValue) const;
int ConvertPtToIn(const float& dValue) const;
int ConvertPtToPc(const float& dValue) const;
int ConvertPc(const std::wstring& sValue) const;
int ConvertPcToPx(const float& dValue) const;
int ConvertPcToMm(const float& dValue) const;
int ConvertPcToCm(const float& dValue) const;
int ConvertPcToIn(const float& dValue) const;
int ConvertPcToPt(const float& dValue) const;
public:
NSProperties::CFont m_oFont;
NSProperties::CIndent m_oMargin;
@ -83,8 +39,6 @@ namespace NSCSS
~CCompiledStyle();
std::wstring ConvertUnitMeasure(const std::wstring& sValue, const float& fPreviousValue, ScalingDirection enScalingDirection = ScalingDirectionNone) const;
void SetDpi(const unsigned short& uiDpi);
void SetUnitMeasure(const UnitMeasure& enUnitMeasure);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);

View File

@ -10,39 +10,39 @@
namespace NSCSS
{
class CCssCalculator_Private;
class CSSCALCULATOR_EXPORT CCssCalculator
{
protected:
CCssCalculator_Private* m_pInternal;
public:
CCssCalculator();
~CCssCalculator();
class CCssCalculator_Private;
class CSSCALCULATOR_EXPORT CCssCalculator
{
protected:
CCssCalculator_Private* m_pInternal;
public:
CCssCalculator();
~CCssCalculator();
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
// void AddStyle(const std::vector<std::string>& sSelectors, const std::string& sStyle);
void AddStyles (const std::string& sStyle);
void AddStyles (const std::wstring& sStyle);
void AddStylesFromFile(const std::wstring& sFileName);
// void AddStyle(const std::vector<std::string>& sSelectors, const std::string& sStyle);
void AddStyles (const std::string& sStyle);
void AddStyles (const std::wstring& sStyle);
void AddStylesFromFile(const std::wstring& sFileName);
void SetUnitMeasure(const UnitMeasure& nType);
void SetDpi(const unsigned short int& nValue);
void SetBodyTree(const CTree &oTree);
void SetUnitMeasure(const UnitMeasure& nType);
void SetDpi(const unsigned short int& nValue);
void SetBodyTree(const CTree &oTree);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
CSizeWindow GetSizeSourceWindow() const;
CSizeWindow GetSizeDeviceWindow() const;
CSizeWindow GetSizeSourceWindow() const;
CSizeWindow GetSizeDeviceWindow() const;
UnitMeasure GetUnitMeasure() const;
std::wstring GetEncoding() const;
unsigned short int GetDpi() const;
UnitMeasure GetUnitMeasure() const;
std::wstring GetEncoding() const;
unsigned short int GetDpi() const;
void Clear();
};
void Clear();
};
}
#endif // CCSSCALCULATOR_H

View File

@ -105,7 +105,7 @@ namespace NSCSS
GetStyleRule((KatanaStyleRule*)oRule);
break;
case KatanaRuleImport:
case KatanaRuleFontFace:
case KatanaRuleFontVariantFace:
case KatanaRuleKeyframes:
case KatanaRuleMedia:
case KatanaRuleSupports:
@ -264,18 +264,18 @@ namespace NSCSS
KatanaParser oParser;
oParser.options = &kKatanaDefaultOptions;
std::wstring sText;
std::wstring wsText;
const KatanaParserString* string = katana_selector_to_string(&oParser, const_cast<KatanaSelector*>(oSelector), NULL);
const char* text = katana_string_to_characters(&oParser, string);
katana_parser_deallocate(&oParser, (void*) string->data);
katana_parser_deallocate(&oParser, (void*) string);
sText = NS_STATIC_FUNCTIONS::stringToWstring(text);
wsText = UTF8_TO_U(std::string(text));
katana_parser_deallocate(&oParser, (void*) text);
katana_parser_deallocate(&oParser, (void*)text);
return sText;
return wsText;
}
inline std::map<std::wstring, std::wstring> CCssCalculator_Private::GetDeclarationList(const KatanaArray* oDeclarations) const
@ -298,7 +298,7 @@ namespace NSCSS
if (oDecl->important)
sValueList += L" !important";
return std::make_pair(NS_STATIC_FUNCTIONS::stringToWstring(oDecl->property), sValueList);
return std::make_pair(UTF8_TO_U(std::string(oDecl->property)), sValueList);
}
inline std::wstring CCssCalculator_Private::GetValueList(const KatanaArray *oValues)
@ -326,7 +326,7 @@ namespace NSCSS
CCompiledStyle oStyle;
oStyle.SetDpi(m_nDpi);
oStyle.SetUnitMeasure(m_UnitMeasure);
oStyle.SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetSizeDeviceWindow(m_oDeviceWindow);
oStyle.SetSizeSourceWindow(m_oSourceWindow);
@ -350,20 +350,20 @@ namespace NSCSS
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
arWords.push_back(oNode->m_sName);
arWords.push_back(oNode->m_wsName);
//TODO:: проверить данный момент
// if (oNode->m_sName == L"td")
// pStyle->m_oMargin.SetPermission(false);
if (oNode->m_sName == L"table")
if (oNode->m_wsName == L"table")
pStyle->m_oBorder.Block();
if (!oNode->m_sClass.empty())
if (!oNode->m_wsClass.empty())
{
if (oNode->m_sClass.find(L' ') != std::wstring::npos)
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_sClass, L" ");
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, L" ");
if (arClasses.size() > 1)
arClasses.resize(unique(arClasses.begin(),arClasses.end()) - arClasses.begin());
@ -394,10 +394,10 @@ namespace NSCSS
}
}
else
arWords.push_back(L'.' + oNode->m_sClass);
arWords.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_sId.empty())
arWords.push_back(L'#' + oNode->m_sId);
if (!oNode->m_wsId.empty())
arWords.push_back(L'#' + oNode->m_wsId);
}
std::vector<CElement*> arElements;
@ -506,33 +506,33 @@ namespace NSCSS
});
}
pStyle->AddStyle(arSelectors[i].m_mAttrs, i + 1);
pStyle->AddStyle(arSelectors[i].m_mAttributes, i + 1);
for (const CElement* oElement : arFindElements)
pStyle->AddStyle(oElement->GetStyle(), i + 1);
if (NULL != m_mStatictics)
{
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_sStyle});
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_wsStyle});
if (oFindCountStyle != m_mStatictics->end())
{
if ((bIsSettings && oFindCountStyle->second < MaxNumberRepetitions) ||
(!bIsSettings && oFindCountStyle->second >= MaxNumberRepetitions))
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
pStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
else if (!bIsSettings)
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
pStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
else if (bIsSettings)
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
pStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
else
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
pStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
if (!bIsSettings)
{
pStyle->SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
pStyle->SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
m_mUsedStyles[arSelectors] = pStyle;
}
@ -560,7 +560,7 @@ namespace NSCSS
{
oStyle.SetDpi(m_nDpi);
oStyle.SetUnitMeasure(m_UnitMeasure);
oStyle.SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetSizeDeviceWindow(m_oDeviceWindow);
oStyle.SetSizeSourceWindow(m_oSourceWindow);
@ -582,19 +582,19 @@ namespace NSCSS
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
arWords.push_back(oNode->m_sName);
arWords.push_back(oNode->m_wsName);
// if (oNode->m_sName == L"td")
// oStyle.m_pMargin.SetPermission(false);
if (oNode->m_sName == L"table")
if (oNode->m_wsName == L"table")
oStyle.m_oBorder.Block();
if (!oNode->m_sClass.empty())
if (!oNode->m_wsClass.empty())
{
if (oNode->m_sClass.find(L' ') != std::wstring::npos)
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_sClass, L" ");
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, L" ");
if (arClasses.size() > 1)
arClasses.resize(unique(arClasses.begin(),arClasses.end()) - arClasses.begin());
@ -625,10 +625,10 @@ namespace NSCSS
}
}
else
arWords.push_back(L'.' + oNode->m_sClass);
arWords.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_sId.empty())
arWords.push_back(L'#' + oNode->m_sId);
if (!oNode->m_wsId.empty())
arWords.push_back(L'#' + oNode->m_wsId);
}
std::vector<CElement*> arElements;
@ -737,33 +737,33 @@ namespace NSCSS
});
}
oStyle.AddStyle(arSelectors[i].m_mAttrs, i + 1);
oStyle.AddStyle(arSelectors[i].m_mAttributes, i + 1);
for (const CElement* oElement : arFindElements)
oStyle.AddStyle(oElement->GetStyle(), i + 1);
if (NULL != m_mStatictics)
{
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_sStyle});
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_wsStyle});
if (oFindCountStyle != m_mStatictics->end())
{
if ((bIsSettings && oFindCountStyle->second < MaxNumberRepetitions) ||
(!bIsSettings && oFindCountStyle->second >= MaxNumberRepetitions))
oStyle.AddStyle(arSelectors[i].m_sStyle, i + 1, true);
oStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
else if (!bIsSettings)
oStyle.AddStyle(arSelectors[i].m_sStyle, i + 1, true);
oStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
else if (bIsSettings)
oStyle.AddStyle(arSelectors[i].m_sStyle, i + 1, true);
oStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
else
oStyle.AddStyle(arSelectors[i].m_sStyle, i + 1, true);
oStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
}
if (!bIsSettings)
{
oStyle.SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
CCompiledStyle *pTemp = new CCompiledStyle(oStyle);
@ -788,7 +788,7 @@ namespace NSCSS
if (sStyle.empty())
return;
AddStyles(NS_STATIC_FUNCTIONS::wstringToString(sStyle));
AddStyles(U_TO_UTF8(sStyle));
}
void CCssCalculator_Private::AddStylesFromFile(const std::wstring& sFileName)
@ -927,14 +927,14 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
case KATANA_VALUE_HZ:
case KATANA_VALUE_KHZ:
case KATANA_VALUE_TURN:
str = NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->raw);
str = UTF8_TO_U(std::string(oValue->raw));
break;
case KATANA_VALUE_IDENT:
str = NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->string);
str = UTF8_TO_U(std::string(oValue->string));
break;
case KATANA_VALUE_STRING:
{
str = L"\"" + NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->string) + L"\"";
str = L"\"" + UTF8_TO_U(std::string(oValue->string)) + L"\"";
break;
}
case KATANA_VALUE_PARSER_FUNCTION:
@ -943,7 +943,7 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
if (args_str.empty())
break;
str = NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->function->name) + args_str + L")";
str = UTF8_TO_U(std::string(oValue->function->name)) + args_str + L")";
break;
}
case KATANA_VALUE_PARSER_OPERATOR:
@ -960,10 +960,10 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
return StringifyValueList(oValue->list);
break;
case KATANA_VALUE_PARSER_HEXCOLOR:
str = L"#" + NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->string);
str = L"#" + UTF8_TO_U(std::string(oValue->string));
break;
case KATANA_VALUE_URI:
str = L"url(" + NSCSS::NS_STATIC_FUNCTIONS::stringToWstring(oValue->string) + L")";
str = L"url(" + UTF8_TO_U(std::string(oValue->string)) + L")";
break;
default:
break;

View File

@ -98,8 +98,8 @@ namespace NSCSS
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
{
std::map<std::wstring, std::wstring> mTempStyle;
if (oElement->GetSelector() == L'.' + oNode->m_sClass ||
oElement->GetSelector() == oNode->m_sName)
if (oElement->GetSelector() == L'.' + oNode->m_wsClass ||
oElement->GetSelector() == oNode->m_wsName)
{
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(arSelectors))
mStyle[pPropertie.first] = pPropertie.second;

View File

@ -8,45 +8,45 @@
namespace NSCSS
{
class CElement
{
std::map<std::wstring, std::wstring> m_mStyle;
class CElement
{
std::map<std::wstring, std::wstring> m_mStyle;
std::vector<CElement*> m_arPrevElements;
std::vector<CElement*> m_arKinElements;
std::vector<CElement*> m_arPrevElements;
std::vector<CElement*> m_arKinElements;
std::wstring m_sSelector;
std::wstring m_sFullSelector;
std::wstring m_sSelector;
std::wstring m_sFullSelector;
std::vector<unsigned short int> m_arWeight;
std::vector<unsigned short int> m_arWeight;
public:
CElement();
~CElement();
public:
CElement();
~CElement();
std::wstring GetSelector() const;
std::wstring GetFullSelector() const;
std::wstring GetSelector() const;
std::wstring GetFullSelector() const;
bool Empty() const;
bool Empty() const;
void SetSelector(const std::wstring& sSelector);
void AddPropertie(const std::wstring& sName, const std::wstring& sValue);
void AddProperties(const std::map<std::wstring, std::wstring>& mProperties);
void AddPrevElement(CElement* oPrevElement);
void AddKinElement(CElement* oKinElement);
void SetSelector(const std::wstring& sSelector);
void AddPropertie(const std::wstring& sName, const std::wstring& sValue);
void AddProperties(const std::map<std::wstring, std::wstring>& mProperties);
void AddPrevElement(CElement* oPrevElement);
void AddKinElement(CElement* oKinElement);
std::map<std::wstring, std::wstring> GetStyle() const;
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<CNode>& arSelectors) const;
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<std::wstring>& arNodes) const;
std::vector<CElement *> GetNextOfKin(const std::wstring& sName, const std::vector<std::wstring>& arClasses = {}) const;
std::vector<CElement *> GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const;
std::map<std::wstring, std::wstring> GetConvertStyle(const std::vector<CNode>& arNodes) const;
std::map<std::wstring, std::wstring> GetStyle() const;
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<CNode>& arSelectors) const;
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<std::wstring>& arNodes) const;
std::vector<CElement *> GetNextOfKin(const std::wstring& sName, const std::vector<std::wstring>& arClasses = {}) const;
std::vector<CElement *> GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const;
std::map<std::wstring, std::wstring> GetConvertStyle(const std::vector<CNode>& arNodes) const;
CElement *FindPrevElement(const std::wstring& sSelector) const;
CElement *FindPrevElement(const std::wstring& sSelector) const;
std::vector<unsigned short int> GetWeight();
void IncreasedWeight();
};
std::vector<unsigned short int> GetWeight();
void IncreasedWeight();
};
}

View File

@ -0,0 +1,55 @@
#include "CNode.h"
namespace NSCSS
{
CNode::CNode()
{}
CNode::CNode(std::wstring wsName, std::wstring wsClass, std::wstring wsId)
: m_wsName(wsName), m_wsClass(wsClass), m_wsId(wsId)
{}
bool CNode::Empty() const
{
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
}
std::vector<std::wstring> CNode::GetData() const
{
std::vector<std::wstring> arValues;
if (!m_wsClass.empty())
arValues.push_back(m_wsClass);
if (!m_wsName.empty())
arValues.push_back(m_wsName);
return arValues;
}
bool CNode::operator<(const CNode& oNode) const
{
if(m_wsName != oNode.m_wsName)
return m_wsName < oNode.m_wsName;
if(m_wsClass != oNode.m_wsClass)
return m_wsClass < oNode.m_wsClass;
if(m_wsId != oNode.m_wsId)
return m_wsId < oNode.m_wsId;
if(m_wsStyle != oNode.m_wsStyle)
return m_wsStyle < oNode.m_wsStyle;
if (m_mAttributes != oNode.m_mAttributes)
return m_mAttributes < oNode.m_mAttributes;
return false;
}
bool CNode::operator==(const CNode& oNode) const
{
return((m_wsId == oNode.m_wsId) &&
(m_wsName == oNode.m_wsName) &&
(m_wsClass == oNode.m_wsClass) &&
(m_wsStyle == oNode.m_wsStyle) &&
(m_mAttributes == oNode.m_mAttributes));
}
}

View File

@ -7,61 +7,25 @@
namespace NSCSS
{
struct CNode
{
std::wstring m_sName; // Имя тэга
std::wstring m_sClass; // Класс тэга
std::wstring m_sId; // Id тэга
std::wstring m_sStyle; // Стиль тэга
std::map<std::wstring, std::wstring> m_mAttrs; // Остальные аттрибуты тэга
class CNode
{
public:
std::wstring m_wsName; // Имя тэга
std::wstring m_wsClass; // Класс тэга
std::wstring m_wsId; // Id тэга
std::wstring m_wsStyle; // Стиль тэга
std::map<std::wstring, std::wstring> m_mAttributes; // Остальные аттрибуты тэга
CNode(){};
CNode(std::wstring sName, std::wstring sClass, std::wstring sId) : m_sName(sName), m_sClass(sClass), m_sId(sId){};
public:
CNode();
CNode(std::wstring wsName, std::wstring wsClass, std::wstring wsId);
bool Empty() const
{
return m_sName.empty() && m_sClass.empty() && m_sId.empty() && m_sStyle.empty();
}
bool Empty() const;
std::vector<std::wstring> GetData() const
{
std::vector<std::wstring> arValues;
if (!m_sClass.empty())
arValues.push_back(m_sClass);
if (!m_sName.empty())
arValues.push_back(m_sName);
return arValues;
}
bool operator< (const CNode& oNode) const
{
if(m_sName != oNode.m_sName)
return m_sName < oNode.m_sName;
if(m_sClass != oNode.m_sClass)
return m_sClass < oNode.m_sClass;
if(m_sId != oNode.m_sId)
return m_sId < oNode.m_sId;
if(m_sStyle != oNode.m_sStyle)
return m_sStyle < oNode.m_sStyle;
if (m_mAttrs != oNode.m_mAttrs)
return m_mAttrs < oNode.m_mAttrs;
return false;
}
bool operator== (const CNode& oNode) const
{
return((m_sId == oNode.m_sId) &&
(m_sName == oNode.m_sName) &&
(m_sClass == oNode.m_sClass) &&
(m_sStyle == oNode.m_sStyle) &&
(m_mAttrs == oNode.m_mAttrs));
}
};
std::vector<std::wstring> GetData() const;
bool operator< (const CNode& oNode) const;
bool operator== (const CNode& oNode) const;
};
}
#endif // CNODE_H

View File

@ -136,130 +136,6 @@ namespace NSCSS
return 0.;
}
std::wstring CUnitMeasureConverter::ConvertUnitMeasure(const std::wstring &wsValue, double dPreviousValue, UnitMeasure enUnitMeasure, unsigned short ushDPI)
{
if (wsValue.empty())
return std::wstring();
std::wstring wsNewValue;
std::vector<std::wstring> arValues = NSCSS::NS_STATIC_FUNCTIONS::GetWordsWithSigns(wsValue);
for (std::wstring& wsValueTemp : arValues)
{
std::transform(wsValueTemp.begin(), wsValueTemp.end(), wsValueTemp.begin(), tolower);
if (wsValueTemp == L"important")
{
wsNewValue += L"!important";
continue;
}
size_t nPosGrid = wsValueTemp.find(L'#');
if (nPosGrid != std::wstring::npos || !NSCSS::NS_STATIC_FUNCTIONS::NumberInWString(wsValueTemp))
{
if (!NSCSS::NS_STATIC_FUNCTIONS::ConvertAbsoluteValue(wsValueTemp, dPreviousValue))
{
wsNewValue += wsValueTemp;
continue;
}
}
double dValue = NSCSS::NS_STATIC_FUNCTIONS::ReadDouble(wsValueTemp);
const size_t posPercent = wsValueTemp.find(L'%');
if (posPercent != std::wstring::npos)
{
wsNewValue += std::to_wstring(dValue * dPreviousValue / 100.);
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"px") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertPx(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"cm") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertCm(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"mm") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertMm(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"in") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertIn(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"pt") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertPt(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"pc") != std::wstring::npos)
{
wsNewValue += std::to_wstring(ConvertPc(dValue, enUnitMeasure, ushDPI));
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else if (wsValueTemp.find(L"em") != std::wstring::npos)
{
wsNewValue += std::to_wstring(dValue * dPreviousValue);
if (wsValueTemp.find(L';') != std::wstring::npos)
wsNewValue += L';';
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
wsNewValue += L' ';
}
else
{
wsNewValue += wsValueTemp;
if (wsValueTemp.find(L";") != std::wstring::npos)
wsNewValue += L';';
continue;
}
if (wsValueTemp.back() != L';' && wsValueTemp.back() != L':' && wsValueTemp.back() != L' ')
wsValueTemp += L' ';
}
return wsNewValue;
}
bool CUnitMeasureConverter::GetValue(const std::wstring &wsValue, double &dValue, UnitMeasure &enUnitMeasure)
{
std::wstring::const_iterator oFoundDigit = std::find_if(wsValue.begin(), wsValue.end(), std::iswdigit);

View File

@ -28,8 +28,6 @@ namespace NSCSS
static double ConvertPt(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
static double ConvertPc(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
static std::wstring ConvertUnitMeasure(const std::wstring& wsValue, double dPreviousValue, UnitMeasure enUnitMeasure, unsigned short ushDPI = 96);
static bool GetValue(const std::wstring& wsValue, double& dValue, UnitMeasure& enUnitMeasure);
};
}

View File

@ -0,0 +1,180 @@
#include "ConstValues.h"
namespace NSCSS
{
CSizeWindow::CSizeWindow()
: m_ushWidth(0), m_ushHeight(0)
{}
CSizeWindow::CSizeWindow(unsigned short unWidth, unsigned short unHeight)
: m_ushWidth(unWidth), m_ushHeight(unHeight)
{}
bool CSizeWindow::Empty() const
{
return ((0 == m_ushWidth) && (0 == m_ushHeight));
}
void CSizeWindow::Clear()
{
m_ushWidth = m_ushHeight = 0;
}
bool CSizeWindow::operator==(const CSizeWindow &oSizeWindow) const
{
return ((m_ushWidth == oSizeWindow.m_ushWidth) && (m_ushHeight == oSizeWindow.m_ushHeight));
}
bool CSizeWindow::operator!=(const CSizeWindow &oSizeWindow) const
{
return ((m_ushWidth != oSizeWindow.m_ushWidth) || (m_ushHeight != oSizeWindow.m_ushHeight));
}
bool StatistickElement::operator<(const StatistickElement &oStatistickElement) const
{
return sValue < oStatistickElement.sValue;
}
void CTree::CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics)
{
if (!oTree.m_oNode.m_wsId.empty())
++mStatictics[StatistickElement{StatistickElement::IsId, L'#' + oTree.m_oNode.m_wsId}];
if (!oTree.m_oNode.m_wsStyle.empty())
++mStatictics[StatistickElement{StatistickElement::IsStyle, oTree.m_oNode.m_wsStyle}];
if (!oTree.m_arrChild.empty())
for (const CTree& oChildren : oTree.m_arrChild)
CountingNumberRepetitions(oChildren, mStatictics);
}
namespace NSConstValues
{
const std::map<std::wstring, std::wstring> COLORS
{
/* Red tones */
{L"indianeed", L"CD5C5C"}, {L"lightcoral", L"F08080"}, {L"salmon", L"FA8072"},
{L"darksalmon", L"E9967A"}, {L"lightsalmon", L"FFA07A"}, {L"crimson", L"DC143C"},
{L"red", L"FF0000"}, {L"firebrick", L"B22222"}, {L"darkred", L"8B0000"},
/* Pink tones */
{L"pink", L"FFC0CB"}, {L"lightpink", L"FFB6C1"}, {L"hotpink", L"FF69B4"},
{L"deeppink", L"FF1493"}, {L"mediumvioletred", L"C71585"}, {L"palevioleteed", L"DB7093"},
/* Orange tones */
{L"lightsalmon", L"FFA07A"}, {L"coral", L"FF7F50"}, {L"tomato", L"FF6347"},
{L"orangered", L"FF4500"}, {L"darkorange", L"FF8C00"}, {L"orange", L"FFA500"},
/* Yellow tones */
{L"gold", L"FFD700"}, {L"yellow", L"FFFF00"}, {L"lightyellow", L"FFFFE0"},
{L"lemonchiffon", L"FFFACD"}, {L"lightgoldenrodyellow", L"FAFAD2"}, {L"papayawhip", L"FFEFD5"},
{L"moccasin", L"FFE4B5"}, {L"peachpuff", L"FFDAB9"}, {L"palegoldenrod", L"EEE8AA"},
{L"khaki", L"F0E68C"}, {L"darkkhaki", L"BDB76B"},
/* Purple tones */
{L"lavender", L"E6E6FA"}, {L"thistle", L"D8BFD8"}, {L"plum", L"DDA0DD"},
{L"violet", L"EE82EE"}, {L"orchid", L"DA70D6"}, {L"fuchsia", L"FF00FF"},
{L"magenta", L"FF00FF"}, {L"mediumorchid", L"BA55D3"}, {L"mediumpurple", L"9370DB"},
{L"blueviolet", L"8A2BE2"}, {L"darkviolet", L"9400D3"}, {L"darkorchid", L"9932CC"},
{L"darkmagenta", L"8B008B"}, {L"purple", L"800080"}, {L"indigo", L"4B0082"},
{L"slateblue", L"6A5ACD"}, {L"darkslateblue", L"483D8B"},
/* Brown tones */
{L"cornsilk", L"FFF8DC"}, {L"blanchedalmond", L"FFEBCD"}, {L"bisque", L"FFE4C4"},
{L"navajowhite", L"FFDEAD"}, {L"wheat", L"F5DEB3"}, {L"burlywood", L"DEB887"},
{L"tan", L"D2B48C"}, {L"rosybrown", L"BC8F8F"}, {L"sandybrown", L"F4A460"},
{L"goldenrod", L"DAA520"}, {L"darkgoldenrod", L"B8860B"}, {L"peru", L"CD853F"},
{L"chocolate", L"D2691E"}, {L"saddlebrown", L"8B4513"}, {L"sienna", L"A0522D"},
{L"brown", L"A52A2A"}, {L"maroon", L"800000"},
/* Green tones */
{L"greenyellow", L"ADFF2F"}, {L"chartreuse", L"7FFF00"}, {L"lawngreen", L"7CFC00"},
{L"lime", L"00FF00"}, {L"limegreen", L"32CD32"}, {L"palegreen", L"98FB98"},
{L"lightgreen", L"90EE90"}, {L"mediumspringgreen", L"00FA9A"}, {L"springgreen", L"00FF7F"},
{L"mediumseagreen", L"3CB371"}, {L"seagreen", L"2E8B57"}, {L"forestgreen", L"228B22"},
{L"green", L"008000"}, {L"darkgreen", L"006400"}, {L"yellowgreen", L"9ACD32"},
{L"olivedrab", L"6B8E23"}, {L"olive", L"808000"}, {L"darkolivegreen",L"556B2F"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
{L"mediumaquamarine", L"66CDAA"}, {L"darkseagreen", L"8FBC8F"}, {L"lightseagreen", L"20B2AA"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
{L"darkcyan", L"008B8B"}, {L"teal", L"008080"},
/* Blue tones */
{L"aqua", L"00FFFF"}, {L"cyan", L"00FFFF"}, {L"lightcyan", L"E0FFFF"},
{L"paleturquoise", L"AFEEEE"}, {L"aquamarine", L"7FFFD4"}, {L"turquoise", L"40E0D0"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
{L"mediumturquoise", L"48D1CC"}, {L"darkturquoise", L"00CED1"}, {L"cadetblue", L"5F9EA0"},
{L"steelblue", L"4682B4"}, {L"lightsteelblue", L"B0C4DE"}, {L"powderblue", L"B0E0E6"},
{L"lightblue", L"ADD8E6"}, {L"skyblue", L"87CEEB"}, {L"lightskyblue", L"87CEFA"},
{L"deepskyblue", L"00BFFF"}, {L"dodgerblue", L"1E90FF"}, {L"cornflowerblue",L"6495ED"},
{L"mediumdlateblue", L"7B68EE"}, {L"royalblue", L"4169E1"}, {L"blue", L"0000FF"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
{L"mediumblue", L"0000CD"}, {L"darkblue", L"00008B"}, {L"navy", L"000080"},
{L"midnightblue", L"191970"},
/* White tones */
{L"white", L"FFFFFF"}, {L"snow", L"FFFAFA"}, {L"honeydew", L"F0FFF0"},
{L"mintcream", L"F5FFFA"}, {L"azure", L"F0FFFF"}, {L"aliceblue", L"F0F8FF"},
{L"ghostwhite", L"F8F8FF"}, {L"whitesmoke", L"F5F5F5"}, {L"seashell", L"FFF5EE"},
{L"beige", L"F5F5DC"}, {L"oldlace", L"FDF5E6"}, {L"floralwhite", L"FFFAF0"},
{L"ivory", L"FFFFF0"}, {L"antiquewhite", L"FAEBD7"}, {L"linen", L"FAF0E6"},
{L"lavenderblush", L"FFF0F5"}, {L"mistyrose", L"FFE4E1"},
/* Gray tones */
{L"gainsboro", L"DCDCDC"}, {L"lightgray", L"D3D3D3"}, {L"silver", L"C0C0C0"},
{L"darkgray", L"A9A9A9"}, {L"gray", L"808080"}, {L"dimgray", L"696969"},
{L"lightslategray", L"778899"}, {L"slategray", L"708090"}, {L"darkslategray", L"2F4F4F"},
{L"black", L"000000"},
/* Outdated */
{L"windowtext", L"000000"}, {L"transparent", L"000000"}
};
const std::vector<std::wstring> DISPLAY_VALUES
{
/* <display-outside> values */
L"block", L"inline", L"run-in",
/* <display-inside> values */
L"flow", L"flow-root", L"table", L"flex", L"grid", L"ruby",
/* <display-outside> plus <display-inside> values */
L"block flow", L"inline table", L"flex run-in",
/* <display-listitem> values */
L"list-item", L"list-item block", L"list-item inline", L"list-item flow",
L"list-item flow-root", L"list-item block flow",
L"list-item block flow-root", L"flow list-item block",
/* <display-internal> values */
L"table-row-group", L"table-header-group", L"table-footer-group",
L"table-row", L"table-cell", L"table-column-group", L"table-column",
L"table-caption", L"ruby-base", L"ruby-text", L"ruby-base-container",
L"ruby-text-container",
/* <display-box> values */
L"contents", L"none",
/* <display-legacy> values */
L"inline-block", L"inline-table", L"inline-flex", L"inline-grid",
/* Global values */
L"inherit", L"initial", L"unset"
};
const std::wstring arPseudoClasses[33]
{
L"invalid",
L"read-only",
L"-moz-placeholder",
L"-webkit-input-placeholder",
L"active",
L"checked",
L"default",
L"disabled",
L"empty",
L"enabled",
L"first-child",
L"first-of-type",
L"focus",
L"hover",
L"indeterminate",
L"lang",
L"last-child",
L"last-of-type",
L"link",
L"not",
L"nth-child",
L"nth-last-child",
L"nth-last-of-type",
L"nth-of-type",
L"only-child",
L"only-of-type",
L"optional",
L"read-write",
L"required",
L"root",
L"target",
L"valid",
L"visited"
};
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,169 @@
#include "StaticFunctions.h"
namespace NSCSS
{
namespace NS_STATIC_FUNCTIONS
{
std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding)
{
const std::string& sEnc = U_TO_UTF8(sEncoding);
NSUnicodeConverter::CUnicodeConverter oConverter;
const std::wstring& sUnicodeContent = oConverter.toUnicode(sString, sEnc.c_str());
return U_TO_UTF8(oConverter.toUnicode(sString, sEnc.c_str()));
}
std::string GetContentAsUTF8(const std::wstring& sFileName)
{
std::string sContent;
// читаем файл как есть. utf-8 тут просто название.
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sFileName, sContent))
return sContent;
std::string sEncoding;
if (true)
{
// определяем кодировку
const std::string::size_type& posCharset = sContent.find("@charset");
if (std::string::npos != posCharset)
{
std::string::size_type pos1 = sContent.find_first_of("\"';", posCharset);
if (std::string::npos != pos1)
{
pos1 += 1;
std::string::size_type pos2 = sContent.find_first_of("\"';", pos1);
if (std::string::npos != pos2)
{
sEncoding = sContent.substr(pos1, pos2 - pos1);
}
// check valid
if (std::string::npos != sEncoding.find_first_of(" \n\r\t\f\v"))
sEncoding = "";
}
}
}
if (sEncoding.empty())
sEncoding = "utf-8";
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sEncoding.c_str()));
}
return sContent;
}
double ReadDouble(const std::wstring& wsValue)
{
double dValue;
std::wistringstream(wsValue) >> dValue;
return dValue;
}
std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
{
std::vector<double> arValues;
std::wregex oPattern(LR"([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)");
std::wsregex_iterator oIter(wsValue.begin(), wsValue.end(), oPattern);
std::wsregex_iterator oEndIter;
for (; oIter != oEndIter; ++oIter)
arValues.push_back(std::stod(oIter->str()));
return arValues;
}
std::vector<std::wstring> GetWordsW(const std::wstring& wsLine, bool bWithSigns, const std::wstring& wsSigns)
{
if (wsLine.empty())
return {};
if (wsLine.find_first_of(wsSigns) == std::wstring::npos)
return std::vector<std::wstring>({wsLine});
std::vector<std::wstring> arWords;
std::wstring::const_iterator oFirstNotSpace = std::find_if_not(wsLine.begin(), wsLine.end(), std::iswspace);
std::wstring::const_iterator oLastNotSpace;
while (oFirstNotSpace != wsLine.end())
{
oLastNotSpace = std::find_first_of(oFirstNotSpace + ((bWithSigns) ? 1 : 0), wsLine.end(), wsSigns.begin(), wsSigns.end());
arWords.push_back(std::wstring(oFirstNotSpace, oLastNotSpace));
oFirstNotSpace = std::find_if_not(oLastNotSpace + ((bWithSigns) ? 1 : 0), wsLine.end(), std::iswspace);
}
return arWords;
}
std::vector<unsigned short int> GetWeightSelector(const std::wstring& wsSelector)
{
if (wsSelector.empty())
return std::vector<unsigned short int>{0, 0, 0, 0};
std::vector<unsigned short int> arWeight = {0, 0, 0, 0};
std::wstring sReverseSelector = wsSelector;
std::reverse(sReverseSelector.begin(), sReverseSelector.end());
const std::vector<std::wstring> arSelectors = NS_STATIC_FUNCTIONS::GetWordsW(sReverseSelector, true, L" .#:");
for (const std::wstring& sSel : arSelectors)
{
if (sSel == L"*")
++arWeight[3];
else if (sSel.rfind(L'#') != std::wstring::npos)
++arWeight[0];
else if (sSel.rfind(L':') != std::wstring::npos)
{
std::wstring sTemp(sSel);
sTemp.erase(std::remove_if(sTemp.begin(), sTemp.end(), [] (const wchar_t& wc) { return !std::iswalpha(wc);}));
// std::find(NSConstValues::arPseudoClasses.begin(), NSConstValues::arPseudoClasses.end(), sTemp) != NSConstValues::arPseudoClasses.end() ? ++arWeight[1] : ++arWeight[2];
}
else if (sSel.find_last_of(L".[]") != std::wstring::npos)
++arWeight[1];
else
++arWeight[2];
}
return arWeight;
}
std::map<std::wstring, std::wstring> GetRules(const std::wstring& wsStyles)
{
if (wsStyles.empty())
return {};
std::map<std::wstring, std::wstring> mRules;
std::wstring::const_iterator oStartProperty = std::find_if_not(wsStyles.begin(), wsStyles.end(), std::iswspace);
std::wstring::const_iterator oEndProperty, oStartValue, oEndValue;
while (wsStyles.end() != oStartProperty)
{
oEndProperty = std::find_if(oStartProperty, wsStyles.end(), [](const wchar_t &wcChar){ return L':' == wcChar;});
oStartValue = std::find_if_not(oEndProperty + 1, wsStyles.end(), std::iswspace);
if (wsStyles.end() == oEndProperty || wsStyles.end() == oStartValue)
break;
oEndValue = std::find_if(oStartValue, wsStyles.end(), [](const wchar_t &wcChar){ return L';' == wcChar;});
mRules.insert({std::wstring(oStartProperty, oEndProperty), std::wstring(oStartValue, oEndValue)});
if (wsStyles.end() == oEndValue)
break;
oStartProperty = std::find_if_not(oEndValue + 1, wsStyles.end(), std::iswspace);
}
return mRules;
}
}
}

View File

@ -3,503 +3,71 @@
#include "../../../../../UnicodeConverter/UnicodeConverter.h"
#include "../../../../../DesktopEditor/common/File.h"
#include "CNode.h"
#include <algorithm>
#include <cwctype>
#include <sstream>
#include <string>
#include <vector>
#include <regex>
#include <list>
namespace NSCSS
{
namespace NS_STATIC_FUNCTIONS
{
inline static std::wstring stringToWstring(const std::string& sString)
{
return UTF8_TO_U(sString);
}
namespace NS_STATIC_FUNCTIONS
{
std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding);
std::string GetContentAsUTF8(const std::wstring& sFileName);
inline static std::string wstringToString(const std::wstring& sWstring)
{
return U_TO_UTF8(sWstring);
}
double ReadDouble(const std::wstring& wsValue);
std::vector<double> ReadDoubleValues(const std::wstring& wsValue);
inline static std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding)
{
const std::string& sEnc = U_TO_UTF8(sEncoding);
std::vector<std::wstring> GetWordsW(const std::wstring& wsLine, bool bWithSigns = false, const std::wstring& wsSigns = L" \n\r\t\f\v:;,!");
std::vector<unsigned short int> GetWeightSelector(const std::wstring& sSelector);
std::map<std::wstring, std::wstring> GetRules(const std::wstring& wsStyles);
}
NSUnicodeConverter::CUnicodeConverter oConverter;
const std::wstring& sUnicodeContent = oConverter.toUnicode(sString, sEnc.c_str());
return U_TO_UTF8(sUnicodeContent);
}
#define SWITCH(str) switch(SWITCH_CASE::str_hash_for_switch(str))
#define CASE(str) static_assert(SWITCH_CASE::str_is_correct(str) && (SWITCH_CASE::str_len(str) <= SWITCH_CASE::MAX_LEN),\
"CASE string contains wrong characters, or its length is greater than 9");\
case SWITCH_CASE::str_hash(str, SWITCH_CASE::str_len(str))
#define DEFAULT default
inline static std::string GetContentAsUTF8(const std::wstring& sFileName)
{
std::string sFileContent;
namespace SWITCH_CASE
{
typedef unsigned long long ullong;
// читаем файл как есть. utf-8 тут просто название.
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sFileName, sFileContent))
return sFileContent;
const unsigned int MAX_LEN = 32;
const ullong N_HASH = static_cast<ullong>(-1);
std::string sEncoding;
if (true)
{
// определяем кодировку
const std::string::size_type& posCharset = sFileContent.find("@charset");
if (std::string::npos != posCharset)
{
std::string::size_type pos1 = sFileContent.find_first_of("\"';", posCharset);
if (std::string::npos != pos1)
{
pos1 += 1;
std::string::size_type pos2 = sFileContent.find_first_of("\"';", pos1);
if (std::string::npos != pos2)
{
sEncoding = sFileContent.substr(pos1, pos2 - pos1);
}
// check valid
if (std::string::npos != sEncoding.find_first_of(" \n\r\t\f\v"))
sEncoding = "";
}
}
}
if (sEncoding.empty())
sEncoding = "utf-8";
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
}
return sFileContent;
}
inline static bool NumberInWString(const std::wstring& sString)
{
if (sString.empty())
return false;
size_t posDigit = sString.find_first_of(L"0123456789");
// size_t posNoDigit = sString.find_first_not_of(L" \n\r\t\f\v123456789.");
if (posDigit != std::wstring::npos)
return true;
return false;
}
inline std::wstring StripSymbols(const std::wstring& sValue, const std::wstring& sSymbols = L" \n\r\t\f\v")
{
if (sValue.empty())
return std::wstring();
size_t start = sValue.find_first_not_of(sSymbols);
if (std::wstring::npos == start)
return sValue;
size_t end = sValue.find_last_not_of(sSymbols); // точно >=0
return sValue.substr(start, end - start + 1);
}
inline std::vector<std::string> GetWords(const std::wstring& sLine)
{
if (sLine.empty())
return {};
std::vector<std::string> arWords;
arWords.reserve(16);
const std::string sTemp = wstringToString(sLine);
size_t posFirstNotSpace = sTemp.find_first_not_of(" \n\r\t\f\v:;,");
while (posFirstNotSpace != std::wstring::npos)
{
const size_t& posLastNotSpace = sTemp.find_first_of(" \n\r\t\f\v:;,", posFirstNotSpace);
arWords.push_back(sTemp.substr(posFirstNotSpace, posLastNotSpace - posFirstNotSpace));
posFirstNotSpace = sTemp.find_first_not_of(" \n\r\t\f\v:;,", posLastNotSpace);
}
return arWords;
}
inline std::vector<std::wstring> GetWordsW(const std::wstring& sLine, const std::wstring& sSigns = L" \n\r\t\f\v:;,")
{
if (sLine.empty())
return {};
if (sLine.find_first_of(sSigns) == std::wstring::npos)
return std::vector<std::wstring>({sLine});
std::vector<std::wstring> arWords;
arWords.reserve(16);
size_t posFirstNotSpace = sLine.find_first_not_of(sSigns);
while (posFirstNotSpace != std::wstring::npos)
{
const size_t& posLastNotSpace = sLine.find_first_of(sSigns, posFirstNotSpace);
arWords.push_back(sLine.substr(posFirstNotSpace, posLastNotSpace - posFirstNotSpace));
posFirstNotSpace = sLine.find_first_not_of(sSigns, posLastNotSpace);
}
return arWords;
}
inline double ReadDouble(const std::wstring& wsValue)
constexpr ullong raise_128_to(const wchar_t power)
{
double dValue;
std::wistringstream(wsValue) >> dValue;
return dValue;
return (1ULL << 7) * power;
}
inline std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
constexpr bool str_is_correct(const wchar_t* const str)
{
std::vector<double> arValues;
std::wregex oPattern(LR"([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)");
std::wsregex_iterator oIter(wsValue.begin(), wsValue.end(), oPattern);
std::wsregex_iterator oEndIter;
for (; oIter != oEndIter; ++oIter)
arValues.push_back(std::stod(oIter->str()));
return arValues;
return (static_cast<wchar_t>(*str) > 0) ? str_is_correct(str + 1) : (*str ? false : true);
}
inline bool ConvertAbsoluteValue(std::wstring& sAbsoluteValue, const float &unId)
{
if (sAbsoluteValue.empty())
return false;
bool bIsConvert = false;
std::map<std::wstring, std::wstring> arAbsoluteFontValues = {{L"xx-small", L"9px"}, {L"x-small", L"10px"},
{L"small", L"13px"}, {L"medium", L"16px"},
{L"large", L"18px"}, {L"x-large", L"24px"},
{L"xx-large", L"32px"}};
std::map<std::wstring, std::wstring> arAbsoluteBorderValues = {{L"thin", L"2px"},
{L"medium", L"4px"},
{L"thick", L"6px"}};
std::map<std::wstring, std::wstring> arAbsoluteValues = ((unId == 0.0f) ? arAbsoluteBorderValues : arAbsoluteFontValues);
if (sAbsoluteValue.find(L' ') == std::wstring::npos && arAbsoluteValues.find(sAbsoluteValue) != arAbsoluteValues.end())
{
sAbsoluteValue = arAbsoluteValues[sAbsoluteValue];
return true;
}
std::wstring sValue;
sValue.reserve(sAbsoluteValue.length() + 1);
for (const std::wstring& sWord : GetWordsW(sAbsoluteValue))
{
std::map<std::wstring, std::wstring>::iterator oFind = arAbsoluteValues.find(sWord);
if (oFind != arAbsoluteValues.end())
{
bIsConvert = true;
sValue += oFind->second + L' ';
}
else
sValue += sWord + L' ';
}
sValue.pop_back();
if (bIsConvert)
sAbsoluteValue = sValue;
return bIsConvert;
}
inline std::vector<std::string> GetSelectorsList(const std::wstring& sSelectors)
{
if (sSelectors.empty())
return std::vector<std::string>();
std::wstring sNames = sSelectors;
std::wstring sClasses;
std::wstring sIds;
size_t posLattice = sNames.find(L"#");
if (posLattice != std::wstring::npos)
{
sNames = sSelectors.substr(0, posLattice);
sIds = sSelectors.substr(posLattice);
}
size_t posPoint = sNames.find(L'.');
if (posPoint != std::wstring::npos)
{
sNames = sSelectors.substr(0, posPoint);
sClasses = sSelectors.substr(posPoint);
posLattice = sClasses.find(L'#');
if (posLattice != std::wstring::npos)
sClasses = sClasses.substr(0, posLattice);
}
std::vector<std::string> arNames = GetWords(sNames);
std::vector<std::string> arClasses = GetWords(sClasses);
std::vector<std::string> arIds = GetWords(sIds);
std::vector<std::string> arSelectors(arNames);
arSelectors.reserve(arNames.size() * arClasses.size() + arNames.size() * arIds.size() + arClasses.size() * arIds.size());
for (std::string& sClass : arClasses)
{
if (sClass.find('.') == std::string::npos)
sClass = '.' + sClass;
arSelectors.push_back(sClass);
for (const std::string& sName : arNames)
arSelectors.push_back(sName + sClass);
for (const std::string& sId : arIds)
arSelectors.push_back(sClass + sId);
}
for (std::string& sId : arIds)
{
if (sId.find('#') == std::string::npos)
sId = '#' + sId;
arSelectors.push_back(sId);
for (const std::string& sName : arNames)
arSelectors.push_back(sName + sId);
}
return arSelectors;
}
inline std::vector<std::string> GetSelectorsListWithParents(const std::vector<CNode> &arParents)
{
if (arParents.size() < 2)
return std::vector<std::string>();
if (arParents.back().m_sName.empty())
return std::vector<std::string>();
std::vector<std::string> arSelectors;
short int nIndex = 0;
while (nIndex < static_cast<short int>(arParents.size() - 1))
{
std::wstring sSelector;
for (unsigned short int i = nIndex; i < arParents.size() - 1; ++i)
{
if (arParents[i].m_sName.empty())
continue;
std::wstring sParentSelector = arParents[i].m_sName;
if (!arParents[i].m_sClass.empty())
sParentSelector += L'.' + arParents[i].m_sClass;
if (!arParents[i].m_sId.empty())
sParentSelector += L'#' + arParents[i].m_sId;
sSelector += sParentSelector + L' ';
}
std::wstring sChildrenSelector = arParents.back().m_sName;
if (!arParents.back().m_sClass.empty())
sChildrenSelector += L'.' + arParents.back().m_sClass;
if (!arParents.back().m_sId.empty())
sChildrenSelector += L'#' + arParents.back().m_sId;
sSelector += sChildrenSelector;
++nIndex;
arSelectors.push_back(wstringToString(sSelector));
}
return arSelectors;
}
inline std::vector<std::wstring> GetWordsWithSigns(const std::wstring& sLine, const std::wstring& sSigns = L" \n\r\t\f\v:;,!")
{
if (sLine.empty())
return {};
if (sLine.find_first_of(sSigns) == std::wstring::npos)
return std::vector<std::wstring>({sLine});
std::vector<std::wstring> arWords;
std::wstring::const_iterator oFirstNotSpace = std::find_if_not(sLine.begin(), sLine.end(), std::iswspace);
std::wstring::const_iterator oLastNotSpace;
while (oFirstNotSpace != sLine.end())
{
oLastNotSpace = std::find_first_of(oFirstNotSpace + 1, sLine.end(), sSigns.begin(), sSigns.end());
arWords.push_back(std::wstring(oFirstNotSpace, oLastNotSpace));
oFirstNotSpace = std::find_if_not(oLastNotSpace + 1, sLine.end(), std::iswspace);
}
return arWords;
}
inline std::map<std::wstring, std::wstring> GetRules(const std::wstring& wsStyles)
constexpr unsigned int str_len(const wchar_t* const str)
{
if (wsStyles.empty())
return {};
std::map<std::wstring, std::wstring> mRules;
std::wstring::const_iterator oStartProperty = std::find_if_not(wsStyles.begin(), wsStyles.end(), std::iswspace);
std::wstring::const_iterator oEndProperty, oStartValue, oEndValue;
while (wsStyles.end() != oStartProperty)
{
oEndProperty = std::find_if(oStartProperty, wsStyles.end(), [](const wchar_t &wcChar){ return L':' == wcChar;});
oStartValue = std::find_if_not(oEndProperty + 1, wsStyles.end(), std::iswspace);
if (wsStyles.end() == oEndProperty || wsStyles.end() == oStartValue)
break;
oEndValue = std::find_if(oStartValue, wsStyles.end(), [](const wchar_t &wcChar){ return L';' == wcChar;});
mRules.insert({std::wstring(oStartProperty, oEndProperty), std::wstring(oStartValue, oEndValue)});
if (wsStyles.end() == oEndValue)
break;
oStartProperty = std::find_if_not(oEndValue + 1, wsStyles.end(), std::iswspace);
}
return mRules;
return *str ? (1 + str_len(str + 1)) : 0;
}
inline bool IsDigit(const std::wstring& sValue)
{
return sValue.empty() ? false : std::all_of(sValue.begin(), sValue.end(), [] (const wchar_t& cChar) { return iswdigit(cChar); });
}
inline std::wstring ConvertRgbToHex(const std::wstring& sRgbValue)
{
size_t posFirst = sRgbValue.find_first_of(L"01234567890");
if (posFirst == std::wstring::npos)
return std::wstring();
const wchar_t cHex[17]{L"0123456789abcdef"};
std::wstring sValue;
while (posFirst != std::wstring::npos)
{
std::wstring sHex;
const size_t posSecond = sRgbValue.find_first_of(L", )", posFirst);
short int nValue = std::stoi(sRgbValue.substr(posFirst, posSecond - posFirst));
if (nValue < 0)
sHex += L"00";
else if (nValue > 255)
sHex += L"ff";
else
{
do
{
sHex = cHex[nValue % 16] + sHex;
nValue /= 16;
}
while (nValue != 0);
}
if (sHex.length() < 2)
sHex = L"0" + sHex;
sValue += sHex;
posFirst = sRgbValue.find_first_of(L"01234567890", posSecond);
}
return sValue;
constexpr ullong str_hash(const wchar_t* const str, const wchar_t current_len)
{
return *str ? (raise_128_to(current_len - 1) * static_cast<wchar_t>(*str) + str_hash(str + 1, current_len - 1)) : 0;
}
inline std::vector<unsigned short int> GetWeightSelector(const std::wstring& sSelector)
{
if (sSelector.empty())
return std::vector<unsigned short int>{0, 0, 0, 0};
inline ullong str_hash_for_switch(const wchar_t* const str)
{
return (str_is_correct(str) && (str_len(str) <= MAX_LEN)) ? str_hash(str, str_len(str)) : N_HASH;
}
std::vector<unsigned short int> arWeight = {0, 0, 0, 0};
std::wstring sReverseSelector = sSelector;
std::reverse(sReverseSelector.begin(), sReverseSelector.end());
const std::vector<std::wstring> arSelectors = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sReverseSelector, L" .#:");
for (const std::wstring& sSel : arSelectors)
{
if (sSel == L"*")
++arWeight[3];
else if (sSel.rfind(L'#') != std::wstring::npos)
++arWeight[0];
else if (sSel.rfind(L':') != std::wstring::npos)
{
std::wstring sTemp(sSel);
sTemp.erase(std::remove_if(sTemp.begin(), sTemp.end(), [] (const wchar_t& wc) { return !std::iswalpha(wc);}));
// std::find(NSConstValues::arPseudoClasses.begin(), NSConstValues::arPseudoClasses.end(), sTemp) != NSConstValues::arPseudoClasses.end() ? ++arWeight[1] : ++arWeight[2];
}
else if (sSel.find_last_of(L".[]") != std::wstring::npos)
++arWeight[1];
else
++arWeight[2];
}
return arWeight;
}
inline bool IsTrue(const std::vector<bool> arValues)
{
for (const bool bValue : arValues)
if (!bValue)
return false;
return true;
}
}
#define SWITCH(str) switch(SWITCH_CASE::str_hash_for_switch(str))
#define CASE(str) static_assert(SWITCH_CASE::str_is_correct(str) && (SWITCH_CASE::str_len(str) <= SWITCH_CASE::MAX_LEN),\
"CASE string contains wrong characters, or its length is greater than 9");\
case SWITCH_CASE::str_hash(str, SWITCH_CASE::str_len(str))
#define DEFAULT default
namespace SWITCH_CASE
{
typedef unsigned long long ullong;
const unsigned int MAX_LEN = 32;
const ullong N_HASH = static_cast<ullong>(-1);
constexpr ullong raise_128_to(const wchar_t power)
{
return (1ULL << 7) * power;
}
constexpr bool str_is_correct(const wchar_t* const str)
{
return (static_cast<wchar_t>(*str) > 0) ? str_is_correct(str + 1) : (*str ? false : true);
}
constexpr unsigned int str_len(const wchar_t* const str)
{
return *str ? (1 + str_len(str + 1)) : 0;
}
constexpr ullong str_hash(const wchar_t* const str, const wchar_t current_len)
{
return *str ? (raise_128_to(current_len - 1) * static_cast<wchar_t>(*str) + str_hash(str + 1, current_len - 1)) : 0;
}
inline ullong str_hash_for_switch(const wchar_t* const str)
{
return (str_is_correct(str) && (str_len(str) <= MAX_LEN)) ? str_hash(str, str_len(str)) : N_HASH;
}
inline ullong str_hash_for_switch(const std::wstring& str)
{
return (str_is_correct(str.c_str()) && (str.length() <= MAX_LEN)) ? str_hash(str.c_str(), str.length()) : N_HASH;
}
}
inline ullong str_hash_for_switch(const std::wstring& str)
{
return (str_is_correct(str.c_str()) && (str.length() <= MAX_LEN)) ? str_hash(str.c_str(), str.length()) : N_HASH;
}
}
}
#endif // STATICFUNCTIONS_H

View File

@ -574,8 +574,8 @@ namespace NSCSS
}
}
const std::map<std::wstring, std::wstring>::const_iterator oHEX = NSConstValues::NSMaps::mColors.find(wsNewValue);
if (oHEX != NSConstValues::NSMaps::mColors.end())
const std::map<std::wstring, std::wstring>::const_iterator oHEX = NSConstValues::COLORS.find(wsNewValue);
if (oHEX != NSConstValues::COLORS.end())
{
m_oValue.SetHEX(oHEX->second);
m_unLevel = unLevel;
@ -1053,7 +1053,7 @@ namespace NSCSS
bool CDisplay::SetDisplay(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
return m_oHAlign.SetValue(wsValue, NSConstValues::arDisplayValues, unLevel, bHardMode);
return m_oHAlign.SetValue(wsValue, NSConstValues::DISPLAY_VALUES, unLevel, bHardMode);
}
const CDigit& CDisplay::GetX() const
@ -1323,7 +1323,22 @@ namespace NSCSS
bool CBorderSide::SetWidth(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
return m_oWidth.SetValue(wsValue, unLevel, bHardMode);
const std::map<std::wstring, std::wstring> arAbsoluteBorderValues =
{{L"thin", L"2px"},
{L"medium", L"4px"},
{L"thick", L"6px"}};
size_t unFoundPos = std::wstring::npos;
std::wstring wsNewValue(wsValue);
for (const std::pair<std::wstring, std::wstring> oAbsValue : arAbsoluteBorderValues)
{
unFoundPos = wsNewValue.find(oAbsValue.first);
if (std::wstring::npos != unFoundPos)
wsNewValue.replace(unFoundPos, oAbsValue.first.length(), oAbsValue.second);
}
return m_oWidth.SetValue(wsNewValue, unLevel, bHardMode);
}
bool CBorderSide::SetStyle(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
@ -2002,7 +2017,23 @@ namespace NSCSS
bool CFont::SetSize(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
return m_oSize.SetValue(wsValue, unLevel, bHardMode);
const std::map<std::wstring, std::wstring> arAbsoluteFontValues =
{{L"xx-small", L"9px"}, {L"x-small", L"10px"},
{L"small", L"13px"}, {L"medium", L"16px"},
{L"large", L"18px"}, {L"x-large", L"24px"},
{L"xx-large", L"32px"}};
size_t unFoundPos = std::wstring::npos;
std::wstring wsNewValue(wsValue);
for (const std::pair<std::wstring, std::wstring> oAbsValue : arAbsoluteFontValues)
{
unFoundPos = wsNewValue.find(oAbsValue.first);
if (std::wstring::npos != unFoundPos)
wsNewValue.replace(unFoundPos, oAbsValue.first.length(), oAbsValue.second);
}
return m_oSize.SetValue(wsNewValue, unLevel, bHardMode);
}
bool CFont::SetLineHeight(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)

View File

@ -8,64 +8,64 @@
#include <iostream>
namespace NSCSS
{
class CStyleUsed
{
CCompiledStyle m_oStyle;
bool m_bIsPStyle;
std::wstring m_sId;
class CStyleUsed
{
CCompiledStyle m_oStyle;
bool m_bIsPStyle;
std::wstring m_sId;
public:
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle) : m_oStyle(oStyle), m_bIsPStyle(bIsPStyle) {}
public:
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle) : m_oStyle(oStyle), m_bIsPStyle(bIsPStyle) {}
bool operator==(const CStyleUsed& oUsedStyle) const
{
return (m_bIsPStyle == oUsedStyle.m_bIsPStyle) && (m_oStyle == oUsedStyle.m_oStyle);
}
bool operator==(const CStyleUsed& oUsedStyle) const
{
return (m_bIsPStyle == oUsedStyle.m_bIsPStyle) && (m_oStyle == oUsedStyle.m_oStyle);
}
std::wstring getId()
{
return m_sId;
}
std::wstring getId()
{
return m_sId;
}
void setId(const std::wstring& sId)
{
m_sId = sId;
}
void setId(const std::wstring& sId)
{
m_sId = sId;
}
};
};
class CSSCALCULATOR_EXPORT CDocumentStyle
{
std::list<std::wstring> m_arStandardStylesUsed;
std::list<std::wstring> m_arStandardStyles;
std::list<CStyleUsed> m_arStyleUsed;
class CSSCALCULATOR_EXPORT CDocumentStyle
{
std::list<std::wstring> m_arStandardStylesUsed;
std::list<std::wstring> m_arStandardStyles;
std::list<CStyleUsed> m_arStyleUsed;
std::wstring m_sStyle;
std::wstring m_sId;
std::wstring m_sStyle;
std::wstring m_sId;
void CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
void CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
public:
CDocumentStyle();
~CDocumentStyle();
public:
CDocumentStyle();
~CDocumentStyle();
void WritePStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteRStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteLitePStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteLiteRStyle(const NSCSS::CCompiledStyle& oStyle);
void WritePStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteRStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteLitePStyle(const NSCSS::CCompiledStyle& oStyle);
void WriteLiteRStyle(const NSCSS::CCompiledStyle& oStyle);
void SetStyle(const std::wstring& sStyle);
void SetId (const std::wstring& sId);
void SetStyle(const std::wstring& sStyle);
void SetId (const std::wstring& sId);
std::wstring GetStyle() const;
std::wstring GetIdAndClear();
std::wstring GetStyle() const;
std::wstring GetIdAndClear();
void Clear();
};
void Clear();
};
}
#endif // CDOCUMENTSTYLE_H

View File

@ -8,40 +8,40 @@
class CXmlElement
{
std::map<NSCSS::NSConstValues::NSProperties::RunnerProperties, std::wstring> m_mRStyleValues;
std::map<NSCSS::NSConstValues::NSProperties::ParagraphProperties, std::wstring> m_mPStyleValues;
std::map<NSCSS::NSConstValues::NSProperties::BasicProperties, std::wstring> m_mBasicValues;
std::map<NSCSS::NSConstValues::NSProperties::RunnerProperties, std::wstring> m_mRStyleValues;
std::map<NSCSS::NSConstValues::NSProperties::ParagraphProperties, std::wstring> m_mPStyleValues;
std::map<NSCSS::NSConstValues::NSProperties::BasicProperties, std::wstring> m_mBasicValues;
std::wstring ConvertPStyle() const;
std::wstring ConvertRStyle() const;
std::wstring ConvertBasicInfoStyle() const;
std::wstring ConvertPStyle() const;
std::wstring ConvertRStyle() const;
std::wstring ConvertBasicInfoStyle() const;
public:
CXmlElement();
CXmlElement(const std::wstring& sNameDefaultElement);
~CXmlElement();
CXmlElement();
CXmlElement(const std::wstring& sNameDefaultElement);
~CXmlElement();
bool Empty() const;
bool Empty() const;
void CreateDefaultElement(const std::wstring& sNameDefaultElement);
void Clear();
void CreateDefaultElement(const std::wstring& sNameDefaultElement);
void Clear();
void AddPropertiesInP (const NSCSS::NSConstValues::NSProperties::ParagraphProperties& nProperties, const std::wstring& sValue);
void AddPropertiesInR (const NSCSS::NSConstValues::NSProperties::RunnerProperties& nProperties, const std::wstring& sValue);
void AddBasicProperties(const NSCSS::NSConstValues::NSProperties::BasicProperties& nProperties, const std::wstring& sValue);
void AddPropertiesInP (const NSCSS::NSConstValues::NSProperties::ParagraphProperties& nProperties, const std::wstring& sValue);
void AddPropertiesInR (const NSCSS::NSConstValues::NSProperties::RunnerProperties& nProperties, const std::wstring& sValue);
void AddBasicProperties(const NSCSS::NSConstValues::NSProperties::BasicProperties& nProperties, const std::wstring& sValue);
std::wstring GetLitePStyle() const;
std::wstring GetLiteRStyle() const;
std::wstring GetPStyle() const;
std::wstring GetRStyle() const;
std::wstring GetStyle() const;
std::wstring GetBasedOn() const;
std::wstring GetStyleId() const;
std::wstring GetName() const;
std::wstring GetLitePStyle() const;
std::wstring GetLiteRStyle() const;
std::wstring GetPStyle() const;
std::wstring GetRStyle() const;
std::wstring GetStyle() const;
std::wstring GetBasedOn() const;
std::wstring GetStyleId() const;
std::wstring GetName() const;
CXmlElement& operator+=(const CXmlElement& oElement);
CXmlElement& operator= (const CXmlElement& oelement);
bool operator== (const CXmlElement& oElement);
CXmlElement& operator+=(const CXmlElement& oElement);
CXmlElement& operator= (const CXmlElement& oelement);
bool operator== (const CXmlElement& oElement);
};
#endif // CXMLELEMENT_H