22 [NanoXlsxQueuePlugIn(PlugInUUID =
"FORMATTED_TEXT_FONT_ID_RESOLVER", QueueUUID = PlugInUUID.WriterPrependingQueue)]
23 internal class FontIdResolver : IPluginWriter
26 private StyleManager styleManager;
33 public Workbook Workbook {
get;
set; }
38 [ExcludeFromCodeCoverage]
39 public XmlElement XmlElement {
get {
return null; } }
48 Font[] fonts = styleManager.GetFonts();
49 Dictionary<Font, int> fontIndexLookup = fonts
50 .Select((font, index) =>
new { font, index })
51 .ToDictionary(x => x.font, x => x.index);
53 for (
int i = 0; i < Workbook.Worksheets.Count; i++)
55 List<FormattedText> formattedTextCells = Workbook.Worksheets[i].Cells.Values
58 .Where(ft => ft.PhoneticProperties?.FontReference !=
null)
60 if (formattedTextCells.Count == 0)
67 Font fontReference = props.FontReference;
68 if (fontIndexLookup.TryGetValue(fontReference, out
int fontIndex))
70 props.FontId = fontIndex;
80 public void Init(IBaseWriter baseWriter)
82 this.Workbook = baseWriter.Workbook;
83 this.styleManager = baseWriter.Styles;