Skip to content

Commit

Permalink
Merge pull request #15 from nationalarchives/fix/ewfc_b_2024_147
Browse files Browse the repository at this point in the history
CLP-11698 numbering fix for [2024] EWFC 147 (B)
  • Loading branch information
jurisdatum authored Jun 26, 2024
2 parents c80a062 + 7c28b52 commit cb8521e
Show file tree
Hide file tree
Showing 5 changed files with 2,544 additions and 19 deletions.
25 changes: 8 additions & 17 deletions src/docx/Numbering2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,6 @@ private static bool StartOverrideIsOperative(MainDocumentPart main, Paragraph ta
return true;
}

private static bool LevelFormatIsCompound(MainDocumentPart main, int numberingId, int ilvl) {
LevelText format = Numbering.GetLevel(main, numberingId, ilvl)?.LevelText;
if (format is null)
return false;
if (!format.Val.HasValue)
return false;
int c = format.Val.Value.Count(c => (c == '%'));
return c > 1;
}

class PrevAbsStartAccumulator {

private readonly Dictionary<int, Dictionary<int, int>> Map = new();
Expand Down Expand Up @@ -631,7 +621,7 @@ internal static int CalculateN(MainDocumentPart main, Paragraph paragraph, int n
int? numIdOfStartOverrideWithoutStyle = null;
bool numOverrideShouldntApplyToStyleOnly = false;

bool prevContainsLowerCompound = false; // see setter below
bool prevContainsNumOverrideAtLowerLevel = false;

int absStart = GetAbstractStart(main, abstractNumId, ilvl);

Expand Down Expand Up @@ -701,10 +691,11 @@ internal static int CalculateN(MainDocumentPart main, Paragraph paragraph, int n
start = absStart;
numIdOfStartOverride = -2;
}
// prevNumIdWithoutStyle.HasValue && ... is not good enough
if (prevNumIdWithoutStyle == numberingId && prevStartOverride.Value > 1)
prevContainsNumOverrideAtLowerLevel = true;
}

if (prevNumIdWithoutStyle == numberingId && LevelFormatIsCompound(main, numberingId, prevIlvl))
prevContainsLowerCompound = true;
continue;
}

Expand Down Expand Up @@ -733,7 +724,7 @@ internal static int CalculateN(MainDocumentPart main, Paragraph paragraph, int n
}
numIdOfStartOverrideStyle = prevNumIdOfStyle;
numIdOfStartOverrideWithoutStyle = prevNumIdWithoutStyle;
if (!prevContainsLowerCompound) // only test37 needs this condition
if (!prevContainsNumOverrideAtLowerLevel) // tests 37 and 87 need this condition
count = 0;
}
}
Expand All @@ -750,8 +741,8 @@ internal static int CalculateN(MainDocumentPart main, Paragraph paragraph, int n
}
}

if (isHigher)
prevContainsLowerCompound = true;
if (isHigher) // why ???
prevContainsNumOverrideAtLowerLevel = true;

bool numOverrideShouldntApply = numOverrideShouldntApplyToStyleOnly && !thisNumIdWithoutStyle.HasValue && thisNumIdOfStyle == numIdOfStartOverrideStyle;

Expand All @@ -761,7 +752,7 @@ internal static int CalculateN(MainDocumentPart main, Paragraph paragraph, int n
start = GetStart(main, numberingId, ilvl);
else if (over.HasValue)
start = over.Value;
if (over.HasValue && !prevContainsLowerCompound) // only test37 needs second condition
if (over.HasValue && !prevContainsNumOverrideAtLowerLevel) // test 37 (and 87?) needs second condition
count = 0;
}
return count + start.Value;
Expand Down
2 changes: 1 addition & 1 deletion test/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Tests() {
Transform.Load(xsltReader);
}

static readonly int total = 86;
static readonly int total = 87;

public static readonly IEnumerable<object[]> indices =
Enumerable.Concat(
Expand Down
Binary file added test/judgments/test87.docx
Binary file not shown.
Loading

0 comments on commit cb8521e

Please sign in to comment.