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

Реализованы градиенты. Реализована прозрачность в градиентах. Сделан конвертер из бинарника в Pdf.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63265 954022d7-b5bf-4e40-9824-e11837661b57
parent 2d5f7b32
This diff is collapsed.
#ifndef _PDF_WRITER_ONLINEOFFICEBINTOPDF_H
#define _PDF_WRITER_ONLINEOFFICEBINTOPDF_H
#include <string>
#include "PdfRenderer.h"
namespace NSOnlineOfficeBinToPdf
{
bool ConvertBinToPdf(CPdfRenderer* pPdf, const std::wstring& wsSrcFile, const std::wstring& wsDstFile, bool bBinary);
};
#endif // _PDF_WRITER_ONLINEOFFICEBINTOPDF_H
This diff is collapsed.
This diff is collapsed.
...@@ -141,6 +141,7 @@ ...@@ -141,6 +141,7 @@
<Text Include="ReadMe.txt" /> <Text Include="ReadMe.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="OnlineOfficeBinToPdf.cpp" />
<ClCompile Include="PdfRenderer.cpp" /> <ClCompile Include="PdfRenderer.cpp" />
<ClCompile Include="Src\Annotation.cpp" /> <ClCompile Include="Src\Annotation.cpp" />
<ClCompile Include="Src\Catalog.cpp" /> <ClCompile Include="Src\Catalog.cpp" />
...@@ -164,6 +165,7 @@ ...@@ -164,6 +165,7 @@
<ClCompile Include="Src\Utils.cpp" /> <ClCompile Include="Src\Utils.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="OnlineOfficeBinToPdf.h" />
<ClInclude Include="PdfRenderer.h" /> <ClInclude Include="PdfRenderer.h" />
<ClInclude Include="Src\Annotation.h" /> <ClInclude Include="Src\Annotation.h" />
<ClInclude Include="Src\Catalog.h" /> <ClInclude Include="Src\Catalog.h" />
......
...@@ -90,6 +90,9 @@ ...@@ -90,6 +90,9 @@
<ClCompile Include="PdfRenderer.cpp"> <ClCompile Include="PdfRenderer.cpp">
<Filter>Src</Filter> <Filter>Src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="OnlineOfficeBinToPdf.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Src\Annotation.h"> <ClInclude Include="Src\Annotation.h">
...@@ -161,5 +164,8 @@ ...@@ -161,5 +164,8 @@
<ClInclude Include="PdfRenderer.h"> <ClInclude Include="PdfRenderer.h">
<Filter>Src</Filter> <Filter>Src</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="OnlineOfficeBinToPdf.h">
<Filter>Src</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -381,7 +381,9 @@ void TestDocument3() ...@@ -381,7 +381,9 @@ void TestDocument3()
pPage->ClosePath(); pPage->ClosePath();
pPage->EoFillStroke(); pPage->EoFillStroke();
pPage->SetExtGrState(oPdf.GetExtGState(0.8, 0.8)); //pPage->SetExtGrState(oPdf.GetExtGState(0.8, 0.8));
pPage->SetStrokeAlpha(20);
pPage->SetFillAlpha(20);
pPage->SetFillColor(15, 15, 120); pPage->SetFillColor(15, 15, 120);
pPage->MoveTo(230, 210); pPage->MoveTo(230, 210);
pPage->LineTo(320, 210); pPage->LineTo(320, 210);
...@@ -404,7 +406,9 @@ void TestDocument3() ...@@ -404,7 +406,9 @@ void TestDocument3()
pPage->Clip(); pPage->Clip();
pPage->EndPath(); pPage->EndPath();
pPage->SetExtGrState(oPdf.GetExtGState(0.5, 0.5)); pPage->SetStrokeAlpha(122);
pPage->SetFillAlpha(122);
//pPage->SetExtGrState(oPdf.GetExtGState(0.5, 0.5));
pPage->MoveTo(230, 310); pPage->MoveTo(230, 310);
pPage->LineTo(320, 310); pPage->LineTo(320, 310);
pPage->LineTo(320, 340); pPage->LineTo(320, 340);
...@@ -749,9 +753,11 @@ void TestDocument8() ...@@ -749,9 +753,11 @@ void TestDocument8()
0, 0, 255 0, 0, 255
}; };
double pPoints[] ={0, 1}; unsigned char pAlphas[] ={ 255, 255 };
CExtGrState* pExtGrState = NULL;
CShading* pShading = oPdf.CreateAxialShading(200, 150, 200, 250, pColors, pPoints, 2); double pPoints[] ={0, 1};
CShading* pShading = oPdf.CreateAxialShading(pPage, 200, 150, 200, 250, pColors, pAlphas, pPoints, 2, pExtGrState);
pPage->DrawShading(pShading); pPage->DrawShading(pShading);
pPage->GrRestore(); pPage->GrRestore();
...@@ -768,10 +774,11 @@ void TestDocument8() ...@@ -768,10 +774,11 @@ void TestDocument8()
255, 255, 255, 255, 255, 255,
0, 0, 255 0, 0, 255
}; };
unsigned char pAlphas2[] ={ 255, 255, 255, 255 };
double pPoints2[] ={ 0, 0.3, 0.7, 1 }; double pPoints2[] ={ 0, 0.3, 0.7, 1 };
CShading* pShading2 = oPdf.CreateAxialShading(400, 150, 400, 250, pColors2, pPoints2, nCount2); CShading* pShading2 = oPdf.CreateAxialShading(pPage, 400, 150, 400, 250, pColors2, pAlphas2, pPoints2, nCount2, pExtGrState);
pPage->DrawShading(pShading2); pPage->DrawShading(pShading2);
pPage->GrRestore(); pPage->GrRestore();
...@@ -788,10 +795,11 @@ void TestDocument8() ...@@ -788,10 +795,11 @@ void TestDocument8()
255, 255, 0, 255, 255, 0,
0, 0, 255 0, 0, 255
}; };
unsigned char pAlphas3[] ={ 255, 255, 255 };
double pPoints3[] ={ 0, 0.5, 1 }; double pPoints3[] ={ 0, 0.5, 1 };
CShading* pShading3 = oPdf.CreateRaidalShading(200, 375, 20, 200, 425, 100, pColors3, pPoints3, nCount3); CShading* pShading3 = oPdf.CreateRadialShading(pPage, 200, 375, 20, 200, 425, 100, pColors3, pAlphas3, pPoints3, nCount3, pExtGrState);
pPage->DrawShading(pShading3); pPage->DrawShading(pShading3);
pPage->GrRestore(); pPage->GrRestore();
...@@ -814,7 +822,7 @@ void TestDocument9() ...@@ -814,7 +822,7 @@ void TestDocument9()
CImageDict* pJpegImage = oPdf.CreateImage(); CImageDict* pJpegImage = oPdf.CreateImage();
pJpegImage->LoadJpeg(L"D:/Test Files/Test.jpg", 600, 400); pJpegImage->LoadJpeg(L"D:/Test Files/Test.jpg", 600, 400);
CImageTilePattern* pPattern = oPdf.CreateImageTilePattern(70, 70, pJpegImage, imagetilepatterntype_InverseX); CImageTilePattern* pPattern = oPdf.CreateImageTilePattern(70, 70, pJpegImage, NULL, imagetilepatterntype_InverseX);
pPage->GrSave(); pPage->GrSave();
pPage->SetPatternColorSpace(pPattern); pPage->SetPatternColorSpace(pPattern);
...@@ -908,6 +916,27 @@ void TestMetafile() ...@@ -908,6 +916,27 @@ void TestMetafile()
//ConvertFolder(L"D://Test Files//Emf//", MetaFile::c_lMetaEmf); //ConvertFolder(L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
ConvertFolder(L"D://Test Files//Wmf//", MetaFile::c_lMetaWmf); ConvertFolder(L"D://Test Files//Wmf//", MetaFile::c_lMetaWmf);
} }
void TestOnlineBin()
{
std::wstring wsFolderPath = L"D://Test Files//Txt//";
CApplicationFonts oFonts;
oFonts.Initialize();
double dPx2Mm = 25.4 / 96;
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"txt");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{
std::wstring wsFilePath = wsFolderPath;
wsFilePath.append(vFiles.at(nIndex));
std::wstring wsOutPath = wsFolderPath + L"Out.pdf";
CPdfRenderer oRenderer(&oFonts);
oRenderer.OnlineWordToPdf(wsFilePath, wsOutPath);
printf("%d of %d %S\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
}
}
void main() void main()
{ {
...@@ -924,6 +953,6 @@ void main() ...@@ -924,6 +953,6 @@ void main()
//TestDocument7(); //TestDocument7();
//TestDocument8(); //TestDocument8();
//TestDocument9(); //TestDocument9();
//TestMetafile();
TestMetafile(); TestOnlineBin();
} }
...@@ -43,6 +43,7 @@ namespace PdfWriter ...@@ -43,6 +43,7 @@ namespace PdfWriter
m_unCompressMode = COMP_NONE; m_unCompressMode = COMP_NONE;
m_pJbig2 = NULL; m_pJbig2 = NULL;
memset((void*)m_sTTFontTag, 0x00, 8); memset((void*)m_sTTFontTag, 0x00, 8);
m_pTransparencyGroup = NULL;
} }
CDocument::~CDocument() CDocument::~CDocument()
{ {
...@@ -65,7 +66,7 @@ namespace PdfWriter ...@@ -65,7 +66,7 @@ namespace PdfWriter
return false; return false;
m_pCatalog->SetPageMode(pagemode_UseNone); m_pCatalog->SetPageMode(pagemode_UseNone);
m_pCatalog->SetPageLayout(pagelayout_Single); m_pCatalog->SetPageLayout(pagelayout_OneColumn);
m_pPageTree = m_pCatalog->GetRoot(); m_pPageTree = m_pCatalog->GetRoot();
if (!m_pPageTree) if (!m_pPageTree)
...@@ -81,6 +82,11 @@ namespace PdfWriter ...@@ -81,6 +82,11 @@ namespace PdfWriter
m_nCurPageNum = -1; m_nCurPageNum = -1;
m_vPages.clear(); m_vPages.clear();
m_vExtGrStates.clear();
m_vFillAlpha.clear();
m_vStrokeAlpha.clear();
m_pTransparencyGroup = NULL;
return true; return true;
} }
...@@ -186,7 +192,7 @@ namespace PdfWriter ...@@ -186,7 +192,7 @@ namespace PdfWriter
} }
CPage* CDocument::AddPage() CPage* CDocument::AddPage()
{ {
CPage* pPage = new CPage(m_pXref, m_pPageTree); CPage* pPage = new CPage(m_pXref, m_pPageTree, this);
m_pPageTree->AddPage(pPage); m_pPageTree->AddPage(pPage);
m_pCurPage = pPage; m_pCurPage = pPage;
m_vPages.push_back(pPage); m_vPages.push_back(pPage);
...@@ -330,6 +336,44 @@ namespace PdfWriter ...@@ -330,6 +336,44 @@ namespace PdfWriter
return pExtGrState; return pExtGrState;
} }
CExtGrState* CDocument::GetStrokeAlpha(double dAlpha)
{
CExtGrState* pExtGrState = NULL;
for (unsigned int unIndex = 0, unCount = m_vStrokeAlpha.size(); unIndex < unCount; unIndex++)
{
pExtGrState = m_vStrokeAlpha.at(unIndex);
if (abs(dAlpha - pExtGrState->GetAlphaStroke()) < 0.001)
return pExtGrState;
}
pExtGrState = new CExtGrState(m_pXref);
if (!pExtGrState)
return NULL;
pExtGrState->SetAlphaStroke(dAlpha);
m_vStrokeAlpha.push_back(pExtGrState);
return pExtGrState;
}
CExtGrState* CDocument::GetFillAlpha(double dAlpha)
{
CExtGrState* pExtGrState = NULL;
for (unsigned int unIndex = 0, unCount = m_vFillAlpha.size(); unIndex < unCount; unIndex++)
{
pExtGrState = m_vFillAlpha.at(unIndex);
if (abs(dAlpha == pExtGrState->GetAlphaFill()) < 0.001)
return pExtGrState;
}
pExtGrState = new CExtGrState(m_pXref);
if (!pExtGrState)
return NULL;
pExtGrState->SetAlphaFill(dAlpha);
m_vFillAlpha.push_back(pExtGrState);
return pExtGrState;
}
CAnnotation* CDocument::CreateTextAnnot(unsigned int unPageNum, TRect oRect, const char* sText) CAnnotation* CDocument::CreateTextAnnot(unsigned int unPageNum, TRect oRect, const char* sText)
{ {
CAnnotation* pAnnot = new CTextAnnotation(m_pXref, oRect, sText); CAnnotation* pAnnot = new CTextAnnotation(m_pXref, oRect, sText);
...@@ -423,6 +467,96 @@ namespace PdfWriter ...@@ -423,6 +467,96 @@ namespace PdfWriter
return m_pJbig2; return m_pJbig2;
} }
CShading* CDocument::CreateShading(CPage* pPage, double *pPattern, bool bAxial, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState)
{
pExtGrState = NULL;
bool bNeedAlpha = false;
unsigned char* pA = new unsigned char[3 * nCount];
if (!pA)
return NULL;
for (int nIndex = 0; nIndex < nCount; nIndex++)
{
pA[3 * nIndex + 0] = pAlphas[nIndex];
pA[3 * nIndex + 1] = pAlphas[nIndex];
pA[3 * nIndex + 2] = pAlphas[nIndex];
if (255 != pAlphas[nIndex])
bNeedAlpha = true;
}
if (!bNeedAlpha)
{
delete[] pA;
if (bAxial)
return CreateAxialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pColors, pPoints, nCount);
else
return CreateRadialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pPattern[4], pPattern[5], pColors, pPoints, nCount);
}
// Создаем 2 shading-объекта, один цветной RGB, второй серый со значениями альфа-канала
CShading* pColorShading = NULL;
CShading* pAlphaShading = NULL;
if (bAxial)
{
pColorShading = CreateAxialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pColors, pPoints, nCount);
pAlphaShading = CreateAxialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pA, pPoints, nCount);
}
else
{
pColorShading = CreateRadialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pPattern[4], pPattern[5], pColors, pPoints, nCount);
pAlphaShading = CreateRadialShading(pPattern[0], pPattern[1], pPattern[2], pPattern[3], pPattern[4], pPattern[5], pA, pPoints, nCount);
}
delete[] pA;
if (!m_pTransparencyGroup)
{
m_pTransparencyGroup = new CDictObject();
m_pTransparencyGroup->Add("Type", "Group");
m_pTransparencyGroup->Add("S", "Transparency");
m_pTransparencyGroup->Add("CS", "DeviceRGB");
}
pPage->Add("Group", m_pTransparencyGroup);
double dWidth = pPage->GetWidth();
double dHeight = pPage->GetHeight();
// Создаем графический объект, который будет альфа-маской
CDictObject* pXObject = new CDictObject(m_pXref, true);
pXObject->Add("Type", "XObject");
pXObject->Add("Subtype", "Form");
pXObject->Add("BBox", CArrayObject::CreateBox(0, 0, dWidth, dHeight));
pXObject->Add("Group", m_pTransparencyGroup);
CDictObject* pResources = new CDictObject();
pXObject->Add("Resources", pResources);
CDictObject* pResShadings = new CDictObject();
pResources->Add("Shading", pResShadings);
pResShadings->Add("S1", pAlphaShading);
CStream* pStream = pXObject->GetStream();
pStream->WriteStr("0 0 ");
pStream->WriteReal(dWidth);
pStream->WriteChar(' ');
pStream->WriteReal(dHeight);
pStream->WriteStr(" re\012W\012\n\012/S1 sh\012");
// Создаем обект-маску для графического состояние
CDictObject* pMask = new CDictObject();
m_pXref->Add(pMask);
pMask->Add("Type", "Mask");
pMask->Add("S", "Luminosity");
pMask->Add("G", pXObject);
// Создаем ExtGState объект, в который мы запишем альфа-маску
pExtGrState = new CExtGrState(m_pXref);
pExtGrState->Add("BM", "Normal");
pExtGrState->Add("ca", 1);
pExtGrState->Add("SMask", pMask);
return pColorShading;
}
CShading* CDocument::CreateAxialShading(double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, double* pPoints, int nCount) CShading* CDocument::CreateAxialShading(double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, double* pPoints, int nCount)
{ {
for (int nIndex = 0, nShadingsCount = m_vShadings.size(); nIndex < nShadingsCount; nIndex++) for (int nIndex = 0, nShadingsCount = m_vShadings.size(); nIndex < nShadingsCount; nIndex++)
...@@ -430,7 +564,7 @@ namespace PdfWriter ...@@ -430,7 +564,7 @@ namespace PdfWriter
CShading* pShading = m_vShadings.at(nIndex); CShading* pShading = m_vShadings.at(nIndex);
if (shadingtype_Axial == pShading->GetShadingType() if (shadingtype_Axial == pShading->GetShadingType()
&& ((CAxialShading*)pShading)->Compare(dX0, dY0, dX1, dY1) && ((CAxialShading*)pShading)->Compare(dX0, dY0, dX1, dY1)
&& pShading->CompareColors(pColors, pPoints, nCount) && pShading->CompareColors(pColors, pPoints, nCount, true)
&& pShading->CompareExtend(true, true)) && pShading->CompareExtend(true, true))
return pShading; return pShading;
} }
...@@ -439,21 +573,21 @@ namespace PdfWriter ...@@ -439,21 +573,21 @@ namespace PdfWriter
if (!pShading) if (!pShading)
return NULL; return NULL;
pShading->SetColors(pColors, pPoints, nCount); pShading->SetRgbColors(pColors, pPoints, nCount);
pShading->SetExtend(true, true); pShading->SetExtend(true, true);
m_vShadings.push_back(pShading); m_vShadings.push_back(pShading);
return pShading; return pShading;
} }
CShading* CDocument::CreateRaidalShading(double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, double* pPoints, int nCount) CShading* CDocument::CreateRadialShading(double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, double* pPoints, int nCount)
{ {
for (int nIndex = 0, nShadingsCount = m_vShadings.size(); nIndex < nShadingsCount; nIndex++) for (int nIndex = 0, nShadingsCount = m_vShadings.size(); nIndex < nShadingsCount; nIndex++)
{ {
CShading* pShading = m_vShadings.at(nIndex); CShading* pShading = m_vShadings.at(nIndex);
if (shadingtype_Radial == pShading->GetShadingType() if (shadingtype_Radial == pShading->GetShadingType()
&& ((CRadialShading*)pShading)->Compare(dX0, dY0, dR0, dX1, dY1, dR1) && ((CRadialShading*)pShading)->Compare(dX0, dY0, dR0, dX1, dY1, dR1)
&& pShading->CompareColors(pColors, pPoints, nCount) && pShading->CompareColors(pColors, pPoints, nCount, true)
&& pShading->CompareExtend(true, true)) && pShading->CompareExtend(true, true))
return pShading; return pShading;
} }
...@@ -462,16 +596,16 @@ namespace PdfWriter ...@@ -462,16 +596,16 @@ namespace PdfWriter
if (!pShading) if (!pShading)
return NULL; return NULL;
pShading->SetColors(pColors, pPoints, nCount); pShading->SetRgbColors(pColors, pPoints, nCount);
pShading->SetExtend(true, true); pShading->SetExtend(true, true);
m_vShadings.push_back(pShading); m_vShadings.push_back(pShading);
return pShading; return pShading;
} }
CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, EImageTilePatternType eType) CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType)
{ {
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, eType); return new CImageTilePattern(m_pXref, dW, dH, pImageDict, pMatrix, 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) 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)
{ {
...@@ -499,6 +633,16 @@ namespace PdfWriter ...@@ -499,6 +633,16 @@ namespace PdfWriter
} }
} }
return CreateImageTilePattern(dW, dH, pImage, imagetilepatterntype_Default); return CreateImageTilePattern(dW, dH, pImage, NULL, imagetilepatterntype_Default);
}
CShading* CDocument::CreateAxialShading(CPage* pPage, double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState)
{
double pPattern[] ={ dX0, dY0, dX1, dY1 };
return CreateShading(pPage, pPattern, true, pColors, pAlphas, pPoints, nCount, pExtGrState);
}
CShading* CDocument::CreateRadialShading(CPage* pPage, double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState)
{
double pPattern[] ={ dX0, dY0, dR0, dX1, dY1, dR1 };
return CreateShading(pPage, pPattern, false, pColors, pAlphas, pPoints, nCount, pExtGrState);
} }
} }
...@@ -32,6 +32,7 @@ namespace PdfWriter ...@@ -32,6 +32,7 @@ namespace PdfWriter
class CJbig2Global; class CJbig2Global;
class CShading; class CShading;
class CImageTilePattern; class CImageTilePattern;
class CPattern;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// CDocument // CDocument
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -58,6 +59,8 @@ namespace PdfWriter ...@@ -58,6 +59,8 @@ namespace PdfWriter
CDestination* CreateDestination(unsigned int unPageIndex); CDestination* CreateDestination(unsigned int unPageIndex);
CExtGrState* GetExtGState(double dAlphaStroke = -1, double dAlphaFill = -1, EBlendMode eMode = blendmode_Unknown, int nStrokeAdjustment = -1); CExtGrState* GetExtGState(double dAlphaStroke = -1, double dAlphaFill = -1, EBlendMode eMode = blendmode_Unknown, int nStrokeAdjustment = -1);
CExtGrState* GetStrokeAlpha(double dAlpha);
CExtGrState* GetFillAlpha(double dAlpha);
CJbig2Global* GetJbig2Global(); CJbig2Global* GetJbig2Global();
CAnnotation* CreateTextAnnot(unsigned int unPageNum, TRect oRect, const char* sText); CAnnotation* CreateTextAnnot(unsigned int unPageNum, TRect oRect, const char* sText);
...@@ -68,10 +71,10 @@ namespace PdfWriter ...@@ -68,10 +71,10 @@ namespace PdfWriter
CFont14* CreateFont14(EStandard14Fonts eType); CFont14* CreateFont14(EStandard14Fonts eType);
CFontCidTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex); CFontCidTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex);
CShading* CreateAxialShading(double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, double* pPoints, int nCount); CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
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); 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);
CShading* CreateAxialShading(CPage* pPage, double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
CShading* CreateRadialShading(CPage* pPage, double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
private: private:
...@@ -80,6 +83,9 @@ namespace PdfWriter ...@@ -80,6 +83,9 @@ namespace PdfWriter
void SaveToStream(CStream* pStream); void SaveToStream(CStream* pStream);
void PrepareEncryption(); void PrepareEncryption();
CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix); CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix);
CShading* CreateShading(CPage* pPage, double *pPattern, bool bAxial, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
CShading* CreateAxialShading(double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, double* pPoints, int nCount);
CShading* CreateRadialShading(double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, double* pPoints, int nCount);
private: private:
...@@ -111,10 +117,13 @@ namespace PdfWriter ...@@ -111,10 +117,13 @@ namespace PdfWriter
unsigned int m_unCompressMode; unsigned int m_unCompressMode;
std::vector<CPage*> m_vPages; std::vector<CPage*> m_vPages;
std::vector<CExtGrState*> m_vExtGrStates; std::vector<CExtGrState*> m_vExtGrStates;
std::vector<CExtGrState*> m_vStrokeAlpha;
std::vector<CExtGrState*> m_vFillAlpha;
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; std::vector<TFontInfo> m_vTTFonts;
CDictObject* m_pTransparencyGroup;
friend class CFontCidTrueType; friend class CFontCidTrueType;
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "Image.h" #include "Image.h"
#include "Shading.h" #include "Shading.h"
#include "Pattern.h" #include "Pattern.h"
#include "Document.h"
#ifdef DrawText #ifdef DrawText
#undef DrawText #undef DrawText
...@@ -165,11 +166,12 @@ namespace PdfWriter ...@@ -165,11 +166,12 @@ namespace PdfWriter
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// CPage // CPage
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
CPage::CPage(CXref* pXref, CPageTree* pParent) CPage::CPage(CXref* pXref, CPageTree* pParent, CDocument* pDocument)
{ {
pXref->Add(this); pXref->Add(this);
m_pXref = pXref; m_pXref = pXref;
m_pDocument = pDocument;
m_pContents = new CDictObject(pXref); m_pContents = new CDictObject(pXref);
m_pStream = m_pContents->GetStream(); m_pStream = m_pContents->GetStream();
m_eGrMode = grmode_PAGE; m_eGrMode = grmode_PAGE;
...@@ -1087,6 +1089,18 @@ namespace PdfWriter ...@@ -1087,6 +1089,18 @@ namespace PdfWriter
m_pStream->WriteEscapeName(sShadingName); m_pStream->WriteEscapeName(sShadingName);
m_pStream->WriteStr(" sh\012"); m_pStream->WriteStr(" sh\012");
} }
void CPage::SetStrokeAlpha(unsigned char unAlpha)
{
CExtGrState* pExtGrState = m_pDocument->GetStrokeAlpha((double)(unAlpha / 255.0));
if (pExtGrState)
SetExtGrState(pExtGrState);
}
void CPage::SetFillAlpha(unsigned char unAlpha)
{
CExtGrState* pExtGrState = m_pDocument->GetFillAlpha((double)(unAlpha / 255.0));
if (pExtGrState)
SetExtGrState(pExtGrState);
}
const char* CPage::GetLocalShadingName(CShading* pShading) const char* CPage::GetLocalShadingName(CShading* pShading)
{ {
if (!m_pShadings) if (!m_pShadings)
...@@ -1162,4 +1176,17 @@ namespace PdfWriter ...@@ -1162,4 +1176,17 @@ namespace PdfWriter
m_pStream->WriteEscapeName(sPatternName); m_pStream->WriteEscapeName(sPatternName);
m_pStream->WriteStr(" scn\012"); m_pStream->WriteStr(" scn\012");
} }
void CPage::SetFilter(unsigned int unFiler)
{
if (m_pContents)
m_pContents->SetFilter(unFiler);
}
CMatrix* CPage::GetTransform()
{
return &m_pGrState->m_oMatrix;
}
void CPage::AddGroup(CDictObject* pDict)
{
Add("Group", pDict);
}
} }
\ No newline at end of file
...@@ -18,6 +18,7 @@ namespace PdfWriter ...@@ -18,6 +18,7 @@ namespace PdfWriter
class CImageDict; class CImageDict;
class CShading; class CShading;
class CImageTilePattern; class CImageTilePattern;
class CDocument;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// CPageTree // CPageTree
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -40,7 +41,7 @@ namespace PdfWriter ...@@ -40,7 +41,7 @@ namespace PdfWriter
class CPage : public CDictObject class CPage : public CDictObject
{ {
public: public:
CPage(CXref* pXref, CPageTree* pParent); CPage(CXref* pXref, CPageTree* pParent, CDocument* pDocument);
~CPage(); ~CPage();
void SetHeight(double dHeight); void SetHeight(double dHeight);
...@@ -82,6 +83,8 @@ namespace PdfWriter ...@@ -82,6 +83,8 @@ namespace PdfWriter
void SetExtGrState(CExtGrState* pExtGrState); void SetExtGrState(CExtGrState* pExtGrState);
void AddAnnotation(CAnnotation* pAnnot); void AddAnnotation(CAnnotation* pAnnot);
void DrawShading(CShading* pShading); void DrawShading(CShading* pShading);
void SetStrokeAlpha(unsigned char unAlpha);
void SetFillAlpha(unsigned char unAlpha);
void BeginText(); void BeginText();
void EndText(); void EndText();
...@@ -97,6 +100,9 @@ namespace PdfWriter ...@@ -97,6 +100,9 @@ namespace PdfWriter
void ExecuteXObject(CXObject* pXObject); void ExecuteXObject(CXObject* pXObject);
void DrawImage(CImageDict* pImage, double dX, double dY, double dWidth, double dHeight); void DrawImage(CImageDict* pImage, double dX, double dY, double dWidth, double dHeight);
void SetPatternColorSpace(CImageTilePattern* pPattern); void SetPatternColorSpace(CImageTilePattern* pPattern);
void SetFilter(unsigned int unFiler);
CMatrix* GetTransform();
void AddGroup(CDictObject* pDict);
private: private:
...@@ -119,6 +125,7 @@ namespace PdfWriter ...@@ -119,6 +125,7 @@ namespace PdfWriter
private: private:
CDocument* m_pDocument;
CPageTree* m_pParent; CPageTree* m_pParent;
CXref* m_pXref; CXref* m_pXref;
CPoint m_oStartPos; // Позиция начала текущего пата CPoint m_oStartPos; // Позиция начала текущего пата
......
...@@ -13,13 +13,28 @@ namespace PdfWriter ...@@ -13,13 +13,28 @@ namespace PdfWriter
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// CImageTilePattern // CImageTilePattern
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, EImageTilePatternType eType) : CPattern(pXref) CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType) : CPattern(pXref)
{ {
Add("Type", "Pattern"); Add("Type", "Pattern");
Add("PatternType", 1); Add("PatternType", 1);
Add("PaintType", 1); // Uncolored Add("PaintType", 1); // Uncolored
Add("TilingType", 1); // No distortion Add("TilingType", 1); // No distortion
if (pMatrix)
{
CArrayObject* pMatrixArray = new CArrayObject();
if (!pMatrixArray)
return;
pMatrixArray->Add(pMatrix->m11);
pMatrixArray->Add(pMatrix->m12);
pMatrixArray->Add(pMatrix->m21);
pMatrixArray->Add(pMatrix->m22);
pMatrixArray->Add(pMatrix->x);
pMatrixArray->Add(pMatrix->y);
Add("Matrix", pMatrixArray);
}
CDictObject* pResources = new CDictObject(); CDictObject* pResources = new CDictObject();
if (!pResources) if (!pResources)
return; return;
......
...@@ -20,7 +20,7 @@ namespace PdfWriter ...@@ -20,7 +20,7 @@ namespace PdfWriter
class CImageTilePattern : public CPattern class CImageTilePattern : public CPattern
{ {
public: public:
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, EImageTilePatternType eType = imagetilepatterntype_Default); CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
}; };
} }
......
...@@ -105,6 +105,7 @@ namespace PdfWriter ...@@ -105,6 +105,7 @@ namespace PdfWriter
m_pXref = pXref; m_pXref = pXref;
pXref->Add(this); pXref->Add(this);
m_bRgb = true;
m_pColors = NULL; m_pColors = NULL;
m_pColorsPoints = NULL; m_pColorsPoints = NULL;
m_nColorsCount = 0; m_nColorsCount = 0;
...@@ -119,11 +120,12 @@ namespace PdfWriter ...@@ -119,11 +120,12 @@ namespace PdfWriter
if (m_pColorsPoints) if (m_pColorsPoints)
delete[] m_pColorsPoints; delete[] m_pColorsPoints;
} }
void CShading::SetColors(unsigned char* pColors, double* pPoints, int nCount) void CShading::SetRgbColors(unsigned char* pColors, double* pPoints, int nCount)
{ {
if (!pColors || !pPoints || nCount <= 1) if (!pColors || !pPoints || nCount <= 1)
return; return;
m_bRgb = true;
m_pColors = new unsigned char[3 * nCount]; m_pColors = new unsigned char[3 * nCount];
m_pColorsPoints = new double[nCount]; m_pColorsPoints = new double[nCount];
m_nColorsCount = nCount; m_nColorsCount = nCount;
...@@ -193,6 +195,53 @@ namespace PdfWriter ...@@ -193,6 +195,53 @@ namespace PdfWriter
delete[] ppValues; delete[] ppValues;
} }
} }
void CShading::SetGrayColors(unsigned char* pColors, double* pPoints, int nCount)
{
if (!pColors || !pPoints || nCount <= 1)
return;
m_bRgb = false;
m_pColors = new unsigned char[nCount];
m_pColorsPoints = new double[nCount];
m_nColorsCount = nCount;
if (!m_pColors || !m_pColorsPoints)
return;
memcpy(m_pColors, pColors, nCount);
Add("ColorSpace", "DeviceGray");
CArrayObject* pDomain = new CArrayObject();
if (!pDomain)
return;
pDomain->Add(0.0);
pDomain->Add(1.0);
Add("Domain", pDomain);
if (nCount <= 2)
{
double pC0Values = pColors[0] / 255.0;
double pC1Values = pColors[1] / 255.0;
CLinearFuntion* pFunction = new CLinearFuntion(m_pXref, &pC0Values, &pC1Values, 1);
Add("Function", pFunction);
}
else
{
double* pValues = new double[(nCount - 1) * 2];
for (int nIndex = 0; nIndex < nCount - 1; nIndex++)
{
pValues[2 * nIndex + 0] = pColors[nIndex] / 255.0;
pValues[2 * nIndex + 1] = pColors[nIndex + 1] / 255.0;
}
CLineSegmentFuntion* pFunction = new CLineSegmentFuntion(m_pXref, &pValues, pPoints + 1, nCount - 1, 1);
Add("Function", pFunction);
delete[] pValues;
}
}
void CShading::SetExtend(bool bBegin, bool bEnd) void CShading::SetExtend(bool bBegin, bool bEnd)
{ {
CArrayObject* pExtend = new CArrayObject(); CArrayObject* pExtend = new CArrayObject();
...@@ -206,22 +255,35 @@ namespace PdfWriter ...@@ -206,22 +255,35 @@ namespace PdfWriter
m_bBeginExtend = bBegin; m_bBeginExtend = bBegin;
m_bEndExtend = bEnd; m_bEndExtend = bEnd;
} }
bool CShading::CompareColors(unsigned char* pColors, double* pPoints, int nCount) bool CShading::CompareColors(unsigned char* pColors, double* pPoints, int nCount, bool bRgb)
{ {
if (nCount != m_nColorsCount if (nCount != m_nColorsCount
|| (pColors && !m_pColors) || (pColors && !m_pColors)
|| (pPoints && !m_pColorsPoints) || (pPoints && !m_pColorsPoints)
|| (!pColors && m_pColors) || (!pColors && m_pColors)
|| (!pPoints && m_pColorsPoints)) || (!pPoints && m_pColorsPoints)
|| bRgb != m_bRgb)
return false; return false;
for (int nIndex = 0; nIndex < nCount; nIndex++) if (m_bRgb)
{ {
if (pColors[3 * nIndex + 0] != m_pColors[3 * nIndex + 0] for (int nIndex = 0; nIndex < nCount; nIndex++)
|| pColors[3 * nIndex + 1] != m_pColors[3 * nIndex + 1] {
|| pColors[3 * nIndex + 2] != m_pColors[3 * nIndex + 2] if (pColors[3 * nIndex + 0] != m_pColors[3 * nIndex + 0]
|| abs(pPoints[nIndex] - m_pColorsPoints[nIndex]) > 0.01) || pColors[3 * nIndex + 1] != m_pColors[3 * nIndex + 1]
return false; || pColors[3 * nIndex + 2] != m_pColors[3 * nIndex + 2]
|| abs(pPoints[nIndex] - m_pColorsPoints[nIndex]) > 0.01)
return false;
}
}
else
{
for (int nIndex = 0; nIndex < nCount; nIndex++)
{
if (pColors[nIndex] != m_pColors[nIndex]
|| abs(pPoints[nIndex] - m_pColorsPoints[nIndex]) > 0.01)
return false;
}
} }
return true; return true;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _PDF_WRITER_SRC_STREAMS_H #define _PDF_WRITER_SRC_STREAMS_H
#include "Objects.h" #include "Objects.h"
#include "Pattern.h"
namespace PdfWriter namespace PdfWriter
{ {
...@@ -20,9 +21,10 @@ namespace PdfWriter ...@@ -20,9 +21,10 @@ namespace PdfWriter
CShading(CXref* pXref); CShading(CXref* pXref);
virtual ~CShading(); virtual ~CShading();
void SetColors(unsigned char* pColors, double* dPoints, int nCount); void SetRgbColors(unsigned char* pColors, double* dPoints, int nCount);
void SetGrayColors(unsigned char* pColors, double* dPoints, int nCount);
void SetExtend(bool bBeing, bool bEnd); void SetExtend(bool bBeing, bool bEnd);
bool CompareColors(unsigned char* pColors, double* pPoints, int nCount); bool CompareColors(unsigned char* pColors, double* pPoints, int nCount, bool bRgb);
bool CompareExtend(bool bBeing, bool bEnd); bool CompareExtend(bool bBeing, bool bEnd);
virtual EShadingType GetShadingType() virtual EShadingType GetShadingType()
...@@ -36,6 +38,7 @@ namespace PdfWriter ...@@ -36,6 +38,7 @@ namespace PdfWriter
private: private:
bool m_bRgb; // Rgb Gray
unsigned char* m_pColors; unsigned char* m_pColors;
double* m_pColorsPoints; double* m_pColorsPoints;
int m_nColorsCount; int m_nColorsCount;
......
...@@ -59,6 +59,27 @@ namespace PdfWriter ...@@ -59,6 +59,27 @@ namespace PdfWriter
y = 0; y = 0;
} }
void Apply(double& dX, double& dY)
{
double _x = dX;
double _y = dY;
dX = _x * m11 + _y * m21 + x;
dY = _x * m12 + _y * m22 + y;
}
bool operator==(const CMatrix& oMatrix)
{
if (abs(oMatrix.m11 - m11) > 0.001
|| abs(oMatrix.m12 - m12) > 0.001
|| abs(oMatrix.m21 - m21) > 0.001
|| abs(oMatrix.m22 - m22) > 0.001
|| abs(oMatrix.x - x) > 0.001
|| abs(oMatrix.y - y) > 0.001)
return false;
return true;
}
public: public:
double m11; double m11;
......
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