полностью реализован механизм билда статической и динамической библиотеки

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63667 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
Oleg.Korshul
2015-07-23 12:18:00 +00:00
committed by Alexander Trofimov
parent b83109f7b9
commit 831ab54516
18 changed files with 12311 additions and 0 deletions

4
.gitattributes vendored
View File

@ -7477,6 +7477,10 @@ DoctRenderer/COMMON/Joiner/bin/Debug/Joiner.exe svn_mime_002dtype=application%2F
DoctRenderer/COMMON/JoinerPPT/bin/Debug/Joiner.exe svn_mime_002dtype=application%2Foctet-stream
DoctRenderer/COMMON/JoinerXLS/bin/Debug/Joiner.exe svn_mime_002dtype=application%2Foctet-stream
DoctRenderer/COMMON/TestConsole/Ionic.Zip.Reduced.dll svn_mime_002dtype=application%2Foctet-stream
/HtmlRenderer svnc_tsvn_003alogminsize=5
HtmlRenderer/include svnc_tsvn_003alogminsize=5
HtmlRenderer/src svnc_tsvn_003alogminsize=5
HtmlRenderer/test svnc_tsvn_003alogminsize=5
OfficeCore/Fonts/FreeType/freetype242_vs2005.lib svn_mime_002dtype=application%2Foctet-stream
OfficeCore/Test/TestConsole/bin/Debug/Interop.OfficeCore.dll svn_mime_002dtype=application%2Foctet-stream
OfficeCore/Test/TestConsole/bin/Debug/TestConsole.exe svn_mime_002dtype=application%2Foctet-stream

View File

@ -0,0 +1,116 @@
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-19T10:22:14
#
#-------------------------------------------------
QT -= core
QT -= gui
VERSION = 1.0.0.1
TARGET = HtmlRenderer
TEMPLATE = lib
QMAKE_CXXFLAGS += -std=c++11
#CONFIG += staticlib
CONFIG += shared
############### destination path ###############
DESTINATION_SDK_PATH = $$PWD/../SDK/lib
# WINDOWS
win32:contains(QMAKE_TARGET.arch, x86_64):{
CONFIG(debug, debug|release) {
DESTDIR = $$DESTINATION_SDK_PATH/win_64/DEBUG
} else {
DESTDIR = $$DESTINATION_SDK_PATH/win_64
}
}
win32:!contains(QMAKE_TARGET.arch, x86_64):{
CONFIG(debug, debug|release) {
DESTDIR = $$DESTINATION_SDK_PATH/win_32/DEBUG
} else {
DESTDIR = $$DESTINATION_SDK_PATH/win_32
}
}
linux-g++:contains(QMAKE_HOST.arch, x86_64):{
DESTDIR = $$DESTINATION_SDK_PATH/linux_64
}
linux-g++:!contains(QMAKE_HOST.arch, x86_64):{
DESTDIR = $$DESTINATION_SDK_PATH/linux_32
}
################################################
############# dynamic dependencies #############
shared {
DEFINES += PDF_USE_DYNAMIC_LIBRARY
LIBS += -L$$DESTDIR -lASCOfficeUtilsLib
LIBS += -L$$DESTDIR -lgraphics
LIBS += -L$$DESTDIR -llibxml
message(dynamic)
win32 {
LIBS += -lgdi32 \
-ladvapi32 \
-luser32 \
-lshell32
TARGET_EXT = .dll
}
linux-g++ | linux-g++-64 | linux-g++-32 {
CONFIG += plugin
TARGET_EXT = .so
}
}
################################################
#################### WINDOWS #####################
win32 {
DEFINES += \
WIN32
}
##################################################
################### LINUX ########################
linux-g++ | linux-g++-64 | linux-g++-32 {
DEFINES += \
LINUX \
_LINUX \
_LINUX_QT
}
##################################################
INCLUDEPATH += \
../../DesktopEditor/agg-2.4/include \
../../DesktopEditor/freetype-2.5.2/include
SOURCES += \
src/HTMLRenderer3.cpp
HEADERS += \
src/CanvasWriter.h \
src/Common.h \
src/Document.h \
src/FontManager.h \
src/FontManagerBase.h \
src/SVGWriter.h \
src/SVGWriter2.h \
src/Text.h \
src/VectorGraphicsWriter.h \
src/VectorGraphicsWriter2.h \
src/VMLWriter.h \
src/Writer.h \
include/HTMLRenderer3.h
unix {
target.path = /usr/lib
INSTALLS += target
}

View File

@ -0,0 +1,152 @@
#ifndef _ASC_HTMLRENDERER3_H_
#define _ASC_HTMLRENDERER3_H_
#include "../../../DesktopEditor/graphics/IRenderer.h"
namespace NSHtmlRenderer
{
class CASCHTMLRenderer3_Private;
class CASCHTMLRenderer3 : public IRenderer
{
public:
CASCHTMLRenderer3();
virtual ~CASCHTMLRenderer3();
public:
// тип рендерера-----------------------------------------------------------------------------
virtual HRESULT get_Type(LONG* lType);
//-------- Функции для работы со страницей --------------------------------------------------
virtual HRESULT NewPage();
virtual HRESULT get_Height(double* dHeight);
virtual HRESULT put_Height(const double& dHeight);
virtual HRESULT get_Width(double* dWidth);
virtual HRESULT put_Width(const double& dWidth);
virtual HRESULT get_DpiX(double* dDpiX);
virtual HRESULT get_DpiY(double* dDpiY);
// pen --------------------------------------------------------------------------------------
virtual HRESULT get_PenColor(LONG* lColor);
virtual HRESULT put_PenColor(const LONG& lColor);
virtual HRESULT get_PenAlpha(LONG* lAlpha);
virtual HRESULT put_PenAlpha(const LONG& lAlpha);
virtual HRESULT get_PenSize(double* dSize);
virtual HRESULT put_PenSize(const double& dSize);
virtual HRESULT get_PenDashStyle(BYTE* val);
virtual HRESULT put_PenDashStyle(const BYTE& val);
virtual HRESULT get_PenLineStartCap(BYTE* val);
virtual HRESULT put_PenLineStartCap(const BYTE& val);
virtual HRESULT get_PenLineEndCap(BYTE* val);
virtual HRESULT put_PenLineEndCap(const BYTE& val);
virtual HRESULT get_PenLineJoin(BYTE* val);
virtual HRESULT put_PenLineJoin(const BYTE& val);
virtual HRESULT get_PenDashOffset(double* dOffset);
virtual HRESULT put_PenDashOffset(const double& dOffset);
virtual HRESULT get_PenAlign(LONG* lAlign);
virtual HRESULT put_PenAlign(const LONG& lAlign);
virtual HRESULT get_PenMiterLimit(double* dOffset);
virtual HRESULT put_PenMiterLimit(const double& dOffset);
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount);
// brush ------------------------------------------------------------------------------------
virtual HRESULT get_BrushType(LONG* lType);
virtual HRESULT put_BrushType(const LONG& lType);
virtual HRESULT get_BrushColor1(LONG* lColor);
virtual HRESULT put_BrushColor1(const LONG& lColor);
virtual HRESULT get_BrushAlpha1(LONG* lAlpha);
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha);
virtual HRESULT get_BrushColor2(LONG* lColor);
virtual HRESULT put_BrushColor2(const LONG& lColor);
virtual HRESULT get_BrushAlpha2(LONG* lAlpha);
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha);
virtual HRESULT get_BrushTexturePath(std::wstring* bsPath);
virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath);
virtual HRESULT get_BrushTextureMode(LONG* lMode);
virtual HRESULT put_BrushTextureMode(const LONG& lMode);
virtual HRESULT get_BrushTextureAlpha(LONG* lTxAlpha);
virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha);
virtual HRESULT get_BrushLinearAngle(double* dAngle);
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height);
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height);
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount);
// font -------------------------------------------------------------------------------------
virtual HRESULT get_FontName(std::wstring* bsName);
virtual HRESULT put_FontName(const std::wstring& bsName);
virtual HRESULT get_FontPath(std::wstring* bsName);
virtual HRESULT put_FontPath(const std::wstring& bsName);
virtual HRESULT get_FontSize(double* dSize);
virtual HRESULT put_FontSize(const double& dSize);
virtual HRESULT get_FontStyle(LONG* lStyle);
virtual HRESULT put_FontStyle(const LONG& lStyle);
virtual HRESULT get_FontStringGID(INT* bGID);
virtual HRESULT put_FontStringGID(const INT& bGID);
virtual HRESULT get_FontCharSpace(double* dSpace);
virtual HRESULT put_FontCharSpace(const double& dSpace);
virtual HRESULT get_FontFaceIndex(int* lFaceIndex);
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex);
//-------- Функции для вывода текста --------------------------------------------------------
virtual HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h);
//-------- Маркеры для команд ---------------------------------------------------------------
virtual HRESULT BeginCommand(const DWORD& lType);
virtual HRESULT EndCommand(const DWORD& lType);
//-------- Функции для работы с Graphics Path -----------------------------------------------
virtual HRESULT PathCommandMoveTo(const double& x, const double& y);
virtual HRESULT PathCommandLineTo(const double& x, const double& y);
virtual HRESULT PathCommandLinesTo(double* points, const int& count);
virtual HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3);
virtual HRESULT PathCommandCurvesTo(double* points, const int& count);
virtual HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle);
virtual HRESULT PathCommandClose();
virtual HRESULT PathCommandEnd();
virtual HRESULT DrawPath(const LONG& nType);
virtual HRESULT PathCommandStart();
virtual HRESULT PathCommandGetCurrentPoint(double* x, double* y);
virtual HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT PathCommandTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h);
//-------- Функции для вывода изображений ---------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255);
// transform --------------------------------------------------------------------------------
virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6);
virtual HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF);
virtual HRESULT ResetTransform();
// -----------------------------------------------------------------------------------------
virtual HRESULT get_ClipMode(LONG* plMode);
virtual HRESULT put_ClipMode(const LONG& lMode);
// additiaonal params ----------------------------------------------------------------------
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand);
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand);
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand);
// owner params ----------------------------------------------------------------------
virtual HRESULT get_Mode(LONG *plMode);
virtual HRESULT put_Mode(LONG lMode);
virtual HRESULT CreateOfficeFile(std::wstring bsFileName);
virtual HRESULT CloseFile();
virtual HRESULT SetAdditionalParam(std::string sParamName, int nValue);
virtual HRESULT SetAdditionalParam(std::string sParamName, const std::wstring& sParam);
protected:
CASCHTMLRenderer3_Private* m_pInternal;
};
}
#endif // _ASC_HTMLRENDERER3_H_

View File

