mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-09 16:15:40 +08:00
Compare commits
215 Commits
v99.99.99.
...
feature/Gr
| Author | SHA1 | Date | |
|---|---|---|---|
| acc81f8c8d | |||
| c0fd800149 | |||
| 0eb442dceb | |||
| 399add2545 | |||
| f245a5b6a5 | |||
| bc3867f281 | |||
| 7e27726dc2 | |||
| ab1bc5e2a9 | |||
| 68ea0b5875 | |||
| 796cd30b09 | |||
| 58d023e023 | |||
| 0ecf5e8eee | |||
| 6f11dd441b | |||
| 5b91e643bb | |||
| c884f2a99d | |||
| fa82a15c07 | |||
| 5006bc3349 | |||
| d87283e485 | |||
| 77ff0a5f15 | |||
| b6dc29364e | |||
| 363d1d7af9 | |||
| d6ce980b12 | |||
| e2289ce58d | |||
| 571e257211 | |||
| fc4fadd4a6 | |||
| 4864a3c303 | |||
| ec760c2aef | |||
| 69bf4d64fb | |||
| 6e3804df33 | |||
| 19f28facf6 | |||
| f45eee1fd6 | |||
| a0e1760e94 | |||
| e57b3e22fd | |||
| 4c3f983cb4 | |||
| 5db60c2581 | |||
| 2bc4ccd343 | |||
| 7304553448 | |||
| fe4e668973 | |||
| bd8589e586 | |||
| 2a298710a7 | |||
| 83fc19672d | |||
| 3217ac7d51 | |||
| c2748fcff4 | |||
| 010c58f110 | |||
| cbf1c9eb16 | |||
| f1236fd01e | |||
| ba10fb7e97 | |||
| 8e2d5ee209 | |||
| 433a0973e5 | |||
| 3a94430a64 | |||
| 40ca82c584 | |||
| 24b7b59af0 | |||
| 2b494e3590 | |||
| f3746f4bb8 | |||
| 9cfe99acae | |||
| 6b406945f7 | |||
| 18b59bf8f8 | |||
| b481b0ef12 | |||
| caaf664633 | |||
| 23167f6460 | |||
| 6707cd05a9 | |||
| 125d2e8b16 | |||
| 79d830f2cf | |||
| cba75df9d0 | |||
| 38177a2793 | |||
| dd9ca63b54 | |||
| ced55d3cde | |||
| c72e44f44e | |||
| bc00d63250 | |||
| 94fd1d94bd | |||
| cb01a629bc | |||
| 93dc58c49e | |||
| fa2595612e | |||
| f10c620ddb | |||
| 3c26e50b5d | |||
| 9286bd4615 | |||
| 2d1f53d952 | |||
| 5e5fb5ea6d | |||
| 34902e06cf | |||
| 1db7a6ae2a | |||
| ec72a22aab | |||
| 6f0539df86 | |||
| 36109d2ba8 | |||
| a283d0c4ad | |||
| 1cefed92b2 | |||
| bfd2627269 | |||
| d690281b8d | |||
| b07c308e9b | |||
| 739a1d2a35 | |||
| 1e2964ccbe | |||
| b445369410 | |||
| 57cc43371c | |||
| de826c1f0f | |||
| e74b75a087 | |||
| c0ffc1dd0f | |||
| c1a6b85431 | |||
| a8978265ea | |||
| 7ec41517e1 | |||
| 43880f909a | |||
| 24d1a9b220 | |||
| ebc81eb7d3 | |||
| 529acfbd5f | |||
| 55e171f86e | |||
| d7254e46c9 | |||
| 633041d07f | |||
| d0afc0fdc0 | |||
| f1b4b2ac29 | |||
| a6b590be74 | |||
| 76f64547a3 | |||
| 0a56b4348f | |||
| f0130f92dc | |||
| 1aa1d63f61 | |||
| efa6115a34 | |||
| 26f344ab99 | |||
| 8bc6c5abb7 | |||
| 2c294d5be6 | |||
| bbfb8553b1 | |||
| d11b0c814e | |||
| 1dba84f407 | |||
| 2a84964f3c | |||
| 0d9d8fad80 | |||
| 6146180408 | |||
| 367b2c5317 | |||
| 0e1a1ca586 | |||
| e354b3b3d5 | |||
| 49cdde75b3 | |||
| 8b3fdbe50a | |||
| 60c8623980 | |||
| 1e7d4586b3 | |||
| 5318dc1238 | |||
| 927585ad86 | |||
| 77efe21913 | |||
| cf88f807cd | |||
| b6d108dd01 | |||
| 0a5f9070de | |||
| 4306486c3c | |||
| 88a3128b87 | |||
| 17b632844a | |||
| 0fb4c8f13a | |||
| bc3dfa5b3f | |||
| 7af5e05ea0 | |||
| d676270cac | |||
| ccfb56fc2e | |||
| 540e89d7a0 | |||
| bec99465a9 | |||
| f4661150c6 | |||
| 442756f964 | |||
| 65d5b5c628 | |||
| 859e96a3ab | |||
| c703722372 | |||
| 4a4a05fd8a | |||
| 099f3f5632 | |||
| 2386c8e1a9 | |||
| 96662a2382 | |||
| cbed11f00b | |||
| 7d6b82554b | |||
| 1c894b7896 | |||
| 7ddc3234a7 | |||
| 7e16297d33 | |||
| bc7eab7f1d | |||
| 15fdb5a8ce | |||
| 52e52ee720 | |||
| 0343d7989d | |||
| 2e9de3748b | |||
| a4b6d57786 | |||
| abcfc66a41 | |||
| fdbc72e1b4 | |||
| 77ef5ead99 | |||
| c7a5f5bdb2 | |||
| 9e246ae8ba | |||
| dcea017b51 | |||
| 2a3d138459 | |||
| 92a8bd2ed5 | |||
| ecec9e2e39 | |||
| e18ed76b48 | |||
| d4dee32fe7 | |||
| d5b46f74fc | |||
| d2db5abe89 | |||
| db7297f5c1 | |||
| 7de16d2d49 | |||
| ad1dc1ebf9 | |||
| fc3e54c485 | |||
| bad7cc3c86 | |||
| ea7030d58e | |||
| dded7e69ef | |||
| bacec90b2e | |||
| cfe6264404 | |||
| 478e3e9dc3 | |||
| 2f5035d0e3 | |||
| 5633b92d19 | |||
| b2f2017158 | |||
| 0ed1fa08e1 | |||
| 76b90d43a4 | |||
| f89f66df45 | |||
| 68922675b5 | |||
| dc0c6c369c | |||
| 0661c9b552 | |||
| c18251dcfd | |||
| f86ef63f58 | |||
| 2b29420eb1 | |||
| 085940c37b | |||
| 891dab4016 | |||
| 2e2bdcdbf1 | |||
| ec0b85511b | |||
| 62710bb443 | |||
| 5d666a0d10 | |||
| 4f97c72212 | |||
| dadd3987f0 | |||
| 1e8d0d62b2 | |||
| 417aab6cee | |||
| 35dc17e584 | |||
| 1ed96f295a | |||
| b3e95df084 | |||
| 2942452a61 | |||
| 2212c3b26f |
@ -3,7 +3,28 @@ DEPENDPATH += $$PWD
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
|
||||
HEADERS += $$files($$PWD/src/*.h, true)
|
||||
SOURCES += $$files($$PWD/src/*.cpp, true)
|
||||
css_calculator_without_xhtml {
|
||||
HEADERS += \
|
||||
$$PWD/src/CCssCalculator_Private.h \
|
||||
$$PWD/src/CElement.h \
|
||||
$$PWD/src/CNode.h \
|
||||
$$PWD/src/ConstValues.h \
|
||||
$$PWD/src/StaticFunctions.h \
|
||||
$$PWD/src/StyleProperties.h \
|
||||
$$PWD/src/CUnitMeasureConverter.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/CCssCalculator_Private.cpp \
|
||||
$$PWD/src/CElement.cpp \
|
||||
$$PWD/src/CNode.cpp \
|
||||
$$PWD/src/ConstValues.cpp \
|
||||
$$PWD/src/StaticFunctions.cpp \
|
||||
$$PWD/src/StyleProperties.cpp \
|
||||
$$PWD/src/CUnitMeasureConverter.cpp
|
||||
} else {
|
||||
HEADERS += $$files($$PWD/src/*.h, true)
|
||||
SOURCES += $$files($$PWD/src/*.cpp, true)
|
||||
|
||||
DEFINES += CSS_CALCULATOR_WITH_XHTML
|
||||
}
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/html/katana.pri)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -9,105 +9,60 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "StyleProperties.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CSSCALCULATOR_EXPORT CCompiledStyle
|
||||
{
|
||||
std::set<std::wstring> m_arParentsStyles;
|
||||
std::wstring m_sId;
|
||||
class CCompiledStyle
|
||||
{
|
||||
friend class CStyle;
|
||||
std::set<std::wstring> m_arParentsStyles;
|
||||
std::wstring m_sId;
|
||||
|
||||
unsigned short int m_nDpi;
|
||||
UnitMeasure m_UnitMeasure;
|
||||
unsigned short int m_nDpi;
|
||||
UnitMeasure m_UnitMeasure;
|
||||
|
||||
CSizeWindow m_oSourceWindow;
|
||||
CSizeWindow m_oDeviceWindow;
|
||||
CSizeWindow m_oSourceWindow;
|
||||
CSizeWindow m_oDeviceWindow;
|
||||
|
||||
std::wstring ConvertUnitMeasure(const std::wstring& sValue, const float& fPreviousValue, ScalingDirection enScalingDirection = ScalingDirectionNone) const;
|
||||
public:
|
||||
NSProperties::CFont m_oFont;
|
||||
NSProperties::CIndent m_oMargin;
|
||||
NSProperties::CIndent m_oPadding;
|
||||
NSProperties::CBackground m_oBackground;
|
||||
NSProperties::CText m_oText;
|
||||
NSProperties::CBorder m_oBorder;
|
||||
NSProperties::CDisplay m_oDisplay;
|
||||
|
||||
void Scale(int &nValue, ScalingDirection enScalingDirection) const;
|
||||
CCompiledStyle();
|
||||
CCompiledStyle(const CCompiledStyle& oStyle);
|
||||
|
||||
int ConvertPx(const std::wstring& sValue) const;
|
||||
int ConvertPxToCm(const float& dValue) const;
|
||||
int ConvertPxToIn(const float& dValue) const;
|
||||
int ConvertPxToMm(const float& dValue) const;
|
||||
int ConvertPxToPt(const float& dValue) const;
|
||||
int ConvertPxToPc(const float& dValue) const;
|
||||
~CCompiledStyle();
|
||||
|
||||
int ConvertCm(const std::wstring& sValue) const;
|
||||
int ConvertCmToPx(const float& dValue) const;
|
||||
int ConvertCmToIn(const float& dValue) const;
|
||||
int ConvertCmToMm(const float& dValue) const;
|
||||
int ConvertCmToPt(const float& dValue) const;
|
||||
int ConvertCmToPc(const float& dValue) const;
|
||||
void SetDpi(const unsigned short& uiDpi);
|
||||
void SetUnitMeasure(const UnitMeasure& enUnitMeasure);
|
||||
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
|
||||
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
|
||||
|
||||
int ConvertMm(const std::wstring& sValue) const;
|
||||
int ConvertMmToPx(const float& dValue) const;
|
||||
int ConvertMmToIn(const float& dValue) const;
|
||||
int ConvertMmToCm(const float& dValue) const;
|
||||
int ConvertMmToPt(const float& dValue) const;
|
||||
int ConvertMmToPc(const float& dValue) const;
|
||||
bool Empty() const;
|
||||
|
||||
int ConvertIn(const std::wstring& sValue) const;
|
||||
int ConvertInToPx(const float& dValue) const;
|
||||
int ConvertInToMm(const float& dValue) const;
|
||||
int ConvertInToCm(const float& dValue) const;
|
||||
int ConvertInToPt(const float& dValue) const;
|
||||
int ConvertInToPc(const float& dValue) const;
|
||||
void AddPropSel(const std::wstring& sProperty, const std::wstring& sValue, const unsigned int unLevel, const bool& bHardMode = true);
|
||||
void AddStyle(const std::map<std::wstring, std::wstring>& mStyle, const unsigned int unLevel, const bool& bHardMode = true);
|
||||
void AddStyle(const std::wstring& sStyle, const unsigned int unLevel, const bool& bHardMode = false);
|
||||
virtual void AddOtherStyle(const std::pair<std::wstring, std::wstring>& oStyle, const unsigned int unLevel, const bool& bHardMode = true) {};
|
||||
void AddParent(const std::wstring& sParentName);
|
||||
|
||||
int ConvertPt(const std::wstring& sValue) const;
|
||||
int ConvertPtToPx(const float& dValue) const;
|
||||
int ConvertPtToMm(const float& dValue) const;
|
||||
int ConvertPtToCm(const float& dValue) const;
|
||||
int ConvertPtToIn(const float& dValue) const;
|
||||
int ConvertPtToPc(const float& dValue) const;
|
||||
std::vector<std::wstring> GetParentsName() const;
|
||||
|
||||
int ConvertPc(const std::wstring& sValue) const;
|
||||
int ConvertPcToPx(const float& dValue) const;
|
||||
int ConvertPcToMm(const float& dValue) const;
|
||||
int ConvertPcToCm(const float& dValue) const;
|
||||
int ConvertPcToIn(const float& dValue) const;
|
||||
int ConvertPcToPt(const float& dValue) const;
|
||||
void SetID(const std::wstring& sId);
|
||||
std::wstring GetId() const;
|
||||
|
||||
public:
|
||||
CCompiledStyle& operator+= (const CCompiledStyle& oElement);
|
||||
CCompiledStyle& operator= (const CCompiledStyle& oElement);
|
||||
bool operator== (const CCompiledStyle& oElement) const;
|
||||
|
||||
NSConstValues::NSCssProperties::Font m_pFont;
|
||||
NSConstValues::NSCssProperties::Margin m_pMargin;
|
||||
NSConstValues::NSCssProperties::Background m_pBackground;
|
||||
NSConstValues::NSCssProperties::Text m_pText;
|
||||
NSConstValues::NSCssProperties::Border m_pBorder;
|
||||
NSConstValues::NSCssProperties::Display m_pDisplay;
|
||||
|
||||
CCompiledStyle();
|
||||
explicit CCompiledStyle(const std::map<std::wstring, std::wstring>& mStyle);
|
||||
CCompiledStyle(const CCompiledStyle& oStyle);
|
||||
|
||||
~CCompiledStyle();
|
||||
|
||||
void SetDpi(const unsigned short& uiDpi);
|
||||
void SetUnitMeasure(const UnitMeasure& enUnitMeasure);
|
||||
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
|
||||
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
void AddPropSel(const std::wstring& sProperty, const std::wstring& sValue, const unsigned int unLevel, const bool& bHardMode = true);
|
||||
void AddStyle(const std::map<std::wstring, std::wstring>& mStyle, const unsigned int unLevel, const bool& bHardMode = true);
|
||||
void AddStyle(const std::wstring& sStyle, const unsigned int unLevel, const bool& bHardMode = false);
|
||||
void AddParent(const std::wstring& sParentName);
|
||||
|
||||
std::vector<std::wstring> GetParentsName() const;
|
||||
|
||||
void SetID(const std::wstring& sId);
|
||||
std::wstring GetId() const;
|
||||
|
||||
void ClearImportants();
|
||||
|
||||
CCompiledStyle& operator+= (const CCompiledStyle& oElement);
|
||||
CCompiledStyle& operator= (const CCompiledStyle& oElement);
|
||||
bool operator== (const CCompiledStyle& oElement) const;
|
||||
|
||||
static void StyleEquation(CCompiledStyle& oFirstStyle, CCompiledStyle& oSecondStyle);
|
||||
};
|
||||
static void StyleEquation(CCompiledStyle& oFirstStyle, CCompiledStyle& oSecondStyle);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CCOMPILEDSTYLE_H
|
||||
|
||||
@ -4,88 +4,93 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CCssCalculator::CCssCalculator()
|
||||
{
|
||||
m_pInternal = new CCssCalculator_Private();
|
||||
}
|
||||
CCssCalculator::CCssCalculator()
|
||||
{
|
||||
m_pInternal = new CCssCalculator_Private();
|
||||
}
|
||||
|
||||
CCssCalculator::~CCssCalculator()
|
||||
{
|
||||
delete m_pInternal;
|
||||
}
|
||||
CCssCalculator::~CCssCalculator()
|
||||
{
|
||||
delete m_pInternal;
|
||||
}
|
||||
|
||||
CCompiledStyle CCssCalculator::GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings, const UnitMeasure& unitMeasure) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(arSelectors, bIsSettings, unitMeasure);
|
||||
}
|
||||
CCompiledStyle CCssCalculator::GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings, const UnitMeasure& unitMeasure) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(arSelectors, bIsSettings, unitMeasure);
|
||||
}
|
||||
|
||||
void CCssCalculator::AddStyles(const std::string &sStyle)
|
||||
{
|
||||
m_pInternal->AddStyles(sStyle);
|
||||
}
|
||||
bool CCssCalculator::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors, const bool &bIsSettings, const UnitMeasure &unitMeasure) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(oStyle, arSelectors, bIsSettings, unitMeasure);
|
||||
}
|
||||
|
||||
void CCssCalculator::AddStyles(const std::wstring &sStyle)
|
||||
{
|
||||
m_pInternal->AddStyles(sStyle);
|
||||
}
|
||||
void CCssCalculator::AddStyles(const std::string &sStyle)
|
||||
{
|
||||
m_pInternal->AddStyles(sStyle);
|
||||
}
|
||||
|
||||
void CCssCalculator::AddStylesFromFile(const std::wstring &sFileName)
|
||||
{
|
||||
m_pInternal->AddStylesFromFile(sFileName);
|
||||
}
|
||||
void CCssCalculator::AddStyles(const std::wstring &wsStyle)
|
||||
{
|
||||
m_pInternal->AddStyles(wsStyle);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetUnitMeasure(const UnitMeasure& nType)
|
||||
{
|
||||
m_pInternal->SetUnitMeasure(nType);
|
||||
}
|
||||
void CCssCalculator::AddStylesFromFile(const std::wstring &wsFileName)
|
||||
{
|
||||
m_pInternal->AddStylesFromFile(wsFileName);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetDpi(const unsigned short int& nValue)
|
||||
{
|
||||
m_pInternal->SetDpi(nValue);
|
||||
}
|
||||
void CCssCalculator::SetUnitMeasure(const UnitMeasure& nType)
|
||||
{
|
||||
m_pInternal->SetUnitMeasure(nType);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetBodyTree(const CTree &oTree)
|
||||
{
|
||||
m_pInternal->SetBodyTree(oTree);
|
||||
}
|
||||
void CCssCalculator::SetDpi(const unsigned short int& nValue)
|
||||
{
|
||||
m_pInternal->SetDpi(nValue);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetSizeSourceWindow(const CSizeWindow &oSizeWindow)
|
||||
{
|
||||
m_pInternal->SetSizeSourceWindow(oSizeWindow);
|
||||
}
|
||||
void CCssCalculator::SetBodyTree(const CTree &oTree)
|
||||
{
|
||||
m_pInternal->SetBodyTree(oTree);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetSizeDeviceWindow(const CSizeWindow &oSizeWindow)
|
||||
{
|
||||
m_pInternal->SetSizeDeviceWindow(oSizeWindow);
|
||||
}
|
||||
void CCssCalculator::SetSizeSourceWindow(const CSizeWindow &oSizeWindow)
|
||||
{
|
||||
m_pInternal->SetSizeSourceWindow(oSizeWindow);
|
||||
}
|
||||
|
||||
CSizeWindow CCssCalculator::GetSizeSourceWindow() const
|
||||
{
|
||||
return m_pInternal->GetSizeSourceWindow();
|
||||
}
|
||||
void CCssCalculator::SetSizeDeviceWindow(const CSizeWindow &oSizeWindow)
|
||||
{
|
||||
m_pInternal->SetSizeDeviceWindow(oSizeWindow);
|
||||
}
|
||||
|
||||
CSizeWindow CCssCalculator::GetSizeDeviceWindow() const
|
||||
{
|
||||
return m_pInternal->GetSizeDeviceWindow();
|
||||
}
|
||||
CSizeWindow CCssCalculator::GetSizeSourceWindow() const
|
||||
{
|
||||
return m_pInternal->GetSizeSourceWindow();
|
||||
}
|
||||
|
||||
UnitMeasure CCssCalculator::GetUnitMeasure() const
|
||||
{
|
||||
return m_pInternal->GetUnitMeasure();
|
||||
}
|
||||
CSizeWindow CCssCalculator::GetSizeDeviceWindow() const
|
||||
{
|
||||
return m_pInternal->GetSizeDeviceWindow();
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator::GetEncoding() const
|
||||
{
|
||||
return m_pInternal->GetEncoding();
|
||||
}
|
||||
UnitMeasure CCssCalculator::GetUnitMeasure() const
|
||||
{
|
||||
return m_pInternal->GetUnitMeasure();
|
||||
}
|
||||
|
||||
unsigned short int CCssCalculator::GetDpi() const
|
||||
{
|
||||
return m_pInternal->GetDpi();
|
||||
}
|
||||
std::wstring CCssCalculator::GetEncoding() const
|
||||
{
|
||||
return m_pInternal->GetEncoding();
|
||||
}
|
||||
|
||||
void CCssCalculator::Clear()
|
||||
{
|
||||
m_pInternal->Clear();
|
||||
}
|
||||
unsigned short int CCssCalculator::GetDpi() const
|
||||
{
|
||||
return m_pInternal->GetDpi();
|
||||
}
|
||||
|
||||
void CCssCalculator::Clear()
|
||||
{
|
||||
m_pInternal->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,38 +10,39 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CCssCalculator_Private;
|
||||
class CSSCALCULATOR_EXPORT CCssCalculator
|
||||
{
|
||||
protected:
|
||||
CCssCalculator_Private* m_pInternal;
|
||||
public:
|
||||
CCssCalculator();
|
||||
~CCssCalculator();
|
||||
class CCssCalculator_Private;
|
||||
class CSSCALCULATOR_EXPORT CCssCalculator
|
||||
{
|
||||
protected:
|
||||
CCssCalculator_Private* m_pInternal;
|
||||
public:
|
||||
CCssCalculator();
|
||||
~CCssCalculator();
|
||||
|
||||
CCompiledStyle GetCompiledStyle(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);
|
||||
void AddStyles (const std::wstring& sStyle);
|
||||
void AddStylesFromFile(const std::wstring& sFileName);
|
||||
// void AddStyle(const std::vector<std::string>& sSelectors, const std::string& sStyle);
|
||||
void AddStyles (const std::string& sStyle);
|
||||
void AddStyles (const std::wstring& wsStyle);
|
||||
void AddStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(const unsigned short int& nValue);
|
||||
void SetBodyTree(const CTree &oTree);
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(const 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();
|
||||
};
|
||||
void Clear();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CCSSCALCULATOR_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -3,74 +3,86 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "CCssCalculator.h"
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include "CElement.h"
|
||||
#include "ConstValues.h"
|
||||
#include "CUnitMeasureConverter.h"
|
||||
#include "../../katana-parser/src/katana.h"
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
#include "CCompiledStyle.h"
|
||||
#endif
|
||||
|
||||
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;
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::map<std::vector<CNode>, CCompiledStyle*> m_mUsedStyles;
|
||||
#endif
|
||||
|
||||
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);
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
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);
|
||||
#endif
|
||||
|
||||
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& wsStyle);
|
||||
void AddStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
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
|
||||
|
||||
@ -6,275 +6,245 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CElement::CElement()
|
||||
{
|
||||
}
|
||||
CElement::~CElement()
|
||||
{
|
||||
for (CElement* oElement : m_arPrevElements)
|
||||
if (oElement != NULL)
|
||||
delete oElement;
|
||||
else
|
||||
continue;
|
||||
CElement::CElement()
|
||||
{
|
||||
}
|
||||
CElement::~CElement()
|
||||
{
|
||||
for (CElement* oElement : m_arPrevElements)
|
||||
if (oElement != NULL)
|
||||
delete oElement;
|
||||
else
|
||||
continue;
|
||||
|
||||
m_mStyle.clear();
|
||||
m_mStyle.clear();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring CElement::GetSelector() const
|
||||
{
|
||||
return m_sSelector;
|
||||
}
|
||||
std::wstring CElement::GetSelector() const
|
||||
{
|
||||
return m_sSelector;
|
||||
}
|
||||
|
||||
std::wstring CElement::GetFullSelector() const
|
||||
{
|
||||
return m_sFullSelector;
|
||||
}
|
||||
std::wstring CElement::GetFullSelector() const
|
||||
{
|
||||
return m_sFullSelector;
|
||||
}
|
||||
|
||||
bool CElement::Empty() const
|
||||
{
|
||||
return m_mStyle.empty();
|
||||
}
|
||||
bool CElement::Empty() const
|
||||
{
|
||||
return m_mStyle.empty();
|
||||
}
|
||||
|
||||
void CElement::SetSelector(const std::wstring &sSelector)
|
||||
{
|
||||
m_sSelector = sSelector;
|
||||
m_sFullSelector = m_sSelector;
|
||||
}
|
||||
void CElement::SetSelector(const std::wstring &sSelector)
|
||||
{
|
||||
m_sSelector = sSelector;
|
||||
m_sFullSelector = m_sSelector;
|
||||
}
|
||||
|
||||
void NSCSS::CElement::AddPropertie(const std::wstring &sName, const std::wstring& sValue)
|
||||
{
|
||||
m_mStyle[sName] = sValue;
|
||||
}
|
||||
void NSCSS::CElement::AddPropertie(const std::wstring &sName, const std::wstring& sValue)
|
||||
{
|
||||
m_mStyle[sName] = sValue;
|
||||
}
|
||||
|
||||
void CElement::AddProperties(const std::map<std::wstring, std::wstring>& mProperties)
|
||||
{
|
||||
for (std::pair<std::wstring, std::wstring> pPropertie : mProperties)
|
||||
{
|
||||
std::transform(pPropertie.first.begin(), pPropertie.first.end(), pPropertie.first.begin(), tolower);
|
||||
std::transform(pPropertie.second.begin(), pPropertie.second.end(), pPropertie.second.begin(), tolower);
|
||||
void CElement::AddProperties(const std::map<std::wstring, std::wstring>& mProperties)
|
||||
{
|
||||
for (std::pair<std::wstring, std::wstring> pPropertie : mProperties)
|
||||
{
|
||||
std::transform(pPropertie.first.begin(), pPropertie.first.end(), pPropertie.first.begin(), tolower);
|
||||
|
||||
if (!m_mStyle[pPropertie.first].empty() && m_mStyle[pPropertie.first].find(L'!') != std::wstring::npos)
|
||||
continue;
|
||||
if (!m_mStyle[pPropertie.first].empty() && m_mStyle[pPropertie.first].find(L'!') != std::wstring::npos)
|
||||
continue;
|
||||
|
||||
if (pPropertie.second.substr(0, 3) == L"rgb")
|
||||
m_mStyle[pPropertie.first] = NSCSS::NS_STATIC_FUNCTIONS::ConvertRgbToHex(pPropertie.second);
|
||||
else
|
||||
m_mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
m_mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
|
||||
void CElement::AddPrevElement(CElement *oPrevElement)
|
||||
{
|
||||
if (NULL == oPrevElement)
|
||||
return;
|
||||
void CElement::AddPrevElement(CElement *oPrevElement)
|
||||
{
|
||||
if (NULL == oPrevElement)
|
||||
return;
|
||||
|
||||
m_arPrevElements.push_back(oPrevElement);
|
||||
oPrevElement->m_sFullSelector += L' ' + m_sFullSelector;
|
||||
}
|
||||
m_arPrevElements.push_back(oPrevElement);
|
||||
oPrevElement->m_sFullSelector += L' ' + m_sFullSelector;
|
||||
}
|
||||
|
||||
void CElement::AddKinElement(CElement *oKinElement)
|
||||
{
|
||||
if (NULL == oKinElement)
|
||||
return;
|
||||
void CElement::AddKinElement(CElement *oKinElement)
|
||||
{
|
||||
if (NULL == oKinElement)
|
||||
return;
|
||||
|
||||
m_arKinElements.push_back(oKinElement);
|
||||
oKinElement->m_sFullSelector += m_sFullSelector;
|
||||
}
|
||||
m_arKinElements.push_back(oKinElement);
|
||||
oKinElement->m_sFullSelector += m_sFullSelector;
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> CElement::GetStyle() const
|
||||
{
|
||||
return m_mStyle;
|
||||
}
|
||||
std::map<std::wstring, std::wstring> CElement::GetStyle() const
|
||||
{
|
||||
return m_mStyle;
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> CElement::GetFullStyle(const std::vector<CNode>& arSelectors) const
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return std::map<std::wstring, std::wstring>();
|
||||
std::map<std::wstring, std::wstring> CElement::GetFullStyle(const std::vector<CNode>& arSelectors) const
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return std::map<std::wstring, std::wstring>();
|
||||
|
||||
std::map<std::wstring, std::wstring> mStyle(m_mStyle);
|
||||
std::map<std::wstring, std::wstring> mStyle(m_mStyle);
|
||||
|
||||
// Print();
|
||||
// std::wcout << L"++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||||
|
||||
for (const CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
|
||||
{
|
||||
std::map<std::wstring, std::wstring> mTempStyle;
|
||||
if (oElement->GetSelector() == L'.' + oNode->m_sClass ||
|
||||
oElement->GetSelector() == oNode->m_sName)
|
||||
{
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(arSelectors))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
for (const CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
|
||||
{
|
||||
std::map<std::wstring, std::wstring> mTempStyle;
|
||||
if (oElement->GetSelector() == L'.' + oNode->m_wsClass ||
|
||||
oElement->GetSelector() == oNode->m_wsName)
|
||||
{
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(arSelectors))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
// const std::map<std::wstring, std::wstring> mTempStyle = oElement->GetFullStyle(arSelectors);
|
||||
// mStyle.insert(mTempStyle.begin(), mTempStyle.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mStyle;
|
||||
}
|
||||
return mStyle;
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> CElement::GetFullStyle(const std::vector<std::wstring> &arNodes) const
|
||||
{
|
||||
if (arNodes.empty() || (m_mStyle.empty() && m_arPrevElements.empty()))
|
||||
return std::map<std::wstring, std::wstring>();
|
||||
std::map<std::wstring, std::wstring> CElement::GetFullStyle(const std::vector<std::wstring> &arNodes) const
|
||||
{
|
||||
if (arNodes.empty() || (m_mStyle.empty() && m_arPrevElements.empty()))
|
||||
return std::map<std::wstring, std::wstring>();
|
||||
|
||||
std::map<std::wstring, std::wstring> mStyle(m_mStyle);
|
||||
std::map<std::wstring, std::wstring> mStyle(m_mStyle);
|
||||
|
||||
for (const CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
for (std::vector<std::wstring>::const_reverse_iterator sNode = arNodes.rbegin(); sNode != arNodes.rend(); ++sNode)
|
||||
{
|
||||
if ((*sNode)[0] == L'.')
|
||||
{
|
||||
for (const std::wstring& sClass : NS_STATIC_FUNCTIONS::GetWordsW(*sNode, L" "))
|
||||
{
|
||||
if (oElement->GetSelector() == sClass)
|
||||
{
|
||||
std::vector<std::wstring> sTempNodes = arNodes;
|
||||
sTempNodes.pop_back();
|
||||
for (const CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
for (std::vector<std::wstring>::const_reverse_iterator sNode = arNodes.rbegin(); sNode != arNodes.rend(); ++sNode)
|
||||
{
|
||||
if ((*sNode)[0] == L'.')
|
||||
{
|
||||
for (const std::wstring& sClass : NS_STATIC_FUNCTIONS::GetWordsW(*sNode, false, L" "))
|
||||
{
|
||||
if (oElement->GetSelector() == sClass)
|
||||
{
|
||||
std::vector<std::wstring> sTempNodes = arNodes;
|
||||
sTempNodes.pop_back();
|
||||
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(sTempNodes))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (oElement->GetSelector() == *sNode)
|
||||
{
|
||||
std::vector<std::wstring> sTempNodes = arNodes;
|
||||
sTempNodes.pop_back();
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(sTempNodes))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(sTempNodes))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (oElement->GetSelector() == *sNode)
|
||||
{
|
||||
std::vector<std::wstring> sTempNodes = arNodes;
|
||||
sTempNodes.pop_back();
|
||||
for (const std::pair<std::wstring, std::wstring> pPropertie : oElement->GetFullStyle(sTempNodes))
|
||||
mStyle[pPropertie.first] = pPropertie.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mStyle;
|
||||
}
|
||||
return mStyle;
|
||||
}
|
||||
|
||||
std::vector<CElement *> CElement::GetNextOfKin(const std::wstring &sName, const std::vector<std::wstring>& arClasses) const
|
||||
{
|
||||
if (m_arKinElements.empty())
|
||||
return std::vector<CElement*>();
|
||||
std::vector<CElement *> CElement::GetNextOfKin(const std::wstring &sName, const std::vector<std::wstring>& arClasses) const
|
||||
{
|
||||
if (m_arKinElements.empty())
|
||||
return std::vector<CElement*>();
|
||||
|
||||
std::vector<CElement*> arElements;
|
||||
for (CElement* oElement : m_arKinElements)
|
||||
{
|
||||
if (!sName.empty() && oElement->m_sSelector == sName)
|
||||
{
|
||||
arElements.push_back(oElement);
|
||||
continue;
|
||||
}
|
||||
std::vector<CElement*> arElements;
|
||||
for (CElement* oElement : m_arKinElements)
|
||||
{
|
||||
if (!sName.empty() && oElement->m_sSelector == sName)
|
||||
{
|
||||
arElements.push_back(oElement);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const std::wstring& sClass : arClasses)
|
||||
{
|
||||
if (oElement->m_sSelector == sClass)
|
||||
arElements.push_back(oElement);
|
||||
}
|
||||
}
|
||||
return arElements;
|
||||
}
|
||||
for (const std::wstring& sClass : arClasses)
|
||||
{
|
||||
if (oElement->m_sSelector == sClass)
|
||||
arElements.push_back(oElement);
|
||||
}
|
||||
}
|
||||
return arElements;
|
||||
}
|
||||
|
||||
std::vector<CElement *> CElement::GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const
|
||||
{
|
||||
if (arNodesRBegin >= arNodesREnd || m_arPrevElements.empty())
|
||||
return std::vector<CElement*>();
|
||||
std::vector<CElement *> CElement::GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const
|
||||
{
|
||||
if (arNodesRBegin >= arNodesREnd || m_arPrevElements.empty())
|
||||
return std::vector<CElement*>();
|
||||
|
||||
std::vector<CElement*> arElements;
|
||||
std::vector<CElement*> arElements;
|
||||
|
||||
for (std::vector<std::wstring>::reverse_iterator iWord = arNodesRBegin; iWord != arNodesREnd; ++iWord)
|
||||
{
|
||||
if ((*arNodesRBegin) == L".module_title")
|
||||
std::wcout << *iWord << std::endl;
|
||||
if ((*iWord)[0] == L'.' && ((*iWord).find(L" ") != std::wstring::npos))
|
||||
{
|
||||
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(*iWord, L" ");
|
||||
for (std::wstring sClass : arClasses)
|
||||
{
|
||||
for (CElement* oPrevElement : m_arPrevElements)
|
||||
{
|
||||
if (oPrevElement->m_sSelector == sClass)
|
||||
{
|
||||
arElements.push_back(oPrevElement);
|
||||
std::vector<CElement*> arTempElements = oPrevElement->GetPrevElements(iWord + 1, arNodesREnd);
|
||||
arElements.insert(arElements.end(), arTempElements.begin(), arTempElements.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (CElement* oPrevElement : m_arPrevElements)
|
||||
{
|
||||
if (oPrevElement->m_sSelector == *iWord)
|
||||
{
|
||||
arElements.push_back(oPrevElement);
|
||||
std::vector<CElement*> arTempElements = oPrevElement->GetPrevElements(iWord + 1, arNodesREnd);
|
||||
arElements.insert(arElements.end(), arTempElements.begin(), arTempElements.end());
|
||||
// return arElements;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (std::vector<std::wstring>::reverse_iterator iWord = arNodesRBegin; iWord != arNodesREnd; ++iWord)
|
||||
{
|
||||
if ((*iWord)[0] == L'.' && ((*iWord).find(L" ") != std::wstring::npos))
|
||||
{
|
||||
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(*iWord, false, L" ");
|
||||
for (std::wstring sClass : arClasses)
|
||||
{
|
||||
for (CElement* oPrevElement : m_arPrevElements)
|
||||
{
|
||||
if (oPrevElement->m_sSelector == sClass)
|
||||
{
|
||||
arElements.push_back(oPrevElement);
|
||||
std::vector<CElement*> arTempElements = oPrevElement->GetPrevElements(iWord + 1, arNodesREnd);
|
||||
arElements.insert(arElements.end(), arTempElements.begin(), arTempElements.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (CElement* oPrevElement : m_arPrevElements)
|
||||
{
|
||||
if (oPrevElement->m_sSelector == *iWord)
|
||||
{
|
||||
arElements.push_back(oPrevElement);
|
||||
std::vector<CElement*> arTempElements = oPrevElement->GetPrevElements(iWord + 1, arNodesREnd);
|
||||
arElements.insert(arElements.end(), arTempElements.begin(), arTempElements.end());
|
||||
// return arElements;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return arElements;
|
||||
return arElements;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CElement *CElement::FindPrevElement(const std::wstring &sSelector) const
|
||||
{
|
||||
if (sSelector.empty())
|
||||
return NULL;
|
||||
CElement *CElement::FindPrevElement(const std::wstring &sSelector) const
|
||||
{
|
||||
if (sSelector.empty())
|
||||
return NULL;
|
||||
|
||||
for (CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
if (oElement->m_sSelector == sSelector)
|
||||
return oElement;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
for (CElement* oElement : m_arPrevElements)
|
||||
{
|
||||
if (oElement->m_sSelector == sSelector)
|
||||
return oElement;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::vector<unsigned short> CElement::GetWeight()
|
||||
{
|
||||
if (m_arWeight.empty())
|
||||
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
|
||||
std::vector<unsigned short> CElement::GetWeight()
|
||||
{
|
||||
if (m_arWeight.empty())
|
||||
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
|
||||
|
||||
return m_arWeight;
|
||||
}
|
||||
|
||||
void CElement::IncreasedWeight()
|
||||
{
|
||||
if (!m_arWeight.empty())
|
||||
{
|
||||
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
|
||||
++m_arWeight[3];
|
||||
}
|
||||
}
|
||||
|
||||
void CElement::Print() const
|
||||
{
|
||||
std::wcout << L"Selector: " << m_sSelector << std::endl;
|
||||
std::wcout << L"Full Selector: " << m_sFullSelector << std::endl;
|
||||
std::wcout << L"===========STYLE(" << m_mStyle.size() << ")===========" << std::endl;
|
||||
for (const std::pair<std::wstring, std::wstring> oPropertie : m_mStyle)
|
||||
std::wcout << oPropertie.first << L" - " << oPropertie.second << std::endl;
|
||||
std::wcout << L"===========================" << std::endl;
|
||||
|
||||
std::wcout << m_arKinElements.size() << L" --- " << m_arPrevElements.size() << std::endl;
|
||||
|
||||
if (!m_arKinElements.empty())
|
||||
{
|
||||
std::wcout << L"\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/" << std::endl;
|
||||
for (CElement* oElement : m_arKinElements)
|
||||
oElement->Print();
|
||||
std::wcout << L"/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\" << std::endl;
|
||||
}
|
||||
for (CElement* oElement : m_arPrevElements)
|
||||
oElement->Print();
|
||||
|
||||
}
|
||||
return m_arWeight;
|
||||
}
|
||||
|
||||
void CElement::IncreasedWeight()
|
||||
{
|
||||
if (!m_arWeight.empty())
|
||||
{
|
||||
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
|
||||
++m_arWeight[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,51 +3,50 @@
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "CCssCalculator.h"
|
||||
#include <string>
|
||||
#include "CNode.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CElement
|
||||
{
|
||||
std::map<std::wstring, std::wstring> m_mStyle;
|
||||
class CElement
|
||||
{
|
||||
std::map<std::wstring, std::wstring> m_mStyle;
|
||||
|
||||
std::vector<CElement*> m_arPrevElements;
|
||||
std::vector<CElement*> m_arKinElements;
|
||||
std::vector<CElement*> m_arPrevElements;
|
||||
std::vector<CElement*> m_arKinElements;
|
||||
|
||||
std::wstring m_sSelector;
|
||||
std::wstring m_sFullSelector;
|
||||
std::wstring m_sSelector;
|
||||
std::wstring m_sFullSelector;
|
||||
|
||||
std::vector<unsigned short int> m_arWeight;
|
||||
std::vector<unsigned short int> m_arWeight;
|
||||
|
||||
public:
|
||||
CElement();
|
||||
~CElement();
|
||||
public:
|
||||
CElement();
|
||||
~CElement();
|
||||
|
||||
std::wstring GetSelector() const;
|
||||
std::wstring GetFullSelector() const;
|
||||
std::wstring GetSelector() const;
|
||||
std::wstring GetFullSelector() const;
|
||||
|
||||
bool Empty() const;
|
||||
bool Empty() const;
|
||||
|
||||
void SetSelector(const std::wstring& sSelector);
|
||||
void AddPropertie(const std::wstring& sName, const std::wstring& sValue);
|
||||
void AddProperties(const std::map<std::wstring, std::wstring>& mProperties);
|
||||
void AddPrevElement(CElement* oPrevElement);
|
||||
void AddKinElement(CElement* oKinElement);
|
||||
void SetSelector(const std::wstring& sSelector);
|
||||
void AddPropertie(const std::wstring& sName, const std::wstring& sValue);
|
||||
void AddProperties(const std::map<std::wstring, std::wstring>& mProperties);
|
||||
void AddPrevElement(CElement* oPrevElement);
|
||||
void AddKinElement(CElement* oKinElement);
|
||||
|
||||
std::map<std::wstring, std::wstring> GetStyle() const;
|
||||
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<CNode>& arSelectors) const;
|
||||
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<std::wstring>& arNodes) const;
|
||||
std::vector<CElement *> GetNextOfKin(const std::wstring& sName, const std::vector<std::wstring>& arClasses = {}) const;
|
||||
std::vector<CElement *> GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const;
|
||||
std::map<std::wstring, std::wstring> GetConvertStyle(const std::vector<CNode>& arNodes) const;
|
||||
std::map<std::wstring, std::wstring> GetStyle() const;
|
||||
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<CNode>& arSelectors) const;
|
||||
std::map<std::wstring, std::wstring> GetFullStyle(const std::vector<std::wstring>& arNodes) const;
|
||||
std::vector<CElement *> GetNextOfKin(const std::wstring& sName, const std::vector<std::wstring>& arClasses = {}) const;
|
||||
std::vector<CElement *> GetPrevElements(const std::vector<std::wstring>::reverse_iterator &arNodesRBegin, const std::vector<std::wstring>::reverse_iterator &arNodesREnd) const;
|
||||
std::map<std::wstring, std::wstring> GetConvertStyle(const std::vector<CNode>& arNodes) const;
|
||||
|
||||
CElement *FindPrevElement(const std::wstring& sSelector) const;
|
||||
CElement *FindPrevElement(const std::wstring& sSelector) const;
|
||||
|
||||
std::vector<unsigned short int> GetWeight();
|
||||
void IncreasedWeight();
|
||||
|
||||
void Print() const;
|
||||
};
|
||||
std::vector<unsigned short int> GetWeight();
|
||||
void IncreasedWeight();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
55
Common/3dParty/html/css/src/CNode.cpp
Normal file
55
Common/3dParty/html/css/src/CNode.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "CNode.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CNode::CNode()
|
||||
{}
|
||||
|
||||
CNode::CNode(std::wstring wsName, std::wstring wsClass, std::wstring wsId)
|
||||
: m_wsName(wsName), m_wsClass(wsClass), m_wsId(wsId)
|
||||
{}
|
||||
|
||||
bool CNode::Empty() const
|
||||
{
|
||||
return m_wsName.empty() && m_wsClass.empty() && m_wsId.empty() && m_wsStyle.empty();
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CNode::GetData() const
|
||||
{
|
||||
std::vector<std::wstring> arValues;
|
||||
if (!m_wsClass.empty())
|
||||
arValues.push_back(m_wsClass);
|
||||
if (!m_wsName.empty())
|
||||
arValues.push_back(m_wsName);
|
||||
return arValues;
|
||||
}
|
||||
|
||||
bool CNode::operator<(const CNode& oNode) const
|
||||
{
|
||||
if(m_wsName != oNode.m_wsName)
|
||||
return m_wsName < oNode.m_wsName;
|
||||
|
||||
if(m_wsClass != oNode.m_wsClass)
|
||||
return m_wsClass < oNode.m_wsClass;
|
||||
|
||||
if(m_wsId != oNode.m_wsId)
|
||||
return m_wsId < oNode.m_wsId;
|
||||
|
||||
if(m_wsStyle != oNode.m_wsStyle)
|
||||
return m_wsStyle < oNode.m_wsStyle;
|
||||
|
||||
if (m_mAttributes != oNode.m_mAttributes)
|
||||
return m_mAttributes < oNode.m_mAttributes;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNode::operator==(const CNode& oNode) const
|
||||
{
|
||||
return((m_wsId == oNode.m_wsId) &&
|
||||
(m_wsName == oNode.m_wsName) &&
|
||||
(m_wsClass == oNode.m_wsClass) &&
|
||||
(m_wsStyle == oNode.m_wsStyle) &&
|
||||
(m_mAttributes == oNode.m_mAttributes));
|
||||
}
|
||||
}
|
||||
@ -7,57 +7,25 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
struct CNode
|
||||
{
|
||||
std::wstring m_sName; // Имя тэга
|
||||
std::wstring m_sClass; // Класс тэга
|
||||
std::wstring m_sId; // Id тэга
|
||||
std::wstring m_sStyle; // Стиль тэга
|
||||
std::map<std::wstring, std::wstring> m_mAttrs; // Остальные аттрибуты тэга
|
||||
class CNode
|
||||
{
|
||||
public:
|
||||
std::wstring m_wsName; // Имя тэга
|
||||
std::wstring m_wsClass; // Класс тэга
|
||||
std::wstring m_wsId; // Id тэга
|
||||
std::wstring m_wsStyle; // Стиль тэга
|
||||
std::map<std::wstring, std::wstring> m_mAttributes; // Остальные аттрибуты тэга
|
||||
|
||||
CNode(){};
|
||||
CNode(std::wstring sName, std::wstring sClass, std::wstring sId) : m_sName(sName), m_sClass(sClass), m_sId(sId){};
|
||||
public:
|
||||
CNode();
|
||||
CNode(std::wstring wsName, std::wstring wsClass, std::wstring wsId);
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return m_sName.empty() && m_sClass.empty() && m_sId.empty() && m_sStyle.empty();
|
||||
}
|
||||
bool Empty() const;
|
||||
|
||||
std::vector<std::wstring> GetData() const
|
||||
{
|
||||
std::vector<std::wstring> arValues;
|
||||
if (!m_sClass.empty())
|
||||
arValues.push_back(m_sClass);
|
||||
if (!m_sName.empty())
|
||||
arValues.push_back(m_sName);
|
||||
return arValues;
|
||||
}
|
||||
|
||||
bool operator< (const CNode& oNode) const
|
||||
{
|
||||
if(m_sName != oNode.m_sName)
|
||||
return m_sName < oNode.m_sName;
|
||||
|
||||
if(m_sClass != oNode.m_sClass)
|
||||
return m_sClass < oNode.m_sClass;
|
||||
|
||||
if(m_sId != oNode.m_sId)
|
||||
return m_sId < oNode.m_sId;
|
||||
|
||||
if(m_sStyle != oNode.m_sStyle)
|
||||
return m_sStyle < oNode.m_sStyle;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator== (const CNode& oNode) const
|
||||
{
|
||||
return((m_sId == oNode.m_sId) &&
|
||||
(m_sName == oNode.m_sName) &&
|
||||
(m_sClass == oNode.m_sClass) &&
|
||||
(m_sStyle == oNode.m_sStyle));
|
||||
}
|
||||
};
|
||||
std::vector<std::wstring> GetData() const;
|
||||
bool operator< (const CNode& oNode) const;
|
||||
bool operator== (const CNode& oNode) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CNODE_H
|
||||
|
||||
178
Common/3dParty/html/css/src/CUnitMeasureConverter.cpp
Normal file
178
Common/3dParty/html/css/src/CUnitMeasureConverter.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
#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.;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
35
Common/3dParty/html/css/src/CUnitMeasureConverter.h
Normal file
35
Common/3dParty/html/css/src/CUnitMeasureConverter.h
Normal file
@ -0,0 +1,35 @@
|
||||
#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 bool GetValue(const std::wstring& wsValue, double& dValue, UnitMeasure& enUnitMeasure);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CUNITMEASURECONVERTER_H
|
||||
182
Common/3dParty/html/css/src/ConstValues.cpp
Normal file
182
Common/3dParty/html/css/src/ConstValues.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
#include "ConstValues.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CSizeWindow::CSizeWindow()
|
||||
: m_ushWidth(0), m_ushHeight(0)
|
||||
{}
|
||||
|
||||
CSizeWindow::CSizeWindow(unsigned short unWidth, unsigned short unHeight)
|
||||
: m_ushWidth(unWidth), m_ushHeight(unHeight)
|
||||
{}
|
||||
|
||||
bool CSizeWindow::Empty() const
|
||||
{
|
||||
return ((0 == m_ushWidth) && (0 == m_ushHeight));
|
||||
}
|
||||
|
||||
void CSizeWindow::Clear()
|
||||
{
|
||||
m_ushWidth = m_ushHeight = 0;
|
||||
}
|
||||
|
||||
bool CSizeWindow::operator==(const CSizeWindow &oSizeWindow) const
|
||||
{
|
||||
return ((m_ushWidth == oSizeWindow.m_ushWidth) && (m_ushHeight == oSizeWindow.m_ushHeight));
|
||||
}
|
||||
|
||||
bool CSizeWindow::operator!=(const CSizeWindow &oSizeWindow) const
|
||||
{
|
||||
return ((m_ushWidth != oSizeWindow.m_ushWidth) || (m_ushHeight != oSizeWindow.m_ushHeight));
|
||||
}
|
||||
|
||||
bool StatistickElement::operator<(const StatistickElement &oStatistickElement) const
|
||||
{
|
||||
return sValue < oStatistickElement.sValue;
|
||||
}
|
||||
|
||||
void CTree::CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics)
|
||||
{
|
||||
if (!oTree.m_oNode.m_wsId.empty())
|
||||
++mStatictics[StatistickElement{StatistickElement::IsId, L'#' + oTree.m_oNode.m_wsId}];
|
||||
if (!oTree.m_oNode.m_wsStyle.empty())
|
||||
++mStatictics[StatistickElement{StatistickElement::IsStyle, oTree.m_oNode.m_wsStyle}];
|
||||
|
||||
if (!oTree.m_arrChild.empty())
|
||||
for (const CTree& oChildren : oTree.m_arrChild)
|
||||
CountingNumberRepetitions(oChildren, mStatictics);
|
||||
}
|
||||
|
||||
namespace NSConstValues
|
||||
{
|
||||
const std::map<std::wstring, std::wstring> COLORS
|
||||
{
|
||||
/* Red tones */
|
||||
{L"indianeed", L"CD5C5C"}, {L"lightcoral", L"F08080"}, {L"salmon", L"FA8072"},
|
||||
{L"darksalmon", L"E9967A"}, {L"lightsalmon", L"FFA07A"}, {L"crimson", L"DC143C"},
|
||||
{L"red", L"FF0000"}, {L"firebrick", L"B22222"}, {L"darkred", L"8B0000"},
|
||||
/* Pink tones */
|
||||
{L"pink", L"FFC0CB"}, {L"lightpink", L"FFB6C1"}, {L"hotpink", L"FF69B4"},
|
||||
{L"deeppink", L"FF1493"}, {L"mediumvioletred", L"C71585"}, {L"palevioleteed", L"DB7093"},
|
||||
/* Orange tones */
|
||||
{L"lightsalmon", L"FFA07A"}, {L"coral", L"FF7F50"}, {L"tomato", L"FF6347"},
|
||||
{L"orangered", L"FF4500"}, {L"darkorange", L"FF8C00"}, {L"orange", L"FFA500"},
|
||||
/* Yellow tones */
|
||||
{L"gold", L"FFD700"}, {L"yellow", L"FFFF00"}, {L"lightyellow", L"FFFFE0"},
|
||||
{L"lemonchiffon", L"FFFACD"}, {L"lightgoldenrodyellow", L"FAFAD2"}, {L"papayawhip", L"FFEFD5"},
|
||||
{L"moccasin", L"FFE4B5"}, {L"peachpuff", L"FFDAB9"}, {L"palegoldenrod", L"EEE8AA"},
|
||||
{L"khaki", L"F0E68C"}, {L"darkkhaki", L"BDB76B"},
|
||||
/* Purple tones */
|
||||
{L"lavender", L"E6E6FA"}, {L"thistle", L"D8BFD8"}, {L"plum", L"DDA0DD"},
|
||||
{L"violet", L"EE82EE"}, {L"orchid", L"DA70D6"}, {L"fuchsia", L"FF00FF"},
|
||||
{L"magenta", L"FF00FF"}, {L"mediumorchid", L"BA55D3"}, {L"mediumpurple", L"9370DB"},
|
||||
{L"blueviolet", L"8A2BE2"}, {L"darkviolet", L"9400D3"}, {L"darkorchid", L"9932CC"},
|
||||
{L"darkmagenta", L"8B008B"}, {L"purple", L"800080"}, {L"indigo", L"4B0082"},
|
||||
{L"slateblue", L"6A5ACD"}, {L"darkslateblue", L"483D8B"},
|
||||
/* Brown tones */
|
||||
{L"cornsilk", L"FFF8DC"}, {L"blanchedalmond", L"FFEBCD"}, {L"bisque", L"FFE4C4"},
|
||||
{L"navajowhite", L"FFDEAD"}, {L"wheat", L"F5DEB3"}, {L"burlywood", L"DEB887"},
|
||||
{L"tan", L"D2B48C"}, {L"rosybrown", L"BC8F8F"}, {L"sandybrown", L"F4A460"},
|
||||
{L"goldenrod", L"DAA520"}, {L"darkgoldenrod", L"B8860B"}, {L"peru", L"CD853F"},
|
||||
{L"chocolate", L"D2691E"}, {L"saddlebrown", L"8B4513"}, {L"sienna", L"A0522D"},
|
||||
{L"brown", L"A52A2A"}, {L"maroon", L"800000"},
|
||||
/* Green tones */
|
||||
{L"greenyellow", L"ADFF2F"}, {L"chartreuse", L"7FFF00"}, {L"lawngreen", L"7CFC00"},
|
||||
{L"lime", L"00FF00"}, {L"limegreen", L"32CD32"}, {L"palegreen", L"98FB98"},
|
||||
{L"lightgreen", L"90EE90"}, {L"mediumspringgreen", L"00FA9A"}, {L"springgreen", L"00FF7F"},
|
||||
{L"mediumseagreen", L"3CB371"}, {L"seagreen", L"2E8B57"}, {L"forestgreen", L"228B22"},
|
||||
{L"green", L"008000"}, {L"darkgreen", L"006400"}, {L"yellowgreen", L"9ACD32"},
|
||||
{L"olivedrab", L"6B8E23"}, {L"olive", L"808000"}, {L"darkolivegreen",L"556B2F"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
|
||||
{L"mediumaquamarine", L"66CDAA"}, {L"darkseagreen", L"8FBC8F"}, {L"lightseagreen", L"20B2AA"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
|
||||
{L"darkcyan", L"008B8B"}, {L"teal", L"008080"},
|
||||
/* Blue tones */
|
||||
{L"aqua", L"00FFFF"}, {L"cyan", L"00FFFF"}, {L"lightcyan", L"E0FFFF"},
|
||||
{L"paleturquoise", L"AFEEEE"}, {L"aquamarine", L"7FFFD4"}, {L"turquoise", L"40E0D0"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
|
||||
{L"mediumturquoise", L"48D1CC"}, {L"darkturquoise", L"00CED1"}, {L"cadetblue", L"5F9EA0"},
|
||||
{L"steelblue", L"4682B4"}, {L"lightsteelblue", L"B0C4DE"}, {L"powderblue", L"B0E0E6"},
|
||||
{L"lightblue", L"ADD8E6"}, {L"skyblue", L"87CEEB"}, {L"lightskyblue", L"87CEFA"},
|
||||
{L"deepskyblue", L"00BFFF"}, {L"dodgerblue", L"1E90FF"}, {L"cornflowerblue",L"6495ED"},
|
||||
{L"mediumdlateblue", L"7B68EE"}, {L"royalblue", L"4169E1"}, {L"blue", L"0000FF"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"}, {L"LightCoral", L"#F08080"},
|
||||
{L"mediumblue", L"0000CD"}, {L"darkblue", L"00008B"}, {L"navy", L"000080"},
|
||||
{L"midnightblue", L"191970"},
|
||||
/* White tones */
|
||||
{L"white", L"FFFFFF"}, {L"snow", L"FFFAFA"}, {L"honeydew", L"F0FFF0"},
|
||||
{L"mintcream", L"F5FFFA"}, {L"azure", L"F0FFFF"}, {L"aliceblue", L"F0F8FF"},
|
||||
{L"ghostwhite", L"F8F8FF"}, {L"whitesmoke", L"F5F5F5"}, {L"seashell", L"FFF5EE"},
|
||||
{L"beige", L"F5F5DC"}, {L"oldlace", L"FDF5E6"}, {L"floralwhite", L"FFFAF0"},
|
||||
{L"ivory", L"FFFFF0"}, {L"antiquewhite", L"FAEBD7"}, {L"linen", L"FAF0E6"},
|
||||
{L"lavenderblush", L"FFF0F5"}, {L"mistyrose", L"FFE4E1"},
|
||||
/* Gray tones */
|
||||
{L"gainsboro", L"DCDCDC"}, {L"lightgray", L"D3D3D3"}, {L"silver", L"C0C0C0"},
|
||||
{L"darkgray", L"A9A9A9"}, {L"gray", L"808080"}, {L"dimgray", L"696969"},
|
||||
{L"lightslategray", L"778899"}, {L"slategray", L"708090"}, {L"darkslategray", L"2F4F4F"},
|
||||
{L"black", L"000000"},
|
||||
/* Outdated */
|
||||
{L"windowtext", L"000000"}, {L"transparent", L"000000"}
|
||||
};
|
||||
|
||||
const std::vector<std::wstring> DISPLAY_VALUES
|
||||
{
|
||||
/* <display-outside> values */
|
||||
L"block", L"inline", L"run-in",
|
||||
/* <display-inside> values */
|
||||
L"flow", L"flow-root", L"table", L"flex", L"grid", L"ruby",
|
||||
/* <display-outside> plus <display-inside> values */
|
||||
L"block flow", L"inline table", L"flex run-in",
|
||||
/* <display-listitem> values */
|
||||
L"list-item", L"list-item block", L"list-item inline", L"list-item flow",
|
||||
L"list-item flow-root", L"list-item block flow",
|
||||
L"list-item block flow-root", L"flow list-item block",
|
||||
/* <display-internal> values */
|
||||
L"table-row-group", L"table-header-group", L"table-footer-group",
|
||||
L"table-row", L"table-cell", L"table-column-group", L"table-column",
|
||||
L"table-caption", L"ruby-base", L"ruby-text", L"ruby-base-container",
|
||||
L"ruby-text-container",
|
||||
/* <display-box> values */
|
||||
L"contents", L"none",
|
||||
/* <display-legacy> values */
|
||||
L"inline-block", L"inline-table", L"inline-flex", L"inline-grid",
|
||||
/* Global values */
|
||||
L"inherit", L"initial", L"unset"
|
||||
};
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
const std::wstring PSEUDO_CLASSES[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"
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
179
Common/3dParty/html/css/src/StaticFunctions.cpp
Normal file
179
Common/3dParty/html/css/src/StaticFunctions.cpp
Normal file
@ -0,0 +1,179 @@
|
||||
#include "StaticFunctions.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
namespace NS_STATIC_FUNCTIONS
|
||||
{
|
||||
std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding)
|
||||
{
|
||||
const std::string& sEnc = U_TO_UTF8(sEncoding);
|
||||
|
||||
NSUnicodeConverter::CUnicodeConverter oConverter;
|
||||
const std::wstring& sUnicodeContent = oConverter.toUnicode(sString, sEnc.c_str());
|
||||
return U_TO_UTF8(oConverter.toUnicode(sString, sEnc.c_str()));
|
||||
}
|
||||
|
||||
std::string GetContentAsUTF8(const std::wstring& sFileName)
|
||||
{
|
||||
std::string sContent;
|
||||
// читаем файл как есть. utf-8 тут просто название.
|
||||
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sFileName, sContent))
|
||||
return sContent;
|
||||
|
||||
std::string sEncoding;
|
||||
if (true)
|
||||
{
|
||||
// определяем кодировку
|
||||
const std::string::size_type& posCharset = sContent.find("@charset");
|
||||
|
||||
if (std::string::npos != posCharset)
|
||||
{
|
||||
std::string::size_type pos1 = sContent.find_first_of("\"';", posCharset);
|
||||
if (std::string::npos != pos1)
|
||||
{
|
||||
pos1 += 1;
|
||||
std::string::size_type pos2 = sContent.find_first_of("\"';", pos1);
|
||||
if (std::string::npos != pos2)
|
||||
{
|
||||
sEncoding = sContent.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
// check valid
|
||||
if (std::string::npos != sEncoding.find_first_of(" \n\r\t\f\v"))
|
||||
sEncoding = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sEncoding.empty())
|
||||
sEncoding = "utf-8";
|
||||
|
||||
|
||||
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
|
||||
{
|
||||
NSUnicodeConverter::CUnicodeConverter oConverter;
|
||||
sContent = U_TO_UTF8(oConverter.toUnicode(sContent, sEncoding.c_str()));
|
||||
}
|
||||
|
||||
return sContent;
|
||||
}
|
||||
|
||||
double ReadDouble(const std::wstring& wsValue)
|
||||
{
|
||||
double dValue;
|
||||
std::wistringstream(wsValue) >> dValue;
|
||||
return dValue;
|
||||
}
|
||||
|
||||
std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
|
||||
{
|
||||
std::vector<double> arValues;
|
||||
|
||||
std::wregex oPattern(LR"([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)");
|
||||
|
||||
std::wsregex_iterator oIter(wsValue.begin(), wsValue.end(), oPattern);
|
||||
std::wsregex_iterator oEndIter;
|
||||
|
||||
for (; oIter != oEndIter; ++oIter)
|
||||
arValues.push_back(std::stod(oIter->str()));
|
||||
|
||||
return arValues;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetWordsW(const std::wstring& wsLine, bool bWithSigns, const std::wstring& wsDelimiters)
|
||||
{
|
||||
if (wsLine.empty())
|
||||
return {};
|
||||
|
||||
size_t unEnd = wsLine.find_first_of(wsDelimiters);
|
||||
|
||||
if (std::wstring::npos == unEnd)
|
||||
return {wsLine};
|
||||
|
||||
size_t unStart = 0;
|
||||
std::vector<std::wstring> arWords;
|
||||
|
||||
while (std::wstring::npos != unEnd)
|
||||
{
|
||||
arWords.emplace_back(wsLine.data() + unStart, unEnd - unStart + ((bWithSigns) ? 1 : 0));
|
||||
unStart = wsLine.find_first_not_of(wsDelimiters, unEnd);
|
||||
unEnd = wsLine.find_first_of(wsDelimiters, unStart);
|
||||
}
|
||||
|
||||
arWords.emplace_back(wsLine.data() + unStart);
|
||||
|
||||
return arWords;
|
||||
}
|
||||
|
||||
std::vector<unsigned short int> GetWeightSelector(const std::wstring& wsSelector)
|
||||
{
|
||||
if (wsSelector.empty())
|
||||
return std::vector<unsigned short int>{0, 0, 0, 0};
|
||||
|
||||
std::vector<unsigned short int> arWeight = {0, 0, 0, 0};
|
||||
|
||||
std::wstring sReverseSelector = wsSelector;
|
||||
std::reverse(sReverseSelector.begin(), sReverseSelector.end());
|
||||
|
||||
const std::vector<std::wstring> arSelectors = NS_STATIC_FUNCTIONS::GetWordsW(sReverseSelector, true, L" .#:");
|
||||
|
||||
for (const std::wstring& sSel : arSelectors)
|
||||
{
|
||||
if (sSel == L"*")
|
||||
++arWeight[3];
|
||||
else if (sSel.rfind(L'#') != std::wstring::npos)
|
||||
++arWeight[0];
|
||||
else if (sSel.rfind(L':') != std::wstring::npos)
|
||||
{
|
||||
std::wstring sTemp(sSel);
|
||||
sTemp.erase(std::remove_if(sTemp.begin(), sTemp.end(), [] (const wchar_t& wc) { return !std::iswalpha(wc);}));
|
||||
// std::find(NSConstValues::arPseudoClasses.begin(), NSConstValues::arPseudoClasses.end(), sTemp) != NSConstValues::arPseudoClasses.end() ? ++arWeight[1] : ++arWeight[2];
|
||||
}
|
||||
else if (sSel.find_last_of(L".[]") != std::wstring::npos)
|
||||
++arWeight[1];
|
||||
else
|
||||
++arWeight[2];
|
||||
}
|
||||
|
||||
return arWeight;
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> GetRules(const std::wstring& wsStyles)
|
||||
{
|
||||
if (wsStyles.empty())
|
||||
return {};
|
||||
|
||||
std::map<std::wstring, std::wstring> mRules;
|
||||
|
||||
std::wstring::const_iterator oStartProperty = std::find_if_not(wsStyles.begin(), wsStyles.end(), std::iswspace);
|
||||
std::wstring::const_iterator oEndProperty, oStartValue, oEndValue;
|
||||
|
||||
while (wsStyles.end() != oStartProperty)
|
||||
{
|
||||
oEndProperty = std::find_if(oStartProperty, wsStyles.end(), [](const wchar_t &wcChar){ return L':' == wcChar;});
|
||||
oStartValue = std::find_if_not(oEndProperty + 1, wsStyles.end(), std::iswspace);
|
||||
|
||||
if (wsStyles.end() == oEndProperty || wsStyles.end() == oStartValue)
|
||||
break;
|
||||
|
||||
oEndValue = std::find_if(oStartValue, wsStyles.end(), [](const wchar_t &wcChar){ return L';' == wcChar;});
|
||||
|
||||
mRules.insert({std::wstring(oStartProperty, oEndProperty), std::wstring(oStartValue, oEndValue)});
|
||||
|
||||
if (wsStyles.end() == oEndValue)
|
||||
break;
|
||||
|
||||
oStartProperty = std::find_if_not(oEndValue + 1, wsStyles.end(), std::iswspace);
|
||||
}
|
||||
|
||||
return mRules;
|
||||
}
|
||||
|
||||
std::wstring RemoveSpaces(std::wstring &wsString)
|
||||
{
|
||||
std::wstring::const_iterator ciStart = std::find_if_not(wsString.begin(), wsString.end(), std::iswspace);
|
||||
std::wstring::const_reverse_iterator criEnd = std::find_if_not(wsString.rbegin(),wsString.rend(), std::iswspace);
|
||||
return std::wstring(ciStart, criEnd.base());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,466 +3,73 @@
|
||||
|
||||
#include "../../../../../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../../../../../DesktopEditor/common/File.h"
|
||||
#include "CNode.h"
|
||||
#include <algorithm>
|
||||
#include <cwctype>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <regex>
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
namespace NS_STATIC_FUNCTIONS
|
||||
{
|
||||
inline static std::wstring stringToWstring(const std::string& sString)
|
||||
{
|
||||
return UTF8_TO_U(sString);
|
||||
}
|
||||
namespace NS_STATIC_FUNCTIONS
|
||||
{
|
||||
std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding);
|
||||
std::string GetContentAsUTF8(const std::wstring& sFileName);
|
||||
|
||||
inline static std::string wstringToString(const std::wstring& sWstring)
|
||||
{
|
||||
return U_TO_UTF8(sWstring);
|
||||
}
|
||||
double ReadDouble(const std::wstring& wsValue);
|
||||
std::vector<double> ReadDoubleValues(const std::wstring& wsValue);
|
||||
|
||||
inline static std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding)
|
||||
{
|
||||
const std::string& sEnc = U_TO_UTF8(sEncoding);
|
||||
std::vector<std::wstring> GetWordsW(const std::wstring& wsLine, bool bWithSigns = false, const std::wstring& wsDelimiters = L" \n\r\t\f\v:;,!");
|
||||
std::vector<unsigned short int> GetWeightSelector(const std::wstring& sSelector);
|
||||
std::map<std::wstring, std::wstring> GetRules(const std::wstring& wsStyles);
|
||||
|
||||
NSUnicodeConverter::CUnicodeConverter oConverter;
|
||||
const std::wstring& sUnicodeContent = oConverter.toUnicode(sString, sEnc.c_str());
|
||||
return U_TO_UTF8(sUnicodeContent);
|
||||
}
|
||||
std::wstring RemoveSpaces(std::wstring& wsString);
|
||||
}
|
||||
|
||||
inline static std::string GetContentAsUTF8(const std::wstring& sFileName)
|
||||
{
|
||||
std::string sFileContent;
|
||||
#define SWITCH(str) switch(SWITCH_CASE::str_hash_for_switch(str))
|
||||
#define CASE(str) static_assert(SWITCH_CASE::str_is_correct(str) && (SWITCH_CASE::str_len(str) <= SWITCH_CASE::MAX_LEN),\
|
||||
"CASE string contains wrong characters, or its length is greater than 9");\
|
||||
case SWITCH_CASE::str_hash(str, SWITCH_CASE::str_len(str))
|
||||
#define DEFAULT default
|
||||
|
||||
// читаем файл как есть. utf-8 тут просто название.
|
||||
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sFileName, sFileContent))
|
||||
return sFileContent;
|
||||
namespace SWITCH_CASE
|
||||
{
|
||||
typedef unsigned long long ullong;
|
||||
|
||||
std::string sEncoding;
|
||||
if (true)
|
||||
{
|
||||
// определяем кодировку
|
||||
const std::string::size_type& posCharset = sFileContent.find("@charset");
|
||||
const unsigned int MAX_LEN = 32;
|
||||
const ullong N_HASH = static_cast<ullong>(-1);
|
||||
|
||||
if (std::string::npos != posCharset)
|
||||
{
|
||||
std::string::size_type pos1 = sFileContent.find_first_of("\"';", posCharset);
|
||||
if (std::string::npos != pos1)
|
||||
{
|
||||
pos1 += 1;
|
||||
std::string::size_type pos2 = sFileContent.find_first_of("\"';", pos1);
|
||||
if (std::string::npos != pos2)
|
||||
{
|
||||
sEncoding = sFileContent.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
// check valid
|
||||
if (std::string::npos != sEncoding.find_first_of(" \n\r\t\f\v"))
|
||||
sEncoding = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sEncoding.empty())
|
||||
sEncoding = "utf-8";
|
||||
|
||||
|
||||
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
|
||||
{
|
||||
NSUnicodeConverter::CUnicodeConverter oConverter;
|
||||
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
|
||||
}
|
||||
|
||||
return sFileContent;
|
||||
}
|
||||
|
||||
inline static bool NumberInWString(const std::wstring& sString)
|
||||
{
|
||||
if (sString.empty())
|
||||
return false;
|
||||
|
||||
size_t posDigit = sString.find_first_of(L"0123456789");
|
||||
// size_t posNoDigit = sString.find_first_not_of(L" \n\r\t\f\v123456789.");
|
||||
|
||||
if (posDigit != std::wstring::npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::wstring StripSymbols(const std::wstring& sValue, const std::wstring& sSymbols = L" \n\r\t\f\v")
|
||||
{
|
||||
if (sValue.empty())
|
||||
return std::wstring();
|
||||
|
||||
size_t start = sValue.find_first_not_of(sSymbols);
|
||||
if (std::wstring::npos == start)
|
||||
return sValue;
|
||||
|
||||
size_t end = sValue.find_last_not_of(sSymbols); // точно >=0
|
||||
return sValue.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> GetWords(const std::wstring& sLine)
|
||||
{
|
||||
if (sLine.empty())
|
||||
return {};
|
||||
|
||||
std::vector<std::string> arWords;
|
||||
arWords.reserve(16);
|
||||
const std::string sTemp = wstringToString(sLine);
|
||||
size_t posFirstNotSpace = sTemp.find_first_not_of(" \n\r\t\f\v:;,");
|
||||
while (posFirstNotSpace != std::wstring::npos)
|
||||
{
|
||||
const size_t& posLastNotSpace = sTemp.find_first_of(" \n\r\t\f\v:;,", posFirstNotSpace);
|
||||
arWords.push_back(sTemp.substr(posFirstNotSpace, posLastNotSpace - posFirstNotSpace));
|
||||
posFirstNotSpace = sTemp.find_first_not_of(" \n\r\t\f\v:;,", posLastNotSpace);
|
||||
}
|
||||
return arWords;
|
||||
}
|
||||
|
||||
inline std::vector<std::wstring> GetWordsW(const std::wstring& sLine, const std::wstring& sSigns = L" \n\r\t\f\v:;,")
|
||||
{
|
||||
if (sLine.empty())
|
||||
return {};
|
||||
|
||||
if (sLine.find_first_of(sSigns) == std::wstring::npos)
|
||||
return std::vector<std::wstring>({sLine});
|
||||
|
||||
std::vector<std::wstring> arWords;
|
||||
arWords.reserve(16);
|
||||
size_t posFirstNotSpace = sLine.find_first_not_of(sSigns);
|
||||
while (posFirstNotSpace != std::wstring::npos)
|
||||
{
|
||||
const size_t& posLastNotSpace = sLine.find_first_of(sSigns, posFirstNotSpace);
|
||||
arWords.push_back(sLine.substr(posFirstNotSpace, posLastNotSpace - posFirstNotSpace));
|
||||
posFirstNotSpace = sLine.find_first_not_of(sSigns, posLastNotSpace);
|
||||
}
|
||||
return arWords;
|
||||
}
|
||||
|
||||
inline bool ConvertAbsoluteValue(std::wstring& sAbsoluteValue, const float &unId)
|
||||
{
|
||||
if (sAbsoluteValue.empty())
|
||||
return false;
|
||||
|
||||
bool bIsConvert = false;
|
||||
|
||||
std::map<std::wstring, std::wstring> arAbsoluteFontValues = {{L"xx-small", L"9px"}, {L"x-small", L"10px"},
|
||||
{L"small", L"13px"}, {L"medium", L"16px"},
|
||||
{L"large", L"18px"}, {L"x-large", L"24px"},
|
||||
{L"xx-large", L"32px"}};
|
||||
|
||||
std::map<std::wstring, std::wstring> arAbsoluteBorderValues = {{L"thin", L"2px"},
|
||||
{L"medium", L"4px"},
|
||||
{L"thick", L"6px"}};
|
||||
|
||||
std::map<std::wstring, std::wstring> arAbsoluteValues = ((unId == 0.0f) ? arAbsoluteBorderValues : arAbsoluteFontValues);
|
||||
|
||||
|
||||
if (sAbsoluteValue.find(L' ') == std::wstring::npos && arAbsoluteValues.find(sAbsoluteValue) != arAbsoluteValues.end())
|
||||
{
|
||||
sAbsoluteValue = arAbsoluteValues[sAbsoluteValue];
|
||||
return true;
|
||||
}
|
||||
|
||||
std::wstring sValue;
|
||||
sValue.reserve(sAbsoluteValue.length() + 1);
|
||||
|
||||
for (const std::wstring& sWord : GetWordsW(sAbsoluteValue))
|
||||
{
|
||||
std::map<std::wstring, std::wstring>::iterator oFind = arAbsoluteValues.find(sWord);
|
||||
if (oFind != arAbsoluteValues.end())
|
||||
{
|
||||
bIsConvert = true;
|
||||
sValue += oFind->second + L' ';
|
||||
}
|
||||
else
|
||||
sValue += sWord + L' ';
|
||||
}
|
||||
sValue.pop_back();
|
||||
|
||||
if (bIsConvert)
|
||||
sAbsoluteValue = sValue;
|
||||
|
||||
return bIsConvert;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> GetSelectorsList(const std::wstring& sSelectors)
|
||||
{
|
||||
if (sSelectors.empty())
|
||||
return std::vector<std::string>();
|
||||
|
||||
std::wstring sNames = sSelectors;
|
||||
std::wstring sClasses;
|
||||
std::wstring sIds;
|
||||
|
||||
size_t posLattice = sNames.find(L"#");
|
||||
if (posLattice != std::wstring::npos)
|
||||
{
|
||||
sNames = sSelectors.substr(0, posLattice);
|
||||
sIds = sSelectors.substr(posLattice);
|
||||
}
|
||||
|
||||
size_t posPoint = sNames.find(L'.');
|
||||
if (posPoint != std::wstring::npos)
|
||||
{
|
||||
sNames = sSelectors.substr(0, posPoint);
|
||||
sClasses = sSelectors.substr(posPoint);
|
||||
posLattice = sClasses.find(L'#');
|
||||
if (posLattice != std::wstring::npos)
|
||||
sClasses = sClasses.substr(0, posLattice);
|
||||
}
|
||||
|
||||
std::vector<std::string> arNames = GetWords(sNames);
|
||||
std::vector<std::string> arClasses = GetWords(sClasses);
|
||||
std::vector<std::string> arIds = GetWords(sIds);
|
||||
std::vector<std::string> arSelectors(arNames);
|
||||
arSelectors.reserve(arNames.size() * arClasses.size() + arNames.size() * arIds.size() + arClasses.size() * arIds.size());
|
||||
|
||||
for (std::string& sClass : arClasses)
|
||||
{
|
||||
if (sClass.find('.') == std::string::npos)
|
||||
sClass = '.' + sClass;
|
||||
arSelectors.push_back(sClass);
|
||||
for (const std::string& sName : arNames)
|
||||
arSelectors.push_back(sName + sClass);
|
||||
for (const std::string& sId : arIds)
|
||||
arSelectors.push_back(sClass + sId);
|
||||
}
|
||||
for (std::string& sId : arIds)
|
||||
{
|
||||
if (sId.find('#') == std::string::npos)
|
||||
sId = '#' + sId;
|
||||
arSelectors.push_back(sId);
|
||||
for (const std::string& sName : arNames)
|
||||
arSelectors.push_back(sName + sId);
|
||||
}
|
||||
|
||||
return arSelectors;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> GetSelectorsListWithParents(const std::vector<CNode> &arParents)
|
||||
{
|
||||
if (arParents.size() < 2)
|
||||
return std::vector<std::string>();
|
||||
|
||||
if (arParents.back().m_sName.empty())
|
||||
return std::vector<std::string>();
|
||||
|
||||
std::vector<std::string> arSelectors;
|
||||
|
||||
short int nIndex = 0;
|
||||
|
||||
while (nIndex < static_cast<short int>(arParents.size() - 1))
|
||||
{
|
||||
std::wstring sSelector;
|
||||
|
||||
for (unsigned short int i = nIndex; i < arParents.size() - 1; ++i)
|
||||
{
|
||||
if (arParents[i].m_sName.empty())
|
||||
continue;
|
||||
|
||||
std::wstring sParentSelector = arParents[i].m_sName;
|
||||
if (!arParents[i].m_sClass.empty())
|
||||
sParentSelector += L'.' + arParents[i].m_sClass;
|
||||
if (!arParents[i].m_sId.empty())
|
||||
sParentSelector += L'#' + arParents[i].m_sId;
|
||||
|
||||
sSelector += sParentSelector + L' ';
|
||||
|
||||
}
|
||||
|
||||
std::wstring sChildrenSelector = arParents.back().m_sName;
|
||||
if (!arParents.back().m_sClass.empty())
|
||||
sChildrenSelector += L'.' + arParents.back().m_sClass;
|
||||
if (!arParents.back().m_sId.empty())
|
||||
sChildrenSelector += L'#' + arParents.back().m_sId;
|
||||
|
||||
sSelector += sChildrenSelector;
|
||||
++nIndex;
|
||||
arSelectors.push_back(wstringToString(sSelector));
|
||||
}
|
||||
|
||||
return arSelectors;
|
||||
}
|
||||
|
||||
inline std::vector<std::wstring> GetWordsWithSigns(const std::wstring& sLine, const std::wstring& sSigns = L" \n\r\t\f\v:;,")
|
||||
{
|
||||
if (sLine.empty())
|
||||
return {};
|
||||
|
||||
if (sLine.find_first_of(sSigns) == std::wstring::npos)
|
||||
return std::vector<std::wstring>({sLine});
|
||||
|
||||
std::vector<std::wstring> arWords;
|
||||
arWords.reserve(16);
|
||||
size_t posFirstNotSpace = sLine.find_first_not_of(sSigns);
|
||||
while (posFirstNotSpace != std::wstring::npos)
|
||||
{
|
||||
const size_t posLastNotSpace = sLine.find_first_of(sSigns, posFirstNotSpace);
|
||||
arWords.push_back(sLine.substr(posFirstNotSpace, (posLastNotSpace != std::wstring::npos) ? posLastNotSpace - posFirstNotSpace + 1 : posLastNotSpace - posFirstNotSpace ));
|
||||
posFirstNotSpace = sLine.find_first_not_of(sSigns, posLastNotSpace);
|
||||
}
|
||||
return arWords;
|
||||
}
|
||||
|
||||
inline bool IsDigit(const std::wstring& sValue)
|
||||
{
|
||||
return sValue.empty() ? false : std::all_of(sValue.begin(), sValue.end(), [] (const wchar_t& cChar) { return iswdigit(cChar); });
|
||||
}
|
||||
|
||||
inline std::wstring NormalizeRGB(const std::wstring& wsValue)
|
||||
constexpr ullong raise_128_to(const wchar_t power)
|
||||
{
|
||||
std::wstring wsNewValue = wsValue;
|
||||
|
||||
size_t unBegin = 0, unEnd;
|
||||
|
||||
while (std::wstring::npos != (unBegin = wsNewValue.find(L"rgb(", unBegin)))
|
||||
{
|
||||
unEnd = wsNewValue.find(L")", unBegin);
|
||||
|
||||
while ((unBegin = wsNewValue.find(L" ", unBegin)) != std::wstring::npos && unBegin < unEnd)
|
||||
{
|
||||
wsNewValue.replace(unBegin, 1, L",");
|
||||
++unBegin;
|
||||
}
|
||||
}
|
||||
|
||||
return wsNewValue;
|
||||
return (1ULL << 7) * power;
|
||||
}
|
||||
|
||||
inline std::wstring ConvertRgbToHex(const std::wstring& sRgbValue)
|
||||
{
|
||||
size_t posFirst = sRgbValue.find_first_of(L"01234567890");
|
||||
if (posFirst == std::wstring::npos)
|
||||
return std::wstring();
|
||||
constexpr bool str_is_correct(const wchar_t* const str)
|
||||
{
|
||||
return (static_cast<wchar_t>(*str) > 0) ? str_is_correct(str + 1) : (*str ? false : true);
|
||||
}
|
||||
|
||||
const wchar_t cHex[17]{L"0123456789abcdef"};
|
||||
constexpr unsigned int str_len(const wchar_t* const str)
|
||||
{
|
||||
return *str ? (1 + str_len(str + 1)) : 0;
|
||||
}
|
||||
|
||||
std::wstring sValue;
|
||||
constexpr ullong str_hash(const wchar_t* const str, const wchar_t current_len)
|
||||
{
|
||||
return *str ? (raise_128_to(current_len - 1) * static_cast<wchar_t>(*str) + str_hash(str + 1, current_len - 1)) : 0;
|
||||
}
|
||||
|
||||
while (posFirst != std::wstring::npos)
|
||||
{
|
||||
std::wstring sHex;
|
||||
inline ullong str_hash_for_switch(const wchar_t* const str)
|
||||
{
|
||||
return (str_is_correct(str) && (str_len(str) <= MAX_LEN)) ? str_hash(str, str_len(str)) : N_HASH;
|
||||
}
|
||||
|
||||
const size_t posSecond = sRgbValue.find_first_of(L", )", posFirst);
|
||||
|
||||
short int nValue = std::stoi(sRgbValue.substr(posFirst, posSecond - posFirst));
|
||||
|
||||
if (nValue < 0)
|
||||
sHex += L"00";
|
||||
else if (nValue > 255)
|
||||
sHex += L"ff";
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
sHex = cHex[nValue % 16] + sHex;
|
||||
nValue /= 16;
|
||||
}
|
||||
while (nValue != 0);
|
||||
}
|
||||
|
||||
if (sHex.length() < 2)
|
||||
sHex = L"0" + sHex;
|
||||
|
||||
sValue += sHex;
|
||||
|
||||
posFirst = sRgbValue.find_first_of(L"01234567890", posSecond);
|
||||
}
|
||||
return sValue;
|
||||
}
|
||||
|
||||
inline std::vector<unsigned short int> GetWeightSelector(const std::wstring& sSelector)
|
||||
{
|
||||
if (sSelector.empty())
|
||||
return std::vector<unsigned short int>{0, 0, 0, 0};
|
||||
|
||||
std::vector<unsigned short int> arWeight = {0, 0, 0, 0};
|
||||
|
||||
std::wstring sReverseSelector = sSelector;
|
||||
std::reverse(sReverseSelector.begin(), sReverseSelector.end());
|
||||
|
||||
const std::vector<std::wstring> arSelectors = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sReverseSelector, L" .#:");
|
||||
|
||||
for (const std::wstring& sSel : arSelectors)
|
||||
{
|
||||
if (sSel == L"*")
|
||||
++arWeight[3];
|
||||
else if (sSel.rfind(L'#') != std::wstring::npos)
|
||||
++arWeight[0];
|
||||
else if (sSel.rfind(L':') != std::wstring::npos)
|
||||
{
|
||||
std::wstring sTemp(sSel);
|
||||
sTemp.erase(std::remove_if(sTemp.begin(), sTemp.end(), [] (const wchar_t& wc) { return !std::iswalpha(wc);}));
|
||||
// std::find(NSConstValues::arPseudoClasses.begin(), NSConstValues::arPseudoClasses.end(), sTemp) != NSConstValues::arPseudoClasses.end() ? ++arWeight[1] : ++arWeight[2];
|
||||
}
|
||||
else if (sSel.find_last_of(L".[]") != std::wstring::npos)
|
||||
++arWeight[1];
|
||||
else
|
||||
++arWeight[2];
|
||||
}
|
||||
|
||||
return arWeight;
|
||||
}
|
||||
|
||||
inline bool IsTrue(const std::vector<bool> arValues)
|
||||
{
|
||||
for (const bool bValue : arValues)
|
||||
if (!bValue)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#define SWITCH(str) switch(SWITCH_CASE::str_hash_for_switch(str))
|
||||
#define CASE(str) static_assert(SWITCH_CASE::str_is_correct(str) && (SWITCH_CASE::str_len(str) <= SWITCH_CASE::MAX_LEN),\
|
||||
"CASE string contains wrong characters, or its length is greater than 9");\
|
||||
case SWITCH_CASE::str_hash(str, SWITCH_CASE::str_len(str))
|
||||
#define DEFAULT default
|
||||
|
||||
namespace SWITCH_CASE
|
||||
{
|
||||
typedef unsigned long long ullong;
|
||||
|
||||
const unsigned int MAX_LEN = 32;
|
||||
const ullong N_HASH = static_cast<ullong>(-1);
|
||||
|
||||
constexpr ullong raise_128_to(const wchar_t power)
|
||||
{
|
||||
return (1ULL << 7) * power;
|
||||
}
|
||||
|
||||
constexpr bool str_is_correct(const wchar_t* const str)
|
||||
{
|
||||
return (static_cast<wchar_t>(*str) > 0) ? str_is_correct(str + 1) : (*str ? false : true);
|
||||
}
|
||||
|
||||
constexpr unsigned int str_len(const wchar_t* const str)
|
||||
{
|
||||
return *str ? (1 + str_len(str + 1)) : 0;
|
||||
}
|
||||
|
||||
constexpr ullong str_hash(const wchar_t* const str, const wchar_t current_len)
|
||||
{
|
||||
return *str ? (raise_128_to(current_len - 1) * static_cast<wchar_t>(*str) + str_hash(str + 1, current_len - 1)) : 0;
|
||||
}
|
||||
|
||||
inline ullong str_hash_for_switch(const wchar_t* const str)
|
||||
{
|
||||
return (str_is_correct(str) && (str_len(str) <= MAX_LEN)) ? str_hash(str, str_len(str)) : N_HASH;
|
||||
}
|
||||
|
||||
inline ullong str_hash_for_switch(const std::wstring& str)
|
||||
{
|
||||
return (str_is_correct(str.c_str()) && (str.length() <= MAX_LEN)) ? str_hash(str.c_str(), str.length()) : N_HASH;
|
||||
}
|
||||
}
|
||||
inline ullong str_hash_for_switch(const std::wstring& str)
|
||||
{
|
||||
return (str_is_correct(str.c_str()) && (str.length() <= MAX_LEN)) ? str_hash(str.c_str(), str.length()) : N_HASH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // STATICFUNCTIONS_H
|
||||
|
||||
2347
Common/3dParty/html/css/src/StyleProperties.cpp
Normal file
2347
Common/3dParty/html/css/src/StyleProperties.cpp
Normal file
File diff suppressed because it is too large
Load Diff
636
Common/3dParty/html/css/src/StyleProperties.h
Normal file
636
Common/3dParty/html/css/src/StyleProperties.h
Normal file
@ -0,0 +1,636 @@
|
||||
#ifndef STYLEPROPERTIES_H
|
||||
#define STYLEPROPERTIES_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include "../../../../DesktopEditor/graphics/Matrix.h"
|
||||
#include "CUnitMeasureConverter.h"
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
namespace NSProperties
|
||||
{
|
||||
template<typename T>
|
||||
class CValue
|
||||
{
|
||||
friend class CString;
|
||||
friend class CMatrix;
|
||||
friend class CDigit;
|
||||
friend class CColor;
|
||||
friend class CEnum;
|
||||
|
||||
T m_oValue;
|
||||
unsigned int m_unLevel;
|
||||
bool m_bImportant;
|
||||
public:
|
||||
CValue(const T& oValue, unsigned int unLevel, bool bImportant) :
|
||||
m_oValue(oValue), m_unLevel(unLevel), m_bImportant(bImportant)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) = 0;
|
||||
|
||||
virtual bool Empty() const = 0;
|
||||
virtual void Clear() = 0;
|
||||
virtual int ToInt() const = 0;
|
||||
virtual double ToDouble() const = 0;
|
||||
virtual std::wstring ToWString() const = 0;
|
||||
|
||||
static void Equation(CValue &oFirstValue, CValue &oSecondValue)
|
||||
{
|
||||
if (oFirstValue.m_bImportant && !oSecondValue.m_bImportant && oFirstValue.Empty())
|
||||
oSecondValue.Clear();
|
||||
else if (oSecondValue.m_bImportant && !oFirstValue.m_bImportant && !oSecondValue.Empty())
|
||||
oFirstValue.Clear();
|
||||
else if (!oSecondValue.Empty())
|
||||
{
|
||||
if (oFirstValue.m_unLevel < oSecondValue.m_unLevel)
|
||||
oFirstValue.Clear();
|
||||
else
|
||||
oSecondValue.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const T& oValue) const { return m_oValue == oValue; }
|
||||
bool operator>=(const T& oValue) const { return m_oValue >= oValue; }
|
||||
bool operator<=(const T& oValue) const { return m_oValue <= oValue; }
|
||||
bool operator> (const T& oValue) const { return m_oValue > oValue; }
|
||||
bool operator< (const T& oValue) const { return m_oValue < oValue; }
|
||||
|
||||
virtual CValue& operator =(const CValue& oValue)
|
||||
{
|
||||
m_oValue = oValue.m_oValue;
|
||||
m_unLevel = oValue.m_unLevel;
|
||||
m_bImportant = oValue.m_bImportant;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CValue& operator =(const T& oValue)
|
||||
{
|
||||
//m_oValue = oValue.m_oValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CValue& operator+=(const CValue& oValue)
|
||||
{
|
||||
if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || oValue.Empty())
|
||||
return *this;
|
||||
|
||||
m_oValue = oValue.m_oValue;
|
||||
m_unLevel = std::max(m_unLevel, oValue.m_unLevel);
|
||||
m_bImportant = std::max(m_bImportant, oValue.m_bImportant);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const CValue& oValue) const
|
||||
{
|
||||
return m_oValue == oValue.m_oValue;
|
||||
}
|
||||
};
|
||||
|
||||
class CString : public CValue<std::wstring>
|
||||
{
|
||||
public:
|
||||
CString();
|
||||
CString(const std::wstring& wsValue, unsigned int unLevel, bool bImportant = false);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
bool SetValue(const std::wstring& wsValue, const std::vector<std::wstring>& arValiableValues, unsigned int unLevel, bool bHardMode);
|
||||
bool SetValue(const std::wstring& wsValue, const std::map<std::wstring, std::wstring>& arValiableValues, unsigned int unLevel, bool bHardMode);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
|
||||
CString& operator+=(const CString& oString);
|
||||
};
|
||||
|
||||
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 = 0, bool bHardMode = true) override;
|
||||
|
||||
bool Empty() const override;
|
||||
bool Zero() const;
|
||||
void Clear() override;
|
||||
|
||||
int ToInt() const override;
|
||||
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
|
||||
{
|
||||
unsigned char uchRed;
|
||||
unsigned char uchGreen;
|
||||
unsigned char uchBlue;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
bool operator==(const TRGB& oRGB) const;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ColorEmpty,
|
||||
ColorNone,
|
||||
ColorRGB,
|
||||
ColorHEX,
|
||||
ColorUrl
|
||||
} ColorType;
|
||||
|
||||
class Q_DECL_EXPORT CColorValue
|
||||
{
|
||||
public:
|
||||
CColorValue();
|
||||
CColorValue(const CColorValue& oColorValue);
|
||||
~CColorValue();
|
||||
|
||||
void SetRGB(unsigned char uchR, unsigned char uchG, unsigned char uchB);
|
||||
void SetRGB(const TRGB& oRGB);
|
||||
void SetHEX(const std::wstring& wsValue);
|
||||
void SetUrl(const std::wstring& wsValue);
|
||||
void SetNone();
|
||||
|
||||
void Clear();
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
ColorType m_enType;
|
||||
void* m_pColor = NULL;
|
||||
|
||||
std::wstring GetColor() const;
|
||||
|
||||
bool operator==(const CColorValue& oColorValue) const;
|
||||
CColorValue& operator= (const CColorValue& oColorValue);
|
||||
};
|
||||
|
||||
class CColor : public CValue<CColorValue>
|
||||
{
|
||||
CDigit m_oOpacity;
|
||||
static TRGB ConvertHEXtoRGB(const std::wstring& wsValue);
|
||||
static std::wstring ConvertRGBtoHEX(const TRGB& oValue);
|
||||
static std::wstring CutURL(const std::wstring& wsValue);
|
||||
public:
|
||||
CColor();
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override;
|
||||
bool SetOpacity(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
ColorType GetType() const;
|
||||
|
||||
double GetOpacity() const;
|
||||
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
TRGB ToRGB() const;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TransformMatrix,
|
||||
TransformTranslate,
|
||||
TransformScale,
|
||||
TransformRotate,
|
||||
TransformNone
|
||||
} TransformType;
|
||||
|
||||
typedef std::vector<std::pair<std::vector<double>, TransformType>> MatrixValues;
|
||||
|
||||
class CMatrix : public CValue<MatrixValues>
|
||||
{
|
||||
std::vector<std::wstring> CutTransforms(const std::wstring& wsValue) const;
|
||||
public:
|
||||
CMatrix();
|
||||
CMatrix(const MatrixValues& oValue, unsigned int unLevel, bool bImportant = false);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
bool SetMatrix(const Aggplus::CMatrix& oValue);
|
||||
|
||||
bool AddValue(const std::vector<double>& arValues, TransformType enType);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
|
||||
Aggplus::CMatrix GetFinalValue(TransformType oWithoutType = TransformNone) const;
|
||||
void ApplyTranform(Aggplus::CMatrix& oMatrix, Aggplus::MatrixOrder order = Aggplus::MatrixOrderPrepend) const;
|
||||
|
||||
bool operator==(const CMatrix& oMatrix) const;
|
||||
};
|
||||
|
||||
class CEnum : public CValue<int>
|
||||
{
|
||||
std::map<std::wstring, int> m_mMap;
|
||||
public:
|
||||
CEnum();
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override;
|
||||
void SetMapping(const std::map<std::wstring, int>& mMap);
|
||||
|
||||
bool Empty() const override;
|
||||
void Clear() override;
|
||||
|
||||
CEnum &operator =(int nValue);
|
||||
|
||||
bool operator==(int nValue) const;
|
||||
bool operator!=(int nValue) const;
|
||||
|
||||
int ToInt() const override;
|
||||
private:
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
};
|
||||
|
||||
// PROPERTIES
|
||||
class CDisplay
|
||||
{
|
||||
public:
|
||||
CDisplay();
|
||||
|
||||
static void Equation(CDisplay &oFirstDisplay, CDisplay &oSecondDisplay);
|
||||
|
||||
bool SetX (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetY (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddX (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddY (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidth (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetHeight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
bool SetHAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetVAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
bool SetDisplay(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
const CDigit& GetX() const;
|
||||
const CDigit& GetY() const;
|
||||
const CDigit& GetWidth() const;
|
||||
const CDigit& GetHeight() const;
|
||||
|
||||
const CString& GetHAlign() const;
|
||||
const CString& GetVAlign() const;
|
||||
|
||||
const CString& GetDisplay() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CDisplay& operator+=(const CDisplay& oDisplay);
|
||||
bool operator==(const CDisplay& oDisplay) const;
|
||||
private:
|
||||
CDigit m_oX;
|
||||
CDigit m_oY;
|
||||
CDigit m_oWidth;
|
||||
CDigit m_oHeight;
|
||||
|
||||
CString m_oHAlign;
|
||||
CString m_oVAlign;
|
||||
|
||||
CString m_oDisplay;
|
||||
};
|
||||
|
||||
class CStroke
|
||||
{
|
||||
public:
|
||||
CStroke();
|
||||
|
||||
static void Equation(CStroke &oFirstStroke, CStroke &oSecondStroke);
|
||||
|
||||
bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidth (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
const CColor& GetColor() const;
|
||||
const CDigit& GetWidth() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CStroke& operator+=(const CStroke& oStroke);
|
||||
bool operator==(const CStroke& oStroke) const;
|
||||
private:
|
||||
CColor m_oColor;
|
||||
CDigit m_oWidth;
|
||||
};
|
||||
|
||||
class CBackground
|
||||
{
|
||||
public:
|
||||
CBackground();
|
||||
|
||||
static void Equation(CBackground &oFirstBackground, CBackground &oSecondBackground);
|
||||
|
||||
bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetBackground(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
void InBorder();
|
||||
|
||||
const CColor& GetColor() const;
|
||||
bool IsInBorder() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CBackground& operator =(const CBackground& oBackground);
|
||||
CBackground& operator+=(const CBackground& oBackground);
|
||||
bool operator==(const CBackground& oBackground) const;
|
||||
private:
|
||||
CColor m_oColor;
|
||||
bool m_bInBorder;
|
||||
};
|
||||
|
||||
class CTransform
|
||||
{
|
||||
public:
|
||||
CTransform();
|
||||
|
||||
void Clear();
|
||||
|
||||
static void Equation(CTransform &oFirstTransform, CTransform &oSecondTransform);
|
||||
|
||||
bool SetMatrix(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetMatrix(const Aggplus::CMatrix &oMatrix);
|
||||
|
||||
const CMatrix& GetMatrix() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CTransform& operator+=(const CTransform& oTransform);
|
||||
bool operator==(const CTransform& oTransform) const;
|
||||
private:
|
||||
CMatrix m_oMatrix;
|
||||
};
|
||||
|
||||
class CBorderSide
|
||||
{
|
||||
public:
|
||||
CBorderSide();
|
||||
|
||||
static void Equation(CBorderSide &oFirstBorderSide, CBorderSide &oSecondBorderSide);
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidth(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyle(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColor(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
void Block();
|
||||
void Unblock();
|
||||
|
||||
bool IsBlock() const;
|
||||
|
||||
const CDigit& GetWidth() const;
|
||||
const CString& GetStyle() const;
|
||||
const CColor& GetColor() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CBorderSide& operator+=(const CBorderSide& oBorderSide);
|
||||
bool operator==(const CBorderSide& oBorderSide) const;
|
||||
private:
|
||||
CDigit m_oWidth;
|
||||
CString m_oStyle;
|
||||
CColor m_oColor;
|
||||
|
||||
bool m_bBlock;
|
||||
};
|
||||
|
||||
class CBorder
|
||||
{
|
||||
public:
|
||||
CBorder();
|
||||
|
||||
static void Equation(CBorder &oFirstBorder, CBorder &oSecondBorder);
|
||||
|
||||
bool SetSides(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidth(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyle(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColor(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
//Left Side
|
||||
bool SetLeftSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidthLeftSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyleLeftSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColorLeftSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
//Top Side
|
||||
bool SetTopSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidthTopSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyleTopSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColorTopSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
//Right Side
|
||||
bool SetRightSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidthRightSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyleRightSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColorRightSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
//Bottom Side
|
||||
bool SetBottomSide (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWidthBottomSide(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyleBottomSide(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColorBottomSide(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
void Block();
|
||||
void Unblock();
|
||||
|
||||
bool Empty() const;
|
||||
bool EqualSides() const;
|
||||
|
||||
const CBorderSide& GetLeftBorder() const;
|
||||
const CBorderSide& GetTopBorder() const;
|
||||
const CBorderSide& GetRightBorder() const;
|
||||
const CBorderSide& GetBottomBorder() const;
|
||||
|
||||
CBorder& operator+=(const CBorder& oBorder);
|
||||
bool operator==(const CBorder& oBorder) const;
|
||||
private:
|
||||
CBorderSide m_oLeft;
|
||||
CBorderSide m_oTop;
|
||||
CBorderSide m_oRight;
|
||||
CBorderSide m_oBottom;
|
||||
};
|
||||
|
||||
class CTextDecorationLine
|
||||
{
|
||||
bool m_bUnderline;
|
||||
bool m_bOverline;
|
||||
bool m_bLineThrough;
|
||||
public:
|
||||
CTextDecorationLine();
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
bool SetValue(const std::wstring& wsValue);
|
||||
|
||||
bool Underline() const;
|
||||
bool Overline() const;
|
||||
bool LineThrough() const;
|
||||
|
||||
CTextDecorationLine &operator+=(const CTextDecorationLine& oTextDecoration);
|
||||
};
|
||||
|
||||
struct TTextDecoration
|
||||
{
|
||||
CTextDecorationLine m_oLine;
|
||||
CString m_oStyle;
|
||||
CColor m_oColor;
|
||||
|
||||
TTextDecoration& operator+=(const TTextDecoration& oTextDecoration);
|
||||
};
|
||||
|
||||
class CText
|
||||
{
|
||||
public:
|
||||
CText();
|
||||
|
||||
static void Equation(CText &oFirstText, CText &oSecondText);
|
||||
|
||||
bool SetIndent (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetDecoration(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
const CDigit& GetIndent() const;
|
||||
const CString& GetAlign() const;
|
||||
const TTextDecoration& GetDecoration() const;
|
||||
const CColor& GetColor() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
bool Underline() const;
|
||||
bool Overline() const;
|
||||
bool LineThrough() const;
|
||||
|
||||
CText& operator+=(const CText& oText);
|
||||
bool operator==(const CText& oText) const;
|
||||
private:
|
||||
TTextDecoration m_oDecoration;
|
||||
CDigit m_oIndent;
|
||||
CString m_oAlign;
|
||||
CColor m_oColor;
|
||||
};
|
||||
|
||||
class CIndent
|
||||
{
|
||||
public:
|
||||
CIndent();
|
||||
|
||||
static void Equation(CIndent &oFirstMargin, CIndent &oSecondMargin);
|
||||
|
||||
void SetPermisson(bool bPermission);
|
||||
|
||||
bool AddValue (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddLeft (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddTop (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddRight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool AddBottom (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
const CDigit& GetLeft () const;
|
||||
const CDigit& GetTop () const;
|
||||
const CDigit& GetRight () const;
|
||||
const CDigit& GetBottom() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CIndent& operator+=(const CIndent& oMargin);
|
||||
bool operator==(const CIndent& oMargin) const;
|
||||
private:
|
||||
bool AddValue(CDigit& oValue, const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
CDigit m_oLeft;
|
||||
CDigit m_oTop;
|
||||
CDigit m_oRight;
|
||||
CDigit m_oBottom;
|
||||
|
||||
bool m_bPermission;
|
||||
};
|
||||
|
||||
class CFont
|
||||
{
|
||||
public:
|
||||
CFont();
|
||||
|
||||
static void Equation(CFont &oFirstFont, CFont &oSecondFont);
|
||||
|
||||
bool SetValue (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetSize (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetLineHeight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetFamily (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStretch (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetStyle (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetVariant (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
bool SetWeight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
bool UpdateSize(double dSize);
|
||||
|
||||
void Clear();
|
||||
|
||||
bool Bold() const;
|
||||
bool Italic() const;
|
||||
|
||||
const CDigit& GetSize() const;
|
||||
const CDigit& GetLineHeight() const;
|
||||
const CString& GetFamily() const;
|
||||
const CString& GetStretch() const;
|
||||
const CString& GetStyle() const;
|
||||
const CString& GetVariant() const;
|
||||
const CString& GetWeight() const;
|
||||
|
||||
bool Empty() const;
|
||||
|
||||
CFont& operator+=(const CFont& oFont);
|
||||
bool operator==(const CFont& oFont) const;
|
||||
private:
|
||||
CDigit m_oSize;
|
||||
CDigit m_oLineHeight;
|
||||
CString m_oFamily;
|
||||
//TODO:: возможно стоит перейти в слудующих переменных на enum
|
||||
CString m_oStretch;
|
||||
CString m_oStyle;
|
||||
CString m_oVariant;
|
||||
CString m_oWeight;
|
||||
|
||||
TTextDecoration m_oTextDecoration;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // STYLEPROPERTIES_H
|
||||
@ -8,467 +8,488 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CDocumentStyle::CDocumentStyle() : m_arStandardStyles({L"a", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6", L"h1-c",
|
||||
L"h2-c", L"h3-c", L"h4-c", L"h5-c", L"h6-c", L"p-c", L"p", L"div-c", L"div", L"a-c"}) {}
|
||||
|
||||
CDocumentStyle::~CDocumentStyle()
|
||||
{
|
||||
m_arStandardStyles. clear();
|
||||
m_arStyleUsed. clear();
|
||||
m_arStandardStylesUsed.clear();
|
||||
}
|
||||
|
||||
std::wstring CDocumentStyle::GetStyle() const
|
||||
{
|
||||
return m_sStyle;
|
||||
}
|
||||
|
||||
std::wstring CDocumentStyle::GetIdAndClear()
|
||||
{
|
||||
std::wstring sId = m_sId;
|
||||
Clear();
|
||||
return sId;
|
||||
}
|
||||
|
||||
void CDocumentStyle::Clear()
|
||||
{
|
||||
m_sId.clear();
|
||||
m_sStyle.clear();
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetStyle(const std::wstring& sStyle)
|
||||
{
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
m_sStyle = sStyle;
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetId (const std::wstring& sId)
|
||||
{
|
||||
if (sId.empty())
|
||||
return;
|
||||
m_sId = sId;
|
||||
}
|
||||
|
||||
void CDocumentStyle::CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement)
|
||||
{
|
||||
if (arStandartedStyles.empty())
|
||||
return;
|
||||
|
||||
std::vector<std::wstring> arStyles;
|
||||
for (const std::wstring& sStyleName : arStandartedStyles)
|
||||
{
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sStyleName) != m_arStandardStyles.end())
|
||||
arStyles.push_back(sStyleName);
|
||||
}
|
||||
|
||||
if (arStyles.empty())
|
||||
return;
|
||||
|
||||
std::wstring sId;
|
||||
for (std::vector<std::wstring>::const_reverse_iterator iStyleName = arStyles.rbegin(); iStyleName != arStyles.rend(); ++iStyleName)
|
||||
{
|
||||
sId += *iStyleName + L'+';
|
||||
CXmlElement oTempElement;
|
||||
CreateStandardStyle(*iStyleName, oTempElement);
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), *iStyleName) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
m_sStyle = oTempElement.GetStyle() + m_sStyle;
|
||||
m_arStandardStylesUsed.push_back(*iStyleName);
|
||||
}
|
||||
oElement += oTempElement;
|
||||
}
|
||||
sId.pop_back();
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Name, sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, sId);
|
||||
}
|
||||
|
||||
void CDocumentStyle::CreateStandardStyle(const std::wstring& sNameStyle, CXmlElement& oElement)
|
||||
{
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sNameStyle) != m_arStandardStyles.end())
|
||||
oElement.CreateDefaultElement(sNameStyle);
|
||||
}
|
||||
|
||||
void CDocumentStyle::ConvertStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle)
|
||||
{
|
||||
if (oStyle.GetId().empty())
|
||||
return;
|
||||
|
||||
std::wstring sName = oStyle.GetId();
|
||||
const size_t posPoint = sName.find(L'.');
|
||||
|
||||
if (posPoint != std::wstring::npos)
|
||||
sName = sName.substr(0, posPoint);
|
||||
else
|
||||
{
|
||||
const size_t posLattice = sName.find(L'#');
|
||||
if (posLattice != std::wstring::npos)
|
||||
sName = sName.substr(0, posLattice);
|
||||
else
|
||||
{
|
||||
const size_t posDash = sName.find(L'-');
|
||||
if (posDash != std::wstring::npos)
|
||||
sName = sName.substr(0, posDash);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bIsPStyle)
|
||||
sName += L"-c";
|
||||
|
||||
CXmlElement oParentStyle;
|
||||
std::vector<std::wstring> arParentsName = oStyle.GetParentsName();
|
||||
|
||||
if (!bIsPStyle)
|
||||
for (std::wstring& sParentName : arParentsName)
|
||||
sParentName += L"-c";
|
||||
|
||||
if (!arParentsName.empty())
|
||||
{
|
||||
CombineStandardStyles(arParentsName, oParentStyle);
|
||||
|
||||
if (!oParentStyle.Empty())
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, L"(" + oParentStyle.GetStyleId() + L")");
|
||||
if (!bIsPStyle)
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, oParentStyle.GetStyleId() + L"-c");
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Type, L"character");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CXmlElement oStandardXmlElement;
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sName) != m_arStandardStyles.end())
|
||||
CreateStandardStyle(sName, oStandardXmlElement);
|
||||
|
||||
if (oStandardXmlElement.Empty() && !oParentStyle.Empty())
|
||||
{
|
||||
const std::wstring sParentsStyleID = oParentStyle.GetStyleId();
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sParentsStyleID) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oParentStyle.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oParentStyle.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sParentsStyleID);
|
||||
}
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sParentsStyleID;
|
||||
return;
|
||||
}
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sParentsStyleID);
|
||||
}
|
||||
else if (!oStandardXmlElement.Empty() && !oParentStyle.Empty())
|
||||
{
|
||||
std::wstring sStandPlusParent = oStandardXmlElement.GetStyleId() + L"+" + oParentStyle.GetStyleId();
|
||||
if(std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sStandPlusParent) != m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandPlusParent;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sStandPlusParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
CXmlElement oTempElement = oParentStyle;
|
||||
oTempElement += oStandardXmlElement;
|
||||
|
||||
oTempElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, sStandPlusParent);
|
||||
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oTempElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oTempElement.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oTempElement.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sStandPlusParent);
|
||||
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandPlusParent;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, oTempElement.GetStyleId());
|
||||
}
|
||||
}
|
||||
else if (!oStandardXmlElement.Empty() && oParentStyle.Empty())
|
||||
{
|
||||
std::wstring sStandartStyleID = oStandardXmlElement.GetStyleId();
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sStandartStyleID) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oStandardXmlElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oStandardXmlElement.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oStandardXmlElement.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sStandartStyleID);
|
||||
}
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandartStyleID;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sStandartStyleID);
|
||||
}
|
||||
|
||||
if (oStyle.Empty() && oElement.Empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
m_sId = oStyle.GetId();
|
||||
if(!bIsPStyle)
|
||||
m_sId += L"-c";
|
||||
else
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, m_sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Name, m_sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Type, bIsPStyle ? L"paragraph" : L"character");
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_CustomStyle, L"1");
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetPStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
|
||||
{
|
||||
ConvertStyle(oStyle, oXmlElement, true);
|
||||
if (oStyle.Empty() && oXmlElement.Empty())
|
||||
return;
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Jc, oStyle.m_pText.GetAlign());
|
||||
|
||||
std::wstring sInfValue;
|
||||
sInfValue.reserve(64);
|
||||
|
||||
if (!oStyle.m_pMargin.Empty() && oStyle.m_pMargin.GetPermission())
|
||||
{
|
||||
const std::wstring& sLeftSide = oStyle.m_pMargin.GetLeftSideW();
|
||||
const std::wstring& sRightSide = oStyle.m_pMargin.GetRightSideW();
|
||||
|
||||
if (!sLeftSide.empty())
|
||||
sInfValue += L"w:left=\"" + sLeftSide + L"\" ";
|
||||
if (!sRightSide.empty())
|
||||
sInfValue += L"w:right=\"" + sRightSide + L"\" ";
|
||||
}
|
||||
|
||||
const std::wstring& sIndent = oStyle.m_pText.GetIndentW();
|
||||
if (!sIndent.empty())
|
||||
sInfValue += L"w:firstLine=\"" + sIndent + L"\" ";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Ind, sInfValue);
|
||||
|
||||
std::wstring sSpacingValue;
|
||||
sSpacingValue.reserve(128);
|
||||
|
||||
if (!oStyle.m_pMargin.Empty() && oStyle.m_pMargin.GetPermission())
|
||||
{
|
||||
sSpacingValue += L"w:afterAutospacing=\"1\" w:after=\"" + oStyle.m_pMargin.GetTopSideW() + L"\" ";
|
||||
sSpacingValue += L"w:beforeAutospacing=\"1\" w:before=\"" + oStyle.m_pMargin.GetTopSideW() + L"\" ";
|
||||
}
|
||||
else/* if (!oStyle.m_pBorder.Empty() || !oStyle.m_pMargin.GetPermission())*/
|
||||
sSpacingValue += L"w:after=\"0\" w:before=\"0\"";
|
||||
|
||||
const std::wstring &sLineHeight = oStyle.m_pFont.GetLineHeight();
|
||||
if (!sLineHeight.empty())
|
||||
{
|
||||
sSpacingValue += L" w:line=\"" + sLineHeight + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_pBorder.Empty())
|
||||
{
|
||||
sSpacingValue += L" w:line=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pFont.GetSize() * 12 + 0.5f)) + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_pBorder.Empty())
|
||||
sSpacingValue += L"w:line=\"240\" w:lineRule=\"auto\" ";
|
||||
|
||||
if (!sSpacingValue.empty())
|
||||
{
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Spacing, sSpacingValue);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_ContextualSpacing, L"true");
|
||||
}
|
||||
|
||||
if (!oStyle.m_pBackground.Empty())
|
||||
{
|
||||
const std::wstring wsColor = oStyle.m_pBackground.GetColorHex();
|
||||
if (wsColor != L"ffffff")
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Shd, wsColor);
|
||||
}
|
||||
|
||||
if (!oStyle.m_pBorder.Empty())
|
||||
{
|
||||
if (oStyle.m_pBorder.EqualSides())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_pBorder.GetColorBottomSide();
|
||||
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleBottomSide();
|
||||
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthBottomSideW();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"0\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_TopBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_LeftBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_BottomBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_RightBorder, sBorder);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!oStyle.m_pBorder.EmptyTopSide())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_pBorder.GetColorTopSide();
|
||||
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleTopSide();
|
||||
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthTopSideW();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_TopBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_pBorder.EmptyRightSide())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_pBorder.GetColorRightSide();
|
||||
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleRightSide();
|
||||
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthRightSideW();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_RightBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_pBorder.EmptyBottomSide())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_pBorder.GetColorBottomSide();
|
||||
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleBottomSide();
|
||||
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthBottomSideW();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_BottomBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_pBorder.EmptyLeftSide())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_pBorder.GetColorLeftSide();
|
||||
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleLeftSide();
|
||||
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthLeftSideW();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_LeftBorder, sBorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetRStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
|
||||
{
|
||||
ConvertStyle(oStyle, oXmlElement, false);
|
||||
if (oStyle.Empty() && oXmlElement.Empty())
|
||||
return;
|
||||
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Highlight, oStyle.m_pBackground.GetColor());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Color, oStyle.m_pText.GetColor());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_U, oStyle.m_pText.GetDecoration());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Sz, oStyle.m_pFont.GetSizeW());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_RFonts, oStyle.m_pFont.GetFamily());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_I, oStyle.m_pFont.GetStyle());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_B, oStyle.m_pFont.GetWeight());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_SmallCaps, oStyle.m_pFont.GetVariant());
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteRStyle (const NSCSS::CCompiledStyle& oStyle)
|
||||
{
|
||||
if(oStyle.GetId().empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
CStyleUsed structStyle(oStyle, false);
|
||||
|
||||
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
|
||||
|
||||
if (oItem != m_arStyleUsed.end())
|
||||
{
|
||||
m_sId = (*oItem).getId();
|
||||
return;
|
||||
}
|
||||
CXmlElement oXmlElement;
|
||||
SetRStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oStyle.Empty() || !oXmlElement.Empty())
|
||||
{
|
||||
structStyle.setId(oXmlElement.GetStyleId());
|
||||
m_arStyleUsed.push_back(structStyle);
|
||||
m_sStyle += oXmlElement.GetRStyle();
|
||||
}
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteLitePStyle(const CCompiledStyle &oStyle)
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
return;
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetPStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oXmlElement.Empty())
|
||||
m_sStyle += oXmlElement.GetLitePStyle();
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteLiteRStyle(const CCompiledStyle &oStyle)
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
return;
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetRStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oXmlElement.Empty())
|
||||
m_sStyle += oXmlElement.GetLiteRStyle();
|
||||
}
|
||||
|
||||
void CDocumentStyle::WritePStyle (const NSCSS::CCompiledStyle& oStyle)
|
||||
{
|
||||
if(oStyle.GetId().empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
CStyleUsed structStyle(oStyle, true);
|
||||
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
|
||||
|
||||
if (oItem != m_arStyleUsed.end())
|
||||
{
|
||||
m_sId = (*oItem).getId();
|
||||
return;
|
||||
}
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetPStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oStyle.Empty() || !oXmlElement.Empty())
|
||||
{
|
||||
structStyle.setId(oXmlElement.GetStyleId());
|
||||
m_arStyleUsed.push_back(structStyle);
|
||||
m_sStyle += oXmlElement.GetPStyle();
|
||||
}
|
||||
}
|
||||
CStyleUsed::CStyleUsed(const CCompiledStyle &oStyle, bool bIsPStyle)
|
||||
: m_oStyle(oStyle), m_bIsPStyle(bIsPStyle)
|
||||
{}
|
||||
|
||||
bool CStyleUsed::operator==(const CStyleUsed &oUsedStyle) const
|
||||
{
|
||||
return (m_bIsPStyle == oUsedStyle.m_bIsPStyle) && (m_oStyle == oUsedStyle.m_oStyle);
|
||||
}
|
||||
|
||||
std::wstring CStyleUsed::getId()
|
||||
{
|
||||
return m_sId;
|
||||
}
|
||||
|
||||
void CStyleUsed::setId(const std::wstring &sId)
|
||||
{
|
||||
m_sId = sId;
|
||||
}
|
||||
|
||||
CDocumentStyle::CDocumentStyle() : m_arStandardStyles({L"a", L"li", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6", L"h1-c",
|
||||
L"h2-c", L"h3-c", L"h4-c", L"h5-c", L"h6-c", L"p-c", L"p", L"div-c", L"div", L"a-c"}) {}
|
||||
|
||||
CDocumentStyle::~CDocumentStyle()
|
||||
{
|
||||
m_arStandardStyles. clear();
|
||||
m_arStyleUsed. clear();
|
||||
m_arStandardStylesUsed.clear();
|
||||
}
|
||||
|
||||
std::wstring CDocumentStyle::GetStyle() const
|
||||
{
|
||||
return m_sStyle;
|
||||
}
|
||||
|
||||
std::wstring CDocumentStyle::GetIdAndClear()
|
||||
{
|
||||
std::wstring sId = m_sId;
|
||||
Clear();
|
||||
return sId;
|
||||
}
|
||||
|
||||
void CDocumentStyle::Clear()
|
||||
{
|
||||
m_sId.clear();
|
||||
m_sStyle.clear();
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetStyle(const std::wstring& sStyle)
|
||||
{
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
m_sStyle = sStyle;
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetId (const std::wstring& sId)
|
||||
{
|
||||
if (sId.empty())
|
||||
return;
|
||||
m_sId = sId;
|
||||
}
|
||||
|
||||
void CDocumentStyle::CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement)
|
||||
{
|
||||
if (arStandartedStyles.empty())
|
||||
return;
|
||||
|
||||
std::vector<std::wstring> arStyles;
|
||||
for (const std::wstring& sStyleName : arStandartedStyles)
|
||||
{
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sStyleName) != m_arStandardStyles.end())
|
||||
arStyles.push_back(sStyleName);
|
||||
}
|
||||
|
||||
if (arStyles.empty())
|
||||
return;
|
||||
|
||||
std::wstring sId;
|
||||
for (std::vector<std::wstring>::const_reverse_iterator iStyleName = arStyles.rbegin(); iStyleName != arStyles.rend(); ++iStyleName)
|
||||
{
|
||||
sId += *iStyleName + L'+';
|
||||
CXmlElement oTempElement;
|
||||
CreateStandardStyle(*iStyleName, oTempElement);
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), *iStyleName) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
m_sStyle = oTempElement.GetStyle() + m_sStyle;
|
||||
m_arStandardStylesUsed.push_back(*iStyleName);
|
||||
}
|
||||
oElement += oTempElement;
|
||||
}
|
||||
sId.pop_back();
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Name, sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, sId);
|
||||
}
|
||||
|
||||
void CDocumentStyle::CreateStandardStyle(const std::wstring& sNameStyle, CXmlElement& oElement)
|
||||
{
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sNameStyle) != m_arStandardStyles.end())
|
||||
oElement.CreateDefaultElement(sNameStyle);
|
||||
}
|
||||
|
||||
void CDocumentStyle::ConvertStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle)
|
||||
{
|
||||
if (oStyle.GetId().empty())
|
||||
return;
|
||||
|
||||
std::wstring sName = oStyle.GetId();
|
||||
const size_t posPoint = sName.find(L'.');
|
||||
|
||||
if (posPoint != std::wstring::npos)
|
||||
sName = sName.substr(0, posPoint);
|
||||
else
|
||||
{
|
||||
const size_t posLattice = sName.find(L'#');
|
||||
if (posLattice != std::wstring::npos)
|
||||
sName = sName.substr(0, posLattice);
|
||||
else
|
||||
{
|
||||
const size_t posDash = sName.find(L'-');
|
||||
if (posDash != std::wstring::npos)
|
||||
sName = sName.substr(0, posDash);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bIsPStyle)
|
||||
sName += L"-c";
|
||||
|
||||
CXmlElement oParentStyle;
|
||||
std::vector<std::wstring> arParentsName = oStyle.GetParentsName();
|
||||
|
||||
if (!bIsPStyle)
|
||||
for (std::wstring& sParentName : arParentsName)
|
||||
sParentName += L"-c";
|
||||
|
||||
if (!arParentsName.empty())
|
||||
{
|
||||
CombineStandardStyles(arParentsName, oParentStyle);
|
||||
|
||||
if (!oParentStyle.Empty())
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, L"(" + oParentStyle.GetStyleId() + L")");
|
||||
if (!bIsPStyle)
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, oParentStyle.GetStyleId() + L"-c");
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Type, L"character");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CXmlElement oStandardXmlElement;
|
||||
if (std::find(m_arStandardStyles.begin(), m_arStandardStyles.end(), sName) != m_arStandardStyles.end())
|
||||
CreateStandardStyle(sName, oStandardXmlElement);
|
||||
|
||||
if (oStandardXmlElement.Empty() && !oParentStyle.Empty())
|
||||
{
|
||||
const std::wstring sParentsStyleID = oParentStyle.GetStyleId();
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sParentsStyleID) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oParentStyle.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oParentStyle.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oParentStyle.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sParentsStyleID);
|
||||
}
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sParentsStyleID;
|
||||
return;
|
||||
}
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sParentsStyleID);
|
||||
}
|
||||
else if (!oStandardXmlElement.Empty() && !oParentStyle.Empty())
|
||||
{
|
||||
std::wstring sStandPlusParent = oStandardXmlElement.GetStyleId() + L"+" + oParentStyle.GetStyleId();
|
||||
if(std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sStandPlusParent) != m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandPlusParent;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sStandPlusParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
CXmlElement oTempElement = oParentStyle;
|
||||
oTempElement += oStandardXmlElement;
|
||||
|
||||
oTempElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, sStandPlusParent);
|
||||
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oTempElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oTempElement.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oTempElement.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sStandPlusParent);
|
||||
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandPlusParent;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, oTempElement.GetStyleId());
|
||||
}
|
||||
}
|
||||
else if (!oStandardXmlElement.Empty() && oParentStyle.Empty())
|
||||
{
|
||||
std::wstring sStandartStyleID = oStandardXmlElement.GetStyleId();
|
||||
if (std::find(m_arStandardStylesUsed.begin(), m_arStandardStylesUsed.end(), sStandartStyleID) == m_arStandardStylesUsed.end())
|
||||
{
|
||||
if (bIsPStyle)
|
||||
{
|
||||
oStandardXmlElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
m_sStyle += oStandardXmlElement.GetPStyle();
|
||||
}
|
||||
else
|
||||
m_sStyle += oStandardXmlElement.GetRStyle();
|
||||
|
||||
m_arStandardStylesUsed.push_back(sStandartStyleID);
|
||||
}
|
||||
if (oStyle.Empty())
|
||||
{
|
||||
m_sId = sStandartStyleID;
|
||||
return;
|
||||
}
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_BasedOn, sStandartStyleID);
|
||||
}
|
||||
|
||||
if (oStyle.Empty() && oElement.Empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
m_sId = oStyle.GetId();
|
||||
if(!bIsPStyle)
|
||||
m_sId += L"-c";
|
||||
else
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_QFormat, L"true");
|
||||
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_StyleId, m_sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Name, m_sId);
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_Type, bIsPStyle ? L"paragraph" : L"character");
|
||||
oElement.AddBasicProperties(NSConstValues::NSProperties::BasicProperties::B_CustomStyle, L"1");
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetPStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
|
||||
{
|
||||
ConvertStyle(oStyle, oXmlElement, true);
|
||||
if (oStyle.Empty() && oXmlElement.Empty())
|
||||
return;
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Jc, oStyle.m_oText.GetAlign().ToWString());
|
||||
|
||||
std::wstring sInfValue;
|
||||
sInfValue.reserve(64);
|
||||
|
||||
//TODO:: проверить Permission в Margin
|
||||
if (!oStyle.m_oMargin.Empty() || !oStyle.m_oPadding.Empty() /*&& oStyle.m_oMargin.GetPermission()*/)
|
||||
{
|
||||
const std::wstring& sLeftSide = (oStyle.m_oMargin.GetLeft() + oStyle.m_oPadding.GetLeft()) .ToWString();
|
||||
const std::wstring& sRightSide = (oStyle.m_oMargin.GetRight() + oStyle.m_oPadding.GetRight()).ToWString();
|
||||
|
||||
if (!sLeftSide.empty())
|
||||
sInfValue += L"w:left=\"" + sLeftSide + L"\" ";
|
||||
if (!sRightSide.empty())
|
||||
sInfValue += L"w:right=\"" + sRightSide + L"\" ";
|
||||
}
|
||||
|
||||
const std::wstring& sIndent = oStyle.m_oText.GetIndent().ToWString();
|
||||
if (!sIndent.empty())
|
||||
sInfValue += L"w:firstLine=\"" + sIndent + L"\" ";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Ind, sInfValue);
|
||||
|
||||
std::wstring sSpacingValue;
|
||||
sSpacingValue.reserve(128);
|
||||
|
||||
//TODO:: проверить Permission в Margin
|
||||
if (!oStyle.m_oMargin.Empty() || !oStyle.m_oPadding.Empty() /*&& oStyle.m_oMargin.GetPermission()*/)
|
||||
{
|
||||
sSpacingValue += L"w:afterAutospacing=\"1\" w:after=\"" + (oStyle.m_oMargin.GetBottom() + oStyle.m_oPadding.GetBottom()).ToWString() + L"\" ";
|
||||
sSpacingValue += L"w:beforeAutospacing=\"1\" w:before=\"" + (oStyle.m_oMargin.GetTop() + oStyle.m_oPadding.GetTop()) .ToWString() + L"\" ";
|
||||
}
|
||||
else/* if (!oStyle.m_pBorder.Empty() || !oStyle.m_oMargin.GetPermission())*/
|
||||
sSpacingValue += L"w:after=\"0\" w:before=\"0\"";
|
||||
|
||||
const std::wstring &sLineHeight = oStyle.m_oFont.GetLineHeight().ToWString();
|
||||
if (!sLineHeight.empty())
|
||||
{
|
||||
sSpacingValue += L" w:line=\"" + sLineHeight + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_oBorder.Empty())
|
||||
{
|
||||
sSpacingValue += L" w:line=\"" + std::to_wstring(static_cast<short int>(oStyle.m_oFont.GetSize().ToDouble() * 12 + 0.5f)) + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_oBorder.Empty())
|
||||
sSpacingValue += L"w:line=\"240\" w:lineRule=\"auto\" ";
|
||||
|
||||
if (!sSpacingValue.empty())
|
||||
{
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Spacing, sSpacingValue);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_ContextualSpacing, L"true");
|
||||
}
|
||||
|
||||
if (!oStyle.m_oBackground.Empty())
|
||||
{
|
||||
const std::wstring wsColor = oStyle.m_oBackground.GetColor().ToWString();
|
||||
if (wsColor != L"ffffff")
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_Shd, wsColor);
|
||||
}
|
||||
|
||||
if (!oStyle.m_oBorder.Empty())
|
||||
{
|
||||
if (oStyle.m_oBorder.EqualSides())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_oBorder.GetLeftBorder().GetColor().ToWString();
|
||||
const std::wstring sBorderStyle = oStyle.m_oBorder.GetLeftBorder().GetStyle().ToWString();
|
||||
const std::wstring sBorderWidth = oStyle.m_oBorder.GetLeftBorder().GetWidth().ToWString();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"0\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_TopBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_LeftBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_BottomBorder, sBorder);
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_RightBorder, sBorder);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!oStyle.m_oBorder.GetTopBorder().Empty())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_oBorder.GetTopBorder().GetColor().ToWString();
|
||||
const std::wstring sBorderStyle = oStyle.m_oBorder.GetTopBorder().GetStyle().ToWString();
|
||||
const std::wstring sBorderWidth = oStyle.m_oBorder.GetTopBorder().GetWidth().ToWString();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_TopBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_oBorder.GetRightBorder().Empty())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_oBorder.GetRightBorder().GetColor().ToWString();
|
||||
const std::wstring sBorderStyle = oStyle.m_oBorder.GetRightBorder().GetStyle().ToWString();
|
||||
const std::wstring sBorderWidth = oStyle.m_oBorder.GetRightBorder().GetWidth().ToWString();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_RightBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_oBorder.GetBottomBorder().Empty())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_oBorder.GetBottomBorder().GetColor().ToWString();
|
||||
const std::wstring sBorderStyle = oStyle.m_oBorder.GetBottomBorder().GetStyle().ToWString();
|
||||
const std::wstring sBorderWidth = oStyle.m_oBorder.GetBottomBorder().GetWidth().ToWString();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_BottomBorder, sBorder);
|
||||
}
|
||||
|
||||
if (!oStyle.m_oBorder.GetLeftBorder().Empty())
|
||||
{
|
||||
const std::wstring sBorderColor = oStyle.m_oBorder.GetLeftBorder().GetColor().ToWString();
|
||||
const std::wstring sBorderStyle = oStyle.m_oBorder.GetLeftBorder().GetStyle().ToWString();
|
||||
const std::wstring sBorderWidth = oStyle.m_oBorder.GetLeftBorder().GetWidth().ToWString();
|
||||
|
||||
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
|
||||
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
|
||||
|
||||
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_LeftBorder, sBorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDocumentStyle::SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement)
|
||||
{
|
||||
ConvertStyle(oStyle, oXmlElement, false);
|
||||
if (oStyle.Empty() && oXmlElement.Empty())
|
||||
return;
|
||||
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Highlight, oStyle.m_oBackground.GetColor().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Color, oStyle.m_oText.GetColor().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_U, (oStyle.m_oText.GetDecoration().m_oLine.Underline()) ? L"underline" : L"");
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_Sz, oStyle.m_oFont.GetSize().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_RFonts, oStyle.m_oFont.GetFamily().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_I, oStyle.m_oFont.GetStyle().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_B, oStyle.m_oFont.GetWeight().ToWString());
|
||||
oXmlElement.AddPropertiesInR(NSConstValues::NSProperties::RunnerProperties::R_SmallCaps, oStyle.m_oFont.GetVariant().ToWString());
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteRStyle (const NSCSS::CCompiledStyle& oStyle)
|
||||
{
|
||||
if(oStyle.GetId().empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
CStyleUsed structStyle(oStyle, false);
|
||||
|
||||
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
|
||||
|
||||
if (oItem != m_arStyleUsed.end())
|
||||
{
|
||||
m_sId = (*oItem).getId();
|
||||
return;
|
||||
}
|
||||
CXmlElement oXmlElement;
|
||||
SetRStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oStyle.Empty() || !oXmlElement.Empty())
|
||||
{
|
||||
structStyle.setId(oXmlElement.GetStyleId());
|
||||
m_arStyleUsed.push_back(structStyle);
|
||||
m_sStyle += oXmlElement.GetRStyle();
|
||||
}
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteLitePStyle(const CCompiledStyle &oStyle)
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
return;
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetPStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oXmlElement.Empty())
|
||||
m_sStyle += oXmlElement.GetLitePStyle();
|
||||
}
|
||||
|
||||
void CDocumentStyle::WriteLiteRStyle(const CCompiledStyle &oStyle)
|
||||
{
|
||||
if (oStyle.Empty())
|
||||
return;
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetRStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oXmlElement.Empty())
|
||||
m_sStyle += oXmlElement.GetLiteRStyle();
|
||||
}
|
||||
|
||||
void CDocumentStyle::WritePStyle (const NSCSS::CCompiledStyle& oStyle)
|
||||
{
|
||||
if(oStyle.GetId().empty())
|
||||
{
|
||||
m_sId = L"normal";
|
||||
return;
|
||||
}
|
||||
|
||||
CStyleUsed structStyle(oStyle, true);
|
||||
std::list<CStyleUsed>::iterator oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), structStyle);
|
||||
|
||||
if (oItem != m_arStyleUsed.end())
|
||||
{
|
||||
m_sId = (*oItem).getId();
|
||||
return;
|
||||
}
|
||||
|
||||
CXmlElement oXmlElement;
|
||||
SetPStyle(oStyle, oXmlElement);
|
||||
|
||||
if (!oStyle.Empty() || !oXmlElement.Empty())
|
||||
{
|
||||
structStyle.setId(oXmlElement.GetStyleId());
|
||||
m_arStyleUsed.push_back(structStyle);
|
||||
m_sStyle += oXmlElement.GetPStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,68 +4,57 @@
|
||||
#include "../CssCalculator_global.h"
|
||||
#include "../CCompiledStyle.h"
|
||||
#include "CXmlElement.h"
|
||||
#include <list>
|
||||
|
||||
#include <iostream>
|
||||
namespace NSCSS
|
||||
{
|
||||
class CStyleUsed
|
||||
{
|
||||
CCompiledStyle m_oStyle;
|
||||
bool m_bIsPStyle;
|
||||
std::wstring m_sId;
|
||||
class CStyleUsed
|
||||
{
|
||||
CCompiledStyle m_oStyle;
|
||||
bool m_bIsPStyle;
|
||||
std::wstring m_sId;
|
||||
|
||||
public:
|
||||
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle) : m_oStyle(oStyle), m_bIsPStyle(bIsPStyle) {}
|
||||
public:
|
||||
CStyleUsed(const CCompiledStyle& oStyle, bool bIsPStyle);
|
||||
|
||||
bool operator==(const CStyleUsed& oUsedStyle) const
|
||||
{
|
||||
return (m_bIsPStyle == oUsedStyle.m_bIsPStyle) && (m_oStyle == oUsedStyle.m_oStyle);
|
||||
}
|
||||
bool operator==(const CStyleUsed& oUsedStyle) const;
|
||||
|
||||
std::wstring getId()
|
||||
{
|
||||
return m_sId;
|
||||
}
|
||||
std::wstring getId();
|
||||
void setId(const std::wstring& sId);
|
||||
};
|
||||
|
||||
void setId(const std::wstring& sId)
|
||||
{
|
||||
m_sId = sId;
|
||||
}
|
||||
class CSSCALCULATOR_EXPORT CDocumentStyle
|
||||
{
|
||||
std::list<std::wstring> m_arStandardStylesUsed;
|
||||
std::list<std::wstring> m_arStandardStyles;
|
||||
std::list<CStyleUsed> m_arStyleUsed;
|
||||
|
||||
};
|
||||
std::wstring m_sStyle;
|
||||
std::wstring m_sId;
|
||||
|
||||
class CSSCALCULATOR_EXPORT CDocumentStyle
|
||||
{
|
||||
std::list<std::wstring> m_arStandardStylesUsed;
|
||||
std::list<std::wstring> m_arStandardStyles;
|
||||
std::list<CStyleUsed> m_arStyleUsed;
|
||||
void CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
|
||||
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
|
||||
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
|
||||
|
||||
std::wstring m_sStyle;
|
||||
std::wstring m_sId;
|
||||
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
|
||||
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
|
||||
|
||||
void CombineStandardStyles(const std::vector<std::wstring>& arStandartedStyles, CXmlElement& oElement);
|
||||
void CreateStandardStyle (const std::wstring& sNameStyle, CXmlElement& oElement);
|
||||
void ConvertStyle (const NSCSS::CCompiledStyle& oStyle, CXmlElement& oElement, bool bIsPStyle);
|
||||
public:
|
||||
CDocumentStyle();
|
||||
~CDocumentStyle();
|
||||
|
||||
void SetRStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
|
||||
void SetPStyle(const NSCSS::CCompiledStyle& oStyle, CXmlElement& oXmlElement);
|
||||
void WritePStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteRStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteLitePStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteLiteRStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
|
||||
public:
|
||||
CDocumentStyle();
|
||||
~CDocumentStyle();
|
||||
void SetStyle(const std::wstring& sStyle);
|
||||
void SetId (const std::wstring& sId);
|
||||
|
||||
void WritePStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteRStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteLitePStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
void WriteLiteRStyle(const NSCSS::CCompiledStyle& oStyle);
|
||||
std::wstring GetStyle() const;
|
||||
std::wstring GetIdAndClear();
|
||||
|
||||
void SetStyle(const std::wstring& sStyle);
|
||||
void SetId (const std::wstring& sId);
|
||||
|
||||
std::wstring GetStyle() const;
|
||||
std::wstring GetIdAndClear();
|
||||
|
||||
void Clear();
|
||||
};
|
||||
void Clear();
|
||||
};
|
||||
}
|
||||
#endif // CDOCUMENTSTYLE_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -4,44 +4,46 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "../ConstValues.h"
|
||||
#include "list"
|
||||
|
||||
|
||||
namespace { namespace CSSProperties = NSCSS::NSConstValues::NSProperties; }
|
||||
|
||||
class CXmlElement
|
||||
{
|
||||
std::map<NSCSS::NSConstValues::NSProperties::RunnerProperties, std::wstring> m_mRStyleValues;
|
||||
std::map<NSCSS::NSConstValues::NSProperties::ParagraphProperties, std::wstring> m_mPStyleValues;
|
||||
std::map<NSCSS::NSConstValues::NSProperties::BasicProperties, std::wstring> m_mBasicValues;
|
||||
std::map<CSSProperties::RunnerProperties, std::wstring> m_mRStyleValues;
|
||||
std::map<CSSProperties::ParagraphProperties, std::wstring> m_mPStyleValues;
|
||||
std::map<CSSProperties::BasicProperties, std::wstring> m_mBasicValues;
|
||||
|
||||
std::wstring ConvertPStyle() const;
|
||||
std::wstring ConvertRStyle() const;
|
||||
std::wstring ConvertBasicInfoStyle() const;
|
||||
std::wstring ConvertPStyle() const;
|
||||
std::wstring ConvertRStyle() const;
|
||||
std::wstring ConvertBasicInfoStyle() const;
|
||||
|
||||
public:
|
||||
CXmlElement();
|
||||
CXmlElement(const std::wstring& sNameDefaultElement);
|
||||
~CXmlElement();
|
||||
CXmlElement();
|
||||
CXmlElement(const std::wstring& sNameDefaultElement);
|
||||
~CXmlElement();
|
||||
|
||||
bool Empty() const;
|
||||
bool Empty() const;
|
||||
|
||||
void CreateDefaultElement(const std::wstring& sNameDefaultElement);
|
||||
void Clear();
|
||||
void CreateDefaultElement(const std::wstring& sNameDefaultElement);
|
||||
void Clear();
|
||||
|
||||
void AddPropertiesInP (const NSCSS::NSConstValues::NSProperties::ParagraphProperties& nProperties, const std::wstring& sValue);
|
||||
void AddPropertiesInR (const NSCSS::NSConstValues::NSProperties::RunnerProperties& nProperties, const std::wstring& sValue);
|
||||
void AddBasicProperties(const NSCSS::NSConstValues::NSProperties::BasicProperties& nProperties, const std::wstring& sValue);
|
||||
void AddPropertiesInP (const CSSProperties::ParagraphProperties& enProperties, const std::wstring& sValue);
|
||||
void AddPropertiesInR (const CSSProperties::RunnerProperties& enProperties, const std::wstring& sValue);
|
||||
void AddBasicProperties(const CSSProperties::BasicProperties& enProperties, const std::wstring& sValue);
|
||||
|
||||
std::wstring GetLitePStyle() const;
|
||||
std::wstring GetLiteRStyle() const;
|
||||
std::wstring GetPStyle() const;
|
||||
std::wstring GetRStyle() const;
|
||||
std::wstring GetStyle() const;
|
||||
std::wstring GetBasedOn() const;
|
||||
std::wstring GetStyleId() const;
|
||||
std::wstring GetName() const;
|
||||
std::wstring GetLitePStyle() const;
|
||||
std::wstring GetLiteRStyle() const;
|
||||
std::wstring GetPStyle() const;
|
||||
std::wstring GetRStyle() const;
|
||||
std::wstring GetStyle() const;
|
||||
std::wstring GetBasedOn() const;
|
||||
std::wstring GetStyleId() const;
|
||||
std::wstring GetName() const;
|
||||
|
||||
CXmlElement& operator+=(const CXmlElement& oElement);
|
||||
CXmlElement& operator= (const CXmlElement& oelement);
|
||||
bool operator== (const CXmlElement& oElement);
|
||||
CXmlElement& operator+=(const CXmlElement& oElement);
|
||||
CXmlElement& operator= (const CXmlElement& oelement);
|
||||
bool operator== (const CXmlElement& oElement);
|
||||
};
|
||||
|
||||
#endif // CXMLELEMENT_H
|
||||
|
||||
@ -21,8 +21,8 @@ if not base.is_dir("katana-parser"):
|
||||
base.cmd_in_dir("katana-parser", "git", ["checkout", "be6df458d4540eee375c513958dcb862a391cdd1"])
|
||||
|
||||
# fix katana
|
||||
base.replaceInFile(base_directory + "/katana-parser/src/tokenizer.c", "static inline bool katana_is_html_space(char c);", "static inline bool2 katana_is_html_space(char c);")
|
||||
base.replaceInFile(base_directory + "/katana-parser/src/tokenizer.c", "inline bool katana_is_html_space(char c)", "static inline bool katana_is_html_space(char c)")
|
||||
base.replaceInFile(base_directory + "/katana-parser/src/tokenizer.c", "static inline bool2 katana_is_html_space(char c);", "static inline bool katana_is_html_space(char c);")
|
||||
base.replaceInFile(base_directory + "/katana-parser/src/parser.c", "katanaget_text(parser->scanner)", "/*katanaget_text(parser->scanner)*/\"error\"")
|
||||
base.replaceInFile(base_directory + "/katana-parser/src/parser.c", "#define KATANA_PARSER_STRING(literal) (KatanaParserString){", "#define KATANA_PARSER_STRING(literal) {")
|
||||
base.replaceInFileUtf8(base_directory + "/katana-parser/src/tokenizer.c", "static inline bool katana_is_html_space(char c);", "static inline bool2 katana_is_html_space(char c);")
|
||||
base.replaceInFileUtf8(base_directory + "/katana-parser/src/tokenizer.c", "inline bool katana_is_html_space(char c)", "static inline bool katana_is_html_space(char c)")
|
||||
base.replaceInFileUtf8(base_directory + "/katana-parser/src/tokenizer.c", "static inline bool2 katana_is_html_space(char c);", "static inline bool katana_is_html_space(char c);")
|
||||
base.replaceInFileUtf8(base_directory + "/katana-parser/src/parser.c", "katanaget_text(parser->scanner)", "/*katanaget_text(parser->scanner)*/\"error\"")
|
||||
base.replaceInFileUtf8(base_directory + "/katana-parser/src/parser.c", "#define KATANA_PARSER_STRING(literal) (KatanaParserString){", "#define KATANA_PARSER_STRING(literal) {")
|
||||
|
||||
@ -677,13 +677,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static std::wstring msLCID2wstring(int id)
|
||||
{
|
||||
MS_LCID_converter lcid;
|
||||
return lcid.get_wstring(id);
|
||||
}
|
||||
static int msLCID2DefCodePage(int id)
|
||||
{
|
||||
MS_LCID_converter lcid;
|
||||
return lcid.get_codepage(id);
|
||||
}
|
||||
//static std::wstring msLCID2wstring(int id)
|
||||
//{
|
||||
// MS_LCID_converter lcid;
|
||||
// return lcid.get_wstring(id);
|
||||
//}
|
||||
//static int msLCID2DefCodePage(int id)
|
||||
//{
|
||||
// MS_LCID_converter lcid;
|
||||
// return lcid.get_codepage(id);
|
||||
//}
|
||||
@ -49,7 +49,7 @@ namespace NSNetwork
|
||||
void SetProperty(const std::string& name, const std::string& value);
|
||||
void Initialize();
|
||||
|
||||
private:
|
||||
public:
|
||||
CSession_private* m_pInternal;
|
||||
};
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ namespace ASC
|
||||
|
||||
public:
|
||||
virtual std::wstring GetPath() = 0;
|
||||
virtual std::wstring GetUrl() = 0;
|
||||
virtual DownloadStatus GetStatus() = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ namespace NSNetwork
|
||||
if (iter != m_props.end())
|
||||
configuration.allowsCellularAccess = (std::stoi(iter->second) == 1) ? YES : NO;
|
||||
|
||||
iter = m_props.find("allowsCellularAccess");
|
||||
iter = m_props.find("requestCachePolicy");
|
||||
if (iter != m_props.end())
|
||||
{
|
||||
if ("NSURLRequestUseProtocolCachePolicy" == iter->second)
|
||||
@ -157,7 +157,11 @@ namespace NSNetwork
|
||||
__block NSData* result = nil;
|
||||
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
|
||||
|
||||
[[((CSessionMAC*)m_pSession)->m_session dataTaskWithRequest:urlRequest
|
||||
NSURLSession* _session = ((CSessionMAC*)m_pSession->m_pInternal)->m_session;
|
||||
if (nil == _session)
|
||||
_session = [NSURLSession sharedSession];
|
||||
|
||||
[[_session dataTaskWithRequest:urlRequest
|
||||
completionHandler:^(NSData *data, NSURLResponse* response, NSError *error) {
|
||||
if (error == nil)
|
||||
result = data;
|
||||
@ -174,8 +178,10 @@ namespace NSNetwork
|
||||
|
||||
nResult = 0;
|
||||
}
|
||||
|
||||
nResult = 1;
|
||||
else
|
||||
{
|
||||
nResult = 1;
|
||||
}
|
||||
|
||||
return nResult;
|
||||
}
|
||||
|
||||
@ -77,6 +77,10 @@ namespace ASC
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
std::wstring GetUrl()
|
||||
{
|
||||
return Url;
|
||||
}
|
||||
};
|
||||
|
||||
class CDownloadManager_private
|
||||
@ -125,7 +129,7 @@ namespace ASC
|
||||
pTask->Handler = handler;
|
||||
pTask->ID = m_nTaskID++;
|
||||
|
||||
if (m_nMaxConcurrentDownloadCount < (int)m_arTasks.size())
|
||||
if (m_nMaxConcurrentDownloadCount > (int)m_arTasks.size())
|
||||
{
|
||||
m_arTasks.push_back(pTask);
|
||||
pTask->DestroyOnFinish();
|
||||
@ -141,7 +145,7 @@ namespace ASC
|
||||
|
||||
void OnDownloadTask(CDownloadTask* task)
|
||||
{
|
||||
CTemporaryCS oCS(&m_oCS);
|
||||
m_oCS.Enter();
|
||||
|
||||
for (std::list<CDownloadTask*>::iterator iter = m_arTasks.begin(); iter != m_arTasks.end(); iter++)
|
||||
{
|
||||
@ -152,6 +156,19 @@ namespace ASC
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_arWaitTasks.empty())
|
||||
{
|
||||
std::list<CDownloadTask*>::iterator iter = m_arWaitTasks.begin();
|
||||
CDownloadTask* pNewTask = *iter;
|
||||
m_arWaitTasks.erase(iter);
|
||||
|
||||
m_arTasks.push_back(pNewTask);
|
||||
pNewTask->DestroyOnFinish();
|
||||
pNewTask->Start(m_nPriority);
|
||||
}
|
||||
|
||||
m_oCS.Leave();
|
||||
|
||||
if (task->Handler)
|
||||
task->Handler(task);
|
||||
}
|
||||
@ -178,19 +195,24 @@ namespace ASC
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
CTemporaryCS oCS(&m_oCS);
|
||||
|
||||
for (std::list<CDownloadTask*>::iterator iter = m_arTasks.begin(); iter != m_arTasks.end(); iter++)
|
||||
{
|
||||
(*iter)->Handler = nullptr;
|
||||
}
|
||||
|
||||
m_oCS.Enter();
|
||||
|
||||
for (std::list<CDownloadTask*>::iterator iter = m_arWaitTasks.begin(); iter != m_arWaitTasks.end();)
|
||||
{
|
||||
CDownloadTask* pTask = *iter;
|
||||
delete pTask;
|
||||
}
|
||||
m_arWaitTasks.clear();
|
||||
|
||||
for (std::list<CDownloadTask*>::iterator iter = m_arTasks.begin(); iter != m_arTasks.end(); iter++)
|
||||
{
|
||||
(*iter)->Handler = nullptr;
|
||||
}
|
||||
|
||||
m_oCS.Leave();
|
||||
|
||||
while (!m_arTasks.empty())
|
||||
NSThreads::Sleep(100);
|
||||
}
|
||||
};
|
||||
|
||||
@ -256,9 +278,6 @@ namespace ASC
|
||||
bool CDownloadManager::DownloadExternal(const std::wstring& url, const std::wstring& path)
|
||||
{
|
||||
NSNetwork::NSFileTransport::CFileDownloader oDownloader(url, false);
|
||||
NSNetwork::NSFileTransport::CSession oSession;
|
||||
oDownloader.SetSession(&oSession);
|
||||
|
||||
oDownloader.SetFilePath(path);
|
||||
|
||||
oDownloader.Start( 0 );
|
||||
|
||||
@ -59,8 +59,9 @@ libsocketio {
|
||||
_WEBSOCKETPP_CPP11_CHRONO_ \
|
||||
\
|
||||
"SIO_TLS=1" \
|
||||
"SIO_TLS_NO=0" \
|
||||
"PING_TIMEOUT_INTERVAL=20000"
|
||||
"SIO_TLS_NO=0"
|
||||
|
||||
#DEFINES += "PING_TIMEOUT_INTERVAL=20000"
|
||||
|
||||
include($$PWD/../../3dParty/boost/boost.pri)
|
||||
|
||||
|
||||
@ -243,3 +243,4 @@
|
||||
#define AVS_FILEUTILS_ERROR_CONVERT_ICU (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005c)
|
||||
#define AVS_FILEUTILS_ERROR_CONVERT_LIMITS (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005d)
|
||||
#define AVS_FILEUTILS_ERROR_CONVERT_ROWLIMITS (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005e)
|
||||
#define AVS_FILEUTILS_ERROR_CONVERT_DETECT (AVS_ERROR_FIRST + AVS_FILEUTILS_ERROR_FIRST + 0x005f)
|
||||
|
||||
@ -16,14 +16,6 @@
|
||||
#ifndef AGG_SPAN_GRADIENT_INCLUDED
|
||||
#define AGG_SPAN_GRADIENT_INCLUDED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../../graphics/structures.h"
|
||||
#include "agg_math.h"
|
||||
#include "agg_array.h"
|
||||
#include "agg_trans_affine.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "./test_grads/custom_gradients.h"
|
||||
namespace agg
|
||||
{
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "../../../graphics/AggPlusEnums.h"
|
||||
#include "../../../graphics/structures.h"
|
||||
#include <cmath>
|
||||
#include "agg_math.h"
|
||||
#include "agg_array.h"
|
||||
#include "agg_trans_affine.h"
|
||||
|
||||
#ifndef M_1_PI
|
||||
#define M_1_PI 0.318309886183790671538
|
||||
#endif
|
||||
|
||||
@ -31,25 +31,25 @@
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
#include "windows.h"
|
||||
#include "windef.h"
|
||||
#include <shlobj.h>
|
||||
#include <Rpc.h>
|
||||
#include "windows.h"
|
||||
#include "windef.h"
|
||||
#include <shlobj.h>
|
||||
#include <Rpc.h>
|
||||
#elif __linux__
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#elif MAC
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#elif _IOS
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@ -58,187 +58,187 @@
|
||||
namespace NSDirectory
|
||||
{
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
static bool is_directory_exist(char* dir)
|
||||
{
|
||||
struct stat st;
|
||||
bool bRes = (0 == stat(dir, &st)) && S_ISDIR(st.st_mode);
|
||||
return bRes;
|
||||
}
|
||||
static bool is_directory_exist(char* dir)
|
||||
{
|
||||
struct stat st;
|
||||
bool bRes = (0 == stat(dir, &st)) && S_ISDIR(st.st_mode);
|
||||
return bRes;
|
||||
}
|
||||
|
||||
static bool _mkdir (const char *dir)
|
||||
{
|
||||
char tmp[MAX_PATH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
bool res = true;
|
||||
static bool _mkdir (const char *dir)
|
||||
{
|
||||
char tmp[MAX_PATH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
bool res = true;
|
||||
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
tmp[len - 1] = 0;
|
||||
for(p = tmp + 1; *p; p++)
|
||||
if(*p == '/') {
|
||||
*p = 0;
|
||||
res = is_directory_exist(tmp);
|
||||
if (!res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
*p = '/';
|
||||
if (!res)
|
||||
break;
|
||||
}
|
||||
if (res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU));
|
||||
return res;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
tmp[len - 1] = 0;
|
||||
for(p = tmp + 1; *p; p++)
|
||||
if(*p == '/') {
|
||||
*p = 0;
|
||||
res = is_directory_exist(tmp);
|
||||
if (!res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
*p = '/';
|
||||
if (!res)
|
||||
break;
|
||||
}
|
||||
if (res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU));
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strDirectory + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
GetFiles2(sSpec, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
std::wstring sSpec = strDirectory + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
GetFiles2(sSpec, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MAC) || defined (_IOS)
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion)
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion)
|
||||
{
|
||||
std::vector<std::wstring> oArray;
|
||||
|
||||
if (!strDirectory.empty())
|
||||
{
|
||||
{
|
||||
GetFiles2(strDirectory, oArray, bIsRecursion);
|
||||
}
|
||||
return oArray;
|
||||
}
|
||||
std::vector<std::wstring> GetDirectories(std::wstring strDirectory)
|
||||
std::vector<std::wstring> GetDirectories(std::wstring strDirectory)
|
||||
{
|
||||
std::vector<std::wstring> oArray;
|
||||
|
||||
if (strDirectory.empty()) return oArray;
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strDirectory + L"\\*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return oArray;
|
||||
do
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
if( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
@ -270,54 +270,54 @@ namespace NSDirectory
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
return oArray;
|
||||
}
|
||||
bool Exists(const std::wstring& strDirectory)
|
||||
bool Exists(const std::wstring& strDirectory)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
DWORD dwAttrib = ::GetFileAttributesW(strDirectory.c_str());
|
||||
return (dwAttrib != INVALID_FILE_ATTRIBUTES && 0 != (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
#endif
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
bool CreateDirectory(const std::wstring& strDirectory)
|
||||
bool CreateDirectory(const std::wstring& strDirectory)
|
||||
{
|
||||
if (Exists(strDirectory) == true) return true;
|
||||
|
||||
@ -326,7 +326,7 @@ namespace NSDirectory
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
int nRes = 0;
|
||||
if (stat((char*)pUtf8, &st) == -1) {
|
||||
@ -336,7 +336,7 @@ namespace NSDirectory
|
||||
return 0 == nRes;
|
||||
#endif
|
||||
}
|
||||
bool CreateDirectories(const std::wstring& strDirectory)
|
||||
bool CreateDirectories(const std::wstring& strDirectory)
|
||||
{
|
||||
if (Exists(strDirectory) == true) return true;
|
||||
|
||||
@ -367,119 +367,119 @@ namespace NSDirectory
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion)
|
||||
{
|
||||
if (!NSDirectory::Exists(strDst))
|
||||
NSDirectory::CreateDirectory(strDst);
|
||||
bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion)
|
||||
{
|
||||
if (!NSDirectory::Exists(strDst))
|
||||
NSDirectory::CreateDirectory(strDst);
|
||||
|
||||
#ifdef WIN32
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strSrc + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return false;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sSpec, strDst + L"/" + sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
CopyDirectory(strSrc + L"/" + sSpec, strDst + L"/" + sSpec, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
return true;
|
||||
std::wstring sSpec = strSrc + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return false;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sSpec, strDst + L"/" + sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
CopyDirectory(strSrc + L"/" + sSpec, strDst + L"/" + sSpec, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MAC) || defined (_IOS)
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot)
|
||||
return false;
|
||||
}
|
||||
void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot)
|
||||
{
|
||||
if (strDirectory.empty()) return;
|
||||
|
||||
@ -498,22 +498,22 @@ namespace NSDirectory
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
#endif
|
||||
}
|
||||
std::wstring GetFolderPath(const std::wstring& wsFolderPath)
|
||||
std::wstring GetFolderPath(const std::wstring& wsFolderPath)
|
||||
{
|
||||
int n1 = (int)wsFolderPath.rfind('\\');
|
||||
if (n1 < 0)
|
||||
@ -527,64 +527,64 @@ namespace NSDirectory
|
||||
}
|
||||
return wsFolderPath.substr(0, n1);
|
||||
}
|
||||
std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix)
|
||||
{
|
||||
return NSFile::CFileBinary::CreateTempFileWithUniqueName(strFolderPathRoot, Prefix);
|
||||
}
|
||||
std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
|
||||
{
|
||||
std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix)
|
||||
{
|
||||
return NSFile::CFileBinary::CreateTempFileWithUniqueName(strFolderPathRoot, Prefix);
|
||||
}
|
||||
std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
UUID uuid;
|
||||
RPC_WSTR str_uuid;
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
std::wstring pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
UUID uuid;
|
||||
RPC_WSTR str_uuid;
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
std::wstring pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
|
||||
int attemps = 10;
|
||||
while (!CreateDirectory(pcTemplate))
|
||||
{
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
attemps--;
|
||||
int attemps = 10;
|
||||
while (!CreateDirectory(pcTemplate))
|
||||
{
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
attemps--;
|
||||
|
||||
if (0 == attemps)
|
||||
{
|
||||
pcTemplate = L"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pcTemplate;
|
||||
if (0 == attemps)
|
||||
{
|
||||
pcTemplate = L"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pcTemplate;
|
||||
#else
|
||||
std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX";
|
||||
char *pcRes = mkdtemp(const_cast <char *> (pcTemplate.c_str()));
|
||||
if (NULL == pcRes)
|
||||
return L"";
|
||||
std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX";
|
||||
char *pcRes = mkdtemp(const_cast <char *> (pcTemplate.c_str()));
|
||||
if (NULL == pcRes)
|
||||
return L"";
|
||||
|
||||
std::string sRes = pcRes;
|
||||
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), (LONG)sRes.length());
|
||||
std::string sRes = pcRes;
|
||||
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), (LONG)sRes.length());
|
||||
#endif
|
||||
}
|
||||
std::wstring GetTempPath()
|
||||
{
|
||||
return NSFile::CFileBinary::GetTempPath();
|
||||
}
|
||||
}
|
||||
std::wstring GetTempPath()
|
||||
{
|
||||
return NSFile::CFileBinary::GetTempPath();
|
||||
}
|
||||
|
||||
int GetFilesCount(const std::wstring& path, const bool& recursive)
|
||||
{
|
||||
std::vector<std::wstring> arrFiles = NSDirectory::GetFiles(path, recursive);
|
||||
int GetFilesCount(const std::wstring& path, const bool& recursive)
|
||||
{
|
||||
std::vector<std::wstring> arrFiles = NSDirectory::GetFiles(path, recursive);
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
return (int)arrFiles.size();
|
||||
return (int)arrFiles.size();
|
||||
#endif
|
||||
return (int)arrFiles.size() + 1;
|
||||
// ???
|
||||
}
|
||||
bool PathIsDirectory(const std::wstring& pathName)
|
||||
{
|
||||
return Exists(pathName);
|
||||
}
|
||||
return (int)arrFiles.size() + 1;
|
||||
// ???
|
||||
}
|
||||
bool PathIsDirectory(const std::wstring& pathName)
|
||||
{
|
||||
return Exists(pathName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,41 +46,45 @@
|
||||
#include "File.h"
|
||||
|
||||
#ifndef FILE_SEPARATOR
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '\\'
|
||||
#define FILE_SEPARATOR_STR L"\\"
|
||||
#define FILE_SEPARATOR_STRA "\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '/'
|
||||
#define FILE_SEPARATOR_STR L"/"
|
||||
#define FILE_SEPARATOR_STRA "/"
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '\\'
|
||||
#define FILE_SEPARATOR_STR L"\\"
|
||||
#define FILE_SEPARATOR_STRA "\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '/'
|
||||
#define FILE_SEPARATOR_STR L"/"
|
||||
#define FILE_SEPARATOR_STRA "/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../../Common/kernel_config.h"
|
||||
namespace NSDirectory
|
||||
{
|
||||
KERNEL_DECL std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false);
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
|
||||
KERNEL_DECL std::vector<std::wstring> GetDirectories(std::wstring strDirectory);
|
||||
KERNEL_DECL bool Exists(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectories(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion = true);
|
||||
KERNEL_DECL void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot = true);
|
||||
KERNEL_DECL std::wstring GetFolderPath(const std::wstring& wsFolderPath);
|
||||
KERNEL_DECL std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix);
|
||||
KERNEL_DECL std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot);
|
||||
KERNEL_DECL std::wstring GetTempPath();
|
||||
|
||||
KERNEL_DECL int GetFilesCount(const std::wstring& path, const bool& recursive);
|
||||
KERNEL_DECL bool PathIsDirectory(const std::wstring& pathName);
|
||||
|
||||
#ifdef _IOS
|
||||
KERNEL_DECL void GetFiles2_ios(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion);
|
||||
namespace NSIOS
|
||||
{
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
}
|
||||
#endif
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
|
||||
KERNEL_DECL std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false);
|
||||
KERNEL_DECL std::vector<std::wstring> GetDirectories(std::wstring strDirectory);
|
||||
KERNEL_DECL bool Exists(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectories(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion = true);
|
||||
KERNEL_DECL void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot = true);
|
||||
KERNEL_DECL std::wstring GetFolderPath(const std::wstring& wsFolderPath);
|
||||
KERNEL_DECL std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix);
|
||||
KERNEL_DECL std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot);
|
||||
KERNEL_DECL std::wstring GetTempPath();
|
||||
|
||||
KERNEL_DECL int GetFilesCount(const std::wstring& path, const bool& recursive);
|
||||
KERNEL_DECL bool PathIsDirectory(const std::wstring& pathName);
|
||||
}
|
||||
|
||||
#endif //_BUILD_DIRECTORY_CROSSPLATFORM_H_
|
||||
|
||||
@ -45,10 +45,6 @@
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef _IOS
|
||||
const char* fileSystemRepresentation(const std::wstring& sFileName);
|
||||
#endif
|
||||
|
||||
#ifdef _MAC
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
@ -959,64 +955,15 @@ namespace NSFile
|
||||
return (unsigned long)m_lFilePosition;
|
||||
}
|
||||
|
||||
#ifdef _IOS
|
||||
|
||||
bool CFileBinary::OpenFile(const std::wstring& sFileName, bool bRewrite)
|
||||
{
|
||||
m_pFile = fopen(fileSystemRepresentation(sFileName), bRewrite ? "rb+" : "rb");
|
||||
|
||||
if (NULL == m_pFile) {
|
||||
#if DEBUG
|
||||
// printf ("NSFile::OpenFile - error open file : %s\n",strerror(errno));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(m_pFile, 0, SEEK_END);
|
||||
m_lFileSize = ftell(m_pFile);
|
||||
fseek(m_pFile, 0, SEEK_SET);
|
||||
|
||||
m_lFilePosition = 0;
|
||||
|
||||
if (0 < sFileName.length())
|
||||
{
|
||||
if (((wchar_t)'/') == sFileName.c_str()[sFileName.length() - 1])
|
||||
m_lFileSize = 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
unsigned int err = 0x7FFFFFFF;
|
||||
unsigned int cur = (unsigned int)m_lFileSize;
|
||||
if (err == cur)
|
||||
{
|
||||
CloseFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileBinary::CreateFileW(const std::wstring& sFileName)
|
||||
{
|
||||
m_pFile = fopen(fileSystemRepresentation(sFileName), "wb");
|
||||
|
||||
if (NULL == m_pFile) {
|
||||
#if DEBUG
|
||||
// printf ("NSFile::CreateFileW - error create file : %s\n",strerror(errno));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lFilePosition = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool CFileBinary::OpenFile(const std::wstring& sFileName, bool bRewrite)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64)
|
||||
if ( NULL == (m_pFile = _wfsopen( sFileName.c_str(), bRewrite ? L"rb+" : L"rb", _SH_DENYNO)))
|
||||
return false;
|
||||
#else
|
||||
#ifdef _IOS
|
||||
std::string sFilePath = NSIOS::GetFileSystemRepresentation(sFileName);
|
||||
m_pFile = fopen((char*)sFilePath.c_str(), bRewrite ? "rb+" : "rb");
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
@ -1027,9 +974,10 @@ namespace NSFile
|
||||
return false;
|
||||
|
||||
m_pFile = fopen((char*)pUtf8, bRewrite ? "rb+" : "rb");
|
||||
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (NULL == m_pFile)
|
||||
return false;
|
||||
|
||||
@ -1061,12 +1009,17 @@ namespace NSFile
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64)
|
||||
if ( 0 != _wfopen_s(&m_pFile, sFileName.c_str(), L"wb"))
|
||||
return false;
|
||||
#else
|
||||
#ifdef _IOS
|
||||
std::string sFilePath = NSIOS::GetFileSystemRepresentation(sFileName);
|
||||
m_pFile = fopen((char*)sFilePath.c_str(), "wb");
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
CUtf8Converter::GetUtf8StringFromUnicode(sFileName.c_str(), sFileName.length(), pUtf8, lLen, false);
|
||||
m_pFile = fopen((char*)pUtf8, "wb");
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
#endif
|
||||
if (NULL == m_pFile)
|
||||
return false;
|
||||
@ -1075,8 +1028,6 @@ namespace NSFile
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool CFileBinary::CreateFile(const std::wstring& sFileName)
|
||||
{
|
||||
return CreateFileW(sFileName);
|
||||
@ -1414,6 +1365,12 @@ namespace NSFile
|
||||
close(dst);
|
||||
return (-1 != read_size_marker) ? true : false;
|
||||
#else
|
||||
|
||||
#ifdef _WIN32
|
||||
if (0 != ::CopyFileW(strSrc.c_str(), strDst.c_str(), 1))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
std::ifstream src;
|
||||
std::ofstream dst;
|
||||
|
||||
|
||||
@ -201,6 +201,13 @@ namespace NSFile
|
||||
static bool Encode(BYTE* pDataSrc, int nLenSrc, char*& pDataDst, int& nLenDst, DWORD dwFlags = NSBase64::B64_BASE64_FLAG_NONE);
|
||||
static bool Decode(const char* pDataSrc, int nLenSrc, BYTE*& pDataDst, int& nLenDst);
|
||||
};
|
||||
|
||||
#ifdef _IOS
|
||||
namespace NSIOS
|
||||
{
|
||||
KERNEL_DECL std::string GetFileSystemRepresentation(const std::wstring& path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace NSFile
|
||||
|
||||
@ -31,21 +31,49 @@
|
||||
*/
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#else
|
||||
#include <objc/objc.h>
|
||||
#include <objc/objc.h>
|
||||
#endif
|
||||
|
||||
#include "./File.h"
|
||||
#include <vector>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
const char* fileSystemRepresentation(const std::wstring& sFileName)
|
||||
namespace NSFile
|
||||
{
|
||||
if (sFileName.empty())
|
||||
return NULL;
|
||||
NSString *path = [[NSString alloc] initWithBytes:(char*)sFileName.data()
|
||||
length:sFileName.size()* sizeof(wchar_t)
|
||||
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE)];
|
||||
namespace NSIOS
|
||||
{
|
||||
std::string GetFileSystemRepresentation(const std::wstring& path)
|
||||
{
|
||||
if (path.empty())
|
||||
return "";
|
||||
|
||||
return (const char*)[path fileSystemRepresentation];
|
||||
NSString* _path = [[NSString alloc] initWithBytes:(char*)path.data() length:path.size() * sizeof(wchar_t)
|
||||
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE)];
|
||||
|
||||
return std::string((const char*)[_path fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace NSDirectory
|
||||
{
|
||||
namespace NSIOS
|
||||
{
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
NSStringEncoding pEncode = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE );
|
||||
|
||||
NSString* directoryPath = [[NSString alloc] initWithBytes : (char*)strDirectory.data()
|
||||
length : strDirectory.size() * sizeof(wchar_t) encoding : pEncode];
|
||||
|
||||
NSArray* directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL];
|
||||
for (int count = 0; count < (int)[directoryContent count]; count++)
|
||||
{
|
||||
NSData* pSData = [[directoryContent objectAtIndex:count] dataUsingEncoding : pEncode];
|
||||
oArray.emplace_back(std::wstring((wchar_t*)[pSData bytes], [pSData length] / sizeof (wchar_t)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,49 +43,49 @@ class IGrObject
|
||||
protected:
|
||||
|
||||
#ifdef __APPLE__
|
||||
volatile int32_t m_lRef;
|
||||
volatile int32_t m_lRef;
|
||||
#else
|
||||
ULONG m_lRef;
|
||||
ULONG m_lRef;
|
||||
#endif
|
||||
|
||||
public:
|
||||
IGrObject()
|
||||
{
|
||||
m_lRef = 1;
|
||||
}
|
||||
IGrObject()
|
||||
{
|
||||
m_lRef = 1;
|
||||
}
|
||||
|
||||
virtual ~IGrObject()
|
||||
{
|
||||
}
|
||||
virtual ~IGrObject()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
OSAtomicIncrement32(&m_lRef);
|
||||
return (ULONG)m_lRef;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
int32_t ret = OSAtomicDecrement32(&m_lRef);
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
OSAtomicIncrement32(&m_lRef);
|
||||
return (ULONG)m_lRef;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
int32_t ret = OSAtomicDecrement32(&m_lRef);
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
|
||||
return (ULONG)ret;
|
||||
}
|
||||
return (ULONG)ret;
|
||||
}
|
||||
#else
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
++m_lRef;
|
||||
return m_lRef;
|
||||
}
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
++m_lRef;
|
||||
return m_lRef;
|
||||
}
|
||||
|
||||
virtual ULONG Release()
|
||||
{
|
||||
ULONG ret = --m_lRef;
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
return ret;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
ULONG ret = --m_lRef;
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -124,10 +124,15 @@ namespace NSSystemPath
|
||||
int nCurrentW = 0;
|
||||
bool bIsUp = false;
|
||||
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
if (pData[nCurrent] == '/' || pData[nCurrent] == '\\')
|
||||
{
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
pDataNorm[nCurrentW++] = pData[nCurrent];
|
||||
#endif
|
||||
++nCurrentSlash;
|
||||
pSlashPoints[nCurrentSlash] = nCurrentW;
|
||||
}
|
||||
|
||||
while (nCurrent < nLen)
|
||||
{
|
||||
if (pData[nCurrent] == '/' || pData[nCurrent] == '\\')
|
||||
|
||||
@ -78,9 +78,9 @@ namespace NSStringUtils
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
if (m_lSize > 10485760/*10 * 1024 * 1024*/)
|
||||
if (m_lSize > 10485760/*10 * 1024 * 1024*/)
|
||||
{
|
||||
m_lSize += (std::max)((int)nSize * 10, 1048576/*1024 * 1024*/);
|
||||
m_lSize += (std::max)((int)nSize * 10, 1048576/*1024 * 1024*/);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -218,9 +218,9 @@ namespace NSStringUtils
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
if (m_lSize > 10485760/*10 * 1024 * 1024*/)
|
||||
if (m_lSize > 10485760/*10 * 1024 * 1024*/)
|
||||
{
|
||||
m_lSize += (std::max)((int)nSize * 10, 1048576/*1024 * 1024*/);
|
||||
m_lSize += (std::max)((int)nSize * 10, 1048576/*1024 * 1024*/);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -252,17 +252,17 @@ namespace NSStringUtils
|
||||
ClearNoAttack();
|
||||
WriteString(bsText);
|
||||
|
||||
for (size_t i = 0; i < m_lSizeCur; ++i)
|
||||
for (size_t i = 0; i < m_lSizeCur; ++i)
|
||||
{
|
||||
if (WCHAR(8233) == m_pData[i])
|
||||
m_pData[i] = WCHAR(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void CStringBuilder::operator+=(const std::wstring& oTemp)
|
||||
{
|
||||
WriteString(oTemp.c_str(), oTemp.length());
|
||||
}
|
||||
void CStringBuilder::operator+=(const std::wstring& oTemp)
|
||||
{
|
||||
WriteString(oTemp.c_str(), oTemp.length());
|
||||
}
|
||||
|
||||
void CStringBuilder::WriteStringNoSafe(const wchar_t* pString, size_t nLen)
|
||||
{
|
||||
@ -604,17 +604,17 @@ namespace NSStringUtils
|
||||
std::wstring str(m_pData, (int)m_lSizeCur);
|
||||
return str;
|
||||
}
|
||||
std::wstring CStringBuilder::GetSubData(const size_t& start, const size_t& count)
|
||||
{
|
||||
if (start >= m_lSizeCur)
|
||||
return L"";
|
||||
std::wstring CStringBuilder::GetSubData(const size_t& start, const size_t& count)
|
||||
{
|
||||
if (start >= m_lSizeCur)
|
||||
return L"";
|
||||
|
||||
size_t nCountMax = m_lSizeCur - start;
|
||||
if (count != std::wstring::npos && count <= nCountMax)
|
||||
nCountMax = count;
|
||||
size_t nCountMax = m_lSizeCur - start;
|
||||
if (count != std::wstring::npos && count <= nCountMax)
|
||||
nCountMax = count;
|
||||
|
||||
return std::wstring(m_pData + start, nCountMax);
|
||||
}
|
||||
return std::wstring(m_pData + start, nCountMax);
|
||||
}
|
||||
|
||||
wchar_t* CStringBuilder::GetBuffer()
|
||||
{
|
||||
@ -676,14 +676,14 @@ namespace NSStringUtils
|
||||
{
|
||||
if (0 == val)
|
||||
{
|
||||
*m_pDataCur++ = (wchar_t)'0';
|
||||
*m_pDataCur++ = (wchar_t)'0';
|
||||
++m_lSizeCur;
|
||||
return;
|
||||
}
|
||||
if (val < 0)
|
||||
{
|
||||
val = -val;
|
||||
*m_pDataCur++ = (wchar_t)'-';
|
||||
*m_pDataCur++ = (wchar_t)'-';
|
||||
++m_lSizeCur;
|
||||
}
|
||||
|
||||
@ -698,7 +698,7 @@ namespace NSStringUtils
|
||||
oval = 1;
|
||||
while (val > 0)
|
||||
{
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + (val % 10));
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + (val % 10));
|
||||
++oval;
|
||||
val /= 10;
|
||||
}
|
||||
@ -711,14 +711,14 @@ namespace NSStringUtils
|
||||
{
|
||||
if (0 == val)
|
||||
{
|
||||
*m_pDataCur++ = (wchar_t)'0';
|
||||
*m_pDataCur++ = (wchar_t)'0';
|
||||
++m_lSizeCur;
|
||||
return;
|
||||
}
|
||||
if (val < 0)
|
||||
{
|
||||
val = -val;
|
||||
*m_pDataCur++ = (wchar_t)'-';
|
||||
*m_pDataCur++ = (wchar_t)'-';
|
||||
++m_lSizeCur;
|
||||
}
|
||||
|
||||
@ -735,9 +735,9 @@ namespace NSStringUtils
|
||||
if (0 != nLastS)
|
||||
{
|
||||
++len;
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + nLastS);
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + nLastS);
|
||||
++oval;
|
||||
m_pDataCur[len - oval] = (wchar_t)('.');
|
||||
m_pDataCur[len - oval] = (wchar_t)('.');
|
||||
++oval;
|
||||
val /= 10;
|
||||
}
|
||||
@ -749,7 +749,7 @@ namespace NSStringUtils
|
||||
|
||||
while (val > 0)
|
||||
{
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + (val % 10));
|
||||
m_pDataCur[len - oval] = (wchar_t)('0' + (val % 10));
|
||||
++oval;
|
||||
val /= 10;
|
||||
}
|
||||
@ -852,14 +852,14 @@ namespace NSStringUtils
|
||||
WriteHexByteNoSafe((value >> 8) & 0xFF);
|
||||
WriteHexByteNoSafe(value & 0xFF);
|
||||
}
|
||||
void CStringBuilder::WriteHexInt4(const unsigned int& value)
|
||||
{
|
||||
AddSize(8);
|
||||
WriteHexByteNoSafe((value >> 24) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 16) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 8) & 0xFF);
|
||||
WriteHexByteNoSafe(value & 0xFF);
|
||||
}
|
||||
void CStringBuilder::WriteHexInt4(const unsigned int& value)
|
||||
{
|
||||
AddSize(8);
|
||||
WriteHexByteNoSafe((value >> 24) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 16) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 8) & 0xFF);
|
||||
WriteHexByteNoSafe(value & 0xFF);
|
||||
}
|
||||
void CStringBuilder::WriteHexColor3(const unsigned char& r, const unsigned char& g, const unsigned char& b)
|
||||
{
|
||||
AddSize(7);
|
||||
@ -874,16 +874,16 @@ namespace NSStringUtils
|
||||
AddSize(7);
|
||||
*m_pDataCur++ = (wchar_t)'#';
|
||||
++m_lSizeCur;
|
||||
WriteHexByteNoSafe(value & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 8) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 16) & 0xFF);
|
||||
WriteHexByteNoSafe(value & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 8) & 0xFF);
|
||||
WriteHexByteNoSafe((value >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
void CStringBuilder::Skip(int nSkip)
|
||||
{
|
||||
m_pDataCur += nSkip;
|
||||
m_lSizeCur += nSkip;
|
||||
}
|
||||
void CStringBuilder::Skip(int nSkip)
|
||||
{
|
||||
m_pDataCur += nSkip;
|
||||
m_lSizeCur += nSkip;
|
||||
}
|
||||
void CStringBuilder::StartNode(const std::wstring& name)
|
||||
{
|
||||
WriteString(g_bstr_nodeopen);
|
||||
@ -1121,22 +1121,22 @@ namespace NSStringUtils
|
||||
return 0;
|
||||
}
|
||||
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,6 +548,8 @@ namespace NSDoctRenderer
|
||||
|
||||
bool ExecuteScript(const std::string& strScript, const std::wstring& sCachePath, std::wstring& strError, std::wstring& strReturnParams)
|
||||
{
|
||||
if (strScript.empty() && sCachePath.empty()) return true;
|
||||
|
||||
LOGGER_SPEED_START();
|
||||
|
||||
bool bIsBreak = false;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define NSHASH_H
|
||||
|
||||
#include <functional>
|
||||
#include <stddef.h>
|
||||
#include "./common.h"
|
||||
|
||||
// hide algs into lib
|
||||
|
||||
@ -1649,7 +1649,7 @@ static long GetNextNameValue(HKEY key, const std::wstring& sSubkey, std::wstring
|
||||
if (hkey)
|
||||
RegCloseKey(hkey);
|
||||
hkey = NULL;
|
||||
return ERROR_SUCCESS;
|
||||
return ERROR_SUCCESS + 1;
|
||||
}
|
||||
|
||||
// if subkey is specified then open key (first time)
|
||||
@ -1749,6 +1749,10 @@ std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles()
|
||||
}
|
||||
}
|
||||
|
||||
sName = L"";
|
||||
sData = L"";
|
||||
GetNextNameValue(0, L"", sName, sData);
|
||||
|
||||
if (true)
|
||||
{
|
||||
std::vector<std::wstring> oArray2 = NSDirectory::GetFiles(L"C:\\Windows\\Fonts", true);
|
||||
@ -1794,8 +1798,10 @@ std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles()
|
||||
#endif
|
||||
|
||||
#ifdef _IOS
|
||||
// own realization (objective c code)
|
||||
return GetSetupFontFiles_ios();
|
||||
std::vector<std::wstring> _array = NSDirectory::GetFiles(L"/System/Library/Fonts", true);
|
||||
if (_array.empty())
|
||||
NSDirectory::GetFiles2(L"/Library/Fonts", _array, true);
|
||||
return _array;
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@ -351,10 +351,6 @@ public:
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
void InitFromReg();
|
||||
#endif
|
||||
|
||||
#ifdef _IOS
|
||||
std::vector<std::wstring> GetSetupFontFiles_ios();
|
||||
#endif
|
||||
|
||||
NSFonts::IFontManager* GenerateFontManager();
|
||||
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "ApplicationFonts.h"
|
||||
#include "../common/Directory.h"
|
||||
|
||||
#ifdef BOOL
|
||||
#undef BOOL
|
||||
#endif
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles_ios()
|
||||
{
|
||||
std::vector<std::wstring> oArray;
|
||||
NSDirectory::GetFiles2(L"/System/Library/Fonts", oArray, true);
|
||||
|
||||
if (oArray.size() == 0)
|
||||
{
|
||||
NSDirectory::GetFiles2(L"/Library/Fonts", oArray, true);
|
||||
}
|
||||
|
||||
return oArray;
|
||||
}
|
||||
|
||||
namespace NSDirectory
|
||||
{
|
||||
void GetFiles2_ios(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
NSString* directoryPath = [ [ NSString alloc ]
|
||||
initWithBytes : (char*)strDirectory.data()
|
||||
length : strDirectory.size() * sizeof(wchar_t)
|
||||
encoding : CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE ) ];
|
||||
|
||||
int count;
|
||||
|
||||
NSArray* directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL];
|
||||
for (count = 0; count < (int)[directoryContent count]; count++)
|
||||
{
|
||||
NSStringEncoding pEncode = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE );
|
||||
NSData* pSData = [[ directoryContent objectAtIndex:count] dataUsingEncoding : pEncode ];
|
||||
|
||||
std::wstring sTmp( (wchar_t*) [ pSData bytes ], [ pSData length] / sizeof ( wchar_t ) );
|
||||
oArray.push_back(sTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
DesktopEditor/graphics/AlphaMask.cpp
Normal file
69
DesktopEditor/graphics/AlphaMask.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include "AlphaMask.h"
|
||||
#include "AlphaMask_private.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
CAlphaMask::CAlphaMask()
|
||||
: m_internal(new CAlphaMask_private())
|
||||
{}
|
||||
|
||||
CAlphaMask::~CAlphaMask()
|
||||
{
|
||||
RELEASEOBJECT(m_internal)
|
||||
}
|
||||
|
||||
void CAlphaMask::Clear()
|
||||
{
|
||||
m_internal->Clear();
|
||||
}
|
||||
|
||||
StatusAlphaMask CAlphaMask::GetStatus() const
|
||||
{
|
||||
return m_internal->GetStatus();
|
||||
}
|
||||
AMaskDataType CAlphaMask::GetDataType() const
|
||||
{
|
||||
return m_internal->GetDataType();
|
||||
}
|
||||
|
||||
Status CAlphaMask::CreateImageBuffer(UINT unWidth, UINT unHeight)
|
||||
{
|
||||
return m_internal->Create(unWidth, unHeight, ImageBuffer);
|
||||
}
|
||||
|
||||
Status CAlphaMask::CreateAlphaBuffer(UINT unWidth, UINT unHeight)
|
||||
{
|
||||
return m_internal->Create(unWidth, unHeight, AlphaBuffer);
|
||||
}
|
||||
|
||||
Status CAlphaMask::LoadFromAlphaBuffer(BYTE *pBuffer, UINT unWidth, UINT unHeight, bool bExternalBuffer)
|
||||
{
|
||||
return m_internal->LoadFromBuffer(pBuffer, unWidth, unHeight, AlphaBuffer, bExternalBuffer);
|
||||
}
|
||||
|
||||
Status CAlphaMask::LoadFromImageBuffer(BYTE *pBuffer, UINT unWidth, UINT unHeight, bool bExternalBuffer)
|
||||
{
|
||||
return m_internal->LoadFromBuffer(pBuffer, unWidth, unHeight, ImageBuffer, bExternalBuffer);
|
||||
}
|
||||
|
||||
Status CAlphaMask::LoadFromFile(const std::wstring &wsFilePath)
|
||||
{
|
||||
return m_internal->LoadFromFile(wsFilePath);
|
||||
}
|
||||
|
||||
Status CAlphaMask::LoadFromImage(IGrObject *pGrObject, bool bCopy)
|
||||
{
|
||||
return m_internal->LoadFromImage(pGrObject, bCopy);
|
||||
}
|
||||
|
||||
BYTE *CAlphaMask::GetMask()
|
||||
{
|
||||
return m_internal->GetMask();
|
||||
}
|
||||
|
||||
CAlphaMask &CAlphaMask::operator=(const CAlphaMask &oAlphaMask)
|
||||
{
|
||||
*m_internal = *oAlphaMask.m_internal;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
53
DesktopEditor/graphics/AlphaMask.h
Normal file
53
DesktopEditor/graphics/AlphaMask.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef _BUILD_ALPHAMASK_H_
|
||||
#define _BUILD_ALPHAMASK_H_
|
||||
|
||||
#include <string>
|
||||
#include "aggplustypes.h"
|
||||
#include "../common/IGrObject.h"
|
||||
#include "./config.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
enum StatusAlphaMask
|
||||
{
|
||||
EmptyAlphaMask,
|
||||
GenerationAlphaMask,
|
||||
ApplyingAlphaMask
|
||||
};
|
||||
|
||||
enum AMaskDataType
|
||||
{
|
||||
ImageBuffer,
|
||||
AlphaBuffer
|
||||
};
|
||||
|
||||
class CAlphaMask_private;
|
||||
class GRAPHICS_DECL CAlphaMask : public IGrObject
|
||||
{
|
||||
public:
|
||||
CAlphaMask();
|
||||
virtual ~CAlphaMask();
|
||||
|
||||
StatusAlphaMask GetStatus() const;
|
||||
AMaskDataType GetDataType() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
Status CreateImageBuffer(UINT unWidth, UINT unHeight);
|
||||
Status CreateAlphaBuffer(UINT unWidth, UINT unHeight);
|
||||
|
||||
Status LoadFromAlphaBuffer(BYTE* pBuffer, UINT unWidth, UINT unHeight, bool bExternalBuffer = true);
|
||||
Status LoadFromImageBuffer(BYTE* pBuffer, UINT unWidth, UINT unHeight, bool bExternalBuffer = true);
|
||||
|
||||
Status LoadFromFile(const std::wstring& wsFilePath);
|
||||
Status LoadFromImage(IGrObject* pGrObject, bool bCopy = true);
|
||||
|
||||
BYTE* GetMask();
|
||||
|
||||
CAlphaMask& operator=(const CAlphaMask& oAlphaMask);
|
||||
public:
|
||||
CAlphaMask_private *m_internal;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _BUILD_ALPHAMASK_H_
|
||||
218
DesktopEditor/graphics/AlphaMask_private.cpp
Normal file
218
DesktopEditor/graphics/AlphaMask_private.cpp
Normal file
@ -0,0 +1,218 @@
|
||||
#include "AlphaMask_private.h"
|
||||
#include "../raster/BgraFrame.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
CAlphaMask_private::CAlphaMask_private()
|
||||
: m_enStatus(EmptyAlphaMask), m_pImageData(NULL), m_pAlphaBufferData(NULL)
|
||||
{}
|
||||
|
||||
CAlphaMask_private::~CAlphaMask_private()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
StatusAlphaMask CAlphaMask_private::GetStatus() const
|
||||
{
|
||||
return m_enStatus;
|
||||
}
|
||||
|
||||
AMaskDataType CAlphaMask_private::GetDataType() const
|
||||
{
|
||||
return m_enDataType;
|
||||
}
|
||||
|
||||
void CAlphaMask_private::Clear()
|
||||
{
|
||||
BYTE *pBuffer = m_oRenderingBuffer.buf();
|
||||
if (NULL != pBuffer)
|
||||
{
|
||||
if (!m_bExternalBuffer)
|
||||
RELEASEARRAYOBJECTS(pBuffer);
|
||||
|
||||
m_oRenderingBuffer.attach(NULL, 0, 0, 0);
|
||||
}
|
||||
|
||||
RELEASEOBJECT(m_pImageData)
|
||||
RELEASEOBJECT(m_pAlphaBufferData)
|
||||
|
||||
m_enStatus = EmptyAlphaMask;
|
||||
}
|
||||
|
||||
Status CAlphaMask_private::Create(UINT unWidth, UINT unHeight, AMaskDataType enDataType)
|
||||
{
|
||||
if (0 == unWidth || 0 == unHeight)
|
||||
return InvalidParameter;
|
||||
|
||||
BYTE* pAlphaBufffer = new BYTE[unWidth * unHeight * ((enDataType == ImageBuffer) ? 4 : 1)];
|
||||
|
||||
if (NULL == pAlphaBufffer)
|
||||
return OutOfMemory;
|
||||
|
||||
Set(pAlphaBufffer, unWidth, unHeight, enDataType);
|
||||
|
||||
if (enDataType == ImageBuffer)
|
||||
m_pImageData->m_oRendererBase.clear(agg::rgba8(0, 0, 0));
|
||||
else if (enDataType == AlphaBuffer)
|
||||
m_pAlphaBufferData->m_oRendererBase.clear(agg::gray8(0));
|
||||
|
||||
m_enStatus = GenerationAlphaMask;
|
||||
m_bExternalBuffer = false;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CAlphaMask_private::LoadFromBuffer(BYTE *pBuffer, UINT unWidth, UINT unHeight, AMaskDataType enBufferType, bool bExternalBuffer)
|
||||
{
|
||||
if (NULL == pBuffer || 0 == unWidth || 0 == unHeight)
|
||||
return InvalidParameter;
|
||||
|
||||
Set(pBuffer, unWidth, unHeight, enBufferType);
|
||||
|
||||
m_enStatus = ApplyingAlphaMask;
|
||||
m_bExternalBuffer = bExternalBuffer;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CAlphaMask_private::LoadFromFile(const std::wstring &wsFilePath)
|
||||
{
|
||||
if (wsFilePath.empty())
|
||||
return InvalidParameter;
|
||||
|
||||
CBgraFrame oFrame;
|
||||
|
||||
if (!oFrame.OpenFile(wsFilePath))
|
||||
return GenericError;
|
||||
|
||||
UINT unWidth = oFrame.get_Width();
|
||||
UINT unHeight = oFrame.get_Height();
|
||||
|
||||
Set(oFrame.get_Data(), unWidth, unHeight, ImageBuffer);
|
||||
|
||||
oFrame.put_Data(NULL);
|
||||
|
||||
m_enStatus = ApplyingAlphaMask;
|
||||
m_bExternalBuffer = false;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CAlphaMask_private::LoadFromImage(IGrObject *pGrObject, bool bCopy)
|
||||
{
|
||||
if (NULL == pGrObject)
|
||||
return InvalidParameter;
|
||||
|
||||
CImage *pImage = (CImage*)pGrObject;
|
||||
|
||||
if (Ok != pImage->GetLastStatus())
|
||||
return GenericError;
|
||||
|
||||
UINT unWidth = pImage->GetWidth();
|
||||
UINT unHeight = pImage->GetHeight();
|
||||
|
||||
BYTE *pBuffer = NULL;
|
||||
|
||||
if (bCopy)
|
||||
{
|
||||
const UINT unSize = 4 * unWidth * unWidth;
|
||||
|
||||
pBuffer = new BYTE[unSize];
|
||||
memcpy(pBuffer, pImage->GetData(), unSize);
|
||||
}
|
||||
else
|
||||
pBuffer = pImage->GetData();
|
||||
|
||||
Set(pBuffer, unWidth, unHeight, ImageBuffer);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
RenBaseBGRA32 &CAlphaMask_private::GetRendererBaseImage()
|
||||
{
|
||||
return m_pImageData->m_oRendererBase;
|
||||
}
|
||||
|
||||
ScanlineBGRA32Gray &CAlphaMask_private::GetScanlineImage()
|
||||
{
|
||||
return m_pImageData->m_oScanLine;
|
||||
}
|
||||
|
||||
ScanlineGray8 &CAlphaMask_private::GetScanlineABuffer()
|
||||
{
|
||||
return m_pAlphaBufferData->m_oScanLine;
|
||||
}
|
||||
|
||||
BYTE *CAlphaMask_private::GetMask()
|
||||
{
|
||||
return m_oRenderingBuffer.buf();
|
||||
}
|
||||
|
||||
void CAlphaMask_private::StartApplying()
|
||||
{
|
||||
m_enStatus = ApplyingAlphaMask;
|
||||
}
|
||||
|
||||
CAlphaMask_private &CAlphaMask_private::operator=(const CAlphaMask_private &oAlphaMask)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_enDataType = oAlphaMask.m_enDataType;
|
||||
m_enStatus = oAlphaMask.m_enStatus;
|
||||
m_bExternalBuffer = false;
|
||||
|
||||
if (EmptyAlphaMask == m_enStatus)
|
||||
return *this;
|
||||
|
||||
const UINT unSize = oAlphaMask.m_oRenderingBuffer.width() * oAlphaMask.m_oRenderingBuffer.height() * ((m_enDataType == ImageBuffer) ? 4 : 1);
|
||||
|
||||
BYTE* pBuffer = new BYTE[unSize];
|
||||
|
||||
memcpy(pBuffer, oAlphaMask.m_oRenderingBuffer.buf(), unSize);
|
||||
|
||||
Set(pBuffer, oAlphaMask.m_oRenderingBuffer.width(), oAlphaMask.m_oRenderingBuffer.height(), m_enDataType);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CAlphaMask_private::Set(BYTE *pBuffer, UINT unWidth, UINT unHeight, AMaskDataType enDataType)
|
||||
{
|
||||
Clear();
|
||||
|
||||
m_enDataType = enDataType;
|
||||
|
||||
switch (enDataType)
|
||||
{
|
||||
case ImageBuffer:
|
||||
{
|
||||
m_oRenderingBuffer.attach(pBuffer, unWidth, unHeight, 4 * unWidth);
|
||||
|
||||
m_pImageData = new AMaskFromImage(m_oRenderingBuffer);
|
||||
|
||||
m_pImageData->m_oPixfmt.attach(m_oRenderingBuffer);
|
||||
m_pImageData->m_oRendererBase.attach(m_pImageData->m_oPixfmt);
|
||||
m_pImageData->m_oAlphaMask.attach(m_oRenderingBuffer);
|
||||
|
||||
break;
|
||||
}
|
||||
case AlphaBuffer:
|
||||
{
|
||||
m_oRenderingBuffer.attach(pBuffer, unWidth, unHeight, unWidth);
|
||||
|
||||
m_pAlphaBufferData = new AMaskFromABuffer(m_oRenderingBuffer);
|
||||
|
||||
m_pAlphaBufferData->m_oPixfmt.attach(m_oRenderingBuffer);
|
||||
m_pAlphaBufferData->m_oRendererBase.attach(m_pAlphaBufferData->m_oPixfmt);
|
||||
m_pAlphaBufferData->m_oAlphaMask.attach(m_oRenderingBuffer);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
agg::rendering_buffer &CAlphaMask_private::GetRenderingBuffer()
|
||||
{
|
||||
return m_oRenderingBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
78
DesktopEditor/graphics/AlphaMask_private.h
Normal file
78
DesktopEditor/graphics/AlphaMask_private.h
Normal file
@ -0,0 +1,78 @@
|
||||
#ifndef _BUILD_ALPHAMASK_PRIVATE_H_
|
||||
#define _BUILD_ALPHAMASK_PRIVATE_H_
|
||||
|
||||
#include <string>
|
||||
#include "aggplustypes.h"
|
||||
#include "./AlphaMask.h"
|
||||
|
||||
#include "../agg-2.4/include/agg_alpha_mask_u8.h"
|
||||
#include "../agg-2.4/include/agg_renderer_base.h"
|
||||
#include "../agg-2.4/include/agg_pixfmt_gray.h"
|
||||
#include "../agg-2.4/include/agg_pixfmt_rgba.h"
|
||||
#include "../agg-2.4/include/agg_scanline_u.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
template <class PixelFormat, class AlphaMask>
|
||||
struct TAlphaMaskData
|
||||
{
|
||||
TAlphaMaskData(agg::rendering_buffer& oRenderingBuffer)
|
||||
: m_oPixfmt(oRenderingBuffer), m_oScanLine(m_oAlphaMask)
|
||||
{};
|
||||
|
||||
PixelFormat m_oPixfmt;
|
||||
agg::renderer_base<PixelFormat> m_oRendererBase;
|
||||
AlphaMask m_oAlphaMask;
|
||||
agg::scanline_u8_am<AlphaMask> m_oScanLine; // Используется для применения альфа маски
|
||||
};
|
||||
|
||||
typedef agg::renderer_base<agg::pixfmt_bgra32> RenBaseBGRA32;
|
||||
typedef agg::scanline_u8_am<agg::alpha_mask_bgra32gray> ScanlineBGRA32Gray;
|
||||
typedef agg::scanline_u8_am<agg::alpha_mask_gray8> ScanlineGray8;
|
||||
|
||||
class CAlphaMask_private
|
||||
{
|
||||
public:
|
||||
CAlphaMask_private();
|
||||
~CAlphaMask_private();
|
||||
|
||||
StatusAlphaMask GetStatus() const;
|
||||
AMaskDataType GetDataType() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
Status Create(UINT unWidth, UINT unHeight, AMaskDataType enDataType);
|
||||
|
||||
Status LoadFromBuffer(BYTE* pBuffer, UINT unWidth, UINT unHeight, AMaskDataType enBufferType, bool bExternalBuffer = true);
|
||||
|
||||
Status LoadFromFile(const std::wstring& wsFilePath);
|
||||
Status LoadFromImage(IGrObject* pGrObject, bool bCopy = true);
|
||||
|
||||
agg::rendering_buffer& GetRenderingBuffer();
|
||||
RenBaseBGRA32& GetRendererBaseImage();
|
||||
ScanlineBGRA32Gray& GetScanlineImage();
|
||||
ScanlineGray8& GetScanlineABuffer();
|
||||
|
||||
BYTE* GetMask();
|
||||
|
||||
void StartApplying();
|
||||
|
||||
CAlphaMask_private& operator=(const CAlphaMask_private& oAlphaMask);
|
||||
private:
|
||||
void Set(BYTE* pBuffer, UINT unWidth, UINT unHeight, AMaskDataType enDataType);
|
||||
|
||||
agg::rendering_buffer m_oRenderingBuffer;
|
||||
StatusAlphaMask m_enStatus;
|
||||
AMaskDataType m_enDataType;
|
||||
|
||||
bool m_bExternalBuffer;
|
||||
public:
|
||||
typedef TAlphaMaskData<agg::pixfmt_bgra32, agg::alpha_mask_bgra32gray> AMaskFromImage;
|
||||
typedef TAlphaMaskData<agg::pixfmt_gray8, agg::alpha_mask_gray8> AMaskFromABuffer;
|
||||
|
||||
AMaskFromImage *m_pImageData;
|
||||
AMaskFromABuffer *m_pAlphaBufferData;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _BUILD_ALPHAMASK_PRIVATE_H_
|
||||
@ -32,6 +32,7 @@
|
||||
#include "Graphics.h"
|
||||
#include <algorithm>
|
||||
#include "../fontengine/FontFile.h"
|
||||
#include "AlphaMask_private.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
@ -67,6 +68,8 @@ namespace Aggplus
|
||||
|
||||
m_dDpiTile = -1;
|
||||
|
||||
m_pAlphaMask = NULL;
|
||||
|
||||
m_nTextRenderMode = FT_RENDER_MODE_NORMAL;
|
||||
m_nBlendMode = agg::comp_op_src_over;
|
||||
|
||||
@ -156,6 +159,8 @@ namespace Aggplus
|
||||
RELEASEOBJECT(m_pGraphics);
|
||||
RELEASEOBJECT(m_pBitmap);
|
||||
#endif
|
||||
|
||||
RELEASEINTERFACE(m_pAlphaMask);
|
||||
}
|
||||
|
||||
INT CGraphics::IsDib()
|
||||
@ -448,7 +453,7 @@ namespace Aggplus
|
||||
m_rasterizer.get_rasterizer().reset_clipping();
|
||||
m_rasterizer.get_rasterizer().clip_box(m_dClipLeft, m_dClipTop, m_dClipWidth + m_dClipLeft, m_dClipHeight + m_dClipTop);
|
||||
|
||||
m_frame_buffer.ren_base().clip_box((int)m_dClipLeft, (int)m_dClipTop, (int)(m_dClipWidth + m_dClipLeft), (int)(m_dClipHeight + m_dClipTop));
|
||||
GetRendererBase().clip_box((int)m_dClipLeft, (int)m_dClipTop, (int)(m_dClipWidth + m_dClipLeft), (int)(m_dClipHeight + m_dClipTop));
|
||||
|
||||
m_oClip.Reset();
|
||||
|
||||
@ -953,7 +958,7 @@ namespace Aggplus
|
||||
b = ptxBrush->m_oBounds.bottom;
|
||||
}
|
||||
|
||||
CMatrix brushMatrix;
|
||||
CMatrix brushMatrix(ptxBrush->m_mtx);
|
||||
if (ptxBrush->GetWrapMode() == Aggplus::WrapModeClamp)
|
||||
{
|
||||
double dScaleX = (r - x) / dwPatternWidth;
|
||||
@ -1207,9 +1212,40 @@ namespace Aggplus
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Status CGraphics::SetAlphaMask(CAlphaMask* pAlphaMask)
|
||||
{
|
||||
RELEASEINTERFACE(m_pAlphaMask);
|
||||
m_pAlphaMask = pAlphaMask;
|
||||
if (m_pAlphaMask)
|
||||
{
|
||||
m_pAlphaMask->AddRef();
|
||||
m_pAlphaMask->m_internal->StartApplying();
|
||||
}
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CGraphics::CreateAlphaMask()
|
||||
{
|
||||
RELEASEINTERFACE(m_pAlphaMask);
|
||||
m_pAlphaMask = new CAlphaMask();
|
||||
return m_pAlphaMask->CreateImageBuffer(m_frame_buffer.width(), m_frame_buffer.height());
|
||||
}
|
||||
|
||||
Status CGraphics::ResetAlphaMask()
|
||||
{
|
||||
RELEASEINTERFACE(m_pAlphaMask);
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CGraphics::StartApplyingAlphaMask()
|
||||
{
|
||||
m_pAlphaMask->m_internal->StartApplying();
|
||||
return Ok;
|
||||
}
|
||||
|
||||
void CGraphics::CalculateFullTransform()
|
||||
{
|
||||
m_oFullTransform = m_oCoordTransform;
|
||||
m_oFullTransform = m_oCoordTransform;
|
||||
m_oFullTransform.Multiply(&m_oBaseTransform, MatrixOrderAppend);
|
||||
m_oFullTransform.Multiply(&m_oTransform, MatrixOrderPrepend);
|
||||
}
|
||||
@ -1218,11 +1254,35 @@ namespace Aggplus
|
||||
return m_oClip.IsClip();
|
||||
}
|
||||
|
||||
agg::rendering_buffer& CGraphics::GetRenderingBuffer()
|
||||
{
|
||||
if (m_pAlphaMask && GenerationAlphaMask == m_pAlphaMask->m_internal->GetStatus())
|
||||
return m_pAlphaMask->m_internal->GetRenderingBuffer();
|
||||
|
||||
return m_frame_buffer.ren_buf();
|
||||
}
|
||||
|
||||
base_renderer_type& CGraphics::GetRendererBase()
|
||||
{
|
||||
if (m_pAlphaMask && GenerationAlphaMask == m_pAlphaMask->GetStatus() && ImageBuffer == m_pAlphaMask->GetDataType())
|
||||
return (base_renderer_type&)m_pAlphaMask->m_internal->GetRendererBaseImage();
|
||||
|
||||
return m_frame_buffer.ren_base();
|
||||
}
|
||||
|
||||
template<class Renderer>
|
||||
void CGraphics::render_scanlines(Renderer& ren)
|
||||
{
|
||||
if (!m_oClip.IsClip())
|
||||
{
|
||||
if (m_pAlphaMask && ApplyingAlphaMask == m_pAlphaMask->GetStatus())
|
||||
{
|
||||
if (ImageBuffer == m_pAlphaMask->GetDataType())
|
||||
return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_pAlphaMask->m_internal->GetScanlineImage(), ren);
|
||||
else if (AlphaBuffer == m_pAlphaMask->GetDataType())
|
||||
return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_pAlphaMask->m_internal->GetScanlineABuffer(), ren);
|
||||
}
|
||||
|
||||
return agg::render_scanlines(m_rasterizer.get_rasterizer(), m_rasterizer.get_scanline(), ren);
|
||||
}
|
||||
else
|
||||
@ -1275,6 +1335,14 @@ namespace Aggplus
|
||||
{
|
||||
if (!m_oClip.IsClip())
|
||||
{
|
||||
if (m_pAlphaMask && ApplyingAlphaMask == m_pAlphaMask->GetStatus())
|
||||
{
|
||||
if (ImageBuffer == m_pAlphaMask->GetDataType())
|
||||
return agg::render_scanlines(ras, m_pAlphaMask->m_internal->GetScanlineImage(), ren);
|
||||
else if (AlphaBuffer == m_pAlphaMask->GetDataType())
|
||||
return agg::render_scanlines(ras, m_pAlphaMask->m_internal->GetScanlineABuffer(), ren);
|
||||
}
|
||||
|
||||
return agg::render_scanlines(ras, m_rasterizer.get_scanline(), ren);
|
||||
}
|
||||
else
|
||||
@ -1315,7 +1383,7 @@ namespace Aggplus
|
||||
comp_renderer_type ren_base;
|
||||
pixfmt_type_comp pixfmt;
|
||||
|
||||
pixfmt.attach(m_frame_buffer.ren_buf());
|
||||
pixfmt.attach(GetRenderingBuffer());
|
||||
pixfmt.comp_op(m_nBlendMode);
|
||||
ren_base.attach(pixfmt);
|
||||
ren_solid.attach(ren_base);
|
||||
@ -1326,7 +1394,7 @@ namespace Aggplus
|
||||
else
|
||||
{
|
||||
typedef agg::renderer_scanline_aa_solid<base_renderer_type> solid_renderer_type;
|
||||
solid_renderer_type ren_fine(m_frame_buffer.ren_base());
|
||||
solid_renderer_type ren_fine(GetRendererBase());
|
||||
ren_fine.color(dwColor.GetAggColor());
|
||||
|
||||
render_scanlines(ren_fine);
|
||||
@ -1397,7 +1465,7 @@ namespace Aggplus
|
||||
gradient_span_alloc span_alloc;
|
||||
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, gradient_span_alloc, gradient_span_gen> renderer_gradient_type;
|
||||
renderer_gradient_type ren_gradient( m_frame_buffer.ren_base(), span_alloc, span_gen );
|
||||
renderer_gradient_type ren_gradient( GetRendererBase(), span_alloc, span_gen );
|
||||
|
||||
if (fabs(m_dGlobalAlpha - 1.0) < FLT_EPSILON)
|
||||
{
|
||||
@ -1478,7 +1546,7 @@ namespace Aggplus
|
||||
gradient_span_alloc span_alloc;
|
||||
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, gradient_span_alloc, gradient_span_gen> renderer_gradient_type;
|
||||
renderer_gradient_type ren_gradient( m_frame_buffer.ren_base(), span_alloc, span_gen );
|
||||
renderer_gradient_type ren_gradient( GetRendererBase(), span_alloc, span_gen );
|
||||
|
||||
if (fabs(m_dGlobalAlpha - 1.0) < FLT_EPSILON)
|
||||
{
|
||||
@ -1537,7 +1605,7 @@ namespace Aggplus
|
||||
hatch_span_alloc span_alloc;
|
||||
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, hatch_span_alloc, hatch_span_gen> renderer_hatch_type;
|
||||
renderer_hatch_type ren_hatch( m_frame_buffer.ren_base(), span_alloc, span_gen );
|
||||
renderer_hatch_type ren_hatch( GetRendererBase(), span_alloc, span_gen );
|
||||
|
||||
if (fabs(m_dGlobalAlpha - 1.0) < FLT_EPSILON)
|
||||
{
|
||||
@ -1579,7 +1647,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf);
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
|
||||
if (fabs(m_dGlobalAlpha - 1.0) < FLT_EPSILON)
|
||||
{
|
||||
@ -1617,7 +1685,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf, agg::rgba(0, 0, 0, 0));
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
//agg::render_scanlines(m_rasterizer.get_rasterizer(), m_rasterizer.get_scanline(), ri);
|
||||
render_scanlines(ri);
|
||||
}
|
||||
@ -1649,7 +1717,7 @@ namespace Aggplus
|
||||
typedef agg::span_image_filter_rgba_nn<img_source_type, interpolator_type_linear> span_gen_type;
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, span_alloc_type, span_gen_type> renderer_type;
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1658,7 +1726,7 @@ namespace Aggplus
|
||||
typedef agg::span_image_filter_rgba_bilinear<img_source_type, interpolator_type_linear> span_gen_type;
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, span_alloc_type, span_gen_type> renderer_type;
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1669,7 +1737,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_bicubic(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1680,7 +1748,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_spline16(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1691,7 +1759,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_blackman256(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1702,7 +1770,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_bilinear(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1725,7 +1793,7 @@ namespace Aggplus
|
||||
typedef agg::span_image_filter_rgba_nn<img_source_type, interpolator_type_linear> span_gen_type;
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, span_alloc_type, span_gen_type> renderer_type;
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1734,7 +1802,7 @@ namespace Aggplus
|
||||
typedef agg::span_image_filter_rgba_bilinear<img_source_type, interpolator_type_linear> span_gen_type;
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, span_alloc_type, span_gen_type> renderer_type;
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1745,7 +1813,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_bicubic(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1756,7 +1824,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_spline16(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1767,7 +1835,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_blackman256(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1778,7 +1846,7 @@ namespace Aggplus
|
||||
agg::image_filter_lut filter;
|
||||
filter.calculate(agg::image_filter_bilinear(), false);
|
||||
span_gen_type sg(img_src, interpolator, filter);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
render_scanlines_alpha(ri, Alpha);
|
||||
break;
|
||||
}
|
||||
@ -1820,7 +1888,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf);
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
|
||||
double dAlpha = m_dGlobalAlpha * Alpha / 255.0;
|
||||
if (fabs(dAlpha - 1.0) < FLT_EPSILON)
|
||||
@ -1846,7 +1914,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf);
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
|
||||
double dAlpha = m_dGlobalAlpha * Alpha / 255.0;
|
||||
if (fabs(dAlpha - 1.0) < FLT_EPSILON)
|
||||
@ -1872,7 +1940,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf);
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
|
||||
double dAlpha = m_dGlobalAlpha * Alpha / 255.0;
|
||||
if (fabs(dAlpha - 1.0) < FLT_EPSILON)
|
||||
@ -1898,7 +1966,7 @@ namespace Aggplus
|
||||
pixfmt img_pixf(PatRendBuff);
|
||||
img_source_type img_src(img_pixf);
|
||||
span_gen_type sg(img_src, interpolator);
|
||||
renderer_type ri(m_frame_buffer.ren_base(), span_allocator, sg);
|
||||
renderer_type ri(GetRendererBase(), span_allocator, sg);
|
||||
|
||||
double dAlpha = m_dGlobalAlpha * Alpha / 255.0;
|
||||
if (fabs(dAlpha - 1.0) < FLT_EPSILON)
|
||||
@ -2039,7 +2107,7 @@ namespace Aggplus
|
||||
((CBrushSolid*)pBrush)->GetColor(&clr);
|
||||
|
||||
typedef agg::renderer_scanline_aa_solid<base_renderer_type> solid_renderer_type;
|
||||
solid_renderer_type ren_fine(m_frame_buffer.ren_base());
|
||||
solid_renderer_type ren_fine(GetRendererBase());
|
||||
ren_fine.color(clr.GetAggColor());
|
||||
|
||||
//agg::render_scanlines(storage, m_rasterizer.get_scanline(), ren_fine);
|
||||
@ -2054,7 +2122,7 @@ namespace Aggplus
|
||||
((CBrushSolid*)pBrush)->GetColor(&clr);
|
||||
|
||||
typedef agg::renderer_scanline_aa_solid<base_renderer_type> solid_renderer_type;
|
||||
solid_renderer_type ren_fine(m_frame_buffer.ren_base());
|
||||
solid_renderer_type ren_fine(GetRendererBase());
|
||||
ren_fine.color(clr.GetAggColor());
|
||||
|
||||
if (m_nTextRenderMode == FT_RENDER_MODE_LCD)
|
||||
@ -2187,7 +2255,7 @@ namespace Aggplus
|
||||
gradient_span_alloc span_alloc;
|
||||
|
||||
typedef agg::renderer_scanline_aa<base_renderer_type, gradient_span_alloc, gradient_span_gen> renderer_gradient_type;
|
||||
renderer_gradient_type ren_gradient( m_frame_buffer.ren_base(), span_alloc, span_gen );
|
||||
renderer_gradient_type ren_gradient( GetRendererBase(), span_alloc, span_gen );
|
||||
|
||||
if (fabs(m_dGlobalAlpha - 1.0) < FLT_EPSILON)
|
||||
{
|
||||
|
||||
@ -65,6 +65,7 @@
|
||||
#include "Color.h"
|
||||
#include "Matrix.h"
|
||||
#include "GraphicsPath.h"
|
||||
#include "AlphaMask.h"
|
||||
#include "Clip.h"
|
||||
#include "Brush.h"
|
||||
#include "Image.h"
|
||||
@ -278,8 +279,11 @@ protected:
|
||||
|
||||
CClipMulti m_oClip;
|
||||
|
||||
CAlphaMask* m_pAlphaMask;
|
||||
|
||||
agg::svg::frame_buffer_rgba<blender_type> m_frame_buffer;
|
||||
agg::svg::rasterizer m_rasterizer;
|
||||
|
||||
|
||||
#ifdef _WINDOW_GRAPHIS_USE_
|
||||
// для отрисовки картинок - используем Gdiplus
|
||||
@ -392,6 +396,12 @@ public:
|
||||
INT DrawStringPath(const std::wstring& strText, CFontManager* pFont, CBrush* pBrush, double x, double y);
|
||||
INT DrawStringPathC(const LONG& lText, CFontManager* pFont, CBrush* pBrush, double x, double y);
|
||||
|
||||
//Работа с альфа-маской
|
||||
Status SetAlphaMask(CAlphaMask* pAlphaMask);
|
||||
Status CreateAlphaMask();
|
||||
Status ResetAlphaMask();
|
||||
Status StartApplyingAlphaMask();
|
||||
|
||||
void CalculateFullTransform();
|
||||
bool IsClip();
|
||||
|
||||
@ -410,6 +420,9 @@ protected:
|
||||
template<class Renderer>
|
||||
void render_scanlines_alpha(Renderer& ren, BYTE Alpha);
|
||||
|
||||
agg::rendering_buffer& GetRenderingBuffer();
|
||||
base_renderer_type& GetRendererBase();
|
||||
|
||||
void DoFillPathSolid(CColor dwColor);
|
||||
void DoFillPathGradient(CBrushLinearGradient *pBrush);
|
||||
void DoFillPathGradient2(CBrushLinearGradient *pBrush);
|
||||
|
||||
@ -190,7 +190,15 @@ Aggplus::CBrush* CGraphicsRenderer::CreateBrush(NSStructures::CBrush* pBrush)
|
||||
}
|
||||
else
|
||||
{
|
||||
Aggplus::CBrushTexture* pNew = new Aggplus::CBrushTexture(pBrush->TexturePath, /*(Aggplus::WrapMode)TextureMode*/Aggplus::WrapModeClamp);
|
||||
Aggplus::CBrushTexture* pNew;
|
||||
|
||||
if (NULL != pBrush->Image)
|
||||
pNew = new Aggplus::CBrushTexture(pBrush->Image, Aggplus::WrapModeClamp);
|
||||
else
|
||||
pNew = new Aggplus::CBrushTexture(pBrush->TexturePath, Aggplus::WrapModeClamp);
|
||||
|
||||
pNew->SetTransform(&m_oBrush.Transform);
|
||||
|
||||
return pNew;
|
||||
}
|
||||
}
|
||||
@ -548,6 +556,23 @@ HRESULT CGraphicsRenderer::put_BrushTexturePath(const std::wstring& bsPath)
|
||||
m_oBrush.TexturePath = bsPath;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::get_BrushTextureImage(Aggplus::CImage** pImage)
|
||||
{
|
||||
*pImage = m_oBrush.Image;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::put_BrushTextureImage(Aggplus::CImage *pImage)
|
||||
{
|
||||
if (NULL == pImage)
|
||||
return S_FALSE;
|
||||
|
||||
RELEASEINTERFACE(m_oBrush.Image);
|
||||
|
||||
m_oBrush.Image = pImage;
|
||||
m_oBrush.Image->AddRef();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::get_BrushTextureMode(LONG* lMode)
|
||||
{
|
||||
*lMode = m_oBrush.TextureMode;
|
||||
@ -578,6 +603,16 @@ HRESULT CGraphicsRenderer::put_BrushLinearAngle(const double& dAngle)
|
||||
m_oBrush.LinearAngle = dAngle;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::get_BrushTransform(Aggplus::CMatrix &oMatrix)
|
||||
{
|
||||
oMatrix = m_oBrush.Transform;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix)
|
||||
{
|
||||
m_oBrush.Transform = oMatrix;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
|
||||
{
|
||||
m_oBrush.Rectable = val;
|
||||
@ -759,6 +794,11 @@ HRESULT CGraphicsRenderer::BeginCommand(const DWORD& lType)
|
||||
{
|
||||
return NewPage();
|
||||
}
|
||||
case c_nMaskType:
|
||||
{
|
||||
m_pRenderer->CreateAlphaMask();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
};
|
||||
@ -788,6 +828,16 @@ HRESULT CGraphicsRenderer::EndCommand(const DWORD& lType)
|
||||
m_bIsSetupClip = FALSE;
|
||||
break;
|
||||
}
|
||||
case c_nMaskType:
|
||||
{
|
||||
m_pRenderer->StartApplyingAlphaMask();
|
||||
break;
|
||||
}
|
||||
case c_nResetMaskType:
|
||||
{
|
||||
m_pRenderer->ResetAlphaMask();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
};
|
||||
@ -943,12 +993,17 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
|
||||
RELEASEARRAYOBJECTS(pImageData);
|
||||
}
|
||||
#else
|
||||
pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode);
|
||||
if (NULL != m_oBrush.Image)
|
||||
pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.Image, oMode);
|
||||
else
|
||||
pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
if( pTextureBrush )
|
||||
{
|
||||
pTextureBrush->SetTransform(&m_oBrush.Transform);
|
||||
|
||||
pTextureBrush->Alpha = (BYTE)m_oBrush.TextureAlpha;
|
||||
|
||||
if (m_oBrush.Rectable == 1)
|
||||
@ -1344,6 +1399,11 @@ void CGraphicsRenderer::CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oR
|
||||
m_pRenderer->SetPageUnit(Aggplus::UnitMillimeter);
|
||||
}
|
||||
|
||||
void CGraphicsRenderer::SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask)
|
||||
{
|
||||
m_pRenderer->SetAlphaMask(pAlphaMask);
|
||||
}
|
||||
|
||||
void CGraphicsRenderer::put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal)
|
||||
{
|
||||
m_bGlobalAlphaEnabled = bEnabled;
|
||||
|
||||
@ -179,12 +179,16 @@ public:
|
||||
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha);
|
||||
virtual HRESULT get_BrushTexturePath(std::wstring* bsPath);
|
||||
virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath);
|
||||
virtual HRESULT get_BrushTextureImage(Aggplus::CImage** pImage);
|
||||
virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage);
|
||||
virtual HRESULT get_BrushTextureMode(LONG* lMode);
|
||||
virtual HRESULT put_BrushTextureMode(const LONG& lMode);
|
||||
virtual HRESULT get_BrushTextureAlpha(LONG* lTxAlpha);
|
||||
virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha);
|
||||
virtual HRESULT get_BrushLinearAngle(double* dAngle);
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
|
||||
virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height);
|
||||
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height);
|
||||
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount);
|
||||
@ -345,6 +349,9 @@ public:
|
||||
inline double GetPixW() { return m_pRenderer->GetPixW(); }
|
||||
inline double GetPixH() { return m_pRenderer->GetPixH(); }
|
||||
|
||||
// alpha mask methods
|
||||
void SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask);
|
||||
|
||||
// smart methods
|
||||
void drawHorLine(BYTE align, double y, double x, double r, double penW)
|
||||
{
|
||||
|
||||
@ -64,6 +64,9 @@ const long c_nComplexFigureType = 0x0800;
|
||||
const long c_nPDFGradientType = 0x1000;
|
||||
const long c_nTableCell = 0x2000;
|
||||
|
||||
const long c_nMaskType = 0x3000;
|
||||
const long c_nResetMaskType = 0x4000;
|
||||
|
||||
const long c_nPDFTilingFill = 0x2001;
|
||||
const long c_nPDFTilingFillIteration = 0x2002;
|
||||
|
||||
@ -137,6 +140,8 @@ public:
|
||||
virtual ~IFormField() {}
|
||||
};
|
||||
|
||||
namespace Aggplus { class CImage; }
|
||||
|
||||
// IRenderer
|
||||
class IRenderer : public IGrObject
|
||||
{
|
||||
@ -150,187 +155,191 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
// тип рендерера-----------------------------------------------------------------------------
|
||||
virtual HRESULT get_Type(LONG* lType) = 0;
|
||||
//-------- Функции для работы со страницей --------------------------------------------------
|
||||
virtual HRESULT NewPage() = 0;
|
||||
virtual HRESULT get_Height(double* dHeight) = 0;
|
||||
virtual HRESULT put_Height(const double& dHeight) = 0;
|
||||
virtual HRESULT get_Width(double* dWidth) = 0;
|
||||
virtual HRESULT put_Width(const double& dWidth) = 0;
|
||||
virtual HRESULT get_DpiX(double* dDpiX) = 0;
|
||||
virtual HRESULT get_DpiY(double* dDpiY) = 0;
|
||||
// тип рендерера-----------------------------------------------------------------------------
|
||||
virtual HRESULT get_Type(LONG* lType) = 0;
|
||||
//-------- Функции для работы со страницей --------------------------------------------------
|
||||
virtual HRESULT NewPage() = 0;
|
||||
virtual HRESULT get_Height(double* dHeight) = 0;
|
||||
virtual HRESULT put_Height(const double& dHeight) = 0;
|
||||
virtual HRESULT get_Width(double* dWidth) = 0;
|
||||
virtual HRESULT put_Width(const double& dWidth) = 0;
|
||||
virtual HRESULT get_DpiX(double* dDpiX) = 0;
|
||||
virtual HRESULT get_DpiY(double* dDpiY) = 0;
|
||||
|
||||
// pen --------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_PenColor(LONG* lColor) = 0;
|
||||
virtual HRESULT put_PenColor(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_PenAlpha(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_PenAlpha(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_PenSize(double* dSize) = 0;
|
||||
virtual HRESULT put_PenSize(const double& dSize) = 0;
|
||||
virtual HRESULT get_PenDashStyle(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenDashStyle(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineStartCap(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineStartCap(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineEndCap(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineEndCap(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineJoin(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineJoin(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenDashOffset(double* dOffset) = 0;
|
||||
virtual HRESULT put_PenDashOffset(const double& dOffset) = 0;
|
||||
virtual HRESULT get_PenAlign(LONG* lAlign) = 0;
|
||||
virtual HRESULT put_PenAlign(const LONG& lAlign) = 0;
|
||||
virtual HRESULT get_PenMiterLimit(double* dOffset) = 0;
|
||||
virtual HRESULT put_PenMiterLimit(const double& dOffset) = 0;
|
||||
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount) = 0;
|
||||
// pen --------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_PenColor(LONG* lColor) = 0;
|
||||
virtual HRESULT put_PenColor(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_PenAlpha(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_PenAlpha(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_PenSize(double* dSize) = 0;
|
||||
virtual HRESULT put_PenSize(const double& dSize) = 0;
|
||||
virtual HRESULT get_PenDashStyle(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenDashStyle(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineStartCap(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineStartCap(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineEndCap(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineEndCap(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenLineJoin(BYTE* val) = 0;
|
||||
virtual HRESULT put_PenLineJoin(const BYTE& val) = 0;
|
||||
virtual HRESULT get_PenDashOffset(double* dOffset) = 0;
|
||||
virtual HRESULT put_PenDashOffset(const double& dOffset) = 0;
|
||||
virtual HRESULT get_PenAlign(LONG* lAlign) = 0;
|
||||
virtual HRESULT put_PenAlign(const LONG& lAlign) = 0;
|
||||
virtual HRESULT get_PenMiterLimit(double* dOffset) = 0;
|
||||
virtual HRESULT put_PenMiterLimit(const double& dOffset) = 0;
|
||||
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount)= 0;
|
||||
|
||||
// brush ------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_BrushType(LONG* lType) = 0;
|
||||
virtual HRESULT put_BrushType(const LONG& lType) = 0;
|
||||
virtual HRESULT get_BrushColor1(LONG* lColor) = 0;
|
||||
virtual HRESULT put_BrushColor1(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_BrushAlpha1(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_BrushColor2(LONG* lColor) = 0;
|
||||
virtual HRESULT put_BrushColor2(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_BrushAlpha2(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_BrushTexturePath(std::wstring* bsPath) = 0;
|
||||
virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath) = 0;
|
||||
virtual HRESULT get_BrushTextureMode(LONG* lMode) = 0;
|
||||
virtual HRESULT put_BrushTextureMode(const LONG& lMode) = 0;
|
||||
virtual HRESULT get_BrushTextureAlpha(LONG* lTxAlpha) = 0;
|
||||
virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha) = 0;
|
||||
virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0;
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0;
|
||||
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
// brush ------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_BrushType(LONG* lType) = 0;
|
||||
virtual HRESULT put_BrushType(const LONG& lType) = 0;
|
||||
virtual HRESULT get_BrushColor1(LONG* lColor) = 0;
|
||||
virtual HRESULT put_BrushColor1(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_BrushAlpha1(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_BrushColor2(LONG* lColor) = 0;
|
||||
virtual HRESULT put_BrushColor2(const LONG& lColor) = 0;
|
||||
virtual HRESULT get_BrushAlpha2(LONG* lAlpha) = 0;
|
||||
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha) = 0;
|
||||
virtual HRESULT get_BrushTexturePath(std::wstring* bsPath) = 0;
|
||||
virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath) = 0;
|
||||
virtual HRESULT get_BrushTextureImage(Aggplus::CImage** pImage) = 0;
|
||||
virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage) = 0;
|
||||
virtual HRESULT get_BrushTextureMode(LONG* lMode) = 0;
|
||||
virtual HRESULT put_BrushTextureMode(const LONG& lMode) = 0;
|
||||
virtual HRESULT get_BrushTextureAlpha(LONG* lTxAlpha) = 0;
|
||||
virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha) = 0;
|
||||
virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix) = 0;
|
||||
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0;
|
||||
virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0;
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0;
|
||||
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
|
||||
|
||||
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0;
|
||||
//virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) {};
|
||||
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0;
|
||||
//virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) {};
|
||||
|
||||
// font -------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_FontName(std::wstring* bsName) = 0;
|
||||
virtual HRESULT put_FontName(const std::wstring& bsName) = 0;
|
||||
virtual HRESULT get_FontPath(std::wstring* bsName) = 0;
|
||||
virtual HRESULT put_FontPath(const std::wstring& bsName) = 0;
|
||||
virtual HRESULT get_FontSize(double* dSize) = 0;
|
||||
virtual HRESULT put_FontSize(const double& dSize) = 0;
|
||||
virtual HRESULT get_FontStyle(LONG* lStyle) = 0;
|
||||
virtual HRESULT put_FontStyle(const LONG& lStyle) = 0;
|
||||
virtual HRESULT get_FontStringGID(INT* bGID) = 0;
|
||||
virtual HRESULT put_FontStringGID(const INT& bGID) = 0;
|
||||
virtual HRESULT get_FontCharSpace(double* dSpace) = 0;
|
||||
virtual HRESULT put_FontCharSpace(const double& dSpace) = 0;
|
||||
virtual HRESULT get_FontFaceIndex(int* lFaceIndex) = 0;
|
||||
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex) = 0;
|
||||
// font -------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_FontName(std::wstring* bsName) = 0;
|
||||
virtual HRESULT put_FontName(const std::wstring& bsName) = 0;
|
||||
virtual HRESULT get_FontPath(std::wstring* bsName) = 0;
|
||||
virtual HRESULT put_FontPath(const std::wstring& bsName) = 0;
|
||||
virtual HRESULT get_FontSize(double* dSize) = 0;
|
||||
virtual HRESULT put_FontSize(const double& dSize) = 0;
|
||||
virtual HRESULT get_FontStyle(LONG* lStyle) = 0;
|
||||
virtual HRESULT put_FontStyle(const LONG& lStyle) = 0;
|
||||
virtual HRESULT get_FontStringGID(INT* bGID) = 0;
|
||||
virtual HRESULT put_FontStringGID(const INT& bGID) = 0;
|
||||
virtual HRESULT get_FontCharSpace(double* dSpace) = 0;
|
||||
virtual HRESULT put_FontCharSpace(const double& dSpace) = 0;
|
||||
virtual HRESULT get_FontFaceIndex(int* lFaceIndex) = 0;
|
||||
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex) = 0;
|
||||
|
||||
//-------- Функции для вывода текста --------------------------------------------------------
|
||||
virtual HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
//-------- Функции для вывода текста --------------------------------------------------------
|
||||
virtual HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
|
||||
virtual HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
|
||||
virtual HRESULT CommandDrawTextCHAR2(unsigned int* codepoints, const unsigned int& codepointscount, const unsigned int& gid, const double& x, const double& y, const double& w, const double& h)
|
||||
{
|
||||
LONG c = (NULL == codepoints) ? 32 : codepoints[0];
|
||||
return CommandDrawTextExCHAR(c, (LONG)gid, x, y, w, h);
|
||||
}
|
||||
virtual HRESULT CommandDrawTextCHAR2(unsigned int* codepoints, const unsigned int& codepointscount, const unsigned int& gid, const double& x, const double& y, const double& w, const double& h)
|
||||
{
|
||||
LONG c = (NULL == codepoints) ? 32 : codepoints[0];
|
||||
return CommandDrawTextExCHAR(c, (LONG)gid, x, y, w, h);
|
||||
}
|
||||
|
||||
//-------- Маркеры для команд ---------------------------------------------------------------
|
||||
virtual HRESULT BeginCommand(const DWORD& lType) = 0;
|
||||
virtual HRESULT EndCommand(const DWORD& lType) = 0;
|
||||
//-------- Маркеры для команд ---------------------------------------------------------------
|
||||
virtual HRESULT BeginCommand(const DWORD& lType) = 0;
|
||||
virtual HRESULT EndCommand(const DWORD& lType) = 0;
|
||||
|
||||
//-------- Функции для работы с Graphics Path -----------------------------------------------
|
||||
virtual HRESULT PathCommandMoveTo(const double& x, const double& y) = 0;
|
||||
virtual HRESULT PathCommandLineTo(const double& x, const double& y) = 0;
|
||||
virtual HRESULT PathCommandLinesTo(double* points, const int& count) = 0;
|
||||
virtual HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3) = 0;
|
||||
virtual HRESULT PathCommandCurvesTo(double* points, const int& count) = 0;
|
||||
virtual HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle) = 0;
|
||||
virtual HRESULT PathCommandClose() = 0;
|
||||
virtual HRESULT PathCommandEnd() = 0;
|
||||
virtual HRESULT DrawPath(const LONG& nType) = 0;
|
||||
virtual HRESULT PathCommandStart() = 0;
|
||||
virtual HRESULT PathCommandGetCurrentPoint(double* x, double* y) = 0;
|
||||
//-------- Функции для работы с Graphics Path -----------------------------------------------
|
||||
virtual HRESULT PathCommandMoveTo(const double& x, const double& y) = 0;
|
||||
virtual HRESULT PathCommandLineTo(const double& x, const double& y) = 0;
|
||||
virtual HRESULT PathCommandLinesTo(double* points, const int& count) = 0;
|
||||
virtual HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3) = 0;
|
||||
virtual HRESULT PathCommandCurvesTo(double* points, const int& count) = 0;
|
||||
virtual HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle) = 0;
|
||||
virtual HRESULT PathCommandClose() = 0;
|
||||
virtual HRESULT PathCommandEnd() = 0;
|
||||
virtual HRESULT DrawPath(const LONG& nType) = 0;
|
||||
virtual HRESULT PathCommandStart() = 0;
|
||||
virtual HRESULT PathCommandGetCurrentPoint(double* x, double* y) = 0;
|
||||
|
||||
virtual HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
|
||||
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
|
||||
//-------- Функции для вывода изображений ---------------------------------------------------
|
||||
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0;
|
||||
//-------- Функции для вывода изображений ---------------------------------------------------
|
||||
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0;
|
||||
|
||||
// transform --------------------------------------------------------------------------------
|
||||
virtual HRESULT GetCommandParams(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT SetCommandParams(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
|
||||
{
|
||||
if ((dWidth <= 1) || (dHeight <= 1))
|
||||
lFlags = 0;
|
||||
// transform --------------------------------------------------------------------------------
|
||||
virtual HRESULT GetCommandParams(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT SetCommandParams(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
|
||||
{
|
||||
if ((dWidth <= 1) || (dHeight <= 1))
|
||||
lFlags = 0;
|
||||
|
||||
INT bFlipX = (0 != (c_nParamFlipX & lFlags));
|
||||
INT bFlipY = (0 != (c_nParamFlipY & lFlags));
|
||||
INT bFlipX = (0 != (c_nParamFlipX & lFlags));
|
||||
INT bFlipY = (0 != (c_nParamFlipY & lFlags));
|
||||
|
||||
float m11 = bFlipX ? -1.0f : 1.0f;
|
||||
float m22 = bFlipY ? -1.0f : 1.0f;
|
||||
float m11 = bFlipX ? -1.0f : 1.0f;
|
||||
float m22 = bFlipY ? -1.0f : 1.0f;
|
||||
|
||||
Aggplus::CMatrix oMatrix(1, 0, 0, 1, 0, 0);
|
||||
Aggplus::CMatrix oMatrix(1, 0, 0, 1, 0, 0);
|
||||
|
||||
if ((0 != dAngle) || (0 != lFlags))
|
||||
{
|
||||
double dCentreX = (double)(dLeft + dWidth / 2.0);
|
||||
double dCentreY = (double)(dTop + dHeight / 2.0);
|
||||
if ((0 != dAngle) || (0 != lFlags))
|
||||
{
|
||||
double dCentreX = (double)(dLeft + dWidth / 2.0);
|
||||
double dCentreY = (double)(dTop + dHeight / 2.0);
|
||||
|
||||
oMatrix.Translate(-dCentreX, -dCentreY , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Translate(-dCentreX, -dCentreY , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Rotate(dAngle , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Scale(m11, m22 , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Rotate(dAngle , Aggplus::MatrixOrderAppend);
|
||||
oMatrix.Scale(m11, m22 , Aggplus::MatrixOrderAppend);
|
||||
|
||||
oMatrix.Translate(dCentreX, dCentreY , Aggplus::MatrixOrderAppend);
|
||||
}
|
||||
double mass[6];
|
||||
oMatrix.GetElements(mass);
|
||||
SetTransform(mass[0], mass[1], mass[2], mass[3], mass[4], mass[5]);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT SetBaseTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) { return S_OK; }
|
||||
virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) = 0;
|
||||
virtual HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF) = 0;
|
||||
virtual HRESULT ResetTransform() = 0;
|
||||
oMatrix.Translate(dCentreX, dCentreY , Aggplus::MatrixOrderAppend);
|
||||
}
|
||||
double mass[6];
|
||||
oMatrix.GetElements(mass);
|
||||
SetTransform(mass[0], mass[1], mass[2], mass[3], mass[4], mass[5]);
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT SetBaseTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) { return S_OK; };
|
||||
virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) = 0;
|
||||
virtual HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF) = 0;
|
||||
virtual HRESULT ResetTransform() = 0;
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_ClipMode(LONG* plMode) = 0;
|
||||
virtual HRESULT put_ClipMode(const LONG& lMode) = 0;
|
||||
// -----------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_ClipMode(LONG* plMode) = 0;
|
||||
virtual HRESULT put_ClipMode(const LONG& lMode) = 0;
|
||||
|
||||
// additiaonal params ----------------------------------------------------------------------
|
||||
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand) = 0;
|
||||
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand) = 0;
|
||||
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand) = 0;
|
||||
// additiaonal params ----------------------------------------------------------------------
|
||||
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand) = 0;
|
||||
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand) = 0;
|
||||
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand) = 0;
|
||||
|
||||
virtual HRESULT StartConvertCoordsToIdentity()
|
||||
{
|
||||
m_bUseTransformCoordsToIdentity = true;
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT EndConvertCoordsToIdentity()
|
||||
{
|
||||
m_bUseTransformCoordsToIdentity = false;
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip) {return S_OK;}
|
||||
virtual HRESULT AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage) {return S_OK;}
|
||||
virtual HRESULT AddFormField(IFormField* pField) {return S_OK;}
|
||||
virtual HRESULT DocInfo(const std::wstring& wsTitle, const std::wstring& wsCreator, const std::wstring& wsSubject, const std::wstring& wsKeywords) {return S_OK;}
|
||||
virtual HRESULT StartConvertCoordsToIdentity()
|
||||
{
|
||||
m_bUseTransformCoordsToIdentity = true;
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT EndConvertCoordsToIdentity()
|
||||
{
|
||||
m_bUseTransformCoordsToIdentity = false;
|
||||
return S_OK;
|
||||
}
|
||||
virtual HRESULT AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip) {return S_OK;}
|
||||
virtual HRESULT AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage) {return S_OK;}
|
||||
virtual HRESULT AddFormField(IFormField* pField) {return S_OK;}
|
||||
virtual HRESULT DocInfo(const std::wstring& wsTitle, const std::wstring& wsCreator, const std::wstring& wsSubject, const std::wstring& wsKeywords) {return S_OK;}
|
||||
|
||||
virtual HRESULT IsExistAdditionalParam(const int& type) {return S_FALSE;}
|
||||
virtual HRESULT GetAdditionalParam(const int& type, std::string& result) {return S_FALSE;}
|
||||
virtual HRESULT IsExistAdditionalParam(const int& type) {return S_FALSE;}
|
||||
virtual HRESULT GetAdditionalParam(const int& type, std::string& result) {return S_FALSE;}
|
||||
};
|
||||
|
||||
#define PROPERTY_RENDERER(NameBase, Name, Type) \
|
||||
|
||||
@ -764,10 +764,6 @@ namespace NSFonts
|
||||
virtual void InitFromReg() = 0;
|
||||
#endif
|
||||
|
||||
#ifdef _IOS
|
||||
virtual std::vector<std::wstring> GetSetupFontFiles_ios() = 0;
|
||||
#endif
|
||||
|
||||
virtual IFontManager* GenerateFontManager() = 0;
|
||||
|
||||
virtual std::wstring GetFontBySymbol(int symbol) = 0;
|
||||
|
||||
@ -39,97 +39,102 @@
|
||||
|
||||
#include "./Image.h"
|
||||
|
||||
#include "../../graphics/AlphaMask.h"
|
||||
|
||||
#include "../IRenderer.h"
|
||||
#include "../structures.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
class CDIB : public IGrObject
|
||||
{
|
||||
public:
|
||||
BYTE* m_pBits;
|
||||
LONG m_lWidth;
|
||||
LONG m_lHeight;
|
||||
class CDIB : public IGrObject
|
||||
{
|
||||
public:
|
||||
BYTE* m_pBits;
|
||||
LONG m_lWidth;
|
||||
LONG m_lHeight;
|
||||
|
||||
public:
|
||||
CDIB() : IGrObject()
|
||||
{
|
||||
m_pBits = NULL;
|
||||
m_lWidth = 0;
|
||||
m_lHeight = 0;
|
||||
}
|
||||
virtual ~CDIB()
|
||||
{
|
||||
// delete all in system wrapper
|
||||
}
|
||||
public:
|
||||
CDIB() : IGrObject()
|
||||
{
|
||||
m_pBits = NULL;
|
||||
m_lWidth = 0;
|
||||
m_lHeight = 0;
|
||||
}
|
||||
virtual ~CDIB()
|
||||
{
|
||||
// delete all in system wrapper
|
||||
}
|
||||
|
||||
virtual INT Create(LONG lWidth, LONG lHeight, double dDPIX, double dDPIY) = 0;
|
||||
};
|
||||
virtual INT Create(LONG lWidth, LONG lHeight, double dDPIX, double dDPIY) = 0;
|
||||
};
|
||||
}
|
||||
namespace NSGraphics
|
||||
{
|
||||
class GRAPHICS_DECL IGraphicsRenderer : public IRenderer
|
||||
{
|
||||
public:
|
||||
IGraphicsRenderer() {}
|
||||
virtual ~IGraphicsRenderer() {}
|
||||
class GRAPHICS_DECL IGraphicsRenderer : public IRenderer
|
||||
{
|
||||
public:
|
||||
IGraphicsRenderer() {}
|
||||
virtual ~IGraphicsRenderer() {}
|
||||
|
||||
public:
|
||||
virtual void SetImageCache(NSImages::IImageFilesCache* pCache) = 0;
|
||||
virtual void SetFontManager(NSFonts::IFontManager* pManager = NULL) = 0;
|
||||
virtual void CheckFontManager() = 0;
|
||||
public:
|
||||
virtual void SetImageCache(NSImages::IImageFilesCache* pCache) = 0;
|
||||
virtual void SetFontManager(NSFonts::IFontManager* pManager = NULL) = 0;
|
||||
virtual void CheckFontManager() = 0;
|
||||
|
||||
virtual NSFonts::IFontManager* GetFontManager() = 0;
|
||||
virtual NSFonts::IFontManager* GetFontManager() = 0;
|
||||
|
||||
virtual void CloseFont() = 0;
|
||||
virtual void ClearInstallFont() = 0;
|
||||
|
||||
virtual void SetSwapRGB(bool bValue) = 0;
|
||||
virtual void SetTileImageDpi(const double& dDpi) = 0;
|
||||
virtual void CloseFont() = 0;
|
||||
virtual void ClearInstallFont() = 0;
|
||||
|
||||
public:
|
||||
virtual void CreateFromBgraFrame(CBgraFrame* pFrame) = 0;
|
||||
virtual void SetCoordTransformOffset(double dOffsetX, double dOffsetY) = 0;
|
||||
virtual void SetSwapRGB(bool bValue) = 0;
|
||||
virtual void SetTileImageDpi(const double& dDpi) = 0;
|
||||
|
||||
public:
|
||||
virtual void CreateFromBgraFrame(CBgraFrame* pFrame) = 0;
|
||||
virtual void SetCoordTransformOffset(double dOffsetX, double dOffsetY) = 0;
|
||||
|
||||
|
||||
virtual void SavePen(NSStructures::CPen& oPen) = 0;
|
||||
virtual void RestorePen(const NSStructures::CPen& oPen) = 0;
|
||||
virtual void SavePen(NSStructures::CPen& oPen) = 0;
|
||||
virtual void RestorePen(const NSStructures::CPen& oPen) = 0;
|
||||
|
||||
virtual void SaveBrush(NSStructures::CBrush& oBrush) = 0;
|
||||
virtual void RestoreBrush(const NSStructures::CBrush& oBrush) = 0;
|
||||
virtual void put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal) = 0;
|
||||
virtual void put_IntegerGrid(const bool& bEnabled) = 0;
|
||||
virtual bool get_IntegerGrid() = 0;
|
||||
virtual void AddRect(const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual void SetFontAttack() = 0;
|
||||
virtual void SaveBrush(NSStructures::CBrush& oBrush) = 0;
|
||||
virtual void RestoreBrush(const NSStructures::CBrush& oBrush) = 0;
|
||||
virtual void put_GlobalAlphaEnabled(const bool& bEnabled, const double& dVal) = 0;
|
||||
virtual void put_IntegerGrid(const bool& bEnabled) = 0;
|
||||
virtual bool get_IntegerGrid() = 0;
|
||||
virtual void AddRect(const double& x, const double& y, const double& w, const double& h) = 0;
|
||||
virtual void SetFontAttack() = 0;
|
||||
|
||||
virtual void Create(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0;
|
||||
virtual void CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0;
|
||||
virtual void Create(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0;
|
||||
virtual void CreateFlip(BYTE* pPixels, const Aggplus::CDoubleRect& oRect, LONG lWidthControl, LONG lHeightControl, Aggplus::CDIB* pDib = NULL) = 0;
|
||||
|
||||
virtual Aggplus::CMatrix* GetFullTransform() = 0;
|
||||
virtual Aggplus::CMatrix* GetTransformMatrix() = 0;
|
||||
virtual void CalculateFullTransform() = 0;
|
||||
virtual void PathCommandRect(double x, double y, double w, double h) = 0;
|
||||
virtual Aggplus::CMatrix* GetCoordTransform() = 0;
|
||||
virtual void Fill() = 0;
|
||||
virtual void Stroke() = 0;
|
||||
virtual double GetPixW() = 0;
|
||||
virtual double GetPixH() = 0;
|
||||
virtual Aggplus::CMatrix* GetFullTransform() = 0;
|
||||
virtual Aggplus::CMatrix* GetTransformMatrix() = 0;
|
||||
virtual void CalculateFullTransform() = 0;
|
||||
virtual void PathCommandRect(double x, double y, double w, double h) = 0;
|
||||
virtual Aggplus::CMatrix* GetCoordTransform() = 0;
|
||||
virtual void Fill() = 0;
|
||||
virtual void Stroke() = 0;
|
||||
virtual double GetPixW() = 0;
|
||||
virtual double GetPixH() = 0;
|
||||
|
||||
// smart methods
|
||||
virtual void drawHorLine(BYTE align, double y, double x, double r, double penW) = 0;
|
||||
virtual void drawHorLine2(BYTE align, double y, double x, double r, double penW) = 0;
|
||||
//alpha mask methods
|
||||
virtual void SetAlphaMask(Aggplus::CAlphaMask* pAlphaMask) = 0;
|
||||
|
||||
virtual void drawVerLine(BYTE align, double x, double y, double b, double penW) = 0;
|
||||
virtual void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) = 0;
|
||||
// smart methods
|
||||
virtual void drawHorLine(BYTE align, double y, double x, double r, double penW) = 0;
|
||||
virtual void drawHorLine2(BYTE align, double y, double x, double r, double penW) = 0;
|
||||
|
||||
// test
|
||||
virtual void drawVerLine(BYTE align, double x, double y, double b, double penW) = 0;
|
||||
virtual void drawHorLineExt(BYTE align, double y, double x, double r, double penW, double leftMW, double rightMW) = 0;
|
||||
|
||||
virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) = 0;
|
||||
virtual void put_BlendMode(const unsigned int nBlendMode) = 0;
|
||||
};
|
||||
// test
|
||||
|
||||
GRAPHICS_DECL IGraphicsRenderer* Create();
|
||||
virtual void put_BrushGradInfo(const NSStructures::GradientInfo &_ginfo) = 0;
|
||||
virtual void put_BlendMode(const unsigned int nBlendMode) = 0;
|
||||
};
|
||||
|
||||
GRAPHICS_DECL IGraphicsRenderer* Create();
|
||||
|
||||
GRAPHICS_DECL std::string GetHatchBase64(const std::wstring& name,
|
||||
unsigned char r1, unsigned char g1, unsigned char b1, unsigned char a1,
|
||||
|
||||
@ -39,10 +39,6 @@ enable_support_shaper {
|
||||
# -------------------------------------------------
|
||||
|
||||
core_ios {
|
||||
|
||||
OBJECTIVE_SOURCES += \
|
||||
$$FONT_ENGINE_PATH/ApplicationFonts_ios.mm \
|
||||
|
||||
LIBS += -framework Foundation
|
||||
}
|
||||
|
||||
|
||||
@ -8,12 +8,12 @@ CONFIG += graphics_dynamic_library
|
||||
DEFINES += _QT
|
||||
graphics_dynamic_library {
|
||||
CONFIG += shared
|
||||
CONFIG += plugin
|
||||
CONFIG += plugin
|
||||
|
||||
DEFINES += GRAPHICS_USE_DYNAMIC_LIBRARY_BUILDING
|
||||
} else {
|
||||
DEFINES += GRAPHICS_NO_USE_DYNAMIC_LIBRARY
|
||||
CONFIG += static
|
||||
CONFIG += static
|
||||
}
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../..
|
||||
@ -36,6 +36,7 @@ INCLUDEPATH += \
|
||||
|
||||
# matrix
|
||||
HEADERS += \
|
||||
$$GRAPHICS_AGG_PATH/include/test_grads/custom_gradients.h \
|
||||
./../Matrix_private.h \
|
||||
./../Matrix.h
|
||||
|
||||
@ -53,6 +54,15 @@ HEADERS += \
|
||||
SOURCES += \
|
||||
./../GraphicsPath.cpp
|
||||
|
||||
# alpha mask
|
||||
HEADERS += \
|
||||
./../AlphaMask_private.h \
|
||||
./../AlphaMask.h
|
||||
|
||||
SOURCES += \
|
||||
./../AlphaMask_private.cpp \
|
||||
./../AlphaMask.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$GRAPHICS_AGG_PATH/src/agg_arc.cpp \
|
||||
$$GRAPHICS_AGG_PATH/src/agg_bezier_arc.cpp \
|
||||
@ -101,11 +111,12 @@ HEADERS += \
|
||||
./../MetafileToGraphicsRenderer.h \
|
||||
./../FormField.h \
|
||||
./../structures.h \
|
||||
./../shading_info.h \
|
||||
./../Graphics.h \
|
||||
./../GraphicsRenderer.h \
|
||||
\
|
||||
./Graphics.h \
|
||||
./Image.h \
|
||||
./Image.h
|
||||
|
||||
SOURCES += \
|
||||
./../ArrowHead.cpp \
|
||||
|
||||
@ -69,13 +69,73 @@ METAFILE_PATH = $$PWD/../../raster/Metafile
|
||||
!metafile_disable_svg {
|
||||
DEFINES += METAFILE_SUPPORT_SVG
|
||||
|
||||
HEADERS += \
|
||||
$$METAFILE_PATH/svg/SVGFramework.h \
|
||||
$$METAFILE_PATH/svg/SVGTransformer.h
|
||||
# DEPRECATED ENGINE. REMOVE IN 7.6+ VERSIONS
|
||||
#CONFIG += svg_old_version
|
||||
|
||||
SOURCES += \
|
||||
$$METAFILE_PATH/svg/SVGFramework.cpp \
|
||||
$$METAFILE_PATH/svg/SVGTransformer.cpp
|
||||
svg_old_version {
|
||||
|
||||
DEFINES += SVG_OLD_ENGINE
|
||||
|
||||
HEADERS += \
|
||||
$$METAFILE_PATH/svg/SVGFramework.h \
|
||||
$$METAFILE_PATH/svg/SVGTransformer.h
|
||||
|
||||
SOURCES += \
|
||||
$$METAFILE_PATH/svg/SVGFramework.cpp \
|
||||
$$METAFILE_PATH/svg/SVGTransformer.cpp
|
||||
|
||||
} else {
|
||||
|
||||
HEADERS += \
|
||||
$$METAFILE_PATH/svg/SvgTypes.h \
|
||||
$$METAFILE_PATH/svg/CSvgFile.h \
|
||||
$$METAFILE_PATH/svg/CSvgParser.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CContainer.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CGradient.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CClipPath.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CMask.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPattern.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CSymbol.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CMarker.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CImage.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CLine.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CRect.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CCircle.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CEllipse.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPath.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CText.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CUse.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPolyline.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CStyle.h \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CObjectBase.h \
|
||||
$$METAFILE_PATH/svg/SvgUtils.h
|
||||
|
||||
SOURCES += \
|
||||
$$METAFILE_PATH/svg/CSvgFile.cpp \
|
||||
$$METAFILE_PATH/svg/CSvgParser.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CContainer.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CGradient.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CClipPath.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CMask.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CMarker.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPattern.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CSymbol.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CImage.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CLine.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CRect.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CCircle.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CEllipse.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPath.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CText.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CUse.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CPolyline.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CObjectBase.cpp \
|
||||
$$METAFILE_PATH/svg/SvgObjects/CStyle.cpp
|
||||
|
||||
CONFIG += css_calculator_without_xhtml
|
||||
|
||||
include($$METAFILE_PATH/../../../Common/3dParty/html/css/CssCalculator.pri)
|
||||
}
|
||||
}
|
||||
|
||||
!metafile_disable_svm {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -32,15 +32,14 @@
|
||||
#ifndef _BUILD_GRAPHICS_STRUCTURES_H_
|
||||
#define _BUILD_GRAPHICS_STRUCTURES_H_
|
||||
|
||||
#include "../common/Array.h"
|
||||
#include "../graphics/aggplustypes.h"
|
||||
#include "../agg-2.4/include/agg_color_rgba.h"
|
||||
#include "shading_info.h"
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "shading_info.h"
|
||||
#include "Matrix.h"
|
||||
#include "../common/IGrObject.h"
|
||||
|
||||
// pen -----------------------------------------------------------
|
||||
const long c_ag_LineCapFlat = 0;
|
||||
@ -117,10 +116,10 @@ const long c_BrushTextureModeTile = 1;
|
||||
const long c_BrushTextureModeTileCenter = 2;
|
||||
// --------------------------------------------------------------
|
||||
|
||||
namespace Aggplus { class CImage; }
|
||||
|
||||
namespace NSStructures
|
||||
{
|
||||
|
||||
|
||||
class CPen
|
||||
{
|
||||
public:
|
||||
@ -222,7 +221,6 @@ namespace NSStructures
|
||||
}
|
||||
CPen(const CPen &other)
|
||||
{
|
||||
SetDefaultParams();
|
||||
*this = other;
|
||||
}
|
||||
CPen &operator=(const CPen &other)
|
||||
@ -275,6 +273,9 @@ namespace NSStructures
|
||||
long Alpha1;
|
||||
long Alpha2;
|
||||
|
||||
Aggplus::CImage *Image;
|
||||
Aggplus::CMatrix Transform;
|
||||
|
||||
std::wstring TexturePath;
|
||||
long TextureAlpha;
|
||||
long TextureMode;
|
||||
@ -376,16 +377,16 @@ namespace NSStructures
|
||||
TextureAlpha = dNewAlpha;
|
||||
}
|
||||
|
||||
INT IsEqual(const CBrush *pBrush)
|
||||
INT IsEqual(const CBrush *pBrush)
|
||||
{
|
||||
if (NULL == pBrush)
|
||||
return FALSE;
|
||||
|
||||
return ((Type == pBrush->Type) &&
|
||||
return ((Type == pBrush->Type) && (Image == pBrush->Image) && Aggplus::CMatrix::IsEqual(&Transform, &pBrush->Transform) &&
|
||||
(Color1 == pBrush->Color1) && (Color2 == pBrush->Color2) &&
|
||||
(Alpha1 == pBrush->Alpha1) && (Alpha2 == pBrush->Alpha2) && (LinearAngle == pBrush->LinearAngle) &&
|
||||
(TexturePath == pBrush->TexturePath) && (TextureAlpha == pBrush->TextureAlpha) && (TextureMode == pBrush->TextureMode) &&
|
||||
(Rectable == pBrush->Rectable) && (Rect.Equals(pBrush->Rect)));
|
||||
(Rectable == pBrush->Rectable) && (Rect.Equals(pBrush->Rect)));
|
||||
}
|
||||
|
||||
void SetDefaultParams()
|
||||
@ -397,6 +398,9 @@ namespace NSStructures
|
||||
Color2 = 0;
|
||||
Alpha2 = 255;
|
||||
|
||||
Image = NULL;
|
||||
Transform.SetElements(1., 0., 0., 1., 0., 0.);
|
||||
|
||||
TextureAlpha = 255;
|
||||
TextureMode = c_BrushTextureModeStretch;
|
||||
|
||||
@ -426,25 +430,7 @@ namespace NSStructures
|
||||
}
|
||||
CBrush(const CBrush &other)
|
||||
{
|
||||
Type = other.Type;
|
||||
|
||||
Color1 = other.Color1;
|
||||
Alpha1 = other.Alpha1;
|
||||
Color2 = other.Color2;
|
||||
Alpha2 = other.Alpha2;
|
||||
|
||||
TexturePath = other.TexturePath;
|
||||
TextureAlpha = other.TextureAlpha;
|
||||
TextureMode = other.TextureMode;
|
||||
|
||||
Rectable = other.Rectable;
|
||||
Rect = other.Rect;
|
||||
|
||||
Bounds = other.Bounds;
|
||||
|
||||
LinearAngle = other.LinearAngle;
|
||||
m_arrSubColors = other.m_arrSubColors;
|
||||
m_oGradientInfo = other.m_oGradientInfo;
|
||||
*this = other;
|
||||
}
|
||||
CBrush &operator=(const CBrush &other)
|
||||
{
|
||||
@ -455,6 +441,9 @@ namespace NSStructures
|
||||
Color2 = other.Color2;
|
||||
Alpha2 = other.Alpha2;
|
||||
|
||||
Image = other.Image;
|
||||
Transform = other.Transform;
|
||||
|
||||
TexturePath = other.TexturePath;
|
||||
TextureAlpha = other.TextureAlpha;
|
||||
TextureMode = other.TextureMode;
|
||||
@ -465,12 +454,17 @@ namespace NSStructures
|
||||
|
||||
LinearAngle = other.LinearAngle;
|
||||
m_arrSubColors = other.m_arrSubColors;
|
||||
m_oGradientInfo = other.m_oGradientInfo;
|
||||
m_oGradientInfo = other.m_oGradientInfo;
|
||||
|
||||
return *this;
|
||||
}
|
||||
virtual ~CBrush()
|
||||
{
|
||||
if (NULL != Image)
|
||||
{
|
||||
((IGrObject*)Image)->Release();
|
||||
Image = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int IsTexture()
|
||||
|
||||
26
DesktopEditor/graphics/tests/alphaMask/alphaMask.pro
Normal file
26
DesktopEditor/graphics/tests/alphaMask/alphaMask.pro
Normal file
@ -0,0 +1,26 @@
|
||||
#CONFIG += c++11 cmdline
|
||||
|
||||
#SOURCES += \
|
||||
QT -= core
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = test
|
||||
CONFIG += console
|
||||
TEMPLATE = app
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
|
||||
|
||||
ADD_DEPENDENCY(kernel, graphics, UnicodeConverter)
|
||||
|
||||
GRAPHICS_AGG_PATH = $$PWD/../../../agg-2.4
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$GRAPHICS_AGG_PATH/include
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX
|
||||
142
DesktopEditor/graphics/tests/alphaMask/main.cpp
Normal file
142
DesktopEditor/graphics/tests/alphaMask/main.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
#include "../../pro/Graphics.h"
|
||||
#include "../../../raster/BgraFrame.h"
|
||||
#include "../../../common/Directory.h"
|
||||
#include "../../AlphaMask.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NSGraphics::IGraphicsRenderer* pRasterRenderer = NSGraphics::Create();
|
||||
|
||||
unsigned int unWidth = 1000;
|
||||
unsigned int unHeight = 1000;
|
||||
|
||||
// Создание основной картинки
|
||||
BYTE* pData = new BYTE[4 * unWidth * unHeight];
|
||||
|
||||
for (unsigned long unIndex = 0; unIndex < unWidth * unHeight; ++unIndex)
|
||||
((unsigned int*)pData)[unIndex] = 0xffffff;
|
||||
|
||||
CBgraFrame oFrame;
|
||||
oFrame.put_Data(pData);
|
||||
oFrame.put_Width(unWidth);
|
||||
oFrame.put_Height(unHeight);
|
||||
oFrame.put_Stride(4 * unWidth);
|
||||
|
||||
pRasterRenderer->CreateFromBgraFrame(&oFrame);
|
||||
pRasterRenderer->SetSwapRGB(false);
|
||||
|
||||
double dW_MM = unWidth;
|
||||
double dH_MM = unHeight;
|
||||
|
||||
pRasterRenderer->put_Width(dW_MM);
|
||||
pRasterRenderer->put_Height(dH_MM);
|
||||
|
||||
enum
|
||||
{
|
||||
GenerationMask,
|
||||
LoadMaskFromBuffer,
|
||||
LoadMaskFromFile
|
||||
} enMode = LoadMaskFromBuffer;
|
||||
|
||||
switch (enMode)
|
||||
{
|
||||
case GenerationMask:
|
||||
{
|
||||
// Генерируем маску
|
||||
pRasterRenderer->BeginCommand(c_nMaskType);
|
||||
pRasterRenderer->PathCommandStart();
|
||||
|
||||
pRasterRenderer->PathCommandMoveTo(0, 300);
|
||||
pRasterRenderer->PathCommandLineTo(1000, 300);
|
||||
pRasterRenderer->PathCommandLineTo(1000, 700);
|
||||
pRasterRenderer->PathCommandLineTo(0, 700);
|
||||
pRasterRenderer->PathCommandClose();
|
||||
|
||||
// Задаем значения для пера и кисти маски
|
||||
pRasterRenderer->put_PenSize(100);
|
||||
pRasterRenderer->put_PenColor(16777215); // белый 16777215
|
||||
|
||||
pRasterRenderer->put_BrushAlpha1(255);
|
||||
pRasterRenderer->put_BrushColor1(8355711); // серый
|
||||
|
||||
pRasterRenderer->Stroke();
|
||||
pRasterRenderer->Fill();
|
||||
|
||||
pRasterRenderer->EndCommand(c_nMaskType);
|
||||
pRasterRenderer->PathCommandEnd();
|
||||
|
||||
break;
|
||||
}
|
||||
case LoadMaskFromBuffer:
|
||||
{
|
||||
Aggplus::CAlphaMask* pAlphaMask = new Aggplus::CAlphaMask();
|
||||
|
||||
BYTE* pAlphaBuffer = new BYTE[unWidth * unHeight];
|
||||
|
||||
BYTE uchAlphaValue = 0;
|
||||
|
||||
for (UINT unRow = 0; unRow < unHeight; ++unRow)
|
||||
{
|
||||
for (UINT unColumn = 0; unColumn < unWidth; ++unColumn)
|
||||
pAlphaBuffer[unRow * unWidth + unColumn] = uchAlphaValue;
|
||||
|
||||
if (0 != unRow && 0 == unRow % 100)
|
||||
uchAlphaValue += 25;
|
||||
}
|
||||
|
||||
pAlphaMask->LoadFromAlphaBuffer(pAlphaBuffer, unWidth, unHeight, false);
|
||||
|
||||
pRasterRenderer->SetAlphaMask(pAlphaMask);
|
||||
|
||||
pAlphaMask->Release();
|
||||
break;
|
||||
}
|
||||
case LoadMaskFromFile:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Отрисовываем тестовый объект
|
||||
pRasterRenderer->BeginCommand(c_nPathType);
|
||||
pRasterRenderer->PathCommandStart();
|
||||
|
||||
// pRasterRenderer->PathCommandMoveTo(400, 0);
|
||||
// pRasterRenderer->PathCommandLineTo(600, 0);
|
||||
// pRasterRenderer->PathCommandLineTo(600, 1000);
|
||||
// pRasterRenderer->PathCommandLineTo(400, 1000);
|
||||
// pRasterRenderer->PathCommandClose();
|
||||
|
||||
pRasterRenderer->PathCommandMoveTo(300, 100);
|
||||
pRasterRenderer->PathCommandLineTo(700, 100);
|
||||
pRasterRenderer->PathCommandLineTo(900, 300);
|
||||
pRasterRenderer->PathCommandLineTo(900, 700);
|
||||
pRasterRenderer->PathCommandLineTo(700, 900);
|
||||
pRasterRenderer->PathCommandLineTo(300, 900);
|
||||
pRasterRenderer->PathCommandLineTo(100, 700);
|
||||
pRasterRenderer->PathCommandLineTo(100, 300);
|
||||
pRasterRenderer->PathCommandClose();
|
||||
|
||||
// Задаем значения для пера и кисти
|
||||
pRasterRenderer->put_PenSize(100);
|
||||
pRasterRenderer->put_PenColor(255); // красный
|
||||
|
||||
pRasterRenderer->put_BrushAlpha1(255);
|
||||
pRasterRenderer->put_BrushColor1(65280); // зеленый
|
||||
|
||||
pRasterRenderer->Stroke();
|
||||
pRasterRenderer->Fill();
|
||||
|
||||
//Сбрасываем маску
|
||||
pRasterRenderer->BeginCommand(c_nResetMaskType);
|
||||
pRasterRenderer->EndCommand(c_nResetMaskType);
|
||||
|
||||
pRasterRenderer->PathCommandEnd();
|
||||
pRasterRenderer->EndCommand(c_nPathType);
|
||||
|
||||
oFrame.SaveFile(L"testAlphaMask.png", 4);
|
||||
|
||||
RELEASEINTERFACE(pRasterRenderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
DesktopEditor/graphics/tests/gradients/gradients.pro
Normal file
23
DesktopEditor/graphics/tests/gradients/gradients.pro
Normal file
@ -0,0 +1,23 @@
|
||||
QT -= core
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = test
|
||||
CONFIG += console
|
||||
TEMPLATE = app
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
|
||||
|
||||
ADD_DEPENDENCY(kernel, graphics, UnicodeConverter)
|
||||
|
||||
GRAPHICS_AGG_PATH = $$PWD/../../../agg-2.4
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$GRAPHICS_AGG_PATH/include
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX
|
||||
131
DesktopEditor/graphics/tests/gradients/main.cpp
Normal file
131
DesktopEditor/graphics/tests/gradients/main.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
#include "../../pro/Graphics.h"
|
||||
#include "../../../raster/BgraFrame.h"
|
||||
#include "../../../common/Directory.h"
|
||||
|
||||
#ifndef RGBA_TO_INT
|
||||
#define RGBA_TO_INT(r, g, b, a) ((unsigned int)( ( (unsigned char)(r) )| ( ( (unsigned char)(g) ) << 8 ) | ( ( (unsigned char)(b) ) << 16 ) ) | ( ( (unsigned char)(a) ) << 24 ) )
|
||||
#endif
|
||||
|
||||
struct TRectD
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
double m_dWidth;
|
||||
double m_dHeight;
|
||||
};
|
||||
|
||||
void StartDrawing(IRenderer* pRenderer)
|
||||
{
|
||||
pRenderer->BeginCommand(c_nPathType);
|
||||
pRenderer->PathCommandStart();
|
||||
}
|
||||
|
||||
void DrawRectangle(IRenderer* pRenderer, const TRectD& oRect)
|
||||
{
|
||||
pRenderer->PathCommandMoveTo(oRect.m_dX, oRect.m_dY);
|
||||
pRenderer->PathCommandLineTo(oRect.m_dX + oRect.m_dWidth, oRect.m_dY);
|
||||
pRenderer->PathCommandLineTo(oRect.m_dX + oRect.m_dWidth, oRect.m_dY + oRect.m_dHeight);
|
||||
pRenderer->PathCommandLineTo(oRect.m_dX, oRect.m_dY + oRect.m_dHeight);
|
||||
pRenderer->PathCommandClose();
|
||||
}
|
||||
|
||||
void EndDrawing(IRenderer* pRenderer)
|
||||
{
|
||||
pRenderer->EndCommand(c_nPathType);
|
||||
pRenderer->DrawPath(c_nWindingFillMode);
|
||||
pRenderer->PathCommandEnd();
|
||||
}
|
||||
|
||||
#define USETRANSFORM 0 // используем для трансформации Transform (1) или Bounds (0)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NSGraphics::IGraphicsRenderer* pRasterRenderer = NSGraphics::Create();
|
||||
|
||||
unsigned int unWidth = 1000;
|
||||
unsigned int unHeight = 1000;
|
||||
|
||||
// Создание основной картинки
|
||||
BYTE* pData = new BYTE[4 * unWidth * unHeight];
|
||||
|
||||
for (unsigned long unIndex = 0; unIndex < unWidth * unHeight; ++unIndex)
|
||||
((unsigned int*)pData)[unIndex] = 0xffffff;
|
||||
|
||||
CBgraFrame oFrame;
|
||||
oFrame.put_Data(pData);
|
||||
oFrame.put_Width(unWidth);
|
||||
oFrame.put_Height(unHeight);
|
||||
oFrame.put_Stride(4 * unWidth);
|
||||
|
||||
pRasterRenderer->CreateFromBgraFrame(&oFrame);
|
||||
pRasterRenderer->SetSwapRGB(false);
|
||||
|
||||
double dW_MM = unWidth;
|
||||
double dH_MM = unHeight;
|
||||
|
||||
pRasterRenderer->put_Width(dW_MM);
|
||||
pRasterRenderer->put_Height(dH_MM);
|
||||
|
||||
// Объявляем цвета градиента и их позиции
|
||||
const UINT unCountColors = 3;
|
||||
|
||||
LONG *pColors = new LONG[unCountColors];
|
||||
double *pPositions = new double[unCountColors];
|
||||
|
||||
pColors[0] = RGBA_TO_INT(255, 0, 0, 255); // Красный
|
||||
pColors[1] = RGBA_TO_INT(255, 255, 255, 255); // Белый
|
||||
pColors[2] = RGBA_TO_INT(0, 0, 255, 255); // Синий
|
||||
|
||||
pPositions[0] = 0;
|
||||
pPositions[1] = 0.5;
|
||||
pPositions[2] = 1;
|
||||
|
||||
pRasterRenderer->put_BrushType(c_BrushTypePathGradient1);
|
||||
pRasterRenderer->put_BrushGradientColors(pColors, pPositions, unCountColors);
|
||||
|
||||
// Создадим 3 прямоугольника, которые будут заполнены градиентами
|
||||
TRectD oRect1{100, 100, 800, 200};
|
||||
TRectD oRect2{100, 400, 800, 200};
|
||||
TRectD oRect3{100, 700, 800, 200};
|
||||
|
||||
// Отрисовываем первый прямоугольник (градиент без изменений)
|
||||
StartDrawing(pRasterRenderer);
|
||||
DrawRectangle(pRasterRenderer, oRect1);
|
||||
pRasterRenderer->BrushBounds(oRect1.m_dX, oRect1.m_dY, oRect1.m_dWidth, oRect1.m_dHeight);
|
||||
EndDrawing(pRasterRenderer);
|
||||
|
||||
// Отрисовываем второй прямоугольник (сам градиент в 2 раза больше, а размер прямоугольника без изменений)
|
||||
StartDrawing(pRasterRenderer);
|
||||
DrawRectangle(pRasterRenderer, oRect2);
|
||||
const double dXScale = 2;
|
||||
const double dYScale = 2;
|
||||
#if USETRANSFORM == 1
|
||||
pRasterRenderer->put_BrushTransform(Aggplus::CMatrix(dXScale, 0., 0., dYScale, 0., 0.));
|
||||
pRasterRenderer->BrushBounds(oRect2.m_dX, oRect2.m_dY, oRect2.m_dWidth, oRect2.m_dHeight);
|
||||
#else
|
||||
pRasterRenderer->BrushBounds(oRect2.m_dX, oRect2.m_dY, oRect2.m_dWidth * dXScale, oRect2.m_dHeight * dYScale);
|
||||
#endif
|
||||
EndDrawing(pRasterRenderer);
|
||||
|
||||
// Отрисовываем второй прямоугольник (сам градиент смещен вправо)
|
||||
StartDrawing(pRasterRenderer);
|
||||
DrawRectangle(pRasterRenderer, oRect3);
|
||||
const double dSkipX = 200;
|
||||
const double dSkipY = 0;
|
||||
#if USETRANSFORM == 1
|
||||
pRasterRenderer->put_BrushTransform(Aggplus::CMatrix(1., 0., 0., 1., dSkipX, dSkipY));
|
||||
pRasterRenderer->BrushBounds(oRect3.m_dX, oRect3.m_dY, oRect3.m_dWidth, oRect3.m_dHeight);
|
||||
#else
|
||||
pRasterRenderer->BrushBounds(oRect3.m_dX + dSkipX, oRect3.m_dY + dSkipY, oRect3.m_dWidth, oRect3.m_dHeight);
|
||||
#endif
|
||||
EndDrawing(pRasterRenderer);
|
||||
|
||||
oFrame.SaveFile(L"testGradients.png", 4);
|
||||
|
||||
delete [] pColors;
|
||||
delete [] pPositions;
|
||||
|
||||
RELEASEINTERFACE(pRasterRenderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -620,7 +620,7 @@ public:
|
||||
if (DownloadFile(sConfigUrl, sTmpFile))
|
||||
{
|
||||
std::vector<std::wstring> arr;
|
||||
if ( ReadConfigJson(sTmpFile, arr) )
|
||||
if ( ReadStoreConfig(sTmpFile, arr) )
|
||||
{
|
||||
for (size_t i = 0; i < arr.size(); i++)
|
||||
{
|
||||
@ -632,7 +632,12 @@ public:
|
||||
{
|
||||
pPluginInfo = FetchPluginInfo(sPluginName);
|
||||
if ( pPluginInfo )
|
||||
{
|
||||
m_arrMarketplace.push_back(pPluginInfo);
|
||||
|
||||
if ( bPrint )
|
||||
MessagePluginInfo(pPluginInfo->m_sNameConfig, pPluginInfo->m_pVersion->m_sVersion, pPluginInfo->m_sGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -640,15 +645,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if ( bPrint )
|
||||
{
|
||||
for (size_t i = 0; i < m_arrMarketplace.size(); i++)
|
||||
{
|
||||
CPluginInfo* pPluginInfo = m_arrMarketplace[i];
|
||||
MessagePluginInfo(pPluginInfo->m_sNameConfig, pPluginInfo->m_pVersion->m_sVersion, pPluginInfo->m_sGuid);
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
@ -1247,6 +1243,29 @@ private:
|
||||
return arrOutput.size() > 0;
|
||||
}
|
||||
|
||||
bool ReadStoreConfig(const std::wstring& sFile, std::vector<std::wstring>& arrOutput)
|
||||
{
|
||||
// [ { "name": "", "discussion": "" }, ... ]
|
||||
std::wstring sJson = L"";
|
||||
if (NSFile::CFileBinary::Exists(sFile) && NSFile::CFileBinary::ReadAllTextUtf8(sFile, sJson))
|
||||
{
|
||||
std::wstring sDelim = L"\"name\": \"";
|
||||
std::wstring::size_type pos1 = sJson.find(sDelim);
|
||||
|
||||
while ( pos1 != std::wstring::npos )
|
||||
{
|
||||
std::wstring::size_type pos2 = sJson.find(L"\"", pos1 + sDelim.length());
|
||||
|
||||
if (pos1 != std::wstring::npos && pos2 > pos1)
|
||||
arrOutput.push_back(sJson.substr(pos1 + sDelim.length(), pos2 - pos1 - sDelim.length()));
|
||||
|
||||
pos1 = sJson.find(sDelim, pos2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return arrOutput.size() > 0;
|
||||
}
|
||||
|
||||
void StringReplaceExt(std::wstring& sText, const std::wstring& sFrom, const std::wstring& sTo)
|
||||
{
|
||||
if ( sText.length() )
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
*/
|
||||
#include "ImageFileFormatChecker.h"
|
||||
#include "../common/File.h"
|
||||
#include "../xml/include/xmlutils.h"
|
||||
|
||||
#include "../cximage/CxImage/ximacfg.h"
|
||||
|
||||
@ -439,93 +440,92 @@ bool CImageFileFormatChecker::isImageFile(std::wstring& fileName)
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_GIF;
|
||||
}
|
||||
if (isPngFile(buffer,sizeRead))
|
||||
else if (isPngFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_PNG;
|
||||
}
|
||||
if (isTgaFile(buffer,sizeRead))
|
||||
else if (isTgaFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_TGA;
|
||||
}
|
||||
if (isPcxFile(buffer,sizeRead))
|
||||
else if (isPcxFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_PCX;
|
||||
}
|
||||
if (isJpgFile(buffer,sizeRead))
|
||||
else if (isJpgFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_JPG;
|
||||
}
|
||||
if (isEmfFile(buffer,sizeRead))
|
||||
else if (isEmfFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_EMF;
|
||||
}
|
||||
if (isWmfFile(buffer,sizeRead))
|
||||
else if (isWmfFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_WMF;
|
||||
}
|
||||
if (isTiffFile(buffer,sizeRead))
|
||||
else if (isTiffFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_TIF;
|
||||
}
|
||||
if (isIcoFile(buffer,sizeRead))
|
||||
else if (isIcoFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_ICO;
|
||||
}
|
||||
if (isWbFile(buffer,sizeRead))
|
||||
else if (isWbFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_WB;
|
||||
}
|
||||
if (isPsdFile(buffer,sizeRead))
|
||||
else if (isPsdFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_PSD;
|
||||
}
|
||||
if (isRasFile(buffer,sizeRead))
|
||||
else if (isRasFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_RAS;
|
||||
}
|
||||
|
||||
if (isIpodFile(buffer,sizeRead))
|
||||
else if (isIpodFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
if (isJ2kFile(buffer,sizeRead))
|
||||
else if (isJ2kFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_JP2;
|
||||
}
|
||||
if (isJp2File(buffer,sizeRead))
|
||||
else if (isJp2File(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_JP2;
|
||||
}
|
||||
if (isMj2File(buffer,sizeRead))
|
||||
else if (isMj2File(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_JP2;
|
||||
}
|
||||
if (isSfwFile(buffer,sizeRead))
|
||||
else if (isSfwFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
if (isSvmFile(buffer,sizeRead))
|
||||
else if (isSvmFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
if (isSwfFile(buffer,sizeRead))
|
||||
else if (isSwfFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
if (isWbcFile(buffer,sizeRead))
|
||||
else if (isWbcFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
if (isWbzFile(buffer,sizeRead))
|
||||
else if (isWbzFile(buffer,sizeRead))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
if (isSvgFile(fileName))
|
||||
//----------------------------------------------------------------
|
||||
else if (isSvgFile(fileName))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_SVG;
|
||||
}
|
||||
if (isRawFile(fileName))
|
||||
else if (isRawFile(fileName))
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
@ -718,51 +718,16 @@ bool CImageFileFormatChecker::isRawFile(BYTE* pBuffer, DWORD dwBytes)
|
||||
}
|
||||
bool CImageFileFormatChecker::isSvgFile(std::wstring& fileName)
|
||||
{
|
||||
NSFile::CFileBinary file;
|
||||
if (!file.OpenFile(fileName))
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
if (!oReader.FromFile(fileName))
|
||||
return false;
|
||||
if (!oReader.ReadNextNode())
|
||||
return false;
|
||||
|
||||
DWORD nSize = (DWORD)file.GetFileSize();
|
||||
if (nSize > 100)
|
||||
nSize = 100;
|
||||
|
||||
BYTE* buffer = new BYTE[nSize];
|
||||
if (!buffer)
|
||||
return false;
|
||||
|
||||
DWORD sizeRead = 0;
|
||||
if (!file.ReadFile(buffer, nSize, sizeRead))
|
||||
{
|
||||
delete []buffer;
|
||||
return false;
|
||||
}
|
||||
file.CloseFile();
|
||||
|
||||
if ('<' == buffer[0] &&
|
||||
's' == buffer[1] &&
|
||||
'v' == buffer[2] &&
|
||||
'g' == buffer[3])
|
||||
{
|
||||
delete [] buffer;
|
||||
if (L"svg" == oReader.GetNameNoNS())
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('<' == buffer[0] &&
|
||||
'?' == buffer[1] &&
|
||||
'x' == buffer[2] &&
|
||||
'm' == buffer[3] &&
|
||||
'l' == buffer[4])
|
||||
{
|
||||
std::string test((char*)buffer, nSize);
|
||||
if (std::string::npos != test.find("<svg"))
|
||||
{
|
||||
delete [] buffer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
return false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring CImageFileFormatChecker::DetectFormatByData(BYTE *Data, int DataSize)
|
||||
|
||||
@ -120,7 +120,7 @@ namespace MetaFile
|
||||
|
||||
return true;
|
||||
}
|
||||
void Close()
|
||||
void Close()
|
||||
{
|
||||
if (!m_bIsExternalBuffer)
|
||||
RELEASEARRAYOBJECTS(m_pBufferData);
|
||||
@ -131,7 +131,7 @@ namespace MetaFile
|
||||
|
||||
this->ClearFile();
|
||||
}
|
||||
void Scan()
|
||||
void Scan()
|
||||
{
|
||||
IOutputDevice* pOutput = m_pOutput;
|
||||
m_pOutput = NULL;
|
||||
@ -144,19 +144,19 @@ namespace MetaFile
|
||||
{
|
||||
return m_pFontManager;
|
||||
}
|
||||
void SetFontManager(NSFonts::IFontManager* pFontManager)
|
||||
void SetFontManager(NSFonts::IFontManager* pFontManager)
|
||||
{
|
||||
m_pFontManager = pFontManager;
|
||||
}
|
||||
void SetOutputDevice(IOutputDevice* pOutput)
|
||||
void SetOutputDevice(IOutputDevice* pOutput)
|
||||
{
|
||||
m_pOutput = pOutput;
|
||||
}
|
||||
void SetError()
|
||||
void SetError()
|
||||
{
|
||||
m_bError = true;
|
||||
}
|
||||
bool CheckError()
|
||||
bool CheckError()
|
||||
{
|
||||
return m_bError;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ namespace MetaFile
|
||||
{
|
||||
pBuffer = pBuf;
|
||||
pCur = pBuf;
|
||||
pEnd = pBuf + unSize + 1;
|
||||
pEnd = pBuf + unSize;
|
||||
};
|
||||
BYTE* GetCurPtr()
|
||||
{
|
||||
@ -112,7 +112,7 @@ namespace MetaFile
|
||||
|
||||
unsigned char ReadUChar()
|
||||
{
|
||||
if (pCur + 1 >= pEnd)
|
||||
if (pCur >= pEnd)
|
||||
return 0;
|
||||
|
||||
unsigned char unResult = pCur[0];
|
||||
@ -121,7 +121,7 @@ namespace MetaFile
|
||||
};
|
||||
unsigned short ReadUShort()
|
||||
{
|
||||
if (pCur + 2 >= pEnd)
|
||||
if (pCur + 1 >= pEnd)
|
||||
return 0;
|
||||
|
||||
unsigned short ushResult = (pCur[0]) | ((pCur[1]) << 8);
|
||||
@ -130,7 +130,7 @@ namespace MetaFile
|
||||
};
|
||||
unsigned int ReadULong()
|
||||
{
|
||||
if (pCur + 4 >= pEnd)
|
||||
if (pCur + 3 >= pEnd)
|
||||
return 0;
|
||||
|
||||
unsigned int unResult = (unsigned int)((pCur[0] << 0) | ((pCur[1]) << 8) | ((pCur[2]) << 16) | ((pCur[3]) << 24));
|
||||
@ -139,7 +139,7 @@ namespace MetaFile
|
||||
};
|
||||
double ReadDouble()
|
||||
{
|
||||
if (pCur + 4 >= pEnd)
|
||||
if (pCur + 3 >= pEnd)
|
||||
return 0;
|
||||
|
||||
float output;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#endif
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
{
|
||||
CEmfInterpretatorSvg::CEmfInterpretatorSvg(CEmfParserBase* pParser, double dWidth, double dHeight)
|
||||
: CInterpretatorSvgBase(pParser, dWidth, dHeight)
|
||||
{}
|
||||
@ -49,17 +49,17 @@ namespace MetaFile
|
||||
m_oViewport.dRight = oTEmfHeader.oFramePx.lRight;
|
||||
m_oViewport.dBottom = oTEmfHeader.oFramePx.lBottom;
|
||||
|
||||
m_oXmlWriter.WriteNodeBegin(L"svg", true);
|
||||
m_oXmlWriter.WriteAttribute(L"xmlns", L"http://www.w3.org/2000/svg");
|
||||
m_oXmlWriter.WriteAttribute(L"xmlns:xlink", L"http://www.w3.org/1999/xlink");
|
||||
m_pXmlWriter->WriteNodeBegin(L"svg", true);
|
||||
m_pXmlWriter->WriteAttribute(L"xmlns", L"http://www.w3.org/2000/svg");
|
||||
m_pXmlWriter->WriteAttribute(L"xmlns:xlink", L"http://www.w3.org/1999/xlink");
|
||||
|
||||
UpdateSize();
|
||||
|
||||
if (m_oViewport.GetWidth() != 0)
|
||||
m_oXmlWriter.WriteAttribute(L"width", ConvertToWString(m_oViewport.GetWidth()));
|
||||
m_pXmlWriter->WriteAttribute(L"width", ConvertToWString(m_oViewport.GetWidth()));
|
||||
|
||||
if (m_oViewport.GetHeight() != 0)
|
||||
m_oXmlWriter.WriteAttribute(L"height", ConvertToWString(m_oViewport.GetHeight()));
|
||||
m_pXmlWriter->WriteAttribute(L"height", ConvertToWString(m_oViewport.GetHeight()));
|
||||
|
||||
double dXScale = 1, dYScale = 1, dXTranslate = 0, dYTranslate = 0;
|
||||
|
||||
@ -82,17 +82,17 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
if (1 != dXScale || 1 != dYScale)
|
||||
m_oXmlWriter.WriteAttribute(L"transform", L"matrix(" + std::to_wstring(dXScale) + L",0,0," + std::to_wstring(dYScale) + L',' + ConvertToWString(dXTranslate) + L',' + ConvertToWString(dYTranslate) + L')');
|
||||
m_pXmlWriter->WriteAttribute(L"transform", L"matrix(" + std::to_wstring(dXScale) + L",0,0," + std::to_wstring(dYScale) + L',' + ConvertToWString(dXTranslate) + L',' + ConvertToWString(dYTranslate) + L')');
|
||||
|
||||
m_oXmlWriter.WriteNodeEnd(L"svg", true, false);
|
||||
m_pXmlWriter->WriteNodeEnd(L"svg", true, false);
|
||||
}
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMR_EOF()
|
||||
{
|
||||
ResetClip();
|
||||
if (!m_wsDefs.empty())
|
||||
m_oXmlWriter.WriteString(L"<defs>" + m_wsDefs + L"</defs>");
|
||||
m_oXmlWriter.WriteNodeEnd(L"svg", false, false);
|
||||
m_pXmlWriter->WriteString(L"<defs>" + m_wsDefs + L"</defs>");
|
||||
m_pXmlWriter->WriteNodeEnd(L"svg", false, false);
|
||||
}
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMR_RESTOREDC(const int &nIndexDC)
|
||||
@ -161,12 +161,12 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(dStartX) + L' ' + ConvertToWString(dStartY);
|
||||
|
||||
wsValue += L" A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -224,12 +224,12 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(oStartPoint.x) + L' ' + ConvertToWString(oStartPoint.y);
|
||||
|
||||
wsValue += L" A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -278,12 +278,12 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(dStartX) + L' ' + ConvertToWString(dStartY);
|
||||
|
||||
wsValue += L" A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY);
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -317,9 +317,9 @@ namespace MetaFile
|
||||
TRectD oNewRect = TranslateRect(oBox);
|
||||
|
||||
NodeAttributes arAttributes = {{L"cx", ConvertToWString((oNewRect.dLeft + oNewRect.dRight) / 2)},
|
||||
{L"cy", ConvertToWString((oNewRect.dTop + oNewRect.dBottom) / 2)},
|
||||
{L"rx", ConvertToWString((oNewRect.dRight - oNewRect.dLeft) / 2)},
|
||||
{L"ry", ConvertToWString((oNewRect.dBottom - oNewRect.dTop) / 2)}};
|
||||
{L"cy", ConvertToWString((oNewRect.dTop + oNewRect.dBottom) / 2)},
|
||||
{L"rx", ConvertToWString((oNewRect.dRight - oNewRect.dLeft) / 2)},
|
||||
{L"ry", ConvertToWString((oNewRect.dBottom - oNewRect.dTop) / 2)}};
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
@ -357,9 +357,9 @@ namespace MetaFile
|
||||
TPointD oCurPos = GetCutPos();
|
||||
|
||||
NodeAttributes arAttributes = {{L"x1", ConvertToWString(oCurPos.x)},
|
||||
{L"y1", ConvertToWString(oCurPos.y)},
|
||||
{L"x2", ConvertToWString(oPoint.x)},
|
||||
{L"y2", ConvertToWString(oPoint.y)}};
|
||||
{L"y1", ConvertToWString(oCurPos.y)},
|
||||
{L"x2", ConvertToWString(oPoint.x)},
|
||||
{L"y2", ConvertToWString(oPoint.y)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
@ -400,8 +400,8 @@ namespace MetaFile
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L' ' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -422,8 +422,8 @@ namespace MetaFile
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L' ' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -444,8 +444,8 @@ namespace MetaFile
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L' ' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -466,8 +466,8 @@ namespace MetaFile
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L' ' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L' ' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L' ' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -507,8 +507,8 @@ namespace MetaFile
|
||||
oLastType = 0x04;
|
||||
}
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L',' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L',' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L',' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L',' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L',' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
unIndex += 3;
|
||||
}
|
||||
@ -557,8 +557,8 @@ namespace MetaFile
|
||||
oLastType = 0x04;
|
||||
}
|
||||
wsValue += ConvertToWString(arPoints[unIndex].x) + L',' + ConvertToWString(arPoints[unIndex].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L',' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L',' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
ConvertToWString(arPoints[unIndex + 1].x) + L',' + ConvertToWString(arPoints[unIndex + 1].y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].x) + L',' + ConvertToWString(arPoints[unIndex + 2].y) + L' ';
|
||||
|
||||
unIndex += 3;
|
||||
}
|
||||
@ -826,9 +826,9 @@ namespace MetaFile
|
||||
TRectD oNewRect = TranslateRect(oBox);
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.dLeft)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)}};
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes, oNewRect.dRight - oNewRect.dLeft, oNewRect.dBottom - oNewRect.dTop);
|
||||
@ -843,9 +843,9 @@ namespace MetaFile
|
||||
TRectD oNewRect = TranslateRect(oBox);
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.dLeft)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)},
|
||||
{L"rx", ConvertToWString((double)oCorner.cx / 2.)},
|
||||
{L"ry", ConvertToWString((double)oCorner.cy / 2.)}};
|
||||
|
||||
@ -1056,12 +1056,12 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(oNewRect.dLeft) + L' ' + ConvertToWString(oNewRect.dTop);
|
||||
|
||||
wsValue += L" A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(oNewRect.dRight) + L' ' +
|
||||
ConvertToWString(oNewRect.dBottom);
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(oNewRect.dRight) + L' ' +
|
||||
ConvertToWString(oNewRect.dBottom);
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -1606,12 +1606,12 @@ namespace MetaFile
|
||||
double dEndY = (oPoint2.y + oPoint1.x) / 2 + dYRadius * sin((pArcTo->sweep) * M_PI / 180);
|
||||
|
||||
wsValue += L"A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(pArcTo->sweep - pArcTo->start) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(pArcTo->sweep - pArcTo->start) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY) + L' ';
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 " +
|
||||
((std::fabs(pArcTo->sweep - pArcTo->start) <= 180) ? L"0" : L"1") + L' ' +
|
||||
((std::fabs(pArcTo->sweep - pArcTo->start) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dEndX) + L' ' +
|
||||
ConvertToWString(dEndY) + L' ';
|
||||
|
||||
oLastType = EMF_PATHCOMMAND_ARCTO;
|
||||
|
||||
|
||||
@ -57,6 +57,9 @@ namespace MetaFile
|
||||
if (ulSize < 1)
|
||||
continue;
|
||||
|
||||
if (ulSize - 8 > m_oStream.CanRead())
|
||||
return SetError();
|
||||
|
||||
m_ulRecordPos = m_oStream.Tell();
|
||||
m_ulRecordSize = ulSize - 8;
|
||||
|
||||
@ -1512,33 +1515,48 @@ namespace MetaFile
|
||||
oWmfParser.SetStream(m_oStream.GetCurPtr(), unWinMetafileSize);
|
||||
oWmfParser.Scan();
|
||||
|
||||
if (!oWmfParser.CheckError())
|
||||
if (oWmfParser.CheckError())
|
||||
return;
|
||||
|
||||
if (NULL == m_pInterpretator)
|
||||
HANDLE_EMR_EOF();
|
||||
else if (InterpretatorType::Render == m_pInterpretator->GetType())
|
||||
{
|
||||
if (NULL != m_pInterpretator && InterpretatorType::Render == m_pInterpretator->GetType())
|
||||
{
|
||||
CMetaFileRenderer oWmfOut(&oWmfParser, ((CEmfInterpretatorRender*)m_pInterpretator)->GetRenderer());
|
||||
oWmfParser.SetInterpretator(&oWmfOut);
|
||||
|
||||
oWmfParser.PlayFile();
|
||||
|
||||
m_bEof = true;
|
||||
}
|
||||
else if (NULL != m_pInterpretator && InterpretatorType::Svg == m_pInterpretator->GetType())
|
||||
{
|
||||
double dWidth, dHeight;
|
||||
|
||||
((CEmfInterpretatorSvg*)m_pInterpretator)->GetSize(dWidth, dHeight);
|
||||
|
||||
((CWmfParserBase*)&oWmfParser)->SetInterpretator(InterpretatorType::Svg, dWidth, dHeight);
|
||||
|
||||
oWmfParser.PlayFile();
|
||||
|
||||
((CEmfInterpretatorSvg*)m_pInterpretator)->SetXmlWriter(((CWmfInterpretatorSvg*)oWmfParser.GetInterpretator())->GetXmlWriter());
|
||||
|
||||
m_bEof = true;
|
||||
}
|
||||
HANDLE_EMR_EOF();
|
||||
}
|
||||
else if (NULL != m_pInterpretator && InterpretatorType::Svg == m_pInterpretator->GetType())
|
||||
{
|
||||
double dWidth, dHeight;
|
||||
|
||||
((CEmfInterpretatorSvg*)m_pInterpretator)->GetSize(dWidth, dHeight);
|
||||
|
||||
((CWmfParserBase*)&oWmfParser)->SetInterpretator(InterpretatorType::Svg, dWidth, dHeight);
|
||||
|
||||
XmlUtils::CXmlWriter *pXmlWriter = ((CEmfInterpretatorSvg*)m_pInterpretator)->GetXmlWriter();
|
||||
|
||||
TRectD oWmfRect = oWmfParser.GetBounds();
|
||||
TEmfRectL *pCuurentRect = GetBounds();
|
||||
|
||||
double dScaleX = std::abs((pCuurentRect->lRight - pCuurentRect->lLeft) / (oWmfRect.dRight - oWmfRect.dLeft));
|
||||
double dScaleY = std::abs((pCuurentRect->lBottom - pCuurentRect->lTop) / (oWmfRect.dBottom - oWmfRect.dTop));
|
||||
|
||||
pXmlWriter->WriteNodeBegin(L"g", true);
|
||||
pXmlWriter->WriteAttribute(L"transform", L"scale(" + std::to_wstring(dScaleX) + L',' + std::to_wstring(dScaleY) + L')');
|
||||
pXmlWriter->WriteNodeEnd(L"g", true, false);
|
||||
|
||||
((CWmfInterpretatorSvg*)oWmfParser.GetInterpretator())->SetXmlWriter(pXmlWriter);
|
||||
|
||||
oWmfParser.PlayFile();
|
||||
|
||||
pXmlWriter->WriteNodeEnd(L"g", false, false);
|
||||
|
||||
HANDLE_EMR_EOF();
|
||||
}
|
||||
|
||||
m_oStream.Skip(unWinMetafileSize);
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ namespace MetaFile
|
||||
{
|
||||
public:
|
||||
CEmfParserBase();
|
||||
~CEmfParserBase();
|
||||
virtual ~CEmfParserBase();
|
||||
|
||||
virtual bool ReadFromBuffer(BYTE* pBuffer, unsigned int unSize, const bool& bIsExternal = true) = 0;
|
||||
virtual bool OpenFromFile(const wchar_t*) = 0;
|
||||
|
||||
@ -37,16 +37,16 @@
|
||||
namespace MetaFile
|
||||
{
|
||||
CEmfPlayer::CEmfPlayer(CEmfParserBase* pParser)
|
||||
: m_pParser(pParser)
|
||||
{
|
||||
m_pDC = new CEmfDC(this);
|
||||
|
||||
if (!m_pDC)
|
||||
{
|
||||
pParser->SetError();
|
||||
if (NULL != m_pParser) m_pParser->SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
m_pParser = pParser;
|
||||
|
||||
InitStockObjects();
|
||||
};
|
||||
CEmfPlayer::~CEmfPlayer()
|
||||
@ -88,7 +88,7 @@ namespace MetaFile
|
||||
m_pDC = new CEmfDC(this);
|
||||
if (!m_pDC)
|
||||
{
|
||||
m_pParser->SetError();
|
||||
if (NULL != m_pParser) m_pParser->SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -102,14 +102,14 @@ namespace MetaFile
|
||||
{
|
||||
if (!m_pDC)
|
||||
{
|
||||
m_pParser->SetError();
|
||||
if (NULL != m_pParser) m_pParser->SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
CEmfDC* pNewDC = m_pDC->Copy();
|
||||
if (!pNewDC)
|
||||
{
|
||||
m_pParser->SetError();
|
||||
if (NULL != m_pParser) m_pParser->SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ namespace MetaFile
|
||||
{
|
||||
if (m_mDCs.empty() || m_mDCs.begin()->first > nIndex)
|
||||
{
|
||||
m_pParser->SetError();
|
||||
if (NULL != m_pParser) m_pParser->SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ namespace MetaFile
|
||||
m_pDC = oFound->second;
|
||||
m_mDCs.erase(oFound);
|
||||
}
|
||||
else
|
||||
else if (NULL != m_pParser)
|
||||
m_pParser->SetError();
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,10 +74,10 @@ namespace MetaFile
|
||||
typedef std::map < unsigned int, CEmfObjectBase* > CEmfObjectMap;
|
||||
typedef std::map < int, CEmfDC* > EmfDCsMap;
|
||||
|
||||
CEmfDC* m_pDC;
|
||||
EmfDCsMap m_mDCs;
|
||||
CEmfParserBase* m_pParser;
|
||||
CEmfObjectMap m_mObjects;
|
||||
CEmfDC* m_pDC;
|
||||
EmfDCsMap m_mDCs;
|
||||
CEmfParserBase* m_pParser;
|
||||
CEmfObjectMap m_mObjects;
|
||||
};
|
||||
|
||||
class CEmfDC
|
||||
|
||||
@ -355,6 +355,7 @@ namespace MetaFile
|
||||
m_lType = c_lMetaSvg;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
@ -563,10 +564,7 @@ namespace MetaFile
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
case c_lMetaSvg:
|
||||
{
|
||||
*pdX = 0;
|
||||
*pdY = 0;
|
||||
*pdW = m_oSvgFile.get_Width();
|
||||
*pdH = m_oSvgFile.get_Height();
|
||||
m_oSvgFile.GetBounds(*pdX, *pdY, *pdW, *pdH);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -46,7 +46,12 @@
|
||||
#endif
|
||||
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
#ifdef SVG_OLD_ENGINE
|
||||
#include "svg/SVGTransformer.h"
|
||||
typedef CSVGTransformer CSvgFile;
|
||||
#else
|
||||
#include "svg/CSvgFile.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace MetaFile
|
||||
@ -94,7 +99,7 @@ namespace MetaFile
|
||||
#endif
|
||||
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
CSVGTransformer m_oSvgFile;
|
||||
CSvgFile m_oSvgFile;
|
||||
#endif
|
||||
|
||||
int m_lType;
|
||||
|
||||
@ -74,11 +74,14 @@ namespace MetaFile
|
||||
};
|
||||
|
||||
CInterpretatorSvgBase::CInterpretatorSvgBase(IMetaFileBase *pParser, double dWidth, double dHeight)
|
||||
: m_oSizeWindow(dWidth, dHeight), m_unNumberDefs(0), m_pParser(pParser)
|
||||
: m_oSizeWindow(dWidth, dHeight), m_unNumberDefs(0), m_pParser(pParser), m_pXmlWriter(new XmlUtils::CXmlWriter()), m_bExternXmlWriter(false)
|
||||
{}
|
||||
|
||||
CInterpretatorSvgBase::~CInterpretatorSvgBase()
|
||||
{}
|
||||
{
|
||||
if (!m_bExternXmlWriter)
|
||||
RELEASEOBJECT(m_pXmlWriter);
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::SetSize(double dWidth, double dHeight)
|
||||
{
|
||||
@ -103,17 +106,23 @@ namespace MetaFile
|
||||
void CInterpretatorSvgBase::SetXmlWriter(XmlUtils::CXmlWriter *pXmlWriter)
|
||||
{
|
||||
if (NULL != pXmlWriter)
|
||||
m_oXmlWriter = *pXmlWriter;
|
||||
{
|
||||
if (!m_bExternXmlWriter)
|
||||
RELEASEOBJECT(m_pXmlWriter);
|
||||
|
||||
m_pXmlWriter = pXmlWriter;
|
||||
m_bExternXmlWriter = true;
|
||||
}
|
||||
}
|
||||
|
||||
XmlUtils::CXmlWriter *CInterpretatorSvgBase::GetXmlWriter()
|
||||
{
|
||||
return &m_oXmlWriter;
|
||||
return m_pXmlWriter;
|
||||
}
|
||||
|
||||
std::wstring CInterpretatorSvgBase::GetFile()
|
||||
{
|
||||
return m_oXmlWriter.GetXmlString();
|
||||
return m_pXmlWriter->GetXmlString();
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::IncludeSvg(const std::wstring &wsSvg, const TRectD &oRect, const TRectD &oClipRect, TXForm *pTransform)
|
||||
@ -151,46 +160,46 @@ namespace MetaFile
|
||||
|
||||
wsNewSvg.insert(unFirstPos, wsClip);
|
||||
|
||||
m_oXmlWriter.WriteString(wsNewSvg);
|
||||
m_pXmlWriter->WriteString(wsNewSvg);
|
||||
|
||||
WriteNodeEnd(L"g");
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::WriteNode(const std::wstring &wsNodeName, const NodeAttributes &arAttributes, const std::wstring &wsValueNode)
|
||||
{
|
||||
m_oXmlWriter.WriteNodeBegin(wsNodeName, true);
|
||||
m_pXmlWriter->WriteNodeBegin(wsNodeName, true);
|
||||
|
||||
for (const NodeAttribute& oAttribute : arAttributes)
|
||||
m_oXmlWriter.WriteAttribute(oAttribute.first, oAttribute.second);
|
||||
m_pXmlWriter->WriteAttribute(oAttribute.first, oAttribute.second);
|
||||
|
||||
if (wsValueNode.empty())
|
||||
{
|
||||
m_oXmlWriter.WriteNodeEnd(wsNodeName, true, true);
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oXmlWriter.WriteNodeEnd(wsNodeName, true, false);
|
||||
m_oXmlWriter.WriteString (wsValueNode);
|
||||
m_oXmlWriter.WriteNodeEnd(wsNodeName, false, false);
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, true, false);
|
||||
m_pXmlWriter->WriteString (wsValueNode);
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::WriteNodeBegin(const std::wstring &wsNodeName, const NodeAttributes &arAttributes)
|
||||
{
|
||||
m_oXmlWriter.WriteNodeBegin(wsNodeName, !arAttributes.empty());
|
||||
m_pXmlWriter->WriteNodeBegin(wsNodeName, !arAttributes.empty());
|
||||
|
||||
if (!arAttributes.empty())
|
||||
{
|
||||
for (const NodeAttribute& oAttribute : arAttributes)
|
||||
m_oXmlWriter.WriteAttribute(oAttribute.first, oAttribute.second);
|
||||
m_pXmlWriter->WriteAttribute(oAttribute.first, oAttribute.second);
|
||||
|
||||
m_oXmlWriter.WriteNodeEnd(wsNodeName, true, false);
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::WriteNodeEnd(const std::wstring &wsNodeName)
|
||||
{
|
||||
m_oXmlWriter.WriteNodeEnd(wsNodeName, false, false);
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, false, false);
|
||||
}
|
||||
|
||||
static void EraseWords(std::wstring& wsString, const std::vector<std::wstring>& arWords)
|
||||
@ -425,7 +434,7 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
if (bWriteG)
|
||||
m_oXmlWriter.WriteNodeEnd(L"g");
|
||||
m_pXmlWriter->WriteNodeEnd(L"g");
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::ResetClip()
|
||||
|
||||
@ -120,8 +120,10 @@ namespace MetaFile
|
||||
unsigned int m_unNumberDefs;
|
||||
std::wstring m_wsDefs;
|
||||
|
||||
IMetaFileBase *m_pParser;
|
||||
XmlUtils::CXmlWriter m_oXmlWriter;
|
||||
IMetaFileBase *m_pParser;
|
||||
|
||||
XmlUtils::CXmlWriter *m_pXmlWriter;
|
||||
bool m_bExternXmlWriter;
|
||||
|
||||
CSvgClip m_oClip;
|
||||
|
||||
|
||||
@ -24,9 +24,9 @@ namespace MetaFile
|
||||
|
||||
void CWmfInterpretatorSvg::HANDLE_META_HEADER(const TWmfPlaceable& oPlaceable, const TWmfHeader& oHeader)
|
||||
{
|
||||
m_oXmlWriter.WriteNodeBegin(L"svg", true);
|
||||
m_oXmlWriter.WriteAttribute(L"xmlns", L"http://www.w3.org/2000/svg");
|
||||
m_oXmlWriter.WriteAttribute(L"xmlns:xlink", L"http://www.w3.org/1999/xlink");
|
||||
m_pXmlWriter->WriteNodeBegin(L"svg", true);
|
||||
m_pXmlWriter->WriteAttribute(L"xmlns", L"http://www.w3.org/2000/svg");
|
||||
m_pXmlWriter->WriteAttribute(L"xmlns:xlink", L"http://www.w3.org/1999/xlink");
|
||||
|
||||
TRect *pBounds = m_pParser->GetDCBounds();
|
||||
|
||||
@ -38,10 +38,10 @@ namespace MetaFile
|
||||
UpdateSize();
|
||||
|
||||
if (m_oViewport.GetWidth() != 0)
|
||||
m_oXmlWriter.WriteAttribute(L"width", ConvertToWString(m_oViewport.GetWidth()));
|
||||
m_pXmlWriter->WriteAttribute(L"width", ConvertToWString(m_oViewport.GetWidth()));
|
||||
|
||||
if (m_oViewport.GetHeight() != 0)
|
||||
m_oXmlWriter.WriteAttribute(L"height", ConvertToWString(m_oViewport.GetHeight()));
|
||||
m_pXmlWriter->WriteAttribute(L"height", ConvertToWString(m_oViewport.GetHeight()));
|
||||
|
||||
double dXScale = 1, dYScale = 1, dXTranslate = 0, dYTranslate = 0;
|
||||
|
||||
@ -64,17 +64,17 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
if (1 != dXScale || 1 != dYScale)
|
||||
m_oXmlWriter.WriteAttribute(L"transform", L"matrix(" + std::to_wstring(dXScale) + L",0,0," + std::to_wstring(dYScale) + L',' + ConvertToWString(dXTranslate) + L',' + ConvertToWString(dYTranslate) + L')');
|
||||
m_pXmlWriter->WriteAttribute(L"transform", L"matrix(" + std::to_wstring(dXScale) + L",0,0," + std::to_wstring(dYScale) + L',' + ConvertToWString(dXTranslate) + L',' + ConvertToWString(dYTranslate) + L')');
|
||||
|
||||
m_oXmlWriter.WriteNodeEnd(L"svg", true, false);
|
||||
m_pXmlWriter->WriteNodeEnd(L"svg", true, false);
|
||||
}
|
||||
|
||||
void CWmfInterpretatorSvg::HANDLE_META_EOF()
|
||||
{
|
||||
ResetClip();
|
||||
if (!m_wsDefs.empty())
|
||||
m_oXmlWriter.WriteString(L"<defs>" + m_wsDefs + L"</defs>");
|
||||
m_oXmlWriter.WriteNodeEnd(L"svg", false, false);
|
||||
m_pXmlWriter->WriteString(L"<defs>" + m_wsDefs + L"</defs>");
|
||||
m_pXmlWriter->WriteNodeEnd(L"svg", false, false);
|
||||
}
|
||||
|
||||
void CWmfInterpretatorSvg::HANDLE_META_ARC(short shYEndArc, short shXEndArc, short shYStartArc, short shXStartArc, short shBottom, short shRight, short shTop, short shLeft)
|
||||
@ -100,12 +100,12 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(dX1 + (shRight + shLeft) / 2.) + L' ' + ConvertToWString(dY1 + (shBottom + shTop) / 2.);
|
||||
|
||||
wsValue += L" A " + ConvertToWString(dXRadius) + L' ' +
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 0 0 " +
|
||||
// ((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
// ((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dX2 + (shRight + shLeft) / 2.) + L' ' +
|
||||
ConvertToWString(dY2 + (shBottom + shTop) / 2.);
|
||||
ConvertToWString(dYRadius) + L' ' +
|
||||
L"0 0 0 " +
|
||||
// ((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"0" : L"1") + L' ' +
|
||||
// ((std::fabs(dSweepAngle - dStartAngle) <= 180) ? L"1" : L"0") + L' ' +
|
||||
ConvertToWString(dX2 + (shRight + shLeft) / 2.) + L' ' +
|
||||
ConvertToWString(dY2 + (shBottom + shTop) / 2.);
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
@ -132,9 +132,9 @@ namespace MetaFile
|
||||
oNewRect.dBottom = shBottom;
|
||||
|
||||
NodeAttributes arAttributes = {{L"cx", ConvertToWString((oNewRect.dLeft + oNewRect.dRight) / 2)},
|
||||
{L"cy", ConvertToWString((oNewRect.dTop + oNewRect.dBottom) / 2)},
|
||||
{L"rx", ConvertToWString((oNewRect.dRight - oNewRect.dLeft) / 2)},
|
||||
{L"ry", ConvertToWString((oNewRect.dBottom - oNewRect.dTop) / 2)}};
|
||||
{L"cy", ConvertToWString((oNewRect.dTop + oNewRect.dBottom) / 2)},
|
||||
{L"rx", ConvertToWString((oNewRect.dRight - oNewRect.dLeft) / 2)},
|
||||
{L"ry", ConvertToWString((oNewRect.dBottom - oNewRect.dTop) / 2)}};
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
@ -261,9 +261,9 @@ namespace MetaFile
|
||||
TPointD oCurPos = GetCutPos();
|
||||
|
||||
NodeAttributes arAttributes = {{L"x1", ConvertToWString(oCurPos.x)},
|
||||
{L"y1", ConvertToWString(oCurPos.y)},
|
||||
{L"x2", ConvertToWString(shX)},
|
||||
{L"y2", ConvertToWString(shY)}};
|
||||
{L"y1", ConvertToWString(oCurPos.y)},
|
||||
{L"x2", ConvertToWString(shX)},
|
||||
{L"y2", ConvertToWString(shY)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
@ -396,9 +396,9 @@ namespace MetaFile
|
||||
oNewRect.dBottom = shB;
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.dLeft)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)}};
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
@ -418,9 +418,9 @@ namespace MetaFile
|
||||
oNewRect.dBottom = shB;
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.dLeft)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)},
|
||||
{L"y", ConvertToWString(oNewRect.dTop)},
|
||||
{L"width", ConvertToWString(oNewRect.dRight - oNewRect.dLeft)},
|
||||
{L"height", ConvertToWString(oNewRect.dBottom - oNewRect.dTop)},
|
||||
{L"rx", ConvertToWString((double)shW / 2.)},
|
||||
{L"ry", ConvertToWString((double)shH / 2.)}};
|
||||
|
||||
|
||||
@ -44,6 +44,10 @@ namespace MetaFile
|
||||
m_unRecordPos = m_oStream.Tell();
|
||||
|
||||
m_oStream >> unSize;
|
||||
|
||||
if (unSize > m_oStream.CanRead())
|
||||
SetError();
|
||||
|
||||
m_oStream >> ushType;
|
||||
|
||||
m_unRecordSize = unSize * 2; // Размер указан в WORD
|
||||
@ -59,13 +63,13 @@ namespace MetaFile
|
||||
case META_SETDIBTODEV: Read_META_SETDIBTODEV(); break;
|
||||
case META_STRETCHBLT: Read_META_STRETCHBLT(); break;
|
||||
case META_STRETCHDIB: Read_META_STRETCHDIB(); break;
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.2 Control records
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.2 Control records
|
||||
//-----------------------------------------------------------
|
||||
case META_EOF: Read_META_EOF(); break;
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.3 Drawing records
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.3 Drawing records
|
||||
//-----------------------------------------------------------
|
||||
case META_ARC: Read_META_ARC(); break;
|
||||
case META_CHORD: Read_META_CHORD(); break;
|
||||
case META_ELLIPSE: Read_META_ELLIPSE(); break;
|
||||
@ -86,9 +90,9 @@ namespace MetaFile
|
||||
case META_ROUNDRECT: Read_META_ROUNDRECT(); break;
|
||||
case META_SETPIXEL: Read_META_SETPIXEL(); break;
|
||||
case META_TEXTOUT: Read_META_TEXTOUT(); break;
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.4 Object records
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.4 Object records
|
||||
//-----------------------------------------------------------
|
||||
case META_CREATEBRUSHINDIRECT: Read_META_CREATEBRUSHINDIRECT(); break;
|
||||
case META_CREATEFONTINDIRECT: Read_META_CREATEFONTINDIRECT(); break;
|
||||
case META_CREATEPALETTE: Read_META_CREATEPALETTE(); break;
|
||||
@ -100,9 +104,9 @@ namespace MetaFile
|
||||
case META_SELECTCLIPREGION: Read_META_SELECTCLIPREGION(); break;
|
||||
case META_SELECTOBJECT: Read_META_SELECTOBJECT(); break;
|
||||
case META_SELECTPALETTE: Read_META_SELECTPALETTE(); break;
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.5 State records
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.5 State records
|
||||
//-----------------------------------------------------------
|
||||
case META_ANIMATEPALETTE: Read_META_UNKNOWN(); break;
|
||||
case META_EXCLUDECLIPRECT: Read_META_EXCLUDECLIPRECT(); break;
|
||||
case META_INTERSECTCLIPRECT: Read_META_INTERSECTCLIPRECT(); break;
|
||||
@ -134,13 +138,13 @@ namespace MetaFile
|
||||
case META_SETVIEWPORTORG: Read_META_SETVIEWPORTORG(); break;
|
||||
case META_SETWINDOWEXT: Read_META_SETWINDOWEXT(); break;
|
||||
case META_SETWINDOWORG: Read_META_SETWINDOWORG(); break;
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.6 State records
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// 2.3.6 State records
|
||||
//-----------------------------------------------------------
|
||||
case META_ESCAPE: Read_META_ESCAPE(); break;
|
||||
//-----------------------------------------------------------
|
||||
// Неизвестные записи
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
// Неизвестные записи
|
||||
//-----------------------------------------------------------
|
||||
default:
|
||||
{
|
||||
//std::cout << ushType << " ";
|
||||
|
||||
@ -1671,78 +1671,106 @@ namespace MetaFile
|
||||
void CWmfParserBase::HANDLE_META_ESCAPE(unsigned short ushEscapeFunction, unsigned short ushByteCount)
|
||||
{
|
||||
if (NULL != m_pInterpretator)
|
||||
{
|
||||
m_pInterpretator->HANDLE_META_ESCAPE(ushEscapeFunction, ushByteCount);
|
||||
|
||||
if (WMF_META_ESCAPE_ENHANCED_METAFILE == ushEscapeFunction)
|
||||
if (WMF_META_ESCAPE_ENHANCED_METAFILE == ushEscapeFunction)
|
||||
{
|
||||
if (ushByteCount < 34)
|
||||
return;
|
||||
|
||||
unsigned int unCommentIdentifier, unCommentType, unVersion;
|
||||
|
||||
m_oStream >> unCommentIdentifier;
|
||||
m_oStream >> unCommentType;
|
||||
m_oStream >> unVersion;
|
||||
|
||||
if (0x43464D57 != unCommentIdentifier || 0x00000001 != unCommentType || 0x00010000 != unVersion)
|
||||
return;
|
||||
|
||||
unsigned short ushChecksum;
|
||||
unsigned int unFlags;
|
||||
|
||||
m_oStream >> ushChecksum;
|
||||
m_oStream >> unFlags;
|
||||
|
||||
if (0x00000000 != unFlags)
|
||||
return;
|
||||
|
||||
unsigned int unCommentRecordCount, unCurrentRecordSize, unRemainingBytes, unEnhancedMetafileDataSize;
|
||||
|
||||
m_oStream >> unCommentRecordCount;
|
||||
m_oStream >> unCurrentRecordSize;
|
||||
m_oStream >> unRemainingBytes;
|
||||
m_oStream >> unEnhancedMetafileDataSize;
|
||||
|
||||
if (m_oEscapeBuffer.Empty())
|
||||
m_oEscapeBuffer.SetSize(unEnhancedMetafileDataSize);
|
||||
|
||||
unsigned int nEscapeRecordSize = m_oEscapeBuffer.GetTileSize();
|
||||
if (nEscapeRecordSize > unCurrentRecordSize)
|
||||
nEscapeRecordSize = unCurrentRecordSize;
|
||||
|
||||
m_oStream.ReadBytes(m_oEscapeBuffer.GetCurPtr(), nEscapeRecordSize);
|
||||
m_oEscapeBuffer.IncreasePosition(nEscapeRecordSize);
|
||||
|
||||
if (0 == unRemainingBytes)
|
||||
{
|
||||
if (ushByteCount < 34)
|
||||
return;
|
||||
CEmfParser oEmfParser;
|
||||
|
||||
unsigned int unCommentIdentifier, unCommentType, unVersion;
|
||||
oEmfParser.SetFontManager(GetFontManager());
|
||||
oEmfParser.SetStream(m_oEscapeBuffer.GetBuffer(), m_oEscapeBuffer.GetSize());
|
||||
oEmfParser.Scan();
|
||||
|
||||
m_oStream >> unCommentIdentifier;
|
||||
m_oStream >> unCommentType;
|
||||
m_oStream >> unVersion;
|
||||
|
||||
if (0x43464D57 != unCommentIdentifier || 0x00000001 != unCommentType || 0x00010000 != unVersion)
|
||||
return;
|
||||
|
||||
unsigned short ushChecksum;
|
||||
unsigned int unFlags;
|
||||
|
||||
m_oStream >> ushChecksum;
|
||||
m_oStream >> unFlags;
|
||||
|
||||
if (0x00000000 != unFlags)
|
||||
return;
|
||||
|
||||
unsigned int unCommentRecordCount, unCurrentRecordSize, unRemainingBytes, unEnhancedMetafileDataSize;
|
||||
|
||||
m_oStream >> unCommentRecordCount;
|
||||
m_oStream >> unCurrentRecordSize;
|
||||
m_oStream >> unRemainingBytes;
|
||||
m_oStream >> unEnhancedMetafileDataSize;
|
||||
|
||||
if (m_oEscapeBuffer.Empty())
|
||||
m_oEscapeBuffer.SetSize(unEnhancedMetafileDataSize);
|
||||
|
||||
m_oStream.ReadBytes(m_oEscapeBuffer.GetCurPtr(), unCurrentRecordSize);
|
||||
|
||||
m_oEscapeBuffer.IncreasePosition(unCurrentRecordSize);
|
||||
|
||||
if (0 == unRemainingBytes)
|
||||
if (oEmfParser.CheckError())
|
||||
{
|
||||
CEmfParser oEmfParser;
|
||||
|
||||
oEmfParser.SetFontManager(GetFontManager());
|
||||
oEmfParser.SetStream(m_oEscapeBuffer.GetBuffer(), m_oEscapeBuffer.GetSize());
|
||||
oEmfParser.Scan();
|
||||
|
||||
if (!oEmfParser.CheckError() && InterpretatorType::Render == m_pInterpretator->GetType())
|
||||
{
|
||||
CMetaFileRenderer oEmfOut(&oEmfParser, ((CWmfInterpretatorRender*)m_pInterpretator)->GetRenderer());
|
||||
oEmfParser.SetInterpretator(&oEmfOut);
|
||||
|
||||
oEmfParser.PlayFile();
|
||||
|
||||
m_bEof = true;
|
||||
}
|
||||
else if (!oEmfParser.CheckError() && InterpretatorType::Svg == m_pInterpretator->GetType())
|
||||
{
|
||||
double dWidth, dHeight;
|
||||
|
||||
((CWmfInterpretatorSvg*)m_pInterpretator)->GetSize(dWidth, dHeight);
|
||||
|
||||
((CEmfParserBase*)&oEmfParser)->SetInterpretator(InterpretatorType::Svg, dWidth, dHeight);
|
||||
|
||||
oEmfParser.PlayFile();
|
||||
|
||||
((CWmfInterpretatorSvg*)m_pInterpretator)->SetXmlWriter(((CEmfInterpretatorSvg*)oEmfParser.GetInterpretator())->GetXmlWriter());
|
||||
|
||||
m_bEof = true;
|
||||
}
|
||||
m_oEscapeBuffer.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (NULL == m_pInterpretator)
|
||||
{
|
||||
m_oEscapeBuffer.Clear();
|
||||
return HANDLE_META_EOF();
|
||||
}
|
||||
else if (InterpretatorType::Render == m_pInterpretator->GetType())
|
||||
{
|
||||
CMetaFileRenderer oEmfOut(&oEmfParser, ((CWmfInterpretatorRender*)m_pInterpretator)->GetRenderer());
|
||||
oEmfParser.SetInterpretator(&oEmfOut);
|
||||
|
||||
oEmfParser.PlayFile();
|
||||
|
||||
HANDLE_META_EOF();
|
||||
}
|
||||
else if (InterpretatorType::Svg == m_pInterpretator->GetType())
|
||||
{
|
||||
double dWidth, dHeight;
|
||||
|
||||
((CWmfInterpretatorSvg*)m_pInterpretator)->GetSize(dWidth, dHeight);
|
||||
|
||||
((CEmfParserBase*)&oEmfParser)->SetInterpretator(InterpretatorType::Svg, dWidth, dHeight);
|
||||
|
||||
XmlUtils::CXmlWriter *pXmlWriter = ((CWmfInterpretatorSvg*)GetInterpretator())->GetXmlWriter();
|
||||
|
||||
TRectD oCurrentRect = GetBounds();
|
||||
TEmfRectL* pEmfRect = oEmfParser.GetBounds();
|
||||
|
||||
double dScaleX = std::abs((oCurrentRect.dRight - oCurrentRect.dLeft) / (pEmfRect->lRight - pEmfRect->lLeft));
|
||||
double dScaleY = std::abs((oCurrentRect.dBottom - oCurrentRect.dTop) / (pEmfRect->lBottom - pEmfRect->lTop));
|
||||
|
||||
pXmlWriter->WriteNodeBegin(L"g", true);
|
||||
pXmlWriter->WriteAttribute(L"transform", L"scale(" + std::to_wstring(dScaleX) + L',' + std::to_wstring(dScaleY) + L')');
|
||||
pXmlWriter->WriteNodeEnd(L"g", true, false);
|
||||
|
||||
((CEmfInterpretatorSvg*)oEmfParser.GetInterpretator())->SetXmlWriter(pXmlWriter);
|
||||
|
||||
oEmfParser.PlayFile();
|
||||
|
||||
pXmlWriter->WriteNodeEnd(L"g", false, false);
|
||||
|
||||
HANDLE_META_EOF();
|
||||
}
|
||||
|
||||
m_oEscapeBuffer.Clear();
|
||||
}
|
||||
}
|
||||
// TODO: Реализовать
|
||||
|
||||
@ -385,68 +385,72 @@ namespace MetaFile
|
||||
};
|
||||
class CWmfEscapeBuffer
|
||||
{
|
||||
public:
|
||||
CWmfEscapeBuffer() : m_pBytes(NULL), m_unSize(0), m_unPosition(0) {};
|
||||
~CWmfEscapeBuffer()
|
||||
public:
|
||||
CWmfEscapeBuffer() : m_pBytes(NULL), m_unSize(0), m_unPosition(0) {};
|
||||
~CWmfEscapeBuffer()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return 0 == m_unSize;
|
||||
}
|
||||
|
||||
void SetSize(unsigned int unSize)
|
||||
{
|
||||
Clear();
|
||||
m_unSize = unSize;
|
||||
m_pBytes = new unsigned char[m_unSize];
|
||||
};
|
||||
|
||||
void IncreasePosition(unsigned int unValue)
|
||||
{
|
||||
m_unPosition += unValue;
|
||||
|
||||
if (m_unPosition > m_unSize)
|
||||
m_unPosition = m_unSize;
|
||||
}
|
||||
|
||||
unsigned char* GetBuffer() const
|
||||
{
|
||||
return m_pBytes;
|
||||
}
|
||||
|
||||
unsigned char* GetCurPtr() const
|
||||
{
|
||||
if (NULL == m_pBytes || 0 == m_unSize)
|
||||
return NULL;
|
||||
|
||||
return m_pBytes + m_unPosition;
|
||||
}
|
||||
|
||||
unsigned int GetSize() const
|
||||
{
|
||||
return m_unSize;
|
||||
}
|
||||
|
||||
unsigned int GetTileSize() const
|
||||
{
|
||||
return m_unSize - m_unPosition;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
if (NULL != m_pBytes)
|
||||
{
|
||||
Clear();
|
||||
delete m_pBytes;
|
||||
m_pBytes = NULL;
|
||||
}
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return 0 == m_unSize;
|
||||
}
|
||||
m_unSize = 0;
|
||||
m_unPosition = 0;
|
||||
}
|
||||
|
||||
void SetSize(unsigned int unSize)
|
||||
{
|
||||
Clear();
|
||||
m_unSize = unSize;
|
||||
m_pBytes = new unsigned char[m_unSize];
|
||||
};
|
||||
|
||||
void IncreasePosition(unsigned int unValue)
|
||||
{
|
||||
m_unPosition += unValue;
|
||||
|
||||
if (m_unPosition > m_unSize)
|
||||
m_unPosition = m_unSize;
|
||||
}
|
||||
|
||||
unsigned char* GetBuffer() const
|
||||
{
|
||||
return m_pBytes;
|
||||
}
|
||||
|
||||
unsigned char* GetCurPtr() const
|
||||
{
|
||||
if (NULL == m_pBytes || 0 == m_unSize)
|
||||
return NULL;
|
||||
|
||||
return m_pBytes + m_unPosition;
|
||||
}
|
||||
|
||||
unsigned int GetSize() const
|
||||
{
|
||||
return m_unSize;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void Clear()
|
||||
{
|
||||
if (NULL != m_pBytes)
|
||||
{
|
||||
delete m_pBytes;
|
||||
m_pBytes = NULL;
|
||||
}
|
||||
|
||||
m_unSize = 0;
|
||||
m_unPosition = 0;
|
||||
}
|
||||
|
||||
unsigned char* m_pBytes;
|
||||
unsigned int m_unSize;
|
||||
unsigned int m_unPosition;
|
||||
private:
|
||||
unsigned char* m_pBytes;
|
||||
unsigned int m_unSize;
|
||||
unsigned int m_unPosition;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
185
DesktopEditor/raster/Metafile/svg/CSvgFile.cpp
Normal file
185
DesktopEditor/raster/Metafile/svg/CSvgFile.cpp
Normal file
@ -0,0 +1,185 @@
|
||||
#include "CSvgFile.h"
|
||||
|
||||
#include "SvgObjects/CContainer.h"
|
||||
|
||||
CSvgFile::CSvgFile()
|
||||
: m_oContainer(L"svg")
|
||||
{}
|
||||
|
||||
CSvgFile::~CSvgFile()
|
||||
{}
|
||||
|
||||
bool CSvgFile::ReadFromBuffer(BYTE *pBuffer, unsigned int unSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSvgFile::OpenFromFile(const std::wstring &wsFile)
|
||||
{
|
||||
Clear();
|
||||
|
||||
return m_oParser.LoadFromFile(wsFile, &m_oContainer, this);
|
||||
}
|
||||
|
||||
bool CSvgFile::Load(const std::wstring &wsContent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSvgFile::Close()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSvgFile::GetBounds(double &dX, double &dY, double &dWidth, double &dHeight) const
|
||||
{
|
||||
if (m_oContainer.Empty())
|
||||
return false;
|
||||
|
||||
SVG::TRect oWindow = m_oContainer.GetWindow();
|
||||
|
||||
dX = oWindow.m_oX .ToDouble(NSCSS::Pixel);
|
||||
dY = oWindow.m_oY .ToDouble(NSCSS::Pixel);
|
||||
dWidth = oWindow.m_oWidth .ToDouble(NSCSS::Pixel);
|
||||
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
|
||||
|
||||
if (0. == dWidth)
|
||||
dWidth = (!m_oContainer.GetViewBox().m_oWidth.Empty()) ? m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel) : 300;
|
||||
if (0. == dHeight)
|
||||
dHeight = (!m_oContainer.GetViewBox().m_oHeight.Empty()) ? m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel) : 150;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const SVG::CSvgCalculator *CSvgFile::GetSvgCalculator() const
|
||||
{
|
||||
return &m_oSvgCalculator;
|
||||
}
|
||||
|
||||
void CSvgFile::SetFontManager(NSFonts::IFontManager *pFontManager)
|
||||
{
|
||||
m_oParser.SetFontManager(pFontManager);
|
||||
}
|
||||
|
||||
bool CSvgFile::MarkObject(SVG::CObject *pObject)
|
||||
{
|
||||
if (NULL == pObject || pObject->GetId().empty())
|
||||
return false;
|
||||
|
||||
m_mMarkedObjects[pObject->GetId()] = pObject;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SVG::CObject *CSvgFile::GetMarkedObject(const std::wstring &wsId) const
|
||||
{
|
||||
if (wsId.empty() || m_mMarkedObjects.empty())
|
||||
return NULL;
|
||||
|
||||
std::wstring wsNewId = wsId;
|
||||
|
||||
size_t unFound = wsNewId.find(L'#');
|
||||
|
||||
if (std::wstring::npos != unFound)
|
||||
wsNewId.erase(0, unFound + 1);
|
||||
|
||||
MarkedMap::const_iterator oConstIter = m_mMarkedObjects.find(wsNewId);
|
||||
|
||||
if (m_mMarkedObjects.end() != oConstIter)
|
||||
return oConstIter->second;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CSvgFile::AddStyles(const std::wstring &wsStyles)
|
||||
{
|
||||
m_oSvgCalculator.AddStyles(wsStyles);
|
||||
}
|
||||
|
||||
bool CSvgFile::Draw(IRenderer *pRenderer, double dX, double dY, double dWidth, double dHeight)
|
||||
{
|
||||
if (NULL == pRenderer || m_oContainer.Empty())
|
||||
return false;
|
||||
|
||||
SVG::TRect oWindow = m_oContainer.GetWindow();
|
||||
SVG::TRect oViewBox = m_oContainer.GetViewBox();
|
||||
|
||||
if (oWindow.m_oWidth.Empty() || oWindow.m_oWidth.Zero())
|
||||
{
|
||||
if (oViewBox.m_oWidth.Empty() || oViewBox.m_oWidth.Zero())
|
||||
oWindow.m_oWidth = 300;
|
||||
else
|
||||
{
|
||||
oWindow.m_oWidth = oViewBox.m_oWidth;
|
||||
oViewBox.m_oWidth.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (oWindow.m_oHeight.Empty() || oWindow.m_oHeight.Zero())
|
||||
{
|
||||
if (oViewBox.m_oHeight.Empty() || oViewBox.m_oHeight.Zero())
|
||||
oWindow.m_oHeight = 150;
|
||||
else
|
||||
{
|
||||
oWindow.m_oHeight = oViewBox.m_oHeight;
|
||||
oViewBox.m_oHeight.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
double dWindowWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel);
|
||||
double dWindowHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
|
||||
|
||||
double dViewBoxWidth = oViewBox.m_oWidth.ToDouble(NSCSS::Pixel);
|
||||
double dViewBoxHeight = oViewBox.m_oHeight.ToDouble(NSCSS::Pixel);
|
||||
|
||||
double oldTransform[6];
|
||||
oldTransform[0] = oldTransform[3] = 1;
|
||||
oldTransform[1] = oldTransform[2] = oldTransform[4] = oldTransform[5] = 0;
|
||||
|
||||
pRenderer->GetTransform(&oldTransform[0], &oldTransform[1], &oldTransform[2], &oldTransform[3], &oldTransform[4], &oldTransform[5]);
|
||||
pRenderer->ResetTransform();
|
||||
|
||||
double dM11 = 1;
|
||||
double dM22 = 1;
|
||||
|
||||
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero())
|
||||
dM11 = dWidth / dWindowWidth;
|
||||
|
||||
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero())
|
||||
dM22 = dHeight / dWindowHeight;
|
||||
|
||||
double dScaleX = 1, dScaleY = 1;
|
||||
|
||||
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero() && !oViewBox.m_oWidth.Empty() && !oViewBox.m_oWidth.Zero())
|
||||
dScaleX = dWindowWidth / dViewBoxWidth;
|
||||
|
||||
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero() && !oViewBox.m_oHeight.Empty() && !oViewBox.m_oHeight.Zero())
|
||||
dScaleY = dWindowHeight / dViewBoxHeight;
|
||||
|
||||
double dMinScale = std::min(dScaleX, dScaleY);
|
||||
|
||||
double dSkipX = -oViewBox.m_oX.ToDouble(NSCSS::Pixel) * dScaleX * dM11;
|
||||
double dSkipY = -oViewBox.m_oY.ToDouble(NSCSS::Pixel) * dScaleY * dM22;
|
||||
|
||||
pRenderer->SetTransform(dM11 * dMinScale, 0, 0, dM22 * dMinScale, dSkipX, dSkipY);
|
||||
|
||||
bool bResult = m_oContainer.Draw(pRenderer, this);
|
||||
|
||||
pRenderer->SetTransform(oldTransform[0], oldTransform[1], oldTransform[2], oldTransform[3], oldTransform[4], oldTransform[5]);
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
void CSvgFile::Clear()
|
||||
{
|
||||
m_oContainer.Clear();
|
||||
m_oSvgCalculator.Clear();
|
||||
|
||||
for (MarkedMap::iterator oIter = m_mMarkedObjects.begin(); oIter != m_mMarkedObjects.end(); ++oIter)
|
||||
{
|
||||
if (SVG::AppliedObject == oIter->second->GetType())
|
||||
delete oIter->second;
|
||||
}
|
||||
|
||||
m_mMarkedObjects.clear();
|
||||
}
|
||||
45
DesktopEditor/raster/Metafile/svg/CSvgFile.h
Normal file
45
DesktopEditor/raster/Metafile/svg/CSvgFile.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef CSVGFILE_H
|
||||
#define CSVGFILE_H
|
||||
|
||||
#include "../../../graphics/IRenderer.h"
|
||||
#include "../../../graphics/pro/Fonts.h"
|
||||
|
||||
#include "CSvgParser.h"
|
||||
#include "SvgObjects/CStyle.h"
|
||||
|
||||
class CSvgFile
|
||||
{
|
||||
public:
|
||||
CSvgFile();
|
||||
~CSvgFile();
|
||||
|
||||
bool ReadFromBuffer(BYTE* pBuffer, unsigned int unSize);
|
||||
bool OpenFromFile(const std::wstring& wsFile);
|
||||
bool Load(const std::wstring& wsContent);
|
||||
|
||||
void Close();
|
||||
|
||||
bool GetBounds(double& dX, double& dY, double& dWidth, double& dHeight) const;
|
||||
const SVG::CSvgCalculator* GetSvgCalculator() const;
|
||||
|
||||
void SetFontManager(NSFonts::IFontManager* pFontManager);
|
||||
|
||||
bool MarkObject(SVG::CObject* pObject);
|
||||
SVG::CObject* GetMarkedObject(const std::wstring& wsId) const;
|
||||
|
||||
void AddStyles(const std::wstring& wsStyles);
|
||||
|
||||
bool Draw(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight);
|
||||
private:
|
||||
void Clear();
|
||||
|
||||
SVG::CSvgParser m_oParser;
|
||||
SVG::CGraphicsContainer m_oContainer;
|
||||
SVG::CSvgCalculator m_oSvgCalculator;
|
||||
|
||||
typedef std::map<std::wstring, SVG::CObject*> MarkedMap;
|
||||
|
||||
MarkedMap m_mMarkedObjects;
|
||||
};
|
||||
|
||||
#endif // CSVGFILE_H
|
||||
281
DesktopEditor/raster/Metafile/svg/CSvgParser.cpp
Normal file
281
DesktopEditor/raster/Metafile/svg/CSvgParser.cpp
Normal file
@ -0,0 +1,281 @@
|
||||
#include "CSvgParser.h"
|
||||
|
||||
#include "SvgUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "CSvgFile.h"
|
||||
|
||||
#include "SvgObjects/CContainer.h"
|
||||
#include "SvgObjects/CPolyline.h"
|
||||
#include "SvgObjects/CGradient.h"
|
||||
#include "SvgObjects/CClipPath.h"
|
||||
#include "SvgObjects/CPattern.h"
|
||||
#include "SvgObjects/CEllipse.h"
|
||||
#include "SvgObjects/CSymbol.h"
|
||||
#include "SvgObjects/CMarker.h"
|
||||
#include "SvgObjects/CCircle.h"
|
||||
#include "SvgObjects/CStyle.h"
|
||||
#include "SvgObjects/CImage.h"
|
||||
#include "SvgObjects/CRect.h"
|
||||
#include "SvgObjects/CLine.h"
|
||||
#include "SvgObjects/CPath.h"
|
||||
#include "SvgObjects/CText.h"
|
||||
#include "SvgObjects/CMask.h"
|
||||
#include "SvgObjects/CUse.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CSvgParser::CSvgParser()
|
||||
: m_pFontManager(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CSvgParser::~CSvgParser()
|
||||
{
|
||||
}
|
||||
|
||||
void CSvgParser::SetFontManager(NSFonts::IFontManager *pFontManager)
|
||||
{
|
||||
m_pFontManager = pFontManager;
|
||||
}
|
||||
|
||||
bool CSvgParser::LoadFromFile(const std::wstring &wsFile, CGraphicsContainer* pContainer, CSvgFile* pFile) const
|
||||
{
|
||||
if (wsFile.empty() || NULL == pFile)
|
||||
return false;
|
||||
|
||||
std::wstring wsXml;
|
||||
NSFile::CFileBinary::ReadAllTextUtf8(wsFile, wsXml);
|
||||
|
||||
XmlUtils::IXmlDOMDocument::DisableOutput();
|
||||
bool bResult = LoadFromString(wsXml, pContainer, pFile);
|
||||
XmlUtils::IXmlDOMDocument::EnableOutput();
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
bool CSvgParser::LoadFromString(const std::wstring &wsContent, CGraphicsContainer* pContainer, CSvgFile* pFile) const
|
||||
{
|
||||
if (wsContent.empty() || NULL == pFile)
|
||||
return false;
|
||||
|
||||
XmlUtils::CXmlNode oXml;
|
||||
if (!oXml.FromXmlString(wsContent))
|
||||
return false;
|
||||
|
||||
ScanStyles(oXml, pFile);
|
||||
|
||||
if (NULL != pContainer)
|
||||
pContainer->SetData(oXml);
|
||||
|
||||
return LoadFromXmlNode(oXml, pContainer, pFile);
|
||||
}
|
||||
|
||||
bool CSvgParser::LoadFromXmlNode(XmlUtils::CXmlNode &oElement, CGraphicsContainer* pContainer, CSvgFile* pFile) const
|
||||
{
|
||||
if (NULL == pFile || !oElement.IsValid())
|
||||
return false;
|
||||
|
||||
const CSvgCalculator *pSvgCalculator = pFile->GetSvgCalculator();
|
||||
|
||||
if (NULL != pSvgCalculator)
|
||||
pSvgCalculator->SetData(pContainer);
|
||||
|
||||
return ReadChildrens(oElement, pContainer, pFile, pContainer);
|
||||
}
|
||||
|
||||
bool CSvgParser::ScanStyles(XmlUtils::CXmlNode &oElement, CSvgFile *pFile) const
|
||||
{
|
||||
if (!oElement.IsValid() || NULL == pFile)
|
||||
return false;
|
||||
|
||||
std::wstring wsElementName = oElement.GetName();
|
||||
|
||||
if (L"style" == wsElementName)
|
||||
{
|
||||
pFile->AddStyles(oElement.GetText());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bScanResult = false;
|
||||
|
||||
if (L"svg" == wsElementName || L"g" == wsElementName || L"defs" == wsElementName)
|
||||
{
|
||||
std::vector<XmlUtils::CXmlNode> arChilds;
|
||||
|
||||
oElement.GetChilds(arChilds);
|
||||
|
||||
for (XmlUtils::CXmlNode& oChild : arChilds)
|
||||
{
|
||||
if (ScanStyles(oChild, pFile))
|
||||
bScanResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
return bScanResult;
|
||||
}
|
||||
|
||||
template <class ObjectType>
|
||||
bool CSvgParser::ReadObject(XmlUtils::CXmlNode &oElement, CContainer<ObjectType> *pContainer, CSvgFile *pFile, CRenderedObject *pParent) const
|
||||
{
|
||||
if (!oElement.IsValid() || NULL == pFile)
|
||||
return false;
|
||||
|
||||
std::wstring wsElementName = oElement.GetName();
|
||||
|
||||
CObject *pObject = NULL;
|
||||
|
||||
if (L"svg" == wsElementName || L"g" == wsElementName || L"a" == wsElementName)
|
||||
{
|
||||
pObject = new CGraphicsContainer(oElement, pParent);
|
||||
if (!ReadChildrens(oElement, (CGraphicsContainer*)pObject, pFile, (CGraphicsContainer*)pObject))
|
||||
{
|
||||
RELEASEOBJECT(pObject);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (L"line" == wsElementName)
|
||||
pObject = new CLine(oElement, pParent);
|
||||
else if (L"rect" == wsElementName)
|
||||
pObject = new CRect(oElement, pParent);
|
||||
else if (L"circle" == wsElementName)
|
||||
pObject = new CCircle(oElement, pParent);
|
||||
else if (L"ellipse" == wsElementName)
|
||||
pObject = new CEllipse(oElement, pParent);
|
||||
else if (L"path" == wsElementName)
|
||||
pObject = new CPath(oElement, pParent);
|
||||
else if (L"polyline" == wsElementName)
|
||||
pObject = new CPolyline(oElement, pParent);
|
||||
else if (L"polygon" == wsElementName)
|
||||
pObject = new CPolygon(oElement, pParent);
|
||||
else if (L"image" == wsElementName)
|
||||
pObject = new CImage(oElement, pParent);
|
||||
else if (L"use" == wsElementName)
|
||||
pObject = new CUse(oElement, pParent, pFile);
|
||||
else if (L"text" == wsElementName)
|
||||
{
|
||||
pObject = CText::Create(oElement, pParent, m_pFontManager);
|
||||
ReadChildrens(oElement, (CText*)pObject, pFile, (CText*)pObject);
|
||||
}
|
||||
else if (L"tspan" == wsElementName)
|
||||
{
|
||||
pObject = CTSpan::Create(oElement, pParent, m_pFontManager);
|
||||
ReadChildrens(oElement, (CTSpan*)pObject, pFile, (CTSpan*)pObject);
|
||||
}
|
||||
else if (L"textPath" == wsElementName)
|
||||
{
|
||||
pObject = CTextPath::Create(oElement, pParent, m_pFontManager, pFile);
|
||||
ReadChildrens(oElement, (CTextPath*)pObject, pFile);
|
||||
}
|
||||
//defs
|
||||
else if (L"defs" == wsElementName)
|
||||
return ReadChildrens<CRenderedObject>(oElement, NULL, pFile);
|
||||
else if(L"linearGradient" == wsElementName)
|
||||
{
|
||||
pObject = new CLinearGradient(oElement);
|
||||
ReadChildrens(oElement, (CLinearGradient*)pObject, pFile);
|
||||
}
|
||||
else if (L"radialGradient" == wsElementName)
|
||||
{
|
||||
pObject = new CRadialGradient(oElement);
|
||||
ReadChildrens(oElement, (CRadialGradient*)pObject, pFile);
|
||||
}
|
||||
else if (L"stop" == wsElementName)
|
||||
{
|
||||
CStopElement *pStopElement = new CStopElement(oElement);
|
||||
if (AddObject((ObjectType*)pStopElement, pContainer))
|
||||
{
|
||||
UpdateStyles(pStopElement, pFile);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(pStopElement);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (L"pattern" == wsElementName)
|
||||
{
|
||||
pObject = new CPattern(oElement, m_pFontManager);
|
||||
ReadChildrens(oElement, (CGraphicsContainer*)(&((CPattern*)pObject)->GetContainer()), pFile);
|
||||
}
|
||||
else if (L"clipPath" == wsElementName)
|
||||
{
|
||||
pObject = new CClipPath(oElement);
|
||||
ReadChildrens(oElement, (CGraphicsContainer*)(&((CClipPath*)pObject)->GetContainer()), pFile);
|
||||
}
|
||||
else if (L"marker" == wsElementName)
|
||||
{
|
||||
pObject = new CMarker(oElement);
|
||||
ReadChildrens(oElement, (CMarker*)pObject, pFile);
|
||||
}
|
||||
else if (L"mask" == wsElementName)
|
||||
{
|
||||
pObject = new CMask(oElement);
|
||||
ReadChildrens(oElement, (CGraphicsContainer*)(&((CMask*)pObject)->GetContainer()), pFile);
|
||||
}
|
||||
else if (L"symbol" == wsElementName)
|
||||
{
|
||||
pObject = new CSymbol(oElement);
|
||||
if (ReadChildrens(oElement, (CSymbol*)pObject, pFile) && MarkObject(pObject, pFile))
|
||||
return true;
|
||||
else
|
||||
RELEASEOBJECT(pObject);
|
||||
}
|
||||
|
||||
if (NULL != pObject)
|
||||
{
|
||||
if ((MarkObject(pObject, pFile) && (AppliedObject == pObject->GetType() || NULL == pContainer)) ||
|
||||
(RendererObject == pObject->GetType() && AddObject((ObjectType*)pObject, pContainer)))
|
||||
{
|
||||
UpdateStyles(pObject, pFile);
|
||||
return true;
|
||||
}
|
||||
delete pObject;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSvgParser::UpdateStyles(CObject *pObject, CSvgFile *pFile) const
|
||||
{
|
||||
if (NULL == pObject || NULL == pFile)
|
||||
return;
|
||||
|
||||
const CSvgCalculator *pSvgCalculator = pFile->GetSvgCalculator();
|
||||
|
||||
if (NULL != pSvgCalculator)
|
||||
pSvgCalculator->SetData(pObject);
|
||||
}
|
||||
|
||||
bool CSvgParser::MarkObject(CObject *pObject, CSvgFile *pFile) const
|
||||
{
|
||||
if (NULL == pObject || NULL == pFile)
|
||||
return false;
|
||||
|
||||
return pFile->MarkObject(pObject);
|
||||
}
|
||||
|
||||
template <class ObjectType>
|
||||
bool CSvgParser::AddObject(ObjectType *pObject, CContainer<ObjectType> *pContainer) const
|
||||
{
|
||||
return (NULL != pContainer && pContainer->AddObject(pObject));
|
||||
}
|
||||
|
||||
template <class ObjectType>
|
||||
bool CSvgParser::ReadChildrens(XmlUtils::CXmlNode &oElement, CContainer<ObjectType>* pContainer, CSvgFile* pFile, CRenderedObject *pParent) const
|
||||
{
|
||||
std::vector<XmlUtils::CXmlNode> arChilds;
|
||||
|
||||
oElement.GetChilds(arChilds);
|
||||
|
||||
if (arChilds.empty())
|
||||
return false;
|
||||
|
||||
for (XmlUtils::CXmlNode& oChild : arChilds)
|
||||
ReadObject(oChild, pContainer, pFile, pParent);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
43
DesktopEditor/raster/Metafile/svg/CSvgParser.h
Normal file
43
DesktopEditor/raster/Metafile/svg/CSvgParser.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef CSVGPARSER_H
|
||||
#define CSVGPARSER_H
|
||||
|
||||
#include "../../graphics/pro/Fonts.h"
|
||||
#include "../../../common/Directory.h"
|
||||
#include "../../../xml/include/xmlutils.h"
|
||||
|
||||
#include "SvgObjects/CContainer.h"
|
||||
|
||||
class CSvgFile;
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
class CSvgParser
|
||||
{
|
||||
public:
|
||||
CSvgParser();
|
||||
~CSvgParser();
|
||||
|
||||
void SetFontManager(NSFonts::IFontManager* pFontManager);
|
||||
|
||||
bool LoadFromFile(const std::wstring& wsFile, CGraphicsContainer* pContainer, CSvgFile* pFile) const;
|
||||
bool LoadFromString(const std::wstring& wsContente, CGraphicsContainer* pContainer, CSvgFile* pFile) const;
|
||||
bool LoadFromXmlNode(XmlUtils::CXmlNode& oElement, CGraphicsContainer* pContainer, CSvgFile* pFile) const;
|
||||
|
||||
template <class ObjectType>
|
||||
bool ReadObject(XmlUtils::CXmlNode& oElement, CContainer<ObjectType>* pContainer, CSvgFile* pFile, CRenderedObject* pParent = NULL) const;
|
||||
private:
|
||||
template <class ObjectType>
|
||||
bool ReadChildrens(XmlUtils::CXmlNode& oElement, CContainer<ObjectType>* pContainer, CSvgFile* pFile, CRenderedObject* pParent = NULL) const;
|
||||
|
||||
bool ScanStyles(XmlUtils::CXmlNode& oElement, CSvgFile* pFile) const;
|
||||
|
||||
void UpdateStyles(CObject* pObject, CSvgFile* pFile) const;
|
||||
bool MarkObject(CObject* pObject, CSvgFile* pFile) const;
|
||||
template <class ObjectType>
|
||||
bool AddObject(ObjectType* pObject, CContainer<ObjectType>* pContainer) const;
|
||||
|
||||
NSFonts::IFontManager *m_pFontManager;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSVGPARSER_H
|
||||
@ -1,6 +1,6 @@
|
||||
#include "SVGFramework.h"
|
||||
|
||||
#define ADD_COLOR( COLOR, R, G, B ) m_Table.insert(std::pair<std::wstring, unsigned int>( L##COLOR, ( G << 16 ) | ( G << 8 ) | R ))
|
||||
#define ADD_COLOR( COLOR, R, G, B ) m_Table.insert(std::pair<std::wstring, unsigned int>( L##COLOR, ( R << 0 ) | ( G << 8 ) | ( B << 16 ) ))
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
@ -247,7 +247,7 @@ namespace SVG
|
||||
if (0 == Color[3])
|
||||
return -2;
|
||||
|
||||
return ( ( (int) (Color [ 2 ]) << 16 ) | ( (int) (Color [ 1 ]) << 8 ) | (int) (Color [ 0 ]) );
|
||||
return ( ( (int) (Color [ 0 ]) ) | ( (int) (Color [ 1 ]) << 8 ) | (int) (Color [ 2 ]) << 16 );
|
||||
}
|
||||
long ColorParser::ColorFromHexString(const std::wstring& Hex)
|
||||
{
|
||||
|
||||
@ -513,7 +513,7 @@ namespace SVG
|
||||
if (0 == len) return 0;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (isdigit(buf[i]) || (buf[i] == L'-') /* || (value[i] == L'.') || (value[i] == L',') */)
|
||||
if (iswdigit(buf[i]) || (buf[i] == L'-') /* || (value[i] == L'.') || (value[i] == L',') */)
|
||||
continue;
|
||||
|
||||
return std::stol(value.substr(0, i));
|
||||
@ -527,7 +527,7 @@ namespace SVG
|
||||
if (0 == len) return 0;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (isdigit(buf[i]) || (buf[i] == L'.') || (buf[i] == L',') || (buf[i] == L'-') || (buf[i] == 'e'))
|
||||
if (iswdigit(buf[i]) || (buf[i] == L'.') || (buf[i] == L',') || (buf[i] == L'-') || (buf[i] == 'e'))
|
||||
continue;
|
||||
|
||||
return std::stol(value.substr(0, i));
|
||||
@ -589,7 +589,7 @@ namespace SVG
|
||||
number = L"";
|
||||
}
|
||||
|
||||
if (isdigit(Source[i]) || (Source[i] == '.') || (Source[i] == '-') || (Source[i] == 'e'))
|
||||
if (iswdigit(Source[i]) || (Source[i] == '.') || (Source[i] == '-') || (Source[i] == 'e'))
|
||||
{
|
||||
number += Source[i];
|
||||
continue;
|
||||
@ -671,6 +671,26 @@ namespace SVG
|
||||
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
static inline void ConvertValue(double &dValue, Metrics eMetrics)
|
||||
{
|
||||
switch (eMetrics)
|
||||
{
|
||||
case EM: break;
|
||||
case EX: break;
|
||||
case PX: dValue *= 96 / 25.4;
|
||||
case PT: break;
|
||||
case PC: break;
|
||||
case CM: break;
|
||||
case MM: break;
|
||||
case INCH: break;
|
||||
|
||||
case PCT: break;
|
||||
|
||||
case UNDEFINED: break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline std::wstring UrlRefValue(const std::wstring& sUrlRef)
|
||||
{
|
||||
if (sUrlRef.length() > 3)
|
||||
@ -1943,6 +1963,10 @@ namespace SVG
|
||||
{
|
||||
m_nFontSize = StrUtils::DoubleValue(oXml.GetAttribute(L"font-size"));
|
||||
m_nFontMetrics = StrUtils::GetMetrics(oXml.GetAttribute(L"font-size"));
|
||||
|
||||
if (UNDEFINED != m_nFontMetrics && 0 != m_nFontSize)
|
||||
StrUtils::ConvertValue(m_nFontSize, m_nFontMetrics);
|
||||
|
||||
m_FontFamily = oXml.GetAttributeOrValue(L"font-family", L"Arial");
|
||||
|
||||
m_nFontTextAnchor = FontTextAnchorStart;
|
||||
@ -1997,6 +2021,10 @@ namespace SVG
|
||||
{
|
||||
m_nFontSize = StrUtils::DoubleValue ( Value );
|
||||
m_nFontMetrics = StrUtils::GetMetrics ( Value );
|
||||
|
||||
if (UNDEFINED != m_nFontMetrics && 0 != m_nFontSize)
|
||||
StrUtils::ConvertValue(m_nFontSize, m_nFontMetrics);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2043,11 +2071,14 @@ namespace SVG
|
||||
bool UpdateStyle(XmlUtils::CXmlNode& oXmlNode)
|
||||
{
|
||||
if (!oXmlNode.GetAttribute ( L"font-size" ).empty())
|
||||
{
|
||||
m_nFontSize = StrUtils::DoubleValue ( oXmlNode.GetAttribute ( L"font-size") );
|
||||
|
||||
if (!oXmlNode.GetAttribute ( L"font-size" ).empty())
|
||||
m_nFontMetrics = StrUtils::GetMetrics ( oXmlNode.GetAttribute ( L"font-size" ) );
|
||||
|
||||
if (UNDEFINED != m_nFontMetrics && 0 != m_nFontSize)
|
||||
StrUtils::ConvertValue(m_nFontSize, m_nFontMetrics);
|
||||
}
|
||||
|
||||
if (!oXmlNode.GetAttributeOrValue ( L"font-family", L"Arial" ).empty())
|
||||
m_FontFamily = oXmlNode.GetAttributeOrValue ( L"font-family", L"Arial");
|
||||
|
||||
|
||||
@ -105,3 +105,13 @@ int CSVGTransformer::get_Metrics()
|
||||
{
|
||||
return m_internal->m_oXmlParser.GetMetrics();
|
||||
}
|
||||
|
||||
bool CSVGTransformer::GetBounds(double &dX, double &dY, double &dWidth, double &dHeight)
|
||||
{
|
||||
dX = 0;
|
||||
dY = 0;
|
||||
dWidth = get_Width();
|
||||
dHeight = get_Height();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -27,6 +27,8 @@ public:
|
||||
int get_Height();
|
||||
int get_Metrics();
|
||||
|
||||
bool GetBounds(double &dX, double &dY, double &dWidth, double &dHeight);
|
||||
|
||||
private:
|
||||
CSVGTransformer_private* m_internal;
|
||||
};
|
||||
|
||||
66
DesktopEditor/raster/Metafile/svg/SvgObjects/CCircle.cpp
Normal file
66
DesktopEditor/raster/Metafile/svg/SvgObjects/CCircle.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "CCircle.h"
|
||||
|
||||
#include "CContainer.h"
|
||||
#include "CStyle.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CCircle::CCircle(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent)
|
||||
: CRenderedObject(oNode, pParent)
|
||||
{
|
||||
m_oCx.SetValue(oNode.GetAttribute(L"cx"));
|
||||
m_oCy.SetValue(oNode.GetAttribute(L"cy"));
|
||||
m_oR .SetValue(oNode.GetAttribute(L"r"));
|
||||
}
|
||||
|
||||
void CCircle::SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
|
||||
{
|
||||
CRenderedObject::SetData(mAttributes, ushLevel, bHardMode);
|
||||
|
||||
SetStroke(mAttributes, ushLevel, bHardMode);
|
||||
SetFill(mAttributes, ushLevel, bHardMode);
|
||||
}
|
||||
|
||||
bool CCircle::Draw(IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles *pOtherStyles) const
|
||||
{
|
||||
Aggplus::CMatrix oOldTransform;
|
||||
|
||||
if (!StartPath(pRenderer, pFile, oOldTransform, oMode))
|
||||
return false;
|
||||
|
||||
TBounds oBounds = (NULL != m_pParent) ? m_pParent->GetBounds() : TBounds{0., 0., 0., 0.};
|
||||
|
||||
double dX = m_oCx.ToDouble(NSCSS::Pixel, oBounds.m_dRight - oBounds.m_dLeft);
|
||||
double dY = m_oCy.ToDouble(NSCSS::Pixel, oBounds.m_dBottom - oBounds.m_dTop);
|
||||
double dR = m_oR .ToDouble(NSCSS::Pixel);
|
||||
|
||||
pRenderer->PathCommandMoveTo(dX + dR, dY);
|
||||
pRenderer->PathCommandArcTo(dX - dR, dY - dR, dR * 2.0, dR * 2.0, 0, 360);
|
||||
|
||||
EndPath(pRenderer, pFile, oOldTransform, oMode, pOtherStyles);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCircle::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
|
||||
{
|
||||
if (Apply(pRenderer, &pStyles->m_oStroke))
|
||||
nTypePath += c_nStroke;
|
||||
|
||||
if (Apply(pRenderer, &pStyles->m_oFill, pFile, true))
|
||||
nTypePath += c_nWindingFillMode;
|
||||
}
|
||||
|
||||
TBounds CCircle::GetBounds() const
|
||||
{
|
||||
TBounds oBounds;
|
||||
|
||||
oBounds.m_dLeft = (m_oCx - m_oR).ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dTop = (m_oCy - m_oR).ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dRight = (m_oCx + m_oR).ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dBottom = (m_oCy + m_oR).ToDouble(NSCSS::Pixel);
|
||||
|
||||
return oBounds;
|
||||
}
|
||||
|
||||
}
|
||||
27
DesktopEditor/raster/Metafile/svg/SvgObjects/CCircle.h
Normal file
27
DesktopEditor/raster/Metafile/svg/SvgObjects/CCircle.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef CCIRCLE_H
|
||||
#define CCIRCLE_H
|
||||
|
||||
#include "CObjectBase.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
class CCircle : public CRenderedObject
|
||||
{
|
||||
public:
|
||||
CCircle(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL);
|
||||
|
||||
void SetData(const std::map<std::wstring, std::wstring>& mAttributes, unsigned short ushLevel, bool bHardMode = false) override;
|
||||
|
||||
bool Draw(IRenderer* pRenderer, const CSvgFile *pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const override;
|
||||
private:
|
||||
void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile *pFile, int& nTypePath) const override;
|
||||
|
||||
TBounds GetBounds() const override;
|
||||
|
||||
SvgDigit m_oCx;
|
||||
SvgDigit m_oCy;
|
||||
SvgDigit m_oR;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CCIRCLE_H
|
||||
36
DesktopEditor/raster/Metafile/svg/SvgObjects/CClipPath.cpp
Normal file
36
DesktopEditor/raster/Metafile/svg/SvgObjects/CClipPath.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "CClipPath.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CClipPath::CClipPath(XmlUtils::CXmlNode &oNode)
|
||||
: CAppliedObject(oNode)
|
||||
{}
|
||||
|
||||
void CClipPath::SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
|
||||
{
|
||||
// SetClip(mAttributes, ushLevel, bHardMode);
|
||||
// SetMask(mAttributes, ushLevel, bHardMode);
|
||||
}
|
||||
|
||||
bool CClipPath::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
|
||||
{
|
||||
if (NULL == pRenderer || NULL == pFile)
|
||||
return false;
|
||||
|
||||
pRenderer->put_ClipMode(c_nClipRegionUnion);
|
||||
|
||||
pRenderer->PathCommandStart();
|
||||
|
||||
for (const CRenderedObject* pObject : m_oContainer.m_arObjects)
|
||||
pObject->Draw(pRenderer, pFile, CommandeModeClip);
|
||||
|
||||
pRenderer->PathCommandEnd();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CContainer<CRenderedObject> &CClipPath::GetContainer()
|
||||
{
|
||||
return m_oContainer;
|
||||
}
|
||||
}
|
||||
25
DesktopEditor/raster/Metafile/svg/SvgObjects/CClipPath.h
Normal file
25
DesktopEditor/raster/Metafile/svg/SvgObjects/CClipPath.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef CCLIPPATH_H
|
||||
#define CCLIPPATH_H
|
||||
|
||||
#include "CContainer.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
class CClipPath : public CAppliedObject
|
||||
{
|
||||
public:
|
||||
CClipPath(XmlUtils::CXmlNode& oNode);
|
||||
|
||||
void SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode) override;
|
||||
|
||||
bool Apply(IRenderer* pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) override;
|
||||
|
||||
CContainer<CRenderedObject>& GetContainer();
|
||||
private:
|
||||
friend class CMask;
|
||||
|
||||
CContainer<CRenderedObject> m_oContainer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CCLIPPATH_H
|
||||
90
DesktopEditor/raster/Metafile/svg/SvgObjects/CContainer.cpp
Normal file
90
DesktopEditor/raster/Metafile/svg/SvgObjects/CContainer.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "CContainer.h"
|
||||
|
||||
#include "../CSvgFile.h"
|
||||
#include "../SvgUtils.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CGraphicsContainer::CGraphicsContainer(const std::wstring &wsName)
|
||||
: CRenderedObject(NSCSS::CNode(wsName, L"", L""))
|
||||
{}
|
||||
|
||||
void CGraphicsContainer::SetData(XmlUtils::CXmlNode &oNode)
|
||||
{
|
||||
m_oWindow.m_oX .SetValue(oNode.GetAttribute(L"x"));
|
||||
m_oWindow.m_oY .SetValue(oNode.GetAttribute(L"y"));
|
||||
m_oWindow.m_oWidth .SetValue(oNode.GetAttribute(L"width"));
|
||||
m_oWindow.m_oHeight.SetValue(oNode.GetAttribute(L"height"));
|
||||
|
||||
const std::wstring wsViewBox = oNode.GetAttribute(L"viewBox");
|
||||
|
||||
if (!wsViewBox.empty())
|
||||
{
|
||||
std::vector<double> arValues = StrUtils::ReadDoubleValues(wsViewBox);
|
||||
if (4 == arValues.size())
|
||||
{
|
||||
m_oViewBox.m_oX = arValues[0];
|
||||
m_oViewBox.m_oY = arValues[1];
|
||||
m_oViewBox.m_oWidth = arValues[2];
|
||||
m_oViewBox.m_oHeight = arValues[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CGraphicsContainer::CGraphicsContainer(XmlUtils::CXmlNode& oNode, CRenderedObject *pParent)
|
||||
: CRenderedObject(oNode, pParent)
|
||||
{
|
||||
SetData(oNode);
|
||||
}
|
||||
|
||||
CGraphicsContainer::CGraphicsContainer(double dWidth, double dHeight, XmlUtils::CXmlNode& oNode, CRenderedObject *pParent)
|
||||
: CRenderedObject(oNode, pParent), m_oWindow{0, 0, dWidth, dHeight}
|
||||
{}
|
||||
|
||||
bool CGraphicsContainer::Draw(IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles *pOtherStyles) const
|
||||
{
|
||||
Aggplus::CMatrix oOldTransform;
|
||||
|
||||
if (!StartPath(pRenderer, pFile, oOldTransform, oMode))
|
||||
return false;
|
||||
|
||||
for (const CRenderedObject* pObject : m_arObjects)
|
||||
pObject->Draw(pRenderer, pFile, oMode, pOtherStyles);
|
||||
|
||||
EndPath(pRenderer, pFile, oOldTransform, oMode, pOtherStyles);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TRect CGraphicsContainer::GetWindow() const
|
||||
{
|
||||
return m_oWindow;
|
||||
}
|
||||
|
||||
TRect CGraphicsContainer::GetViewBox() const
|
||||
{
|
||||
return m_oViewBox;
|
||||
}
|
||||
|
||||
TBounds CGraphicsContainer::GetBounds() const
|
||||
{
|
||||
TBounds oBounds, oTempBounds;
|
||||
|
||||
oBounds.m_dLeft = oBounds.m_dRight = m_oWindow.m_oX.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dTop = oBounds.m_dBottom = m_oWindow.m_oY.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dRight += m_oWindow.m_oWidth.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dBottom += m_oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
|
||||
|
||||
for (const CRenderedObject* pObject : m_arObjects)
|
||||
{
|
||||
oTempBounds = pObject->GetBounds();
|
||||
oBounds.m_dLeft = std::min(oBounds.m_dLeft, oTempBounds.m_dLeft);
|
||||
oBounds.m_dTop = std::min(oBounds.m_dTop, oTempBounds.m_dTop);
|
||||
oBounds.m_dRight = std::max(oBounds.m_dRight, oTempBounds.m_dRight);
|
||||
oBounds.m_dBottom = std::max(oBounds.m_dBottom, oTempBounds.m_dBottom);
|
||||
}
|
||||
|
||||
return oBounds;
|
||||
}
|
||||
|
||||
}
|
||||
105
DesktopEditor/raster/Metafile/svg/SvgObjects/CContainer.h
Normal file
105
DesktopEditor/raster/Metafile/svg/SvgObjects/CContainer.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef CCONTAINER_H
|
||||
#define CCONTAINER_H
|
||||
|
||||
#include "CObjectBase.h"
|
||||
|
||||
#include "../../../graphics/pro/Fonts.h"
|
||||
|
||||
class CSvgFile;
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
class CSvgParser;
|
||||
|
||||
template<typename TypeObject>
|
||||
class CContainer
|
||||
{
|
||||
public:
|
||||
CContainer(){}
|
||||
~CContainer()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
for (TypeObject* pObject : m_arObjects)
|
||||
delete pObject;
|
||||
}
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return m_arObjects.empty();
|
||||
}
|
||||
|
||||
virtual bool AddObject(TypeObject* pObject)
|
||||
{
|
||||
if (NULL != pObject)
|
||||
{
|
||||
m_arObjects.push_back(pObject);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual TypeObject* GetObject(const std::wstring& wsId) const
|
||||
{
|
||||
if (wsId.empty() || m_arObjects.empty())
|
||||
return NULL;
|
||||
|
||||
std::wstring wsNewId = wsId;
|
||||
|
||||
size_t unFound = wsNewId.find(L'#');
|
||||
|
||||
if (std::wstring::npos != unFound)
|
||||
wsNewId.erase(0, unFound + 1);
|
||||
|
||||
typename std::vector<TypeObject*>::const_iterator oFound = std::find_if(m_arObjects.begin(), m_arObjects.end(), [&wsNewId](TypeObject* pObject){ if (wsNewId == pObject->GetId()) return true; else return false;});
|
||||
|
||||
if (m_arObjects.end() != oFound)
|
||||
return *oFound;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
private:
|
||||
std::vector<TypeObject*> m_arObjects;
|
||||
|
||||
friend class CText;
|
||||
friend class CMask;
|
||||
friend class CTSpan;
|
||||
friend class CMarker;
|
||||
friend class CPattern;
|
||||
friend class CGradient;
|
||||
friend class CClipPath;
|
||||
friend class CTextPath;
|
||||
friend class CGraphicsContainer;
|
||||
};
|
||||
|
||||
class CGraphicsContainer : public CContainer<CRenderedObject>, public CRenderedObject
|
||||
{
|
||||
public:
|
||||
CGraphicsContainer(const std::wstring& wsName = L"GraphicsContainer");
|
||||
CGraphicsContainer(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL);
|
||||
CGraphicsContainer(double dWidth, double dHeight, XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL);
|
||||
CGraphicsContainer(const CGraphicsContainer& oGraphicsContainer);
|
||||
|
||||
void SetData(XmlUtils::CXmlNode& oNode);
|
||||
|
||||
bool Draw(IRenderer* pRenderer, const CSvgFile *pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const override;
|
||||
|
||||
TRect GetWindow() const;
|
||||
TRect GetViewBox() const;
|
||||
private:
|
||||
TBounds GetBounds() const override;
|
||||
|
||||
friend class CPattern;
|
||||
friend class CMarker;
|
||||
friend class CSymbol;
|
||||
friend class CMask;
|
||||
|
||||
TRect m_oWindow;
|
||||
TRect m_oViewBox;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CCONTAINER_H
|
||||
70
DesktopEditor/raster/Metafile/svg/SvgObjects/CEllipse.cpp
Normal file
70
DesktopEditor/raster/Metafile/svg/SvgObjects/CEllipse.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include "CEllipse.h"
|
||||
|
||||
#include "CStyle.h"
|
||||
#include "CContainer.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CEllipse::CEllipse(XmlUtils::CXmlNode &oNode, CRenderedObject *pParent)
|
||||
: CRenderedObject(oNode, pParent)
|
||||
{
|
||||
m_oCx.SetValue(oNode.GetAttribute(L"cx"));
|
||||
m_oCy.SetValue(oNode.GetAttribute(L"cy"));
|
||||
m_oRx.SetValue(oNode.GetAttribute(L"rx"));
|
||||
m_oRy.SetValue(oNode.GetAttribute(L"ry"));
|
||||
}
|
||||
|
||||
void CEllipse::SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
|
||||
{
|
||||
CRenderedObject::SetData(mAttributes, ushLevel, bHardMode);
|
||||
|
||||
SetStroke(mAttributes, ushLevel, bHardMode);
|
||||
SetFill(mAttributes, ushLevel, bHardMode);
|
||||
}
|
||||
|
||||
bool CEllipse::Draw(IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles *pOtherStyles) const
|
||||
{
|
||||
Aggplus::CMatrix oOldTransform;
|
||||
|
||||
if (!StartPath(pRenderer, pFile, oOldTransform, oMode))
|
||||
return false;
|
||||
|
||||
TBounds oBounds = (NULL != m_pParent) ? m_pParent->GetBounds() : TBounds{0., 0., 0., 0.};
|
||||
|
||||
double dParentWidth = oBounds.m_dRight - oBounds.m_dLeft;
|
||||
double dParentHeight = oBounds.m_dBottom - oBounds.m_dTop;
|
||||
|
||||
double dX = m_oCx.ToDouble(NSCSS::Pixel, dParentWidth);
|
||||
double dY = m_oCy.ToDouble(NSCSS::Pixel, dParentHeight);
|
||||
double dRx = m_oRx.ToDouble(NSCSS::Pixel, dParentWidth);
|
||||
double dRy = m_oRy.ToDouble(NSCSS::Pixel, dParentHeight);
|
||||
|
||||
pRenderer->PathCommandMoveTo(dX + dRx, dY);
|
||||
pRenderer->PathCommandArcTo(dX - dRx, dY - dRy, dRx * 2.0, dRy * 2.0, 0, 360);
|
||||
|
||||
EndPath(pRenderer, pFile, oOldTransform, oMode, pOtherStyles);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEllipse::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
|
||||
{
|
||||
if (Apply(pRenderer, &pStyles->m_oStroke))
|
||||
nTypePath += c_nStroke;
|
||||
|
||||
if (Apply(pRenderer, &pStyles->m_oFill, pFile, true))
|
||||
nTypePath += c_nWindingFillMode;
|
||||
}
|
||||
|
||||
TBounds CEllipse::GetBounds() const
|
||||
{
|
||||
TBounds oBounds;
|
||||
|
||||
oBounds.m_dLeft = m_oCx.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dTop = m_oCy.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dRight = oBounds.m_dLeft + m_oRx.ToDouble(NSCSS::Pixel);
|
||||
oBounds.m_dBottom = oBounds.m_dTop + m_oRy.ToDouble(NSCSS::Pixel);;
|
||||
|
||||
return oBounds;
|
||||
}
|
||||
}
|
||||
29
DesktopEditor/raster/Metafile/svg/SvgObjects/CEllipse.h
Normal file
29
DesktopEditor/raster/Metafile/svg/SvgObjects/CEllipse.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef CELLIPSE_H
|
||||
#define CELLIPSE_H
|
||||
|
||||
|
||||
#include "CObjectBase.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
class CEllipse : public CRenderedObject
|
||||
{
|
||||
public:
|
||||
CEllipse(XmlUtils::CXmlNode& oNode, CRenderedObject* pParent = NULL);
|
||||
|
||||
void SetData(const std::map<std::wstring, std::wstring>& mAttributes, unsigned short ushLevel, bool bHardMode = false) override;
|
||||
|
||||
bool Draw(IRenderer* pRenderer, const CSvgFile *pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const override;
|
||||
private:
|
||||
void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile *pFile, int& nTypePath) const override;
|
||||
|
||||
TBounds GetBounds() const override;
|
||||
|
||||
SvgDigit m_oCx;
|
||||
SvgDigit m_oCy;
|
||||
SvgDigit m_oRx;
|
||||
SvgDigit m_oRy;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CELLIPSE_H
|
||||
150
DesktopEditor/raster/Metafile/svg/SvgObjects/CGradient.cpp
Normal file
150
DesktopEditor/raster/Metafile/svg/SvgObjects/CGradient.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
#include "CGradient.h"
|
||||
#include "../CSvgFile.h"
|
||||
|
||||
namespace SVG
|
||||
{
|
||||
CStopElement::CStopElement(XmlUtils::CXmlNode& oNode)
|
||||
: CObject(oNode)
|
||||
{}
|
||||
|
||||
ObjectType CStopElement::GetType() const
|
||||
{
|
||||
return AppliedObject;
|
||||
}
|
||||
|
||||
SvgDigit CStopElement::GetOffset() const
|
||||
{
|
||||
return m_oOffset;
|
||||
}
|
||||
|
||||
SvgColor CStopElement::GetColor() const
|
||||
{
|
||||
return m_oColor;
|
||||
}
|
||||
|
||||
void CStopElement::SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
|
||||
{
|
||||
if (mAttributes.end() != mAttributes.find(L"stop-color"))
|
||||
m_oColor.SetValue(mAttributes.at(L"stop-color"));
|
||||
|
||||
if (mAttributes.end() != mAttributes.find(L"offset") && m_oOffset.SetValue(mAttributes.at(L"offset")) && m_oOffset.ToDouble() > 1.)
|
||||
m_oOffset /= 100;
|
||||
|
||||
if (mAttributes.end() != mAttributes.find(L"stop-opacity"))
|
||||
m_oColor.SetOpacity(mAttributes.at(L"stop-opacity"));
|
||||
}
|
||||
|
||||
CGradient::CGradient(XmlUtils::CXmlNode &oNode)
|
||||
: CAppliedObject(oNode)
|
||||
{
|
||||
m_wsXlinkHref = oNode.GetAttribute(L"href", oNode.GetAttribute(L"xlink:href"));
|
||||
}
|
||||
|
||||
void CGradient::SetData(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
|
||||
{
|
||||
if (mAttributes.end() != mAttributes.find(L"transform"))
|
||||
m_oTransform.SetMatrix(mAttributes.at(L"transform"), ushLevel, bHardMode);
|
||||
}
|
||||
|
||||
bool CGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
return false;
|
||||
|
||||
if (m_arObjects.empty())
|
||||
{
|
||||
if (m_wsXlinkHref.empty() || NULL == pFile)
|
||||
return false;
|
||||
|
||||
CGradient *pGradiend = dynamic_cast<CGradient*>(pFile->GetMarkedObject(m_wsXlinkHref));
|
||||
|
||||
return (NULL == pGradiend) ? false : pGradiend->Apply(pRenderer, pFile, oObjectBounds);
|
||||
}
|
||||
|
||||
std::vector<LONG> arColors;
|
||||
std::vector<double> arPositions;
|
||||
|
||||
for (const CStopElement* pStopElement : m_arObjects)
|
||||
{
|
||||
arColors.push_back(((unsigned int)(pStopElement->GetColor().ToInt() | ((unsigned char)(255. * pStopElement->GetColor().GetOpacity()) << 24))));
|
||||
arPositions.push_back(pStopElement->GetOffset().ToDouble());
|
||||
}
|
||||
|
||||
pRenderer->put_BrushGradientColors(arColors.data(), arPositions.data(), arColors.size());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CLinearGradient::CLinearGradient(XmlUtils::CXmlNode& oNode)
|
||||
: CGradient(oNode)
|
||||
{
|
||||
m_oX1.SetValue(oNode.GetAttribute(L"x1"));
|
||||
m_oY1.SetValue(oNode.GetAttribute(L"y1"));
|
||||
m_oX2.SetValue(oNode.GetAttribute(L"x2"));
|
||||
m_oY2.SetValue(oNode.GetAttribute(L"y2"));
|
||||
}
|
||||
|
||||
bool CLinearGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
|
||||
{
|
||||
if (!CGradient::Apply(pRenderer, pFile, oObjectBounds))
|
||||
return false;
|
||||
|
||||
pRenderer->put_BrushType(c_BrushTypePathGradient1);
|
||||
|
||||
double dX1 = m_oX1.ToDouble(NSCSS::Pixel);
|
||||
double dY1 = m_oY1.ToDouble(NSCSS::Pixel);
|
||||
double dX2 = m_oX2.ToDouble(NSCSS::Pixel);
|
||||
double dY2 = m_oY2.ToDouble(NSCSS::Pixel);
|
||||
|
||||
double dWidthKoef = 1.;
|
||||
double dHeightKoef = 1.;
|
||||
|
||||
if (NSCSS::UnitMeasure::Percent == m_oX2.GetUnitMeasure())
|
||||
dWidthKoef*= dX2 / 100.;
|
||||
else if (NSCSS::UnitMeasure::None == m_oX2.GetUnitMeasure() && dX2 > 1.)
|
||||
dWidthKoef = dX2;
|
||||
|
||||
if (NSCSS::UnitMeasure::Percent == m_oY2.GetUnitMeasure())
|
||||
dHeightKoef*= dY2 / 100.;
|
||||
else if (NSCSS::UnitMeasure::None == m_oY2.GetUnitMeasure() && dY2 > 1.)
|
||||
dHeightKoef = dY2;
|
||||
|
||||
double dAngle = 0.;
|
||||
|
||||
if (std::fabs(dX2 - dX1) >= 0. || fabs(dY2 - dY1) >= 0.)
|
||||
dAngle = 180. * std::atan2(dY2 - dY1, dX2 - dX1) / M_PI;
|
||||
|
||||
pRenderer->put_BrushLinearAngle(dAngle);
|
||||
pRenderer->BrushBounds(oObjectBounds.m_dLeft, oObjectBounds.m_dTop, (oObjectBounds.m_dRight - oObjectBounds.m_dLeft) * dWidthKoef, (oObjectBounds.m_dBottom - oObjectBounds.m_dTop) * dHeightKoef);
|
||||
|
||||
Aggplus::CMatrix oMatrix(1, 0, 0, 1, 100, 0);
|
||||
pRenderer->put_BrushTransform(oMatrix);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CRadialGradient::CRadialGradient(XmlUtils::CXmlNode& oNode)
|
||||
: CGradient(oNode)
|
||||
{
|
||||
m_oCx.SetValue(oNode.GetAttribute(L"cx"));
|
||||
m_oCy.SetValue(oNode.GetAttribute(L"cy"));
|
||||
m_oR.SetValue(oNode.GetAttribute(L"r"));
|
||||
}
|
||||
|
||||
bool CRadialGradient::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds)
|
||||
{
|
||||
if (!CGradient::Apply(pRenderer, pFile, oObjectBounds))
|
||||
return false;
|
||||
|
||||
pRenderer->put_BrushType(c_BrushTypePathGradient2);
|
||||
|
||||
double dCx = m_oCx.ToDouble(NSCSS::Pixel) * (oObjectBounds.m_dRight - oObjectBounds.m_dLeft) + oObjectBounds.m_dLeft;
|
||||
double dCy = m_oCy.ToDouble(NSCSS::Pixel) * (oObjectBounds.m_dBottom - oObjectBounds.m_dTop) + oObjectBounds.m_dTop;
|
||||
double dR = m_oR .ToDouble(NSCSS::Pixel) * (oObjectBounds.m_dRight - oObjectBounds.m_dLeft);
|
||||
|
||||
pRenderer->BrushBounds(dCx - dR, dCy - dR, (dR != 0) ? dR * 2 : (oObjectBounds.m_dRight - oObjectBounds.m_dLeft), (dR != 0) ? dR * 2 : (oObjectBounds.m_dBottom - oObjectBounds.m_dTop));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user