mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Changed working with svg records data and refactoring
This commit is contained in:
@ -16,7 +16,7 @@ namespace NSCSS
|
||||
{
|
||||
typedef std::map<std::wstring, std::wstring>::const_iterator styles_iterator;
|
||||
|
||||
CCompiledStyle::CCompiledStyle() : m_nDpi(96), m_UnitMeasure(Default){}
|
||||
CCompiledStyle::CCompiledStyle() : m_nDpi(96), m_UnitMeasure(Point){}
|
||||
|
||||
CCompiledStyle::CCompiledStyle(const CCompiledStyle& oStyle) :
|
||||
m_arParentsStyles(oStyle.m_arParentsStyles), m_sId(oStyle.m_sId),
|
||||
@ -663,12 +663,12 @@ namespace NSCSS
|
||||
else if (ScalingDirectionX == enScalingDirection && 0 != m_oSourceWindow.m_ushWidth &&
|
||||
0 != m_oDeviceWindow.m_ushWidth && m_oSourceWindow.m_ushWidth != m_oDeviceWindow.m_ushWidth)
|
||||
{
|
||||
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushWidth * m_oDeviceWindow.m_ushWidth + 0.5f);
|
||||
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushWidth * m_oDeviceWindow.m_ushWidth + 0.5f);
|
||||
}
|
||||
else if (ScalingDirectionY == enScalingDirection && 0 != m_oSourceWindow.m_ushHeight &&
|
||||
0 != m_oDeviceWindow.m_ushHeight && m_oSourceWindow.m_ushHeight != m_oDeviceWindow.m_ushHeight)
|
||||
{
|
||||
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushHeight * m_oDeviceWindow.m_ushHeight + 0.5f);
|
||||
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushHeight * m_oDeviceWindow.m_ushHeight + 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,7 +684,6 @@ namespace NSCSS
|
||||
{
|
||||
case Pixel:
|
||||
return static_cast<int>(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return ConvertPxToPt(dValue);
|
||||
case Cantimeter:
|
||||
@ -735,7 +734,6 @@ namespace NSCSS
|
||||
|
||||
switch (m_UnitMeasure)
|
||||
{
|
||||
case Default:
|
||||
case Point:
|
||||
return ConvertCmToPt(dValue);
|
||||
case Pixel:
|
||||
@ -790,7 +788,6 @@ namespace NSCSS
|
||||
{
|
||||
case Pixel:
|
||||
return ConvertMmToPx(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return ConvertMmToPt(dValue);
|
||||
case Cantimeter:
|
||||
@ -817,12 +814,12 @@ namespace NSCSS
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToPc(const float& dValue) const
|
||||
{
|
||||
return static_cast<int>(2.8346f * dValue + 0.5f);
|
||||
return static_cast<int>(0.236f * dValue + 0.5f);
|
||||
}
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToPt(const float& dValue) const
|
||||
{
|
||||
return static_cast<int>(0.23262f * dValue + 0.5f);
|
||||
return static_cast<int>(2.835f * dValue + 0.5f);
|
||||
}
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToPx(const float& dValue) const
|
||||
@ -842,7 +839,6 @@ namespace NSCSS
|
||||
{
|
||||
case Pixel:
|
||||
return ConvertInToPx(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return ConvertInToPt(dValue);
|
||||
case Cantimeter:
|
||||
@ -894,7 +890,6 @@ namespace NSCSS
|
||||
{
|
||||
case Pixel:
|
||||
return ConvertPtToPx(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return static_cast<int>(dValue + 0.5f);
|
||||
case Cantimeter:
|
||||
@ -947,7 +942,6 @@ namespace NSCSS
|
||||
{
|
||||
case Pixel:
|
||||
return ConvertPcToPx(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return ConvertPcToPt(dValue);
|
||||
case Cantimeter:
|
||||
|
||||
@ -19,8 +19,8 @@ namespace NSCSS
|
||||
CCssCalculator();
|
||||
~CCssCalculator();
|
||||
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Default) const;
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Default) const;
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
|
||||
|
||||
// void AddStyle(const std::vector<std::string>& sSelectors, const std::string& sStyle);
|
||||
void AddStyles (const std::string& sStyle);
|
||||
|
||||
@ -40,7 +40,7 @@ bool operator<(const std::vector<NSCSS::CNode> &arLeftSelectors, const std::vect
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_UnitMeasure(Default), m_mStatictics(NULL), m_sEncoding(L"UTF-8"){}
|
||||
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_UnitMeasure(Point), m_mStatictics(NULL), m_sEncoding(L"UTF-8"){}
|
||||
|
||||
CCssCalculator_Private::~CCssCalculator_Private()
|
||||
{
|
||||
@ -309,8 +309,7 @@ namespace NSCSS
|
||||
if (arSelectors.empty())
|
||||
return CCompiledStyle();
|
||||
|
||||
if (unitMeasure != Default)
|
||||
SetUnitMeasure(unitMeasure);
|
||||
SetUnitMeasure(unitMeasure);
|
||||
|
||||
if (!bIsSettings)
|
||||
{
|
||||
@ -542,8 +541,7 @@ namespace NSCSS
|
||||
if (arSelectors.empty())
|
||||
return false;
|
||||
|
||||
if (unitMeasure != Default)
|
||||
SetUnitMeasure(unitMeasure);
|
||||
SetUnitMeasure(unitMeasure);
|
||||
|
||||
if (!bIsSettings)
|
||||
{
|
||||
@ -843,6 +841,10 @@ namespace NSCSS
|
||||
return m_nDpi;
|
||||
}
|
||||
|
||||
const std::map<std::wstring, CElement *> *CCssCalculator_Private::GetData() const
|
||||
{
|
||||
return &m_mData;
|
||||
}
|
||||
|
||||
UnitMeasure CCssCalculator_Private::GetUnitMeasure() const
|
||||
{
|
||||
@ -858,7 +860,7 @@ namespace NSCSS
|
||||
{
|
||||
m_sEncoding = L"UTF-8";
|
||||
m_nDpi = 96;
|
||||
m_UnitMeasure = Default;
|
||||
m_UnitMeasure = Point;
|
||||
|
||||
m_mData.clear();
|
||||
m_arFiles.clear();
|
||||
|
||||
@ -11,67 +11,69 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CCssCalculator_Private
|
||||
{
|
||||
unsigned short int m_nDpi;
|
||||
unsigned short int m_nCountNodes;
|
||||
UnitMeasure m_UnitMeasure;
|
||||
class CCssCalculator_Private
|
||||
{
|
||||
unsigned short int m_nDpi;
|
||||
unsigned short int m_nCountNodes;
|
||||
UnitMeasure m_UnitMeasure;
|
||||
|
||||
std::list<std::wstring> m_arFiles;
|
||||
std::list<std::wstring> m_arFiles;
|
||||
|
||||
std::map<std::wstring, CElement*> m_mData;
|
||||
std::map<std::wstring, CElement*> m_mData;
|
||||
|
||||
std::map<StatistickElement, unsigned int> *m_mStatictics; // Количество повторений свойств id и style у селекторов
|
||||
std::map<StatistickElement, unsigned int> *m_mStatictics; // Количество повторений свойств id и style у селекторов
|
||||
|
||||
std::map<std::vector<CNode>, CCompiledStyle*> m_mUsedStyles;
|
||||
std::map<std::vector<CNode>, CCompiledStyle*> m_mUsedStyles;
|
||||
|
||||
std::wstring m_sEncoding;
|
||||
std::wstring m_sEncoding;
|
||||
|
||||
CSizeWindow m_oSourceWindow;
|
||||
CSizeWindow m_oDeviceWindow;
|
||||
CSizeWindow m_oSourceWindow;
|
||||
CSizeWindow m_oDeviceWindow;
|
||||
|
||||
void GetStylesheet(const KatanaStylesheet* oStylesheet);
|
||||
void GetRule(const KatanaRule* oRule);
|
||||
void GetStylesheet(const KatanaStylesheet* oStylesheet);
|
||||
void GetRule(const KatanaRule* oRule);
|
||||
|
||||
void GetStyleRule(const KatanaStyleRule* oRule);
|
||||
void GetStyleRule(const KatanaStyleRule* oRule);
|
||||
|
||||
std::wstring GetValueList(const KatanaArray* oValues);
|
||||
std::wstring GetValueList(const KatanaArray* oValues);
|
||||
|
||||
std::vector<std::wstring> GetSelectorList(const KatanaArray* oSelectors) const;
|
||||
std::wstring GetSelector(const KatanaSelector* oSelector) const;
|
||||
std::vector<std::wstring> GetSelectorList(const KatanaArray* oSelectors) const;
|
||||
std::wstring GetSelector(const KatanaSelector* oSelector) const;
|
||||
|
||||
std::map<std::wstring, std::wstring> GetDeclarationList(const KatanaArray* oDeclarations) const;
|
||||
std::pair<std::wstring, std::wstring> GetDeclaration(const KatanaDeclaration* oDecl) const;
|
||||
std::map<std::wstring, std::wstring> GetDeclarationList(const KatanaArray* oDeclarations) const;
|
||||
std::pair<std::wstring, std::wstring> GetDeclaration(const KatanaDeclaration* oDecl) const;
|
||||
|
||||
void GetOutputData(KatanaOutput* oOutput);
|
||||
void GetOutputData(KatanaOutput* oOutput);
|
||||
|
||||
public:
|
||||
CCssCalculator_Private();
|
||||
~CCssCalculator_Private();
|
||||
public:
|
||||
CCssCalculator_Private();
|
||||
~CCssCalculator_Private();
|
||||
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Default);
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Default);
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point);
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point);
|
||||
|
||||
void AddStyles(const std::string& sStyle);
|
||||
void AddStyles(const std::wstring& sStyle);
|
||||
void AddStylesFromFile(const std::wstring& sFileName);
|
||||
void AddStyles(const std::string& sStyle);
|
||||
void AddStyles(const std::wstring& sStyle);
|
||||
void AddStylesFromFile(const std::wstring& sFileName);
|
||||
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(unsigned short int nValue);
|
||||
void SetBodyTree(const CTree &oTree);
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(unsigned short int nValue);
|
||||
void SetBodyTree(const CTree &oTree);
|
||||
|
||||
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
|
||||
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
|
||||
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
|
||||
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
|
||||
|
||||
CSizeWindow GetSizeSourceWindow() const;
|
||||
CSizeWindow GetSizeDeviceWindow() const;
|
||||
CSizeWindow GetSizeSourceWindow() const;
|
||||
CSizeWindow GetSizeDeviceWindow() const;
|
||||
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
std::wstring GetEncoding() const;
|
||||
unsigned short int GetDpi() const;
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
std::wstring GetEncoding() const;
|
||||
unsigned short int GetDpi() const;
|
||||
|
||||
void Clear();
|
||||
const std::map<std::wstring, CElement*>* GetData() const;
|
||||
|
||||
};
|
||||
void Clear();
|
||||
|
||||
};
|
||||
}
|
||||
#endif // CCSSCALCULATOR_PRIVATE_H
|
||||
|
||||
302
Common/3dParty/html/css/src/CUnitMeasureConverter.cpp
Normal file
302
Common/3dParty/html/css/src/CUnitMeasureConverter.cpp
Normal file
@ -0,0 +1,302 @@
|
||||
#include "CUnitMeasureConverter.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "StaticFunctions.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CUnitMeasureConverter::CUnitMeasureConverter()
|
||||
{}
|
||||
|
||||
double CUnitMeasureConverter::ConvertPx(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Pixel:
|
||||
return dValue;
|
||||
case NSCSS::Point:
|
||||
return 72. / (double)ushDPI * dValue;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue / (double)ushDPI * 2.54;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue / (double)ushDPI * 25.4;
|
||||
case NSCSS::Inch:
|
||||
return 1. / (double)ushDPI * dValue;
|
||||
case NSCSS::Peak:
|
||||
return 0.16667 / (double)ushDPI * dValue;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
double CUnitMeasureConverter::ConvertCm(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Point:
|
||||
return 28.35 * dValue;
|
||||
case NSCSS::Pixel:
|
||||
return (double)ushDPI / 2.54 * dValue;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue * 10.;
|
||||
case NSCSS::Inch:
|
||||
return dValue / 2.54f;
|
||||
case NSCSS::Peak:
|
||||
return 2.36 * dValue;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
double CUnitMeasureConverter::ConvertMm(double dValue, NSCSS::UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Point:
|
||||
return 2.835 * dValue;
|
||||
case NSCSS::Pixel:
|
||||
return (double)ushDPI / 25.4 * dValue;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue / 10.;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue;
|
||||
case NSCSS::Inch:
|
||||
return dValue / 25.4;
|
||||
case NSCSS::Peak:
|
||||
return 0.236 * dValue;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
double CUnitMeasureConverter::ConvertIn(double dValue, NSCSS::UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Point:
|
||||
return dValue / 6.;
|
||||
case NSCSS::Pixel:
|
||||
return dValue * (double)ushDPI;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue * 2.54;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue * 25.4;
|
||||
case NSCSS::Inch:
|
||||
return dValue;
|
||||
case NSCSS::Peak:
|
||||
return dValue / 72.;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
double CUnitMeasureConverter::ConvertPt(double dValue, NSCSS::UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Point:
|
||||
return dValue;
|
||||
case NSCSS::Pixel:
|
||||
return (double)ushDPI / 72. * dValue;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue * 0.03528;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue * 0.3528;
|
||||
case NSCSS::Inch:
|
||||
return dValue / 72.;
|
||||
case NSCSS::Peak:
|
||||
return dValue / 12.;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
double CUnitMeasureConverter::ConvertPc(double dValue, NSCSS::UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
switch (enUnitMeasure)
|
||||
{
|
||||
case NSCSS::Point:
|
||||
return dValue * 12.;
|
||||
case NSCSS::Pixel:
|
||||
return (double)ushDPI / 6. * dValue;
|
||||
case NSCSS::Cantimeter:
|
||||
return dValue * 0.423;
|
||||
case NSCSS::Millimeter:
|
||||
return dValue * 4.23;
|
||||
case NSCSS::Inch:
|
||||
return dValue / 6.;
|
||||
case NSCSS::Peak:
|
||||
return dValue;
|
||||
}
|
||||
|
||||
return 0.;
|
||||
}
|
||||
|
||||
std::wstring CUnitMeasureConverter::ConvertUnitMeasure(const std::wstring &wsValue, double dPreviousValue, UnitMeasure enUnitMeasure, unsigned short ushDPI)
|
||||
{
|
||||
if (wsValue.empty())
|
||||
return std::wstring();
|
||||
|
||||
std::wstring wsNewValue;
|
||||
|
||||
std::vector<std::wstring> arValues = NSCSS::NS_STATIC_FUNCTIONS::GetWordsWithSigns(wsValue);
|
||||
|
||||
for (std::wstring& wsValueTemp : arValues)
|
||||
{
|
||||
std::transform(wsValueTemp.begin(), wsValueTemp.end(), wsValueTemp.begin(), tolower);
|
||||
|
||||
if (wsValueTemp == L"important")
|
||||
{
|
||||
wsNewValue += L"!important";
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t nPosGrid = wsValueTemp.find(L'#');
|
||||
|
||||
if (nPosGrid != std::wstring::npos || !NSCSS::NS_STATIC_FUNCTIONS::NumberInWString(wsValueTemp))
|
||||
{
|
||||
if (!NSCSS::NS_STATIC_FUNCTIONS::ConvertAbsoluteValue(wsValueTemp, dPreviousValue))
|
||||
{
|
||||
wsNewValue += wsValueTemp;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
double dValue = NSCSS::NS_STATIC_FUNCTIONS::ReadDouble(wsValueTemp);
|
||||
|
||||
const size_t posPercent = wsValueTemp.find(L'%');
|
||||
|
||||
if (posPercent != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(dValue * dPreviousValue / 100.);
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"px") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertPx(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"cm") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertCm(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"mm") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertMm(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"in") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertIn(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"pt") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertPt(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"pc") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(ConvertPc(dValue, enUnitMeasure, ushDPI));
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else if (wsValueTemp.find(L"em") != std::wstring::npos)
|
||||
{
|
||||
wsNewValue += std::to_wstring(dValue * dPreviousValue);
|
||||
|
||||
if (wsValueTemp.find(L';') != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
else if (arValues.size() > 1 && wsValueTemp.find(L':') == std::wstring::npos)
|
||||
wsNewValue += L' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
wsNewValue += wsValueTemp;
|
||||
|
||||
if (wsValueTemp.find(L";") != std::wstring::npos)
|
||||
wsNewValue += L';';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wsValueTemp.back() != L';' && wsValueTemp.back() != L':' && wsValueTemp.back() != L' ')
|
||||
wsValueTemp += L' ';
|
||||
}
|
||||
|
||||
return wsNewValue;
|
||||
}
|
||||
|
||||
bool CUnitMeasureConverter::GetValue(const std::wstring &wsValue, double &dValue, UnitMeasure &enUnitMeasure)
|
||||
{
|
||||
std::wstring::const_iterator oFoundDigit = std::find_if(wsValue.begin(), wsValue.end(), std::iswdigit);
|
||||
|
||||
if (wsValue.end() == oFoundDigit)
|
||||
return false;
|
||||
|
||||
std::wistringstream(wsValue) >> dValue;
|
||||
|
||||
std::wstring::const_iterator oFoundUM = std::find_if(oFoundDigit, wsValue.end(), [](wchar_t wcSymbol){ return std::iswalpha(wcSymbol) || L'%' == wcSymbol; });
|
||||
|
||||
if (wsValue.end() != oFoundUM)
|
||||
{
|
||||
if (L'%' == *oFoundUM)
|
||||
{
|
||||
enUnitMeasure = Percent;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring wsUnitMeasure(oFoundUM, oFoundUM + 2);
|
||||
|
||||
if (L"px" == wsUnitMeasure)
|
||||
enUnitMeasure = Pixel;
|
||||
else if (L"pt" == wsUnitMeasure)
|
||||
enUnitMeasure = Point;
|
||||
else if (L"cm" == wsUnitMeasure)
|
||||
enUnitMeasure = Cantimeter;
|
||||
else if (L"mm" == wsUnitMeasure)
|
||||
enUnitMeasure = Millimeter;
|
||||
else if (L"in" == wsUnitMeasure)
|
||||
enUnitMeasure = Inch;
|
||||
else if (L"pc" == wsUnitMeasure)
|
||||
enUnitMeasure = Peak;
|
||||
}
|
||||
else
|
||||
enUnitMeasure = None;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
37
Common/3dParty/html/css/src/CUnitMeasureConverter.h
Normal file
37
Common/3dParty/html/css/src/CUnitMeasureConverter.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef CUNITMEASURECONVERTER_H
|
||||
#define CUNITMEASURECONVERTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
None,
|
||||
Percent,
|
||||
Pixel,
|
||||
Point,
|
||||
Cantimeter,
|
||||
Millimeter,
|
||||
Inch,
|
||||
Peak
|
||||
} UnitMeasure;
|
||||
|
||||
class CUnitMeasureConverter
|
||||
{
|
||||
CUnitMeasureConverter();
|
||||
public:
|
||||
static double ConvertPx(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
static double ConvertCm(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
static double ConvertMm(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
static double ConvertIn(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
static double ConvertPt(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
static double ConvertPc(double dValue, UnitMeasure enUnitMeasure, unsigned short ushDPI);
|
||||
|
||||
static std::wstring ConvertUnitMeasure(const std::wstring& wsValue, double dPreviousValue, UnitMeasure enUnitMeasure, unsigned short ushDPI = 96);
|
||||
|
||||
static bool GetValue(const std::wstring& wsValue, double& dValue, UnitMeasure& enUnitMeasure);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CUNITMEASURECONVERTER_H
|
||||
@ -16,16 +16,6 @@ namespace NSCSS
|
||||
#define RGB_TO_INT(r, g, b) ((unsigned int)( ( (unsigned char)(r) )| ( ( (unsigned char)(g) ) << 8 ) | ( ( (unsigned char)(b) ) << 16 ) ) )
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
Default = 0,
|
||||
Pixel,
|
||||
Point,
|
||||
Cantimeter,
|
||||
Millimeter,
|
||||
Inch,
|
||||
Peak
|
||||
} UnitMeasure;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ScalingDirectionNone = 0,
|
||||
@ -3358,40 +3348,40 @@ namespace NSCSS
|
||||
};
|
||||
}
|
||||
|
||||
const std::vector<std::wstring> arPseudoClasses {
|
||||
L"invalid",
|
||||
L"read-only",
|
||||
L"-moz-placeholder",
|
||||
L"-webkit-input-placeholder",
|
||||
L"active",
|
||||
L"checked",
|
||||
L"default",
|
||||
L"disabled",
|
||||
L"empty",
|
||||
L"enabled",
|
||||
L"first-child",
|
||||
L"first-of-type",
|
||||
L"focus",
|
||||
L"hover",
|
||||
L"indeterminate",
|
||||
L"lang",
|
||||
L"last-child",
|
||||
L"last-of-type",
|
||||
L"link",
|
||||
L"not",
|
||||
L"nth-child",
|
||||
L"nth-last-child",
|
||||
L"nth-last-of-type",
|
||||
L"nth-of-type",
|
||||
L"only-child",
|
||||
L"only-of-type",
|
||||
L"optional",
|
||||
L"read-write",
|
||||
L"required",
|
||||
L"root",
|
||||
L"target",
|
||||
L"valid",
|
||||
L"visited"};
|
||||
const std::wstring arPseudoClasses[33] {
|
||||
L"invalid",
|
||||
L"read-only",
|
||||
L"-moz-placeholder",
|
||||
L"-webkit-input-placeholder",
|
||||
L"active",
|
||||
L"checked",
|
||||
L"default",
|
||||
L"disabled",
|
||||
L"empty",
|
||||
L"enabled",
|
||||
L"first-child",
|
||||
L"first-of-type",
|
||||
L"focus",
|
||||
L"hover",
|
||||
L"indeterminate",
|
||||
L"lang",
|
||||
L"last-child",
|
||||
L"last-of-type",
|
||||
L"link",
|
||||
L"not",
|
||||
L"nth-child",
|
||||
L"nth-last-child",
|
||||
L"nth-last-of-type",
|
||||
L"nth-of-type",
|
||||
L"only-child",
|
||||
L"only-of-type",
|
||||
L"optional",
|
||||
L"read-write",
|
||||
L"required",
|
||||
L"root",
|
||||
L"target",
|
||||
L"valid",
|
||||
L"visited"};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "../../../../../DesktopEditor/common/File.h"
|
||||
#include "CNode.h"
|
||||
#include <cwctype>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
@ -144,6 +145,13 @@ namespace NSCSS
|
||||
return arWords;
|
||||
}
|
||||
|
||||
inline double ReadDouble(const std::wstring& wsValue)
|
||||
{
|
||||
double dValue;
|
||||
std::wistringstream(wsValue) >> dValue;
|
||||
return dValue;
|
||||
}
|
||||
|
||||
inline std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
|
||||
{
|
||||
std::vector<double> arValues;
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#include "StyleProperties.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "StaticFunctions.h"
|
||||
#include "ConstValues.h"
|
||||
|
||||
@ -223,10 +221,29 @@ namespace NSCSS
|
||||
return *this;
|
||||
}
|
||||
|
||||
double CDigit::ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const
|
||||
{
|
||||
switch(m_enUnitMeasure)
|
||||
{
|
||||
case Percent: return dPrevValue * m_oValue;
|
||||
case Pixel: return CUnitMeasureConverter::ConvertPx(m_oValue, enUnitMeasure, 96);
|
||||
case Point: return CUnitMeasureConverter::ConvertPt(m_oValue, enUnitMeasure, 96);
|
||||
case Cantimeter: return CUnitMeasureConverter::ConvertCm(m_oValue, enUnitMeasure, 96);
|
||||
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 None: return m_oValue;
|
||||
}
|
||||
}
|
||||
|
||||
CDigit::CDigit()
|
||||
: CValue(DBL_MIN, 0, false)
|
||||
{}
|
||||
|
||||
CDigit::CDigit(double dValue)
|
||||
: CValue(dValue, 0, false)
|
||||
{}
|
||||
|
||||
CDigit::CDigit(double dValue, unsigned int unLevel, bool bImportant)
|
||||
: CValue(dValue, unLevel, bImportant)
|
||||
{}
|
||||
@ -265,6 +282,35 @@ namespace NSCSS
|
||||
return std::to_wstring(m_oValue);
|
||||
}
|
||||
|
||||
int CDigit::ToInt(UnitMeasure enUnitMeasure, double dPrevValue) const
|
||||
{
|
||||
if (DBL_MIN == m_oValue)
|
||||
return 0;
|
||||
|
||||
return static_cast<int>(ConvertValue(dPrevValue, enUnitMeasure) + 0.5);
|
||||
}
|
||||
|
||||
double CDigit::ToDouble(UnitMeasure enUnitMeasure, double dPrevValue) const
|
||||
{
|
||||
if (DBL_MIN == m_oValue)
|
||||
return 0;
|
||||
|
||||
return ConvertValue(dPrevValue, enUnitMeasure);
|
||||
}
|
||||
|
||||
std::wstring CDigit::ToWString(UnitMeasure enUnitMeasure, double dPrevValue) const
|
||||
{
|
||||
if (DBL_MIN == m_oValue)
|
||||
return 0;
|
||||
|
||||
return std::to_wstring(ConvertValue(dPrevValue, enUnitMeasure));
|
||||
}
|
||||
|
||||
UnitMeasure CDigit::GetUnitMeasure() const
|
||||
{
|
||||
return m_enUnitMeasure;
|
||||
}
|
||||
|
||||
CDigit CDigit::operator+(const CDigit &oDigit) const
|
||||
{
|
||||
CDigit oTemp;
|
||||
@ -276,6 +322,48 @@ namespace NSCSS
|
||||
return oTemp;
|
||||
}
|
||||
|
||||
CDigit CDigit::operator-(const CDigit &oDigit) const
|
||||
{
|
||||
CDigit oTemp;
|
||||
|
||||
oTemp.m_oValue = m_oValue - oDigit.m_oValue;
|
||||
oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel);
|
||||
oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant);
|
||||
|
||||
return oTemp;
|
||||
}
|
||||
|
||||
CDigit CDigit::operator*(const CDigit &oDigit) const
|
||||
{
|
||||
CDigit oTemp;
|
||||
|
||||
oTemp.m_oValue = m_oValue * oDigit.m_oValue;
|
||||
oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel);
|
||||
oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant);
|
||||
|
||||
return oTemp;
|
||||
}
|
||||
|
||||
CDigit CDigit::operator/(const CDigit &oDigit) const
|
||||
{
|
||||
CDigit oTemp;
|
||||
|
||||
oTemp.m_oValue = m_oValue / oDigit.m_oValue;
|
||||
oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel);
|
||||
oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant);
|
||||
|
||||
return oTemp;
|
||||
}
|
||||
|
||||
CDigit CDigit::operator*(double dValue) const
|
||||
{
|
||||
CDigit oTemp(*this);
|
||||
|
||||
oTemp.m_oValue *= dValue;
|
||||
|
||||
return oTemp;
|
||||
}
|
||||
|
||||
CDigit &CDigit::operator+=(const CDigit &oDigit)
|
||||
{
|
||||
if (m_unLevel > oDigit.m_unLevel || (m_bImportant && !oDigit.m_bImportant) || DBL_MIN == oDigit.m_oValue)
|
||||
@ -294,12 +382,30 @@ namespace NSCSS
|
||||
return *this;
|
||||
}
|
||||
|
||||
CDigit &CDigit::operator-=(double dValue)
|
||||
{
|
||||
m_oValue -= dValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CDigit &CDigit::operator*=(double dValue)
|
||||
{
|
||||
m_oValue *= dValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CDigit &CDigit::operator/=(double dValue)
|
||||
{
|
||||
m_oValue /= dValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CDigit &CDigit::operator =(double dValue)
|
||||
{
|
||||
m_oValue = dValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool CDigit::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
if (wsValue.empty() || (m_bImportant && !bHardMode))
|
||||
@ -307,16 +413,13 @@ namespace NSCSS
|
||||
|
||||
std::wstring wsNewValue = wsValue;
|
||||
|
||||
bool bImportant = CutImportant(wsNewValue);
|
||||
|
||||
bool bImportant = CutImportant(wsNewValue); //TODO:: иногда мы знаем, что "!important" точно не встретится
|
||||
// возможно стоит добавить ещё метод
|
||||
if (m_bImportant && !bImportant)
|
||||
return false;
|
||||
|
||||
double dValue = 0;
|
||||
CUnitMeasureConverter::GetValue(wsValue, m_oValue, m_enUnitMeasure);
|
||||
|
||||
std::wistringstream(wsValue) >> dValue;
|
||||
|
||||
m_oValue = dValue;
|
||||
m_unLevel = unLevel;
|
||||
m_bImportant = bImportant;
|
||||
|
||||
@ -1572,9 +1675,9 @@ namespace NSCSS
|
||||
{
|
||||
std::wstring wsNewFamily(wsValue);
|
||||
|
||||
if (wsNewFamily.end() == wsNewFamily.erase(std::remove(wsNewFamily.begin(), wsNewFamily.end(), L'\''), wsNewFamily.end()) &&
|
||||
wsNewFamily.end() == wsNewFamily.erase(std::remove(wsNewFamily.begin(), wsNewFamily.end(), L'"'), wsNewFamily.end()))
|
||||
return false;
|
||||
// if (wsNewFamily.end() == wsNewFamily.erase(std::remove(wsNewFamily.begin(), wsNewFamily.end(), L'\''), wsNewFamily.end()) &&
|
||||
// wsNewFamily.end() == wsNewFamily.erase(std::remove(wsNewFamily.begin(), wsNewFamily.end(), L'"'), wsNewFamily.end()))
|
||||
// return false;
|
||||
|
||||
std::vector<std::wstring> arWords = NS_STATIC_FUNCTIONS::GetWordsW(wsNewFamily, L",");
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "../../../../DesktopEditor/graphics/Matrix.h"
|
||||
#include "CUnitMeasureConverter.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
@ -71,8 +72,12 @@ namespace NSCSS
|
||||
|
||||
class CDigit : public CValue<double>
|
||||
{
|
||||
UnitMeasure m_enUnitMeasure;
|
||||
|
||||
double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const;
|
||||
public:
|
||||
CDigit();
|
||||
CDigit(double dValue);
|
||||
CDigit(double dValue, unsigned int unLevel, bool bImportant = false);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
@ -84,11 +89,26 @@ namespace NSCSS
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
|
||||
int ToInt(UnitMeasure enUnitMeasure, double dPrevValue = 0.) const;
|
||||
double ToDouble(UnitMeasure enUnitMeasure, double dPrevValue = 0.) const;
|
||||
std::wstring ToWString(UnitMeasure enUnitMeasure, double dPrevValue = 0.) const;
|
||||
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
|
||||
CDigit operator+(const CDigit& oDigit) const;
|
||||
CDigit operator-(const CDigit& oDigit) const;
|
||||
CDigit operator*(const CDigit& oDigit) const;
|
||||
CDigit operator/(const CDigit& oDigit) const;
|
||||
|
||||
CDigit operator*(double dValue) const;
|
||||
|
||||
CDigit& operator+=(const CDigit& oDigit);
|
||||
CDigit& operator-=(const CDigit& oDigit);
|
||||
CDigit& operator+=(double dValue);
|
||||
CDigit& operator-=(double dValue);
|
||||
CDigit& operator*=(double dValue);
|
||||
CDigit& operator/=(double dValue);
|
||||
CDigit& operator =(double dValue);
|
||||
};
|
||||
|
||||
struct TRGB
|
||||
|
||||
Reference in New Issue
Block a user