public bool sameProps(HtmlText other) { if (other == null) { return(false); } return(this.top == other.top && this.fontSize == other.fontSize && this.fontColor == other.fontColor && this.italic == other.italic && this.bold == other.bold && this.underline == other.underline && this.fontFamily == other.fontFamily); }
private void DrawText(StringBuilder shapeBuilder) { int top = getTopForCurrentAnchoring(this.Shape.VerticalAlign, this.Shape.Texts); foreach (var par in Shape.Texts) { //If top add spacing before - otherwise not (I think) int paragraphTop = this.top + (this.Shape.VerticalAlign.Equals(DocumentFormat.OpenXml.Drawing.TextAnchoringTypeValues.Top) ? par.getSpaceBeforePoints() : 0); string htmlStyle = par.Invisible ? "DC0" : "DC1"; if (par.Animatable) { shapeBuilder.Append("<div id=\"" + id + "p" + par.Paragraph + "\" style=\"top:" + paragraphTop + "px;left:" + this.left.ToString() + "px;height:" + height.ToString() + "px;width:" + width.ToString() + "px;\">"); shapeBuilder.Append("<div class=\"" + htmlStyle + "\" id=\"" + id + "p" + par.Paragraph + "c" + "\">"); } else { shapeBuilder.Append("<div id=\"" + id + "p" + par.Paragraph + "\" style=\"top:" + (this.top).ToString() + "px;left:" + this.left.ToString() + "px;height:" + height.ToString() + "px;width:" + width.ToString() + "px;\">"); } int newTop = par.getSpaceBeforePoints(); int left = 0; List <HtmlText> textElements = new List <HtmlText>(); if (par.RunPropList == null || par.RunPropList.Count == 0 && par.defaultRunProperties != null) //Only paragraph! { float points = float.Parse(par.defaultRunProperties.FontSize.ToString()) * 72.0F / 96.0F; Font font = new System.Drawing.Font(par.defaultRunProperties.FontFamily.ToString(), points); newTop = font.Height; } List <HtmlText> processedElements = new List <HtmlText>(); foreach (var text in breakTextsToShape(par)) { 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); } newTop = font.Height > newTop ? font.Height : newTop; newTop = par.getLineSpacingInPointsFromFont(newTop); if (text.isBreak) { top += newTop; left = 0; fixLeftSpacingForAlignment(processedElements, par, font); processedElements.Clear(); continue; } String currentString = text.Text.TrimEnd() + getStringFromTextElements(processedElements); //Text must already be broken to lines //Size size = MeasureString(currentString, font); // if (size.Width > this.width - par.Indent - par.marginLeft - par.marginRight) // { // top += newTop; // left = 0; // fixLeftSpacingForAlignment(processedElements, par, font); // processedElements.Clear(); // } HtmlText t1 = new HtmlText(left: left, top: top, fontFamily: text.FontFamily, fontColor: text.FontColor, fontSize: text.FontSize, isBullet: text.isBullet, bold: text.Bold, italic: text.Italic, underline: text.Underline, id: id, slideIndex: slideIndex) { Rotate = Rotate }; t1.width = MeasureString(text.Text, font); if (text.isBullet && text.Text != null && text.Text.Contains("rId")) { t1.PictureBullet = true; t1.width = text.bulletSize; t1.bulletSize = text.bulletSize; newTop = text.bulletSize; } t1.Text = text.Text; textElements.Add(t1); processedElements.Add(t1); } fixLeftSpacingForAlignment(processedElements, par); HtmlText lastTxt = null; List <HtmlText> mergedTextElements = new List <HtmlText>(); foreach (HtmlText textElement in textElements) { if (lastTxt == null || !lastTxt.sameProps(textElement)) { mergedTextElements.Add(textElement); } else { mergedTextElements[mergedTextElements.Count - 1].Text += textElement.Text; } lastTxt = textElement; } foreach (HtmlText textElement in mergedTextElements) { shapeBuilder.Append(textElement.DrawElement()); } top += newTop; top += par.getSpaceAfterPoints(newTop); top += par.getSpaceBeforePoints(newTop); shapeBuilder.Append("</div>"); if (par.Animatable) { shapeBuilder.Append("</div>"); } } }