@ -0,0 +1,212 @@
#ifndef _ASC_HTMLRENDERER_CANVASWRITER_H_
#define _ASC_HTMLRENDERER_CANVASWRITER_H_
#include "Common.h"
#include "../../../DesktopEditor/graphics/GraphicsPath.h"
namespace NSHtmlRenderer
{
class CCanvasWriter
{
public:
NSStringUtils::CStringBuilder m_oPath;
NSStringUtils::CStringBuilder m_oDocument;
LONG m_lCurDocumentID;
LONG m_lClippingPath;
bool m_bIsClipping;
LONG m_lClipMode;
bool m_bIsMoveTo;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
double m_lWidth;
double m_lHeight;
double m_dDpiX;
double m_dDpiY;
public:
CCanvasWriter() : m_oPath(), m_oDocument()
{
m_lCurDocumentID = 0;
m_lClippingPath = 0;
m_pPen = NULL;
m_pBrush = NULL;
m_dDpiX = 96;
m_dDpiY = 96;
m_lClipMode = c_nWindingFillMode;
m_bIsClipping = false;
m_bIsMoveTo = false;
}
void SetSettings(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush)
{
m_pPen = pPen;
m_pBrush = pBrush;
}
void CloseFile(std::wstring strFile = L"")
{
if (!strFile.empty())
{
NSFile::CFileBinary::SaveToFile(strFile, m_oDocument.GetData());
}
m_oDocument.ClearNoAttack();
m_oPath.ClearNoAttack();
}
void NewDocument(double& dWidth, double& dHeigth)
{
CloseFile(L"");
m_lWidth = (int)dWidth;
m_lHeight = (int)dHeigth;
}
public:
inline void WritePathEnd()
{
}
inline void WritePathStart()
{
m_bIsMoveTo = false;
m_oDocument.WriteString(L"b(c);\n", 6);
}
void WritePathClose()
{
m_oDocument.WriteString(L"x(c);\n", 6);
}
void WritePathMoveTo(double& x, double& y)
{
m_oDocument.WriteString(L"m(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oDocument);
m_oDocument.WriteString(L");\n", 3);
m_bIsMoveTo = true;
}
void WritePathLineTo(double& x, double& y)
{
if (false == m_bIsMoveTo)
WritePathMoveTo(x, y);
m_oDocument.WriteString(L"l(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oDocument);
m_oDocument.WriteString(L");\n", 3);
}
void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
if (false == m_bIsMoveTo)
WritePathMoveTo(x1, y1);
m_oDocument.WriteString(L"cu(c,", 5);
WriteIntsToStringBuilder(round(x1), round(y1), round(x2), round(y2), round(x3), round(y3), &m_oDocument);
m_oDocument.WriteString(L");\n", 3);
}
void WriteDrawPath(LONG lType, Aggplus::CMatrix* pTransform, Aggplus::CGraphicsPathSimpleConverter* pConverter, LONG lTxId)
{
bool bStroke = false;
if (m_pPen->Alpha == 0)
lType &= 0xFF00;
if ((-1 == lTxId) && (0 == m_pBrush->Alpha1))
lType &= 0xFF;
if ((lType & 0x01) == 0x01)
{
SetStrokeColor(m_pPen->Color, m_pPen->Alpha, &m_oDocument);
bStroke = true;
}
if (lType > 0x01)
{
if (-1 != lTxId)
{
// текстура!
double x = 0;
double y = 0;
double w = 0;
double h = 0;
pConverter->PathCommandGetBounds(x, y, w, h);
double r = x + w;
double b = y + h;
pTransform->TransformPoint(x, y);
pTransform->TransformPoint(r, b);
w = r - x;
h = b - y;
m_oDocument.WriteString(L"img", 3);
m_oDocument.AddInt(lTxId);
m_oDocument.WriteString(L".src = \"media\\\\image", 20);
m_oDocument.AddInt(lTxId);
m_oDocument.WriteString(L".jpg\";img", 9);
m_oDocument.AddInt(lTxId);
m_oDocument.WriteString(L".onload = function(){c.drawImage(img", 36);
WriteIntsToStringBuilder(lTxId, round(x), round(y), round(w), round(h), &m_oDocument);
m_oDocument.WriteString(L");drawpage", 10);
m_oDocument.AddInt(m_lCurDocumentID);
m_oDocument.AddCharSafe('_');
m_oDocument.AddInt(lTxId);
m_oDocument.WriteString(L"(c);};\n}\nfunction drawpage", 26);
m_oDocument.AddInt(m_lCurDocumentID);
m_oDocument.AddCharSafe('_');
m_oDocument.AddInt(lTxId);
m_oDocument.WriteString(L"(c)\n{\n", 6);
}
else
{
SetFillColor(m_pBrush->Color1, m_pBrush->Alpha1, &m_oDocument);
m_oDocument.WriteString(L"f(c);\n", 6);
}
}
if (bStroke)
{
m_oDocument.WriteString(L"s(c);\n", 6);
}
}
void WritePathClip()
{
m_bIsClipping = true;
++m_lClippingPath;
}
void WritePathClipEnd()
{
if (!m_bIsClipping)
{
m_oDocument.WriteString(L"c.save();\n", 10);
}
m_bIsClipping = true;
m_oDocument.WriteString(L"c.clip();\n", 10);
}
void WritePathResetClip()
{
if (m_bIsClipping)
{
m_oDocument.WriteString(L"c.restore();\n", 13);
}
m_bIsClipping = false;
}
inline void WriteStyleClip()
{
}
};
}
#endif // _ASC_HTMLRENDERER_CANVASWRITER_H_

936
HtmlRenderer/src/Common.h Normal file
View File

@ -0,0 +1,936 @@
#ifndef _ASC_HTMLRENDERER_COMMON_H_
#define _ASC_HTMLRENDERER_COMMON_H_
#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
{
class IBaseMatrixUpdater
{
public:
virtual void OnBaseMatrixUpdate(const double& dWidth, const double& dHeight) = 0;
};
class CDstInfo
{
public:
std::wstring m_strDstFilePath;
std::wstring m_strAdditionalPath;
std::wstring m_strDstMedia;
bool m_bIsWeb;
public:
CDstInfo()
{
m_strDstFilePath = L"";
m_strAdditionalPath = L"";
m_strDstMedia = L"";
m_bIsWeb = false;
}
CDstInfo(const CDstInfo& oInfo)
{
*this = oInfo;
}
CDstInfo& operator=(const CDstInfo& oSrc)
{
m_strDstFilePath = oSrc.m_strDstFilePath;
m_strAdditionalPath = oSrc.m_strAdditionalPath;
m_strDstMedia = oSrc.m_strDstMedia;
m_bIsWeb = oSrc.m_bIsWeb;
return *this;
}
};
}
namespace NSHtmlRenderer
{
inline LONG ConvertColor(const LONG& lBGR)
{
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
}
inline void WriteIntsToStringBuilder(const int& n1, const int& n2, NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->AddSize(21);
pBuilder->AddIntNoCheck(n1);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n2);
}
inline void WriteIntsToStringBuilder(const int& n1, const int& n2,
const int& n3, const int& n4,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->AddSize(65);
pBuilder->AddIntNoCheck(n1);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n2);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n3);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n4);
}
inline void WriteIntsToStringBuilder(const int& n1, const int& n2,
const int& n3, const int& n4,
const int& n5,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->AddSize(65);
pBuilder->AddIntNoCheck(n1);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n2);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n3);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n4);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n5);
}
inline void WriteIntsToStringBuilder(const int& n1, const int& n2,
const int& n3, const int& n4,
const int& n5, const int& n6,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->AddSize(65);
pBuilder->AddIntNoCheck(n1);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n2);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n3);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n4);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n5);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(n6);
}
inline void WriteFormatted(const wchar_t* s1, const int& n1,
const wchar_t* s2,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->WriteString(s1, wcslen(s1));
pBuilder->AddInt(n1);
pBuilder->WriteString(s2, wcslen(s2));
}
inline void WriteFormatted(const wchar_t* s1, const int& n1,
const wchar_t* s2, const int& n2,
const wchar_t* s3,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->WriteString(s1, wcslen(s1));
pBuilder->AddInt(n1);
pBuilder->WriteString(s2, wcslen(s2));
pBuilder->AddInt(n2);
pBuilder->WriteString(s3, wcslen(s3));
}
inline void WriteFormatted(const wchar_t* s1, const int& n1,
const wchar_t* s2, const int& n2,
const wchar_t* s3, const int& n3,
const wchar_t* s4,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->WriteString(s1, wcslen(s1));
pBuilder->AddInt(n1);
pBuilder->WriteString(s2, wcslen(s2));
pBuilder->AddInt(n2);
pBuilder->WriteString(s3, wcslen(s3));
pBuilder->AddInt(n3);
pBuilder->WriteString(s4, wcslen(s4));
}
inline void WriteFormatted(const wchar_t* s1, const int& n1,
const wchar_t* s2, const int& n2,
const wchar_t* s3, const int& n3,
const wchar_t* s4, const int& n4,
const wchar_t* s5,
NSStringUtils::CStringBuilder* pBuilder)
{
pBuilder->WriteString(s1, wcslen(s1));
pBuilder->AddInt(n1);
pBuilder->WriteString(s2, wcslen(s2));
pBuilder->AddInt(n2);
pBuilder->WriteString(s3, wcslen(s3));
pBuilder->AddInt(n3);
pBuilder->WriteString(s4, wcslen(s4));
pBuilder->AddInt(n4);
pBuilder->WriteString(s5, wcslen(s5));
}
inline void SetStringColor(LONG lBGR, NSStringUtils::CStringBuilder* pBuilder)
{
BYTE R = (BYTE)(lBGR & 0xFF);
BYTE G = (BYTE)((lBGR >> 8) & 0xFF);
BYTE B = (BYTE)((lBGR >> 16) & 0xFF);
pBuilder->AddSize(50);
pBuilder->WriteString(L"rgb(", 4);
pBuilder->AddIntNoCheck(R);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(G);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(B);
pBuilder->AddCharSafe(')');
}
inline void SetStrokeColor(LONG lBGR, LONG lA, NSStringUtils::CStringBuilder* pBuilder)
{
BYTE R = (BYTE)(lBGR & 0xFF);
BYTE G = (BYTE)((lBGR >> 8) & 0xFF);
BYTE B = (BYTE)((lBGR >> 16) & 0xFF);
pBuilder->WriteString(L"c.strokeStyle = \"rgba(", 22);
pBuilder->AddSize(70);
pBuilder->AddIntNoCheck(R);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(G);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(B);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheckDel100(100 * lA / 255);
pBuilder->WriteString(L")\";\n", 4);
}
inline void SetFillColor(LONG lBGR, LONG lA, NSStringUtils::CStringBuilder* pBuilder)
{
BYTE R = (BYTE)(lBGR & 0xFF);
BYTE G = (BYTE)((lBGR >> 8) & 0xFF);
BYTE B = (BYTE)((lBGR >> 16) & 0xFF);
pBuilder->WriteString(L"c.fillStyle = \"rgba(", 20);
pBuilder->AddSize(70);
pBuilder->AddIntNoCheck(R);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(G);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheck(B);
pBuilder->AddCharNoSafe(',');
pBuilder->AddIntNoCheckDel100(100 * lA / 255);
pBuilder->WriteString(L")\";\n", 4);
}
struct RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
};
inline bool IsEqualMain(const Aggplus::CMatrix* pMatrix, const Aggplus::CMatrix* pMatrix2)
{
if (fabs(pMatrix->m_agg_mtx.sx - pMatrix2->m_agg_mtx.sx) < 0.001 &&
fabs(pMatrix->m_agg_mtx.sy - pMatrix2->m_agg_mtx.sy) < 0.001 &&
fabs(pMatrix->m_agg_mtx.shx - pMatrix2->m_agg_mtx.shx) < 0.001 &&
fabs(pMatrix->m_agg_mtx.shy - pMatrix2->m_agg_mtx.shy) < 0.001)
return true;
return false;
}
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;
}
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
{
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_COMMON_H_

828
HtmlRenderer/src/Document.h Normal file
View File

@ -0,0 +1,828 @@
#ifndef _ASC_HTMLRENDERER_DOCUMENT_H_
#define _ASC_HTMLRENDERER_DOCUMENT_H_
#include "Common.h"
#include <vector>
#include "../../../DesktopEditor/graphics/GraphicsRenderer.h"
namespace NSHtmlRenderer
{
class CPageInfo
{
private:
double m_dWidthMM;
double m_dHeightMM;
bool m_bInitW;
bool m_bInitH;
IBaseMatrixUpdater* m_pUpdater;
public:
CPageInfo()
{
m_dWidthMM = 190;
m_dHeightMM = 270;
m_bInitW = false;
m_bInitH = false;
m_pUpdater = NULL;
}
CPageInfo(const CPageInfo& oSrc)
{
*this = oSrc;
}
CPageInfo& operator=(const CPageInfo& oSrc)
{
m_dWidthMM = oSrc.m_dWidthMM;
m_dHeightMM = oSrc.m_dHeightMM;
m_bInitW = oSrc.m_bInitW;
m_bInitH = oSrc.m_bInitH;
m_pUpdater = oSrc.m_pUpdater;
return *this;
}
inline double GetWidth()
{
return m_dWidthMM;
}
inline double GetHeight()
{
return m_dHeightMM;
}
inline void SetWidth(const double& width)
{
m_dWidthMM = width;
m_bInitW = true;
if (m_bInitH && (NULL != m_pUpdater))
{
m_pUpdater->OnBaseMatrixUpdate(m_dWidthMM, m_dHeightMM);
}
}
inline void SetHeight(const double& height)
{
m_dHeightMM = height;
m_bInitH = true;
if (m_bInitW && (NULL != m_pUpdater))
{
m_pUpdater->OnBaseMatrixUpdate(m_dWidthMM, m_dHeightMM);
}
}
inline void SetUpdater(IBaseMatrixUpdater* pUpdater)
{
m_pUpdater = pUpdater;
}
};
class CDocument
{
private:
public:
std::vector<CPageInfo> m_arrPages;
IBaseMatrixUpdater* m_pUpdater;
public:
CDocument() : m_arrPages()
{
m_pUpdater = NULL;
}
inline void SetUpdater(IBaseMatrixUpdater* pUpdater)
{
m_pUpdater = pUpdater;
}
public:
inline void NewPage()
{
CPageInfo oInfo;
oInfo.SetUpdater(m_pUpdater);
m_arrPages.push_back(oInfo);
}
inline void SetWidth(const double& dValue)
{
size_t nCount = m_arrPages.size();
if (nCount > 0)
{
m_arrPages[nCount - 1].SetWidth(dValue);
}
}
inline void SetHeight(const double& dValue)
{
size_t nCount = m_arrPages.size();
if (nCount > 0)
{
m_arrPages[nCount - 1].SetHeight(dValue);
}
}
// --------------------------------------------------------------------
std::wstring GetThumbnailsHTML()
{
std::wstring strHTML = L"<html>";
strHTML += GetThumbnailsHeader();
strHTML += GetThumbnailsBody();
strHTML += L"</html>";
return strHTML;
}
std::wstring GetViewerHTML()
{
std::wstring strHTML = L"<html>";
strHTML += GetViewerHeader();
strHTML += GetViewerBody();
strHTML += L"</html>";
return strHTML;
}
std::wstring GetThumbnailBlockHTML(int nPageNum)
{
std::wstring strPage = std::to_wstring(nPageNum);
std::wstring strResult = L"<div class=\"blockpage\"><div class=\"blockthumbnail\" align=\"center\"><img align=\"center\" src=\"thumbnails\\page" +
strPage + L".png\" onClick=\"OnChangePage(" + strPage + L")\" width=\"100%\" height=\"90%\"/>" + L"page" + strPage + L"</div></div>";
return strResult;
}
std::wstring GetThumbnailsBody()
{
std::wstring strBody = L"<body bgcolor=\"#FEFEFE\">";
size_t nCount = m_arrPages.size();
for (size_t i = 0; i < nCount; ++i)
{
strBody += GetThumbnailBlockHTML((int)(i + 1));
}
strBody += L"</body>";
return strBody;
}
std::wstring GetThumbnailsHeader()
{
return L"<head>\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></meta>\
<title>thumbnails</title>\
<style type=\"text/css\">\
.blockpage {\
width: 80%;\
height: 200px;\
background: #FEFEFE;\
padding: 10px;\
float: none;\
text-align: center;\
}\
.blockthumbnail {\
width: 100%;\
height: 100%;\
background: #FEFEFE;\
padding: 0px;\
float: none;\
}\
</style>\
<script language=\"JavaScript\">\
function OnChangePage(pageNum)\
{\
top.frames['viewer'].OnChangePage(pageNum);\
}\
</script>\
</head>";
}
std::wstring GetViewerHeader()
{
return L"<head>\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></meta>\
<title>viewer</title>\
<style type=\"text/css\">\
.blockpage {\
position: relative;\
left: 20%;\
width: 60%;\
height: 1200px;\
background: #FFFFFF;\
padding: 10px;\
border-style: outset;\
border-color: #F0F0F0;\
border-width: 2px 3px 3px 2px;\
float: none;\
text-align: center;\
}\
.blockpagebetween {\
width: 100%;\
height: 20px;\
background: #FEFEFE;\
padding: 0px;\
float: none;\
text-align: center;\
}\
.blockpagenatural {\
width: 100%;\
height: 100%;\
background: #FEFEFE;\
padding: 0px;\
float: none;\
}\
</style>\
<script language=\"JavaScript\">\
function OnChangePage(pageNum)\
{\
var nPage = Number(pageNum);\
var position = ((nPage - 1) * 1225 + (nPage - 1) * 20);\
scroll(0, position);\
}\
</script>\
</head>";
}
std::wstring GetViewerBlockHTML(int nPageNum)
{
std::wstring strPage = std::to_wstring(nPageNum);
std::wstring strResult = L"<div class=\"blockpage\">\n<div class=\"blockpagenatural\" align=\"center\">\n<img align=\"center\" src=\"thumbnails\\page" +
strPage + L".png\" onClick=\"OnChangePage(" + strPage + L")\" width=\"100%\" height=\"100%\"/>\n" + L"</div>\n</div>\n" + L"<div class=\"blockpagebetween\"></div>\n";
return strResult;
}
std::wstring GetViewerBody()
{
std::wstring strBody = L"<body bgcolor=\"#FEFEFE\">";
size_t nCount = m_arrPages.size();
for (size_t i = 0; i < nCount; ++i)
{
strBody += GetViewerBlockHTML((int)(i + 1));
}
strBody += L"</body>";
return strBody;
}
std::wstring GetMenuHTML()
{
return L"<html>\
<head>\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></meta>\
<title>menu</title>\
</head>\
<body bgcolor=\"#5F5F5F\">\
</body>\
</html>";
}
std::wstring GetDocumentHTML()
{
return L"<html>\
<head>\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></meta>\
<title>document viewer</title>\
</head>\
<frameset rows=\"50,*\" framespacing=\"0\" frameborder=\"0\">\
<frame src=\"menu.html\" name=\"menu\" noresize border=\"1\" bordercolor=\"#F0F0F0\" scrolling=\"no\"></frame>\
<frameset cols=\"*,200\">\
<frame id=\"id_viewer\" src=\"viewer.html\" name=\"viewer\" noresize></frame>\
<frame id=\"id_thumbnails\" src=\"thumbnails.html\" name=\"thumbnail\"></frame>\
</frameset>\
</frameset>\
</html>";
}
void CreateDirectories(std::wstring strHTML)
{
NSDirectory::CreateDirectory(strHTML);
NSDirectory::CreateDirectory(strHTML + L"/thumbnails");
}
void CreateHTMLs(std::wstring strHTML)
{
NSFile::CFileBinary::SaveToFile(strHTML + L"/docviewer.html", GetDocumentHTML(), true);
NSFile::CFileBinary::SaveToFile(strHTML + L"/menu.html", GetMenuHTML(), true);
NSFile::CFileBinary::SaveToFile(strHTML + L"/viewer.html", GetViewerHTML(), true);
NSFile::CFileBinary::SaveToFile(strHTML + L"/thumbnails.html", GetThumbnailsHTML(), true);
}
};
class CThumbnails
{
private:
CGraphicsRenderer* m_pRenderer;
CBgraFrame* m_pFrame;
LONG m_lWidth;
LONG m_lHeight;
public:
CThumbnails()
{
m_pRenderer = NULL;
m_pFrame = NULL;
m_lWidth = 0;
m_lHeight = 0;
}
~CThumbnails()
{
RELEASEOBJECT(m_pRenderer);
RELEASEOBJECT(m_pFrame);
}
public:
void Create(const double& dWidth, const double& dHeight, LONG lSizeMax = 200)
{
LONG lWidthNew = 0;
LONG lHeightNew = 0;
if (dWidth >= dHeight)
{
lWidthNew = lSizeMax;
lHeightNew = (LONG)((dHeight / dWidth) * lWidthNew);
}
else
{
lHeightNew = lSizeMax;
lWidthNew = (LONG)((dWidth / dHeight) * lHeightNew);
}
if ((m_lWidth == lWidthNew) && (m_lHeight == lHeightNew) && (NULL != m_pFrame))
{
// размер не поменялся - значит и память перевыделять не нужно
BYTE* pBuffer = m_pFrame->get_Data();
memset(pBuffer, 0xFF, 4 * m_lWidth * m_lHeight);
CreateRenderer();
return;
}
RELEASEOBJECT(m_pFrame);
m_lWidth = lWidthNew;
m_lHeight = lHeightNew;
CreateMediaData();
CreateRenderer();
m_pRenderer->put_Width(dWidth);
m_pRenderer->put_Height(dHeight);
}
inline void Save(std::wstring& strFile)
{
SaveFrame(strFile);
}
protected:
void CreateMediaData()
{
RELEASEOBJECT(m_pFrame);
m_pFrame = new CBgraFrame();
m_pFrame->put_Width(m_lWidth);
m_pFrame->put_Height(m_lHeight);
m_pFrame->put_Stride(4 * m_lWidth);
BYTE* pBuffer = new BYTE[4 * m_lWidth * m_lHeight];
memset(pBuffer, 0xFF, 4 * m_lWidth * m_lHeight);
m_pFrame->put_Data(pBuffer);
}
void CreateRenderer()
{
// теперь на всякий случай (сбросить все состояния) - пересоздадим рендерер
RELEASEINTERFACE(m_pRenderer);
m_pRenderer = new CGraphicsRenderer();
m_pRenderer->CreateFromBgraFrame(m_pFrame);
}
void SaveFrame(const std::wstring& strFile)
{
m_pFrame->SaveFile(strFile, 4);
}
public:
inline HRESULT get_Type(LONG* lType)
{
return m_pRenderer->get_Type(lType);
}
//-------- Функции для работы со страницей --------------------------------------------------
inline HRESULT NewPage()
{
if (NULL == m_pRenderer)
return S_OK;
return m_pRenderer->NewPage();
}
inline HRESULT get_Height(double* dHeight)
{
return m_pRenderer->get_Height(dHeight);
}
inline HRESULT put_Height(const double& dHeight)
{
if (NULL == m_pRenderer)
return S_OK;
return m_pRenderer->put_Height(dHeight);
}
inline HRESULT get_Width(double* dWidth)
{
return m_pRenderer->get_Width(dWidth);
}
inline HRESULT put_Width(const double& dWidth)
{
if (NULL == m_pRenderer)
return S_OK;
return m_pRenderer->put_Width(dWidth);
}
inline HRESULT get_DpiX(double* dDpiX)
{
return m_pRenderer->get_DpiX(dDpiX);
}
inline HRESULT get_DpiY(double* dDpiY)
{
return m_pRenderer->get_DpiY(dDpiY);
}
// pen --------------------------------------------------------------------------------------
inline HRESULT get_PenColor(LONG* lColor)
{
return m_pRenderer->get_PenColor(lColor);
}
inline HRESULT put_PenColor(const LONG& lColor)
{
return m_pRenderer->put_PenColor(lColor);
}
inline HRESULT get_PenAlpha(LONG* lAlpha)
{
return m_pRenderer->get_PenAlpha(lAlpha);
}
inline HRESULT put_PenAlpha(const LONG& lAlpha)
{
return m_pRenderer->put_PenAlpha(lAlpha);
}
inline HRESULT get_PenSize(double* dSize)
{
return m_pRenderer->get_PenSize(dSize);
}
inline HRESULT put_PenSize(const double& dSize)
{
return m_pRenderer->put_PenSize(dSize);
}
inline HRESULT get_PenDashStyle(BYTE* val)
{
return m_pRenderer->get_PenDashStyle(val);
}
inline HRESULT put_PenDashStyle(const BYTE& val)
{
return m_pRenderer->put_PenDashStyle(val);
}
inline HRESULT get_PenLineStartCap(BYTE* val)
{
return m_pRenderer->get_PenLineStartCap(val);
}
inline HRESULT put_PenLineStartCap(const BYTE& val)
{
return m_pRenderer->put_PenLineStartCap(val);
}
inline HRESULT get_PenLineEndCap(BYTE* val)
{
return m_pRenderer->get_PenLineEndCap(val);
}
inline HRESULT put_PenLineEndCap(const BYTE& val)
{
return m_pRenderer->put_PenLineEndCap(val);
}
inline HRESULT get_PenLineJoin(BYTE* val)
{
return m_pRenderer->get_PenLineJoin(val);
}
inline HRESULT put_PenLineJoin(const BYTE& val)
{
return m_pRenderer->put_PenLineJoin(val);
}
inline HRESULT get_PenDashOffset(double* val)
{
return m_pRenderer->get_PenDashOffset(val);
}
inline HRESULT put_PenDashOffset(const double& val)
{
return m_pRenderer->put_PenDashOffset(val);
}
inline HRESULT get_PenAlign(LONG* val)
{
return m_pRenderer->get_PenAlign(val);
}
inline HRESULT put_PenAlign(const LONG& val)
{
return m_pRenderer->put_PenAlign(val);
}
inline HRESULT get_PenMiterLimit(double* val)
{
return m_pRenderer->get_PenMiterLimit(val);
}
inline HRESULT put_PenMiterLimit(const double& val)
{
return m_pRenderer->put_PenMiterLimit(val);
}
inline HRESULT PenDashPattern(double* pPattern, LONG lCount)
{
return m_pRenderer->PenDashPattern(pPattern, lCount);
}
// brush ------------------------------------------------------------------------------------
inline HRESULT get_BrushType(LONG* lType)
{
return m_pRenderer->get_BrushType(lType);
}
inline HRESULT put_BrushType(const LONG& lType)
{
return m_pRenderer->put_BrushType(lType);
}
inline HRESULT get_BrushColor1(LONG* lColor)
{
return m_pRenderer->get_BrushColor1(lColor);
}
inline HRESULT put_BrushColor1(const LONG& lColor)
{
return m_pRenderer->put_BrushColor1(lColor);
}
inline HRESULT get_BrushAlpha1(LONG* lAlpha)
{
return m_pRenderer->get_BrushAlpha1(lAlpha);
}
inline HRESULT put_BrushAlpha1(const LONG& lAlpha)
{
return m_pRenderer->put_BrushAlpha1(lAlpha);
}
inline HRESULT get_BrushColor2(LONG* lColor)
{
return m_pRenderer->get_BrushColor2(lColor);
}
inline HRESULT put_BrushColor2(const LONG& lColor)
{
return m_pRenderer->put_BrushColor2(lColor);
}
inline HRESULT get_BrushAlpha2(LONG* lAlpha)
{
return m_pRenderer->get_BrushAlpha2(lAlpha);
}
inline HRESULT put_BrushAlpha2(const LONG& lAlpha)
{
return m_pRenderer->put_BrushAlpha2(lAlpha);
}
inline HRESULT get_BrushTexturePath(std::wstring* sPath)
{
return m_pRenderer->get_BrushTexturePath(sPath);
}
inline HRESULT put_BrushTexturePath(const std::wstring& bsPath)
{
return m_pRenderer->put_BrushTexturePath(bsPath);
}
inline HRESULT get_BrushTextureMode(LONG* lMode)
{
return m_pRenderer->get_BrushTextureMode(lMode);
}
inline HRESULT put_BrushTextureMode(const LONG& lMode)
{
return m_pRenderer->put_BrushTextureMode(lMode);
}
inline HRESULT get_BrushTextureAlpha(LONG* lTxAlpha)
{
return m_pRenderer->get_BrushTextureAlpha(lTxAlpha);
}
inline HRESULT put_BrushTextureAlpha(const LONG lTxAlpha)
{
return m_pRenderer->put_BrushTextureAlpha(lTxAlpha);
}
inline HRESULT get_BrushLinearAngle(double* dAngle)
{
return m_pRenderer->get_BrushLinearAngle(dAngle);
}
inline HRESULT put_BrushLinearAngle(const double& dAngle)
{
return m_pRenderer->put_BrushLinearAngle(dAngle);
}
inline HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
{
return m_pRenderer->BrushRect(val, left, top, width, height);
}
inline HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height)
{
return m_pRenderer->BrushBounds(left, top, width, height);
}
inline HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount)
{
return m_pRenderer->put_BrushGradientColors(lColors, pPositions, nCount);
}
// font -------------------------------------------------------------------------------------
inline HRESULT get_FontName(std::wstring* bsName)
{
return m_pRenderer->get_FontName(bsName);
}
inline HRESULT put_FontName(const std::wstring& bsName)
{
return m_pRenderer->put_FontName(bsName);
}
inline HRESULT get_FontPath(std::wstring* bsName)
{
return m_pRenderer->get_FontPath(bsName);
}
inline HRESULT put_FontPath(const std::wstring& bsName)
{
return m_pRenderer->put_FontPath(bsName);
}
inline HRESULT get_FontSize(double* dSize)
{
return m_pRenderer->get_FontSize(dSize);
}
inline HRESULT put_FontSize(const double& dSize)
{
return m_pRenderer->put_FontSize(dSize);
}
inline HRESULT get_FontStyle(LONG* lStyle)
{
return m_pRenderer->get_FontStyle(lStyle);
}
inline HRESULT put_FontStyle(const LONG& lStyle)
{
return m_pRenderer->put_FontStyle(lStyle);
}
inline HRESULT get_FontStringGID(INT* bGID)
{
return m_pRenderer->get_FontStringGID(bGID);
}
inline HRESULT put_FontStringGID(const INT& bGID)
{
return m_pRenderer->put_FontStringGID(bGID);
}
inline HRESULT get_FontCharSpace(double* dSpace)
{
return m_pRenderer->get_FontCharSpace(dSpace);
}
inline HRESULT put_FontCharSpace(const double& dSpace)
{
return m_pRenderer->put_FontCharSpace(dSpace);
}
inline HRESULT get_FontFaceIndex(int* lFaceIndex)
{
return m_pRenderer->get_FontFaceIndex(lFaceIndex);
}
inline HRESULT put_FontFaceIndex(const int& lFaceIndex)
{
return m_pRenderer->put_FontFaceIndex(lFaceIndex);
}
//-------- Функции для вывода текста --------------------------------------------------------
virtual HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->CommandDrawTextCHAR(c, x, y, w, h);
}
virtual HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->CommandDrawText(bsText, x, y, w, h);
}
virtual HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->CommandDrawTextExCHAR(c, gid, x, y, w, h);
}
virtual HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->CommandDrawTextEx(bsUnicodeText, pGids, nGidsCount, x, y, w, h);
}
//-------- Маркеры для команд ---------------------------------------------------------------
inline HRESULT BeginCommand(const DWORD& lType)
{
return m_pRenderer->BeginCommand(lType);
}
inline HRESULT EndCommand(const DWORD& lType)
{
return m_pRenderer->EndCommand(lType);
}
//-------- Функции для работы с Graphics Path -----------------------------------------------
inline HRESULT PathCommandMoveTo(const double& fX, const double& fY)
{
return m_pRenderer->PathCommandMoveTo(fX, fY);
}
inline HRESULT PathCommandLineTo(const double& fX, const double& fY)
{
return m_pRenderer->PathCommandLineTo(fX, fY);
}
inline HRESULT PathCommandLinesTo(double* points, const int& count)
{
return m_pRenderer->PathCommandLinesTo(points, count);
}
inline HRESULT PathCommandCurveTo(const double& fX1, const double& fY1, const double& fX2, const double& fY2, const double& fX3, const double& fY3)
{
return m_pRenderer->PathCommandCurveTo(fX1, fY1, fX2, fY2, fX3, fY3);
}
inline HRESULT PathCommandCurvesTo(double* points, const int& count)
{
return m_pRenderer->PathCommandCurvesTo(points, count);
}
inline HRESULT PathCommandArcTo(const double& fX, const double& fY, const double& fWidth, const double& fHeight, const double& fStartAngle, const double& fSweepAngle)
{
return m_pRenderer->PathCommandArcTo(fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle);
}
inline HRESULT PathCommandClose()
{
return m_pRenderer->PathCommandClose();
}
inline HRESULT PathCommandEnd()
{
return m_pRenderer->PathCommandEnd();
}
inline HRESULT DrawPath(const LONG& nType)
{
return m_pRenderer->DrawPath(nType);
}
inline HRESULT PathCommandStart()
{
return m_pRenderer->PathCommandStart();
}
inline HRESULT PathCommandGetCurrentPoint(double* fX, double* fY)
{
return m_pRenderer->PathCommandGetCurrentPoint(fX, fY);
}
inline HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->PathCommandTextCHAR(c, x, y, w, h);
}
inline HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->PathCommandText(bsText, x, y, w, h);
}
inline HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->PathCommandTextExCHAR(c, gid, x, y, w, h);
}
inline HRESULT PathCommandTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
{
return m_pRenderer->PathCommandTextEx(bsUnicodeText, pGids, nGidsCount, x, y, w, h);
}
//-------- Функции для вывода изображений ---------------------------------------------------
inline HRESULT DrawImage(IGrObject* pInterface, const double& fX, const double& fY, const double& fWidth, const double& fHeight)
{
return m_pRenderer->DrawImage(pInterface, fX, fY, fWidth, fHeight);
}
inline HRESULT DrawImageFromFile(const std::wstring& sPath, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255)
{
return m_pRenderer->DrawImageFromFile(sPath, x, y, w, h, lAlpha);
}
// transform --------------------------------------------------------------------------------
inline HRESULT SetTransform(const double& dA, const double& dB, const double& dC, const double& dD, const double& dE, const double& dF)
{
return m_pRenderer->SetTransform(dA, dB, dC, dD, dE, dF);
}
inline HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF)
{
return m_pRenderer->GetTransform(pdA, pdB, pdC, pdD, pdE, pdF);
}
inline HRESULT ResetTransform(void)
{
return m_pRenderer->ResetTransform();
}
// -----------------------------------------------------------------------------------------
inline HRESULT get_ClipMode(LONG* plMode)
{
return m_pRenderer->get_ClipMode(plMode);
}
inline HRESULT put_ClipMode(const LONG& lMode)
{
return m_pRenderer->put_ClipMode(lMode);
}
// additiaonal params ----------------------------------------------------------------------
inline HRESULT CommandLong(const LONG& lType, const LONG& lCommand)
{
m_pRenderer->CommandLong(lType, lCommand);
}
inline HRESULT CommandDouble(const LONG& lType, const double& dCommand)
{
m_pRenderer->CommandDouble(lType, dCommand);
}
inline HRESULT CommandString(const LONG& lType, const std::wstring& sCommand)
{
m_pRenderer->CommandString(lType, sCommand);
}
};
}
#endif // _ASC_HTMLRENDERER_DOCUMENT_H_

