public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //change the following to "true", if you want "id.", "eid.", "ead.", "eaed." written in italics or other font styles bool outputInItalics = true; bool outputInSmallCaps = false; bool outputInBold = false; bool outputUnderlined = false; //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg)", you can define them as group prefix and suffix on the field element inside the component part editor handled = false; if (componentPart == null) { return(null); } if (componentPart.Elements == null || componentPart.Elements.Count == 0) { return(null); } if (citation == null) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } Reference parentReference = reference.ParentReference; if (parentReference == null) { return(null); } //get editor person field elements (or authors in case of CollectedWorks) and make it a separate List<>, since we are going to change that collection below List <PersonFieldElement> editorPersonFieldElements = parentReference.ReferenceType == ReferenceType.CollectedWorks ? componentPart.Elements.OfType <PersonFieldElement>().Where(element => element.PropertyId == ReferencePropertyId.Authors).ToList() : componentPart.Elements.OfType <PersonFieldElement>().Where(element => element.PropertyId == ReferencePropertyId.Editors).ToList(); if (editorPersonFieldElements == null || editorPersonFieldElements.Count() == 0) { return(null); } //we DO have a valid citation/reference that is a parent's child ReferencePersonCollection childAuthorsCollection = reference.Authors; if (childAuthorsCollection == null || childAuthorsCollection.Count == 0) { return(null); } List <Person> childAuthors = new List <Person>(childAuthorsCollection); ReferencePersonCollection parentEditorsCollection = parentReference.ReferenceType == ReferenceType.CollectedWorks ? parentReference.Authors : parentReference.Editors; if (parentEditorsCollection == null || parentEditorsCollection.Count == 0) { return(null); } List <Person> parentEditors = new List <Person>(parentEditorsCollection); bool usePlural = parentEditors.Count() > 1; PersonEquality equality = CheckPersonEquality(childAuthors, parentEditors); if (equality == PersonEquality.None) { return(null); } //we DO have some equality, so let's check what we need to output instead of the person's name(s) var textIdem = string.Empty; switch (equality) { //see http://en.wiktionary.org/wiki/idem#Inflection case PersonEquality.M: case PersonEquality.N: textIdem = "id."; break; case PersonEquality.F: textIdem = "ead."; break; case PersonEquality.NN: textIdem = "ead."; break; case PersonEquality.MM: textIdem = "iid."; break; case PersonEquality.MN: case PersonEquality.FM: case PersonEquality.FMN: textIdem = "eid."; break; case PersonEquality.FF: case PersonEquality.FN: textIdem = "eaed."; break; } foreach (PersonFieldElement editors in editorPersonFieldElements) { TextUnitCollection output = new TextUnitCollection(); #region GroupPrefix if (usePlural && !string.IsNullOrEmpty(editors.GroupPrefixPlural.Text)) { output.Add(new LiteralTextUnit(editors.GroupPrefixPlural.Text, editors.GroupPrefixPlural.FontStyle)); } else if (!usePlural & !string.IsNullOrEmpty(editors.GroupPrefixSingular.Text)) { output.Add(new LiteralTextUnit(editors.GroupPrefixSingular.Text, editors.GroupPrefixSingular.FontStyle)); } #endregion GroupPrefix SwissAcademic.Drawing.FontStyle fontStyle; fontStyle = SwissAcademic.Drawing.FontStyle.Neutral; if (outputInItalics) { fontStyle |= SwissAcademic.Drawing.FontStyle.Italic; } if (outputInSmallCaps) { fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps; } if (outputInBold) { fontStyle |= SwissAcademic.Drawing.FontStyle.Bold; } if (outputUnderlined) { fontStyle |= SwissAcademic.Drawing.FontStyle.Underline; } var fontStyleNeutral = SwissAcademic.Drawing.FontStyle.Neutral; output.Add(new LiteralTextUnit(textIdem, fontStyle)); #region GroupSuffix if (usePlural && !string.IsNullOrEmpty(editors.GroupSuffixPlural.Text)) { output.Add(new LiteralTextUnit(editors.GroupSuffixPlural.Text, editors.GroupSuffixPlural.FontStyle)); } else if (!usePlural && !string.IsNullOrEmpty(editors.GroupSuffixSingular.Text)) { output.Add(new LiteralTextUnit(editors.GroupSuffixSingular.Text, editors.GroupSuffixSingular.FontStyle)); } #endregion GroupSuffix //inject this as LiteralElements into the componentPart, replacing the editors person field element componentPart.Elements.ReplaceItem(editors, TextUnitsToLiteralElements(output, componentPart)); //for some reason this does not work } handled = false; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //change the following to "true", if you want "ders."/"dies." written in italics or other font styles var outputInItalics = true; var outputInSmallCaps = false; var outputInBold = false; var outputUnderlined = false; //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg)", you can define them as group prefix and suffix on the field element inside the component part editor handled = false; if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } if (citation == null) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } Reference parentReference = citation.Reference.ParentReference; #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetPersonFieldElement(componentPart); if (thisPersonFieldElement == null) { return(null); } #endregion #region ThesePersons List <Person> thesePersons = GetPersonsDisplayed(thisPersonFieldElement, reference); #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, reference); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons List <Person> previousPersons = GetPersonsDisplayed(previousPersonFieldElement, reference); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion bool usePlural = thesePersons.Count > 1; PersonEquality equality = CheckPersonEquality(thesePersons, previousPersons); if (equality == PersonEquality.None) { return(null); } //we DO have some equality, so let's check what we need to output instead of the person's name(s) var textIdem = string.Empty; switch (equality) { case PersonEquality.M: case PersonEquality.N: textIdem = "ders."; break; default: //all others textIdem = "dies."; break; } TextUnitCollection output = new TextUnitCollection(); #region GroupPrefix if (usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupPrefixPlural.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupPrefixPlural.Text, thisPersonFieldElement.GroupPrefixPlural.FontStyle)); } else if (!usePlural & !string.IsNullOrEmpty(thisPersonFieldElement.GroupPrefixSingular.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupPrefixSingular.Text, thisPersonFieldElement.GroupPrefixSingular.FontStyle)); } #endregion GroupPrefix SwissAcademic.Drawing.FontStyle fontStyle; fontStyle = SwissAcademic.Drawing.FontStyle.Neutral; if (outputInItalics) { fontStyle |= SwissAcademic.Drawing.FontStyle.Italic; } if (outputInSmallCaps) { fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps; } if (outputInBold) { fontStyle |= SwissAcademic.Drawing.FontStyle.Bold; } if (outputUnderlined) { fontStyle |= SwissAcademic.Drawing.FontStyle.Underline; } var fontStyleNeutral = SwissAcademic.Drawing.FontStyle.Neutral; output.Add(new LiteralTextUnit(textIdem, fontStyle)); #region GroupSuffix if (usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupSuffixPlural.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupSuffixPlural.Text, thisPersonFieldElement.GroupSuffixPlural.FontStyle)); } else if (!usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupSuffixSingular.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupSuffixSingular.Text, thisPersonFieldElement.GroupSuffixSingular.FontStyle)); } #endregion GroupSuffix //inject this as LiteralElements into the componentPart, replacing the editors person field element componentPart.Elements.ReplaceItem(thisPersonFieldElement, TextUnitsToLiteralElements(output, componentPart)); //for some reason this does not work //all literal elements should always be output: foreach (LiteralElement literalElement in componentPart.Elements.OfType <LiteralElement>()) { literalElement.ApplyCondition = ElementApplyCondition.Always; } handled = false; return(null); }