Compare commits

...

21 Commits

Author SHA1 Message Date
acc81f8c8d Added gradient testing 2023-08-17 18:54:12 +03:00
c0fd800149 Merge pull request #1247 from ONLYOFFICE/fix/x2ttester
Fix bug 63562
2023-08-17 12:39:03 +05:00
0eb442dceb Fix bug 63609 2023-08-16 13:48:43 +03:00
399add2545 fix bug #63682 2023-08-16 09:01:12 +03:00
f245a5b6a5 fix bug #63681 2023-08-16 08:37:42 +03:00
bc3867f281 Fix bug 63558 2023-08-15 20:56:53 +03:00
7e27726dc2 Merge branch 'release/v7.5.0' of https://github.com/ONLYOFFICE/core into release/v7.5.0 2023-08-15 18:29:42 +03:00
ab1bc5e2a9 Merge remote-tracking branch 'origin/feature/android-fix-build' into release/v7.5.0 2023-08-15 18:29:00 +03:00
68ea0b5875 Fix crash with 2+ emf inside wmf 2023-08-15 18:25:33 +03:00
796cd30b09 Merge pull request #1249 from ONLYOFFICE/fix/Svg_Reader
Refactoring and added support for some properties in Svg Reader
2023-08-15 14:45:07 +05:00
58d023e023 Merge pull request #1248 from ONLYOFFICE/fix/MetafileToSvg
Editing metafile conversion to svg
2023-08-15 14:44:42 +05:00
0ecf5e8eee Refactoring and added support for some properties 2023-08-15 11:28:00 +03:00
6f11dd441b Refactoring 2023-08-15 11:21:14 +03:00
5b91e643bb Fix bug #63608 2023-08-15 11:21:14 +03:00
c884f2a99d Refactoring 2023-08-15 11:21:14 +03:00
fa82a15c07 Tab refactoring 2023-08-15 11:21:14 +03:00
5006bc3349 Fixed a bug with metafiles embedded in the metafile 2023-08-15 11:21:14 +03:00
d87283e485 fix bug #57247 2023-08-15 10:48:57 +03:00
77ff0a5f15 Fix bug 63609 2023-08-14 14:47:12 +03:00
4c3f983cb4 Fix bug 63562 2023-08-05 16:43:44 +03:00
6146180408 . 2023-07-13 16:24:13 +03:00
53 changed files with 944 additions and 925 deletions

View File

@ -392,11 +392,12 @@ namespace NSCSS
std::wstring CColor::ConvertRGBtoHEX(const TRGB &oValue)
{
wchar_t arTemp[6];
const int tempLen = 7;
wchar_t arTemp[tempLen];
swprintf(arTemp, sizeof(arTemp), L"%2hhX%2hhX%2hhX", oValue.uchRed, oValue.uchGreen, oValue.uchBlue);
swprintf(arTemp, tempLen, L"%02X%02X%02X", oValue.uchRed, oValue.uchGreen, oValue.uchBlue);
return std::wstring(arTemp);
return std::wstring(arTemp, 6);
}
std::wstring CColor::CutURL(const std::wstring &wsValue)
@ -2212,8 +2213,25 @@ namespace NSCSS
bool CColorValue::operator==(const CColorValue &oColorValue) const
{
return (m_enType == oColorValue.m_enType) && ((ColorEmpty == m_enType) || (ColorNone == m_enType) ||
(ColorRGB == m_enType && *static_cast<std::wstring*>(m_pColor) == *static_cast<std::wstring*>(oColorValue.m_pColor)) || ((ColorHEX == m_enType || ColorUrl == m_enType) && *static_cast<std::wstring*>(m_pColor) == *static_cast<std::wstring*>(oColorValue.m_pColor)));
if (m_enType != oColorValue.m_enType)
return false;
if (ColorEmpty == m_enType ||
ColorNone == m_enType)
return true;
switch (m_enType)
{
case ColorRGB:
return *static_cast<TRGB*>(m_pColor) == *static_cast<TRGB*>(oColorValue.m_pColor);
case ColorHEX:
case ColorUrl:
return *static_cast<std::wstring*>(m_pColor) == *static_cast<std::wstring*>(oColorValue.m_pColor);
default:
break;
}
return false;
}
CColorValue &CColorValue::operator=(const CColorValue &oColorValue)

View File

@ -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();
}
}
}

View 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

View 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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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

View File

@ -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()

View File

@ -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;

View File

@ -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.)}};

View File

@ -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 << " ";

View File

@ -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: Реализовать

View File

@ -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;
};
}

View File

@ -66,9 +66,6 @@ namespace SVG
return m_oViewBox;
}
void CGraphicsContainer::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
{}
TBounds CGraphicsContainer::GetBounds() const
{
TBounds oBounds, oTempBounds;

View File

@ -90,8 +90,6 @@ namespace SVG
TRect GetWindow() const;
TRect GetViewBox() const;
private:
void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile *pFile, int& nTypePath) const override;
TBounds GetBounds() const override;
friend class CPattern;

View File

