// *********************************************************************** // Assembly : Construction // Author : flythink // Created : 06-30-2020 // // Last Modified By : flythink // Last Modified On : 09-01-2020 // *********************************************************************** // // Copyright (c) jindongfang. All rights reserved. // // // *********************************************************************** namespace WellWorkDataUI { using DevExpress.Utils; using DevExpress.Utils.Drawing; using DevExpress.Utils.Paint; using DevExpress.XtraEditors.Drawing; using System; using System.Drawing; /// /// 高分辨率绘制类 /// public static class HighDpiPainter { /// /// The chinese white space /// public const string ChineseWhiteSpace = " "; private static CustomButtonEditPainter buttonEditPainter = new CustomButtonEditPainter(); private static CustomTextEditPainter textEditPainter = new CustomTextEditPainter(); /// /// Gets the new painter. /// /// The type of the t painter. /// The origin. /// TPainter. public static TPainter GetNewPainter(TPainter origin) where TPainter : BaseControlPainter { Type type = origin.GetType(); if (type == typeof(TextEditPainter)) { return textEditPainter as TPainter; } else if (type == typeof(ButtonEditPainter)) { return buttonEditPainter as TPainter; } return origin; } /// /// Switches the x paint. /// /// The cache. /// IDisposable. public static IDisposable SwitchXPaint(GraphicsCache cache) { if (cache.Paint is XPaintMixed) { return XPaintHelper.Switch(cache, CustomXPaintMixed.Default); } else if (cache.Paint is XPaintTextRender) { return XPaintHelper.Switch(cache, CustomXPaintTextRender.Default); } else { return XPaintHelper.Switch(cache, CustomXPaint.Default); } } private static Font ConvertFont(Font font) { // return font; return new Font(font.FontFamily, font.SizeInPoints - 0.25f); } /// /// Class CustomButtonEditPainter. /// Implements the /// /// public class CustomButtonEditPainter : ButtonEditPainter { /// /// Draws the text. /// /// The information. protected override void DrawText(ControlGraphicsInfoArgs info) { using (SwitchXPaint(info.Cache)) { base.DrawText(info); } } } /// /// Class CustomTextEditPainter. /// Implements the /// /// public class CustomTextEditPainter : TextEditPainter { /// /// Draws the text. /// /// The information. protected override void DrawText(ControlGraphicsInfoArgs info) { using (SwitchXPaint(info.Cache)) { base.DrawText(info); } } } /// /// Class CustomXPaint. /// Implements the /// /// public class CustomXPaint : XPaint { /// /// Gets the default. /// /// The default. public static CustomXPaint Default { get; } = new CustomXPaint(); /// /// Creates the instance. /// /// XPaint. protected override XPaint CreateInstance() { return new CustomXPaint(); } } /// /// Class CustomXPaintMixed. /// Implements the /// /// public class CustomXPaintMixed : XPaintMixed { /// /// Gets the default. /// /// The default. public static CustomXPaintMixed Default { get; } = new CustomXPaintMixed(); /// /// Creates the instance. /// /// XPaint. protected override XPaint CreateInstance() { return new CustomXPaintMixed(); } /// /// Internals the draw string. /// /// The cache. /// The s. /// The font. /// The r. /// The fore brush. /// The string format. protected override void InternalDrawString( GraphicsCache cache, string s, Font font, Rectangle r, Brush foreBrush, StringFormat strFormat) { if ( /*!IsLockStringDrawing &&*/ s != null && this.CanDraw(r)) { if (s.Length >= 65536) { s = s.Substring(0, 65535); } cache.Graphics.DrawString(s, font, foreBrush, r, strFormat); } } /// /// Internals the draw string. /// /// The cache. /// The s. /// The font. /// The r. /// The fore brush. /// The string format. protected override void InternalDrawString( GraphicsCache cache, string s, Font font, Rectangle r, Brush foreBrush, StringFormatInfo strFormat) { if ( /*!IsLockStringDrawing &&*/ s != null && this.CanDraw(r)) { if (s.Length >= 65536) { s = s.Substring(0, 65535); } cache.Graphics.DrawString( s, font, foreBrush, r, strFormat.StringFormat); } } } /// /// Class CustomXPaintTextRender. /// Implements the /// /// public class CustomXPaintTextRender : XPaintTextRender { /// /// Gets the default. /// /// The default. public static CustomXPaintTextRender Default { get; } = new CustomXPaintTextRender(); /// /// Creates the instance. /// /// XPaint. protected override XPaint CreateInstance() { return new CustomXPaintTextRender(); } } } }