Skip to content

Commit

Permalink
Added new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Mar 29, 2024
1 parent 2f86e19 commit 57fb98e
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ApiExamples.csproj
Expand Up @@ -128,7 +128,7 @@
<PackageReference Include="Aspose.BarCode" Version="24.2.0" />
<PackageReference Include="Aspose.Page" Version="24.2.0" />
<PackageReference Include="Aspose.PDF" Version="24.2.0" />
<PackageReference Include="Aspose.Words" Version="24.3.0" />
<PackageReference Include="Aspose.Words" Version="24.4.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.3.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
Expand Down
55 changes: 55 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Expand Up @@ -1712,5 +1712,60 @@ public void DataTable()
doc.Save(ArtifactsDir + "Charts.DataTable.docx");
//ExEnd:DataTable
}

[Test]
public void ChartFormat()
{
//ExStart:ChartFormat
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:Chart.Format
//ExFor:ChartTitle.Format
//ExFor:ChartAxisTitle.Format
//ExFor:ChartLegend.Format
//ExSummary:Shows how to use chart formating.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;

// Delete series generated by default.
ChartSeriesCollection series = chart.Series;
series.Clear();

string[] categories = new string[] { "Category 1", "Category 2" };
series.Add("Series 1", categories, new double[] { 1, 2 });
series.Add("Series 2", categories, new double[] { 3, 4 });

// Format chart background.
chart.Format.Fill.Solid(Color.DarkSlateGray);

// Hide axis tick labels.
chart.AxisX.TickLabels.Position = AxisTickLabelPosition.None;
chart.AxisY.TickLabels.Position = AxisTickLabelPosition.None;

// Format chart title.
chart.Title.Format.Fill.Solid(Color.LightGoldenrodYellow);

// Format axis title.
chart.AxisX.Title.Show = true;
chart.AxisX.Title.Format.Fill.Solid(Color.LightGoldenrodYellow);

// Format legend.
chart.Legend.Format.Fill.Solid(Color.LightGoldenrodYellow);

doc.Save(ArtifactsDir + "Charts.ChartFormat.docx");
//ExEnd:ChartFormat

doc = new Document(ArtifactsDir + "Charts.ChartFormat.docx");

shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
chart = shape.Chart;

Assert.AreEqual(Color.DarkSlateGray.ToArgb(), chart.Format.Fill.Color.ToArgb());
Assert.AreEqual(Color.LightGoldenrodYellow.ToArgb(), chart.Title.Format.Fill.Color.ToArgb());
Assert.AreEqual(Color.LightGoldenrodYellow.ToArgb(), chart.AxisX.Title.Format.Fill.Color.ToArgb());
Assert.AreEqual(Color.LightGoldenrodYellow.ToArgb(), chart.Legend.Format.Fill.Color.ToArgb());
}
}
}
15 changes: 15 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExHtmlLoadOptions.cs
Expand Up @@ -328,5 +328,20 @@ public void BlockImport(BlockImportMode blockImportMode)
doc.Save(ArtifactsDir + "HtmlLoadOptions.BlockImport.docx");
//ExEnd
}

[Test]
public void FontFaceRules()
{
//ExStart:FontFaceRules
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:HtmlLoadOptions.SupportFontFaceRules
//ExSummary:Shows how to load declared "@font-face" rules.
HtmlLoadOptions loadOptions = new HtmlLoadOptions();
loadOptions.SupportFontFaceRules = true;
Document doc = new Document(MyDir + "Html with FontFace.html", loadOptions);

Assert.AreEqual("Bitstream Vera Serif Bold", doc.FontInfos[0].Name);
//ExEnd:FontFaceRules
}
}
}
6 changes: 2 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExImage.cs
Expand Up @@ -410,14 +410,13 @@ public void ScaleImage()
Assert.AreEqual(300.0d, imageSize.HeightPoints);
}

#if NET5_0_OR_GREATER
[Test]
public void InsertWebpImage()
{
//ExStart:InsertWebpImage
//GistId:e386727403c2341ce4018bca370a5b41
//ExFor:DocumentBuilder.InsertImage(String)
//ExSummary:Shows how to insert WebP image (only .NetStandard)
//ExSummary:Shows how to insert WebP image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Expand All @@ -433,13 +432,12 @@ public void ReadWebpImage()
//ExStart:ReadWebpImage
//GistId:e386727403c2341ce4018bca370a5b41
//ExFor:ImageType
//ExSummary:Shows how to read WebP image (only .NetStandard)
//ExSummary:Shows how to read WebP image.
Document doc = new Document(MyDir + "Document with WebP image.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Assert.AreEqual(ImageType.WebP, shape.ImageData.ImageType);
//ExEnd:ReadWebpImage
}
#endif
}
}
20 changes: 20 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs
Expand Up @@ -10,6 +10,7 @@
using System.Drawing;
using System.IO;
using Aspose.Words;
using Aspose.Words.DigitalSignatures;
using Aspose.Words.Drawing;
using Aspose.Words.Lists;
using Aspose.Words.Loading;
Expand Down Expand Up @@ -402,5 +403,24 @@ public void Zip64ModeOption()
new OoxmlSaveOptions { Zip64Mode = Zip64Mode.Always });
//ExEnd:Zip64ModeOption
}

[Test]
public void DigitalSignature()
{
//ExStart:DigitalSignature
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:OoxmlSaveOptions.DigitalSignatureDetails
//ExSummary:Shows how to sign OOXML document.
Document doc = new Document(MyDir + "Document.docx");

CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.DigitalSignatureDetails = new DigitalSignatureDetails(
certificateHolder,
new SignOptions() { Comments = "Some comments", SignTime = DateTime.Now });

doc.Save(ArtifactsDir + "OoxmlSaveOptions.DigitalSignature.docx", saveOptions);
//ExEnd:DigitalSignature
}
}
}
21 changes: 21 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs
Expand Up @@ -528,5 +528,26 @@ public void ParagraphBaselineAlignment()
format = doc.FirstSection.Body.Paragraphs[0].ParagraphFormat;
Assert.AreEqual(BaselineAlignment.Top, format.BaselineAlignment);
}

