diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 14e21598db..c792778416 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -4385,6 +4385,11 @@ void CPdfEditor::ScanAndProcessFonts(PDFDoc* pPDFDocument, XRef* xref, Dict* pRe } m_pWriter->AddFont(L"Embedded: " + wsFontName, false, false, wsFileName, 0); PdfWriter::CObjectBase* pObj = m_mObjManager.GetObj(nFontRef.num); + if (!pObj) + { + pObj = new PdfWriter::CObjectBase(); + pObj->SetRef(nFontRef.num, nFontRef.gen); + } m_pWriter->GetDocument()->CreateFontEmbedded(wsFileName, 0, sFontKey, static_cast(gfxFont->getType()), pObj, mCodeToWidth, mCodeToUnicode, mCodeToGID); } } diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 8ea8e1b474..a240016f09 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -2267,4 +2267,13 @@ namespace PdfWriter { m_pCurPage->ClearContentFull(m_pXref); } + CObjectBase* CDocument::FindObjByID(unsigned int nObjectId) + { + TXrefEntry* pRes = NULL; + if (m_pLastXref) + pRes = m_pLastXref->GetEntryByObjectId(nObjectId); + if (!pRes) + pRes = m_pXref->GetEntryByObjectId(nObjectId); + return pRes? pRes->pObject : NULL; + } } diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index b5af6f1845..24e9fa9f84 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -226,6 +226,7 @@ namespace PdfWriter void RemoveObj(CObjectBase* pObj); void SetEncryption(CEncryptDict* pEncrypt, CObjectBase* pID); void AddNameTree(CStringObject* pName, CDestination* pDest); + CObjectBase* FindObjByID(unsigned int nObjectId); private: char* GetTTFontTag(); diff --git a/PdfFile/SrcWriter/Font14.cpp b/PdfFile/SrcWriter/Font14.cpp index c1495f75eb..16e7959806 100644 --- a/PdfFile/SrcWriter/Font14.cpp +++ b/PdfFile/SrcWriter/Font14.cpp @@ -142,4 +142,14 @@ namespace PdfWriter return pair.first; return 0; } + CObjectBase* CFontEmbedded::GetObj() + { + if (m_pObj->GetType() != object_type_UNKNOWN) + return m_pObj; + return new PdfWriter::CProxyObject(m_pObj, true); + } + CObjectBase* CFontEmbedded::GetObj2() + { + return m_pObj; + } } diff --git a/PdfFile/SrcWriter/Font14.h b/PdfFile/SrcWriter/Font14.h index d765b8e086..7efca80c43 100644 --- a/PdfFile/SrcWriter/Font14.h +++ b/PdfFile/SrcWriter/Font14.h @@ -71,7 +71,8 @@ namespace PdfWriter unsigned int GetWidth(unsigned short ushCode); unsigned int EncodeUnicode(const unsigned int& unGID, const unsigned int& unUnicode); unsigned int EncodeGID(const unsigned int& unGID); - CObjectBase* GetObj() { return m_pObj; } + CObjectBase* GetObj(); + CObjectBase* GetObj2(); const char* GetFontKey() const { return m_sFontKey.c_str(); } void UpdateKey(const std::string& sFontKey) { m_sFontKey = sFontKey; } diff --git a/PdfFile/SrcWriter/Objects.cpp b/PdfFile/SrcWriter/Objects.cpp index 686c65462f..0c0928c93c 100644 --- a/PdfFile/SrcWriter/Objects.cpp +++ b/PdfFile/SrcWriter/Objects.cpp @@ -891,10 +891,7 @@ namespace PdfWriter while (pXref) { - if (pXref->m_arrEntries.size() + pXref->m_unStartOffset <= nObjectId) - return NULL; - - if (pXref->m_unStartOffset <= nObjectId) + if (pXref->m_unStartOffset <= nObjectId && pXref->m_arrEntries.size() + pXref->m_unStartOffset > nObjectId) { for (unsigned int unIndex = 0, nCount = pXref->m_arrEntries.size(); unIndex < nCount; unIndex++) { diff --git a/PdfFile/SrcWriter/ResourcesDictionary.cpp b/PdfFile/SrcWriter/ResourcesDictionary.cpp index 174a0d34be..fd74076ca5 100644 --- a/PdfFile/SrcWriter/ResourcesDictionary.cpp +++ b/PdfFile/SrcWriter/ResourcesDictionary.cpp @@ -91,7 +91,7 @@ namespace PdfWriter } } - const char *sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj() : pFont); + const char *sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj2() : pFont); if (!sKey) { // если фонт не зарегистрирован в ресурсах, тогда регистрируем его @@ -108,7 +108,7 @@ namespace PdfWriter pPointer = (char*)StrCpy(sFontName, "F", pEndPointer); ItoA(pPointer, m_unFontsCount, pEndPointer); m_pFonts->Add(sFontName, pEmbedded ? pEmbedded->GetObj() : pFont); - sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj() : pFont); + sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj2() : pFont); if (sEmbeddedFontKey) pEmbedded->UpdateKey(sKey); } diff --git a/PdfFile/test/test.cpp b/PdfFile/test/test.cpp index 3f2876f068..24d00a32c4 100644 --- a/PdfFile/test/test.cpp +++ b/PdfFile/test/test.cpp @@ -711,7 +711,7 @@ TEST_F(CPdfFileTest, EditPdfSign) TEST_F(CPdfFileTest, PrintPdf) { - //GTEST_SKIP(); + GTEST_SKIP(); LoadFromFile(wsDstFile);