예제 #1
0
        public SizeF MeasureString(String text, Font font, int width, StringFormat format)
        {
            SixLabors.Fonts.FontFamily family = SixLabors.Fonts.SystemFonts.Find(font.Name);
            //font.Bold
            //font.Italic
            //font.Underline
            //font.Strikeout

            SixLabors.Fonts.Font            fo = new SixLabors.Fonts.Font(family, font.Size);
            SixLabors.Fonts.RendererOptions ro = new SixLabors.Fonts.RendererOptions(fo);

            SixLabors.Primitives.SizeF result = SixLabors.Fonts.TextMeasurer.Measure(text, ro);

            return(new System.Drawing.SizeF(result.Width, result.Height));
        }
예제 #2
0
        public static IMAGE32 RenderText(this SixLabors.Fonts.FontFamily ffamily, string text, float fsize, float padding, COLOR color, TextGraphicsOptions options)
        {
            // http://sixlabors.com/2017/04/08/watermarks/

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            var font     = new SixLabors.Fonts.Font(ffamily, fsize);
            var roptions = new SixLabors.Fonts.RendererOptions(font, 96);
            var size     = SixLabors.Fonts.TextMeasurer.Measure(text, roptions);

            var w   = (int)Math.Ceiling(size.Width + padding * 2);
            var h   = (int)Math.Ceiling(size.Height + padding * 2);
            var img = new IMAGE32(w, h);

            img.Mutate(dc => dc.DrawText(options, text, font, color, new System.Numerics.Vector2(padding, padding)));

            return(img);
        }