diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index fe8cf9e2f9..2ec92230d3 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -958,7 +958,7 @@ void ReadInteractiveFormsFonts(CDrawingFile* pGrFile, int nType) if (pFont) free(pFont); - if (true) + if (false) continue; pFont = GetGIDByUnicode(pGrFile, (char*)sFontName.c_str()); @@ -1353,9 +1353,9 @@ int main(int argc, char* argv[]) std::cout << " Unicode " << nPathLength; nPathLength = READ_INT(pGlyphs + i); i += 4; - std::cout << " width " << (double)nPathLength / 10000.0; + std::cout << "\twidth " << (double)nPathLength / 10000.0; if (nCharX) - std::cout << " charX " << (double)nCharX / 10000.0; + std::cout << "\tcharX " << (double)nCharX / 10000.0; std::cout << std::endl; } } @@ -2252,7 +2252,7 @@ int main(int argc, char* argv[]) } // SCAN PAGE Fonts - if (false) + if (true) { SetScanPageFonts(pGrFile, nTestPage); diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 844288193c..477f0b6079 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -58,6 +58,7 @@ #include "SrcWriter/GState.h" #include "SrcWriter/RedactOutputDev.h" #include "SrcWriter/Image.h" +#include "SrcWriter/Font14.h" #define AddToObject(oVal)\ {\ @@ -4488,26 +4489,36 @@ void CPdfEditor::ScanAndProcessFonts(PDFDoc* pPDFDocument, XRef* xref, Dict* pRe Ref nFontRef = oFontRef.getRef(); if (pFontList->GetFont(&nFontRef, &pFontEntry)) { - std::map mCodeToWidth, mCodeToUnicode, mCodeToGID; - PdfReader::CollectFontWidths(gfxFont, oFont.getDict(), mCodeToWidth); - for (int nIndex = 0; nIndex < pFontEntry.unLenUnicode; ++nIndex) + PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); + PdfWriter::CFontEmbedded* pFont = pDoc->FindFontEmbedded(wsFileName, 0); + if (pFont) { - if (pFontEntry.pCodeToUnicode[nIndex]) - mCodeToUnicode[nIndex] = pFontEntry.pCodeToUnicode[nIndex]; + pFont->UpdateKey(sFontKey); } - for (int nIndex = 0; nIndex < pFontEntry.unLenGID; ++nIndex) + else { - if (pFontEntry.pCodeToGID[nIndex]) - mCodeToGID[nIndex] = pFontEntry.pCodeToGID[nIndex]; + std::map mCodeToWidth, mCodeToUnicode, mCodeToGID; + int nDW = PdfReader::CollectFontWidths(gfxFont, oFont.getDict(), mCodeToWidth); + for (int nIndex = 0; nIndex < pFontEntry.unLenUnicode; ++nIndex) + { + if (pFontEntry.pCodeToUnicode[nIndex]) + mCodeToUnicode[nIndex] = pFontEntry.pCodeToUnicode[nIndex]; + } + for (int nIndex = 0; nIndex < pFontEntry.unLenGID; ++nIndex) + { + if (pFontEntry.pCodeToGID[nIndex]) + mCodeToGID[nIndex] = pFontEntry.pCodeToGID[nIndex]; + } + m_pWriter->AddFont(L"Embedded: " + wsFontName, false, false, wsFileName, 0); + PdfWriter::CObjectBase* pObj = m_mObjManager.GetObj(nFontRef.num + nStartRefID); + if (!pObj) + { + pObj = new PdfWriter::CObjectBase(); + pObj->SetRef(nFontRef.num, nFontRef.gen); + } + pFont = pDoc->CreateFontEmbedded(wsFileName, 0, sFontKey, static_cast(gfxFont->getType()), pObj, mCodeToWidth, mCodeToUnicode, mCodeToGID); + pFont->SetDW(nDW); } - m_pWriter->AddFont(L"Embedded: " + wsFontName, false, false, wsFileName, 0); - PdfWriter::CObjectBase* pObj = m_mObjManager.GetObj(nFontRef.num + nStartRefID); - 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/SrcReader/PdfFont.cpp b/PdfFile/SrcReader/PdfFont.cpp index 93cacbf318..75e394ee2c 100644 --- a/PdfFile/SrcReader/PdfFont.cpp +++ b/PdfFile/SrcReader/PdfFont.cpp @@ -953,8 +953,9 @@ std::map GetFreeTextFont(PDFDoc* pdfDoc, NSFonts::IF return mRes; } -void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map& mGIDToWidth) +int CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map& mGIDToWidth) { + int nDefaultWidth = 1000; // Пытаемся получить ширины из словаря Widths Object oWidths; if (pFontDict->lookup("Widths", &oWidths)->isArray()) @@ -988,7 +989,6 @@ void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::mapisInt()) nDefaultWidth = oDW.getInt(); oDW.free(); @@ -1063,6 +1063,8 @@ void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map GetAnnotFontInfos(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFontList* pFontList, Object* oAnnotRef); std::map GetFreeTextFont(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFontList* pFontList, Object* oAnnotRef, std::vector& arrRC); bool FindFonts(Object* oStream, int nDepth, Object* oResFonts); -void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map& mGIDToWidth); +int CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map& mGIDToWidth); void CheckFontStylePDF(std::wstring& sName, bool& bBold, bool& bItalic); bool EraseSubsetTag(std::wstring& sFontName); } diff --git a/PdfFile/SrcWriter/Font14.cpp b/PdfFile/SrcWriter/Font14.cpp index 0b7196ee53..2f9cc565cb 100644 --- a/PdfFile/SrcWriter/Font14.cpp +++ b/PdfFile/SrcWriter/Font14.cpp @@ -106,6 +106,7 @@ namespace PdfWriter bool CFontEmbedded::LoadFont(const std::string& sFontKey, EFontType eFontType, CObjectBase* pObj, const std::map& mCodeToWidth, const std::map& mCodeToUnicode, const std::map& mCodeToGID) { + m_unDW = 1000; m_sFontKey = sFontKey; m_eFontType = eFontType; m_pObj = pObj; @@ -122,7 +123,7 @@ namespace PdfWriter if (it != m_mCodeToWidth.end()) return it->second; - return 0; + return m_unDW; } unsigned int CFontEmbedded::EncodeUnicode(const unsigned int& unGID, const unsigned int& unUnicode) { diff --git a/PdfFile/SrcWriter/Font14.h b/PdfFile/SrcWriter/Font14.h index 7efca80c43..481f45a94b 100644 --- a/PdfFile/SrcWriter/Font14.h +++ b/PdfFile/SrcWriter/Font14.h @@ -75,8 +75,10 @@ namespace PdfWriter CObjectBase* GetObj2(); const char* GetFontKey() const { return m_sFontKey.c_str(); } void UpdateKey(const std::string& sFontKey) { m_sFontKey = sFontKey; } + void SetDW(unsigned int unDW) { m_unDW = unDW; } private: + unsigned int m_unDW; std::string m_sFontKey; EFontType m_eFontType; CObjectBase* m_pObj; diff --git a/PdfFile/SrcWriter/ResourcesDictionary.cpp b/PdfFile/SrcWriter/ResourcesDictionary.cpp index 3a6de8595f..a2c3e8f89a 100644 --- a/PdfFile/SrcWriter/ResourcesDictionary.cpp +++ b/PdfFile/SrcWriter/ResourcesDictionary.cpp @@ -104,7 +104,16 @@ namespace PdfWriter } } - const char *sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj2() : pFont); + const char *sKey = NULL; + if (pEmbedded) + { + CObjectBase* pObj1 = pEmbedded->GetObj2(); + CObjectBase* pObj2 = m_pFonts->Get(pEmbedded->GetFontKey()); + if (pObj1 && pObj2 && pObj1->GetType() == object_type_UNKNOWN && pObj1->GetObjId() == pObj2->GetObjId()) + sKey = pEmbedded->GetFontKey(); + } + if (!sKey) + sKey = m_pFonts->GetKey(pEmbedded ? pEmbedded->GetObj2() : pFont); if (!sKey) { // если фонт не зарегистрирован в ресурсах, тогда регистрируем его