mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Added a method for equating any one to the nearest of the given ones
This commit is contained in:
@ -621,9 +621,9 @@ namespace NSCSS
|
||||
TRGB oRGB = ConvertHEXtoRGB(*pValue);
|
||||
return RGB_TO_INT(oRGB.uchRed, oRGB.uchGreen, oRGB.uchBlue);
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
double CColor::ToDouble() const
|
||||
@ -641,6 +641,47 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring CColor::EquateToColor(const std::vector<std::wstring>& arColors) const
|
||||
{
|
||||
if (arColors.empty())
|
||||
return L"none";
|
||||
|
||||
TRGB oColor;
|
||||
|
||||
switch(m_oValue.m_enType)
|
||||
{
|
||||
case ColorRGB: oColor = *static_cast<TRGB*>(m_oValue.m_pColor); break;
|
||||
case ColorHEX: oColor = ConvertHEXtoRGB(*static_cast<std::wstring*>(m_oValue.m_pColor)); break;
|
||||
default: return L"none";
|
||||
}
|
||||
|
||||
TRGB oTempColor;
|
||||
std::wstring wsSelectedColor;
|
||||
double dMinDistance = DBL_MAX;
|
||||
double dDistance;
|
||||
|
||||
for (const std::wstring& wsColor : arColors)
|
||||
{
|
||||
oTempColor = ConvertHEXtoRGB(wsColor);
|
||||
dDistance = sqrt(pow(oTempColor.uchRed - oColor.uchRed, 2) + pow(oTempColor.uchGreen - oColor.uchGreen, 2) + pow(oTempColor.uchBlue - oColor.uchBlue, 2));
|
||||
|
||||
if (dDistance < dMinDistance)
|
||||
{
|
||||
dMinDistance = dDistance;
|
||||
wsSelectedColor = wsColor;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring>::const_iterator oIter =
|
||||
std::find_if(NSConstValues::COLORS.begin(), NSConstValues::COLORS.end(), [&wsSelectedColor](const std::pair<std::wstring, std::wstring>& oPair)
|
||||
{ return wsSelectedColor == oPair.second; });
|
||||
|
||||
if (NSConstValues::COLORS.end() == oIter)
|
||||
return std::wstring();
|
||||
|
||||
return oIter->first;
|
||||
}
|
||||
|
||||
TRGB CColor::ToRGB() const
|
||||
{
|
||||
switch(m_oValue.m_enType)
|
||||
@ -802,6 +843,8 @@ namespace NSCSS
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -878,6 +921,8 @@ namespace NSCSS
|
||||
wsValue = L"rotate(";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return wsValue;
|
||||
|
||||
@ -237,6 +237,7 @@ namespace NSCSS
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
std::wstring EquateToColor(const std::vector<std::wstring>& arColors) const;
|
||||
TRGB ToRGB() const;
|
||||
};
|
||||
|
||||
|
||||
@ -419,7 +419,7 @@ namespace NSCSS
|
||||
if (oStyle.m_oText.GetDecoration().m_oLine.Underline())
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_U, (!oStyle.m_oText.GetDecoration().m_oStyle.Empty()) ? oStyle.m_oText.GetDecoration().m_oStyle.ToWString() : L"single");
|
||||
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_Highlight, oStyle.m_oBackground.GetColor().ToWString());
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_Highlight, oStyle.m_oBackground.GetColor().EquateToColor({L"000000", L"0000FF", L"00FFFF", L"00FF00", L"FF00FF", L"FF0000", L"FFFF00", L"FFFFFF", L"00008B", L"008B8B", L"006400", L"8B008B", L"8B0000", L"8B8000", L"A9A9A9", L"D3D3D3"}));
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_Color, oStyle.m_oText.GetColor().ToWString());
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_RFonts, oStyle.m_oFont.GetFamily().ToWString());
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_I, oStyle.m_oFont.GetStyle().ToWString());
|
||||
|
||||
@ -448,11 +448,12 @@ std::wstring CXmlElement::ConvertRStyle(bool bIsLite) const
|
||||
sRStyle += L"<w:u w:val=\"" + oItem.second + L"\"/>";
|
||||
break;
|
||||
}
|
||||
// case CSSProperties::RunnerProperties::R_Highlight:
|
||||
// {
|
||||
// sRStyle += L"<w:highlight w:val=\"" + oItem.second + L"\"/>";
|
||||
// break;
|
||||
// }
|
||||
case CSSProperties::RunnerProperties::R_Highlight:
|
||||
{
|
||||
if (!oItem.second.empty())
|
||||
sRStyle += L"<w:highlight w:val=\"" + oItem.second + L"\"/>";
|
||||
break;
|
||||
}
|
||||
case CSSProperties::RunnerProperties::R_SmallCaps:
|
||||
{
|
||||
if (oItem.second == L"smallCaps")
|
||||
|
||||
Reference in New Issue
Block a user