Fix bugs in html to ooxml conversion

This commit is contained in:
Kirill Polyakov
2024-03-12 14:54:08 +03:00
parent 8a9e5ad267
commit e18883f126
4 changed files with 95 additions and 68 deletions

View File

@ -151,10 +151,10 @@ namespace NSCSS
case Millimeter: return CUnitMeasureConverter::ConvertMm(m_oValue, enUnitMeasure, 96);
case Inch: return CUnitMeasureConverter::ConvertIn(m_oValue, enUnitMeasure, 96);
case Peak: return CUnitMeasureConverter::ConvertPc(m_oValue, enUnitMeasure, 96);
case Twips: return CUnitMeasureConverter::ConvertTw(m_oValue, enUnitMeasure, 96);
case Em:
case Rem: return m_oValue * dPrevValue;
case None:
case Twips: return m_oValue;
case None: return m_oValue;
}
}
@ -254,7 +254,8 @@ namespace NSCSS
bool CDigit::operator==(const CDigit &oDigit) const
{
return (std::abs(oDigit.m_oValue - m_oValue) <= DBL_EPSILON);
return (std::abs(oDigit.m_oValue - m_oValue) <= DBL_EPSILON) &&
m_enUnitMeasure == oDigit.m_enUnitMeasure;
}
bool CDigit::operator!=(const double &oValue) const
@ -1333,8 +1334,13 @@ namespace NSCSS
return false;
if (L"none" == wsValue)
{
SetColor(L"#ffffff", unLevel, bHardMode);
SetStyle(L"solid", unLevel, bHardMode);
SetWidth(L"0",unLevel,bHardMode);
return true;
}
const std::vector<std::wstring> arValues = NS_STATIC_FUNCTIONS::GetWordsW(wsValue, false, L" ");
for (const std::wstring& sValue : arValues)
{
@ -1431,6 +1437,11 @@ namespace NSCSS
return m_oWidth.Zero();
}
bool CBorderSide::Valid() const
{
return !m_oWidth.Empty() && !m_oWidth.Zero();
}
CBorderSide &CBorderSide::operator+=(const CBorderSide &oBorderSide)
{
m_oWidth = oBorderSide.m_oWidth;
@ -2287,7 +2298,7 @@ namespace NSCSS
m_oStretch == oFont.m_oStretch &&
m_oStyle == oFont.m_oStyle &&
m_oVariant == oFont.m_oVariant &&
m_oWeight == oFont.m_oWeight;
m_oWeight == oFont.m_oWeight;
}
CColorValue::CColorValue()

View File

@ -440,6 +440,7 @@ namespace NSCSS
bool Empty() const;
bool Zero() const;
bool Valid() const;
CBorderSide& operator+=(const CBorderSide& oBorderSide);
bool operator==(const CBorderSide& oBorderSide) const;

View File

@ -304,7 +304,12 @@ namespace NSCSS
// sSpacingValue += L"w:after=\"0\" w:before=\"0\"";
if (!oStyle.m_oFont.GetLineHeight().Empty() && !oStyle.m_oFont.GetLineHeight().Zero())
sSpacingValue += L" w:line=\"" + std::to_wstring(oStyle.m_oFont.GetLineHeight().ToInt(NSCSS::Twips, DEFAULT_LINEHEIGHT)) + L"\" w:lineRule=\"auto\"";
{
const std::wstring wsLine{std::to_wstring(oStyle.m_oFont.GetLineHeight().ToInt(NSCSS::Twips, DEFAULT_LINEHEIGHT))};
const std::wstring wsLineRule{(NSCSS::Percent == oStyle.m_oFont.GetLineHeight().GetUnitMeasure() ? L"auto" : L"atLeast")};
sSpacingValue += L" w:line=\"" + wsLine + L"\" w:lineRule=\"" + wsLineRule + L"\"";
}
if (!sSpacingValue.empty())
{
@ -392,7 +397,7 @@ namespace NSCSS
{
if (oBorder.Empty())
return L"";
std::wstring wsColor = oBorder.GetColor().ToWString();
std::wstring wsStyle = oBorder.GetStyle().ToWString();
double dWidth = oBorder.GetWidth().ToDouble(Point) * 8; // Так как значение указано в восьмых долях точки
@ -403,9 +408,6 @@ namespace NSCSS
if (wsStyle.empty())
wsStyle = L"single";
if (1 > dWidth)
dWidth = 1;
return L"w:val=\"" + wsStyle + L"\" w:sz=\"" + std::to_wstring(static_cast<int>(dWidth)) + + L"\" w:space=\"0\" w:color=\"" + wsColor + L"\"";
}
@ -416,11 +418,11 @@ namespace NSCSS
return;
if (!oStyle.m_oFont.GetSize().Empty())
oXmlElement.AddPropertiesInR(RProperties::R_Sz, std::to_wstring(oStyle.m_oFont.GetSize().ToInt(NSCSS::Point) * 2)); // Значения шрифта увеличивает на 2
oXmlElement.AddPropertiesInR(RProperties::R_Sz, std::to_wstring(static_cast<int>(oStyle.m_oFont.GetSize().ToDouble(NSCSS::Point) * 2. + 0.5))); // Значения шрифта увеличивает на 2
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_Color, oStyle.m_oText.GetColor().ToWString());
oXmlElement.AddPropertiesInR(RProperties::R_RFonts, oStyle.m_oFont.GetFamily().ToWString());