@ -101,9 +101,6 @@ namespace SVG
return true;
}
void CImage::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
{}
TBounds CImage::GetBounds() const
{
TBounds oBounds;

View File

@ -12,8 +12,6 @@ namespace SVG
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;
TRect m_oRect;

View File

@ -3,6 +3,41 @@
namespace SVG
{
TSvgStyles &TSvgStyles::operator+=(const TSvgStyles &oSvgStyles)
{
m_oTransform.SetMatrix(oSvgStyles.m_oTransform.GetMatrix().ToWString(), 0, false);
if (!oSvgStyles.m_oFill.Empty())
m_oFill.SetValue(L'#' + oSvgStyles.m_oFill.ToWString(), 0, false);
m_oFill.SetOpacity(std::to_wstring(oSvgStyles.m_oFill.GetOpacity()), 0, false);
if (!oSvgStyles.m_oStroke.m_oColor.Empty())
m_oStroke.m_oColor.SetValue(L'#' + oSvgStyles.m_oStroke.m_oColor.ToWString(), 0, false);
m_oStroke.m_oWidth.SetValue(oSvgStyles.m_oStroke.m_oWidth.ToWString(), 0, false);
if (m_oStroke.m_arDash.empty() && !oSvgStyles.m_oStroke.m_arDash.empty())
m_oStroke.m_arDash = oSvgStyles.m_oStroke.m_arDash;
if (m_oStroke.m_oLineCap.Empty() && !oSvgStyles.m_oStroke.m_oLineCap.Empty())
m_oStroke.m_oLineCap = oSvgStyles.m_oStroke.m_oLineCap;
if (m_oStroke.m_oLineJoin.Empty() && !oSvgStyles.m_oStroke.m_oLineJoin.Empty())
m_oStroke.m_oLineJoin = oSvgStyles.m_oStroke.m_oLineJoin;
if (m_oClip.m_oHref.Empty() && !oSvgStyles.m_oClip.m_oHref.Empty())
m_oClip.m_oHref = oSvgStyles.m_oClip.m_oHref;
if (m_oClip.m_oRule.Empty() && !oSvgStyles.m_oClip.m_oRule.Empty())
m_oClip.m_oRule = oSvgStyles.m_oClip.m_oRule;
if (m_oMask.Empty() && !oSvgStyles.m_oMask.Empty() && NSCSS::NSProperties::ColorUrl == oSvgStyles.m_oMask.GetType())
m_oMask= oSvgStyles.m_oMask;
return *this;
}
CObject::CObject(const NSCSS::CNode &oData)
: m_oXmlNode(oData)
{}
@ -22,17 +57,15 @@ namespace SVG
{
if (L"class" == arProperties[unIndex])
{
m_oXmlNode.m_wsClass = arValues[unIndex];
std::transform(m_oXmlNode.m_wsClass.begin(), m_oXmlNode.m_wsClass.end(), m_oXmlNode.m_wsClass.begin(), std::towlower);
m_oXmlNode.m_wsClass = arValues[unIndex];
std::transform(m_oXmlNode.m_wsClass.begin(), m_oXmlNode.m_wsClass.end(), m_oXmlNode.m_wsClass.begin(), std::towlower);
}
else if (L"id" == arProperties[unIndex])
{
m_oXmlNode.m_wsId = arValues[unIndex];
}
else if (L"style" == arProperties[unIndex])
m_oXmlNode.m_wsStyle = arValues[unIndex];
m_oXmlNode.m_wsStyle = arValues[unIndex];
else
m_oXmlNode.m_mAttributes.insert({arProperties[unIndex], arValues[unIndex]});
m_oXmlNode.m_mAttributes.insert({arProperties[unIndex], arValues[unIndex]});
}
}
@ -105,7 +138,7 @@ namespace SVG
m_oStyles.m_oStroke.m_oMiterlimit = 4.;
m_oStyles.m_bDisplay = true;
m_oStyles.m_bDraw = true;
}
void CRenderedObject::SetStroke(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
@ -119,6 +152,9 @@ namespace SVG
if (mAttributes.end() != mAttributes.find(L"stroke-dasharray"))
m_oStyles.m_oStroke.m_arDash = NSCSS::NS_STATIC_FUNCTIONS::ReadDoubleValues(mAttributes.at(L"stroke-dasharray"));
if (mAttributes.end() != mAttributes.find(L"stroke-dashoffset"))
m_oStyles.m_oStroke.m_oDashOffset.SetValue(mAttributes.at(L"stroke-dashoffset"), ushLevel, bHardMode);
if (mAttributes.end() != mAttributes.find(L"stroke-linecap"))
m_oStyles.m_oStroke.m_oLineCap.SetValue(mAttributes.at(L"stroke-linecap"), ushLevel, bHardMode);
@ -173,19 +209,23 @@ namespace SVG
void CRenderedObject::SetDisplay(const std::map<std::wstring, std::wstring> &mAttributes, unsigned short ushLevel, bool bHardMode)
{
if (mAttributes.end() != mAttributes.find(L"display"))
{
const std::wstring wsDisplay = mAttributes.at(L"display");
std::wstring wsDisplay, wsVisibility;
if (!wsDisplay.empty()) m_oStyles.m_bDisplay = (L"none" == wsDisplay) ? false : true;
}
if (mAttributes.end() != mAttributes.find(L"display"))
wsDisplay = mAttributes.at(L"display");
if (mAttributes.end() != mAttributes.find(L"visibility"))
wsVisibility = mAttributes.at(L"visibility");
if (L"none" == wsDisplay || L"hidden" == wsVisibility || L"collapse" == wsVisibility)
m_oStyles.m_bDraw = false;
else
m_oStyles.m_bDisplay = true;
m_oStyles.m_bDraw = true;
}
bool CRenderedObject::StartPath(IRenderer *pRenderer, const CSvgFile *pFile, Aggplus::CMatrix &oOldTransform, CommandeMode oMode) const
{
if (NULL == pRenderer || !m_oStyles.m_bDisplay)
if (NULL == pRenderer || !m_oStyles.m_bDraw)
return false;
Apply(pRenderer, &m_oStyles.m_oTransform, oOldTransform);
@ -243,6 +283,9 @@ namespace SVG
pRenderer->SetTransform(oOldTransform.sx(), oOldTransform.shy(), oOldTransform.shx(), oOldTransform.sy(), oOldTransform.tx(), oOldTransform.ty());
}
void CRenderedObject::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
{}
bool CRenderedObject::Apply(IRenderer *pRenderer, const TStroke *pStroke, bool bUseDefault) const
{
if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))

View File

@ -18,42 +18,9 @@ namespace SVG
SvgTransform m_oTransform;
TClip m_oClip;
SvgColor m_oMask;
bool m_bDisplay;
bool m_bDraw;
TSvgStyles& operator+=(const TSvgStyles& oSvgStyles)
{
m_oTransform.SetMatrix(oSvgStyles.m_oTransform.GetMatrix().ToWString(), 0, false);
if (!oSvgStyles.m_oFill.Empty())
m_oFill.SetValue(L'#' + oSvgStyles.m_oFill.ToWString(), 0, false);
m_oFill.SetOpacity(std::to_wstring(oSvgStyles.m_oFill.GetOpacity()), 0, false);
if (!oSvgStyles.m_oStroke.m_oColor.Empty())
m_oStroke.m_oColor.SetValue(L'#' + oSvgStyles.m_oStroke.m_oColor.ToWString(), 0, false);
m_oStroke.m_oWidth.SetValue(oSvgStyles.m_oStroke.m_oWidth.ToWString(), 0, false);
if (m_oStroke.m_arDash.empty() && !oSvgStyles.m_oStroke.m_arDash.empty())
m_oStroke.m_arDash = oSvgStyles.m_oStroke.m_arDash;
if (m_oStroke.m_oLineCap.Empty() && !oSvgStyles.m_oStroke.m_oLineCap.Empty())
m_oStroke.m_oLineCap = oSvgStyles.m_oStroke.m_oLineCap;
if (m_oStroke.m_oLineJoin.Empty() && !oSvgStyles.m_oStroke.m_oLineJoin.Empty())
m_oStroke.m_oLineJoin = oSvgStyles.m_oStroke.m_oLineJoin;
if (m_oClip.m_oHref.Empty() && !oSvgStyles.m_oClip.m_oHref.Empty())
m_oClip.m_oHref = oSvgStyles.m_oClip.m_oHref;
if (m_oClip.m_oRule.Empty() && !oSvgStyles.m_oClip.m_oRule.Empty())
m_oClip.m_oRule = oSvgStyles.m_oClip.m_oRule;
if (m_oMask.Empty() && !oSvgStyles.m_oMask.Empty() && NSCSS::NSProperties::ColorUrl == oSvgStyles.m_oMask.GetType())
m_oMask= oSvgStyles.m_oMask;
return *this;
}
TSvgStyles& operator+=(const TSvgStyles& oSvgStyles);
};
enum ObjectType
@ -132,7 +99,7 @@ namespace SVG
bool StartPath(IRenderer* pRenderer, const CSvgFile *pFile, Aggplus::CMatrix& oOldTransform, CommandeMode oMode = CommandeModeDraw) const;
void EndPath(IRenderer* pRenderer, const CSvgFile *pFile, const Aggplus::CMatrix& oOldTransform, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const;
virtual void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile *pFile, int& nTypePath) const = 0;
virtual void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile *pFile, int& nTypePath) const;
bool Apply(IRenderer* pRenderer, const TStroke* pStroke, bool bUseDefault = false) const;
bool Apply(IRenderer* pRenderer, const SvgColor* pFill, const CSvgFile *pFile, bool bUseDefault = false) const;

View File

