------ #### RaUIV4 V4.0.2311.0701 - *.[全新]整合了MyDb、ryControls、MyDb_MySQL等dll文件到RaUI一个项目。 - *.[新增]新增ApkOp类,可以轻松获取APK信息。 - *.[新增]新增JsonExt扩展类,让Json操作更简单。 - *.[新增]新增WebP类,可以支持webp格式的图片。 - *.[改进]ryQuickSQL中的AddField方法改为自动替换已存在的同名值。 - *.[修复]ryQuickSQL中的AddFieldCalc方法无法正常计算的BUG。
123 lines
3.0 KiB
C#
123 lines
3.0 KiB
C#
// "Therefore those skilled at the unorthodox
|
|
// are infinite as heaven and earth,
|
|
// inexhaustible as the great rivers.
|
|
// When they come to an end,
|
|
// they begin again,
|
|
// like the days and months;
|
|
// they die and are reborn,
|
|
// like the four seasons."
|
|
//
|
|
// - Sun Tsu,
|
|
// "The Art of War"
|
|
|
|
using System;
|
|
using System.Drawing;
|
|
using TheArtOfDev.HtmlRenderer.Adapters;
|
|
|
|
namespace TheArtOfDev.HtmlRenderer.WinForms.Adapters
|
|
{
|
|
/// <summary>
|
|
/// Adapter for WinForms Font object for core.
|
|
/// </summary>
|
|
internal sealed class FontAdapter : RFont
|
|
{
|
|
#region Fields and Consts
|
|
|
|
/// <summary>
|
|
/// the underline win-forms font.
|
|
/// </summary>
|
|
private readonly Font _font;
|
|
|
|
/// <summary>
|
|
/// a handle to this Font.
|
|
/// </summary>
|
|
private IntPtr _hFont;
|
|
|
|
/// <summary>
|
|
/// the vertical offset of the font underline location from the top of the font.
|
|
/// </summary>
|
|
private float _underlineOffset = -1;
|
|
|
|
/// <summary>
|
|
/// Cached font height.
|
|
/// </summary>
|
|
private float _height = -1;
|
|
|
|
/// <summary>
|
|
/// Cached font whitespace width.
|
|
/// </summary>
|
|
private double _whitespaceWidth = -1;
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// Init.
|
|
/// </summary>
|
|
public FontAdapter(Font font)
|
|
{
|
|
_font = font;
|
|
}
|
|
|
|
/// <summary>
|
|
/// the underline win-forms font.
|
|
/// </summary>
|
|
public Font Font
|
|
{
|
|
get { return _font; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the handle to this Font.
|
|
/// </summary>
|
|
public IntPtr HFont
|
|
{
|
|
get
|
|
{
|
|
if (_hFont == IntPtr.Zero)
|
|
_hFont = _font.ToHfont();
|
|
return _hFont;
|
|
}
|
|
}
|
|
|
|
public override double Size
|
|
{
|
|
get { return _font.Size; }
|
|
}
|
|
|
|
public override double UnderlineOffset
|
|
{
|
|
get { return _underlineOffset; }
|
|
}
|
|
|
|
public override double Height
|
|
{
|
|
get { return _height; }
|
|
}
|
|
|
|
public override double LeftPadding
|
|
{
|
|
get { return _height / 6f; }
|
|
}
|
|
|
|
public override double GetWhitespaceWidth(RGraphics graphics)
|
|
{
|
|
if (_whitespaceWidth < 0)
|
|
{
|
|
_whitespaceWidth = graphics.MeasureString(" ", this).Width;
|
|
}
|
|
return _whitespaceWidth;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set font metrics to be cached for the font for future use.
|
|
/// </summary>
|
|
/// <param name="height">the full height of the font</param>
|
|
/// <param name="underlineOffset">the vertical offset of the font underline location from the top of the font.</param>
|
|
internal void SetMetrics(int height, int underlineOffset)
|
|
{
|
|
_height = height;
|
|
_underlineOffset = underlineOffset;
|
|
}
|
|
}
|
|
} |