processStylesFile method

Future<void> processStylesFile(
  1. ArchiveFile stylesFile,
  2. List<Styles> stylesList,
  3. Map<String, String> defaultValues
)

Function for processing styles file

Implementation

Future<void> processStylesFile(ArchiveFile stylesFile, List<Styles> stylesList, Map<String, String> defaultValues) async {
  stylesList.clear();
  final fileContent = utf8.decode(stylesFile.content);
  final stylesDoc = xml.XmlDocument.parse(fileContent);
  var stylesRoot = stylesDoc.findAllElements("w:styles");
  if (stylesRoot.isNotEmpty) {
    var allStyles = stylesRoot.first.findAllElements("w:style");
    if (allStyles.isNotEmpty) {
      for (var style in allStyles) {
        Styles tempStyles = await compute(getStyles, GetStylesParam(style));
        stylesList.add(tempStyles);
      }
    }
  }
  var rDefault = stylesDoc.findAllElements("w:rPrDefault");
  if (rDefault.isNotEmpty) {
    var fSize = rDefault.first.findAllElements("w:sz");
    if (fSize.isNotEmpty) {
      var tempSize = fSize.first.getAttribute("w:val");
      if (tempSize != null) {
        defaultValues["fontSize"] = tempSize;
      }
    }
  }
  var pDefault = stylesDoc.findAllElements("w:pPrDefault");
  if (pDefault.isNotEmpty) {
    var spacing = pDefault.first.findAllElements("w:spacing");
    if (spacing.isNotEmpty) {
      var tempSpacing = spacing.first.getAttribute("w:line");
      if (tempSpacing != null) {
        defaultValues["lineSpacing"] = tempSpacing;
      }
    }
  }
}