diff --git a/PdfSharp.sln.DotSettings b/PdfSharp.sln.DotSettings index 34155a0e..87f689af 100644 --- a/PdfSharp.sln.DotSettings +++ b/PdfSharp.sln.DotSettings @@ -44,5 +44,6 @@ True True True + True True True \ No newline at end of file diff --git a/README.md b/README.md index b6321e33..a3e975dd 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # PDFsharp & MigraDoc 6.0 -Version **6.0.0-preview-2** -Published **2023-04-25** +Version **6.0.0-preview-3** +Published **2023-07-27** -This is the second preview of the **PDFsharp** project, the main project of PDFsharp & MigraDoc 6.0 with updates for C# 10 and .NET 6.0. +This is the third preview of the **PDFsharp** project, the main project of PDFsharp & MigraDoc 6.0 with updates for C# 10 and .NET 6.0. PDFsharp: Copyright (c) 2005-2023 empira Software GmbH, Troisdorf (Cologne Area, Germany) MigraDoc: Copyright (c) 2001-2023 empira Software GmbH, Troisdorf (Cologne Area, Germany) diff --git a/dev/build-local-nuget-packages-release.ps1 b/dev/build-local-nuget-packages-release.ps1 index f4149c93..d6eeba5b 100644 --- a/dev/build-local-nuget-packages-release.ps1 +++ b/dev/build-local-nuget-packages-release.ps1 @@ -1,40 +1,40 @@ -# Updates local nuget packages. - -#Requires -Version 7 -#Requires -PSEdition Core - -param ( - [Parameter(Mandatory = $false)] [bool]$deleteBinAndObj = $true -) - -Push-Location $PSScriptRoot - -try { - Write-Host "Delete bin and obj " $deleteBinAndObj - if ($deleteBinAndObj) { - Write-Host "Deleting BIN and OBJ" - .\del-bin-and-obj.ps1 - Write-Host "Done deleting bin and obj" - } - - Push-Location .. - try { - Write-Host "Invoking ’dotnet build’" - dotnet build -c release - $build = $LASTEXITCODE - Write-Host "’dotnet build’ has finished" - } - finally { - Pop-Location - } - - if ($build -gt 0) { - Write-Host "’dotnet build’ failed with code " $build - throw "’dotnet build’ failed with code " + $build - } - - .\update-local-nuget-packages-release.ps1 -} -finally { - Pop-Location -} +# Updates local nuget packages. + +#Requires -Version 7 +#Requires -PSEdition Core + +param ( + [Parameter(Mandatory = $false)] [bool]$deleteBinAndObj = $true +) + +Push-Location $PSScriptRoot + +try { + Write-Host "Delete bin and obj " $deleteBinAndObj + if ($deleteBinAndObj) { + Write-Host "Deleting BIN and OBJ" + .\del-bin-and-obj.ps1 + Write-Host "Done deleting bin and obj" + } + + Push-Location .. + try { + Write-Host "Invoking ’dotnet build’" + dotnet build -c release + $build = $LASTEXITCODE + Write-Host "’dotnet build’ has finished" + } + finally { + Pop-Location + } + + if ($build -gt 0) { + Write-Host "’dotnet build’ failed with code " $build + throw "’dotnet build’ failed with code " + $build + } + + .\update-local-nuget-packages-release.ps1 +} +finally { + Pop-Location +} diff --git a/docs/BoilerplateText.md b/docs/BoilerplateText.md index 7361a764..3156d0d6 100644 --- a/docs/BoilerplateText.md +++ b/docs/BoilerplateText.md @@ -65,8 +65,8 @@ MigraDoc is a .NET library that allows developers to create documents such as PD PDFsharp: This is a preview version of PDFsharp 6.0.0 using .NET 6. -The package ’PdfSharp’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. +The package ’PdfSharp’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. The Target Framework is ’net6.0-windows’. We also publish packages that contain PDFsharp plus MigraDoc. See the project docs site for further information: https://docs.pdfsharp.net/history/readme-v6.0.html @@ -74,7 +74,7 @@ https://docs.pdfsharp.net/history/readme-v6.0.html PDFsharp & MigraDoc: This is a preview version of PDFsharp and MigraDoc Foundation 6.0.0 using .NET 6. -The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. +The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. The Target Framework is ’net6.0-windows’. See the project docs site for further information: https://docs.pdfsharp.net/history/readme-v6.0.html diff --git a/docs/DevNotes.md b/docs/DevNotes.md index 7aa7267a..2c8dcee5 100644 --- a/docs/DevNotes.md +++ b/docs/DevNotes.md @@ -5,3 +5,40 @@ ## List of files to be checked before publishing a release README.md + + +## Comments + +### DELETE yyyy-mm-dd + +Here is code that is replaced by newer code and should be deleted in the future. +But keeps here at the moment as reference in case the new code has bugs. + +After the specified date the code can be deleted. + +### KEEP + +Here is older code that is not used anymore but keeps here for +documentation or reference purposes and shall not be removed. + +### TODO + +**Here is something to be done __before the project is released__.** + +### BUG + +**Here is a bug that must be fixed before the project is released.** + +### IMPROV + +Here is code that substantially works but has potential for improvements +for better reliability. + +### OBSERVATION + + +### EXPERIMENTAL + + +### TEST +Here is code that should be coved by (more) unit tests. \ No newline at end of file diff --git a/gitversion.yml b/gitversion.yml index e2d93597..c3b00703 100644 --- a/gitversion.yml +++ b/gitversion.yml @@ -1,10 +1,11 @@ -# 23-03-22 +# 23-05-24 assembly-versioning-scheme: MajorMinorPatch mode: Mainline assembly-informational-format: '{NuGetVersion}' branches: develop: # Current development - # 5.0.0-develop.123 + # branch: develop -- is always 'develop' + # version: {6.0.0}-develop.123 -- taken from git tag plus 'develop' plus commit count regex: ^develop$ mode: ContinuousDeployment increment: None @@ -13,11 +14,10 @@ branches: track-merge-target: true source-branches: ['feature', 'release'] release: # Release and preview versions. - # 22.40.0 / 22.40.0-rc-1 - # 5.0.0-preview-2 + # branch: release/6.0.0-preview-3 -- must be same as git tag without leading 'v'. + # version: {6-0-0-preview-3} -- taken from git tag only regex: ^(release[/-]|master) - # ^(user|feature|fix)[/-] - # Must not have mode set to be mainline + # Must not have mode set to be mainline? WTF? increment: None tag: '' prevent-increment-of-merged-branch-version: true @@ -26,8 +26,8 @@ branches: is-mainline: true source-branches: ['develop', 'release', 'feature'] feature: # Features and bug fixes. - # 22.40.0-dev-anse-gvupd.1 - # 5.0.0-dev-my-branch.123 + # branch: feature/my-new-feature -- arbitrary name, e.g. a new preview + # version: {6.0.0}-dev-{my-new-feature}.123 -- taken from git tag plus 'dev-' plus branch name plus commit count regex: ^(user|feature|fix)[/-] mode: ContinuousDeployment increment: None @@ -39,6 +39,4 @@ branches: regex: ^(pull|pull\-requests|pr)[/-] tag: PullRequest mode: ContinuousDeployment -#ignore: -# sha: [] merge-message-formats: {} diff --git a/src/foundation/nuget/src/MigraDoc.NuGet-gdi/ReleaseNotes.txt b/src/foundation/nuget/src/MigraDoc.NuGet-gdi/ReleaseNotes.txt index 9ef450da..f06f5da0 100644 --- a/src/foundation/nuget/src/MigraDoc.NuGet-gdi/ReleaseNotes.txt +++ b/src/foundation/nuget/src/MigraDoc.NuGet-gdi/ReleaseNotes.txt @@ -1,5 +1,5 @@ This is a preview version of PDFsharp and MigraDoc Foundation 6.0.0 using .NET 6. -The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. +The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. The Target Framework is ’net6.0-windows’. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/nuget/src/MigraDoc.NuGet-wpf/ReleaseNotes.txt b/src/foundation/nuget/src/MigraDoc.NuGet-wpf/ReleaseNotes.txt index 9ef450da..f06f5da0 100644 --- a/src/foundation/nuget/src/MigraDoc.NuGet-wpf/ReleaseNotes.txt +++ b/src/foundation/nuget/src/MigraDoc.NuGet-wpf/ReleaseNotes.txt @@ -1,5 +1,5 @@ This is a preview version of PDFsharp and MigraDoc Foundation 6.0.0 using .NET 6. -The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. +The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. The Target Framework is ’net6.0-windows’. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/nuget/src/MigraDoc.NuGet/ReleaseNotes.txt b/src/foundation/nuget/src/MigraDoc.NuGet/ReleaseNotes.txt index 9ef450da..f06f5da0 100644 --- a/src/foundation/nuget/src/MigraDoc.NuGet/ReleaseNotes.txt +++ b/src/foundation/nuget/src/MigraDoc.NuGet/ReleaseNotes.txt @@ -1,5 +1,5 @@ This is a preview version of PDFsharp and MigraDoc Foundation 6.0.0 using .NET 6. -The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. +The package ’PDFsharp-MigraDoc’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-MigraDoc-GDI’ and ’PDFsharp-MigraDoc-WPF’ can be used under Windows only. The Target Framework is ’net6.0-windows’. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/nuget/src/PDFsharp.NuGet-gdi/ReleaseNotes.txt b/src/foundation/nuget/src/PDFsharp.NuGet-gdi/ReleaseNotes.txt index a4187c64..82ed04c4 100644 --- a/src/foundation/nuget/src/PDFsharp.NuGet-gdi/ReleaseNotes.txt +++ b/src/foundation/nuget/src/PDFsharp.NuGet-gdi/ReleaseNotes.txt @@ -1,6 +1,6 @@ This is a preview version of PDFsharp 6.0.0 using .NET 6. -The package ’PdfSharp’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. +The package ’PdfSharp’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. The Target Framework is ’net6.0-windows’. We also publish packages that contain PDFsharp plus MigraDoc. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/nuget/src/PDFsharp.NuGet-wpf/ReleaseNotes.txt b/src/foundation/nuget/src/PDFsharp.NuGet-wpf/ReleaseNotes.txt index a4187c64..82ed04c4 100644 --- a/src/foundation/nuget/src/PDFsharp.NuGet-wpf/ReleaseNotes.txt +++ b/src/foundation/nuget/src/PDFsharp.NuGet-wpf/ReleaseNotes.txt @@ -1,6 +1,6 @@ This is a preview version of PDFsharp 6.0.0 using .NET 6. -The package ’PdfSharp’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. +The package ’PdfSharp’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. The Target Framework is ’net6.0-windows’. We also publish packages that contain PDFsharp plus MigraDoc. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/nuget/src/PDFsharp.NuGet/ReleaseNotes.txt b/src/foundation/nuget/src/PDFsharp.NuGet/ReleaseNotes.txt index a4187c64..82ed04c4 100644 --- a/src/foundation/nuget/src/PDFsharp.NuGet/ReleaseNotes.txt +++ b/src/foundation/nuget/src/PDFsharp.NuGet/ReleaseNotes.txt @@ -1,6 +1,6 @@ This is a preview version of PDFsharp 6.0.0 using .NET 6. -The package ’PdfSharp’ can be used on any platform including Windows and Linux. -The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. +The package ’PdfSharp’ can be used on any platform including Windows and Linux. The Target Framework is ’net6.0’. +The packages ’PDFsharp-gdi’ and ’PDFsharp-wpf’ can be used under Windows only. The Target Framework is ’net6.0-windows’. We also publish packages that contain PDFsharp plus MigraDoc. See the project docs site for further information: https://docs.pdfsharp.net/link/readme-v6.0.html diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/Capabilities.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/Capabilities.cs index 4804ee03..2d226aa6 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/Capabilities.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/Capabilities.cs @@ -80,7 +80,6 @@ public static class BackwardCompatibility /// public static bool DoNotCreateLastSection { get; set; } = false; - // TODO Space before on new page /// @@ -109,7 +108,6 @@ public static class BackwardCompatibility // public static FeatureNotAvailableAction GlyphsToPath { get; set; } = FeatureNotAvailableAction.DoNothing; //} - /// /// Compatibility settings for MigraDoc. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.IO/DdlScanner.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.IO/DdlScanner.cs index 8956656e..86aecd09 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.IO/DdlScanner.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.IO/DdlScanner.cs @@ -714,7 +714,6 @@ internal Symbol ScanSingleLineComment() return Symbol.Comment; } - /// /// Gets the current symbol. /// @@ -1340,7 +1339,6 @@ Symbol ScanPunctuator() // return str; //} - /// /// Scans verbatim strings like @"String with ""quoted"" text". /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/ErrorHelpers.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/ErrorHelpers.cs index 78a9dd98..d82e9079 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/ErrorHelpers.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/ErrorHelpers.cs @@ -21,7 +21,6 @@ static class TH // RENAME TODO { #region General Messages - //public static string? BaseStyleRequired => GetString(DomMsgID.BaseStyleRequired); //public static string? EmptyBaseStyle => GetString(DomMsgID.EmptyBaseStyle); @@ -106,7 +105,6 @@ public static ArgumentException ArgumentException_UndefinedBaseStyle(string base public static string InvalidDocumentObjectType => "The given document object is not valid in this context."; - //// ----- General Messages --------------------------------------------------------------------- //StyleExpected, //BaseStyleRequired, diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/LogMessages.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/LogMessages.cs index 95edf9e9..20d4881c 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/LogMessages.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/LogMessages.cs @@ -20,7 +20,6 @@ public static partial void ArgbValueIsConsideredEmptyColor( this ILogger logger, LogLevel level); - // What to log? // Image not found (not loadable, not found, ...) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/Meta.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/Meta.cs index d0d0edae..5bc4b68e 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/Meta.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Internals/Meta.cs @@ -192,7 +192,6 @@ public void SetNull(DocumentObject dom, string name) if (vd.ValueName is "Owner" or "Tag" or "Document" or "Section") continue; - if (vd.IsRefOnly is false) { //ValueDescriptors[index].SetNull(dom); diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/Series.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/Series.cs index 332511cf..11cfe0fd 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/Series.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/Series.cs @@ -19,7 +19,7 @@ public Series() /// /// Creates a deep copy of this object. /// - public new Series Clone() + public new Series Clone() => (Series)DeepCopy(); /// @@ -116,7 +116,11 @@ public LineFormat LineFormat public FillFormat FillFormat { get => Values.FillFormat ??= new(this); - set => Values.FillFormat = value; + set + { + SetParent(value); + Values.FillFormat = value; + } } /// @@ -306,7 +310,7 @@ internal SeriesValues(DocumentObject owner) : base(owner) public Color? MarkerForegroundColor { get => _color; - set => _color = DocumentObjectModel.Color.MakeNullIfEmpty(value); + set => _color = Color.MakeNullIfEmpty(value); } Color? _color; @@ -314,7 +318,12 @@ public Color? MarkerForegroundColor /// Gets or sets the internal nullable implementation value of the enclosing document object property. /// See enclosing document object class for documentation of this property. /// - public Color? MarkerBackgroundColor { get; set; } // BUG Differs from MarkerForegroundColor + public Color? MarkerBackgroundColor + { + get => _markerBackgroundColor; + set => _markerBackgroundColor = Color.MakeNullIfEmpty(value); + } + Color? _markerBackgroundColor; /// /// Gets or sets the internal nullable implementation value of the enclosing document object property. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TextArea.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TextArea.cs index 698c8aa8..d6b98f24 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TextArea.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TextArea.cs @@ -167,7 +167,11 @@ public string Style public ParagraphFormat Format { get => Values.Format ??= new(this); - set => Values.Format = value; + set + { + SetParent(value); + Values.Format = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TickLabels.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TickLabels.cs index 2a822b05..35cc0d02 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TickLabels.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes.Charts/TickLabels.cs @@ -68,7 +68,11 @@ public string Format public Font Font { get => Values.Font ??= new(this); - set => Values.Font = value; + set + { + SetParent(value); + Values.Font = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Image.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Image.cs index 31cf06ad..6c590fcf 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Image.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Image.cs @@ -13,7 +13,7 @@ public class Image : Shape /// public Image() { - BaseValues = new ImageValues(this); + BaseValues = new ImageValues(this); } /// @@ -35,7 +35,7 @@ public Image(string name) : this() /// /// Creates a deep copy of this object. /// - public new Image Clone() + public new Image Clone() => (Image)DeepCopy(); /// @@ -53,7 +53,7 @@ protected override object DeepCopy() } //#endregion -//#region Properties + //#region Properties /// /// Gets or sets the name of the image. /// @@ -99,7 +99,11 @@ public bool LockAspectRatio public PictureFormat PictureFormat { get => Values.PictureFormat ??= new(this); - set => Values.PictureFormat = value; + set + { + SetParent(value); + Values.PictureFormat = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs index 138df093..1f394c17 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs @@ -238,13 +238,13 @@ internal ShapeValues(DocumentObject owner) : base(owner) /// Gets or sets the internal nullable implementation value of the enclosing document object property. /// See enclosing document object class for documentation of this property. /// - public Unit? Height { get; set; } //= null; // BUG??? Unit.NullValue; + public Unit? Height { get; set; } /// /// Gets or sets the internal nullable implementation value of the enclosing document object property. /// See enclosing document object class for documentation of this property. /// - public Unit? Width { get; set; } //= null; // BUG??? Unit.NullValue; + public Unit? Width { get; set; } } } } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Cell.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Cell.cs index 5f277670..3c9244c1 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Cell.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Cell.cs @@ -6,6 +6,7 @@ using MigraDoc.DocumentObjectModel.Shapes; using MigraDoc.DocumentObjectModel.Shapes.Charts; using static MigraDoc.DocumentObjectModel.Tables.Row; +using System.Diagnostics; namespace MigraDoc.DocumentObjectModel.Tables { @@ -216,7 +217,11 @@ public string Style public ParagraphFormat Format { get => Values.Format ??= new(this); - set => Values.Format = value; + set + { + SetParent(value); + Values.Format = value; + } } /// @@ -234,7 +239,11 @@ public VerticalAlignment VerticalAlignment public Borders Borders { get => Values.Borders ??= new(this); - set => Values.Borders = value; + set + { + SetParent(value); + Values.Borders = value; + } } /// @@ -243,7 +252,11 @@ public Borders Borders public Shading Shading { get => Values.Shading ??= new(this); - set => Values.Shading = value; + set + { + SetParent(value); + Values.Shading = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Column.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Column.cs index ddfce208..f6c23e0c 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Column.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Column.cs @@ -136,7 +136,11 @@ public string Style public ParagraphFormat Format { get => Values.Format ??= new(this); - set => Values.Format = value; + set + { + SetParent(value); + Values.Format = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Table.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Table.cs index 88b24a1d..c57ecc55 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Table.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Tables/Table.cs @@ -257,7 +257,11 @@ public string Style public ParagraphFormat Format { get => Values.Format ??= new(this); - set => Values.Format = value; + set + { + SetParent(value); + Values.Format = value; + } } /// @@ -302,7 +306,11 @@ public Unit RightPadding public Borders Borders { get => Values.Borders ??= new(this); - set => Values.Borders = value; + set + { + SetParent(value); + Values.Borders = value; + } } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/CellComparer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/CellComparer.cs index 7c7a76f4..1482aba4 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/CellComparer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/CellComparer.cs @@ -46,7 +46,6 @@ public class CellComparer : IComparer // return cellLhs.Column.Index - cellRhs.Column.Index; //} - /// /// Compares the specified cells. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/ElementsExtensions.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/ElementsExtensions.cs index abf740e0..4fadfe3b 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/ElementsExtensions.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/ElementsExtensions.cs @@ -403,7 +403,6 @@ public static Unit GetUsedFormatValue(this DocumentObject documentObject, Func value.IsEmpty, Unit.Zero); } - /// /// Gets a directly or via style assigned Font sub-value. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/PdfFlattenVisitor.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/PdfFlattenVisitor.cs index cb4f7ac0..9aa1a615 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/PdfFlattenVisitor.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/PdfFlattenVisitor.cs @@ -169,15 +169,15 @@ internal override void VisitFormattedText(FormattedText formattedText) if (formattedText.Values.Font is null && format.Values.Font is not null) formattedText.Font = format.Values.Font.Clone(); else if (format.Values.Font is not null) - FlattenFont(formattedText.Values.Font, format.Values.Font); + FlattenFont(formattedText.Values.Font!, format.Values.Font); } var parentFont = GetParentFont(formattedText); - if (formattedText.Values.Font == null && parentFont != null) + if (formattedText.Values.Font is null && parentFont is not null) formattedText.Font = parentFont.Clone(); else if (parentFont != null) - FlattenFont(formattedText.Values.Font, parentFont); + FlattenFont(formattedText.Values.Font!, parentFont); } internal override void VisitHyperlink(Hyperlink hyperlink) @@ -197,7 +197,7 @@ internal override void VisitHyperlink(Hyperlink hyperlink) if (hyperlink.Values.Font is null && parentFont is not null) hyperlink.Font = parentFont.Clone(); else - FlattenFont(hyperlink.Values.Font, parentFont); + FlattenFont(hyperlink.Values.Font!, parentFont!); } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/VisitorBase.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/VisitorBase.cs index 39b22139..13a3b654 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/VisitorBase.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/VisitorBase.cs @@ -125,7 +125,7 @@ protected void FlattenListInfo(ListInfo listInfo, ListInfo refListInfo) /// /// Flattens the the specified document object. /// - protected void FlattenFont(Font? font, Font? refFont) // BUG params must be not-nullable + protected void FlattenFont(Font font, Font refFont) // BUG params must be not-nullable { if (font == null) throw new ArgumentNullException(nameof(font)); @@ -134,7 +134,7 @@ protected void FlattenFont(Font? font, Font? refFont) // BUG params must be not throw new ArgumentNullException(nameof(refFont)); font.Values.Name ??= refFont.Values.Name; - font.Values.Size ??= refFont.Values.Size; // TODO ??= + font.Values.Size ??= refFont.Values.Size; if (font.Values.Color.IsValueNullOrEmpty()) font.Values.Color = refFont.Values.Color; if (font.Values.Underline is null) @@ -441,7 +441,6 @@ internal override void VisitChart(Chart chart) else FlattenParagraphFormat(chart.Values.Format, style?.Values.ParagraphFormat ?? NRT.ThrowOnNull()); - FlattenLineFormat(chart.Values.LineFormat, null); FlattenFillFormat(chart.Values.FillFormat); diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Borders.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Borders.cs index 79f40c75..c8c493bf 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Borders.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Borders.cs @@ -56,7 +56,7 @@ public bool HasBorder(BorderType type) case BorderType.Horizontal: // Not used in MigraDoc 1.2. case BorderType.Vertical: // Not used in MigraDoc 1.2. #pragma warning restore CS0618 - return null; /*(Border?)GetValue(type.ToString(), GV.GetNull);*/ // BUG: why??? -> return null + return null; case BorderType.Left: return Values.Left; case BorderType.Right: @@ -456,7 +456,7 @@ internal void Serialize(Serializer serializer, Borders? refBorders) // enumerator.Reset(); // for (int idx = 0; idx < _index + 1; idx++) // enumerator.MoveNext(); -// return (((DictionaryEntry)enumerator.Current).Value as Border)!; // BUG: May return null +// return (((DictionaryEntry)enumerator.Current).Value as Border)!; // B_UG: May return null // } // } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Color.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Color.cs index b4e29dbd..2d1890b6 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Color.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Color.cs @@ -52,8 +52,7 @@ static Color() // Aqua == Cyan // Fuchsia == Magenta //var key = new Style(); ??? - if (!StandardColors.ContainsKey(d)) - StandardColors.Add(d, c); + StandardColors.TryAdd(d, c); } } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentElements.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentElements.cs index 6f271a07..d0f27456 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentElements.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentElements.cs @@ -32,7 +32,7 @@ internal DocumentElements(DocumentObject parent) : base(parent) /// /// Gets a document object by its index. /// - public new DocumentObject this[int index] => base[index]!; // BUG??? + public new DocumentObject this[int index] => base[index]!; // May return null in derived classes. /// /// Creates a deep copy of this object. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentObjectCollection.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentObjectCollection.cs index 979efdbc..fbd7d8c0 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentObjectCollection.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DocumentObjectCollection.cs @@ -256,7 +256,9 @@ void IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, bool visitChildren) /// /// The elements can contain null depending on the derived class. /// - protected List _elements = new(); // BUG Hack for generic implementation + List _elements = new(); + + internal IEnumerable Elements => _elements; #region IList Members diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DomSR.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DomSR.cs index d8af1592..1980fccc 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DomSR.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/DomSR.cs @@ -212,5 +212,4 @@ public static void TestResourceMessages() #endregion } - } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Font.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Font.cs index 6104b54b..eb97efd0 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Font.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Font.cs @@ -278,10 +278,10 @@ internal override void Serialize(Serializer serializer) /// internal void Serialize(Serializer serializer, Font? font) { - if (Parent is FormattedText) + if (Parent is FormattedText parent) { string fontStyle = ""; - if (((FormattedText)Parent).Values.Style is null) + if (parent.Values.Style is null) { // Check if we can use a DDL keyword. var notNull = CheckWhatIsNotNull(); @@ -292,21 +292,24 @@ internal void Serialize(Serializer serializer, Font? font) return; } - // BUG Check what this code really does... THHO4STLA: "Check if we can use a DDL keyword." - if (notNull == FontProperties.Bold && Bold) // or if (Values.Bold is true)??? + // Check if we can use a DDL keyword. + if (notNull == FontProperties.Bold && Bold) { + // Only Bold is set. serializer.Write("\\bold"); return; } if (notNull == FontProperties.Italic && Italic) { + // Only Italic is set. serializer.Write("\\italic"); return; } if (notNull == FontProperties.Color) { + // Only Color is set. serializer.Write(Invariant($"\\fontcolor({Color})")); return; } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeaderFooter.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeaderFooter.cs index 7205032a..97c783e8 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeaderFooter.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeaderFooter.cs @@ -32,7 +32,7 @@ internal HeaderFooter(DocumentObject parent) : base(parent) /// /// Creates a deep copy of this object. /// - public new HeaderFooter Clone() + public new HeaderFooter Clone() => (HeaderFooter)DeepCopy(); /// @@ -153,12 +153,12 @@ public void Add(TextFrame textFrame) /// /// Returns true if this is a header, false otherwise. /// - public bool IsHeader => ((HeadersFooters?)Parent)!.IsHeader; // BUG Exception if no parent? (following properties too) + public bool IsHeader => ((HeadersFooters?)Parent)?.IsHeader ?? false; /// /// Returns true if this is a footer, false otherwise. /// - public bool IsFooter => ((HeadersFooters?)Parent)!.IsFooter; + public bool IsFooter => ((HeadersFooters?)Parent)?.IsFooter ?? false; /// /// Returns true if this is a first page header or footer, false otherwise. @@ -245,11 +245,11 @@ internal override void Serialize(Serializer serializer) /// internal void Serialize(Serializer serializer, string prefix) { - if (IsNull()) // BUG??? + if (IsNull()) return; - // Do not write attributes if there are no elements. // BUG??? - if (Values.Elements is null) // BUG??? + // Do not write attributes if there are no elements. + if (Values.Elements is null) return; serializer.WriteComment(Values.Comment); @@ -280,7 +280,8 @@ void IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, bool visitChildren) /// public override bool IsNull() { - return false; // BUG??? + // Object exists and is therefore not null. + return false; } /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeadersFooters.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeadersFooters.cs index dba83338..7fb060a9 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeadersFooters.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/HeadersFooters.cs @@ -29,7 +29,7 @@ public HeadersFooters(DocumentObject parent) : base(parent) /// /// Creates a deep copy of this object. /// - public new HeadersFooters Clone() + public new HeadersFooters Clone() => (HeadersFooters)DeepCopy(); /// @@ -63,8 +63,8 @@ public bool IsHeader { get { - var sec = Parent as Section; // BUG??? Exception if parent is null? - //Section sec = (Section)Parent; // BUG??? Exception if parent is null? + // Return false if it has no parent. + var sec = Parent as Section; return sec?.Values.Headers == this; } } @@ -72,7 +72,15 @@ public bool IsHeader /// /// Returns true if this collection contains footers, false otherwise. /// - public bool IsFooter => !IsHeader; + public bool IsFooter // => !IsHeader; -> No, would be true if no parent. + { + get + { + // Return false if it has no parent. + var sec = Parent as Section; + return sec?.Values.Footers == this; + } + } /// /// Determines whether a particular header or footer exists. @@ -87,16 +95,14 @@ public bool HasHeaderFooter(HeaderFooterIndex index) /// Determines whether a particular header or footer exists. /// public bool HasHeaderFooter(HeaderFooter? item) - { - return item is not null && !item.IsNull(); - } + => item is not null && !item.IsNull(); /// /// Gets or sets the even page HeaderFooter of the HeadersFooters object. /// public HeaderFooter EvenPage { - get => Values.EvenPage ??= new HeaderFooter(this); + get => Values.EvenPage ??= new(this); set { SetParent(value); @@ -109,7 +115,7 @@ public HeaderFooter EvenPage /// public HeaderFooter FirstPage { - get => Values.FirstPage ??= new HeaderFooter(this); + get => Values.FirstPage ??= new(this); set { SetParent(value); diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Hyperlink.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Hyperlink.cs index c001322a..63221702 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Hyperlink.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Hyperlink.cs @@ -653,10 +653,6 @@ internal HyperlinkValues(DocumentObject owner) : base(owner) /// public bool? NoHyperlinkStyle { get; set; } - /// - /// Gets or sets the internal nullable implementation value of the enclosing document object property. - /// See enclosing document object class for documentation of this property. - /// /// /// Gets or sets the internal nullable implementation value of the enclosing document object property. /// See enclosing document object class for documentation of this property. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/PageSetup.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/PageSetup.cs index 81dbb7dc..50fd79ba 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/PageSetup.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/PageSetup.cs @@ -498,7 +498,7 @@ void EnsureNotFrozen() // It is still possible to change DefaultPageSetup directly via Values, // but that's your own bad luck. if (_frozen) - throw new InvalidOperationException("DefaultPageSetup must not be changed."); + throw new InvalidOperationException("DefaultPageSetup must not be changed. Change the PageSetup member of your Section. You can assign a Clone() of DefaultPageSetup to that PageSetup member as needed."); } bool _frozen; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Paragraph.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Paragraph.cs index b532306b..aa1e1baa 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Paragraph.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Paragraph.cs @@ -418,7 +418,6 @@ public string Comment set => Values.Comment = value; } - /// /// Allows the visitor object to visit the document object and its child objects. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphElements.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphElements.cs index 48b706e1..0880e572 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphElements.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphElements.cs @@ -30,7 +30,7 @@ internal ParagraphElements(DocumentObject parent) : base(parent) /// /// Gets a ParagraphElement by its index. /// - public new DocumentObject? this[int index] => base[index]; // BUG??? + public new DocumentObject? this[int index] => base[index]; /// /// Creates a deep copy of this object. @@ -48,8 +48,7 @@ public Text AddText(string text) { if (text == null) throw new ArgumentNullException(nameof(text)); -#if true - Text txt = null!; + Text txt = default!; string[] lines = text.Split('\n'); int lineCount = lines.Length; for (int line = 0; line < lineCount; line++) @@ -69,13 +68,7 @@ public Text AddText(string text) if (line < lineCount - 1) AddLineBreak(); } - return txt; // BUG return value does not make much sense to me. -#else - Text txt = new Text(); - txt.Content = text; - Add(txt); return txt; -#endif } /// @@ -493,7 +486,7 @@ internal override void Serialize(Serializer serializer) int count = Count; for (int index = 0; index < count; ++index) { - DocumentObject element = this[index]!; // BUG??? "!" added. + DocumentObject element = this[index]!; element.Serialize(serializer); } } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphFormat.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphFormat.cs index a0895c31..0a23f448 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphFormat.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/ParagraphFormat.cs @@ -320,7 +320,7 @@ internal void Serialize(Serializer serializer, string name, ParagraphFormat? ref { int pos = serializer.BeginContent(name); - if (!Values.Font.IsValueNullOrEmpty() && Parent!.GetType() != typeof(Style)) // BUG??? "!" added. + if (!Values.Font.IsValueNullOrEmpty() && Parent!.GetType() != typeof(Style)) Font.Serialize(serializer); // If a refFormat is specified, it is important to compare the fields and not the properties. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/TabStops.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/TabStops.cs index 23e418b5..956433df 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/TabStops.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/TabStops.cs @@ -1,6 +1,8 @@ // MigraDoc - Creating Documents on the Fly // See the LICENSE file in the solution root for more information. +using System.Collections; + namespace MigraDoc.DocumentObjectModel { /// @@ -38,15 +40,15 @@ internal TabStops(DocumentObject parent) : base(parent) /// /// Returns an enumerator that iterates through the tab stop collection. /// - public new IEnumerator GetEnumerator() - => _elements.Cast().GetEnumerator(); + public new IEnumerator GetEnumerator() + => Elements.Cast().GetEnumerator(); /// /// Gets a TabStop by its index. /// public new TabStop this[int index] #nullable disable - => (base[index] as TabStop)!; // HACK // BUG: May return null TODO: TabStop? Exception? + => (base[index] as TabStop)!; // HACK // BUG: May return null TODO: TabStop? Exception? #nullable restore /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Unit.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Unit.cs index c8e55091..f86b9ad9 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Unit.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel/Unit.cs @@ -440,7 +440,6 @@ public static implicit operator Unit(string? value) //NRT.ThrowOnNull("string parameter was null"); // BUG Throwing on null. return Zero; - var unit = Zero; value = value.Trim(); diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Resources/Messages2.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Resources/Messages2.cs index 52182fb1..d7d61d6e 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Resources/Messages2.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Resources/Messages2.cs @@ -63,7 +63,6 @@ internal static string ImageNotReadable(string imageName, string innerException) internal static string ObjectNotRenderable => FormatMessage(IDs.ObjectNotRenderable); - // ReSharper disable InconsistentNaming enum IDs { @@ -98,16 +97,11 @@ static ResourceManager ResourceManager static ResourceManager? _resourceManager; - static string FormatMessage(IDs id, params object[] args) { string? message; try { -#if true_ - //BUG - return $"BUG IN ResourceManager: {id.ToString()}"; -#else message = ResourceManager.GetString(id.ToString()); if (message != null) { @@ -122,7 +116,6 @@ static string FormatMessage(IDs id, params object[] args) else message = "<<>>"; return message; -#endif } catch (Exception /*ex*/) { diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestLayout.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestLayout.cs index 08aaafb6..703f33a3 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestLayout.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestLayout.cs @@ -3,8 +3,6 @@ using MigraDoc.DocumentObjectModel; -#pragma warning disable 1591 - namespace MigraDoc.Rendering.UnitTest { /// @@ -12,51 +10,64 @@ namespace MigraDoc.Rendering.UnitTest /// public class TestLayout { + /// + /// Creates two paragraphs. + /// public static void TwoParagraphs(string outputFile) { var doc = new Document(); - Section sec = doc.Sections.AddSection(); + var sec = doc.Sections.AddSection(); sec.PageSetup.TopMargin = 0; sec.PageSetup.BottomMargin = 0; - Paragraph par1 = sec.AddParagraph(); + var par1 = sec.AddParagraph(); TestParagraphRenderer.FillFormattedParagraph(par1); TestParagraphRenderer.GiveBorders(par1); par1.Format.SpaceAfter = "2cm"; par1.Format.SpaceBefore = "3cm"; - Paragraph par2 = sec.AddParagraph(); + var par2 = sec.AddParagraph(); TestParagraphRenderer.FillFormattedParagraph(par2); TestParagraphRenderer.GiveBorders(par2); par2.Format.SpaceBefore = "3cm"; - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = doc; + var renderer = new PdfDocumentRenderer + { + Document = doc + }; renderer.RenderDocument(); renderer.PdfDocument.Save(outputFile); } + /// + /// Creates thousand paragraphs. + /// public static void A1000Paragraphs(string outputFile) { - Document doc = new Document(); - Section sec = doc.Sections.AddSection(); + var doc = new Document(); + var sec = doc.Sections.AddSection(); sec.PageSetup.TopMargin = 0; sec.PageSetup.BottomMargin = 0; for (int idx = 1; idx <= 1000; ++idx) { - Paragraph par = sec.AddParagraph(); + var par = sec.AddParagraph(); par.AddText("Paragraph " + idx + ": "); TestParagraphRenderer.FillFormattedParagraph(par); TestParagraphRenderer.GiveBorders(par); } - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = doc; + var renderer = new PdfDocumentRenderer + { + Document = doc + }; renderer.RenderDocument(); renderer.PdfDocument.Save(outputFile); } + /// + /// Does nothing. + /// public static string DumpParagraph() { return ""; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestParagraphRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestParagraphRenderer.cs index 74a8afea..866ab957 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestParagraphRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestParagraphRenderer.cs @@ -3,8 +3,6 @@ using MigraDoc.DocumentObjectModel; -#pragma warning disable 1591 - namespace MigraDoc.Rendering.UnitTest { /// @@ -17,9 +15,9 @@ public class TestParagraphRenderer /// public static void TextAndBlanks(string pdfOutputFile) { - Document document = new Document(); - Section section = document.AddSection(); - Paragraph par = section.AddParagraph("Dies"); + var document = new Document(); + var section = document.AddSection(); + var par = section.AddParagraph("Dies"); for (int idx = 0; idx <= 40; ++idx) { par.AddCharacter(SymbolName.Blank); @@ -29,8 +27,7 @@ public static void TextAndBlanks(string pdfOutputFile) par.AddCharacter(SymbolName.Blank); par.AddText((idx + 2).ToString()); } - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(pdfOutputFile); } @@ -40,12 +37,11 @@ public static void TextAndBlanks(string pdfOutputFile) /// public static void Formatted(string pdfOutputFile) { - Document document = new Document(); - Section section = document.AddSection(); - Paragraph par = section.AddParagraph(); + var document = new Document(); + var section = document.AddSection(); + var par = section.AddParagraph(); FillFormattedParagraph(par); - PdfDocumentRenderer printer = new PdfDocumentRenderer(); - printer.Document = document; + var printer = new PdfDocumentRenderer { Document = document }; printer.RenderDocument(); printer.PdfDocument.Save(pdfOutputFile); } @@ -56,7 +52,7 @@ internal static void FillFormattedParagraph(Paragraph par) { if (idx < 60) { - FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Bold); + var formText = par.AddFormattedText((idx).ToString(), TextFormat.Bold); formText.Font.Size = 16; formText.AddText(" "); } @@ -67,7 +63,7 @@ internal static void FillFormattedParagraph(Paragraph par) } else { - FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Italic); + var formText = par.AddFormattedText((idx).ToString(), TextFormat.Italic); formText.Font.Size = 6; formText.AddText(" "); } @@ -82,11 +78,11 @@ internal static void FillFormattedParagraph(Paragraph par) /// public static void Alignment(string pdfOutputFile) { - Document document = new Document(); - Section section = document.AddSection(); + var document = new Document(); + var section = document.AddSection(); section.PageSetup.LeftMargin = 0; section.PageSetup.RightMargin = 0; - Paragraph par = section.AddParagraph(); + var par = section.AddParagraph(); // FillFormattedParagraph(par); // par.Format.Alignment = ParagraphAlignment.Left; @@ -105,8 +101,7 @@ public static void Alignment(string pdfOutputFile) par.Format.FirstLineIndent = "-2cm"; par.Format.LeftIndent = "2cm"; par.Format.RightIndent = "3cm"; - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(pdfOutputFile); } @@ -116,24 +111,23 @@ public static void Alignment(string pdfOutputFile) /// public static void Tabs(string pdfOutputFile) { - Document document = new Document(); - Section section = document.AddSection(); + var document = new Document(); + var section = document.AddSection(); section.PageSetup.LeftMargin = 0; section.PageSetup.RightMargin = 0; - Paragraph par = section.AddParagraph(); + var par = section.AddParagraph(); par.Format.TabStops.AddTabStop("20cm", TabAlignment.Right); par.AddText(" text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla."); //par.AddTab(); par.AddText(" ............ after tab bla bla bla."); - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(pdfOutputFile); } internal static void GiveBorders(Paragraph par) { - Borders borders = par.Format.Borders; + var borders = par.Format.Borders; borders.Top.Color = Colors.Gray; borders.Top.Width = 4; borders.Top.Style = BorderStyle.DashDot; @@ -160,14 +154,13 @@ internal static void GiveBorders(Paragraph par) /// public static void Borders(string outputFile) { - Document document = new Document(); - Section section = document.AddSection(); - Paragraph par = section.AddParagraph(); + var document = new Document(); + var section = document.AddSection(); + var par = section.AddParagraph(); FillFormattedParagraph(par); GiveBorders(par); - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(outputFile); } @@ -177,9 +170,9 @@ public static void Borders(string outputFile) /// public static void Fields(string outputFile) { - Document document = new Document(); - Section section = document.AddSection(); - Paragraph par = section.AddParagraph(); + var document = new Document(); + var section = document.AddSection(); + var par = section.AddParagraph(); par.AddText("Section: "); par.AddSectionField().Format = "ALPHABETIC"; par.AddLineBreak(); @@ -207,8 +200,7 @@ public static void Fields(string outputFile) par.AddText("PageRef: "); par.AddPageRefField("Egal"); - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); renderer.PdfDocument.Save(outputFile); } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestTable.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestTable.cs index 0217b70e..0023c2f2 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestTable.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/TestTable.cs @@ -26,14 +26,14 @@ public static void Borders(string outputFile) table.Rows.Height = 14; var row = table.AddRow(); var cell = row.Cells[0]; - cell!.Borders.Visible = true; + cell.Borders.Visible = true; cell.Borders.Left.Width = 8; cell.Borders.Right.Width = 2; cell.AddParagraph("First Cell"); row = table.AddRow(); cell = row.Cells[1]; - cell!.AddParagraph("Last Cell within this table"); + cell.AddParagraph("Last Cell within this table"); cell.Borders.Bottom.Width = 15; cell.Shading.Color = Colors.LightBlue; sec.AddParagraph("A Paragraph afterwards"); @@ -53,7 +53,7 @@ public static void CellMerge(string outputFile) table.AddColumn(); var row = table.AddRow(); var cell = row.Cells[0]; - cell!.MergeRight = 1; + cell.MergeRight = 1; cell.Borders.Visible = true; cell.Borders.Left.Width = 8; cell.Borders.Right.Width = 2; @@ -61,12 +61,12 @@ public static void CellMerge(string outputFile) row = table.AddRow(); cell = row.Cells[1]; - cell!.AddParagraph("Last Cell within this row"); + cell.AddParagraph("Last Cell within this row"); cell.MergeDown = 1; cell.Borders.Bottom.Width = 15; cell.Borders.Right.Width = 30; cell.Shading.Color = Colors.LightBlue; - row = table.AddRow(); + table.AddRow(); sec.AddParagraph("A Paragraph afterwards"); var renderer = new PdfDocumentRenderer { Document = document }; renderer.RenderDocument(); @@ -86,13 +86,14 @@ public static void VerticalAlign(string outputFile) row.HeightRule = RowHeightRule.Exactly; row.Height = 70; row.VerticalAlignment = VerticalAlignment.Center; - row[0]!.AddParagraph("First Cell"); - row[1]!.AddParagraph("Second Cell"); + row[0].AddParagraph("First Cell"); + row[1].AddParagraph("Second Cell"); sec.AddParagraph("A Paragraph afterwards."); - - PdfDocumentRenderer renderer = new PdfDocumentRenderer(); - renderer.Document = document; + PdfDocumentRenderer renderer = new() + { + Document = document + }; renderer.RenderDocument(); renderer.PdfDocument.Save(outputFile); } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/ValueDumper.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/ValueDumper.cs index b0be3e93..910b93a6 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/ValueDumper.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.UnitTest/ValueDumper.cs @@ -3,8 +3,6 @@ using System.Reflection; -#pragma warning disable 1591 - namespace MigraDoc.Rendering.UnitTest { /// @@ -12,9 +10,6 @@ namespace MigraDoc.Rendering.UnitTest /// class ValueDumper { - internal ValueDumper() - { } - internal static string DumpValues(object obj) { string dumpString = "[" + obj.GetType() + "]\r\n"; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Windows/DocumentPreview.xaml.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Windows/DocumentPreview.xaml.cs index 0bccf0aa..5484eaac 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Windows/DocumentPreview.xaml.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering.Windows/DocumentPreview.xaml.cs @@ -284,7 +284,6 @@ public Document? Document /// public DocumentRenderer? Renderer { get; private set; } - /// /// Helper class to render a single visual. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/BordersRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/BordersRenderer.cs index bbffa899..4423b8ff 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/BordersRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/BordersRenderer.cs @@ -152,7 +152,6 @@ internal void RenderHorizontally(BorderType type, XUnit left, XUnit top, XUnit w _gfx.DrawLine(pen, left + width, top, left, top); } - internal void RenderDiagonally(BorderType type, XUnit left, XUnit top, XUnit width, XUnit height) { XUnit borderWidth = GetWidth(type); diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ChartRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ChartRenderer.cs index fd7ffd21..e89395cc 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ChartRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ChartRenderer.cs @@ -46,7 +46,7 @@ internal ChartRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos? fieldIn FormattedTextArea? GetFormattedTextArea(TextArea? area) { - return GetFormattedTextArea(area, double.NaN); + return GetFormattedTextArea(area, Double.NaN); } void GetLeftRightVerticalPosition(out XUnit top, out XUnit bottom) @@ -185,22 +185,22 @@ internal override void Format(Area area, FormatInfo? previousFormatInfo) var formatInfo = (ChartFormatInfo)_renderInfo.FormatInfo; var textArea = _chart.Values.HeaderArea; - formatInfo.FormattedHeader = GetFormattedTextArea(textArea, _chart.Width.Point); // BUG is null ?? Throw(); + formatInfo.FormattedHeader = GetFormattedTextArea(textArea, _chart.Width.Point); textArea = _chart.Values.FooterArea; - formatInfo.FormattedFooter = GetFormattedTextArea(textArea, _chart.Width.Point); // BUG is null ?? Throw(); + formatInfo.FormattedFooter = GetFormattedTextArea(textArea, _chart.Width.Point); textArea = _chart.Values.LeftArea; - formatInfo.FormattedLeft = GetFormattedTextArea(textArea); // BUG is null ?? Throw(); + formatInfo.FormattedLeft = GetFormattedTextArea(textArea); textArea = _chart.Values.RightArea; - formatInfo.FormattedRight = GetFormattedTextArea(textArea); // BUG is null ?? Throw(); + formatInfo.FormattedRight = GetFormattedTextArea(textArea); textArea = _chart.Values.TopArea; - formatInfo.FormattedTop = GetFormattedTextArea(textArea, GetTopBottomWidth()); // BUG is null ?? Throw(); + formatInfo.FormattedTop = GetFormattedTextArea(textArea, GetTopBottomWidth()); textArea = _chart.Values.BottomArea; - formatInfo.FormattedBottom = GetFormattedTextArea(textArea, GetTopBottomWidth()); // BUG is null ?? Throw(); + formatInfo.FormattedBottom = GetFormattedTextArea(textArea, GetTopBottomWidth()); base.Format(area, previousFormatInfo); formatInfo.ChartFrame = ChartMapper.ChartMapper.Map(_chart); @@ -209,7 +209,6 @@ internal override void Format(Area area, FormatInfo? previousFormatInfo) // => throw new InvalidOperationException("Must not be null here."); } - XUnit AlignVertically(VerticalAlignment vAlign, XUnit top, XUnit bottom, XUnit height) { switch (vAlign) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/DocumentRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/DocumentRenderer.cs index 27f0bac2..90ff580e 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/DocumentRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/DocumentRenderer.cs @@ -1,6 +1,7 @@ // MigraDoc - Creating Documents on the Fly // See the LICENSE file in the solution root for more information. +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using PdfSharp.Pdf; using PdfSharp.Drawing; @@ -37,24 +38,12 @@ public void PrepareDocument() { var visitor = new PdfFlattenVisitor(); visitor.Visit(_document); - //_previousListNumbers = _previousListNumbers[ListType.NumberList1] = 0; _previousListNumbers[ListType.NumberList2] = 0; _previousListNumbers[ListType.NumberList3] = 0; _formattedDocument = new FormattedDocument(_document, this); - //REM: Size should not be necessary in this case. -#if true + XGraphics gfx = XGraphics.CreateMeasureContext(new XSize(2000, 2000), XGraphicsUnit.Point, XPageDirection.Downwards); -#else -#if GDI - XGraphics gfx = XGraphics.FromGraphics(Graphics.FromHwnd(IntPtr.Zero), new XSize(2000, 2000)); -#endif -#if WPF - XGraphics gfx = XGraphics.FromDrawingContext(null, new XSize(2000, 2000), XGraphicsUnit.Point); -#endif -#endif - // BUG? - // _previousListNumber = Int32.MinValue; _previousListInfo = null; _formattedDocument.Format(gfx); @@ -74,7 +63,7 @@ internal virtual void OnPrepareDocumentProgress(int value, int maximum) { if (PrepareDocumentProgress != null) { - // Invokes the delegates. + // Invokes the delegates. var e = new PrepareDocumentProgressEventArgs(value, maximum); PrepareDocumentProgress(this, e); } @@ -250,8 +239,9 @@ internal void AddOutline(int level, string title, PdfPage? destinationPage, XPoi return; var document = destinationPage.Owner; - if (document == null) - return; + Debug.Assert(document != null); + //if (document == null) + // return; var outlines = document.Outlines; while (--level > 0) diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs index fdc0be07..bb006968 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedDocument.cs @@ -126,7 +126,6 @@ void FormatHeadersFooters() } } - void FormatHeader(HeaderFooterPosition hfp, HeaderFooter? header) { if (header != null && !_formattedHeaders.ContainsKey(hfp)) @@ -140,7 +139,6 @@ void FormatHeader(HeaderFooterPosition hfp, HeaderFooter? header) } } - void FormatFooter(HeaderFooterPosition hfp, HeaderFooter? footer) { if (footer != null && !_formattedFooters.ContainsKey(hfp)) @@ -357,7 +355,6 @@ Rectangle GetFooterArea(Section section, int page) /// public int PageCount { get; private set; } - /// /// Gets information about the specified page. /// @@ -462,7 +459,6 @@ bool PositionHorizontallyToMargin(LayoutInfo layoutInfo) var rect = CalcContentRect(_currentPage); var align = GetCurrentAlignment(layoutInfo.HorizontalAlignment); - switch (align) { case ElementAlignment.Near: diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs index 76d3945f..18695a20 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedHeaderFooter.cs @@ -60,7 +60,6 @@ internal RenderInfo[] GetRenderInfos() XUnit ContentHeight => _contentHeight; XUnit _contentHeight; - bool IAreaProvider.PositionVertically(LayoutInfo layoutInfo) { IAreaProvider formattedDoc = _documentRenderer.FormattedDocument; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedTextArea.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedTextArea.cs index d3dfb64f..f8e5089c 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedTextArea.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/FormattedTextArea.cs @@ -56,7 +56,6 @@ internal XUnit InnerHeight } } - XUnit CalcInherentWidth() { XUnit inherentWidth = 0; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/LayoutInfo.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/LayoutInfo.cs index c7ae3573..ed71fb92 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/LayoutInfo.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/LayoutInfo.cs @@ -57,7 +57,7 @@ internal LayoutInfo() /// /// Gets or sets the Area needed by the content (including padding and borders for e.g. paragraphs). /// - public Area ContentArea { get; set; } = null!; //BUG + public Area ContentArea { get; set; } = default!; /// /// Gets or sets the value indicating whether the element shall appear on a new page. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/PageBreakRenderInfo.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/PageBreakRenderInfo.cs index 7eee2213..90e64759 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/PageBreakRenderInfo.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/PageBreakRenderInfo.cs @@ -21,7 +21,7 @@ public override FormatInfo FormatInfo get => _pageBreakFormatInfo; internal set => _pageBreakFormatInfo = (PageBreakFormatInfo)value; } - PageBreakFormatInfo _pageBreakFormatInfo = null!; // BUG NRT + PageBreakFormatInfo _pageBreakFormatInfo = default!; /// /// Gets the document object to which the layout information applies. Use the Tag property of DocumentObject to identify an object. @@ -31,6 +31,6 @@ public override DocumentObject DocumentObject get => _pageBreak; internal set => _pageBreak = (PageBreak)value; } - PageBreak _pageBreak = null!; // BUG NRT + PageBreak _pageBreak = default!; } } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphIterator.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphIterator.cs index 8507d5b4..815a0350 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphIterator.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphIterator.cs @@ -83,7 +83,6 @@ internal bool IsLastLeaf return SeekLastLeaf(); } - /// /// Gets the first leaf of the element tree. /// diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphRenderer.cs index fcbed132..b0c4bf39 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ParagraphRenderer.cs @@ -320,7 +320,6 @@ bool IsBlankOrSoftHyphen(DocumentObject docObj) return docObj is Text { Content: " " or "\u00AD" }; } - bool IsBlank(DocumentObject docObj) { if (docObj is Text { Content: " " }) @@ -737,7 +736,7 @@ void ReMeasureLine(ref LineInfo lineInfo) NRT.ThrowOnNull(); goOn = _currentLeaf != null && _currentLeaf.Current != _endLeaf.Current; if (goOn) - _currentLeaf = _currentLeaf!.GetNextLeaf(); // BUG in ReSharper: _currentLeaf cannot be null if goOn is true. + _currentLeaf = _currentLeaf!.GetNextLeaf(); } lineInfo.LineWidth = _currentLineWidth; lineInfo.WordsWidth = _currentWordsWidth; @@ -1077,7 +1076,7 @@ bool IgnoreBlank() var obj = prevIter?.Current; while (obj is BookmarkField) { - prevIter = prevIter?.GetPreviousLeaf(); // BUG??? ?? NRT.ThrowOnNull(); + prevIter = prevIter?.GetPreviousLeaf(); obj = prevIter?.Current; } if (obj == null) @@ -1321,7 +1320,7 @@ bool InitFormat(Area area, FormatInfo? previousFormatInfo) } else { - _currentLeaf = prevParaFormatInfo?.GetLastLineInfo().EndIter?.GetNextLeaf() ?? NRT.ThrowOnNull(); + _currentLeaf = prevParaFormatInfo?.GetLastLineInfo().EndIter?.GetNextLeaf(); // Do not check here. ?? NRT.ThrowOnNull(); _isFirstLine = false; ((ParagraphFormatInfo)_renderInfo.FormatInfo)._isStarting = false; } @@ -1548,7 +1547,6 @@ void FinishLayoutInfo() } } - XUnit PopSavedBlankWidth() { XUnit width = _savedBlankWidth; @@ -2617,7 +2615,7 @@ bool UnderlinePenChanged(XPen? pen) bool _isFirstLine; bool _isLastLine; VerticalLineInfo _currentVerticalInfo; - Area _formattingArea = null!; // BUG check + Area _formattingArea = default!; XUnit _currentYPosition; XUnit _currentXPosition; ParagraphIterator? _currentLeaf; @@ -2625,8 +2623,8 @@ bool UnderlinePenChanged(XPen? pen) ParagraphIterator? _endLeaf; bool _reMeasureLine; XUnit _minWidth = 0; - Dictionary _imageRenderInfos = null!; // BUG check - List _tabOffsets = null!; // BUG check + Dictionary _imageRenderInfos = default!; + List _tabOffsets = default!; DocumentObject? _lastTab; bool _lastTabPassed; XUnit _lastTabPosition; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/Renderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/Renderer.cs index 9adbdeff..5542c9eb 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/Renderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/Renderer.cs @@ -138,8 +138,11 @@ internal FieldInfos FieldInfos if (renderer != null) renderer._documentRenderer = documentRenderer; - +#if DEBUG // TODO Investigate why we can come here with "null". + if (renderer == null) + ((Action)(() => { }))(); // A place for a break point; +#endif return renderer!; // BUG??? => return type "Renderer?" // ?? NRT.ThrowOnNull(); } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ShapeRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ShapeRenderer.cs index a152778f..4ae1d661 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ShapeRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/ShapeRenderer.cs @@ -91,7 +91,6 @@ internal override void Format(Area area, FormatInfo? previousFormatInfo) FinishLayoutInfo(area); } - void FinishLayoutInfo(Area area) { var layoutInfo = _renderInfo.LayoutInfo; diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TableRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TableRenderer.cs index 2a24455f..50bb3e6c 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TableRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TableRenderer.cs @@ -136,8 +136,8 @@ void EqualizeRoundedCornerBorders(Cell cell) void RenderShading(Cell cell, Rectangle innerRect) { - var shadeRenderer = new ShadingRenderer(_gfx, cell.Shading); - shadeRenderer.Render(innerRect.X, innerRect.Y, innerRect.Width, innerRect.Height, cell.RoundedCorner); + var shadingRenderer = new ShadingRenderer(_gfx, cell.Shading); + shadingRenderer.Render(innerRect.X, innerRect.Y, innerRect.Width, innerRect.Height, cell.RoundedCorner); } void RenderBorders(Cell cell, Rectangle innerRect) @@ -337,7 +337,7 @@ void InitFormat(Area area, FormatInfo? previousFormatInfo) // Equalize the two borders, that are used to determine a rounded corner's border. // This way the innerWidth of the cell, which is got by the saved _formattedCells, is the same regardless of which corner relevant border is set. - foreach (var row in _table.Rows.Cast()) // BUG Make better enumerator. + foreach (var row in _table.Rows.Cast()) { foreach (var cell in row.Cells.Cast()) EqualizeRoundedCornerBorders(cell); @@ -502,7 +502,7 @@ void FinishLayoutInfo(Area area, XUnit currentHeight, XUnit startingHeight) else if (_table.Rows.Alignment == RowAlignment.Left) { XUnit leftOffset = LeftBorderOffset; - leftOffset += _table.Columns[0]!.LeftPadding; // BUG check + leftOffset += _table.Columns[0].LeftPadding; layoutInfo.Left = -leftOffset; } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TextFrameFormatInfo.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TextFrameFormatInfo.cs index 36c3692c..57e7256e 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TextFrameFormatInfo.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TextFrameFormatInfo.cs @@ -8,6 +8,6 @@ namespace MigraDoc.Rendering /// sealed class TextFrameFormatInfo : ShapeFormatInfo { - internal FormattedTextFrame FormattedTextFrame = null!; // BUG + internal FormattedTextFrame FormattedTextFrame = default!; } } diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TopDownFormatter.cs b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TopDownFormatter.cs index 7e407f9a..46ffe514 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TopDownFormatter.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.Rendering/Rendering/TopDownFormatter.cs @@ -75,13 +75,13 @@ public void FormatOnAreas(XGraphics gfx, bool topLevel) } var renderer = Renderer.Create(gfx, _documentRenderer, docObj, _areaProvider.AreaFieldInfos); - if (renderer != null) // "Slightly hacked" for legends: see below + if (renderer != null) // "Slightly hacked" for legends: see below. renderer.MaxElementHeight = maxHeight; if (topLevel && _documentRenderer.HasPrepareDocumentProgress) { _documentRenderer.OnPrepareDocumentProgress(_documentRenderer.ProgressCompleted + idx + 1, - _documentRenderer.ProgressMaximum); + _documentRenderer.ProgressMaximum); } // "Slightly hacked" for legends: they are rendered as part of the chart. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/MigraDoc.RtfRendering.csproj b/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/MigraDoc.RtfRendering.csproj index 6894f334..5cd4379f 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/MigraDoc.RtfRendering.csproj +++ b/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/MigraDoc.RtfRendering.csproj @@ -21,6 +21,16 @@ + + + + + + + + + +