@ -8,6 +8,10 @@
namespace SVG
{
IPathElement::~IPathElement()
{
}
#define ISPATHCOMMAND(wchar) L'M' == wchar || L'm' == wchar || L'Z' == wchar || L'z' == wchar || L'L' == wchar || L'l' == wchar || L'H' == wchar || L'h' == wchar || L'V' == wchar || L'v' == wchar || L'C' == wchar || L'c' == wchar || L'S' == wchar || L's' == wchar || L'Q' == wchar || L'q' == wchar || L'T' == wchar || L't' == wchar || L'A' == wchar || L'a' == wchar
// IpathElement
TBounds IPathElement::GetBounds() const
@ -39,6 +43,10 @@ namespace SVG
m_arPoints.push_back(oPoint);
}
CMoveElement::~CMoveElement()
{
}
EPathElement CMoveElement::GetType() const
{
return EPathElement::Move;
@ -150,6 +158,9 @@ namespace SVG
m_arPoints.push_back(oPoint2);
m_arPoints.push_back(oPointE);
}
CCBezierElement::~CCBezierElement()
{
}
EPathElement CCBezierElement::GetType() const
{
@ -386,6 +397,10 @@ namespace SVG
CCloseElement::CCloseElement()
{}
CCloseElement::~CCloseElement()
{
}
EPathElement CCloseElement::GetType() const
{
return EPathElement::Close;

View File

@ -30,6 +30,7 @@ namespace SVG
class IPathElement
{
public:
virtual ~IPathElement();
virtual EPathElement GetType() const = 0;
virtual void Draw(IRenderer* pRenderer) const = 0;
@ -56,6 +57,7 @@ namespace SVG
{
public:
CMoveElement(const Point& oPoint);
virtual ~CMoveElement();
EPathElement GetType() const override;
static CMoveElement* CreateFromArray(std::vector<double>& arValues, bool bRelativeCoordinate, IPathElement* pPrevElement = NULL);
void Draw(IRenderer* pRenderer) const override;
@ -77,6 +79,7 @@ namespace SVG
{
public:
CCBezierElement(const Point& oPoint1, const Point& oPoint2, const Point& oPointE, EPathElement enType = CBezier);
virtual ~CCBezierElement();
EPathElement GetType() const override;
static IPathElement* CreateFromArray(std::vector<double>& arValues, bool bRelativeCoordinate, IPathElement* pPrevElement = NULL);
static IPathElement* CreateFromSArray(std::vector<double>& arValues, bool bRelativeCoordinate, IPathElement* pPrevElement = NULL);
@ -94,6 +97,7 @@ namespace SVG
{
public:
CCloseElement();
virtual ~CCloseElement();
EPathElement GetType() const override;
void Draw(IRenderer* pRenderer) const override;
};

View File

@ -28,7 +28,7 @@ namespace SVG
void CSvgCalculator::SetData(CObject *pSvgObject) const
{
if (NULL == pSvgObject)
return;
return;
const std::map<std::wstring, NSCSS::CElement *> *pData = m_pInternal->GetData();
const std::vector<NSCSS::CNode> arSelectors = pSvgObject->GetFullPath();
@ -46,42 +46,21 @@ namespace SVG
{
arWords.push_back(oNode->m_wsName);
if (!oNode->m_wsClass.empty())
if (!oNode->m_wsClass.empty())
{
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
{
std::vector<std::wstring> arClasses = NSCSS::NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, L" ");
std::vector<std::wstring> arClasses = NSCSS::NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, L" ");
if (arClasses.size() > 1)
arClasses.resize(unique(arClasses.begin(),arClasses.end()) - arClasses.begin());
switch (arClasses.size())
{
case 1:
{
arWords.push_back(L'.' + arClasses[0]);
break;
}
case 2:
{
arWords.push_back(L'.' + arClasses[0] + L" ." + arClasses[1]);
break;
}
case 3:
{
arWords.push_back(L'.' + arClasses[0] + L" ." + arClasses[1] + L" ." + arClasses[2]);
break;
}
default:
{
arWords.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
break;
}
}
arWords.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
[](std::wstring sRes, const std::wstring& sClass)
{return sRes += L'.' + sClass + L' ';}));
}
else
arWords.push_back(L'.' + oNode->m_wsClass);
arWords.push_back(L'.' + oNode->m_wsClass);
}
if (!oNode->m_wsId.empty())
arWords.push_back(L'#' + oNode->m_wsId);
@ -173,10 +152,10 @@ namespace SVG
if (arFindElements.size() > 1)
{
std::sort(arFindElements.rbegin(), arFindElements.rend(),
[](NSCSS::CElement* oFirstElement, NSCSS::CElement* oSecondElement)
{
return oFirstElement->GetWeight() > oSecondElement->GetWeight();
});
[](NSCSS::CElement* oFirstElement, NSCSS::CElement* oSecondElement)
{
return oFirstElement->GetWeight() > oSecondElement->GetWeight();
});
}
pSvgObject->SetData(arSelectors[i].m_wsStyle, i + 1, true);

View File

@ -27,7 +27,7 @@ namespace SVG
bool CUse::Draw(IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles* pOtherStyles) const
{
if (NULL == pRenderer || !m_oStyles.m_bDisplay)
if (NULL == pRenderer || !m_oStyles.m_bDraw)
return false;
double dM11, dM12, dM21, dM22, dRx, dRy;
@ -53,9 +53,6 @@ namespace SVG
return true;
}
void CUse::ApplyStyle(IRenderer *pRenderer, const TSvgStyles *pStyles, const CSvgFile *pFile, int &nTypePath) const
{}
TBounds CUse::GetBounds() const
{
return TBounds{0., 0., 0., 0.};

View File

@ -16,8 +16,6 @@ namespace SVG
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;
CRenderedObject *m_pUsedObject;

View File

@ -24,6 +24,7 @@ namespace SVG
SvgColor m_oColor;
SvgDigit m_oWidth;
std::vector<double> m_arDash;
SvgDigit m_oDashOffset;
SvgEnum m_oLineCap;
SvgEnum m_oLineJoin;
SvgDigit m_oMiterlimit;

View File

@ -27,10 +27,9 @@ namespace SVG
UNDEFINED
};
class StrUtils
namespace StrUtils
{
public:
static inline std::vector<double> ReadDoubleValues(std::wstring::const_iterator oBegin, std::wstring::const_iterator oEnd)
inline std::vector<double> ReadDoubleValues(std::wstring::const_iterator oBegin, std::wstring::const_iterator oEnd)
{
std::vector<double> arValues;
@ -45,269 +44,12 @@ namespace SVG
return arValues;
}
static inline std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
inline std::vector<double> ReadDoubleValues(const std::wstring& wsValue)
{
return ReadDoubleValues(wsValue.begin(), wsValue.end());
}
static inline long LongValue(const std::wstring& value)
{
size_t len = value.length(); const wchar_t* buf = value.c_str();
if (0 == len) return 0;
for (size_t i = 0; i < len; ++i)
{
if (iswdigit(buf[i]) || (buf[i] == L'-') /* || (value[i] == L'.') || (value[i] == L',') */)
continue;
return std::stol(value.substr(0, i));
}
return std::stol(value);
}
static inline double DoubleValue(const std::wstring& value)
{
size_t len = value.length(); const wchar_t* buf = value.c_str();
if (0 == len) return 0;
for (size_t i = 0; i < len; ++i)
{
if (iswdigit(buf[i]) || (buf[i] == L'.') || (buf[i] == L',') || (buf[i] == L'-') || (buf[i] == 'e'))
continue;
return std::stol(value.substr(0, i));
}
bool bNeedZero = false;
bool bNeedMZero = false;
if(value.front() == L'-')
{
if(value.length() > 1)
if(value[1] == L'.')
bNeedMZero = true;
}
else if(value.front() == L'.')
bNeedZero = true;
return std::stod(bNeedZero ? L'0' + value : (bNeedMZero ? L"-0" + value.substr(1) : value));
}
static inline double DoubleValuePct(const std::wstring& sVal)
{
bool bNeedZero = false;
bool bNeedMZero = false;
if(!sVal.empty())
{
if(sVal.front() == L'-')
{
if(sVal.length() > 1)
if(sVal[1] == L'.')
bNeedMZero = true;
}
else if(sVal.front() == L'.')
bNeedZero = true;
if ('%' == sVal.back())
return std::stod(sVal.substr(0, sVal.length() - 1)) * 0.01;
}
else
return 0;
return std::stod(bNeedZero ? L'0' + sVal : (bNeedMZero ? L"-0" + sVal.substr(1) : sVal));
}
static bool DoubleValues(const std::wstring& SourceW, std::vector<double>& Values)
{
std::wstring number = L"";
size_t length = SourceW.length();
const wchar_t* Source = SourceW.c_str();
for (size_t i = 0; i < length; ++i)
{
if ('-' == Source[i])
{
if (i > 1)
{
if ('e' == Source[i - 1])
{
number += Source[i];
continue;
}
}
if (!number.empty())
Values.push_back(std::stod(number.front() == L'.' ? L'0' + number : number));
number = L"";
}
if (iswdigit(Source[i]) || (Source[i] == '.') || (Source[i] == '-') || (Source[i] == 'e'))
{
number += Source[i];
continue;
}
if (!number.empty())
{
bool bNeedZero = false;
bool bNeedMZero = false;
if(number.front() == L'-')
{
if(number.length() > 1)
if(number[1] == L'.')
bNeedMZero = true;
}
else if(number.front() == L'.')
bNeedZero = true;
Values.push_back(std::stod(bNeedZero ? L'0' + number : (bNeedMZero ? L"-0" + number.substr(1) : number)));
}
number = L"";
}
if (!number.empty())
Values.push_back(std::stod(number.front() == L'.' ? L'0' + number : number));
return (0 != Values.size());
}
static inline std::wstring RemoveSymbol(std::wstring& src, wchar_t symbol)
{
std::wstring result;
const wchar_t* buf = src.c_str();
size_t len = src.length();
for (size_t i = 0; i < len; i++)
{
wchar_t currentChar = buf[i];
if (currentChar != symbol)
result += currentChar;
}
src = result;
return result;
}
static inline std::wstring RemoveSpaces(std::wstring& src)
{
return RemoveSymbol(src, ' ');
}
static inline Metrics GetMetrics(const std::wstring& value ) // only for long numbers in value
{
const wchar_t* buf = value.c_str();
size_t len = value.length();
for (size_t i = 0; i < len; ++i)
{
if (isdigit(buf[i]) || (buf[i] == '.') || (buf[i] == ','))
continue;
std::wstring metrics = value.substr(i, len - i);
if (metrics.empty())
return PX;
if (metrics == L"px")
return PX;
if (metrics == L"mm")
return MM;
if (metrics == L"cm")
return CM;
if (metrics == L"%")
return PCT;
if (metrics == L"in")
return INCH;
if (metrics == L"em") // default - 16px
return EM;
if (metrics == L"pt")
return PT;
return UNDEFINED;
}
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)
{
std::wstring str = sUrlRef;
str = StrUtils::RemoveSpaces(str);
const wchar_t* buf = str.c_str();
if ((buf[0] == 'u') || (buf[1] == 'r') || (buf[2] == 'l'))
{
std::wstring::size_type Oct = str.find(L"#");
if (std::wstring::npos != Oct)
{
Oct += 1; // #
if (')' == str[str.length() - 1])
return str.substr(Oct, str.length() - Oct - 1);
return str.substr(Oct, str.length() - Oct);
}
}
}
return L"";
}
static inline bool UrlRefValue2(std::wstring& sUrlRef)
{
std::wstring sRet = StrUtils::UrlRefValue(sUrlRef);
if (!sRet.empty())
{
sUrlRef = sRet;
return true;
}
return false;
}
static inline int Decode16(wchar_t c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'A' && c <= 'F')
return 10 + c - 'A';
if (c >= 'a' && c <= 'f')
return 10 + c - 'a';
return 0;
}
static std::wstring UrlDecode(const std::wstring& Source)
{
std::wstring strDecoded;
const wchar_t* buf = Source.c_str();
size_t len = Source.length();
for ( size_t i = 0; i < len; ++i )
{
if ('%' == buf[i] && isxdigit(buf[i + 1]) && isxdigit(buf[i + 2]))
{
int byHex1 = Decode16(buf[i + 1]);
int byHex2 = Decode16(buf[i + 2]);
strDecoded += (wchar_t)(byHex1 * 16 + byHex2);
i += 2;
}
else
strDecoded += buf[i];
}
return strDecoded;
}
static std::wstring TrimExtraEnding(const std::wstring& wsString)
inline std::wstring TrimExtraEnding(const std::wstring& wsString)
{
std::wstring::const_iterator itBeginPos = std::find_if(wsString.begin(), wsString.end(), [](const wchar_t& wChar){ return !iswspace(wChar);});
std::wstring::const_reverse_iterator itEndPos = std::find_if(wsString.rbegin(), wsString.rend(), [](const wchar_t& wChar){ return !iswspace(wChar);});

View File

@ -38,7 +38,7 @@
#include <memory>
#ifdef _MSC_VER
#pragma warning (disable: 4100 4189)
#pragma warning (disable: 4100 4189)
#endif
#include "../../common/StringBuilder.h"
@ -52,13 +52,13 @@ namespace XmlUtils
class KERNEL_DECL CXmlWriter
{
private:
class Impl;
std::shared_ptr<Impl> impl_;
class Impl;
std::shared_ptr<Impl> impl_;
public:
CXmlWriter();
~CXmlWriter();
~CXmlWriter();
std::wstring GetXmlString();
void SetXmlString(const std::wstring& strValue);

View File

@ -34,122 +34,126 @@
namespace XmlUtils
{
class CXmlWriter::Impl
{
public:
std::wstring m_str;
};
class CXmlWriter::Impl
{
public:
NSStringUtils::CStringBuilder m_str;
};
CXmlWriter::CXmlWriter() : impl_(NULL)
{
impl_ = std::make_shared<CXmlWriter::Impl>();
}
CXmlWriter::~CXmlWriter()
{
}
CXmlWriter::CXmlWriter() : impl_(NULL)
{
impl_ = std::make_shared<CXmlWriter::Impl>();
}
CXmlWriter::~CXmlWriter()
{
}
std::wstring CXmlWriter::GetXmlString()
{
if (impl_) return impl_->m_str;
else return L"";
}
void CXmlWriter::SetXmlString(const std::wstring& strValue)
{
if (impl_) impl_->m_str = strValue;
}
std::wstring CXmlWriter::GetXmlString()
{
if (impl_) return impl_->m_str.GetData();
else return L"";
}
void CXmlWriter::SetXmlString(const std::wstring& strValue)
{
if (impl_)
{
impl_->m_str.Clear();
impl_->m_str.WriteString(strValue);
}
}
bool CXmlWriter::SaveToFile(const std::wstring& strFilePath/*, bool bEncodingToUTF8 = false*/)
{
if (impl_)
return NSFile::CFileBinary::SaveToFile(strFilePath, impl_->m_str);
else
return false;
}
void CXmlWriter::WriteString(const std::wstring& strValue)
{
if (impl_) impl_->m_str += strValue;
}
void CXmlWriter::WriteInteger(int Value)
{
if (impl_) impl_->m_str += std::to_wstring(Value);
}
void CXmlWriter::WriteDouble(double Value)
{
if (impl_) impl_->m_str += std::to_wstring(Value);
}
void CXmlWriter::WriteBoolean(bool Value)
{
if (!impl_) return;
bool CXmlWriter::SaveToFile(const std::wstring& strFilePath/*, bool bEncodingToUTF8 = false*/)
{
if (impl_)
return NSFile::CFileBinary::SaveToFile(strFilePath, impl_->m_str.GetData());
else
return false;
}
void CXmlWriter::WriteString(const std::wstring& strValue)
{
if (impl_) impl_->m_str += strValue;
}
void CXmlWriter::WriteInteger(int Value)
{
if (impl_) impl_->m_str += std::to_wstring(Value);
}
void CXmlWriter::WriteDouble(double Value)
{
if (impl_) impl_->m_str += std::to_wstring(Value);
}
void CXmlWriter::WriteBoolean(bool Value)
{
if (!impl_) return;
if (Value)
impl_->m_str += (L"true");
else
impl_->m_str += (L"false");
}
void CXmlWriter::WriteNodeBegin(const std::wstring& strNodeName, bool bAttributed)
{
if (!impl_) return;
if (Value)
impl_->m_str += (L"true");
else
impl_->m_str += (L"false");
}
void CXmlWriter::WriteNodeBegin(const std::wstring& strNodeName, bool bAttributed)
{
if (!impl_) return;
impl_->m_str += (L"<") + strNodeName;
impl_->m_str += (L"<") + strNodeName;
if (!bAttributed)
impl_->m_str += (L">");
}
void CXmlWriter::WriteNodeEnd(const std::wstring& strNodeName, bool bEmptyNode, bool bEndNode)
{
if (!impl_) return;
if (!bAttributed)
impl_->m_str += (L">");
}
void CXmlWriter::WriteNodeEnd(const std::wstring& strNodeName, bool bEmptyNode, bool bEndNode)
{
if (!impl_) return;
if (bEmptyNode)
{
if (bEndNode)
impl_->m_str += (L" />");
else
impl_->m_str += (L">");
}
else
impl_->m_str += (L"</") + strNodeName + (L">");
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, const std::wstring& strNodeValue)
{
if (!impl_) return;
if (bEmptyNode)
{
if (bEndNode)
impl_->m_str += (L" />");
else
impl_->m_str += (L">");
}
else
impl_->m_str += (L"</") + strNodeName + (L">");
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, const std::wstring& strNodeValue)
{
if (!impl_) return;
if (strNodeValue.empty())
impl_->m_str += L"<" + strNodeName + L"/>";
else
impl_->m_str += L"<" + strNodeName + L">" + strNodeValue + L"</" + strNodeName + L">";
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, int nValue, const std::wstring& strTextBeforeValue, const std::wstring& strTextAfterValue)
{
WriteNodeBegin(strNodeName);
WriteString(strTextBeforeValue);
WriteInteger(nValue);
WriteString(strTextAfterValue);
WriteNodeEnd(strNodeName);
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, double dValue)
{
WriteNodeBegin(strNodeName);
WriteDouble(dValue);
WriteNodeEnd(strNodeName);
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const std::wstring& strAttributeValue)
{
if (impl_) impl_->m_str += L" " + strAttributeName + L"=\"" + strAttributeValue + L"\"";
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, int nValue, const std::wstring& strTextBeforeValue, const std::wstring& strTextAfterValue)
{
WriteString(L" " + strAttributeName + L"=");
WriteString(L"\"");
WriteString(strTextBeforeValue);
WriteInteger(nValue);
WriteString(strTextAfterValue);
WriteString(L"\"");
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, double dValue)
{
WriteString(L" " + strAttributeName + L"=");
WriteString(L"\"");
WriteDouble(dValue);
WriteString(L"\"");
}
if (strNodeValue.empty())
impl_->m_str += L"<" + strNodeName + L"/>";
else
impl_->m_str += L"<" + strNodeName + L">" + strNodeValue + L"</" + strNodeName + L">";
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, int nValue, const std::wstring& strTextBeforeValue, const std::wstring& strTextAfterValue)
{
WriteNodeBegin(strNodeName);
WriteString(strTextBeforeValue);
WriteInteger(nValue);
WriteString(strTextAfterValue);
WriteNodeEnd(strNodeName);
}
void CXmlWriter::WriteNode(const std::wstring& strNodeName, double dValue)
{
WriteNodeBegin(strNodeName);
WriteDouble(dValue);
WriteNodeEnd(strNodeName);
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const std::wstring& strAttributeValue)
{
if (impl_) impl_->m_str += L" " + strAttributeName + L"=\"" + strAttributeValue + L"\"";
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, int nValue, const std::wstring& strTextBeforeValue, const std::wstring& strTextAfterValue)
{
WriteString(L" " + strAttributeName + L"=");
WriteString(L"\"");
WriteString(strTextBeforeValue);
WriteInteger(nValue);
WriteString(strTextAfterValue);
WriteString(L"\"");
}
void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, double dValue)
{
WriteString(L" " + strAttributeName + L"=");
WriteString(L"\"");
WriteDouble(dValue);
WriteString(L"\"");
}
}

View File

@ -1528,7 +1528,7 @@ std::wstring PPT::CShapeWriter::ConvertGroup()
double width = bChildAnchorEnabled ? pGroupElement->m_rcChildAnchor.GetWidth() : pGroupElement->m_rcAnchor.GetWidth();
double height = bChildAnchorEnabled ? pGroupElement->m_rcChildAnchor.GetHeight() : pGroupElement->m_rcAnchor.GetHeight();
if ( width > 0 || height > 0 )
if ( width > 0 && height > 0 )
{
m_oWriter.WriteString(L"<a:ext cx=\"" + std::to_wstring((int)width) + L"\" cy=\"" + std::to_wstring((int)height) + L"\"/>");
}
@ -1770,7 +1770,7 @@ std::wstring PPT::CShapeWriter::ConvertTable ()
double width = pGroupElement->m_bChildAnchorEnabled ? pGroupElement->m_rcChildAnchor.GetWidth() : pGroupElement->m_rcAnchor.GetWidth();
double height = pGroupElement->m_bChildAnchorEnabled ? pGroupElement->m_rcChildAnchor.GetHeight() : pGroupElement->m_rcAnchor.GetHeight();
if ( width > 0 || height > 0 )
if ( width > 0 && height > 0 )
{
m_oWriter.WriteString(L"<a:ext cx=\"" + std::to_wstring((int)width) + L"\" cy=\"" + std::to_wstring((int)height) + L"\"/>");
}
@ -1883,7 +1883,7 @@ std::wstring PPT::CShapeWriter::ConvertShape()
double width = pShapeElement->m_bChildAnchorEnabled ? pShapeElement->m_rcChildAnchor.GetWidth() : pShapeElement->m_rcAnchor.GetWidth();
double height = pShapeElement->m_bChildAnchorEnabled ? pShapeElement->m_rcChildAnchor.GetHeight() : pShapeElement->m_rcAnchor.GetHeight();
if ( width > 0 || height > 0 )
if ( width > 0 && height > 0 )
{
m_oWriter.WriteString(L"<a:ext cx=\"" + std::to_wstring((int)width) + L"\" cy=\"" + std::to_wstring((int)height) + L"\"/>");
}
@ -2135,7 +2135,7 @@ std::wstring PPT::CShapeWriter::ConvertImage()
_INT64 width = (_INT64)(pImageElement->m_bChildAnchorEnabled ? pImageElement->m_rcChildAnchor.GetWidth() : pImageElement->m_rcAnchor.GetWidth());
_INT64 height = (_INT64)(pImageElement->m_bChildAnchorEnabled ? pImageElement->m_rcChildAnchor.GetHeight() : pImageElement->m_rcAnchor.GetHeight());
if (( width > 0 || height > 0 ) && ((_UINT64)width) < 0xffffffffffff && ((_UINT64)height) < 0xffffffffffff)
if (( width > 0 && height > 0 ) && ((_UINT64)width) < 0xffffffffffff && ((_UINT64)height) < 0xffffffffffff)
{
m_oWriter.WriteString(L"<a:ext cx=\"" + std::to_wstring(width) + L"\" cy=\"" + std::to_wstring(height) + L"\"/>");
}

View File

@ -57,7 +57,7 @@ CRecordShapeProgBinaryTagSubContainerOrAtom *CRecordOfficeArtClientData::getProg
{
for (auto* progtag : m_rgShapeClientRoundtripData)
{
if (progtag->m_pTagName->m_strText == tagname)
if ((progtag->m_pTagName) && (progtag->m_pTagName->m_strText == tagname))
return progtag;
}

View File

@ -394,6 +394,8 @@
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\FRTSqref.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\FRTSqrefs.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\RelID.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxOs.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxSu.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\UncheckedSqRfX.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BiffString.cpp" />
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BiffStructure.cpp" />
@ -1202,6 +1204,8 @@
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\FRTSqref.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\FRTSqrefs.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\RelID.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxOs.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxSu.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\UncheckedSqRfX.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\XLWideString.h" />
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BiffAttribute.h" />

View File

@ -2434,6 +2434,12 @@
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\FRTParsedFormula.cpp">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClCompile>
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxOs.cpp">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClCompile>
<ClCompile Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxSu.cpp">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\XlsFile\Format\Logging\Log.h">
@ -4881,5 +4887,11 @@
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\CellRef.h">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClInclude>
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxOs.h">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClInclude>
<ClInclude Include="..\..\..\XlsFile\Format\Logic\Biff_structures\BIFF12\SxSu.h">
<Filter>Logic\Biff_structures\BIFF12</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -75,8 +75,10 @@ void ExternSheet::readFields(CFRecord& record)
{
_UINT16 cXTI_2b;
record >> cXTI_2b;
for(int i = 0; i < cXTI_2b; ++i)
for(_UINT16 i = 0; i < cXTI_2b; ++i)
{
if (record.getRdPtr() + 6 > record.getDataSize())
break;
XTIPtr xti(new XTI);
record >> *xti;
rgXTI.push_back(xti);
@ -86,7 +88,7 @@ void ExternSheet::readFields(CFRecord& record)
else
{
record >> cXTI;
for(int i = 0; i < cXTI; ++i)
for(_UINT32 i = 0; i < cXTI; ++i)
{
XTIPtr xti(new XTI);
record >> *xti;

View File

@ -32,9 +32,9 @@
#pragma once
#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_structures/BiffStructure.h"
#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/BiffRecord.h"
#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_structures/BiffString.h"
#include "../BiffStructure.h"
#include "../../Biff_records/BiffRecord.h"
#include "../BiffString.h"
namespace XLSB

View File

@ -32,8 +32,8 @@
#pragma once
#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_structures/BiffStructure.h"
#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/BiffRecord.h"
#include "../BiffStructure.h"
#include "../../Biff_records/BiffRecord.h"
#include "SxOs.h"

View File

@ -34,7 +34,7 @@
#include "Ptg.h"
#include "CellRangeRef.h"
#include "Boolean.h"
#include "../../../../../OOXML/XlsbFormat/Biff12_structures/SxSu.h"
#include "BIFF12/SxSu.h"
namespace XLS
{

View File

@ -663,6 +663,8 @@
#include "../Biff_structures/BIFF12/FRTSqrefs.cpp"
#include "../Biff_structures/BIFF12/RelID.cpp"
#include "../Biff_structures/BIFF12/UncheckedSqRfX.cpp"
#include "../Biff_structures/BIFF12/SxOs.cpp"
#include "../Biff_structures/BIFF12/SxSu.cpp"
#include "../Biff_unions/AI.cpp"
#include "../Biff_unions/ATTACHEDLABEL_bu.cpp"

View File

@ -642,6 +642,8 @@ SOURCES += \
$$LOGIC_DIR/Biff_structures/BIFF12/FRTSqrefs.cpp \
$$LOGIC_DIR/Biff_structures/BIFF12/RelID.cpp \
$$LOGIC_DIR/Biff_structures/BIFF12/UncheckedSqRfX.cpp \
$$LOGIC_DIR/Biff_structures/BIFF12/SxOs.cpp \
$$LOGIC_DIR/Biff_structures/BIFF12/SxSu.cpp \
\
$$LOGIC_DIR/Biff_unions/AI.cpp \
$$LOGIC_DIR/Biff_unions/ATTACHEDLABEL_bu.cpp \
@ -1128,6 +1130,8 @@ HEADERS += \
$$LOGIC_DIR/Biff_structures/BIFF12/RelID.h \
$$LOGIC_DIR/Biff_structures/BIFF12/UncheckedSqRfX.h \
$$LOGIC_DIR/Biff_structures/BIFF12/XLWideString.h \
$$LOGIC_DIR/Biff_structures/BIFF12/SxOs.h \
$$LOGIC_DIR/Biff_structures/BIFF12/SxSu.h \
$$LOGIC_DIR/Biff_structures/AddinUdf.h \
$$LOGIC_DIR/Biff_structures/AF12Criteria.h \
$$LOGIC_DIR/Biff_structures/AF12CellIcon.h \

View File

@ -694,8 +694,6 @@ SOURCES += \
../../../XlsbFormat/Biff12_structures/BookProtectionFlags.cpp \
../../../XlsbFormat/Biff12_structures/Cell.cpp \
../../../XlsbFormat/Biff12_structures/GrbitFmla.cpp \
../../../XlsbFormat/Biff12_structures/SxOs.cpp \
../../../XlsbFormat/Biff12_structures/SxSu.cpp \
../../../XlsbFormat/Biff12_structures/CFType.cpp \
../../../XlsbFormat/Biff12_structures/CFTemp.cpp \
../../../XlsbFormat/Biff12_structures/CFOper.cpp \
@ -1142,7 +1140,6 @@ HEADERS += \
../../../XlsbFormat/Biff12_records/CalcProp.h \
../../../XlsbFormat/Biff12_records/Cell.h \
../../../XlsbFormat/Biff12_records/CellMeta.h \
../../../XlsbFormat/Biff12_records/Color.h \
../../../XlsbFormat/Biff12_records/Color14.h \
../../../XlsbFormat/Biff12_records/CommentAuthor.h \
../../../XlsbFormat/Biff12_records/CommentText.h \
@ -1727,37 +1724,19 @@ HEADERS += \
../../../XlsbFormat/Biff12_structures/CFVOType14.h \
../../../XlsbFormat/Biff12_structures/CFVOtype.h \
../../../XlsbFormat/Biff12_structures/Cell.h \
../../../XlsbFormat/Biff12_structures/CellRangeRef.h \
../../../XlsbFormat/Biff12_structures/CellRef.h \
../../../XlsbFormat/Biff12_structures/CodeName.h \
../../../XlsbFormat/Biff12_structures/ColSpan.h \
../../../XlsbFormat/Biff12_structures/FRTBlank.h \
../../../XlsbFormat/Biff12_structures/FRTFormula.h \
../../../XlsbFormat/Biff12_structures/FRTFormulas.h \
../../../XlsbFormat/Biff12_structures/FRTHeader.h \
../../../XlsbFormat/Biff12_structures/FRTParsedFormula.h \
../../../XlsbFormat/Biff12_structures/FRTProductVersion.h \
../../../XlsbFormat/Biff12_structures/FRTRef.h \
../../../XlsbFormat/Biff12_structures/FRTRefs.h \
../../../XlsbFormat/Biff12_structures/FRTRelID.h \
../../../XlsbFormat/Biff12_structures/FRTSqref.h \
../../../XlsbFormat/Biff12_structures/FRTSqrefs.h \
../../../XlsbFormat/Biff12_structures/GradientStop.h \
../../../XlsbFormat/Biff12_structures/GrbitFmla.h \
../../../XlsbFormat/Biff12_structures/IsoPasswordData.h \
../../../XlsbFormat/Biff12_structures/LPByteBuf.h \
../../../XlsbFormat/Biff12_structures/PhRun.h \
../../../XlsbFormat/Biff12_structures/RelID.h \
../../../XlsbFormat/Biff12_structures/RichStr.h \
../../../XlsbFormat/Biff12_structures/StrRun.h \
../../../XlsbFormat/Biff12_structures/SxOs.h \
../../../XlsbFormat/Biff12_structures/SxSu.h \
../../../XlsbFormat/Biff12_structures/UncheckedSqRfX.h \
../../../XlsbFormat/Biff12_structures/XLWideString.h \
../../../XlsbFormat/Biff12_structures/ListType.h \
../../../XlsbFormat/Biff12_structures/XmlDataType.h \
../../../XlsbFormat/Biff12_structures/ListTotalRowFunction.h \
../../../XlsbFormat/Biff12_structures/DValStrings.h \
../../../XlsbFormat/Biff12_structures/DBType.h \
../../../XlsbFormat/Biff12_structures/CmdType.h \
../../../XlsbFormat/Biff12_structures/PCDISrvFmt.h \

View File

@ -687,8 +687,6 @@
#include "../../../XlsbFormat/Biff12_structures/BookProtectionFlags.cpp"
#include "../../../XlsbFormat/Biff12_structures/Cell.cpp"
#include "../../../XlsbFormat/Biff12_structures/GrbitFmla.cpp"
#include "../../../XlsbFormat/Biff12_structures/SxOs.cpp"
#include "../../../XlsbFormat/Biff12_structures/SxSu.cpp"
#include "../../../XlsbFormat/Biff12_structures/CFType.cpp"
#include "../../../XlsbFormat/Biff12_structures/CFTemp.cpp"
#include "../../../XlsbFormat/Biff12_structures/CFOper.cpp"

View File

@ -701,8 +701,6 @@
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\StrRun.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SXET.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SXMA.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SxOs.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SxSu.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\Tws.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\XmlDataType.cpp" />
<ClCompile Include="..\..\..\XlsbFormat\Biff12_unions\ACABSPATH.cpp" />
@ -1724,8 +1722,6 @@
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\StrRun.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SXET.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SXMA.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SxOs.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SxSu.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\Tws.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\XmlDataType.h" />
<ClInclude Include="..\..\..\XlsbFormat\Biff12_unions\ACABSPATH.h" />

View File

@ -2058,12 +2058,6 @@
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SXMA.cpp">
<Filter>structures</Filter>
</ClCompile>
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SxOs.cpp">
<Filter>structures</Filter>
</ClCompile>
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\SxSu.cpp">
<Filter>structures</Filter>
</ClCompile>
<ClCompile Include="..\..\..\XlsbFormat\Biff12_structures\Tws.cpp">
<Filter>structures</Filter>
</ClCompile>
@ -5091,12 +5085,6 @@
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SXMA.h">
<Filter>structures</Filter>
</ClInclude>
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SxOs.h">
<Filter>structures</Filter>
</ClInclude>
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\SxSu.h">
<Filter>structures</Filter>
</ClInclude>
<ClInclude Include="..\..\..\XlsbFormat\Biff12_structures\Tws.h">
<Filter>structures</Filter>
</ClInclude>

View File

@ -97,12 +97,15 @@ border_style& border_style::operator =(const border_style& Value)
}
border_style::border_style(const std::wstring & Value) : initialized_(false), none_(false)
{
if (Value.empty()) return;
std::wstring tmp = boost::algorithm::trim_copy(Value);
boost::algorithm::to_lower(tmp);
if (L"none" == tmp || tmp.length() < 1)
if (L"none" == tmp/* || tmp.length() < 1*/)
{
none_ = true;
style_ = none;
}
else
{
@ -139,7 +142,6 @@ border_style::border_style(const std::wstring & Value) : initialized_(false), no
border_style border_style::parse( const std::wstring & Value)
{
return border_style(Value);
}
border_style::border_style(const color & color_, const type & style_, const length & length_)

View File

@ -227,9 +227,10 @@ unsigned int pptx_table_state::current_rows_spanned(unsigned int Column) const
struct pptx_border_edge
{
bool present;
bool present = false;
bool none = false;
std::wstring color;
int width;
int width = 0;
std::wstring cmpd;
std::wstring prstDash;
};
@ -241,11 +242,13 @@ void convert_border_style(const odf_types::border_style& borderStyle, pptx_borde
if (borderStyle.initialized())
{
if (borderStyle.is_none()) border.present = false;
border.present = true;
if (borderStyle.is_none()) border.none = true;
switch(borderStyle.get_style())
{
case odf_types::border_style::none: border.present = false; break;
case odf_types::border_style::none: border.none = true; break;
case odf_types::border_style::double_: border.cmpd = L"dbl"; break;
case odf_types::border_style::dotted: border.prstDash = L"dot"; break;
case odf_types::border_style::dashed: border.prstDash = L"dash"; break;
@ -279,23 +282,30 @@ void oox_serialize_border(std::wostream & strm, std::wstring Node, pptx_border_e
if (content.present == false) return;
CP_XML_WRITER(strm)
{
{
CP_XML_NODE(Node)
{
CP_XML_ATTR(L"w", content.width);
//CP_XML_ATTR(L"cap", L"flat");
CP_XML_ATTR(L"cmpd", content.cmpd);
//CP_XML_ATTR(L"algn", L"ctr");
CP_XML_NODE(L"a:solidFill")
{
if (content.none)
{
_CP_OPT(double) opacity;
oox_serialize_srgb(CP_XML_STREAM(),content.color,opacity);
CP_XML_NODE(L"a:noFill") {}
}
CP_XML_NODE(L"a:prstDash")
else
{
CP_XML_ATTR(L"val", content.prstDash);
CP_XML_ATTR(L"w", content.width);
//CP_XML_ATTR(L"cap", L"flat");
CP_XML_ATTR(L"cmpd", content.cmpd);
//CP_XML_ATTR(L"algn", L"ctr");
CP_XML_NODE(L"a:solidFill")
{
_CP_OPT(double) opacity;
oox_serialize_srgb(CP_XML_STREAM(), content.color, opacity);
}
CP_XML_NODE(L"a:prstDash")
{
CP_XML_ATTR(L"val", content.prstDash);
}
}
}
}

View File

@ -333,25 +333,25 @@ void table_table_cell::pptx_convert(oox::pptx_conversion_context & Context)
style_name = Context.get_table_context().get_default_cell_style();
if (!style_name.empty())
{
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell, false);
if (style_inst) style_instances.push_back(style_inst);
}
style_name = Context.get_table_context().get_default_cell_style_col(Context.get_table_context().current_column());
if (!style_name.empty())
{
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell, false);
if (style_inst)style_instances.push_back(style_inst);
}
style_name = Context.get_table_context().get_default_cell_style_row();
if (!style_name.empty())
{
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell, false);
if (style_inst) style_instances.push_back(style_inst);
}
style_name = attlist_.table_style_name_.get_value_or(L"");
if (!style_name.empty())
{
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell, false);
if (style_inst) style_instances.push_back(style_inst);
}
@ -379,8 +379,8 @@ void table_table_cell::pptx_convert(oox::pptx_conversion_context & Context)
bool presentText = content_.pptx_convert(Context);
std::wstring cellContent = Context.get_text_context().end_object();
if (cellContent.length()>0)
if (false == cellContent.empty())
{
CP_XML_NODE(L"a:txBody")
{
@ -392,7 +392,6 @@ void table_table_cell::pptx_convert(oox::pptx_conversion_context & Context)
CP_XML_STREAM() << emptyParTable;
oox_serialize_tcPr(CP_XML_STREAM(), style_instances, Context);
}
Context.get_table_context().end_cell();

View File

@ -89,6 +89,10 @@ bool CFormatsList::IsPdf(const std::wstring& ext) const
{
return ext == m_pdf;
}
bool CFormatsList::IsAny(const std::wstring& ext) const
{
return IsDocument(ext) || IsPresentation(ext) || IsSpreadsheet(ext) || IsCrossplatform(ext) || IsImage(ext) || IsPdf(ext);
}
void CFormatsList::AddDocument(const std::wstring& ext)
{
@ -199,8 +203,8 @@ CFormatsList CFormatsList::GetDefaultExts()
list.m_crossplatform.push_back(L"djvu");
list.m_crossplatform.push_back(L"xps");
list.m_images.push_back(L"jpg");
list.m_images.push_back(L"png");
// list.m_images.push_back(L"jpg");
// list.m_images.push_back(L"png");
list.m_pdf = L"pdf";
@ -494,20 +498,27 @@ void Cx2tTester::Start()
m_outputDirectory = m_troughConversionDirectory;
m_outputExts = {L"doct", L"xlst", L"pptt"};
Convert(files, true);
Convert(files, true, true);
m_outputDirectory = copy_outputDirectory;
m_inputExts = m_outputExts;
m_outputExts = copy_outputExts;
m_inputDirectory = m_troughConversionDirectory;
m_inputDirectory = m_troughConversionDirectory;
files = NSDirectory::GetFiles(m_troughConversionDirectory, true);
}
Convert(files);
WriteTime();
for(auto&& val : m_deleteLaterFiles)
NSFile::CFileBinary::Remove(val);
for(auto&& val : m_deleteLaterDirectories)
NSDirectory::DeleteDirectory(val);
}
void Cx2tTester::Convert(const std::vector<std::wstring>& files, bool bNoDirectory)
void Cx2tTester::Convert(const std::vector<std::wstring>& files, bool bNoDirectory, bool bTrough)
{
for(int i = 0; i < files.size(); i++)
{
@ -544,7 +555,9 @@ void Cx2tTester::Convert(const std::vector<std::wstring>& files, bool bNoDirecto
// all formats -> pdf
|| m_outputFormatsList.IsPdf(ext))
// input format != output format
&& ext != input_ext)
&& ext != input_ext
// any good input ext
&& m_inputFormatsList.IsAny(input_ext))
{
output_file_exts.push_back(ext);
}
@ -617,6 +630,7 @@ void Cx2tTester::Convert(const std::vector<std::wstring>& files, bool bNoDirecto
converter->SetX2tPath(m_x2tPath);
converter->SetErrorsOnly(m_bIsErrorsOnly);
converter->SetDeleteOk(m_bIsDeleteOk);
converter->SetTrough(bTrough);
converter->SetXmlErrorsDirectory(m_errorsXmlDirectory);
converter->SetCsvTxtEncoding(csvTxtEncoding);
converter->SetCsvDelimiter(csvDelimiter);
@ -682,6 +696,15 @@ void Cx2tTester::WriteTime()
m_reportStream.WriteStringUTF8(L"Time: " + std::to_wstring(time));
}
void Cx2tTester::AddDeleteLaterFile(const std::wstring& file)
{
m_deleteLaterFiles.push_back(file);
}
void Cx2tTester::AddDeleteLaterDirectory(const std::wstring& directory)
{
m_deleteLaterDirectories.push_back(directory);
}
bool Cx2tTester::IsAllBusy()
{
CTemporaryCS CS(&m_coresCS);
@ -758,6 +781,10 @@ void CConverter::SetDeleteOk(bool bIsDeleteOk)
{
m_bIsDeleteOk = bIsDeleteOk;
}
void CConverter::SetTrough(bool bIsTrough)
{
m_bIsTrough = bIsTrough;
}
void CConverter::SetXmlErrorsDirectory(const std::wstring& errorsXmlDirectory)
{
m_errorsXmlDirectory = errorsXmlDirectory;
@ -1015,15 +1042,25 @@ DWORD CConverter::ThreadProc()
if(m_bIsDeleteOk && ok)
{
if(output_format & AVS_OFFICESTUDIO_FILE_IMAGE)
NSDirectory::DeleteDirectory(output_file);
if(m_bIsTrough)
{
if(output_format & AVS_OFFICESTUDIO_FILE_IMAGE)
m_internal->AddDeleteLaterDirectory(output_file);
else
m_internal->AddDeleteLaterFile(output_file);
}
else
NSFile::CFileBinary::Remove(output_file);
{
if(output_format & AVS_OFFICESTUDIO_FILE_IMAGE)
NSDirectory::DeleteDirectory(output_file);
else
NSFile::CFileBinary::Remove(output_file);
}
}
}
m_internal->WriteReports(reports);
if(m_bIsDeleteOk && is_all_ok)
if(m_bIsDeleteOk && is_all_ok && !m_bIsTrough)
NSDirectory::DeleteDirectory(m_outputFilesDirectory);
CTemporaryCS CS(&m_internal->m_coresCS);

View File

@ -41,6 +41,7 @@ public:
bool IsCrossplatform(const std::wstring& ext) const;
bool IsImage(const std::wstring& ext) const;
bool IsPdf(const std::wstring& ext) const;
bool IsAny(const std::wstring& ext) const;
void AddDocument(const std::wstring& ext);
void AddPresentation(const std::wstring& ext);
@ -93,6 +94,9 @@ public:
void WriteReports(const std::vector<Report>& reports);
void WriteTime();
void AddDeleteLaterFile(const std::wstring& file);
void AddDeleteLaterDirectory(const std::wstring& directory);
bool IsAllBusy();
bool IsAllFree();
@ -106,7 +110,7 @@ public:
private:
// parse string like "docx txt" into vector
std::vector<std::wstring> ParseExtensionsString(std::wstring extensions, const CFormatsList& fl);
void Convert(const std::vector<std::wstring>& files, bool bNoDirectory = false);
void Convert(const std::vector<std::wstring>& files, bool bNoDirectory = false, bool bTrough = false);
// takes from config
std::wstring m_reportFile;
@ -149,6 +153,9 @@ private:
// format -> *t format -> all formats
bool m_bTroughConversion;
std::vector<std::wstring> m_deleteLaterFiles;
std::vector<std::wstring> m_deleteLaterDirectories;
};
// generates temp xml, convert, calls m_internal->writeReport
@ -166,6 +173,7 @@ public:
void SetX2tPath(const std::wstring& x2tPath);
void SetErrorsOnly(bool bIsErrorsOnly);
void SetDeleteOk(bool bIsDeleteOk);
void SetTrough(bool bIsTrough);
void SetXmlErrorsDirectory(const std::wstring& errorsXmlDirectory);
void SetCsvTxtEncoding(int csvTxtEncoding);
void SetCsvDelimiter(const std::wstring& csvDelimiter);
@ -195,6 +203,7 @@ private:
bool m_bIsErrorsOnly;
bool m_bIsDeleteOk;
bool m_bIsTrough;
int m_totalFiles;
int m_currFile;