readAllSlides method
Future<void>
readAllSlides(
- Presentation presentation,
- List<
Relationship> relationShips, - Archive archive,
- String presentationOutputDirectory,
Function for processing slides
Implementation
Future<void> readAllSlides(Presentation presentation, List<Relationship> relationShips, Archive archive, String presentationOutputDirectory) async {
for (int i = 0; i < presentation.slides.length; i++) {
var slideRelation = relationShips.firstWhereOrNull((rel) {
return rel.id == presentation.slides[i].rId;
});
if (slideRelation != null) {
var slideFile = archive.singleWhere((archiveFile) {
return archiveFile.name.endsWith(slideRelation.target);
});
if (slideFile.isFile) {
final fileContent = utf8.decode(slideFile.content);
final slideDoc = xml.XmlDocument.parse(fileContent);
presentation.slides[i].fileName = slideFile.name.split("/").last;
var spElement = slideDoc.findAllElements("p:sp");
if (spElement.isNotEmpty) {
for (int j = 0; j < spElement.length; j++) {
var checkCustomDiagram = spElement.elementAt(j).findAllElements("a:custGeom");
if (checkCustomDiagram.isNotEmpty) {
var pathListElement = checkCustomDiagram.first.findAllElements("a:pathLst");
if (pathListElement.isNotEmpty) {
double offsetX = 0;
double offsetY = 0;
int width = 0;
int height = 0;
String clrScheme = "";
String srgbClr = "";
int rotate = 0;
int flipH = 0;
int flipV = 0;
String lumMod = "";
String lumOff = "";
Map<String, double> offsetValue = {"offsetX": offsetX, "offsetY": offsetY};
Map<String, int> rotFlip = {"rot": rotate, "flipH": flipH, "flipV": flipV};
Map<String, int> widthHeight = {"width": width, "height": height};
Map<String, String> colorDetails = {"clrScheme": clrScheme, "lumMod": lumMod, "lumOff": lumOff, "srgbClr": srgbClr};
getGroupDetails(spElement.elementAt(j), offsetValue, rotFlip, widthHeight, colorDetails);
offsetX = offsetValue["offsetX"]!;
offsetY = offsetValue["offsetY"]!;
rotate = rotFlip["rot"]!;
flipH = rotFlip["flipH"]!;
flipV = rotFlip["flipV"]!;
width = widthHeight["width"]!;
height = widthHeight["height"]!;
clrScheme = colorDetails["clrScheme"]!;
lumMod = colorDetails["lumMod"]!;
lumOff = colorDetails["lumOff"]!;
srgbClr = colorDetails["srgbClr"]!;
/*if (spElement.elementAt(j).parentElement != null &&
spElement.elementAt(j).parentElement?.name.toString() == "p:grpSp") {
var grpSpPr = spElement.elementAt(j).parentElement?.findAllElements("p:grpSpPr");
if (grpSpPr != null && grpSpPr.isNotEmpty) {
var chckOff = grpSpPr.first.findAllElements("a:off");
if (chckOff.isNotEmpty) {
var offX = chckOff.first.getAttribute("x");
if (offX != null) {
offsetX = double.parse(offX);
}
var offY = chckOff.first.getAttribute("y");
if (offY != null) {
offsetY = double.parse(offY);
}
}
var chkChOff=grpSpPr.first.findAllElements("a:chOff");
if(chkChOff.isNotEmpty){
//print("a:chOff");
//print(chkChOff);
var offX=chkChOff.first.getAttribute("x");
if(offX!=null){
//print(offsetX);
offsetX=offsetX-double.parse(offX);
//print(offsetX);
}
var offY=chkChOff.first.getAttribute("y");
if(offY!=null){
//print(offsetY);
offsetY=offsetY-double.parse(offY);
//print(offsetY);
}
}
}
}*/
var xfrmElement = spElement.elementAt(j).findAllElements("a:xfrm");
if (xfrmElement.isNotEmpty) {
var chkOff = xfrmElement.first.findAllElements("a:off");
if (chkOff.isNotEmpty) {
var offX = chkOff.first.getAttribute("x");
var offY = chkOff.first.getAttribute("y");
if (offX != null && offY != null) {
offsetX = double.parse(offX) + offsetX;
offsetY = double.parse(offY) + offsetY;
}
}
var chkExt = xfrmElement.first.findAllElements("a:ext");
if (chkExt.isNotEmpty) {
var tempWidth = chkExt.first.getAttribute("cx");
var tempHeight = chkExt.first.getAttribute("cy");
if (tempWidth != null && tempHeight != null) {
width = int.parse(tempWidth);
height = int.parse(tempHeight);
}
}
var chkRotate = xfrmElement.first.getAttribute("rot");
if (chkRotate != null) {
rotate = rotate + int.parse(chkRotate) ~/ 60000;
}
var chkFlipH = xfrmElement.first.getAttribute("flipH");
if (chkFlipH != null) {
if (chkFlipH == "1") {
flipH = 1;
}
}
var chkFlipV = xfrmElement.first.getAttribute("flipV");
if (chkFlipV != null) {
if (chkFlipV == "1") {
flipV = 1;
}
}
}
var chkSpPr = spElement.elementAt(j).findAllElements("p:spPr");
if (chkSpPr.isNotEmpty) {
var chkSolidFill = chkSpPr.first.findAllElements("a:solidFill");
if (chkSolidFill.isNotEmpty) {
var chkSchemeClr = chkSolidFill.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
clrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
var chkRGBClr = chkSolidFill.first.findAllElements("a:srgbClr");
if (chkRGBClr.isNotEmpty) {
var tempVal = chkRGBClr.first.getAttribute("val");
if (tempVal != null) {
srgbClr = tempVal;
}
}
}
}
var pathElement = pathListElement.first.findAllElements("a:path");
var pathChildElements = pathElement.first.childElements;
PresentationCustomDiagram presentationCustomDiagram = PresentationCustomDiagram(offsetX, offsetY, width, height);
presentationCustomDiagram.clrScheme = clrScheme;
presentationCustomDiagram.srgbClr = srgbClr;
if (rotate != 0) {
presentationCustomDiagram.rotate = rotate;
}
if (flipH == 1) {
presentationCustomDiagram.flipH = "1";
}
if (flipV == 1) {
presentationCustomDiagram.flipV = "1";
}
if (lumOff.isNotEmpty) {
presentationCustomDiagram.lumOff = lumOff;
}
if (lumMod.isNotEmpty) {
presentationCustomDiagram.lumMod = lumMod;
}
pathChildElements.forEach((path) {
List<Points> points = [];
var pt = path.findAllElements("a:pt");
if (pt.isNotEmpty) {
pt.forEach((pts) {
points.add(Points(double.parse(pts.getAttribute("x") ?? "0"), double.parse(pts.getAttribute("y") ?? "0")));
});
}
if (points.isNotEmpty) {
PathAction pathAction = PathAction(points, path.localName);
presentationCustomDiagram.pathList.add(pathAction);
}
});
if (presentationCustomDiagram.pathList.isNotEmpty) {
presentation.slides[i].components.add(presentationCustomDiagram);
}
}
}
var checkPresetShape = spElement.elementAt(j).findAllElements("a:prstGeom");
if (checkPresetShape.isNotEmpty) {
double offsetX = 0;
double offsetY = 0;
int width = 0;
int height = 0;
/*if (spElement.elementAt(j).parentElement != null &&
spElement.elementAt(j).parentElement?.name.toString() == "p:grpSp") {
var grpSpPr = spElement.elementAt(j).parentElement?.findAllElements("p:grpSpPr");
if (grpSpPr != null && grpSpPr.isNotEmpty) {
var chckOff = grpSpPr.first.findAllElements("a:off");
if (chckOff.isNotEmpty) {
var offX = chckOff.first.getAttribute("x");
if (offX != null) {
offsetX = double.parse(offX);
}
var offY = chckOff.first.getAttribute("y");
if (offY != null) {
offsetY = double.parse(offY);
}
}
var chkChOff=grpSpPr.first.findAllElements("a:chOff");
if(chkChOff.isNotEmpty){
//print("a:chOff");
//print(chkChOff);
var offX=chkChOff.first.getAttribute("x");
if(offX!=null){
//print(offsetX);
offsetX=offsetX-double.parse(offX);
//print(offsetX);
}
var offY=chkChOff.first.getAttribute("y");
if(offY!=null){
//print(offsetY);
offsetY=offsetY-double.parse(offY);
//print(offsetY);
}
}
}
}*/
String fillClrScheme = "";
String lumMod = "";
String lumOff = "";
String srgbClr = "";
int rotate = 0;
int flipH = 0;
int flipV = 0;
Map<String, double> offsetValue = {"offsetX": offsetX, "offsetY": offsetY};
Map<String, int> rotFlip = {"rot": rotate, "flipH": flipH, "flipV": flipV};
Map<String, int> widthHeight = {"width": width, "height": height};
Map<String, String> colorDetails = {"clrScheme": fillClrScheme, "lumMod": lumMod, "lumOff": lumOff, "srgbClr": srgbClr};
getGroupDetails(spElement.elementAt(j), offsetValue, rotFlip, widthHeight, colorDetails);
offsetX = offsetValue["offsetX"]!;
offsetY = offsetValue["offsetY"]!;
rotate = rotFlip["rot"]!;
flipH = rotFlip["flipH"]!;
flipV = rotFlip["flipV"]!;
width = widthHeight["width"]!;
height = widthHeight["height"]!;
fillClrScheme = colorDetails["clrScheme"]!;
lumMod = colorDetails["lumMod"]!;
lumOff = colorDetails["lumOff"]!;
srgbClr = colorDetails["srgbClr"]!;
var xfrmElement = spElement.elementAt(j).findAllElements("a:xfrm");
if (xfrmElement.isNotEmpty) {
var chkOff = xfrmElement.first.findAllElements("a:off");
if (chkOff.isNotEmpty) {
var offX = chkOff.first.getAttribute("x");
var offY = chkOff.first.getAttribute("y");
if (offX != null && offY != null) {
offsetX = double.parse(offX) + offsetX;
offsetY = double.parse(offY) + offsetY;
}
}
var chkExt = xfrmElement.first.findAllElements("a:ext");
if (chkExt.isNotEmpty) {
var extX = chkExt.first.getAttribute("cx");
var extY = chkExt.first.getAttribute("cy");
if (extX != null && extY != null) {
width = int.parse(extX);
height = int.parse(extY);
//size = Size(double.parse(extX), double.parse(extY));
}
}
var chkRotate = xfrmElement.first.getAttribute("rot");
if (chkRotate != null) {
rotate = rotate + (int.parse(chkRotate) ~/ 60000);
}
var chkFlipH = xfrmElement.first.getAttribute("flipH");
if (chkFlipH != null) {
if (chkFlipH == "1") {
flipH = 1;
}
}
var chkFlipV = xfrmElement.first.getAttribute("flipV");
if (chkFlipV != null) {
if (chkFlipV == "1") {
flipV = 1;
}
}
}
String presetShapeType = "";
String adjVal = "";
String adjVal2 = "";
String adjVal3 = "";
var chkPresetShapeType = checkPresetShape.first.getAttribute("prst");
if (chkPresetShapeType != null) {
presetShapeType = chkPresetShapeType;
if (chkPresetShapeType == "rect" || chkPresetShapeType == "roundRect" || chkPresetShapeType == "ellipse") {
if ((width + widthHeight["width"]!) > 0 && (height + widthHeight["height"]!) > 0) {
width = width + widthHeight["width"]!;
height = height + widthHeight["height"]!;
}
}
}
var chkPresetAdjVal = checkPresetShape.first.findAllElements("a:gd");
if (chkPresetAdjVal.isNotEmpty) {
var checkFormula = chkPresetAdjVal.first.getAttribute("fmla");
if (checkFormula != null) {
adjVal = checkFormula;
}
if (chkPresetAdjVal.length > 1) {
var checkFormula2 = chkPresetAdjVal.elementAt(1).getAttribute("fmla");
if (checkFormula2 != null) {
adjVal2 = checkFormula2;
}
}
if (chkPresetAdjVal.length > 2) {
var checkFormula3 = chkPresetAdjVal.elementAt(2).getAttribute("fmla");
if (checkFormula3 != null) {
adjVal3 = checkFormula3;
}
}
}
var chkShapePr = spElement.elementAt(j).findAllElements("p:spPr");
if (chkShapePr.isNotEmpty) {
var chkSolidFill = chkShapePr.first.findAllElements("a:solidFill");
if (chkSolidFill.isNotEmpty) {
var chkSchemeClr = chkSolidFill.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
fillClrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
} else {
var chkPStyle = spElement.elementAt(j).findAllElements("p:style");
if (chkPStyle.isNotEmpty) {
var chkFillRef = chkPStyle.first.findAllElements("a:fillRef");
if (chkFillRef.isNotEmpty) {
var chkSchemeClr = chkFillRef.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
fillClrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
}
}
}
}
var chkIsTextBox = spElement.elementAt(j).findAllElements("a:t");
//if(chkIsTextBox.isEmpty) {
PresentationPresetShapes presentationPresetShapes = PresentationPresetShapes(presetShapeType, adjVal, fillClrScheme);
presentationPresetShapes.top = offsetY;
presentationPresetShapes.left = offsetX;
presentationPresetShapes.width = width;
presentationPresetShapes.height = height;
if (adjVal2.isNotEmpty) {
presentationPresetShapes.adjValue2 = adjVal2;
}
if (adjVal3.isNotEmpty) {
presentationPresetShapes.adjValue3 = adjVal3;
}
if (rotate != 0) {
presentationPresetShapes.rotate = rotate;
}
if (flipH == 1) {
presentationPresetShapes.flipH = "1";
}
if (flipV == 1) {
presentationPresetShapes.flipV = "1";
}
if (lumOff.isNotEmpty) {
presentationPresetShapes.lumOff = lumOff;
}
if (lumMod.isNotEmpty) {
presentationPresetShapes.lumMod = lumMod;
}
presentation.slides[i].components.add(presentationPresetShapes);
//}
}
var checkTextBody = spElement.elementAt(j).findAllElements("p:txBody");
if (checkTextBody.isNotEmpty) {
var tempTextBox =
await compute(getPresentationTextBox, GetPresentationTextBoxParam(spElement.elementAt(j), presentation.slides[i].clearMap));
if (tempTextBox != null) {
presentation.slides[i].components.add(tempTextBox);
}
}
}
}
var checkSlideRel = archive.singleWhereOrNull((archiveFile) {
return archiveFile.name.endsWith("${presentation.slides[i].fileName}.rels");
});
if (checkSlideRel != null) {
List<Relationship> slideLevelRelations = [];
final fileContent = utf8.decode(checkSlideRel.content);
String drawingTarget = "";
String layoutTarget = "";
String slideMaster = "";
final document = xml.XmlDocument.parse(fileContent);
final relationshipsElement = document.findAllElements("Relationship");
for (var rel in relationshipsElement) {
if (rel.getAttribute("Id") != null) {
slideLevelRelations.add(Relationship(rel.getAttribute("Id").toString(), rel.getAttribute("Target").toString()));
}
if (rel.getAttribute("Type") != null && rel.getAttribute("Type")!.endsWith("relationships/diagramDrawing")) {
drawingTarget = rel.getAttribute("Target").toString().replaceAll("../", "");
}
if (rel.getAttribute("Type") != null && rel.getAttribute("Type")!.endsWith("relationships/slideLayout")) {
layoutTarget = rel.getAttribute("Target").toString().replaceAll("../", "");
}
}
if (drawingTarget.isNotEmpty) {
var diagramFile = archive.singleWhereOrNull((archiveFile) {
return archiveFile.name.endsWith(drawingTarget);
});
if (diagramFile != null) {
getAllShapes(diagramFile, presentation.slides[i]);
}
}
if (layoutTarget.isNotEmpty) {
var checkLayoutRel = archive.singleWhereOrNull((archiveFile) {
return archiveFile.name.endsWith("${layoutTarget.split("/").last}.rels");
});
List<Relationship> layoutRelations = [];
if (checkLayoutRel != null) {
final fileContent2 = utf8.decode(checkLayoutRel.content);
final document2 = xml.XmlDocument.parse(fileContent2);
final relationshipsElement2 = document2.findAllElements("Relationship");
for (var rel in relationshipsElement2) {
if (rel.getAttribute("Id") != null) {
//print(rel.getAttribute("Id"));
//print(rel.getAttribute("Target"));
if (rel.getAttribute("Type") != null) {
if (rel.getAttribute("Type")!.endsWith("relationships/slideMaster")) {
if (rel.getAttribute("Target") != null) {
slideMaster = rel.getAttribute("Target")!.replaceAll("../", "");
}
}
}
layoutRelations.add(Relationship(rel.getAttribute("Id").toString(), rel.getAttribute("Target").toString()));
}
}
}
//print(i);
//print(layoutTarget);
var layoutFile = archive.singleWhereOrNull((archiveFile) {
return archiveFile.name.endsWith(layoutTarget);
});
if (layoutFile != null) {
//print("0.5");
final fileContent3 = utf8.decode(layoutFile.content);
final document3 = xml.XmlDocument.parse(fileContent3);
var chkBg = document3.findAllElements("p:bg");
if (chkBg.isNotEmpty) {
var chkBlip = chkBg.first.findAllElements("a:blip");
if (chkBlip.isNotEmpty) {
var chkEmbed = chkBlip.first.getAttribute("r:embed");
if (chkEmbed != null) {
var layoutRelTarget = layoutRelations.firstWhereOrNull((rel) {
return rel.id == chkEmbed;
});
if (layoutRelTarget != null) {
//print(layoutRelTarget.target.split("/").last);
presentation.slides[i].backgroundImagePath = "$presentationOutputDirectory/${layoutRelTarget.target.split("/").last}";
}
}
}
}
var chkShape = document3.findAllElements("p:sp");
if (chkShape.isNotEmpty) {
//print("1");
SlideLayout slideLayout = SlideLayout();
chkShape.forEach((shapeElement) {
//print("2");
var chkPara = shapeElement.findAllElements("p:ph");
if (chkPara.isNotEmpty) {
//print("3");
String type = "", idx = "", sz = "", anchor = "", schemeClr = "";
int defaultSz = 0;
var tempType = chkPara.first.getAttribute("type");
if (tempType != null) {
type = tempType;
}
var tempIdx = chkPara.first.getAttribute("idx");
if (tempIdx != null) {
idx = tempIdx;
}
var tempSz = chkPara.first.getAttribute("sz");
if (tempSz != null) {
sz = tempSz;
}
var chkBodyPr = shapeElement.findAllElements("a:bodyPr");
if (chkBodyPr.isNotEmpty) {
var tempAnchor = chkBodyPr.first.getAttribute("anchor");
if (tempAnchor != null) {
anchor = tempAnchor;
}
}
var chkDefaultRPr = shapeElement.findAllElements("a:defRPr");
if (chkDefaultRPr.isNotEmpty) {
var tempDefaultSz = chkDefaultRPr.first.getAttribute("sz");
if (tempDefaultSz != null) {
defaultSz = int.parse(tempDefaultSz);
}
}
//print("type");
//print(type);
//print("idx");
//print(idx);
SlideLayoutParagraph paragraph = SlideLayoutParagraph(type, idx, sz, anchor, schemeClr, defaultSz);
var xfrmElement = shapeElement.findAllElements("a:xfrm");
if (xfrmElement.isNotEmpty) {
var chkOff = xfrmElement.first.findAllElements("a:off");
if (chkOff.isNotEmpty) {
var offX = chkOff.first.getAttribute("x");
var offY = chkOff.first.getAttribute("y");
if (offX != null && offY != null) {
paragraph.x = double.parse(offX);
paragraph.y = double.parse(offY);
}
}
var chkExt = xfrmElement.first.findAllElements("a:ext");
if (chkExt.isNotEmpty) {
var extX = chkExt.first.getAttribute("cx");
var extY = chkExt.first.getAttribute("cy");
if (extX != null && extY != null) {
paragraph.width = int.parse(extX);
paragraph.height = int.parse(extY);
}
}
}
slideLayout.paragraphs.add(paragraph);
}
var checkPresetShape = shapeElement.findAllElements("a:prstGeom");
if (checkPresetShape.isNotEmpty) {
double offsetX = 0;
double offsetY = 0;
int width = 0;
int height = 0;
/*if (shapeElement.parentElement != null &&
shapeElement.parentElement?.name.toString() == "p:grpSp") {
var grpSpPr = shapeElement.parentElement?.findAllElements("p:grpSpPr");
if (grpSpPr != null && grpSpPr.isNotEmpty) {
var chckOff = grpSpPr.first.findAllElements("a:off");
if (chckOff.isNotEmpty) {
var offX = chckOff.first.getAttribute("x");
if (offX != null) {
offsetX = double.parse(offX);
}
var offY = chckOff.first.getAttribute("y");
if (offY != null) {
offsetY = double.parse(offY);
}
}
var chkChOff=grpSpPr.first.findAllElements("a:chOff");
if(chkChOff.isNotEmpty){
//print("a:chOff");
//print(chkChOff);
var offX=chkChOff.first.getAttribute("x");
if(offX!=null){
//print(offsetX);
offsetX=offsetX-double.parse(offX);
//print(offsetX);
}
var offY=chkChOff.first.getAttribute("y");
if(offY!=null){
//print(offsetY);
offsetY=offsetY-double.parse(offY);
//print(offsetY);
}
}
}
}*/
var xfrmElement = shapeElement.findAllElements("a:xfrm");
if (xfrmElement.isNotEmpty) {
var chkOff = xfrmElement.first.findAllElements("a:off");
if (chkOff.isNotEmpty) {
var offX = chkOff.first.getAttribute("x");
var offY = chkOff.first.getAttribute("y");
if (offX != null && offY != null) {
offsetX = double.parse(offX) + offsetX;
offsetY = double.parse(offY) + offsetY;
}
}
var chkExt = xfrmElement.first.findAllElements("a:ext");
if (chkExt.isNotEmpty) {
var extX = chkExt.first.getAttribute("cx");
var extY = chkExt.first.getAttribute("cy");
if (extX != null && extY != null) {
width = int.parse(extX);
height = int.parse(extY);
//size = Size(double.parse(extX), double.parse(extY));
}
}
}
String presetShapeType = "";
String adjVal = "";
String fillClrScheme = "";
String lumMod = "";
String lumOff = "";
var chkPresetShapeType = checkPresetShape.first.getAttribute("prst");
if (chkPresetShapeType != null) {
presetShapeType = chkPresetShapeType;
}
var chkPresetAdjVal = checkPresetShape.first.findAllElements("a:gd");
if (chkPresetAdjVal.isNotEmpty) {
var checkFormula = chkPresetAdjVal.first.getAttribute("fmla");
if (checkFormula != null) {
adjVal = checkFormula;
}
}
var chkSpPr = shapeElement.findAllElements("p:spPr");
if (chkSpPr.isNotEmpty) {
var chkSolidFill = chkSpPr.first.findAllElements("a:solidFill");
if (chkSolidFill.isNotEmpty) {
var chkSchemeClr = chkSolidFill.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
fillClrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
} else {
var chkFillRef = chkSpPr.first.findAllElements("a:fillRef");
if (chkFillRef.isNotEmpty) {
var chkSchemeClr = chkFillRef.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
fillClrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
}
}
}
//var chkIsTextBox=shapeElement.findAllElements("a:t");
//if(chkIsTextBox.isEmpty) {
PresentationPresetShapes presentationPresetShapes = PresentationPresetShapes(presetShapeType, adjVal, fillClrScheme);
presentationPresetShapes.top = offsetY;
presentationPresetShapes.left = offsetX;
presentationPresetShapes.width = width;
presentationPresetShapes.height = height;
var chkPh = shapeElement.findAllElements("p:ph");
if (chkPh.isNotEmpty) {
//print(chkPh);
var type = chkPh.first.getAttribute("type");
if (type != null) {
presentationPresetShapes.phType = type;
}
var idx = chkPh.first.getAttribute("idx");
if (idx != null) {
presentationPresetShapes.idx = idx;
}
}
if (lumOff.isNotEmpty) {
presentationPresetShapes.lumOff = lumOff;
}
if (lumMod.isNotEmpty) {
presentationPresetShapes.lumMod = lumMod;
}
slideLayout.components.add(presentationPresetShapes);
//}
}
var checkCustomDiagram = shapeElement.findAllElements("a:custGeom");
if (checkCustomDiagram.isNotEmpty) {
var pathListElement = checkCustomDiagram.first.findAllElements("a:pathLst");
if (pathListElement.isNotEmpty) {
double offsetX = 0;
double offsetY = 0;
int width = 0;
int height = 0;
String clrScheme = "";
String lumMod = "";
String lumOff = "";
String srgbClr = "";
int rotate = 0;
int flipH = 0;
int flipV = 0;
Map<String, double> offsetValue = {"offsetX": offsetX, "offsetY": offsetY};
Map<String, int> rotFlip = {"rot": rotate, "flipH": flipH, "flipV": flipV};
Map<String, int> widthHeight = {"width": width, "height": height};
Map<String, String> colorDetails = {"clrScheme": clrScheme, "lumMod": lumMod, "lumOff": lumOff, "srgbClr": srgbClr};
getGroupDetails(shapeElement, offsetValue, rotFlip, widthHeight, colorDetails);
offsetX = offsetValue["offsetX"]!;
offsetY = offsetValue["offsetY"]!;
rotate = rotFlip["rot"]!;
flipH = rotFlip["flipH"]!;
flipV = rotFlip["flipV"]!;
width = widthHeight["width"]!;
height = widthHeight["height"]!;
clrScheme = colorDetails["clrScheme"]!;
lumMod = colorDetails["lumMod"]!;
lumOff = colorDetails["lumOff"]!;
srgbClr = colorDetails["srgbClr"]!;
var xfrmElement = shapeElement.findAllElements("a:xfrm");
if (xfrmElement.isNotEmpty) {
var chkOff = xfrmElement.first.findAllElements("a:off");
if (chkOff.isNotEmpty) {
var offX = chkOff.first.getAttribute("x");
var offY = chkOff.first.getAttribute("y");
if (offX != null && offY != null) {
offsetX = double.parse(offX) + offsetX;
offsetY = double.parse(offY) + offsetY;
}
}
var chkExt = xfrmElement.first.findAllElements("a:ext");
if (chkExt.isNotEmpty) {
var tempWidth = chkExt.first.getAttribute("cx");
var tempHeight = chkExt.first.getAttribute("cy");
if (tempWidth != null && tempHeight != null) {
width = int.parse(tempWidth);
height = int.parse(tempHeight);
}
}
var chkRotate = xfrmElement.first.getAttribute("rot");
if (chkRotate != null) {
rotate = rotate + (int.parse(chkRotate) ~/ 60000);
}
var chkFlipH = xfrmElement.first.getAttribute("flipH");
if (chkFlipH != null) {
if (chkFlipH == "1") {
flipH = 1;
}
}
var chkFlipV = xfrmElement.first.getAttribute("flipV");
if (chkFlipV != null) {
if (chkFlipV == "1") {
flipV = 1;
}
}
}
var chkSpPr = shapeElement.findAllElements("p:spPr");
if (chkSpPr.isNotEmpty) {
var chkSolidFill = chkSpPr.first.findAllElements("a:solidFill");
if (chkSolidFill.isNotEmpty) {
var chkSchemeClr = chkSolidFill.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempVal = chkSchemeClr.first.getAttribute("val");
if (tempVal != null) {
clrScheme = tempVal;
}
var chkLumMod = chkSchemeClr.first.findAllElements("a:lumMod");
if (chkLumMod.isNotEmpty) {
var tempLumMod = chkLumMod.first.getAttribute("val");
if (tempLumMod != null) {
lumMod = tempLumMod;
}
}
var chkLumOff = chkSchemeClr.first.findAllElements("a:lumOff");
if (chkLumOff.isNotEmpty) {
var tempLumOff = chkLumOff.first.getAttribute("val");
if (tempLumOff != null) {
lumOff = tempLumOff;
}
}
}
var chkRGBClr = chkSolidFill.first.findAllElements("a:srgbClr");
if (chkRGBClr.isNotEmpty) {
var tempVal = chkRGBClr.first.getAttribute("val");
if (tempVal != null) {
srgbClr = tempVal;
}
}
}
}
var pathElement = pathListElement.first.findAllElements("a:path");
var pathChildElements = pathElement.first.childElements;
PresentationCustomDiagram presentationCustomDiagram = PresentationCustomDiagram(offsetX, offsetY, width, height);
presentationCustomDiagram.clrScheme = clrScheme;
presentationCustomDiagram.srgbClr = srgbClr;
if (rotate != 0) {
presentationCustomDiagram.rotate = rotate;
}
if (flipH == 1) {
presentationCustomDiagram.flipH = "1";
}
if (flipV == 1) {
presentationCustomDiagram.flipV = "1";
}
if (lumOff.isNotEmpty) {
presentationCustomDiagram.lumOff = lumOff;
}
if (lumMod.isNotEmpty) {
presentationCustomDiagram.lumMod = lumMod;
}
pathChildElements.forEach((path) {
List<Points> points = [];
var pt = path.findAllElements("a:pt");
if (pt.isNotEmpty) {
pt.forEach((pts) {
points.add(Points(double.parse(pts.getAttribute("x") ?? "0"), double.parse(pts.getAttribute("y") ?? "0")));
});
}
if (points.isNotEmpty) {
PathAction pathAction = PathAction(points, path.localName);
presentationCustomDiagram.pathList.add(pathAction);
}
});
if (presentationCustomDiagram.pathList.isNotEmpty) {
slideLayout.components.add(presentationCustomDiagram);
}
}
}
});
presentation.slides[i].slideLayout = slideLayout;
}
}
//print("slideMaster");
//print(slideMaster.split("/").last+".rels");
var slideMasterRelFile = archive.singleWhereOrNull((archiveFile) {
//print(archiveFile.name);
return archiveFile.name.endsWith(slideMaster.split("/").last + ".rels");
});
//print("slideMasterRelFile");
//print(slideMasterRelFile);
if (slideMasterRelFile != null) {
final fileContent4 = utf8.decode(slideMasterRelFile.content);
final document4 = xml.XmlDocument.parse(fileContent4);
final relationshipsElement3 = document4.findAllElements("Relationship");
String themeFile = "";
for (var rel in relationshipsElement3) {
if (rel.getAttribute("Type") != null) {
if (rel.getAttribute("Type")!.endsWith("relationships/theme")) {
if (rel.getAttribute("Target") != null) {
themeFile = rel.getAttribute("Target")!.replaceAll("../", "");
}
}
}
}
// print("themeFile");
//print(themeFile);
if (themeFile.isNotEmpty) {
var selectedThemeFile = archive.singleWhereOrNull((archiveFile) {
return archiveFile.name.endsWith(themeFile);
});
if (selectedThemeFile != null) {
final fileContent5 = utf8.decode(selectedThemeFile.content);
final document5 = xml.XmlDocument.parse(fileContent5);
var chkColorScheme = document5.findAllElements("a:clrScheme");
if (chkColorScheme.isNotEmpty) {
for (var clrSch in chkColorScheme.first.childElements) {
String name = "", sysClrName = "", sysClrLast = "", srgbClr = "";
name = clrSch.name.local;
var chkSysClr = clrSch.findAllElements("a:sysClr");
if (chkSysClr.isNotEmpty) {
var tempClrName = chkSysClr.first.getAttribute("val");
if (tempClrName != null) {
sysClrName = tempClrName;
}
var tempClrLast = chkSysClr.first.getAttribute("lastClr");
if (tempClrLast != null) {
sysClrLast = tempClrLast;
}
}
var chksrgbClr = clrSch.findAllElements("a:srgbClr");
if (chksrgbClr.isNotEmpty) {
var tempSrgbClr = chksrgbClr.first.getAttribute("val");
if (tempSrgbClr != null) {
srgbClr = tempSrgbClr;
}
}
presentation.slides[i].colorSchemes.add(
PresentationColorSchemes(presentation.slides[i].colorSchemes.length.toString(), name, sysClrName, sysClrLast, srgbClr));
}
}
}
}
}
var slideMasterFile = archive.singleWhereOrNull((archiveFile) {
//print(archiveFile.name);
return archiveFile.name.endsWith(slideMaster.split("/").last);
});
if (slideMasterFile != null) {
final fileContent6 = utf8.decode(slideMasterFile.content);
final document6 = xml.XmlDocument.parse(fileContent6);
var chkClearMap = document6.findAllElements("p:clrMap");
if (chkClearMap.isNotEmpty) {
//print(chkClearMap);
chkClearMap.first.attributes.forEach((attribute) {
//print(attribute);
presentation.slides[i].clearMap[attribute.name.toString()] = attribute.value;
//print(presentation.slides[i].clearMap);
});
}
}
}
}
}
}
}
}