View File

@ -0,0 +1,89 @@
#ifndef _ASC_HTMLRENDERER_FM_H_
#define _ASC_HTMLRENDERER_FM_H_
#include "FontManagerBase.h"
namespace NSHtmlRenderer
{
using namespace NSFontManager;
const long g_lNewNoJustifySpace = 5;
class CFontManager : public CFontManagerBase
{
public:
NSStructures::CFont* m_pFont;
Aggplus::CMatrix* m_pTransform;
double m_dSpaceWidthMM;
public:
CFontManager() : m_pFont(NULL), CFontManagerBase()
{
m_pTransform = NULL;
m_dSpaceWidthMM = 0;
}
virtual ~CFontManager()
{
}
public:
virtual void LoadFont(long lFaceIndex = 0, bool bIsNeedAddToMap = true)
{
if (NULL == m_pManager)
return;
double dSize = m_pFont->Size;
double dSizeFont = dSize * ((m_pTransform->m_agg_mtx.sx + m_pTransform->m_agg_mtx.sy) / 2);
m_pFont->Size = dSizeFont;
if (IsEqual2(m_pFont, &m_oFont.m_oFont))
{
m_pFont->Size = dSize;
return;
}
m_oFont.m_oFont = *m_pFont;
m_pFont->Size = dSize;
bool bIsPath = false;
if (L"" == m_pFont->Path)
{
CFontManagerBase::LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle());
}
else
{
CFontManagerBase::LoadFontByFile(m_oFont.m_oFont.Path, m_oFont.m_oFont.Size, lFaceIndex);
m_pFont->SetStyle(m_oFont.m_oProperties.m_lStyle);
m_oFont.m_oFont.SetStyle(m_oFont.m_oProperties.m_lStyle);
bIsPath = true;
}
CalculateSpace();
}
inline void CalculateSpace()
{
LONG lGid = m_pManager->m_bStringGID;
m_pManager->SetStringGID(FALSE);
m_pManager->LoadString1(L" ", 0, 0);
TBBox _box = m_pManager->MeasureString2();
m_dSpaceWidthMM = (double)(_box.fMaxX - _box.fMinX) * c_dPixToMM;
if (0 >= m_dSpaceWidthMM)
{
m_dSpaceWidthMM = 1.0;
}
m_pManager->SetStringGID(lGid);
}
};
}
#endif // _ASC_HTMLRENDERER_FM_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,773 @@
#ifndef _ASC_HTMLRENDERER_SVGWRITER_H_
#define _ASC_HTMLRENDERER_SVGWRITER_H_
#include "Common.h"
#include <vector>
#include "../../../DesktopEditor/graphics/GraphicsPath.h"
namespace NSHtmlRenderer
{
class CClipSVG
{
public:
std::vector<std::wstring> m_arPaths;
std::vector<LONG> m_arTypes;
LONG m_lWidth;
LONG m_lHeight;
CClipSVG() : m_arPaths(), m_arTypes()
{
m_lWidth = 0;
m_lHeight = 0;
}
~CClipSVG()
{
}
void Write(NSStringUtils::CStringBuilder& oWriter, LONG& lCurrentClipPath)
{
// сначала запишем все пути
size_t nCount = m_arPaths.size();
for (size_t i = 0; i < nCount; ++i)
{
oWriter.WriteString(L"<clipPath id=\"clip", 18);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\"><path id=\"path", 16);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\" d=\"", 5);
oWriter.WriteString(m_arPaths[i]);
if (c_nClipRegionTypeWinding == m_arTypes[i])
oWriter.WriteString(L"\" clip-rule=\"nonzero\" /></clipPath>", 35);
else
oWriter.WriteString(L"\" clip-rule=\"evenodd\" /></clipPath>", 35);
++lCurrentClipPath;
}
LONG lWritePathID = (LONG)lCurrentClipPath - 2;
// теперь запишем пересечения
for (size_t i = 1; i < nCount; ++i)
{
oWriter.WriteString(L"<clipPath id=\"clip", 18);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\" clip-path=\"url(#clip", 22);
oWriter.AddInt(lCurrentClipPath - 1);
WriteFormatted(L")\"><use x=\"0\" y=\"0\" width=\"", (int)m_lWidth, L"\" height=\"", (int)m_lHeight, L"\" xlink:href=\"#path", (int)lWritePathID, L"\"/></clipPath>", &oWriter);
++lCurrentClipPath;
--lWritePathID;
}
}
void Write2(NSStringUtils::CStringBuilder& oWriter, LONG& lCurrentClipPath)
{
// сначала запишем все пути
size_t nCount = m_arPaths.size();
double dMemoryClipTypes = 0;
for (size_t i = 0; i < nCount; ++i)
{
dMemoryClipTypes += m_arTypes[i];
}
dMemoryClipTypes /= nCount;
if (0 != dMemoryClipTypes && 1 != dMemoryClipTypes)
return Write(oWriter, lCurrentClipPath);
oWriter.WriteString(L"<clipPath id=\"clip", 18);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\"><path id=\"path", 16);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\" d=\"", 5);
for (size_t i = 0; i < nCount; ++i)
{
oWriter.WriteString(m_arPaths[i]);
}
if (dMemoryClipTypes == 0)
oWriter.WriteString(L"\" clip-rule=\"nonzero\" /></clipPath>", 35);
else
oWriter.WriteString(L"\" clip-rule=\"evenodd\" /></clipPath>", 35);
++lCurrentClipPath;
}
inline void Clear()
{
m_arPaths.clear();
m_arTypes.clear();
}
inline bool IsInit()
{
return (0 != m_arPaths.size());
}
};
class CClipSVG2
{
public:
std::vector<std::wstring> m_arPaths;
std::vector<LONG> m_arTypes;
LONG m_lWidth;
LONG m_lHeight;
LONG m_lCountWriteClips;
CClipSVG2() : m_arPaths(), m_arTypes()
{
m_lWidth = 0;
m_lHeight = 0;
m_lCountWriteClips = 0;
}
~CClipSVG2()
{
}
void Write(NSStringUtils::CStringBuilder& oWriter, LONG& lCurrentClipPath)
{
// сначала запишем все пути
size_t nCount = m_arPaths.size();
LONG lOld = lCurrentClipPath;
for (size_t i = 0; i < nCount; ++i)
{
oWriter.WriteString(L"<clipPath id=\"clip", 18);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\"><path id=\"path", 16);
oWriter.AddInt(lCurrentClipPath);
oWriter.WriteString(L"\" d=\"", 5);
oWriter.WriteString(m_arPaths[i]);
if (c_nClipRegionTypeWinding == m_arTypes[i])
oWriter.WriteString(L"\" clip-rule=\"nonzero\" /></clipPath>", 35);
else
oWriter.WriteString(L"\" clip-rule=\"evenodd\" /></clipPath>", 35);
++lCurrentClipPath;
}
m_lCountWriteClips = (LONG)nCount;
for (LONG i = 0; i < m_lCountWriteClips; i++)
{
oWriter.WriteString(L"<g clip-path=\"url(#clip", 23);
oWriter.AddInt(lOld++);
oWriter.WriteString(L")\">", 3);
}
}
void WriteEnd(NSStringUtils::CStringBuilder& oWriter)
{
while (m_lCountWriteClips > 0)
{
oWriter.WriteString(L"</g>\n", 5);
--m_lCountWriteClips;
}
}
inline void Clear()
{
m_arPaths.clear();
m_arTypes.clear();
}
inline bool IsInit()
{
return (0 != m_arPaths.size());
}
};
class CSVGWriter
{
public:
NSStringUtils::CStringBuilder m_oPath;
NSStringUtils::CStringBuilder m_oDocument;
LONG m_lCurDocumentID;
LONG m_lClippingPath;
LONG m_lPatternID;
bool m_bIsClipping;
bool m_bIsNeedUpdateClip;
LONG m_lClipMode;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
int m_lWidth;
int m_lHeight;
double m_dDpiX;
double m_dDpiY;
CClipSVG m_oClip;
public:
CSVGWriter() : m_oPath(), m_oDocument()
{
m_lCurDocumentID = 0;
m_lClippingPath = 0;
m_lPatternID = 0;
m_pPen = NULL;
m_pBrush = NULL;
m_dDpiX = 96;
m_dDpiY = 96;
m_lClipMode = c_nClipRegionTypeWinding;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
}
void ReInit()
{
m_oClip.Clear();
m_oPath.ClearNoAttack();
m_oDocument.ClearNoAttack();
m_lCurDocumentID = 0;
m_lClippingPath = 0;
m_lPatternID = 0;
m_dDpiX = 96;
m_dDpiY = 96;
m_lClipMode = c_nClipRegionTypeWinding;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
}
void SetSettings(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush)
{
m_pPen = pPen;
m_pBrush = pBrush;
}
void CloseFile(std::wstring strFile = L"")
{
if (!strFile.empty())
{
m_oDocument.WriteString(L"</svg>", 5);
NSFile::CFileBinary::SaveToFile(strFile, m_oDocument.GetData());
}
if (3000000 < m_oDocument.GetSize())
m_oDocument.Clear();
m_oDocument.ClearNoAttack();
m_oPath.ClearNoAttack();
m_oClip.Clear();
m_lClippingPath = 0;
m_lPatternID = 0;
m_bIsClipping = false;
}
void NewDocument(double& dWidth, double& dHeigth, LONG& lPageNumber)
{
m_lWidth = (int)dWidth;
m_lHeight = (int)dHeigth;
m_oClip.m_lWidth = m_lWidth;
m_oClip.m_lHeight = m_lHeight;
m_lCurDocumentID = lPageNumber;
WriteFormatted(L"<svg width=\"", m_lWidth, L"px\" height=\"", m_lHeight, L"px\" viewBox=\"0 0 ", m_lWidth, L" ", m_lHeight,
L"\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", &m_oDocument);
m_oClip.Clear();
m_lClippingPath = 0;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
}
void NewDocument(int& lWidth, int& lHeigth)
{
m_lWidth = lWidth;
m_lHeight = lHeigth;
m_oClip.m_lWidth = m_lWidth;
m_oClip.m_lHeight = m_lHeight;
WriteFormatted(L"<svg width=\"", m_lWidth, L"px\" height=\"", m_lHeight, L"px\" viewBox=\"0 0 ", m_lWidth, L" ", m_lHeight,
L"\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", &m_oDocument);
m_oClip.Clear();
m_lClippingPath = 0;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
}
public:
inline void WritePathEnd()
{
m_oPath.ClearNoAttack();
}
inline void WritePathStart()
{
m_oPath.ClearNoAttack();
}
void WritePathClose()
{
m_oPath.AddSize(2);
m_oPath.AddCharNoCheck('Z');
m_oPath.AddSpaceNoCheck();
}
void WritePathMoveTo(double& x, double& y)
{
m_oPath.AddSize(30);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheck(round(x));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheck(round(y));
m_oPath.AddSpaceNoCheck();
}
void WritePathLineTo(double& x, double& y)
{
if (0 == m_oPath.GetCurSize())
{
WritePathMoveTo(x, y);
}
m_oPath.AddSize(30);
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheck(round(x));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheck(round(y));
m_oPath.AddSpaceNoCheck();
}
void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
if (0 == m_oPath.GetCurSize())
{
WritePathMoveTo(x1, y1);
}
m_oPath.AddSize(80);
m_oPath.AddCharNoCheck('C');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheck(round(x1));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheck(round(y1));
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheck(round(x2));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheck(round(y2));
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheck(round(x3));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheck(round(y3));
m_oPath.AddSpaceNoCheck();
}
void WriteDrawPath(LONG nType, Aggplus::CMatrix* pTransform, Aggplus::CGraphicsPathSimpleConverter* pConverter, CImageInfo& oInfo, const double& dAngle)
{
if (m_oPath.GetCurSize() < 3)
return;
WriteClip();
double dScaleTransform = (pTransform->m_agg_mtx.sx + pTransform->m_agg_mtx.sy) / 2.0;
int nPenW = int(m_pPen->Size * dScaleTransform);
if (0 == nPenW)
nPenW = 1;
if (0 == m_pPen->Alpha)
nType &= 0xFF00;
if (c_BrushTypeTexture == m_pBrush->Type)
{
if (0 == m_pBrush->TextureAlpha)
nType &= 0xFF;
}
else
{
if (0 == m_pBrush->Alpha1)
nType &= 0xFF;
}
bool bStroke = (0x01 == (0x01 & nType));
bool bFill = (0x01 < nType);
if (!bFill)
{
// stroke
m_oDocument.WriteString(L"<path ", 6);
m_oDocument.WriteString(L"style=\"fill:none;stroke:", 24);
m_oDocument.WriteHexColor3(m_pPen->Color);
m_oDocument.WriteString(L";stroke-width:", 14);
m_oDocument.AddInt(nPenW);
m_oDocument.WriteString(L"px;stroke-opacity:", 18);
m_oDocument.AddIntDel100(100 * m_pPen->Alpha / 255);
m_oDocument.WriteString(L";\" ", 3);
if (m_pPen->DashStyle == 0)
{
m_oDocument.WriteString(L";\" ", 3);
}
else
{
m_oDocument.WriteString(L";stroke-dasharray: 2,2;\" ", 25);
}
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
return;
}
else if (c_BrushTypeTexture == m_pBrush->Type)
{
double x = 0;
double y = 0;
double r = 0;
double b = 0;
pConverter->PathCommandGetBounds(x, y, r, b);
r += x;
b += y;
if (0 == dAngle)
{
pTransform->TransformPoint(x, y);
pTransform->TransformPoint(r, b);
}
else
{
Aggplus::CMatrix oTemp = *pTransform;
double dCx = (x + r) / 2;
double dCy = (y + b) / 2;
pTransform->TransformPoint(dCx, dCy);
oTemp.RotateAt(-dAngle, dCx, dCy, Aggplus::MatrixOrderAppend);
oTemp.TransformPoint(x, y);
oTemp.TransformPoint(r, b);
}
int _x = round(x);
int _y = round(y);
int _w = round(r - x);
int _h = round(b - y);
// пока заглушка
return WriteImage(oInfo, _x, _y, _w, _h, dAngle);
#if 0
CString strPattern = _T("");
/*
if (itJPG == oInfo.m_eType)
{
strPattern.Format(g_svg_string_pattern_jpg, m_lPatternID, _w, _h, _w, _h, _x, _y, _w, _h, oInfo.m_lID);
}
else
{
strPattern.Format(g_svg_string_pattern_png, m_lPatternID, _w, _h, _w, _h, _x, _y, _w, _h, oInfo.m_lID);
}
*/
m_oDocument.WriteString(strPattern);
CString strMode = _T("nonzero");
if (nType & c_nEvenOddFillMode)
strMode = _T("evenodd");
if (!bStroke)
{
CString strStyle = _T("");
strStyle.Format(g_svg_string_vml_StyleFillTx, m_lPatternID, (double)m_pBrush->Alpha1 / 255, strMode);
m_oDocument.WriteString(g_svg_bstr_vml_Path);
m_oDocument.WriteString(strStyle);
WriteStyleClip();
m_oDocument.WriteString(g_svg_bstr_path_d);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(g_svg_bstr_path_d_end);
m_oDocument.WriteString(g_svg_bstr_nodeClose);
}
else
{
int nPenColor = ConvertColor(m_pPen->Color);
CString strStyle = _T("");
strStyle.Format(g_svg_string_vml_StyleTx, m_lPatternID, (double)m_pBrush->Alpha1 / 255, strMode, nPenColor, nPenW, (double)m_pPen->Alpha / 255);
m_oDocument.WriteString(g_svg_bstr_vml_Path);
m_oDocument.WriteString(strStyle);
WriteStyleClip();
m_oDocument.WriteString(g_svg_bstr_path_d);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(g_svg_bstr_path_d_end);
m_oDocument.WriteString(g_svg_bstr_nodeClose);
}
++m_lPatternID;
return;
#endif
}
if (!bStroke)
{
m_oDocument.WriteString(L"<path ", 6);
m_oDocument.WriteString(L"style=\"fill:", 12);
m_oDocument.WriteHexColor3(m_pBrush->Color1);
m_oDocument.WriteString(L";fill-opacity:", 14);
m_oDocument.AddIntDel100(100 * m_pBrush->Alpha1 / 255);
if (nType & c_nEvenOddFillMode)
m_oDocument.WriteString(L";fill-rule:evenodd;stroke:none\"", 31);
else
m_oDocument.WriteString(L";fill-rule:nonzero;stroke:none\"", 31);
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
return;
}
m_oDocument.WriteString(L"<path ", 6);
m_oDocument.WriteString(L"style=\"fill:", 12);
m_oDocument.WriteHexColor3(m_pBrush->Color1);
m_oDocument.WriteString(L";fill-opacity:", 14);
m_oDocument.AddIntDel100(100 * m_pBrush->Alpha1 / 255);
if (nType & c_nEvenOddFillMode)
m_oDocument.WriteString(L";fill-rule:evenodd;stroke:", 26);
else
m_oDocument.WriteString(L";fill-rule:nonzero;stroke:", 26);
m_oDocument.WriteHexColor3(m_pPen->Color);
m_oDocument.WriteString(L";stroke-width:", 14);
m_oDocument.AddInt(nPenW);
m_oDocument.WriteString(L";stroke-opacity:", 16);
m_oDocument.AddIntDel100(100 * m_pPen->Alpha / 255);
m_oDocument.WriteString(L"\" ", 2);
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
}
void WritePathClip()
{
m_bIsClipping = true;
m_bIsNeedUpdateClip = true;
}
void WritePathClipEnd()
{
if (0 == m_oPath.GetCurSize())
return;
m_oClip.m_arPaths.push_back(m_oPath.GetData());
m_oClip.m_arTypes.push_back(m_lClipMode);
}
void WritePathResetClip()
{
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
m_oClip.Clear();
}
void WriteImage(CImageInfo& oInfo, const double& x, const double& y, const double& w, const double& h, const double& dAngle)
{
bool bIsClipping = false;
if ((1 < h) && (1 < w) && (1 > fabs(dAngle)))
{
WriteClip();
bIsClipping = m_bIsClipping;
}
double dCentreX = x + w / 2.0;
double dCentreY = y + h / 2.0;
bool bIsRotate = (abs(dAngle) > 1) ? true : false;
if (itJPG == oInfo.m_eType)
{
if (bIsClipping)
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddInt(round(x));
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddInt(round(y));
m_oDocument.WriteString(L"\" width=\"", 10);
m_oDocument.AddInt(round(w));
m_oDocument.WriteString(L"\" height=\"", 11);
m_oDocument.AddInt(round(h));
m_oDocument.WriteString(L"\" clip-path=\"url(#clip", 22);
m_oDocument.AddInt(m_lClippingPath - 1);
m_oDocument.WriteString(L")\" xlink:href=\"media/image", 26);
m_oDocument.AddInt(oInfo.m_lID);
if (!bIsRotate)
{
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\"/>", 34);
}
else
{
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\" transform=\"rotate(", 51);
m_oDocument.AddDouble(dAngle, 4);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreX, 2);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreY, 2);
m_oDocument.WriteString(L")\"/>", 4);
}
}
else
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddInt(round(x));
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddInt(round(y));
m_oDocument.WriteString(L"\" width=\"", 10);
m_oDocument.AddInt(round(w));
m_oDocument.WriteString(L"\" height=\"", 11);
m_oDocument.AddInt(round(h));
m_oDocument.WriteString(L"\" xlink:href=\"media/image", 25);
m_oDocument.AddInt(oInfo.m_lID);
if (!bIsRotate)
{
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\"/>", 34);
}
else
{
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\" transform=\"rotate(", 51);
m_oDocument.AddDouble(dAngle, 4);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreX, 2);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreY, 2);
m_oDocument.WriteString(L")\"/>", 4);
}
}
}
else
{
if (bIsClipping)
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddInt(round(x));
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddInt(round(y));
m_oDocument.WriteString(L"\" width=\"", 10);
m_oDocument.AddInt(round(w));
m_oDocument.WriteString(L"\" height=\"", 11);
m_oDocument.AddInt(round(h));
m_oDocument.WriteString(L"\" clip-path=\"url(#clip", 22);
m_oDocument.AddInt(m_lClippingPath - 1);
m_oDocument.WriteString(L")\" xlink:href=\"media/image", 26);
m_oDocument.AddInt(oInfo.m_lID);
if (!bIsRotate)
{
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\"/>", 34);
}
else
{
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\" transform=\"rotate(", 51);
m_oDocument.AddDouble(dAngle, 4);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreX, 2);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreY, 2);
m_oDocument.WriteString(L")\"/>", 4);
}
}
else
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddInt(round(x));
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddInt(round(y));
m_oDocument.WriteString(L"\" width=\"", 10);
m_oDocument.AddInt(round(w));
m_oDocument.WriteString(L"\" height=\"", 11);
m_oDocument.AddInt(round(h));
m_oDocument.WriteString(L"\" xlink:href=\"media/image", 25);
m_oDocument.AddInt(oInfo.m_lID);
if (!bIsRotate)
{
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\"/>", 34);
}
else
{
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\" transform=\"rotate(", 51);
m_oDocument.AddDouble(dAngle, 4);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreX, 2);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(dCentreY, 2);
m_oDocument.WriteString(L")\"/>", 4);
}
}
}
}
inline void WriteClip()
{
if (m_bIsClipping && m_bIsNeedUpdateClip && (m_oClip.IsInit()))
{
m_oClip.Write(m_oDocument, m_lClippingPath);
//m_oClip.Clear();
m_bIsNeedUpdateClip = false;
}
}
inline void WriteToMainHtml_1(NSStringUtils::CStringBuilder* pWriter, const CDstInfo& oInfo)
{
if (!oInfo.m_bIsWeb)
{
pWriter->WriteString(L"<object class=\"_svg\" data=\"page", 31);
pWriter->AddInt(m_lCurDocumentID);
pWriter->WriteString(L".svg\" type=\"image/svg+xml\">", 27);
CloseFile(oInfo.m_strDstFilePath + L"/page" + std::to_wstring(m_lCurDocumentID) + L".svg");
}
else
{
pWriter->WriteString(L"<object class=\"_svg\" data=\"", 27);
pWriter->WriteString(oInfo.m_strAdditionalPath);
pWriter->WriteString(L"/page", 5);
pWriter->AddInt(m_lCurDocumentID);
pWriter->WriteString(L".svg\" type=\"image/svg+xml\">", 27);
CloseFile(oInfo.m_strDstFilePath + L"/page" + std::to_wstring(m_lCurDocumentID) + L".svg");
}
}
inline void WriteToMainHtml_2(NSStringUtils::CStringBuilder* pWriter)
{
pWriter->WriteString(L"</object>", 9);
}
inline void WriteStyleClip()
{
if (m_bIsClipping)
{
m_oDocument.WriteString(L"clip-path=\"url(#clip", 20);
m_oDocument.AddInt(m_lClippingPath - 1);
m_oDocument.WriteString(L")\" ", 3);
}
}
};
}
#endif // _ASC_HTMLRENDERER_SVGWRITER_H_

