Skip to content

Commit

Permalink
Fix/pptx writing (#2806)
Browse files Browse the repository at this point in the history
* fix pptx writing

* fix pptx writing

* fix broken pptx
  • Loading branch information
SergeyLuzyanin authored Jun 3, 2022
1 parent 8c83440 commit d4fa2fe
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 271 deletions.
586 changes: 400 additions & 186 deletions common/Drawings/Format/Format.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/Shapes/SerializeWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4525,7 +4525,7 @@ function CBinaryFileWriter()
oThis.WriteUChar(g_nodeAttributeStart);
oThis._WriteInt1(0, cNvPr.id);
oThis._WriteString1(1, cNvPr.name);
oThis._WriteBool1(2, cNvPr.isHidden);
oThis._WriteBool2(2, cNvPr.isHidden);
oThis._WriteString2(3, cNvPr.title);
oThis._WriteString2(4, cNvPr.descr);
oThis._WriteBool2(5, cNvPr.form);
Expand Down
120 changes: 66 additions & 54 deletions common/Shapes/SerializeXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@
if (AscCommon.vertalign_SubScript === this.VertAlign) {
writer.WriteXmlAttributeInt("baseline", -25000);
}
else if (AscCommon.vertalign_SuperScript == this.VertAlign) {
else if (AscCommon.vertalign_SuperScript === this.VertAlign) {
writer.WriteXmlAttributeInt("baseline", 30000);
}

Expand All @@ -918,36 +918,44 @@
//writer.WriteXmlAttributeString("smtId", smtId);
//writer.WriteXmlAttributeString("bmk", bmk);

writer.WriteXmlAttributesEnd();

if(this.TextOutline) {
this.TextOutline.toXml(writer, "a:ln");
}
if(this.Unifill) {
this.Unifill.toXml(writer);
}
//EffectList.toXmlWriter(writer);
if(this.HighlightColor) {
writer.WriteXmlNodeStart("a:highlight");
writer.WriteXmlAttributesEnd();
this.HighlightColor.toXml(writer);
writer.WriteXmlNodeEnd("a:highlight");
}
//writer.Write(uFill);
//writer.Write(uFillTx);
if(this.RFonts.Ascii)
writeTypeface(writer, "a:latin", this.RFonts.Ascii.Name);
if(this.RFonts.EastAsia)
writeTypeface(writer, "a:ea", this.RFonts.EastAsia.Name);
if(this.RFonts.CS)
writeTypeface(writer, "a:cs", this.RFonts.CS.Name);
//writer.Write(sym);

let oParaHyperlink = null;
if(oRun) {
let oParaHyperlink = null;
if(oRun.Parent instanceof ParaHyperlink) {
oParaHyperlink = oRun.Parent;
}
}
if(this.TextOutline || this.Unifill || this.HighlightColor ||
(this.RFonts.Ascii && this.RFonts.Ascii.Name) ||
(this.RFonts.EastAsia && this.RFonts.EastAsia.Name) ||
(this.RFonts.CS && this.RFonts.CS.Name) ||
oParaHyperlink) {

writer.WriteXmlAttributesEnd();

if(this.TextOutline) {
this.TextOutline.toXml(writer, "a:ln");
}
if(this.Unifill) {
this.Unifill.toXml(writer);
}
//EffectList.toXmlWriter(writer);
if(this.HighlightColor) {
writer.WriteXmlNodeStart("a:highlight");
writer.WriteXmlAttributesEnd();
this.HighlightColor.toXml(writer);
writer.WriteXmlNodeEnd("a:highlight");
}
//writer.Write(uFill);
//writer.Write(uFillTx);
if(this.RFonts.Ascii)
writeTypeface(writer, "a:latin", this.RFonts.Ascii.Name);
if(this.RFonts.EastAsia)
writeTypeface(writer, "a:ea", this.RFonts.EastAsia.Name);
if(this.RFonts.CS)
writeTypeface(writer, "a:cs", this.RFonts.CS.Name);
//writer.Write(sym);


if(oParaHyperlink) {
let oHyperlink = new AscFormat.CT_Hyperlink();
oHyperlink.id = oParaHyperlink.Value;
Expand All @@ -956,17 +964,20 @@
}
oHyperlink.toXml(writer, "a:hlinkClick");
}
}
// if(this.hlinkClick) {
// this.hlinkClick.toXml(writer, "a:hlinkClick");
// }
//
// if(this.hlinkMouseOver) {
// this.hlinkMouseOver.toXml(writer, "a:hlinkMouseOver");
// }
//writer.Write(rtl);
// if(this.hlinkClick) {
// this.hlinkClick.toXml(writer, "a:hlinkClick");
// }
//
// if(this.hlinkMouseOver) {
// this.hlinkMouseOver.toXml(writer, "a:hlinkMouseOver");
// }
//writer.Write(rtl);

writer.WriteXmlNodeEnd(sName);
writer.WriteXmlNodeEnd(sName);
}
else {
writer.WriteXmlAttributesEnd(true);
}
};
AscCommonWord.CParaPr.prototype.fromDrawingML = function (reader) {
let sName;
Expand Down Expand Up @@ -1092,7 +1103,7 @@

if(this.Ind) {
if(this.Ind.FirstLine !== null && this.Ind.FirstLine !== undefined) {
writer.WriteXmlAttributeInt("indent", this.Ind.FirstLine * 36000 + 0.5 >> 0);
writer.WriteXmlAttributeInt("indent", (this.Ind.FirstLine * 36000 + 0.5) >> 0);
}
}
if(this.Jc !== undefined && this.Jc !== null) {
Expand Down Expand Up @@ -1191,6 +1202,9 @@
if(this.Content.length > 0) {
this.toDrawingMLText(writer, 0, this.Content.length - 1);
}
else {
writer.WriteXmlString("<a:t></a:t>");
}
writer.WriteXmlNodeEnd("a:fld");
};
AscCommonWord.CTable.prototype.fromDrawingML = function(reader) {
Expand Down Expand Up @@ -1250,8 +1264,7 @@
for (let nGridCol = 0; nGridCol < this.TableGrid.length; ++nGridCol) {
writer.WriteXmlNodeStart("a:gridCol");
writer.WriteXmlAttributeUInt("w", this.TableGrid[nGridCol] * 36000 >> 0);
writer.WriteXmlAttributesEnd();
writer.WriteXmlNodeEnd("a:gridCol");
writer.WriteXmlAttributesEnd(true);
}
writer.WriteXmlString("</a:tblGrid>");
let oTableRowGrid = AscCommon.GenerateTableWriteGrid(this);
Expand Down Expand Up @@ -1839,11 +1852,16 @@
};
CParaTabs.prototype.toDrawingML = function(writer) {
writer.WriteXmlNodeStart("a:tabLst");
writer.WriteXmlAttributesEnd();
for(let nIdx = 0; nIdx < this.Tabs.length; ++nIdx) {
this.Tabs[nIdx].toDrawingML(writer);
if(this.Tabs.length > 0) {
writer.WriteXmlAttributesEnd();
for(let nIdx = 0; nIdx < this.Tabs.length; ++nIdx) {
this.Tabs[nIdx].toDrawingML(writer);
}
writer.WriteXmlNodeEnd("a:tabLst");
}
else {
writer.WriteXmlAttributesEnd(true);
}
writer.WriteXmlNodeEnd("a:tabLst");
};
CParaTab.prototype.fromDrawingML = function(reader) {
let sName;
Expand Down Expand Up @@ -1881,8 +1899,7 @@
}
writer.WriteXmlAttributeString("algn", sAlign );
writer.WriteXmlAttributeString("pos", this.Pos * 36000 + 0.5 >> 0 );
writer.WriteXmlAttributesEnd();
writer.WriteXmlNodeEnd("a:tab");
writer.WriteXmlAttributesEnd(true);
};
CStyles.prototype.fromDrawingML = function(reader) {
if (!reader.ReadNextNode()) {
Expand Down Expand Up @@ -2320,14 +2337,12 @@
if(oSpacing.valPct !== undefined && oSpacing.valPct !== null) {
writer.WriteXmlNodeStart("a:spcPct");
writer.WriteXmlAttributeString("val", (oSpacing.valPct * 100000 + 0.5 >> 0) + "");
writer.WriteXmlAttributesEnd();
writer.WriteXmlNodeEnd("a:spcPct");
writer.WriteXmlAttributesEnd(true);
}
else if(oSpacing.val !== undefined && oSpacing.val !== null) {
writer.WriteXmlNodeStart("a:spcPts");
writer.WriteXmlAttributeString("val", (oSpacing.val / SPACING_SCALE + 0.5 >> 0) + "");
writer.WriteXmlAttributesEnd();
writer.WriteXmlNodeEnd("a:spcPts");
writer.WriteXmlAttributesEnd(true);
}
writer.WriteXmlNodeEnd(sName);
}
Expand Down Expand Up @@ -2366,10 +2381,7 @@
}
function writeTypeface(writer, sName, sFont) {
if(typeof sFont === "string") {
writer.WriteXmlNodeStart(sName);
writer.WriteXmlAttributeString("typeface", sFont);
writer.WriteXmlAttributesEnd();
writer.WriteXmlNodeEnd(sName);
AscFormat.FontCollection.prototype.writeFont(writer, sName, sFont)
}
}
function readHighlightColor(reader) {
Expand Down
4 changes: 3 additions & 1 deletion slide/Editor/Format/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,9 @@ AscFormat.InitClass(SlideLayout, AscFormat.CBaseFormatObject, AscDFH.historyitem
writer.WriteXmlAttributeString("xmlns:m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
writer.WriteXmlAttributeString("xmlns:w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

writer.WriteXmlNullableAttributeString("matchingName", this.matchingName);
if(typeof this.matchingName === "string" && this.matchingName.length > 0) {
writer.WriteXmlAttributeString("matchingName", this.matchingName);
}
writer.WriteXmlNullableAttributeBool("preserve", this.preserve);
writer.WriteXmlNullableAttributeBool("showMasterPhAnim", this.showMasterPhAnim);
writer.WriteXmlNullableAttributeBool("showMasterSp", this.showMasterSp);
Expand Down
73 changes: 46 additions & 27 deletions slide/Editor/Format/Presentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2795,14 +2795,12 @@ CSlideSize.prototype.GetWidthMM = function() {
CSlideSize.prototype.GetHeightMM = function() {
return this.GetHeightEMU() / g_dKoef_mm_to_emu;
};

CSlideSize.prototype.GetSizeType = function () {
if(AscFormat.isRealNumber(this.type)) {
return this.type;
}
return Asc.c_oAscSlideSZType.SzCustom;
};

CSlideSize.prototype.readAttrXml = function(name, reader) {
switch (name) {
case "cx": {
Expand Down Expand Up @@ -2885,6 +2883,11 @@ CSlideSize.prototype.readAttrXml = function(name, reader) {
}
}
};
CSlideSize.prototype.toXml = function (writer, name) {
writer.WriteXmlNodeStart(name);
this.writeAttrXmlImpl(writer);
writer.WriteXmlAttributesEnd(true);
};
CSlideSize.prototype.writeAttrXmlImpl = function(writer) {
writer.WriteXmlNullableAttributeInt("cx", this.cx);
writer.WriteXmlNullableAttributeInt("cy", this.cy);
Expand Down Expand Up @@ -2962,7 +2965,6 @@ CSlideSize.prototype.writeAttrXmlImpl = function(writer) {
}
};


let CONFORMANCE_STRICT = 0;
let CONFORMANCE_TRANSITIONAL = 1;

Expand Down Expand Up @@ -4022,6 +4024,9 @@ CPresentation.prototype.GetSlide = function(nIndex) {
}
return null;
};
CPresentation.prototype.GetSlidesCount = function(nIndex) {
return this.Slides.length;
};
CPresentation.prototype.GetCurrentSlide = function() {
return this.GetSlide(this.CurPage);
};
Expand Down Expand Up @@ -11851,6 +11856,7 @@ CPresentation.prototype.toZip = function(zip, context) {
let memory = new AscCommon.CMemory();
memory.context = context;
context.document = this;
context.presentation = this;

let filePart = new AscCommon.openXml.OpenXmlPackage(zip, memory);

Expand Down Expand Up @@ -11943,9 +11949,13 @@ CPresentation.prototype.toZip = function(zip, context) {
let oThemePart = presentationPart.part.addPartWithoutRels(AscCommon.openXml.Types.theme);
oUriMap[oTheme.Id] = oThemePart.uri;
oThemePart.setDataXml(oTheme, memory);
presentationPart.part.addRelationship(AscCommon.openXml.Types.theme.relationType, oThemePart.uri.replace("/ppt/", ""));
memory.Seek(0);
if(nTheme === 0) {
presentationPart.part.addRelationship(AscCommon.openXml.Types.theme.relationType, oThemePart.uri.replace("/ppt/", ""));
}
}
let aMastersRId = [];
let nLayoutsCount = 0;
for(let nSlideMaster = 0; nSlideMaster < aSlideMasters.length; ++nSlideMaster) {
let oSlideMaster = aSlideMasters[nSlideMaster];
let masterSlidePart = presentationPart.part.addPart(AscCommon.openXml.Types.slideMaster);
Expand All @@ -11966,7 +11976,10 @@ CPresentation.prototype.toZip = function(zip, context) {
context.clearSlideLayoutRels();
masterSlidePart.part.addRelationship(AscCommon.openXml.Types.theme.relationType, fGetRelPath(oUriMap[oSlideMaster.Theme.Id]));
memory.context.addSlideMasterRel(masterSlidePart.rId);
aMastersRId.push({rId: masterSlidePart.rId, id: "" + (AscFormat.MIN_SLD_MASTER_ID + nLayoutsCount)});
nLayoutsCount += (aSlideLayouts.length + 1);
}
context.aMastersRId = aMastersRId;
for(let nNotesMaster = 0; nNotesMaster < aNotesMasters.length; ++nNotesMaster) {
let oNotesMaster = aNotesMasters[nNotesMaster];
let oNotesMasterPart = presentationPart.part.addPart(AscCommon.openXml.Types.notesMaster);
Expand Down Expand Up @@ -12055,11 +12068,24 @@ CPresentation.prototype.toXml = function (writer) {
writer.WriteXmlAttributesEnd();

let oContext = writer.context;
(new IdList("p:sldMasterIdLst")).writeRIdList(writer, oContext.sldMasterIdLst, "p:sldMasterId");
(new IdList("p:notesMasterIdLst")).writeRIdList(writer, oContext.notesMasterIdLst, "p:notesMasterId");
(new IdList("p:handoutMasterIdLst")).writeRIdList(writer, oContext.handoutMasterIdLst, "p:handoutMasterId");
(new IdList("p:sldMasterIdLst")).writeRIdList(writer, oContext.aMastersRId, "p:sldMasterId");
let aNotesMastersId = [];
for(let nIdx = 0; nIdx < oContext.notesMasterIdLst.length; ++nIdx) {
aNotesMastersId.push({rId: oContext.notesMasterIdLst[nIdx]});
}
(new IdList("p:notesMasterIdLst")).writeRIdList(writer, aNotesMastersId, "p:notesMasterId");
let aHandoutMastersId = [];
for(let nIdx = 0; nIdx < oContext.handoutMasterIdLst.length; ++nIdx) {
aHandoutMastersId.push({rId: oContext.handoutMasterIdLst[nIdx]});
}
(new IdList("p:handoutMasterIdLst")).writeRIdList(writer, aHandoutMastersId, "p:handoutMasterId");
//writer.WriteArray("p:embeddedFontLst", embeddedFontLst);
(new IdList("p:sldIdLst")).writeRIdList(writer, oContext.sldIdLst, "p:sldId");

let aSlideId = [];
for(let nIdx = 0; nIdx < oContext.sldIdLst.length; ++nIdx) {
aSlideId.push({rId: oContext.sldIdLst[nIdx], id: AscFormat.MIN_SLD_ID + nIdx + 1});
}
(new IdList("p:sldIdLst")).writeRIdList(writer, aSlideId, "p:sldId");

writer.WriteXmlNullable(this.sldSz, "p:sldSz");
CSlideSize.prototype.static_CreateNotesSize().toXml(writer, "p:notesSz");
Expand Down Expand Up @@ -12184,32 +12210,25 @@ IdList.prototype.toXml = function(writer) {
}
writer.WriteXmlNodeEnd(this.name);
};
let MIN_SLD_MASTER_ID = 2147483649;
let MIN_SLD_ID = 256;
let MIN_SLD_LAYOUT_ID = 2147483649;
let MIN_SLD_MASTER_ID = 0x80000000;
let MIN_SLD_ID = 0xFF;
let MIN_SLD_LAYOUT_ID = 0x80000000;

AscFormat.MIN_SLD_MASTER_ID = MIN_SLD_MASTER_ID;
AscFormat.MIN_SLD_ID = MIN_SLD_ID;
AscFormat.MIN_SLD_LAYOUT_ID = MIN_SLD_LAYOUT_ID;
IdList.prototype.fillFromRIdList = function(aRId, sEntryName) {
let nCounter = null;
if(sEntryName === "p:sldMasterId") {
nCounter = MIN_SLD_MASTER_ID;
}
else if(sEntryName === "p:sldId") {
nCounter = MIN_SLD_ID;
}
else if(sEntryName === "p:sldLayoutId") {
nCounter = MIN_SLD_LAYOUT_ID;
}
for(let nItem = 0; nItem < aRId.length; ++nItem) {
let oItem = new IdEntry(sEntryName);
oItem.rId = aRId[nItem];
if(nCounter !== null) {
oItem.id = nCounter++;
}
let oRID = aRId[nItem];
oItem.rId = oRID.rId;
oItem.id = oRID.id;
this.list.push(oItem);
}
};
IdList.prototype.writeRIdList = function(writer, aRId, sEntryName) {
IdList.prototype.writeRIdList = function(writer, aRId, sEntryName, nCounterBase) {
if(aRId.length > 0) {
this.fillFromRIdList(aRId, sEntryName);
this.fillFromRIdList(aRId, sEntryName, nCounterBase);
this.toXml(writer);
}
};
Expand Down
7 changes: 6 additions & 1 deletion slide/Editor/Format/SlideMaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,12 @@ MasterSlide.prototype.toXml = function(writer) {
writer.WriteXmlNullable(this.clrMap, "p:clrMap");
writer.WriteXmlNullable(this.transition, "p:transition");
let oContext = writer.context;
(new IdList("p:sldLayoutIdLst")).writeRIdList(writer, oContext.sldLayoutIdLst, "p:sldLayoutId");
let aRId = [];
for(let nId = 0; nId < oContext.sldLayoutIdLst.length; ++nId) {
aRId.push({rId: oContext.sldLayoutIdLst[nId], id: AscFormat.MIN_SLD_MASTER_ID + oContext.sldLayoutsCount + nId + 1})
}
oContext.sldLayoutsCount += (oContext.sldLayoutIdLst.length + 1);
(new IdList("p:sldLayoutIdLst")).writeRIdList(writer, aRId, "p:sldLayoutId");
writer.WriteXmlNullable(this.timing, "p:timing");
writer.WriteXmlNullable(this.hf, "p:hf");
writer.WriteXmlNullable(this.txStyles, "p:txStyles");
Expand Down
2 changes: 1 addition & 1 deletion slide/apiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@
*/
ApiPresentation.prototype.GetSlidesCount = function()
{
return this.Presentation.Slides.length;
return this.Presentation.GetSlidesCount();
};

/**
Expand Down
Loading

0 comments on commit d4fa2fe

Please sign in to comment.