private bool GetParagraphChildElements(Shape shape, PPTParagraph par, bool hasText, OpenXmlElement obj) { if (obj is Run) { Run run = (Run)obj; hasText = true; PPTRunProperties runProp = new PPTRunProperties(par.defaultRunProperties); runProp.Text = run.Text.Text; runProp.SetRunProperties(run.RunProperties, shape, ref effectShapes); runProp.FontSize = Math.Round(fontScale * runProp.FontSize / Globals.PercentageConstant); par.RunPropList.Add(runProp); } else if (obj is Field) { Field run = (Field)obj; hasText = true; PPTRunProperties runProp = new PPTRunProperties(par.defaultRunProperties); runProp.Text = run.Text.Text; runProp.SetRunProperties(run.RunProperties, shape, ref effectShapes); runProp.FontSize = Math.Round(fontScale * runProp.FontSize / Globals.PercentageConstant); par.RunPropList.Add(runProp); } else if (obj is Break) { Break aBreak = (Break)obj; PPTRunProperties runProp = new PPTRunProperties(par.defaultRunProperties); runProp.SetRunProperties(aBreak.RunProperties, shape, ref effectShapes); runProp.FontSize = Math.Round(fontScale * runProp.FontSize / Globals.PercentageConstant); runProp.isBreak = true; par.RunPropList.Add(runProp); } return(hasText); }
private IEnumerable <PPTRunProperties> breakTextsToShape(PPTParagraph par) { List <Dom.PPTTexts.PPTRunProperties> list = par.RunPropList; List <PPTRunProperties> result = new List <PPTRunProperties>(); String previousToken = null; int bulletSize = 0; foreach (var text in list) { float points = float.Parse(text.FontSize.ToString()) * 72.0F / 96.0F; Font font = new System.Drawing.Font(text.FontFamily.ToString(), points); if (text.Bold) { font = new System.Drawing.Font(text.FontFamily.ToString(), points, FontStyle.Bold); } else if (text.Italic) { font = new System.Drawing.Font(text.FontFamily.ToString(), points, FontStyle.Italic); } else if (text.Underline != null && text.Underline.Equals("Single")) { font = new System.Drawing.Font(text.FontFamily.ToString(), points, FontStyle.Underline); } int size = 0; if (text.isBullet && text.Text != null && text.Text.Contains("rId")) { bulletSize = text.bulletSize; } else { size = MeasureString((previousToken == null ? "" : previousToken + " ") + text.Text, font); } if (text.isBreak || size + bulletSize < this.width - par.Indent - par.marginLeft - par.marginRight - Shape.LeftInset - Shape.RightInset) { if (text.Text != null && text.Text.Trim() != "" && !(text.isBullet && text.Text.Contains("rId"))) { previousToken = (previousToken == null ? "" : previousToken) + text.Text; } if (text.isBreak) { previousToken = null; } result.Add(text); continue; } // previousToken = null; string[] tokens = text.Text.Split(' '); int index = 0; foreach (string token in tokens) { index++; int combinedSize = MeasureString((previousToken == null ? "" : previousToken + " ") + token, font); if (combinedSize + bulletSize > this.width - par.Indent - par.marginLeft - par.marginRight - Shape.LeftInset - Shape.RightInset) { PPTRunProperties temp = new PPTRunProperties(text); temp.Text = ""; temp.isBreak = true; result.Add(temp); temp = new PPTRunProperties(text); temp.Text = index < tokens.Length? token + " ":token; result.Add(temp); previousToken = token; } else { PPTRunProperties temp = new PPTRunProperties(text); temp.Text = index < tokens.Length ? token + " " : token; result.Add(temp); previousToken = (previousToken == null ? "" : previousToken + " ") + token; } } } return(result); }