diff --git a/DesktopEditor/graphics/pro/js/wasm/src/pdfwriter.cpp b/DesktopEditor/graphics/pro/js/wasm/src/pdfwriter.cpp index 87e1c4d213..76de8ff5f4 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/pdfwriter.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/pdfwriter.cpp @@ -143,6 +143,7 @@ HRESULT CPdfWriter::DrawImageWith1bppMask(IGrObject* pImage, NSImages::CPixJbig2 bool CPdfWriter::EditPage(PdfWriter::CPage* pNewPage) { return false; } bool CPdfWriter::AddPage(int nPageIndex) { return false; } bool CPdfWriter::EditClose() { return false; } +void CPdfWriter::PageClear() {} 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) {} HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWidgetsInfo* pFieldInfo, const std::wstring& wsTempDirectory) { return 0; } diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 54452bbaf5..0c7e3f9ccb 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -54,7 +54,7 @@ public: int GetPagesCount() { return 0; } int GetRotate(int nPageIndex) { return 0; } void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) {} - bool EditPage(int nPageIndex) { return false; } + bool EditPage() { return false; } void AddShapeXML(const std::string& sXML) {} void EndMarkedContent() {} }; diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index efc99604de..8b04f0579a 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -1854,6 +1854,8 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF pTextAnnot->SetStateModel(pPr->GetStateModel()); if (nFlags & (1 << 18)) pTextAnnot->SetState(pPr->GetState()); + + pTextAnnot->SetAP(); } else if (oInfo.IsInk()) { diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 05f9378f3d..d5841ebe6f 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -466,10 +466,29 @@ namespace PdfWriter { case 3: { - CAnnotAppearanceObject* pAP = new CAnnotAppearanceObject(m_pXref, this); + CAnnotAppearance* pAP = new CAnnotAppearance(m_pXref, this); Add("AP", pAP); + std::string sColor = GetColor(dynamic_cast(Get("C")), false); + CAnnotAppearanceObject* pN = pAP->GetNormal(); + pN->DrawTextCommentN(sColor); + + CArrayObject* pArray = new CArrayObject(); + pN->Add("BBox", pArray); + pArray->Add(0); + pArray->Add(0); + pArray->Add(24); + pArray->Add(24); + + CAnnotAppearanceObject* pR = pAP->GetRollover(); + pR->DrawTextCommentR(sColor); + + pArray = new CArrayObject(); + pR->Add("BBox", pArray); + pArray->Add(0); + pArray->Add(0); + pArray->Add(24); + pArray->Add(24); - pAP->DrawTextComment(); break; } case 10: @@ -789,6 +808,28 @@ namespace PdfWriter CAnnotAppearanceObject* pNormal = pAppearance->GetNormal(); CStream* pStream = pNormal->GetStream(); + CArrayObject* pArray = new CArrayObject(); + if (!pArray) + return; + pNormal->Add("BBox", pArray); + + pArray->Add(GetRect().fLeft); + pArray->Add(GetRect().fBottom); + pArray->Add(GetRect().fRight); + pArray->Add(GetRect().fTop); + + pArray = new CArrayObject(); + if (!pArray) + return; + + pNormal->Add("Matrix", pArray); + pArray->Add(1); + pArray->Add(0); + pArray->Add(0); + pArray->Add(1); + pArray->Add(-GetRect().fLeft); + pArray->Add(-GetRect().fBottom); + if (GetBorderType() == EBorderType::Dashed) pStream->WriteStr(GetBorderDash().c_str()); diff --git a/PdfFile/SrcWriter/Field.cpp b/PdfFile/SrcWriter/Field.cpp index 38703828e2..d025fa7e14 100644 --- a/PdfFile/SrcWriter/Field.cpp +++ b/PdfFile/SrcWriter/Field.cpp @@ -1654,37 +1654,18 @@ namespace PdfWriter m_pAnnot = pAnnot; m_pField = NULL; - CArrayObject* pArray = new CArrayObject(); - if (!pArray) - return; - Add("BBox", pArray); - if (pAnnot->GetAnnotationType() == EAnnotType::AnnotWidget) { + CArrayObject* pArray = new CArrayObject(); + if (!pArray) + return; + Add("BBox", pArray); + pArray->Add(0); pArray->Add(0); pArray->Add(fabs(pAnnot->GetRect().fRight - pAnnot->GetRect().fLeft)); pArray->Add(fabs(pAnnot->GetRect().fBottom - pAnnot->GetRect().fTop)); } - else - { - pArray->Add(pAnnot->GetRect().fLeft); - pArray->Add(pAnnot->GetRect().fBottom); - pArray->Add(pAnnot->GetRect().fRight); - pArray->Add(pAnnot->GetRect().fTop); - - pArray = new CArrayObject(); - if (!pArray) - return; - - Add("Matrix", pArray); - pArray->Add(1); - pArray->Add(0); - pArray->Add(0); - pArray->Add(1); - pArray->Add(-pAnnot->GetRect().fLeft); - pArray->Add(-pAnnot->GetRect().fBottom); - } } void CAnnotAppearanceObject::DrawSimpleText(const std::wstring& wsText, unsigned short* pCodes, unsigned int unCount, CFontDict* pFont, double dFontSize, double dX, double dY, double dR, double dG, double dB, const char* sExtGStateName, double dWidth, double dHeight, CFontCidTrueType** ppFonts, double* pShifts) { @@ -2620,18 +2601,24 @@ namespace PdfWriter m_pStream->WriteStr("ET\012"); m_pStream->WriteStr("Q\012EMC\012"); } - void CAnnotAppearanceObject::DrawTextComment() + void CAnnotAppearanceObject::DrawTextCommentN(const std::string& sColor) { - CArrayObject* pArray = new CArrayObject(); - if (!pArray) - return; - - Add("BBox", pArray); - pArray->Add(0); - pArray->Add(0); - pArray->Add(20); - pArray->Add(20); - - m_pStream->WriteStr(""); + m_pStream->WriteStr("q 1 1 1 rg 0 i 1 w 4 M 1 j 0 J [] 0 d "); + // GS0 gs + m_pStream->WriteStr("1 0 0 1 9 5.0908 cm 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c "); + m_pStream->WriteStr("7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c h f Q 0 G "); + m_pStream->WriteStr(sColor.c_str()); + m_pStream->WriteStr(" 0 i 0.60 w 4 M 1 j 0 J [0 100] 1 d 1 0 0 1 9 5.0908 cm 1 0 m -2.325 -2.81 l -2.325 0 l -5.72 0 l -5.72 8.94 l 5.51 8.94 l 5.51 0 l 1 0 l -3.50 5.01 m "); + m_pStream->WriteStr("-3.50 5.59 l 3.29 5.59 l 3.29 5.01 l -3.50 5.01 l -3.50 3.34 m -3.50 3.92 l 2.27 3.92 l 2.27 3.34 l -3.50 3.34 l 7.74 12.616 m -7.74 12.616 l "); + m_pStream->WriteStr("-8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l "); + m_pStream->WriteStr("8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c b"); + } + void CAnnotAppearanceObject::DrawTextCommentR(const std::string& sColor) + { + m_pStream->WriteStr("0 G "); + m_pStream->WriteStr(sColor.c_str()); + m_pStream->WriteStr(" 0 i 0.60 w 4 M 1 j 0 J [0 100] 1 d 1 0 0 1 9 5.0908 cm 4.1 1.71 m -0.54 -2.29 l -0.54 1.71 l -5.5 1.71 l -5.5 14.42 l 10.5 14.42 l 10.5 1.71 l 4.1 1.71 l "); + m_pStream->WriteStr("-2.33 9.66 m 7.34 9.66 l 7.34 8.83 l -2.33 8.83 l -2.33 9.66 l -2.33 7.28 m 5.88 7.28 l 5.88 6.46 l -2.33 6.46 l -2.33 7.28 l 14.9 23.1235 m -14.9 23.1235 l "); + m_pStream->WriteStr("-14.9 -20.345 l 14.9 -20.345 l 14.9 23.1235 l b"); } } diff --git a/PdfFile/SrcWriter/Field.h b/PdfFile/SrcWriter/Field.h index 9d199d04f9..03786678e9 100644 --- a/PdfFile/SrcWriter/Field.h +++ b/PdfFile/SrcWriter/Field.h @@ -396,7 +396,8 @@ namespace PdfWriter void EndText(); void EndDraw(); - void DrawTextComment(); + void DrawTextCommentN(const std::string& sColor); + void DrawTextCommentR(const std::string& sColor); CStream* GetStream() { return m_pStream; } bool m_bStart; diff --git a/PdfFile/test/test.cpp b/PdfFile/test/test.cpp index fb83ca3d9b..19b3ce54a4 100644 --- a/PdfFile/test/test.cpp +++ b/PdfFile/test/test.cpp @@ -305,7 +305,7 @@ TEST_F(CPdfFileTest, EditPdfFromBase64) EXPECT_TRUE(NSBase64::Base64Decode((const char*)pFileContent, dwFileSize, pBuffer, &nBufferLen)); CConvertFromBinParams* pParams = new CConvertFromBinParams(); - pParams->m_sMediaDirectory = NSFile::GetProcessDirectory() + L"/media"; + pParams->m_sMediaDirectory = NSFile::GetProcessDirectory(); pdfFile->AddToPdfFromBinary(pBuffer, nBufferLen, pParams); RELEASEOBJECT(pParams);