diff --git a/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs b/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs index 296429d55..baba5cd8a 100644 --- a/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs +++ b/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs @@ -65,4 +65,4 @@ public void Create() //ExEnd } } -} \ No newline at end of file +} diff --git a/Examples/ApiExamples/ApiExamples/ExCharts.cs b/Examples/ApiExamples/ApiExamples/ExCharts.cs index 92b73cfe1..d01c103d0 100644 --- a/Examples/ApiExamples/ApiExamples/ExCharts.cs +++ b/Examples/ApiExamples/ApiExamples/ExCharts.cs @@ -157,9 +157,9 @@ public void AxisProperties() xAxis.MinorTickMark = AxisTickMark.Cross; xAxis.MajorUnit = 10.0d; xAxis.MinorUnit = 15.0d; - xAxis.TickLabelOffset = 50; - xAxis.TickLabelPosition = AxisTickLabelPosition.Low; - xAxis.TickLabelSpacingIsAuto = false; + xAxis.TickLabels.Offset = 50; + xAxis.TickLabels.Position = AxisTickLabelPosition.Low; + xAxis.TickLabels.IsAutoSpacing = false; xAxis.TickMarkSpacing = 1; ChartAxis yAxis = chart.AxisY; @@ -170,7 +170,7 @@ public void AxisProperties() yAxis.MinorTickMark = AxisTickMark.Cross; yAxis.MajorUnit = 100.0d; yAxis.MinorUnit = 20.0d; - yAxis.TickLabelPosition = AxisTickLabelPosition.NextToAxis; + yAxis.TickLabels.Position = AxisTickLabelPosition.NextToAxis; // Column charts do not have a Z-axis. Assert.Null(chart.AxisZ); @@ -188,9 +188,9 @@ public void AxisProperties() Assert.AreEqual(AxisTickMark.Cross, chart.AxisX.MinorTickMark); Assert.AreEqual(1.0d, chart.AxisX.MajorUnit); Assert.AreEqual(0.5d, chart.AxisX.MinorUnit); - Assert.AreEqual(50, chart.AxisX.TickLabelOffset); - Assert.AreEqual(AxisTickLabelPosition.Low, chart.AxisX.TickLabelPosition); - Assert.False(chart.AxisX.TickLabelSpacingIsAuto); + Assert.AreEqual(50, chart.AxisX.TickLabels.Offset); + Assert.AreEqual(AxisTickLabelPosition.Low, chart.AxisX.TickLabels.Position); + Assert.False(chart.AxisX.TickLabels.IsAutoSpacing); Assert.AreEqual(1, chart.AxisX.TickMarkSpacing); Assert.AreEqual(AxisCategoryType.Category, chart.AxisY.CategoryType); @@ -200,7 +200,7 @@ public void AxisProperties() Assert.AreEqual(AxisTickMark.Cross, chart.AxisY.MinorTickMark); Assert.AreEqual(100.0d, chart.AxisY.MajorUnit); Assert.AreEqual(20.0d, chart.AxisY.MinorUnit); - Assert.AreEqual(AxisTickLabelPosition.NextToAxis, chart.AxisY.TickLabelPosition); + Assert.AreEqual(AxisTickLabelPosition.NextToAxis, chart.AxisY.TickLabels.Position); } [Test] @@ -279,7 +279,7 @@ public void DateTimeValues() // Define Y-axis properties for decimal values. ChartAxis yAxis = chart.AxisY; - yAxis.TickLabelPosition = AxisTickLabelPosition.High; + yAxis.TickLabels.Position = AxisTickLabelPosition.High; yAxis.MajorUnit = 100.0d; yAxis.MinorUnit = 50.0d; yAxis.DisplayUnit.Unit = AxisBuiltInUnit.Hundreds; @@ -304,7 +304,7 @@ public void DateTimeValues() Assert.AreEqual(true, chart.AxisX.HasMajorGridlines); Assert.AreEqual(true, chart.AxisX.HasMinorGridlines); - Assert.AreEqual(AxisTickLabelPosition.High, chart.AxisY.TickLabelPosition); + Assert.AreEqual(AxisTickLabelPosition.High, chart.AxisY.TickLabels.Position); Assert.AreEqual(100.0d, chart.AxisY.MajorUnit); Assert.AreEqual(50.0d, chart.AxisY.MinorUnit); Assert.AreEqual(AxisBuiltInUnit.Hundreds, chart.AxisY.DisplayUnit.Unit); @@ -1121,9 +1121,9 @@ public void AxisDisplayUnit() // Set the X-axis bounds so that the X-axis spans 5 major tick marks and 12 minor tick marks. axis.Scaling.Minimum = new AxisBound(-10); axis.Scaling.Maximum = new AxisBound(30); - axis.TickLabelAlignment = ParagraphAlignment.Right; + axis.TickLabels.Alignment = ParagraphAlignment.Right; - Assert.AreEqual(1, axis.TickLabelSpacing); + Assert.AreEqual(1, axis.TickLabels.Spacing); // Set the tick labels to display their value in millions. axis.DisplayUnit.Unit = AxisBuiltInUnit.Millions; @@ -1149,8 +1149,8 @@ public void AxisDisplayUnit() Assert.AreEqual(10.0d, axis.MajorUnit); Assert.AreEqual(-10.0d, axis.Scaling.Minimum.Value); Assert.AreEqual(30.0d, axis.Scaling.Maximum.Value); - Assert.AreEqual(1, axis.TickLabelSpacing); - Assert.AreEqual(ParagraphAlignment.Right, axis.TickLabelAlignment); + Assert.AreEqual(1, axis.TickLabels.Spacing); + Assert.AreEqual(ParagraphAlignment.Right, axis.TickLabels.Alignment); Assert.AreEqual(AxisBuiltInUnit.Custom, axis.DisplayUnit.Unit); Assert.AreEqual(1000000.0d, axis.DisplayUnit.CustomUnit); @@ -1641,7 +1641,7 @@ public void DataTable() Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; - + ChartSeriesCollection series = chart.Series; series.Clear(); double[] xValues = new double[] { 2020, 2021, 2022, 2023 }; diff --git a/Examples/ApiExamples/ApiExamples/ExDocument.cs b/Examples/ApiExamples/ApiExamples/ExDocument.cs index c4f04dedf..6a8bf8dbb 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocument.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocument.cs @@ -3010,5 +3010,74 @@ public void InsertDocumentInline() Assert.AreEqual("Before [src content] after", dstDoc.Document.GetText().TrimEnd()); //ExEnd:InsertDocumentInline } + + [TestCase(SaveFormat.Doc)] + [TestCase(SaveFormat.Dot)] + [TestCase(SaveFormat.Docx)] + [TestCase(SaveFormat.Docm)] + [TestCase(SaveFormat.Dotx)] + [TestCase(SaveFormat.Dotm)] + [TestCase(SaveFormat.FlatOpc)] + [TestCase(SaveFormat.FlatOpcMacroEnabled)] + [TestCase(SaveFormat.FlatOpcTemplate)] + [TestCase(SaveFormat.FlatOpcTemplateMacroEnabled)] + [TestCase(SaveFormat.Rtf)] + [TestCase(SaveFormat.WordML)] + [TestCase(SaveFormat.Pdf)] + [TestCase(SaveFormat.Xps)] + [TestCase(SaveFormat.XamlFixed)] + [TestCase(SaveFormat.Svg)] + [TestCase(SaveFormat.HtmlFixed)] + [TestCase(SaveFormat.OpenXps)] + [TestCase(SaveFormat.Ps)] + [TestCase(SaveFormat.Pcl)] + [TestCase(SaveFormat.Html)] + [TestCase(SaveFormat.Mhtml)] + [TestCase(SaveFormat.Epub)] + [TestCase(SaveFormat.Azw3)] + [TestCase(SaveFormat.Mobi)] + [TestCase(SaveFormat.Odt)] + [TestCase(SaveFormat.Ott)] + [TestCase(SaveFormat.Text)] + [TestCase(SaveFormat.XamlFlow)] + [TestCase(SaveFormat.XamlFlowPack)] + [TestCase(SaveFormat.Markdown)] + [TestCase(SaveFormat.Xlsx)] + [TestCase(SaveFormat.Tiff)] + [TestCase(SaveFormat.Png)] + [TestCase(SaveFormat.Bmp)] + [TestCase(SaveFormat.Emf)] + [TestCase(SaveFormat.Jpeg)] + [TestCase(SaveFormat.Gif)] + [TestCase(SaveFormat.Eps)] + public void SaveDocumentToStream(SaveFormat saveFormat) + { + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + builder.Writeln("Lorem ipsum"); + + using (Stream stream = new MemoryStream()) + { + if (saveFormat == SaveFormat.HtmlFixed) + { + HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions(); + saveOptions.ExportEmbeddedCss = true; + saveOptions.ExportEmbeddedFonts = true; + saveOptions.SaveFormat = saveFormat; + + doc.Save(stream, saveOptions); + } + else if (saveFormat == SaveFormat.XamlFixed) + { + XamlFixedSaveOptions saveOptions = new XamlFixedSaveOptions(); + saveOptions.ResourcesFolder = ArtifactsDir; + saveOptions.SaveFormat = saveFormat; + + doc.Save(stream, saveOptions); + } + else + doc.Save(stream, saveFormat); + } + } } } diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs index d6331c345..da6863361 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs @@ -111,7 +111,7 @@ public void HeadersAndFooters() doc.Save(ArtifactsDir + "DocumentBuilder.HeadersAndFooters.docx"); //ExEnd - HeaderFooterCollection headersFooters = + HeaderFooterCollection headersFooters = new Document(ArtifactsDir + "DocumentBuilder.HeadersAndFooters.docx").FirstSection.HeadersFooters; Assert.AreEqual(3, headersFooters.Count); @@ -135,7 +135,7 @@ public void MergeFields() // Move the cursor to the first MERGEFIELD. builder.MoveToMergeField("MyMergeField1", true, false); - + // Note that the cursor is placed immediately after the first MERGEFIELD, and before the second. Assert.AreEqual(doc.Range.Fields[1].Start, builder.CurrentNode); Assert.AreEqual(doc.Range.Fields[0].End, builder.CurrentNode.PreviousSibling); @@ -147,7 +147,7 @@ public void MergeFields() builder.Write(" Text between our merge fields. "); doc.Save(ArtifactsDir + "DocumentBuilder.MergeFields.docx"); - //ExEnd + //ExEnd doc = new Document(ArtifactsDir + "DocumentBuilder.MergeFields.docx"); @@ -155,9 +155,9 @@ public void MergeFields() " Text between our merge fields. " + "\u0013MERGEFIELD MyMergeField2 \\* MERGEFORMAT\u0014«MyMergeField2»\u0015", doc.GetText().Trim()); Assert.AreEqual(2, doc.Range.Fields.Count); - TestUtil.VerifyField(FieldType.FieldMergeField, @"MERGEFIELD MyMergeField1 \* MERGEFORMAT", + TestUtil.VerifyField(FieldType.FieldMergeField, @"MERGEFIELD MyMergeField1 \* MERGEFORMAT", "«MyMergeField1»", doc.Range.Fields[0]); - TestUtil.VerifyField(FieldType.FieldMergeField, @"MERGEFIELD MyMergeField2 \* MERGEFORMAT", + TestUtil.VerifyField(FieldType.FieldMergeField, @"MERGEFIELD MyMergeField2 \* MERGEFORMAT", "«MyMergeField2»", doc.Range.Fields[1]); } @@ -210,7 +210,7 @@ public void HorizontalRuleFormatExceptions() horizontalRuleFormat.WidthPercent = 100; Assert.That(() => horizontalRuleFormat.WidthPercent = 0, Throws.TypeOf()); Assert.That(() => horizontalRuleFormat.WidthPercent = 101, Throws.TypeOf()); - + horizontalRuleFormat.Height = 0; horizontalRuleFormat.Height = 1584; Assert.That(() => horizontalRuleFormat.Height = -1, Throws.TypeOf()); @@ -351,7 +351,7 @@ public void InsertWatermark() Assert.AreEqual(RelativeVerticalPosition.Page, shape.RelativeVerticalPosition); Assert.AreEqual((doc.FirstSection.PageSetup.PageWidth - shape.Width) / 2, shape.Left); Assert.AreEqual((doc.FirstSection.PageSetup.PageHeight - shape.Height) / 2, shape.Top); - } + } [Test] public void InsertOleObject() @@ -363,7 +363,7 @@ public void InsertOleObject() //ExSummary:Shows how to insert an OLE object into a document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - + // OLE objects are links to files in our local file system that can be opened by other installed applications. // Double clicking these shapes will launch the application, and then use it to open the linked object. // There are three ways of using the InsertOleObject method to insert these shapes and configure their appearance. @@ -372,7 +372,7 @@ public void InsertOleObject() { // If 'presentation' is omitted and 'asIcon' is set, this overloaded method selects // the icon according to the file extension and uses the filename for the icon caption. - builder.InsertOleObject(MyDir + "Spreadsheet.xlsx", false, false, imageStream); + builder.InsertOleObject(MyDir + "Spreadsheet.xlsx", false, false, imageStream); } // If 'presentation' is omitted and 'asIcon' is set, this overloaded method selects @@ -391,7 +391,7 @@ public void InsertOleObject() doc = new Document(ArtifactsDir + "DocumentBuilder.InsertOleObject.docx"); Shape shape = (Shape)doc.GetChild(NodeType.Shape,0, true); - + Assert.AreEqual(ShapeType.OleObject, shape.ShapeType); Assert.AreEqual("Excel.Sheet.12", shape.OleFormat.ProgId); Assert.AreEqual(".xlsx", shape.OleFormat.SuggestedExtension); @@ -418,9 +418,9 @@ public void InsertHtml() Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - const string html = "

