internal static FontData Create(FontDescriptor fontDescriptor, FontDataSettings settings) { var fontData = new FontData(fontDescriptor, settings) { Pages = GeneratePages(fontDescriptor, settings), }; return(fontData); }
private static FontPage[] GeneratePages(FontDescriptor fontDescriptor, FontDataSettings settings) { var characters = new HashSet <uint>(settings.Characters ?? new uint[] { }); var query = from item in fontDescriptor.Glyphs where settings.Characters == null || characters.Contains(item.Key) let glyph = item.Value where glyph.Bitmap != null let metrics = glyph.Metrics orderby metrics.Width descending orderby metrics.Height descending select glyph; var items = query.ToArray(); var index = 0; var pageList = new List <FontPage>(); var page = new FontPage(index++, settings); pageList.Add(page); foreach (var item in items) { var reservator = page.ReserveRegion(item); if (reservator == null) { page = new FontPage(index++, settings); pageList.Add(page); reservator = page.ReserveRegion(item); } try { reservator.Reserve(); } catch { reservator.Reject(); } } return(pageList.ToArray()); }
private FontData(FontDescriptor fontDescriptor, FontDataSettings settings) { this.fontDescriptor = fontDescriptor ?? throw new ArgumentNullException(nameof(fontDescriptor)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); }