diff --git a/src/SIL.Machine/Corpora/UsfmStylesheet.cs b/src/SIL.Machine/Corpora/UsfmStylesheet.cs index 3fdb71ff..e63f8c96 100644 --- a/src/SIL.Machine/Corpora/UsfmStylesheet.cs +++ b/src/SIL.Machine/Corpora/UsfmStylesheet.cs @@ -72,11 +72,11 @@ public class UsfmStylesheet { "note", UsfmTextProperties.Note } }; - private readonly Dictionary _markers; + private readonly Dictionary _tags; public UsfmStylesheet(string stylesheetFileName, string alternateStylesheetFileName = null) { - _markers = new Dictionary(); + _tags = new Dictionary(); Parse(stylesheetFileName); if (!string.IsNullOrEmpty(alternateStylesheetFileName)) Parse(alternateStylesheetFileName); @@ -84,10 +84,10 @@ public UsfmStylesheet(string stylesheetFileName, string alternateStylesheetFileN public UsfmTag GetTag(string marker) { - if (_markers.TryGetValue(marker, out UsfmTag tag)) + if (_tags.TryGetValue(marker, out UsfmTag tag)) return tag; - if (IsCellRange(marker, out string baseMarker, out _) && _markers.TryGetValue(baseMarker, out tag)) + if (IsCellRange(marker, out string baseMarker, out _) && _tags.TryGetValue(baseMarker, out tag)) return tag; tag = CreateTag(marker); @@ -143,7 +143,6 @@ private void Parse(string stylesheetFileName) List entries = SplitStylesheet(lines); - HashSet foundStyles = new HashSet(); for (int i = 0; i < entries.Count; ++i) { StylesheetEntry entry = entries[i]; @@ -155,30 +154,28 @@ private void Parse(string stylesheetFileName) if (parts.Length > 1 && parts[1] == "-") { // If the entry looks like "\marker xy -" remove the tag and its end tag if any - _markers.Remove(parts[0]); - _markers.Remove(parts[0] + "*"); + _tags.Remove(parts[0]); + _tags.Remove(parts[0] + "*"); continue; } - UsfmTag marker = CreateTag(entry.Text); - UsfmTag endMarker = ParseTagEntry(marker, entries, i + 1); + UsfmTag tag = CreateTag(entry.Text); + UsfmTag endTag = ParseTagEntry(tag, entries, i + 1); - if (endMarker != null && !_markers.ContainsKey(endMarker.Marker)) - _markers[endMarker.Marker] = endMarker; - - foundStyles.Add(entry.Text); + if (endTag != null && !_tags.ContainsKey(endTag.Marker)) + _tags[endTag.Marker] = endTag; } } private UsfmTag CreateTag(string marker) { // If tag already exists update with addtl info (normally from custom.sty) - if (!_markers.TryGetValue(marker, out UsfmTag tag)) + if (!_tags.TryGetValue(marker, out UsfmTag tag)) { tag = new UsfmTag(marker); if (marker != "c" && marker != "v") tag.TextProperties = UsfmTextProperties.Publishable; - _markers[marker] = tag; + _tags[marker] = tag; } return tag; @@ -255,19 +252,19 @@ private static UsfmTag ParseTagEntry(UsfmTag tag, List styleshe break; case "leftmargin": - int leftMargin; - if (ParseInteger(entry, out leftMargin)) + float leftMargin; + if (ParseFloat(entry, out leftMargin)) tag.LeftMargin = leftMargin; break; case "rightmargin": - int rightMargin; - if (ParseInteger(entry, out rightMargin)) + float rightMargin; + if (ParseFloat(entry, out rightMargin)) tag.RightMargin = rightMargin; break; case "firstlineindent": - int firstLineIndent; + float firstLineIndent; if (ParseFloat(entry, out firstLineIndent)) tag.FirstLineIndent = firstLineIndent; break; @@ -413,19 +410,17 @@ private static bool ParseInteger(StylesheetEntry entry, out int result) && result >= 0; } - private static bool ParseFloat(StylesheetEntry entry, out int result) + private static bool ParseFloat(StylesheetEntry entry, out float result) { - float floatResult; if ( float.TryParse( entry.Text, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, - out floatResult + out result ) ) { - result = (int)(floatResult * 1000); return true; } diff --git a/src/SIL.Machine/Corpora/UsfmTag.cs b/src/SIL.Machine/Corpora/UsfmTag.cs index 08ef1605..3a2cdf58 100644 --- a/src/SIL.Machine/Corpora/UsfmTag.cs +++ b/src/SIL.Machine/Corpora/UsfmTag.cs @@ -91,7 +91,7 @@ public UsfmTag(string marker) public string EndMarker { get; set; } - public int FirstLineIndent { get; set; } + public float FirstLineIndent { get; set; } public string FontName { get; set; } @@ -101,7 +101,7 @@ public UsfmTag(string marker) public UsfmJustification Justification { get; set; } - public int LeftMargin { get; set; } + public float LeftMargin { get; set; } public int LineSpacing { get; set; } @@ -115,7 +115,7 @@ public UsfmTag(string marker) public int Rank { get; set; } - public int RightMargin { get; set; } + public float RightMargin { get; set; } public bool SmallCaps { get; set; }