Paragraph right

" + + const string html = "

Paragraph right

" + "Implicit paragraph left" + - "
Div center
" + + "
Div center
" + "

Heading 1 left.

"; builder.InsertHtml(html); @@ -510,7 +510,7 @@ public void InsertTextAndBookmark() builder.StartBookmark("MyBookmark"); builder.Writeln("Hello world!"); builder.EndBookmark("MyBookmark"); - + Assert.AreEqual(1, doc.Range.Bookmarks.Count); Assert.AreEqual("MyBookmark", doc.Range.Bookmarks[0].Name); Assert.AreEqual("Hello world!", doc.Range.Bookmarks[0].Text.Trim()); @@ -578,9 +578,9 @@ public void CreateForm() // Form fields are objects in the document that the user can interact with by being prompted to enter values. // We can create them using a document builder, and below are two ways of doing so. // 1 - Basic text input: - builder.InsertTextInput("My text input", TextFormFieldType.Regular, + builder.InsertTextInput("My text input", TextFormFieldType.Regular, "", "Enter your name here", 30); - + // 2 - Combo box with prompt text, and a range of possible values: string[] items = { @@ -689,7 +689,7 @@ public void WorkingWithNodes() DocumentBuilder builder = new DocumentBuilder(doc); // Create a valid bookmark, an entity that consists of nodes enclosed by a bookmark start node, - // and a bookmark end node. + // and a bookmark end node. builder.StartBookmark("MyBookmark"); builder.Write("Bookmark contents."); builder.EndBookmark("MyBookmark"); @@ -1043,7 +1043,7 @@ public void InsertTableSetHeadingRow() { //ExStart //ExFor:RowFormat.HeadingFormat - //ExSummary:Shows how to build a table with rows that repeat on every page. + //ExSummary:Shows how to build a table with rows that repeat on every page. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -1158,7 +1158,7 @@ public void InsertCellsWithPreferredWidths() builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGreen; builder.Writeln("Automatically sized cell."); - + doc.Save(ArtifactsDir + "DocumentBuilder.InsertCellsWithPreferredWidths.docx"); //ExEnd @@ -1167,7 +1167,7 @@ public void InsertCellsWithPreferredWidths() doc = new Document(ArtifactsDir + "DocumentBuilder.InsertCellsWithPreferredWidths.docx"); table = doc.FirstSection.Body.Tables[0]; - + Assert.AreEqual(PreferredWidthType.Points, table.FirstRow.Cells[0].CellFormat.PreferredWidth.Type); Assert.AreEqual(40.0d, table.FirstRow.Cells[0].CellFormat.PreferredWidth.Value); Assert.AreEqual("Cell with a width of 800.\r\a", table.FirstRow.Cells[0].GetText().Trim()); @@ -1480,8 +1480,7 @@ public void InsertHyperlinkToLocalBookmark() builder.EndBookmark("Bookmark1"); builder.Writeln("Text outside of the bookmark."); - // Insert a HYPERLINK field that links to the bookmark. We can pass field switches - // to the "InsertHyperlink" method as part of the argument containing the referenced bookmark's name. + // Insert a HYPERLINK field that links to the bookmark. builder.Font.Color = Color.Blue; builder.Font.Underline = Underline.Single; FieldHyperlink hyperlink = (FieldHyperlink)builder.InsertHyperlink("Link to Bookmark1", "Bookmark1", true); @@ -1513,7 +1512,7 @@ public void CursorPosition() Assert.AreEqual("Hello world!", builder.CurrentParagraph.GetText().Trim()); // Move to the beginning of the document and place the cursor at an existing node. - builder.MoveToDocumentStart(); + builder.MoveToDocumentStart(); Assert.AreEqual(NodeType.Run, builder.CurrentNode.NodeType); } @@ -1950,7 +1949,7 @@ public void SignatureLineProviderId() CertificateHolder certHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw"); - DigitalSignatureUtil.Sign(ArtifactsDir + "DocumentBuilder.SignatureLineProviderId.docx", + DigitalSignatureUtil.Sign(ArtifactsDir + "DocumentBuilder.SignatureLineProviderId.docx", ArtifactsDir + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions); // Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true", @@ -2466,7 +2465,7 @@ public void MoveToField(bool moveCursorToAfterTheField) Assert.Null(builder.CurrentNode); builder.Write(" Text immediately after the field."); - Assert.AreEqual("\u0013 AUTHOR \"John Doe\" \u0014John Doe\u0015 Text immediately after the field.", + Assert.AreEqual("\u0013 AUTHOR \"John Doe\" \u0014John Doe\u0015 Text immediately after the field.", doc.GetText().Trim()); } else @@ -2474,7 +2473,7 @@ public void MoveToField(bool moveCursorToAfterTheField) Assert.AreEqual(field.Start, builder.CurrentNode); builder.Write("Text immediately before the field. "); - Assert.AreEqual("Text immediately before the field. \u0013 AUTHOR \"John Doe\" \u0014John Doe\u0015", + Assert.AreEqual("Text immediately before the field. \u0013 AUTHOR \"John Doe\" \u0014John Doe\u0015", doc.GetText().Trim()); } //ExEnd @@ -2499,7 +2498,7 @@ public void InsertPieChart() Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - Chart chart = builder.InsertChart(ChartType.Pie, ConvertUtil.PixelToPoint(300), + Chart chart = builder.InsertChart(ChartType.Pie, ConvertUtil.PixelToPoint(300), ConvertUtil.PixelToPoint(300)).Chart; Assert.AreEqual(225.0d, ConvertUtil.PixelToPoint(300)); //ExSkip chart.Series.Clear(); @@ -2566,7 +2565,7 @@ public void InsertField() // This overload of the InsertField method automatically updates inserted fields. Assert.That(DateTime.Parse(field.Result), Is.EqualTo(DateTime.Today).Within(1).Days); - //ExEnd + //ExEnd } [TestCase(false)] @@ -2679,9 +2678,9 @@ public FieldResultFormatter(string numberFormat, string dateFormat, string gener public string FormatNumeric(double value, string format) { - if (string.IsNullOrEmpty(mNumberFormat)) + if (string.IsNullOrEmpty(mNumberFormat)) return null; - + string newValue = String.Format(mNumberFormat, value); FormatInvocations.Add(new FormatInvocation(FormatInvocationType.Numeric, value, format, newValue)); return newValue; @@ -2721,12 +2720,12 @@ public int CountFormatInvocations(FormatInvocationType formatInvocationType) { if (formatInvocationType == FormatInvocationType.All) return FormatInvocations.Count; - + return FormatInvocations.Count(f => f.FormatInvocationType == formatInvocationType); } public void PrintFormatInvocations() - { + { foreach (FormatInvocation f in FormatInvocations) Console.WriteLine($"Invocation type:\t{f.FormatInvocationType}\n" + $"\tOriginal value:\t\t{f.Value}\n" + @@ -2736,9 +2735,9 @@ public void PrintFormatInvocations() private readonly string mNumberFormat; private readonly string mDateFormat; - private readonly string mGeneralFormat; + private readonly string mGeneralFormat; private List FormatInvocations { get; } = new List(); - + private class FormatInvocation { public FormatInvocationType FormatInvocationType { get; } @@ -2942,9 +2941,9 @@ public void InsertStyleSeparator() Assert.AreEqual("Heading 1", doc.FirstSection.Body.Paragraphs[0].ParagraphFormat.Style.Name); Assert.AreEqual("MyParaStyle", doc.FirstSection.Body.Paragraphs[1].ParagraphFormat.Style.Name); Assert.AreEqual(" ", doc.FirstSection.Body.Paragraphs[1].Runs[0].GetText()); - TestUtil.DocPackageFileContainsString("w:rPr>", + TestUtil.DocPackageFileContainsString("w:rPr>", ArtifactsDir + "DocumentBuilder.InsertStyleSeparator.docx", "document.xml"); - TestUtil.DocPackageFileContainsString(" ", + TestUtil.DocPackageFileContainsString(" ", ArtifactsDir + "DocumentBuilder.InsertStyleSeparator.docx", "document.xml"); } @@ -3023,11 +3022,11 @@ public void SmartStyleBehavior() public void EmphasesWarningSourceMarkdown() { Document doc = new Document(MyDir + "Emphases markdown warning.docx"); - + WarningInfoCollection warnings = new WarningInfoCollection(); doc.WarningCallback = warnings; doc.Save(ArtifactsDir + "DocumentBuilder.EmphasesWarningSourceMarkdown.md"); - + foreach (WarningInfo warningInfo in warnings) { if (warningInfo.Source == WarningSource.Markdown) @@ -3043,10 +3042,10 @@ public void DoNotIgnoreHeaderFooter() //ExSummary:Shows how to specifies ignoring or not source formatting of headers/footers content. Document dstDoc = new Document(MyDir + "Document.docx"); Document srcDoc = new Document(MyDir + "Header and footer types.docx"); - + ImportFormatOptions importFormatOptions = new ImportFormatOptions(); importFormatOptions.IgnoreHeaderFooter = false; - + dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting, importFormatOptions); dstDoc.Save(ArtifactsDir + "DocumentBuilder.DoNotIgnoreHeaderFooter.docx"); @@ -3056,19 +3055,19 @@ public void DoNotIgnoreHeaderFooter() public void MarkdownDocumentEmphases() { DocumentBuilder builder = new DocumentBuilder(); - + // Bold and Italic are represented as Font.Bold and Font.Italic. builder.Font.Italic = true; builder.Writeln("This text will be italic"); - + // Use clear formatting if we don't want to combine styles between paragraphs. builder.Font.ClearFormatting(); - + builder.Font.Bold = true; builder.Writeln("This text will be bold"); - + builder.Font.ClearFormatting(); - + builder.Font.Italic = true; builder.Write("You "); builder.Font.Bold = true; @@ -3080,28 +3079,28 @@ public void MarkdownDocumentEmphases() builder.Font.StrikeThrough = true; builder.Writeln("This text will be strikethrough"); - + // Markdown treats asterisks (*), underscores (_) and tilde (~) as indicators of emphasis. builder.Document.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } - + public void MarkdownDocumentInlineCode() { Document doc = new Document(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); DocumentBuilder builder = new DocumentBuilder(doc); - + // Prepare our created document for further work // and clear paragraph formatting not to use the previous styles. builder.MoveToDocumentEnd(); builder.ParagraphFormat.ClearFormatting(); builder.Writeln("\n"); - + // Style with name that starts from word InlineCode, followed by optional dot (.) and number of backticks (`). // If number of backticks is missed, then one backtick will be used by default. Style inlineCode1BackTicks = doc.Styles.Add(StyleType.Character, "InlineCode"); builder.Font.Style = inlineCode1BackTicks; builder.Writeln("Text with InlineCode style with one backtick"); - + // Use optional dot (.) and number of backticks (`). // There will be 3 backticks. Style inlineCode3BackTicks = doc.Styles.Add(StyleType.Character, "InlineCode.3"); @@ -3110,7 +3109,7 @@ public void MarkdownDocumentInlineCode() builder.Document.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } - + public void MarkdownDocumentHeadings() { Document doc = new Document(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); @@ -3121,13 +3120,13 @@ public void MarkdownDocumentHeadings() builder.MoveToDocumentEnd(); builder.ParagraphFormat.ClearFormatting(); builder.Writeln("\n"); - + // By default, Heading styles in Word may have bold and italic formatting. // If we do not want text to be emphasized, set these properties explicitly to false. // Thus we can't use 'builder.Font.ClearFormatting()' because Bold/Italic will be set to true. builder.Font.Bold = false; builder.Font.Italic = false; - + // Create for one heading for each level. builder.ParagraphFormat.StyleName = "Heading 1"; builder.Font.Italic = true; @@ -3142,7 +3141,7 @@ public void MarkdownDocumentHeadings() builder.ParagraphFormat.Style = setextHeading1; doc.Styles["SetextHeading1"].BaseStyleName = "Heading 1"; builder.Writeln("SetextHeading 1"); - + builder.ParagraphFormat.StyleName = "Heading 2"; builder.Writeln("This is an H2 tag"); @@ -3153,17 +3152,17 @@ public void MarkdownDocumentHeadings() builder.ParagraphFormat.Style = setextHeading2; doc.Styles["SetextHeading2"].BaseStyleName = "Heading 2"; builder.Writeln("SetextHeading 2"); - + builder.ParagraphFormat.Style = doc.Styles["Heading 3"]; builder.Writeln("This is an H3 tag"); - + builder.Font.Bold = false; builder.Font.Italic = false; builder.ParagraphFormat.Style = doc.Styles["Heading 4"]; builder.Font.Bold = true; builder.Writeln("This is an bold H4 tag"); - + builder.Font.Bold = false; builder.Font.Italic = false; @@ -3171,13 +3170,13 @@ public void MarkdownDocumentHeadings() builder.Font.Italic = true; builder.Font.Bold = true; builder.Writeln("This is an italic and bold H5 tag"); - + builder.Font.Bold = false; builder.Font.Italic = false; builder.ParagraphFormat.Style = doc.Styles["Heading 6"]; builder.Writeln("This is an H6 tag"); - + doc.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } @@ -3195,44 +3194,44 @@ public void MarkdownDocumentBlockquotes() // By default, the document stores blockquote style for the first level. builder.ParagraphFormat.StyleName = "Quote"; builder.Writeln("Blockquote"); - + // Create styles for nested levels through style inheritance. Style quoteLevel2 = doc.Styles.Add(StyleType.Paragraph, "Quote1"); builder.ParagraphFormat.Style = quoteLevel2; doc.Styles["Quote1"].BaseStyleName = "Quote"; builder.Writeln("1. Nested blockquote"); - + Style quoteLevel3 = doc.Styles.Add(StyleType.Paragraph, "Quote2"); builder.ParagraphFormat.Style = quoteLevel3; doc.Styles["Quote2"].BaseStyleName = "Quote1"; builder.Font.Italic = true; builder.Writeln("2. Nested italic blockquote"); - + Style quoteLevel4 = doc.Styles.Add(StyleType.Paragraph, "Quote3"); builder.ParagraphFormat.Style = quoteLevel4; doc.Styles["Quote3"].BaseStyleName = "Quote2"; builder.Font.Italic = false; builder.Font.Bold = true; builder.Writeln("3. Nested bold blockquote"); - + Style quoteLevel5 = doc.Styles.Add(StyleType.Paragraph, "Quote4"); builder.ParagraphFormat.Style = quoteLevel5; doc.Styles["Quote4"].BaseStyleName = "Quote3"; builder.Font.Bold = false; builder.Writeln("4. Nested blockquote"); - + Style quoteLevel6 = doc.Styles.Add(StyleType.Paragraph, "Quote5"); builder.ParagraphFormat.Style = quoteLevel6; doc.Styles["Quote5"].BaseStyleName = "Quote4"; builder.Writeln("5. Nested blockquote"); - + Style quoteLevel7 = doc.Styles.Add(StyleType.Paragraph, "Quote6"); builder.ParagraphFormat.Style = quoteLevel7; doc.Styles["Quote6"].BaseStyleName = "Quote5"; builder.Font.Italic = true; builder.Font.Bold = true; builder.Writeln("6. Nested italic bold blockquote"); - + doc.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } @@ -3251,7 +3250,7 @@ public void MarkdownDocumentIndentedCode() Style indentedCode = doc.Styles.Add(StyleType.Paragraph, "IndentedCode"); builder.ParagraphFormat.Style = indentedCode; builder.Writeln("This is an indented code"); - + doc.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } @@ -3291,7 +3290,7 @@ public void MarkdownDocumentHorizontalRule() // Insert HorizontalRule that will be present in .md file as '-----'. builder.InsertHorizontalRule(); - + builder.Document.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } @@ -3311,13 +3310,13 @@ public void MarkdownDocumentBulletedList() // There can be 3 types of bulleted lists. // The only diff in a numbering format of the very first level are ‘-’, ‘+’ or ‘*’ respectively. builder.ListFormat.List.ListLevels[0].NumberFormat = "-"; - + builder.Writeln("Item 1"); builder.Writeln("Item 2"); builder.ListFormat.ListIndent(); builder.Writeln("Item 2a"); builder.Writeln("Item 2b"); - + builder.Document.Save(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); } @@ -3361,7 +3360,7 @@ public void LoadMarkdownDocumentAndAssertContent(string text, string styleName, // Load created document from previous tests. Document doc = new Document(ArtifactsDir + "DocumentBuilder.MarkdownDocument.md"); ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs; - + foreach (Paragraph paragraph in paragraphs) { if (paragraph.Runs.Count != 0) @@ -3382,7 +3381,7 @@ public void LoadMarkdownDocumentAndAssertContent(string text, string styleName, // Check that document also has a HorizontalRule present as a shape. NodeCollection shapesCollection = doc.FirstSection.Body.GetChildNodes(NodeType.Shape, true); Shape horizontalRuleShape = (Shape) shapesCollection[0]; - + Assert.IsTrue(shapesCollection.Count == 1); Assert.IsTrue(horizontalRuleShape.IsHorizontalRule); } @@ -3396,7 +3395,7 @@ public async Task InsertOnlineVideo() //ExSummary:Shows how to insert an online video into a document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - + string videoUrl = "https://vimeo.com/52477838"; // Insert a shape that plays a video from the web when clicked in Microsoft Word. @@ -3548,7 +3547,7 @@ public void PreserveBlocks() // Set the new mode of import HTML block-level elements. HtmlInsertOptions insertOptions = HtmlInsertOptions.PreserveBlocks; - + DocumentBuilder builder = new DocumentBuilder(); builder.InsertHtml(html, insertOptions); builder.Document.Save(ArtifactsDir + "DocumentBuilder.PreserveBlocks.docx"); @@ -3564,7 +3563,7 @@ public void PhoneticGuide() //ExFor:PhoneticGuide.BaseText //ExFor:PhoneticGuide.RubyText //ExSummary:Shows how to get properties of the phonetic guide. - Document doc = new Document(MyDir + "Phonetic guide.docx"); + Document doc = new Document(MyDir + "Phonetic guide.docx"); RunCollection runs = doc.FirstSection.Body.FirstParagraph.Runs; // Use phonetic guide in the Asian text. diff --git a/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs index 2d4fac412..bed5763ec 100644 --- a/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs @@ -1944,5 +1944,23 @@ public void Notify(DocumentSavingArgs args) private const double MaxDuration = 0.1d; } //ExEnd + + [TestCase(SaveFormat.Mobi)] + [TestCase(SaveFormat.Azw3)] + public void MobiAzw3DefaultEncoding(SaveFormat saveFormat) + { + Document doc = new Document(MyDir + "Rendering.docx"); + + HtmlSaveOptions saveOptions = new HtmlSaveOptions(); + saveOptions.SaveFormat = saveFormat; + saveOptions.Encoding = Encoding.ASCII; + + string outputFileName = $"{ArtifactsDir}HtmlSaveOptions.MobiDefaultEncoding{FileFormatUtil.SaveFormatToExtension(saveFormat)}"; + doc.Save(outputFileName); + + Encoding encoding = TestUtil.GetEncoding(outputFileName); + Assert.AreNotEqual(Encoding.ASCII, encoding); + Assert.AreEqual(Encoding.UTF8, encoding); + } } } diff --git a/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs index 51ff62364..1ed04e10a 100644 --- a/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs @@ -553,14 +553,15 @@ public void JpegQuality() [TestCase(TiffCompression.Ccitt4), Category("SkipMono")] public void TiffImageCompression(TiffCompression tiffCompression) { - //ExStart + //ExStart:TiffImageCompression + //GistId:0e50f625c0e76c25844c7e77ffa31057 //ExFor:TiffCompression //ExFor:ImageSaveOptions.TiffCompression //ExSummary:Shows how to select the compression scheme to apply to a document that we convert into a TIFF image. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - builder.InsertImage(ImageDir + "Logo.jpg"); + builder.InsertImage(ImageDir + "Tagged Image File Format.tiff"); // Create an "ImageSaveOptions" object which we can pass to the document's "Save" method // to modify the way in which that method renders the document into an image. @@ -574,7 +575,7 @@ public void TiffImageCompression(TiffCompression tiffCompression) options.TiffCompression = tiffCompression; doc.Save(ArtifactsDir + "ImageSaveOptions.TiffImageCompression.tiff", options); - //ExEnd + //ExEnd:TiffImageCompression var testedImageLength = new FileInfo(ArtifactsDir + "ImageSaveOptions.TiffImageCompression.tiff").Length; @@ -585,23 +586,27 @@ public void TiffImageCompression(TiffCompression tiffCompression) break; case TiffCompression.Rle: #if NET5_0_OR_GREATER - Assert.That(testedImageLength, Is.LessThan(7500)); + Assert.That(testedImageLength, Is.LessThan(12200)); #else - Assert.That(testedImageLength, Is.LessThan(687000)); + Assert.That(testedImageLength, Is.LessThan(780200)); #endif break; case TiffCompression.Lzw: - Assert.That(testedImageLength, Is.LessThan(250000)); + Assert.That(testedImageLength, Is.LessThan(548500)); break; case TiffCompression.Ccitt3: #if NET5_0_OR_GREATER - Assert.That(testedImageLength, Is.LessThan(6100)); + Assert.That(testedImageLength, Is.LessThan(11900)); #else - Assert.That(testedImageLength, Is.LessThan(8300)); + Assert.That(testedImageLength, Is.LessThan(10100)); #endif break; - case TiffCompression.Ccitt4: - Assert.That(testedImageLength, Is.LessThan(1700)); + case TiffCompression.Ccitt4: +#if NET5_0_OR_GREATER + Assert.That(testedImageLength, Is.LessThan(8900)); +#else + Assert.That(testedImageLength, Is.LessThan(5000)); +#endif break; } } diff --git a/Examples/ApiExamples/ApiExamples/ExInlineStory.cs b/Examples/ApiExamples/ApiExamples/ExInlineStory.cs index 4ede7ea22..02993509b 100644 --- a/Examples/ApiExamples/ApiExamples/ExInlineStory.cs +++ b/Examples/ApiExamples/ApiExamples/ExInlineStory.cs @@ -642,4 +642,4 @@ public void UpdateActualReferenceMarks() //ExEnd:UpdateActualReferenceMarks } } -} \ No newline at end of file +} diff --git a/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs index 97acae7a7..1e63ede97 100644 --- a/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs @@ -1,11 +1,14 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; -using ApiExamples; +using System.Threading.Tasks; +using Aspose.Words; using Aspose.Words.Loading; using NUnit.Framework; -namespace Aspose.Words.ApiExamples +namespace ApiExamples { class ExMarkdownLoadOptions : ApiExampleBase { diff --git a/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs b/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs index 66b5ee2d8..c5703d23e 100644 --- a/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs +++ b/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs @@ -155,7 +155,7 @@ public void RestartingListNumberingDynamicallyWhileMultipleInsertionsDocumentDyn mainTemplate.Save(ArtifactsDir + "ReportingEngine.RestartingListNumberingDynamicallyWhileMultipleInsertionsDocumentDynamically.docx"); Assert.IsTrue(DocumentHelper.CompareDocs(ArtifactsDir + "ReportingEngine.RestartingListNumberingDynamicallyWhileMultipleInsertionsDocumentDynamically.docx", GoldsDir + "ReportingEngine.RestartingListNumberingDynamicallyWhileInsertingDocumentDynamically Gold.docx")); - } + } [Test] public void ChartTest() @@ -1209,9 +1209,9 @@ public void DollarTextFormat() NumericTestClass testData = new NumericTestBuilder().WithValues(1234, 5621718.589).Build(); - ReportingEngine engine = new ReportingEngine(); - engine.KnownTypes.Add(typeof(NumericTestClass)); - engine.BuildReport(doc, testData, "ds"); + ReportingEngine report = new ReportingEngine(); + report.KnownTypes.Add(typeof(NumericTestClass)); + report.BuildReport(doc, testData, "ds"); doc.Save(ArtifactsDir + "ReportingEngine.DollarTextFormat.docx"); //ExEnd:DollarTextFormat @@ -1234,7 +1234,7 @@ public void RestrictedTypes() // Note, that you can't set restricted types during or after building a report. ReportingEngine.SetRestrictedTypes(typeof(System.Type)); // We set "AllowMissingMembers" option to avoid exceptions during building a report. - ReportingEngine engine = new ReportingEngine() { Options = ReportBuildOptions.AllowMissingMembers }; + ReportingEngine engine = new ReportingEngine() { Options = ReportBuildOptions.AllowMissingMembers }; engine.BuildReport(doc, new object()); // We get an empty string because we can't access the GetType() method. diff --git a/Examples/ApiExamples/ApiExamples/ExShape.cs b/Examples/ApiExamples/ApiExamples/ExShape.cs index dfa4676fc..05cb39479 100644 --- a/Examples/ApiExamples/ApiExamples/ExShape.cs +++ b/Examples/ApiExamples/ApiExamples/ExShape.cs @@ -25,7 +25,6 @@ using HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment; using TextBox = Aspose.Words.Drawing.TextBox; using Aspose.Words.Themes; -using Aspose.Words.Forms2; namespace ApiExamples { @@ -1436,7 +1435,7 @@ public void RenderOfficeMath() //ExEnd if (!IsRunningOnMono()) - TestUtil.VerifyImage(795, 87, ArtifactsDir + "Shape.RenderOfficeMath.png"); + TestUtil.VerifyImage(792, 87, ArtifactsDir + "Shape.RenderOfficeMath.png"); else TestUtil.VerifyImage(735, 128, ArtifactsDir + "Shape.RenderOfficeMath.png"); } @@ -2762,14 +2761,14 @@ public void OfficeMathRenderer() OfficeMathRenderer renderer = new OfficeMathRenderer(officeMath); // Verify the size of the image that the OfficeMath object will create when we render it. - Assert.AreEqual(119.0f, renderer.SizeInPoints.Width, 0.2f); + Assert.AreEqual(119.0f, renderer.SizeInPoints.Width, 0.25f); Assert.AreEqual(13.0f, renderer.SizeInPoints.Height, 0.1f); - Assert.AreEqual(119.0f, renderer.BoundsInPoints.Width, 0.2f); + Assert.AreEqual(119.0f, renderer.BoundsInPoints.Width, 0.25f); Assert.AreEqual(13.0f, renderer.BoundsInPoints.Height, 0.1f); // Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties. - Assert.AreEqual(119.0f, renderer.OpaqueBoundsInPoints.Width, 0.2f); + Assert.AreEqual(119.0f, renderer.OpaqueBoundsInPoints.Width, 0.25f); Assert.AreEqual(14.2f, renderer.OpaqueBoundsInPoints.Height, 0.1f); // Get the shape size in pixels, with linear scaling to a specific DPI. @@ -3033,8 +3032,8 @@ public void FitImageToShape() doc.Save(ArtifactsDir + "Shape.FitImageToShape.docx"); //ExEnd:FitImageToShape - } - + } + [Test] public void StrokeForeThemeColors() { @@ -3069,7 +3068,7 @@ public void StrokeBackThemeColors() //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"); + Document doc = new Document(MyDir + "Stroke gradient outline.docx"); Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); Stroke stroke = shape.Stroke; diff --git a/Examples/ApiExamples/ApiExamples/ExStyles.cs b/Examples/ApiExamples/ApiExamples/ExStyles.cs index 1ec4a25c0..aa8d9197a 100644 --- a/Examples/ApiExamples/ApiExamples/ExStyles.cs +++ b/Examples/ApiExamples/ApiExamples/ExStyles.cs @@ -384,7 +384,7 @@ public void StylePriority() //ExSummary:Shows how to prioritize and hide a style. Document doc = new Document(); Style styleTitle = doc.Styles[StyleIdentifier.Subtitle]; - + if (styleTitle.Priority == 9) styleTitle.Priority = 10; diff --git a/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs index 0456bc48f..16f5b9628 100644 --- a/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs @@ -102,4 +102,4 @@ public void SaveOfficeMath() //ExEnd:SaveOfficeMath } } -} \ No newline at end of file +} diff --git a/Examples/ApiExamples/ApiExamples/TestUtil.cs b/Examples/ApiExamples/ApiExamples/TestUtil.cs index ef1c6f59d..856da341f 100644 --- a/Examples/ApiExamples/ApiExamples/TestUtil.cs +++ b/Examples/ApiExamples/ApiExamples/TestUtil.cs @@ -561,5 +561,17 @@ internal static void VerifyEditableRange(int expectedId, string expectedEditorUs Assert.AreEqual(expectedEditorGroup, editableRange.EditorGroup); }); } + + /// + /// Get File's Encoding. + /// + internal static Encoding GetEncoding(string filename) + { + using (var streamReader = new StreamReader(filename, true)) + { + streamReader.Read(); + return streamReader.CurrentEncoding; + } + } } }