File diff suppressed because it is too large Load Diff

929
HtmlRenderer/src/Text.h Normal file
View File

@ -0,0 +1,929 @@
#ifndef _ASC_HTMLRENDERER_TEXT_H_
#define _ASC_HTMLRENDERER_TEXT_H_
#include "FontManager.h"
#include "../../../Common/OfficeFileFormats.h"
#ifdef min
#undef min
#endif
#include <algorithm>
namespace NSHtmlRenderer
{
class CHChar
{
public:
int unicode; // юникодное значение
int gid; // индекс глифа в файле
double x; // сдвиг по baseline
double width; // ширина символа (сдвиг до след буквы)
double* matrix; // матрица преобразования (!!! без сдвига)
public:
CHChar()
{
unicode = 0;
gid = 0;
width = 0;
matrix = NULL;
}
CHChar(const CHChar& oSrc)
{
*this = oSrc;
}
CHChar& operator=(const CHChar& oSrc)
{
unicode = oSrc.unicode;
gid = oSrc.gid;
width = oSrc.width;
matrix = NULL;
if (NULL != oSrc.matrix)
{
matrix = new double[4];
memcpy(matrix, oSrc.matrix, 4 * sizeof(double));
}
return *this;
}
~CHChar()
{
RELEASEARRAYOBJECTS(matrix);
}
inline void Clear()
{
unicode = 0;
gid = 0;
width = 0;
RELEASEARRAYOBJECTS(matrix);
}
};
class CHLine
{
public:
double m_dAscent;
double m_dDescent;
double m_dX;
double m_dY;
double m_dEndX;
double m_dEndY;
// baseline ruler: y = k*x + b
double m_dK;
double m_dB;
double m_ex;
double m_ey;
bool m_bIsConstX;
// symbols
// не менять на списки. постоянное создание объектов и их удаление -
// плохо влияет на скорость
CHChar* m_pChars;
LONG m_lSizeChars;
LONG m_lCharsTail;
bool m_bIsSetUpTransform;
double m_sx;
double m_sy;
double m_shx;
double m_shy;
public:
CHLine()
{
m_dAscent = 0;
m_dDescent = 0;
m_dX = 0;
m_dY = 0;
m_dK = 0;
m_dB = 0;
m_bIsConstX = false;
m_ex = 0;
m_ey = 0;
m_lSizeChars = 1000;
m_lCharsTail = 0;
m_pChars = new CHChar[m_lSizeChars];
m_bIsSetUpTransform = false;
m_sx = 1;
m_sy = 1;
m_shx = 0;
m_shy = 0;
}
CHLine& operator=(const CHLine& oLine)
{
m_dAscent = oLine.m_dAscent;
m_dDescent = oLine.m_dDescent;
m_dX = oLine.m_dX;
m_dY = oLine.m_dY;
m_dK = oLine.m_dK;
m_dB = oLine.m_dB;
m_lSizeChars = oLine.m_lSizeChars;
m_lCharsTail = oLine.m_lCharsTail;
RELEASEARRAYOBJECTS(m_pChars);
m_pChars = new CHChar[m_lSizeChars];
for (LONG i = 0; i < m_lSizeChars; ++i)
m_pChars[i] = oLine.m_pChars[i];
m_bIsSetUpTransform = oLine.m_bIsSetUpTransform;
m_sx = oLine.m_sx;
m_sy = oLine.m_sy;
m_shx = oLine.m_shx;
m_shy = oLine.m_shy;
return *this;
}
~CHLine()
{
RELEASEARRAYOBJECTS(m_pChars);
}
inline void Clear()
{
m_dAscent = 0;
m_dDescent = 0;
m_dX = 0;
m_dY = 0;
m_dK = 0;
m_dB = 0;
m_bIsConstX = false;
m_ex = 0;
m_ey = 0;
m_lCharsTail = 0;
m_bIsSetUpTransform = false;
m_sx = 1;
m_sy = 1;
m_shx = 0;
m_shy = 0;
}
inline CHChar* AddTail()
{
if (m_lCharsTail >= m_lSizeChars)
{
CHChar* pNews = new CHChar[2 * m_lSizeChars];
for (LONG i = 0; i < m_lSizeChars; ++i)
{
pNews[i] = m_pChars[i];
}
RELEASEARRAYOBJECTS(m_pChars);
m_pChars = pNews;
m_lSizeChars *= 2;
}
CHChar* pChar = &m_pChars[m_lCharsTail];
++m_lCharsTail;
pChar->Clear();
return pChar;
}
inline CHChar* GetTail()
{
if (0 == m_lCharsTail)
return NULL;
return &m_pChars[m_lCharsTail - 1];
}
inline LONG GetCountChars()
{
return m_lCharsTail;
}
};
const BYTE g_lfHorizontal = 0x01;
const BYTE g_lfGids = 0x02;
const BYTE g_lfWidth = 0x04;
class CHFontInfo
{
public:
USHORT m_lAscent;
USHORT m_lDescent;
USHORT m_lLineHeight;
USHORT m_lUnitsPerEm;
public:
CHFontInfo()
{
m_lAscent = 0;
m_lDescent = 0;
m_lLineHeight = 0;
m_lUnitsPerEm = 0;
}
CHFontInfo(const CHFontInfo& oSrc)
{
m_lAscent = oSrc.m_lAscent;
m_lDescent = oSrc.m_lDescent;
m_lLineHeight = oSrc.m_lLineHeight;
m_lUnitsPerEm = oSrc.m_lUnitsPerEm;
}
CHFontInfo& operator=(const CHFontInfo& oSrc)
{
m_lAscent = oSrc.m_lAscent;
m_lDescent = oSrc.m_lDescent;
m_lLineHeight = oSrc.m_lLineHeight;
m_lUnitsPerEm = oSrc.m_lUnitsPerEm;
return *this;
}
};
class CFontMapInfo
{
public:
std::wstring Path;
int FaceIndex;
public:
CFontMapInfo()
{
Path = L"";
FaceIndex = 0;
}
CFontMapInfo(const CFontMapInfo& oSrc)
{
Path = oSrc.Path;
FaceIndex = oSrc.FaceIndex;
}
CFontMapInfo& operator=(const CFontMapInfo& oSrc)
{
Path = oSrc.Path;
FaceIndex = oSrc.FaceIndex;
return *this;
}
};
class CFontManagerWrapper
{
private:
::CFontManager* m_pManager;
public:
CHFontInfo m_oCurrentInfo;
NSStructures::CFont* m_pFont;
std::map<std::wstring, CHFontInfo> m_mapInfos;
public:
CFontManagerWrapper()
{
m_pManager = NULL;
}
void Init(CApplicationFonts* pApplicationFonts)
{
RELEASEOBJECT(m_pManager);
m_pManager = pApplicationFonts->GenerateFontManager();
}
virtual ~CFontManagerWrapper()
{
RELEASEOBJECT(m_pManager);
}
void SetStringGID(INT bGid)
{
m_pManager->SetStringGID(bGid);
}
public:
inline void LoadCurrentFont(bool bIsAttack, int lFaceIndex = 0)
{
if (L"" == m_pFont->Path)
{
std::wstring sFind = m_pFont->Name + L"__ASC_FONT__" + std::to_wstring(m_pFont->GetStyle());
std::map<std::wstring, CHFontInfo>::const_iterator pPair = m_mapInfos.find(sFind);
if (m_mapInfos.end() != pPair)
{
if (bIsAttack)
{
LoadFontByName(m_pFont->Name, m_pFont->Size, m_pFont->GetStyle());
}
else
{
m_oCurrentInfo = pPair->second;
}
}
else
{
LoadFontByName(m_pFont->Name, m_pFont->Size, m_pFont->GetStyle());
m_mapInfos.insert(std::pair<std::wstring, CHFontInfo>(sFind, m_oCurrentInfo));
}
}
else
{
std::map<std::wstring, CHFontInfo>::const_iterator pPair = m_mapInfos.find(m_pFont->Path);
if (m_mapInfos.end() != pPair)
{
if (bIsAttack)
{
LoadFontByFile(m_pFont->Path, m_pFont->Size, lFaceIndex);
}
else
{
m_oCurrentInfo = pPair->second;
}
}
else
{
LoadFontByFile(m_pFont->Path, m_pFont->Size, lFaceIndex);
m_mapInfos.insert(std::pair<std::wstring, CHFontInfo>(m_pFont->Path, m_oCurrentInfo));
}
}
}
inline void LoadFontByName(const std::wstring& strName, const double& dSize, const LONG& lStyle)
{
m_pManager->LoadFontByName(strName, dSize, lStyle, c_dDpi, c_dDpi);
LoadFontMetrics();
}
inline void LoadFontByFile(const std::wstring& strPath, const double& dSize, const int& lFaceIndex)
{
m_pManager->LoadFontFromFile(strPath, lFaceIndex, dSize, c_dDpi, c_dDpi);
LoadFontMetrics();
}
public:
double MeasureString(const unsigned int* symbols, const int& count, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight)
{
dBoxX = 0;
dBoxY = 0;
dBoxWidth = 0;
dBoxHeight = 0;
if (NULL == m_pManager)
return 0;
m_pManager->LoadString1(symbols, count, (float)x, (float)y);
TBBox _box = m_pManager->MeasureString2();
dBoxX = (double)(_box.fMinX);
dBoxY = (double)(_box.fMinY);
dBoxWidth = (double)(_box.fMaxX - _box.fMinX);
dBoxHeight = (double)(_box.fMaxY - _box.fMinY);
if (dBoxWidth < 0)
dBoxWidth = -dBoxWidth;
if (dBoxHeight < 0)
dBoxHeight = -dBoxHeight;
// переводим в миллиметры
dBoxX *= c_dPixToMM;
dBoxY *= c_dPixToMM;
dBoxWidth *= c_dPixToMM;
dBoxHeight *= c_dPixToMM;
return dBoxWidth;
}
public:
void LoadFontMetrics()
{
m_pManager->AfterLoad();
m_oCurrentInfo.m_lAscent = (m_pManager->m_lAscender < 0) ? ((USHORT)(-m_pManager->m_lAscender)) : (USHORT)m_pManager->m_lAscender;
m_oCurrentInfo.m_lDescent = (m_pManager->m_lDescender < 0) ? ((USHORT)(-m_pManager->m_lDescender)) : (USHORT)m_pManager->m_lDescender;
m_oCurrentInfo.m_lLineHeight = (m_pManager->m_lLineHeight < 0) ? ((USHORT)(-m_pManager->m_lLineHeight)) : (USHORT)m_pManager->m_lLineHeight;
m_oCurrentInfo.m_lUnitsPerEm = (m_pManager->m_lUnits_Per_Em < 0) ? ((USHORT)(-m_pManager->m_lUnits_Per_Em)) : (USHORT)m_pManager->m_lUnits_Per_Em;
}
};
class CHText
{
public:
CFontManagerWrapper m_oFontManager;
CHLine m_oLine;
CMetafile* m_pMeta;
NSStructures::CBrush* m_pBrush;
NSStructures::CFont* m_pFont;
NSStructures::CBrush* m_pLastBrush;
NSStructures::CFont* m_pLastFont;
Aggplus::CMatrix* m_pTransform;
Aggplus::CMatrix* m_pLastTransform;
CMetafile m_oMeta;
CMetafile* m_pPageMeta;
double m_dTextSpaceEps;
LONG m_lCountParagraphs;
LONG m_lCountWords;
LONG m_lCountSymbols;
LONG m_lCountSpaces;
public:
CHText() : m_oFontManager(), m_oLine()
{
m_dTextSpaceEps = 0.1;
m_lCountParagraphs = 0;
m_lCountWords = 0;
m_lCountSymbols = 0;
m_lCountSpaces = 0;
}
void Init(CApplicationFonts* pApplicationFonts)
{
m_oFontManager.Init(pApplicationFonts);
}
template<typename T>
void SetParams(T writer)
{
m_oFontManager.m_pFont = writer->m_pFont;
m_pBrush = writer->m_pBrush;
m_pFont = writer->m_pFont;
m_pLastBrush = &writer->m_oLastBrush;
m_pLastFont = &writer->m_oLastFont;
m_pTransform = writer->m_pTransform;
m_pLastTransform = &writer->m_oLastTransform;
m_pPageMeta = &writer->m_oPage;
switch (writer->m_lSrcFileType)
{
case AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF:
case AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_XPS:
break;
default:
m_dTextSpaceEps = 0.1;
break;
}
}
~CHText()
{
}
void NewPage()
{
m_oMeta.ClearNoAttack();
}
void ClosePage()
{
LONG nCount = m_oLine.GetCountChars();
if (0 != nCount)
DumpLine();
}
public:
template<typename T>
void CommandText(const int* pUnicodes, const int* pGids, const int& nCount,
const double& x, const double& y, const double& width, const double& height, bool bIsDumpFont, T writer)
{
// 1) сначала определяем точку отсчета и направление baseline
double _x1 = x;
double _y1 = y;
double _x2 = x + 1;
double _y2 = y;
m_pTransform->TransformPoint(_x1, _y1);
m_pTransform->TransformPoint(_x2, _y2);
double _k = 0;
double _b = 0;
bool _isConstX = false;
if (fabs(_x1 - _x2) < 0.001)
{
_isConstX = true;
_b = _x1;
}
else
{
_k = (_y1 - _y2) / (_x1 - _x2);
_b = _y1 - _k * _x1;
}
double dAbsVec = sqrt((_x1 - _x2) * (_x1 - _x2) + (_y1 - _y2) * (_y1 - _y2));
if (dAbsVec == 0)
dAbsVec = 1;
LONG nCountChars = m_oLine.GetCountChars();
bool bIsNewLine = true;
if (0 != nCountChars)
{
if (_isConstX && m_oLine.m_bIsConstX && fabs(_b - m_oLine.m_dB) < 0.001)
bIsNewLine = false;
else if (!_isConstX && !m_oLine.m_bIsConstX && fabs(_k - m_oLine.m_dK) < 0.001 && fabs(_b - m_oLine.m_dB) < 0.001)
bIsNewLine = false;
}
if (bIsNewLine && (0 != nCountChars))
{
// не совпала baseline. поэтому просто скидываем линию в поток
DumpLine();
}
// теперь нужно определить сдвиг по baseline относительно destination точки
nCountChars = m_oLine.GetCountChars();
double dOffsetX = 0;
if (0 == nCountChars)
{
m_oLine.m_bIsConstX = _isConstX;
m_oLine.m_dK = _k;
m_oLine.m_dB = _b;
m_oLine.m_dX = _x1;
m_oLine.m_dY = _y1;
m_oLine.m_ex = (_x2 - _x1) / dAbsVec;
m_oLine.m_ey = (_y2 - _y1) / dAbsVec;
m_oLine.m_dEndX = _x1;
m_oLine.m_dEndY = _y1;
}
else
{
double sx = _x1 - m_oLine.m_dEndX;
double sy = _y1 - m_oLine.m_dEndY;
double len = sqrt(sx*sx + sy*sy);
if (sx*m_oLine.m_ex >= 0 && sy*m_oLine.m_ey >= 0)
{
// продолжаем линию
dOffsetX = len;
// теперь посмотрим, может быть нужно вставить пробел??
CHChar* pLastChar = m_oLine.GetTail();
if (dOffsetX > (pLastChar->width + 0.5))
{
// вставляем пробел. Пробел у нас будет не совсем пробел. А специфический
CHChar* pSpaceChar = m_oLine.AddTail();
pSpaceChar->x = pLastChar->width;
pSpaceChar->width = dOffsetX - pLastChar->width;
pSpaceChar->unicode = 0xFFFF;
pSpaceChar->gid = 0xFFFF;
dOffsetX -= pLastChar->width;
m_oMeta.WriteBYTE(0);
}
}
else
{
// буква сдвинута влево относительно предыдущей буквы
// на такую ситуацию реагируем просто - просто начинаем новую линию,
// предварительно сбросив старую
DumpLine();
m_oLine.m_bIsConstX = _isConstX;
m_oLine.m_dX = _x1;
m_oLine.m_dY = _y1;
m_oLine.m_dK = _k;
m_oLine.m_dB = _b;
m_oLine.m_ex = (_x2 - _x1) / dAbsVec;
m_oLine.m_ey = (_y2 - _y1) / dAbsVec;
}
m_oLine.m_dEndX = _x1;
m_oLine.m_dEndY = _y1;
}
// смотрим, совпадает ли главная часть матрицы.
bool bIsTransform = !IsEqualMain(m_pLastTransform, m_pTransform);
if (bIsTransform)
bIsDumpFont = true;
bool bIsColor = ((m_pBrush->Color1 != m_pLastBrush->Color1) || (m_pBrush->Alpha1 != m_pLastBrush->Alpha1));
BYTE nLenMetaCommands = 0;
if (bIsColor)
nLenMetaCommands += 5;
if (bIsTransform)
nLenMetaCommands += 17;
if (bIsDumpFont)
nLenMetaCommands += 13;
m_oMeta.WriteBYTE(nLenMetaCommands);
agg::trans_affine* _src = &m_pTransform->m_agg_mtx;
double _dumpSize = writer->m_dCurrentFontSize;
double _dumpMtx[4];
_dumpMtx[0] = _src->sx;
_dumpMtx[1] = _src->shy;
_dumpMtx[2] = _src->shx;
_dumpMtx[3] = _src->sy;
double dTextScale = std::min( sqrt( _dumpMtx[2] * _dumpMtx[2] + _dumpMtx[3] * _dumpMtx[3] ), sqrt( _dumpMtx[0] * _dumpMtx[0] + _dumpMtx[1] * _dumpMtx[1] ) );
if ((_dumpSize < 0.1 && dTextScale > 10) || (_dumpSize > 10 && dTextScale < 0.1))
{
_dumpSize *= dTextScale;
_dumpMtx[0] /= dTextScale;
_dumpMtx[1] /= dTextScale;
_dumpMtx[2] /= dTextScale;
_dumpMtx[3] /= dTextScale;
}
if (bIsDumpFont)
{
m_oMeta.WriteCommandType(CMetafile::ctFontName);
m_oMeta.WriteLONG(writer->m_lCurrentFont);
m_oMeta.WriteLONG(writer->m_pFont->GetStyle());
m_oMeta.WriteDouble(_dumpSize/*writer->m_dCurrentFontSize*/);
}
if (bIsTransform)
{
agg::trans_affine* _dst = &m_pLastTransform->m_agg_mtx;
_dst->sx = _src->sx;
_dst->shx = _src->shx;
_dst->shy = _src->shy;
_dst->sy = _src->sy;
m_oLine.m_bIsSetUpTransform = true;
m_oLine.m_sx = _src->sx;
m_oLine.m_shx = _src->shx;
m_oLine.m_shy = _src->shy;
m_oLine.m_sy = _src->sy;
m_oMeta.WriteBYTE(CMetafile::ctCommandTextTransform);
//m_oMeta.WriteDouble(_dst->sx);
//m_oMeta.WriteDouble(_dst->shy);
//m_oMeta.WriteDouble(_dst->shx);
//m_oMeta.WriteDouble(_dst->sy);
m_oMeta.WriteDouble(_dumpMtx[0]);
m_oMeta.WriteDouble(_dumpMtx[1]);
m_oMeta.WriteDouble(_dumpMtx[2]);
m_oMeta.WriteDouble(_dumpMtx[3]);
}
if (bIsColor)
{
m_pLastBrush->Color1 = m_pBrush->Color1;
m_pLastBrush->Alpha1 = m_pBrush->Alpha1;
m_oMeta.WriteBYTE(CMetafile::ctBrushColor1);
LONG lBGR = m_pBrush->Color1;
m_oMeta.WriteBYTE((BYTE)(lBGR & 0xFF));
m_oMeta.WriteBYTE((BYTE)((lBGR >> 8) & 0xFF));
m_oMeta.WriteBYTE((BYTE)((lBGR >> 16) & 0xFF));
m_oMeta.WriteBYTE((BYTE)m_pBrush->Alpha1);
}
// все, baseline установлен. теперь просто продолжаем линию
LONG lTextLen = nCount;
bool bIsLoadFontAttack = true;
// говенные значения приходят из пдф
/*
if (1 == lTextLen && 0 <= width)
bIsLoadFontAttack = false;
*/
if (bIsDumpFont)
m_oFontManager.LoadCurrentFont(bIsLoadFontAttack);
double dKoef = m_oFontManager.m_pFont->Size * 25.4 / (72 * m_oFontManager.m_oCurrentInfo.m_lUnitsPerEm);
double dKoefMetr = dAbsVec;
double dAscender = m_oFontManager.m_oCurrentInfo.m_lAscent * dKoef * dKoefMetr;
double dDescender = m_oFontManager.m_oCurrentInfo.m_lDescent * dKoef * dKoefMetr;
if (m_oLine.m_dAscent < dAscender)
m_oLine.m_dAscent = dAscender;
if (m_oLine.m_dDescent < dDescender)
m_oLine.m_dDescent = dDescender;
if (!bIsLoadFontAttack)
{
CHChar* pChar = m_oLine.AddTail();
pChar->unicode = pUnicodes[0];
pChar->gid = (NULL == pGids) ? 0xFFFF : pGids[0];
pChar->width = width;
pChar->x = dOffsetX;
}
else
{
double dPlusOffset = 0;
const int* input = NULL;
if (NULL != pGids)
{
input = pGids;
m_oFontManager.SetStringGID(TRUE);
}
else
{
input = pUnicodes;
m_oFontManager.SetStringGID(FALSE);
}
double dBoxX = 0;
double dBoxY = 0;
double dBoxW = 0;
double dBoxH = 0;
double dPrevW = dOffsetX;
for (LONG lIndex = 0; lIndex < lTextLen; ++lIndex)
{
double dW = m_oFontManager.MeasureString((const unsigned int*)(input + lIndex), 1, 0, 0, dBoxX, dBoxY, dBoxW, dBoxH);
CHChar* pChar = m_oLine.AddTail();
pChar->unicode = pUnicodes[lIndex];
pChar->gid = (NULL == pGids) ? 0xFFFF : pGids[lIndex];
pChar->x = dPrevW;
if (lIndex != 0)
dPlusOffset += dPrevW;
dPrevW = dW;
pChar->width = dW * dAbsVec;
if (0 != lIndex)
m_oMeta.WriteBYTE(0);
if (lIndex == (lTextLen - 1))
{
m_oLine.m_dEndX += dPlusOffset * m_oLine.m_ex;
m_oLine.m_dEndY += dPlusOffset * m_oLine.m_ey;
}
}
}
}
void DumpLine()
{
if (m_oLine.m_bIsSetUpTransform)
{
// выставится трансформ!!!
// cравнивать нужно с ним!!!
agg::trans_affine* _dst = &m_pLastTransform->m_agg_mtx;
_dst->sx = m_oLine.m_sx;
_dst->shx = m_oLine.m_shx;
_dst->shy = m_oLine.m_shy;
_dst->sy = m_oLine.m_sy;
_dst->tx = 0;
_dst->ty = 0;
}
// скидываем линию в поток pMeta
BYTE mask = 0;
if (fabs(m_oLine.m_ex - 1.0) < 0.001 && fabs(m_oLine.m_ey) < 0.001)
mask |= g_lfHorizontal;
LONG lCountSpaces = 0;
LONG lCountSymbols = 0;
LONG lCountWords = 0;
bool bIsLastSymbol = false;
bool bIsGidExist = false;
LONG nCount = m_oLine.GetCountChars();
for (LONG i = 0; i < nCount; ++i)
{
CHChar* pChar = &m_oLine.m_pChars[i];
if (pChar->gid != 0xFFFF)
{
mask |= g_lfGids;
bIsGidExist = true;
}
if (0xFFFF == pChar->unicode || ((WCHAR)' ') == pChar->unicode || ((WCHAR)'\t') == pChar->unicode)
{
lCountSpaces++;
if (bIsLastSymbol)
{
bIsLastSymbol = false;
lCountWords++;
}
}
else
{
lCountSymbols++;
bIsLastSymbol = true;
}
}
if (bIsLastSymbol)
lCountWords++;
if (0 == nCount)
{
m_oLine.Clear();
m_oMeta.ClearNoAttack();
return;
}
m_lCountParagraphs += 1;
m_lCountWords += lCountWords;
m_lCountSymbols += lCountSymbols;
m_lCountSpaces += lCountSpaces;
if (nCount > 1)
mask |= g_lfWidth;
m_pPageMeta->CheckBufferSize(60);
m_pPageMeta->WriteBYTE_nocheck(CMetafile::ctCommandTextLine);
m_pPageMeta->WriteBYTE_nocheck(mask);
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_dX);
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_dY);
if ((mask & g_lfHorizontal) == 0)
{
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_ex);
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_ey);
}
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_dAscent);
m_pPageMeta->WriteDouble_nocheck(m_oLine.m_dDescent);
LONG _position = 0;
if (nCount > 1)
{
_position = m_pPageMeta->GetPosition();
m_pPageMeta->WriteLONG_nocheck(0);
}
BYTE* pBufferMeta = m_oMeta.GetData();
double dWidthLine = 0;
double dCurrentGlyphLineOffset = 0;
for (LONG lIndexChar = 0; lIndexChar < nCount; ++lIndexChar)
{
CHChar* pChar = &m_oLine.m_pChars[lIndexChar];
// все настроки буквы (m_oMeta)
BYTE lLen = *pBufferMeta;
++pBufferMeta;
if (lLen > 0)
{
m_pPageMeta->Write(pBufferMeta, lLen);
}
pBufferMeta += lLen;
// смещение относительно предыдущей буквы (у всех, кроме первой)
// юникодное значение
// гид (если bIsGidExist == true)
// ширина буквы
m_pPageMeta->CheckBufferSize(20);
m_pPageMeta->WriteBYTE_nocheck(CMetafile::ctDrawText);
if (0 != lIndexChar)
{
m_pPageMeta->WriteDouble2_nocheck(pChar->x);
}
m_pPageMeta->WriteWCHAR_nocheck2(pChar->unicode);
if (bIsGidExist)
m_pPageMeta->WriteUSHORT_nocheck(pChar->gid);
m_pPageMeta->WriteDouble2_nocheck(pChar->width);
if (lIndexChar != 0)
dCurrentGlyphLineOffset += pChar->x;
if (lIndexChar == (nCount - 1))
dWidthLine = dCurrentGlyphLineOffset + pChar->width;
}
if (nCount > 1)
{
LONG* pWidthBuf = (LONG*)(m_pPageMeta->GetData() + _position);
*pWidthBuf = (LONG)(dWidthLine * 10000);
}
m_oLine.Clear();
m_oMeta.ClearNoAttack();
m_pPageMeta->WriteBYTE(CMetafile::ctCommandTextLineEnd);
}
};
}
#endif // _ASC_HTMLRENDERER_TEXT_H_

