diff --git a/HtmlRenderer/htmlrenderer.pro b/HtmlRenderer/htmlrenderer.pro
index 0431454987..a666f792f4 100644
--- a/HtmlRenderer/htmlrenderer.pro
+++ b/HtmlRenderer/htmlrenderer.pro
@@ -119,7 +119,8 @@ HEADERS += \
src/VectorGraphicsWriter2.h \
src/VMLWriter.h \
src/Writer.h \
- include/HTMLRenderer3.h
+ include/HTMLRenderer3.h \
+ src/Common2.h
unix {
target.path = /usr/lib
diff --git a/HtmlRenderer/include/ASCSVGWriter.h b/HtmlRenderer/include/ASCSVGWriter.h
new file mode 100644
index 0000000000..44370e1cb3
--- /dev/null
+++ b/HtmlRenderer/include/ASCSVGWriter.h
@@ -0,0 +1,206 @@
+#ifndef _ASC_HTMLRENDERER_SVG_WRITER_H_
+#define _ASC_HTMLRENDERER_SVG_WRITER_H_
+
+#include "../../DesktopEditor/graphics/IRenderer.h"
+
+namespace Aggplus
+{
+ class CMatrix;
+ class CGraphicsPathSimpleConverter;
+}
+class CFontManager;
+namespace NSHtmlRenderer
+{
+ class CSVGGraphicsWriter;
+}
+namespace NSStructures
+{
+ class CPen;
+ class CBrush;
+ class CFont;
+}
+namespace NSHtmlRenderer
+{
+ class CASCSVGWriter : public IRenderer
+ {
+ public:
+ CASCSVGWriter();
+ ~CASCSVGWriter();
+
+ public:
+ // тип рендерера-----------------------------------------------------------------------------
+ HRESULT get_Type(LONG* lType);
+ //-------- Функции для работы со страницей --------------------------------------------------
+ HRESULT NewPage();
+ HRESULT get_Height(double* dHeight);
+ HRESULT put_Height(const double& dHeight);
+ HRESULT get_Width(double* dWidth);
+ HRESULT put_Width(const double& dWidth);
+ HRESULT get_DpiX(double* dDpiX);
+ HRESULT get_DpiY(double* dDpiY);
+
+ // pen --------------------------------------------------------------------------------------
+ HRESULT get_PenColor(LONG* lColor);
+ HRESULT put_PenColor(const LONG& lColor);
+ HRESULT get_PenAlpha(LONG* lAlpha);
+ HRESULT put_PenAlpha(const LONG& lAlpha);
+ HRESULT get_PenSize(double* dSize);
+ HRESULT put_PenSize(const double& dSize);
+ HRESULT get_PenDashStyle(BYTE* val);
+ HRESULT put_PenDashStyle(const BYTE& val);
+ HRESULT get_PenLineStartCap(BYTE* val);
+ HRESULT put_PenLineStartCap(const BYTE& val);
+ HRESULT get_PenLineEndCap(BYTE* val);
+ HRESULT put_PenLineEndCap(const BYTE& val);
+ HRESULT get_PenLineJoin(BYTE* val);
+ HRESULT put_PenLineJoin(const BYTE& val);
+ HRESULT get_PenDashOffset(double* dOffset);
+ HRESULT put_PenDashOffset(const double& dOffset);
+ HRESULT get_PenAlign(LONG* lAlign);
+ HRESULT put_PenAlign(const LONG& lAlign);
+ HRESULT get_PenMiterLimit(double* dOffset);
+ HRESULT put_PenMiterLimit(const double& dOffset);
+ HRESULT PenDashPattern(double* pPattern, LONG lCount);
+
+ // brush ------------------------------------------------------------------------------------
+ HRESULT get_BrushType(LONG* lType);
+ HRESULT put_BrushType(const LONG& lType);
+ HRESULT get_BrushColor1(LONG* lColor);
+ HRESULT put_BrushColor1(const LONG& lColor);
+ HRESULT get_BrushAlpha1(LONG* lAlpha);
+ HRESULT put_BrushAlpha1(const LONG& lAlpha);
+ HRESULT get_BrushColor2(LONG* lColor);
+ HRESULT put_BrushColor2(const LONG& lColor);
+ HRESULT get_BrushAlpha2(LONG* lAlpha);
+ HRESULT put_BrushAlpha2(const LONG& lAlpha);
+ HRESULT get_BrushTexturePath(std::wstring* bsPath);
+ HRESULT put_BrushTexturePath(const std::wstring& bsPath);
+ HRESULT get_BrushTextureMode(LONG* lMode);
+ HRESULT put_BrushTextureMode(const LONG& lMode);
+ HRESULT get_BrushTextureAlpha(LONG* lTxAlpha);
+ HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha);
+ HRESULT get_BrushLinearAngle(double* dAngle);
+ HRESULT put_BrushLinearAngle(const double& dAngle);
+ HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height);
+ HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height);
+
+ HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount);
+
+ // font -------------------------------------------------------------------------------------
+ HRESULT get_FontName(std::wstring* bsName);
+ HRESULT put_FontName(const std::wstring& bsName);
+ HRESULT get_FontPath(std::wstring* bsName);
+ HRESULT put_FontPath(const std::wstring& bsName);
+ HRESULT get_FontSize(double* dSize);
+ HRESULT put_FontSize(const double& dSize);
+ HRESULT get_FontStyle(LONG* lStyle) ;
+ HRESULT put_FontStyle(const LONG& lStyle);
+ HRESULT get_FontStringGID(INT* bGID);
+ HRESULT put_FontStringGID(const INT& bGID);
+ HRESULT get_FontCharSpace(double* dSpace);
+ HRESULT put_FontCharSpace(const double& dSpace);
+ HRESULT get_FontFaceIndex(int* lFaceIndex);
+ HRESULT put_FontFaceIndex(const int& lFaceIndex);
+
+ //-------- Функции для вывода текста --------------------------------------------------------
+ HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h);
+ HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h);
+
+ HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h);
+ HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h);
+
+ //-------- Маркеры для команд ---------------------------------------------------------------
+ HRESULT BeginCommand(const DWORD& lType);
+ HRESULT EndCommand(const DWORD& lType);
+
+ //-------- Функции для работы с Graphics Path -----------------------------------------------
+ HRESULT PathCommandMoveTo(const double& x, const double& y);
+ HRESULT PathCommandLineTo(const double& x, const double& y);
+ HRESULT PathCommandLinesTo(double* points, const int& count);
+ HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3);
+ HRESULT PathCommandCurvesTo(double* points, const int& count);
+ HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle);
+ HRESULT PathCommandClose();
+ HRESULT PathCommandEnd();
+ HRESULT DrawPath(const LONG& nType);
+ HRESULT PathCommandStart();
+ HRESULT PathCommandGetCurrentPoint(double* x, double* y);
+
+ HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h);
+ HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h);
+
+ HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h);
+ HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h);
+
+ //-------- Функции для вывода изображений ---------------------------------------------------
+ HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h);
+ HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha);
+
+ // transform --------------------------------------------------------------------------------
+ HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6);
+ HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF);
+ HRESULT ResetTransform();
+
+ // -----------------------------------------------------------------------------------------
+ HRESULT get_ClipMode(LONG* plMode);
+ HRESULT put_ClipMode(const LONG& lMode);
+ // additiaonal params ----------------------------------------------------------------------
+ HRESULT SaveFile(const std::wstring& strFileSave);
+ HRESULT ReInit();
+ HRESULT IsRaster(bool* bVal);
+ // additiaonal params ----------------------------------------------------------------------
+ HRESULT CommandLong(const LONG& lType, const LONG& lCommand);
+ HRESULT CommandDouble(const LONG& lType, const double& dCommand);
+ HRESULT CommandString(const LONG& lType, const std::wstring& sCommand);
+ public:
+
+ void OnBaseMatrixUpdate(const double& dWidth, const double& dHeight);
+ void SetFontManager(CFontManager* pFontManager);
+
+ private:
+
+ NSHtmlRenderer::CSVGGraphicsWriter* m_pVectorWriter;
+
+ Aggplus::CGraphicsPathSimpleConverter* m_pSimpleGraphicsConverter; // конвертер сложных гафических путей в простые
+ CFontManager* m_pFontManager; // менеджер шрифтов
+ bool m_bDeleteFontManager;
+
+ Aggplus::CMatrix* m_pBaseTransform; // матрица перерасчета координатных осей (здесь: миллиметры -> пикселы)
+ Aggplus::CMatrix* m_pTransform; // текущая матрица преобразований рендерера
+ Aggplus::CMatrix* m_pFullTransform; // полная матрица преобразований (m_oBaseTransform * m_oTransform)
+
+ double m_dTransformAngle;
+
+ LONG m_lCurrentCommandType; // текущая команда
+
+ double m_dDpiX;
+ double m_dDpiY;
+
+ double m_dWidth;
+ double m_dHeight;
+
+ LONG m_lClipMode;
+
+ NSStructures::CPen* m_pPen; // настройки всей графики (скопирован ашник из AVSGraphics)
+ NSStructures::CBrush* m_pBrush;
+ NSStructures::CFont* m_pFont;
+
+ NSStructures::CFont* m_pInstalledFont;
+
+ bool m_bIsRaster;
+ //todo
+ //IASCWinFonts* m_pFonts;
+
+ protected:
+ void CalculateFullTransform();
+ inline void MoveTo(const double& dX, const double& dY);
+ inline void LineTo(const double& dX, const double& dY);
+ inline void CurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3);
+ void Start();
+ void End();
+ void Close();
+ void _SetFont();
+ };
+}
+
+#endif // _ASC_HTMLRENDERER_SVG_WRITER_H_
diff --git a/HtmlRenderer/src/ASCSVGWriter.cpp b/HtmlRenderer/src/ASCSVGWriter.cpp
new file mode 100644
index 0000000000..ec81546808
--- /dev/null
+++ b/HtmlRenderer/src/ASCSVGWriter.cpp
@@ -0,0 +1,926 @@
+#include "../include/ASCSVGWriter.h"
+
+#include "../../DesktopEditor/graphics/GraphicsPath.h"
+#include "VectorGraphicsWriter2.h"
+
+namespace NSHtmlRenderer
+{
+ CASCSVGWriter::CASCSVGWriter()
+ {
+ m_dDpiX = 96.0;
+ m_dDpiY = 96.0;
+
+ m_dWidth = 100;
+ m_dHeight = 100;
+ m_bIsRaster = false;
+
+ m_lClipMode = c_nClipRegionTypeWinding;
+
+ m_pSimpleGraphicsConverter = new Aggplus::CGraphicsPathSimpleConverter();
+ m_pSimpleGraphicsConverter->SetRenderer(this);
+
+ m_dTransformAngle = 0.0;
+
+ m_pFontManager = NULL;
+ m_bDeleteFontManager = true;
+ m_pPen = new NSStructures::CPen();
+ m_pBrush = new NSStructures::CBrush();
+ m_pFont = new NSStructures::CFont();
+ m_pInstalledFont = new NSStructures::CFont();
+
+ m_pBaseTransform = new Aggplus::CMatrix();
+ m_pTransform = new Aggplus::CMatrix();
+ m_pFullTransform = new Aggplus::CMatrix();
+
+ //todo вроде как подбора нет, но может нужно передавать?
+ m_pFontManager = new CFontManager();
+ m_pFontManager->Initialize();
+
+ m_pVectorWriter = new NSHtmlRenderer::CSVGGraphicsWriter();
+ m_pVectorWriter->m_pSimpleConverter = m_pSimpleGraphicsConverter;
+ m_pVectorWriter->m_pFullTransform = m_pFullTransform;
+ m_pVectorWriter->SetSettings(m_pPen, m_pBrush, m_pSimpleGraphicsConverter);
+ }
+ CASCSVGWriter::~CASCSVGWriter()
+ {
+ RELEASEOBJECT(m_pSimpleGraphicsConverter);
+ if(m_bDeleteFontManager)
+ RELEASEOBJECT(m_pFontManager);
+ RELEASEOBJECT(m_pPen);
+ RELEASEOBJECT(m_pBrush);
+ RELEASEOBJECT(m_pFont);
+ RELEASEOBJECT(m_pInstalledFont);
+ RELEASEOBJECT(m_pBaseTransform);
+ RELEASEOBJECT(m_pTransform);
+ RELEASEOBJECT(m_pFullTransform);
+ RELEASEOBJECT(m_pVectorWriter);
+ }
+
+ HRESULT CASCSVGWriter::get_Type(LONG* lType)
+ {
+ if (NULL == lType)
+ return S_FALSE;
+
+ *lType = c_nSVGRendrerer;
+ return S_OK;
+ }
+ //-------- Функции для работы со страницей --------------------------------------------------
+ HRESULT CASCSVGWriter::NewPage()
+ {
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_Height(double* dHeight)
+ {
+ *dHeight = m_dHeight;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_Height(const double& dHeight)
+ {
+ m_dHeight = dHeight;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_Width(double* dWidth)
+ {
+ *dWidth = m_dWidth;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_Width(const double& dWidth)
+ {
+ m_dWidth = dWidth;
+ return S_OK;
+ }
+
+ HRESULT CASCSVGWriter::get_DpiX(double* dDpiX)
+ {
+ if (NULL != dDpiX)
+ *dDpiX = m_dDpiX;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_DpiY(double* dDpiY)
+ {
+ if (NULL != dDpiY)
+ *dDpiY = m_dDpiY;
+ return S_OK;
+ }
+ // pen --------------------------------------------------------------------------------------
+ HRESULT CASCSVGWriter::get_PenColor(LONG* lColor)
+ {
+ *lColor = m_pPen->Color;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenColor(const LONG& lColor)
+ {
+ m_pPen->Color = lColor;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenAlpha(LONG* lAlpha)
+ {
+ *lAlpha = m_pPen->Alpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenAlpha(const LONG& lAlpha)
+ {
+ m_pPen->Alpha = lAlpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenSize(double* dSize)
+ {
+ *dSize = m_pPen->Size;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenSize(const double& dSize)
+ {
+ m_pPen->Size = dSize;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenDashStyle(BYTE* val)
+ {
+ *val = m_pPen->DashStyle;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenDashStyle(const BYTE& val)
+ {
+ m_pPen->DashStyle = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenLineStartCap(BYTE* val)
+ {
+ *val = m_pPen->LineStartCap;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenLineStartCap(const BYTE& val)
+ {
+ m_pPen->LineStartCap = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenLineEndCap(BYTE* val)
+ {
+ *val = m_pPen->LineEndCap;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenLineEndCap(const BYTE& val)
+ {
+ m_pPen->LineEndCap = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenLineJoin(BYTE* val)
+ {
+ *val = m_pPen->LineJoin;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenLineJoin(const BYTE& val)
+ {
+ m_pPen->LineJoin = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenDashOffset(double* val)
+ {
+ *val = m_pPen->DashOffset;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenDashOffset(const double& val)
+ {
+ m_pPen->DashOffset = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenAlign(LONG* val)
+ {
+ *val = m_pPen->Align;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenAlign(const LONG& val)
+ {
+ m_pPen->Align = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_PenMiterLimit(double* val)
+ {
+ *val = m_pPen->MiterLimit;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_PenMiterLimit(const double& val)
+ {
+ m_pPen->MiterLimit = val;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PenDashPattern(double* pPattern, LONG lCount)
+ {
+ if (NULL != pPattern)
+ {
+ m_pPen->SetDashPattern(pPattern, lCount);
+ }
+
+ return S_OK;
+ }
+ // brush ------------------------------------------------------------------------------------
+ HRESULT CASCSVGWriter::get_BrushType(LONG* lType)
+ {
+ *lType = m_pBrush->Type;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushType(const LONG& lType)
+ {
+ m_pBrush->Type = lType;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushColor1(LONG* lColor)
+ {
+ *lColor = m_pBrush->Color1;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushColor1(const LONG& lColor)
+ {
+ m_pBrush->Color1 = lColor;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushAlpha1(LONG* lAlpha)
+ {
+ *lAlpha = m_pBrush->Alpha1;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushAlpha1(const LONG& lAlpha)
+ {
+ m_pBrush->Alpha1 = lAlpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushColor2(LONG* lColor)
+ {
+ *lColor = m_pBrush->Color2;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushColor2(const LONG& lColor)
+ {
+ m_pBrush->Color2 = lColor;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushAlpha2(LONG* lAlpha)
+ {
+ *lAlpha = m_pBrush->Alpha2;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushAlpha2(const LONG& lAlpha)
+ {
+ m_pBrush->Alpha2 = lAlpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushTexturePath(std::wstring* bsPath)
+ {
+ *bsPath = m_pBrush->TexturePath;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushTexturePath(const std::wstring& bsPath)
+ {
+ m_pBrush->TexturePath = bsPath;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushTextureMode(LONG* lMode)
+ {
+ *lMode = m_pBrush->TextureMode;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushTextureMode(const LONG& lMode)
+ {
+ m_pBrush->TextureMode = lMode;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushTextureAlpha(LONG* lTxAlpha)
+ {
+ *lTxAlpha = m_pBrush->TextureAlpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushTextureAlpha(const LONG& lTxAlpha)
+ {
+ m_pBrush->TextureAlpha = lTxAlpha;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_BrushLinearAngle(double* dAngle)
+ {
+ *dAngle = m_pBrush->LinearAngle;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_BrushLinearAngle(const double& dAngle)
+ {
+ m_pBrush->LinearAngle = dAngle;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
+ {
+ m_pBrush->Rectable = val;
+ m_pBrush->Rect.X = (float)left;
+ m_pBrush->Rect.Y = (float)top;
+ m_pBrush->Rect.Width = (float)width;
+ m_pBrush->Rect.Height = (float)height;
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::BrushBounds(const double& left, const double& top, const double& width, const double& height)
+ {
+ return S_OK;
+ }
+
+ HRESULT CASCSVGWriter::put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount)
+ {
+ return S_OK;
+ }
+
+ // font -------------------------------------------------------------------------------------
+ HRESULT CASCSVGWriter::get_FontName(std::wstring* bsName)
+ {
+ *bsName = m_pFont->Name;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontName(const std::wstring& bsName)
+ {
+ m_pFont->Name = bsName;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontPath(std::wstring* bsName)
+ {
+ *bsName = m_pFont->Path;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontPath(const std::wstring& bsName)
+ {
+ m_pFont->Path = bsName;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontSize(double* dSize)
+ {
+ *dSize = m_pFont->Size;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontSize(const double& dSize)
+ {
+ m_pFont->Size = dSize;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontStyle(LONG* lStyle)
+ {
+ *lStyle = m_pFont->GetStyle();
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontStyle(const LONG& lStyle)
+ {
+ m_pFont->SetStyle(lStyle);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontStringGID(INT* bGID)
+ {
+ *bGID = m_pFont->StringGID;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontStringGID(const INT& bGID)
+ {
+ m_pFont->StringGID = bGID;
+ m_pFontManager->SetStringGID(bGID);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontCharSpace(double* dSpace)
+ {
+ *dSpace = m_pFont->CharSpace;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontCharSpace(const double& dSpace)
+ {
+ m_pFont->CharSpace = dSpace;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::get_FontFaceIndex(int* lFaceIndex)
+ {
+ *lFaceIndex = m_pFont->FaceIndex;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_FontFaceIndex(const int& lFaceIndex)
+ {
+ m_pFont->FaceIndex = lFaceIndex;
+ return S_OK;
+ }
+ //-------- Функции для вывода текста --------------------------------------------------------
+ HRESULT CASCSVGWriter::CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::CommandDrawText(const std::wstring& bsText,const double& x,const double& y,const double& w, const double& h)
+ {
+ if (c_nHyperlinkType == m_lCurrentCommandType)
+ return S_OK;
+
+ if (m_bIsRaster)
+ return S_OK;
+
+ PathCommandEnd();
+ BeginCommand(c_nPathType);
+ PathCommandText(bsText, x, y, w, h);
+ DrawPath(c_nWindingFillMode);
+ EndCommand(c_nPathType);
+ PathCommandEnd();
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ PathCommandEnd();
+ BeginCommand(c_nPathType);
+ PathCommandTextEx(bsUnicodeText, pGids,nGidsCount , x, y, w, h);
+ DrawPath(c_nWindingFillMode);
+ EndCommand(c_nPathType);
+ PathCommandEnd();
+ return S_OK;
+ }
+ //-------- Маркеры для команд ---------------------------------------------------------------
+ HRESULT CASCSVGWriter::BeginCommand(const DWORD& lType)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nClipType == lType)
+ {
+ m_pVectorWriter->WritePathClip();
+ }
+ else if (c_nPathType == lType)
+ {
+ m_pVectorWriter->WritePathStart();
+ m_pSimpleGraphicsConverter->PathCommandEnd();
+ }
+ m_lCurrentCommandType = lType;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::EndCommand(const DWORD& lType)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nClipType == lType)
+ {
+ m_pVectorWriter->WritePathClipEnd();
+ }
+ else if (c_nResetClipType == lType)
+ {
+ m_pVectorWriter->WritePathResetClip();
+ }
+ m_lCurrentCommandType = -1;
+ return S_OK;
+ }
+ //-------- Функции для работы с Graphics Path -----------------------------------------------
+ HRESULT CASCSVGWriter::PathCommandMoveTo(const double& fX, const double& fY)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ MoveTo(fX, fY);
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandMoveTo(fX, fY);
+ }
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandLineTo(const double& fX, const double& fY)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ LineTo(fX, fY);
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandLineTo(fX, fY);
+ }
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandLinesTo(double* points, const int& count)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ m_pSimpleGraphicsConverter->PathCommandLinesTo(points, count);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandCurveTo(const double& fX1, const double& fY1, const double& fX2, const double& fY2, const double& fX3, const double& fY3)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ CurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandCurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
+ }
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandCurvesTo(double* points, const int& count)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ m_pSimpleGraphicsConverter->PathCommandCurvesTo(points, count);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandArcTo(const double& fX, const double& fY, const double& fWidth, const double& fHeight, const double& fStartAngle, const double& fSweepAngle)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ m_pSimpleGraphicsConverter->PathCommandArcTo(fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandClose()
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ Close();
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandClose();
+ }
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandEnd()
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ End();
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandEnd();
+ }
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::DrawPath(const long& nType)
+ {
+ if (m_pBrush->Type == c_BrushTypeTexture)
+ m_bIsRaster = true;
+
+ if (m_bIsRaster)
+ return S_OK;
+
+ m_pVectorWriter->WriteDrawPath(nType);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandStart()
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ if (c_nSimpleGraphicType == m_lCurrentCommandType)
+ {
+ Start();
+ }
+ else
+ {
+ m_pSimpleGraphicsConverter->PathCommandEnd();
+ m_pSimpleGraphicsConverter->PathCommandStart();
+ }
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandGetCurrentPoint(double* fX, double* fY)
+ {
+ m_pSimpleGraphicsConverter->PathCommandGetCurrentPoint(fX, fY);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandText(const std::wstring& bsText, const double& fX, const double& fY, const double& fWidth, const double& fHeight)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ _SetFont();
+ m_pSimpleGraphicsConverter->PathCommandText(bsText, m_pFontManager, fX, fY, fWidth, fHeight, 0);
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
+ {
+ if (m_bIsRaster)
+ return S_OK;
+
+ bool bGid = m_pFont->StringGID != 0 ? true : false;
+
+ //TODOOO
+ //if (bsGidText.empty())
+ //{
+ // m_pFont->StringGID = 1;
+ // PathCommandText(bsGidText, x, y, w, h, baselineOffset);
+ //}
+
+ m_pFont->StringGID = 0;
+ PathCommandText(sText, x, y, w, h);
+
+ m_pFont->StringGID = bGid ? 1 : 0;
+ return S_OK;
+ }
+ //-------- Функции для вывода изображений ---------------------------------------------------
+ HRESULT CASCSVGWriter::DrawImage(IGrObject* pImage, const double& fX, const double& fY, const double& fWidth, const double& fHeight)
+ {
+ m_bIsRaster = true;
+ /*
+ double x = fX;
+ double y = fY;
+
+ double r = fX + fWidth;
+ double b = fY + fHeight;
+
+ if (0 == m_dTransformAngle)
+ {
+ m_pFullTransform->TransformPoint(x, y);
+ m_pFullTransform->TransformPoint(r, b);
+ }
+ else
+ {
+ NSHtmlRenderer::CMatrix oTemp = *m_pFullTransform;
+
+ double dCx = (x + r) / 2;
+ double dCy = (y + b) / 2;
+ m_pFullTransform->TransformPoint(dCx, dCy);
+ oTemp.RotateAt(-m_dTransformAngle, dCx, dCy, Aggplus::MatrixOrderAppend);
+
+ oTemp.TransformPoint(x, y);
+ oTemp.TransformPoint(r, b);
+ }
+
+ m_oWriter.WriteImage(pInterface, x, y, r - x, b - y, m_dTransformAngle);
+ */
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::DrawImageFromFile(const std::wstring& sVal, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255)
+ {
+ m_bIsRaster = true;
+ /*
+ double x = fX;
+ double y = fY;
+
+ double r = fX + fWidth;
+ double b = fY + fHeight;
+
+ if (0 == m_dTransformAngle)
+ {
+ m_pFullTransform->TransformPoint(x, y);
+ m_pFullTransform->TransformPoint(r, b);
+ }
+ else
+ {
+ NSHtmlRenderer::CMatrix oTemp = *m_pFullTransform;
+
+ double dCx = (x + r) / 2;
+ double dCy = (y + b) / 2;
+ m_pFullTransform->TransformPoint(dCx, dCy);
+ oTemp.RotateAt(-m_dTransformAngle, dCx, dCy, Aggplus::MatrixOrderAppend);
+
+ oTemp.TransformPoint(x, y);
+ oTemp.TransformPoint(r, b);
+ }
+
+ m_oWriter.WriteImage((CString)bstrVal, x, y, r - x, b - y, m_pTransform->z_Rotation());
+ */
+
+ return S_OK;
+ }
+ // transform --------------------------------------------------------------------------------
+ HRESULT CASCSVGWriter::SetTransform(const double& dA, const double& dB, const double& dC, const double& dD, const double& dE, const double& dF)
+ {
+ Aggplus::CMatrix oTrans(dA, dB, dC, dD, dE, dF);
+ *m_pTransform = oTrans;
+
+ CalculateFullTransform();
+
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF)
+ {
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::ResetTransform(void)
+ {
+ m_pTransform->Reset();
+ CalculateFullTransform();
+ return S_OK;
+ }
+ // -----------------------------------------------------------------------------------------
+ HRESULT CASCSVGWriter::get_ClipMode(LONG* plMode)
+ {
+ *plMode = m_lClipMode;
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::put_ClipMode(const LONG& lMode)
+ {
+ m_lClipMode = lMode;
+ m_pVectorWriter->SetClipMode(m_lClipMode);
+ return S_OK;
+ }
+ // additiaonal params ----------------------------------------------------------------------
+ HRESULT CASCSVGWriter::SaveFile(const std::wstring& strFileSave)
+ {
+ NSFile::CFileBinary oFile;
+ if(oFile.CreateFileW(strFileSave))
+ {
+ NSStringUtils::CStringBuilder oBuilder;
+ WriteFormatted(L"");
+ }
+ oFile.CloseFile();
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::ReInit()
+ {
+ m_dDpiX = 96.0;
+ m_dDpiY = 96.0;
+
+ m_dWidth = 100;
+ m_dHeight = 100;
+ m_bIsRaster = false;
+
+ m_lClipMode = c_nClipRegionTypeWinding;
+
+ RELEASEOBJECT(m_pSimpleGraphicsConverter);
+ m_pSimpleGraphicsConverter = new Aggplus::CGraphicsPathSimpleConverter();
+ m_pSimpleGraphicsConverter->SetRenderer(this);
+
+ m_dTransformAngle = 0.0;
+
+
+ m_pVectorWriter->m_pSimpleConverter = m_pSimpleGraphicsConverter;
+ m_pVectorWriter->m_pFullTransform = m_pFullTransform;
+ m_pVectorWriter->SetSettings(m_pPen, m_pBrush, m_pSimpleGraphicsConverter);
+
+ m_pPen->SetDefaultParams();
+ m_pBrush->SetDefaultParams();
+ m_pFont->SetDefaultParams();
+
+ m_pBaseTransform->Reset();
+ m_pTransform->Reset();
+ m_pFullTransform->Reset();
+
+ m_pVectorWriter->m_oSVG.ReInit();
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::IsRaster(bool* bVal)
+ {
+ *bVal = m_bIsRaster;
+ return S_OK;
+ }
+ // additiaonal params ----------------------------------------------------------------------
+ HRESULT CASCSVGWriter::CommandLong(const LONG& lType, const LONG& lCommand)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::CommandDouble(const LONG& lType, const double& dCommand)
+ {
+ //todo new command
+ return S_OK;
+ }
+ HRESULT CASCSVGWriter::CommandString(const LONG& lType, const std::wstring& sCommand)
+ {
+ //todo new command
+ return S_OK;
+ }
+ // --------------------------------------------------------------------------------------------
+ void CASCSVGWriter::OnBaseMatrixUpdate(const double& dWidth, const double& dHeight)
+ {
+ m_pBaseTransform->Reset();
+
+ double dScaleX = m_dDpiX / NSHtmlRenderer::c_ag_Inch_to_MM;
+ double dScaleY = m_dDpiY / NSHtmlRenderer::c_ag_Inch_to_MM;
+
+ m_pBaseTransform->Scale(dScaleX, dScaleY, Aggplus::MatrixOrderAppend);
+
+ CalculateFullTransform();
+
+ double dWidthPix = dScaleX * dWidth;
+ double dHeightPix = dScaleY * dHeight;
+ }
+ void CASCSVGWriter::SetFontManager(CFontManager* pFontManager)
+ {
+ if(NULL != pFontManager)
+ {
+ if(m_bDeleteFontManager)
+ RELEASEOBJECT(m_pFontManager);
+ m_pFontManager = pFontManager;
+ m_bDeleteFontManager = false;
+ }
+ }
+ void CASCSVGWriter::CalculateFullTransform()
+ {
+ *m_pFullTransform = *m_pBaseTransform;
+ m_pFullTransform->Multiply(m_pTransform, Aggplus::MatrixOrderPrepend);
+
+ m_dTransformAngle = m_pTransform->z_Rotation();
+ }
+
+ inline void CASCSVGWriter::MoveTo(const double& dX, const double& dY)
+ {
+ double x = dX;
+ double y = dY;
+ m_pFullTransform->TransformPoint(x, y);
+
+ m_pVectorWriter->WritePathMoveTo(x, y);
+ }
+ inline void CASCSVGWriter::LineTo(const double& dX, const double& dY)
+ {
+ double x = dX;
+ double y = dY;
+ m_pFullTransform->TransformPoint(x, y);
+
+ m_pVectorWriter->WritePathLineTo(x, y);
+ }
+ inline void CASCSVGWriter::CurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
+ {
+ double _x1 = x1;
+ double _y1 = y1;
+ m_pFullTransform->TransformPoint(_x1, _y1);
+
+ double _x2 = x2;
+ double _y2 = y2;
+ m_pFullTransform->TransformPoint(_x2, _y2);
+
+ double _x3 = x3;
+ double _y3 = y3;
+ m_pFullTransform->TransformPoint(_x3, _y3);
+
+ m_pVectorWriter->WritePathCurveTo(_x1, _y1, _x2, _y2, _x3, _y3);
+ }
+ void CASCSVGWriter::Start()
+ {
+ m_pVectorWriter->WritePathStart();
+ }
+ void CASCSVGWriter::End()
+ {
+ m_pVectorWriter->WriteEndPath();
+ }
+ void CASCSVGWriter::Close()
+ {
+ m_pVectorWriter->WritePathClose();
+ }
+
+ void CASCSVGWriter::_SetFont()
+ {
+ double dPix = m_pFont->CharSpace * m_dDpiX / 25.4;
+
+ if (m_pInstalledFont->IsEqual(m_pFont))
+ {
+ if (1 < m_dWidth)
+ {
+ m_pFontManager->SetCharSpacing(dPix);
+ }
+ return;
+ }
+
+ m_pFontManager->SetStringGID(m_pFont->StringGID);
+ if (1 < m_dWidth)
+ {
+ m_pFontManager->SetCharSpacing(dPix);
+ }
+
+ if (m_pFont->Path.empty())
+ {
+ m_pFontManager->LoadFontByName(m_pFont->Name, (float)m_pFont->Size, m_pFont->GetStyle(), m_dDpiX, m_dDpiY);
+ }
+ else
+ {
+ m_pFontManager->LoadFontFromFile(m_pFont->Path, (float)m_pFont->Size, m_dDpiX, m_dDpiY, 0);
+ }
+
+ *m_pInstalledFont = *m_pFont;
+ }
+}
diff --git a/HtmlRenderer/src/Common.h b/HtmlRenderer/src/Common.h
index 6c7127d30a..caaa2bac43 100644
--- a/HtmlRenderer/src/Common.h
+++ b/HtmlRenderer/src/Common.h
@@ -4,13 +4,11 @@
#include "../../DesktopEditor/common/Types.h"
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/common/Directory.h"
-#include "../../DesktopEditor/raster/BgraFrame.h"
#include "../../DesktopEditor/graphics/Matrix.h"
#include "../../DesktopEditor/graphics/structures.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../../DesktopEditor/common/StringBuilder.h"
#include "../../DesktopEditor/graphics/IRenderer.h"
-#include "../../DesktopEditor/xml/include/xmlutils.h"
namespace NSHtmlRenderer
{
@@ -54,9 +52,9 @@ namespace NSHtmlRenderer
namespace NSHtmlRenderer
{
inline LONG ConvertColor(const LONG& lBGR)
- {
- return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
- }
+ {
+ return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
+ }
inline void WriteIntsToStringBuilder(const int& n1, const int& n2, NSStringUtils::CStringBuilder* pBuilder)
{
@@ -232,705 +230,47 @@ namespace NSHtmlRenderer
return false;
}
- static RECT GetImageBounds(CBgraFrame* pFrame)
+ const double c_ag_Inch_to_MM = 25.4;
+ const double c_ag_1pxWidth = 25.4 / 96;
+
+ enum ImageType
{
- BYTE* pBuffer = pFrame->get_Data();
- LONG lWidth = (LONG)pFrame->get_Width();
- LONG lHeight = (LONG)pFrame->get_Height();
+ itJPG = 0,
+ itPNG = 1
+ };
- RECT rect;
- rect.left = 0;
- rect.top = 0;
- rect.right = lWidth - 1;
- rect.bottom = lHeight - 1;
-
- // top
- unsigned int* pData = (unsigned int*)pBuffer;
- for (; rect.top < lHeight; rect.top++)
- {
- bool bIsBreak = false;
- for (LONG i = 0; i < lWidth; ++i, ++pData)
- {
- if (*pData != 0x00)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.top >= lHeight)
- rect.top = (lHeight - 1);
-
- // bottom
- for (; rect.bottom >= rect.top; rect.bottom--)
- {
- pData = (unsigned int*)pBuffer;
- pData += (lWidth * rect.bottom);
-
- bool bIsBreak = false;
- for (LONG i = 0; i < lWidth; ++i, ++pData)
- {
- if (*pData != 0x00)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.bottom < rect.top)
- rect.bottom = rect.top;
-
- LONG lDelta = rect.bottom - rect.top + 1;
-
- // left
- for (; rect.left < lWidth; rect.left++)
- {
- pData = (unsigned int*)(pBuffer + 4 * lWidth * rect.top);
- pData += rect.left;
-
- bool bIsBreak = false;
- for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
- {
- if (*pData != 0x00)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.left >= lWidth)
- rect.left = lWidth - 1;
-
- // right
- for (; rect.right >= rect.left; rect.right--)
- {
- pData = (unsigned int*)(pBuffer + 4 * lWidth * rect.top);
- pData += rect.right;
-
- bool bIsBreak = false;
- for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
- {
- if (*pData != 0x00)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.right < rect.left)
- rect.right = rect.left;
-
- return rect;
- }
-
- static RECT GetImageBounds2(CBgraFrame* pFrame, BYTE* pCache)
- {
- BYTE* pBuffer = pFrame->get_Data();
- LONG lWidth = (LONG)pFrame->get_Width();
- LONG lHeight = (LONG)pFrame->get_Height();
-
- RECT rect;
- rect.left = 0;
- rect.top = 0;
- rect.right = lWidth - 1;
- rect.bottom = lHeight - 1;
-
- // top
- unsigned int** pData = (unsigned int**)pBuffer;
- unsigned int** pDataSrc = (unsigned int**)pCache;
- for (; rect.top < lHeight; rect.top++)
- {
- if (0 != memcmp((void*)pData, (void*)pDataSrc, 4 * lWidth))
- break;
-
- pData += lWidth;
- pDataSrc += lWidth;
- }
- if (rect.top >= lHeight)
- rect.top = (lHeight - 1);
-
- // bottom
- for (; rect.bottom >= rect.top; rect.bottom--)
- {
- pData = (unsigned int**)pBuffer;
- pData += (lWidth * rect.bottom);
- pDataSrc = (unsigned int**)pCache;
- pDataSrc += (lWidth * rect.bottom);
-
- if (0 != memcmp((void*)pData, (void*)pDataSrc, 4 * lWidth))
- break;
- }
- if (rect.bottom < rect.top)
- rect.bottom = rect.top;
-
- LONG lDelta = rect.bottom - rect.top + 1;
-
- // left
- for (; rect.left < lWidth; rect.left++)
- {
- pData = (unsigned int**)(pBuffer + 4 * lWidth * rect.top);
- pData += rect.left;
- pDataSrc = (unsigned int**)(pCache + 4 * lWidth * rect.top);
- pDataSrc += rect.left;
-
- bool bIsBreak = false;
- for (LONG i = 0; i < lDelta; ++i, pData += lWidth, pDataSrc += lWidth)
- {
- if (*pData != *pDataSrc)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.left >= lWidth)
- rect.left = lWidth - 1;
-
- // right
- for (; rect.right >= rect.left; rect.right--)
- {
- pData = (unsigned int**)(pBuffer + 4 * lWidth * rect.top);
- pData += rect.right;
-
- pDataSrc = (unsigned int**)(pCache + 4 * lWidth * rect.top);
- pDataSrc += rect.right;
-
- bool bIsBreak = false;
- for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
- {
- if (*pData != *pDataSrc)
- {
- bIsBreak = true;
- break;
- }
- }
- if (bIsBreak)
- break;
- }
- if (rect.right < rect.left)
- rect.right = rect.left;
-
- return rect;
- }
-
- const double c_ag_Inch_to_MM = 25.4;
- const double c_ag_1pxWidth = 25.4 / 96;
-
- enum ImageType
- {
- itJPG = 0,
- itPNG = 1
- };
-
- class CImageInfo
- {
- public:
- ImageType m_eType;
- LONG m_lID;
-
- CImageInfo()
- {
- m_eType = itJPG;
- m_lID = -1;
- }
- CImageInfo(const CImageInfo& oSrc)
- {
- *this = oSrc;
- }
- CImageInfo& operator=(const CImageInfo& oSrc)
- {
- m_eType = oSrc.m_eType;
- m_lID = oSrc.m_lID;
-
- return *this;
- }
- };
-
- inline double FABS(double dVal)
- {
- return (dVal >= 0) ? dVal : -dVal;
- }
- inline int round(double dVal)
- {
- return (int)(dVal + 0.5);
- }
-}
-
-namespace NSHtmlRenderer
-{
- class CMetafile
+ class CImageInfo
{
public:
- enum CommandType
+ ImageType m_eType;
+ LONG m_lID;
+
+ CImageInfo()
{
- // pen
- ctPenXML = 0,
- ctPenColor = 1,
- ctPenAlpha = 2,
- ctPenSize = 3,
- ctPenDashStyle = 4,
- ctPenLineStartCap = 5,
- ctPenLineEndCap = 6,
- ctPenLineJoin = 7,
- ctPenDashPatern = 8,
- ctPenDashPatternCount = 9,
- ctPenDashOffset = 10,
- ctPenAlign = 11,
- ctPenMiterLimit = 12,
-
- // brush
- ctBrushXML = 20,
- ctBrushType = 21,
- ctBrushColor1 = 22,
- ctBrushColor2 = 23,
- ctBrushAlpha1 = 24,
- ctBrushAlpha2 = 25,
- ctBrushTexturePath = 26,
- ctBrushTextureAlpha = 27,
- ctBrushTextureMode = 28,
- ctBrushRectable = 29,
- ctBrushAngle = 30,
- ctBrushSubColors = 31,
-
- // font
- ctFontXML = 40,
- ctFontName = 41,
- ctFontSize = 42,
- ctFontStyle = 43,
- ctFontPath = 44,
- ctFontGID = 45,
- ctFontCharSpace = 46,
-
- // shadow
- ctShadowXML = 50,
- ctShadowVisible = 51,
- ctShadowDistanceX = 52,
- ctShadowDistanceY = 53,
- ctShadowBlurSize = 54,
- ctShadowColor = 55,
- ctShadowAlpha = 56,
-
- // edge
- ctEdgeXML = 70,
- ctEdgeVisible = 71,
- ctEdgeDistance = 72,
- ctEdgeColor = 73,
- ctEdgeAlpha = 74,
-
- // text
- ctDrawText = 80,
- ctDrawTextEx = 81,
-
- // pathcommands
- ctPathCommandMoveTo = 91,
- ctPathCommandLineTo = 92,
- ctPathCommandLinesTo = 93,
- ctPathCommandCurveTo = 94,
- ctPathCommandCurvesTo = 95,
- ctPathCommandArcTo = 96,
- ctPathCommandClose = 97,
- ctPathCommandEnd = 98,
- ctDrawPath = 99,
- ctPathCommandStart = 100,
- ctPathCommandGetCurrentPoint = 101,
- ctPathCommandText = 102,
- ctPathCommandTextEx = 103,
-
- // image
- ctDrawImage = 110,
- ctDrawImageFromFile = 111,
-
- ctSetParams = 120,
-
- ctBeginCommand = 121,
- ctEndCommand = 122,
-
- ctSetTransform = 130,
- ctResetTransform = 131,
-
- ctClipMode = 140,
-
- ctCommandLong1 = 150,
- ctCommandDouble1 = 151,
- ctCommandString1 = 152,
- ctCommandLong2 = 153,
- ctCommandDouble2 = 154,
- ctCommandString2 = 155,
-
- ctCommandTextLine = 160,
- ctCommandTextTransform = 161,
- ctCommandTextLineEnd = 162,
-
- ctCommandTextClipRectReset = 163,
- ctCommandTextClipRect = 164,
-
- ctError = 255
- };
-
- private:
-
- // сам метафайл
- BYTE* m_pBuffer;
- BYTE* m_pBufferMem;
-
- size_t m_lPosition;
- size_t m_lSize;
-
- LONG m_lSizeofDouble;
- LONG m_lSizeofFloat;
- LONG m_lSizeofLONG;
- LONG m_lSizeofBYTE;
-
- public:
- double m_fWidth;
- double m_fHeight;
-
- public:
- CMetafile()
- {
- Clear();
-
- m_lSizeofDouble = sizeof(double);
- m_lSizeofFloat = sizeof(float);
- m_lSizeofLONG = sizeof(int);
- m_lSizeofBYTE = sizeof(BYTE);
+ m_eType = itJPG;
+ m_lID = -1;
}
- ~CMetafile()
+ CImageInfo(const CImageInfo& oSrc)
{
- RELEASEARRAYOBJECTS(m_pBuffer);
+ *this = oSrc;
}
-
- public:
-
- inline LONG GetPosition()
+ CImageInfo& operator=(const CImageInfo& oSrc)
{
- return (LONG)m_lPosition;
- }
- inline BYTE* GetData()
- {
- return m_pBuffer;
- }
- inline void ClearNoAttack()
- {
- m_lPosition = 0;
- m_pBufferMem = m_pBuffer;
- }
+ m_eType = oSrc.m_eType;
+ m_lID = oSrc.m_lID;
- inline void Clear()
- {
- m_lSize = 0;
- m_lPosition = 0;
-
- m_pBuffer = NULL;
- m_pBufferMem = NULL;
- }
- inline void Seek(LONG lPos)
- {
- m_lPosition = (size_t)lPos;
- m_pBufferMem = m_pBuffer + m_lPosition;
- }
-
- inline void CheckBufferSize(size_t lPlus)
- {
- if (NULL != m_pBuffer)
- {
- size_t nNewSize = m_lPosition + lPlus;
-
- if (nNewSize >= m_lSize)
- {
- while (nNewSize >= m_lSize)
- {
- m_lSize *= 2;
- }
-
- BYTE* pNew = new BYTE[m_lSize];
- memcpy(pNew, m_pBuffer, m_lPosition);
-
- RELEASEARRAYOBJECTS(m_pBuffer);
- m_pBuffer = pNew;
- }
- }
- else
- {
- m_lSize = 1000;
- m_pBuffer = new BYTE[m_lSize];
-
- CheckBufferSize(lPlus);
- }
- }
-
- inline void WriteCommandType(const CommandType& eType)
- {
- CheckBufferSize(m_lSizeofBYTE);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
- }
-
- //
- inline void WriteBYTE_nocheck(const BYTE& lValue)
- {
- *(m_pBuffer + m_lPosition) = lValue;
- m_lPosition += m_lSizeofBYTE;
- }
- inline void WriteLONG_nocheck(const int& lValue)
- {
- *((int*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += m_lSizeofLONG;
- }
- inline void WriteUSHORT_nocheck(const USHORT& lValue)
- {
- *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(USHORT);
- }
- inline void WriteWCHAR_nocheck(const WCHAR& lValue)
- {
- *((WCHAR*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(WCHAR);
- }
- inline void WriteWCHAR_nocheck2(const int& lValue)
- {
- if (lValue < 0x10000)
- {
- *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += 2;
- }
- else
- {
- int code = lValue - 0x10000;
- *((USHORT*)(m_pBuffer + m_lPosition)) = 0xD800 | ((code >> 10) & 0x03FF);
- *((USHORT*)(m_pBuffer + m_lPosition + 2)) = 0xDC00 | (code & 0x03FF);
- m_lPosition += 4;
- }
- }
- inline void WriteDouble_nocheck(const double& dValue)
- {
- // здесь никаких даблов. Сплошные округления
- LONG lValue = (LONG)(dValue * 10000);
- WriteLONG_nocheck(lValue);
- return;
-
- CheckBufferSize(m_lSizeofDouble);
-
- *((double*)(m_pBuffer + m_lPosition)) = dValue;
- m_lPosition += m_lSizeofDouble;
- }
- inline void WriteDouble2_nocheck(const double& dValue)
- {
- // здесь никаких даблов. Сплошные округления
- SHORT lValue = (SHORT)(dValue * 100);
- *((SHORT*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(SHORT);
- }
- //
- inline void WriteBYTE(const BYTE& lValue)
- {
- CheckBufferSize(m_lSizeofBYTE);
-
- *(m_pBuffer + m_lPosition) = lValue;
- m_lPosition += m_lSizeofBYTE;
- }
- inline void WriteLONG(const int& lValue)
- {
- CheckBufferSize(m_lSizeofLONG);
-
- *((int*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += m_lSizeofLONG;
- }
- inline void WriteUSHORT(const USHORT& lValue)
- {
- CheckBufferSize(sizeof(USHORT));
-
- *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(USHORT);
- }
- inline void WriteWCHAR(const WCHAR& lValue)
- {
- CheckBufferSize(sizeof(WCHAR));
-
- *((WCHAR*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(WCHAR);
- }
- inline void WriteDouble(const double& dValue)
- {
- // здесь никаких даблов. Сплошные округления
- int lValue = (int)(dValue * 10000);
- WriteLONG(lValue);
- return;
-
- CheckBufferSize(m_lSizeofDouble);
-
- *((double*)(m_pBuffer + m_lPosition)) = dValue;
- m_lPosition += m_lSizeofDouble;
- }
- inline void WriteDouble2(const double& dValue)
- {
- // здесь никаких даблов. Сплошные округления
- SHORT lValue = (SHORT)(dValue * 100);
- CheckBufferSize(sizeof(SHORT));
-
- *((SHORT*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += sizeof(SHORT);
- }
- inline void WriteFloat(const float& fValue)
- {
- CheckBufferSize(m_lSizeofFloat);
-
- *((float*)(m_pBuffer + m_lPosition)) = fValue;
- m_lPosition += m_lSizeofFloat;
- }
- inline void WriteString(wchar_t* bstrValue)
- {
- int lSize = (int)wcslen(bstrValue) + 1;
-
- int lSizeMem = lSize * sizeof(wchar_t);
-
- CheckBufferSize(m_lSizeofLONG + lSizeMem);
-
- *((int*)(m_pBuffer + m_lPosition)) = lSizeMem;
- m_lPosition += m_lSizeofLONG;
-
- memcpy(m_pBuffer + m_lPosition, bstrValue, lSizeMem);
- m_lPosition += lSizeMem;
- }
-
- inline void WriteBYTE(const CommandType& eType, const BYTE& lValue)
- {
- CheckBufferSize(2 * m_lSizeofBYTE);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
-
- *(m_pBuffer + m_lPosition) = lValue;
- m_lPosition += m_lSizeofBYTE;
- }
- inline void WriteLONG(const CommandType& eType, const int& lValue)
- {
- CheckBufferSize(m_lSizeofBYTE + m_lSizeofLONG);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
-
- *((int*)(m_pBuffer + m_lPosition)) = lValue;
- m_lPosition += m_lSizeofLONG;
- }
- inline void WriteDouble(const CommandType& eType, const double& dValue)
- {
- CheckBufferSize(m_lSizeofBYTE + m_lSizeofDouble);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
-
- *((double*)(m_pBuffer + m_lPosition)) = dValue;
- m_lPosition += m_lSizeofDouble;
- }
- inline void WriteFloat(const CommandType& eType, const float& fValue)
- {
- CheckBufferSize(m_lSizeofBYTE + m_lSizeofFloat);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
-
- *((float*)(m_pBuffer + m_lPosition)) = fValue;
- m_lPosition += m_lSizeofFloat;
- }
- inline void WriteString(const CommandType& eType, wchar_t* bstrValue)
- {
- int lSize = (int)wcslen(bstrValue) + 1;
-
- int lSizeMem = lSize * sizeof(wchar_t);
-
- CheckBufferSize(m_lSizeofBYTE + m_lSizeofLONG + lSizeMem);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eType;
- m_lPosition += m_lSizeofBYTE;
-
- *((int*)(m_pBuffer + m_lPosition)) = lSizeMem;
- m_lPosition += m_lSizeofLONG;
-
- memcpy(m_pBuffer + m_lPosition, bstrValue, lSizeMem);
- m_lPosition += lSizeMem;
- }
-
- inline void Write(const BYTE* pData, const LONG& lLen)
- {
- CheckBufferSize((size_t)lLen);
- memcpy(m_pBuffer + m_lPosition, pData, lLen);
- m_lPosition += lLen;
- }
-
- inline void Write(const CommandType& eCommand, const double& f1, const double& f2)
- {
- size_t lMem = m_lSizeofBYTE + 2 * m_lSizeofDouble;
-
- CheckBufferSize(lMem);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
- *((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += m_lSizeofDouble;
- }
-
- inline void Write(const CommandType& eCommand, const double& f1, const double& f2, const double& f3, const double& f4, const double& f5, const double& f6)
- {
- size_t lMem = m_lSizeofBYTE + 6 * m_lSizeofDouble;
-
- CheckBufferSize(lMem);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
- *((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f3; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f4; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f5; m_lPosition += m_lSizeofDouble;
- *((double*)(m_pBuffer + m_lPosition))= f6; m_lPosition += m_lSizeofDouble;
- }
-
- inline void Write(const CommandType& eCommand, const int& lCount, float* pData)
- {
- size_t lFloats = lCount * m_lSizeofFloat;
- size_t lMem = m_lSizeofBYTE + m_lSizeofLONG + lFloats;
-
- CheckBufferSize(lMem);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
- *((int*)(m_pBuffer + m_lPosition)) = lCount; m_lPosition += m_lSizeofLONG;
-
- memcpy(m_pBuffer + m_lPosition, pData, lFloats);
- m_lPosition += lFloats;
- }
- inline void Write(const CommandType& eCommand, const int& lCount, double* pData)
- {
- size_t lFloats = lCount * m_lSizeofDouble;
- size_t lMem = m_lSizeofBYTE + m_lSizeofLONG + lFloats;
-
- CheckBufferSize(lMem);
-
- *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
- *((int*)(m_pBuffer + m_lPosition)) = lCount; m_lPosition += m_lSizeofLONG;
-
- memcpy(m_pBuffer + m_lPosition, pData, lFloats);
- m_lPosition += lFloats;
- }
-
- inline void Write(CMetafile& oMeta)
- {
- LONG lPos = oMeta.GetPosition();
- CheckBufferSize(lPos);
-
- memcpy(m_pBuffer + m_lPosition, oMeta.GetData(), lPos);
- m_lPosition += lPos;
+ return *this;
}
};
+
+ inline double FABS(double dVal)
+ {
+ return (dVal >= 0) ? dVal : -dVal;
+ }
+ inline int round(double dVal)
+ {
+ return (int)(dVal + 0.5);
+ }
}
#endif // _ASC_HTMLRENDERER_COMMON_H_
diff --git a/HtmlRenderer/src/Common2.h b/HtmlRenderer/src/Common2.h
new file mode 100644
index 0000000000..fc23180a6d
--- /dev/null
+++ b/HtmlRenderer/src/Common2.h
@@ -0,0 +1,669 @@
+#ifndef _ASC_HTMLRENDERER_COMMON2_H_
+#define _ASC_HTMLRENDERER_COMMON2_H_
+
+#include "Common.h"
+#include "../../DesktopEditor/raster/BgraFrame.h"
+#include "../../DesktopEditor/xml/include/xmlutils.h"
+
+namespace NSHtmlRenderer
+{
+ static RECT GetImageBounds(CBgraFrame* pFrame)
+ {
+ BYTE* pBuffer = pFrame->get_Data();
+ LONG lWidth = (LONG)pFrame->get_Width();
+ LONG lHeight = (LONG)pFrame->get_Height();
+
+ RECT rect;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = lWidth - 1;
+ rect.bottom = lHeight - 1;
+
+ // top
+ unsigned int* pData = (unsigned int*)pBuffer;
+ for (; rect.top < lHeight; rect.top++)
+ {
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lWidth; ++i, ++pData)
+ {
+ if (*pData != 0x00)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.top >= lHeight)
+ rect.top = (lHeight - 1);
+
+ // bottom
+ for (; rect.bottom >= rect.top; rect.bottom--)
+ {
+ pData = (unsigned int*)pBuffer;
+ pData += (lWidth * rect.bottom);
+
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lWidth; ++i, ++pData)
+ {
+ if (*pData != 0x00)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.bottom < rect.top)
+ rect.bottom = rect.top;
+
+ LONG lDelta = rect.bottom - rect.top + 1;
+
+ // left
+ for (; rect.left < lWidth; rect.left++)
+ {
+ pData = (unsigned int*)(pBuffer + 4 * lWidth * rect.top);
+ pData += rect.left;
+
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
+ {
+ if (*pData != 0x00)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.left >= lWidth)
+ rect.left = lWidth - 1;
+
+ // right
+ for (; rect.right >= rect.left; rect.right--)
+ {
+ pData = (unsigned int*)(pBuffer + 4 * lWidth * rect.top);
+ pData += rect.right;
+
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
+ {
+ if (*pData != 0x00)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.right < rect.left)
+ rect.right = rect.left;
+
+ return rect;
+ }
+
+ static RECT GetImageBounds2(CBgraFrame* pFrame, BYTE* pCache)
+ {
+ BYTE* pBuffer = pFrame->get_Data();
+ LONG lWidth = (LONG)pFrame->get_Width();
+ LONG lHeight = (LONG)pFrame->get_Height();
+
+ RECT rect;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = lWidth - 1;
+ rect.bottom = lHeight - 1;
+
+ // top
+ unsigned int** pData = (unsigned int**)pBuffer;
+ unsigned int** pDataSrc = (unsigned int**)pCache;
+ for (; rect.top < lHeight; rect.top++)
+ {
+ if (0 != memcmp((void*)pData, (void*)pDataSrc, 4 * lWidth))
+ break;
+
+ pData += lWidth;
+ pDataSrc += lWidth;
+ }
+ if (rect.top >= lHeight)
+ rect.top = (lHeight - 1);
+
+ // bottom
+ for (; rect.bottom >= rect.top; rect.bottom--)
+ {
+ pData = (unsigned int**)pBuffer;
+ pData += (lWidth * rect.bottom);
+ pDataSrc = (unsigned int**)pCache;
+ pDataSrc += (lWidth * rect.bottom);
+
+ if (0 != memcmp((void*)pData, (void*)pDataSrc, 4 * lWidth))
+ break;
+ }
+ if (rect.bottom < rect.top)
+ rect.bottom = rect.top;
+
+ LONG lDelta = rect.bottom - rect.top + 1;
+
+ // left
+ for (; rect.left < lWidth; rect.left++)
+ {
+ pData = (unsigned int**)(pBuffer + 4 * lWidth * rect.top);
+ pData += rect.left;
+ pDataSrc = (unsigned int**)(pCache + 4 * lWidth * rect.top);
+ pDataSrc += rect.left;
+
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lDelta; ++i, pData += lWidth, pDataSrc += lWidth)
+ {
+ if (*pData != *pDataSrc)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.left >= lWidth)
+ rect.left = lWidth - 1;
+
+ // right
+ for (; rect.right >= rect.left; rect.right--)
+ {
+ pData = (unsigned int**)(pBuffer + 4 * lWidth * rect.top);
+ pData += rect.right;
+
+ pDataSrc = (unsigned int**)(pCache + 4 * lWidth * rect.top);
+ pDataSrc += rect.right;
+
+ bool bIsBreak = false;
+ for (LONG i = 0; i < lDelta; ++i, pData += lWidth)
+ {
+ if (*pData != *pDataSrc)
+ {
+ bIsBreak = true;
+ break;
+ }
+ }
+ if (bIsBreak)
+ break;
+ }
+ if (rect.right < rect.left)
+ rect.right = rect.left;
+
+ return rect;
+ }
+}
+
+namespace NSHtmlRenderer
+{
+ class CMetafile
+ {
+ public:
+ enum CommandType
+ {
+ // pen
+ ctPenXML = 0,
+ ctPenColor = 1,
+ ctPenAlpha = 2,
+ ctPenSize = 3,
+ ctPenDashStyle = 4,
+ ctPenLineStartCap = 5,
+ ctPenLineEndCap = 6,
+ ctPenLineJoin = 7,
+ ctPenDashPatern = 8,
+ ctPenDashPatternCount = 9,
+ ctPenDashOffset = 10,
+ ctPenAlign = 11,
+ ctPenMiterLimit = 12,
+
+ // brush
+ ctBrushXML = 20,
+ ctBrushType = 21,
+ ctBrushColor1 = 22,
+ ctBrushColor2 = 23,
+ ctBrushAlpha1 = 24,
+ ctBrushAlpha2 = 25,
+ ctBrushTexturePath = 26,
+ ctBrushTextureAlpha = 27,
+ ctBrushTextureMode = 28,
+ ctBrushRectable = 29,
+ ctBrushAngle = 30,
+ ctBrushSubColors = 31,
+
+ // font
+ ctFontXML = 40,
+ ctFontName = 41,
+ ctFontSize = 42,
+ ctFontStyle = 43,
+ ctFontPath = 44,
+ ctFontGID = 45,
+ ctFontCharSpace = 46,
+
+ // shadow
+ ctShadowXML = 50,
+ ctShadowVisible = 51,
+ ctShadowDistanceX = 52,
+ ctShadowDistanceY = 53,
+ ctShadowBlurSize = 54,
+ ctShadowColor = 55,
+ ctShadowAlpha = 56,
+
+ // edge
+ ctEdgeXML = 70,
+ ctEdgeVisible = 71,
+ ctEdgeDistance = 72,
+ ctEdgeColor = 73,
+ ctEdgeAlpha = 74,
+
+ // text
+ ctDrawText = 80,
+ ctDrawTextEx = 81,
+
+ // pathcommands
+ ctPathCommandMoveTo = 91,
+ ctPathCommandLineTo = 92,
+ ctPathCommandLinesTo = 93,
+ ctPathCommandCurveTo = 94,
+ ctPathCommandCurvesTo = 95,
+ ctPathCommandArcTo = 96,
+ ctPathCommandClose = 97,
+ ctPathCommandEnd = 98,
+ ctDrawPath = 99,
+ ctPathCommandStart = 100,
+ ctPathCommandGetCurrentPoint = 101,
+ ctPathCommandText = 102,
+ ctPathCommandTextEx = 103,
+
+ // image
+ ctDrawImage = 110,
+ ctDrawImageFromFile = 111,
+
+ ctSetParams = 120,
+
+ ctBeginCommand = 121,
+ ctEndCommand = 122,
+
+ ctSetTransform = 130,
+ ctResetTransform = 131,
+
+ ctClipMode = 140,
+
+ ctCommandLong1 = 150,
+ ctCommandDouble1 = 151,
+ ctCommandString1 = 152,
+ ctCommandLong2 = 153,
+ ctCommandDouble2 = 154,
+ ctCommandString2 = 155,
+
+ ctCommandTextLine = 160,
+ ctCommandTextTransform = 161,
+ ctCommandTextLineEnd = 162,
+
+ ctCommandTextClipRectReset = 163,
+ ctCommandTextClipRect = 164,
+
+ ctError = 255
+ };
+
+ private:
+
+ // сам метафайл
+ BYTE* m_pBuffer;
+ BYTE* m_pBufferMem;
+
+ size_t m_lPosition;
+ size_t m_lSize;
+
+ LONG m_lSizeofDouble;
+ LONG m_lSizeofFloat;
+ LONG m_lSizeofLONG;
+ LONG m_lSizeofBYTE;
+
+ public:
+ double m_fWidth;
+ double m_fHeight;
+
+ public:
+ CMetafile()
+ {
+ Clear();
+
+ m_lSizeofDouble = sizeof(double);
+ m_lSizeofFloat = sizeof(float);
+ m_lSizeofLONG = sizeof(int);
+ m_lSizeofBYTE = sizeof(BYTE);
+ }
+ ~CMetafile()
+ {
+ RELEASEARRAYOBJECTS(m_pBuffer);
+ }
+
+ public:
+
+ inline LONG GetPosition()
+ {
+ return (LONG)m_lPosition;
+ }
+ inline BYTE* GetData()
+ {
+ return m_pBuffer;
+ }
+ inline void ClearNoAttack()
+ {
+ m_lPosition = 0;
+ m_pBufferMem = m_pBuffer;
+ }
+
+ inline void Clear()
+ {
+ m_lSize = 0;
+ m_lPosition = 0;
+
+ m_pBuffer = NULL;
+ m_pBufferMem = NULL;
+ }
+ inline void Seek(LONG lPos)
+ {
+ m_lPosition = (size_t)lPos;
+ m_pBufferMem = m_pBuffer + m_lPosition;
+ }
+
+ inline void CheckBufferSize(size_t lPlus)
+ {
+ if (NULL != m_pBuffer)
+ {
+ size_t nNewSize = m_lPosition + lPlus;
+
+ if (nNewSize >= m_lSize)
+ {
+ while (nNewSize >= m_lSize)
+ {
+ m_lSize *= 2;
+ }
+
+ BYTE* pNew = new BYTE[m_lSize];
+ memcpy(pNew, m_pBuffer, m_lPosition);
+
+ RELEASEARRAYOBJECTS(m_pBuffer);
+ m_pBuffer = pNew;
+ }
+ }
+ else
+ {
+ m_lSize = 1000;
+ m_pBuffer = new BYTE[m_lSize];
+
+ CheckBufferSize(lPlus);
+ }
+ }
+
+ inline void WriteCommandType(const CommandType& eType)
+ {
+ CheckBufferSize(m_lSizeofBYTE);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+ }
+
+ //
+ inline void WriteBYTE_nocheck(const BYTE& lValue)
+ {
+ *(m_pBuffer + m_lPosition) = lValue;
+ m_lPosition += m_lSizeofBYTE;
+ }
+ inline void WriteLONG_nocheck(const int& lValue)
+ {
+ *((int*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += m_lSizeofLONG;
+ }
+ inline void WriteUSHORT_nocheck(const USHORT& lValue)
+ {
+ *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(USHORT);
+ }
+ inline void WriteWCHAR_nocheck(const WCHAR& lValue)
+ {
+ *((WCHAR*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(WCHAR);
+ }
+ inline void WriteWCHAR_nocheck2(const int& lValue)
+ {
+ if (lValue < 0x10000)
+ {
+ *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += 2;
+ }
+ else
+ {
+ int code = lValue - 0x10000;
+ *((USHORT*)(m_pBuffer + m_lPosition)) = 0xD800 | ((code >> 10) & 0x03FF);
+ *((USHORT*)(m_pBuffer + m_lPosition + 2)) = 0xDC00 | (code & 0x03FF);
+ m_lPosition += 4;
+ }
+ }
+ inline void WriteDouble_nocheck(const double& dValue)
+ {
+ // здесь никаких даблов. Сплошные округления
+ LONG lValue = (LONG)(dValue * 10000);
+ WriteLONG_nocheck(lValue);
+ return;
+
+ CheckBufferSize(m_lSizeofDouble);
+
+ *((double*)(m_pBuffer + m_lPosition)) = dValue;
+ m_lPosition += m_lSizeofDouble;
+ }
+ inline void WriteDouble2_nocheck(const double& dValue)
+ {
+ // здесь никаких даблов. Сплошные округления
+ SHORT lValue = (SHORT)(dValue * 100);
+ *((SHORT*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(SHORT);
+ }
+ //
+ inline void WriteBYTE(const BYTE& lValue)
+ {
+ CheckBufferSize(m_lSizeofBYTE);
+
+ *(m_pBuffer + m_lPosition) = lValue;
+ m_lPosition += m_lSizeofBYTE;
+ }
+ inline void WriteLONG(const int& lValue)
+ {
+ CheckBufferSize(m_lSizeofLONG);
+
+ *((int*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += m_lSizeofLONG;
+ }
+ inline void WriteUSHORT(const USHORT& lValue)
+ {
+ CheckBufferSize(sizeof(USHORT));
+
+ *((USHORT*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(USHORT);
+ }
+ inline void WriteWCHAR(const WCHAR& lValue)
+ {
+ CheckBufferSize(sizeof(WCHAR));
+
+ *((WCHAR*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(WCHAR);
+ }
+ inline void WriteDouble(const double& dValue)
+ {
+ // здесь никаких даблов. Сплошные округления
+ int lValue = (int)(dValue * 10000);
+ WriteLONG(lValue);
+ return;
+
+ CheckBufferSize(m_lSizeofDouble);
+
+ *((double*)(m_pBuffer + m_lPosition)) = dValue;
+ m_lPosition += m_lSizeofDouble;
+ }
+ inline void WriteDouble2(const double& dValue)
+ {
+ // здесь никаких даблов. Сплошные округления
+ SHORT lValue = (SHORT)(dValue * 100);
+ CheckBufferSize(sizeof(SHORT));
+
+ *((SHORT*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += sizeof(SHORT);
+ }
+ inline void WriteFloat(const float& fValue)
+ {
+ CheckBufferSize(m_lSizeofFloat);
+
+ *((float*)(m_pBuffer + m_lPosition)) = fValue;
+ m_lPosition += m_lSizeofFloat;
+ }
+ inline void WriteString(wchar_t* bstrValue)
+ {
+ int lSize = (int)wcslen(bstrValue) + 1;
+
+ int lSizeMem = lSize * sizeof(wchar_t);
+
+ CheckBufferSize(m_lSizeofLONG + lSizeMem);
+
+ *((int*)(m_pBuffer + m_lPosition)) = lSizeMem;
+ m_lPosition += m_lSizeofLONG;
+
+ memcpy(m_pBuffer + m_lPosition, bstrValue, lSizeMem);
+ m_lPosition += lSizeMem;
+ }
+
+ inline void WriteBYTE(const CommandType& eType, const BYTE& lValue)
+ {
+ CheckBufferSize(2 * m_lSizeofBYTE);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+
+ *(m_pBuffer + m_lPosition) = lValue;
+ m_lPosition += m_lSizeofBYTE;
+ }
+ inline void WriteLONG(const CommandType& eType, const int& lValue)
+ {
+ CheckBufferSize(m_lSizeofBYTE + m_lSizeofLONG);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+
+ *((int*)(m_pBuffer + m_lPosition)) = lValue;
+ m_lPosition += m_lSizeofLONG;
+ }
+ inline void WriteDouble(const CommandType& eType, const double& dValue)
+ {
+ CheckBufferSize(m_lSizeofBYTE + m_lSizeofDouble);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+
+ *((double*)(m_pBuffer + m_lPosition)) = dValue;
+ m_lPosition += m_lSizeofDouble;
+ }
+ inline void WriteFloat(const CommandType& eType, const float& fValue)
+ {
+ CheckBufferSize(m_lSizeofBYTE + m_lSizeofFloat);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+
+ *((float*)(m_pBuffer + m_lPosition)) = fValue;
+ m_lPosition += m_lSizeofFloat;
+ }
+ inline void WriteString(const CommandType& eType, wchar_t* bstrValue)
+ {
+ int lSize = (int)wcslen(bstrValue) + 1;
+
+ int lSizeMem = lSize * sizeof(wchar_t);
+
+ CheckBufferSize(m_lSizeofBYTE + m_lSizeofLONG + lSizeMem);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eType;
+ m_lPosition += m_lSizeofBYTE;
+
+ *((int*)(m_pBuffer + m_lPosition)) = lSizeMem;
+ m_lPosition += m_lSizeofLONG;
+
+ memcpy(m_pBuffer + m_lPosition, bstrValue, lSizeMem);
+ m_lPosition += lSizeMem;
+ }
+
+ inline void Write(const BYTE* pData, const LONG& lLen)
+ {
+ CheckBufferSize((size_t)lLen);
+ memcpy(m_pBuffer + m_lPosition, pData, lLen);
+ m_lPosition += lLen;
+ }
+
+ inline void Write(const CommandType& eCommand, const double& f1, const double& f2)
+ {
+ size_t lMem = m_lSizeofBYTE + 2 * m_lSizeofDouble;
+
+ CheckBufferSize(lMem);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
+ *((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += m_lSizeofDouble;
+ }
+
+ inline void Write(const CommandType& eCommand, const double& f1, const double& f2, const double& f3, const double& f4, const double& f5, const double& f6)
+ {
+ size_t lMem = m_lSizeofBYTE + 6 * m_lSizeofDouble;
+
+ CheckBufferSize(lMem);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
+ *((double*)(m_pBuffer + m_lPosition))= f1; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f2; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f3; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f4; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f5; m_lPosition += m_lSizeofDouble;
+ *((double*)(m_pBuffer + m_lPosition))= f6; m_lPosition += m_lSizeofDouble;
+ }
+
+ inline void Write(const CommandType& eCommand, const int& lCount, float* pData)
+ {
+ size_t lFloats = lCount * m_lSizeofFloat;
+ size_t lMem = m_lSizeofBYTE + m_lSizeofLONG + lFloats;
+
+ CheckBufferSize(lMem);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
+ *((int*)(m_pBuffer + m_lPosition)) = lCount; m_lPosition += m_lSizeofLONG;
+
+ memcpy(m_pBuffer + m_lPosition, pData, lFloats);
+ m_lPosition += lFloats;
+ }
+ inline void Write(const CommandType& eCommand, const int& lCount, double* pData)
+ {
+ size_t lFloats = lCount * m_lSizeofDouble;
+ size_t lMem = m_lSizeofBYTE + m_lSizeofLONG + lFloats;
+
+ CheckBufferSize(lMem);
+
+ *(m_pBuffer + m_lPosition) = (BYTE)eCommand; m_lPosition += m_lSizeofBYTE;
+ *((int*)(m_pBuffer + m_lPosition)) = lCount; m_lPosition += m_lSizeofLONG;
+
+ memcpy(m_pBuffer + m_lPosition, pData, lFloats);
+ m_lPosition += lFloats;
+ }
+
+ inline void Write(CMetafile& oMeta)
+ {
+ LONG lPos = oMeta.GetPosition();
+ CheckBufferSize(lPos);
+
+ memcpy(m_pBuffer + m_lPosition, oMeta.GetData(), lPos);
+ m_lPosition += lPos;
+ }
+ };
+}
+
+#endif // _ASC_HTMLRENDERER_COMMON2_H_
diff --git a/HtmlRenderer/src/SVGWriter2.h b/HtmlRenderer/src/SVGWriter2.h
index 6522db6ad7..63a84482f0 100644
--- a/HtmlRenderer/src/SVGWriter2.h
+++ b/HtmlRenderer/src/SVGWriter2.h
@@ -1,6 +1,7 @@
#ifndef _ASC_HTMLRENDERER_SVGWRITER2_H_
#define _ASC_HTMLRENDERER_SVGWRITER2_H_
+#include "Common2.h"
#include "SVGWriter.h"
#include "../../DesktopEditor/graphics/GraphicsRenderer.h"
diff --git a/HtmlRenderer/test/main.cpp b/HtmlRenderer/test/main.cpp
index 4275fe3f34..1b1e6cef80 100644
--- a/HtmlRenderer/test/main.cpp
+++ b/HtmlRenderer/test/main.cpp
@@ -8,45 +8,70 @@
#include "../../PdfWriter/PdfRenderer.h"
#include "../include/HTMLRenderer3.h"
+#include "../include/ASCSVGWriter.h"
+#include "../../DesktopEditor/raster/Metafile/MetaFile.h"
+
int main(int argc, char *argv[])
{
- //QCoreApplication a(argc, argv);
-
-#if 0
- //std::wstring sFile = L"\\\\KIRILLOV8\\_Office\\PDF\\Android intro(2p).pdf";
- std::wstring sFile = L"\\\\kirillov8\\_Office\\PDF\\Main Window(15p).pdf";
- //std::wstring sFile = L"D:\\knut.djvu";
- //std::wstring sFile = L"D:\\bankomats.xps";
- std::wstring sDst = L"D:\\test\\Document";
-#endif
-
-#if 1
- //std::wstring sFile = L"/home/oleg/activex/Android intro(2p).pdf";
- //std::wstring sFile = L"/home/oleg/activex/knut.djvu";
- std::wstring sFile = L"/home/oleg/activex/bankomats.xps";
- std::wstring sDst = L"/home/oleg/activex/1";
-#endif
-
CApplicationFonts oFonts;
oFonts.Initialize();
+#if 0
+
+ NSHtmlRenderer::CASCSVGWriter oWriterSVG;
+ oWriterSVG.SetFontManager(oFonts.GenerateFontManager());
+
+ MetaFile::CMetaFile oMetafile(&oFonts);
+
+ oMetafile.LoadFromFile(L"D:\\2\\ppt\\media\\image4.wmf");
+
+ double x = 0, y = 0, w = 0, h = 0;
+ oMetafile.GetBounds(&x, &y, &w, &h);
+
+ oWriterSVG.put_Width(100000);
+ oWriterSVG.put_Height(100000);
+ oMetafile.DrawOnRenderer(&oWriterSVG, 0, 0, 100000, 100000);
+
+ oWriterSVG.SaveFile(L"D:\\oleg.svg");
+
+ return 0;
+
+#endif
+
+
+ //QCoreApplication a(argc, argv);
+#ifdef WIN32
+ //std::wstring sFile = L"\\\\KIRILLOV8\\_Office\\PDF\\Android intro(2p).pdf";
+ //std::wstring sFile = L"D:\\activex\\Pi(1p).pdf";
+ //std::wstring sFile = L"\\\\192.168.3.208\\allusers\\Files\\PDF\\AllPDF\\asia.pdf";
+ //std::wstring sFile = L"D:\\knut.djvu";
+ std::wstring sFile = L"D:\\bankomats.xps";
+ std::wstring sDst = L"D:\\test\\Document";
+#else
+ //std::wstring sFile = L"/home/oleg/activex/Android intro(2p).pdf";
+ //std::wstring sFile = L"/home/oleg/activex/Pi(1p).pdf";
+ std::wstring sFile = L"/home/oleg/activex/knut.djvu";
+ //std::wstring sFile = L"/home/oleg/activex/bankomats.xps";
+ std::wstring sDst = L"/home/oleg/activex/1";
+#endif
+
#if 0
PdfReader::CPdfReader oReader(&oFonts);
oReader.SetTempFolder(sDst.c_str());
#endif
-#if 0
+#if 1
CDjVuFile oReader;
#endif
-#if 1
+#if 0
CXpsFile oReader(&oFonts);
oReader.SetTempFolder(sDst.c_str());
#endif
bool bResult = oReader.LoadFromFile(sFile.c_str());
-#if 0
+#if 1
NSHtmlRenderer::CASCHTMLRenderer3 oHtmlRenderer;
oHtmlRenderer.CreateOfficeFile(sDst);
#else
@@ -75,7 +100,7 @@ int main(int argc, char *argv[])
oHtmlRenderer.EndCommand(c_nPageType);
}
-#if 0
+#if 1
oHtmlRenderer.CloseFile();
#else
oHtmlRenderer.SaveToFile(L"/home/oleg/activex/1/1.pdf");
diff --git a/HtmlRenderer/test/test.pro b/HtmlRenderer/test/test.pro
index 3341b2c019..ff9244e963 100644
--- a/HtmlRenderer/test/test.pro
+++ b/HtmlRenderer/test/test.pro
@@ -12,6 +12,8 @@ TARGET = test
CONFIG += console
CONFIG -= app_bundle
+CONFIG += c++11
+
DEFINES += PDFREADER_USE_DYNAMIC_LIBRARY
DEFINES += PDFWRITER_USE_DYNAMIC_LIBRARY
DEFINES += XPS_USE_DYNAMIC_LIBRARY
@@ -50,6 +52,7 @@ linux-g++:!contains(QMAKE_HOST.arch, x86_64):{
}
LIBS += -L$$DESTINATION_SDK_PATH -lgraphics
+LIBS += -L$$DESTINATION_SDK_PATH -lASCOfficeUtilsLib
LIBS += -L$$DESTINATION_SDK_PATH -lHtmlRenderer
LIBS += -L$$DESTINATION_SDK_PATH -lPdfReader
LIBS += -L$$DESTINATION_SDK_PATH -lDjVuFile
@@ -63,4 +66,8 @@ LIBS += -lgdi32 \
-lshell32
}
-SOURCES += main.cpp
+SOURCES += main.cpp \
+ ../src/ASCSVGWriter.cpp
+
+HEADERS += \
+ ../include/ASCSVGWriter.h