mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 03:08:28 +08:00
Improved the speed of html format conversion
This commit is contained in:
@ -2180,8 +2180,8 @@ private:
|
||||
if (m_mDivs.empty())
|
||||
pXml->WriteString(L"<w:divs>");
|
||||
|
||||
NSCSS::CCompiledStyle oStyle;
|
||||
m_oStylesCalculator.GetCompiledStyle(oStyle, sSelectors);
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
NSCSS::CCompiledStyle *pStyle = sSelectors.back().m_pCompiledStyle;
|
||||
|
||||
const bool bInTable = ElementInTable(sSelectors);
|
||||
|
||||
@ -2190,17 +2190,17 @@ private:
|
||||
INT nMarTop = (!bInTable) ? 100 : 0;
|
||||
INT nMarBottom = (!bInTable) ? 100 : 0;
|
||||
|
||||
if (!oStyle.m_oMargin.GetLeft().Empty() && !oStyle.m_oMargin.GetLeft().Zero())
|
||||
nMarLeft = oStyle.m_oMargin.GetLeft().ToInt(NSCSS::Twips, m_oPageData.GetWidth().ToInt(NSCSS::Twips));
|
||||
if (!pStyle->m_oMargin.GetLeft().Empty() && !pStyle->m_oMargin.GetLeft().Zero())
|
||||
nMarLeft = pStyle->m_oMargin.GetLeft().ToInt(NSCSS::Twips, m_oPageData.GetWidth().ToInt(NSCSS::Twips));
|
||||
|
||||
if (!oStyle.m_oMargin.GetRight().Empty() && !oStyle.m_oMargin.GetRight().Zero())
|
||||
nMarRight = oStyle.m_oMargin.GetRight().ToInt(NSCSS::Twips, m_oPageData.GetWidth().ToInt(NSCSS::Twips));
|
||||
if (!pStyle->m_oMargin.GetRight().Empty() && !pStyle->m_oMargin.GetRight().Zero())
|
||||
nMarRight = pStyle->m_oMargin.GetRight().ToInt(NSCSS::Twips, m_oPageData.GetWidth().ToInt(NSCSS::Twips));
|
||||
|
||||
if (!oStyle.m_oMargin.GetTop().Empty() && !oStyle.m_oMargin.GetTop().Zero())
|
||||
nMarTop = oStyle.m_oMargin.GetTop().ToInt(NSCSS::Twips, m_oPageData.GetHeight().ToInt(NSCSS::Twips));
|
||||
if (!pStyle->m_oMargin.GetTop().Empty() && !pStyle->m_oMargin.GetTop().Zero())
|
||||
nMarTop = pStyle->m_oMargin.GetTop().ToInt(NSCSS::Twips, m_oPageData.GetHeight().ToInt(NSCSS::Twips));
|
||||
|
||||
if (!oStyle.m_oMargin.GetBottom().Empty() && !oStyle.m_oMargin.GetBottom().Zero())
|
||||
nMarBottom = oStyle.m_oMargin.GetBottom().ToInt(NSCSS::Twips, m_oPageData.GetHeight().ToInt(NSCSS::Twips));
|
||||
if (!pStyle->m_oMargin.GetBottom().Empty() && !pStyle->m_oMargin.GetBottom().Zero())
|
||||
nMarBottom = pStyle->m_oMargin.GetBottom().ToInt(NSCSS::Twips, m_oPageData.GetHeight().ToInt(NSCSS::Twips));
|
||||
|
||||
if (L"blockquote" == wsKeyWord)
|
||||
{
|
||||
@ -2327,7 +2327,7 @@ private:
|
||||
readStream(&m_oDocXml, sSelectors, oTS);
|
||||
}
|
||||
|
||||
bool ReadText(NSStringUtils::CStringBuilder* pXml, const std::vector<NSCSS::CNode>& arSelectors, CTextSettings& oTS)
|
||||
bool ReadText(NSStringUtils::CStringBuilder* pXml, std::vector<NSCSS::CNode>& arSelectors, CTextSettings& oTS)
|
||||
{
|
||||
if (NULL == pXml)
|
||||
return false;
|
||||
@ -2520,8 +2520,8 @@ private:
|
||||
if (m_oState.m_bInP)
|
||||
{
|
||||
OpenR(pXml);
|
||||
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(arSelectors);
|
||||
if(oStyle.m_oText.GetAlign() == L"both")
|
||||
m_oStylesCalculator.CalculateCompiledStyle(arSelectors);
|
||||
if(arSelectors.back().m_pCompiledStyle->m_oText.GetAlign() == L"both")
|
||||
pXml->WriteString(L"<w:tab/>");
|
||||
pXml->WriteString(L"<w:br/>");
|
||||
CloseR(pXml);
|
||||
@ -3325,24 +3325,23 @@ private:
|
||||
return bResult;
|
||||
}
|
||||
|
||||
void CalculateCellStyles(TTableCellStyle* pCellStyle, const std::vector<NSCSS::CNode>& arSelectors)
|
||||
void CalculateCellStyles(TTableCellStyle* pCellStyle, std::vector<NSCSS::CNode>& arSelectors)
|
||||
{
|
||||
if (NULL == pCellStyle)
|
||||
return;
|
||||
|
||||
NSCSS::CCompiledStyle oStyle;
|
||||
m_oStylesCalculator.GetCompiledStyle(oStyle, arSelectors);
|
||||
m_oStylesCalculator.CalculateCompiledStyle(arSelectors);
|
||||
|
||||
pCellStyle->m_wsVAlign = oStyle.m_oDisplay.GetVAlign().ToWString();
|
||||
pCellStyle->m_wsHAlign = oStyle.m_oDisplay.GetHAlign().ToWString();
|
||||
pCellStyle->m_oBackground = oStyle.m_oBackground.GetColor();
|
||||
pCellStyle->m_oHeight = oStyle.m_oDisplay.GetHeight();
|
||||
pCellStyle->m_oWidth = oStyle.m_oDisplay.GetWidth();
|
||||
pCellStyle->m_oPadding = oStyle.m_oPadding;
|
||||
pCellStyle->m_oBorder = oStyle.m_oBorder;
|
||||
pCellStyle->m_wsVAlign = arSelectors.back().m_pCompiledStyle->m_oDisplay.GetVAlign().ToWString();
|
||||
pCellStyle->m_wsHAlign = arSelectors.back().m_pCompiledStyle->m_oDisplay.GetHAlign().ToWString();
|
||||
pCellStyle->m_oBackground = arSelectors.back().m_pCompiledStyle->m_oBackground.GetColor();
|
||||
pCellStyle->m_oHeight = arSelectors.back().m_pCompiledStyle->m_oDisplay.GetHeight();
|
||||
pCellStyle->m_oWidth = arSelectors.back().m_pCompiledStyle->m_oDisplay.GetWidth();
|
||||
pCellStyle->m_oPadding = arSelectors.back().m_pCompiledStyle->m_oPadding;
|
||||
pCellStyle->m_oBorder = arSelectors.back().m_pCompiledStyle->m_oBorder;
|
||||
|
||||
if (pCellStyle->m_wsHAlign.empty())
|
||||
pCellStyle->m_wsHAlign = oStyle.m_oText.GetAlign().ToWString();
|
||||
pCellStyle->m_wsHAlign = arSelectors.back().m_pCompiledStyle->m_oText.GetAlign().ToWString();
|
||||
}
|
||||
|
||||
void ParseTableCaption(CTable& oTable, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
|
||||
@ -3464,7 +3463,7 @@ private:
|
||||
|
||||
GetSubClass(pCell->GetData(), sSelectors);
|
||||
|
||||
const std::vector<NSCSS::CNode> arNewSelectors{(std::vector<NSCSS::CNode>::const_iterator)std::find_if(sSelectors.begin(), sSelectors.end(), [](const NSCSS::CNode& oNode){ return L"table" == oNode.m_wsName; }), sSelectors.cend()};
|
||||
std::vector<NSCSS::CNode> arNewSelectors{(std::vector<NSCSS::CNode>::const_iterator)std::find_if(sSelectors.begin(), sSelectors.end(), [](const NSCSS::CNode& oNode){ return L"table" == oNode.m_wsName; }), sSelectors.cend()};
|
||||
|
||||
CalculateCellStyles(pCell->GetStyles(), arNewSelectors);
|
||||
|
||||
@ -3583,17 +3582,18 @@ private:
|
||||
|
||||
CTextSettings oNewSettings{oTS};
|
||||
|
||||
NSCSS::CCompiledStyle oStyle{m_oStylesCalculator.GetCompiledStyle(sSelectors)};
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
|
||||
const std::wstring wsHighlight{oStyle.m_oBackground.GetColor().EquateToColor({{{0, 0, 0}, L"black"}, {{0, 0, 255}, L"blue"}, {{0, 255, 255}, L"cyan"},
|
||||
{{0, 255, 0}, L"green"}, {{255, 0, 255}, L"magenta"}, {{255, 0, 0}, L"red"},
|
||||
{{255, 255, 0}, L"yellow"}, {{255, 255, 255}, L"white"}, {{0, 0, 139}, L"darkBlue"},
|
||||
{{0, 139, 139}, L"darkCyan"}, {{0, 100, 0}, L"darkGreen"}, {{139, 0, 139}, L"darkMagenta"},
|
||||
{{139, 0, 0}, L"darkRed"}, {{128, 128, 0}, L"darkYellow"},{{169, 169, 169}, L"darkGray"},
|
||||
{{211, 211, 211}, L"lightGray"}})};
|
||||
const std::wstring wsHighlight{sSelectors.back().m_pCompiledStyle->m_oBackground.GetColor()
|
||||
.EquateToColor({{{0, 0, 0}, L"black"}, {{0, 0, 255}, L"blue"}, {{0, 255, 255}, L"cyan"},
|
||||
{{0, 255, 0}, L"green"}, {{255, 0, 255}, L"magenta"}, {{255, 0, 0}, L"red"},
|
||||
{{255, 255, 0}, L"yellow"}, {{255, 255, 255}, L"white"}, {{0, 0, 139}, L"darkBlue"},
|
||||
{{0, 139, 139}, L"darkCyan"}, {{0, 100, 0}, L"darkGreen"}, {{139, 0, 139}, L"darkMagenta"},
|
||||
{{139, 0, 0}, L"darkRed"}, {{128, 128, 0}, L"darkYellow"},{{169, 169, 169}, L"darkGray"},
|
||||
{{211, 211, 211}, L"lightGray"}})};
|
||||
|
||||
if (L"none" != wsHighlight)
|
||||
oNewSettings.oAdditionalStyle.m_oText.SetHighlight(oStyle.m_oBackground.GetColor().ToWString(), NEXT_LEVEL);
|
||||
oNewSettings.oAdditionalStyle.m_oText.SetHighlight(sSelectors.back().m_pCompiledStyle->m_oBackground.GetColor().ToWString(), NEXT_LEVEL);
|
||||
// oNewSettings.AddRStyle(L"<w:shd w:val=\"" + wsHighlight + L"\"/>");
|
||||
|
||||
if (L"rt" == sSelectors.back().m_wsName)
|
||||
@ -3622,12 +3622,13 @@ private:
|
||||
|
||||
if (0 != oRT.GetSize())
|
||||
{
|
||||
NSCSS::CCompiledStyle oStyle{m_oStylesCalculator.GetCompiledStyle(sSelectors)};
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
NSCSS::CCompiledStyle *pStyle = sSelectors.back().m_pCompiledStyle;
|
||||
|
||||
int nFontSize = 24;
|
||||
|
||||
if (!oStyle.m_oFont.GetSize().Empty() && !oStyle.m_oFont.GetSize().Zero())
|
||||
nFontSize = oStyle.m_oFont.GetSize().ToInt(NSCSS::Point) * 2;
|
||||
if (!pStyle->m_oFont.GetSize().Empty() && !pStyle->m_oFont.GetSize().Zero())
|
||||
nFontSize = pStyle->m_oFont.GetSize().ToInt(NSCSS::Point) * 2;
|
||||
|
||||
bool bConsistsChineseCharacters = false;
|
||||
|
||||
@ -3665,45 +3666,45 @@ private:
|
||||
CTextSettings oTextSettings{oTS};
|
||||
oTextSettings.sPStyle.clear();
|
||||
|
||||
NSCSS::CCompiledStyle oStyle;
|
||||
m_oStylesCalculator.GetCompiledStyle(oStyle, sSelectors);
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
NSCSS::CCompiledStyle *pStyle = sSelectors.back().m_pCompiledStyle;
|
||||
|
||||
//Table styles
|
||||
std::wstring wsFrame;
|
||||
|
||||
for (const std::pair<std::wstring, std::wstring>& oArgument : sSelectors.back().m_mAttributes)
|
||||
{
|
||||
if (oStyle.m_oBorder.Empty() && L"border" == oArgument.first)
|
||||
if (pStyle->m_oBorder.Empty() && L"border" == oArgument.first)
|
||||
{
|
||||
const int nWidth = NSStringFinder::ToInt(oArgument.second);
|
||||
|
||||
if (0 < nWidth)
|
||||
{
|
||||
oStyle.m_oBorder.SetStyle(L"outset", 0, true);
|
||||
oStyle.m_oBorder.SetWidth(nWidth, 0, true);
|
||||
oStyle.m_oBorder.SetColor(L"auto", 0, true);
|
||||
pStyle->m_oBorder.SetStyle(L"outset", 0, true);
|
||||
pStyle->m_oBorder.SetWidth(nWidth, 0, true);
|
||||
pStyle->m_oBorder.SetColor(L"auto", 0, true);
|
||||
oTable.SetRules(L"all");
|
||||
}
|
||||
else
|
||||
{
|
||||
oStyle.m_oBorder.SetNone(0, true);
|
||||
pStyle->m_oBorder.SetNone(0, true);
|
||||
oTable.SetRules(L"none");
|
||||
}
|
||||
}
|
||||
else if (L"cellpadding" == oArgument.first)
|
||||
oStyle.m_oPadding.SetValues(oArgument.second + L"px", 0, true);
|
||||
pStyle->m_oPadding.SetValues(oArgument.second + L"px", 0, true);
|
||||
else if (L"rules" == oArgument.first)
|
||||
oTable.SetRules(oArgument.second);
|
||||
else if (L"frame" == oArgument.first)
|
||||
wsFrame = oArgument.second;
|
||||
}
|
||||
|
||||
if (!wsFrame.empty() && oStyle.m_oBorder.Empty())
|
||||
if (!wsFrame.empty() && pStyle->m_oBorder.Empty())
|
||||
{
|
||||
#define SetDefaultBorderSide(side) \
|
||||
oStyle.m_oBorder.SetStyle##side(L"solid", 0, true); \
|
||||
oStyle.m_oBorder.SetWidth##side(1, 0, true); \
|
||||
oStyle.m_oBorder.SetColor##side(L"black", 0, true);
|
||||
pStyle->m_oBorder.SetStyle##side(L"solid", 0, true); \
|
||||
pStyle->m_oBorder.SetWidth##side(1, 0, true); \
|
||||
pStyle->m_oBorder.SetColor##side(L"black", 0, true);
|
||||
|
||||
if (NSStringFinder::Equals(L"border", wsFrame))
|
||||
{
|
||||
@ -3737,18 +3738,18 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if (oStyle.m_oBorder.GetCollapse() == NSCSS::NSProperties::BorderCollapse::Collapse)
|
||||
if (pStyle->m_oBorder.GetCollapse() == NSCSS::NSProperties::BorderCollapse::Collapse)
|
||||
oTable.SetCellSpacing(0);
|
||||
else if (sSelectors.back().m_mAttributes.end() != sSelectors.back().m_mAttributes.find(L"cellspacing"))
|
||||
oTable.SetCellSpacing(NSStringFinder::ToInt(sSelectors.back().m_mAttributes[L"cellspacing"]));
|
||||
else if (oStyle.m_oBorder.GetCollapse() == NSCSS::NSProperties::BorderCollapse::Separate)
|
||||
else if (pStyle->m_oBorder.GetCollapse() == NSCSS::NSProperties::BorderCollapse::Separate)
|
||||
oTable.SetCellSpacing(15);
|
||||
|
||||
oTable.SetWidth(oStyle.m_oDisplay.GetWidth());
|
||||
oTable.SetBorder(oStyle.m_oBorder);
|
||||
oTable.SetPadding(oStyle.m_oPadding);
|
||||
oTable.SetMargin(oStyle.m_oMargin);
|
||||
oTable.SetAlign(oStyle.m_oDisplay.GetHAlign().ToWString());
|
||||
oTable.SetWidth(pStyle->m_oDisplay.GetWidth());
|
||||
oTable.SetBorder(pStyle->m_oBorder);
|
||||
oTable.SetPadding(pStyle->m_oPadding);
|
||||
oTable.SetMargin(pStyle->m_oMargin);
|
||||
oTable.SetAlign(pStyle->m_oDisplay.GetHAlign().ToWString());
|
||||
//------
|
||||
|
||||
int nDeath = m_oLightReader.GetDepth();
|
||||
@ -4293,19 +4294,16 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring wrP(NSStringUtils::CStringBuilder* oXml, const std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
|
||||
std::wstring wrP(NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
|
||||
{
|
||||
OpenP(oXml);
|
||||
|
||||
if (m_oState.m_bWasPStyle)
|
||||
return L"";
|
||||
|
||||
NSCSS::CCompiledStyle oStyleSetting{oTS.oAdditionalStyle};
|
||||
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
|
||||
NSCSS::CCompiledStyle::StyleEquation(oStyle, oStyleSetting);
|
||||
|
||||
std::wstring sPStyle = GetStyle(oStyle, true);
|
||||
std::wstring sPStyle = GetStyle(*sSelectors.back().m_pCompiledStyle, true);
|
||||
|
||||
if (sPStyle.empty() && !ElementInTable(sSelectors))
|
||||
sPStyle = L"normal-web";
|
||||
@ -4313,7 +4311,7 @@ private:
|
||||
if (sPStyle.empty() && oTS.sPStyle.empty())
|
||||
return L"";
|
||||
|
||||
m_oXmlStyle.WriteLitePStyle(oStyleSetting);
|
||||
m_oXmlStyle.WriteLitePStyle(oTS.oAdditionalStyle);
|
||||
const std::wstring sPSettings = m_oXmlStyle.GetStyle();
|
||||
m_oXmlStyle.Clear();
|
||||
|
||||
@ -4333,19 +4331,16 @@ private:
|
||||
return sPStyle;
|
||||
}
|
||||
|
||||
std::wstring wrRPr(NSStringUtils::CStringBuilder* oXml, const std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
|
||||
std::wstring wrRPr(NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
|
||||
{
|
||||
if (!m_oState.m_bInP)
|
||||
return L"";
|
||||
|
||||
NSCSS::CCompiledStyle oStyleSetting{oTS.oAdditionalStyle};
|
||||
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
|
||||
m_oStylesCalculator.CalculateCompiledStyle(sSelectors);
|
||||
|
||||
NSCSS::CCompiledStyle::StyleEquation(oStyle, oStyleSetting);
|
||||
std::wstring sRStyle = GetStyle(*sSelectors.back().m_pCompiledStyle, false);
|
||||
|
||||
std::wstring sRStyle = GetStyle(oStyle, false);
|
||||
|
||||
m_oXmlStyle.WriteLiteRStyle(oStyleSetting);
|
||||
m_oXmlStyle.WriteLiteRStyle(oTS.oAdditionalStyle);
|
||||
const std::wstring sRSettings = m_oXmlStyle.GetStyle();
|
||||
m_oXmlStyle.Clear();
|
||||
|
||||
@ -4355,7 +4350,7 @@ private:
|
||||
|
||||
if (0 != nCalculatedFontChange)
|
||||
{
|
||||
int nFontSizeLevel{static_cast<int>((oStyle.m_oFont.Empty()) ? 3 : GetFontSizeLevel(oStyle.m_oFont.GetSize().ToInt(NSCSS::Point) * 2))};
|
||||
int nFontSizeLevel{static_cast<int>((sSelectors.back().m_pCompiledStyle->m_oFont.Empty()) ? 3 : GetFontSizeLevel(sSelectors.back().m_pCompiledStyle->m_oFont.GetSize().ToInt(NSCSS::Point) * 2))};
|
||||
|
||||
nFontSizeLevel += nCalculatedFontChange;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user