Compare commits

...

4 Commits

8 changed files with 51 additions and 26 deletions

View File

@ -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);

View File

@ -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<unsigned int, unsigned int> 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<unsigned int, unsigned int> 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<PdfWriter::EFontType>(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<PdfWriter::EFontType>(gfxFont->getType()), pObj, mCodeToWidth, mCodeToUnicode, mCodeToGID);
}
}
}

View File

@ -953,8 +953,9 @@ std::map<std::wstring, std::wstring> GetFreeTextFont(PDFDoc* pdfDoc, NSFonts::IF
return mRes;
}
void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int, unsigned int>& mGIDToWidth)
int CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int, unsigned int>& mGIDToWidth)
{
int nDefaultWidth = 1000;
// Пытаемся получить ширины из словаря Widths
Object oWidths;
if (pFontDict->lookup("Widths", &oWidths)->isArray())
@ -988,7 +989,6 @@ void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int,
{
// Получаем DW (default width)
Object oDW;
int nDefaultWidth = 1000;
if (oCIDFont.dictLookup("DW", &oDW)->isInt())
nDefaultWidth = oDW.getInt();
oDW.free();
@ -1063,6 +1063,8 @@ void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int,
oCIDFont.free();
}
oDescendantFonts.free();
return nDefaultWidth;
}
void CheckFontStylePDF(std::wstring& sName, bool& bBold, bool& bItalic)
{

View File

@ -64,7 +64,7 @@ bool GetFontFromAP(PDFDoc* pdfDoc, AcroFormField* pField, Object* oFontRef, std:
std::vector<CAnnotFontInfo> GetAnnotFontInfos(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFontList* pFontList, Object* oAnnotRef);
std::map<std::wstring, std::wstring> GetFreeTextFont(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFontList* pFontList, Object* oAnnotRef, std::vector<CAnnotMarkup::CFontData*>& arrRC);
bool FindFonts(Object* oStream, int nDepth, Object* oResFonts);
void CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int, unsigned int>& mGIDToWidth);
int CollectFontWidths(GfxFont* gfxFont, Dict* pFontDict, std::map<unsigned int, unsigned int>& mGIDToWidth);
void CheckFontStylePDF(std::wstring& sName, bool& bBold, bool& bItalic);
bool EraseSubsetTag(std::wstring& sFontName);
}

View File

@ -106,6 +106,7 @@ namespace PdfWriter
bool CFontEmbedded::LoadFont(const std::string& sFontKey, EFontType eFontType, CObjectBase* pObj,
const std::map<unsigned int, unsigned int>& mCodeToWidth, const std::map<unsigned int, unsigned int>& mCodeToUnicode, const std::map<unsigned int, unsigned int>& 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)
{

View File

@ -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;

View File

@ -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)
{
// если фонт не зарегистрирован в ресурсах, тогда регистрируем его

View File

@ -656,7 +656,7 @@ GBool XRef::readXRefTable(GFileOffset *pos, int offset, XRefPosSet *posSet) {
// get the 'Prev' pointer
//~ this can be a 64-bit int (?)
obj.getDict()->lookupNF("Prev", &obj2);
if (obj2.isInt()) {
if (obj2.isInt() && obj2.getInt() != 0) {
*pos = (GFileOffset)(Guint)obj2.getInt();
more = gTrue;
} else if (obj2.isRef()) {