|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
// Assembly : Construction
|
|
|
|
|
|
// Author : flythink
|
|
|
|
|
|
// Created : 06-30-2020
|
|
|
|
|
|
//
|
|
|
|
|
|
// Last Modified By : flythink
|
|
|
|
|
|
// Last Modified On : 09-01-2020
|
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
// <copyright file="HighDpiPainter.cs" company="jindongfang">
|
|
|
|
|
|
// Copyright (c) jindongfang. All rights reserved.
|
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
// <summary></summary>
|
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
namespace WellWorkDataUI
|
|
|
|
|
|
{
|
|
|
|
|
|
using DevExpress.Utils;
|
|
|
|
|
|
using DevExpress.Utils.Drawing;
|
|
|
|
|
|
using DevExpress.Utils.Paint;
|
|
|
|
|
|
using DevExpress.XtraEditors.Drawing;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 高分辨率绘制类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class HighDpiPainter
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The chinese white space
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public const string ChineseWhiteSpace = " ";
|
|
|
|
|
|
|
|
|
|
|
|
private static CustomButtonEditPainter buttonEditPainter = new CustomButtonEditPainter();
|
|
|
|
|
|
|
|
|
|
|
|
private static CustomTextEditPainter textEditPainter = new CustomTextEditPainter();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the new painter.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TPainter">The type of the t painter.</typeparam>
|
|
|
|
|
|
/// <param name="origin">The origin.</param>
|
|
|
|
|
|
/// <returns>TPainter.</returns>
|
|
|
|
|
|
public static TPainter GetNewPainter<TPainter>(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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Switches the x paint.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cache">The cache.</param>
|
|
|
|
|
|
/// <returns>IDisposable.</returns>
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class CustomButtonEditPainter.
|
|
|
|
|
|
/// Implements the <see cref="DevExpress.XtraEditors.Drawing.ButtonEditPainter" />
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <seealso cref="DevExpress.XtraEditors.Drawing.ButtonEditPainter" />
|
|
|
|
|
|
public class CustomButtonEditPainter : ButtonEditPainter
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Draws the text.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="info">The information.</param>
|
|
|
|
|
|
protected override void DrawText(ControlGraphicsInfoArgs info)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SwitchXPaint(info.Cache))
|
|
|
|
|
|
{
|
|
|
|
|
|
base.DrawText(info);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class CustomTextEditPainter.
|
|
|
|
|
|
/// Implements the <see cref="DevExpress.XtraEditors.Drawing.TextEditPainter" />
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <seealso cref="DevExpress.XtraEditors.Drawing.TextEditPainter" />
|
|
|
|
|
|
public class CustomTextEditPainter : TextEditPainter
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Draws the text.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="info">The information.</param>
|
|
|
|
|
|
protected override void DrawText(ControlGraphicsInfoArgs info)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SwitchXPaint(info.Cache))
|
|
|
|
|
|
{
|
|
|
|
|
|
base.DrawText(info);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class CustomXPaint.
|
|
|
|
|
|
/// Implements the <see cref="DevExpress.Utils.Paint.XPaint" />
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <seealso cref="DevExpress.Utils.Paint.XPaint" />
|
|
|
|
|
|
public class CustomXPaint : XPaint
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The default.</value>
|
|
|
|
|
|
public static CustomXPaint Default { get; } = new CustomXPaint();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates the instance.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>XPaint.</returns>
|
|
|
|
|
|
protected override XPaint CreateInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new CustomXPaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class CustomXPaintMixed.
|
|
|
|
|
|
/// Implements the <see cref="DevExpress.Utils.Paint.XPaintMixed" />
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <seealso cref="DevExpress.Utils.Paint.XPaintMixed" />
|
|
|
|
|
|
public class CustomXPaintMixed : XPaintMixed
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The default.</value>
|
|
|
|
|
|
public static CustomXPaintMixed Default { get; } = new CustomXPaintMixed();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates the instance.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>XPaint.</returns>
|
|
|
|
|
|
protected override XPaint CreateInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new CustomXPaintMixed();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Internals the draw string.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cache">The cache.</param>
|
|
|
|
|
|
/// <param name="s">The s.</param>
|
|
|
|
|
|
/// <param name="font">The font.</param>
|
|
|
|
|
|
/// <param name="r">The r.</param>
|
|
|
|
|
|
/// <param name="foreBrush">The fore brush.</param>
|
|
|
|
|
|
/// <param name="strFormat">The string format.</param>
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Internals the draw string.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cache">The cache.</param>
|
|
|
|
|
|
/// <param name="s">The s.</param>
|
|
|
|
|
|
/// <param name="font">The font.</param>
|
|
|
|
|
|
/// <param name="r">The r.</param>
|
|
|
|
|
|
/// <param name="foreBrush">The fore brush.</param>
|
|
|
|
|
|
/// <param name="strFormat">The string format.</param>
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class CustomXPaintTextRender.
|
|
|
|
|
|
/// Implements the <see cref="DevExpress.Utils.Paint.XPaintTextRender" />
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <seealso cref="DevExpress.Utils.Paint.XPaintTextRender" />
|
|
|
|
|
|
public class CustomXPaintTextRender : XPaintTextRender
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the default.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The default.</value>
|
|
|
|
|
|
public static CustomXPaintTextRender Default { get; } = new CustomXPaintTextRender();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates the instance.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>XPaint.</returns>
|
|
|
|
|
|
protected override XPaint CreateInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new CustomXPaintTextRender();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|