public static void AddMargin(TextBoxInfo textboxesInfo, float? margin = null) { margin = margin ?? Margin; textboxesInfo.Left -= margin.Value; textboxesInfo.Top -= margin.Value; textboxesInfo.Width += 2 * margin.Value; textboxesInfo.Height += 2 * margin.Value; }
private TextBoxInfo GetTextBoxesInfo(IEnumerable<Shape> textShapes) { var result = new TextBoxInfo(); var rightMost = 0f; var bottomMost = 0f; foreach (var partialResult in textShapes.Select(GetTextBoxInfo)) { result.Left = partialResult.Left < result.Left ? partialResult.Left : result.Left; result.Top = partialResult.Top < result.Top ? partialResult.Top : result.Top; rightMost = partialResult.Left + partialResult.Width > rightMost ? partialResult.Left + partialResult.Width : rightMost; bottomMost = partialResult.Top + partialResult.Height > bottomMost ? partialResult.Top + partialResult.Height : bottomMost; } result.Width = rightMost - result.Left; result.Height = bottomMost - result.Top; return result; }
private TextBoxInfo GetTextBoxInfo(Shape textShape) { var result = new TextBoxInfo(); var paragraphs = textShape.TextFrame2.TextRange.Paragraphs; var rightMost = 0f; var bottomMost = 0f; foreach (TextRange2 textRange in paragraphs) { var paragraph = textRange.TrimText(); if (StringUtil.IsNotEmpty(paragraph.Text)) { result.Left = paragraph.BoundLeft < result.Left ? paragraph.BoundLeft : result.Left; result.Top = paragraph.BoundTop < result.Top ? paragraph.BoundTop : result.Top; rightMost = paragraph.BoundLeft + paragraph.BoundWidth > rightMost ? paragraph.BoundLeft + paragraph.BoundWidth : rightMost; bottomMost = paragraph.BoundTop + paragraph.BoundHeight > bottomMost ? paragraph.BoundTop + paragraph.BoundHeight : bottomMost; } } result.Width = rightMost - result.Left; result.Height = bottomMost - result.Top; AddMargin(result, ExtendMargin); return result; }
private void SetupTextBoxesPosition(TextBoxInfo boxesInfo) { switch (_pos) { case Position.TopLeft: case Position.Left: case Position.BottomLeft: _left = Margin; break; case Position.Top: case Position.Centre: case Position.Bottom: _left = _slideWidth/2 - boxesInfo.Width/2; break; case Position.TopRight: case Position.Right: case Position.BottomRight: _left = _slideWidth - boxesInfo.Width - Margin; break; } switch (_pos) { case Position.TopLeft: case Position.Top: case Position.TopRight: _top = Margin; break; case Position.Left: case Position.Centre: case Position.Right: _top = _slideHeight/2 - boxesInfo.Height/2; break; case Position.BottomLeft: case Position.Bottom: case Position.BottomRight: _top = _slideHeight - boxesInfo.Height - Margin; break; } }
private void AdjustShapeLeft(Shape textShape, TextBoxInfo boxesInfo, TextBoxInfo singleBoxInfo) { ShapeUtil.AddTag(textShape, Tag.OriginalShapeLeft, textShape.Left.ToString(CultureInfo.InvariantCulture)); switch (_align) { case Alignment.Left: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - 0f); break; case Alignment.Centre: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - (boxesInfo.Width/2 - singleBoxInfo.Width/2)); break; case Alignment.Right: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - (boxesInfo.Width - singleBoxInfo.Width)); break; } }
private void AdjustShapeTop(Shape textShape, TextBoxInfo singleBoxInfo, float accumulatedHeight) { ShapeUtil.AddTag(textShape, Tag.OriginalShapeTop, textShape.Top.ToString(CultureInfo.InvariantCulture)); textShape.Top = _top + textShape.Top - (singleBoxInfo.Top - accumulatedHeight); }
private void AdjustShapeLeft(Shape textShape, TextBoxInfo boxesInfo, TextBoxInfo singleBoxInfo) { switch (_align) { case Alignment.Left: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - 0f); break; case Alignment.Centre: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - (boxesInfo.Width/2 - singleBoxInfo.Width/2)); break; case Alignment.Right: textShape.Left = _left + textShape.Left - (singleBoxInfo.Left - (boxesInfo.Width - singleBoxInfo.Width)); break; } }
private void AdjustShapeTop(Shape textShape, TextBoxInfo singleBoxInfo, float accumulatedHeight) { textShape.Top = _top + textShape.Top - (singleBoxInfo.Top - accumulatedHeight); }