Merge pull request 'Fix write base fonts' (#216) from fix/pdf-standart-fonts into release/v8.3.0

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/216
This commit is contained in:
Oleg Korshul
2025-02-03 12:40:28 +00:00
2 changed files with 30 additions and 4 deletions

View File

@ -1505,10 +1505,13 @@ bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bIt
std::map<std::wstring, std::wstring>::iterator it = m_mFonts.find(wsFontName); std::map<std::wstring, std::wstring>::iterator it = m_mFonts.find(wsFontName);
if (it != m_mFonts.end()) if (it != m_mFonts.end())
wsFontPath = it->second; wsFontPath = it->second;
std::map<std::wstring, std::wstring> mFonts = pReader->GetFonts(); if (wsFontPath.empty())
std::map<std::wstring, std::wstring>::iterator it2 = mFonts.find(wsFontName); {
if (it2 != mFonts.end()) std::map<std::wstring, std::wstring> mFonts = pReader->GetFonts();
wsFontPath = it2->second; std::map<std::wstring, std::wstring>::iterator it2 = mFonts.find(wsFontName);
if (it2 != mFonts.end())
wsFontPath = it2->second;
}
if (wsFontPath.empty()) if (wsFontPath.empty())
return false; return false;
if (wsFontName == L"Helvetica") if (wsFontName == L"Helvetica")

View File

@ -42,6 +42,7 @@
#include "OnlineOfficeBinToPdf.h" #include "OnlineOfficeBinToPdf.h"
#include "SrcWriter/Document.h" #include "SrcWriter/Document.h"
#include "Resources/BaseFonts.h"
#else #else
class CPdfEditor class CPdfEditor
@ -908,6 +909,28 @@ HRESULT CPdfFile::put_FontName(const std::wstring& wsName)
lStyle |= 2; lStyle |= 2;
put_FontStyle(lStyle); put_FontStyle(lStyle);
} }
NSFonts::IFontsMemoryStorage* pMemoryStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
if (wsFontPath == sSub && (!pMemoryStorage || !pMemoryStorage->Get(wsFontPath)))
{
const BYTE* pData14 = NULL;
unsigned int nSize14 = 0;
std::wstring wsTempFileName = m_pInternal->wsTempFolder + L"/" + wsFontPath + L".base";
if (NSFile::CFileBinary::Exists(wsTempFileName))
wsFontPath = wsTempFileName;
else if (PdfReader::GetBaseFont(sSub, pData14, nSize14))
{
NSFile::CFileBinary oFile;
if (oFile.CreateFileW(wsTempFileName))
{
oFile.WriteFile((BYTE*)pData14, nSize14);
wsFontPath = wsTempFileName;
}
else if (!wsTempFileName.empty())
NSFile::CFileBinary::Remove(wsTempFileName);
oFile.CloseFile();
}
}
} }
else else
wsFont = sSub; wsFont = sSub;