Commit 831ab545 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

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

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63667 954022d7-b5bf-4e40-9824-e11837661b57
parent b83109f7
......@@ -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
#-------------------------------------------------
#
# 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
}
#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_
#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_
#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_
#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_
#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_
#ifndef _ASC_HTMLRENDERER_FMBASE_H_
#define _ASC_HTMLRENDERER_FMBASE_H_
#include "Common.h"
#include <vector>
#include <map>
#include <list>
namespace NSHtmlRenderer
{
namespace NSFontManager
{
const double c_dInchToMM = 25.4;
const double c_dPixToMM = 25.4 / 72.0;
const double c_dPtToMM = 25.4 / 72.0;
const double c_dMMToPt = 72.0 / 25.4;
const double c_dDpi = 72.0;
class CFontProperties
{
public:
std::wstring m_strFamilyName;
BYTE m_strPANOSE[10];
LONG m_lStyle;
std::vector<DWORD> m_arSignature;
bool m_bIsFixedWidth;
LONG m_lAvgWidth;
public:
CFontProperties()
{
m_strFamilyName = L"";
memset(m_strPANOSE, 0, 10);
m_lStyle = 0;
m_arSignature.clear();
m_bIsFixedWidth = false;
m_lAvgWidth = -1;
}
CFontProperties(const CFontProperties& oSrc)
{
*this = oSrc;
}
CFontProperties& operator=(const CFontProperties& oSrc)
{
m_strFamilyName = oSrc.m_strFamilyName;
memcpy(m_strPANOSE, oSrc.m_strPANOSE, 10);
m_lStyle = oSrc.m_lStyle;
m_arSignature = oSrc.m_arSignature;
m_bIsFixedWidth = oSrc.m_bIsFixedWidth;
m_lAvgWidth = oSrc.m_lAvgWidth;
return *this;
}
~CFontProperties()
{
}
};
class CFontAdvanced
{
public:
NSStructures::CFont m_oFont;
// font metrics
double m_dAscent;
double m_dDescent;
double m_dLineSpacing;
double m_dEmHeight;
double m_dBaselineOffsetDOCX;
double m_dBaselineOffsetHTML;
double m_dSpaceWidthMM;
// font params
CFontProperties m_oProperties;
public:
CFontAdvanced(): m_oProperties()
{
m_oFont.SetDefaultParams();
m_dAscent = 0;
m_dDescent = 0;
m_dLineSpacing = 0;
m_dEmHeight = 0;
m_dBaselineOffsetDOCX = 0;
m_dBaselineOffsetHTML = 0;
m_dSpaceWidthMM = 0;
}
CFontAdvanced(const CFontAdvanced& oSrc)
{
*this = oSrc;
}
CFontAdvanced& operator=(const CFontAdvanced& oSrc)
{
m_oFont = oSrc.m_oFont;
m_dAscent = oSrc.m_dAscent;
m_dDescent = oSrc.m_dDescent;
m_dLineSpacing = oSrc.m_dLineSpacing;
m_dEmHeight = oSrc.m_dEmHeight;
m_dBaselineOffsetDOCX = oSrc.m_dBaselineOffsetDOCX;
m_dBaselineOffsetHTML = oSrc.m_dBaselineOffsetHTML;
m_dSpaceWidthMM = oSrc.m_dSpaceWidthMM;
m_oProperties = oSrc.m_oProperties;
return *this;
}
};
class CFontPickUp
{
public:
CFontAdvanced m_oFont;
BYTE m_lRangeNum;
BYTE m_lRange;
std::wstring m_strPickFont;
LONG m_lPickStyle;
public:
CFontPickUp() : m_oFont()
{
m_lRangeNum = 0xFF;
m_lRange = 0xFF;
m_strPickFont = L"";
m_lPickStyle = 0;
}
CFontPickUp(const CFontPickUp& oSrc)
{
*this = oSrc;
}
CFontPickUp& operator=(const CFontPickUp& oSrc)
{
m_oFont = oSrc.m_oFont;
m_lRange = oSrc.m_lRange;
m_lRangeNum = oSrc.m_lRangeNum;
m_strPickFont = oSrc.m_strPickFont;
m_lPickStyle = oSrc.m_lPickStyle;
return *this;
}
};
class CFontManagerBase
{
public:
enum MeasureType
{
MeasureTypeGlyph = 0,
MeasureTypePosition = 1
};
protected:
CApplicationFonts m_oApplicationFonts;
CFontManager* m_pManager;
std::wstring m_strDefaultFont;
public:
CFontAdvanced m_oFont;
//для подбора шрифтов
BYTE m_pRanges[0xFFFF];
BYTE m_pRangesNums[0xFFFF];
BYTE m_mapUnicode[0xFFFF];
std::map<std::wstring, CFontProperties> m_mapFontPathToProperties;
CFontProperties* m_pCurrentProperties;
std::list<CFontPickUp> m_arListPicUps;
std::wstring m_strCurrentPickFont;
LONG m_lCurrentPictFontStyle;
bool m_bIsUseFontWidth;
public:
CFontManagerBase() : m_oFont(), m_mapFontPathToProperties(), m_oApplicationFonts()
{
m_oApplicationFonts.Initialize();
m_pManager = m_oApplicationFonts.GenerateFontManager();
SetDefaultFont(L"Arial");
ClearPickUps();
InitializeRanges();
InitializeUnicodeMap();
ClearPickUps();
m_pCurrentProperties = NULL;
m_bIsUseFontWidth = false;
}
virtual ~CFontManagerBase()
{
RELEASEOBJECT(m_pManager);
}
inline void ClearPickUps()
{
m_arListPicUps.clear();
m_strCurrentPickFont = L"";
m_lCurrentPictFontStyle = 0;
}
public:
inline void SetDefaultFont(const std::wstring& strName)
{
m_strDefaultFont = strName;
//m_pManager->SetDefaultFont(m_strDefaultFont);
}
inline std::wstring GetDefaultFont()
{
return m_strDefaultFont;
}
virtual void LoadFont(long lFaceIndex = 0, bool bIsNeedAddToMap = true)
{
}
inline void LoadCurrentFont(long lFaceIndex = 0)
{
if (m_oFont.m_oFont.Path.empty())
{
LoadFontByName(m_oFont.m_oFont.Name, m_oFont.m_oFont.Size, m_oFont.m_oFont.GetStyle());
}
else
{
LoadFontByFile(m_oFont.m_oFont.Path, m_oFont.m_oFont.Size, lFaceIndex);
m_oFont.m_oFont.SetStyle(m_oFont.m_oProperties.m_lStyle);
}
}
void LoadFontByName(std::wstring& strName, const double& dSize, const LONG& lStyle)
{
m_pManager->LoadFontByName(strName, (float)dSize, lStyle, c_dDpi, c_dDpi);
LoadFontMetrics();
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
m_oFont.m_oProperties.m_lStyle = m_oFont.m_oFont.GetStyle();
m_strCurrentPickFont = m_oFont.m_oProperties.m_strFamilyName;
m_lCurrentPictFontStyle = m_oFont.m_oProperties.m_lStyle;
m_oFont.m_oProperties.m_lAvgWidth = -1;
}
void LoadFontByFile(std::wstring& strPath, const double& dSize, const LONG& lFaceIndex)
{
m_pManager->LoadFontFromFile(strPath, lFaceIndex, dSize, c_dDpi, c_dDpi);
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
m_oFont.m_oProperties.m_lStyle = m_oFont.m_oFont.GetStyle();
m_strCurrentPickFont = m_oFont.m_oProperties.m_strFamilyName;
m_lCurrentPictFontStyle = m_oFont.m_oProperties.m_lStyle;
m_oFont.m_oProperties.m_lAvgWidth = -1;
LoadFontMetrics();
LoadFontParams();
}
public:
void MeasureString(const std::wstring& strText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
MeasureStringPix(strText, x, y, dBoxX, dBoxY, dBoxWidth, dBoxHeight, measureType);
// переводим в миллиметры
dBoxX *= c_dPixToMM;
dBoxY *= c_dPixToMM;
dBoxWidth *= c_dPixToMM;
dBoxHeight *= c_dPixToMM;
}
void MeasureStringPix(std::wstring bsText, double x, double y, double& dBoxX, double& dBoxY, double& dBoxWidth, double& dBoxHeight, MeasureType measureType)
{
dBoxX = 0;
dBoxY = 0;
dBoxWidth = 0;
dBoxHeight = 0;
if (NULL == m_pManager)
return;
m_pManager->LoadString1(bsText, (float)x, (float)y);
TBBox tBox;
if (MeasureTypeGlyph == measureType)
{
tBox = m_pManager->MeasureString();
}
else if (MeasureTypePosition == measureType)
{
tBox = m_pManager->MeasureString2();
}
dBoxX = (double)tBox.fMinX;
dBoxY = (double)tBox.fMinY;
dBoxWidth = (double)(tBox.fMaxX - tBox.fMinX);
dBoxHeight = (double)(tBox.fMaxY - tBox.fMinY);
}
public:
void LoadFontMetrics()
{
m_pManager->AfterLoad();
m_oFont.m_dAscent = m_pManager->m_lAscender;
m_oFont.m_dDescent = m_pManager->m_lDescender;
m_oFont.m_dLineSpacing = m_pManager->m_lLineHeight;
m_oFont.m_dEmHeight = m_pManager->m_lUnits_Per_Em;
m_oFont.m_dBaselineOffsetDOCX = (c_dPtToMM * m_oFont.m_dDescent * m_oFont.m_oFont.Size / m_oFont.m_dEmHeight);
double d1 = 3 * (m_oFont.m_dLineSpacing - m_oFont.m_dDescent) - m_oFont.m_dAscent;
d1 /= 2.0;
d1 *= (m_oFont.m_oFont.Size / m_oFont.m_dEmHeight);
m_oFont.m_dBaselineOffsetHTML = d1;
}
std::wstring DeletePdfPrefix(const std::wstring& sFamilyName)
{
// Удаляем префикс, который встречается в шрифтах внедренных в PDF
// Его вид : BAAAAA+FamilyName (6 латинских букв в верхнем регистре и '+')
// Пример : EOODIA+Poetica
if ( sFamilyName.length() > 7 )
{
const wchar_t* buf = sFamilyName.c_str();
bool bPrefix = true;
for ( int nIndex = 0; nIndex < 6; nIndex++ )
{
wchar_t nChar = buf[nIndex];
if ( nChar < (wchar_t)('A') || nChar > (wchar_t)('Z') )
{
bPrefix = false;
break;
}
}
if ( buf[6] != wchar_t('+') )
bPrefix = false;
if ( bPrefix )
{
return sFamilyName.substr(7);
}
}
else
{
// Ничего не делаем
return sFamilyName;
}
}
void LoadFontParams()
{
// читаем и выставляем все настройки шрифта
if (NULL == m_pManager)
return;
// загрузка была из path
std::map<std::wstring, CFontProperties>::const_iterator iFind = m_mapFontPathToProperties.find(m_oFont.m_oFont.Path);
if (iFind != m_mapFontPathToProperties.end())
{
m_oFont.m_oProperties = iFind->second;
return;
}
if (m_oFont.m_oFont.Name.empty())
{
// FamilyName
m_oFont.m_oProperties.m_strFamilyName = DeletePdfPrefix(m_pManager->m_sName);
}
else
{
m_oFont.m_oProperties.m_strFamilyName = m_oFont.m_oFont.Name;
}
CFontFile* pFontFile = m_pManager->m_pFont;
if (!pFontFile)
return;
// StyleName
std::string strStyle = pFontFile->GetStyleName();
if ("Bold" == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x01;
}
else if ("Italic" == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x02;
}
else if ("Bold Italic" == strStyle)
{
m_oFont.m_oProperties.m_lStyle = 0x03;
}
else
{
m_oFont.m_oProperties.m_lStyle = 0x00;
}
pFontFile->GetPanose(m_oFont.m_oProperties.m_strPANOSE);
// IsFixed
m_oFont.m_oProperties.m_bIsFixedWidth = pFontFile->IsFixedWidth();
// Signature
m_oFont.m_oProperties.m_arSignature.clear();
for ( unsigned int i = 0; i < 6; i++ )
{
DWORD value = 0;
for ( unsigned long bit = 0; bit < 32; bit++ )
{
int iRes = pFontFile->IsUnicodeRangeAvailable( bit, i );
if( iRes > 0 )
{
value |= ( 1 << bit );
}
}
m_oFont.m_oProperties.m_arSignature.push_back(value);
}
if (m_bIsUseFontWidth)
{
std::wstring sExt;
std::wstring sEncodingPath;
int nFindExt = m_oFont.m_oFont.Path.find_last_of((wchar_t)'.');
if (nFindExt == std::wstring::npos)
{
sEncodingPath = m_oFont.m_oFont.Path + L".enc";
sExt = L"";
}
else
{
sExt = m_oFont.m_oFont.Path.substr(nFindExt + 1);
sEncodingPath = m_oFont.m_oFont.Path.substr(0, nFindExt);
}
bool bIsCID = false;
if (std::wstring::npos != sExt.find(L"cid"))
bIsCID = true;
XmlUtils::CXmlNode oMainNode;
oMainNode.FromXmlFile(sEncodingPath);
if (L"PDF-resources" == oMainNode.GetName())
{
if (bIsCID)
{
XmlUtils::CXmlNode oType0Node;
if ( oMainNode.GetNode( L"Type0", oType0Node ) )
{
XmlUtils::CXmlNode oNode;
if ( oType0Node.GetNode( L"DescendantFonts", oNode ) )
{
XmlUtils::CXmlNode oDescNode;
if ( oNode.GetNode( L"FontDescriptor", oDescNode ) )
{
XmlUtils::CXmlNode oCurNode;
if ( oNode.GetNode( L"AvgWidth", oCurNode ) )
{
m_oFont.m_oProperties.m_lAvgWidth = oCurNode.GetAttributeInt(L"value");
}
}
}
}
}
else
{
XmlUtils::CXmlNode oNode;
if ( oMainNode.GetNode( L"FontDescriptor", oNode ) )
{
XmlUtils::CXmlNode oCurNode;
if ( oNode.GetNode( L"AvgWidth", oCurNode ) )
{
m_oFont.m_oProperties.m_lAvgWidth = oCurNode.GetAttributeInt(L"value");
}
else
{
XmlUtils::CXmlNode oNodeWidths;
if (oMainNode.GetNode(L"Widths", oNodeWidths))
{
LONG lCount = 0;
double dWidth = 0;
XmlUtils::CXmlNodes oNodesW;
if (oNodeWidths.GetNodes(L"Width", oNodesW))
{
int nCountW = oNodesW.GetCount();
for (int i = 0; i < nCountW; ++i)
{
XmlUtils::CXmlNode oNodeMem;
oNodesW.GetAt(i, oNodeMem);
double dMem = oCurNode.GetAttributeDouble(L"value");
if (0 < dMem)
{
++lCount;
dWidth += dMem;
}
}
}
if (10 < lCount)
{
m_oFont.m_oProperties.m_lAvgWidth = (LONG)(0.8 * dWidth / lCount);
}
}
}
}
}
}
}
m_mapFontPathToProperties.insert(std::pair<std::wstring, CFontProperties>(m_oFont.m_oFont.Path, m_oFont.m_oProperties));
}
private:
void InitializeRanges()
{
memset(m_pRanges, 0xFF, 0xFFFF);
memset(m_pRangesNums, 0xFF, 0xFFFF);
// теперь просто по порядку заполняем все рэнджи
int nStart = 0;
int nCount = 0;
// rangeNum 0
// case 00: sUCRName = "Basic Latin"; break; /* U+0020-U+007E */
nStart = 0x0020;
nCount = 0x007E - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 01: sUCRName = "Latin-1 Supplement"; break; /* U+0080-U+00FF */
nStart = 0x0080;
nCount = 0x00FF - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 02: sUCRName = "Latin Extended-A"; break; /* U+0100-U+017F */
nStart = 0x0100;
nCount = 0x017F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 03: sUCRName = "Latin Extended-B"; break; /* U+0180-U+024F */
nStart = 0x0180;
nCount = 0x024F - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 04: sUCRName = "IPA Extensions"; break; /* U+0250-U+02AF */ /* U+1D00-U+1D7F */ /* U+1D80-U+1DBF */
nStart = 0x0250;
nCount = 0x02AF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1D00;
nCount = 0x1D7F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1D80;
nCount = 0x1DBF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 05: sUCRName = "Spacing Modifier Letters"; break; /* U+02B0-U+02FF */ /* U+A700-U+A71F */
nStart = 0x02B0;
nCount = 0x02FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA700;
nCount = 0xA71F - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 06: sUCRName = "Combining Diacritical Marks"; break; /* U+0300-U+036F */ /* U+1DC0-U+1DFF */
nStart = 0x0300;
nCount = 0x036F - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x1DC0;
nCount = 0x1DFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 07: sUCRName = "Greek and Coptic"; break; /* U+0370-U+03FF */
nStart = 0x0370;
nCount = 0x03FF - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 08: sUCRName = "Coptic"; break; /* U+2C80-U+2CFF */
nStart = 0x2C80;
nCount = 0x2CFF - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 09: sUCRName = "Cyrillic"; break; /* U+0400-U+04FF */ /* U+0500-U+052F */ /* U+2DE0-U+2DFF */ /* U+A640-U+A69F */
nStart = 0x0400;
nCount = 0x04FF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x0500;
nCount = 0x052F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2DE0;
nCount = 0x2DFF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA640;
nCount = 0xA69F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 10: sUCRName = "Armenian"; break; /* U+0530-U+058F */
nStart = 0x0530;
nCount = 0x058F - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 11: sUCRName = "Hebrew"; break; /* U+0590-U+05FF */
nStart = 0x0590;
nCount = 0x05FF - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 12: sUCRName = "Vai"; break; /* U+A500-U+A63F */
nStart = 0xA500;
nCount = 0xA63F - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 13: sUCRName = "Arabic"; break; /* U+0600-U+06FF */ /* U+0750-U+077F */
nStart = 0x0600;
nCount = 0x06FF - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x0750;
nCount = 0x077F - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 14: sUCRName = "NKo"; break; /* U+07C0-U+07FF */
nStart = 0x07C0;
nCount = 0x07FF - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 15: sUCRName = "Devanagari"; break; /* U+0900-U+097F */
nStart = 0x0900;
nCount = 0x097F - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 16: sUCRName = "Bengali"; break; /* U+0980-U+09FF */
nStart = 0x0980;
nCount = 0x09FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 17: sUCRName = "Gurmukhi"; break; /* U+0A00-U+0A7F */
nStart = 0x0A00;
nCount = 0x0A7F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 18: sUCRName = "Gujarati"; break; /* U+0A80-U+0AFF */
nStart = 0x0A80;
nCount = 0x0AFF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 19: sUCRName = "Oriya"; break; /* U+0B00-U+0B7F */
nStart = 0x0B00;
nCount = 0x0B7F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 20: sUCRName = "Tamil"; break; /* U+0B80-U+0BFF */
nStart = 0x0B80;
nCount = 0x0BFF - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 21: sUCRName = "Telugu"; break; /* U+0C00-U+0C7F */
nStart = 0x0C00;
nCount = 0x0C7F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 22: sUCRName = "Kannada"; break; /* U+0C80-U+0CFF */
nStart = 0x0C80;
nCount = 0x0CFF - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 23: sUCRName = "Malayalam"; break; /* U+0D00-U+0D7F */
nStart = 0x0D00;
nCount = 0x0D7F - nStart + 1;
memset(m_pRanges + nStart, 23, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 24: sUCRName = "Thai"; break; /* U+0E00-U+0E7F */
nStart = 0x0E00;
nCount = 0x0E7F - nStart + 1;
memset(m_pRanges + nStart, 24, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 25: sUCRName = "Lao"; break; /* U+0E80-U+0EFF */
nStart = 0x0E80;
nCount = 0x0EFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 26: sUCRName = "Georgian"; break; /* U+10A0-U+10FF */ /* U+2D00-U+2D2F */
nStart = 0x10A0;
nCount = 0x10FF - nStart + 1;
memset(m_pRanges + nStart, 26, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2D00;
nCount = 0x2D2F - nStart + 1;
memset(m_pRanges + nStart, 26, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 27: sUCRName = "Balinese"; break; /* U+1B00-U+1B7F */
nStart = 0x1B00;
nCount = 0x1B7F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 28: sUCRName = "Hangul Jamo"; break; /* U+1100-U+11FF */
nStart = 0x1100;
nCount = 0x11FF - nStart + 1;
memset(m_pRanges + nStart, 28, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 29: sUCRName = "Latin Extended Additional"; break; /* U+1E00-U+1EFF */ /* U+2C60-U+2C7F */ /* U+A720-U+A7FF */
nStart = 0x1E00;
nCount = 0x1EFF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2C60;
nCount = 0x2C7F - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0xA720;
nCount = 0xA7FF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 30: sUCRName = "Greek Extended"; break; /* U+1F00-U+1FFF */
nStart = 0x1F00;
nCount = 0x1FFF - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
//case 31: sUCRName = "General Punctuation"; break; /* U+2000-U+206F */ /* U+2E00-U+2E7F */
nStart = 0x2000;
nCount = 0x206F - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
nStart = 0x2E00;
nCount = 0x2E7F - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 0, nCount);
// rangeNum 1
//case 00: sUCRName = "Superscripts And Subscripts"; break; /* U+2070-U+209F */
nStart = 0x2070;
nCount = 0x209F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 01: sUCRName = "Currency Symbols"; break; /* U+20A0-U+20CF */
nStart = 0x20A0;
nCount = 0x20CF - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 02: sUCRName = "Combining Diacritical Marks For Symbols"; break; /* U+20D0-U+20FF */
nStart = 0x20D0;
nCount = 0x20FF - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 03: sUCRName = "Letterlike Symbols"; break; /* U+2100-U+214F */
nStart = 0x2100;
nCount = 0x214F - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 04: sUCRName = "Number Forms"; break; /* U+2150-U+218F */
nStart = 0x2150;
nCount = 0x218F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 05: sUCRName = "Arrows"; break; /* U+2190-U+21FF */ /* U+27F0-U+27FF */ /* U+2900-U+297F */ /* U+2B00-U+2BFF */
nStart = 0x2190;
nCount = 0x21FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x27F0;
nCount = 0x27FF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2900;
nCount = 0x297F - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2B00;
nCount = 0x2BFF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 06: sUCRName = "Mathematical Operators"; break; /* U+2200-U+22FF */ /* U+2A00-U+2AFF */ /* U+27C0-U+27EF */ /* U+2980-U+29FF */
nStart = 0x2200;
nCount = 0x22FF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2A00;
nCount = 0x2AFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x27C0;
nCount = 0x27EF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2980;
nCount = 0x29FF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 07: sUCRName = "Miscellaneous Technical"; break; /* U+2300-U+23FF */
nStart = 0x2300;
nCount = 0x23FF - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 08: sUCRName = "Control Pictures"; break; /* U+2400-U+243F */
nStart = 0x2400;
nCount = 0x243F - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 09: sUCRName = "Optical Character Recognition"; break; /* U+2440-U+245F */
nStart = 0x2440;
nCount = 0x245F - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 10: sUCRName = "Enclosed Alphanumerics"; break; /* U+2460-U+24FF */
nStart = 0x2460;
nCount = 0x24FF - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 11: sUCRName = "Box Drawing"; break; /* U+2500-U+257F */
nStart = 0x2500;
nCount = 0x257F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 12: sUCRName = "Block Elements"; break; /* U+2580-U+259F */
nStart = 0x2580;
nCount = 0x259F - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 13: sUCRName = "Geometric Shapes"; break; /* U+25A0-U+25FF */
nStart = 0x25A0;
nCount = 0x25FF - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 14: sUCRName = "Miscellaneous Symbols"; break; /* U+2600-U+26FF */
nStart = 0x2600;
nCount = 0x26FF - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 15: sUCRName = "Dingbats"; break; /* U+2700-U+27BF */
nStart = 0x2700;
nCount = 0x27BF - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 16: sUCRName = "CJK Symbols and Punctuation"; break; /* U+3000-U+303F */
nStart = 0x3000;
nCount = 0x303F - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 17: sUCRName = "Hiragana"; break; /* U+3040-U+309F */
nStart = 0x3040;
nCount = 0x309F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 18: sUCRName = "Katakana"; break; /* U+30A0-U+30FF */ /* U+31F0-U+31FF */
nStart = 0x30A0;
nCount = 0x30FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x31F0;
nCount = 0x31FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 19: sUCRName = "Bopomofo"; break; /* U+3100-U+312F */ /* U+31A0-U+31BF */
nStart = 0x3100;
nCount = 0x312F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x31A0;
nCount = 0x31BF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 20: sUCRName = "Hangul Compatibility Jamo"; break; /* U+3130-U+318F */
nStart = 0x3130;
nCount = 0x318F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 21: sUCRName = "Phags-pa"; break; /* U+A840-U+A87F */
nStart = 0xA840;
nCount = 0xA87F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 22: sUCRName = "Enclosed CJK Letters and Months"; break; /* U+3200-U+32FF */
nStart = 0x3200;
nCount = 0x32FF - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 23: sUCRName = "CJK Compatibility"; break; /* U+3300-U+33FF */
nStart = 0x3300;
nCount = 0x33FF - nStart + 1;
memset(m_pRanges + nStart, 23, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 24: sUCRName = "Hangul Syllables"; break; /* U+AC00-U+D7AF */
nStart = 0xAC00;
nCount = 0xD7AF - nStart + 1;
memset(m_pRanges + nStart, 24, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 25: sUCRName = "Non-Plane 0"; break; /* U+D800-U+DB7F */ /* U+DB80-U+DBFF */ /* U+DC00-U+DFFF */ // Не юникодные символы
nStart = 0xD800;
nCount = 0xDB7F - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xDB80;
nCount = 0xDBFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xDC00;
nCount = 0xDFFF - nStart + 1;
memset(m_pRanges + nStart, 25, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 26: sUCRName = "Phoenician"; break; /*U+10900-U+1091F*/
//case 27: sUCRName = "CJK Unified Ideographs"; break; /* U+4E00-U+9FFF */ /* U+2E80-U+2EFF */ /* U+2F00-U+2FDF */ /* U+2FF0-U+2FFF */ /* U+3400-U+4DB5 */ /*U+20000-U+2A6D6*/ /* U+3190-U+319F */
nStart = 0x4E00;
nCount = 0x9FFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2E80;
nCount = 0x2EFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2F00;
nCount = 0x2FDF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x2FF0;
nCount = 0x2FFF - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x3400;
nCount = 0x4DB5 - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0x3190;
nCount = 0x319F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 28: sUCRName = "Private Use Area (plane 0)"; break; /* U+E000-U+F8FF */ // Не юникодные символы
nStart = 0xE000;
nCount = 0xF8FF - nStart + 1;
memset(m_pRanges + nStart, 28, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 29: sUCRName = "CJK Strokes"; break; /* U+31C0-U+31EF */ /* U+F900-U+FAFF */ /*U+2F800-U+2FA1F*/
nStart = 0x31C0;
nCount = 0x31EF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
nStart = 0xF900;
nCount = 0xFAFF - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 30: sUCRName = "Alphabetic Presentation Forms"; break; /* U+FB00-U+FB4F */
nStart = 0xFB00;
nCount = 0xFB4F - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
//case 31: sUCRName = "Arabic Presentation Forms-A"; break; /* U+FB50-U+FDFF */
nStart = 0xFB50;
nCount = 0xFDFF - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 1, nCount);
// rangeNum 2
//case 00: sUCRName = "Combining Half Marks"; break; /* U+FE20-U+FE2F */
nStart = 0xFE20;
nCount = 0xFE2F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 01: sUCRName = "Vertical forms"; break; /* U+FE10-U+FE1F */ /* U+FE30-U+FE4F */
nStart = 0xFE10;
nCount = 0xFE1F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0xFE30;
nCount = 0xFE4F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 02: sUCRName = "Small Form Variants"; break; /* U+FE50-U+FE6F */
nStart = 0xFE50;
nCount = 0xFE6F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 03: sUCRName = "Arabic Presentation Forms-B"; break; /* U+FE70-U+FEFE */
nStart = 0xFE70;
nCount = 0xFEFE - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 04: sUCRName = "Halfwidth and Fullwidth Forms"; break; /* U+FF00-U+FFEF */
nStart = 0xFF00;
nCount = 0xFFEF - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 05: sUCRName = "Specials"; break; /* U+FFF0-U+FFFF */
nStart = 0xFFF0;
nCount = 0xFFFF - nStart + 1;
memset(m_pRanges + nStart, 5, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 06: sUCRName = "Tibetan"; break; /* U+0F00-U+0FFF */
nStart = 0x0F00;
nCount = 0x0FFF - nStart + 1;
memset(m_pRanges + nStart, 6, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 07: sUCRName = "Syriac"; break; /* U+0700-U+074F */
nStart = 0x0700;
nCount = 0x074F - nStart + 1;
memset(m_pRanges + nStart, 7, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 08: sUCRName = "Thaana"; break; /* U+0780-U+07BF */
nStart = 0x0780;
nCount = 0x07BF - nStart + 1;
memset(m_pRanges + nStart, 8, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 09: sUCRName = "Sinhala"; break; /* U+0D80-U+0DFF */
nStart = 0x0D80;
nCount = 0x0DFF - nStart + 1;
memset(m_pRanges + nStart, 9, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 10: sUCRName = "Myanmar"; break; /* U+1000-U+109F */
nStart = 0x1000;
nCount = 0x109F - nStart + 1;
memset(m_pRanges + nStart, 10, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 11: sUCRName = "Ethiopic"; break; /* U+1200-U+137F */ /* U+1380-U+139F */ /* U+2D80-U+2DDF */
nStart = 0x1200;
nCount = 0x137F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1380;
nCount = 0x139F - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x2D80;
nCount = 0x2DDF - nStart + 1;
memset(m_pRanges + nStart, 11, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 12: sUCRName = "Cherokee"; break; /* U+13A0-U+13FF */
nStart = 0x13A0;
nCount = 0x13FF - nStart + 1;
memset(m_pRanges + nStart, 12, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 13: sUCRName = "Unified Canadian Aboriginal Syllabics"; break; /* U+1400-U+167F */
nStart = 0x1400;
nCount = 0x167F - nStart + 1;
memset(m_pRanges + nStart, 13, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 14: sUCRName = "Ogham"; break; /* U+1680-U+169F */
nStart = 0x1680;
nCount = 0x169F - nStart + 1;
memset(m_pRanges + nStart, 14, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 15: sUCRName = "Runic"; break; /* U+16A0-U+16FF */
nStart = 0x16A0;
nCount = 0x16FF - nStart + 1;
memset(m_pRanges + nStart, 15, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 16: sUCRName = "Khmer"; break; /* U+1780-U+17FF */ /* U+19E0-U+19FF */
nStart = 0x1780;
nCount = 0x17FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x19E0;
nCount = 0x19FF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 17: sUCRName = "Mongolian"; break; /* U+1800-U+18AF */
nStart = 0x1800;
nCount = 0x18AF - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 18: sUCRName = "Braille Patterns"; break; /* U+2800-U+28FF */
nStart = 0x2800;
nCount = 0x28FF - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 19: sUCRName = "Yi Syllables"; break; /* U+A000-U+A48F */ /* U+A490-U+A4CF */
nStart = 0xA000;
nCount = 0xA48F - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0xA490;
nCount = 0xA4CF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 20: sUCRName = "Tagalog"; break; /* U+1700-U+171F */ /* U+1720-U+173F */ /* U+1740-U+175F */ /* U+1760-U+177F */
nStart = 0x1700;
nCount = 0x171F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1720;
nCount = 0x173F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1740;
nCount = 0x175F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
nStart = 0x1760;
nCount = 0x177F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 21: sUCRName = "Old Italic"; break; /*U+10300-U+1032F*/
//case 22: sUCRName = "Gothic"; break; /*U+10330-U+1034F*/
//case 23: sUCRName = "Deseret"; break; /*U+10400-U+1044F*/
//case 24: sUCRName = "Byzantine Musical Symbols"; break; /*U+1D000-U+1D0FF*/ /*U+1D100-U+1D1FF*/ /*U+1D200-U+1D24F*/
//case 25: sUCRName = "Mathematical Alphanumeric Symbols"; break; /*U+1D400-U+1D7FF*/
//case 26: sUCRName = "Private Use (plane 15)"; break; /*U+F0000-U+FFFFD*/ /*U+100000-U+10FFFD*/ // Не юникодные символы
//case 27: sUCRName = "Variation Selectors"; break; /* U+FE00-U+FE0F */ /*U+E0100-U+E01EF*/
nStart = 0xFE00;
nCount = 0xFE0F - nStart + 1;
memset(m_pRanges + nStart, 27, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 28: sUCRName = "Tags"; break; /*U+E0000-U+E007F*/
//case 29: sUCRName = "Limbu"; break; /* U+1900-U+194F */
nStart = 0x1900;
nCount = 0x194F - nStart + 1;
memset(m_pRanges + nStart, 29, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 30: sUCRName = "Tai Le"; break; /* U+1950-U+197F */
nStart = 0x1950;
nCount = 0x197F - nStart + 1;
memset(m_pRanges + nStart, 30, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
//case 31: sUCRName = "New Tai Lue"; break; /* U+1980-U+19DF */
nStart = 0x1980;
nCount = 0x19DF - nStart + 1;
memset(m_pRanges + nStart, 31, nCount);
memset(m_pRangesNums + nStart, 2, nCount);
// rangeNum 3
//case 00: sUCRName = "Buginese"; break; /* U+1A00-U+1A1F */
nStart = 0x1A00;
nCount = 0x1A1F - nStart + 1;
memset(m_pRanges + nStart, 0, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 01: sUCRName = "Glagolitic"; break; /* U+2C00-U+2C5F */
nStart = 0x2C00;
nCount = 0x2C5F - nStart + 1;
memset(m_pRanges + nStart, 1, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 02: sUCRName = "Tifinagh"; break; /* U+2D30-U+2D7F */
nStart = 0x2D30;
nCount = 0x2D7F - nStart + 1;
memset(m_pRanges + nStart, 2, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 03: sUCRName = "Yijing Hexagram Symbols"; break; /* U+4DC0-U+4DFF */
nStart = 0x4DC0;
nCount = 0x4DFF - nStart + 1;
memset(m_pRanges + nStart, 3, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 04: sUCRName = "Syloti Nagri"; break; /* U+A800-U+A82F */
nStart = 0xA800;
nCount = 0xA82F - nStart + 1;
memset(m_pRanges + nStart, 4, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 05: sUCRName = "Linear B Syllabary"; break; /*U+10000-U+1007F*/ /*U+10080-U+100FF*/ /*U+10100-U+1013F*/
//case 06: sUCRName = "Ancient Greek Numbers"; break; /*U+10140-U+1018F*/
//case 07: sUCRName = "Ugaritic"; break; /*U+10380-U+1039F*/
//case 08: sUCRName = "Old Persian"; break; /*U+103A0-U+103DF*/
//case 09: sUCRName = "Shavian"; break; /*U+10450-U+1047F*/
//case 10: sUCRName = "Osmanya"; break; /*U+10480-U+104AF*/
//case 11: sUCRName = "Cypriot Syllabary"; break; /*U+10800-U+1083F*/
//case 12: sUCRName = "Kharoshthi"; break; /*U+10A00-U+10A5F*/
//case 13: sUCRName = "Tai Xuan Jing Symbols"; break; /*U+1D300-U+1D35F*/
//case 14: sUCRName = "Cuneiform"; break; /*U+12000-U+123FF*/ /*U+12400-U+1247F*/
//case 15: sUCRName = "Counting Rod Numerals"; break; /*U+1D360-U+1D37F*/
//case 16: sUCRName = "Sundanese"; break; /* U+1B80-U+1BBF */
nStart = 0x1B80;
nCount = 0x1BBF - nStart + 1;
memset(m_pRanges + nStart, 16, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 17: sUCRName = "Lepcha"; break; /* U+1C00-U+1C4F */
nStart = 0x1C00;
nCount = 0x1C4F - nStart + 1;
memset(m_pRanges + nStart, 17, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 18: sUCRName = "Ol Chiki"; break; /* U+1C50-U+1C7F */
nStart = 0x1C50;
nCount = 0x1C7F - nStart + 1;
memset(m_pRanges + nStart, 18, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 19: sUCRName = "Saurashtra"; break; /* U+A880-U+A8DF */
nStart = 0xA880;
nCount = 0xA8DF - nStart + 1;
memset(m_pRanges + nStart, 19, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 20: sUCRName = "Kayah Li"; break; /* U+A900-U+A92F */
nStart = 0xA900;
nCount = 0xA92F - nStart + 1;
memset(m_pRanges + nStart, 20, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 21: sUCRName = "Rejang"; break; /* U+A930-U+A95F */
nStart = 0xA930;
nCount = 0xA95F - nStart + 1;
memset(m_pRanges + nStart, 21, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 22: sUCRName = "Cham"; break; /* U+AA00-U+AA5F */
nStart = 0xAA00;
nCount = 0xAA5F - nStart + 1;
memset(m_pRanges + nStart, 22, nCount);
memset(m_pRangesNums + nStart, 3, nCount);
//case 23: sUCRName = "Ancient Symbols"; break; /*U+10190-U+101CF*/
//case 24: sUCRName = "Phaistos Disc"; break; /*U+101D0-U+101FF*/
//case 25: sUCRName = "Carian"; break; /*U+102A0-U+102DF*/ /*U+10280-U+1029F*/ /*U+10920-U+1093F*/
//case 26: sUCRName = "Domino Tiles"; break; /*U+1F030-U+1F09F*/ /*U+1F000-U+1F02F*/
//case 27: sUCRName = "Reserved for process-internal usage"; break;
//case 28: sUCRName = "Reserved for process-internal usage"; break;
//case 29: sUCRName = "Reserved for process-internal usage"; break;
//case 30: sUCRName = "Reserved for process-internal usage"; break;
//case 31: sUCRName = "Reserved for process-internal usage"; break;
}
inline void InitializeUnicodeMap()
{
memset(m_mapUnicode, 0, 0xFFFF);
m_mapUnicode[0x0009] = 1;
m_mapUnicode[0x000A] = 1;
m_mapUnicode[0x000D] = 1;
memset(m_mapUnicode + 0x0020, 1, 0xD7FF - 0x0020 + 1);
memset(m_mapUnicode + 0xE000, 1, 0xFFFD - 0xE000 + 1);
}
inline bool GetRange(const WCHAR& symbol, BYTE& lRangeNum, BYTE& lRange)
{
lRangeNum = m_pRangesNums[symbol];
lRange = m_pRanges[symbol];
return (0xFF != lRangeNum);
}
inline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, const std::wstring& strText)
{
int lCount = strText.length();
const WCHAR* pData = strText.c_str();
BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF;
for (int i = 0; i < lCount; ++i, ++pData)
{
if (GetRange(*pData, lRangeNum, lRange))
{
if (0 == lRangeNum)
lRange1 |= 1 << lRange;
else if (1 == lRangeNum)
lRange2 |= 1 << lRange;
else if (2 == lRangeNum)
lRange3 |= 1 << lRange;
else
lRange4 |= 1 << lRange;
}
}
}
inline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, BYTE& lRangeNum, BYTE& lRange)
{
if (0 == lRangeNum)
lRange1 |= 1 << lRange;
else if (1 == lRangeNum)
lRange2 |= 1 << lRange;
else if (2 == lRangeNum)
lRange3 |= 1 << lRange;
else
lRange4 |= 1 << lRange;
}
public:
inline static bool IsEqual3(NSStructures::CFont* f1, NSStructures::CFont* f2)
{
return ((f1->Path == f2->Path) && (f1->Bold == f2->Bold) && (f1->Italic == f2->Italic));
}
inline static bool IsEqual2(NSStructures::CFont* f1, NSStructures::CFont* f2, double dScalingSrcSize = 1)
{
if (!f1->Path.empty() && !f2->Path.empty())
return ((f1->Path == f2->Path) &&
(f1->StringGID == f2->StringGID) &&
(fabs(f1->Size - (f2->Size * dScalingSrcSize)) < 0.0001) &&
(f1->Bold == f2->Bold) &&
(f1->Italic == f2->Italic));
return ((f1->Name == f2->Name) &&
(f1->Path == f2->Path) &&
(f1->StringGID == f2->StringGID) &&
(f1->Size == (f2->Size * dScalingSrcSize)) &&
(f1->Bold == f2->Bold) &&
(f1->Italic == f2->Italic));
}
public:
inline bool GenerateFontName(NSStringUtils::CStringBuilder& oTextItem, bool bIsFontChanged)
{
if (m_oFont.m_oFont.Path.empty())
return false;
BYTE lRangeNum = 0xFF;
BYTE lRange = 0xFF;
GetRange(oTextItem.GetBuffer()[0], lRangeNum, lRange);
if (!bIsFontChanged && (0 != m_arListPicUps.size()))
{
CFontPickUp& oPick = *m_arListPicUps.begin();
if ((lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange))
{
// по идее не надо приравнивать, они должны были быть выставлены ещ раньше
//m_strCurrentPickFont = oPick.m_strPickFont;
//m_lCurrentPictFontStyle = oPick.m_lPickStyle;
return false;
}
}
std::list<CFontPickUp>::iterator pos = m_arListPicUps.begin();
while (pos != m_arListPicUps.end())
{
CFontPickUp& oPick = *pos;
pos++;
if ((IsEqual3(&m_oFont.m_oFont, &oPick.m_oFont.m_oFont)) && (lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange))
{
// нашли! ничего подбирать не нужно
// нужно просто выкинуть этот шрифт наверх
if (pos != m_arListPicUps.begin())
{
m_arListPicUps.splice(m_arListPicUps.begin(), m_arListPicUps, pos, std::next(pos));
}
m_strCurrentPickFont = oPick.m_strPickFont;
m_lCurrentPictFontStyle = oPick.m_lPickStyle;
return false;
}
}
// не нашли...
CFontPickUp oPick;
oPick.m_lRangeNum = lRangeNum;
oPick.m_lRange = lRange;
oPick.m_oFont = m_oFont;
oPick.m_strPickFont = m_oFont.m_oProperties.m_strFamilyName;
oPick.m_lPickStyle = m_oFont.m_oProperties.m_lStyle;
LONG lCountSigs = (LONG)m_oFont.m_oProperties.m_arSignature.size();
DWORD dwR1 = 0;
if (0 < lCountSigs)
dwR1 = m_oFont.m_oProperties.m_arSignature[0];
DWORD dwR2 = 0;
if (1 < lCountSigs)
dwR2 = m_oFont.m_oProperties.m_arSignature[1];
DWORD dwR3 = 0;
if (2 < lCountSigs)
dwR3 = m_oFont.m_oProperties.m_arSignature[2];
DWORD dwR4 = 0;
if (3 < lCountSigs)
dwR4 = m_oFont.m_oProperties.m_arSignature[3];
DWORD dwCodePage1 = 0;
DWORD dwCodePage2 = 0;
if ((lRangeNum == 1) && (lRange == 28))
{
dwCodePage1 = 0x80000000;
//strText = (WCHAR)(strText[0] - 0xF000);
}
else if (((lRangeNum == 2) && (lRange == 3)) || ((lRangeNum == 1) && (lRange == 31)) || ((lRangeNum == 0) && (lRange == 13)))
{
// ебаный арабский язык!!!
dwR1 = 1 << 13;
dwR2 = 1 << 31;
dwR3 = 1 << 3;
}
else
{
CheckRanges(dwR1, dwR2, dwR3, dwR4, lRangeNum, lRange);
}
CFontSelectFormat oFormat;
oFormat.wsName = new std::wstring(m_oFont.m_oProperties.m_strFamilyName);
oFormat.pPanose = new BYTE[10];
memcpy(oFormat.pPanose, m_oFont.m_oProperties.m_strPANOSE, 10);
oFormat.bBold = new INT(m_oFont.m_oFont.Bold);
oFormat.bItalic = new INT(m_oFont.m_oFont.Italic);
oFormat.bFixedWidth = new INT(m_oFont.m_oProperties.m_bIsFixedWidth ? 1 : 0);
if (0 != dwR1)
oFormat.ulRange1 = new ULONG(dwR1);
if (0 != dwR2)
oFormat.ulRange2 = new ULONG(dwR2);
if (0 != dwR3)
oFormat.ulRange3 = new ULONG(dwR3);
if (0 != dwR4)
oFormat.ulRange4 = new ULONG(dwR4);
if (0 != dwCodePage1)
oFormat.ulCodeRange1 = new ULONG(dwCodePage1);
if (0 != dwCodePage2)
oFormat.ulCodeRange2 = new ULONG(dwCodePage2);
CFontInfo* pInfo = m_pManager->GetFontInfoByParams(oFormat);
oPick.m_strPickFont = pInfo->m_wsFontName;
oPick.m_lPickStyle = m_oFont.m_oFont.GetStyle();
m_strCurrentPickFont = oPick.m_strPickFont;
m_lCurrentPictFontStyle = oPick.m_lPickStyle;
m_arListPicUps.push_front(oPick);
return true;
}
inline void SetStringGid(const LONG& lGid)
{
m_pManager->SetStringGID(lGid);
}
inline LONG GetStringGid()
{
return m_pManager->m_bStringGID;
}
inline wchar_t* GetUnicodeString(wchar_t* bsText)
{
wchar_t* start = (wchar_t*)bsText;
wchar_t* s = start;
for (; *s != 0; ++s);
LONG lLen = (LONG)(s - start);
wchar_t* pData = new wchar_t[lLen + 1];
for (LONG i = 0; i < lLen; ++i, ++start)
{
if (m_mapUnicode[*start])
pData[i] = *start;
else
pData[i] = (wchar_t)(' ');
}
return pData;
}
std::wstring GetFontPath(NSStructures::CFont* pFont)
{
CFontSelectFormat oFormat;
oFormat.bBold = new INT(pFont->Bold);
oFormat.bItalic = new INT(pFont->Italic);
oFormat.wsName = new std::wstring(pFont->Name);
CFontInfo* pInfo = m_pManager->GetFontInfoByParams(oFormat);
return pInfo->m_wsFontPath;
}
};
}
}
#endif // _ASC_HTMLRENDERER_FMBASE_H_
#include "../include/HTMLRenderer3.h"
#include "./Common.h"
#include "./Document.h"
#include "./Writer.h"
namespace NSHtmlRenderer
{
class CASCHTMLRenderer3_Private : public NSHtmlRenderer::IBaseMatrixUpdater
{
public:
NSHtmlRenderer::CDocument m_oDocument; // вся информация о документе (только страницы и их размеры)
NSHtmlRenderer::CWriter m_oWriter; // сам вьюер. основной класс
NSHtmlRenderer::CGraphicsDumper m_oDumper;
bool m_bIsGraphicsDumperMode;
std::wstring m_strDstFile;
int m_lLastSavedPage;
Aggplus::CGraphicsPathSimpleConverter m_oSimpleGraphicsConverter; // конвертер сложных гафических путей в простые
CApplicationFonts m_oApplicationFonts;
::CFontManager* m_pFontManager; // менеджер шрифтов
Aggplus::CMatrix m_oTransform; // текущая матрица преобразований рендерера
double m_dTransformAngle;
int m_lCurrentCommandType; // текущая команда
int m_lCurrentPage; // текущая страница
bool m_bIsMetafileDrawing;
bool m_bIsTextGraphicType;
int m_lClipMode;
NSStructures::CPen m_oPen; // настройки всей графики (скопирован ашник из AVSGraphics)
NSStructures::CBrush m_oBrush;
NSStructures::CFont m_oFont;
NSStructures::CFont m_oInstalledFont;
bool m_bPageClosed;
bool m_bPageOpened;
bool m_bIsChangedFontParamBetweenDrawText;
public:
int* m_pTempUnicodes;
int m_nTempUnicodesAlloc;
int m_nTempUnicodesLen;
public:
CASCHTMLRenderer3_Private()
{
m_oApplicationFonts.Initialize();
m_lLastSavedPage = 0;
m_oDocument.SetUpdater(this);
m_oWriter.m_pPen = &m_oPen;
m_oWriter.m_pBrush = &m_oBrush;
m_oWriter.m_pFont = &m_oFont;
m_bPageClosed = true;
m_dTransformAngle = 0.0;
m_pFontManager = NULL;
m_oWriter.SetSimpleConverter(&m_oSimpleGraphicsConverter, &m_oTransform);
m_oWriter.SetApplicationFonts(&m_oApplicationFonts);
m_bIsMetafileDrawing = false;
m_bIsTextGraphicType = false;
m_bIsChangedFontParamBetweenDrawText = true;
m_bIsGraphicsDumperMode = false;
m_nTempUnicodesAlloc = 100;
m_pTempUnicodes = new int[m_nTempUnicodesAlloc];
m_nTempUnicodesLen = 0;
}
~CASCHTMLRenderer3_Private()
{
RELEASEARRAYOBJECTS(m_pTempUnicodes);
}
public:
void GetUnicodes(const std::wstring& sText)
{
int nLen = (int)sText.length();
if (nLen > m_nTempUnicodesAlloc)
{
RELEASEARRAYOBJECTS(m_pTempUnicodes);
m_nTempUnicodesAlloc = nLen;
m_pTempUnicodes = new int[m_nTempUnicodesAlloc];
}
m_nTempUnicodesLen = 0;
const wchar_t* pWchars = sText.c_str();
if (sizeof(wchar_t) == 2)
{
for (int nIndex = 0, nGlyphIndex = 0; nIndex < nLen; ++nIndex, ++nGlyphIndex)
{
int code = (int)pWchars[nIndex];
if (code >= 0xD800 && code <= 0xDFFF && (nIndex + 1) < nLen)
{
++nIndex;
code = 0x10000 + (((code & 0x3FF) << 10) | (0x03FF & pWchars[nIndex]));
}
m_pTempUnicodes[m_nTempUnicodesLen++] = code;
}
}
else
{
for ( int nIndex = 0; nIndex < nLen; ++nIndex )
{
m_pTempUnicodes[m_nTempUnicodesLen++] = (int)pWchars[nIndex];
}
}
}
public:
virtual void OnBaseMatrixUpdate(const double& dWidth, const double& dHeight)
{
if (m_bPageClosed)
{
// значит размеры пришли не в первый раз для текущей страницы
return;
}
m_bPageClosed = true;
StartPage(dWidth, dHeight);
}
void CalculateFullTransform()
{
m_dTransformAngle = m_oTransform.z_Rotation();
}
inline void MoveTo(const double& dX, const double& dY)
{
m_oWriter.WritePathMoveTo(dX, dY);
}
inline void LineTo(const double& dX, const double& dY)
{
m_oWriter.WritePathLineTo(dX, dY);
}
inline void CurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{
m_oWriter.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
}
void Start()
{
m_oWriter.WriteBeginPath();
}
void End()
{
m_oWriter.WriteEndPath();
}
void Close()
{
m_oWriter.WritePathClose();
}
void StartPage(const double& dWidth, const double& dHeight)
{
++m_lCurrentPage;
m_oWriter.NewPage(dWidth, dHeight);
}
void EndPage()
{
m_oWriter.EndPage();
m_bPageOpened = FALSE;
}
void _SetFont()
{
if (NULL == m_pFontManager)
{
m_pFontManager = m_oApplicationFonts.GenerateFontManager();
}
double dPix = m_oFont.CharSpace * 96 / 25.4;
if (m_oInstalledFont.IsEqual(&m_oFont))
{
if (1 < m_oWriter.m_dWidth)
{
m_pFontManager->SetCharSpacing(dPix);
}
return;
}
m_pFontManager->SetStringGID(m_oFont.StringGID);
if (1 < m_oWriter.m_dWidth)
{
m_pFontManager->SetCharSpacing(dPix);
}
if (m_oFont.Path.empty())
{
m_pFontManager->LoadFontByName(m_oFont.Name, m_oFont.Size, m_oFont.GetStyle(), 96, 96);
}
else
{
m_pFontManager->LoadFontFromFile(m_oFont.Path, m_oFont.FaceIndex, m_oFont.Size, 96, 96);
}
m_oInstalledFont = m_oFont;
}
};
CASCHTMLRenderer3::CASCHTMLRenderer3()
{
m_pInternal = new CASCHTMLRenderer3_Private();
}
CASCHTMLRenderer3::~CASCHTMLRenderer3()
{
RELEASEOBJECT(m_pInternal);
}
HRESULT CASCHTMLRenderer3::get_Type(LONG* lType)
{
*lType = c_nHtmlRendrerer2;
return S_OK;
}
//-------- Функции для работы со страницей --------------------------------------------------
HRESULT CASCHTMLRenderer3::NewPage()
{
if (m_pInternal->m_bPageOpened)
{
m_pInternal->EndPage();
}
m_pInternal->m_oPen.SetDefaultParams();
m_pInternal->m_oBrush.SetDefaultParams();
m_pInternal->m_oFont.SetDefaultParams();
m_pInternal->m_oDocument.NewPage();
m_pInternal->m_bPageClosed = false;
m_pInternal->m_bPageOpened = true;
m_pInternal->m_bIsMetafileDrawing = false;
m_pInternal->m_bIsTextGraphicType = false;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_Height(double* dHeight)
{
size_t nCount = m_pInternal->m_oDocument.m_arrPages.size();
if ((nCount > 0) && (NULL != dHeight))
*dHeight = m_pInternal->m_oDocument.m_arrPages[nCount - 1].GetHeight();
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_Height(const double& dHeight)
{
size_t nCount = m_pInternal->m_oDocument.m_arrPages.size();
if (nCount > 0)
m_pInternal->m_oDocument.m_arrPages[nCount - 1].SetHeight(dHeight);
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_Width(double* dWidth)
{
size_t nCount = m_pInternal->m_oDocument.m_arrPages.size();
if ((nCount > 0) && (NULL != dWidth))
*dWidth = m_pInternal->m_oDocument.m_arrPages[nCount - 1].GetWidth();
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_Width(const double& dWidth)
{
size_t nCount = m_pInternal->m_oDocument.m_arrPages.size();
if (nCount > 0)
m_pInternal->m_oDocument.m_arrPages[nCount - 1].SetWidth(dWidth);
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_DpiX(double* dDpiX)
{
*dDpiX = 96;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_DpiY(double* dDpiY)
{
*dDpiY = 96;
return S_OK;
}
// pen --------------------------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::get_PenColor(LONG* lColor)
{
*lColor = m_pInternal->m_oPen.Color;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenColor(const LONG& lColor)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenColor(lColor);
m_pInternal->m_oPen.Color = lColor;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenAlpha(LONG* lAlpha)
{
*lAlpha = m_pInternal->m_oPen.Alpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenAlpha(const LONG& lAlpha)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenAlpha(lAlpha);
m_pInternal->m_oPen.Alpha = lAlpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenSize(double* dSize)
{
*dSize = m_pInternal->m_oPen.Size;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenSize(const double& dSize)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenSize(dSize);
m_pInternal->m_oPen.Size = dSize;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenDashStyle(BYTE* val)
{
*val = m_pInternal->m_oPen.DashStyle;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenDashStyle(const BYTE& val)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenDashStyle(val);
m_pInternal->m_oPen.DashStyle = val;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenLineStartCap(BYTE* val)
{
*val = m_pInternal->m_oPen.LineStartCap;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenLineStartCap(const BYTE& val)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenLineStartCap(val);
m_pInternal->m_oPen.LineStartCap = val;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenLineEndCap(BYTE* val)
{
*val = m_pInternal->m_oPen.LineEndCap;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenLineEndCap(const BYTE& val)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenLineEndCap(val);
m_pInternal->m_oPen.LineEndCap = val;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenLineJoin(BYTE* val)
{
*val = m_pInternal->m_oPen.LineJoin;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenLineJoin(const BYTE& val)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenLineJoin(val);
m_pInternal->m_oPen.LineJoin = val;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenDashOffset(double* dOffset)
{
*dOffset = m_pInternal->m_oPen.DashOffset;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenDashOffset(const double& dOffset)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenDashOffset(dOffset);
m_pInternal->m_oPen.DashOffset = dOffset;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenAlign(LONG* lAlign)
{
*lAlign = m_pInternal->m_oPen.Align;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenAlign(const LONG& lAlign)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenAlign(lAlign);
m_pInternal->m_oPen.Align = lAlign;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_PenMiterLimit(double* dOffset)
{
*dOffset = m_pInternal->m_oPen.MiterLimit;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_PenMiterLimit(const double& dOffset)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_PenMiterLimit(dOffset);
m_pInternal->m_oPen.MiterLimit = dOffset;
return S_OK;
}
HRESULT CASCHTMLRenderer3::PenDashPattern(double* pPattern, LONG lCount)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PenDashPattern(pPattern, lCount);
m_pInternal->m_oPen.SetDashPattern(pPattern, lCount);
return S_OK;
}
// brush ------------------------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::get_BrushType(LONG* lType)
{
*lType = m_pInternal->m_oBrush.Type;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushType(const LONG& lType)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushType(lType);
m_pInternal->m_oBrush.Type = lType;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushColor1(LONG* lColor)
{
*lColor = m_pInternal->m_oBrush.Color1;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushColor1(const LONG& lColor)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushColor1(lColor);
m_pInternal->m_oBrush.Color1 = lColor;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushAlpha1(LONG* lAlpha)
{
*lAlpha = m_pInternal->m_oBrush.Alpha1;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushAlpha1(const LONG& lAlpha)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushAlpha1(lAlpha);
m_pInternal->m_oBrush.Alpha1 = lAlpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushColor2(LONG* lColor)
{
*lColor = m_pInternal->m_oBrush.Color2;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushColor2(const LONG& lColor)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushColor2(lColor);
m_pInternal->m_oBrush.Color2 = lColor;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushAlpha2(LONG* lAlpha)
{
*lAlpha = m_pInternal->m_oBrush.Alpha2;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushAlpha2(const LONG& lAlpha)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushAlpha2(lAlpha);
m_pInternal->m_oBrush.Alpha2 = lAlpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushTexturePath(std::wstring* bsPath)
{
*bsPath = m_pInternal->m_oBrush.TexturePath;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushTexturePath(const std::wstring& bsPath)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushTexturePath(bsPath);
m_pInternal->m_oBrush.TexturePath = bsPath;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushTextureMode(LONG* lMode)
{
*lMode = m_pInternal->m_oBrush.TextureMode;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushTextureMode(const LONG& lMode)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushTextureMode(lMode);
m_pInternal->m_oBrush.TextureMode = lMode;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushTextureAlpha(LONG* lTxAlpha)
{
*lTxAlpha = m_pInternal->m_oBrush.TextureAlpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushTextureAlpha(const LONG& lTxAlpha)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushTextureAlpha(lTxAlpha);
m_pInternal->m_oBrush.TextureAlpha = lTxAlpha;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_BrushLinearAngle(double* dAngle)
{
*dAngle = m_pInternal->m_oBrush.LinearAngle;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushLinearAngle(const double& dAngle)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushLinearAngle(dAngle);
m_pInternal->m_oBrush.LinearAngle = dAngle;
return S_OK;
}
HRESULT CASCHTMLRenderer3::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.BrushRect(val, left, top, width, height);
m_pInternal->m_oBrush.Rectable = val;
m_pInternal->m_oBrush.Rect.X = (float)left;
m_pInternal->m_oBrush.Rect.Y = (float)top;
m_pInternal->m_oBrush.Rect.Width = (float)width;
m_pInternal->m_oBrush.Rect.Height = (float)height;
return S_OK;
}
HRESULT CASCHTMLRenderer3::BrushBounds(const double& left, const double& top, const double& width, const double& height)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.BrushBounds(left, top, width, height);
m_pInternal->m_oBrush.Bounds.left = left;
m_pInternal->m_oBrush.Bounds.top = top;
m_pInternal->m_oBrush.Bounds.right = left + width;
m_pInternal->m_oBrush.Bounds.bottom = top + height;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_BrushGradientColors(lColors, pPositions, nCount);
m_pInternal->m_oBrush.m_arrSubColors.RemoveAll();
for (LONG i = 0; i < nCount; ++i)
{
NSStructures::CBrush::TSubColor color;
color.color = lColors[i];
color.position = (long)(pPositions[i] * 65536);
m_pInternal->m_oBrush.m_arrSubColors.Add(color);
}
return S_OK;
}
// font -------------------------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::get_FontName(std::wstring* bsName)
{
*bsName = m_pInternal->m_oFont.Name;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontName(const std::wstring& bsName)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontName(bsName);
m_pInternal->m_oFont.Name = bsName;
m_pInternal->m_bIsChangedFontParamBetweenDrawText = true;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontPath(std::wstring* bsName)
{
*bsName = m_pInternal->m_oFont.Path;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontPath(const std::wstring& bsName)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontPath(bsName);
m_pInternal->m_oFont.Path = bsName;
m_pInternal->m_bIsChangedFontParamBetweenDrawText = true;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontSize(double* dSize)
{
*dSize = m_pInternal->m_oFont.Size;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontSize(const double& dSize)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontSize(dSize);
if (m_pInternal->m_oFont.Size != dSize)
{
m_pInternal->m_oFont.Size = dSize;
m_pInternal->m_bIsChangedFontParamBetweenDrawText = true;
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontStyle(LONG* lStyle)
{
*lStyle = m_pInternal->m_oFont.GetStyle();
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontStyle(const LONG& lStyle)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontStyle(lStyle);
LONG lOld = m_pInternal->m_oFont.GetStyle();
if (lOld != lStyle)
{
m_pInternal->m_oFont.SetStyle(lStyle);
m_pInternal->m_bIsChangedFontParamBetweenDrawText = true;
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontStringGID(INT* bGID)
{
*bGID = m_pInternal->m_oFont.StringGID;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontStringGID(const INT& bGID)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontStringGID(bGID);
m_pInternal->m_oFont.StringGID = bGID;
m_pInternal->m_pFontManager->SetStringGID(bGID);
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontCharSpace(double* dSpace)
{
*dSpace = m_pInternal->m_oFont.CharSpace;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontCharSpace(const double& dSpace)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontCharSpace(dSpace);
m_pInternal->m_oFont.CharSpace = dSpace;
return S_OK;
}
HRESULT CASCHTMLRenderer3::get_FontFaceIndex(int* lFaceIndex)
{
*lFaceIndex = m_pInternal->m_oFont.FaceIndex;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_FontFaceIndex(const int& lFaceIndex)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_FontFaceIndex(lFaceIndex);
m_pInternal->m_oFont.FaceIndex = lFaceIndex;
return S_OK;
}
//-------- Функции для вывода текста --------------------------------------------------------
HRESULT CASCHTMLRenderer3::CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.CommandDrawTextCHAR(c, x, y, w, h);
if (c_nHyperlinkType == m_pInternal->m_lCurrentCommandType)
return S_OK;
int _c = (int)c;
m_pInternal->m_oWriter.WriteText(&_c, NULL, 1, x, y, w, h, m_pInternal->m_bIsChangedFontParamBetweenDrawText);
m_pInternal->m_bIsChangedFontParamBetweenDrawText = false;
return S_OK;
}
HRESULT CASCHTMLRenderer3::CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.CommandDrawText(bsText, x, y, w, h);
if (c_nHyperlinkType == m_pInternal->m_lCurrentCommandType)
return S_OK;
m_pInternal->GetUnicodes(bsText);
m_pInternal->m_oWriter.WriteText(m_pInternal->m_pTempUnicodes, NULL, m_pInternal->m_nTempUnicodesLen,
x, y, w, h, m_pInternal->m_bIsChangedFontParamBetweenDrawText);
m_pInternal->m_bIsChangedFontParamBetweenDrawText = false;
return S_OK;
}
HRESULT CASCHTMLRenderer3::CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.CommandDrawTextExCHAR(c, gid, x, y, w, h);
if (c_nHyperlinkType == m_pInternal->m_lCurrentCommandType)
return S_OK;
int _c = (int)c;
int _g = (int)gid;
m_pInternal->m_oWriter.WriteText(&_c, &_g, 1,
x, y, w, h, m_pInternal->m_bIsChangedFontParamBetweenDrawText);
m_pInternal->m_bIsChangedFontParamBetweenDrawText = false;
return S_OK;
}
HRESULT CASCHTMLRenderer3::CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.CommandDrawText(bsUnicodeText, x, y, w, h);
if (c_nHyperlinkType == m_pInternal->m_lCurrentCommandType)
return S_OK;
m_pInternal->GetUnicodes(bsUnicodeText);
m_pInternal->m_oWriter.WriteText(m_pInternal->m_pTempUnicodes, (const int*)pGids, m_pInternal->m_nTempUnicodesLen,
x, y, w, h, m_pInternal->m_bIsChangedFontParamBetweenDrawText);
m_pInternal->m_bIsChangedFontParamBetweenDrawText = false;
return S_OK;
}
//-------- Маркеры для команд ---------------------------------------------------------------
HRESULT CASCHTMLRenderer3::BeginCommand(const DWORD& lType)
{
if (m_pInternal->m_bIsGraphicsDumperMode && lType != c_nPDFTilingFill)
return m_pInternal->m_oDumper.BeginCommand(lType);
if (c_nClipType == lType)
{
m_pInternal->m_oWriter.WritePathClip();
}
else if (c_nPathType == lType)
{
m_pInternal->m_oWriter.WriteBeginPath();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandEnd();
}
else if (c_nImageType == lType)
{
m_pInternal->m_bIsMetafileDrawing = true;
}
else if (c_nTextGraphicType == lType)
{
m_pInternal->m_bIsTextGraphicType = true;
}
else if (c_nPDFTilingFill == lType)
{
m_pInternal->m_oWriter.m_lTilingCounter++;
}
m_pInternal->m_lCurrentCommandType = lType;
return S_OK;
}
HRESULT CASCHTMLRenderer3::EndCommand(const DWORD& lType)
{
if (m_pInternal->m_bIsGraphicsDumperMode && lType != c_nPDFTilingFill)
return m_pInternal->m_oDumper.EndCommand(lType);
if (c_nPageType == lType)
{
m_pInternal->EndPage();
}
else if (c_nClipType == lType)
{
m_pInternal->m_oWriter.WritePathClipEnd();
}
else if (c_nResetClipType == lType)
{
m_pInternal->m_oWriter.WritePathResetClip();
}
//else if (c_nPathType == lType)
//{
// PathCommandEnd();
//}
else if (c_nImageType == lType)
{
m_pInternal->m_bIsMetafileDrawing = false;
}
else if (c_nTextGraphicType == lType)
{
m_pInternal->m_bIsTextGraphicType = false;
}
else if (c_nPDFTilingFill == lType)
{
m_pInternal->m_oWriter.m_lTilingCounter--;
if (0 == m_pInternal->m_oWriter.m_lTilingCounter)
{
m_pInternal->m_bIsGraphicsDumperMode = false;
// dump Graphics
CBgraFrame* pFrame = m_pInternal->m_oDumper.ConvertVectorGraphics();
m_pInternal->m_oWriter.WritePattern(pFrame, m_pInternal->m_oDumper.m_oTile);
RELEASEOBJECT(pFrame);
}
}
//else if (c_nParagraphType == lType)
//{
// m_oWriter.m_oPage.m_oText.EndParagraph();
//}
m_pInternal->m_lCurrentCommandType = -1;
return S_OK;
}
//-------- Функции для работы с Graphics Path -----------------------------------------------
HRESULT CASCHTMLRenderer3::PathCommandMoveTo(const double& x, const double& y)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandMoveTo(x, y);
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->MoveTo(x, y);
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandMoveTo(x, y);
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandLineTo(const double& x, const double& y)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandLineTo(x, y);
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->LineTo(x, y);
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandLineTo(x, y);
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandLinesTo(double* points, const int& count)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandLinesTo(points, count);
m_pInternal->m_oSimpleGraphicsConverter.PathCommandLinesTo(points, count);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->CurveTo(x1, y1, x2, y2, x3, y3);
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandCurvesTo(double* points, const int& count)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandCurvesTo(points, count);
m_pInternal->m_oSimpleGraphicsConverter.PathCommandCurvesTo(points, count);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandArcTo(x, y, w, h, startAngle, sweepAngle);
m_pInternal->m_oSimpleGraphicsConverter.PathCommandArcTo(x, y, w, h, startAngle, sweepAngle);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandClose()
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandClose();
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->Close();
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandClose();
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandEnd()
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandEnd();
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->End();
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandEnd();
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::DrawPath(const LONG& nType)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.DrawPath(nType);
m_pInternal->m_oWriter.WriteDrawPath(nType);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandStart()
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandStart();
if (c_nSimpleGraphicType == m_pInternal->m_lCurrentCommandType)
{
m_pInternal->Start();
}
else
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandEnd();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandStart();
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandGetCurrentPoint(double* x, double* y)
{
m_pInternal->m_oSimpleGraphicsConverter.PathCommandGetCurrentPoint(x, y);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandTextCHAR(c, x, y, w, h);
int _c = (int)c;
m_pInternal->_SetFont();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandText2(&_c, NULL, 1, m_pInternal->m_pFontManager, x, y, w, h);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandText(bsText, x, y, w, h);
m_pInternal->GetUnicodes(bsText);
m_pInternal->_SetFont();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandText2(m_pInternal->m_pTempUnicodes, NULL, m_pInternal->m_nTempUnicodesLen,
m_pInternal->m_pFontManager, x, y, w, h);
return S_OK;
}
HRESULT CASCHTMLRenderer3::PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandTextExCHAR(c, gid, x, y, w, h);
int _c = (int)c;
int _g = (int)gid;
m_pInternal->_SetFont();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandText2(&_c, &_g, 1,
m_pInternal->m_pFontManager, x, y, w, h);
return S_OK;
}
HRESULT CASCHTMLRenderer3::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)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.PathCommandTextEx(bsUnicodeText, pGids, nGidsCount, x, y, w, h);
m_pInternal->_SetFont();
m_pInternal->m_oSimpleGraphicsConverter.PathCommandText2(NULL, (const int*)pGids, nGidsCount,
m_pInternal->m_pFontManager, x, y, w, h);
return S_OK;
}
//-------- Функции для вывода изображений ---------------------------------------------------
HRESULT CASCHTMLRenderer3::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.DrawImage(pImage, x, y, w, h);
if (NULL == pImage)
return S_OK;
m_pInternal->m_oWriter.WriteImage(pImage, x, y, w, h);
return S_OK;
}
HRESULT CASCHTMLRenderer3::DrawImageFromFile(const std::wstring& sPath, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.DrawImageFromFile(sPath, x, y, w, h, lAlpha);
m_pInternal->m_oWriter.WriteImage(sPath, x, y, w, h);
return S_OK;
}
// transform --------------------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.SetTransform(m1, m2, m3, m4, m5, m6);
agg::trans_affine* paff = &m_pInternal->m_oTransform.m_agg_mtx;
paff->sx = m1;
paff->shy = m2;
paff->shx = m3;
paff->sy = m4;
paff->tx = m5;
paff->ty = m6;
return S_OK;
}
HRESULT CASCHTMLRenderer3::GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF)
{
agg::trans_affine* paff = &m_pInternal->m_oTransform.m_agg_mtx;
*pdA = paff->sx;
*pdB = paff->shy;
*pdC = paff->shx;
*pdD = paff->sy;
*pdE = paff->tx;
*pdF = paff->ty;
return S_OK;
}
HRESULT CASCHTMLRenderer3::ResetTransform()
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.ResetTransform();
m_pInternal->m_oTransform.Reset();
return S_OK;
}
// -----------------------------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::get_ClipMode(LONG* plMode)
{
*plMode = m_pInternal->m_lClipMode;
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_ClipMode(const LONG& lMode)
{
if (m_pInternal->m_bIsGraphicsDumperMode)
return m_pInternal->m_oDumper.put_ClipMode(lMode);
m_pInternal->m_lClipMode = lMode;
m_pInternal->m_oWriter.m_oSVGWriter.m_lClipMode = lMode;
return S_OK;
}
// additiaonal params ----------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::CommandLong(const LONG& lType, const LONG& lCommand)
{
return S_OK;
}
HRESULT CASCHTMLRenderer3::CommandDouble(const LONG& lType, const double& dCommand)
{
return S_OK;
}
HRESULT CASCHTMLRenderer3::CommandString(const LONG& lType, const std::wstring& sCommand)
{
return S_OK;
}
// owner params ----------------------------------------------------------------------
HRESULT CASCHTMLRenderer3::get_Mode(LONG *plMode)
{
return S_OK;
}
HRESULT CASCHTMLRenderer3::put_Mode(LONG lMode)
{
return S_OK;
}
HRESULT CASCHTMLRenderer3::CreateOfficeFile(std::wstring bsFileName)
{
m_pInternal->m_strDstFile = bsFileName;
size_t pos1 = m_pInternal->m_strDstFile.find_last_of(wchar_t('/'));
size_t pos2 = m_pInternal->m_strDstFile.find_last_of(wchar_t('\\'));
size_t pos = std::wstring::npos;
if (pos1 != std::wstring::npos)
pos = pos1;
if (pos2 != std::wstring::npos)
{
if (pos == std::wstring::npos)
pos = pos2;
else if (pos2 > pos)
pos = pos2;
}
if (pos == std::wstring::npos)
return S_FALSE;
std::wstring strDir = m_pInternal->m_strDstFile.substr(0, pos);
size_t nIndexExt = m_pInternal->m_strDstFile.find_last_of(wchar_t('.'));
if (nIndexExt == std::wstring::npos || nIndexExt <= pos)
nIndexExt = pos;
std::wstring strName = m_pInternal->m_strDstFile.substr(pos + 1, nIndexExt - pos - 1);
m_pInternal->m_oWriter.m_pTransform = &m_pInternal->m_oTransform;
m_pInternal->m_oWriter.CreateFile(strDir, strName);
m_pInternal->m_oWriter.WriteStartDocument();
m_pInternal->m_oWriter.m_oSmartText.m_oFontManager.Init(&m_pInternal->m_oApplicationFonts);
m_pInternal->m_lCurrentPage = -1;
m_pInternal->m_bPageOpened = false;
m_pInternal->m_pFontManager = m_pInternal->m_oApplicationFonts.GenerateFontManager();
m_pInternal->m_oFont.SetDefaultParams();
m_pInternal->m_oInstalledFont.SetDefaultParams();
m_pInternal->m_oSimpleGraphicsConverter.SetRenderer(this);
return S_OK;
}
HRESULT CASCHTMLRenderer3::CloseFile()
{
if (m_pInternal->m_bPageOpened)
{
m_pInternal->EndPage();
}
m_pInternal->m_oWriter.WriteEndDocument(m_pInternal->m_oDocument);
return S_OK;
}
HRESULT CASCHTMLRenderer3::SetAdditionalParam(std::string sParamName, int nValue)
{
if ("SourceType" == sParamName)
{
m_pInternal->m_oWriter.m_lSrcFileType = nValue;
return S_OK;
}
return S_OK;
}
HRESULT CASCHTMLRenderer3::SetAdditionalParam(std::string sParamName, const std::wstring& sParam)
{
if ("TilingHtmlPattern" == sParamName)
{
if (1 == m_pInternal->m_oWriter.m_lTilingCounter)
{
m_pInternal->m_bIsGraphicsDumperMode = true;
m_pInternal->m_oDumper.m_oTile.LoadFromXml(sParam);
m_pInternal->m_oDumper.NewPage(m_pInternal->m_oWriter.m_dWidth, m_pInternal->m_oWriter.m_dHeight);
m_pInternal->m_oDumper.m_oTile.bbox_x = 0;
m_pInternal->m_oDumper.m_oTile.bbox_y = 0;
m_pInternal->m_oDumper.m_oTile.bbox_r = m_pInternal->m_oDumper.m_lWidthPix - 1;
m_pInternal->m_oDumper.m_oTile.bbox_b = m_pInternal->m_oDumper.m_lHeightPix - 1;
m_pInternal->m_oDumper.m_oBounds.left = 0;
m_pInternal->m_oDumper.m_oBounds.top = 0;
m_pInternal->m_oDumper.m_oBounds.right = m_pInternal->m_oDumper.m_lWidthPix - 1;
m_pInternal->m_oDumper.m_oBounds.bottom = m_pInternal->m_oDumper.m_lHeightPix - 1;
}
}
return S_OK;
}
}
#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_
#ifndef _ASC_HTMLRENDERER_SVGWRITER2_H_
#define _ASC_HTMLRENDERER_SVGWRITER2_H_
#include "SVGWriter.h"
#include "../../../DesktopEditor/graphics/GraphicsRenderer.h"
#define SVG_INLINE_MAX_SIZE 500000 // 500Kb
#define SVG_TO_RASTER_MIN_SIZE 50000000 // 1Mb
namespace NSHtmlRenderer
{
#define USE_SIMPLE_GRAPHICS_NOSVG
//#define USE_BIG_GRAPHICS_TORASTER // разкоментировать, как научимся скидывать в растр!!! (пока свг не кроссплатформенный)
class CRendererGr
{
public:
CGraphicsRenderer* m_pRenderer;
CBgraFrame* m_pFrame;
double m_dWidth;
double m_dHeight;
LONG m_lWidthPix;
LONG m_lHeightPix;
bool m_bIsRasterNeed;
public:
CRendererGr()
{
m_pRenderer = NULL;
m_pFrame = NULL;
m_dWidth = -1;
m_dHeight = -1;
m_lWidthPix = -1;
m_lHeightPix = -1;
}
~CRendererGr()
{
RELEASEOBJECT(m_pRenderer);
RELEASEOBJECT(m_pFrame);
}
inline void UncheckRaster()
{
m_bIsRasterNeed = false;
}
inline void CheckRasterNeed(const bool& bIsRaster)
{
if (!m_bIsRasterNeed)
m_bIsRasterNeed = bIsRaster;
}
void CheckRaster(double dWidth, double dHeight)
{
if (dWidth != m_dWidth || dHeight != m_dHeight)
{
RELEASEOBJECT(m_pFrame);
m_dWidth = dWidth;
m_dHeight = dHeight;
}
RELEASEOBJECT(m_pRenderer);
m_lWidthPix = (LONG)(96 * m_dWidth / 25.4);
m_lHeightPix = (LONG)(96 * m_dHeight / 25.4);
if (NULL == m_pFrame)
{
m_pFrame = new CBgraFrame();
m_pFrame->put_Width((int)m_lWidthPix);
m_pFrame->put_Height((int)m_lHeightPix);
m_pFrame->put_Stride(4 * ((int)m_lWidthPix));
BYTE* pData = new BYTE[4 * m_lWidthPix * m_lHeightPix];
memset(pData, 0xFF, 4 * m_lWidthPix * m_lHeightPix);
m_pFrame->put_Data(pData);
}
m_pRenderer = new CGraphicsRenderer();
m_pRenderer->put_Width(m_dWidth);
m_pRenderer->put_Height(m_dHeight);
m_pRenderer->CreateFromBgraFrame(m_pFrame);
}
template<typename T>
void CheckRasterData(T pPage, double& dWidth, double& dHeight)
{
if (m_bIsRasterNeed)
{
CheckRaster(dWidth, dHeight);
GetRasterData(pPage);
}
UncheckRaster();
}
template<typename T>
void GetRasterData(T pPage)
{
// определ¤ем размеры картинки
if (NULL == m_pFrame)
return NULL;
BYTE* pBuffer = m_pFrame->get_Data();
RECT rect = GetImageBounds(m_pFrame);
if (((rect.right - rect.left) < 5) && ((rect.bottom - rect.top) < 5))
return NULL;
BYTE* pBufferSrcMem = pBuffer + 4 * rect.top * m_lWidthPix + 4 * rect.left;
LONG lWidthShape = rect.right - rect.left + 1;
LONG lHeightShape = rect.bottom - rect.top + 1;
CBgraFrame* pShapePicture = new CBgraFrame();
pShapePicture->put_Width((int)lWidthShape);
pShapePicture->put_Height((int)lHeightShape);
pShapePicture->put_Stride(4 * ((int)lWidthShape));
BYTE* pBufferDst = new BYTE[4 * lWidthShape * lHeightShape];
m_pFrame->put_Data(pBufferDst);
for (LONG lLine = 0; lLine < lHeightShape; ++lLine)
{
memcpy(pBufferDst, pBufferSrcMem, 4 * lWidthShape);
pBufferDst += 4 * lWidthShape;
pBufferSrcMem += 4 * m_lWidthPix;
}
double dL = 25.4 * rect.left / 96.0;
double dT = 25.4 * rect.top / 96.0;
double dW = 25.4 * lWidthShape / 96.0;
double dH = 25.4 * lHeightShape / 96.0;
double dHeightMM = 25.4 * m_lWidthPix / 96.0;
dT = (dHeightMM - dT - dH);
pPage->WriteImage(pShapePicture, dL, dT, dW, dH);
RELEASEOBJECT(pShapePicture);
}
};
class CDoubleBounds
{
public:
bool IsCleared;
double x;
double y;
double r;
double b;
public:
CDoubleBounds()
{
Clear();
}
void Clear()
{
IsCleared = true;
x = 10000000.0;
y = 10000000.0;
r = -10000000.0;
b = -10000000.0;
}
inline void CheckPoint(const double& _x, const double& _y)
{
IsCleared = false;
if (x > _x)
x = _x;
if (y > _y)
y = _y;
if (r < _x)
r = _x;
if (b < _y)
b = _y;
}
inline void Intersect(const CDoubleBounds& oBounds)
{
if (IsCleared)
{
x = oBounds.x;
y = oBounds.y;
r = oBounds.r;
b = oBounds.b;
IsCleared = false;
}
else
{
if (oBounds.x > x)
x = oBounds.x;
if (oBounds.y > y)
y = oBounds.y;
if (oBounds.r < r)
r = oBounds.r;
if (oBounds.b < b)
b = oBounds.b;
}
}
};
class CSVGWriter2
{
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;
NSStructures::CPen* m_pLastPen;
NSStructures::CBrush* m_pLastBrush;
Aggplus::CMatrix* m_pTransform;
int m_lWidth;
int m_lHeight;
double m_dDpiX;
double m_dDpiY;
CClipSVG2 m_oClip;
// здесь храним пат в координатах не трансформированных
// (чтобы, если заливки сложные - можно было делать трансформы
// непосредственно при использовании графического пути).
double* m_pCoordsArray;
unsigned int m_lCoordsSize;
double* m_pCoordsArrayCur;
unsigned int m_lCoordsSizeCur;
bool m_bIsCurveToExist;
BYTE* m_pPathTypes;
unsigned int m_lPathTypesSize;
BYTE* m_pPathTypesCur;
unsigned int m_lPathTypesSizeCur;
double m_dCoordsScaleX;
double m_dCoordsScaleY;
unsigned int m_lEmtyDocChecker;
BYTE* m_pBase64Code;
CDoubleBounds m_oTextClipBounds;
// переменная говорит о том, какой клип дл¤ текста записан сейчас
// если true - то послана команда ResetTextClipRect
// если false - то нет
bool m_bIsTextClipWriteCleared;
// были ли новые clip'ы
bool m_bIsIntersectNewClipRect;
// сохранение в растр. (если сложная заливка, или слишком большая векторная графика)
//CRendererGr m_oGrRenderer;
//Graphics::IASCMetafile* m_pGrRenderer;
// клип для картинок. для конвертации сложной векторной графики в растр
CMetafile m_oClipMetafile;
int m_nDEBUG_svg_index;
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
CMetafile m_oVectors;
bool m_bIsSimpleGraphics;
bool m_bIsSimpleSetupBrush;
LONG m_lBrushColorOld;
LONG m_lBrushAlphaOld;
#endif
public:
CSVGWriter2() : m_oPath(), m_oDocument()
{
m_lCurDocumentID = 0;
m_lClippingPath = 0;
m_lPatternID = 0;
m_pPen = NULL;
m_pBrush = NULL;
m_pLastPen = NULL;
m_pLastBrush = NULL;
m_dDpiX = 96;
m_dDpiY = 96;
m_dCoordsScaleX = m_dDpiX / 25.4;
m_dCoordsScaleY = m_dDpiY / 25.4;
m_lClipMode = c_nClipRegionTypeWinding;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
m_pCoordsArray = NULL;
m_lCoordsSize = 0;
m_pCoordsArrayCur = NULL;
m_lCoordsSizeCur = 0;
m_pPathTypes = NULL;
m_lPathTypesSize = 0;
m_pPathTypesCur = NULL;
m_lPathTypesSizeCur = 0;
m_lEmtyDocChecker = 0;
m_pBase64Code = new BYTE[2 * SVG_INLINE_MAX_SIZE];
m_bIsTextClipWriteCleared = true;
m_bIsIntersectNewClipRect = false;
m_bIsCurveToExist = false;
m_nDEBUG_svg_index = 0;
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
m_bIsSimpleGraphics = true;
m_bIsSimpleSetupBrush = false;
m_lBrushColorOld = 0;
m_lBrushAlphaOld = 255;
#endif
}
~CSVGWriter2()
{
RELEASEARRAYOBJECTS(m_pBase64Code);
}
void ReInit()
{
m_bIsTextClipWriteCleared = true;
m_bIsIntersectNewClipRect = false;
m_oTextClipBounds.Clear();
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>", 6);
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;
}
std::wstring GetSVGXml()
{
m_oClip.WriteEnd(m_oDocument);
m_oDocument.WriteString(L"</svg>", 6);
return m_oDocument.GetData();
}
void DEBUG_DumpSVG(const std::wstring& sTempPath)
{
std::wstring sEndDebug = L"";
int nCountWriteClips = m_oClip.m_lCountWriteClips;
while (nCountWriteClips > 0)
{
sEndDebug += L"</g>\n";
--nCountWriteClips;
}
sEndDebug += L"</svg>";
m_nDEBUG_svg_index++;
std::wstring sDocument = m_oDocument.GetData() + sEndDebug;
NSFile::CFileBinary::SaveToFile(sTempPath + L"/svg_" + std::to_wstring(m_nDEBUG_svg_index) + L".svg", sDocument);
}
void CloseFile2(std::wstring strFile, bool bIsNeedEnd = true)
{
if (bIsNeedEnd)
{
m_oClip.WriteEnd(m_oDocument);
m_oDocument.WriteString(L"</svg>", 6);
}
NSFile::CFileBinary::SaveToFile(strFile, m_oDocument.GetData());
m_oDocument.ClearNoAttack();
m_oPath.ClearNoAttack();
if (m_bIsClipping)
{
m_bIsNeedUpdateClip = true;
}
m_lPatternID = 0;
}
int CloseFile3(NSHtmlRenderer::CMetafile* m_pMeta, bool bIsNeedEnd = true)
{
if (bIsNeedEnd)
{
m_oClip.WriteEnd(m_oDocument);
m_oDocument.WriteString(L"</svg>", 6);
}
BYTE* pDataSrc = NULL;
LONG nLenSrc = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(m_oDocument.GetBuffer(), (LONG)m_oDocument.GetCurSize(), pDataSrc, nLenSrc);
char* pBase64 = NULL;
int nLenDst = 2 * SVG_INLINE_MAX_SIZE;
NSBase64::Base64Encode(pDataSrc, (int)nLenSrc, m_pBase64Code, &nLenDst);
RELEASEARRAYOBJECTS(pDataSrc);
m_pMeta->WriteLONG(nLenDst);
m_pMeta->Write(m_pBase64Code, nLenDst);
m_oDocument.ClearNoAttack();
m_oPath.ClearNoAttack();
if (m_bIsClipping)
{
m_bIsNeedUpdateClip = true;
}
m_lPatternID = 0;
return nLenDst;
}
void NewDocument(const double& dWidth, const double& dHeigth, const LONG& lPageNumber)
{
m_lWidth = (int)(dWidth * m_dCoordsScaleX);
m_lHeight = (int)(dHeigth * m_dCoordsScaleY);
m_oClip.m_lWidth = m_lWidth;
m_oClip.m_lHeight = m_lHeight;
m_lCurDocumentID = lPageNumber;
m_oDocument.ClearNoAttack();
m_oDocument.WriteString(L"<svg width=\"", 12);
m_oDocument.AddInt(m_lWidth);
m_oDocument.WriteString(L"px\" height=\"", 12);
m_oDocument.AddInt(m_lHeight);
m_oDocument.WriteString(L"px\" viewBox=\"0 0 ", 17);
m_oDocument.AddInt(m_lWidth);
m_oDocument.AddCharSafe(' ');
m_oDocument.AddInt(m_lHeight);
m_oDocument.WriteString(L"\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", 95);
m_oClip.Clear();
m_lClippingPath = 0;
m_bIsClipping = false;
m_bIsNeedUpdateClip = false;
m_lEmtyDocChecker = (unsigned int)m_oDocument.GetCurSize();
}
public:
inline void WritePathEnd()
{
m_bIsCurveToExist = false;
m_oPath.ClearNoAttack();
ClearVectorCoords();
}
inline void WritePathStart()
{
m_bIsCurveToExist = false;
m_oPath.ClearNoAttack();
ClearVectorCoords();
}
void WritePathClose()
{
CheckSizeVectorB();
*m_pPathTypesCur++ = 3;
++m_lPathTypesSizeCur;
/*
m_oPath.AddSize(2);
m_oPath.AddCharNoCheck('Z');
m_oPath.AddSpaceNoCheck();
*/
}
void WritePathMoveTo(const double& x, const double& y)
{
CheckSizeVectorB();
*m_pPathTypesCur++ = 0;
++m_lPathTypesSizeCur;
CheckSizeVectorD(2);
m_pCoordsArrayCur[0] = x;
m_pCoordsArrayCur[1] = y;
m_pTransform->TransformPoint(m_pCoordsArrayCur[0], m_pCoordsArrayCur[1]);
m_pCoordsArrayCur += 2;
m_lCoordsSizeCur += 2;
/*
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(const double& x, const double& y)
{
if (0 == m_lPathTypesSizeCur)
{
WritePathMoveTo(x, y);
return;
}
CheckSizeVectorB();
*m_pPathTypesCur++ = 1;
++m_lPathTypesSizeCur;
CheckSizeVectorD(2);
m_pCoordsArrayCur[0] = x;
m_pCoordsArrayCur[1] = y;
m_pTransform->TransformPoint(m_pCoordsArrayCur[0], m_pCoordsArrayCur[1]);
if (fabs(m_pCoordsArray[m_lCoordsSizeCur - 2] - m_pCoordsArrayCur[0]) < 0.1 &&
fabs(m_pCoordsArray[m_lCoordsSizeCur - 1] - m_pCoordsArrayCur[1]) < 0.1)
{
// попали в текущую точку. не добавл¤ем
--m_pPathTypesCur;
--m_lPathTypesSizeCur;
return;
}
m_pCoordsArrayCur += 2;
m_lCoordsSizeCur += 2;
/*
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(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{
if (0 == m_lPathTypesSizeCur)
WritePathMoveTo(x1, y1);
CheckSizeVectorB();
*m_pPathTypesCur++ = 2;
++m_lPathTypesSizeCur;
CheckSizeVectorD(6);
m_pCoordsArrayCur[0] = x1;
m_pCoordsArrayCur[1] = y1;
m_pCoordsArrayCur[2] = x2;
m_pCoordsArrayCur[3] = y2;
m_pCoordsArrayCur[4] = x3;
m_pCoordsArrayCur[5] = y3;
m_pTransform->TransformPoint(m_pCoordsArrayCur[0], m_pCoordsArrayCur[1]);
m_pTransform->TransformPoint(m_pCoordsArrayCur[2], m_pCoordsArrayCur[3]);
m_pTransform->TransformPoint(m_pCoordsArrayCur[4], m_pCoordsArrayCur[5]);
m_pCoordsArrayCur += 6;
m_lCoordsSizeCur += 6;
m_bIsCurveToExist = true;
/*
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::CGraphicsPathSimpleConverter* pConverter, CImageInfo& oInfo)
{
if (m_lPathTypesSizeCur == 0)
return;
WriteClip();
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
if (m_bIsClipping)
m_bIsSimpleGraphics = false;
#endif
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 bIsNeedTransform = true;
// первым делом нужно пон¤ть, будем ли мы трансформировать пути
if (nType > 0xFF && m_pBrush->Type == c_BrushTypeTexture)
{
bIsNeedTransform = false;
}
int nPenW = 1;
if (0 != m_pPen->Size)
{
if (!bIsNeedTransform)
{
nPenW = (int)(m_pPen->Size);
}
else
{
double _x1 = 0;
double _y1 = 0;
double _x2 = 1;
double _y2 = 1;
m_pTransform->TransformPoint(_x1, _y1);
m_pTransform->TransformPoint(_x2, _y2);
double dScaleTransform = sqrt(((_x2 - _x1) * (_x2 - _x1) + (_y2 - _y1) * (_y2 - _y1)) / 2) * m_dCoordsScaleX;
nPenW = (int)(m_pPen->Size * dScaleTransform);
}
}
bool bStroke = (0x01 == (0x01 & nType));
if (nPenW == 0 && bStroke)
nPenW = 1;
bool bFill = (0x01 < nType);
bool bIsLine = false;
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
if (m_bIsSimpleGraphics)
{
if (bFill && ((0 != (nType & c_nEvenOddFillMode)) || m_pBrush->Type != c_BrushTypeSolid))
m_bIsSimpleGraphics = false;
if (bStroke && m_pPen->DashStyle != 0)
m_bIsSimpleGraphics = false;
}
if (m_bIsSimpleGraphics)
{
// пишем вектор и настройки brush/pen
m_oVectors.WriteCommandType(CMetafile::ctPathCommandStart);
WriteToPathToSimpleVector();
bIsLine = WriteToPathToSVGPath(false, (bFill && !bStroke) ? true : false);
if (bFill && !bIsLine)
{
if (!m_pLastBrush->IsEqual(m_pBrush))
{
if (!m_bIsSimpleSetupBrush)
{
m_lBrushColorOld = m_pLastBrush->Color1;
m_lBrushAlphaOld = m_pLastBrush->Alpha1;
m_bIsSimpleSetupBrush = true;
}
*m_pLastBrush = *m_pBrush;
m_oVectors.WriteCommandType(CMetafile::ctBrushColor1);
LONG lBGR = m_pBrush->Color1;
m_oVectors.WriteBYTE((BYTE)(lBGR & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 8) & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 16) & 0xFF));
m_oVectors.WriteBYTE((BYTE)m_pBrush->Alpha1);
}
}
else if (bIsLine)
{
LONG _C = m_pPen->Color;
LONG _A = m_pPen->Alpha;
double _W = m_pPen->Size;
m_pPen->Color = m_pBrush->Color1;
m_pPen->Alpha = m_pBrush->Alpha1;
m_pPen->Size = 1 / m_dCoordsScaleX;
if (!m_pLastPen->IsEqual(m_pPen))
{
*m_pLastPen = *m_pPen;
m_oVectors.WriteCommandType(CMetafile::ctPenColor);
LONG lBGR = m_pPen->Color;
m_oVectors.WriteBYTE((BYTE)(lBGR & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 8) & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 16) & 0xFF));
m_oVectors.WriteBYTE((BYTE)m_pPen->Alpha);
m_oVectors.WriteCommandType(CMetafile::ctPenSize);
m_oVectors.WriteDouble((double)nPenW / m_dCoordsScaleX);
}
m_pPen->Color = _C;
m_pPen->Alpha = _A;
m_pPen->Size = _W;
}
if (bStroke)
{
if (!m_pLastPen->IsEqual(m_pPen))
{
*m_pLastPen = *m_pPen;
m_oVectors.WriteCommandType(CMetafile::ctPenColor);
LONG lBGR = m_pPen->Color;
m_oVectors.WriteBYTE((BYTE)(lBGR & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 8) & 0xFF));
m_oVectors.WriteBYTE((BYTE)((lBGR >> 16) & 0xFF));
m_oVectors.WriteBYTE((BYTE)m_pPen->Alpha);
m_oVectors.WriteCommandType(CMetafile::ctPenSize);
m_oVectors.WriteDouble((double)nPenW / m_dCoordsScaleX);
}
}
m_oVectors.WriteCommandType(CMetafile::ctDrawPath);
m_oVectors.WriteLONG(bIsLine ? 1 : nType);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandStart);
}
else
{
bIsLine = WriteToPathToSVGPath(false, (bFill && !bStroke) ? true : false);
}
#else
bIsLine = WriteToPathToSVGPath(false, (bFill && !bStroke) ? true : false);
#endif
if (!bFill)
{
// stroke
m_oDocument.WriteString(L"<path style=\"fill:none;stroke:", 30);
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.AddDouble((double)m_pPen->Alpha / 255, 2);
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 w = 0;
double h = 0;
pConverter->PathCommandGetBounds(x, y, w, h);
if (m_pBrush->TextureMode == c_BrushTextureModeStretch || true)
{
// 1) пишем паттерн
agg::trans_affine* mtx = &m_pTransform->m_agg_mtx;
double _tx = mtx->tx * m_dCoordsScaleX;
double _ty = mtx->ty * m_dCoordsScaleY;
double _w = w * m_dCoordsScaleX;
double _h = h * m_dCoordsScaleY;
m_oDocument.WriteString(L"<pattern id=\"pt", 15);
m_oDocument.AddInt(m_lPatternID);
m_oDocument.WriteString(L"\" patternUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"", 51);
m_oDocument.AddInt(round(_w));
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddInt(round(_h));
m_oDocument.WriteString(L"\" viewBox=\"0 0 ", 15);
m_oDocument.AddInt(round(_w));
m_oDocument.AddCharSafe(' ');
m_oDocument.AddInt(round(_h));
m_oDocument.WriteString(L"\" transform=\"matrix(");
m_oDocument.AddDouble(mtx->sx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->sy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_tx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_ty, 3);
m_oDocument.WriteString(L")\"><image x=\"0\" y=\"0\" width=\"", 29);
m_oDocument.AddInt(round(_w));
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddInt(round(_h));
m_oDocument.WriteString(L"\" xlink:href=\"image", 19);
m_oDocument.AddInt(oInfo.m_lID);
if (itJPG == oInfo.m_eType)
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\"/></pattern>", 44);
else
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\"/></pattern>", 44);
}
else
{
// TODO:
}
m_oDocument.WriteString(L"<path style=\"fill:url(#pt", 25);
m_oDocument.AddInt(m_lPatternID);
m_oDocument.WriteString(L");fill-opacity:");
m_oDocument.AddDouble((double)m_pBrush->Alpha1 / 255, 2);
if (nType & c_nEvenOddFillMode)
m_oDocument.WriteString(L";fill-rule:evenodd;", 19);
else
m_oDocument.WriteString(L";fill-rule:nonzero;", 19);
if (!bStroke)
{
m_oDocument.WriteString(L"stroke:none;\" ", 14);
}
else
{
m_oDocument.WriteString(L"stroke:", 7);
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.AddDouble((double)m_pPen->Alpha / 255, 2);
m_oDocument.WriteString(L"\" ", 2);
}
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
++m_lPatternID;
return;
}
int nColorBrush = ConvertColor(m_pBrush->Color1);
if (nType & c_nEvenOddFillMode)
{
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
m_bIsSimpleGraphics = false;
#endif
}
if (!bStroke)
{
if (bIsLine)
{
m_oDocument.WriteString(L"<path style=\"fill:none;stroke:", 30);
m_oDocument.WriteHexColor3(m_pBrush->Color1);
m_oDocument.WriteString(L";stroke-width:", 14);
m_oDocument.AddInt(1);
m_oDocument.WriteString(L";stroke-opacity:", 16);
m_oDocument.AddDouble((double)m_pBrush->Alpha1 / 255, 2);
m_oDocument.WriteString(L";\" ", 3);
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
return;
}
m_oDocument.WriteString(L"<path style=\"fill:", 18);
m_oDocument.WriteHexColor3(m_pBrush->Color1);
m_oDocument.WriteString(L";fill-opacity:", 14);
m_oDocument.AddDouble((double)m_pBrush->Alpha1 / 255, 2);
if (nType & c_nEvenOddFillMode)
m_oDocument.WriteString(L";fill-rule:evenodd;stroke:none\" ", 32);
else
m_oDocument.WriteString(L";fill-rule:nonzero;stroke:none\" ", 32);
WriteStyleClip();
m_oDocument.WriteString(L" d=\"", 4);
m_oDocument.Write(m_oPath);
m_oDocument.WriteString(L"\" />\n", 5);
return;
}
m_oDocument.WriteString(L"<path style=\"fill:", 18);
m_oDocument.WriteHexInt3(m_pBrush->Color1);
m_oDocument.WriteString(L";fill-opacity:", 14);
m_oDocument.AddDouble((double)m_pBrush->Alpha1 / 255, 2);
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.WriteHexInt3(m_pPen->Color);
m_oDocument.WriteString(L";stroke-width:", 14);
m_oDocument.AddInt(nPenW);
m_oDocument.WriteString(L";stroke-opacity:", 16);
m_oDocument.AddDouble((double)m_pPen->Alpha / 255, 2);
m_oDocument.WriteString(L";\" ", 3);
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 (1 == m_lPathTypesSizeCur && m_pPathTypes[0] <= 1)
{
// не надо клип делать. пат странен)
return;
}
else if (2 == m_lPathTypesSizeCur &&
((m_pPathTypes[0] == 0 || m_pPathTypes[1] == 0) && (m_pPathTypes[0] <= 1 && m_pPathTypes[1] <= 1)))
{
// пат все еще странен
return;
}
*/
m_oClip.WriteEnd(m_oDocument);
m_bIsIntersectNewClipRect = true;
WriteToPathToSVGPath(true);
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();
m_oTextClipBounds.Clear();
m_oClipMetafile.ClearNoAttack();
m_oClip.WriteEnd(m_oDocument);
}
void WriteImage(CImageInfo& oInfo, const double& x, const double& y, const double& w, const double& h)
{
bool bIsClipping = false;
if ((1 < h) && (1 < w))
{
WriteClip();
bIsClipping = m_bIsClipping;
}
double dCentreX = x + w / 2.0;
double dCentreY = y + h / 2.0;
agg::trans_affine* mtx = &m_pTransform->m_agg_mtx;
bool bIsNoNeedTransform = agg::is_equal_eps(mtx->sx, 1.0, 0.0001) &&
agg::is_equal_eps(mtx->shy, 0.0, 0.0001) &&
agg::is_equal_eps(mtx->shx, 0.0, 0.0001) &&
agg::is_equal_eps(mtx->sy, 1.0, 0.0001);
if (bIsNoNeedTransform)
{
double _x = x + m_pTransform->m_agg_mtx.tx;
double _y = y + m_pTransform->m_agg_mtx.ty;
_x *= m_dCoordsScaleX;
_y *= m_dCoordsScaleY;
double _w = w * m_dCoordsScaleX;
double _h = h * m_dCoordsScaleY;
if (itJPG == oInfo.m_eType)
{
/*if (bIsClipping)
{
//("<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" clip-path=\"url(#clip%d)\" xlink:href=\"image%d.jpg\" preserveAspectRatio=\"none\"/>");
strImage.Format(g_svg_string_image_clip_jpg1, round(_x), round(_y), round(_w), round(_h), m_lClippingPath - 1, oInfo.m_lID);
}
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=\"", 9);
m_oDocument.AddInt( round(_w));
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddInt( round(_h));
m_oDocument.WriteString(L"\" xlink:href=\"image", 19);
m_oDocument.AddInt(oInfo.m_lID);
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\"/>", 34);
}
}
else
{
/*if (bIsClipping)
{
//("<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" clip-path=\"url(#clip%d)\" xlink:href=\"image%d.png\" preserveAspectRatio=\"none\"/>");
strImage.Format(g_svg_string_image_clip_png1, round(_x), round(_y), round(_w), round(_h), m_lClippingPath - 1, oInfo.m_lID);
}
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=\"", 9);
m_oDocument.AddInt( round(_w));
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddInt( round(_h));
m_oDocument.WriteString(L"\" xlink:href=\"image", 19);
m_oDocument.AddInt(oInfo.m_lID);
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\"/>", 34);
}
}
}
else
{
double _tx = m_pTransform->m_agg_mtx.tx * m_dCoordsScaleX;
double _ty = m_pTransform->m_agg_mtx.ty * m_dCoordsScaleY;
double _x = x * m_dCoordsScaleX;
double _y = y * m_dCoordsScaleY;
double _w = w * m_dCoordsScaleX;
double _h = h * m_dCoordsScaleY;
if (itJPG == oInfo.m_eType)
{
/*if (bIsClipping)
{
//_T("<image x=\"%.3lf\" y=\"%.3lf\" width=\"%.3lf\" height=\"%.3lf\" clip-path=\"url(#clip%d)\" xlink:href=\"image%d.jpg\" preserveAspectRatio=\"none\" transform=\"matrix(%.3lf, %.3lf,%.3lf,%.3lf, %.3lf,%.3lf)\"/>");
strImage.Format(g_svg_string_image_clip_jpg_mtx, _x, _y, _w, _h, m_lClippingPath - 1, oInfo.m_lID, mtx->sx, mtx->shy, mtx->shx, mtx->sy, _tx, _ty);
}
else*/
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddDouble(_x, 3);
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddDouble(_y, 3);
m_oDocument.WriteString(L"\" width=\"", 9);
m_oDocument.AddDouble(_w, 3);
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddDouble(_h, 3);
m_oDocument.WriteString(L"\" xlink:href=\"image", 19);
m_oDocument.AddInt(oInfo.m_lID);
m_oDocument.WriteString(L".jpg\" preserveAspectRatio=\"none\" transform=\"matrix(/>", 53);
m_oDocument.AddDouble(mtx->sx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->sy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_tx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_ty, 3);
m_oDocument.WriteString(L")\"/>", 4);
}
}
else
{
/*if (bIsClipping)
{
//_T("<image x=\"%.3lf\" y=\"%.3lf\" width=\"%.3lf\" height=\"%.3lf\" clip-path=\"url(#clip%d)\" xlink:href=\"image%d.jpg\" preserveAspectRatio=\"none\" transform=\"matrix(%.3lf, %.3lf,%.3lf,%.3lf, %.3lf,%.3lf)\"/>");
strImage.Format(g_svg_string_image_clip_png_mtx, _x, _y, _w, _h, m_lClippingPath - 1, oInfo.m_lID, mtx->sx, mtx->shy, mtx->shx, mtx->sy, _tx, _ty);
}
else*/
{
m_oDocument.WriteString(L"<image x=\"", 10);
m_oDocument.AddDouble(_x, 3);
m_oDocument.WriteString(L"\" y=\"", 5);
m_oDocument.AddDouble(_y, 3);
m_oDocument.WriteString(L"\" width=\"", 9);
m_oDocument.AddDouble(_w, 3);
m_oDocument.WriteString(L"\" height=\"", 10);
m_oDocument.AddDouble(_h, 3);
m_oDocument.WriteString(L"\" xlink:href=\"image", 19);
m_oDocument.AddInt(oInfo.m_lID);
m_oDocument.WriteString(L".png\" preserveAspectRatio=\"none\" transform=\"matrix(/>", 53);
m_oDocument.AddDouble(mtx->sx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->shx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(mtx->sy, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_tx, 3);
m_oDocument.AddCharSafe(',');
m_oDocument.AddDouble(_ty, 3);
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 WriteStyleClip()
{
// сейчас не пишем (оборачиваем в g)
return;
if (m_bIsClipping)
{
//_T("clip-path=\"url(#clip%d)\" ");
m_oDocument.WriteString(L"clip-path=\"url(#clip", 20);
m_oDocument.AddInt(m_lClippingPath - 1);
m_oDocument.WriteString(L")\" ", 3);
}
}
void CheckSizeVectorB(const int& len = 1)
{
if (NULL != m_pPathTypes)
{
unsigned int nNewSize = (unsigned int)(m_lPathTypesSizeCur + len);
if (nNewSize >= m_lPathTypesSize)
{
if (nNewSize >= m_lPathTypesSize)
{
while (nNewSize >= m_lPathTypesSize)
{
m_lPathTypesSize *= 2;
}
BYTE* pNew = new BYTE[m_lPathTypesSize];
memcpy(pNew, m_pPathTypes, m_lPathTypesSizeCur);
RELEASEARRAYOBJECTS(m_pPathTypes);
m_pPathTypes = pNew;
m_pPathTypesCur = m_pPathTypes + m_lPathTypesSizeCur;
}
}
}
else
{
m_lPathTypesSize = 1000;
m_pPathTypes = new BYTE[m_lPathTypesSize];
m_pPathTypesCur = m_pPathTypes;
m_lPathTypesSizeCur = 0;
}
}
void CheckSizeVectorD(const int& len)
{
if (NULL != m_pCoordsArray)
{
unsigned int nNewSize = (unsigned int)(m_lCoordsSizeCur + len);
if (nNewSize >= m_lCoordsSize)
{
while (nNewSize >= m_lCoordsSize)
{
m_lCoordsSize *= 2;
}
double* pNew = new double[m_lCoordsSize];
memcpy(pNew, m_pCoordsArray, m_lCoordsSizeCur * sizeof(double));
RELEASEARRAYOBJECTS(m_pCoordsArray);
m_pCoordsArray = pNew;
m_pCoordsArrayCur = m_pCoordsArray + m_lCoordsSizeCur;
}
}
else
{
m_lCoordsSize = 1000;
m_pCoordsArray = new double[m_lCoordsSize];
m_pCoordsArrayCur = m_pCoordsArray;
m_lCoordsSizeCur = 0;
}
}
void ClearVectorCoords()
{
m_lCoordsSizeCur = 0;
m_pCoordsArrayCur = m_pCoordsArray;
m_lPathTypesSizeCur = 0;
m_pPathTypesCur = m_pPathTypes;
}
bool WriteToPathToSVGPath(bool bIsClipping = false, bool bIsNeedAnalyzeLine = false)
{
m_oPath.ClearNoAttack();
CDoubleBounds oBounds;
if (!bIsNeedAnalyzeLine)
{
unsigned int lSize = m_lCoordsSizeCur;
for (unsigned int i = 0; i < lSize; i += 2)
{
if (bIsClipping)
{
oBounds.CheckPoint(m_pCoordsArray[i], m_pCoordsArray[i + 1]);
}
m_pCoordsArray[i] *= m_dCoordsScaleX;
m_pCoordsArray[i + 1] *= m_dCoordsScaleY;
}
}
else
{
if (!bIsClipping && m_lPathTypesSizeCur <= 4 && !m_bIsCurveToExist)
{
unsigned int lSize = m_lCoordsSizeCur;
for (unsigned int i = 0; i < lSize; i += 2)
{
m_pCoordsArray[i] *= m_dCoordsScaleX;
m_pCoordsArray[i + 1] *= m_dCoordsScaleY;
}
switch (m_lPathTypesSizeCur)
{
case 2:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1])
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[2]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[3]));
m_oPath.AddSpaceNoCheck();
return true;
}
break;
}
case 3:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1])
{
if (3 == m_pPathTypes[2])
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[2]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[3]));
m_oPath.AddSpaceNoCheck();
return true;
}
else
{
if ((fabs(m_pCoordsArray[4] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[5] - m_pCoordsArray[1]) < 0.2))
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[2]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[3]));
m_oPath.AddSpaceNoCheck();
return true;
}
else if ((fabs(m_pCoordsArray[2] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[3] - m_pCoordsArray[1]) < 0.2))
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[4]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[5]));
m_oPath.AddSpaceNoCheck();
return true;
}
}
}
break;
}
case 4:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1] && 1 == m_pPathTypes[2])
{
if ((fabs(m_pCoordsArray[4] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[5] - m_pCoordsArray[1]) < 0.2))
{
if (3 == m_pPathTypes[3])
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[2]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[3]));
m_oPath.AddSpaceNoCheck();
return true;
}
else if (1 == m_pPathTypes[3] && ((fabs(m_pCoordsArray[6] - m_pCoordsArray[2]) < 0.2) &&
(fabs(m_pCoordsArray[7] - m_pCoordsArray[3]) < 0.2)))
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[2]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[3]));
m_oPath.AddSpaceNoCheck();
return true;
}
}
else if ((fabs(m_pCoordsArray[2] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[3] - m_pCoordsArray[1]) < 0.2))
{
if (3 == m_pPathTypes[3])
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[4]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[5]));
m_oPath.AddSpaceNoCheck();
return true;
}
else if (1 == m_pPathTypes[3] && ((fabs(m_pCoordsArray[6] - m_pCoordsArray[2]) < 0.2) &&
(fabs(m_pCoordsArray[7] - m_pCoordsArray[3]) < 0.2)))
{
m_oPath.AddSize(60);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[0]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[1]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[4]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[5]));
m_oPath.AddSpaceNoCheck();
return true;
}
}
}
break;
}
default:
break;
}
}
else
{
unsigned int lSize = m_lCoordsSizeCur;
for (unsigned int i = 0; i < lSize; i += 2)
{
if (bIsClipping)
{
oBounds.CheckPoint(m_pCoordsArray[i], m_pCoordsArray[i + 1]);
}
m_pCoordsArray[i] *= m_dCoordsScaleX;
m_pCoordsArray[i + 1] *= m_dCoordsScaleY;
}
}
}
if (bIsClipping)
m_oTextClipBounds.Intersect(oBounds);
unsigned int lCurrentCoord = 0;
for (unsigned int nCommand = 0; nCommand < m_lPathTypesSizeCur; ++nCommand)
{
switch (m_pPathTypes[nCommand])
{
case 0:
{
m_oPath.AddSize(30);
m_oPath.AddCharNoCheck('M');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddSpaceNoCheck();
break;
}
case 1:
{
m_oPath.AddSize(30);
m_oPath.AddCharNoCheck('L');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddSpaceNoCheck();
break;
}
case 2:
{
m_oPath.AddSize(80);
m_oPath.AddCharNoCheck('C');
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddSpaceNoCheck();
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddCharNoCheck(',');
m_oPath.AddIntNoCheckDel10(round(10 * m_pCoordsArray[lCurrentCoord++]));
m_oPath.AddSpaceNoCheck();
break;
}
case 3:
{
m_oPath.AddSize(2);
m_oPath.AddCharNoCheck('Z');
m_oPath.AddSpaceNoCheck();
break;
}
default:
break;
}
}
if (bIsClipping)
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandStart);
m_oClipMetafile.WriteLONG(CMetafile::ctBeginCommand, c_nClipType);
lCurrentCoord = 0;
for (ULONG nCommand = 0; nCommand < m_lPathTypesSizeCur; ++nCommand)
{
switch (m_pPathTypes[nCommand])
{
case 0:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleX);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleY);
break;
}
case 1:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleX);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleY);
break;
}
case 2:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandCurveTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleX);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleY);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleX);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleY);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleX);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++] / m_dCoordsScaleY);
break;
}
case 3:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandClose);
break;
}
default:
break;
}
}
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
}
return false;
}
LONG WriteTempClip()
{
LONG nRet = m_oClipMetafile.GetPosition();
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandStart);
m_oClipMetafile.WriteLONG(CMetafile::ctBeginCommand, c_nClipType);
LONG lCurrentCoord = 0;
for (ULONG nCommand = 0; nCommand < m_lPathTypesSizeCur; ++nCommand)
{
switch (m_pPathTypes[nCommand])
{
case 0:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 1:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 2:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandCurveTo);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oClipMetafile.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 3:
{
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandClose);
break;
}
default:
break;
}
}
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
return nRet;
}
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
void WriteToPathToSimpleVector()
{
if (m_lPathTypesSizeCur <= 4 && !m_bIsCurveToExist)
{
switch (m_lPathTypesSizeCur)
{
case 2:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1])
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[2]);
m_oVectors.WriteDouble(m_pCoordsArray[3]);
return;
}
break;
}
case 3:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1])
{
if (3 == m_pPathTypes[2])
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[2]);
m_oVectors.WriteDouble(m_pCoordsArray[3]);
return;
}
else
{
if ((fabs(m_pCoordsArray[4] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[5] - m_pCoordsArray[1]) < 0.2))
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[2]);
m_oVectors.WriteDouble(m_pCoordsArray[3]);
return;
}
else if ((fabs(m_pCoordsArray[2] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[3] - m_pCoordsArray[1]) < 0.2))
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[4]);
m_oVectors.WriteDouble(m_pCoordsArray[5]);
return;
}
}
}
break;
}
case 4:
{
if (0 == m_pPathTypes[0] && 1 == m_pPathTypes[1] && 1 == m_pPathTypes[2])
{
if ((fabs(m_pCoordsArray[4] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[5] - m_pCoordsArray[1]) < 0.2))
{
if (3 == m_pPathTypes[3])
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[2]);
m_oVectors.WriteDouble(m_pCoordsArray[3]);
return;
}
else if (1 == m_pPathTypes[3] && ((fabs(m_pCoordsArray[6] - m_pCoordsArray[2]) < 0.2) &&
(fabs(m_pCoordsArray[7] - m_pCoordsArray[3]) < 0.2)))
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[2]);
m_oVectors.WriteDouble(m_pCoordsArray[3]);
return;
}
}
else if ((fabs(m_pCoordsArray[2] - m_pCoordsArray[0]) < 0.2) &&
(fabs(m_pCoordsArray[3] - m_pCoordsArray[1]) < 0.2))
{
if (3 == m_pPathTypes[3])
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[4]);
m_oVectors.WriteDouble(m_pCoordsArray[5]);
return;
}
else if (1 == m_pPathTypes[3] && ((fabs(m_pCoordsArray[6] - m_pCoordsArray[2]) < 0.2) &&
(fabs(m_pCoordsArray[7] - m_pCoordsArray[3]) < 0.2)))
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[0]);
m_oVectors.WriteDouble(m_pCoordsArray[1]);
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[4]);
m_oVectors.WriteDouble(m_pCoordsArray[5]);
return;
}
}
}
break;
}
default:
break;
}
}
unsigned int lCurrentCoord = 0;
for (unsigned int nCommand = 0; nCommand < m_lPathTypesSizeCur; ++nCommand)
{
switch (m_pPathTypes[nCommand])
{
case 0:
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandMoveTo);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 1:
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandLineTo);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 2:
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandCurveTo);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
m_oVectors.WriteDouble(m_pCoordsArray[lCurrentCoord++]);
break;
}
case 3:
{
m_oVectors.WriteCommandType(CMetafile::ctPathCommandClose);
break;
}
default:
break;
}
}
}
#endif
void CheckPathTextRect(CDoubleBounds& oBounds)
{
unsigned int lSize = m_lCoordsSizeCur;
for (unsigned int i = 0; i < lSize; i += 2)
{
oBounds.CheckPoint(m_pCoordsArray[i] * m_dCoordsScaleX, m_pCoordsArray[i + 1] * m_dCoordsScaleY);
}
}
inline void NewSVG()
{
m_oDocument.SetCurSize(m_lEmtyDocChecker);
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
if (m_bIsSimpleSetupBrush && !m_bIsSimpleGraphics)
{
m_pLastBrush->Color1 = m_lBrushColorOld;
m_pLastBrush->Alpha1 = m_lBrushAlphaOld;
}
m_oVectors.ClearNoAttack();
m_bIsSimpleGraphics = true;
m_bIsSimpleSetupBrush = false;
#endif
}
};
}
#endif // _ASC_HTMLRENDERER_SVGWRITER2_H_
#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_
#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_
#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_
#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_
#ifndef _ASC_HTMLRENDERER_WRITER_H_
#define _ASC_HTMLRENDERER_WRITER_H_
#include "SVGWriter2.h"
#include <map>
#include "../../../DesktopEditor/xml/include/xmlutils.h"
#include "../../../DesktopEditor/common/CalculatorCRC32.h"
#include "Text.h"
#include "Document.h"
#include "../../../DesktopEditor/fontengine/FontConverter.h"
namespace NSHtmlRenderer
{
static double __g_matrix_eps = 0.0001;
class CTileInfo
{
/*
_T("<htmltiling x=\"%.2lf\" y=\"%.2lf\" countx=\"%.2lf\" county=\"%.2lf\" stepx=\"%.2lf\" stepy=\"%.2lf\">\
<bbox x=\".2lf\" y=\"%.2lf\" r=\"%.2lf\" b=\"%.2lf\" />\
<transform m1=\"%.2lf\" m2=\"%.2lf\" m3=\"%.2lf\" m4=\"%.2lf\" m5=\"%.2lf\" m6=\"%.2lf\" />\
</htmltiling>
*/
public:
double x;
double y;
double countx;
double county;
double stepx;
double stepy;
double bbox_x;
double bbox_y;
double bbox_r;
double bbox_b;
double transform_1;
double transform_2;
double transform_3;
double transform_4;
double transform_5;
double transform_6;
public:
CTileInfo()
{
Clear();
}
public:
void Clear()
{
x = 0;
y = 0;
countx = 0;
county = 0;
stepx = 0;
stepy = 0;
bbox_x = 0;
bbox_y = 0;
bbox_r = 0;
bbox_b = 0;
transform_1 = 1;
transform_2 = 0;
transform_3 = 0;
transform_4 = 1;
transform_5 = 0;
transform_6 = 0;
}
void LoadFromXml(const std::wstring& strXml)
{
XmlUtils::CXmlNode oNode;
if (oNode.FromXmlString(strXml))
{
x = oNode.ReadAttributeDouble(L"x", 0);
y = oNode.ReadAttributeDouble(L"y", 0);
countx = oNode.ReadAttributeDouble(L"countx", 0);
county = oNode.ReadAttributeDouble(L"county", 0);
stepx = oNode.ReadAttributeDouble(L"stepx", 0);
stepy = oNode.ReadAttributeDouble(L"stepy", 0);
XmlUtils::CXmlNode oNodeBox;
if (oNode.GetNode(L"bbox", oNodeBox))
{
bbox_x = oNode.ReadAttributeDouble(L"x", 0);
bbox_y = oNode.ReadAttributeDouble(L"y", 0);
bbox_r = oNode.ReadAttributeDouble(L"r", 0);
bbox_b = oNode.ReadAttributeDouble(L"b", 0);
}
XmlUtils::CXmlNode oNodeTr;
if (oNode.GetNode(L"transform", oNodeTr))
{
transform_1 = oNode.ReadAttributeDouble(L"m1", 0);
transform_2 = oNode.ReadAttributeDouble(L"m2", 0);
transform_3 = oNode.ReadAttributeDouble(L"m3", 0);
transform_4 = oNode.ReadAttributeDouble(L"m4", 0);
transform_5 = oNode.ReadAttributeDouble(L"m5", 0);
transform_6 = oNode.ReadAttributeDouble(L"m6", 0);
}
}
}
};
class CGraphicsDumper
{
public:
CGraphicsRenderer* m_pRenderer;
CBgraFrame* m_pFrame;
double m_dWidth;
double m_dHeight;
int m_lWidthPix;
int m_lHeightPix;
RECT m_oBounds;
CTileInfo m_oTile;
public:
CGraphicsDumper()
{
m_pRenderer = NULL;
m_pFrame = NULL;
m_dWidth = -1;
m_dHeight = -1;
m_lWidthPix = -1;
m_lHeightPix = -1;
m_oBounds.left = 0;
m_oBounds.top = 0;
m_oBounds.right = 0;
m_oBounds.bottom = 0;
}
~CGraphicsDumper()
{
RELEASEOBJECT(m_pRenderer);
RELEASEOBJECT(m_pFrame);
}
void NewPage(double dWidth, double dHeight)
{
if (dWidth != m_dWidth || dHeight != m_dHeight)
{
RELEASEOBJECT(m_pFrame);
m_dWidth = dWidth;
m_dHeight = dHeight;
}
RELEASEOBJECT(m_pRenderer);
m_lWidthPix = (int)(96 * dWidth / 25.4);
m_lHeightPix = (int)(96 * dHeight / 25.4);
if (NULL == m_pFrame)
{
m_pFrame = new CBgraFrame();
m_pFrame->put_Width(m_lWidthPix);
m_pFrame->put_Height(m_lHeightPix);
m_pFrame->put_Stride(4 * m_lWidthPix * m_lHeightPix);
m_pFrame->put_Data(new BYTE[4 * m_lWidthPix * m_lHeightPix]);
}
BYTE* pBuffer = m_pFrame->get_Data();
memset(pBuffer, 0xFF, 4 * m_lWidthPix * m_lHeightPix);
m_pRenderer = new CGraphicsRenderer();
m_pRenderer->put_Width(m_dWidth);
m_pRenderer->put_Height(m_dHeight);
m_pRenderer->CreateFromBgraFrame(m_pFrame);
}
CBgraFrame* ConvertVectorGraphics()
{
BYTE* pBuffer = m_pFrame->get_Data();
BYTE* pBufferSrcMem = pBuffer + 4 * m_oBounds.top * m_lWidthPix + 4 * m_oBounds.left;
int lWidthShape = (int)(m_oBounds.right - m_oBounds.left + 1);
int lHeightShape = (int)(m_oBounds.bottom - m_oBounds.top + 1);
CBgraFrame* pReturnFrame = new CBgraFrame();
pReturnFrame->put_Width(lWidthShape);
pReturnFrame->put_Height(lHeightShape);
pReturnFrame->put_Stride(4 * lWidthShape * lHeightShape);
BYTE* pBufferDst = new BYTE[4 * lWidthShape * lHeightShape];
pReturnFrame->put_Data(pBufferDst);
for (LONG lLine = 0; lLine < lHeightShape; ++lLine)
{
memcpy(pBufferDst, pBufferSrcMem, 4 * lWidthShape);
pBufferDst += 4 * lWidthShape;
pBufferSrcMem += 4 * m_lWidthPix;
}
return pReturnFrame;
}
public:
inline HRESULT get_Type(LONG* lType)
{
if (m_pRenderer)
return m_pRenderer->get_Type(lType);
return S_OK;
}
//-------- Функции для работы со страницей --------------------------------------------------
inline HRESULT NewPage()
{
if (m_pRenderer)
return m_pRenderer->NewPage();
return S_OK;
}
inline HRESULT get_Height(double* dHeight)
{
if (m_pRenderer)
return m_pRenderer->get_Height(dHeight);
return S_OK;
}
inline HRESULT put_Height(const double& dHeight)
{
if (m_pRenderer)
return m_pRenderer->put_Height(dHeight);
return S_OK;
}
inline HRESULT get_Width(double* dWidth)
{
if (m_pRenderer)
return m_pRenderer->get_Width(dWidth);
return S_OK;
}
inline HRESULT put_Width(const double& dWidth)
{
if (m_pRenderer)
return m_pRenderer->put_Width(dWidth);
return S_OK;
}
inline HRESULT get_DpiX(double* dDpiX)
{
if (m_pRenderer)
return m_pRenderer->get_DpiX(dDpiX);
return S_OK;
}
inline HRESULT get_DpiY(double* dDpiY)
{
if (m_pRenderer)
return m_pRenderer->get_DpiY(dDpiY);
return S_OK;
}
// pen --------------------------------------------------------------------------------------
inline HRESULT get_PenColor(LONG* lColor)
{
if (m_pRenderer)
return m_pRenderer->get_PenColor(lColor);
return S_OK;
}
inline HRESULT put_PenColor(const LONG& lColor)
{
if (m_pRenderer)
return m_pRenderer->put_PenColor(lColor);
return S_OK;
}
inline HRESULT get_PenAlpha(LONG* lAlpha)
{
if (m_pRenderer)
return m_pRenderer->get_PenAlpha(lAlpha);
return S_OK;
}
inline HRESULT put_PenAlpha(const LONG& lAlpha)
{
if (m_pRenderer)
return m_pRenderer->put_PenAlpha(lAlpha);
return S_OK;
}
inline HRESULT get_PenSize(double* dSize)
{
if (m_pRenderer)
return m_pRenderer->get_PenSize(dSize);
return S_OK;
}
inline HRESULT put_PenSize(const double& dSize)
{
if (m_pRenderer)
return m_pRenderer->put_PenSize(dSize);
return S_OK;
}
inline HRESULT get_PenDashStyle(BYTE* val)
{
if (m_pRenderer)
return m_pRenderer->get_PenDashStyle(val);
return S_OK;
}
inline HRESULT put_PenDashStyle(const BYTE& val)
{
if (m_pRenderer)
return m_pRenderer->put_PenDashStyle(val);
return S_OK;
}
inline HRESULT get_PenLineStartCap(BYTE* val)
{
if (m_pRenderer)
return m_pRenderer->get_PenLineStartCap(val);
return S_OK;
}
inline HRESULT put_PenLineStartCap(const BYTE& val)
{
if (m_pRenderer)
return m_pRenderer->put_PenLineStartCap(val);
return S_OK;
}
inline HRESULT get_PenLineEndCap(BYTE* val)
{
if (m_pRenderer)
return m_pRenderer->get_PenLineEndCap(val);
return S_OK;
}
inline HRESULT put_PenLineEndCap(const BYTE& val)
{
if (m_pRenderer)
return m_pRenderer->put_PenLineEndCap(val);
return S_OK;
}
inline HRESULT get_PenLineJoin(BYTE* val)
{
if (m_pRenderer)
return m_pRenderer->get_PenLineJoin(val);
return S_OK;
}
inline HRESULT put_PenLineJoin(const BYTE& val)
{
if (m_pRenderer)
return m_pRenderer->put_PenLineJoin(val);
return S_OK;
}
inline HRESULT get_PenDashOffset(double* dOffset)
{
if (m_pRenderer)
return m_pRenderer->get_PenDashOffset(dOffset);
return S_OK;
}
inline HRESULT put_PenDashOffset(const double& dOffset)
{
if (m_pRenderer)
return m_pRenderer->put_PenDashOffset(dOffset);
return S_OK;
}
inline HRESULT get_PenAlign(LONG* lAlign)
{
if (m_pRenderer)
return m_pRenderer->get_PenAlign(lAlign);
return S_OK;
}
inline HRESULT put_PenAlign(const LONG& lAlign)
{
if (m_pRenderer)
return m_pRenderer->put_PenAlign(lAlign);
return S_OK;
}
inline HRESULT get_PenMiterLimit(double* dOffset)
{
if (m_pRenderer)
return m_pRenderer->get_PenMiterLimit(dOffset);
return S_OK;
}
inline HRESULT put_PenMiterLimit(const double& dOffset)
{
if (m_pRenderer)
return m_pRenderer->put_PenMiterLimit(dOffset);
return S_OK;
}
inline HRESULT PenDashPattern(double* pPattern, LONG lCount)
{
if (m_pRenderer)
return m_pRenderer->PenDashPattern(pPattern, lCount);
return S_OK;
}
// brush ------------------------------------------------------------------------------------
inline HRESULT get_BrushType(LONG* lType)
{
if (m_pRenderer)
return m_pRenderer->get_BrushType(lType);
return S_OK;
}
inline HRESULT put_BrushType(const LONG& lType)
{
if (m_pRenderer)
return m_pRenderer->put_BrushType(lType);
return S_OK;
}
inline HRESULT get_BrushColor1(LONG* lColor)
{
if (m_pRenderer)
return m_pRenderer->get_BrushColor1(lColor);
return S_OK;
}
inline HRESULT put_BrushColor1(const LONG& lColor)
{
if (m_pRenderer)
return m_pRenderer->put_BrushColor1(lColor);
return S_OK;
}
inline HRESULT get_BrushAlpha1(LONG* lAlpha)
{
if (m_pRenderer)
return m_pRenderer->get_BrushAlpha1(lAlpha);
return S_OK;
}
inline HRESULT put_BrushAlpha1(const LONG& lAlpha)
{
if (m_pRenderer)
return m_pRenderer->put_BrushAlpha1(lAlpha);
return S_OK;
}
inline HRESULT get_BrushColor2(LONG* lColor)
{
if (m_pRenderer)
return m_pRenderer->get_BrushColor2(lColor);
return S_OK;
}
inline HRESULT put_BrushColor2(const LONG& lColor)
{
if (m_pRenderer)
return m_pRenderer->put_BrushColor2(lColor);
return S_OK;
}
inline HRESULT get_BrushAlpha2(LONG* lAlpha)
{
if (m_pRenderer)
return m_pRenderer->get_BrushAlpha2(lAlpha);
return S_OK;
}
inline HRESULT put_BrushAlpha2(const LONG& lAlpha)
{
if (m_pRenderer)
return m_pRenderer->put_BrushAlpha2(lAlpha);
return S_OK;
}
inline HRESULT get_BrushTexturePath(std::wstring* bsPath)
{
if (m_pRenderer)
return m_pRenderer->get_BrushTexturePath(bsPath);
return S_OK;
}
inline HRESULT put_BrushTexturePath(const std::wstring& bsPath)
{
if (m_pRenderer)
return m_pRenderer->put_BrushTexturePath(bsPath);
return S_OK;
}
inline HRESULT get_BrushTextureMode(LONG* lMode)
{
if (m_pRenderer)
return m_pRenderer->get_BrushTextureMode(lMode);
return S_OK;
}
inline HRESULT put_BrushTextureMode(const LONG& lMode)
{
if (m_pRenderer)
return m_pRenderer->put_BrushTextureMode(lMode);
return S_OK;
}
inline HRESULT get_BrushTextureAlpha(LONG* lTxAlpha)
{
if (m_pRenderer)
return m_pRenderer->get_BrushTextureAlpha(lTxAlpha);
return S_OK;
}
inline HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha)
{
if (m_pRenderer)
return m_pRenderer->put_BrushTextureAlpha(lTxAlpha);
return S_OK;
}
inline HRESULT get_BrushLinearAngle(double* dAngle)
{
if (m_pRenderer)
return m_pRenderer->get_BrushLinearAngle(dAngle);
return S_OK;
}
inline HRESULT put_BrushLinearAngle(const double& dAngle)
{
if (m_pRenderer)
return m_pRenderer->put_BrushLinearAngle(dAngle);
return S_OK;
}
inline HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
{
if (m_pRenderer)
return m_pRenderer->BrushRect(val, left, top, width, height);
return S_OK;
}
inline HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height)
{
if (m_pRenderer)
return m_pRenderer->BrushBounds(left, top, width, height);
return S_OK;
}
inline HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount)
{
if (m_pRenderer)
return m_pRenderer->put_BrushGradientColors(lColors, pPositions, nCount);
return S_OK;
}
// font -------------------------------------------------------------------------------------
inline HRESULT get_FontName(std::wstring* bsName)
{
if (m_pRenderer)
return m_pRenderer->get_FontName(bsName);
return S_OK;
}
inline HRESULT put_FontName(const std::wstring& bsName)
{
if (m_pRenderer)
return m_pRenderer->put_FontName(bsName);
return S_OK;
}
inline HRESULT get_FontPath(std::wstring* bsName)
{
if (m_pRenderer)
return m_pRenderer->get_FontPath(bsName);
return S_OK;
}
inline HRESULT put_FontPath(const std::wstring& bsName)
{
if (m_pRenderer)
return m_pRenderer->put_FontPath(bsName);
return S_OK;
}
inline HRESULT get_FontSize(double* dSize)
{
if (m_pRenderer)
return m_pRenderer->get_FontSize(dSize);
return S_OK;
}
inline HRESULT put_FontSize(const double& dSize)
{
if (m_pRenderer)
return m_pRenderer->put_FontSize(dSize);
return S_OK;
}
inline HRESULT get_FontStyle(LONG* lStyle)
{
if (m_pRenderer)
return m_pRenderer->get_FontStyle(lStyle);
return S_OK;
}
inline HRESULT put_FontStyle(const LONG& lStyle)
{
if (m_pRenderer)
return m_pRenderer->put_FontStyle(lStyle);
return S_OK;
}
inline HRESULT get_FontStringGID(INT* bGID)
{
if (m_pRenderer)
return m_pRenderer->get_FontStringGID(bGID);
return S_OK;
}
inline HRESULT put_FontStringGID(const INT& bGID)
{
if (m_pRenderer)
return m_pRenderer->put_FontStringGID(bGID);
return S_OK;
}
inline HRESULT get_FontCharSpace(double* dSpace)
{
if (m_pRenderer)
return m_pRenderer->get_FontCharSpace(dSpace);
return S_OK;
}
inline HRESULT put_FontCharSpace(const double& dSpace)
{
if (m_pRenderer)
return m_pRenderer->put_FontCharSpace(dSpace);
return S_OK;
}
inline HRESULT get_FontFaceIndex(int* lFaceIndex)
{
if (m_pRenderer)
return m_pRenderer->get_FontFaceIndex(lFaceIndex);
return S_OK;
}
inline HRESULT put_FontFaceIndex(const int& lFaceIndex)
{
if (m_pRenderer)
return m_pRenderer->put_FontFaceIndex(lFaceIndex);
return S_OK;
}
//-------- Функции для вывода текста --------------------------------------------------------
inline HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->CommandDrawTextCHAR(c, x, y, w, h);
return S_OK;
}
inline HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->CommandDrawText(bsText, x, y, w, h);
return S_OK;
}
inline HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->CommandDrawTextExCHAR(c, gid, x, y, w, h);
return S_OK;
}
inline 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)
{
if (m_pRenderer)
return m_pRenderer->CommandDrawTextEx(bsUnicodeText, pGids, nGidsCount, x, y, w, h);
return S_OK;
}
//-------- Маркеры для команд ---------------------------------------------------------------
inline HRESULT BeginCommand(const DWORD& lType)
{
if (m_pRenderer)
return m_pRenderer->BeginCommand(lType);
return S_OK;
}
inline HRESULT EndCommand(const DWORD& lType)
{
if (m_pRenderer)
return m_pRenderer->EndCommand(lType);
return S_OK;
}
//-------- Функции для работы с Graphics Path -----------------------------------------------
inline HRESULT PathCommandMoveTo(const double& x, const double& y)
{
if (m_pRenderer)
return m_pRenderer->PathCommandMoveTo(x, y);
return S_OK;
}
inline HRESULT PathCommandLineTo(const double& x, const double& y)
{
if (m_pRenderer)
return m_pRenderer->PathCommandLineTo(x, y);
return S_OK;
}
inline HRESULT PathCommandLinesTo(double* points, const int& count)
{
if (m_pRenderer)
return m_pRenderer->PathCommandLinesTo(points, count);
return S_OK;
}
inline HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{
if (m_pRenderer)
return m_pRenderer->PathCommandCurveTo(x1, y1, x2, y2, x3, y3);
return S_OK;
}
inline HRESULT PathCommandCurvesTo(double* points, const int& count)
{
if (m_pRenderer)
return m_pRenderer->PathCommandCurvesTo(points, count);
return S_OK;
}
inline HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle)
{
if (m_pRenderer)
return m_pRenderer->PathCommandArcTo(x, y, w, h, startAngle, sweepAngle);
return S_OK;
}
inline HRESULT PathCommandClose()
{
if (m_pRenderer)
return m_pRenderer->PathCommandClose();
return S_OK;
}
inline HRESULT PathCommandEnd()
{
if (m_pRenderer)
return m_pRenderer->PathCommandEnd();
return S_OK;
}
inline HRESULT DrawPath(const LONG& nType)
{
if (m_pRenderer)
return m_pRenderer->DrawPath(nType);
return S_OK;
}
inline HRESULT PathCommandStart()
{
if (m_pRenderer)
return m_pRenderer->PathCommandStart();
return S_OK;
}
inline HRESULT PathCommandGetCurrentPoint(double* x, double* y)
{
if (m_pRenderer)
return m_pRenderer->PathCommandGetCurrentPoint(x, y);
return S_OK;
}
inline HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->PathCommandTextCHAR(c, x, y, w, h);
return S_OK;
}
inline HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->PathCommandText(bsText, x, y, w, h);
return S_OK;
}
inline HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->PathCommandTextExCHAR(c, gid, x, y, w, h);
return S_OK;
}
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)
{
if (m_pRenderer)
return m_pRenderer->PathCommandTextEx(bsUnicodeText, pGids, nGidsCount, x, y, w, h);
return S_OK;
}
//-------- Функции для вывода изображений ---------------------------------------------------
inline HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h)
{
if (m_pRenderer)
return m_pRenderer->DrawImage(pImage, x, y, w, h);
return S_OK;
}
inline HRESULT DrawImageFromFile(const std::wstring& sPath, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255)
{
if (m_pRenderer)
return m_pRenderer->DrawImageFromFile(sPath, x, y, w, h, lAlpha);
return S_OK;
}
// transform --------------------------------------------------------------------------------
inline HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6)
{
if (m_pRenderer)
return m_pRenderer->SetTransform(m1, m2, m3, m4, m5, m6);
return S_OK;
}
inline HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF)
{
if (m_pRenderer)
return m_pRenderer->GetTransform(pdA, pdB, pdC, pdD, pdE, pdF);
return S_OK;
}
inline HRESULT ResetTransform()
{
if (m_pRenderer)
return m_pRenderer->ResetTransform();
return S_OK;
}
// -----------------------------------------------------------------------------------------
inline HRESULT get_ClipMode(LONG* plMode)
{
if (m_pRenderer)
return m_pRenderer->get_ClipMode(plMode);
return S_OK;
}
inline HRESULT put_ClipMode(const LONG& lMode)
{
if (m_pRenderer)
return m_pRenderer->put_ClipMode(lMode);
return S_OK;
}
};
class CPageMeta
{
public:
double m_dWidth;
double m_dHeight;
LONG m_lStart;
LONG m_lEnd;
public:
CPageMeta()
{
m_dWidth = 0;
m_dHeight = 0;
m_lStart = 0;
m_lEnd = 0;
}
CPageMeta(const CPageMeta& oSrc)
{
*this = oSrc;
}
CPageMeta& operator=(const CPageMeta& oSrc)
{
m_dWidth = oSrc.m_dWidth;
m_dHeight = oSrc.m_dHeight;
m_lStart = oSrc.m_lStart;
m_lEnd = oSrc.m_lEnd;
return *this;
}
};
class CFontEmbedded
{
public:
std::map<int, BYTE> m_mapChars;
std::wstring m_strFontName;
LONG m_lFontStyle;
int m_lFontPathLen;
std::wstring m_strFontPath;
DWORD m_dwCRC32;
public:
CFontEmbedded() : m_mapChars()
{
m_strFontName = L"";
m_strFontPath = L"";
m_lFontPathLen = 0;
m_lFontStyle = 0;
m_dwCRC32 = 0;
}
CFontEmbedded(const CFontEmbedded& oSrc)
{
*this = oSrc;
}
CFontEmbedded& operator=(const CFontEmbedded& oSrc)
{
m_strFontPath = oSrc.m_strFontPath;
m_strFontName = oSrc.m_strFontName;
m_lFontStyle = oSrc.m_lFontStyle;
m_dwCRC32 = oSrc.m_dwCRC32;
m_lFontPathLen = oSrc.m_lFontPathLen;
for (std::map<int, BYTE>::const_iterator i = oSrc.m_mapChars.begin(); i != oSrc.m_mapChars.end(); i++)
{
m_mapChars.insert(std::pair<int, BYTE>(i->first, i->second));
}
return *this;
}
public:
void AddString(const int* sText, const int& len)
{
if (NULL != sText)
{
for (int i = 0; i < len; ++i)
{
if (m_mapChars.end() == m_mapChars.find(sText[i]))
m_mapChars.insert(std::pair<int, BYTE>(sText[i], 1));
}
}
}
void GenerateArray(int*& pData, int& nCount)
{
nCount = m_mapChars.size();
if (0 == nCount)
return;
pData = new int[nCount];
int* pDataCur = pData;
for (std::map<int, BYTE>::const_iterator i = m_mapChars.begin(); i != m_mapChars.end(); i++)
{
*pDataCur++ = i->first;
}
}
};
class CFontDstGenerator
{
public:
CFontEmbedded* m_pFonts;
LONG m_lCurrentIndex;
LONG m_lCountFonts;
LONG m_lSize;
std::map<std::wstring, DWORD> m_mapFontPathCRC;
std::map<DWORD, LONG> m_mapFontCRCIndex;
CCalculatorCRC32 m_oCalc;
std::wstring m_strCurrentFontPath;
int m_lCurrentFontStyle;
int m_lCurrentFontPathLen;
std::map<std::wstring, int> m_mapFontPathToIndex;
public:
CFontDstGenerator()
{
m_lSize = 50;
m_pFonts = NULL;
m_lCurrentIndex = -1;
m_lCountFonts = 0;
m_strCurrentFontPath = L"";
m_lCurrentFontPathLen = 0;
m_lCurrentFontStyle = -1;
Grow();
}
~CFontDstGenerator()
{
RELEASEARRAYOBJECTS(m_pFonts);
}
public:
LONG AddFont(NSStructures::CFont* pFont, CFontManagerBase* pBase, const int* symbols, const int& count)
{
// TODO:
// нужно учитывать FaceIndex. В пдфах не бывает никогда таких файлов (но могут)
// поэтому решил не менять, чтобы не нарушить. Как будет время - сделать зависимость кэша
// не только от пути, но и от индекса
bool bIsDumpFontEmptyPath = false;
int nLen = (int)pFont->Path.length();
if (nLen == 0)
{
pFont->Path = pBase->GetFontPath(pFont);
nLen = pFont->Path.length();
bIsDumpFontEmptyPath = true;
}
LONG lNewStyle = pFont->GetStyle2();
bool bIsFontChanged = true;
if (nLen == m_lCurrentFontPathLen && (m_lCurrentFontStyle == lNewStyle))
{
if (m_strCurrentFontPath == pFont->Path)
bIsFontChanged = false;
}
if (!bIsFontChanged)
{
m_pFonts[m_lCurrentIndex].AddString(symbols, count);
if (bIsDumpFontEmptyPath)
pFont->Path = L"";
return m_lCurrentIndex;
}
std::map<std::wstring, int>::const_iterator pPairIndex = m_mapFontPathToIndex.find(pFont->Path);
if (m_mapFontPathToIndex.end() != pPairIndex)
{
m_lCurrentIndex = pPairIndex->second;
NSHtmlRenderer::CFontEmbedded* pEmb = &m_pFonts[m_lCurrentIndex];
m_strCurrentFontPath = pFont->Path;
m_lCurrentFontPathLen = nLen;
m_lCurrentFontStyle = lNewStyle;
pEmb->AddString(symbols, count);
if (bIsDumpFontEmptyPath)
pFont->Path = L"";
return m_lCurrentIndex;
}
// такой путь еще не приходил.
// первым делом проверим, не совпадает ли он с каким-то (по чексумме)
NSFile::CFileBinary oFile;
oFile.OpenFile(pFont->Path);
DWORD lFontFileSize = (DWORD)oFile.GetFileSize();
BYTE* pFontPathData = new BYTE[lFontFileSize];
DWORD dwRead = 0;
oFile.ReadFile(pFontPathData, lFontFileSize, dwRead);
DWORD dwCRC32 = m_oCalc.Calc(pFontPathData, (int)lFontFileSize);
oFile.CloseFile();
RELEASEARRAYOBJECTS(pFontPathData);
std::map<DWORD, LONG>::const_iterator pPair2 = m_mapFontCRCIndex.find(dwCRC32);
if (m_mapFontCRCIndex.end() == pPair2)
{
// шрифт реально новый
m_mapFontCRCIndex.insert(std::pair<DWORD, LONG>(dwCRC32, m_lCountFonts));
m_mapFontPathToIndex.insert(std::pair<std::wstring, int>(pFont->Path, m_lCountFonts));
}
else
{
m_lCurrentIndex = pPair2->second;
m_mapFontPathToIndex.insert(std::pair<std::wstring, int>(pFont->Path, m_lCurrentIndex));
m_strCurrentFontPath = pFont->Path;
m_lCurrentFontPathLen = nLen;
m_lCurrentFontStyle = lNewStyle;
m_pFonts[m_lCurrentIndex].AddString(symbols, count);
if (bIsDumpFontEmptyPath)
pFont->Path = L"";
return m_lCurrentIndex;
}
if (m_lCountFonts == m_lSize)
{
// нужно перевыделить память
Grow();
}
m_lCurrentIndex = m_lCountFonts;
++m_lCountFonts;
NSHtmlRenderer::CFontEmbedded* pCurEmb = &m_pFonts[m_lCurrentIndex];
pCurEmb->m_strFontName = pFont->Name;
pCurEmb->m_strFontPath = pFont->Path;
pCurEmb->m_lFontStyle = lNewStyle;
pCurEmb->m_lFontPathLen = nLen;
pCurEmb->AddString(symbols, count);
// теперь нужно найти к нему путь...
if (0 == nLen)
{
pCurEmb->m_strFontPath = pBase->GetFontPath(pFont);
pCurEmb->m_lFontPathLen = pCurEmb->m_strFontPath.length();
}
if (bIsDumpFontEmptyPath)
pFont->Path = L"";
m_strCurrentFontPath = pCurEmb->m_strFontPath;
m_lCurrentFontPathLen = pCurEmb->m_lFontPathLen;
m_lCurrentFontStyle = pCurEmb->m_lFontStyle;
return m_lCurrentIndex;
}
public:
void WriteFonts(::CFontManager* pFontManager, const std::wstring& strFolderDst, bool bIsGid = false)
{
std::wstring sDstF = strFolderDst;
NSDirectory::CreateDirectory(sDstF);
std::wstring strAllTypes = L"";
std::wstring strTempFont = sDstF + L"/font.tmp";
CFontConverter oFontConverter;
LONG lFontConverterFlag = 16;
if (bIsGid)
lFontConverterFlag |= 0x0080;
for (LONG lIndex = 0; lIndex < m_lCountFonts; ++lIndex)
{
CFontEmbedded& oCur = m_pFonts[lIndex];
pFontManager->LoadFontFromFile(oCur.m_strFontPath, 0, 12, 72, 72);
std::wstring sName = L"";
int nNameLen = (int)pFontManager->m_sName.length();
const wchar_t* pNameStr = pFontManager->m_sName.c_str();
for (int i = 0; i < nNameLen; ++i)
{
if ((pNameStr[i] >= 'a' && pNameStr[i] <= 'z') ||
(pNameStr[i] >= 'A' && pNameStr[i] <= 'Z') ||
(pNameStr[i] >= '0' && pNameStr[i] <= '9'))
{
sName.push_back(pNameStr[i]);
}
else
{
sName.push_back((wchar_t)'_');
}
}
strAllTypes += (L"embedded" + std::to_wstring(lIndex));
strAllTypes += L": ";
strAllTypes += pFontManager->GetFontType();
strAllTypes += L", ";
strAllTypes += sName;
strAllTypes += L"\n";
int* symbols = NULL;
int symbolsCount = 0;
oCur.GenerateArray(symbols, symbolsCount);
oFontConverter.ToOTF(oCur.m_strFontPath, strTempFont, (unsigned int*)symbols, symbolsCount, sName, lFontConverterFlag); // TRUETYPE only
RELEASEARRAYOBJECTS(symbols);
// dump font
NSFile::CFileBinary oFileFontFile;
oFileFontFile.OpenFile(strTempFont);
int nInputLen = (int)oFileFontFile.GetFileSize();
BYTE* pData = new BYTE[nInputLen];
DWORD dwReadSize = 0;
oFileFontFile.ReadFile(pData, (DWORD)nInputLen, dwReadSize);
oFileFontFile.CloseFile();
char* pOutput = NULL;
int nOutputLen = 0;
NSFile::CBase64Converter::Encode(pData, nInputLen, pOutput, nOutputLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
NSFile::CFileBinary oFileFontFileJS;
oFileFontFileJS.CreateFileW(sDstF + L"/embedded" + std::to_wstring(lIndex) + L".js");
std::string sHeader = "window[\"embedded" + std::to_string(lIndex) + "\"] = \"" + std::to_string(nInputLen) + ";";
oFileFontFileJS.WriteFile((const BYTE*)sHeader.c_str(), sHeader.length());
oFileFontFileJS.WriteFile((const BYTE*)pOutput, nOutputLen);
std::string sFooter = "\";";
oFileFontFileJS.WriteFile((const BYTE*)sFooter.c_str(), sFooter.length());
RELEASEARRAYOBJECTS(pOutput);
RELEASEARRAYOBJECTS(pData);
NSFile::CFileBinary::Remove(strTempFont);
}
NSFile::CFileBinary oFileFontFileJS_type;
oFileFontFileJS_type.CreateFileW(sDstF + L"/types.txt");
oFileFontFileJS_type.WriteStringUTF8(strAllTypes);
oFileFontFileJS_type.CloseFile();
}
protected:
void Grow()
{
if (NULL == m_pFonts)
{
m_pFonts = new CFontEmbedded[m_lSize];
return;
}
m_lSize *= 2;
CFontEmbedded* pNewBuffer = new CFontEmbedded[m_lSize];
for (LONG i = 0; i < m_lCountFonts; ++i)
{
pNewBuffer[i] = m_pFonts[i];
}
RELEASEARRAYOBJECTS(m_pFonts);
m_pFonts = pNewBuffer;
}
};
class CWriter
{
public:
CMetafile m_oPage;
CSVGWriter2 m_oSVGWriter;
std::vector<CPageMeta> m_arrPages;
bool m_bIsBigPicture;
int m_lTilingCounter;
public:
NSStructures::CPen* m_pPen;
NSStructures::CBrush* m_pBrush;
NSStructures::CFont* m_pFont;
NSStructures::CPen m_oLastPen;
NSStructures::CBrush m_oLastBrush;
NSStructures::CFont m_oLastFont;
int m_lCurrentFont;
double m_dCurrentFontSize;
CFontDstGenerator m_oDstFontGenerator;
NSHtmlRenderer::CFontManager m_oFontManager;
CHText m_oSmartText;
double m_dDpiX;
double m_dDpiY;
bool m_bPathClosed;
std::map<std::wstring, CImageInfo> m_mapImagesFile;
std::map<DWORD, CImageInfo> m_mapImageData;
CCalculatorCRC32 m_oCRC;
double m_dWidthDocMM;
double m_dHeightDocMM;
double m_dHeightPageMM;
Aggplus::CGraphicsPathSimpleConverter* m_pSimpleConverter;
NSFile::CFileBinary m_oFileWriter;
bool m_bIsGids;
CApplicationFonts* m_pApplicationFonts;
public:
double m_dWidth;
double m_dHeight;
bool m_bIsImageFromVectors;
private:
LONG m_lNextIDShape;
LONG m_lNextIDImage;
LONG m_lCurrentPage;
LONG m_lCurrentFunctionPage;
LONG m_lPagesCount;
LONG m_lMaxSizeImage;
public:
std::wstring m_strDstDirectory;
std::wstring m_strDstMedia;
std::wstring m_strDstDirectoryFiles;
std::wstring m_strFileName;
Aggplus::CMatrix* m_pTransform;
Aggplus::CMatrix m_oLastTransform;
int m_lCurrentDumpSize;
int m_lSrcFileType;
bool m_bIsClipping;
bool m_bIsSimpleGraphics;
public:
CWriter()
{
m_dDpiX = 96.0;
m_dDpiY = 96.0;
m_dWidth = 0;
m_dHeight = 0;
m_lNextIDImage = 0;
m_lNextIDShape = 0;
m_lCurrentPage = -1;
m_bPathClosed = true;
m_pSimpleConverter = NULL;
m_lMaxSizeImage = 800;
m_dWidthDocMM = 0;
m_dHeightDocMM = 0;
m_dHeightPageMM = 0;
m_lPagesCount = 0;
m_bIsImageFromVectors = false;
m_lSrcFileType = 0;
m_bIsClipping = false;
m_bIsSimpleGraphics = false;
m_lTilingCounter = 0;
}
void SetApplicationFonts(CApplicationFonts* pFonts)
{
m_pApplicationFonts = pFonts;
}
void SetSimpleConverter(Aggplus::CGraphicsPathSimpleConverter* pSimpleConverter, Aggplus::CMatrix* pMatrix)
{
m_pSimpleConverter = pSimpleConverter;
m_pTransform = pMatrix;
m_oSVGWriter.m_pTransform = m_pTransform;
m_oSVGWriter.m_pPen = m_pPen;
m_oSVGWriter.m_pBrush = m_pBrush;
m_oSVGWriter.m_pLastPen = &m_oLastPen;
m_oSVGWriter.m_pLastBrush = &m_oLastBrush;
}
void WriteText(const int* pUnicodes, const int* pGids, const int& nCount, const double& x, const double& y,
const double& width, const double& height, const bool& bIsChangedFontParamBetweenDrawText)
{
if (m_lSrcFileType == AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU)
{
// не нужно ничего писать из djvu
return;
}
CheckVectorGraphics();
CheckTectClipRect();
bool bIsDumpFont = false;
if (m_lCurrentFont == -1 || bIsChangedFontParamBetweenDrawText)
{
const int* pSymbols = (NULL == pGids) ? pUnicodes : pGids;
LONG lCurrentFontIndex = m_oDstFontGenerator.AddFont(m_pFont, &m_oFontManager, pSymbols, nCount);
if ((lCurrentFontIndex != m_lCurrentFont) || (m_pFont->Size != m_dCurrentFontSize))
{
m_lCurrentFont = lCurrentFontIndex;
m_dCurrentFontSize = m_pFont->Size;
bIsDumpFont = true;
}
}
else
{
const int* pSymbols = (NULL == pGids) ? pUnicodes : pGids;
m_oDstFontGenerator.m_pFonts[m_lCurrentFont].AddString(pSymbols, nCount);
}
if (NULL != pGids)
m_bIsGids = true;
m_oSmartText.CommandText(pUnicodes, pGids, nCount, x, y, width, height, bIsDumpFont, this);
return;
}
inline void CheckTectClipRect()
{
// смотрим, нужно ли обновить рект для клиппирования текста
if (m_oSVGWriter.m_bIsTextClipWriteCleared)
{
if (!m_oSVGWriter.m_oTextClipBounds.IsCleared)
{
m_oSmartText.DumpLine();
// записать клип
m_oPage.WriteCommandType(CMetafile::ctCommandTextClipRect);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.x);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.y);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.r);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.b);
m_oSVGWriter.m_bIsTextClipWriteCleared = false;
}
}
else
{
if (m_oSVGWriter.m_oTextClipBounds.IsCleared)
{
m_oSmartText.DumpLine();
// записать команду сброса клипа текстректа
m_oPage.WriteCommandType(CMetafile::ctCommandTextClipRectReset);
m_oSVGWriter.m_bIsTextClipWriteCleared = true;
return;
}
else if (m_oSVGWriter.m_bIsIntersectNewClipRect)
{
m_oSmartText.DumpLine();
// записать клип
m_oPage.WriteCommandType(CMetafile::ctCommandTextClipRect);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.x);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.y);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.r);
m_oPage.WriteDouble(m_oSVGWriter.m_oTextClipBounds.b);
m_oSVGWriter.m_bIsIntersectNewClipRect = false;
}
}
}
inline void WriteBeginPath()
{
}
inline void WriteEndPath()
{
m_oSVGWriter.WritePathEnd();
}
inline void WritePathStart()
{
}
inline void WritePathClose()
{
m_oSVGWriter.WritePathClose();
}
inline void WritePathMoveTo(const double& x, const double& y)
{
m_oSVGWriter.WritePathMoveTo(x, y);
}
inline void WritePathLineTo(const double& x, const double& y)
{
m_oSVGWriter.WritePathLineTo(x, y);
}
inline void WritePathCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3)
{
m_oSVGWriter.WritePathCurveTo(x1, y1, x2, y2, x3, y3);
}
inline void WriteDrawPath(LONG lType)
{
/*
if (lType > 0xFF)
{
if (!m_oLastBrush.IsEqual(m_pBrush))
{
m_oLastBrush = *m_pBrush;
SetFillColor(true);
}
}
if (lType & 0x01)
{
if (!m_oLastPen.IsEqual(m_pPen))
{
m_oLastPen = *m_pPen;
SetStrokeColor(true);
SetLineWidth(true);
}
}
m_oVectors.WriteCommandType(CMetafile::ctDrawPath);
m_oVectors.WriteLONG(lType);
*/
CImageInfo oInfo;
if ((lType > 0xFF) && (c_BrushTypeTexture == m_pBrush->Type))
{
oInfo = GenerateImageID(m_pBrush->TexturePath);
if (TRUE)
{
// пока делаем так
double x = 0;
double y = 0;
double w = 0;
double h = 0;
m_pSimpleConverter->PathCommandGetBounds(x, y, w, h);
CheckVectorGraphics();
/*
bool bIsClip = (m_oSVGWriter.m_oClipMetafile.GetPosition() > 0) ? true : false;
if (bIsClip)
m_oPage.Write(m_oSVGWriter.m_oClipMetafile);
*/
LONG _oldPos = m_oSVGWriter.WriteTempClip();
m_oPage.Write(m_oSVGWriter.m_oClipMetafile);
WriteImage2(oInfo, x, y, w, h);
m_oSVGWriter.m_oClipMetafile.Seek(_oldPos);
/*
if (bIsClip)
m_oPage.WriteLONG(CMetafile::ctBeginCommand, c_nResetClipType);
*/
m_oPage.WriteLONG(CMetafile::ctBeginCommand, c_nResetClipType);
lType &= 0xFF;
}
}
m_oSVGWriter.WriteDrawPath(lType, m_pSimpleConverter, oInfo);
}
inline void WritePathClip()
{
m_oSVGWriter.WritePathClip();
}
inline void WritePathClipEnd()
{
m_oSVGWriter.WritePathClipEnd();
}
inline void WritePathResetClip()
{
m_oSVGWriter.WritePathResetClip();
}
void NewPage(const double& dWidthMM, const double& dHeightMM)
{
++m_lPagesCount;
CPageMeta oInfo;
oInfo.m_dWidth = dWidthMM;
oInfo.m_dHeight = dHeightMM;
oInfo.m_lStart = m_lCurrentDumpSize;
oInfo.m_lEnd = 0;
m_dWidth = dWidthMM;
m_dHeight = dHeightMM;
m_arrPages.push_back(oInfo);
m_oLastBrush.Color1 = -1;
m_oLastPen.Color = -1;
m_oLastFont.Name = L"";
m_lCurrentFont = -1;
m_dCurrentFontSize = 0.0;
m_oLastTransform.Reset();
m_pTransform->Reset();
m_bIsBigPicture = false;
m_oSVGWriter.NewDocument(m_dWidth, m_dHeight, m_lPagesCount - 1);
}
void EndPage()
{
m_oSmartText.ClosePage();
CheckVectorGraphics();
m_arrPages[m_arrPages.size() - 1].m_lEnd = m_lCurrentDumpSize + m_oPage.GetPosition();
m_lCurrentDumpSize += m_oPage.GetPosition();
m_oFileWriter.WriteFile(m_oPage.GetData(), m_oPage.GetPosition());
m_oPage.Clear();
}
inline void CheckVectorGraphics()
{
/*
if (0 < m_oVectors.GetPosition() && m_bIsSimpleGraphics && !m_oSVGWriter.m_bIsClipping)
{
m_oPage.Write(m_oVectors);
}
else if (m_oSVGWriter.m_oDocument.GetCurSize() > 0)
{
WriteImageID_SVG();
}
m_oVectors.ClearNoAttack();
*/
if (m_oSVGWriter.m_lEmtyDocChecker < (ULONG)m_oSVGWriter.m_oDocument.GetCurSize())
WriteImageID_SVG();
}
inline void WritePattern(CBgraFrame* pPattern, CTileInfo& oTile)
{
CheckVectorGraphics();
m_oSmartText.DumpLine();
SetTransformToDocument(true);
NSHtmlRenderer::CImageInfo oInfo = GenerateImageID(pPattern);
bool bIsClip = (m_oSVGWriter.m_oClipMetafile.GetPosition() > 0) ? true : false;
if (bIsClip)
m_oPage.Write(m_oSVGWriter.m_oClipMetafile);
WriteImagePattrern(oInfo, oTile);
if (bIsClip)
m_oPage.WriteLONG(CMetafile::ctBeginCommand, c_nResetClipType);
}
inline void WriteImage(IGrObject* pImage, double x, double y, double width, double height)
{
CheckVectorGraphics();
m_oSmartText.DumpLine();
SetTransformToDocument(true);
bool bIsClip = (m_oSVGWriter.m_oClipMetafile.GetPosition() > 0) ? true : false;
if (bIsClip)
m_oPage.Write(m_oSVGWriter.m_oClipMetafile);
NSHtmlRenderer::CImageInfo oInfo = GenerateImageID(pImage);
//m_oSVGWriter.WriteImage(oInfo, x, y, width, height);
WriteImage2(oInfo, x, y, width, height);
if (bIsClip)
m_oPage.WriteLONG(CMetafile::ctBeginCommand, c_nResetClipType);
}
inline void WriteImage(const std::wstring& sPath, double x, double y, double width, double height)
{
if (m_lTilingCounter > 0)
{
NSHtmlRenderer::CImageInfo oInfo = GenerateImageID(sPath);
m_oSVGWriter.WriteImage(oInfo, x, y, width, height);
return;
}
CheckVectorGraphics();
m_oSmartText.DumpLine();
SetTransformToDocument(true);
bool bIsClip = (m_oSVGWriter.m_oClipMetafile.GetPosition() > 0) ? true : false;
if (bIsClip)
m_oPage.Write(m_oSVGWriter.m_oClipMetafile);
NSHtmlRenderer::CImageInfo oInfo = GenerateImageID(sPath);
//m_oSVGWriter.WriteImage(oInfo, x, y, width, height);
WriteImage2(oInfo, x, y, width, height);
if (bIsClip)
m_oPage.WriteLONG(CMetafile::ctBeginCommand, c_nResetClipType);
}
NSHtmlRenderer::CImageInfo GenerateImageID(IGrObject* pGrObject)
{
Aggplus::CImage* pImage = (Aggplus::CImage*)pGrObject;
CBgraFrame* pFrame = new CBgraFrame();
pFrame->put_Width((int)pImage->GetWidth());
pFrame->put_Height((int)pImage->GetHeight());
pFrame->put_Stride((int)pImage->GetStride());
pFrame->put_Data(pImage->GetData());
NSHtmlRenderer::CImageInfo _info = GenerateImageID(pFrame, true);
RELEASEOBJECT(pFrame);
return _info;
}
NSHtmlRenderer::CImageInfo GenerateImageID(CBgraFrame* pFrame, bool bIsFromObject = false)
{
CImageInfo oInfo;
if (NULL == pFrame)
return oInfo;
int nLen = 4 * pFrame->get_Width() * pFrame->get_Height();
BYTE* pBuffer = pFrame->get_Data();
DWORD dwSum = (DWORD)m_oCRC.Calc(pBuffer, nLen);
std::map<DWORD, CImageInfo>::const_iterator pPair = m_mapImageData.find(dwSum);
if (m_mapImageData.end() == pPair)
{
// нужно добавить
++m_lNextIDImage;
oInfo.m_lID = m_lNextIDImage;
SaveImage(pFrame, oInfo, !bIsFromObject);
m_mapImageData.insert(std::pair<DWORD, CImageInfo>(dwSum, oInfo));
}
else
{
pFrame->put_Data(NULL);
oInfo = pPair->second;
}
return oInfo;
}
CImageInfo GenerateImageID(const std::wstring& strFileName)
{
CImageInfo oInfo;
std::map<std::wstring, CImageInfo>::const_iterator pPair = m_mapImagesFile.find(strFileName);
if (m_mapImagesFile.end() == pPair)
{
// нужно добавить
++m_lNextIDImage;
oInfo.m_lID = m_lNextIDImage;
CBgraFrame oFrame;
oFrame.OpenFile(strFileName);
SaveImage(&oFrame, oInfo, true);
m_mapImagesFile.insert(std::pair<std::wstring, CImageInfo>(strFileName, oInfo));
}
else
{
oInfo = pPair->second;
}
return oInfo;
}
ImageType GetImageType(CBgraFrame* pFrame)
{
BYTE* pBufferMem = pFrame->get_Data() + 3;
LONG lCountPix = pFrame->get_Width() * pFrame->get_Height();
for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4)
{
if (255 != *pBufferMem)
return itPNG;
}
return itJPG;
}
inline void SaveImage(CBgraFrame* pFrame, CImageInfo& oInfo, bool bIsDestroy)
{
oInfo.m_eType = GetImageType(pFrame);
int lWidth = pFrame->get_Width();
int lHeight = pFrame->get_Height();
bool bIsResized = false;
if (true || (lWidth <= m_lMaxSizeImage) && (lHeight <= m_lMaxSizeImage))
{
// не ресайзим
}
else
{
LONG lW = 0;
LONG lH = 0;
double dAspect = (double)lWidth / lHeight;
if (lWidth >= lHeight)
{
lW = m_lMaxSizeImage;
lH = (LONG)((double)lW / dAspect);
}
else
{
lH = m_lMaxSizeImage;
lW = (LONG)(dAspect * lH);
}
bIsResized = true;
pFrame->Resize(lW, lH, bIsDestroy);
}
std::wstring strSave = m_strDstMedia + L"/image" + std::to_wstring(oInfo.m_lID) + ((itJPG == oInfo.m_eType) ? L".jpg" : L".png");
pFrame->SaveFile(strSave, (itJPG == oInfo.m_eType) ? 3 : 4);
if (!bIsDestroy && !bIsResized)
pFrame->put_Data(NULL);
}
inline void WriteImage2(NSHtmlRenderer::CImageInfo& oID, const double& x, const double& y, const double& w, const double& h)
{
SetTransformToDocument(true);
if (fabs(m_pTransform->m_agg_mtx.shx) < 0.0000001 && fabs(m_pTransform->m_agg_mtx.shy) < 0.0000001 &&
m_pTransform->m_agg_mtx.sx >= 0 && m_pTransform->m_agg_mtx.sy >= 0)
{
double xx = x;
double yy = y;
double rr = x + w;
double bb = y + h;
m_pTransform->TransformPoint(xx, yy);
m_pTransform->TransformPoint(rr, bb);
if (oID.m_eType == itJPG)
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(0);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(xx);
m_oPage.WriteDouble(yy);
m_oPage.WriteDouble(rr - xx);
m_oPage.WriteDouble(bb - yy);
}
else
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(1);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(xx);
m_oPage.WriteDouble(yy);
m_oPage.WriteDouble(rr - xx);
m_oPage.WriteDouble(bb - yy);
}
}
else
{
if (oID.m_eType == itJPG)
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(10);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(x);
m_oPage.WriteDouble(y);
m_oPage.WriteDouble(w);
m_oPage.WriteDouble(h);
agg::trans_affine* t = &m_pTransform->m_agg_mtx;
m_oPage.WriteDouble(t->sx);
m_oPage.WriteDouble(t->shy);
m_oPage.WriteDouble(t->shx);
m_oPage.WriteDouble(t->sy);
m_oPage.WriteDouble(t->tx);
m_oPage.WriteDouble(t->ty);
}
else
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(11);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(x);
m_oPage.WriteDouble(y);
m_oPage.WriteDouble(w);
m_oPage.WriteDouble(h);
agg::trans_affine* t = &m_pTransform->m_agg_mtx;
m_oPage.WriteDouble(t->sx);
m_oPage.WriteDouble(t->shy);
m_oPage.WriteDouble(t->shx);
m_oPage.WriteDouble(t->sy);
m_oPage.WriteDouble(t->tx);
m_oPage.WriteDouble(t->ty);
}
}
}
inline void WriteImagePattrern(NSHtmlRenderer::CImageInfo& oID, CTileInfo& oTile)
{
SetTransformToDocument(true);
double dKoef = 25.4 / m_dDpiX;
double xx = oTile.bbox_x * dKoef;
double yy = oTile.bbox_y * dKoef;
double rr = oTile.bbox_r * dKoef;
double bb = oTile.bbox_b * dKoef;
if (oID.m_eType == itJPG)
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(0);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(xx);
m_oPage.WriteDouble(yy);
m_oPage.WriteDouble(rr - xx);
m_oPage.WriteDouble(bb - yy);
}
else
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(1);
m_oPage.WriteLONG(oID.m_lID);
m_oPage.WriteDouble(xx);
m_oPage.WriteDouble(yy);
m_oPage.WriteDouble(rr - xx);
m_oPage.WriteDouble(bb - yy);
}
}
void WriteImageID_SVG()
{
m_oSmartText.DumpLine();
SetTransformToDocument(true);
#if 0
m_oSVGWriter.DEBUG_DumpSVG(m_strDstMedia);
#endif
bool bIsBIG = false;
#ifdef USE_SIMPLE_GRAPHICS_NOSVG
if (m_oSVGWriter.m_bIsSimpleGraphics)
{
if (m_oSVGWriter.m_oVectors.GetPosition() > SVG_TO_RASTER_MIN_SIZE)
bIsBIG = true;
if (!bIsBIG)
{
m_oPage.Write(m_oSVGWriter.m_oVectors);
m_oSVGWriter.NewSVG();
return;
}
}
#endif
if (!bIsBIG)
{
if (m_oSVGWriter.m_oDocument.GetCurSize() > SVG_TO_RASTER_MIN_SIZE)
bIsBIG = true;
}
bool bIsNeedWriteEndSVG = true;
if (bIsBIG)
{
#ifdef USE_BIG_GRAPHICS_TORASTER
bool bIsBIGWrite = WriteSVGAsBitmap();
bIsNeedWriteEndSVG = false;
if (bIsBIGWrite)
{
m_oSVGWriter.NewSVG();
return;
}
#endif
}
if ((m_oSVGWriter.m_oDocument.GetCurSize() > SVG_INLINE_MAX_SIZE))
{
++m_lNextIDImage;
std::wstring strSaveItem = m_strDstMedia + L"/image" + std::to_wstring(m_lNextIDImage) + L".svg";
m_oSVGWriter.CloseFile2(strSaveItem, bIsNeedWriteEndSVG);
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(2);
m_oPage.WriteLONG(m_lNextIDImage);
}
else
{
m_oPage.WriteCommandType(CMetafile::ctDrawImage);
m_oPage.WriteBYTE(3);
m_oSVGWriter.CloseFile3(&m_oPage, bIsNeedWriteEndSVG);
}
m_oSVGWriter.NewSVG();
}
bool WriteSVGAsBitmap()
{
// TODO:
return true;
}
inline void SetTransformToDocument(bool bIsFromGraphics)
{
if (NULL == m_pTransform)
return;
if (bIsFromGraphics)
{
if ((fabs(1 - m_oLastTransform.m_agg_mtx.sx) < __g_matrix_eps) &&
(fabs(0 - m_oLastTransform.m_agg_mtx.shx) < __g_matrix_eps) &&
(fabs(0 - m_oLastTransform.m_agg_mtx.shy) < __g_matrix_eps) &&
(fabs(1 - m_oLastTransform.m_agg_mtx.sy) < __g_matrix_eps))
{
// ничего делать не нужно
}
else
{
m_oPage.WriteCommandType(CMetafile::ctResetTransform);
m_oLastTransform.Reset();
}
}
else
{
if (true)
{
m_oLastTransform = *m_pTransform;
agg::trans_affine* m = &m_pTransform->m_agg_mtx;
//m_oPage.Write(CMetafile::ctSetTransform, m->sx, m->shy, m->shx, m->sy, m->tx, m->ty);
m_oPage.WriteCommandType(CMetafile::ctSetTransform);
m_oPage.WriteDouble(m->sx);
m_oPage.WriteDouble(m->shy);
m_oPage.WriteDouble(m->shx);
m_oPage.WriteDouble(m->sy);
m_oPage.WriteDouble(m->tx);
m_oPage.WriteDouble(m->ty);
return;
}
if ((fabs(m_pTransform->m_agg_mtx.sx - m_oLastTransform.m_agg_mtx.sx) < __g_matrix_eps) &&
(fabs(m_pTransform->m_agg_mtx.shx - m_oLastTransform.m_agg_mtx.shx) < __g_matrix_eps) &&
(fabs(m_pTransform->m_agg_mtx.shy - m_oLastTransform.m_agg_mtx.shy) < __g_matrix_eps) &&
(fabs(m_pTransform->m_agg_mtx.sy - m_oLastTransform.m_agg_mtx.sy) < __g_matrix_eps) &&
(fabs(m_pTransform->m_agg_mtx.tx - m_oLastTransform.m_agg_mtx.tx) < __g_matrix_eps) &&
(fabs(m_pTransform->m_agg_mtx.ty - m_oLastTransform.m_agg_mtx.ty) < __g_matrix_eps))
{
// ничего делать не нужно
return;
}
if ((fabs(1 - m_pTransform->m_agg_mtx.sx) < __g_matrix_eps) &&
(fabs(0 - m_pTransform->m_agg_mtx.shx) < __g_matrix_eps) &&
(fabs(0 - m_pTransform->m_agg_mtx.shy) < __g_matrix_eps) &&
(fabs(1 - m_pTransform->m_agg_mtx.sy) < __g_matrix_eps) &&
(fabs(1 - m_oLastTransform.m_agg_mtx.sx) < __g_matrix_eps) &&
(fabs(0 - m_oLastTransform.m_agg_mtx.shx) < __g_matrix_eps) &&
(fabs(0 - m_oLastTransform.m_agg_mtx.shy) < __g_matrix_eps) &&
(fabs(1 - m_oLastTransform.m_agg_mtx.sy) < __g_matrix_eps))
{
// ничего делать не нужно
m_oLastTransform.Reset();
}
else
{
if ((fabs(1 - m_pTransform->m_agg_mtx.sx) < __g_matrix_eps) &&
(fabs(0 - m_pTransform->m_agg_mtx.shx) < __g_matrix_eps) &&
(fabs(0 - m_pTransform->m_agg_mtx.shy) < __g_matrix_eps) &&
(fabs(1 - m_pTransform->m_agg_mtx.sy) < __g_matrix_eps))
{
// ничего делать не нужно
m_oPage.WriteCommandType(CMetafile::ctResetTransform);
m_oLastTransform.Reset();
return;
}
m_oLastTransform = *m_pTransform;
agg::trans_affine* m = &m_pTransform->m_agg_mtx;
//m_oPage.Write(CMetafile::ctSetTransform, m->sx, m->shy, m->shx, m->sy, m->tx, m->ty);
m_oPage.WriteCommandType(CMetafile::ctSetTransform);
m_oPage.WriteDouble(m->sx);
m_oPage.WriteDouble(m->shy);
m_oPage.WriteDouble(m->shx);
m_oPage.WriteDouble(m->sy);
m_oPage.WriteDouble(m->tx);
m_oPage.WriteDouble(m->ty);
}
}
}
/////////////////////////////////////////////////////
void WriteStartDocument()
{
m_bIsGids = false;
}
void WriteEndDocument(CDocument& oDocument)
{
CMetafile oDocInfo;
oDocInfo.WriteLONG(m_lPagesCount);
oDocInfo.WriteLONG(m_oSmartText.m_lCountParagraphs);
oDocInfo.WriteLONG(m_oSmartText.m_lCountWords);
oDocInfo.WriteLONG(m_oSmartText.m_lCountSymbols);
oDocInfo.WriteLONG(m_oSmartText.m_lCountSpaces);
oDocInfo.WriteLONG(m_oDstFontGenerator.m_lCountFonts);
LONG lOffset = (6 + 4 * m_lPagesCount) * sizeof(LONG);
for (LONG i = 0; i < m_lPagesCount; i++)
{
CPageMeta& oMeta = m_arrPages[i];
oDocInfo.WriteDouble(oMeta.m_dWidth);
oDocInfo.WriteDouble(oMeta.m_dHeight);
oDocInfo.WriteLONG(oMeta.m_lStart + lOffset);
oDocInfo.WriteLONG(oMeta.m_lEnd + lOffset);
}
m_oFileWriter.CloseFile();
NSFile::CFileBinary oFilePages;
oFilePages.OpenFile(m_strDstDirectoryFiles + L"/document_temp.bin");
LONG lMetaSize = (LONG)oFilePages.GetFileSize();
LONG lSizeAll = oDocInfo.GetPosition() + lMetaSize;
BYTE* pData = new BYTE[lSizeAll];
memcpy(pData, oDocInfo.GetData(), oDocInfo.GetPosition());
DWORD dwRead = 0;
oFilePages.ReadFile(pData + oDocInfo.GetPosition(), lMetaSize, dwRead);
oFilePages.CloseFile();
NSFile::CFileBinary::Remove(m_strDstDirectoryFiles + L"/document_temp.bin");
char* pOutput = NULL;
int nOutputLen = 0;
NSFile::CBase64Converter::Encode(pData, lSizeAll, pOutput, nOutputLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
RELEASEARRAYOBJECTS(pData);
std::string sDstLen = std::to_string(nOutputLen);
sDstLen += ";";
NSFile::CFileBinary _file;
_file.CreateFileW(m_strDstDirectoryFiles + L"/Editor.bin");
_file.WriteFile((BYTE*)sDstLen.c_str(), (DWORD)sDstLen.length());
_file.WriteFile((BYTE*)pOutput, (DWORD)nOutputLen);
_file.CloseFile();
::CFontManager* pFontManager = m_pApplicationFonts->GenerateFontManager();
m_oDstFontGenerator.WriteFonts(pFontManager, m_strDstDirectoryFiles + L"/fonts", m_bIsGids);
RELEASEOBJECT(pFontManager);
}
void CreateFile(std::wstring& strDir, std::wstring& strFileName)
{
m_lPagesCount = 0;
m_lCurrentPage = -1;
m_strDstDirectory = strDir;
m_strDstDirectoryFiles = m_strDstDirectory + L"/" + strFileName;// + _T("_files");
m_strFileName = strFileName;
NSDirectory::CreateDirectory(m_strDstDirectoryFiles);
m_strDstMedia = m_strDstDirectoryFiles + L"/media";
NSDirectory::CreateDirectory(m_strDstMedia);
std::wstring strFileFonts = m_strDstDirectoryFiles + L"/fonts";
NSDirectory::CreateDirectory(strFileFonts);
std::wstring strDocRendererS = m_strDstDirectoryFiles + L"/document_temp.bin";
m_oFileWriter.CreateFileW(strDocRendererS);
m_oPage.Clear();
m_arrPages.clear();
m_bIsGids = false;
m_lCurrentDumpSize = 0;
m_oSmartText.SetParams(this);
m_oSmartText.m_lCountParagraphs = 0;
m_oSmartText.m_lCountWords = 0;
m_oSmartText.m_lCountSymbols = 0;
m_oSmartText.m_lCountSpaces = 0;
}
};
}
#endif // _ASC_HTMLRENDERER_WRITER_H_
#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();
}
#-------------------------------------------------
#
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment