getPresentationTextBox static method
Implementation
static PresentationTextBox? getPresentationTextBox(GetPresentationTextBoxParam params) {
Offset offset = const Offset(0, 0);
Size size = const Size(0, 0);
double offsetY = 0;
double offsetX = 0;
if (params.spElement.parentElement != null && params.spElement.parentElement?.name.toString() == "p:grpSp") {
var grpSpPr = params.spElement.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 = params.spElement.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) {
offset = Offset(double.parse(offX) + offsetX, 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) {
size = Size(double.parse(extX), double.parse(extY));
}
}
}
List<PresentationParagraph> presentationParagraphs = [];
params.spElement.findAllElements("p:txBody").forEach((txt) {
var chkPara = txt.findAllElements("a:p");
List<PresentationText> presentationTexts = [];
if (chkPara.isNotEmpty) {
for (var para in chkPara) {
var chkParaProp = para.findAllElements("a:pPr");
String align = "";
if (chkParaProp.isNotEmpty) {
var chkAlg = chkParaProp.first.getAttribute("algn");
if (chkAlg != null) {
align = chkAlg;
}
}
presentationTexts = [];
var chkR = para.findAllElements("a:r");
if (chkR.isNotEmpty) {
for (var r in chkR) {
double fontSize = 20;
String colorScheme = "";
bool isBold = false;
String lumMod = "";
String lumOff = "";
var rPr = r.findAllElements("a:rPr");
if (rPr.isNotEmpty) {
var tempSize = rPr.first.getAttribute("sz");
if (tempSize != null) {
fontSize = double.parse(tempSize) / 180;
}
var tempBold = rPr.first.getAttribute("b");
if (tempBold != null) {
if (tempBold == "1") {
isBold = true;
}
}
var chkSchemeClr = rPr.first.findAllElements("a:schemeClr");
if (chkSchemeClr.isNotEmpty) {
var tempClrScheme = chkSchemeClr.first.getAttribute("val");
if (tempClrScheme != null) {
if (params.clrMap[tempClrScheme] != null) {
colorScheme = params.clrMap[tempClrScheme]!;
} else {
colorScheme = tempClrScheme;
}
}
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 text = "";
r.findAllElements("a:t").forEach((txt2) {
text += txt2.innerText;
});
if (text.isNotEmpty) {
PresentationText presentationText = PresentationText(text, fontSize);
if (colorScheme.isNotEmpty) {
presentationText.colorScheme = colorScheme;
}
if (isBold) {
presentationText.isBold = true;
}
if (lumOff.isNotEmpty) {
presentationText.lumOff = lumOff;
}
if (lumMod.isNotEmpty) {
presentationText.lumMod = lumMod;
}
presentationTexts.add(presentationText);
}
}
}
if (presentationTexts.isNotEmpty || params.spElement.findAllElements("p:ph").isNotEmpty) {
PresentationParagraph paragraph = PresentationParagraph();
paragraph.textSpans = presentationTexts;
if (align.isNotEmpty) {
paragraph.align = align;
}
var chkPh = params.spElement.findAllElements("p:ph");
if (chkPh.isNotEmpty) {
//print(chkPh);
var type = chkPh.first.getAttribute("type");
if (type != null) {
paragraph.type = type;
}
var idx = chkPh.first.getAttribute("idx");
if (idx != null) {
paragraph.idx = idx;
}
}
presentationParagraphs.add(paragraph);
}
}
}
});
if (presentationParagraphs.isNotEmpty) {
PresentationTextBox presentationTextBox = PresentationTextBox(offset, size);
presentationTextBox.presentationParas = presentationParagraphs;
return presentationTextBox;
} else {
return null;
}
}