element
}
///
- /// Gets the text content of the cell's elements as a string.
+ /// Gets the text content of the cell’s elements as a string.
///
/// The cell.
/// Text content as string.
@@ -195,7 +194,7 @@ public static string GetText(this Cell cell)
}
///
- /// Gets the text content of the paragraph's elements as a string.
+ /// Gets the text content of the paragraph’s elements as a string.
///
/// The paragraph.
/// Text content as string.
@@ -205,7 +204,7 @@ public static string GetText(this Paragraph paragraph)
}
///
- /// Gets the text content of the hyperlinks's elements as a string.
+ /// Gets the text content of the hyperlinks’s elements as a string.
///
/// The hyperlink.
/// Text content as string.
@@ -362,7 +361,7 @@ public static Unit GetUsedFormatValue(this DocumentObject documentObject, FuncThe empty value to return if the value is not assigned or could not be determined.
public static T GetUsedFormatValue(this DocumentObject documentObject, Func getValue, Func isEmpty, T emptyValue)
{
- // Won't work properly inside of tables, as the formats of table columns and rows are not considered as used value. Supplement this when needed.
+ // Won’t work properly inside of tables, as the formats of table columns and rows are not considered as used value. Supplement this when needed.
T result;
var format = documentObject.GetFormat();
@@ -391,7 +390,7 @@ public static T GetUsedFormatValue(this DocumentObject documentObject, FuncThe empty value to return if the value is not assigned or could not be determined.
public static T GetUsedFormatValue(this DocumentObject documentObject, Func getValue, Func isEmpty, T emptyValue)
{
- // Won't work properly inside of tables, as the formats of table columns and rows are not considered as used value. Supplement this when needed.
+ // Won’t work properly inside of tables, as the formats of table columns and rows are not considered as used value. Supplement this when needed.
T result;
var font = documentObject.GetFont();
@@ -440,8 +439,8 @@ public static T GetUsedFormatValue(this DocumentObject documentObject, Func= columns)
throw TH.InvalidOperationException_MergeRightTooLarge(rwIdx, clmIdx, mergeRight);
- for (int idxMergedRows = 0; idxMergedRows <= mergeDown; ++idxMergedRows)
+ for (int idxMergedRows = 0; idxMergedRows <= mergeDown; idxMergedRows++)
{
- for (int idxMergedColumns = 0; idxMergedColumns <= mergeRight; ++idxMergedColumns)
+ for (int idxMergedColumns = 0; idxMergedColumns <= mergeRight; idxMergedColumns++)
{
flags[rwIdx + idxMergedRows, clmIdx + idxMergedColumns] = true;
}
@@ -220,8 +220,7 @@ Borders GetEffectiveBordersInternal(Cell cell, bool considerHeadingRows, int? co
if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Left) > GetEffectiveBorderWidth(borders, BorderType.Right))
borders.SetValue("Right", GetBorderFromBorders(nbrBrdrs, BorderType.Left));
}
-
-
+
// If considering heading rows and if cellRowIndex is an index a header is been inserted at, override topRowIndex with the last heading row.
// This way for rows after a repeated heading row the original last heading row is considered as the top neighbor for top border determination
// instead of the last content row on the page before.
@@ -237,7 +236,7 @@ Borders GetEffectiveBordersInternal(Cell cell, bool considerHeadingRows, int? co
var topNeighbor = GetNeighborTop(cellIdx, topRowIndexOverride);
// If not considering heading rows and if the topNeighbor is a heading row, set it to null to ignore it for top border determination.
- // This way the first content row's top border doesn't possibly get the bottom border of the original last heading row.
+ // This way the first content row’s top border doesn’t possibly get the bottom border of the original last heading row.
// This behaviour is wanted for RTF only, where all heading rows repetitions are rendered with their border formatting in the RTF application when displaying the
// document and where content row movement or insertion in the RTF application must not copy formatting values that actually belong to the original last heading row.
if (!considerHeadingRows && topNeighbor?.Row.HeadingFormat == true)
@@ -250,7 +249,6 @@ Borders GetEffectiveBordersInternal(Cell cell, bool considerHeadingRows, int? co
borders.SetValue("Top", GetBorderFromBorders(nbrBrdrs, BorderType.Bottom));
}
-
var bottomNeighbor = GetNeighborBottom(cellIdx);
if (bottomNeighbor != null && bottomNeighbor.RoundedCorner != RoundedCorner.TopLeft && bottomNeighbor.RoundedCorner != RoundedCorner.TopRight)
{
@@ -301,7 +299,7 @@ Borders GetEffectiveBordersInternal(Cell cell, bool considerHeadingRows, int? co
///
/// Returns the border of the given borders-object of the specified type (top, bottom, ...).
- /// If that border doesn't exist, it returns a new border object that inherits all properties from the given borders object.
+ /// If that border doesn’t exist, it returns a new border object that inherits all properties from the given borders object.
///
static Border GetBorderFromBorders(Borders borders, BorderType type)
{
@@ -397,7 +395,7 @@ static Unit GetEffectiveBorderWidth(Borders? borders, BorderType type)
}
///
- /// Gets the specified cell's uppermost neighbor at the specified position.
+ /// Gets the specified cell’s uppermost neighbor at the specified position.
///
[Obsolete("Use GetNeighborTop, GetNeighborBottom, GetNeighborLeft, GetNeighborRight instead.")]
Cell? GetNeighbor(int cellIdx, NeighborPosition position)
@@ -428,7 +426,7 @@ static Unit GetEffectiveBorderWidth(Borders? borders, BorderType type)
if (cell2.Row.Index == cell.Row.Index)
return cell2;
}
- for (int index = cellIdx + 1; index < Count; ++index)
+ for (int index = cellIdx + 1; index < Count; index++)
{
var currCell = this[index];
if (IsNeighbor(cell, currCell, position))
@@ -437,7 +435,7 @@ static Unit GetEffectiveBorderWidth(Borders? borders, BorderType type)
break;
case NeighborPosition.Bottom:
- for (int index = cellIdx + 1; index < Count; ++index)
+ for (int index = cellIdx + 1; index < Count; index++)
{
var currCell = this[index];
if (IsNeighbor(cell, currCell, position))
@@ -503,7 +501,7 @@ static Unit GetEffectiveBorderWidth(Borders? borders, BorderType type)
if (cell2.Row.Index == cell.Row.Index)
return cell2;
}
- for (var index = cellIdx + 2; index < Count; ++index)
+ for (var index = cellIdx + 2; index < Count; index++)
{
var currCell = this[index];
if (IsNeighborRight(cell, currCell))
@@ -518,7 +516,7 @@ static Unit GetEffectiveBorderWidth(Borders? borders, BorderType type)
if (cell.Row.Index + cell.MergeDown == cell.Table.Rows.Count - 1)
return null;
- for (var index = cellIdx + 1; index < Count; ++index)
+ for (var index = cellIdx + 1; index < Count; index++)
{
var currCell = this[index];
if (IsNeighborBottom(cell, currCell))
@@ -613,7 +611,6 @@ bool IsNeighborTop(Cell cell1, Cell cell2, int? topRowIndexOverride = null)
c2CI <= c1CI;
}
-
readonly SortedSet _headerInsertionRowIndices = new();
///
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 8699a716..2dbe6bb1 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
@@ -21,7 +21,7 @@ internal override void VisitDocumentElements(DocumentElements elements)
#if true
// New version without sorted list.
int count = elements.Count;
- for (int idx = 0; idx < count; ++idx)
+ for (int idx = 0; idx < count; idx++)
{
if (elements[idx] is Paragraph paragraph)
{
@@ -41,7 +41,7 @@ internal override void VisitDocumentElements(DocumentElements elements)
#else
SortedList splitParaList = new SortedList();
- for (int idx = 0; idx < elements.Count; ++idx)
+ for (int idx = 0; idx < elements.Count; idx++)
{
Paragraph paragraph = elements[idx] as Paragraph;
if (paragraph != null)
@@ -53,7 +53,7 @@ internal override void VisitDocumentElements(DocumentElements elements)
}
int insertedObjects = 0;
- for (int idx = 0; idx < splitParaList.Count; ++idx)
+ for (int idx = 0; idx < splitParaList.Count; idx++)
{
int insertPosition = (int)splitParaList.GetKey(idx);
Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx);
@@ -78,7 +78,7 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
List textIndices = new List();
if (elements is ParagraphElements)
{
- for (int idx = 0; idx < elements.Count; ++idx)
+ for (int idx = 0; idx < elements.Count; idx++)
{
if (elements[idx] is Text)
textIndices.Add(idx);
@@ -97,7 +97,7 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
for (var chIdx = 0; chIdx < content.Length; chIdx++)
{
var ch = content[chIdx];
- // TODO Add support for other breaking spaces (en space, em space, &c.).
+ // TODO_OLD Add support for other breaking spaces (en space, em space, &c.).
switch (ch)
{
case ' ':
@@ -117,14 +117,14 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
case '-': // minus.
currentString.Append('-');
- // Recognize minus as a sign, if it's the first char of the currently processed string...
+ // Recognize minus as a sign, if it’s the first char of the currently processed string...
bool isSign;
if (currentString.Length != 1)
isSign = false;
else
{
var nextIdx = chIdx + 1;
- // ...and if it's followed by a number...
+ // ...and if it’s followed by a number...
if (nextIdx < content.Length && char.IsNumber(content[nextIdx]))
isSign = true;
else
@@ -190,10 +190,10 @@ internal override void VisitFormattedText(FormattedText formattedText)
var document = formattedText.Document;
ParagraphFormat? format = null;
- var style = document.Styles[formattedText.Values.Style]; // BUG??? We get "null" for "null".
+ var style = document.Styles[formattedText.Values.Style]; // BUG_OLD??? We get "null" for "null".
if (style != null)
format = style.Values.ParagraphFormat;
- else if (!String.IsNullOrEmpty(formattedText.Values.Style) /*!= ""*/) // BUG??? Treat "null" like empty string.
+ else if (!String.IsNullOrEmpty(formattedText.Values.Style) /*!= ""*/) // BUG_OLD??? Treat "null" like empty string.
format = document.Styles[StyleNames.InvalidStyleName]?.Values.ParagraphFormat ?? throw new InvalidOperationException("Style does not exist.");
if (format != null)
@@ -201,7 +201,7 @@ 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);
+ VisitorBase.FlattenFont(formattedText.Values.Font!, format.Values.Font);
}
var parentFont = GetParentFont(formattedText);
@@ -209,38 +209,37 @@ internal override void VisitFormattedText(FormattedText formattedText)
if (formattedText.Values.Font is null && parentFont is not null)
formattedText.Font = parentFont.Clone();
else if (parentFont != null)
- FlattenFont(formattedText.Values.Font!, parentFont);
+ VisitorBase.FlattenFont(formattedText.Values.Font!, parentFont);
}
internal override void VisitHyperlink(Hyperlink hyperlink)
{
// If NoHyperlinkStyle is set to true, the Hyperlink shall look like the surrounding text without using the Hyperlink Style.
- // May be used for text references, e. g. in tables, which shall not be rendered as links.
+ // May be used for text references, e.g. in tables, which shall not be rendered as links.
if (!hyperlink.NoHyperlinkStyle)
{
- var styleFont = hyperlink.Document.Styles[StyleNames.Hyperlink]!.Font; // BUG ??? "!"
+ var styleFont = hyperlink.Document.Styles[StyleNames.Hyperlink]!.Font; // BUG_OLD ??? "!"
if (hyperlink.Values.Font is null)
hyperlink.Font = styleFont.Clone();
else
- FlattenFont(hyperlink.Values.Font, styleFont);
+ VisitorBase.FlattenFont(hyperlink.Values.Font, styleFont);
}
var parentFont = GetParentFont(hyperlink);
if (hyperlink.Values.Font is null && parentFont is not null)
hyperlink.Font = parentFont.Clone();
else
- FlattenFont(hyperlink.Values.Font!, parentFont!);
+ VisitorBase.FlattenFont(hyperlink.Values.Font!, parentFont!);
}
///
/// Get the font for the parent of a given object.
///
/// The object to start with.
- ///
/// Exception that is thrown of the parent object is neither Paragraph nor Hyperlink or FormattedText.
protected Font? GetParentFont(DocumentObject obj)
{
- DocumentObject parentElements = DocumentRelations.GetParent(obj) ?? NRT.ThrowOnNull(); // BUG Throwing on null;
+ DocumentObject parentElements = DocumentRelations.GetParent(obj) ?? NRT.ThrowOnNull(); // BUG_OLD Throwing on null;
DocumentObject? parentObject = DocumentRelations.GetParent(parentElements);
Font? parentFont;
if (parentObject is Paragraph paragraph)
diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/RtfFlattenVisitor.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/RtfFlattenVisitor.cs
index 914e0b9f..b5095362 100644
--- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/RtfFlattenVisitor.cs
+++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Visitors/RtfFlattenVisitor.cs
@@ -18,14 +18,14 @@ internal override void VisitFormattedText(FormattedText formattedText)
if (style != null)
format = style.Values.ParagraphFormat;
else if (!String.IsNullOrEmpty(formattedText.Values.Style))
- format = document.Styles[StyleNames.InvalidStyleName]!.Values.ParagraphFormat; // BUG: Clone here?
+ format = document.Styles[StyleNames.InvalidStyleName]!.Values.ParagraphFormat; // BUG_OLD: Clone here?
if (format != null)
{
if (formattedText.Values.Font is null)
- formattedText.Font = format.Values.Font?.Clone() ?? NRT.ThrowOnNull(); // BUG Throwing if format.Values.Font is null
+ formattedText.Font = format.Values.Font?.Clone() ?? NRT.ThrowOnNull(); // BUG_OLD Throwing if format.Values.Font is null
else if (format.Values.Font is not null)
- FlattenFont(formattedText.Values.Font, format.Values.Font);
+ VisitorBase.FlattenFont(formattedText.Values.Font, format.Values.Font);
}
}
@@ -35,7 +35,7 @@ internal override void VisitHyperlink(Hyperlink hyperlink)
if (hyperlink.Values.Font is null)
hyperlink.Font = styleFont.Clone();
else
- FlattenFont(hyperlink.Values.Font, styleFont);
+ VisitorBase.FlattenFont(hyperlink.Values.Font, styleFont);
}
}
}
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 13a3b654..987686f3 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
@@ -1,10 +1,13 @@
-// MigraDoc - Creating Documents on the Fly
+// MigraDoc - Creating Documents on the Fly
// See the LICENSE file in the solution root for more information.
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
+// ReSharper disable ConvertIfStatementToNullCoalescingAssignment
+#pragma warning disable IDE0074 // Use compound assignment
+
namespace MigraDoc.DocumentObjectModel.Visitors
{
///
@@ -23,9 +26,9 @@ public override void Visit(DocumentObject documentObject)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenParagraphFormat(ParagraphFormat format, ParagraphFormat? refFormat)
+ protected static void FlattenParagraphFormat(ParagraphFormat format, ParagraphFormat? refFormat)
{
if (refFormat != null)
{
@@ -51,6 +54,7 @@ protected void FlattenParagraphFormat(ParagraphFormat format, ParagraphFormat? r
if (values.LineSpacingRule is null)
values.LineSpacingRule = refValues.LineSpacingRule;
+
if (values.LineSpacing is null)
values.LineSpacing = refValues.LineSpacing;
@@ -79,7 +83,7 @@ protected void FlattenParagraphFormat(ParagraphFormat format, ParagraphFormat? r
}
}
else if (refValues.Font is not null)
- FlattenFont(values.Font, refValues.Font);
+ VisitorBase.FlattenFont(values.Font, refValues.Font);
if (values.Shading is null)
{
@@ -110,9 +114,9 @@ protected void FlattenParagraphFormat(ParagraphFormat format, ParagraphFormat? r
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenListInfo(ListInfo listInfo, ListInfo refListInfo)
+ protected static void FlattenListInfo(ListInfo listInfo, ListInfo refListInfo)
{
if (listInfo.Values.ContinuePreviousList is null)
listInfo.Values.ContinuePreviousList = refListInfo.Values.ContinuePreviousList;
@@ -123,9 +127,9 @@ protected void FlattenListInfo(ListInfo listInfo, ListInfo refListInfo)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenFont(Font font, Font refFont) // BUG params must be not-nullable
+ protected static void FlattenFont(Font font, Font refFont)
{
if (font == null)
throw new ArgumentNullException(nameof(font));
@@ -151,9 +155,9 @@ protected void FlattenFont(Font font, Font refFont) // BUG params must be not-n
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenShading(Shading shading, Shading refShading)
+ protected static void FlattenShading(Shading shading, Shading refShading)
{
//fClear?
if (shading.Values.Visible is null)
@@ -163,9 +167,9 @@ protected void FlattenShading(Shading shading, Shading refShading)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected Border FlattenedBorderFromBorders(Border? border, Borders parentBorders)
+ protected static Border FlattenedBorderFromBorders(Border? border, Borders parentBorders)
{
if (border == null)
border = new Border(parentBorders);
@@ -186,9 +190,9 @@ protected Border FlattenedBorderFromBorders(Border? border, Borders parentBorder
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenBorders(Borders borders, Borders refBorders)
+ protected static void FlattenBorders(Borders borders, Borders refBorders)
{
borders.Values.Visible ??= refBorders.Values.Visible;
if (borders.Values.Width.IsValueNullOrEmpty())
@@ -232,9 +236,9 @@ protected void FlattenBorders(Borders borders, Borders refBorders)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenBorder(Border border, Border refBorder)
+ protected static void FlattenBorder(Border border, Border refBorder)
{
border.Values.Visible ??= refBorder.Values.Visible;
@@ -252,9 +256,9 @@ protected void FlattenBorder(Border border, Border refBorder)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenTabStops(TabStops tabStops, TabStops refTabStops)
+ protected static void FlattenTabStops(TabStops tabStops, TabStops refTabStops)
{
if (!tabStops.TabsCleared)
{
@@ -267,9 +271,9 @@ protected void FlattenTabStops(TabStops tabStops, TabStops refTabStops)
for (int i = 0; i < tabStops.Count; i++)
{
- TabStop tabStop = tabStops[i];
+ var tabStop = tabStops[i];
if (!tabStop.AddTab)
- tabStops.RemoveObjectAt(i);
+ tabStops.RemoveObjectAt(i--);
}
// The TabStopCollection is complete now.
@@ -278,50 +282,96 @@ protected void FlattenTabStops(TabStops tabStops, TabStops refTabStops)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenPageSetup(PageSetup pageSetup, PageSetup refPageSetup)
+ protected static void FlattenPageSetup(PageSetup pageSetup, PageSetup refPageSetup)
{
- if (pageSetup.Values.PageWidth.IsValueNullOrEmpty() && pageSetup.Values.PageHeight is null)
+ var definesOrientation = pageSetup.Values.Orientation is not null;
+
+ // Inherit orientation now, as the value is needed below.
+ if (pageSetup.Values.Orientation is null)
+ pageSetup.Values.Orientation = refPageSetup.Values.Orientation;
+
+ Debug.Assert(pageSetup.Values.Orientation is not null);
+
+ var realizeOrientation = false; // The default is updating the Orientation value due to PageWidth and PageHeight instead of realizing the Orientation.
+
+ // PageWidth and PageHeight are not set.
+ if (pageSetup.Values.PageWidth.IsValueNullOrEmpty() && pageSetup.Values.PageHeight.IsValueNullOrEmpty())
{
+ // If all values are null, inherit them from refPageSetup.
if (pageSetup.Values.PageFormat is null)
{
pageSetup.Values.PageWidth = refPageSetup.Values.PageWidth;
pageSetup.Values.PageHeight = refPageSetup.Values.PageHeight;
pageSetup.Values.PageFormat = refPageSetup.Values.PageFormat;
+
+ // Realize Orientation, if no PageWidth, PageHeight and PageFormat, but Orientation was set for this PageSetup.
+ if (definesOrientation)
+ realizeOrientation = true;
}
+ // If only PageFormat is set, calculate PageWidth and PageHeight from PageFormat.
else
{
+ // Realize Orientation, if only PageFormat was set for this PageSetup.
+ realizeOrientation = true;
+
// Cannot use properties as out parameters, so use local vars.
PageSetup.GetPageSize(pageSetup.PageFormat, out Unit width, out Unit height);
pageSetup.Values.PageWidth = width;
pageSetup.Values.PageHeight = height;
}
}
+ // At least PageWidth or PageHeight is set.
else
{
if (pageSetup.Values.PageWidth.IsValueNullOrEmpty())
{
+ // If only PageHeight is set, inherit PageFormat and PageWidth.
if (pageSetup.Values.PageFormat is null)
- pageSetup.Values.PageHeight = refPageSetup.Values.PageHeight;
+ {
+ pageSetup.Values.PageWidth = refPageSetup.Values.PageWidth;
+ pageSetup.Values.PageFormat = refPageSetup.Values.PageFormat;
+ }
+ // If only PageHeight and PageFormat are set, calculate PageWidth from PageFormat.
else
{
- PageSetup.GetPageSize(pageSetup.PageFormat, out _, out Unit height);
- pageSetup.Values.PageHeight = height;
+ PageSetup.GetPageSize(pageSetup.PageFormat, out Unit width, out Unit height);
+ // Take PageWidth according to page format orientation, even if Orientation may be updated later due to the final PageWidth and PageHeight.
+ pageSetup.Values.PageWidth = pageSetup.Orientation == Orientation.Landscape ? height : width;
}
}
else if (pageSetup.Values.PageHeight.IsValueNullOrEmpty())
{
+ // If only PageWidth is set, inherit PageFormat and PageHeight.
if (pageSetup.Values.PageFormat is null)
- pageSetup.Values.PageWidth = refPageSetup.Values.PageWidth;
+ {
+ pageSetup.Values.PageHeight = refPageSetup.Values.PageHeight;
+ pageSetup.Values.PageFormat = refPageSetup.Values.PageFormat;
+ }
+ // If only PageWidth and PageFormat are set, calculate PageHeight from PageFormat.
else
{
- PageSetup.GetPageSize(pageSetup.PageFormat, out Unit width, out _);
- pageSetup.Values.PageWidth = width;
+ PageSetup.GetPageSize(pageSetup.PageFormat, out Unit width, out Unit height);
+ // Take PageHeight according to page format orientation, even if Orientation may be updated later due to the final PageWidth and PageHeight.
+ pageSetup.Values.PageHeight = pageSetup.Orientation == Orientation.Landscape ? width : height;
}
}
}
+ Debug.Assert(!pageSetup.Values.PageWidth.IsValueNullOrEmpty() || !pageSetup.Values.PageHeight.IsValueNullOrEmpty());
+
+ // If the page size is newly initialized from PageFormat and/or Orientation only, swap PageWidth and PageHeight due to Orientation, if necessary.
+ if (realizeOrientation)
+ RealizeOrientation(pageSetup);
+ // If the page size is inherited or set by PageWidth and PageHeight, update Orientation due to PageWidth and PageHeight.
+ // For inherited PageFormat values, PageWidth and PageHeight were already swapped for the source PageSetup, if necessary.
+ else
+ UpdateOrientation(pageSetup);
+
+ Debug.Assert((pageSetup.Values.Orientation == Orientation.Portrait && pageSetup.Values.PageWidth <= pageSetup.Values.PageHeight) ||
+ (pageSetup.Values.Orientation == Orientation.Landscape && pageSetup.Values.PageWidth > pageSetup.Values.PageHeight));
+
// if (pageSetup.pageWidth.IsNull)
// pageSetup.pageWidth = refPageSetup.pageWidth;
// if (pageSetup.pageHeight.IsNull)
@@ -330,8 +380,6 @@ protected void FlattenPageSetup(PageSetup pageSetup, PageSetup refPageSetup)
// pageSetup.pageFormat = refPageSetup.pageFormat;
if (pageSetup.Values.SectionStart is null)
pageSetup.Values.SectionStart = refPageSetup.Values.SectionStart;
- if (pageSetup.Values.Orientation is null)
- pageSetup.Values.Orientation = refPageSetup.Values.Orientation;
if (pageSetup.Values.TopMargin.IsValueNullOrEmpty())
pageSetup.Values.TopMargin = refPageSetup.Values.TopMargin;
if (pageSetup.Values.BottomMargin.IsValueNullOrEmpty())
@@ -355,21 +403,55 @@ protected void FlattenPageSetup(PageSetup pageSetup, PageSetup refPageSetup)
}
///
- /// Flattens the the specified document object.
+ /// Realizes the Orientation for PageSetup.
+ /// This shall be done for PageSetups initialized with PageFormat and or Orientation only.
+ /// For quadratic pages, Orientation is set to Portrait, as it is Portrait by definition.
+ /// Otherwise, PageWidth and PageHeight are swapped, if necessary.
+ ///
+ static void RealizeOrientation(PageSetup pageSetup)
+ {
+ var effectiveOrientation = pageSetup.Orientation;
+
+ // Set quadratic page to Portrait.
+ if (pageSetup.Values.PageWidth == pageSetup.Values.PageHeight)
+ pageSetup.Values.Orientation = Orientation.Portrait;
+ // Otherwise swap PageWidth and PageHeight, if not fitting to effectiveOrientation.
+ else if ((pageSetup.Values.PageWidth > pageSetup.Values.PageHeight && effectiveOrientation == Orientation.Portrait) ||
+ (pageSetup.Values.PageWidth < pageSetup.Values.PageHeight && effectiveOrientation == Orientation.Landscape))
+ (pageSetup.Values.PageWidth, pageSetup.Values.PageHeight) = (pageSetup.Values.PageHeight, pageSetup.Values.PageWidth);
+ }
+
+ ///
+ /// Updates the orientation according to a PageSetup’s PageWidth and PageHeight.
///
- protected void FlattenHeaderFooter(HeaderFooter headerFooter, bool isHeader)
+ static void UpdateOrientation(PageSetup pageSetup)
+ {
+ // Quadratic page is considered to be Portrait.
+ pageSetup.Values.Orientation = pageSetup.Values.PageWidth <= pageSetup.Values.PageHeight
+ ? Orientation.Portrait
+ : Orientation.Landscape;
+ }
+
+ ///
+ /// Flattens the specified document object.
+ ///
+#pragma warning disable IDE0060
+ protected static void FlattenHeaderFooter(HeaderFooter headerFooter, bool isHeader)
+#pragma warning restore IDE0060
{ }
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenFillFormat(FillFormat? fillFormat)
+#pragma warning disable IDE0060
+ protected static void FlattenFillFormat(FillFormat? fillFormat)
+#pragma warning restore IDE0060
{ }
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenLineFormat(LineFormat? lineFormat, LineFormat? refLineFormat)
+ protected static void FlattenLineFormat(LineFormat? lineFormat, LineFormat? refLineFormat)
{
if (refLineFormat != null && lineFormat != null)
{
@@ -379,9 +461,9 @@ protected void FlattenLineFormat(LineFormat? lineFormat, LineFormat? refLineForm
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenAxis(Axis? axis)
+ protected static void FlattenAxis(Axis? axis)
{
if (axis == null)
return;
@@ -390,9 +472,12 @@ protected void FlattenAxis(Axis? axis)
{
Values = { Width = 0.15 }
};
- if (axis.Values.HasMajorGridlines == true && axis.Values.MajorGridlines is not null)
+ //if (axis.Values.HasMajorGridlines == true && axis.Values.MajorGridlines is not null)
+ if (axis.Values is { HasMajorGridlines: true, MajorGridlines: not null })
FlattenLineFormat(axis.Values.MajorGridlines.Values.LineFormat, refLineFormat);
- if (axis.Values.HasMinorGridlines == true && axis.Values.MinorGridlines is not null)
+
+ //if (axis.Values.HasMinorGridlines == true && axis.Values.MinorGridlines is not null)
+ if (axis.Values is { HasMinorGridlines: true, MinorGridlines: not null })
FlattenLineFormat(axis.Values.MinorGridlines.Values.LineFormat, refLineFormat);
refLineFormat.Values.Width = 0.4;
@@ -412,17 +497,21 @@ protected void FlattenAxis(Axis? axis)
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenPlotArea(PlotArea? plotArea)
+#pragma warning disable IDE0060
+ protected static void FlattenPlotArea(PlotArea? plotArea)
+#pragma warning restore IDE0060
{
// plotArea can be null.
}
///
- /// Flattens the the specified document object.
+ /// Flattens the specified document object.
///
- protected void FlattenDataLabel(DataLabel? dataLabel)
+#pragma warning disable IDE0060 // Remove unused parameter
+ protected static void FlattenDataLabel(DataLabel? dataLabel)
+#pragma warning restore IDE0060 // Remove unused parameter
{ }
// Chart
@@ -487,13 +576,13 @@ internal override void VisitFootnote(Footnote footnote)
ParagraphFormat? format;
- var style = document.Styles[footnote.Values.Style!]; // BUG??? "!" added.
+ var style = document.Styles[footnote.Values.Style!]; // BUG_OLD??? "!" added.
if (style != null)
format = ParagraphFormatFromStyle(style);
else
{
footnote.Style = StyleNames.Footnote;
- format = document.Styles[StyleNames.Footnote]!.Values.ParagraphFormat!; // BUG: Check null
+ format = document.Styles[StyleNames.Footnote]!.Values.ParagraphFormat!; // BUG_OLD: Check null
}
if (footnote.Values.Format is null)
@@ -512,7 +601,7 @@ internal override void VisitParagraph(Paragraph paragraph)
ParagraphFormat format;
var currentElementHolder = GetDocumentElementHolder(paragraph);
- var style = document.Styles[paragraph.Values.Style ?? String.Empty];
+ var style = document.Styles[paragraph.Values.Style ?? ""];
if (style != null)
format = ParagraphFormatFromStyle(style);
@@ -545,12 +634,12 @@ internal override void VisitParagraph(Paragraph paragraph)
}
else if (currentElementHolder is TextArea area)
{
- paragraph.Style = area.Style; // BUG ???
+ paragraph.Style = area.Style; // BUG_OLD ???
format = area.Values.Format ?? NRT.ThrowOnNull();
}
else
{
- if (!String.IsNullOrEmpty(paragraph.Values.Style)) //StL:BUG see old code
+ if (!String.IsNullOrEmpty(paragraph.Values.Style)) //StL:BUG_OLD see old code
paragraph.Style = StyleNames.InvalidStyleName;
else
paragraph.Style = StyleNames.Normal;
@@ -559,22 +648,19 @@ internal override void VisitParagraph(Paragraph paragraph)
if (paragraph.Values.Format == null)
{
- paragraph.Format = format.Clone(); //StL:BUG see old code
+ paragraph.Format = format.Clone(); //StL:BUG_OLD see old code
paragraph.Format.Parent = paragraph;
}
else
FlattenParagraphFormat(paragraph.Format, format);
}
+
// Section
internal override void VisitHeaderFooter(HeaderFooter headerFooter)
{
var document = headerFooter.Document;
- string styleString;
- if (headerFooter.IsHeader)
- styleString = StyleNames.Header;
- else
- styleString = StyleNames.Footer;
+ var styleString = headerFooter.IsHeader ? StyleNames.Header : StyleNames.Footer;
ParagraphFormat format;
var style = document.Styles[headerFooter.Values.Style];
@@ -707,7 +793,7 @@ internal override void VisitRows(Rows rows)
/// Returns a paragraph format object initialized by the given style.
/// It differs from style.ParagraphFormat if style is a character style.
///
- ParagraphFormat ParagraphFormatFromStyle(Style style)
+ static ParagraphFormat ParagraphFormatFromStyle(Style style)
{
if (style.Type == StyleType.Character)
{
@@ -930,15 +1016,14 @@ internal override void VisitTextArea(TextArea? textArea)
if (textArea?.Values.Elements == null)
return;
- var document = textArea.Document;
+ _ = textArea.Document;
ParagraphFormat parentFormat;
if (textArea.Values.Style is not null)
{
var style = textArea.Document.Styles[textArea.Style];
- if (style == null)
- style = textArea.Document.Styles[StyleNames.InvalidStyleName] ?? NRT.ThrowOnNull