[Test]
public void MirrorIndents()
{
//ExStart:MirrorIndents
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:ParagraphFormat.MirrorIndents
//ExSummary:Show how to make left and right indents the same.
Document doc = new Document(MyDir + "Document.docx");
ParagraphFormat format = doc.FirstSection.Body.Paragraphs[0].ParagraphFormat;

format.MirrorIndents = true;

doc.Save(ArtifactsDir + "ParagraphFormat.MirrorIndents.docx");
//ExEnd:MirrorIndents

doc = new Document(ArtifactsDir + "ParagraphFormat.MirrorIndents.docx");
format = doc.FirstSection.Body.Paragraphs[0].ParagraphFormat;

Assert.AreEqual(true, format.MirrorIndents);
}
}
}
74 changes: 74 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExShape.cs
Expand Up @@ -3106,5 +3106,79 @@ public void TextBoxOleControl()
Assert.AreEqual("Updated text", textBoxControl.Text);
//ExEnd:TextBoxOleControl
}

[Test]
public void Glow()
{
//ExStart:Glow
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:ShapeBase.Glow
//ExFor:GlowFormat.Color
//ExFor:GlowFormat.Radius
//ExFor:GlowFormat.Transparency
//ExFor:GlowFormat.Remove()
//ExSummary:Shows how to interact with glow shape effect.
Document doc = new Document(MyDir + "Various shapes.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

shape.Glow.Color = Color.Salmon;
shape.Glow.Radius = 30;
shape.Glow.Transparency = 0.15;

doc.Save(ArtifactsDir + "Shape.Glow.docx");

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

Assert.AreEqual(Color.FromArgb(217, 250, 128, 114).ToArgb(), shape.Glow.Color.ToArgb());
Assert.AreEqual(30, shape.Glow.Radius);
Assert.AreEqual(0.15d, shape.Glow.Transparency, 0.01d);

shape.Glow.Remove();

Assert.AreEqual(Color.Black.ToArgb(), shape.Glow.Color.ToArgb());
Assert.AreEqual(0, shape.Glow.Radius);
Assert.AreEqual(0, shape.Glow.Transparency);
//ExEnd:Glow
}

[Test]
public void Reflection()
{
//ExStart:Reflection
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:ShapeBase.Reflection
//ExFor:ReflectionFormat.Size
//ExFor:ReflectionFormat.Blur
//ExFor:ReflectionFormat.Transparency
//ExFor:ReflectionFormat.Distance
//ExFor:ReflectionFormat.Remove()
//ExSummary:Shows how to interact with reflection shape effect.
Document doc = new Document(MyDir + "Various shapes.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

shape.Reflection.Transparency = 0.37;
shape.Reflection.Size = 0.48;
shape.Reflection.Blur = 17.5;
shape.Reflection.Distance = 9.2;

doc.Save(ArtifactsDir + "Shape.Reflection.docx");

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

Assert.AreEqual(0.37d, shape.Reflection.Transparency, 0.01d);
Assert.AreEqual(0.48d, shape.Reflection.Size, 0.01d);
Assert.AreEqual(17.5d, shape.Reflection.Blur, 0.01d);
Assert.AreEqual(9.2d, shape.Reflection.Distance, 0.01d);

shape.Reflection.Remove();

Assert.AreEqual(0, shape.Reflection.Transparency);
Assert.AreEqual(0, shape.Reflection.Size);
Assert.AreEqual(0, shape.Reflection.Blur);
Assert.AreEqual(0, shape.Reflection.Distance);
//ExEnd:Reflection
}
}
}
24 changes: 24 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExStyles.cs
Expand Up @@ -397,5 +397,29 @@ public void StylePriority()
doc.Save(ArtifactsDir + "Styles.StylePriority.docx");
//ExEnd:StylePriority
}

[Test]
public void LinkedStyleName()
{
//ExStart:LinkedStyleName
//GistId:5f20ac02cb42c6b08481aa1c5b0cd3db
//ExFor:Style.LinkedStyleName
//ExSummary:Shows how to link styles among themselves.
Document doc = new Document();

Style styleHeading1 = doc.Styles[StyleIdentifier.Heading1];

Style styleHeading1Char = doc.Styles.Add(StyleType.Character, "Heading 1 Char");
styleHeading1Char.Font.Name = "Verdana";
styleHeading1Char.Font.Bold = true;
styleHeading1Char.Font.Border.LineStyle = LineStyle.Dot;
styleHeading1Char.Font.Border.LineWidth = 15;

styleHeading1.LinkedStyleName = "Heading 1 Char";

Assert.AreEqual("Heading 1 Char", styleHeading1.LinkedStyleName);
Assert.AreEqual("Heading 1", styleHeading1Char.LinkedStyleName);
//ExEnd:LinkedStyleName
}
}
}
16 changes: 16 additions & 0 deletions Examples/Data/Html with FontFace.html
@@ -0,0 +1,16 @@
<html>
<head>
<title>Web Font Sample</title>
<style type="text/css" media="screen, print">
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("MyFonts/VeraSeBd.ttf");
}

body { font-family: "Bitstream Vera Serif Bold", serif }
</style>
</head>
<body>
This is Bitstream Vera Serif Bold.
</body>
</html>
Binary file added Examples/Data/MyFonts/VeraSeBd.ttf
Binary file not shown.

0 comments on commit 57fb98e

Please sign in to comment.