private static void ParseTextProperties(ScrTag qTag, StylesheetEntry entry) { string text = entry.Text.ToLowerInvariant(); string[] parts = text.Split(); foreach (string part in parts) { if (part.Trim() == "") { continue; } qTag.AddTextProperty(ParseEnum(part, propToTextProps)); } if (qTag.HasTextProperty(TextProperties.scNonpublishable)) { qTag.RemoveTextProperty(TextProperties.scPublishable); } }
/// <summary> /// ScrTag as parsed from the specified stylesheet entries. /// </summary> /// <param name="qTag">qTag needs to have the Marker set when calling this method</param> /// <param name="stylesheetEntries"></param> /// <param name="entryIndex"></param> /// <param name="errors"></param> /// <returns></returns> internal static ScrTag ParseSTYMarkerEntry(ScrTag qTag, List <StylesheetEntry> stylesheetEntries, int entryIndex, out List <string> errors) { int markerLineNumber = stylesheetEntries[entryIndex - 1].LineNumber; // The following items are present for conformance with // Paratext release 5.0 stylesheets. Release 6.0 and later // follows the guidelines set in InitPropertyMaps. // Make sure \id gets book property if (qTag.Marker == "id") { qTag.AddTextProperty(TextProperties.scBook); } errors = new List <string>(); HashSet <string> foundAttribs = new HashSet <string>(); ScrTag qTagEndMarker = null; while (entryIndex < stylesheetEntries.Count) { StylesheetEntry entry = stylesheetEntries[entryIndex]; ++entryIndex; if (entry.Marker == "marker") { break; } if (foundAttribs.Contains(entry.Marker)) { errors.Add(GetMessage(entry.LineNumber, string.Format(Localizer.Str("Duplicate style attribute '{0}'"), entry.Marker))); } try { switch (entry.Marker) { case "name": qTag.Name = entry.Text; break; case "description": qTag.Description = entry.Text; break; case "fontname": qTag.Fontname = entry.Text; break; case "fontsize": qTag.FontSize = entry.Text == "-" ? 0 : ParseI(entry); break; case "xmltag": qTag.XMLTag = entry.Text; break; case "encoding": qTag.Encoding = entry.Text; break; case "linespacing": qTag.LineSpacing = ParseI(entry); break; case "spacebefore": qTag.SpaceBefore = ParseI(entry); break; case "spaceafter": qTag.SpaceAfter = ParseI(entry); break; case "leftmargin": qTag.LeftMargin = ParseF(entry); break; case "rightmargin": qTag.RightMargin = ParseF(entry); break; case "firstlineindent": qTag.FirstLineIndent = ParseF(entry); break; case "rank": qTag.Rank = entry.Text == "-" ? 0 : ParseI(entry); break; case "bold": qTag.Bold = (entry.Text != "-"); break; case "smallcaps": qTag.SmallCaps = (entry.Text != "-"); break; case "subscript": qTag.Subscript = (entry.Text != "-"); break; case "italic": qTag.Italic = (entry.Text != "-"); break; // FB 23177 - added the \Regular tag so that there is a way to reset Italic, Bold and Superscript // that is compatible with the ptx2pdf macros used by PrintDraft case "regular": qTag.Italic = qTag.Bold = qTag.Superscript = false; qTag.Regular = true; break; case "underline": qTag.Underline = (entry.Text != "-"); break; case "superscript": qTag.Superscript = (entry.Text != "-"); break; case "testylename": break; // Ignore this tag, later we will use it to tie to FW styles case "notrepeatable": qTag.NotRepeatable = (entry.Text != "-"); break; case "textproperties": ParseTextProperties(qTag, entry); break; case "texttype": ParseTextType(qTag, entry); break; case "color": qTag.RawColor = entry.Text == "-" ? 0 : ParseColor(entry); break; case "colorname": qTag.RawColor = entry.Text == "-" ? 0 : GetThemeColor(entry); break; case "justification": qTag.JustificationType = ParseEnum(entry.Text, propToJustification); break; case "styletype": qTag.StyleType = ParseEnum(entry.Text, propToStyleType); break; case "attributes": try { qTag.RawAttributes = entry.Text; } catch (ArgumentException e) { errors.Add(GetMessage(entry.LineNumber, e.Message)); } break; case "occursunder": qTag.OccursUnder = String.Join(" ", entry.Text.Split(spaceSep, StringSplitOptions.RemoveEmptyEntries)); break; case "endmarker": qTagEndMarker = MakeEndMarker(entry.Text); qTag.Endmarker = entry.Text; break; default: errors.Add(GetMessage(entry.LineNumber, string.Format(Localizer.Str("Unknown marker: {0}"), entry.Marker))); break; } } catch (ArgumentOutOfRangeException e) { errors.Add(GetMessage(entry.LineNumber, string.Format(Localizer.Str("Invalid definition for marker '{0}': {1}"), entry.Marker, e.ActualValue))); } foundAttribs.Add(entry.Marker); } if (string.IsNullOrEmpty(qTag.Name)) { errors.Add(GetMessage(markerLineNumber, string.Format(Localizer.Str("Missing name for style: {0}"), qTag.Marker))); } // If we have not seen an end marker but this is a character style if (qTag.StyleType == ScrStyleType.scCharacterStyle && qTagEndMarker == null) { string endMarker = qTag.Marker + "*"; qTagEndMarker = MakeEndMarker(endMarker); qTag.Endmarker = endMarker; } else if (qTag.StyleType == ScrStyleType.scMilestone) { if (qTagEndMarker != null) { qTagEndMarker.StyleType = ScrStyleType.scMilestoneEnd; qTagEndMarker.RawAttributes = "?id"; // id is always an optional attribute for the end marker qTagEndMarker.Name = qTag.Name; } else { errors.Add(GetMessage(markerLineNumber, string.Format(Localizer.Str("Missing end marker for style: {0}"), qTag.Marker))); } } // Special cases if (qTag.TextType == ScrTextType.scOther && !qTag.HasTextProperty(TextProperties.scNonpublishable) && !qTag.HasTextProperty(TextProperties.scChapter) && !qTag.HasTextProperty(TextProperties.scVerse) && (qTag.StyleType == ScrStyleType.scCharacterStyle || qTag.StyleType == ScrStyleType.scParagraphStyle)) { qTag.AddTextProperty(TextProperties.scPublishable); } return(qTagEndMarker); }