ROTATES 2

This commit is contained in:
melekhin
2026-08-10 13:58:11 +07:00
parent 265bfc7419
commit 9c81a084f1
3 changed files with 452 additions and 268 deletions
+12 -12
View File
@@ -77,7 +77,7 @@ internal static class SimplyReplaceExt
}
}
internal static bool SimpleReplace(this Paragraph? paragraph, string oldValue, string newValue, StringComparison comparisonType, PageBreakType splitValue = PageBreakType.None)
internal static bool SimpleReplace(this Paragraph? paragraph, string oldValue, string newValue, StringComparison comparisonType, BreakType? splitValue = null)
{
if (paragraph is null || string.IsNullOrEmpty(oldValue))
return false;
@@ -108,7 +108,7 @@ internal static class SimplyReplaceExt
}
internal static bool SimpleReplace(this Paragraph? paragraph, string oldValue, string newValue, StringComparison comparisonType, bool breakPage)
=> SimpleReplace(paragraph, oldValue, newValue, comparisonType, breakPage ? PageBreakType.PageBreak : PageBreakType.None);
=> SimpleReplace(paragraph, oldValue, newValue, comparisonType, breakPage ? BreakType.PageBreak : null);
internal static void Replace(this Paragraph paragraph, IEnumerable<KeyValuePair<string, string>> replacements, StringComparison comparisonType)
{
@@ -139,7 +139,7 @@ internal static class SimplyReplaceExt
OldValue = kvp.Key,
NewValue = kvp.Value ?? string.Empty,
Index = pos,
SplitValue = PageBreakType.None
BreakValue = null
});
pos += kvp.Key.Length;
}
@@ -159,7 +159,7 @@ internal static class SimplyReplaceExt
var nodesToReplace = FindNodesToReplace(structure, matchIndex, matchEnd);
if (nodesToReplace.Count > 0)
{
ExecuteReplacement(nodesToReplace, matchIndex, matchEnd, replacement.NewValue, replacement.SplitValue);
ExecuteReplacement(nodesToReplace, matchIndex, matchEnd, replacement.NewValue, replacement.BreakValue);
}
}
}
@@ -193,7 +193,7 @@ internal static class SimplyReplaceExt
OldValue = kvp.Key,
NewValue = kvp.Value.Text ?? string.Empty,
Index = pos,
SplitValue = kvp.Value.SplitValue
BreakValue = kvp.Value.BreakValue
});
pos += kvp.Key.Length;
}
@@ -213,7 +213,7 @@ internal static class SimplyReplaceExt
var nodesToReplace = FindNodesToReplace(structure, matchIndex, matchEnd);
if (nodesToReplace.Count > 0)
{
ExecuteReplacement(nodesToReplace, matchIndex, matchEnd, replacement.NewValue, replacement.SplitValue);
ExecuteReplacement(nodesToReplace, matchIndex, matchEnd, replacement.NewValue, replacement.BreakValue);
}
}
}
@@ -223,7 +223,7 @@ internal static class SimplyReplaceExt
internal string OldValue { get; set; } = null!;
internal string NewValue { get; set; } = null!;
internal int Index { get; set; }
internal PageBreakType SplitValue { get; set; } = PageBreakType.None;
internal BreakType? BreakValue { get; set; } = null;
}
private static ParagraphStructure AnalyzeParagraphStructure(IEnumerable<Run> runs)
@@ -287,7 +287,7 @@ internal static class SimplyReplaceExt
int matchStart,
int matchEnd,
string newValue,
PageBreakType splitValue)
BreakType? splitValue)
{
if (nodesToReplace.Count == 0) return;
@@ -312,7 +312,7 @@ internal static class SimplyReplaceExt
nodesToReplace[i].Text.Text = string.Empty;
}
if (splitValue == PageBreakType.PageBreak)
if (splitValue == BreakType.PageBreak)
{
if (nodesToReplace[0].Text.Parent is Run run && run.Parent is Paragraph para)
{
@@ -322,7 +322,7 @@ internal static class SimplyReplaceExt
para.AppendChild(breakRun);
}
}
else if (splitValue == PageBreakType.NewLandscapeSection || splitValue == PageBreakType.NewPortraitSection)
else if (splitValue == BreakType.NewLandscapeSection || splitValue == BreakType.NewPortraitSection)
{
var firstText = nodesToReplace[0].Text;
if (firstText.Parent is Run run && run.Parent is Paragraph para)
@@ -332,10 +332,10 @@ internal static class SimplyReplaceExt
}
}
private static void AddSectionProperties(Paragraph para, PageBreakType splitValue)
private static void AddSectionProperties(Paragraph para, BreakType? splitValue)
{
if (para is null) return;
PageOrientationValues orientation = splitValue == PageBreakType.NewLandscapeSection
PageOrientationValues orientation = splitValue == BreakType.NewLandscapeSection
? PageOrientationValues.Landscape
: PageOrientationValues.Portrait;