protected override void DrawTextInternal(string value, Font font, Rectangle rectangle, Color color, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
 {
     System.Windows.Forms.TextFormatFlags flags = System.Windows.Forms.TextFormatFlags.Left;
     switch (horizontalAlignment)
     {
         case HorizontalAlignment.Center:
         {
             flags |= System.Windows.Forms.TextFormatFlags.HorizontalCenter;
             break;
         }
         case HorizontalAlignment.Right:
         {
             flags |= System.Windows.Forms.TextFormatFlags.Right;
             break;
         }
     }
     switch (verticalAlignment)
     {
         case VerticalAlignment.Bottom:
         {
             flags |= System.Windows.Forms.TextFormatFlags.Bottom;
             break;
         }
         case VerticalAlignment.Middle:
         {
             flags |= System.Windows.Forms.TextFormatFlags.VerticalCenter;
             break;
         }
     }
     System.Windows.Forms.TextRenderer.DrawText(mvarGraphics, value, FontToNativeFont(font), RectangleToNativeRectangle(rectangle), ColorToNativeColor(color), flags);
 }
 public static Font FromFamily(string familyName, double size, double weight = 400)
 {
     Font font = new Font();
     font.FamilyName = familyName;
     font.Size = size;
     font.Weight = weight;
     return font;
 }
        private IntPtr GetHandleByFont(IntPtr hdc, Font font)
        {
            Internal.Windows.Structures.GDI.LOGFONT lplf = new Internal.Windows.Structures.GDI.LOGFONT();
            lplf.lfFaceName = font.FamilyName;
            lplf.lfCharSet = Internal.Windows.Constants.GDI.LogFontCharSet.Default;
            lplf.lfItalic = (byte)(font.Italic ? 1 : 0);
            lplf.lfQuality = Internal.Windows.Constants.GDI.LogFontQuality.ClearType;
            int lpy = Internal.Windows.Methods.GDI.GetDeviceCaps(hdc, Internal.Windows.Constants.GDI.DeviceCapsIndex.LogPixelsY);

            // 72 points/inch, lpy pixels/inch

            // thanks https://support.microsoft.com/en-us/kb/74299
            lplf.lfHeight = (int)(Math.Round(-(font.Size * lpy) / (double)72));
            lplf.lfWeight = (int)font.Weight;

            IntPtr retval = Internal.Windows.Methods.GDI.CreateFontIndirect(ref lplf);
            return retval;
        }
 protected abstract void DrawTextInternal(string value, Font font, Rectangle rectangle, Color color, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment);
 public void DrawText(string value, Font font, Rectangle rectangle, Color color, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top)
 {
     DrawTextInternal(value, font, rectangle, color, horizontalAlignment, verticalAlignment);
 }
 private System.Drawing.FontStyle GetNativeFontStyle(Font font)
 {
     System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;
     if (font.Italic) style |= System.Drawing.FontStyle.Italic;
     if (font.Weight >= FontWeights.Bold) style |= System.Drawing.FontStyle.Bold;
     return style;
 }
 private System.Drawing.Font FontToNativeFont(Font font)
 {
     // TODO: get rid of this hardcoding and actually create real Font objects from system fonts
     if (font == SystemFonts.MenuFont)
     {
         return System.Drawing.SystemFonts.MenuFont;
     }
     else if (font == null)
     {
         return System.Drawing.SystemFonts.DefaultFont;
     }
     return new System.Drawing.Font(font.FamilyName, (float)font.Size, GetNativeFontStyle(font));
 }