Skip to content

Commit

Permalink
Pass a content fragment to AddLexReferences()
Browse files Browse the repository at this point in the history
Converting the fragment to a string was resulting in the
loss of all styling for Word Export.  Now we pass the
content fragment to AddLexReferences() and let the xhtml
and json generators do the conversion to a string.

Change-Id: I0574ae94317c1580894e944429432ea4d56c99c6
  • Loading branch information
mark-sil committed May 22, 2024
1 parent 796784b commit bd6e4b0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
26 changes: 15 additions & 11 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ internal static StringBuilder GenerateLetterHeaderIfNeeded(ICmObject entry,
}

/// <summary>
/// This method uses a ThreadPool to execute the given individualActions in parallel.
/// It waits for all the individualActions to complete and then returns.
/// </summary>
internal static void SpawnEntryGenerationThreadsAndWait(List<Action> individualActions, IThreadedProgress progress)
/// This method uses a ThreadPool to execute the given individualActions in parallel.
/// It waits for all the individualActions to complete and then returns.
/// </summary>
internal static void SpawnEntryGenerationThreadsAndWait(List<Action> individualActions, IThreadedProgress progress)
{
var actionCount = individualActions.Count;
//Note that our COM classes all implement the STA threading model, while the ThreadPool always uses MTA model threads.
Expand Down Expand Up @@ -1580,29 +1580,33 @@ private static void GenerateContentForLexEntryRefsByType(ConfigurableDictionaryN
// Generate XHTML by Type
foreach (var typeGuid in lexEntryTypesFiltered)
{
var innerBldr = new StringBuilder();
var combinedContent = settings.ContentGenerator.CreateFragment();
bool first = true;
foreach (var lexEntRef in lerCollection)
{
if (isComplex ? lexEntRef.ComplexEntryTypesRS.Any(t => t.Guid == typeGuid) : lexEntRef.VariantEntryTypesRS.Any(t => t.Guid == typeGuid))
{
innerBldr.Append(GenerateCollectionItemContent(config, pubDecorator, lexEntRef, collectionOwner, settings, first, typeNode));
first = false;
var content = GenerateCollectionItemContent(config, pubDecorator, lexEntRef, collectionOwner, settings, first, typeNode);
if (!content.IsNullOrEmpty())
{
combinedContent.Append(content);
first = false;
}
}
}

if (innerBldr.Length > 0)
if (!first)
{
var lexEntryType = lexEntryTypes.First(t => t.Guid.Equals(typeGuid));
// Display the Type iff there were refs of this Type (and we are factoring)
// Display the Type if there were refs of this Type (and we are factoring)
var generateLexType = typeNode != null;
var lexTypeContent = generateLexType
? GenerateCollectionItemContent(typeNode, pubDecorator, lexEntryType,
lexEntryType.Owner, settings, first)
lexEntryType.Owner, settings, false)
: null;
var className = generateLexType ? settings.StylesGenerator.AddStyles(typeNode).Trim('.') : null;
var refsByType = settings.ContentGenerator.AddLexReferences(generateLexType,
lexTypeContent, config, className, innerBldr.ToString(), IsTypeBeforeForm(config));
lexTypeContent, config, className, combinedContent, IsTypeBeforeForm(config));
bldr.Append(refsByType);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/ILcmContentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IFragment GenerateGroupingNode(object field, string className, ConfigurableDicti
IFragment AddImage(string classAttribute, string srcAttribute, string pictureGuid);
IFragment AddImageCaption(string captionContent);
IFragment GenerateSenseNumber(string formattedSenseNumber, string senseNumberWs, ConfigurableDictionaryNode config);
IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className, string referencesContent, bool typeBefore);
IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className, IFragment referencesContent, bool typeBefore);
void BeginCrossReference(IFragmentWriter writer, bool isBlockProperty, string className);
void EndCrossReference(IFragmentWriter writer);
IFragment WriteProcessedSenses(bool isBlock, IFragment senseContent, ConfigurableDictionaryNode config, string className, IFragment sharedCollectionInfo);
Expand Down
4 changes: 2 additions & 2 deletions Src/xWorks/LcmJsonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public IFragment GenerateSenseNumber(string formattedSenseNumber, string wsId, C
}

public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className,
string referencesContent, bool typeBefore)
IFragment referencesContent, bool typeBefore)
{
var bldr = new StringBuilder();
var fragment = new StringFragment(bldr);
Expand All @@ -382,7 +382,7 @@ public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent
// Write an array with the references.
xw.WritePropertyName("references");
xw.WriteStartArray();
xw.WriteRaw(referencesContent);
xw.WriteRaw(referencesContent.ToString());
xw.WriteEndArray();
// Write properties related to the factored type (if any and if after).
if (generateLexType && !typeBefore)
Expand Down
4 changes: 2 additions & 2 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ public IFragment GenerateSenseNumber(string formattedSenseNumber, string senseNu
senseNum.AddStyleLink(WordStylesGenerator.SenseNumberStyleName, senseConfigNode, ConfigurableDictionaryNode.StyleTypes.Character);
return senseNum;
}
public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className, string referencesContent, bool typeBefore)
public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className, IFragment referencesContent, bool typeBefore)
{
var fragment = new DocFragment();
// Generate the factored ref types element (if before).
Expand All @@ -1390,7 +1390,7 @@ public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent
fragment.Append(WriteProcessedObject(false, lexTypeContent, config, className));
}
// Then add all the contents for the LexReferences (e.g. headwords)
fragment.Append(new DocFragment(referencesContent));
fragment.Append(referencesContent);
// Generate the factored ref types element (if after).
if (generateLexType && !typeBefore)
{
Expand Down
4 changes: 2 additions & 2 deletions Src/xWorks/LcmXhtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public IFragment GenerateSenseNumber(string formattedSenseNumber, string senseNu
}

public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent, ConfigurableDictionaryNode config, string className,
string referencesContent, bool typeBefore)
IFragment referencesContent, bool typeBefore)
{
var bldr = new StringBuilder(100);
var fragment = new StringFragment(bldr);
Expand All @@ -971,7 +971,7 @@ public IFragment AddLexReferences(bool generateLexType, IFragment lexTypeContent
bldr.Append(WriteProcessedObject(false, lexTypeContent, config, className));
}
// Then add all the contents for the LexReferences (e.g. headwords)
bldr.Append(referencesContent);
bldr.Append(referencesContent.ToString());
// Generate the factored ref types element (if after).
if (generateLexType && !typeBefore)
{
Expand Down

0 comments on commit bd6e4b0

Please sign in to comment.