mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Fix bugs in svg conversion and optimization
This commit is contained in:
@ -14,6 +14,15 @@ namespace NSCSS
|
||||
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
|
||||
}
|
||||
|
||||
void CNode::Clear()
|
||||
{
|
||||
m_wsName .clear();
|
||||
m_wsClass .clear();
|
||||
m_wsId .clear();
|
||||
m_wsStyle .clear();
|
||||
m_mAttributes.clear();
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CNode::GetData() const
|
||||
{
|
||||
std::vector<std::wstring> arValues;
|
||||
|
||||
@ -22,6 +22,8 @@ namespace NSCSS
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
std::vector<std::wstring> GetData() const;
|
||||
bool operator< (const CNode& oNode) const;
|
||||
bool operator== (const CNode& oNode) const;
|
||||
|
||||
@ -7,12 +7,18 @@ namespace NSCSS
|
||||
return sValue < oStatistickElement.sValue;
|
||||
}
|
||||
|
||||
void CTree::Clear()
|
||||
{
|
||||
m_arrChild.clear();
|
||||
m_oNode.Clear();
|
||||
}
|
||||
|
||||
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_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)
|
||||
|
||||
@ -33,6 +33,8 @@ namespace NSCSS
|
||||
NSCSS::CNode m_oNode;
|
||||
std::vector<CTree> m_arrChild;
|
||||
|
||||
void Clear();
|
||||
|
||||
static void CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics);
|
||||
};
|
||||
|
||||
|
||||
@ -614,11 +614,11 @@ namespace NSCSS
|
||||
|
||||
void CColor::SetHEX(const std::wstring &wsValue)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if (6 != wsValue.length() && 3 != wsValue.length())
|
||||
return;
|
||||
|
||||
Clear();
|
||||
|
||||
if (6 == wsValue.length())
|
||||
m_oValue = new std::wstring(wsValue);
|
||||
else
|
||||
@ -632,8 +632,6 @@ namespace NSCSS
|
||||
|
||||
void CColor::SetUrl(const std::wstring &wsValue)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if (wsValue.empty())
|
||||
return;
|
||||
|
||||
@ -648,6 +646,8 @@ namespace NSCSS
|
||||
return;
|
||||
}
|
||||
|
||||
Clear();
|
||||
|
||||
m_oValue = pURL;
|
||||
m_enType = ColorUrl;
|
||||
}
|
||||
@ -659,6 +659,16 @@ namespace NSCSS
|
||||
m_enType = ColorNone;
|
||||
}
|
||||
|
||||
char NormalizeNegativeColorValue(INT nValue)
|
||||
{
|
||||
if (nValue > 255)
|
||||
return 0xff;
|
||||
else if (nValue < 0)
|
||||
return (char)(std::abs(nValue) % 255);
|
||||
|
||||
return (char)nValue;
|
||||
}
|
||||
|
||||
bool CColor::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
if ((CHECK_CONDITIONS && !bHardMode) || (wsValue.empty() && unLevel == m_unLevel))
|
||||
@ -704,29 +714,18 @@ namespace NSCSS
|
||||
if (3 > arValues.size())
|
||||
return false;
|
||||
|
||||
INT nRed = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[0], 255));
|
||||
INT nGreen = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[1], 255));
|
||||
INT nBlue = std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[2], 255));
|
||||
const char chRed = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[0], 255)));
|
||||
const char chGreen = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[1], 255)));
|
||||
const char chBlue = NormalizeNegativeColorValue(std::ceil(NS_STATIC_FUNCTIONS::CalculatePersentage(arValues[2], 255)));
|
||||
|
||||
if (nRed < 0 || nGreen < 0 || nBlue < 0)
|
||||
{
|
||||
SetEmpty(unLevel);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (255 < nRed) nRed = 255;
|
||||
if (255 < nGreen) nGreen = 255;
|
||||
if (255 < nBlue) nBlue = 255;
|
||||
|
||||
SetRGB(nRed, nGreen, nBlue);
|
||||
SetRGB(chRed, chGreen, chBlue);
|
||||
|
||||
if (wsNewValue.substr(0, 4) == L"rgba" && 4 == arValues.size())
|
||||
m_oOpacity.SetValue(arValues[3], unLevel, bHardMode);
|
||||
|
||||
bResult = true;
|
||||
}
|
||||
|
||||
if (5 <= wsNewValue.length())
|
||||
else if (5 <= wsNewValue.length())
|
||||
{
|
||||
SetUrl(wsValue);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user