Skip to content

Commit

Permalink
Merge branch 'master' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahabov committed Sep 3, 2022
2 parents 24b4123 + df408b6 commit d9d6fd0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
17 changes: 16 additions & 1 deletion ShapeCrawler.Tests/ParagraphPortionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using ShapeCrawler.Collections;
Expand Down Expand Up @@ -50,6 +49,22 @@ public void Text_SetterThrowsElementIsRemovedException_WhenPortionIsRemoved()
// Act-Assert
portion.Invoking(p => p.Text = "new text").Should().Throw<ElementIsRemovedException>();
}

[Fact]
public void Text_Setter_updates_text()
{
// Arrange
var pptxStream = GetTestFileStream("autoshape-case001.pptx");
var pres = SCPresentation.Open(pptxStream, true);
var autoShape = pres.SlideMasters[0].Shapes.GetByName<IAutoShape>("AutoShape 1");
var portion = autoShape.TextBox.Paragraphs[0].Portions[0];

// Act
portion.Text = "test";

// Assert
portion.Text.Should().Be("test");
}

[Theory]
[MemberData(nameof(TestCasesHyperlinkSetter))]
Expand Down
Binary file modified ShapeCrawler.Tests/Resource/autoshape/autoshape-case001.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion ShapeCrawler/AutoShapes/SCFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private int GetSize()
slideMaster = ((SCTableCell) textBoxContainer).SlideMasterInternal;
}

if (slideMaster.ParentPresentation.ParaLvlToFontData.TryGetValue(paragraphLvl, out FontData fontData))
if (slideMaster.Presentation.ParaLvlToFontData.TryGetValue(paragraphLvl, out FontData fontData))
{
if (fontData.FontSize != null)
{
Expand Down
2 changes: 1 addition & 1 deletion ShapeCrawler/Drawing/ColorFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void InitColor()

// Presentation level
string colorHexVariant;
if (this.parentSlideMaster.ParentPresentation.ParaLvlToFontData.TryGetValue(paragraphLevel, out FontData preFontData))
if (this.parentSlideMaster.Presentation.ParaLvlToFontData.TryGetValue(paragraphLevel, out FontData preFontData))
{
colorHexVariant = this.GetHexVariantByScheme(preFontData.ASchemeColor.Val);
this.colorType = SCColorType.Scheme;
Expand Down
2 changes: 1 addition & 1 deletion ShapeCrawler/Drawing/MasterPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal MasterPicture(P.Picture pPicture, SCSlideMaster slideMaster, StringValu
: base(pPicture, slideMaster)
{
this.picReference = picReference;
this.PresentationInternal = slideMaster.ParentPresentation;
this.PresentationInternal = slideMaster.Presentation;
}

public SCImage Image => this.GetImage();
Expand Down
2 changes: 1 addition & 1 deletion ShapeCrawler/PowerPoint/LayoutShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected LayoutShape(SCSlideLayout slideLayout, OpenXmlCompositeElement pShapeT

public override IPlaceholder Placeholder => LayoutPlaceholder.Create(this.PShapeTreesChild, this);

public override SCPresentation PresentationInternal => ((SCSlideMaster)this.SlideLayoutInternal.SlideMaster).ParentPresentation;
public override SCPresentation PresentationInternal => ((SCSlideMaster)this.SlideLayoutInternal.SlideMaster).Presentation;

public SCSlideLayout SlideLayoutInternal { get; }
}
Expand Down
25 changes: 16 additions & 9 deletions ShapeCrawler/SlideMasters/SCSlideMaster.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using ShapeCrawler.Collections;
using ShapeCrawler.Exceptions;
using ShapeCrawler.Factories;
using ShapeCrawler.Placeholders;
using ShapeCrawler.Shared;
using P = DocumentFormat.OpenXml.Presentation;

namespace ShapeCrawler.SlideMasters
{
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "SC — ShapeCrawler")]
internal class SCSlideMaster : SlideBase, ISlideMaster
{
private readonly ResettableLazy<List<SCSlideLayout>> slideLayouts;
internal readonly DocumentFormat.OpenXml.Presentation.SlideMaster PSlideMaster;

internal SCSlideMaster(SCPresentation parentPresentation, DocumentFormat.OpenXml.Presentation.SlideMaster pSlideMaster)
internal SCSlideMaster(SCPresentation presentation, P.SlideMaster pSlideMaster)
{
this.ParentPresentation = parentPresentation;
this.Presentation = presentation;
this.PSlideMaster = pSlideMaster;
this.slideLayouts = new ResettableLazy<List<SCSlideLayout>>(this.GetSlideLayouts);
}

internal P.SlideMaster PSlideMaster { get; }

internal SCPresentation ParentPresentation { get; }
internal SCPresentation Presentation { get; }

internal Dictionary<int, FontData> BodyParaLvlToFontData =>
FontDataParser.FromCompositeElement(this.PSlideMaster.TextStyles.BodyStyle);
FontDataParser.FromCompositeElement(this.PSlideMaster.TextStyles!.BodyStyle!);

internal Dictionary<int, FontData> TitleParaLvlToFontData =>
FontDataParser.FromCompositeElement(this.PSlideMaster.TextStyles.TitleStyle);
FontDataParser.FromCompositeElement(this.PSlideMaster.TextStyles!.TitleStyle!);

internal ThemePart ThemePart => this.PSlideMaster.SlideMasterPart.ThemePart;

Expand Down Expand Up @@ -99,7 +101,12 @@ private SCImage GetBackground()

public override void ThrowIfRemoved()
{
throw new NotImplementedException();
if (IsRemoved)
{
throw new ElementIsRemovedException("Slide MAster is removed");
}

this.Presentation.ThrowIfClosed();
}
}
}

0 comments on commit d9d6fd0

Please sign in to comment.