View File

@ -0,0 +1,350 @@
#ifndef _ASC_HTMLRENDERER_VMLWRITER_H_
#define _ASC_HTMLRENDERER_VMLWRITER_H_
#include "Common.h"
namespace NSHtmlRenderer
{
class CVMLWriter
{
public:
NSStringUtils::CStringBuilder m_oPath;
NSStringUtils::CStringBuilder m_oDocument;
LONG m_lCurDocumentID;
LONG m_lClippingPath;
bool m_bIsClipping;
LONG m_lClipMode;
bool m_bIsClippingNow;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
double m_lWidth;
double m_lHeight;
double m_dDpiX;
double m_dDpiY;
public:
CVMLWriter() : m_oPath(), m_oDocument()
{
m_lCurDocumentID = 0;
m_lClippingPath = 0;
m_pPen = NULL;
m_pBrush = NULL;
m_dDpiX = 96;
m_dDpiY = 96;
m_lClipMode = c_nWindingFillMode;
m_bIsClipping = false;
m_bIsClippingNow = false;
}
void SetSettings(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush)
{
m_pPen = pPen;
m_pBrush = pBrush;
}
void CloseFile(std::wstring strFile = L"")
{
if (L"" != strFile)
{
m_oDocument.WriteString(L"</v:group>\n</xml>", 17);
NSFile::CFileBinary oFile;
oFile.CreateFileW(strFile);
BYTE* pData;
LONG nDataSize;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(m_oDocument.GetBuffer(), m_oDocument.GetCurSize(), pData, nDataSize);
oFile.WriteFile(pData, nDataSize);
RELEASEARRAYOBJECTS(pData);
}
if (3000000 < m_oDocument.GetSize())
m_oDocument.Clear();
m_oDocument.ClearNoAttack();
m_oPath.ClearNoAttack();
}
void NewDocument(double& dWidth, double& dHeigth, LONG& lPageNumber)
{
CloseFile(L"");
m_lWidth = (int)dWidth;
m_lHeight = (int)dHeigth;
m_lCurDocumentID = lPageNumber;
m_oDocument.AddSize(150);
m_oDocument.WriteString(L"<xml xmlns:v=\"urn:schemas-microsoft-com:vml\">\n<v:group id=\"page", 63);
m_oDocument.AddIntNoCheck((int)m_lCurDocumentID);
m_oDocument.WriteString(L"\" style=\"position: absolute; width:1; height:1;\" coordsize=\"1 1\">\n", 66);
}
public:
inline void WritePathEnd()
{
m_oPath.ClearNoAttack();
}
inline void WritePathStart()
{
m_oPath.ClearNoAttack();
}
void WritePathClose()
{
if (m_bIsClippingNow)
return;
m_oPath.AddCharSafe('x');
}
void WritePathMoveTo(double& x, double& y)
{
if (m_bIsClippingNow)
return;
m_oPath.AddSize(30);
m_oPath.AddCharNoSafe('m');
m_oPath.AddIntNoCheck(round(x));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(y));
m_oPath.AddCharNoSafe(' ');
}
void WritePathLineTo(double& x, double& y)
{
if (m_bIsClippingNow)
return;
if (0 == m_oPath.GetCurSize())
{
WritePathMoveTo(x, y);
}
m_oPath.AddSize(30);
m_oPath.AddCharNoSafe('l');
m_oPath.AddIntNoCheck(round(x));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(y));
m_oPath.AddCharNoSafe(' ');
}
void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
if (0 == m_oPath.GetCurSize())
{
WritePathMoveTo(x1, y1);
}
m_oPath.AddSize(80);
m_oPath.AddCharNoSafe('c');
m_oPath.AddIntNoCheck(round(x1));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(y1));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(x2));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(y2));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(x3));
m_oPath.AddCharNoSafe(',');
m_oPath.AddIntNoCheck(round(y3));
m_oPath.AddCharNoSafe(' ');
}
void WriteDrawPath(LONG lType, Aggplus::CMatrix* pTransform, Aggplus::CGraphicsPathSimpleConverter* pConverter, CImageInfo& oInfo, const double& dAngle)
{
if (m_oPath.GetCurSize() < 3)
return;
int nStrokeColor = ConvertColor(m_pPen->Color);
m_oDocument.WriteString(L"<v:shape style=\"position:absolute; width:1; height:1\" stroked=\"", 63);
bool bStroke = false;
bool bFilled = false;
if (m_pPen->Alpha == 0)
lType &= 0xFF00;
if ((-1 == oInfo.m_lID) && (0 == m_pBrush->Alpha1))
lType &= 0xFF;
// canvas
if ((lType & 0x01) == 0x01)
{
bStroke = true;
}
if (lType > 0x01)
{
bFilled = true;
}
if (bStroke)
m_oDocument.WriteString(L"true", 4);
else
m_oDocument.WriteString(L"false", 5);
m_oDocument.WriteString(L"\" strokecolor=\"", 15);
m_oDocument.WriteHexColor3(nStrokeColor);
m_oDocument.WriteString(L"\" filled=\"", 10);
if (bFilled)
m_oDocument.WriteString(L"true", 4);
else
m_oDocument.WriteString(L"false", 5);
m_oDocument.WriteString(L"\" ", 2);
if (-1 != oInfo.m_lID)
{
if (itJPG == oInfo.m_eType)
{
m_oDocument.WriteString(L"path=\"", 6);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\"><v:fill src=\"media/image", 26);
m_oDocument.AddSize(10);
m_oDocument.AddIntNoCheck(oInfo.m_lID);
m_oDocument.WriteString(L".jpg\" type=\"frame\" opacity=\"", 28);
m_oDocument.AddIntNoCheckDel100((100 * m_pBrush->TextureAlpha) / 255);
m_oDocument.WriteString(L"\"/></v:shape>\n", 14);
}
else
{
m_oDocument.WriteString(L"path=\"", 6);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\"><v:fill src=\"media/image", 26);
m_oDocument.AddSize(10);
m_oDocument.AddIntNoCheck(oInfo.m_lID);
m_oDocument.WriteString(L".png\" type=\"frame\" opacity=\"", 28);
m_oDocument.AddIntNoCheckDel100((100 * m_pBrush->TextureAlpha) / 255);
m_oDocument.WriteString(L"\"/></v:shape>\n", 14);
}
}
else if (0xFF == m_pBrush->Alpha1)
{
if (0x00 == (lType & 0xFF) || (0 == m_pPen->DashStyle))
{
m_oDocument.WriteString(L"fillcolor=\"", 11);
m_oDocument.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oDocument.WriteString(L"\" path=\"", 8);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
}
else
{
m_oDocument.WriteString(L"fillcolor=\"", 11);
m_oDocument.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oDocument.WriteString(L"\" path=\"", 8);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\"><v:stroke dashstyle=\"dot\"/></v:shape>\n", 40);
}
}
else
{
if (0x00 == (lType & 0xFF) || (0 == m_pPen->DashStyle))
{
m_oDocument.WriteString(L"fillcolor=\"", 11);
m_oDocument.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oDocument.WriteString(L"\" path=\"", 8);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\"><v:fill opacity=\"", 19);
m_oDocument.AddIntNoCheckDel100((100 * m_pBrush->Alpha1) / 255);
m_oDocument.WriteString(L"\" />\n", 5);
}
else
{
m_oDocument.WriteString(L"fillcolor=\"", 11);
m_oDocument.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oDocument.WriteString(L"\" path=\"", 8);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\"><v:fill opacity=\"", 19);
m_oDocument.AddIntNoCheckDel100((100 * m_pBrush->Alpha1) / 255);
m_oDocument.WriteString(L"\"><v:stroke dashstyle=\"dot\"/></v:shape>\n", 40);
}
}
}
void WriteImage(CImageInfo oInfo, const double& x, const double& y, const double& w, const double& h, const double& dAngle)
{
m_oDocument.WriteString(L"<v:image src=\"media/image", 25);
m_oDocument.AddSize(100);
m_oDocument.AddIntNoCheck(oInfo.m_lID);
if (itJPG == oInfo.m_eType)
m_oDocument.WriteString(L".jpg\" style=\"left:", 18);
else
m_oDocument.WriteString(L".png\" style=\"left:", 18);
m_oDocument.AddIntNoCheck(round(x));
m_oDocument.WriteString(L";top:", 5);
m_oDocument.AddIntNoCheck(round(y));
m_oDocument.WriteString(L";width:", 7);
m_oDocument.AddIntNoCheck(round(w));
m_oDocument.WriteString(L";height:", 8);
m_oDocument.AddIntNoCheck(round(h));
m_oDocument.WriteString(L";\"/>", 4);
}
void WritePathClip()
{
m_bIsClipping = true;
m_bIsClippingNow = true;
++m_lClippingPath;
}
void WritePathClipEnd()
{
m_bIsClippingNow = false;
}
void WritePathResetClip()
{
m_bIsClipping = false;
}
inline void WriteStyleClip()
{
}
void WriteToMainHtml(NSStringUtils::CStringBuilder* pWriter, const CDstInfo& oInfo)
{
if (!oInfo.m_bIsWeb)
{
pWriter->WriteString(L"<v:vmlframe clip=\"true\" origin=\"0,0\" size=\"", 43);
pWriter->AddSize(100);
pWriter->AddIntNoCheck((int)m_lWidth);
pWriter->AddCharNoSafe(',');
pWriter->AddIntNoCheck((int)m_lHeight);
pWriter->WriteString(L"\" src=\"page", 11);
pWriter->AddIntNoCheck(m_lCurDocumentID);
pWriter->WriteString(L".vml#page", 9);
pWriter->AddIntNoCheck(m_lCurDocumentID);
pWriter->WriteString(L"\" unselectable=\"on\"/>\n", 22);
std::wstring sPath = oInfo.m_strDstFilePath + L"\\page" + std::to_wstring(m_lCurDocumentID) + L".vml";
CloseFile(sPath);
}
else
{
pWriter->WriteString(L"<v:vmlframe clip=\"true\" origin=\"0,0\" size=\"", 43);
pWriter->AddSize(100);
pWriter->AddIntNoCheck((int)m_lWidth);
pWriter->AddCharNoSafe(',');
pWriter->AddIntNoCheck((int)m_lHeight);
pWriter->WriteString(L"\" src=\"", 7);
pWriter->WriteString(oInfo.m_strAdditionalPath);
pWriter->WriteString(L"/page", 5);
pWriter->AddIntNoCheck(m_lCurDocumentID);
pWriter->WriteString(L".vml#page", 9);
pWriter->AddIntNoCheck(m_lCurDocumentID);
pWriter->WriteString(L"\" unselectable=\"on\"/>\n", 22);
std::wstring sPath = oInfo.m_strDstFilePath + L"\\page" + std::to_wstring(m_lCurDocumentID) + L".vml";
CloseFile(sPath);
}
}
};
}
#endif // _ASC_HTMLRENDERER_VMLWRITER_H_

