diff --git a/PdfFile/SrcReader/Adaptors.cpp b/PdfFile/SrcReader/Adaptors.cpp index 35c6bfcc9a..3a1c85c87e 100644 --- a/PdfFile/SrcReader/Adaptors.cpp +++ b/PdfFile/SrcReader/Adaptors.cpp @@ -189,7 +189,7 @@ bool GlobalParamsAdaptor::GetCMap(const char* sName, char*& pData, unsigned int& bool operator==(const Ref &a, const Ref &b) { - return a.gen == b.gen && a.num == b.gen; + return a.gen == b.gen && a.num == b.num; } bool operator<(const Ref &a, const Ref &b) diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 217b393aba..029439506b 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -35,6 +35,7 @@ #include "../lib/xpdf/TextString.h" #include "../lib/xpdf/Link.h" #include "../lib/xpdf/Annot.h" +#include "../lib/xpdf/GfxFont.h" #include "../lib/goo/GList.h" #include "../../DesktopEditor/common/Types.h" @@ -677,19 +678,6 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo oObj.fetch(xref, &oField); oObj.free(); - // Шрифт и размер шрифта - из DA - Ref fontID; - pField->getFont(&fontID, &m_dFontSize); - if (fontID.num > 0) - { - Object oFont, oFontRef; - oFontRef.initRef(fontID.num, fontID.gen); - oFontRef.fetch(xref, &oFont); - oFontRef.free(); - - oFont.free(); - } - // Цвет текста - из DA int nSpace; GList *arrColors = pField->getColorSpace(&nSpace); @@ -854,10 +842,90 @@ CAnnotWidget::~CAnnotWidget() void CAnnotWidget::SetFont(PDFDoc* pdfDoc, AcroFormField* pField, NSFonts::IFontManager* pFontManager, CFontList *pFontList) { + GfxFont* gfxFont = NULL; + GfxFontDict *gfxFontDict = NULL; + + // Шрифт и размер шрифта - из DA + Ref fontID; + pField->getFont(&fontID, &m_dFontSize); + if (fontID.num > 0) + { + Object oObj, oField, oFont; + XRef* xref = pdfDoc->getXRef(); + pField->getFieldRef(&oObj); + oObj.fetch(xref, &oField); + oObj.free(); + + bool bFindResources = false; + + if (oField.dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) + { + for (int i = 0; i < oFont.dictGetLength(); ++i) + { + Object oFontRef; + if (oFont.dictGetValNF(i, &oFontRef)->isRef() && oFontRef.getRef() == fontID) + { + bFindResources = true; + oFontRef.free(); + break; + } + oFontRef.free(); + } + } + oFont.free(); oField.free(); + + if (!bFindResources) + { + oObj.free(); + AcroForm* pAcroForms = pdfDoc->getCatalog()->getForm(); + Object* oAcroForm = pAcroForms->getAcroFormObj(); + if (oAcroForm->isDict() && oAcroForm->dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) + { + for (int i = 0; i < oFont.dictGetLength(); ++i) + { + Object oFontRef; + if (oFont.dictGetValNF(i, &oFontRef)->isRef() && oFontRef.getRef() == fontID) + { + bFindResources = true; + oFontRef.free(); + break; + } + oFontRef.free(); + } + } + oFont.free(); + } + + if (bFindResources) + { + Object oFontRef; + if (oObj.dictLookupNF("Font", &oFontRef)->isRef()) + { + if (oFontRef.fetch(xref, &oFont)->isDict()) + { + Ref r = oFontRef.getRef(); + gfxFontDict = new GfxFontDict(pdfDoc->getXRef(), &r, oFont.getDict()); + gfxFont = gfxFontDict->lookupByRef(fontID); + } + oFont.free(); + } + else if (oFontRef.isDict()) + { + gfxFontDict = new GfxFontDict(pdfDoc->getXRef(), NULL, oFontRef.getDict()); + gfxFont = gfxFontDict->lookupByRef(fontID); + } + oFontRef.free(); + } + oObj.free(); + } + std::wstring wsFileName, wsFontName; - GetFont(pdfDoc->getXRef(), pFontManager, pFontList, NULL, wsFileName, wsFontName); + if (gfxFont) + GetFont(pdfDoc->getXRef(), pFontManager, pFontList, gfxFont, wsFileName, wsFontName); m_sFontName = U_TO_UTF8(wsFileName); + + RELEASEOBJECT(gfxFontDict); } //------------------------------------------------------------------------ diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index a617f96d4f..70ea517936 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -512,7 +512,7 @@ private: std::vector m_arrCO; // Порядок вычислений - CO std::vector m_arrParents; // Родительские Fields - std::vector m_arrAnnots; + std::vector m_arrAnnots; }; } diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index a52be50b9c..f816e2c6c7 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -59,6 +59,7 @@ #ifndef BUILDING_WASM_MODULE #define FONTS_USE_AFM_SETTINGS #else +#include "../../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" #include "FontsWasm.h" #define FONTS_USE_ONLY_MEMORY_STREAMS #endif @@ -880,7 +881,7 @@ namespace PdfReader { } - void GetFont(XRef* pXref, NSFonts::IFontManager* pFontManager, CFontList *pFontList, GfxFont *pFont, std::wstring& wsFileName, std::wstring& wsFontName) + void GetFont(XRef* pXref, NSFonts::IFontManager* pFontManager, CFontList *pFontList, GfxFont* pFont, std::wstring& wsFileName, std::wstring& wsFontName) { wsFileName = L""; wsFontName = L""; diff --git a/PdfFile/SrcReader/RendererOutputDev.h b/PdfFile/SrcReader/RendererOutputDev.h index f78b87813c..2e57daf431 100644 --- a/PdfFile/SrcReader/RendererOutputDev.h +++ b/PdfFile/SrcReader/RendererOutputDev.h @@ -102,7 +102,7 @@ namespace PdfReader NSCriticalSection::CRITICAL_SECTION m_oCS; // Критическая секция }; - void GetFont(XRef* pXref, NSFonts::IFontManager* pFontManager, CFontList *pFontList, GfxFont *pFont, std::wstring& wsFileName, std::wstring& wsFontName); + void GetFont(XRef* pXref, NSFonts::IFontManager* pFontManager, CFontList *pFontList, GfxFont* pFont, std::wstring& wsFileName, std::wstring& wsFontName); //------------------------------------------------------------------------------------------------------------------------------- template inline static double PDFCoordsToMM(T tX)