Commit 739d4f95 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Реализованы некоторые функции рендерера : выставление настроек пена, браша,...

Реализованы некоторые функции рендерера : выставление настроек пена, браша, шрифта. Реализована отрисовка картинок.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63132 954022d7-b5bf-4e40-9824-e11837661b57
parent 40b82b45
......@@ -2,9 +2,14 @@
#include "Src/Document.h"
#include "Src/Pages.h"
#include "Src/Image.h"
#define MM_2_PT(X) (X * 25.4 / 72.0)
#define PT_2_MM(X) (X * 72.0 / 25.4)
#include "../DesktopEditor/graphics/Image.h"
#include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/cximage/CxImage/ximage.h"
#define MM_2_PT(X) ((X) * 72.0 / 25.4)
#define PT_2_MM(X) ((X) * 25.4 / 72.0)
using namespace PdfWriter;
......@@ -17,6 +22,7 @@ CPdfRenderer::CPdfRenderer()
return;
}
m_bValid = true;
m_dPageHeight = 297;
m_dPageWidth = 210;
m_pPage = NULL;
......@@ -26,6 +32,13 @@ CPdfRenderer::~CPdfRenderer()
if (m_pDocument)
delete m_pDocument;
}
void CPdfRenderer::SaveToFile(const std::wstring& wsPath)
{
if (!IsValid())
return;
m_pDocument->SaveToFile(wsPath);
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
......@@ -208,25 +221,457 @@ HRESULT CPdfRenderer::PenDashPattern(double* pPattern, LONG lCount)
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_BrushType(LONG* lType)
{
*lType = m_oBrush.GetType();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushType(const LONG& lType)
{
m_oBrush.SetType(lType);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushColor1(LONG* lColor)
{
*lColor = m_oBrush.GetColor1();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushColor1(const LONG& lColor)
{
m_oBrush.SetColor1(lColor);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushAlpha1(LONG* lAlpha)
{
*lAlpha = m_oBrush.GetAlpha1();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushAlpha1(const LONG& lAlpha)
{
m_oBrush.SetAlpha1(lAlpha);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushColor2(LONG* lColor)
{
*lColor = m_oBrush.GetColor2();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushColor2(const LONG& lColor)
{
m_oBrush.SetColor2(lColor);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushAlpha2(LONG* lAlpha)
{
*lAlpha = m_oBrush.GetAlpha2();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushAlpha2(const LONG& lAlpha)
{
m_oBrush.SetAlpha2(lAlpha);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushTexturePath(std::wstring* wsPath)
{
*wsPath = m_oBrush.GetTexturePath();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushTexturePath(const std::wstring& wsPath)
{
m_oBrush.SetTexturePath(wsPath);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushTextureMode(LONG* lMode)
{
*lMode = m_oBrush.GetTextureMode();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushTextureMode(const LONG& lMode)
{
m_oBrush.SetTextureMode(lMode);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushTextureAlpha(LONG* lAlpha)
{
*lAlpha = m_oBrush.GetTextureAlpha();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushTextureAlpha(const LONG& lAlpha)
{
m_oBrush.SetTextureAlpha(lAlpha);
return S_OK;
}
HRESULT CPdfRenderer::get_BrushLinearAngle(double* dAngle)
{
*dAngle = m_oBrush.GetLinearAngle();
return S_OK;
}
HRESULT CPdfRenderer::put_BrushLinearAngle(const double& dAngle)
{
m_oBrush.SetLinearAngle(dAngle);
return S_OK;
}
HRESULT CPdfRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::BrushBounds(const double& left, const double& top, const double& width, const double& height)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::put_BrushGradientColors(LONG* lColors, double* pPositions, LONG lCount)
{
m_oBrush.SetShadingColors(lColors, pPositions, lCount);
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_FontName(std::wstring* wsName)
{
*wsName = m_oFont.GetName();
return S_OK;
}
HRESULT CPdfRenderer::put_FontName(const std::wstring& wsName)
{
m_oFont.SetName(wsName);
return S_OK;
}
HRESULT CPdfRenderer::get_FontPath(std::wstring* wsPath)
{
*wsPath = m_oFont.GetPath();
return S_OK;
}
HRESULT CPdfRenderer::put_FontPath(const std::wstring& wsPath)
{
m_oFont.SetPath(wsPath);
return S_OK;
}
HRESULT CPdfRenderer::get_FontSize(double* dSize)
{
*dSize = m_oFont.GetSize();
return S_OK;
}
HRESULT CPdfRenderer::put_FontSize(const double& dSize)
{
m_oFont.SetSize(dSize);
return S_OK;
}
HRESULT CPdfRenderer::get_FontStyle(LONG* lStyle)
{
*lStyle = m_oFont.GetStyle();
return S_OK;
}
HRESULT CPdfRenderer::put_FontStyle(const LONG& lStyle)
{
m_oFont.SetStyle(lStyle);
return S_OK;
}
HRESULT CPdfRenderer::get_FontStringGID(INT* bGid)
{
*bGid = m_oFont.GetGid() ? 1 : 0;
return S_OK;
}
HRESULT CPdfRenderer::put_FontStringGID(const INT& bGid)
{
m_oFont.SetGid(bGid ? true : false);
return S_OK;
}
HRESULT CPdfRenderer::get_FontCharSpace(double* dSpace)
{
*dSpace = m_oFont.GetCharSpace();
return S_OK;
}
HRESULT CPdfRenderer::put_FontCharSpace(const double& dSpace)
{
m_oFont.SetCharSpace(dSpace);
return S_OK;
}
HRESULT CPdfRenderer::get_FontFaceIndex(int* nFaceIndex)
{
*nFaceIndex = (int)m_oFont.GetFaceIndex();
return S_OK;
}
HRESULT CPdfRenderer::put_FontFaceIndex(const int& nFaceIndex)
{
m_oFont.SetFaceIndex(nFaceIndex);
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
// TODO:
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)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::CommandDrawTextEx(const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
// TODO:
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::BeginCommand(const DWORD& dwType)
{
//
return S_OK;
}
HRESULT CPdfRenderer::EndCommand(const DWORD& dwType)
{
// 2 :
// TODO:
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::PathCommandStart()
{
m_oPath.Clear();
return S_OK;
}
HRESULT CPdfRenderer::PathCommandEnd()
{
m_oPath.Clear();
return S_OK;
}
HRESULT CPdfRenderer::DrawPath(const LONG& lType)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::PathCommandMoveTo(const double& dX, const double& dY)
{
m_oPath.MoveTo(dX, dY);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandLineTo(const double& dX, const double& dY)
{
m_oPath.LineTo(dX, dY);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandLinesTo(double* pPoints, const int& nCount)
{
if (nCount < 4 || !pPoints)
return S_OK;
if (!m_oPath.IsMoveTo())
m_oPath.MoveTo(pPoints[0], pPoints[1]);
int nPointsCount = (nCount / 2) - 1;
for (int nIndex = 1; nIndex <= nPointsCount; ++nIndex)
{
m_oPath.LineTo(pPoints[nIndex * 2], pPoints[nIndex * 2 + 1]);
}
return S_OK;
}
HRESULT CPdfRenderer::PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe)
{
m_oPath.CurveTo(dX1, dY1, dX2, dY2, dXe, dYe);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandCurvesTo(double* pPoints, const int& nCount)
{
if (nCount < 8 || !pPoints)
return S_OK;
if (!m_oPath.IsMoveTo())
m_oPath.MoveTo(pPoints[0], pPoints[1]);
int nPointsCount = (nCount - 2) / 6;
double* pCur = pPoints + 2;
for (int nIndex = 0; nIndex <= nPointsCount; ++nIndex, pCur += 6)
{
m_oPath.CurveTo(pCur[0], pCur[1], pCur[2], pCur[3], pCur[4], pCur[5]);
}
return S_OK;
}
HRESULT CPdfRenderer::PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle)
{
m_oPath.ArcTo(dX, dY, dW, dH, dStartAngle, dSweepAngle);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandClose()
{
m_oPath.Close();
return S_OK;
}
HRESULT CPdfRenderer::PathCommandGetCurrentPoint(double* dX, double* dY)
{
m_oPath.GetLastPoint(*dX, *dY);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
m_oPath.AddText(m_oFont, lUnicode, dX, dY, dW, dH, dBaselineOffset);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandText(const std::wstring& wsText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
m_oPath.AddText(m_oFont, wsText, dX, dY, dW, dH, dBaselineOffset);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
m_oPath.AddText(m_oFont, lUnicode, lGid, dX, dY, dW, dH, dBaselineOffset, dwFlags);
return S_OK;
}
HRESULT CPdfRenderer::PathCommandTextEx(const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
m_oPath.AddText(m_oFont, wsUnicodeText, wsGidText, dX, dY, dW, dH, dBaselineOffset, dwFlags);
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH)
{
if (!IsPageValid() || !pImage)
return S_OK;
// TODO:
if (!DrawImage((Aggplus::CImage*)pImage, dX, dY, dW, dH, 255))
return S_FALSE;
return S_OK;
}
HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
{
if (!IsPageValid())
return S_OK;
// TODO:
Aggplus::CImage oAggImage(wsImagePath);
if (!DrawImage(&oAggImage, dX, dY, dW, dH, nAlpha))
return S_FALSE;
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY)
{
// TODO:
return S_OK;
}
HRESULT CPdfRenderer::ResetTransform()
{
// TODO:
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;
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::get_ClipMode(LONG* lMode)
{
*lMode = m_lClipMode;
return S_OK;
}
HRESULT CPdfRenderer::put_ClipMode(const LONG& lMode)
{
m_lClipMode = lMode;
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::CommandLong(const LONG& lType, const LONG& lCommand)
{
return S_OK;
}
HRESULT CPdfRenderer::CommandDouble(const LONG& lType, const double& dCommand)
{
return S_OK;
}
HRESULT CPdfRenderer::CommandString(const LONG& lType, const std::wstring& sCommand)
{
return S_OK;
}
//----------------------------------------------------------------------------------------
// Pdf
//----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::CommandDrawTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& wsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
return S_OK;
}
HRESULT CPdfRenderer::PathCommandTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& bsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
return S_OK;
}
HRESULT CPdfRenderer::DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWidth, const unsigned int& unHeight, const double& dX, const double& dY, const double& dW, const double& dH)
{
if (!IsPageValid() || !pImageBuffer)
return S_OK;
// TODO:
CImageDict* pPdfImage = m_pDocument->CreateImage();
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));
return S_OK;
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
bool CPdfRenderer::DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
{
int nImageW = abs((int)pImage->GetWidth());
int nImageH = abs((int)pImage->GetHeight());
BYTE* pData = pImage->GetData();
int nStride = 4 * nImageW;
// -
bool bAlpha = false;
for (int nIndex = 0, nSize = nImageW * nImageH; nIndex < nSize; nIndex++)
{
if (pData[4 * nIndex + 3] < 255)
{
bAlpha = true;
break;
}
}
CxImage oCxImage;
if (!oCxImage.CreateFromArray(pData, nImageW, nImageH, 32, nStride, (nStride >= 0) ? true : false))
return false;
BYTE* pBuffer = NULL;
int nBufferSize = 0;
if (!oCxImage.Encode(pBuffer, nBufferSize, CXIMAGE_FORMAT_JP2))
return false;
if (!pBuffer || !nBufferSize)
return false;
CImageDict* pPdfImage = m_pDocument->CreateImage();
if (bAlpha || nAlpha < 255)
pPdfImage->LoadSMask(pData, nImageW, nImageH, nAlpha);
pPdfImage->LoadJpx(pBuffer, nBufferSize, nImageW, nImageH);
m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH));
free(pBuffer);
return true;
}
......@@ -2,19 +2,29 @@
#define _PDF_WRITER_PDFRENDERER_H
#include "../DesktopEditor/graphics/IRenderer.h"
#include <string>
#include <vector>
#include <algorithm>
struct Pix;
namespace PdfWriter
{
class CDocument;
class CPage;
};
}
namespace Aggplus
{
class CImage;
}
class CPdfRenderer : public IRenderer
{
public:
CPdfRenderer();
~CPdfRenderer();
void SaveToFile(const std::wstring& wsPath);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
......@@ -32,151 +42,130 @@ public:
//----------------------------------------------------------------------------------------
// Pen
//----------------------------------------------------------------------------------------
virtual HRESULT get_PenColor(LONG* lColor) = 0;
virtual HRESULT put_PenColor(const LONG& lColor) = 0;
virtual HRESULT get_PenAlpha(LONG* lAlpha) = 0;
virtual HRESULT put_PenAlpha(const LONG& lAlpha) = 0;
virtual HRESULT get_PenSize(double* dSize) = 0;
virtual HRESULT put_PenSize(const double& dSize) = 0;
virtual HRESULT get_PenDashStyle(BYTE* val) = 0;
virtual HRESULT put_PenDashStyle(const BYTE& val) = 0;
virtual HRESULT get_PenLineStartCap(BYTE* val) = 0;
virtual HRESULT put_PenLineStartCap(const BYTE& val) = 0;
virtual HRESULT get_PenLineEndCap(BYTE* val) = 0;
virtual HRESULT put_PenLineEndCap(const BYTE& val) = 0;
virtual HRESULT get_PenLineJoin(BYTE* val) = 0;
virtual HRESULT put_PenLineJoin(const BYTE& val) = 0;
virtual HRESULT get_PenDashOffset(double* dOffset) = 0;
virtual HRESULT put_PenDashOffset(const double& dOffset) = 0;
virtual HRESULT get_PenAlign(LONG* lAlign) = 0;
virtual HRESULT put_PenAlign(const LONG& lAlign) = 0;
virtual HRESULT get_PenMiterLimit(double* dOffset) = 0;
virtual HRESULT put_PenMiterLimit(const double& dOffset) = 0;
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount)= 0;
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* nDashStyle);
virtual HRESULT put_PenDashStyle(const BYTE& nDashStyle);
virtual HRESULT get_PenLineStartCap(BYTE* nCapStyle);
virtual HRESULT put_PenLineStartCap(const BYTE& nCapStyle);
virtual HRESULT get_PenLineEndCap(BYTE* nCapStyle);
virtual HRESULT put_PenLineEndCap(const BYTE& nCapStyle);
virtual HRESULT get_PenLineJoin(BYTE* nJoinStyle);
virtual HRESULT put_PenLineJoin(const BYTE& nJoinStyle);
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* dMiter);
virtual HRESULT put_PenMiterLimit(const double& dMiter);
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount);
//----------------------------------------------------------------------------------------
// Brush
//----------------------------------------------------------------------------------------
virtual HRESULT get_BrushType(LONG* lType) = 0;
virtual HRESULT put_BrushType(const LONG& lType) = 0;
virtual HRESULT get_BrushColor1(LONG* lColor) = 0;
virtual HRESULT put_BrushColor1(const LONG& lColor) = 0;
virtual HRESULT get_BrushAlpha1(LONG* lAlpha) = 0;
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha) = 0;
virtual HRESULT get_BrushColor2(LONG* lColor) = 0;
virtual HRESULT put_BrushColor2(const LONG& lColor) = 0;
virtual HRESULT get_BrushAlpha2(LONG* lAlpha) = 0;
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha) = 0;
virtual HRESULT get_BrushTexturePath(std::wstring* bsPath) = 0;
virtual HRESULT put_BrushTexturePath(const std::wstring& bsPath) = 0;
virtual HRESULT get_BrushTextureMode(LONG* lMode) = 0;
virtual HRESULT put_BrushTextureMode(const LONG& lMode) = 0;
virtual HRESULT get_BrushTextureAlpha(LONG* lTxAlpha) = 0;
virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha) = 0;
virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0;
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 -------------------------------------------------------------------------------------
virtual HRESULT get_FontName(std::wstring* bsName) = 0;
virtual HRESULT put_FontName(const std::wstring& bsName) = 0;
virtual HRESULT get_FontPath(std::wstring* bsName) = 0;
virtual HRESULT put_FontPath(const std::wstring& bsName) = 0;
virtual HRESULT get_FontSize(double* dSize) = 0;
virtual HRESULT put_FontSize(const double& dSize) = 0;
virtual HRESULT get_FontStyle(LONG* lStyle) = 0;
virtual HRESULT put_FontStyle(const LONG& lStyle) = 0;
virtual HRESULT get_FontStringGID(INT* bGID) = 0;
virtual HRESULT put_FontStringGID(const INT& bGID) = 0;
virtual HRESULT get_FontCharSpace(double* dSpace) = 0;
virtual HRESULT put_FontCharSpace(const double& dSpace) = 0;
virtual HRESULT get_FontFaceIndex(int* lFaceIndex) = 0;
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex) = 0;
//-------- --------------------------------------------------------
virtual HRESULT CommandDrawTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset) = 0;
virtual HRESULT CommandDrawText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset) = 0;
virtual HRESULT CommandDrawTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) = 0;
virtual HRESULT CommandDrawTextEx(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) = 0;
virtual HRESULT CommandDrawTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& wsSrcCodeText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) { return 0; };
//-------- ---------------------------------------------------------------
virtual HRESULT BeginCommand(const DWORD& lType) = 0;
virtual HRESULT EndCommand(const DWORD& lType) = 0;
//-------- Graphics Path -----------------------------------------------
virtual HRESULT PathCommandMoveTo(const double& x, const double& y) = 0;
virtual HRESULT PathCommandLineTo(const double& x, const double& y) = 0;
virtual HRESULT PathCommandLinesTo(double* points, const int& count) = 0;
virtual HRESULT PathCommandCurveTo(const double& x1, const double& y1, const double& x2, const double& y2, const double& x3, const double& y3) = 0;
virtual HRESULT PathCommandCurvesTo(double* points, const int& count) = 0;
virtual HRESULT PathCommandArcTo(const double& x, const double& y, const double& w, const double& h, const double& startAngle, const double& sweepAngle) = 0;
virtual HRESULT PathCommandClose() = 0;
virtual HRESULT PathCommandEnd() = 0;
virtual HRESULT DrawPath(const LONG& nType) = 0;
virtual HRESULT PathCommandStart() = 0;
virtual HRESULT PathCommandGetCurrentPoint(double* x, double* y) = 0;
virtual HRESULT PathCommandTextCHAR(const LONG& c, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset) = 0;
virtual HRESULT PathCommandText(const std::wstring& bsText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset) = 0;
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) = 0;
virtual HRESULT PathCommandTextEx(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) = 0;
virtual HRESULT PathCommandTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& bsSrcCodeText, const double& x, const double& y, const double& w, const double& h, const double& baselineOffset, const DWORD& lFlags) { return 0; };
//-------- ---------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0;
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0;
// transform --------------------------------------------------------------------------------
virtual HRESULT GetCommandParams(double* dAngle, double* dLeft, double* dTop, double* dWidth, double* dHeight, DWORD* lFlags)
{
return S_OK;
}
virtual HRESULT SetCommandParams(double dAngle, double dLeft, double dTop, double dWidth, double dHeight, DWORD lFlags)
{
if ((dWidth <= 1) || (dHeight <= 1))
lFlags = 0;
INT bFlipX = (0 != (c_nParamFlipX & lFlags));
INT bFlipY = (0 != (c_nParamFlipY & lFlags));
float m11 = bFlipX ? -1.0f : 1.0f;
float m22 = bFlipY ? -1.0f : 1.0f;
Aggplus::CMatrix oMatrix(1, 0, 0, 1, 0, 0);
if ((0 != dAngle) || (0 != lFlags))
{
double dCentreX = (double)(dLeft + dWidth / 2.0);
double dCentreY = (double)(dTop + dHeight / 2.0);
oMatrix.Translate(-dCentreX, -dCentreY, Aggplus::MatrixOrderAppend);
oMatrix.Rotate(dAngle, Aggplus::MatrixOrderAppend);
oMatrix.Scale(m11, m22, Aggplus::MatrixOrderAppend);
oMatrix.Translate(dCentreX, dCentreY, Aggplus::MatrixOrderAppend);
}
double mass[6];
oMatrix.GetElements(mass);
SetTransform(mass[0], mass[1], mass[2], mass[3], mass[4], mass[5]);
return S_OK;
}
virtual HRESULT SetTransform(const double& m1, const double& m2, const double& m3, const double& m4, const double& m5, const double& m6) = 0;
virtual HRESULT GetTransform(double *pdA, double *pdB, double *pdC, double *pdD, double *pdE, double *pdF) = 0;
virtual HRESULT ResetTransform() = 0;
// -----------------------------------------------------------------------------------------
virtual HRESULT get_ClipMode(LONG* plMode) = 0;
virtual HRESULT put_ClipMode(const LONG& lMode) = 0;
// 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;
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* wsPath);
virtual HRESULT put_BrushTexturePath(const std::wstring& wsPath);
virtual HRESULT get_BrushTextureMode(LONG* lMode);
virtual HRESULT put_BrushTextureMode(const LONG& lMode);
virtual HRESULT get_BrushTextureAlpha(LONG* lAlpha);
virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha);
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* pColors, double* pPositions, LONG lCount);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT get_FontName(std::wstring* wsName);
virtual HRESULT put_FontName(const std::wstring& wsName);
virtual HRESULT get_FontPath(std::wstring* wsPath);
virtual HRESULT put_FontPath(const std::wstring& wsPath);
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& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset);
virtual HRESULT CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset);
virtual HRESULT 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);
virtual HRESULT CommandDrawTextEx(const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT BeginCommand(const DWORD& lType);
virtual HRESULT EndCommand(const DWORD& lType);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT PathCommandMoveTo(const double& dX, const double& dY);
virtual HRESULT PathCommandLineTo(const double& dX, const double& dY);
virtual HRESULT PathCommandLinesTo(double* pPoints, const int& nCount);
virtual HRESULT PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe);
virtual HRESULT PathCommandCurvesTo(double* pPoints, const int& nCount);
virtual HRESULT PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle);
virtual HRESULT PathCommandClose();
virtual HRESULT PathCommandEnd();
virtual HRESULT DrawPath(const LONG& lType);
virtual HRESULT PathCommandStart();
virtual HRESULT PathCommandGetCurrentPoint(double* dX, double* dY);
virtual HRESULT PathCommandTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset);
virtual HRESULT PathCommandText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset);
virtual HRESULT PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags);
virtual HRESULT PathCommandTextEx(const std::wstring& wsUnicodeText, const std::wstring& wsGidText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH);
virtual HRESULT DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha = 255);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY);
virtual HRESULT GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY);
virtual HRESULT ResetTransform();
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
virtual HRESULT get_ClipMode(LONG* lMode);
virtual HRESULT put_ClipMode(const LONG& lMode);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
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);
//----------------------------------------------------------------------------------------
// Pdf
//----------------------------------------------------------------------------------------
virtual HRESULT CommandDrawTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& wsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags);
virtual HRESULT PathCommandTextPdf(const std::wstring& bsUnicodeText, const std::wstring& bsGidText, const std::wstring& bsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags);
virtual HRESULT DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWidth, const unsigned int& unHeight, const double& dX, const double& dY, const double& dW, const double& dH);
private:
bool DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha);
private:
......@@ -184,13 +173,60 @@ private:
{
return m_bValid;
}
bool IsPageValid()
{
if (!IsValid() || !m_pPage)
return false;
return true;
}
void SetError()
{
m_bValid = true;
m_bValid = false;;
}
private:
struct TColor
{
TColor()
{
lColor = 0;
r = 0;
g = 0;
b = 0;
}
TColor(const LONG& lColor)
{
Set(lColor);
}
void Set(const LONG& _lColor)
{
lColor = _lColor;
r = (unsigned char)(lColor & 0xFF);
g = (unsigned char)((lColor >> 8) & 0xFF);
b = (unsigned char)((lColor >> 16) & 0xFF);
}
void operator=(const LONG& _lColor)
{
Set(lColor);
}
void Set(BYTE _r, BYTE _g, BYTE _b)
{
r = _r;
g = _g;
b = _b;
lColor = (LONG)(((LONG)r) | ((LONG)g << 8) | ((LONG)b << 16) | ((LONG)0 << 24));
}
LONG lColor;
BYTE r;
BYTE g;
BYTE b;
};
class CPenState
{
public:
......@@ -207,20 +243,19 @@ private:
}
inline LONG GetColor()
{
return m_lColor;
return m_oColor.lColor;
}
inline void SetColor(const LONG& lColor)
{
m_lColor = lColor;
UpdateColor();
m_oColor.Set(lColor);
}
inline LONG GetAlpha()
{
return m_nA;
return m_nAlpha;
}
inline void SetAlpha(const LONG& lAlpha)
{
m_nA = (BYTE)max(0, min(255, lAlpha));
m_nAlpha = (BYTE)max(0, min(255, lAlpha));
}
inline double GetSize()
{
......@@ -317,33 +352,19 @@ private:
if (m_pDashPattern)
delete[] m_pDashPattern;
m_lColor = 0;
m_oColor.Set(0);
m_dSize = 0;
m_nA = 255;
m_nAlpha = 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;
TColor m_oColor;
BYTE m_nAlpha;
BYTE m_nStartCapStyle;
BYTE m_nEndCapStyle;
BYTE m_nJoinStyle;
......@@ -357,12 +378,836 @@ private:
LONG m_lDashPatternSize;
};
class CBrushState
{
public:
CBrushState()
{
m_pShadingColors = NULL;
m_pShadingPoints = NULL;
m_lShadingPointsCount = 0;
}
~CBrushState()
{
if (m_pShadingColors)
delete[] m_pShadingColors;
if (m_pShadingPoints)
delete[] m_pShadingPoints;
}
inline LONG GetType()
{
return m_lType;
}
inline void SetType(const LONG& lType)
{
m_lType = lType;
}
inline LONG GetColor1()
{
return m_oColor1.lColor;
}
inline void SetColor1(const LONG& lColor)
{
m_oColor1.Set(lColor);
}
inline LONG GetColor2()
{
return m_oColor2.lColor;
}
inline void SetColor2(const LONG& lColor)
{
m_oColor2.Set(lColor);
}
inline LONG GetAlpha1()
{
return m_nAlpha1;
}
inline void SetAlpha1(const LONG& lAlpha)
{
m_nAlpha1 = (BYTE)max(0, min(255, lAlpha));
}
inline LONG GetAlpha2()
{
return m_nAlpha2;
}
inline void SetAlpha2(const LONG& lAlpha)
{
m_nAlpha2 = (BYTE)max(0, min(255, lAlpha));
}
inline std::wstring GetTexturePath()
{
return m_wsTexturePath;
}
inline void SetTexturePath(const std::wstring& wsPath)
{
m_wsTexturePath = wsPath;
}
inline LONG GetTextureMode()
{
return m_lTextureMode;
}
inline void SetTextureMode(const LONG& lMode)
{
m_lTextureMode = lMode;
}
inline BYTE GetTextureAlpha()
{
return m_nTextureAlpha;
}
inline void SetTextureAlpha(const LONG& lAlpha)
{
m_nTextureAlpha = (BYTE)max(0, min(255, lAlpha));
}
inline double GetLinearAngle()
{
return m_dLinearAngle;
}
inline void SetLinearAngle(const double& dAngle)
{
m_dLinearAngle = dAngle;
}
inline void SetShadingColors(LONG* pColors, double* pPoints, const LONG& lCount)
{
// , 0 1 .
if (m_pShadingColors)
{
delete[] m_pShadingColors;
m_pShadingColors = NULL;
}
if (m_pShadingPoints)
{
delete[] m_pShadingPoints;
m_pShadingPoints = NULL;
}
if (!pColors || !pPoints || !lCount)
return;
if (1 == lCount)
{
m_pShadingPoints = new double[2];
m_pShadingColors = new TColor[2];
if (!m_pShadingColors || !m_pShadingColors)
return;
m_pShadingPoints[0] = 0.0;
m_pShadingPoints[1] = 1.0;
m_pShadingColors[0] = pColors[0];
m_pShadingColors[1] = pColors[0];
}
else
{
std::vector<TColorAndPoint> vPoints;
for (LONG lIndex = 0; lIndex < lCount; lIndex++)
{
vPoints.push_back(TColorAndPoint(pColors[lIndex], pPoints[lIndex]));
}
std::sort(vPoints.begin(), vPoints.end(), TColorAndPoint::Compare);
LONG lMinIn = -1, lMaxIn = -1, lMinOut = -1, lMaxOut = -1;
for (LONG lIndex = 0; lIndex < lCount; lIndex++)
{
double dPoint = vPoints.at(lIndex).dPoint;
if (0 <= dPoint && dPoint <= 1)
{
if (-1 == lMinIn || dPoint < vPoints.at(lMinIn).dPoint)
lMinIn = lIndex;
if (-1 == lMaxOut || dPoint > vPoints.at(lMaxOut).dPoint)
lMaxOut = lIndex;
}
else if (dPoint < 0)
{
if (-1 == lMinOut || dPoint > vPoints.at(lMinOut).dPoint)
lMinOut = lIndex;
}
else// if (dPoint > 1)
{
if (-1 == lMaxOut || dPoint < vPoints.at(lMaxOut).dPoint)
lMaxOut = lIndex;
}
}
LONG lBeginIndex = lMinIn;
LONG lEndIndex = lMaxIn;
bool bNeed0 = true, bNeed1 = true;
if (-1 != lMinIn && vPoints.at(lMinIn).dPoint < 0.001)
{
bNeed0 = false;
lBeginIndex = lMinIn;
vPoints.at(lMinIn).dPoint = 0;
}
else if (-1 != lMinOut && vPoints.at(lMinOut).dPoint > -0.001)
{
bNeed0 = false;
lBeginIndex = lMinOut;
vPoints.at(lMinOut).dPoint = 0;
}
if (-1 != lMaxIn && vPoints.at(lMaxIn).dPoint > 0.999)
{
bNeed1 = false;
lEndIndex = lMaxIn;
vPoints.at(lEndIndex).dPoint = 1;
}
else if (-1 != lMaxOut && vPoints.at(lMaxOut).dPoint < 1.001)
{
bNeed1 = false;
lEndIndex = lMaxOut;
vPoints.at(lEndIndex).dPoint = 1;
}
std::vector<TColorAndPoint> vResPoints;
if (bNeed0)
{
LONG lIndex0, lIndex1;
if (-1 != lMinOut)
{
if (-1 != lMinIn)
{
lIndex0 = lMinOut;
lIndex1 = lMinIn;
}
else if (-1 != lMaxOut)
{
lIndex0 = lMinOut;
lIndex1 = lMaxOut;
}
else
{
lIndex0 = lMinIn - 1;
lIndex1 = lMinIn;
}
}
else
{
if (-1 != lMinIn)
{
lIndex0 = lMinIn;
lIndex1 = lMinIn + 1;
}
else
{
lIndex0 = lMaxOut;
lIndex1 = lMaxOut + 1;
}
}
LONG lColor0 = TColorAndPoint::GetLinearApprox(vPoints.at(lIndex0), vPoints.at(lIndex1), 0);
vResPoints.push_back(TColorAndPoint(lColor0, 0));
}
if (-1 != lBeginIndex && -1 != lEndIndex)
{
for (LONG lIndex = lBeginIndex; lIndex <= lEndIndex; lIndex++)
{
vResPoints.push_back(vPoints.at(lIndex));
}
}
if (bNeed1)
{
LONG lIndex0, lIndex1;
if (-1 != lMaxOut)
{
if (-1 != lMaxIn)
{
lIndex0 = lMaxIn;
lIndex1 = lMaxOut;
}
else if (-1 != lMinOut)
{
lIndex0 = lMinOut;
lIndex1 = lMaxOut;
}
else
{
lIndex0 = lMaxOut;
lIndex1 = lMaxOut + 1;
}
}
else
{
if (-1 != lMaxIn)
{
lIndex0 = lMaxIn - 1;
lIndex1 = lMaxIn;
}
else
{
lIndex0 = lMinOut - 1;
lIndex1 = lMinOut;
}
}
LONG lColor1 = TColorAndPoint::GetLinearApprox(vPoints.at(lIndex0), vPoints.at(lIndex1), 1);
vResPoints.push_back(TColorAndPoint(lColor1, 1));
}
LONG lResCount = vResPoints.size();
if (!lResCount)
return;
m_pShadingColors = new TColor[lResCount];
m_pShadingPoints = new double[lResCount];
m_lShadingPointsCount = lResCount;
if (!m_pShadingColors || !m_pShadingPoints)
return;
for (LONG lIndex = 0; lIndex < lResCount; lIndex++)
{
m_pShadingColors[lIndex] = vResPoints.at(lIndex).lColor;
m_pShadingPoints[lIndex] = vResPoints.at(lIndex).dPoint;
}
}
}
private:
struct TColorAndPoint
{
TColorAndPoint()
{
lColor = 0;
dPoint = 0;
bUse = false;
}
TColorAndPoint(const LONG& color, const double& point)
{
lColor = color;
dPoint = point;
bUse = true;
}
static bool Compare(const TColorAndPoint& oFirst, const TColorAndPoint& oSecond)
{
return (oFirst.dPoint < oSecond.dPoint);
}
static LONG GetLinearApprox(const TColorAndPoint& oPoint1, const TColorAndPoint& oPoint2, const double& dDstPoint)
{
double dPoint1 = oPoint1.dPoint;
double dPoint2 = oPoint2.dPoint;
LONG lColor1 = oPoint1.lColor;
LONG lColor2 = oPoint2.lColor;
double dDiff = dPoint2 - dPoint1;
if (abs(dDiff) < 0)
return lColor1;
TColor oColor1 = lColor1;
TColor oColor2 = lColor2;
BYTE r = (BYTE)max(0, min(255, (oColor1.r + (oColor2.r - oColor1.r) / dDiff * (dDstPoint - dPoint1))));
BYTE g = (BYTE)max(0, min(255, (oColor1.g + (oColor2.g - oColor1.g) / dDiff * (dDstPoint - dPoint1))));
BYTE b = (BYTE)max(0, min(255, (oColor1.b + (oColor2.b - oColor1.b) / dDiff * (dDstPoint - dPoint1))));
TColor oResColor;
oResColor.Set(r, g, b);
return oResColor.lColor;
}
LONG lColor;
double dPoint;
bool bUse;
};
private:
LONG m_lType;
TColor m_oColor1;
TColor m_oColor2;
BYTE m_nAlpha1;
BYTE m_nAlpha2;
std::wstring m_wsTexturePath;
LONG m_lTextureMode;
BYTE m_nTextureAlpha;
double m_dLinearAngle;
TColor* m_pShadingColors;
double* m_pShadingPoints;
LONG m_lShadingPointsCount;
};
class CFontState
{
public:
inline std::wstring GetName()
{
return m_wsName;
}
inline void SetName(const std::wstring& wsName)
{
m_wsName = wsName;
}
inline std::wstring GetPath()
{
return m_wsPath;
}
inline void SetPath(const std::wstring& wsPath)
{
m_wsPath = wsPath;
}
inline double GetSize()
{
return m_dSize;
}
inline void SetSize(const double& dSize)
{
m_dSize = dSize;
}
inline LONG GetFaceIndex()
{
return m_lFaceIndex;
}
inline void SetFaceIndex(const LONG& lFaceIndex)
{
m_lFaceIndex = lFaceIndex;
}
inline LONG GetStyle()
{
return m_lStyle;
}
inline void SetStyle(const LONG& lStyle)
{
m_lStyle = lStyle;
m_bBold = (lStyle & 1 ? true : false);
m_bItalic = (lStyle & 2 ? true : false);
}
inline bool GetGid()
{
return m_bGid;
}
inline void SetGid(const bool& bGid)
{
m_bGid = bGid;
}
inline double GetCharSpace()
{
return m_dCharSpace;
}
inline void SetCharSpace(const double& dCharSpace)
{
m_dCharSpace = dCharSpace;
}
private:
std::wstring m_wsName;
std::wstring m_wsPath;
double m_dSize;
bool m_bGid;
LONG m_lFaceIndex;
LONG m_lStyle;
bool m_bBold;
bool m_bItalic;
double m_dCharSpace;
};
enum EPathCommandType
{
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:
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:
double x;
double y;
};
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:
double x;
double y;
};
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:
double x1;
double y1;
double x2;
double y2;
double xe;
double ye;
};
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:
double x;
double y;
double w;
double h;
double startAngle;
double sweepAngle;
};
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;
dY = y;
}
EPathCommandType GetType()
{
return rendererpathcommand_TextChar;
}
public:
CFontState font;
LONG unicode;
double x;
double y;
double w;
double h;
double baseline;
};
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:
CFontState font;
std::wstring text;
double x;
double y;
double w;
double h;
double baseline;
};
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:
CFontState font;
LONG unicode;
LONG gid;
double x;
double y;
double w;
double h;
double baseline;
};
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:
CFontState font;
std::wstring unicodeText;
std::wstring gidText;
double x;
double y;
double w;
double h;
double baseline;
};
class CPath
{
public:
CPath()
{
m_bIsMoveTo = false;
}
~CPath()
{
Clear();
}
bool MoveTo(const double& dX, const double& dY)
{
m_bIsMoveTo = true;
return Add(new CPathMoveTo(dX, dY));
}
bool LineTo(const double& dX, const double& dY)
{
if (!m_bIsMoveTo)
MoveTo(dX, dY);
return Add(new CPathLineTo(dX, dY));
}
bool CurveTo(double dX1, double dY1, double dX2, double dY2, double dXE, double dYE)
{
if (!m_bIsMoveTo)
MoveTo(dX1, dY1);
return Add(new CPathCurveTo(dX1, dY1, dX2, dY2, dXE, dYE));
}
bool ArcTo(double dX, double dY, double dW, double dH, double dStart, double dSweep)
{
if (!m_bIsMoveTo)
MoveTo(dX, dY);
return Add(new CPathArcTo(dX, dY, dW, dH, dStart, dSweep));
}
bool AddText(const CFontState& oFont, const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
return Add(new CPathTextChar(oFont, lUnicode, dX, dY, dW, dH, dBaselineOffset));
}
bool AddText(const CFontState& oFont, const std::wstring& wsText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{
return Add(new CPathText(oFont, wsText, dX, dY, dW, dH, dBaselineOffset));
}
bool AddText(const CFontState& oFont, const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
{
return Add(new CPathTextExChar(oFont, lUnicode, lGid, dX, dY, dW, dH, dBaselineOffset));
}
bool AddText(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, const DWORD& dwFlags)
{
return Add(new CPathTextEx(oFont, wsUnicodeText, wsGidText, dX, dY, dW, dH, dBaselineOffset));
}
bool Close()
{
return Add(new CPathClose());
}
void Clear()
{
for (int nIndex = 0, nCount = m_vCommands.size(); nIndex < nCount; nIndex++)
{
CPathCommandBase* pCommand = m_vCommands.at(nIndex);
delete pCommand;
}
m_vCommands.clear();
m_bIsMoveTo = false;
}
bool IsMoveTo()
{
return m_bIsMoveTo;
}
void GetLastPoint(double& dX, double& dY)
{
if (m_vCommands.size() <= 0)
{
dX = 0;
dY = 0;
}
else
{
m_vCommands.at(m_vCommands.size() - 1)->GetLastPoint(dX, dY);
}
}
private:
bool Add(CPathCommandBase* pCommand)
{
if (pCommand)
{
m_vCommands.push_back(pCommand);
return true;
}
return false;
}
public:
std::vector<CPathCommandBase*> m_vCommands;
bool m_bIsMoveTo;
};
PdfWriter::CDocument* m_pDocument;
PdfWriter::CPage* m_pPage;
CPenState m_oPen;
CBrushState m_oBrush;
CFontState m_oFont;
CPath m_oPath;
LONG m_lClipMode;
bool m_bValid;
double m_dPageHeight;
......
......@@ -3,6 +3,8 @@
#include "stdafx.h"
#include "../PdfRenderer.h"
#include "../Src/Streams.h"
#include "../Src/Utils.h"
#include "../Src/Objects.h"
......@@ -30,6 +32,11 @@
#include "../../DesktopEditor/cximage/tiff/tiffio.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../../DesktopEditor/raster/Metafile/MetaFile.h"
#include <vector>
#ifdef DrawText
#undef DrawText
#endif
......@@ -821,19 +828,92 @@ void TestDocument9()
oPdf.Close();
}
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
{
std::vector<std::wstring> vwsNames;
std::wstring wsSearchPath = wsFolder;
wsSearchPath.append(L"*.");
wsSearchPath.append(wsExt);
WIN32_FIND_DATA oFindData;
HANDLE hFind = ::FindFirstFile(wsSearchPath.c_str(), &oFindData);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (!(oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
vwsNames.push_back(oFindData.cFileName);
}
} while (::FindNextFile(hFind, &oFindData));
::FindClose(hFind);
}
return vwsNames;
}
void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, const int nType)
{
CPdfRenderer oRenderer;
oMetaFile.Close();
std::wstring sExt;
switch (nType)
{
case MetaFile::c_lMetaEmf: sExt = L"emf"; break;
case MetaFile::c_lMetaWmf: sExt = L"wmf"; break;
case MetaFile::c_lMetaSvm: sExt = L"svm"; break;
}
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, sExt);
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{
oRenderer.NewPage();
std::wstring wsFilePath = wsFolderPath;
wsFilePath.append(vFiles.at(nIndex));
if (oMetaFile.LoadFromFile(wsFilePath.c_str()))
{
double dW = 210;
double dH = 297;
//double dW, dH, dX, dY;
//oMetaFile.GetBounds(&dX, &dY, &dW, &dH);
oRenderer.put_Width(dW);
oRenderer.put_Height(dH);
oMetaFile.DrawOnRenderer(&oRenderer, 0, 0, dW, dH);
oMetaFile.Close();
}
printf("%d of %d %S\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
}
oRenderer.SaveToFile(wsFolderPath + L"Out.pdf");
}
void TestMetafile()
{
CApplicationFonts oFonts;
oFonts.Initialize();
MetaFile::CMetaFile oMetaFile(&oFonts);
ConvertFolder(oMetaFile, L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
}
void main()
{
TestStreams();
TestObjects();
TestEncrypt();
TestDict();
TestDocument1();
TestDocument2();
TestDocument3();
TestDocument4();
TestDocument5();
TestDocument6();
TestDocument7();
TestDocument8();
TestDocument9();
//TestStreams();
//TestObjects();
//TestEncrypt();
//TestDict();
//TestDocument1();
//TestDocument2();
//TestDocument3();
//TestDocument4();
//TestDocument5();
//TestDocument6();
//TestDocument7();
//TestDocument8();
//TestDocument9();
TestMetafile();
}
......@@ -99,7 +99,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\DesktopEditor\freetype-2.5.2\include;..\..\..\DesktopEditor\agg-2.4\include;..\..\..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\DesktopEditor\freetype-2.5.2\include;..\..\DesktopEditor\agg-2.4\include;..\..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4018;4005;4267</DisableSpecificWarnings>
</ClCompile>
<Link>
......
......@@ -47,6 +47,22 @@ namespace PdfWriter
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_JPX_DECODE);
}
void CImageDict::LoadJpx(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight)
{
CMemoryStream* pStream = new CMemoryStream();
if (!pStream)
return;
pStream->Write(pBuffer, nBufferSize);
SetStream(m_pXref, pStream);
Add("Type", "XObject");
Add("Subtype", "Image");
Add("Height", unHeight);
Add("Width", unWidth);
Add("ColorSpace", "DeviceRGB");
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_JPX_DECODE);
}
void CImageDict::LoadJb2(const wchar_t* wsFilePath, unsigned int unWidth, unsigned int unHeight)
{
CFileStream* pStream = new CFileStream();
......@@ -108,16 +124,28 @@ namespace PdfWriter
Add("Height", unHeight);
Add("BitsPerComponent", 8);
}
void CImageDict::LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight)
void CImageDict::LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight, unsigned char unAlpha)
{
CMemoryStream* pStream = new CMemoryStream();
CMemoryStream* pStream = new CMemoryStream(unWidth * unHeight);
if (!pStream)
return;
if (255 != unAlpha)
{
double dKoef = unAlpha / 255.0;
for (unsigned int unIndex = 0, unSize = 4 * unWidth * unHeight; unIndex < unSize; unIndex += 4)
{
BYTE nChar = *(pBgra + unIndex + 3) * dKoef;
pStream->Write(&nChar, 1);
}
}
else
{
for (unsigned int unIndex = 0, unSize = 4 * unWidth * unHeight; unIndex < unSize; unIndex += 4)
{
pStream->Write(pBgra + unIndex + 3, 1);
}
}
CImageDict* pImageSMask = new CImageDict(m_pXref, m_pDocument);
if (!pImageSMask)
......
......@@ -28,10 +28,11 @@ namespace PdfWriter
void LoadJpeg(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadJpx(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadJpx(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight);
void LoadJb2(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadCCITT4(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadRaw(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight);
void LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight);
void LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight, unsigned char lAlpha = 255);
void LoadBW(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride);
void LoadBW(Pix* pPix, unsigned int unWidth, unsigned int unHeight);
......
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