Commit 574fe0f0 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Реализованы некоторые функции рендерера.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63077 954022d7-b5bf-4e40-9824-e11837661b57
parent 5754306f
......@@ -3,6 +3,9 @@
#include "Src/Document.h"
#include "Src/Pages.h"
#define MM_2_PT(X) (X * 25.4 / 72.0)
#define PT_2_MM(X) (X * 72.0 / 25.4)
using namespace PdfWriter;
CPdfRenderer::CPdfRenderer()
......@@ -23,52 +26,207 @@ CPdfRenderer::~CPdfRenderer()
if (m_pDocument)
delete m_pDocument;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_Type(LONG* lType)
{
*lType = c_nPDFWriter;
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::NewPage()
{
if (!IsValid())
return;
return S_FALSE;
m_pPage = m_pDocument->AddPage();
if (!m_pPage)
{
SetError();
return S_FALSE;
}
m_pPage->SetWidth(m_dPageWidth);
m_pPage->SetHeight(m_dPageHeight);
m_oPen.Reset();
return S_OK;
}
HRESULT CPdfRenderer::get_Height(double* dHeight)
{
*dHeight = m_dPageHeight;
return S_OK;
}
HRESULT CPdfRenderer::put_Height(const double& dHeight)
{
if (!IsValid() || !m_pPage)
return;
return S_FALSE;
m_dPageHeight = dHeight;
m_pPage->SetHeight(dHeight);
m_pPage->SetHeight(MM_2_PT(dHeight));
return S_OK;
}
HRESULT CPdfRenderer::get_Width(double* dWidth)
{
*dWidth = m_dPageWidth;
return S_OK;
}
HRESULT CPdfRenderer::put_Width(const double& dWidth)
{
if (!IsValid() || !m_pPage)
return;
return S_FALSE;
m_dPageWidth = dWidth;
m_pPage->SetWidth(dWidth);
m_pPage->SetWidth(MM_2_PT(dWidth));
return S_OK;
}
HRESULT CPdfRenderer::get_DpiX(double* dDpiX)
{
*dDpiX = 72;
return S_OK;
}
HRESULT CPdfRenderer::get_DpiY(double* dDpiY)
{
*dDpiY = 72;
return S_OK;
}
//----------------------------------------------------------------------------------------
// Pen
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_PenColor(LONG* lColor)
{
*lColor = m_oPen.GetColor();
return S_OK;
}
HRESULT CPdfRenderer::put_PenColor(const LONG& lColor)
{
m_oPen.SetColor(lColor);
return S_OK;
}
HRESULT CPdfRenderer::get_PenAlpha(LONG* lAlpha)
{
*lAlpha = m_oPen.GetAlpha();
return S_OK;
}
HRESULT CPdfRenderer::put_PenAlpha(const LONG& lAlpha)
{
m_oPen.SetAlpha(lAlpha);
return S_OK;
}
HRESULT CPdfRenderer::get_PenSize(double* dSize)
{
*dSize = m_oPen.GetSize();
return S_OK;
}
HRESULT CPdfRenderer::put_PenSize(const double& dSize)
{
m_oPen.SetSize(dSize);
return S_OK;
}
HRESULT CPdfRenderer::get_PenDashStyle(BYTE* nDashStyle)
{
*nDashStyle = m_oPen.GetDashStyle();
return S_OK;
}
HRESULT CPdfRenderer::put_PenDashStyle(const BYTE& nDashStyle)
{
m_oPen.SetDashStyle(nDashStyle);
return S_OK;
}
HRESULT CPdfRenderer::get_PenLineStartCap(BYTE* nCapStyle)
{
*nCapStyle = m_oPen.GetStartCapStyle();
return S_OK;
}
HRESULT CPdfRenderer::put_PenLineStartCap(const BYTE& nCapStyle)
{
m_oPen.SetStartCapStyle(nCapStyle);
return S_OK;
}
HRESULT CPdfRenderer::get_PenLineEndCap(BYTE* nCapStyle)
{
*nCapStyle = m_oPen.GetEndCapStyle();
return S_OK;
}
HRESULT CPdfRenderer::put_PenLineEndCap(const BYTE& nCapStyle)
{
m_oPen.SetEndCapStyle(nCapStyle);
return S_OK;
}
HRESULT CPdfRenderer::get_PenLineJoin(BYTE* nJoinStyle)
{
*nJoinStyle = m_oPen.GetJoinStyle();
return S_OK;
}
HRESULT CPdfRenderer::put_PenLineJoin(const BYTE& nJoinStyle)
{
m_oPen.SetJoinStyle(nJoinStyle);
return S_OK;
}
HRESULT CPdfRenderer::get_PenDashOffset(double* dOffset)
{
*dOffset = m_oPen.GetDashOffset();
return S_OK;
}
HRESULT CPdfRenderer::put_PenDashOffset(const double& dOffset)
{
m_oPen.SetDashOffset(dOffset);
return S_OK;
}
HRESULT CPdfRenderer::get_PenAlign(LONG* lAlign)
{
*lAlign = m_oPen.GetAlign();
return S_OK;
}
HRESULT CPdfRenderer::put_PenAlign(const LONG& lAlign)
{
m_oPen.SetAlign(lAlign);
return S_OK;
}
HRESULT CPdfRenderer::get_PenMiterLimit(double* dMiter)
{
*dMiter = m_oPen.GetMiter();
return S_OK;
}
HRESULT CPdfRenderer::put_PenMiterLimit(const double& dMiter)
{
m_oPen.SetMiter(dMiter);
return S_OK;
}
HRESULT CPdfRenderer::PenDashPattern(double* pPattern, LONG lCount)
{
m_oPen.SetDashPattern(pPattern, lCount);
return S_OK;
}
//----------------------------------------------------------------------------------------
// Brush
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_BrushType(LONG* lType)
{
return S_OK;
}
HRESULT CPdfRenderer::put_BrushType(const LONG& lType) = 0;
HRESULT CPdfRenderer::get_BrushColor1(LONG* lColor) = 0;
HRESULT CPdfRenderer::put_BrushColor1(const LONG& lColor) = 0;
HRESULT CPdfRenderer::get_BrushAlpha1(LONG* lAlpha) = 0;
HRESULT CPdfRenderer::put_BrushAlpha1(const LONG& lAlpha) = 0;
HRESULT CPdfRenderer::get_BrushColor2(LONG* lColor) = 0;
HRESULT CPdfRenderer::put_BrushColor2(const LONG& lColor) = 0;
HRESULT CPdfRenderer::get_BrushAlpha2(LONG* lAlpha) = 0;
HRESULT CPdfRenderer::put_BrushAlpha2(const LONG& lAlpha) = 0;
HRESULT CPdfRenderer::get_BrushTexturePath(std::wstring* bsPath) = 0;
HRESULT CPdfRenderer::put_BrushTexturePath(const std::wstring& bsPath) = 0;
HRESULT CPdfRenderer::get_BrushTextureMode(LONG* lMode) = 0;
HRESULT CPdfRenderer::put_BrushTextureMode(const LONG& lMode) = 0;
HRESULT CPdfRenderer::get_BrushTextureAlpha(LONG* lTxAlpha) = 0;
HRESULT CPdfRenderer::put_BrushTextureAlpha(const LONG& lTxAlpha) = 0;
HRESULT CPdfRenderer::get_BrushLinearAngle(double* dAngle) = 0;
HRESULT CPdfRenderer::put_BrushLinearAngle(const double& dAngle) = 0;
HRESULT CPdfRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
HRESULT CPdfRenderer::BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
HRESULT CPdfRenderer::put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0;
#ifndef _PDF_WRITER_PDFRENDERER_H
#define _PDF_WRITER_PDFRENDERER_H
#include "../DesktopEditor/graphics/IRenderer.h"
namespace PdfWriter
{
class CDocument;
class CPage;
};
class CPdfRenderer : public IRenderer
{
#ifndef _PDF_WRITER_PDFRENDERER_H
#define _PDF_WRITER_PDFRENDERER_H
#include "../DesktopEditor/graphics/IRenderer.h"
namespace PdfWriter
{
class CDocument;
class CPage;
};
class CPdfRenderer : public IRenderer
{
public:
CPdfRenderer();
~CPdfRenderer();
// -----------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT get_Type(LONG* lType);
//-------- --------------------------------------------------
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT NewPage();
virtual HRESULT get_Height(double* dHeight);
virtual HRESULT put_Height(const double& dHeight);
......@@ -25,8 +29,9 @@ public:
virtual HRESULT put_Width(const double& dWidth);
virtual HRESULT get_DpiX(double* dDpiX);
virtual HRESULT get_DpiY(double* dDpiY);
// pen --------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Pen
//----------------------------------------------------------------------------------------
virtual HRESULT get_PenColor(LONG* lColor) = 0;
virtual HRESULT put_PenColor(const LONG& lColor) = 0;
virtual HRESULT get_PenAlpha(LONG* lAlpha) = 0;
......@@ -48,8 +53,9 @@ public:
virtual HRESULT get_PenMiterLimit(double* dOffset) = 0;
virtual HRESULT put_PenMiterLimit(const double& dOffset) = 0;
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount)= 0;
// brush ------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Brush
//----------------------------------------------------------------------------------------
virtual HRESULT get_BrushType(LONG* lType) = 0;
virtual HRESULT put_BrushType(const LONG& lType) = 0;
virtual HRESULT get_BrushColor1(LONG* lColor) = 0;
......@@ -70,7 +76,6 @@ public:
virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0;
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0;
// font -------------------------------------------------------------------------------------
......@@ -171,27 +176,197 @@ public:
// additiaonal params ----------------------------------------------------------------------
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand) = 0;
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand) = 0;
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand) = 0;
private:
bool IsValid()
{
return m_bValid;
}
void SetError()
{
m_bValid = true;
}
private:
PdfWriter::CDocument* m_pDocument;
PdfWriter::CPage* m_pPage;
bool m_bValid;
double m_dPageHeight;
double m_dPageWidth;
};
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand) = 0;
private:
bool IsValid()
{
return m_bValid;
}
void SetError()
{
m_bValid = true;
}
private:
class CPenState
{
public:
CPenState()
{
m_pDashPattern = NULL;
Reset();
}
~CPenState()
{
if (m_pDashPattern)
delete[] m_pDashPattern;
}
inline LONG GetColor()
{
return m_lColor;
}
inline void SetColor(const LONG& lColor)
{
m_lColor = lColor;
UpdateColor();
}
inline LONG GetAlpha()
{
return m_nA;
}
inline void SetAlpha(const LONG& lAlpha)
{
m_nA = (BYTE)max(0, min(255, lAlpha));
}
inline double GetSize()
{
return m_dSize;
}
inline void SetSize(const double& dSize)
{
m_dSize = dSize;
}
inline BYTE GetDashStyle()
{
return m_nDashStyle;
}
inline void SetDashStyle(const BYTE& nDashStyle)
{
m_nDashStyle = nDashStyle;
}
inline BYTE GetStartCapStyle()
{
return m_nStartCapStyle;
}
inline void SetStartCapStyle(const BYTE& nCapStyle)
{
m_nStartCapStyle = nCapStyle;
}
inline BYTE GetEndCapStyle()
{
return m_nEndCapStyle;
}
inline void SetEndCapStyle(const BYTE& nCapStyle)
{
m_nEndCapStyle = nCapStyle;
}
inline BYTE GetJoinStyle()
{
return m_nJoinStyle;
}
inline void SetJoinStyle(const BYTE& nJoinStyle)
{
m_nJoinStyle = nJoinStyle;
}
inline double GetDashOffset()
{
return m_dDashOffset;
}
inline void SetDashOffset(const double& dOffset)
{
m_dDashOffset = dOffset;
}
inline LONG GetAlign()
{
return m_lAlign;
}
inline void SetAlign(const LONG& lAlign)
{
m_lAlign = lAlign;
}
inline double GetMiter()
{
return m_dMiter;
}
inline void SetMiter(const double& dMiter)
{
m_dMiter = dMiter;
}
inline void SetDashPattern(const double* pPattern, const LONG& lSize)
{
if (m_pDashPattern)
{
delete[] m_pDashPattern;
m_pDashPattern = NULL;
}
m_lDashPatternSize = 0;
if (!pPattern || !lSize)
{
m_lDashPatternSize = 0;
m_pDashPattern = NULL;
}
else
{
m_pDashPattern = new double[lSize];
if (m_pDashPattern)
{
memcpy((void*)m_pDashPattern, (const void*)pPattern, lSize * sizeof(double));
m_lDashPatternSize = lSize;
}
}
}
void Reset()
{
if (m_pDashPattern)
delete[] m_pDashPattern;
m_lColor = 0;
m_dSize = 0;
m_nA = 255;
m_nDashStyle = 0;
m_lDashPatternSize = 0;
m_pDashPattern = NULL;
UpdateColor();
}
private:
void UpdateColor()
{
m_nR = (unsigned char)(m_lColor & 0xFF);
m_nG = (unsigned char)((m_lColor >> 8) & 0xFF);
m_nB = (unsigned char)((m_lColor >> 16) & 0xFF);
}
private:
double m_dSize;
LONG m_lColor;
BYTE m_nA;
BYTE m_nR;
BYTE m_nG;
BYTE m_nB;
BYTE m_nStartCapStyle;
BYTE m_nEndCapStyle;
BYTE m_nJoinStyle;
LONG m_lAlign;
double m_dMiter;
BYTE m_nDashStyle;
double m_dDashOffset;
double*m_pDashPattern;
LONG m_lDashPatternSize;
};
PdfWriter::CDocument* m_pDocument;
PdfWriter::CPage* m_pPage;
CPenState m_oPen;
bool m_bValid;
double m_dPageHeight;
double m_dPageWidth;
};
#endif // _PDF_WRITER_PDFRENDERER_H
\ No newline at end of file
......@@ -11,10 +11,10 @@ namespace PdfWriter
{
public:
CFont14(CXref* pXref, CDocument* pDocument, EStandard14Fonts eType);
EFontType GetFontType()
{
return fontType1;
}
EFontType GetFontType()
{
return fontType1;
}
};
}
......
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