Calculate proper font size for AddString

This commit is contained in:
Jaex 2017-02-17 23:23:19 +03:00
parent b66f09f9dc
commit 01682b0e3e
3 changed files with 10 additions and 5 deletions

View file

@ -177,12 +177,16 @@ public static void DrawTextWithOutline(this Graphics g, string text, PointF posi
{
using (StringFormat sf = new StringFormat())
{
gp.AddString(text, font.FontFamily, (int)font.Style, font.Size, position, sf);
float emSize = g.DpiY * font.SizeInPoints / 72;
gp.AddString(text, font.FontFamily, (int)font.Style, emSize, position, sf);
}
using (Pen borderPen = new Pen(borderColor, borderSize) { LineJoin = LineJoin.Round })
if (borderSize > 0)
{
g.DrawPath(borderPen, gp);
using (Pen borderPen = new Pen(borderColor, borderSize) { LineJoin = LineJoin.Round })
{
g.DrawPath(borderPen, gp);
}
}
using (Brush textBrush = new SolidBrush(textColor))

View file

@ -47,7 +47,7 @@ public class AnnotationOptions
public TextDrawingOptions TextOutlineOptions { get; set; } = new TextDrawingOptions()
{
Color = PrimaryColor,
Size = 40,
Size = 30,
Bold = true
};
public Color TextOutlineBorderColor { get; set; } = SecondaryColor;

View file

@ -63,7 +63,8 @@ protected void DrawTextWithOutline(Graphics g, string text, TextDrawingOptions o
using (Font font = new Font(options.Font, options.Size, options.Style))
using (StringFormat sf = new StringFormat { Alignment = options.AlignmentHorizontal, LineAlignment = options.AlignmentVertical })
{
gp.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, sf);
float emSize = g.DpiY * font.SizeInPoints / 72;
gp.AddString(text, font.FontFamily, (int)font.Style, emSize, rect, sf);
}
g.SmoothingMode = SmoothingMode.HighQuality;