View File

@ -0,0 +1,729 @@
#ifndef _ASC_HTMLRENDERER_VGW_H_
#define _ASC_HTMLRENDERER_VGW_H_
#include "Common.h"
#include "../../../DesktopEditor/graphics/GraphicsPath.h"
#include <vector>
namespace NSHtmlRenderer
{
// приходится в html разруливать простую графику.
// (линии (горизонтальные/вектикальные), ректы (не повернутые)).
// для них не нужно генерить html5-код, который генерит тяжелую картинку
// и подгружает ее в память
const LONG g_lSimpleCommandsCountMax = 100;
class CVectorGraphicsWriter
{
public:
enum SimpleCommand
{
scMoveTo = 0,
scLineTo = 1,
scClose = 2
};
class CSimpleCommand
{
public:
SimpleCommand m_eType;
double m_dX;
double m_dY;
};
public:
NSStringUtils::CStringBuilder m_oWriterSimpleGraphics;
NSStringUtils::CStringBuilder m_oWriterVMLPath;
NSStringUtils::CStringBuilder m_oWriterCanvas;
NSStringUtils::CStringBuilder m_oWriterVML;
Aggplus::CGraphicsPathSimpleConverter* m_pSimpleConverter;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
Aggplus::CMatrix* m_pFullTransform;
double m_dCurrentMoveToX;
double m_dCurrentMoveToY;
bool m_bIsSimpleGraphics;
public:
bool m_bIsSimple;
bool m_bIsClip;
bool m_bIsClipping;
CSimpleCommand* m_arSimpleCommands;
LONG m_lCountSC;
public:
CVectorGraphicsWriter() : m_oWriterVML(), m_oWriterCanvas(), m_oWriterSimpleGraphics(), m_oWriterVMLPath()
{
m_bIsClip = FALSE;
m_bIsClipping = FALSE;
m_bIsSimple = TRUE;
m_pSimpleConverter = NULL;
m_pPen = NULL;
m_pBrush = NULL;
m_pFullTransform = NULL;
m_dCurrentMoveToX = 0;
m_dCurrentMoveToY = 0;
m_lCountSC = 0;
m_bIsSimpleGraphics = true;
m_arSimpleCommands = new CSimpleCommand[g_lSimpleCommandsCountMax];
}
~CVectorGraphicsWriter()
{
RELEASEARRAYOBJECTS(m_arSimpleCommands);
}
inline void EndPage()
{
m_oWriterSimpleGraphics.ClearNoAttack();
m_oWriterVMLPath.ClearNoAttack();
m_oWriterCanvas.ClearNoAttack();
m_oWriterVML.ClearNoAttack();
m_bIsSimpleGraphics = true;
}
inline void WriteBeginPath()
{
m_oWriterCanvas.WriteString(L"b(c);\n", 6);
}
inline void WriteEndPath()
{
m_oWriterVMLPath.ClearNoAttack();
m_bIsSimple = true;
m_lCountSC = 0;
}
void WritePathStart()
{
m_oWriterCanvas.WriteString(L"b(c);\n", 6);
}
void WritePathClose()
{
m_oWriterCanvas.WriteString(L"x(c);\n", 6);
if (!m_bIsClipping)
{
m_oWriterVMLPath.AddCharSafe('x');
}
if (m_bIsSimple)
{
if (0 < m_lCountSC)
{
m_arSimpleCommands[m_lCountSC].m_eType = scLineTo;
m_arSimpleCommands[m_lCountSC].m_dX = m_dCurrentMoveToX;
m_arSimpleCommands[m_lCountSC].m_dY = m_dCurrentMoveToY;
++m_lCountSC;
if (m_lCountSC == g_lSimpleCommandsCountMax)
{
m_bIsSimple = false;
}
}
}
}
void WritePathMoveTo(double& x, double& y)
{
m_oWriterCanvas.WriteString(L"m(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");\n", 3);
if (!m_bIsClipping)
{
m_oWriterVMLPath.AddCharSafe('m');
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterVMLPath);
m_oWriterVMLPath.AddCharSafe(' ');
}
if (m_bIsSimple)
{
m_arSimpleCommands[m_lCountSC].m_eType = scMoveTo;
m_arSimpleCommands[m_lCountSC].m_dX = x;
m_arSimpleCommands[m_lCountSC].m_dY = y;
m_dCurrentMoveToX = x;
m_dCurrentMoveToY = y;
++m_lCountSC;
if (m_lCountSC == g_lSimpleCommandsCountMax)
{
m_bIsSimple = false;
}
}
}
void WritePathLineTo(double& x, double& y)
{
if (0 == m_oWriterVMLPath.GetCurSize())
{
m_oWriterCanvas.WriteString(L"m(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");\n", 3);
m_oWriterVMLPath.AddCharSafe('m');
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterVMLPath);
m_oWriterVMLPath.AddCharSafe(' ');
}
m_oWriterCanvas.WriteString(L"l(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");\n", 3);
if (!m_bIsClipping)
{
m_oWriterVMLPath.AddCharSafe('l');
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterVMLPath);
m_oWriterVMLPath.AddCharSafe(' ');
}
if (m_bIsSimple)
{
if (0 == m_lCountSC)
{
m_arSimpleCommands[m_lCountSC].m_eType = scMoveTo;
m_arSimpleCommands[m_lCountSC].m_dX = x;
m_arSimpleCommands[m_lCountSC].m_dY = y;
m_dCurrentMoveToX = x;
m_dCurrentMoveToY = y;
++m_lCountSC;
}
else
{
double _x = m_arSimpleCommands[m_lCountSC - 1].m_dX;
double _y = m_arSimpleCommands[m_lCountSC - 1].m_dY;
if ((FABS(_x - x) < 0.01) || (FABS(_y - y) < 0.01))
{
// продолжаем симпл!
m_arSimpleCommands[m_lCountSC].m_eType = scLineTo;
m_arSimpleCommands[m_lCountSC].m_dX = x;
m_arSimpleCommands[m_lCountSC].m_dY = y;
++m_lCountSC;
if (m_lCountSC == g_lSimpleCommandsCountMax)
{
m_bIsSimple = false;
}
}
}
}
}
void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
if (0 == m_oWriterVMLPath.GetCurSize())
{
m_oWriterCanvas.WriteString(L"m(c,", 4);
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");\n", 3);
m_oWriterVMLPath.AddCharSafe('m');
WriteIntsToStringBuilder(round(x), round(y), &m_oWriterVMLPath);
m_oWriterVMLPath.AddCharSafe(' ');
}
m_oWriterCanvas.WriteString(L"cu(c,", 5);
WriteIntsToStringBuilder(round(x1), round(y1), round(x2), round(y2), round(x3), round(y3), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");\n", 3);
if (!m_bIsClipping)
{
m_oWriterVMLPath.AddCharSafe('c');
WriteIntsToStringBuilder(round(x1), round(y1), round(x2), round(y2), round(x3), round(y3), &m_oWriterVMLPath);
m_oWriterVMLPath.AddCharSafe(' ');
}
m_bIsSimple = false;
}
void WriteDrawPath(LONG lType, LONG lIDTx, LONG& lCurTxNumber, LONG& lPageNumber)
{
if (m_bIsSimple && (-1 == lIDTx))
{
// пишем по-крутому
double x = 0;
double y = 0;
double w = 0;
double h = 0;
bool bIsRect = IsRect(x, y, w, h);
if (bIsRect)
{
if ((0 == w && 0 == h))
return;
w = max(1, w);
h = max(1, h);
if (bIsRect)
{
CString strLineColor = GetStringColor(m_pPen->Color);
CString strFillColor = GetStringColor(m_pBrush->Color1);
if (0 == m_pBrush->Alpha1)
strFillColor = _T("transparent");
if ((1 >= w) || (1 >= h) && (lType < 0xFF))
{
m_oWriterSimpleGraphics.WriteString(L"<div class=\"rt\" style=\"border-width: 0px; background-color: ", 60);
SetStringColor(m_pPen->Color, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; border-color: ", 16);
SetStringColor(m_pPen->Color, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; opacity:", 10);
m_oWriterSimpleGraphics.AddIntNoCheckDel100(100 * m_pPen->Alpha / 255);
m_oWriterSimpleGraphics.AddSize(100);
m_oWriterSimpleGraphics.WriteString(L"; left: ", 8);
m_oWriterSimpleGraphics.AddIntNoCheck(round(x));
m_oWriterSimpleGraphics.WriteString(L"px; top: ", 9);
m_oWriterSimpleGraphics.AddIntNoCheck(round(y));
m_oWriterSimpleGraphics.WriteString(L"px; width: ", 11);
m_oWriterSimpleGraphics.AddIntNoCheck(round(w));
m_oWriterSimpleGraphics.WriteString(L"px; height: ", 12);
m_oWriterSimpleGraphics.AddIntNoCheck(round(h));
m_oWriterSimpleGraphics.WriteString(L"px;\"></div>\n");
}
else
{
if (0x00 == (lType & 0xFF))
{
m_oWriterSimpleGraphics.WriteString(L"<div class=\"rt\" style=\"border-width: 0px; background-color: ", 60);
if (0 == m_pBrush->Alpha1)
m_oWriterSimpleGraphics.WriteString(L"transparent", 11);
else
SetStringColor(m_pBrush->Color1, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; border-color: ", 16);
SetStringColor(m_pPen->Color, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; opacity:", 10);
m_oWriterSimpleGraphics.AddIntNoCheckDel100(100 * m_pBrush->Alpha1 / 255);
m_oWriterSimpleGraphics.AddSize(100);
m_oWriterSimpleGraphics.WriteString(L"; left: ", 8);
m_oWriterSimpleGraphics.AddIntNoCheck(round(x));
m_oWriterSimpleGraphics.WriteString(L"px; top: ", 9);
m_oWriterSimpleGraphics.AddIntNoCheck(round(y));
m_oWriterSimpleGraphics.WriteString(L"px; width: ", 11);
m_oWriterSimpleGraphics.AddIntNoCheck(round(w));
m_oWriterSimpleGraphics.WriteString(L"px; height: ", 12);
m_oWriterSimpleGraphics.AddIntNoCheck(round(h));
m_oWriterSimpleGraphics.WriteString(L"px;\"></div>\n");
}
else if (lType < 0xFF)
{
m_oWriterSimpleGraphics.WriteString(L"<div class=\"rt\" style=\"border-width: 1px; background-color: ", 60);
if (0 == m_pBrush->Alpha1)
m_oWriterSimpleGraphics.WriteString(L"transparent", 11);
else
SetStringColor(m_pBrush->Color1, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; border-color: ", 16);
SetStringColor(m_pPen->Color, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; opacity:", 10);
m_oWriterSimpleGraphics.AddIntNoCheckDel100(100 * m_pPen->Alpha / 255);
m_oWriterSimpleGraphics.AddSize(100);
m_oWriterSimpleGraphics.WriteString(L"; left: ", 8);
m_oWriterSimpleGraphics.AddIntNoCheck(round(x));
m_oWriterSimpleGraphics.WriteString(L"px; top: ", 9);
m_oWriterSimpleGraphics.AddIntNoCheck(round(y));
m_oWriterSimpleGraphics.WriteString(L"px; width: ", 11);
m_oWriterSimpleGraphics.AddIntNoCheck(round(w));
m_oWriterSimpleGraphics.WriteString(L"px; height: ", 12);
m_oWriterSimpleGraphics.AddIntNoCheck(round(h));
m_oWriterSimpleGraphics.WriteString(L"px;\"></div>\n");
}
else
{
m_oWriterSimpleGraphics.WriteString(L"<div class=\"rt\" style=\"border-width: 1px; background-color: ", 60);
if (0 == m_pBrush->Alpha1)
m_oWriterSimpleGraphics.WriteString(L"transparent", 11);
else
SetStringColor(m_pBrush->Color1, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; border-color: ", 16);
SetStringColor(m_pPen->Color, &m_oWriterSimpleGraphics);
m_oWriterSimpleGraphics.WriteString(L"; opacity:", 10);
m_oWriterSimpleGraphics.AddIntNoCheckDel100(100 * m_pBrush->Alpha1 / 255);
m_oWriterSimpleGraphics.AddSize(100);
m_oWriterSimpleGraphics.WriteString(L"; left: ", 8);
m_oWriterSimpleGraphics.AddIntNoCheck(round(x));
m_oWriterSimpleGraphics.WriteString(L"px; top: ", 9);
m_oWriterSimpleGraphics.AddIntNoCheck(round(y));
m_oWriterSimpleGraphics.WriteString(L"px; width: ", 11);
m_oWriterSimpleGraphics.AddIntNoCheck(round(w));
m_oWriterSimpleGraphics.WriteString(L"px; height: ", 12);
m_oWriterSimpleGraphics.AddIntNoCheck(round(h));
m_oWriterSimpleGraphics.WriteString(L"px;\"></div>\n");
}
}
}
}
else
{
m_bIsSimpleGraphics = false;
}
}
else
{
m_bIsSimpleGraphics = false;
}
std::wstring strStroked = L"false";
std::wstring strFilled = L"false";
//if (0x00 != (0x02 & (lType >> 8)) && ((lType & 0xFF) == 0x00))
//{
// lType = 1;
// m_pPen->Color = m_pBrush->Color1;
// m_pPen->Alpha = m_pBrush->Alpha1;
//}
bool bStroke = false;
if (m_pPen->Alpha == 0)
lType &= 0xFF00;
if ((-1 == lIDTx) && (0 == m_pBrush->Alpha1))
lType &= 0xFF;
// canvas
if ((lType & 0x01) == 0x01)
{
SetStrokeColor(m_pPen->Color, m_pPen->Alpha, &m_oWriterCanvas);
bStroke = true;
if (0x00 != m_pPen->Alpha)
{
strStroked = L"true";
}
}
if (lType > 0x01)
{
if (-1 != lIDTx)
{
double x = 0;
double y = 0;
double w = 0;
double h = 0;
m_pSimpleConverter->PathCommandGetBounds(&x, &y, &w, &h);
double r = x + w;
double b = y + h;
m_pFullTransform->TransformPoint(x, y);
m_pFullTransform->TransformPoint(r, b);
w = r - x;
h = b - y;
m_oWriterCanvas.WriteString(L"img", 3);
m_oWriterCanvas.AddInt(lIDTx);
m_oWriterCanvas.WriteString(L".src = \"media\\\\image", 20);
m_oWriterCanvas.AddInt(lIDTx);
m_oWriterCanvas.WriteString(L".jpg\";img", 9);
m_oWriterCanvas.AddInt(lIDTx);
m_oWriterCanvas.WriteString(L".onload = function(){c.drawImage(img", 36);
WriteIntsToStringBuilder(lIDTx, round(x), round(y), round(w), round(h), &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L");drawpage", 10);
m_oWriterCanvas.AddInt(lPageNumber);
m_oWriterCanvas.AddCharSafe('_');
m_oWriterCanvas.AddInt(lCurTxNumber);
m_oWriterCanvas.WriteString(L"(c);};\n}\nfunction drawpage", 26);
m_oWriterCanvas.AddInt(lPageNumber);
m_oWriterCanvas.AddCharSafe('_');
m_oWriterCanvas.AddInt(lCurTxNumber);
m_oWriterCanvas.WriteString(L"(c)\n{\n", 6);
}
else
{
SetFillColor(m_pBrush->Color1, m_pBrush->Alpha1, &m_oWriterCanvas);
m_oWriterCanvas.WriteString(L"f(c);\n", 6);
}
strFilled = L"true";
}
if (bStroke)
{
m_oWriterCanvas.WriteString(L"s(c);\n", 6);
}
if (-1 != lIDTx)
{
m_oWriterVML.WriteString(L"<v:shape style=\"position:absolute; width:1; height:1\" coordsize=\"1 1\" stroked=\"", 79);
m_oWriterVML.WriteString(strStroked);
m_oWriterVML.WriteString(L"\" strokecolor=\"", 15);
m_oWriterVML.WriteHexColor3(ConvertColor(m_pPen->Color));
m_oWriterVML.WriteString(L"\" filled=\"", 10);
m_oWriterVML.WriteString(strFilled);
m_oWriterVML.WriteString(L"\" path=\"", 8);
m_oWriterVML.Write(m_oWriterVMLPath);
m_oWriterVML.WriteString(L"\"><v:fill src=\"media\\image", 26);
m_oWriterVML.AddInt(lIDTx);
m_oWriterVML.WriteString(L".jpg\" type=\"frame\" opacity=\"", 28);
m_oWriterVML.AddIntDel100(100 * m_pBrush->Alpha1 / 255);
m_oWriterVML.WriteString(L"\"/></v:shape>\n", 14);
}
else if (0xFF == m_pBrush->Alpha1)
{
m_oWriterVML.WriteString(L"<v:shape style=\"position:absolute; width:1; height:1\" coordsize=\"1 1\" stroked=\"", 79);
m_oWriterVML.WriteString(strStroked);
m_oWriterVML.WriteString(L"\" strokecolor=\"", 15);
m_oWriterVML.WriteHexColor3(ConvertColor(m_pPen->Color));
m_oWriterVML.WriteString(L"\" filled=\"", 10);
m_oWriterVML.WriteString(strFilled);
m_oWriterVML.WriteString(L"\" fillcolor=\"", 13);
m_oWriterVML.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oWriterVML.WriteString(L"\" path=\"", 8);
m_oWriterVML.Write(m_oWriterVMLPath);
m_oWriterVML.WriteString(L"\" />\n", 5);
}
else
{
m_oWriterVML.WriteString(L"<v:shape style=\"position:absolute; width:1; height:1\" coordsize=\"1 1\" stroked=\"", 79);
m_oWriterVML.WriteString(strStroked);
m_oWriterVML.WriteString(L"\" strokecolor=\"", 15);
m_oWriterVML.WriteHexColor3(ConvertColor(m_pPen->Color));
m_oWriterVML.WriteString(L"\" filled=\"", 10);
m_oWriterVML.WriteString(strFilled);
m_oWriterVML.WriteString(L"\" fillcolor=\"", 13);
m_oWriterVML.WriteHexColor3(ConvertColor(m_pBrush->Color1));
m_oWriterVML.WriteString(L"\" path=\"", 8);
m_oWriterVML.Write(m_oWriterVMLPath);
m_oWriterVML.WriteString(L"\"><v:fill opacity=\"", 19);
m_oWriterVML.AddIntDel100(100 * m_pBrush->Alpha1 / 255);
m_oWriterVML.WriteString(L"\"/></v:shape>\n", 14);
}
m_oWriterVML.WriteString(strVML);
if (-1 != lIDTx)
{
++lCurTxNumber;
}
}
void WritePathClip()
{
m_bIsClipping = true;
}
void WritePathClipEnd()
{
m_bIsClipping = false;
double x = 0;
double y = 0;
double w = 0;
double h = 0;
m_pSimpleConverter->PathCommandGetBounds(&x, &y, &w, &h);
if ((0 > w) || (0 > h))
{
// никакого клипа нет!
return;
}
else
{
if (!m_bIsClip)
{
m_oWriterCanvas.WriteString(L"c.save();\n", 10);
}
m_bIsClip = true;
m_oWriterCanvas.WriteString(L"c.clip();\n", 10);
}
}
void WritePathResetClip()
{
if (m_bIsClip)
{
m_oWriterCanvas.WriteString(L"c.restore();\n", 13);
}
m_bIsClip = false;
m_bIsClipping = false;
}
protected:
bool IsRect(double& x, double& y, double& w, double& h)
{
if (1 >= m_lCountSC)
return false;
double dPrevX = m_arSimpleCommands[0].m_dX;
double dPrevY = m_arSimpleCommands[0].m_dY;
long lCurDirection = 0;
std::vector<double> arX;
std::vector<double> arY;
arX.push_back(dPrevX);
arY.push_back(dPrevY);
double dXmin = dPrevX;
double dXmax = dPrevX;
double dYmin = dPrevY;
double dYmax = dPrevY;
double _dX = m_arSimpleCommands[m_lCountSC - 1].m_dX;
double _dY = m_arSimpleCommands[m_lCountSC - 1].m_dY;
for (LONG i = 1; i < m_lCountSC; ++i)
{
CSimpleCommand* pComm = &m_arSimpleCommands[i];
if (scLineTo != pComm->m_eType)
return false;
long lDir = SkipCurDirection(lCurDirection, i, dPrevX, dPrevY);
double dX = _dX;
double dY = _dY;
if (i < m_lCountSC)
{
dX = m_arSimpleCommands[i - 1].m_dX;
dY = m_arSimpleCommands[i - 1].m_dY;
}
if (dX > dXmax)
dXmax = dX;
else if (dX < dXmin)
dXmin = dX;
if (dY > dYmax)
dYmax = dY;
else if (dY < dYmin)
dYmin = dY;
arX.push_back(dX);
arY.push_back(dY);
lCurDirection = lDir;
}
// все, массивы заполнены.
// теперь осталось определить, рект ли это
// должно:
// 1) кроме минимумов и максимумов ничего не может быть.
// 2) все точки ректа должны присутствовать
bool b1 = false;
bool b2 = false;
bool b3 = false;
bool b4 = false;
int lCount = (int)arX.size();
for (int i = 0; i < lCount; ++i)
{
double ___x = arX[i];
double ___y = arY[i];
bool bBreak = false;
if (IsEqualPoint(___x, ___y, dXmin, dYmin))
b1 = true;
else if (IsEqualPoint(___x, ___y, dXmax, dYmin))
b2 = true;
else if (IsEqualPoint(___x, ___y, dXmin, dYmax))
b4 = true;
else if (IsEqualPoint(___x, ___y, dXmax, dYmax))
b3 = true;
else
return false;
}
x = dXmin;
y = dYmin;
w = dXmax - dXmin;
h = dYmax - dYmin;
if (b1 && b2 && !b3 && !b4)
return true;
if (b1 && !b2 && !b3 && b4)
return true;
if (!b1 && b2 && b3 && !b4)
return true;
if (!b1 && !b2 && b3 && b4)
return true;
if (b1 && b2 && b3 && b4)
return true;
return false;
}
// direction: (0 - вправо, 1 - вниз, 2 - влево, 3 - вверх)
inline long SkipCurDirection(const long& lDirection, long& lIndexCur, double& dPrevX, double& dPrevY)
{
for (; lIndexCur < m_lCountSC; ++lIndexCur)
{
long lDir = GetCurDirection(lIndexCur, dPrevX, dPrevY);
dPrevX = m_arSimpleCommands[lIndexCur].m_dX;
dPrevY = m_arSimpleCommands[lIndexCur].m_dY;
if ((-1 == lDir) || (lDir == lDirection))
continue;
return lDir;
}
return -1;
}
inline long GetCurDirection(const long& lIndex, const double& dPrevX, const double& dPrevY)
{
double x = m_arSimpleCommands[lIndex].m_dX;
double y = m_arSimpleCommands[lIndex].m_dY;
if (FABS(y - dPrevY) < 0.01)
{
if (FABS(x - dPrevX) < 0.01)
{
return -1;
}
return (x >= dPrevX) ? 0 : 2;
}
else
{
return (y >= dPrevY) ? 1 : 3;
}
}
inline bool IsEqualPoint(double& x, double&y, double& _x, double& _y)
{
if ((FABS(x - _x) < 0.1) && (FABS(y - _y) < 0.1))
return true;
return false;
}
bool IsTwoRectOneDirection()
{
return true;
}
LONG SkipRect(LONG& lStart, LONG& lEnd)
{
}
};
}
#endif // _ASC_HTMLRENDERER_VGW_H_

View File

@ -0,0 +1,318 @@
#ifndef _ASC_HTMLRENDERER_VGW2_H_
#define _ASC_HTMLRENDERER_VGW2_H_
#include "Common.h"
#include "SVGWriter.h"
#include "VMLWriter.h"
#include "../../DesktopEditor/graphics/GraphicsPath.h"
namespace NSHtmlRenderer
{
class CVectorGraphicsWriter
{
public:
CSVGWriter m_oSVG;
CVMLWriter m_oVML;
//CCanvasWriter m_oCanvas;
Aggplus::CGraphicsPathSimpleConverter* m_pSimpleConverter;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
Aggplus::CMatrix* m_pFullTransform;
LONG m_lCurrentObjectInPage;
LONG m_lCurrentPageNumber;
double m_dWidth;
double m_dHeight;
public:
CVectorGraphicsWriter() : m_oSVG(), m_oVML()/*, m_oCanvas()*/
{
m_pSimpleConverter = NULL;
m_lCurrentObjectInPage = 0;
}
~CVectorGraphicsWriter()
{
}
void SetSettings(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, Aggplus::CGraphicsPathSimpleConverter* pSimpleConverter)
{
m_pPen = pPen;
m_pBrush = pBrush;
m_pSimpleConverter = pSimpleConverter;
m_oSVG.SetSettings(m_pPen, m_pBrush);
m_oVML.SetSettings(m_pPen, m_pBrush);
//m_oCanvas.SetSettings(m_pPen, m_pBrush, m_pSimpleConverter);
}
inline void NewPage(double& dW, double& dH, const LONG& lPageNumber)
{
m_lCurrentPageNumber = lPageNumber;
m_dWidth = dW;
m_dHeight = dH;
m_oSVG.NewDocument(m_dWidth, m_dHeight, m_lCurrentPageNumber);
m_oVML.NewDocument(m_dWidth, m_dHeight, m_lCurrentPageNumber);
}
inline void EndPage()
{
m_oSVG.CloseFile();
m_oVML.CloseFile();
//m_oCanvas.CloseFile();
m_lCurrentObjectInPage = 0;
}
inline void WriteEndPath()
{
m_oSVG.WritePathEnd();
m_oVML.WritePathEnd();
//m_oCanvas.WritePathEnd();
}
inline void WritePathStart()
{
m_oSVG.WritePathStart();
m_oVML.WritePathStart();
//m_oCanvas.WritePathStart();
}
inline void WritePathClose()
{
m_oSVG.WritePathClose();
m_oVML.WritePathClose();
//m_oCanvas.WritePathClose();
}
inline void WritePathMoveTo(double& x, double& y)
{
m_oSVG.WritePathMoveTo(x, y);
m_oVML.WritePathMoveTo(x, y);
//m_oCanvas.WritePathMoveTo(x,y);
}
inline void WritePathLineTo(double& x, double& y)
{
m_oSVG.WritePathLineTo(x, y);
m_oVML.WritePathLineTo(x, y);
//m_oCanvas.WritePathLineTo(x, y);
}
inline void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
m_oSVG.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
m_oVML.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
//m_oCanvas.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
}
inline void WriteDrawPath(LONG lType, CImageInfo& oInfo, const double& dAngle)
{
// вот мега заглушка под некоторые таблицы из pdf
// проблема в том, что приходит path нулевой толщины - а след-но он не рисуется.
// здесь это отслеживаем и правим пат. Не очень хорошо, так как всякие пунктирности
// в таких патах - теряются при таком подходе
if (0x00 == (lType & 0xFF))
{
double x = 0;
double y = 0;
double r = 0;
double b = 0;
m_pSimpleConverter->PathCommandGetBounds(x, y, r, b);
r += x;
b += y;
if ((fabs(r - x) < 0.5) || (fabs(b - y) < 0.5))
{
m_pFullTransform->TransformPoint(x, y);
m_pFullTransform->TransformPoint(r, b);
int _x = round(x);
int _y = round(y);
int _r = round(r);
int _b = round(b);
if ((_x == _r) || (_y == _b))
{
LONG lPenColor = m_pPen->Color;
LONG lPenAlpha = m_pPen->Alpha;
double dPenW = m_pPen->Size;
m_pPen->Color = m_pBrush->Color1;
m_pPen->Alpha = m_pBrush->Alpha1;
m_pPen->Size = c_ag_1pxWidth;
WriteEndPath();
WritePathStart();
WritePathMoveTo(x, y);
WritePathLineTo(r, b);
WriteDrawPath(0x01, oInfo, dAngle);
m_pPen->Color = lPenColor;
m_pPen->Alpha = lPenAlpha;
m_pPen->Size = dPenW;
return;
}
}
}
m_oSVG.WriteDrawPath(lType, m_pFullTransform, m_pSimpleConverter, oInfo, dAngle);
m_oVML.WriteDrawPath(lType, m_pFullTransform, m_pSimpleConverter, oInfo, dAngle);
m_pSimpleConverter->PathCommandEnd();
//m_oCanvas.WriteDrawPath(lType, m_pFullTransform, m_pSimpleConverter, lIdTx);
}
inline void WritePathClip()
{
m_oSVG.WritePathClip();
m_oVML.WritePathClip();
//m_oCanvas.WritePathClip();
}
inline void WritePathClipEnd()
{
m_oSVG.WritePathClipEnd();
m_oVML.WritePathClipEnd();
//m_oCanvas.WritePathClipEnd();
}
inline void SetClipMode(LONG lClipMode)
{
m_oSVG.m_lClipMode = lClipMode;
m_oVML.m_lClipMode = lClipMode;
}
inline void WriteImage(double& x, double& y, double& width, double& height, CImageInfo& oInfo, double dAngle)
{
m_oSVG.WriteImage(oInfo, x, y, width, height, dAngle);
m_oVML.WriteImage(oInfo, x, y, width, height, dAngle);
}
inline void WritePathResetClip()
{
m_oSVG.WritePathResetClip();
m_oVML.WritePathResetClip();
//m_oCanvas.WritePathResetClip();
}
inline bool IsGraphics()
{
// 10 цифр на номер страницы
// LEN(<xml xmlns:v=\"urn:schemas-microsoft-com:vml\">\n<v:group id=\"page%d\" style=\"position: absolute; width:1; height:1;\" coordsize=\"1 1\">\n) = 131
return ((131 + 10) < (int)m_oVML.m_oDocument.GetCurSize());
}
inline void WriteToDocument(NSStringUtils::CStringBuilder* pDocument, const CDstInfo& oInfo)
{
m_oSVG.WriteToMainHtml_1(pDocument, oInfo);
m_oVML.WriteToMainHtml(pDocument, oInfo);
m_oSVG.WriteToMainHtml_2(pDocument);
}
};
class CSVGGraphicsWriter
{
public:
CSVGWriter m_oSVG;
Aggplus::CGraphicsPathSimpleConverter* m_pSimpleConverter;
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
Aggplus::CMatrix* m_pFullTransform;
double m_dWidth;
double m_dHeight;
public:
CSVGGraphicsWriter() : m_oSVG()
{
m_pSimpleConverter = NULL;
}
~CSVGGraphicsWriter()
{
}
void SetSettings(NSStructures::CPen* pPen, NSStructures::CBrush* pBrush, Aggplus::CGraphicsPathSimpleConverter* pSimpleConverter)
{
m_pPen = pPen;
m_pBrush = pBrush;
m_pSimpleConverter = pSimpleConverter;
m_oSVG.SetSettings(m_pPen, m_pBrush);
}
inline void NewPage(double& dW, double& dH)
{
m_dWidth = dW;
m_dHeight = dH;
}
inline void EndPage()
{
m_oSVG.CloseFile();
}
inline void WriteEndPath()
{
m_oSVG.WritePathEnd();
}
inline void WritePathStart()
{
m_oSVG.WritePathStart();
}
inline void WritePathClose()
{
m_oSVG.WritePathClose();
}
inline void WritePathMoveTo(double& x, double& y)
{
m_oSVG.WritePathMoveTo(x, y);
}
inline void WritePathLineTo(double& x, double& y)
{
m_oSVG.WritePathLineTo(x, y);
}
inline void WritePathCurveTo(double& x1, double& y1, double& x2, double& y2, double& x3, double& y3)
{
m_oSVG.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
}
inline void WriteDrawPath(LONG lType)
{
CImageInfo oInfo;
m_oSVG.WriteDrawPath(lType, m_pFullTransform, m_pSimpleConverter, oInfo, 0.0);
m_pSimpleConverter->PathCommandEnd();
}
inline void WritePathClip()
{
m_oSVG.WritePathClip();
}
inline void WritePathClipEnd()
{
m_oSVG.WritePathClipEnd();
}
inline void SetClipMode(LONG lClipMode)
{
m_oSVG.m_lClipMode = lClipMode;
}
inline void WriteImage(double& x, double& y, double& width, double& height, CImageInfo& oInfo, double dAngle)
{
m_oSVG.WriteImage(oInfo, x, y, width, height, dAngle);
}
inline void WritePathResetClip()
{
m_oSVG.WritePathResetClip();
}
inline bool IsGraphics()
{
// 10 цифр на номер страницы
// LEN(<xml xmlns:v=\"urn:schemas-microsoft-com:vml\">\n<v:group id=\"page%d\" style=\"position: absolute; width:1; height:1;\" coordsize=\"1 1\">\n) = 131
return ((131 + 10) < (int)m_oSVG.m_oDocument.GetCurSize());
}
};
}
#endif // _ASC_HTMLRENDERER_VGW2_H_

2098
HtmlRenderer/src/Writer.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
#include <QCoreApplication>
#include "../../../PdfReader/PdfReader.h"
#include "../include/HTMLRenderer3.h"
#include "../../../DesktopEditor/fontengine/ApplicationFonts.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//std::wstring sFile = L"\\\\KIRILLOV8\\_Office\\PDF\\Android intro(2p).pdf";
std::wstring sFile = L"\\\\kirillov8\\_Office\\PDF\\Main Window(15p).pdf";
CApplicationFonts oFonts;
oFonts.Initialize();
PdfReader::CPdfReader oReader(&oFonts);
oReader.SetTempFolder(L"D:\\test\\Document");
bool bResult = oReader.LoadFromFile(sFile.c_str());
NSHtmlRenderer::CASCHTMLRenderer3 oHtmlRenderer;
oHtmlRenderer.CreateOfficeFile(L"D:\\test\\Document");
int nPagesCount = oReader.GetPagesCount();
for (int i = 0; i < nPagesCount; ++i)
{
oReader.DrawPageOnRenderer(&oHtmlRenderer, i, NULL);
}
oHtmlRenderer.CloseFile();
return a.exec();
}

View File

@ -0,0 +1,30 @@
#-------------------------------------------------
#
# Project created by QtCreator 2015-07-21T18:28:42
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
INCLUDEPATH += \
../../../DesktopEditor/freetype-2.5.2/include \
TEMPLATE = app
LIBS += -L../../../../SDK/lib/win_64/DEBUG -lASCOfficeUtilsLib
LIBS += -L../../../../SDK/lib/win_64/DEBUG -lgraphics
LIBS += -L../../../../SDK/lib/win_64/DEBUG -lHtmlRenderer
LIBS += -L../../../../SDK/lib/win_64/DEBUG -llibxml
LIBS += -L../../../../SDK/lib/win_64/DEBUG -lPdfReader
LIBS += -lgdi32 \
-ladvapi32 \
-luser32 \
-lshell32
SOURCES += main.cpp