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

Реализованы заливка пата хэтчами и текстурой. Исправлен баг с переворачиванием...

Реализованы заливка пата хэтчами и текстурой. Исправлен баг с переворачиванием картинок при отрисовке.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63209 954022d7-b5bf-4e40-9824-e11837661b57
parent 55bfcd1b
This diff is collapsed.
......@@ -13,6 +13,7 @@ namespace PdfWriter
class CDocument;
class CPage;
class CFontCidTrueType;
class CImageDict;
}
namespace Aggplus
......@@ -169,6 +170,7 @@ public:
private:
PdfWriter::CImageDict* LoadImage(Aggplus::CImage* pImage, 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();
void UpdateTransform();
......@@ -868,6 +870,7 @@ private:
{
}
virtual void Draw(PdfWriter::CPage* pPage) = 0;
virtual void UpdateBounds(double& dL, double& dT, double& dR, double& dB) = 0;
virtual void GetLastPoint(double& dX, double& dY) = 0;
virtual EPathCommandType GetType() = 0;
};
......@@ -885,6 +888,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_MoveTo;
......@@ -909,6 +913,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_LineTo;
......@@ -937,6 +942,7 @@ private:
dY = ye;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_CurveTo;
......@@ -970,6 +976,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_ArcTo;
......@@ -997,6 +1004,7 @@ private:
dY = 0;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_Close;
......@@ -1021,6 +1029,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_TextChar;
......@@ -1055,6 +1064,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_Text;
......@@ -1090,6 +1100,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_TextExChar;
......@@ -1126,6 +1137,7 @@ private:
dY = y;
}
void Draw(PdfWriter::CPage* pPage);
void UpdateBounds(double& dL, double& dT, double& dR, double& dB);
EPathCommandType GetType()
{
return rendererpathcommand_TextEx;
......@@ -1214,19 +1226,9 @@ private:
{
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);
}
}
void GetLastPoint(double& dX, double& dY);
void Draw(PdfWriter::CPage* pPage, bool bStroke, bool bFill, bool bEoFill);
void GetBounds(double& dL, double& dT, double& dR, double& dB);
private:
......@@ -1303,6 +1305,8 @@ private:
double m_dPageWidth;
bool m_bValid;
int m_nCounter; // TODO: ,
};
#endif // _PDF_WRITER_PDFRENDERER_H
\ No newline at end of file
......@@ -888,7 +888,7 @@ void ConvertFolder(std::wstring wsFolderPath, const int nType)
dY *= dPx2Mm;
double dAspect = dH / dW;
dW = 1000;
dW = 595.27;
dH = dAspect * dW;
oRenderer.put_Width(dW);
......
......@@ -15,6 +15,8 @@
#include "Shading.h"
#include "Pattern.h"
#include "../../DesktopEditor/agg-2.4/include/agg_span_hatch.h"
#ifdef CreateFont
#undef CreateFont
#endif
......@@ -471,4 +473,32 @@ namespace PdfWriter
{
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, eType);
}
CImageTilePattern*CDocument::CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch)
{
// TODO: Надо бы сделать мап, чтобы не создавать одинаковых паттернов
CImageDict* pImage = CreateImage();
BYTE* pBuffer = new BYTE[3 * HATCH_TX_SIZE * HATCH_TX_SIZE];
if (!pBuffer)
return NULL;
TColor oColor1(nR1, nG1, nB1);
TColor oColor2(nR2, nG2, nB2);
agg::GetHatchPattern<TColor>(wsHatch, (TColor*)pBuffer, oColor1, oColor2);
pImage->LoadRaw(pBuffer, 3 * HATCH_TX_SIZE * HATCH_TX_SIZE, HATCH_TX_SIZE, HATCH_TX_SIZE);
delete[] pBuffer;
if (255 != nAlpha1 || 255 != nAlpha2)
{
BYTE* pSMask = new BYTE[HATCH_TX_SIZE * HATCH_TX_SIZE];
if (pSMask)
{
agg::GetHatchPattern<BYTE>(wsHatch, pSMask, nAlpha1, nAlpha2);
pImage->LoadSMask(pSMask, (unsigned int)HATCH_TX_SIZE * HATCH_TX_SIZE, (unsigned int)HATCH_TX_SIZE, (unsigned int)HATCH_TX_SIZE);
delete[] pSMask;
}
}
return CreateImageTilePattern(dW, dH, pImage, imagetilepatterntype_Default);
}
}
......@@ -71,6 +71,7 @@ namespace PdfWriter
CShading* CreateAxialShading(double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, double* pPoints, int nCount);
CShading* CreateRaidalShading(double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, double* pPoints, int nCount);
CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, EImageTilePatternType eType = imagetilepatterntype_Default);
CImageTilePattern*CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch);
private:
......
......@@ -31,6 +31,22 @@ namespace PdfWriter
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_DCT_DECODE);
}
void CImageDict::LoadJpeg(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_DCT_DECODE);
}
void CImageDict::LoadJpx(const wchar_t* wsFilePath, unsigned int unWidth, unsigned int unHeight)
{
CFileStream* pStream = new CFileStream();
......@@ -107,7 +123,7 @@ namespace PdfWriter
}
void CImageDict::LoadRaw(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight)
{
CMemoryStream* pStream = new CMemoryStream();
CMemoryStream* pStream = new CMemoryStream(3 * unWidth * unHeight);
if (!pStream)
return;
......@@ -123,6 +139,22 @@ namespace PdfWriter
Add("Width", unWidth);
Add("Height", unHeight);
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_FLATE_DECODE);
}
void CImageDict::LoadRaw(const BYTE* pBuffer, unsigned int unSize, unsigned int unWidth, unsigned int unHeight)
{
CMemoryStream* pStream = new CMemoryStream(unSize);
if (!pStream)
return;
pStream->Write(pBuffer, unSize);
SetStream(m_pXref, pStream);
Add("Type", "XObject");
Add("Subtype", "Image");
Add("ColorSpace", "DeviceRGB");
Add("Width", unWidth);
Add("Height", unHeight);
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_FLATE_DECODE);
}
void CImageDict::LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight, unsigned char unAlpha)
{
......@@ -167,6 +199,27 @@ namespace PdfWriter
Add("SMask", pImageSMask);
}
void CImageDict::LoadSMask(const BYTE* pBuffer, unsigned int unSize, unsigned int unWidth, unsigned int unHeight)
{
CMemoryStream* pStream = new CMemoryStream(unSize);
if (!pStream)
return;
pStream->Write(pBuffer, unSize);
CImageDict* pImageSMask = new CImageDict(m_pXref, m_pDocument);
if (!pImageSMask)
return;
pImageSMask->SetStream(m_pXref, pStream);
pImageSMask->Add("Type", "XObject");
pImageSMask->Add("Subtype", "Image");
pImageSMask->Add("ColorSpace", "DeviceGray");
pImageSMask->Add("Width", unWidth);
pImageSMask->Add("Height", unHeight);
pImageSMask->Add("BitsPerComponent", 8);
pImageSMask->SetFilter(STREAM_FILTER_FLATE_DECODE);
Add("SMask", pImageSMask);
}
void CImageDict::LoadBW(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride)
{
SetStream(m_pXref, new CMemoryStream());
......
......@@ -27,12 +27,15 @@ namespace PdfWriter
CImageDict(CXref* pXref, CDocument* pDocument);
void LoadJpeg(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadJpeg(BYTE* pBuffer, int nBufferSize, 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 LoadRaw(const BYTE* pBuffer, unsigned int unSize, unsigned int unWidth, unsigned int unHeight);
void LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight, unsigned char lAlpha = 255);
void LoadSMask(const BYTE* pBuffer, unsigned int unSize, unsigned int unWidth, unsigned int unHeight);
void LoadBW(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride);
void LoadBW(Pix* pPix, unsigned int unWidth, unsigned int unHeight);
......
......@@ -426,10 +426,10 @@ namespace PdfWriter
dStartX = dX + dXRad * cos(AngToEllPrm(dAngle1, dXRad, dYRad));
dStartY = dY + dYRad * sin(AngToEllPrm(dAngle1, dXRad, dYRad));
m_pStream->WriteReal(dStartX);
m_pStream->WriteChar(' ');
m_pStream->WriteReal(dStartY);
m_pStream->WriteStr(" m\012");
//m_pStream->WriteReal(dStartX);
//m_pStream->WriteChar(' ');
//m_pStream->WriteReal(dStartY);
//m_pStream->WriteStr(" m\012");
// Дальше рисуем по четверям
double dCurX = dStartX, dCurY = dStartY;
......
......@@ -4,10 +4,16 @@
namespace PdfWriter
{
//----------------------------------------------------------------------------------------
// CPattern
//----------------------------------------------------------------------------------------
CPattern::CPattern(CXref* pXref) : CDictObject(pXref, true)
{
}
//----------------------------------------------------------------------------------------
// CImageTilePattern
//----------------------------------------------------------------------------------------
CImageTilePattern::CImageTilePattern(CXref* pXref, double dW, double dH, CImageDict* pImageDict, EImageTilePatternType eType) : CDictObject(pXref, true)
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, EImageTilePatternType eType) : CPattern(pXref)
{
Add("Type", "Pattern");
Add("PatternType", 1);
......
......@@ -7,12 +7,20 @@ namespace PdfWriter
{
class CImageDict;
//----------------------------------------------------------------------------------------
// CPattern
//----------------------------------------------------------------------------------------
class CPattern : public CDictObject
{
public:
CPattern(CXref* pXref);
};
//----------------------------------------------------------------------------------------
// CImageTilePattern
//----------------------------------------------------------------------------------------
class CImageTilePattern : public CDictObject
class CImageTilePattern : public CPattern
{
public:
CImageTilePattern(CXref* pXref, double dW, double dH, CImageDict* pImageDict, EImageTilePatternType eType = imagetilepatterntype_Default);
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, EImageTilePatternType eType = imagetilepatterntype_Default);
};
}
......
......@@ -181,6 +181,26 @@ namespace PdfWriter
return false;
}
};
struct TColor
{
unsigned char r;
unsigned char g;
unsigned char b;
public:
TColor()
{
r = 0;
g = 0;
b = 0;
}
TColor(const unsigned char& R, const unsigned char& G, const unsigned char& B)
{
r = R;
g = G;
b = B;
}
};
enum EPageLayout
{
pagelayout_Single = 0,
......
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