From d70d4d50f0ebc7d4bbdfed780569437394251cf2 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Thu, 3 Nov 2022 17:47:16 +0300 Subject: [PATCH] fix PdfReader and PdfWriter, fix BUILDING_WASM_MODULE --- .../graphics/pro/js/drawingfile.json | 7 +- .../graphics/pro/officedrawingfile.h | 2 - DjVuFile/DjVu.cpp | 2 - DjVuFile/DjVu.h | 2 - DjVuFile/DjVuFileImplementation.cpp | 5 +- DjVuFile/DjVuFileImplementation.h | 6 - PdfFile/PdfFile.cpp | 183 ++- PdfFile/PdfFile.h | 3 - PdfFile/Src/PdfReader.cpp | 1202 +++++++---------- PdfFile/Src/PdfReader.h | 89 +- PdfFile/Src/PdfWriter.cpp | 79 +- PdfFile/Src/PdfWriter.h | 220 ++- PdfReader/PdfReader.cpp | 4 - PdfReader/PdfReader.h | 2 - XpsFile/XpsFile.cpp | 2 - XpsFile/XpsFile.h | 2 - XpsFile/XpsLib/Document.cpp | 6 - XpsFile/XpsLib/Document.h | 2 - XpsFile/XpsLib/XpsPage.cpp | 6 - XpsFile/XpsLib/XpsPage.h | 4 - 20 files changed, 868 insertions(+), 960 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index b65e4bdc46..84557cf6f7 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -156,7 +156,7 @@ { "name": "p", "folder": "../../../../PdfReader/", - "files": ["PdfReader.cpp", "Src/Adaptors.cpp", "Src/GfxClip.cpp", "Src/RendererOutputDev.cpp", "Src/JPXStream2.cpp", "Resources/BaseFonts.cpp", "Resources/CMapMemory/cmap_memory.cpp", "lib/fofi/FofiBase.cc", "lib/fofi/FofiEncodings.cc", "lib/fofi/FofiIdentifier.cc", "lib/fofi/FofiTrueType.cc", "lib/fofi/FofiType1.cc", "lib/fofi/FofiType1C.cc", "lib/goo/FixedPoint.cc", "lib/goo/gfile.cc", "lib/goo/GHash.cc", "lib/goo/GList.cc", "lib/goo/gmem.cc", "lib/goo/gmempp.cc", "lib/goo/GString.cc", "lib/goo/parseargs.c", "lib/goo/Trace.cc", "lib/splash/Splash.cc", "lib/splash/SplashBitmap.cc", "lib/splash/SplashClip.cc", "lib/splash/SplashFont.cc", "lib/splash/SplashFontEngine.cc", "lib/splash/SplashFontFile.cc", "lib/splash/SplashFontFileID.cc", "lib/splash/SplashFTFont.cc", "lib/splash/SplashFTFontEngine.cc", "lib/splash/SplashFTFontFile.cc", "lib/splash/SplashPath.cc", "lib/splash/SplashPattern.cc", "lib/splash/SplashScreen.cc", "lib/splash/SplashState.cc", "lib/splash/SplashXPath.cc", "lib/splash/SplashXPathScanner.cc", "lib/xpdf/AcroForm.cc", "lib/xpdf/Annot.cc", "lib/xpdf/Array.cc", "lib/xpdf/BuiltinFont.cc", "lib/xpdf/BuiltinFontTables.cc", "lib/xpdf/Catalog.cc", "lib/xpdf/CharCodeToUnicode.cc", "lib/xpdf/CMap.cc", "lib/xpdf/Decrypt.cc", "lib/xpdf/Dict.cc", "lib/xpdf/DisplayState.cc", "lib/xpdf/Error.cc", "lib/xpdf/FontEncodingTables.cc", "lib/xpdf/Function.cc", "lib/xpdf/Gfx.cc", "lib/xpdf/GfxFont.cc", "lib/xpdf/GfxState.cc", "lib/xpdf/GlobalParams.cc", "lib/xpdf/ImageOutputDev.cc", "lib/xpdf/JArithmeticDecoder.cc", "lib/xpdf/JBIG2Stream.cc", "lib/xpdf/JPXStream.cc", "lib/xpdf/Lexer.cc", "lib/xpdf/Link.cc", "lib/xpdf/NameToCharCode.cc", "lib/xpdf/Object.cc", "lib/xpdf/OptionalContent.cc", "lib/xpdf/Outline.cc", "lib/xpdf/OutputDev.cc", "lib/xpdf/Page.cc", "lib/xpdf/Parser.cc", "lib/xpdf/PDF417Barcode.cc", "lib/xpdf/PDFCore.cc", "lib/xpdf/PDFDoc.cc", "lib/xpdf/PDFDocEncoding.cc", "lib/xpdf/PreScanOutputDev.cc", "lib/xpdf/PSOutputDev.cc", "lib/xpdf/PSTokenizer.cc", "lib/xpdf/SecurityHandler.cc", "lib/xpdf/ShadingImage.cc", "lib/xpdf/SplashOutputDev.cc", "lib/xpdf/Stream.cc", "lib/xpdf/TextOutputDev.cc", "lib/xpdf/TextString.cc", "lib/xpdf/TileCache.cc", "lib/xpdf/TileCompositor.cc", "lib/xpdf/TileMap.cc", "lib/xpdf/UnicodeMap.cc", "lib/xpdf/UnicodeRemapping.cc", "lib/xpdf/UnicodeTypeTable.cc", "lib/xpdf/UTF8.cc", "lib/xpdf/WebFont.cc", "lib/xpdf/XFAScanner.cc", "lib/xpdf/XRef.cc", "lib/xpdf/Zoox.cc"] + "files": ["Src/Adaptors.cpp", "Src/GfxClip.cpp", "Src/RendererOutputDev.cpp", "Src/JPXStream2.cpp", "Resources/BaseFonts.cpp", "Resources/CMapMemory/cmap_memory.cpp", "lib/fofi/FofiBase.cc", "lib/fofi/FofiEncodings.cc", "lib/fofi/FofiIdentifier.cc", "lib/fofi/FofiTrueType.cc", "lib/fofi/FofiType1.cc", "lib/fofi/FofiType1C.cc", "lib/goo/FixedPoint.cc", "lib/goo/gfile.cc", "lib/goo/GHash.cc", "lib/goo/GList.cc", "lib/goo/gmem.cc", "lib/goo/gmempp.cc", "lib/goo/GString.cc", "lib/goo/parseargs.c", "lib/goo/Trace.cc", "lib/splash/Splash.cc", "lib/splash/SplashBitmap.cc", "lib/splash/SplashClip.cc", "lib/splash/SplashFont.cc", "lib/splash/SplashFontEngine.cc", "lib/splash/SplashFontFile.cc", "lib/splash/SplashFontFileID.cc", "lib/splash/SplashFTFont.cc", "lib/splash/SplashFTFontEngine.cc", "lib/splash/SplashFTFontFile.cc", "lib/splash/SplashPath.cc", "lib/splash/SplashPattern.cc", "lib/splash/SplashScreen.cc", "lib/splash/SplashState.cc", "lib/splash/SplashXPath.cc", "lib/splash/SplashXPathScanner.cc", "lib/xpdf/AcroForm.cc", "lib/xpdf/Annot.cc", "lib/xpdf/Array.cc", "lib/xpdf/BuiltinFont.cc", "lib/xpdf/BuiltinFontTables.cc", "lib/xpdf/Catalog.cc", "lib/xpdf/CharCodeToUnicode.cc", "lib/xpdf/CMap.cc", "lib/xpdf/Decrypt.cc", "lib/xpdf/Dict.cc", "lib/xpdf/DisplayState.cc", "lib/xpdf/Error.cc", "lib/xpdf/FontEncodingTables.cc", "lib/xpdf/Function.cc", "lib/xpdf/Gfx.cc", "lib/xpdf/GfxFont.cc", "lib/xpdf/GfxState.cc", "lib/xpdf/GlobalParams.cc", "lib/xpdf/ImageOutputDev.cc", "lib/xpdf/JArithmeticDecoder.cc", "lib/xpdf/JBIG2Stream.cc", "lib/xpdf/JPXStream.cc", "lib/xpdf/Lexer.cc", "lib/xpdf/Link.cc", "lib/xpdf/NameToCharCode.cc", "lib/xpdf/Object.cc", "lib/xpdf/OptionalContent.cc", "lib/xpdf/Outline.cc", "lib/xpdf/OutputDev.cc", "lib/xpdf/Page.cc", "lib/xpdf/Parser.cc", "lib/xpdf/PDF417Barcode.cc", "lib/xpdf/PDFCore.cc", "lib/xpdf/PDFDoc.cc", "lib/xpdf/PDFDocEncoding.cc", "lib/xpdf/PreScanOutputDev.cc", "lib/xpdf/PSOutputDev.cc", "lib/xpdf/PSTokenizer.cc", "lib/xpdf/SecurityHandler.cc", "lib/xpdf/ShadingImage.cc", "lib/xpdf/SplashOutputDev.cc", "lib/xpdf/Stream.cc", "lib/xpdf/TextOutputDev.cc", "lib/xpdf/TextString.cc", "lib/xpdf/TileCache.cc", "lib/xpdf/TileCompositor.cc", "lib/xpdf/TileMap.cc", "lib/xpdf/UnicodeMap.cc", "lib/xpdf/UnicodeRemapping.cc", "lib/xpdf/UnicodeTypeTable.cc", "lib/xpdf/UTF8.cc", "lib/xpdf/WebFont.cc", "lib/xpdf/XFAScanner.cc", "lib/xpdf/XRef.cc", "lib/xpdf/Zoox.cc"] }, { "name": "opj", @@ -192,6 +192,11 @@ "name": "u", "folder": "../../../../UnicodeConverter/", "files": ["UnicodeConverter.cpp"] + }, + { + "name": "pd", + "folder": "../../../../PdfFile/", + "files": ["PdfFile.cpp", "Src/PdfReader.cpp"] } ] } diff --git a/DesktopEditor/graphics/pro/officedrawingfile.h b/DesktopEditor/graphics/pro/officedrawingfile.h index f0921d4d13..b74b55e5a9 100644 --- a/DesktopEditor/graphics/pro/officedrawingfile.h +++ b/DesktopEditor/graphics/pro/officedrawingfile.h @@ -86,10 +86,8 @@ public: // Common methods for viewer virtual std::wstring GetInfo() = 0; -#ifdef BUILDING_WASM_MODULE virtual unsigned char* GetStructure() = 0; virtual unsigned char* GetLinks(int nPageIndex) = 0; -#endif }; #endif // _OFFICE_DRAWING_FILE_H diff --git a/DjVuFile/DjVu.cpp b/DjVuFile/DjVu.cpp index efc5334c43..98a5398f2a 100644 --- a/DjVuFile/DjVu.cpp +++ b/DjVuFile/DjVu.cpp @@ -109,7 +109,6 @@ void CDjVuFile::ConvertToPdf(const std::wstring& wsDstPath) if (m_pImplementation) m_pImplementation->ConvertToPdf(wsDstPath); } -#ifdef BUILDING_WASM_MODULE BYTE* CDjVuFile::GetStructure() { if (m_pImplementation) @@ -122,4 +121,3 @@ BYTE* CDjVuFile::GetLinks (int nPageIndex) return m_pImplementation->GetPageLinks(nPageIndex); return NULL; } -#endif diff --git a/DjVuFile/DjVu.h b/DjVuFile/DjVu.h index 1d685be528..6fe7398cf3 100644 --- a/DjVuFile/DjVu.h +++ b/DjVuFile/DjVu.h @@ -74,8 +74,6 @@ public: void ConvertToPdf(const std::wstring& path); -#ifdef BUILDING_WASM_MODULE virtual BYTE* GetStructure(); virtual BYTE* GetLinks (int nPageIndex); -#endif }; diff --git a/DjVuFile/DjVuFileImplementation.cpp b/DjVuFile/DjVuFileImplementation.cpp index 27b9b7dadd..4da84eae55 100644 --- a/DjVuFile/DjVuFileImplementation.cpp +++ b/DjVuFile/DjVuFileImplementation.cpp @@ -47,9 +47,10 @@ #include +#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" + #ifdef BUILDING_WASM_MODULE #define DISABLE_TEMP_DIRECTORY -#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" #endif namespace NSDjvu @@ -277,7 +278,6 @@ std::wstring CDjVuFileImplementation::GetInfo() return sRes; } -#ifdef BUILDING_WASM_MODULE void getBookmars(const GP& nav, int& pos, int count, NSWasm::CData& out, int level) { while (count > 0 && pos < nav->getBookMarkCount()) @@ -422,7 +422,6 @@ BYTE* CDjVuFileImplementation::GetPageLinks(int nPageIndex) catch (...) {} return NULL; } -#endif void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP& pPage, int nPage, XmlUtils::CXmlNode& text) { diff --git a/DjVuFile/DjVuFileImplementation.h b/DjVuFile/DjVuFileImplementation.h index e5b75f0d6b..18749dd8dc 100644 --- a/DjVuFile/DjVuFileImplementation.h +++ b/DjVuFile/DjVuFileImplementation.h @@ -51,10 +51,6 @@ #include "../DesktopEditor/graphics/IRenderer.h" #include "../DesktopEditor/graphics/pro/Fonts.h" -#ifdef BUILDING_WASM_MODULE -#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" -#endif - class CDjVuFileImplementation { private: @@ -79,11 +75,9 @@ public: void ConvertToPdf(const std::wstring& wsDstPath); std::wstring GetInfo(); -#ifdef BUILDING_WASM_MODULE BYTE* GetStructure(); BYTE* GetPageGlyphs(int nPageIndex); BYTE* GetPageLinks (int nPageIndex); -#endif private: diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index e076f13f76..0de8eb7731 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -160,11 +160,12 @@ class CPdfFile_Private { public: CPdfWriter* pWriter; - PdfReader::CPdfReader* pReader; + CPdfReader* pReader; std::wstring wsSrcFile; std::wstring wsPassword; bool bEdit; bool bEditPage; + NSFonts::IApplicationFonts* pAppFonts; void GetPageTree(XRef* xref, Object* pPagesRefObj) { @@ -239,8 +240,9 @@ CPdfFile::CPdfFile(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) { m_pInternal = new CPdfFile_Private(); - m_pInternal->pWriter = new CPdfWriter(pAppFonts, isPDFA); - m_pInternal->pReader = new PdfReader::CPdfReader(pAppFonts); + m_pInternal->pAppFonts = pAppFonts; + m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, isPDFA); + m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts); m_pInternal->wsPassword = L""; m_pInternal->bEdit = false; m_pInternal->bEditPage = false; @@ -250,10 +252,11 @@ CPdfFile::CPdfFile(NSFonts::IApplicationFonts* pAppFonts, int nMode, bool isPDFA { m_pInternal = new CPdfFile_Private(); + m_pInternal->pAppFonts = pAppFonts; if (nMode & 1) - m_pInternal->pReader = new PdfReader::CPdfReader(pAppFonts); + m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts); if (nMode & 2) - m_pInternal->pWriter = new CPdfWriter(pAppFonts, isPDFA); + m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, isPDFA); m_pInternal->wsPassword = L""; m_pInternal->bEdit = false; m_pInternal->bEditPage = false; @@ -653,13 +656,13 @@ bool CPdfFile::LoadFromFile(const std::wstring& file, const std::wstring& option { m_pInternal->wsSrcFile = file; m_pInternal->wsPassword = owner_password; - return m_pInternal->pReader->LoadFromFile(file, L"", owner_password, user_password) && (m_pInternal->pReader->GetError() == 0); + return m_pInternal->pReader->LoadFromFile(m_pInternal->pAppFonts, file, owner_password, user_password) && (m_pInternal->pReader->GetError() == 0); } bool CPdfFile::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options, const std::wstring& owner_password, const std::wstring& user_password) { m_pInternal->wsSrcFile = L""; m_pInternal->wsPassword = owner_password; - return m_pInternal->pReader->LoadFromMemory(data, length, L"", owner_password, user_password) && (m_pInternal->pReader->GetError() == 0); + return m_pInternal->pReader->LoadFromMemory(m_pInternal->pAppFonts, data, length, owner_password, user_password) && (m_pInternal->pReader->GetError() == 0); } void CPdfFile::Close() { @@ -667,7 +670,7 @@ void CPdfFile::Close() } NSFonts::IApplicationFonts* CPdfFile::GetFonts() { - return m_pInternal->pReader->GetFonts(); + return m_pInternal->pAppFonts; } OfficeDrawingFileType CPdfFile::GetType() { @@ -691,13 +694,12 @@ void CPdfFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, do } void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) { - m_pInternal->pReader->DrawPageOnRenderer(this, nPageIndex, pBreak); + m_pInternal->pReader->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak); } std::wstring CPdfFile::GetInfo() { return m_pInternal->pReader->GetInfo(); } -#ifdef BUILDING_WASM_MODULE BYTE* CPdfFile::GetStructure() { return m_pInternal->pReader->GetStructure(); @@ -706,7 +708,6 @@ BYTE* CPdfFile::GetLinks(int nPageIndex) { return m_pInternal->pReader->GetLinks(nPageIndex); } -#endif // ------------------------------------------------------------------------ @@ -1085,7 +1086,7 @@ HRESULT CPdfFile::PathCommandEnd() } HRESULT CPdfFile::DrawPath(const LONG& lType) { - return m_pInternal->pWriter->DrawPath(lType); + return m_pInternal->pWriter->DrawPath(m_pInternal->pAppFonts, lType); } HRESULT CPdfFile::PathCommandStart() { @@ -1117,7 +1118,7 @@ HRESULT CPdfFile::DrawImage(IGrObject* pImage, const double& dX, const double& d } HRESULT CPdfFile::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { - return m_pInternal->pWriter->DrawImageFromFile(wsImagePath, dX, dY, dW, dH, nAlpha); + return m_pInternal->pWriter->DrawImageFromFile(m_pInternal->pAppFonts, wsImagePath, dX, dY, dW, dH, nAlpha); } HRESULT CPdfFile::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) { @@ -1161,5 +1162,159 @@ HRESULT CPdfFile::AddLink(const double& dX, const double& dY, const double& dW, } HRESULT CPdfFile::AddFormField(const CFormFieldInfo& oInfo) { - return m_pInternal->pWriter->AddFormField(oInfo); + return m_pInternal->pWriter->AddFormField(m_pInternal->pAppFonts, oInfo); } + +#ifdef BUILDING_WASM_MODULE +CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) : m_oCommandManager(this) {} +CPdfWriter::~CPdfWriter() {} +int CPdfWriter::SaveToFile(const std::wstring& wsPath) { return 0; } +void CPdfWriter::SetPassword(const std::wstring& wsPassword) {} +void CPdfWriter::SetDocumentID(const std::wstring& wsDocumentID) {} +void CPdfWriter::SetTempFolder(const std::wstring& wsPath) {} +std::wstring CPdfWriter::GetTempDirectory() { return std::wstring(); } +std::wstring CPdfWriter::GetTempFile() { return std::wstring(); } +HRESULT CPdfWriter::get_Type(LONG* lType) { return 0; } +HRESULT CPdfWriter::NewPage() { return 0; } +HRESULT CPdfWriter::get_Height(double* dHeight) { return 0; } +HRESULT CPdfWriter::put_Height(const double& dHeight) { return 0; } +HRESULT CPdfWriter::get_Width(double* dWidth) { return 0; } +HRESULT CPdfWriter::put_Width(const double& dWidth) { return 0; } +HRESULT CPdfWriter::get_DpiX(double* dDpiX) { return 0; } +HRESULT CPdfWriter::get_DpiY(double* dDpiY) { return 0; } +HRESULT CPdfWriter::get_PenColor(LONG* lColor) { return 0; } +HRESULT CPdfWriter::put_PenColor(const LONG& lColor) { return 0; } +HRESULT CPdfWriter::get_PenAlpha(LONG* lAlpha) { return 0; } +HRESULT CPdfWriter::put_PenAlpha(const LONG& lAlpha) { return 0; } +HRESULT CPdfWriter::get_PenSize(double* dSize) { return 0; } +HRESULT CPdfWriter::put_PenSize(const double& dSize) { return 0; } +HRESULT CPdfWriter::get_PenDashStyle(BYTE* nDashStyle) { return 0; } +HRESULT CPdfWriter::put_PenDashStyle(const BYTE& nDashStyle) { return 0; } +HRESULT CPdfWriter::get_PenLineStartCap(BYTE* nCapStyle) { return 0; } +HRESULT CPdfWriter::put_PenLineStartCap(const BYTE& nCapStyle) { return 0; } +HRESULT CPdfWriter::get_PenLineEndCap(BYTE* nCapStyle) { return 0; } +HRESULT CPdfWriter::put_PenLineEndCap(const BYTE& nCapStyle) { return 0; } +HRESULT CPdfWriter::get_PenLineJoin(BYTE* nJoinStyle) { return 0; } +HRESULT CPdfWriter::put_PenLineJoin(const BYTE& nJoinStyle) { return 0; } +HRESULT CPdfWriter::get_PenDashOffset(double* dOffset) { return 0; } +HRESULT CPdfWriter::put_PenDashOffset(const double& dOffset) { return 0; } +HRESULT CPdfWriter::get_PenAlign(LONG* lAlign) { return 0; } +HRESULT CPdfWriter::put_PenAlign(const LONG& lAlign) { return 0; } +HRESULT CPdfWriter::get_PenMiterLimit(double* dMiter) { return 0; } +HRESULT CPdfWriter::put_PenMiterLimit(const double& dMiter) { return 0; } +HRESULT CPdfWriter::PenDashPattern(double* pPattern, LONG lCount) { return 0; } +HRESULT CPdfWriter::get_BrushType(LONG* lType) { return 0; } +HRESULT CPdfWriter::put_BrushType(const LONG& lType) { return 0; } +HRESULT CPdfWriter::get_BrushColor1(LONG* lColor) { return 0; } +HRESULT CPdfWriter::put_BrushColor1(const LONG& lColor) { return 0; } +HRESULT CPdfWriter::get_BrushAlpha1(LONG* lAlpha) { return 0; } +HRESULT CPdfWriter::put_BrushAlpha1(const LONG& lAlpha) { return 0; } +HRESULT CPdfWriter::get_BrushColor2(LONG* lColor) { return 0; } +HRESULT CPdfWriter::put_BrushColor2(const LONG& lColor) { return 0; } +HRESULT CPdfWriter::get_BrushAlpha2(LONG* lAlpha) { return 0; } +HRESULT CPdfWriter::put_BrushAlpha2(const LONG& lAlpha) { return 0; } +HRESULT CPdfWriter::get_BrushTexturePath(std::wstring* wsPath) { return 0; } +HRESULT CPdfWriter::put_BrushTexturePath(const std::wstring& wsPath) { return 0; } +HRESULT CPdfWriter::get_BrushTextureMode(LONG* lMode) { return 0; } +HRESULT CPdfWriter::put_BrushTextureMode(const LONG& lMode) { return 0; } +HRESULT CPdfWriter::get_BrushTextureAlpha(LONG* lAlpha) { return 0; } +HRESULT CPdfWriter::put_BrushTextureAlpha(const LONG& lAlpha) { return 0; } +HRESULT CPdfWriter::get_BrushLinearAngle(double* dAngle) { return 0; } +HRESULT CPdfWriter::put_BrushLinearAngle(const double& dAngle) { return 0; } +HRESULT CPdfWriter::BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight) { return 0; } +HRESULT CPdfWriter::BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight) { return 0; } +HRESULT CPdfWriter::put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount) { return 0; } +HRESULT CPdfWriter::get_FontName(std::wstring* wsName) { return 0; } +HRESULT CPdfWriter::put_FontName(const std::wstring& wsName) { return 0; } +HRESULT CPdfWriter::get_FontPath(std::wstring* wsPath) { return 0; } +HRESULT CPdfWriter::put_FontPath(const std::wstring& wsPath) { return 0; } +HRESULT CPdfWriter::get_FontSize(double* dSize) { return 0; } +HRESULT CPdfWriter::put_FontSize(const double& dSize) { return 0; } +HRESULT CPdfWriter::get_FontStyle(LONG* lStyle) { return 0; } +HRESULT CPdfWriter::put_FontStyle(const LONG& lStyle) { return 0; } +HRESULT CPdfWriter::get_FontStringGID(INT* bGid) { return 0; } +HRESULT CPdfWriter::put_FontStringGID(const INT& bGid) { return 0; } +HRESULT CPdfWriter::get_FontCharSpace(double* dSpace) { return 0; } +HRESULT CPdfWriter::put_FontCharSpace(const double& dSpace) { return 0; } +HRESULT CPdfWriter::get_FontFaceIndex(int* lFaceIndex) { return 0; } +HRESULT CPdfWriter::put_FontFaceIndex(const int& lFaceIndex) { return 0; } +HRESULT CPdfWriter::CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::CommandDrawTextCHAR2 (unsigned int* unUnicode, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::BeginCommand(const DWORD& lType) { return 0; } +HRESULT CPdfWriter::EndCommand(const DWORD& lType) { return 0; } +HRESULT CPdfWriter::PathCommandMoveTo(const double& dX, const double& dY) { return 0; } +HRESULT CPdfWriter::PathCommandLineTo(const double& dX, const double& dY) { return 0; } +HRESULT CPdfWriter::PathCommandLinesTo(double* pPoints, const int& nCount) { return 0; } +HRESULT CPdfWriter::PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe) { return 0; } +HRESULT CPdfWriter::PathCommandCurvesTo(double* pPoints, const int& nCount) { return 0; } +HRESULT CPdfWriter::PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle) { return 0; } +HRESULT CPdfWriter::PathCommandClose() { return 0; } +HRESULT CPdfWriter::PathCommandEnd() { return 0; } +HRESULT CPdfWriter::DrawPath(NSFonts::IApplicationFonts* pAppFonts, const LONG& lType) { return 0; } +HRESULT CPdfWriter::PathCommandStart() { return 0; } +HRESULT CPdfWriter::PathCommandGetCurrentPoint(double* dX, double* dY) { return 0; } +HRESULT CPdfWriter::PathCommandTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::DrawImageFromFile(NSFonts::IApplicationFonts* pAppFonts, const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { return 0; } +HRESULT CPdfWriter::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) { return 0; } +HRESULT CPdfWriter::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY) { return 0; } +HRESULT CPdfWriter::ResetTransform() { return 0; } +HRESULT CPdfWriter::get_ClipMode(LONG* lMode) { return 0; } +HRESULT CPdfWriter::put_ClipMode(const LONG& lMode) { return 0; } +HRESULT CPdfWriter::CommandLong(const LONG& lType, const LONG& lCommand) { return 0; } +HRESULT CPdfWriter::CommandDouble(const LONG& lType, const double& dCommand) { return 0; } +HRESULT CPdfWriter::CommandString(const LONG& lType, const std::wstring& sCommand) { return 0; } +HRESULT CPdfWriter::AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip) { return 0; } +HRESULT CPdfWriter::AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage) { return 0; } +HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, const CFormFieldInfo& oInfo) { return 0; } +HRESULT CPdfWriter::CommandDrawTextPdf(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const std::wstring& wsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::PathCommandTextPdf(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const std::wstring& bsSrcCodeText, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::DrawImage1bpp(NSImages::CPixJbig2* pImageBuffer, const unsigned int& unWidth, const unsigned int& unHeight, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +HRESULT CPdfWriter::EnableBrushRect(const LONG& lEnable) { return 0; } +HRESULT CPdfWriter::SetLinearGradient(const double& dX1, const double& dY1, const double& dX2, const double& dY2) { return 0; } +HRESULT CPdfWriter::SetRadialGradient(const double& dX1, const double& dY1, const double& dR1, const double& dX2, const double& dY2, const double& dR2) { return 0; } +HRESULT CPdfWriter::DrawImageWith1bppMask(IGrObject* pImage, NSImages::CPixJbig2* pMaskBuffer, const unsigned int& unMaskWidth, const unsigned int& unMaskHeight, const double& dX, const double& dY, const double& dW, const double& dH) { return 0; } +std::pair CPdfWriter::GetPageRef(int nPageIndex) { return std::make_pair(0, 0); } +bool CPdfWriter::EditPage(PdfWriter::CPage* pNewPage) { return false; } +bool CPdfWriter::AddPage(int nPageIndex) { return false; } +bool CPdfWriter::DeletePage(int nPageIndex) { return false; } +bool CPdfWriter::EditClose() { return false; } +void CPdfWriter::PageRotate(int nRotate) {} +void CPdfWriter::Sign(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsPicturePath, ICertificate* pCertificate) {} +std::wstring CPdfWriter::GetEditPdfPath() { return std::wstring(); } +PdfWriter::CImageDict* CPdfWriter::LoadImage(Aggplus::CImage* pImage, const BYTE& nAlpha) { return NULL; } +bool CPdfWriter::DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { return false; } +bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY) { return false; } +bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids) { return false; } +void CPdfWriter::UpdateFont() {} +void CPdfWriter::GetFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex) {} +PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontPath, const LONG& lFontIndex) { return NULL; } +PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic) { return NULL; } +void CPdfWriter::UpdateTransform() {} +void CPdfWriter::UpdatePen() {} +void CPdfWriter::UpdateBrush(NSFonts::IApplicationFonts* pAppFonts) {} +void CPdfWriter::Reset() {} +bool CPdfWriter::IsValid() { return false; } +bool CPdfWriter::IsPageValid() { return false; } +void CPdfWriter::SetError() {} +void CPdfWriter::AddLink(PdfWriter::CPage* pPage, const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const unsigned int& unDestPage) {} +unsigned char* CPdfWriter::EncodeString(const unsigned int* pUnicodes, const unsigned int& unUnicodesCount, const unsigned int* pGIDs) { return NULL; } +unsigned char* CPdfWriter::EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount) { return NULL; } +std::wstring CPdfWriter::GetDownloadFile(const std::wstring& sUrl) { return std::wstring(); } + +CPdfWriter::CCommandManager::CCommandManager(CPdfWriter* pRenderer) {} +CPdfWriter::CCommandManager::~CCommandManager() {} +CRendererTextCommand* CPdfWriter::CCommandManager::AddText(unsigned char* pCodes, unsigned int nLen, const double& dX, const double& dY) {} +void CPdfWriter::CCommandManager::Flush() {} +void CPdfWriter::CCommandManager::SetTransform(const CTransform& oTransform) {} +void CPdfWriter::CCommandManager::SetTransform(const double& m11, const double& m12, const double& m21, const double& m22, const double& dx, const double& dy) {} +void CPdfWriter::CCommandManager::Add(CRendererCommandBase* pCommand) {} +void CPdfWriter::CCommandManager::Clear() {} +void CPdfWriter::CBrushState::Reset() {} +#endif diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 9d4f236be2..d4cde6de15 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -119,11 +119,8 @@ public: virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); virtual std::wstring GetInfo(); - -#ifdef BUILDING_WASM_MODULE virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); -#endif // --- WRITER --- diff --git a/PdfFile/Src/PdfReader.cpp b/PdfFile/Src/PdfReader.cpp index fa721e224a..a09526b718 100644 --- a/PdfFile/Src/PdfReader.cpp +++ b/PdfFile/Src/PdfReader.cpp @@ -32,756 +32,588 @@ #define errMemory 12 -#include "../../DesktopEditor/graphics/pro/Graphics.h" #include "PdfReader.h" #include "../../PdfReader/Src/Adaptors.h" #include "../../PdfReader/lib/xpdf/ErrorCodes.h" -#include "../../Common/OfficeDefines.h" -#include "../../DesktopEditor/raster/BgraFrame.h" #include "../../DesktopEditor/graphics/IRenderer.h" #include "../../DesktopEditor/common/Directory.h" #include "../../DesktopEditor/common/StringExt.h" -#include "../../DesktopEditor/common/Path.h" -#include "../../PdfWriter/PdfRenderer.h" #include "../../PdfReader/lib/xpdf/PDFDoc.h" #include "../../PdfReader/lib/xpdf/GlobalParams.h" #include "../../PdfReader/lib/xpdf/ErrorCodes.h" -#include "../../PdfReader/lib/xpdf/ImageOutputDev.h" #include "../../PdfReader/lib/xpdf/TextString.h" -#include "../../PdfReader/lib/xpdf/SecurityHandler.h" #include "../../PdfReader/lib/xpdf/Lexer.h" #include "../../PdfReader/lib/xpdf/Parser.h" -#include "../../PdfReader/lib/xpdf/AcroForm.h" -#include "../../PdfReader/Src/RendererOutputDev.h" #include "../../PdfReader/Src/Adaptors.h" -#ifdef BUILDING_WASM_MODULE #include "../../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" #include "../../PdfReader/lib/xpdf/Outline.h" #include "../../PdfReader/lib/xpdf/Link.h" #include "../../PdfReader/lib/xpdf/TextOutputDev.h" #include "../../PdfReader/lib/goo/GList.h" #include -#endif -namespace PdfReader +CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) { - class CPdfReader_Private - { - public: - PDFDoc* m_pPDFDocument; - std::wstring m_wsTempFolder; - std::wstring m_wsCMapFolder; - std::wstring m_wsSrcPath; - NSFonts::IApplicationFonts* m_pAppFonts; - NSFonts::IFontManager* m_pFontManager; - CFontList* m_pFontList; - DWORD m_nFileLength; - }; + m_wsTempFolder = L""; + m_wsSrcPath = L""; - CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) - { - m_pInternal = new CPdfReader_Private(); + m_pPDFDocument = NULL; + m_nFileLength = 0; - m_pInternal->m_wsTempFolder = L""; - m_pInternal->m_wsCMapFolder = L""; - m_pInternal->m_wsSrcPath = L""; - - m_pInternal->m_pPDFDocument = NULL; - m_pInternal->m_pFontManager = NULL; - m_pInternal->m_nFileLength = 0; - - globalParams = new GlobalParamsAdaptor(NULL); + globalParams = new GlobalParamsAdaptor(NULL); #ifndef _DEBUG - globalParams->setErrQuiet(gTrue); + globalParams->setErrQuiet(gTrue); #endif - m_pInternal->m_pFontList = new CFontList(); + m_pFontList = new PdfReader::CFontList(); - m_pInternal->m_pAppFonts = pAppFonts; - - // Создаем менеджер шрифтов с собственным кэшем - m_pInternal->m_pFontManager = pAppFonts->GenerateFontManager(); - NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); - pMeasurerCache->SetStreams(pAppFonts->GetStreams()); - m_pInternal->m_pFontManager->SetOwnerCache(pMeasurerCache); - pMeasurerCache->SetCacheSize(1); - ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pInternal->m_pFontManager); - #ifndef BUILDING_WASM_MODULE - globalParams->setupBaseFonts(NULL); - #endif + // Создаем менеджер шрифтов с собственным кэшем + m_pFontManager = pAppFonts->GenerateFontManager(); + NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); + pMeasurerCache->SetStreams(pAppFonts->GetStreams()); + m_pFontManager->SetOwnerCache(pMeasurerCache); + pMeasurerCache->SetCacheSize(1); + ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pFontManager); +#ifndef BUILDING_WASM_MODULE + globalParams->setupBaseFonts(NULL); +#endif #ifdef CMAP_USE_MEMORY - SetCMapMemory(); + ((GlobalParamsAdaptor*)globalParams)->SetCMapMemory(); #endif - m_eError = errNone; - } - CPdfReader::~CPdfReader() - { - if (m_pInternal->m_pFontList) - { - m_pInternal->m_pFontList->Clear(); - delete m_pInternal->m_pFontList; - } + m_eError = errNone; +} +CPdfReader::~CPdfReader() +{ + if (m_pFontList) + { + m_pFontList->Clear(); + delete m_pFontList; + } - m_pInternal->m_wsCMapFolder = L""; + if (!m_wsTempFolder.empty()) + { + NSDirectory::DeleteDirectory(m_wsTempFolder); + m_wsTempFolder = L""; + } - if (!m_pInternal->m_wsTempFolder.empty()) - { - NSDirectory::DeleteDirectory(m_pInternal->m_wsTempFolder); - m_pInternal->m_wsTempFolder = L""; - } + RELEASEOBJECT(m_pPDFDocument); + RELEASEOBJECT(globalParams); + RELEASEINTERFACE(m_pFontManager); +} +bool CPdfReader::LoadFromFile(NSFonts::IApplicationFonts* pAppFonts, const std::wstring& wsSrcPath, const std::wstring& wsOwnerPassword, const std::wstring& wsUserPassword) +{ + RELEASEINTERFACE(m_pFontManager); + m_pFontManager = pAppFonts->GenerateFontManager(); + NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); + pMeasurerCache->SetStreams(pAppFonts->GetStreams()); + m_pFontManager->SetOwnerCache(pMeasurerCache); + pMeasurerCache->SetCacheSize(1); + ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pFontManager); - RELEASEOBJECT((m_pInternal->m_pPDFDocument)); - RELEASEOBJECT((globalParams)); - RELEASEINTERFACE((m_pInternal->m_pFontManager)); - } - bool CPdfReader::LoadFromFile(const std::wstring& wsSrcPath, const std::wstring& wsOptions, - const std::wstring& wsOwnerPassword, const std::wstring& wsUserPassword) - { -// TODO: Сейчас при загрузке каждой новой картинки мы пересоздаем -// FontManager, потому что сейчас в нем кэш без ограничения. -//------------------------------------------------------ - RELEASEINTERFACE((m_pInternal->m_pFontManager)); - m_pInternal->m_pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager(); - NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); - pMeasurerCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams()); - m_pInternal->m_pFontManager->SetOwnerCache(pMeasurerCache); - pMeasurerCache->SetCacheSize(1); - ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pInternal->m_pFontManager); -//------------------------------------------------------ + if (m_pPDFDocument) + delete m_pPDFDocument; - if (m_pInternal->m_pPDFDocument) - delete m_pInternal->m_pPDFDocument; + if (GetTempDirectory() == L"") + { + SetTempDirectory(NSDirectory::GetTempPath()); + } - if (GetTempDirectory() == L"") + m_eError = errNone; + GString* owner_pswd = NSStrings::CreateString(wsOwnerPassword); + GString* user_pswd = NSStrings::CreateString(wsUserPassword); + + // конвертим путь в utf8 - под виндой они сконвертят в юникод, а на остальных - так и надо + m_wsSrcPath = wsSrcPath; + std::string sPathUtf8 = U_TO_UTF8(wsSrcPath); + m_pPDFDocument = new PDFDoc((char*)sPathUtf8.c_str(), owner_pswd, user_pswd); + + delete owner_pswd; + delete user_pswd; + + NSFile::CFileBinary oFile; + if (oFile.OpenFile(wsSrcPath)) + { + m_nFileLength = oFile.GetFileSize(); + oFile.CloseFile(); + } + + if (m_pPDFDocument) + m_eError = m_pPDFDocument->getErrorCode(); + else + m_eError = errMemory; + + if (!m_pPDFDocument || !m_pPDFDocument->isOk()) + { + RELEASEOBJECT(m_pPDFDocument); + return false; + } + + m_pFontList->Clear(); + + return true; +} +bool CPdfReader::LoadFromMemory(NSFonts::IApplicationFonts* pAppFonts, BYTE* data, DWORD length, const std::wstring& owner_password, const std::wstring& user_password) +{ + RELEASEINTERFACE(m_pFontManager); + m_pFontManager = pAppFonts->GenerateFontManager(); + NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); + pMeasurerCache->SetStreams(pAppFonts->GetStreams()); + m_pFontManager->SetOwnerCache(pMeasurerCache); + pMeasurerCache->SetCacheSize(1); + ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pFontManager); + + RELEASEOBJECT(m_pPDFDocument); + m_eError = errNone; + GString* owner_pswd = NSStrings::CreateString(owner_password); + GString* user_pswd = NSStrings::CreateString(user_password); + + Object obj; + obj.initNull(); + // будет освобожден в деструкторе PDFDoc + BaseStream *str = new MemStream((char*)data, 0, length, &obj); + m_pPDFDocument = new PDFDoc(str, owner_pswd, user_pswd); + m_nFileLength = length; + + delete owner_pswd; + delete user_pswd; + + m_eError = m_pPDFDocument ? m_pPDFDocument->getErrorCode() : errMemory; + + if (!m_pPDFDocument || !m_pPDFDocument->isOk()) + { + RELEASEOBJECT(m_pPDFDocument); + return false; + } + + m_pFontList->Clear(); + + return true; +} +void CPdfReader::Close() +{ + RELEASEOBJECT(m_pPDFDocument); +} + +int CPdfReader::GetError() +{ + if (!m_pPDFDocument) + return m_eError; + + if (m_pPDFDocument->isOk()) + return 0; + + return m_pPDFDocument->getErrorCode(); +} +int CPdfReader::GetPagesCount() +{ + if (!m_pPDFDocument) + return 0; + + return m_pPDFDocument->getNumPages(); +} +double CPdfReader::GetVersion() +{ + if (!m_pPDFDocument) + return 0; + + return m_pPDFDocument->getPDFVersion(); +} +void CPdfReader::GetPageInfo(int _nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) +{ + int nPageIndex = _nPageIndex + 1; + + if (!m_pPDFDocument) + return; + + int nRotate = m_pPDFDocument->getPageRotate(nPageIndex); + + while (nRotate >= 360) + nRotate -= 360; + + while (nRotate < 0) + nRotate += 360; + + if (0 != nRotate && 180 != nRotate) + { + *pdHeight = m_pPDFDocument->getPageCropWidth(nPageIndex); + *pdWidth = m_pPDFDocument->getPageCropHeight(nPageIndex); + } + else + { + *pdWidth = m_pPDFDocument->getPageCropWidth(nPageIndex); + *pdHeight = m_pPDFDocument->getPageCropHeight(nPageIndex); + } + + *pdDpiX = 72; + *pdDpiY = 72; +} +void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* pbBreak) +{ + int nPageIndex = _nPageIndex + 1; + + if (m_pPDFDocument && pRenderer) + { + PdfReader::RendererOutputDev oRendererOut(pRenderer, m_pFontManager, m_pFontList); + oRendererOut.NewPDF(m_pPDFDocument->getXRef()); + oRendererOut.SetBreak(pbBreak); + m_pPDFDocument->displayPage(&oRendererOut, nPageIndex, 72.0, 72.0, 0, false, true, false); + } +} +void CPdfReader::SetTempDirectory(const std::wstring& wsTempFolder) +{ + if (!m_wsTempFolder.empty()) + { + NSDirectory::DeleteDirectory(m_wsTempFolder); + m_wsTempFolder = wsTempFolder; + } + + if (!wsTempFolder.empty()) + { + std::wstring wsFolderName = std::wstring(wsTempFolder) + L"//pdftemp"; + std::wstring wsFolder = wsFolderName; + int nCounter = 0; + while (NSDirectory::Exists(wsFolder)) { - SetTempDirectory(NSDirectory::GetTempPath()); + nCounter++; + wsFolder = wsFolderName + L"_" + std::to_wstring(nCounter); } - - m_eError = errNone; - GString* owner_pswd = NSStrings::CreateString(wsOwnerPassword); - GString* user_pswd = NSStrings::CreateString(wsUserPassword); - - // конвертим путь в utf8 - под виндой они сконвертят в юникод, а на остальных - так и надо - m_pInternal->m_wsSrcPath = wsSrcPath; - std::string sPathUtf8 = U_TO_UTF8(wsSrcPath); - m_pInternal->m_pPDFDocument = new PDFDoc((char*)sPathUtf8.c_str(), owner_pswd, user_pswd); - - delete owner_pswd; - delete user_pswd; - - NSFile::CFileBinary oFile; - if (oFile.OpenFile(wsSrcPath)) - { - m_pInternal->m_nFileLength = oFile.GetFileSize(); - oFile.CloseFile(); - } - - if (m_pInternal->m_pPDFDocument) - m_eError = m_pInternal->m_pPDFDocument->getErrorCode(); - else - m_eError = errMemory; - - if (!m_pInternal->m_pPDFDocument || !m_pInternal->m_pPDFDocument->isOk()) - { - RELEASEOBJECT(m_pInternal->m_pPDFDocument); - return false; - } - - m_pInternal->m_pFontList->Clear(); - - return true; - } - bool CPdfReader::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options, - const std::wstring& owner_password, const std::wstring& user_password) - { -// TODO: Сейчас при загрузке каждой новой картинки мы пересоздаем -// FontManager, потому что сейчас в нем кэш без ограничения. -//------------------------------------------------------ - RELEASEINTERFACE((m_pInternal->m_pFontManager)); - m_pInternal->m_pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager(); - NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); - pMeasurerCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams()); - m_pInternal->m_pFontManager->SetOwnerCache(pMeasurerCache); - pMeasurerCache->SetCacheSize(1); - ((GlobalParamsAdaptor*)globalParams)->SetFontManager(m_pInternal->m_pFontManager); -//------------------------------------------------------ - - RELEASEOBJECT(m_pInternal->m_pPDFDocument); - m_eError = errNone; - GString* owner_pswd = NSStrings::CreateString(owner_password); - GString* user_pswd = NSStrings::CreateString(user_password); - - Object obj; - obj.initNull(); - // будет освобожден в деструкторе PDFDoc - BaseStream *str = new MemStream((char*)data, 0, length, &obj); - m_pInternal->m_pPDFDocument = new PDFDoc(str, owner_pswd, user_pswd); - m_pInternal->m_nFileLength = length; - - delete owner_pswd; - delete user_pswd; - - m_eError = m_pInternal->m_pPDFDocument ? m_pInternal->m_pPDFDocument->getErrorCode() : errMemory; - - if (!m_pInternal->m_pPDFDocument || !m_pInternal->m_pPDFDocument->isOk()) - { - RELEASEOBJECT(m_pInternal->m_pPDFDocument); - return false; - } - - m_pInternal->m_pFontList->Clear(); - - return true; - } - void CPdfReader::Close() - { - RELEASEOBJECT((m_pInternal->m_pPDFDocument)); - } - NSFonts::IApplicationFonts* CPdfReader::GetFonts() - { - return m_pInternal->m_pAppFonts; + NSDirectory::CreateDirectory(wsFolder); + m_wsTempFolder = wsFolder; } + else + m_wsTempFolder = L""; - int CPdfReader::GetError() - { - if (!m_pInternal->m_pPDFDocument) - return m_eError; + if (globalParams) + ((GlobalParamsAdaptor*)globalParams)->SetTempFolder(m_wsTempFolder.c_str()); +} +std::wstring CPdfReader::GetTempDirectory() +{ + return m_wsTempFolder; +} - if (m_pInternal->m_pPDFDocument->isOk()) - return 0; - - return m_pInternal->m_pPDFDocument->getErrorCode(); - } - int CPdfReader::GetPagesCount() - { - if (!m_pInternal->m_pPDFDocument) - return 0; - - return m_pInternal->m_pPDFDocument->getNumPages(); - } - double CPdfReader::GetVersion() - { - if (!m_pInternal->m_pPDFDocument) - return 0; - - return m_pInternal->m_pPDFDocument->getPDFVersion(); - } - int CPdfReader::GetPermissions() - { - if (!m_pInternal->m_pPDFDocument) - return 0; - - int nPermissions = 0; - - if (m_pInternal->m_pPDFDocument->okToPrint()) - nPermissions += PERMISSION_PRINT; - if (m_pInternal->m_pPDFDocument->okToCopy()) - nPermissions += PERMISSION_COPY; - if (m_pInternal->m_pPDFDocument->okToChange()) - nPermissions += PERMISSION_CHANGE; - - return nPermissions; - } - std::wstring CPdfReader::GetPageLabel(int nPageIndex) - { - if (!m_pInternal->m_pPDFDocument) - return std::wstring(); -// todo label -// StringExt* seLabel = m_pInternal->m_pPDFDocument->GetPageLabels()->GetLabel(nPageIndex); -// if (seLabel) -// { -// std::wstring wsResult(seLabel->GetWString()); -// delete seLabel; -// return wsResult; -// } - - return std::wstring(); - } - bool CPdfReader::ExtractAllImages(const wchar_t* wsDstPath, const wchar_t* wsPrefix) - { - std::wstring sDstPath(wsDstPath); - if (sDstPath.empty()) - return false; - - // check last symbol (directory) - wchar_t nLastSymbol = sDstPath[sDstPath.length() - 1]; - if ('\\' != nLastSymbol && '/' != nLastSymbol) - sDstPath += '/'; - // prefix for each file - if (NULL != wsPrefix) - sDstPath += std::wstring(wsPrefix); - - std::string sDstPathA = U_TO_UTF8(sDstPath); - ImageOutputDev *pOutputDev = new ImageOutputDev((char*)sDstPathA.c_str(), true, false, false); - if (!pOutputDev) - return false; - - int nPagesCount = GetPagesCount(); - for (int nIndex = 1; nIndex <= nPagesCount; nIndex++) - { - m_pInternal->m_pPDFDocument->displayPage(pOutputDev, nIndex, 72, 72, 0, false, false, false); - } - - delete pOutputDev; - - return true; - } - void CPdfReader::GetPageInfo(int _nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) - { - int nPageIndex = _nPageIndex + 1; - - if (!m_pInternal->m_pPDFDocument) - return; - - const double c_dInch = 25.399; // Миллиметров в дюйме - const double c_dXResolution = 154.0; - const double c_dYResolution = 154.0; - - double dKoefX = c_dInch / c_dXResolution; - double dKoefY = c_dInch / c_dYResolution; - - int nRotate = m_pInternal->m_pPDFDocument->getPageRotate(nPageIndex); - - while (nRotate >= 360) - nRotate -= 360; - - while (nRotate < 0) - nRotate += 360; - - if (0 != nRotate && 180 != nRotate) - { - *pdHeight = m_pInternal->m_pPDFDocument->getPageCropWidth(nPageIndex); - *pdWidth = m_pInternal->m_pPDFDocument->getPageCropHeight(nPageIndex); - } - else - { - *pdWidth = m_pInternal->m_pPDFDocument->getPageCropWidth(nPageIndex); - *pdHeight = m_pInternal->m_pPDFDocument->getPageCropHeight(nPageIndex); - } - - *pdDpiX = 72; - *pdDpiY = 72; - } - void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* pbBreak) - { - int nPageIndex = _nPageIndex + 1; - - if (m_pInternal->m_pPDFDocument && pRenderer) - { - RendererOutputDev oRendererOut(pRenderer, m_pInternal->m_pFontManager, m_pInternal->m_pFontList); - oRendererOut.NewPDF(m_pInternal->m_pPDFDocument->getXRef()); - oRendererOut.SetBreak(pbBreak); - m_pInternal->m_pPDFDocument->displayPage(&oRendererOut, nPageIndex, 72.0, 72.0, 0, false, true, false); - } - } - int CPdfReader::GetImagesCount() - { -// ImageOutputDev *pOutputDev = new ImageOutputDev(NULL, true, true, false); -// if (!pOutputDev) -// return 0; -// -// for (int nIndex = 1; nIndex <= m_pInternal->m_pPDFDocument->GetPagesCount(); nIndex++) -// { -// m_pInternal->m_pPDFDocument->displayPage(pOutputDev, nIndex, 72, 72, 0, false, false, false); -// } -// -// return pOutputDev-> -return 0; - } - void CPdfReader::SetTempDirectory(const std::wstring& wsTempFolder) - { - if (!m_pInternal->m_wsTempFolder.empty()) - { - NSDirectory::DeleteDirectory(m_pInternal->m_wsTempFolder); - m_pInternal->m_wsTempFolder = wsTempFolder; - } - - if (!wsTempFolder.empty()) - { - std::wstring wsFolderName = std::wstring(wsTempFolder) + L"//pdftemp"; - std::wstring wsFolder = wsFolderName; - int nCounter = 0; - while (NSDirectory::Exists(wsFolder)) - { - nCounter++; - wsFolder = wsFolderName + L"_" + std::to_wstring(nCounter); - } - NSDirectory::CreateDirectory(wsFolder); - m_pInternal->m_wsTempFolder = wsFolder; - } - else - m_pInternal->m_wsTempFolder = L""; - - if (globalParams) - ((GlobalParamsAdaptor*)globalParams)->SetTempFolder(m_pInternal->m_wsTempFolder.c_str()); - } - std::wstring CPdfReader::GetTempDirectory() - { - return m_pInternal->m_wsTempFolder; - } - - void CPdfReader::SetCMapFolder(const wchar_t* wsCMapFolder) - { - m_pInternal->m_wsCMapFolder = std::wstring(wsCMapFolder); - - if (globalParams) - ((GlobalParamsAdaptor*)globalParams)->SetCMapFolder(m_pInternal->m_wsCMapFolder.c_str()); - } - void CPdfReader::SetCMapMemory() - { - if (globalParams) - ((GlobalParamsAdaptor*)globalParams)->SetCMapMemory(); - } - NSFonts::IFontManager* CPdfReader::GetFontManager() - { - return m_pInternal->m_pFontManager; - } - std::wstring CPdfReader::ToXml(const std::wstring& wsFilePath, bool isPrintStream) - { - XMLConverter oConverter(m_pInternal->m_pPDFDocument->getXRef(), isPrintStream); - std::wstring wsXml = oConverter.GetXml(); - - if (wsFilePath != L"") - { - NSFile::CFileBinary oFile; - if (!oFile.CreateFileW(wsFilePath)) - return wsXml; - - oFile.WriteStringUTF8(wsXml); - oFile.CloseFile(); - } - - return wsXml; - } - PDFDoc* CPdfReader::GetPDFDocument() - { - return m_pInternal->m_pPDFDocument; - } - void CPdfReader::ChangeLength(DWORD nLength) - { - m_pInternal->m_nFileLength = nLength; - } +void CPdfReader::ChangeLength(DWORD nLength) +{ + m_nFileLength = nLength; +} #define DICT_LOOKUP(sName, wsName) \ - if (info.dictLookup(sName, &obj1)->isString())\ - {\ - TextString* s = new TextString(obj1.getString());\ - sRes += L"\"";\ - sRes += wsName;\ - sRes += L"\":\"";\ - std::wstring sValue = NSStringExt::CConverter::GetUnicodeFromUTF32(s->getUnicode(), s->getLength());\ - NSStringExt::Replace(sValue, L"\"", L"\\\"");\ - sRes += sValue;\ - sRes += L"\",";\ - delete s;\ - }\ +if (info.dictLookup(sName, &obj1)->isString())\ +{\ + TextString* s = new TextString(obj1.getString());\ + sRes += L"\"";\ + sRes += wsName;\ + sRes += L"\":\"";\ + std::wstring sValue = NSStringExt::CConverter::GetUnicodeFromUTF32(s->getUnicode(), s->getLength());\ + NSStringExt::Replace(sValue, L"\"", L"\\\"");\ + sRes += sValue;\ + sRes += L"\",";\ + delete s;\ +}\ #define DICT_LOOKUP_DATE(sName, wsName) \ - if (info.dictLookup(sName, &obj1)->isString())\ +if (info.dictLookup(sName, &obj1)->isString())\ +{\ + char* str = obj1.getString()->getCString();\ + if (str)\ {\ - char* str = obj1.getString()->getCString();\ - if (str)\ + TextString* s = new TextString(obj1.getString());\ + std::wstring sNoDate = NSStringExt::CConverter::GetUnicodeFromUTF32(s->getUnicode(), s->getLength());\ + if (sNoDate.length() > 16)\ {\ - TextString* s = new TextString(obj1.getString());\ - std::wstring sNoDate = NSStringExt::CConverter::GetUnicodeFromUTF32(s->getUnicode(), s->getLength());\ - if (sNoDate.length() > 16)\ - {\ - std::wstring sDate = sNoDate.substr(2, 4) + L'-' + sNoDate.substr(6, 2) + L'-' + sNoDate.substr(8, 2) + L'T' +\ - sNoDate.substr(10, 2) + L':' + sNoDate.substr(12, 2) + L':' + sNoDate.substr(14, 2);\ - if (sNoDate.length() > 21)\ - sDate += (L".000" + sNoDate.substr(16, 3) + L':' + sNoDate.substr(20, 2));\ - else\ - sDate += L"Z";\ - NSStringExt::Replace(sDate, L"\"", L"\\\"");\ - sRes += L"\"";\ - sRes += wsName;\ - sRes += L"\":\"";\ - sRes += sDate;\ - sRes += L"\",";\ - }\ - delete s;\ + std::wstring sDate = sNoDate.substr(2, 4) + L'-' + sNoDate.substr(6, 2) + L'-' + sNoDate.substr(8, 2) + L'T' +\ + sNoDate.substr(10, 2) + L':' + sNoDate.substr(12, 2) + L':' + sNoDate.substr(14, 2);\ + if (sNoDate.length() > 21)\ + sDate += (L".000" + sNoDate.substr(16, 3) + L':' + sNoDate.substr(20, 2));\ + else\ + sDate += L"Z";\ + NSStringExt::Replace(sDate, L"\"", L"\\\"");\ + sRes += L"\"";\ + sRes += wsName;\ + sRes += L"\":\"";\ + sRes += sDate;\ + sRes += L"\",";\ }\ + delete s;\ }\ +}\ - std::wstring CPdfReader::GetInfo() +std::wstring CPdfReader::GetInfo() +{ + if (!m_pPDFDocument) + return NULL; + XRef* xref = m_pPDFDocument->getXRef(); + BaseStream* str = m_pPDFDocument->getBaseStream(); + if (!xref || !str) + return NULL; + + std::wstring sRes = L"{"; + + Object info, obj1; + m_pPDFDocument->getDocInfo(&info); + if (info.isDict()) { - if (!m_pInternal->m_pPDFDocument) - return NULL; - XRef* xref = m_pInternal->m_pPDFDocument->getXRef(); - BaseStream* str = m_pInternal->m_pPDFDocument->getBaseStream(); - if (!xref || !str) - return NULL; + DICT_LOOKUP("Title", L"Title"); + DICT_LOOKUP("Author", L"Author"); + DICT_LOOKUP("Subject", L"Subject"); + DICT_LOOKUP("Keywords", L"Keywords"); + DICT_LOOKUP("Creator", L"Creator"); + DICT_LOOKUP("Producer", L"Producer"); - std::wstring sRes = L"{"; - - Object info, obj1; - m_pInternal->m_pPDFDocument->getDocInfo(&info); - if (info.isDict()) - { - DICT_LOOKUP("Title", L"Title"); - DICT_LOOKUP("Author", L"Author"); - DICT_LOOKUP("Subject", L"Subject"); - DICT_LOOKUP("Keywords", L"Keywords"); - DICT_LOOKUP("Creator", L"Creator"); - DICT_LOOKUP("Producer", L"Producer"); - - DICT_LOOKUP_DATE("CreationDate", L"CreationDate"); - DICT_LOOKUP_DATE("ModDate", L"ModDate"); - } - - info.free(); - obj1.free(); - - std::wstring version = std::to_wstring(GetVersion()); - std::wstring::size_type posDot = version.find('.'); - if (posDot != std::wstring::npos) - version = version.substr(0, posDot + 2); - - sRes += L"\"Version\":"; - sRes += version; - double nW = 0; - double nH = 0; - double nDpi = 0; - GetPageInfo(0, &nW, &nH, &nDpi, &nDpi); - sRes += L",\"PageWidth\":"; - sRes += std::to_wstring((int)(nW * 100)); - sRes += L",\"PageHeight\":"; - sRes += std::to_wstring((int)(nH * 100)); - sRes += L",\"NumberOfPages\":"; - sRes += std::to_wstring(GetPagesCount()); - sRes += L",\"FastWebView\":"; - - Object obj2, obj3, obj4, obj5, obj6; - bool bLinearized = false; - obj1.initNull(); - Parser* parser = new Parser(xref, new Lexer(xref, str->makeSubStream(str->getStart(), gFalse, 0, &obj1)), gTrue); - parser->getObj(&obj1); - parser->getObj(&obj2); - parser->getObj(&obj3); - parser->getObj(&obj4); - if (obj1.isInt() && obj2.isInt() && obj3.isCmd("obj") && obj4.isDict()) - { - obj4.dictLookup("Linearized", &obj5); - obj4.dictLookup("L", &obj6); - if (obj5.isNum() && obj5.getNum() > 0 && obj6.isNum()) - { - unsigned long size = obj6.getNum(); - bLinearized = size == m_pInternal->m_nFileLength; - } - obj6.free(); - obj5.free(); - } - obj4.free(); - obj3.free(); - obj2.free(); - obj1.free(); - delete parser; - - sRes += bLinearized ? L"true" : L"false"; - sRes += L",\"Tagged\":"; - - bool bTagged = false; - Object catDict, markInfoObj; - if (xref->getCatalog(&catDict) && catDict.isDict() && catDict.dictLookup("MarkInfo", &markInfoObj) && markInfoObj.isDict()) - { - Object marked, suspects; - if (markInfoObj.dictLookup("Marked", &marked) && marked.isBool() && marked.getBool()) - { - bTagged = true; - // If Suspects is true, the document may not completely conform to Tagged PDF conventions. - if (markInfoObj.dictLookup("Suspects", &suspects) && suspects.isBool() && suspects.getBool()) - bTagged = false; - } - marked.free(); - suspects.free(); - } - markInfoObj.free(); - catDict.free(); - - sRes += bTagged ? L"true" : L"false"; - sRes += L"}"; - - return sRes; + DICT_LOOKUP_DATE("CreationDate", L"CreationDate"); + DICT_LOOKUP_DATE("ModDate", L"ModDate"); } -#ifdef BUILDING_WASM_MODULE - void getBookmars(PDFDoc* pdfDoc, OutlineItem* pOutlineItem, NSWasm::CData& out, int level) + + info.free(); + obj1.free(); + + std::wstring version = std::to_wstring(GetVersion()); + std::wstring::size_type posDot = version.find('.'); + if (posDot != std::wstring::npos) + version = version.substr(0, posDot + 2); + + sRes += L"\"Version\":"; + sRes += version; + double nW = 0; + double nH = 0; + double nDpi = 0; + GetPageInfo(0, &nW, &nH, &nDpi, &nDpi); + sRes += L",\"PageWidth\":"; + sRes += std::to_wstring((int)(nW * 100)); + sRes += L",\"PageHeight\":"; + sRes += std::to_wstring((int)(nH * 100)); + sRes += L",\"NumberOfPages\":"; + sRes += std::to_wstring(GetPagesCount()); + sRes += L",\"FastWebView\":"; + + Object obj2, obj3, obj4, obj5, obj6; + bool bLinearized = false; + obj1.initNull(); + Parser* parser = new Parser(xref, new Lexer(xref, str->makeSubStream(str->getStart(), gFalse, 0, &obj1)), gTrue); + parser->getObj(&obj1); + parser->getObj(&obj2); + parser->getObj(&obj3); + parser->getObj(&obj4); + if (obj1.isInt() && obj2.isInt() && obj3.isCmd("obj") && obj4.isDict()) { - int nLengthTitle = pOutlineItem->getTitleLength(); - Unicode* pTitle = pOutlineItem->getTitle(); - std::string sTitle = NSStringExt::CConverter::GetUtf8FromUTF32(pTitle, nLengthTitle); - - LinkAction* pLinkAction = pOutlineItem->getAction(); - if (!pLinkAction) - return; - LinkActionKind kind = pLinkAction->getKind(); - if (kind != actionGoTo) - return; - - GString* str = ((LinkGoTo*)pLinkAction)->getNamedDest(); - LinkDest* pLinkDest = str ? pdfDoc->findDest(str) : ((LinkGoTo*)pLinkAction)->getDest(); - if (!pLinkDest) - return; - int pg; - if (pLinkDest->isPageRef()) + obj4.dictLookup("Linearized", &obj5); + obj4.dictLookup("L", &obj6); + if (obj5.isNum() && obj5.getNum() > 0 && obj6.isNum()) { - Ref pageRef = pLinkDest->getPageRef(); - pg = pdfDoc->findPage(pageRef.num, pageRef.gen); + unsigned long size = (unsigned long)obj6.getNum(); + bLinearized = size == m_nFileLength; } - else - pg = pLinkDest->getPageNum(); - if (pg == 0) - pg = 1; - double dy = 0; - double dTop = pLinkDest->getTop(); - double dHeight = pdfDoc->getPageCropHeight(pg); - if (dTop > 0 && dTop < dHeight) - dy = dHeight - dTop; - if (str) - RELEASEOBJECT(pLinkDest); - - out.AddInt(pg - 1); - out.AddInt(level); - out.AddDouble(dy); - out.WriteString((BYTE*)sTitle.c_str(), sTitle.length()); - - pOutlineItem->open(); - GList* pList = pOutlineItem->getKids(); - if (!pList) - return; - int num = pList->getLength(); - for (int i = 0; i < num; i++) - { - OutlineItem* pOutlineItemKid = (OutlineItem*)pList->get(i); - if (!pOutlineItemKid) - continue; - getBookmars(pdfDoc, pOutlineItemKid, out, level + 1); - } - pOutlineItem->close(); + obj6.free(); + obj5.free(); } - BYTE* CPdfReader::GetStructure() + obj4.free(); + obj3.free(); + obj2.free(); + obj1.free(); + delete parser; + + sRes += bLinearized ? L"true" : L"false"; + sRes += L",\"Tagged\":"; + + bool bTagged = false; + Object catDict, markInfoObj; + if (xref->getCatalog(&catDict) && catDict.isDict() && catDict.dictLookup("MarkInfo", &markInfoObj) && markInfoObj.isDict()) { - if (!m_pInternal->m_pPDFDocument) - return NULL; - Outline* pOutline = m_pInternal->m_pPDFDocument->getOutline(); - if (!pOutline) - return NULL; - GList* pList = pOutline->getItems(); - if (!pList) - return NULL; - - NSWasm::CData oRes; - oRes.SkipLen(); - int num = pList->getLength(); - for (int i = 0; i < num; i++) + Object marked, suspects; + if (markInfoObj.dictLookup("Marked", &marked) && marked.isBool() && marked.getBool()) { - OutlineItem* pOutlineItem = (OutlineItem*)pList->get(i); - if (pOutlineItem) - getBookmars(m_pInternal->m_pPDFDocument, pOutlineItem, oRes, 1); + bTagged = true; + // If Suspects is true, the document may not completely conform to Tagged PDF conventions. + if (markInfoObj.dictLookup("Suspects", &suspects) && suspects.isBool() && suspects.getBool()) + bTagged = false; } - oRes.WriteLen(); - - BYTE* bRes = oRes.GetBuffer(); - oRes.ClearWithoutAttack(); - return bRes; + marked.free(); + suspects.free(); } - BYTE* CPdfReader::GetLinks(int nPageIndex) - { - if (!m_pInternal->m_pPDFDocument) - return NULL; + markInfoObj.free(); + catDict.free(); - nPageIndex++; + sRes += bTagged ? L"true" : L"false"; + sRes += L"}"; - NSWasm::CPageLink oLinks; - double height = m_pInternal->m_pPDFDocument->getPageCropHeight(nPageIndex); - - // Гиперссылка - Links* pLinks = m_pInternal->m_pPDFDocument->getLinks(nPageIndex); - if (!pLinks) - return NULL; - - int num = pLinks->getNumLinks(); - for (int i = 0; i < num; i++) - { - Link* pLink = pLinks->getLink(i); - if (!pLink) - continue; - - GString* str = NULL; - double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, dy = 0.0; - pLink->getRect(&x1, &y1, &x2, &y2); - y1 = height - y1; - y2 = height - y2; - - LinkAction* pLinkAction = pLink->getAction(); - if (!pLinkAction) - continue; - LinkActionKind kind = pLinkAction->getKind(); - if (kind == actionGoTo) - { - str = ((LinkGoTo*)pLinkAction)->getNamedDest(); - LinkDest* pLinkDest = str ? m_pInternal->m_pPDFDocument->findDest(str) : ((LinkGoTo*)pLinkAction)->getDest()->copy(); - if (pLinkDest) - { - int pg; - if (pLinkDest->isPageRef()) - { - Ref pageRef = pLinkDest->getPageRef(); - pg = m_pInternal->m_pPDFDocument->findPage(pageRef.num, pageRef.gen); - } - else - pg = pLinkDest->getPageNum(); - std::string sLink = "#" + std::to_string(pg - 1); - str = new GString(sLink.c_str()); - dy = m_pInternal->m_pPDFDocument->getPageCropHeight(pg) - pLinkDest->getTop(); - } - RELEASEOBJECT(pLinkDest); - } - else if (kind == actionURI) - str = ((LinkURI*)pLinkAction)->getURI()->copy(); - - oLinks.m_arLinks.push_back({str ? std::string(str->getCString(), str->getLength()) : "", dy, x1, y2, x2 - x1, y1 - y2}); - RELEASEOBJECT(str); - } - RELEASEOBJECT(pLinks); - - // Текст-ссылка - TextOutputControl textOutControl; - textOutControl.mode = textOutReadingOrder; - TextOutputDev* pTextOut = new TextOutputDev(NULL, &textOutControl, gFalse); - m_pInternal->m_pPDFDocument->displayPage(pTextOut, nPageIndex, 72, 72, 0, gFalse, gTrue, gFalse); - m_pInternal->m_pPDFDocument->processLinks(pTextOut, nPageIndex); - TextWordList* pWordList = pTextOut->makeWordList(); - for (int i = 0; i < pWordList->getLength(); i++) - { - TextWord* pWord = pWordList->get(i); - if (!pWord) - continue; - GString* sLink = pWord->getText(); - if (!sLink) - continue; - std::string link(sLink->getCString(), sLink->getLength()); - size_t find = link.find("http://"); - if (find == std::string::npos) - find = link.find("https://"); - if (find == std::string::npos) - find = link.find("www."); - if (find != std::string::npos) - { - link.erase(0, find); - double x1, y1, x2, y2; - pWord->getBBox(&x1, &y1, &x2, &y2); - oLinks.m_arLinks.push_back({link, 0, x1, y1, x2 - x1, y2 - y1}); - } - } - RELEASEOBJECT(pTextOut); - - return oLinks.Serialize(); - } -#endif + return sRes; +} + +void getBookmars(PDFDoc* pdfDoc, OutlineItem* pOutlineItem, NSWasm::CData& out, int level) +{ + int nLengthTitle = pOutlineItem->getTitleLength(); + Unicode* pTitle = pOutlineItem->getTitle(); + std::string sTitle = NSStringExt::CConverter::GetUtf8FromUTF32(pTitle, nLengthTitle); + + LinkAction* pLinkAction = pOutlineItem->getAction(); + if (!pLinkAction) + return; + LinkActionKind kind = pLinkAction->getKind(); + if (kind != actionGoTo) + return; + + GString* str = ((LinkGoTo*)pLinkAction)->getNamedDest(); + LinkDest* pLinkDest = str ? pdfDoc->findDest(str) : ((LinkGoTo*)pLinkAction)->getDest(); + if (!pLinkDest) + return; + int pg; + if (pLinkDest->isPageRef()) + { + Ref pageRef = pLinkDest->getPageRef(); + pg = pdfDoc->findPage(pageRef.num, pageRef.gen); + } + else + pg = pLinkDest->getPageNum(); + if (pg == 0) + pg = 1; + double dy = 0; + double dTop = pLinkDest->getTop(); + double dHeight = pdfDoc->getPageCropHeight(pg); + if (dTop > 0 && dTop < dHeight) + dy = dHeight - dTop; + if (str) + RELEASEOBJECT(pLinkDest); + + out.AddInt(pg - 1); + out.AddInt(level); + out.AddDouble(dy); + out.WriteString((BYTE*)sTitle.c_str(), (unsigned int)sTitle.length()); + + pOutlineItem->open(); + GList* pList = pOutlineItem->getKids(); + if (!pList) + return; + int num = pList->getLength(); + for (int i = 0; i < num; i++) + { + OutlineItem* pOutlineItemKid = (OutlineItem*)pList->get(i); + if (!pOutlineItemKid) + continue; + getBookmars(pdfDoc, pOutlineItemKid, out, level + 1); + } + pOutlineItem->close(); +} +BYTE* CPdfReader::GetStructure() +{ + if (!m_pPDFDocument) + return NULL; + Outline* pOutline = m_pPDFDocument->getOutline(); + if (!pOutline) + return NULL; + GList* pList = pOutline->getItems(); + if (!pList) + return NULL; + + NSWasm::CData oRes; + oRes.SkipLen(); + int num = pList->getLength(); + for (int i = 0; i < num; i++) + { + OutlineItem* pOutlineItem = (OutlineItem*)pList->get(i); + if (pOutlineItem) + getBookmars(m_pPDFDocument, pOutlineItem, oRes, 1); + } + oRes.WriteLen(); + + BYTE* bRes = oRes.GetBuffer(); + oRes.ClearWithoutAttack(); + return bRes; +} +BYTE* CPdfReader::GetLinks(int nPageIndex) +{ + if (!m_pPDFDocument) + return NULL; + + nPageIndex++; + + NSWasm::CPageLink oLinks; + double height = m_pPDFDocument->getPageCropHeight(nPageIndex); + + // Гиперссылка + Links* pLinks = m_pPDFDocument->getLinks(nPageIndex); + if (!pLinks) + return NULL; + + int num = pLinks->getNumLinks(); + for (int i = 0; i < num; i++) + { + Link* pLink = pLinks->getLink(i); + if (!pLink) + continue; + + GString* str = NULL; + double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, dy = 0.0; + pLink->getRect(&x1, &y1, &x2, &y2); + y1 = height - y1; + y2 = height - y2; + + LinkAction* pLinkAction = pLink->getAction(); + if (!pLinkAction) + continue; + LinkActionKind kind = pLinkAction->getKind(); + if (kind == actionGoTo) + { + str = ((LinkGoTo*)pLinkAction)->getNamedDest(); + LinkDest* pLinkDest = str ? m_pPDFDocument->findDest(str) : ((LinkGoTo*)pLinkAction)->getDest()->copy(); + if (pLinkDest) + { + int pg; + if (pLinkDest->isPageRef()) + { + Ref pageRef = pLinkDest->getPageRef(); + pg = m_pPDFDocument->findPage(pageRef.num, pageRef.gen); + } + else + pg = pLinkDest->getPageNum(); + std::string sLink = "#" + std::to_string(pg - 1); + str = new GString(sLink.c_str()); + dy = m_pPDFDocument->getPageCropHeight(pg) - pLinkDest->getTop(); + } + RELEASEOBJECT(pLinkDest); + } + else if (kind == actionURI) + str = ((LinkURI*)pLinkAction)->getURI()->copy(); + + oLinks.m_arLinks.push_back({str ? std::string(str->getCString(), str->getLength()) : "", dy, x1, y2, x2 - x1, y1 - y2}); + RELEASEOBJECT(str); + } + RELEASEOBJECT(pLinks); + + // Текст-ссылка + TextOutputControl textOutControl; + textOutControl.mode = textOutReadingOrder; + TextOutputDev* pTextOut = new TextOutputDev(NULL, &textOutControl, gFalse); + m_pPDFDocument->displayPage(pTextOut, nPageIndex, 72, 72, 0, gFalse, gTrue, gFalse); + m_pPDFDocument->processLinks(pTextOut, nPageIndex); + TextWordList* pWordList = pTextOut->makeWordList(); + for (int i = 0; i < pWordList->getLength(); i++) + { + TextWord* pWord = pWordList->get(i); + if (!pWord) + continue; + GString* sLink = pWord->getText(); + if (!sLink) + continue; + std::string link(sLink->getCString(), sLink->getLength()); + size_t find = link.find("http://"); + if (find == std::string::npos) + find = link.find("https://"); + if (find == std::string::npos) + find = link.find("www."); + if (find != std::string::npos) + { + link.erase(0, find); + double x1, y1, x2, y2; + pWord->getBBox(&x1, &y1, &x2, &y2); + oLinks.m_arLinks.push_back({link, 0, x1, y1, x2 - x1, y2 - y1}); + } + } + RELEASEOBJECT(pTextOut); + + return oLinks.Serialize(); } diff --git a/PdfFile/Src/PdfReader.h b/PdfFile/Src/PdfReader.h index 50835d9956..21f0cb021f 100644 --- a/PdfFile/Src/PdfReader.h +++ b/PdfFile/Src/PdfReader.h @@ -34,76 +34,47 @@ #include "../../DesktopEditor/graphics/pro/Fonts.h" #include "../../DesktopEditor/graphics/IRenderer.h" +#include "../../PdfReader/Src/RendererOutputDev.h" class PDFDoc; -namespace PdfReader +class CPdfReader { - typedef enum - { - errorNone = 0, // Нет ошибок - errorOpenFile = 1, // Ошибка при открытии PDF файла - errorBadCatalog = 2, // couldn't read the page catalog - errorDamaged = 3, // PDF файл был поврежден и его невозможно восстановить - errorEncrypted = 4, // Файл зашифрован, авторизация не пройдена - errorHighlightFile = 5, // nonexistent or invalid highlight file - errorBadPrinter = 6, // плохой принтер - errorPrinting = 7, // ошибка во время печати - errorPermission = 8, // Ошибка связанная с ограничениями наложенными на файл - errorBadPageNum = 9, // Неверное количество страниц - errorFileIO = 10, // Ошибка при чтении/записи - errorMemory = 11 // Memory exceed - } EError; +public: - class CPdfReader_Private; - class CPdfReader - { - public: + CPdfReader(NSFonts::IApplicationFonts* pAppFonts); + ~CPdfReader(); - CPdfReader(NSFonts::IApplicationFonts* fonts); - ~CPdfReader(); + bool LoadFromFile (NSFonts::IApplicationFonts* pAppFonts, const std::wstring& file, const std::wstring& owner_password = L"", const std::wstring& user_password = L""); + bool LoadFromMemory(NSFonts::IApplicationFonts* pAppFonts, BYTE* data, DWORD length, const std::wstring& owner_password = L"", const std::wstring& user_password = L""); - bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"", - const std::wstring& owner_password = L"", const std::wstring& user_password = L""); - bool LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options = L"", - const std::wstring& owner_password = L"", const std::wstring& user_password = L""); + void Close(); - void Close(); + std::wstring GetTempDirectory(); + void SetTempDirectory(const std::wstring& directory); - NSFonts::IApplicationFonts* GetFonts(); + int GetPagesCount(); + void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); + void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); + std::wstring GetInfo(); - std::wstring GetTempDirectory(); - void SetTempDirectory(const std::wstring& directory); + int GetError(); + double GetVersion(); - int GetPagesCount(); - void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); - void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); - std::wstring GetInfo(); + NSFonts::IFontManager* GetFontManager() { return m_pFontManager; } + PDFDoc* GetPDFDocument() { return m_pPDFDocument; } + void ChangeLength(DWORD nLength); - int GetError(); - double GetVersion(); - int GetPermissions(); - std::wstring GetPageLabel(int nPageIndex); + BYTE* GetStructure(); + BYTE* GetLinks(int nPageIndex); - bool ExtractAllImages(const wchar_t* wsDstPath, const wchar_t* wsPrefix = 0); - int GetImagesCount(); - - void SetCMapFolder(const wchar_t* wsCMapFolder); - void SetCMapMemory(); - NSFonts::IFontManager* GetFontManager(); - - std::wstring ToXml(const std::wstring& wsXmlPath, bool isPrintStreams = false); - PDFDoc* GetPDFDocument(); - void ChangeLength(DWORD nLength); - - #ifdef BUILDING_WASM_MODULE - BYTE* GetStructure(); - BYTE* GetLinks(int nPageIndex); - #endif - - private: - CPdfReader_Private* m_pInternal; - int m_eError; - }; -} +private: + PDFDoc* m_pPDFDocument; + std::wstring m_wsTempFolder; + std::wstring m_wsSrcPath; + NSFonts::IFontManager* m_pFontManager; + PdfReader::CFontList* m_pFontList; + DWORD m_nFileLength; + int m_eError; +}; #endif // _PDF_READER_H diff --git a/PdfFile/Src/PdfWriter.cpp b/PdfFile/Src/PdfWriter.cpp index 2f8cd0d327..b63289948e 100644 --- a/PdfFile/Src/PdfWriter.cpp +++ b/PdfFile/Src/PdfWriter.cpp @@ -493,15 +493,13 @@ void CPdfWriter::CCommandManager::SetTransform(const double& m11, const double& //---------------------------------------------------------------------------------------- CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) : m_oCommandManager(this) { - m_pAppFonts = pAppFonts; - - // Создаем менеджер шрифтов с собственным кэшем - m_pFontManager = pAppFonts->GenerateFontManager(); + // Создаем менеджер шрифтов с собственным кэшем + m_pFontManager = pAppFonts->GenerateFontManager(); NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); - pMeasurerCache->SetStreams(pAppFonts->GetStreams()); - m_pFontManager->SetOwnerCache(pMeasurerCache); + pMeasurerCache->SetStreams(pAppFonts->GetStreams()); + m_pFontManager->SetOwnerCache(pMeasurerCache); - m_pDocument = new CDocument(); + m_pDocument = new CDocument(); if (isPDFA) m_pDocument->SetPDFAConformanceMode(true); @@ -532,7 +530,7 @@ CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) : m_o CPdfWriter::~CPdfWriter() { RELEASEOBJECT(m_pDocument); - RELEASEINTERFACE(m_pFontManager); + RELEASEINTERFACE(m_pFontManager); if (L"" != m_wsTempFolder) NSDirectory::DeleteDirectory(m_wsTempFolder); @@ -1105,7 +1103,7 @@ HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const u return S_FALSE; } - unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids); + unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids); RELEASEARRAYOBJECTS(pUnicodes); return DrawText(pCodes, unLen * 2, dX, dY) ? S_OK : S_FALSE; } @@ -1182,7 +1180,7 @@ HRESULT CPdfWriter::PathCommandEnd() m_oPath.Clear(); return S_OK; } -HRESULT CPdfWriter::DrawPath(const LONG& lType) +HRESULT CPdfWriter::DrawPath(NSFonts::IApplicationFonts* pAppFonts, const LONG& lType) { m_oCommandManager.Flush(); @@ -1213,7 +1211,7 @@ HRESULT CPdfWriter::DrawPath(const LONG& lType) m_oBrush.SetTexturePath(sTextureTmpPath); } - UpdateBrush(); + UpdateBrush(pAppFonts); } if (!m_pShading) @@ -1318,7 +1316,7 @@ HRESULT CPdfWriter::PathCommandGetCurrentPoint(double* dX, double* dY) HRESULT CPdfWriter::PathCommandTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH) { unsigned int unUnicode = lUnicode; - bool bRes = PathCommandDrawText(&unUnicode, 1, dX, dY, NULL); + bool bRes = PathCommandDrawText(&unUnicode, 1, dX, dY, NULL); return bRes ? S_OK : S_FALSE; } HRESULT CPdfWriter::PathCommandText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) @@ -1328,7 +1326,7 @@ HRESULT CPdfWriter::PathCommandText(const std::wstring& wsUnicodeText, const dou if (!pUnicodes) return S_FALSE; - PathCommandDrawText(pUnicodes, unLen, dX, dY, NULL); + PathCommandDrawText(pUnicodes, unLen, dX, dY, NULL); delete[] pUnicodes; return S_OK; @@ -1337,7 +1335,7 @@ HRESULT CPdfWriter::PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid { unsigned int unUnicode = lUnicode; unsigned int unGid = lGid; - bool bRes = PathCommandDrawText(&unUnicode, 1, dX, dY, &unGid); + bool bRes = PathCommandDrawText(&unUnicode, 1, dX, dY, &unGid); return bRes ? S_OK : S_FALSE; } HRESULT CPdfWriter::PathCommandTextEx(const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int unGidsCount, const double& dX, const double& dY, const double& dW, const double& dH) @@ -1375,7 +1373,7 @@ HRESULT CPdfWriter::PathCommandTextEx(const std::wstring& wsUnicodeText, const u return S_FALSE; } - bool bRes = PathCommandDrawText(pUnicodes, unLen, dX, dY, pGids); + bool bRes = PathCommandDrawText(pUnicodes, unLen, dX, dY, pGids); RELEASEARRAYOBJECTS(pUnicodes); return bRes ? S_OK : S_FALSE; @@ -1395,7 +1393,7 @@ HRESULT CPdfWriter::DrawImage(IGrObject* pImage, const double& dX, const double& return S_OK; } -HRESULT CPdfWriter::DrawImageFromFile(const std::wstring& wsImagePathSrc, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) +HRESULT CPdfWriter::DrawImageFromFile(NSFonts::IApplicationFonts* pAppFonts, const std::wstring& wsImagePathSrc, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { m_oCommandManager.Flush(); @@ -1414,7 +1412,7 @@ HRESULT CPdfWriter::DrawImageFromFile(const std::wstring& wsImagePathSrc, const _CXIMAGE_FORMAT_SVG == oImageFormat.eFileType) { // TODO: Реализовать отрисовку метафайлов по-нормальному - MetaFile::IMetaFile* pMeta = MetaFile::Create(m_pAppFonts); + MetaFile::IMetaFile* pMeta = MetaFile::Create(pAppFonts); pMeta->LoadFromFile(wsImagePath.c_str()); double dNewW = std::max(10.0, dW) / 25.4 * 300; @@ -1520,14 +1518,14 @@ HRESULT CPdfWriter::AddLink(const double& dX, const double& dY, const double& dW return S_OK; } -HRESULT CPdfWriter::AddFormField(const CFormFieldInfo &oInfo) +HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, const CFormFieldInfo &oInfo) { unsigned int unPagesCount = m_pDocument->GetPagesCount(); if (!m_pDocument || 0 == unPagesCount) return S_OK; if (m_bNeedUpdateTextFont) - UpdateFont(); + UpdateFont(); if (!m_pFont) return S_OK; @@ -1651,8 +1649,8 @@ HRESULT CPdfWriter::AddFormField(const CFormFieldInfo &oInfo) if (!m_pFont->HaveChar(unUnicode)) { - std::wstring wsFontFamily = m_pAppFonts->GetFontBySymbol(unUnicode); - CFontCidTrueType* pTempFont = GetFont(wsFontFamily, isBold, isItalic); + std::wstring wsFontFamily = pAppFonts->GetFontBySymbol(unUnicode); + CFontCidTrueType* pTempFont = GetFont(wsFontFamily, isBold, isItalic); if (pTempFont) { pCodes[unIndex] = pTempFont->EncodeUnicode(unUnicode); @@ -1863,8 +1861,8 @@ HRESULT CPdfWriter::AddFormField(const CFormFieldInfo &oInfo) if (!m_pFont->HaveChar(unUnicode)) { - std::wstring wsFontFamily = m_pAppFonts->GetFontBySymbol(unUnicode); - CFontCidTrueType* pTempFont = GetFont(wsFontFamily, isBold, isItalic); + std::wstring wsFontFamily = pAppFonts->GetFontBySymbol(unUnicode); + CFontCidTrueType* pTempFont = GetFont(wsFontFamily, isBold, isItalic); if (pTempFont) { pCodes[unIndex] = pTempFont->EncodeUnicode(unUnicode); @@ -1944,8 +1942,8 @@ HRESULT CPdfWriter::AddFormField(const CFormFieldInfo &oInfo) pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); pField->SetValue(pPr->IsChecked()); - CFontCidTrueType* pCheckedFont = GetFont(pPr->GetCheckedFontName(), false, false); - CFontCidTrueType* pUncheckedFont = GetFont(pPr->GetUncheckedFontName(), false, false); + CFontCidTrueType* pCheckedFont = GetFont(pPr->GetCheckedFontName(), false, false); + CFontCidTrueType* pUncheckedFont = GetFont(pPr->GetUncheckedFontName(), false, false); if (!pCheckedFont) pCheckedFont = m_pFont; @@ -2166,11 +2164,6 @@ std::wstring CPdfWriter::GetEditPdfPath() { return m_pDocument->GetEditPdfPath(); } - -NSFonts::IApplicationFonts* CPdfWriter::GetApplicationFonts() -{ - return m_pAppFonts; -} //---------------------------------------------------------------------------------------- // Внутренние функции //---------------------------------------------------------------------------------------- @@ -2302,7 +2295,7 @@ bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, cons } bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids) { - unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids); + unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids); if (!pCodes) return false; @@ -2315,7 +2308,7 @@ void CPdfWriter::UpdateFont() std::wstring wsFontPath = m_oFont.GetPath(); LONG lFaceIndex = m_oFont.GetFaceIndex(); if (L"" == wsFontPath) - GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex); + GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex); m_oFont.SetNeedDoBold(false); m_oFont.SetNeedDoItalic(false); @@ -2323,7 +2316,7 @@ void CPdfWriter::UpdateFont() m_pFont = NULL; if (L"" != wsFontPath) { - m_pFont = GetFont(wsFontPath, lFaceIndex); + m_pFont = GetFont(wsFontPath, lFaceIndex); if (m_pFont) { if (m_oFont.IsItalic() && !m_pFont->IsItalic()) @@ -2355,7 +2348,7 @@ void CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, oFontSelect.wsName = new std::wstring(wsFontName); oFontSelect.bItalic = new INT(bItalic ? 1 : 0); oFontSelect.bBold = new INT(bBold ? 1 : 0); - NSFonts::CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect, false); + NSFonts::CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect, false); if (!NSFonts::CFontInfo::CanEmbedForPreviewAndPrint(pFontInfo->m_usType)) { oFontSelect.Fill(pFontInfo); @@ -2364,7 +2357,7 @@ void CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, else oFontSelect.usType = new USHORT(NSFONTS_EMBEDDING_RIGHTS_PRINT_AND_PREVIEW); - pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect, false); + pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect, false); } wsFontPath = pFontInfo->m_wsFontPath; @@ -2383,13 +2376,13 @@ PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontPath, return pFont; // TODO: Пока мы здесь предполагаем, что шрифты только либо TrueType, либо OpenType - if (!m_pFontManager->LoadFontFromFile(wsFontPath, lFaceIndex, 10, 72, 72)) + if (!m_pFontManager->LoadFontFromFile(wsFontPath, lFaceIndex, 10, 72, 72)) { std::wcout << L"PDF Writer: Can't load fontfile " << wsFontPath.c_str() << "\n"; return NULL; } - std::wstring wsFontType = m_pFontManager->GetFontType(); + std::wstring wsFontType = m_pFontManager->GetFontType(); if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType) pFont = m_pDocument->CreateCidTrueTypeFont(wsFontPath, lFaceIndex); } @@ -2401,8 +2394,8 @@ PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontName, std::wstring wsFontPath; LONG lFaceIndex; - GetFontPath(wsFontName, bBold, bItalic, wsFontPath, lFaceIndex); - return GetFont(wsFontPath, lFaceIndex); + GetFontPath(wsFontName, bBold, bItalic, wsFontPath, lFaceIndex); + return GetFont(wsFontPath, lFaceIndex); } void CPdfWriter::UpdateTransform() { @@ -2469,7 +2462,7 @@ void CPdfWriter::UpdatePen() else m_pPage->SetLineJoin(linejoin_Round); } -void CPdfWriter::UpdateBrush() +void CPdfWriter::UpdateBrush(NSFonts::IApplicationFonts* pAppFonts) { m_pShading = NULL; m_pShadingExtGrState = NULL; @@ -2505,7 +2498,7 @@ void CPdfWriter::UpdateBrush() _CXIMAGE_FORMAT_SVG == oImageFormat.eFileType) { // TODO: Реализовать отрисовку метафайлов по-нормальному - MetaFile::IMetaFile* pMeta = MetaFile::Create(m_pAppFonts); + MetaFile::IMetaFile* pMeta = MetaFile::Create(pAppFonts); pMeta->LoadFromFile(wsTexturePath.c_str()); double dL, dR, dT, dB; @@ -2858,7 +2851,7 @@ void CPdfWriter::SetError() unsigned char* CPdfWriter::EncodeString(const unsigned int *pUnicodes, const unsigned int& unCount, const unsigned int *pGIDs) { if (m_bNeedUpdateTextFont) - UpdateFont(); + UpdateFont(); if (!m_pFont) return NULL; @@ -2884,7 +2877,7 @@ unsigned char* CPdfWriter::EncodeString(const unsigned int *pUnicodes, const uns unsigned char* CPdfWriter::EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount) { if (m_bNeedUpdateTextFont) - UpdateFont(); + UpdateFont(); if (!m_pFont) return NULL; diff --git a/PdfFile/Src/PdfWriter.h b/PdfFile/Src/PdfWriter.h index 6c3a85c617..80104ed192 100644 --- a/PdfFile/Src/PdfWriter.h +++ b/PdfFile/Src/PdfWriter.h @@ -77,138 +77,138 @@ public: //---------------------------------------------------------------------------------------- // Тип рендерера //---------------------------------------------------------------------------------------- - virtual HRESULT get_Type(LONG* lType); + HRESULT get_Type(LONG* lType); //---------------------------------------------------------------------------------------- // Функции для работы со страницей //---------------------------------------------------------------------------------------- - virtual HRESULT NewPage(); - virtual HRESULT get_Height(double* dHeight); - virtual HRESULT put_Height(const double& dHeight); - virtual HRESULT get_Width(double* dWidth); - virtual HRESULT put_Width(const double& dWidth); - virtual HRESULT get_DpiX(double* dDpiX); - virtual HRESULT get_DpiY(double* dDpiY); + HRESULT NewPage(); + HRESULT get_Height(double* dHeight); + HRESULT put_Height(const double& dHeight); + HRESULT get_Width(double* dWidth); + HRESULT put_Width(const double& dWidth); + HRESULT get_DpiX(double* dDpiX); + HRESULT get_DpiY(double* dDpiY); //---------------------------------------------------------------------------------------- // Функции для работы с Pen //---------------------------------------------------------------------------------------- - 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); + HRESULT get_PenColor(LONG* lColor); + HRESULT put_PenColor(const LONG& lColor); + HRESULT get_PenAlpha(LONG* lAlpha); + HRESULT put_PenAlpha(const LONG& lAlpha); + HRESULT get_PenSize(double* dSize); + HRESULT put_PenSize(const double& dSize); + HRESULT get_PenDashStyle(BYTE* nDashStyle); + HRESULT put_PenDashStyle(const BYTE& nDashStyle); + HRESULT get_PenLineStartCap(BYTE* nCapStyle); + HRESULT put_PenLineStartCap(const BYTE& nCapStyle); + HRESULT get_PenLineEndCap(BYTE* nCapStyle); + HRESULT put_PenLineEndCap(const BYTE& nCapStyle); + HRESULT get_PenLineJoin(BYTE* nJoinStyle); + HRESULT put_PenLineJoin(const BYTE& nJoinStyle); + HRESULT get_PenDashOffset(double* dOffset); + HRESULT put_PenDashOffset(const double& dOffset); + HRESULT get_PenAlign(LONG* lAlign); + HRESULT put_PenAlign(const LONG& lAlign); + HRESULT get_PenMiterLimit(double* dMiter); + HRESULT put_PenMiterLimit(const double& dMiter); + HRESULT PenDashPattern(double* pPattern, LONG lCount); //---------------------------------------------------------------------------------------- // Функции для работы с Brush //---------------------------------------------------------------------------------------- - 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& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); - virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); - virtual HRESULT put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount); + HRESULT get_BrushType(LONG* lType); + HRESULT put_BrushType(const LONG& lType); + HRESULT get_BrushColor1(LONG* lColor); + HRESULT put_BrushColor1(const LONG& lColor); + HRESULT get_BrushAlpha1(LONG* lAlpha); + HRESULT put_BrushAlpha1(const LONG& lAlpha); + HRESULT get_BrushColor2(LONG* lColor); + HRESULT put_BrushColor2(const LONG& lColor); + HRESULT get_BrushAlpha2(LONG* lAlpha); + HRESULT put_BrushAlpha2(const LONG& lAlpha); + HRESULT get_BrushTexturePath(std::wstring* wsPath); + HRESULT put_BrushTexturePath(const std::wstring& wsPath); + HRESULT get_BrushTextureMode(LONG* lMode); + HRESULT put_BrushTextureMode(const LONG& lMode); + HRESULT get_BrushTextureAlpha(LONG* lAlpha); + HRESULT put_BrushTextureAlpha(const LONG& lAlpha); + HRESULT get_BrushLinearAngle(double* dAngle); + HRESULT put_BrushLinearAngle(const double& dAngle); + HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); + HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); + 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); + HRESULT get_FontName(std::wstring* wsName); + HRESULT put_FontName(const std::wstring& wsName); + HRESULT get_FontPath(std::wstring* wsPath); + HRESULT put_FontPath(const std::wstring& wsPath); + HRESULT get_FontSize(double* dSize); + HRESULT put_FontSize(const double& dSize); + HRESULT get_FontStyle(LONG* lStyle); + HRESULT put_FontStyle(const LONG& lStyle); + HRESULT get_FontStringGID(INT* bGid); + HRESULT put_FontStringGID(const INT& bGid); + HRESULT get_FontCharSpace(double* dSpace); + HRESULT put_FontCharSpace(const double& dSpace); + HRESULT get_FontFaceIndex(int* lFaceIndex); + HRESULT put_FontFaceIndex(const int& lFaceIndex); //---------------------------------------------------------------------------------------- // Функции для вывода текста //---------------------------------------------------------------------------------------- - virtual HRESULT CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT CommandDrawTextCHAR2 (unsigned int* unUnicode, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT CommandDrawTextCHAR2 (unsigned int* unUnicode, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH); //---------------------------------------------------------------------------------------- // Маркеры команд //---------------------------------------------------------------------------------------- - virtual HRESULT BeginCommand(const DWORD& lType); - virtual HRESULT EndCommand(const DWORD& lType); + HRESULT BeginCommand(const DWORD& lType); + 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); - virtual HRESULT PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH); - virtual HRESULT PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT PathCommandMoveTo(const double& dX, const double& dY); + HRESULT PathCommandLineTo(const double& dX, const double& dY); + HRESULT PathCommandLinesTo(double* pPoints, const int& nCount); + HRESULT PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe); + HRESULT PathCommandCurvesTo(double* pPoints, const int& nCount); + HRESULT PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle); + HRESULT PathCommandClose(); + HRESULT PathCommandEnd(); + HRESULT DrawPath(NSFonts::IApplicationFonts* pAppFonts, const LONG& lType); + HRESULT PathCommandStart(); + HRESULT PathCommandGetCurrentPoint(double* dX, double* dY); + HRESULT PathCommandTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH); //---------------------------------------------------------------------------------------- // Функции для вывода изображений //---------------------------------------------------------------------------------------- - 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); + HRESULT DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH); + HRESULT DrawImageFromFile(NSFonts::IApplicationFonts* pAppFonts, 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(); + HRESULT SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY); + HRESULT GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY); + HRESULT ResetTransform(); //---------------------------------------------------------------------------------------- // Тип клипа //---------------------------------------------------------------------------------------- - virtual HRESULT get_ClipMode(LONG* lMode); - virtual HRESULT put_ClipMode(const LONG& lMode); + HRESULT get_ClipMode(LONG* lMode); + 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); - virtual HRESULT AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip); - virtual HRESULT AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage); - virtual HRESULT AddFormField(const CFormFieldInfo& oInfo); + HRESULT CommandLong(const LONG& lType, const LONG& lCommand); + HRESULT CommandDouble(const LONG& lType, const double& dCommand); + HRESULT CommandString(const LONG& lType, const std::wstring& sCommand); + HRESULT AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip); + HRESULT AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage); + HRESULT AddFormField(NSFonts::IApplicationFonts* pAppFonts, const CFormFieldInfo& oInfo); //---------------------------------------------------------------------------------------- // Дополнительные функции Pdf рендерера //---------------------------------------------------------------------------------------- @@ -233,27 +233,25 @@ public: std::wstring GetEditPdfPath(); PdfWriter::CDocument* GetPDFDocument() { return m_pDocument; } - NSFonts::IApplicationFonts* GetApplicationFonts(); - 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); bool DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY); - bool PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids = NULL); - void UpdateFont(); - void GetFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex); - PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontPath, const LONG& lFontIndex); - PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic); + bool PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids = NULL); + void UpdateFont(); + void GetFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex); + PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontPath, const LONG& lFontIndex); + PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic); void UpdateTransform(); void UpdatePen(); - void UpdateBrush(); + void UpdateBrush(NSFonts::IApplicationFonts* pAppFonts); void Reset(); bool IsValid(); bool IsPageValid(); void SetError(); void AddLink(PdfWriter::CPage* pPage, const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const unsigned int& unDestPage); - unsigned char* EncodeString(const unsigned int* pUnicodes, const unsigned int& unUnicodesCount, const unsigned int* pGIDs = NULL); - unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount); + unsigned char* EncodeString(const unsigned int* pUnicodes, const unsigned int& unUnicodesCount, const unsigned int* pGIDs = NULL); + unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount); std::wstring GetDownloadFile(const std::wstring& sUrl); private: @@ -1825,9 +1823,7 @@ private: }; private: - - NSFonts::IApplicationFonts* m_pAppFonts; - NSFonts::IFontManager* m_pFontManager; + NSFonts::IFontManager* m_pFontManager; std::wstring m_wsTempFolder; PdfWriter::CDocument* m_pDocument; diff --git a/PdfReader/PdfReader.cpp b/PdfReader/PdfReader.cpp index da5e78386e..e1990feec9 100644 --- a/PdfReader/PdfReader.cpp +++ b/PdfReader/PdfReader.cpp @@ -58,14 +58,12 @@ #include "Src/RendererOutputDev.h" #include "Src/Adaptors.h" -#ifdef BUILDING_WASM_MODULE #include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" #include "lib/xpdf/Outline.h" #include "lib/xpdf/Link.h" #include "lib/xpdf/TextOutputDev.h" #include "lib/goo/GList.h" #include -#endif namespace PdfReader { @@ -613,7 +611,6 @@ return 0; return sRes; } -#ifdef BUILDING_WASM_MODULE void getBookmars(PDFDoc* pdfDoc, OutlineItem* pOutlineItem, NSWasm::CData& out, int level) { int nLengthTitle = pOutlineItem->getTitleLength(); @@ -787,5 +784,4 @@ return 0; return oLinks.Serialize(); } -#endif } diff --git a/PdfReader/PdfReader.h b/PdfReader/PdfReader.h index 463d282afc..85bc9d909f 100644 --- a/PdfReader/PdfReader.h +++ b/PdfReader/PdfReader.h @@ -103,10 +103,8 @@ namespace PdfReader PDFDoc* GetPDFDocument(); void ChangeLength(DWORD nLength); - #ifdef BUILDING_WASM_MODULE virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); - #endif private: CPdfReader_Private* m_pInternal; diff --git a/XpsFile/XpsFile.cpp b/XpsFile/XpsFile.cpp index 2f074e43d9..2a4e062c94 100644 --- a/XpsFile/XpsFile.cpp +++ b/XpsFile/XpsFile.cpp @@ -220,7 +220,6 @@ void CXpsFile::ConvertToPdf(const std::wstring& wsPath) } #endif -#ifdef BUILDING_WASM_MODULE BYTE* CXpsFile::GetStructure() { return m_pInternal->m_pDocument->GetStructure(); @@ -229,4 +228,3 @@ BYTE* CXpsFile::GetLinks (int nPageIndex) { return m_pInternal->m_pDocument->GetPageLinks(nPageIndex); } -#endif diff --git a/XpsFile/XpsFile.h b/XpsFile/XpsFile.h index aeb9ee2563..bc390514ca 100644 --- a/XpsFile/XpsFile.h +++ b/XpsFile/XpsFile.h @@ -71,10 +71,8 @@ public: void ConvertToPdf(const std::wstring& wsDstPath); #endif -#ifdef BUILDING_WASM_MODULE virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); -#endif private: CXpsFile_Private* m_pInternal; diff --git a/XpsFile/XpsLib/Document.cpp b/XpsFile/XpsLib/Document.cpp index 32ed9f2784..0dfb523f06 100644 --- a/XpsFile/XpsLib/Document.cpp +++ b/XpsFile/XpsLib/Document.cpp @@ -192,7 +192,6 @@ namespace XPS std::wstring wsFilePath = GetPath(wsSourceFile); - #ifdef BUILDING_WASM_MODULE // Оглавление, содержание, structure oReader.Clear(); @@ -271,7 +270,6 @@ namespace XPS } } } - #endif oReader.Clear(); @@ -305,7 +303,6 @@ namespace XPS continue; } - #ifdef BUILDING_WASM_MODULE if (!oReader.IsEmptyElement()) { int nDepth = oReader.GetDepth(); @@ -333,7 +330,6 @@ namespace XPS } } } - #endif m_mPages.insert(std::pair(nIndex++, new XPS::Page(wsPagePath, m_wsPath, &m_oFontList, m_pFontManager, this))); } @@ -352,7 +348,6 @@ namespace XPS if (oIter != m_mPages.end()) oIter->second->GetSize(nW, nH); } -#ifdef BUILDING_WASM_MODULE BYTE* CDocument::GetStructure() { NSWasm::CData oRes; @@ -376,7 +371,6 @@ namespace XPS return oIter->second->m_oLinks.Serialize(); return NULL; } -#endif void CDocument::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak) { std::map::const_iterator oIter = m_mPages.find(nPageIndex); diff --git a/XpsFile/XpsLib/Document.h b/XpsFile/XpsLib/Document.h index 743770b1b2..5793f4e906 100644 --- a/XpsFile/XpsLib/Document.h +++ b/XpsFile/XpsLib/Document.h @@ -59,7 +59,6 @@ namespace XPS CStaticResource* GetStaticResource(const wchar_t* wsPath); std::wstring GetInfo(); - #ifdef BUILDING_WASM_MODULE struct CDocumentStructure { int nLevel; @@ -72,7 +71,6 @@ namespace XPS BYTE* GetPageLinks (int nPageIndex); std::vector m_vStructure; std::map m_mInternalLinks; - #endif private: IFolder* m_wsPath; diff --git a/XpsFile/XpsLib/XpsPage.cpp b/XpsFile/XpsLib/XpsPage.cpp index c328dcac15..b6d3754b9a 100644 --- a/XpsFile/XpsLib/XpsPage.cpp +++ b/XpsFile/XpsLib/XpsPage.cpp @@ -837,9 +837,7 @@ namespace XPS CWString wsFill; CWString wsClip, wsTransform, wsPathData, wsPathTransform; - #ifdef BUILDING_WASM_MODULE std::vector::iterator find = m_pDocument->m_vStructure.end(); - #endif if (oReader.MoveToFirstAttribute()) { std::wstring wsAttrName = oReader.GetName(); @@ -929,7 +927,6 @@ namespace XPS { wsPathData.create(oReader.GetText(), true); } - #ifdef BUILDING_WASM_MODULE else if (L"Name" == wsAttrName) { std::wstring wsNameTarget = oReader.GetText(); @@ -1016,7 +1013,6 @@ namespace XPS } } } - #endif if (!oReader.MoveToNextAttribute()) break; @@ -1025,7 +1021,6 @@ namespace XPS } } oReader.MoveToElement(); - #ifdef BUILDING_WASM_MODULE if (find != m_pDocument->m_vStructure.end()) { std::wstring wsPath = wsPathData.c_stdstr(); @@ -1038,7 +1033,6 @@ namespace XPS find->dY = GetDouble(wsPath.substr(nFindY, nFindEndY - nFindY)); } } - #endif CBrush* pBrush = NULL; bool bDeleteBrush = false; diff --git a/XpsFile/XpsLib/XpsPage.h b/XpsFile/XpsLib/XpsPage.h index 5a532b26d2..ffcd242c2e 100644 --- a/XpsFile/XpsLib/XpsPage.h +++ b/XpsFile/XpsLib/XpsPage.h @@ -39,9 +39,7 @@ #include "Utils.h" #include "ContextState.h" -#ifdef BUILDING_WASM_MODULE #include "../../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" -#endif namespace XPS { @@ -57,9 +55,7 @@ namespace XPS void GetSize(int& nW, int& nH) const; void Draw(IRenderer* pRenderer, bool* pbBreak); - #ifdef BUILDING_WASM_MODULE NSWasm::CPageLink m_oLinks; - #endif private: