mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Improved the speed of html format conversion
This commit is contained in:
@ -49,6 +49,8 @@ namespace NSCSS
|
||||
if (!oElement.m_sId.empty())
|
||||
m_sId += L'+' + oElement.m_sId;
|
||||
|
||||
m_arParentsStyles.insert(oElement.m_arParentsStyles.begin(), oElement.m_arParentsStyles.end());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -69,6 +71,8 @@ namespace NSCSS
|
||||
m_oDisplay = oElement.m_oDisplay;
|
||||
m_oTransform = oElement.m_oTransform;
|
||||
|
||||
m_arParentsStyles = oElement.m_arParentsStyles;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -109,7 +113,8 @@ namespace NSCSS
|
||||
bool CCompiledStyle::Empty() const
|
||||
{
|
||||
return m_oBackground.Empty() && m_oBorder.Empty() && m_oFont.Empty() &&
|
||||
m_oMargin.Empty() && m_oPadding.Empty() && m_oText.Empty() && m_oDisplay.Empty();
|
||||
m_oMargin.Empty() && m_oPadding.Empty() && m_oText.Empty() &&
|
||||
m_oDisplay.Empty() && m_oTransform.Empty();
|
||||
}
|
||||
|
||||
void CCompiledStyle::AddPropSel(const std::wstring& sProperty, const std::wstring& sValue, const unsigned int unLevel, const bool& bHardMode)
|
||||
@ -521,7 +526,7 @@ namespace NSCSS
|
||||
{
|
||||
return m_sId;
|
||||
}
|
||||
|
||||
|
||||
bool CCompiledStyle::HaveThisParent(const std::wstring &wsParentName) const
|
||||
{
|
||||
return m_arParentsStyles.end() != m_arParentsStyles.find(wsParentName);
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
#ifndef CCOMPILEDSTYLE_H
|
||||
#define CCOMPILEDSTYLE_H
|
||||
|
||||
#include "CssCalculator_global.h"
|
||||
#include "ConstValues.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
@ -13,14 +13,9 @@ namespace NSCSS
|
||||
delete m_pInternal;
|
||||
}
|
||||
|
||||
CCompiledStyle CCssCalculator::GetCompiledStyle(const std::vector<CNode> &arSelectors) const
|
||||
bool CCssCalculator::CalculateCompiledStyle(std::vector<CNode>& arSelectors) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(arSelectors);
|
||||
}
|
||||
|
||||
bool CCssCalculator::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(oStyle, arSelectors);
|
||||
return m_pInternal->CalculateCompiledStyle(arSelectors);
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator::CalculateStyleId(const CNode& oNode)
|
||||
|
||||
@ -19,8 +19,7 @@ namespace NSCSS
|
||||
CCssCalculator();
|
||||
~CCssCalculator();
|
||||
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors) const;
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors) const;
|
||||
bool CalculateCompiledStyle(std::vector<CNode>& arSelectors) const;
|
||||
|
||||
std::wstring CalculateStyleId(const CNode& oNode);
|
||||
bool CalculatePageStyle(NSProperties::CPage& oPageData, const std::vector<CNode> &arSelectors);
|
||||
|
||||
@ -91,7 +91,7 @@ namespace NSCSS
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
for (const std::pair<std::wstring, std::wstring> &oData : mData)
|
||||
@ -107,11 +107,11 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors)
|
||||
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors, unsigned int unStart)
|
||||
{
|
||||
std::vector<std::wstring> arNodes;
|
||||
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
|
||||
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend() - unStart; ++oNode)
|
||||
{
|
||||
if (!oNode->m_wsName.empty())
|
||||
arNodes.push_back(oNode->m_wsName);
|
||||
@ -239,7 +239,7 @@ namespace NSCSS
|
||||
{
|
||||
m_arPageDatas.push_back({NS_STATIC_FUNCTIONS::GetWordsW(wsPageNames), NS_STATIC_FUNCTIONS::GetRules(wsStyles)});
|
||||
}
|
||||
|
||||
|
||||
inline void CCssCalculator_Private::GetStylesheet(const KatanaStylesheet *oStylesheet)
|
||||
{
|
||||
for (size_t i = 0; i < oStylesheet->imports.length; ++i)
|
||||
@ -457,19 +457,7 @@ namespace NSCSS
|
||||
}
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
CCompiledStyle CCssCalculator_Private::GetCompiledStyle(const std::vector<CNode>& arSelectors)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return CCompiledStyle();
|
||||
|
||||
CCompiledStyle oStyle;
|
||||
|
||||
GetCompiledStyle(oStyle, arSelectors);
|
||||
|
||||
return oStyle;
|
||||
}
|
||||
|
||||
bool CCssCalculator_Private::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors)
|
||||
bool CCssCalculator_Private::CalculateCompiledStyle(std::vector<CNode> &arSelectors)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return false;
|
||||
@ -478,54 +466,59 @@ namespace NSCSS
|
||||
|
||||
if (oItem != m_mUsedStyles.end())
|
||||
{
|
||||
oStyle = oItem->second;
|
||||
arSelectors.back().SetCompiledStyle(new CCompiledStyle(oItem->second));
|
||||
return true;
|
||||
}
|
||||
|
||||
oStyle.SetDpi(m_nDpi);
|
||||
arSelectors.back().m_pCompiledStyle->SetDpi(m_nDpi);
|
||||
unsigned int unStart = 0;
|
||||
|
||||
std::vector<std::wstring> arNodes = CalculateAllNodes(arSelectors);
|
||||
std::vector<CNode>::const_reverse_iterator itFound = std::find_if(arSelectors.crbegin(), arSelectors.crend(), [](const CNode& oNode){ return !oNode.m_pCompiledStyle->Empty(); });
|
||||
|
||||
if (itFound != arSelectors.crend())
|
||||
unStart = itFound.base() - arSelectors.cbegin();
|
||||
|
||||
std::vector<std::wstring> arNodes = CalculateAllNodes(arSelectors, unStart);
|
||||
std::vector<std::wstring> arPrevNodes;
|
||||
bool bInTable = false;
|
||||
|
||||
for (size_t i = 0; i < arSelectors.size(); ++i)
|
||||
|
||||
for (size_t i = unStart; i < arSelectors.size(); ++i)
|
||||
{
|
||||
oStyle.AddParent(arSelectors[i].m_wsName);
|
||||
if (0 != i)
|
||||
*arSelectors[i].m_pCompiledStyle += *arSelectors[i - 1].m_pCompiledStyle;
|
||||
|
||||
arSelectors[i].m_pCompiledStyle->AddParent(arSelectors[i].m_wsName);
|
||||
|
||||
if (!bInTable)
|
||||
bInTable = IsTableElement(arSelectors[i].m_wsName);
|
||||
|
||||
if (bInTable)
|
||||
{
|
||||
oStyle.m_oBackground.Clear();
|
||||
oStyle.m_oBorder.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oBackground.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oBorder.Clear();
|
||||
}
|
||||
|
||||
CCompiledStyle oTempStyle;
|
||||
|
||||
oTempStyle.AddStyle(arSelectors[i].m_mAttributes, i + 1);
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(arSelectors[i].m_mAttributes, i + 1);
|
||||
|
||||
for (const CElement* oElement : FindElements(arNodes, arPrevNodes))
|
||||
oTempStyle.AddStyle(oElement->GetStyle(), i + 1);
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(oElement->GetStyle(), i + 1);
|
||||
|
||||
if (!arSelectors[i].m_wsStyle.empty())
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
|
||||
oStyle += oTempStyle;
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
|
||||
// Скидываем некоторые внешние стили, которые внутри таблицы переопределяются
|
||||
if (bInTable && i < arSelectors.size() - 1)
|
||||
{
|
||||
oStyle.m_oFont.GetLineHeight().Clear();
|
||||
oStyle.m_oPadding.Clear();
|
||||
oStyle.m_oMargin.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oFont.GetLineHeight().Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oPadding.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oMargin.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
oStyle.SetID(CalculateStyleId(arSelectors.back()));
|
||||
arSelectors.back().m_pCompiledStyle->SetID(CalculateStyleId(arSelectors.back()));
|
||||
|
||||
if (!oStyle.Empty())
|
||||
m_mUsedStyles[arSelectors] = oStyle;
|
||||
if (!arSelectors.back().m_pCompiledStyle->Empty())
|
||||
m_mUsedStyles[arSelectors] = *arSelectors.back().m_pCompiledStyle;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -562,7 +555,7 @@ namespace NSCSS
|
||||
if (arSelectors[i].m_mAttributes.end() != arSelectors[i].m_mAttributes.find(L"page"))
|
||||
SetPageData(oPageData, GetPageData(arSelectors[i].m_mAttributes.at(L"page")), i + 1, false);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@ -584,7 +577,7 @@ namespace NSCSS
|
||||
std::wregex oRegex(L"@page\\s*([^{]*)(\\{[^}]*\\})");
|
||||
std::wsmatch oMatch;
|
||||
std::wstring::const_iterator oSearchStart(wsStyle.cbegin());
|
||||
|
||||
|
||||
while (std::regex_search(oSearchStart, wsStyle.cend(), oMatch, oRegex))
|
||||
{
|
||||
AddPageData(oMatch[1].str(), oMatch[2].str());
|
||||
@ -735,9 +728,7 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
|
||||
|
||||
inline static bool IsTableElement(const std::wstring& wsNameTag)
|
||||
{
|
||||
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
|
||||
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
|
||||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
|
||||
L"th" == wsNameTag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,11 +35,11 @@ namespace NSCSS
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
|
||||
|
||||
|
||||
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
|
||||
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors, unsigned int unStart = 0);
|
||||
|
||||
void FindPrevAndKindElements(const CElement* pElement, const std::vector<std::wstring>& arNextNodes, std::vector<CElement*>& arFindedElements, const std::wstring& wsName, const std::vector<std::wstring>& arClasses = {});
|
||||
std::vector<CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes);
|
||||
@ -69,8 +69,7 @@ namespace NSCSS
|
||||
~CCssCalculator_Private();
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors);
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors);
|
||||
bool CalculateCompiledStyle(std::vector<CNode>& arSelectors);
|
||||
|
||||
std::wstring CalculateStyleId(const CNode& oNode);
|
||||
bool CalculatePageStyle(NSProperties::CPage& oPageData, const std::vector<CNode> &arSelectors);
|
||||
|
||||
@ -1,19 +1,44 @@
|
||||
#include "CNode.h"
|
||||
#include "CCompiledStyle.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CNode::CNode()
|
||||
: m_pCompiledStyle(new CCompiledStyle())
|
||||
{}
|
||||
|
||||
CNode::CNode(const CNode& oNode)
|
||||
: m_wsName(oNode.m_wsName), m_wsClass(oNode.m_wsClass), m_wsId(oNode.m_wsId),
|
||||
m_wsStyle(oNode.m_wsStyle), m_mAttributes(oNode.m_mAttributes)
|
||||
{
|
||||
m_pCompiledStyle = new CCompiledStyle();
|
||||
*m_pCompiledStyle = *oNode.m_pCompiledStyle;
|
||||
}
|
||||
|
||||
CNode::CNode(const std::wstring& wsName, const std::wstring& wsClass, const std::wstring& wsId)
|
||||
: m_wsName(wsName), m_wsClass(wsClass), m_wsId(wsId)
|
||||
: m_wsName(wsName), m_wsClass(wsClass), m_wsId(wsId), m_pCompiledStyle(new CCompiledStyle())
|
||||
{}
|
||||
|
||||
CNode::~CNode()
|
||||
{
|
||||
if (nullptr != m_pCompiledStyle)
|
||||
delete m_pCompiledStyle;
|
||||
}
|
||||
|
||||
bool CNode::Empty() const
|
||||
{
|
||||
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
|
||||
}
|
||||
|
||||
void CNode::SetCompiledStyle(CCompiledStyle* pCompiledStyle)
|
||||
{
|
||||
if (nullptr != m_pCompiledStyle)
|
||||
delete m_pCompiledStyle;
|
||||
|
||||
m_pCompiledStyle = new CCompiledStyle();
|
||||
*m_pCompiledStyle = *pCompiledStyle;
|
||||
}
|
||||
|
||||
void CNode::Clear()
|
||||
{
|
||||
m_wsName .clear();
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CCompiledStyle;
|
||||
class CNode
|
||||
{
|
||||
public:
|
||||
@ -16,12 +17,17 @@ namespace NSCSS
|
||||
std::wstring m_wsStyle; // Стиль тэга
|
||||
std::map<std::wstring, std::wstring> m_mAttributes; // Остальные аттрибуты тэга
|
||||
|
||||
CCompiledStyle *m_pCompiledStyle;
|
||||
public:
|
||||
CNode();
|
||||
CNode(const CNode& oNode);
|
||||
CNode(const std::wstring& wsName, const std::wstring& wsClass, const std::wstring& wsId);
|
||||
~CNode();
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
void SetCompiledStyle(CCompiledStyle* pCompiledStyle);
|
||||
|
||||
void Clear();
|
||||
|
||||
std::vector<std::wstring> GetData() const;
|
||||
|
||||
@ -22,10 +22,10 @@ namespace NSCSS
|
||||
: m_oStyle(oStyle), m_bIsPStyle(bIsPStyle)
|
||||
{}
|
||||
|
||||
bool CheckArrays(const std::vector<std::wstring>& arInitial, const std::set<std::wstring>& arFirst, const std::set<std::wstring>& arSecond)
|
||||
bool CheckArrays(const std::vector<std::wstring>& arInitial, const std::set<std::wstring>& arFirst, const std::set<std::wstring>& arSecond)
|
||||
{
|
||||
std::unordered_set<std::wstring> arInitialSet(arInitial.begin(), arInitial.end());
|
||||
|
||||
|
||||
std::vector<std::wstring> arCommonElements1;
|
||||
std::vector<std::wstring> arCommonElements2;
|
||||
|
||||
@ -559,7 +559,7 @@ namespace NSCSS
|
||||
|
||||
if (oXmlElement.Empty())
|
||||
return false;
|
||||
|
||||
|
||||
m_sStyle += oXmlElement.GetPStyle(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include "Types.h"
|
||||
|
||||
#include "../../Common/kernel_config.h"
|
||||
|
||||
|
||||
@ -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