diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 5c32d59cc7..50bf4f12a0 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -268,16 +268,22 @@ CPdfFile::~CPdfFile() } void CPdfFile::SetTemp(const std::wstring& wsPath) { - m_pInternal->pWriter->SetTempFolder (wsPath); - m_pInternal->pReader->SetTempDirectory(wsPath); + if (m_pInternal->pWriter) + m_pInternal->pWriter->SetTempFolder (wsPath); + if (m_pInternal->pReader) + m_pInternal->pReader->SetTempDirectory(wsPath); } NSFonts::IFontManager* CPdfFile::GetFontManager() { + if (!m_pInternal->pReader) + return NULL; return m_pInternal->pReader->GetFontManager(); } bool CPdfFile::EditPdf(const std::wstring& wsDstFile) { + if (!m_pInternal->pWriter || !m_pInternal->pReader) + return false; if (!wsDstFile.empty()) NSFile::CFileBinary::Copy(m_pInternal->wsSrcFile, wsDstFile); @@ -448,6 +454,8 @@ bool CPdfFile::EditPdf(const std::wstring& wsDstFile) } bool CPdfFile::EditClose() { + if (!m_pInternal->pWriter || !m_pInternal->pReader) + return false; PDFDoc* pPDFDocument = m_pInternal->pReader->GetPDFDocument(); PdfWriter::CDocument* pDoc = m_pInternal->pWriter->GetPDFDocument(); if (!pPDFDocument || !pDoc || !m_pInternal->bEdit) @@ -545,6 +553,8 @@ bool CPdfFile::EditClose() } bool CPdfFile::EditPage(int nPageIndex) { + if (!m_pInternal->pWriter || !m_pInternal->pReader) + return false; PDFDoc* pPDFDocument = m_pInternal->pReader->GetPDFDocument(); PdfWriter::CDocument* pDoc = m_pInternal->pWriter->GetPDFDocument(); if (!pPDFDocument || !pDoc || !m_pInternal->bEdit) @@ -608,13 +618,13 @@ bool CPdfFile::EditPage(int nPageIndex) } bool CPdfFile::DeletePage(int nPageIndex) { - if (!m_pInternal->bEdit) + if (!m_pInternal->pWriter || !m_pInternal->bEdit) return false; return m_pInternal->pWriter->DeletePage(nPageIndex); } bool CPdfFile::AddPage(int nPageIndex) { - if (!m_pInternal->bEdit) + if (!m_pInternal->pWriter || !m_pInternal->bEdit) return false; bool bRes = m_pInternal->pWriter->AddPage(nPageIndex); if (bRes) @@ -634,13 +644,13 @@ bool CPdfFile::AddPage(int nPageIndex) } void CPdfFile::Sign(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsPicturePath, ICertificate* pCertificate) { - if (!m_pInternal->bEdit) + if (!m_pInternal->pWriter || !m_pInternal->bEdit) return; m_pInternal->pWriter->Sign(dX, dY, dW, dH, wsPicturePath, pCertificate); } void CPdfFile::PageRotate(int nRotate) { - if (!m_pInternal->bEdit) + if (!m_pInternal->pWriter || !m_pInternal->bEdit) return; m_pInternal->pWriter->PageRotate(nRotate); } @@ -649,23 +659,31 @@ void CPdfFile::PageRotate(int nRotate) int CPdfFile::GetError() { + if (!m_pInternal->pReader) + return 1; return m_pInternal->pReader->GetError(); } bool CPdfFile::LoadFromFile(const std::wstring& file, const std::wstring& options, const std::wstring& owner_password, const std::wstring& user_password) { + if (!m_pInternal->pReader) + return false; m_pInternal->wsSrcFile = file; m_pInternal->wsPassword = owner_password; 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) { + if (!m_pInternal->pReader) + return false; m_pInternal->wsSrcFile = L""; m_pInternal->wsPassword = owner_password; return m_pInternal->pReader->LoadFromMemory(m_pInternal->pAppFonts, data, length, owner_password, user_password) && (m_pInternal->pReader->GetError() == 0); } void CPdfFile::Close() { + if (!m_pInternal->pReader) + return; m_pInternal->pReader->Close(); } NSFonts::IApplicationFonts* CPdfFile::GetFonts() @@ -678,34 +696,50 @@ OfficeDrawingFileType CPdfFile::GetType() } std::wstring CPdfFile::GetTempDirectory() { + if (!m_pInternal->pReader) + return std::wstring(); return m_pInternal->pReader->GetTempDirectory(); } void CPdfFile::SetTempDirectory(const std::wstring& directory) { + if (!m_pInternal->pReader) + return; m_pInternal->pReader->SetTempDirectory(directory); } int CPdfFile::GetPagesCount() { + if (!m_pInternal->pReader) + return 0; return m_pInternal->pReader->GetPagesCount(); } void CPdfFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) { + if (!m_pInternal->pReader) + return; m_pInternal->pReader->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY); } void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) { + if (!m_pInternal->pReader) + return; m_pInternal->pReader->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak); } std::wstring CPdfFile::GetInfo() { + if (!m_pInternal->pReader) + return std::wstring(); return m_pInternal->pReader->GetInfo(); } BYTE* CPdfFile::GetStructure() { + if (!m_pInternal->pReader) + return NULL; return m_pInternal->pReader->GetStructure(); } BYTE* CPdfFile::GetLinks(int nPageIndex) { + if (!m_pInternal->pReader) + return NULL; return m_pInternal->pReader->GetLinks(nPageIndex); } @@ -713,451 +747,665 @@ BYTE* CPdfFile::GetLinks(int nPageIndex) int CPdfFile::SaveToFile(const std::wstring& wsPath) { + if (!m_pInternal->pWriter) + return 0; return m_pInternal->pWriter->SaveToFile(wsPath); } void CPdfFile::SetPassword(const std::wstring& wsPassword) { + if (!m_pInternal->pWriter) + return; m_pInternal->pWriter->SetPassword(wsPassword); } void CPdfFile::SetDocumentID(const std::wstring& wsDocumentID) { + if (!m_pInternal->pWriter) + return; m_pInternal->pWriter->SetDocumentID(wsDocumentID); } void CPdfFile::SetTempFolder(const std::wstring& wsPath) { + if (!m_pInternal->pWriter) + return; m_pInternal->pWriter->SetTempFolder(wsPath); } HRESULT CPdfFile::OnlineWordToPdf(const std::wstring& wsSrcFile, const std::wstring& wsDstFile, CConvertFromBinParams* pParams) { - if (!NSOnlineOfficeBinToPdf::ConvertBinToPdf(this, wsSrcFile, wsDstFile, false, pParams)) + if (!m_pInternal->pWriter || !NSOnlineOfficeBinToPdf::ConvertBinToPdf(this, wsSrcFile, wsDstFile, false, pParams)) return S_FALSE; return S_OK; } HRESULT CPdfFile::OnlineWordToPdfFromBinary(const std::wstring& wsSrcFile, const std::wstring& wsDstFile, CConvertFromBinParams* pParams) { - if (!NSOnlineOfficeBinToPdf::ConvertBinToPdf(this, wsSrcFile, wsDstFile, true, pParams)) + if (!m_pInternal->pWriter || !NSOnlineOfficeBinToPdf::ConvertBinToPdf(this, wsSrcFile, wsDstFile, true, pParams)) return S_FALSE; return S_OK; } HRESULT CPdfFile::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) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->DrawImageWith1bppMask(pImage, pMaskBuffer, unMaskWidth, unMaskHeight, dX, dY, dW, dH); } HRESULT CPdfFile::DrawImage1bpp(NSImages::CPixJbig2* pImageBuffer, const unsigned int& unWidth, const unsigned int& unHeight, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->DrawImage1bpp(pImageBuffer, unWidth, unHeight, dX, dY, dW, dH); } HRESULT CPdfFile::SetLinearGradient(const double& dX1, const double& dY1, const double& dX2, const double& dY2) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->SetLinearGradient(dX1, dY1, dX2, dY2); } HRESULT CPdfFile::SetRadialGradient(const double& dX1, const double& dY1, const double& dR1, const double& dX2, const double& dY2, const double& dR2) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->SetRadialGradient(dX1, dY1, dR1, dX2, dY2, dR2); } HRESULT CPdfFile::get_Type(LONG* lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_Type(lType); } HRESULT CPdfFile::NewPage() { - if (m_pInternal->bEdit) + if (!m_pInternal->pWriter || m_pInternal->bEdit) return S_FALSE; return m_pInternal->pWriter->NewPage(); } HRESULT CPdfFile::get_Height(double* dHeight) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_Height(dHeight); } HRESULT CPdfFile::put_Height(const double& dHeight) { + if (!m_pInternal->pWriter) + return S_FALSE; if (m_pInternal->bEdit && m_pInternal->bEditPage) return S_OK; return m_pInternal->pWriter->put_Height(dHeight); } HRESULT CPdfFile::get_Width(double* dWidth) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_Width(dWidth); } HRESULT CPdfFile::put_Width(const double& dWidth) { + if (!m_pInternal->pWriter) + return S_FALSE; if (m_pInternal->bEdit && m_pInternal->bEditPage) return S_OK; return m_pInternal->pWriter->put_Width(dWidth); } HRESULT CPdfFile::get_DpiX(double* dDpiX) { - return m_pInternal->pWriter->get_DpiX(dDpiX); + if (!m_pInternal->pWriter) + return S_FALSE; + *dDpiX = 72; + return S_OK; } HRESULT CPdfFile::get_DpiY(double* dDpiY) { - return m_pInternal->pWriter->get_DpiY(dDpiY); + if (!m_pInternal->pWriter) + return S_FALSE; + *dDpiY = 72; + return S_OK; } HRESULT CPdfFile::get_PenColor(LONG* lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenColor(lColor); } HRESULT CPdfFile::put_PenColor(const LONG& lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenColor(lColor); } HRESULT CPdfFile::get_PenAlpha(LONG* lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenAlpha(lAlpha); } HRESULT CPdfFile::put_PenAlpha(const LONG& lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenAlpha(lAlpha); } HRESULT CPdfFile::get_PenSize(double* dSize) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenSize(dSize); } HRESULT CPdfFile::put_PenSize(const double& dSize) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenSize(dSize); } HRESULT CPdfFile::get_PenDashStyle(BYTE* nDashStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenDashStyle(nDashStyle); } HRESULT CPdfFile::put_PenDashStyle(const BYTE& nDashStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenDashStyle(nDashStyle); } HRESULT CPdfFile::get_PenLineStartCap(BYTE* nCapStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenLineStartCap(nCapStyle); } HRESULT CPdfFile::put_PenLineStartCap(const BYTE& nCapStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenLineStartCap(nCapStyle); } HRESULT CPdfFile::get_PenLineEndCap(BYTE* nCapStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenLineEndCap(nCapStyle); } HRESULT CPdfFile::put_PenLineEndCap(const BYTE& nCapStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenLineEndCap(nCapStyle); } HRESULT CPdfFile::get_PenLineJoin(BYTE* nJoinStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenLineJoin(nJoinStyle); } HRESULT CPdfFile::put_PenLineJoin(const BYTE& nJoinStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenLineJoin(nJoinStyle); } HRESULT CPdfFile::get_PenDashOffset(double* dOffset) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenDashOffset(dOffset); } HRESULT CPdfFile::put_PenDashOffset(const double& dOffset) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenDashOffset(dOffset); } HRESULT CPdfFile::get_PenAlign(LONG* lAlign) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenAlign(lAlign); } HRESULT CPdfFile::put_PenAlign(const LONG& lAlign) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenAlign(lAlign); } HRESULT CPdfFile::get_PenMiterLimit(double* dMiter) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_PenMiterLimit(dMiter); } HRESULT CPdfFile::put_PenMiterLimit(const double& dMiter) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_PenMiterLimit(dMiter); } HRESULT CPdfFile::PenDashPattern(double* pPattern, LONG lCount) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PenDashPattern(pPattern, lCount); } HRESULT CPdfFile::get_BrushType(LONG* lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushType(lType); } HRESULT CPdfFile::put_BrushType(const LONG& lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushType(lType); } HRESULT CPdfFile::get_BrushColor1(LONG* lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushColor1(lColor); } HRESULT CPdfFile::put_BrushColor1(const LONG& lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushColor1(lColor); } HRESULT CPdfFile::get_BrushAlpha1(LONG* lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushAlpha1(lAlpha); } HRESULT CPdfFile::put_BrushAlpha1(const LONG& lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushAlpha1(lAlpha); } HRESULT CPdfFile::get_BrushColor2(LONG* lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushColor2(lColor); } HRESULT CPdfFile::put_BrushColor2(const LONG& lColor) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushColor2(lColor); } HRESULT CPdfFile::get_BrushAlpha2(LONG* lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushAlpha2(lAlpha); } HRESULT CPdfFile::put_BrushAlpha2(const LONG& lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushAlpha2(lAlpha); } HRESULT CPdfFile::get_BrushTexturePath(std::wstring* wsPath) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushTexturePath(wsPath); } HRESULT CPdfFile::put_BrushTexturePath(const std::wstring& wsPath) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushTexturePath(wsPath); } HRESULT CPdfFile::get_BrushTextureMode(LONG* lMode) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushTextureMode(lMode); } HRESULT CPdfFile::put_BrushTextureMode(const LONG& lMode) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushTextureMode(lMode); } HRESULT CPdfFile::get_BrushTextureAlpha(LONG* lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushTextureAlpha(lAlpha); } HRESULT CPdfFile::put_BrushTextureAlpha(const LONG& lAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushTextureAlpha(lAlpha); } HRESULT CPdfFile::get_BrushLinearAngle(double* dAngle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_BrushLinearAngle(dAngle); } HRESULT CPdfFile::put_BrushLinearAngle(const double& dAngle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushLinearAngle(dAngle); } HRESULT CPdfFile::BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->BrushRect(nVal, dLeft, dTop, dWidth, dHeight); } HRESULT CPdfFile::BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->BrushBounds(dLeft, dTop, dWidth, dHeight); } HRESULT CPdfFile::put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_BrushGradientColors(pColors, pPositions, lCount); } HRESULT CPdfFile::get_FontName(std::wstring* wsName) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontName(wsName); } HRESULT CPdfFile::put_FontName(const std::wstring& wsName) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontName(wsName); } HRESULT CPdfFile::get_FontPath(std::wstring* wsPath) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontPath(wsPath); } HRESULT CPdfFile::put_FontPath(const std::wstring& wsPath) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontPath(wsPath); } HRESULT CPdfFile::get_FontSize(double* dSize) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontSize(dSize); } HRESULT CPdfFile::put_FontSize(const double& dSize) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontSize(dSize); } HRESULT CPdfFile::get_FontStyle(LONG* lStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontStyle(lStyle); } HRESULT CPdfFile::put_FontStyle(const LONG& lStyle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontStyle(lStyle); } HRESULT CPdfFile::get_FontStringGID(INT* bGid) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontStringGID(bGid); } HRESULT CPdfFile::put_FontStringGID(const INT& bGid) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontStringGID(bGid); } HRESULT CPdfFile::get_FontCharSpace(double* dSpace) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontCharSpace(dSpace); } HRESULT CPdfFile::put_FontCharSpace(const double& dSpace) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontCharSpace(dSpace); } HRESULT CPdfFile::get_FontFaceIndex(int* lFaceIndex) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_FontFaceIndex(lFaceIndex); } HRESULT CPdfFile::put_FontFaceIndex(const int& lFaceIndex) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_FontFaceIndex(lFaceIndex); } HRESULT CPdfFile::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDrawTextCHAR(lUnicode, dX, dY, dW, dH); } HRESULT CPdfFile::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDrawTextExCHAR(lUnicode, lGid, dX, dY, dW, dH); } HRESULT CPdfFile::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDrawText(wsUnicodeText, dX, dY, dW, dH); } HRESULT CPdfFile::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) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDrawTextEx(wsUnicodeText, pGids, nGidsCount, dX, dY, dW, dH); } HRESULT CPdfFile::CommandDrawTextCHAR2(unsigned int* unUnicode, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDrawTextCHAR2(unUnicode, unUnicodeCount, unGid, dX, dY, dW, dH); } HRESULT CPdfFile::BeginCommand(const DWORD& lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->BeginCommand(lType); } HRESULT CPdfFile::EndCommand(const DWORD& lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->EndCommand(lType); } HRESULT CPdfFile::PathCommandMoveTo(const double& dX, const double& dY) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandMoveTo(dX, dY); } HRESULT CPdfFile::PathCommandLineTo(const double& dX, const double& dY) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandLineTo(dX, dY); } HRESULT CPdfFile::PathCommandLinesTo(double* pPoints, const int& nCount) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandLinesTo(pPoints, nCount); } HRESULT CPdfFile::PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandCurveTo(dX1, dY1, dX2, dY2, dXe, dYe); } HRESULT CPdfFile::PathCommandCurvesTo(double* pPoints, const int& nCount) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandCurvesTo(pPoints, nCount); } HRESULT CPdfFile::PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandArcTo(dX, dY, dW, dH, dStartAngle, dSweepAngle); } HRESULT CPdfFile::PathCommandClose() { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandClose(); } HRESULT CPdfFile::PathCommandEnd() { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandEnd(); } HRESULT CPdfFile::DrawPath(const LONG& lType) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->DrawPath(m_pInternal->pAppFonts, lType); } HRESULT CPdfFile::PathCommandStart() { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandStart(); } HRESULT CPdfFile::PathCommandGetCurrentPoint(double* dX, double* dY) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandGetCurrentPoint(dX, dY); } HRESULT CPdfFile::PathCommandTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandTextCHAR(lUnicode, dX, dY, dW, dH); } HRESULT CPdfFile::PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandTextExCHAR(lUnicode, lGid, dX, dY, dW, dH); } HRESULT CPdfFile::PathCommandText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandText(wsUnicodeText, dX, dY, dW, dH); } HRESULT CPdfFile::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) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->PathCommandTextEx(wsUnicodeText, pGids, nGidsCount, dX, dY, dW, dH); } HRESULT CPdfFile::DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->DrawImage(pImage, dX, dY, dW, dH); } HRESULT CPdfFile::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { + if (!m_pInternal->pWriter) + return S_FALSE; 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) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->SetTransform(dM11, dM12, dM21, dM22, dX, dY); } HRESULT CPdfFile::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->GetTransform(dM11, dM12, dM21, dM22, dX, dY); } HRESULT CPdfFile::ResetTransform() { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->ResetTransform(); } HRESULT CPdfFile::get_ClipMode(LONG* lMode) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->get_ClipMode(lMode); } HRESULT CPdfFile::put_ClipMode(const LONG& lMode) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->put_ClipMode(lMode); } HRESULT CPdfFile::CommandLong(const LONG& lType, const LONG& lCommand) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandLong(lType, lCommand); } HRESULT CPdfFile::CommandDouble(const LONG& lType, const double& dCommand) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandDouble(lType, dCommand); } HRESULT CPdfFile::CommandString(const LONG& lType, const std::wstring& sCommand) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->CommandString(lType, sCommand); } HRESULT CPdfFile::AddHyperlink(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsUrl, const std::wstring& wsTooltip) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->AddHyperlink(dX, dY, dW, dH, wsUrl, wsTooltip); } HRESULT CPdfFile::AddLink(const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const int& nPage) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->AddLink(dX, dY, dW, dH, dDestX, dDestY, nPage); } HRESULT CPdfFile::AddFormField(const CFormFieldInfo& oInfo) { + if (!m_pInternal->pWriter) + return S_FALSE; return m_pInternal->pWriter->AddFormField(m_pInternal->pAppFonts, oInfo); } diff --git a/PdfFile/Src/PdfWriter.cpp b/PdfFile/Src/PdfWriter.cpp index b63289948e..a3d17066ad 100644 --- a/PdfFile/Src/PdfWriter.cpp +++ b/PdfFile/Src/PdfWriter.cpp @@ -50,6 +50,7 @@ #include "../../DesktopEditor/raster/ImageFileFormatChecker.h" #include "../../DesktopEditor/graphics/pro/Fonts.h" #include "../../DesktopEditor/graphics/pro/Image.h" +#include "../../DesktopEditor/common/StringExt.h" #include "../../UnicodeConverter/UnicodeConverter.h" #include "../../Common/Network/FileTransporter/include/FileTransporter.h" @@ -86,63 +87,6 @@ using namespace PdfWriter; -static unsigned int* WStringToUtf32(const std::wstring& wsUnicodeText, unsigned int& unLen) -{ - if (wsUnicodeText.size() <= 0) - return NULL; - - unsigned int* pUnicodes = new unsigned int[wsUnicodeText.size()]; - if (!pUnicodes) - return NULL; - - unLen = 0; - if (2 == sizeof(wchar_t)) - { - const wchar_t* wsEnd = wsUnicodeText.c_str() + wsUnicodeText.size(); - wchar_t* wsInput = (wchar_t*)wsUnicodeText.c_str(); - - wchar_t wLeading, wTrailing; - unsigned int unCode; - while (wsInput < wsEnd) - { - wLeading = *wsInput++; - if (wLeading < 0xD800 || wLeading > 0xDFFF) - { - pUnicodes[unLen++] = (unsigned int)wLeading; - } - else if (wLeading >= 0xDC00) - { - // Такого не должно быть - continue; - } - else - { - unCode = (wLeading & 0x3FF) << 10; - wTrailing = *wsInput++; - if (wTrailing < 0xDC00 || wTrailing > 0xDFFF) - { - // Такого не должно быть - continue; - } - else - { - pUnicodes[unLen++] = ((unCode | (wTrailing & 0x3FF)) + 0x10000); - } - } - } - } - else - { - unLen = wsUnicodeText.size(); - for (unsigned int unIndex = 0; unIndex < unLen; unIndex++) - { - pUnicodes[unIndex] = (unsigned int)wsUnicodeText.at(unIndex); - } - } - - return pUnicodes; -} - // Этих типов браша нет в рендерере, мы их используем, когда конвертим из веба static const long c_BrushTypeLinearGradient = 8001; static const long c_BrushTypeRadialGradient = 8002; @@ -657,16 +601,6 @@ HRESULT CPdfWriter::put_Width(const double& dWidth) m_pPage->SetWidth(MM_2_PT(dWidth)); return S_OK; } -HRESULT CPdfWriter::get_DpiX(double* dDpiX) -{ - *dDpiX = 72; - return S_OK; -} -HRESULT CPdfWriter::get_DpiY(double* dDpiY) -{ - *dDpiY = 72; - return S_OK; -} //---------------------------------------------------------------------------------------- // Функции для работы с Pen //---------------------------------------------------------------------------------------- @@ -1011,7 +945,7 @@ HRESULT CPdfWriter::CommandDrawText(const std::wstring& wsUnicodeText, const dou return S_FALSE; unsigned int unLen; - unsigned int* pUnicodes = WStringToUtf32(wsUnicodeText, unLen); + unsigned int* pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unLen); if (!pUnicodes) return S_FALSE; @@ -1081,7 +1015,7 @@ HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const u if (wsUnicodeText.size()) { unsigned int unUnicodeLen; - pUnicodes = WStringToUtf32(wsUnicodeText, unUnicodeLen); + pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unUnicodeLen); if (!pUnicodes || unUnicodeLen != unLen) RELEASEARRAYOBJECTS(pUnicodes); } @@ -1098,7 +1032,7 @@ HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const u } else { - pUnicodes = WStringToUtf32(wsUnicodeText, unLen); + pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unLen); if (!pUnicodes) return S_FALSE; } @@ -1322,7 +1256,7 @@ HRESULT CPdfWriter::PathCommandTextCHAR(const LONG& lUnicode, const double& dX, HRESULT CPdfWriter::PathCommandText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH) { unsigned int unLen; - unsigned int* pUnicodes = WStringToUtf32(wsUnicodeText, unLen); + unsigned int* pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unLen); if (!pUnicodes) return S_FALSE; @@ -1351,7 +1285,7 @@ HRESULT CPdfWriter::PathCommandTextEx(const std::wstring& wsUnicodeText, const u if (wsUnicodeText.size()) { unsigned int unUnicodeLen; - pUnicodes = WStringToUtf32(wsUnicodeText, unUnicodeLen); + pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unUnicodeLen); if (!pUnicodes || unUnicodeLen != unLen) RELEASEARRAYOBJECTS(pUnicodes); } @@ -1368,7 +1302,7 @@ HRESULT CPdfWriter::PathCommandTextEx(const std::wstring& wsUnicodeText, const u } else { - pUnicodes = WStringToUtf32(wsUnicodeText, unLen); + pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeText, unLen); if (!pUnicodes) return S_FALSE; } @@ -1624,7 +1558,7 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, const CF std::wstring wsValue = pPr->GetTextValue(); unsigned int unLen; - unsigned int* pUnicodes = WStringToUtf32(wsValue, unLen); + unsigned int* pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsValue, unLen); if (!pUnicodes) return S_FALSE; @@ -1836,7 +1770,7 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, const CF std::wstring wsValue = pPr->GetTextValue(); unsigned int unLen; - unsigned int* pUnicodes = WStringToUtf32(wsValue, unLen); + unsigned int* pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsValue, unLen); if (!pUnicodes) return S_FALSE; @@ -2835,7 +2769,7 @@ void CPdfWriter::AddLink(PdfWriter::CPage* pPage, const double& dX, const double } bool CPdfWriter::IsValid() { - return m_bValid; + return m_bValid; } bool CPdfWriter::IsPageValid() { diff --git a/PdfFile/Src/PdfWriter.h b/PdfFile/Src/PdfWriter.h index 80104ed192..63fadb29d2 100644 --- a/PdfFile/Src/PdfWriter.h +++ b/PdfFile/Src/PdfWriter.h @@ -86,8 +86,6 @@ public: 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 //----------------------------------------------------------------------------------------