Commit 3a0d3dc6 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Реализована функция отрисовки текста, выставления шрифта (только если он...

Реализована функция отрисовки текста, выставления шрифта (только если он TrueType), выставления трансформа.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63156 954022d7-b5bf-4e40-9824-e11837661b57
parent 8bb23352
...@@ -3,18 +3,39 @@ ...@@ -3,18 +3,39 @@
#include "Src/Document.h" #include "Src/Document.h"
#include "Src/Pages.h" #include "Src/Pages.h"
#include "Src/Image.h" #include "Src/Image.h"
#include "Src/Font.h"
#include "Src/FontCidTT.h"
#include "../DesktopEditor/graphics/Image.h" #include "../DesktopEditor/graphics/Image.h"
#include "../DesktopEditor/raster/BgraFrame.h" #include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/cximage/CxImage/ximage.h" #include "../DesktopEditor/cximage/CxImage/ximage.h"
#include "../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../DesktopEditor/fontengine/FontManager.h"
#define MM_2_PT(X) ((X) * 72.0 / 25.4) #define MM_2_PT(X) ((X) * 72.0 / 25.4)
#define PT_2_MM(X) ((X) * 25.4 / 72.0) #define PT_2_MM(X) ((X) * 25.4 / 72.0)
#ifdef DrawText
#undef DrawText
#endif
using namespace PdfWriter; using namespace PdfWriter;
CPdfRenderer::CPdfRenderer() #define HI_SURROGATE_START 0xD800
#define HI_SURROGATE_END 0xDBFF
#define LO_SURROGATE_START 0xDC00
#define LO_SURROGATE_END 0xDFFF
CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts)
{ {
m_pAppFonts = pAppFonts;
//
m_pFontManager = pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
m_pDocument = new CDocument(); m_pDocument = new CDocument();
if (!m_pDocument || !m_pDocument->CreateNew()) if (!m_pDocument || !m_pDocument->CreateNew())
{ {
...@@ -26,11 +47,12 @@ CPdfRenderer::CPdfRenderer() ...@@ -26,11 +47,12 @@ CPdfRenderer::CPdfRenderer()
m_dPageHeight = 297; m_dPageHeight = 297;
m_dPageWidth = 210; m_dPageWidth = 210;
m_pPage = NULL; m_pPage = NULL;
m_pFont = NULL;
} }
CPdfRenderer::~CPdfRenderer() CPdfRenderer::~CPdfRenderer()
{ {
if (m_pDocument) RELEASEOBJECT(m_pDocument);
delete m_pDocument; RELEASEINTERFACE(m_pFontManager);
} }
void CPdfRenderer::SaveToFile(const std::wstring& wsPath) void CPdfRenderer::SaveToFile(const std::wstring& wsPath)
{ {
...@@ -407,7 +429,77 @@ HRESULT CPdfRenderer::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX ...@@ -407,7 +429,77 @@ HRESULT CPdfRenderer::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX
} }
HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset) HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{ {
// TODO: if (!IsPageValid() || !wsUnicodeText.size())
return S_FALSE;
m_pPage->GrSave();
UpdateTransform();
UpdateFont();
if (!m_pFont)
return S_FALSE;
unsigned int* pUnicodes = new unsigned int[wsUnicodeText.size()];
if (!pUnicodes)
return S_FALSE;
unsigned int* pOutput = pUnicodes;
unsigned int unLen = 0;
if (2 == sizeof(wchar_t))
{
const wchar_t* wsEnd = wsUnicodeText.c_str() + wsUnicodeText.size();
wchar_t* wsInput = (wchar_t*)wsUnicodeText.c_str();
wchar_t wLeading, wTrailing;
unsigned int unCode;
while (wsInput < wsEnd)
{
wLeading = *wsInput++;
if (wLeading < 0xD800 || wLeading > 0xDFFF)
{
pUnicodes[unLen++] = (unsigned int)wLeading;
}
else if (wLeading >= 0xDC00)
{
//
continue;
}
else
{
unCode = (wLeading & 0x3FF) << 10;
wTrailing = *wsInput++;
if (wTrailing < 0xDC00 || wTrailing > 0xDFFF)
{
//
continue;
}
else
{
pUnicodes[unLen++] = (unCode | (wTrailing & 0x3FF) + 0x10000);
}
}
}
}
else
{
unLen = wsUnicodeText.size();
for (unsigned int unIndex = 0; unIndex < unLen; unIndex++)
{
pUnicodes[unIndex] = (unsigned int)wsUnicodeText.at(unIndex);
}
}
unsigned char* pCodes = m_pFont->EncodeString(pUnicodes, unLen);
delete[] pUnicodes;
m_pPage->BeginText();
m_pPage->SetFontAndSize(m_pFont, m_oFont.GetSize());
m_pPage->DrawText(MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY), pCodes, unLen * 2);
m_pPage->EndText();
m_pPage->GrRestore();
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags) HRESULT CPdfRenderer::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
...@@ -568,17 +660,22 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d ...@@ -568,17 +660,22 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) HRESULT CPdfRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{ {
// TODO: m_oTransform.Set(dM11, dM12, dM21, dM22, dX, dY);
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY) HRESULT CPdfRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY)
{ {
// TODO: *dM11 = m_oTransform.m11;
*dM12 = m_oTransform.m12;
*dM21 = m_oTransform.m21;
*dM22 = m_oTransform.m22;
*dX = m_oTransform.dx;
*dY = m_oTransform.dy;
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::ResetTransform() HRESULT CPdfRenderer::ResetTransform()
{ {
// TODO: m_oTransform.Reset();
return S_OK; return S_OK;
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -625,10 +722,14 @@ HRESULT CPdfRenderer::DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWid ...@@ -625,10 +722,14 @@ HRESULT CPdfRenderer::DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWid
if (!IsPageValid() || !pImageBuffer) if (!IsPageValid() || !pImageBuffer)
return S_OK; return S_OK;
// TODO: m_pPage->GrSave();
UpdateTransform();
CImageDict* pPdfImage = m_pDocument->CreateImage(); CImageDict* pPdfImage = m_pDocument->CreateImage();
pPdfImage->LoadBW(pImageBuffer, unWidth, unHeight); pPdfImage->LoadBW(pImageBuffer, unWidth, unHeight);
m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH)); m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH));
m_pPage->GrRestore();
return S_OK; return S_OK;
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -674,4 +775,36 @@ bool CPdfRenderer::DrawImage(Aggplus::CImage* pImage, const double& dX, const do ...@@ -674,4 +775,36 @@ bool CPdfRenderer::DrawImage(Aggplus::CImage* pImage, const double& dX, const do
return true; return true;
} }
void CPdfRenderer::UpdateFont()
{
std::wstring& wsFontPath = m_oFont.GetPath();
LONG lFaceIndex = m_oFont.GetFaceIndex();
if (L"" == wsFontPath)
{
CFontSelectFormat oFontSelect;
oFontSelect.wsName = new std::wstring(m_oFont.GetName());
oFontSelect.bItalic = new INT(m_oFont.IsItalic() ? 0 : 1);
oFontSelect.bItalic = new INT(m_oFont.IsBold() ? 0 : 1);
CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect);
wsFontPath = pFontInfo->m_wsFontPath;
lFaceIndex = pFontInfo->m_lIndex;
}
m_pFont = NULL;
if (L"" != wsFontPath)
{
// TODO: , TrueType, OpenType
LONG lFaceIndex = m_oFont.GetFaceIndex();
m_pFontManager->LoadFontFromFile(wsFontPath, lFaceIndex, 10, 72, 72);
std::wstring wsFontType = m_pFontManager->GetFontType();
if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType)
m_pFont = m_pDocument->CreateTrueTypeFont(wsFontPath, lFaceIndex);
}
}
void CPdfRenderer::UpdateTransform()
{
CTransform& t = m_oTransform;
m_pPage->Concat(t.m11, -t.m12, -t.m21, t.m22, MM_2_PT(t.dx + t.m21 * m_dPageHeight), MM_2_PT(m_dPageHeight - m_dPageHeight * t.m22 - t.dy));
}
...@@ -12,6 +12,7 @@ namespace PdfWriter ...@@ -12,6 +12,7 @@ namespace PdfWriter
{ {
class CDocument; class CDocument;
class CPage; class CPage;
class CFontCidTrueType;
} }
namespace Aggplus namespace Aggplus
...@@ -19,10 +20,13 @@ namespace Aggplus ...@@ -19,10 +20,13 @@ namespace Aggplus
class CImage; class CImage;
} }
class CFontManager;
class CApplicationFonts;
class CPdfRenderer : public IRenderer class CPdfRenderer : public IRenderer
{ {
public: public:
CPdfRenderer(); CPdfRenderer(CApplicationFonts* pAppFonts);
~CPdfRenderer(); ~CPdfRenderer();
void SaveToFile(const std::wstring& wsPath); void SaveToFile(const std::wstring& wsPath);
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -166,9 +170,8 @@ public: ...@@ -166,9 +170,8 @@ public:
private: private:
bool DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha); bool DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha);
void UpdateFont();
private: void UpdateTransform();
bool IsValid() bool IsValid()
{ {
return m_bValid; return m_bValid;
...@@ -735,6 +738,11 @@ private: ...@@ -735,6 +738,11 @@ private:
{ {
public: public:
CFontState() : m_wsPath(L""), m_wsName(L"Arial"), m_lStyle(0), m_bBold(false), m_bItalic(false), m_dCharSpace(0),
m_lFaceIndex(0), m_dSize(10), m_bGid(false)
{
}
inline std::wstring GetName() inline std::wstring GetName()
{ {
return m_wsName; return m_wsName;
...@@ -793,6 +801,14 @@ private: ...@@ -793,6 +801,14 @@ private:
{ {
m_dCharSpace = dCharSpace; m_dCharSpace = dCharSpace;
} }
inline bool IsBold()
{
return m_bBold;
}
inline bool IsItalic()
{
return m_bItalic;
}
private: private:
...@@ -806,295 +822,298 @@ private: ...@@ -806,295 +822,298 @@ private:
bool m_bItalic; bool m_bItalic;
double m_dCharSpace; double m_dCharSpace;
}; };
enum EPathCommandType class CPath
{
rendererpathcommand_Unknown = 0x00,
rendererpathcommand_MoveTo = 0x01,
rendererpathcommand_LineTo = 0x02,
rendererpathcommand_CurveTo = 0x03,
rendererpathcommand_ArcTo = 0x04,
rendererpathcommand_Close = 0x05,
rendererpathcommand_TextChar = 0x06,
rendererpathcommand_Text = 0x07,
rendererpathcommand_TextExChar = 0x08,
rendererpathcommand_TextEx = 0x09
};
class CPathCommandBase
{
public:
CPathCommandBase()
{
}
virtual ~CPathCommandBase()
{
}
virtual void GetLastPoint(double& dX, double& dY) = 0;
virtual EPathCommandType GetType() = 0;
};
class CPathMoveTo : public CPathCommandBase
{ {
public: private:
CPathMoveTo(const double& dX, const double& dY)
{ enum EPathCommandType
x = dX; {
y = dY; rendererpathcommand_Unknown = 0x00,
} rendererpathcommand_MoveTo = 0x01,
void GetLastPoint(double& dX, double& dY) rendererpathcommand_LineTo = 0x02,
rendererpathcommand_CurveTo = 0x03,
rendererpathcommand_ArcTo = 0x04,
rendererpathcommand_Close = 0x05,
rendererpathcommand_TextChar = 0x06,
rendererpathcommand_Text = 0x07,
rendererpathcommand_TextExChar = 0x08,
rendererpathcommand_TextEx = 0x09
};
class CPathCommandBase
{ {
dX = x; public:
dY = y; CPathCommandBase()
} {
EPathCommandType GetType() }
virtual ~CPathCommandBase()
{
}
virtual void GetLastPoint(double& dX, double& dY) = 0;
virtual EPathCommandType GetType() = 0;
};
class CPathMoveTo : public CPathCommandBase
{ {
return rendererpathcommand_MoveTo; public:
} CPathMoveTo(const double& dX, const double& dY)
{
x = dX;
y = dY;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_MoveTo;
}
public: public:
double x; double x;
double y; double y;
}; };
class CPathLineTo : public CPathCommandBase class CPathLineTo : public CPathCommandBase
{
public:
CPathLineTo(const double& dX, const double& dY)
{
x = dX;
y = dY;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_LineTo; public:
} CPathLineTo(const double& dX, const double& dY)
{
x = dX;
y = dY;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_LineTo;
}
public: public:
double x; double x;
double y; double y;
}; };
class CPathCurveTo : public CPathCommandBase class CPathCurveTo : public CPathCommandBase
{
public:
CPathCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe)
{
x1 = dX1;
y1 = dY1;
x2 = dXe;
y2 = dY2;
xe = dXe;
ye = dYe;
}
void GetLastPoint(double& dX, double& dY)
{
dX = xe;
dY = ye;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_CurveTo; public:
} CPathCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe)
{
x1 = dX1;
y1 = dY1;
x2 = dXe;
y2 = dY2;
xe = dXe;
ye = dYe;
}
void GetLastPoint(double& dX, double& dY)
{
dX = xe;
dY = ye;
}
EPathCommandType GetType()
{
return rendererpathcommand_CurveTo;
}
public: public:
double x1; double x1;
double y1; double y1;
double x2; double x2;
double y2; double y2;
double xe; double xe;
double ye; double ye;
}; };
class CPathArcTo : public CPathCommandBase class CPathArcTo : public CPathCommandBase
{
public:
CPathArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle)
{
x = dX;
y = dY;
w = dW;
h = dH;
startAngle = dStartAngle;
sweepAngle = dSweepAngle;
}
void GetLastPoint(double& dX, double& dY)
{
// TODO:
dX = x;
dY = y;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_ArcTo; public:
} CPathArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle)
{
x = dX;
y = dY;
w = dW;
h = dH;
startAngle = dStartAngle;
sweepAngle = dSweepAngle;
}
void GetLastPoint(double& dX, double& dY)
{
// TODO:
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_ArcTo;
}
public: public:
double x; double x;
double y; double y;
double w; double w;
double h; double h;
double startAngle; double startAngle;
double sweepAngle; double sweepAngle;
}; };
class CPathClose : public CPathCommandBase class CPathClose : public CPathCommandBase
{
public:
CPathClose()
{
}
void GetLastPoint(double& dX, double& dY)
{
// TODO:
dX = 0;
dY = 0;
}
EPathCommandType GetType()
{
return rendererpathcommand_Close;
}
};
class CPathTextChar : public CPathCommandBase
{
public:
CPathTextChar(const CFontState& oFont, const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicode = lUnicode;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{ {
dX = x; public:
dY = y; CPathClose()
} {
EPathCommandType GetType() }
void GetLastPoint(double& dX, double& dY)
{
// TODO:
dX = 0;
dY = 0;
}
EPathCommandType GetType()
{
return rendererpathcommand_Close;
}
};
class CPathTextChar : public CPathCommandBase
{ {
return rendererpathcommand_TextChar; public:
} CPathTextChar(const CFontState& oFont, const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicode = lUnicode;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_TextChar;
}
public: public:
CFontState font; CFontState font;
LONG unicode; LONG unicode;
double x; double x;
double y; double y;
double w; double w;
double h; double h;
double baseline; double baseline;
}; };
class CPathText : public CPathCommandBase class CPathText : public CPathCommandBase
{
public:
CPathText(const CFontState& oFont, const std::wstring& wsText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
text = wsText;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_Text; public:
} CPathText(const CFontState& oFont, const std::wstring& wsText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
text = wsText;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_Text;
}
public: public:
CFontState font; CFontState font;
std::wstring text; std::wstring text;
double x; double x;
double y; double y;
double w; double w;
double h; double h;
double baseline; double baseline;
}; };
class CPathTextExChar : public CPathCommandBase class CPathTextExChar : public CPathCommandBase
{
public:
CPathTextExChar(const CFontState& oFont, const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicode = lUnicode;
gid = lGid;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_TextExChar; public:
} CPathTextExChar(const CFontState& oFont, const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicode = lUnicode;
gid = lGid;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_TextExChar;
}
public: public:
CFontState font; CFontState font;
LONG unicode; LONG unicode;
LONG gid; LONG gid;
double x; double x;
double y; double y;
double w; double w;
double h; double h;
double baseline; double baseline;
}; };
class CPathTextEx : public CPathCommandBase class CPathTextEx : public CPathCommandBase
{
public:
CPathTextEx(const CFontState& oFont, const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicodeText = wsUnicodeText;
gidText = wsGidText;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{ {
return rendererpathcommand_TextEx; public:
} CPathTextEx(const CFontState& oFont, const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
font = oFont;
unicodeText = wsUnicodeText;
gidText = wsGidText;
x = dX;
y = dY;
w = dW;
h = dH;
baseline = dBaselineOffset;
}
void GetLastPoint(double& dX, double& dY)
{
dX = x;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_TextEx;
}
public: public:
CFontState font;
std::wstring unicodeText;
std::wstring gidText;
double x;
double y;
double w;
double h;
double baseline;
};
CFontState font;
std::wstring unicodeText;
std::wstring gidText;
double x;
double y;
double w;
double h;
double baseline;
};
class CPath
{
public: public:
CPath() CPath()
...@@ -1198,20 +1217,62 @@ private: ...@@ -1198,20 +1217,62 @@ private:
std::vector<CPathCommandBase*> m_vCommands; std::vector<CPathCommandBase*> m_vCommands;
bool m_bIsMoveTo; bool m_bIsMoveTo;
}; };
class CTransform
{
public:
CTransform()
{
Reset();
}
void Reset()
{
m11 = 1.0;
m12 = 0.0;
m21 = 0.0;
m22 = 1.0;
dx = 0;
dy = 0;
}
void Set(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{
m11 = dM11;
m12 = dM12;
m21 = dM21;
m22 = dM22;
dx = dX;
dy = dY;
}
public:
double m11;
double m12;
double m21;
double m22;
double dx;
double dy;
};
private:
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
PdfWriter::CDocument* m_pDocument; PdfWriter::CDocument* m_pDocument;
PdfWriter::CPage* m_pPage; PdfWriter::CPage* m_pPage;
PdfWriter::CFontCidTrueType* m_pFont;
CPenState m_oPen; CPenState m_oPen;
CBrushState m_oBrush; CBrushState m_oBrush;
CFontState m_oFont; CFontState m_oFont;
CPath m_oPath; CPath m_oPath;
LONG m_lClipMode; CTransform m_oTransform;
LONG m_lClipMode;
double m_dPageHeight;
double m_dPageWidth;
bool m_bValid; bool m_bValid;
double m_dPageHeight;
double m_dPageWidth;
}; };
#endif // _PDF_WRITER_PDFRENDERER_H #endif // _PDF_WRITER_PDFRENDERER_H
\ No newline at end of file
...@@ -851,9 +851,13 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin ...@@ -851,9 +851,13 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin
} }
return vwsNames; return vwsNames;
} }
void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, const int nType) void ConvertFolder(std::wstring wsFolderPath, const int nType)
{ {
CPdfRenderer oRenderer; CApplicationFonts oFonts;
oFonts.Initialize();
MetaFile::CMetaFile oMetaFile(&oFonts);
CPdfRenderer oRenderer(&oFonts);
oMetaFile.Close(); oMetaFile.Close();
...@@ -865,6 +869,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -865,6 +869,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
case MetaFile::c_lMetaWmf: sExt = L"wmf"; break; case MetaFile::c_lMetaWmf: sExt = L"wmf"; break;
case MetaFile::c_lMetaSvm: sExt = L"svm"; break; case MetaFile::c_lMetaSvm: sExt = L"svm"; break;
} }
double dPx2Mm = 25.4 / 96;
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, sExt); std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, sExt);
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++) for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{ {
...@@ -874,14 +879,17 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -874,14 +879,17 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
wsFilePath.append(vFiles.at(nIndex)); wsFilePath.append(vFiles.at(nIndex));
if (oMetaFile.LoadFromFile(wsFilePath.c_str())) if (oMetaFile.LoadFromFile(wsFilePath.c_str()))
{ {
double dW = 210; double dW, dH, dX, dY;
double dH = 297; oMetaFile.GetBounds(&dX, &dY, &dW, &dH);
//double dW, dH, dX, dY;
//oMetaFile.GetBounds(&dX, &dY, &dW, &dH); dW *= dPx2Mm;
dH *= dPx2Mm;
dX *= dPx2Mm;
dY *= dPx2Mm;
oRenderer.put_Width(dW); oRenderer.put_Width(dW);
oRenderer.put_Height(dH); oRenderer.put_Height(dH);
oMetaFile.DrawOnRenderer(&oRenderer, 0, 0, dW, dH); oMetaFile.DrawOnRenderer(&oRenderer, -dX, -dY, dW, dH);
oMetaFile.Close(); oMetaFile.Close();
} }
...@@ -892,11 +900,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -892,11 +900,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
} }
void TestMetafile() void TestMetafile()
{ {
CApplicationFonts oFonts; ConvertFolder(L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
oFonts.Initialize();
MetaFile::CMetaFile oMetaFile(&oFonts);
ConvertFolder(oMetaFile, L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
} }
void main() void main()
......
...@@ -105,6 +105,7 @@ namespace PdfWriter ...@@ -105,6 +105,7 @@ namespace PdfWriter
m_vExtGrStates.clear(); m_vExtGrStates.clear();
m_vPages.clear(); m_vPages.clear();
m_vShadings.clear(); m_vShadings.clear();
m_vTTFonts.clear();
} }
bool CDocument::SaveToFile(const std::wstring& wsPath) bool CDocument::SaveToFile(const std::wstring& wsPath)
{ {
...@@ -372,7 +373,19 @@ namespace PdfWriter ...@@ -372,7 +373,19 @@ namespace PdfWriter
} }
CFontCidTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex) CFontCidTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex)
{ {
return new CFontCidTrueType(m_pXref, this, wsFontPath, unIndex); for (int nIndex = 0, nCount = m_vTTFonts.size(); nIndex < nCount; nIndex++)
{
TFontInfo& oInfo = m_vTTFonts.at(nIndex);
if (wsFontPath == oInfo.wsPath && unIndex == oInfo.unIndex)
return oInfo.pFont;
}
CFontCidTrueType* pFont = new CFontCidTrueType(m_pXref, this, wsFontPath, unIndex);
if (!pFont)
return NULL;
m_vTTFonts.push_back(TFontInfo(wsFontPath, unIndex, pFont));
return pFont;
} }
char* CDocument::GetTTFontTag() char* CDocument::GetTTFontTag()
{ {
......
...@@ -81,6 +81,21 @@ namespace PdfWriter ...@@ -81,6 +81,21 @@ namespace PdfWriter
CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix); CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix);
private: private:
struct TFontInfo
{
TFontInfo(const std::wstring& path, const unsigned int& index, CFontCidTrueType* font)
{
wsPath = path;
unIndex = index;
pFont = font;
}
std::wstring wsPath;
unsigned int unIndex;
CFontCidTrueType* pFont;
};
CCatalog* m_pCatalog; CCatalog* m_pCatalog;
COutline* m_pOutlines; COutline* m_pOutlines;
CXref* m_pXref; CXref* m_pXref;
...@@ -98,6 +113,7 @@ namespace PdfWriter ...@@ -98,6 +113,7 @@ namespace PdfWriter
char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0") char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0")
CJbig2Global* m_pJbig2; CJbig2Global* m_pJbig2;
std::vector<CShading*> m_vShadings; std::vector<CShading*> m_vShadings;
std::vector<TFontInfo> m_vTTFonts;
friend class CFontCidTrueType; friend class CFontCidTrueType;
}; };
......
...@@ -23,10 +23,10 @@ namespace PdfWriter ...@@ -23,10 +23,10 @@ namespace PdfWriter
CFontCidTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex); CFontCidTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex);
~CFontCidTrueType(); ~CFontCidTrueType();
unsigned char* EncodeString(unsigned int* pUnicodes, unsigned int unLen); unsigned char* EncodeString(unsigned int* pUnicodes, unsigned int unLen);
EFontType GetFontType() EFontType GetFontType()
{ {
return fontCIDType2; return fontCIDType2;
} }
private: private:
......
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