getAllShapes method

void getAllShapes(
  1. ArchiveFile presentationFile,
  2. Slide slide
)

Function for processing all shapes

Implementation

void getAllShapes(ArchiveFile presentationFile, Slide slide) {
  final fileContent = utf8.decode(presentationFile.content);
  final diagramDoc = xml.XmlDocument.parse(fileContent);
  var diagramsRoot = diagramDoc.findAllElements("dsp:sp");
  if (diagramsRoot.isNotEmpty) {
    for (var diagram in diagramsRoot) {
      String id = "";
      String text = "";
      double offsety = 0;
      Offset offset = const Offset(0, 0);
      Size size = const Size(0, 0);
      var tempId = diagram.getAttribute("modelId");
      if (tempId != null) {
        id = tempId;
      }
      var checkTxtBody = diagram.findAllElements("dsp:txBody");
      if (checkTxtBody.isNotEmpty) {
        var checkParaElement = checkTxtBody.first.findAllElements("a:p");
        if (checkParaElement.isNotEmpty) {
          var txtElement = checkParaElement.first.findAllElements("a:t");
          if (txtElement.isNotEmpty) {
            text = txtElement.first.innerText;
          }
        }
      }
      var checkSlFrm = diagram.findAllElements("a:xfrm");
      if (checkSlFrm.isNotEmpty) {
        var checkOffE = checkSlFrm.first.findAllElements("a:off");
        if (checkOffE.isNotEmpty) {
          var tempX = checkOffE.first.getAttribute("x");
          if (tempX != null) {}
          var tempY = checkOffE.first.getAttribute("y");
          if (tempY != null) {
            offsety = double.parse(tempY);
          }
        }
      }

      var checkTxFrm = diagram.findAllElements("dsp:txXfrm");
      if (checkTxFrm.isNotEmpty) {
        var checkOffE = checkTxFrm.first.findAllElements("a:off");
        if (checkOffE.isNotEmpty) {
          double x = 0;
          double y = 0;
          var tempX = checkOffE.first.getAttribute("x");
          if (tempX != null) {
            x = double.parse(tempX);
          }
          var tempY = checkOffE.first.getAttribute("y");
          if (tempY != null) {
            y = double.parse(tempY);
          }
          offset = Offset(x, y + offsety);
        }
        var checkExtE = checkTxFrm.first.findAllElements("a:ext");
        if (checkExtE.isNotEmpty) {
          double x = 0;
          double y = 0;
          var tempX = checkExtE.first.getAttribute("cx");
          if (tempX != null) {
            x = double.parse(tempX);
          }
          var tempY = checkExtE.first.getAttribute("cy");
          if (tempY != null) {
            y = double.parse(tempY);
          }
          size = Size(x, y);
        }
      }
      slide.components.add(PresentationShape(id, text, offset, size));
    }
  }
}