20 [NanoXlsxQueuePlugIn(PlugInUUID =
"FORMATTED_TEXT_FONT_ID_RESOLVER", QueueUUID = PlugInUUID.PreparingInlineProcessor)]
21 internal class FontIdResolver : IPluginInlineWriteProcessor
27 public IWriteContext WriteContext {
get;
set; }
36 Workbook workbook = WriteContext.Workbook;
37 StyleManager styleManager = WriteContext.WriterProcessingData.StyleManager;
38 Font[] fonts = styleManager.GetFonts();
39 Dictionary<Font, int> fontIndexLookup = fonts
40 .Select((font, index) =>
new { font, index })
41 .ToDictionary(x => x.font, x => x.index);
43 for (
int i = 0; i < workbook.Worksheets.Count; i++)
45 List<FormattedText> formattedTextCells = workbook.Worksheets[i].Cells.Values
48 .Where(ft => ft.PhoneticProperties?.FontReference !=
null)
50 if (formattedTextCells.Count == 0)
57 Font fontReference = props.FontReference;
58 if (fontIndexLookup.TryGetValue(fontReference, out
int fontIndex))
60 props.FontId = fontIndex;
70 public void Init(IWriteContext context)
72 this.WriteContext = context;