Compare commits

...

6 Commits

11 changed files with 74 additions and 31 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

@ -736,7 +736,7 @@ namespace PPTX
if (m_elem.is_init())
m_elem->toXmlWriter(pWriter);
}
std::wstring SpTreeElem::GetSlicerRequires()
std::wstring SpTreeElem::GetRequires()
{
if (m_elem.IsInit() && m_elem.is<PPTX::Logic::GraphicFrame>())
{
@ -749,6 +749,10 @@ namespace PPTX
{
return L"sle15";
}
else if (oGraphicFrame.chartRec.IsInit() && oGraphicFrame.chartRec->m_bChartEx)
{
return L"cx4";
}
}
return L"";
}

View File

@ -96,7 +96,7 @@ namespace PPTX
smart_ptr<WrapperWritingElement> GetElemAlternative();
virtual void SetParentPointer(const WrapperWritingElement* pParent);
std::wstring GetSlicerRequires();
std::wstring GetRequires();
nullable<OOX::Logic::CBinData> m_binaryData;
std::wstring m_sRequires;//from mc:Choice

View File

@ -165,7 +165,7 @@ namespace OOX
}
if(m_oElement.IsInit())
{
std::wstring sRequires = m_oElement->GetSlicerRequires();
std::wstring sRequires = m_oElement->GetRequires();
if(L"a14" == sRequires)
{
writer.WriteString(L"<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" Requires=\"a14\">");
@ -174,14 +174,28 @@ namespace OOX
{
writer.WriteString(L"<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice xmlns:sle15=\"http://schemas.microsoft.com/office/drawing/2012/slicer\" Requires=\"sle15\">");
}
else if (L"cx4" == sRequires)
{
writer.WriteString(L"<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" Requires=\"cx4\">");
}
NSBinPptxRW::CXmlWriter oXmlWriter(XMLWRITER_DOC_TYPE_XLSX);
m_oElement->toXmlWriter(&oXmlWriter);
writer.WriteString(oXmlWriter.GetXmlString());
if(L"a14" == sRequires || L"sle15" == sRequires)
if(L"a14" == sRequires || L"sle15" == sRequires || L"cx4" == sRequires)
{
writer.WriteString(L"</mc:Choice><mc:Fallback xmlns=\"\"><xdr:sp macro=\"\" textlink=\"\"><xdr:nvSpPr><xdr:cNvPr id=\"0\" name=\"\"/><xdr:cNvSpPr><a:spLocks noTextEdit=\"1\"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"0\" cy=\"0\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val=\"white\"/></a:solidFill><a:ln w=\"1\"><a:solidFill><a:prstClr val=\"green\"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow=\"clip\" horzOverflow=\"clip\"/><a:lstStyle/><a:p><a:r><a:rPr lang=\"en-US\" sz=\"1100\"/><a:t>This shape represents a table slicer. Table slicers are not supported in this version of Excel.\n\nIf the shape was modified in an earlier version of Excel, or if the workbook was saved in Excel 2007 or earlier, the slicer can't be used.</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent>");
std::wstring text;
if (L"a14" == sRequires || L"sle15" == sRequires)
{
text = L"This shape represents a table slicer.Table slicers are not supported in this version of Excel.\n\nIf the shape was modified in an earlier version of Excel, or if the workbook was saved in Excel 2007 or earlier, the slicer can't be used.";
}
else if (L"cx4" == sRequires)
{
text = L"This chart isn't available in your version of Excel.\n\nEditing this shape or saving this workbook into a different file format will permanently break the chart.";
}
writer.WriteString(L"</mc:Choice><mc:Fallback xmlns=\"\"><xdr:sp macro=\"\" textlink=\"\"><xdr:nvSpPr><xdr:cNvPr id=\"0\" name=\"\"/><xdr:cNvSpPr><a:spLocks noTextEdit=\"1\"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"0\" cy=\"0\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val=\"white\"/></a:solidFill><a:ln w=\"1\"><a:solidFill><a:prstClr val=\"green\"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow=\"clip\" horzOverflow=\"clip\"/><a:lstStyle/><a:p><a:r><a:rPr lang=\"en-US\" sz=\"1100\"/><a:t>" + text +
L"</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent>");
}
}
if (m_oClientData.IsInit())

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()) {