Example #1
0
        internal static FontData Create(FontDescriptor fontDescriptor, FontDataSettings settings)
        {
            var fontData = new FontData(fontDescriptor, settings)
            {
                Pages = GeneratePages(fontDescriptor, settings),
            };

            return(fontData);
        }
Example #2
0
 public FontPage(int index, FontDataSettings settings)
 {
     this.Index    = index;
     this.settings = settings;
     this.Name     = settings.Name;
     this.Width    = settings.Width;
     this.Height   = settings.Height;
     this.node     = FontNode.Create(this, settings);
 }
Example #3
0
 private FontNode(FontPage page, FontNode parent, Rectangle rectangle, FontDataSettings settings)
 {
     this.Page      = page;
     this.Parent    = parent;
     this.Rectangle = rectangle;
     this.pointList = parent == null ? new List <Point>(settings.Capacity * 2)
     {
         Point.Empty
     } : parent.pointList;
     this.rightBottomList = parent == null ? new List <Point>(settings.Capacity) : parent.rightBottomList;
     this.settings        = settings;
     this.Childs          = Slice(rectangle).Select(item => new FontNode(page, this, item, settings)).ToArray();
     while (parent != null)
     {
         parent.count++;
         parent = parent.Parent;
     }
 }
Example #4
0
        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());
        }
Example #5
0
 private FontData(FontDescriptor fontDescriptor, FontDataSettings settings)
 {
     this.fontDescriptor = fontDescriptor ?? throw new ArgumentNullException(nameof(fontDescriptor));
     this.settings       = settings ?? throw new ArgumentNullException(nameof(settings));
 }
Example #6
0
        public static FontNode Create(FontPage page, FontDataSettings settings)
        {
            var rectangle = new Rectangle(0, 0, settings.Width, settings.Height);

            return(new FontNode(page, null, rectangle, settings));
        }
Example #7
0
 public FontData CreateData(FontDataSettings settings)
 {
     return(FontData.Create(this, settings));
 }