Merge two documents (use the attached ones) that already have embedded files with the same names.
Observed:
at Telerik.Windows.Documents.Core.Fonts.Type1.Type1Format.Type1FontSource.GetFontFamily()
This exception was originally thrown at this call stack: Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyEmbeddedFilesTo(Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader, Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.IRadFixedDocumentImportContext) in DocumentCatalog.cs
A strange symbol is added as a name when embedding a file with an empty string as its name argument.
For example exporting the text "\uD83D\uDE0A" with "Segoe UI Symbol" font family should export a single smiling face. Instead the characters are skipped during the export as PdfProcessing is trying to export them as separate char values ("\uD83D" and "\uDE0A") and the font does not contain glyphs corresponding to these char codes.
When characters are in the ranges 61472-61566, 61565-61695, 65535-65535 they are correctly exported with Wingdings font. However, when the character value is outside these ranges the font fallback mechanism exports them with different font and this causes wrong glyph rendering in the resulted PDF.
The following code snippet shows how the Wingdings characters can be modified so that they are correctly exported to PDF when converting from WordsProcessing's RadFlowDocument:
RadFlowDocument document = new DocxFormatProvider().Import(File.ReadAllBytes(@"test_document.docx"));
foreach (Run run in document.EnumerateChildrenOfType<Run>())
{
if (run.FontFamily.GetActualValue(document.Theme).Source.Contains("Wingdings"))
{
StringBuilder modifiedText = new StringBuilder();
foreach (char character in run.Text)
{
modifiedText.Append(character > 256 ? character : (char)(character + 61440));
}
run.Text = modifiedText.ToString();
}
}
Workaround: When creating a RadFixedDocument:
using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(this.fixedDocument))
{
byte[] data = File.ReadAllBytes(@"CustomFont.ttf");
FontsRepository.RegisterFont(new FontFamily("CustomFont"), FontStyles.Normal, FontWeights.Normal, data);
FontBase customFont;
FontsRepository.TryCreateFont(new FontFamily("CustomFont"), FontStyles.Normal, FontWeights.Normal, out customFont);
editor.CharacterProperties.Font = customFont;
string text = "w";
StringBuilder modifiedText = new StringBuilder();
foreach (char character in text)
{
modifiedText.Append(character > 256 ? character : (char)(character + 61440));
}
text = modifiedText.ToString();
editor.InsertRun(text);
}