Skip to content

Commit

Permalink
Added API 24.01 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Dec 26, 2023
1 parent 3dc89b4 commit 9eaa07e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Threading.Tasks;
using System.Threading;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.Words.Bibliography;
#if NET5_0_OR_GREATER
using SkiaSharp;
#endif
Expand Down Expand Up @@ -7607,6 +7608,42 @@ void IFieldUpdatingProgressCallback.Notify(FieldUpdatingProgressArgs args)
public IList<string> FieldUpdatedCalls { get; }
}
//ExEnd

[Test]
public void BibliographySources()
{
//ExStart:BibliographySources
//ReleaseVersion:24.01
//ExFor:Bibliography
//ExFor:Bibliography.Sources
//ExFor:Source.Title
//ExFor:Source.Contributors
//ExFor:ContributorCollection
//ExFor:ContributorCollection.Author
//ExFor:PersonCollection
//ExFor:Person
//ExFor:Person.First
//ExFor:Person.Middle
//ExFor:Person.Last
//ExSummary:Shows how to get bibliography sources available in the document.
Document document = new Document(MyDir + "Bibliography sources.docx");

Bibliography bibliography = document.Bibliography;
Assert.AreEqual(12, bibliography.Sources.Count);

Source source = bibliography.Sources.FirstOrDefault();
Assert.AreEqual("Book 0 (No LCID)", source.Title);

ContributorCollection contributors = source.Contributors;
PersonCollection authors = (PersonCollection)contributors.Author;
Assert.AreEqual(2, authors.Count());

Person person = authors.FirstOrDefault();
Assert.AreEqual("Roxanne", person.First);
Assert.AreEqual("Brielle", person.Middle);
Assert.AreEqual("Tejeda", person.Last);
//ExEnd:BibliographySources
}
}
}

18 changes: 18 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,23 @@ public void ImagesFolder()
Document doc = new Document(ArtifactsDir + "MarkdownSaveOptions.ImagesFolder.md");
doc.GetText().Contains("http://example.com/images/MarkdownSaveOptions.ImagesFolder.001.jpeg");
}

[Test]
public void ExportUnderlineFormatting()
{
//ExStart:ExportUnderlineFormatting
//ReleaseVersion:24.01
//ExFor:MarkdownSaveOptions.ExportUnderlineFormatting
//ExSummary:Shows how to export underline formatting as ++.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Underline = Underline.Single;
builder.Write("Lorem ipsum. Dolor sit amet.");

MarkdownSaveOptions saveOptions = new MarkdownSaveOptions() { ExportUnderlineFormatting = true };
doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportUnderlineFormatting.md", saveOptions);
//ExEnd:ExportUnderlineFormatting
}
}
}
22 changes: 22 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExReportingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,28 @@ public void DollarTextFormat()
Assert.AreEqual("one thousand two hundred thirty-four and 00/100\rfive million six hundred twenty-one thousand seven hundred eighteen and 59/100\r\f", doc.GetText());
}

[Test]
public void RestrictedTypes()
{
//ExStart:RestrictedTypes
//ReleaseVersion:24.01
//ExFor:ReportingEngine.SetRestrictedTypes(Type[])
//ExSummary:Shows how to deny access to members of types considered insecure.
Document doc =
DocumentHelper.CreateSimpleDocument(
"<<var [typeVar = \"\".GetType().BaseType]>><<[typeVar]>>");

// We set "AllowMissingMembers" option to avoid exceptions during building a report.
ReportingEngine engine = new ReportingEngine() { Options = ReportBuildOptions.AllowMissingMembers };
// Note, that you can't set restricted types during or after building a report.
ReportingEngine.SetRestrictedTypes(typeof(System.Type));
engine.BuildReport(doc, new object());

// We get an empty string because we can't access the GetType() method.
Assert.AreEqual(string.Empty, doc.GetText().Trim());
//ExEnd:RestrictedTypes
}

private static void BuildReport(Document document, object dataSource, ReportBuildOptions reportBuildOptions)
{
ReportingEngine engine = new ReportingEngine { Options = reportBuildOptions };
Expand Down
73 changes: 73 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment;
using TextBox = Aspose.Words.Drawing.TextBox;
using Aspose.Words.Themes;
using Aspose.Words.Forms2;

namespace ApiExamples
{
Expand Down Expand Up @@ -3033,5 +3034,77 @@ public void FitImageToShape()
doc.Save(ArtifactsDir + "Shape.FitImageToShape.docx");
//ExEnd:FitImageToShape
}

[Test]
public void StrokeForeThemeColors()
{
//ExStart:StrokeForeThemeColors
//ReleaseVersion:24.01
//ExFor:Stroke.ForeThemeColor
//ExFor:Stroke.ForeTintAndShade
//ExSummary:Shows how to set fore theme color and tint and shade.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertShape(ShapeType.TextBox, 100, 40);
Stroke stroke = shape.Stroke;
stroke.ForeThemeColor = ThemeColor.Dark1;
stroke.ForeTintAndShade = 0.5;

doc.Save(ArtifactsDir + "Shape.StrokeForeThemeColors.docx");
//ExEnd:StrokeForeThemeColors

doc = new Document(ArtifactsDir + "Shape.StrokeForeThemeColors.docx");
shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

Assert.AreEqual(ThemeColor.Dark1, shape.Stroke.ForeThemeColor);
Assert.AreEqual(0.5, shape.Stroke.ForeTintAndShade);

}

[Test]
public void StrokeBackThemeColors()
{
//ExStart:StrokeBackThemeColors
//ReleaseVersion:24.01
//ExFor:Stroke.BackThemeColor
//ExFor:Stroke.BackTintAndShade
//ExSummary:Shows how to set back theme color and tint and shade.
Document doc = new Document(MyDir + "Stroke gradient outline.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Stroke stroke = shape.Stroke;
stroke.BackThemeColor = ThemeColor.Dark2;
stroke.BackTintAndShade = 0.2d;

doc.Save(ArtifactsDir + "Shape.StrokeBackThemeColors.docx");
//ExEnd:StrokeBackThemeColors

doc = new Document(ArtifactsDir + "Shape.StrokeBackThemeColors.docx");
shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

Assert.AreEqual(ThemeColor.Dark2, shape.Stroke.BackThemeColor);
double precision = 1e-6;
Assert.AreEqual(0.2d, shape.Stroke.BackTintAndShade, precision);
}

[Test]
public void TextBoxOleControl()
{
//ExStart:TextBoxOleControl
//ReleaseVersion:24.01
//ExFor:TextBoxControl
//ExFor:TextBoxControl.Text
//ExSummary:Shows how to change text of the TextBox OLE control.
Document doc = new Document(MyDir + "Textbox control.docm");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
TextBoxControl textBoxControl = (TextBoxControl)shape.OleFormat.OleControl;
Assert.AreEqual("Aspose.Words test", textBoxControl.Text);

textBoxControl.Text = "Updated text";
Assert.AreEqual("Updated text", textBoxControl.Text);
//ExEnd:TextBoxOleControl
}
}
}
Binary file added Examples/Data/Bibliography sources.docx
Binary file not shown.
Binary file added Examples/Data/Stroke gradient outline.docx
Binary file not shown.
Binary file added Examples/Data/Textbox control.docm
Binary file not shown.

0 comments on commit 9eaa07e

Please sign in to comment.