mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fixed the merge conflict
This commit is contained in:
@ -2,10 +2,8 @@
|
||||
#define CCSSCALCULATOR_H
|
||||
|
||||
#include "CssCalculator_global.h"
|
||||
#include "CCompiledStyle.h"
|
||||
#include "ConstValues.h"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "StyleProperties.h"
|
||||
#include "CNode.h"
|
||||
#include <vector>
|
||||
|
||||
namespace NSCSS
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
@ -488,6 +486,80 @@ namespace NSCSS
|
||||
{}
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
bool CCssCalculator_Private::CalculateCompiledStyle(std::vector<CNode>& arSelectors)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return false;
|
||||
|
||||
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
|
||||
|
||||
if (oItem != m_mUsedStyles.end())
|
||||
{
|
||||
arSelectors.back().SetCompiledStyle(new CCompiledStyle(oItem->second));
|
||||
return true;
|
||||
}
|
||||
|
||||
arSelectors.back().m_pCompiledStyle->SetDpi(m_nDpi);
|
||||
unsigned int unStart = 0;
|
||||
|
||||
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 < unStart; ++i)
|
||||
{
|
||||
if (!bInTable)
|
||||
bInTable = IsTableElement(arSelectors[i].m_wsName);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = unStart; i < arSelectors.size(); ++i)
|
||||
{
|
||||
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)
|
||||
{
|
||||
arSelectors[i].m_pCompiledStyle->m_oBackground.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oBorder.Clear();
|
||||
}
|
||||
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(arSelectors[i].m_mAttributes, i + 1);
|
||||
|
||||
for (const CElement* oElement : FindElements(arNodes, arPrevNodes))
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(oElement->GetStyle(), i + 1);
|
||||
|
||||
if (!arSelectors[i].m_wsStyle.empty())
|
||||
arSelectors[i].m_pCompiledStyle->AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
|
||||
// Скидываем некоторые внешние стили, которые внутри таблицы переопределяются
|
||||
if (bInTable && i < arSelectors.size() - 1)
|
||||
{
|
||||
arSelectors[i].m_pCompiledStyle->m_oFont.GetLineHeight().Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oPadding.Clear();
|
||||
arSelectors[i].m_pCompiledStyle->m_oMargin.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
arSelectors.back().m_pCompiledStyle->SetID(CalculateStyleId(arSelectors.back()));
|
||||
|
||||
if (!arSelectors.back().m_pCompiledStyle->Empty())
|
||||
m_mUsedStyles[arSelectors] = *arSelectors.back().m_pCompiledStyle;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
//TODO:: пересмотреть данный метод
|
||||
@ -505,11 +577,11 @@ namespace NSCSS
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
@ -631,79 +703,6 @@ 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)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return false;
|
||||
|
||||
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
|
||||
|
||||
if (oItem != m_mUsedStyles.end())
|
||||
{
|
||||
oStyle = oItem->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
oStyle.SetDpi(m_nDpi);
|
||||
|
||||
std::vector<std::wstring> arNodes = CalculateAllNodes(arSelectors);
|
||||
std::vector<std::wstring> arPrevNodes;
|
||||
bool bInTable = false;
|
||||
|
||||
for (size_t i = 0; i < arSelectors.size(); ++i)
|
||||
{
|
||||
oStyle.AddParent(arSelectors[i].m_wsName);
|
||||
|
||||
if (!bInTable)
|
||||
bInTable = IsTableElement(arSelectors[i].m_wsName);
|
||||
|
||||
if (bInTable)
|
||||
{
|
||||
oStyle.m_oBackground.Clear();
|
||||
oStyle.m_oBorder.Clear();
|
||||
}
|
||||
|
||||
CCompiledStyle oTempStyle;
|
||||
|
||||
oTempStyle.AddStyle(arSelectors[i].m_mAttributes, i + 1);
|
||||
|
||||
for (const CElement* oElement : FindElements(arNodes, arPrevNodes))
|
||||
oTempStyle.AddStyle(oElement->GetStyle(), i + 1);
|
||||
|
||||
if (!arSelectors[i].m_wsStyle.empty())
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
|
||||
oStyle += oTempStyle;
|
||||
|
||||
// Скидываем некоторые внешние стили, которые внутри таблицы переопределяются
|
||||
if (bInTable && i < arSelectors.size() - 1)
|
||||
{
|
||||
oStyle.m_oFont.GetLineHeight().Clear();
|
||||
oStyle.m_oPadding.Clear();
|
||||
oStyle.m_oMargin.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
oStyle.SetID(CalculateStyleId(arSelectors.back()));
|
||||
|
||||
if (!oStyle.Empty())
|
||||
m_mUsedStyles[arSelectors] = oStyle;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator_Private::CalculateStyleId(const CNode& oNode)
|
||||
{
|
||||
return oNode.m_wsName + ((!oNode.m_wsClass.empty()) ? L'.' + oNode.m_wsClass : L"") + ((oNode.m_wsId.empty()) ? L"" : L'#' + oNode.m_wsId) + L'-' + std::to_wstring(++m_nCountNodes);
|
||||
@ -910,4 +909,11 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
|
||||
return str;
|
||||
}
|
||||
|
||||
inline static bool IsTableElement(const std::wstring& wsNameTag)
|
||||
{
|
||||
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
|
||||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
|
||||
L"th" == wsNameTag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -102,8 +102,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);
|
||||
@ -111,7 +110,7 @@ namespace NSCSS
|
||||
void ClearPageData();
|
||||
#endif
|
||||
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors, unsigned int unStart = 0);
|
||||
std::vector<const CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes);
|
||||
|
||||
void AddStyles(const std::string& sStyle);
|
||||
|
||||
Reference in New Issue
Block a user