* ISymbol: 将字体图标最大尺寸从64调整到128

This commit is contained in:
Sunny 2021-07-18 22:29:01 +08:00
parent 782c45c162
commit 609791b3d3
22 changed files with 82 additions and 230 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,131 +1,4 @@
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\Administrator\source\repos\SunnyUI\SunnyUI\ codebase based on best match to current usage at 2021/7/15
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]
[*.cs]
#Core editorconfig formatting - indentation
#use soft tabs (spaces) for indentation
indent_style = space
#Formatting - indentation options
#indent switch case contents.
csharp_indent_case_contents = true
#indent switch labels
csharp_indent_switch_labels = true
#Formatting - new line options
#place catch statements on a new line
csharp_new_line_before_catch = true
#place else statements on a new line
csharp_new_line_before_else = true
#require members of object initializers to be on the same line
csharp_new_line_before_members_in_object_initializers = false
#require braces to be on a new line for accessors, object_collection_array_initializers, methods, types, control_blocks, and properties (also known as "Allman" style)
csharp_new_line_before_open_brace = accessors, object_collection_array_initializers, methods, types, control_blocks, properties
#require elements of query expression clauses to be on the same line
csharp_new_line_between_query_expression_clauses = false
#Formatting - organize using options
#sort System.* using directives alphabetically, and place them before other usings
dotnet_sort_system_directives_first = true
#Formatting - spacing options
#require NO space between a cast and the value
csharp_space_after_cast = false
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_after_colon_in_inheritance_clause = true
#require a space after a keyword in a control flow statement such as a for loop
csharp_space_after_keywords_in_control_flow_statements = true
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_before_colon_in_inheritance_clause = true
#remove space within empty argument list parentheses
csharp_space_between_method_call_empty_parameter_list_parentheses = false
#remove space between method call name and opening parenthesis
csharp_space_between_method_call_name_and_opening_parenthesis = false
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
csharp_space_between_method_call_parameter_list_parentheses = false
#remove space within empty parameter list parentheses for a method declaration
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false
#Formatting - wrapping options
#leave code block on separate lines
csharp_preserve_single_line_blocks = false
#leave statements and member declarations on the same line
csharp_preserve_single_line_statements = true
#Style - Code block preferences
#prefer no curly braces if allowed
csharp_prefer_braces = false:suggestion
#Style - expression bodied member options
#prefer expression-bodied members for accessors
csharp_style_expression_bodied_accessors = true:suggestion
#prefer block bodies for constructors
csharp_style_expression_bodied_constructors = false:suggestion
#prefer block bodies for methods
csharp_style_expression_bodied_methods = false:suggestion
#prefer expression-bodied members for properties
csharp_style_expression_bodied_properties = true:suggestion
#Style - expression level options
#prefer out variables to be declared inline in the argument list of a method call when possible
csharp_style_inlined_variable_declaration = true:suggestion
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_member_access = true:suggestion
#Style - Expression-level preferences
#prefer objects to not be initialized using object initializers
dotnet_style_object_initializer = false:suggestion
#Style - implicit and explicit types
#prefer explicit type over var in all cases, unless overridden by another code style rule
csharp_style_var_elsewhere = false:suggestion
#prefer explicit type over var to declare variables with built-in system types such as int
csharp_style_var_for_built_in_types = false:suggestion
#prefer explicit type over var when the type is already mentioned on the right-hand side of a declaration
csharp_style_var_when_type_is_apparent = false:suggestion
#Style - language keyword and framework type options
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
#Style - modifier options
#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
#Style - Modifier preferences
#when this rule is set to a list of modifiers, prefer the specified ordering.
csharp_preferred_modifier_order = public,private,protected,internal,static,override,readonly,virtual,extern,new,sealed:suggestion
#Style - Pattern matching
#prefer pattern matching instead of is expression with type casts
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
#Style - qualification options
#prefer events not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_event = false:suggestion
#prefer fields not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_field = false:suggestion
#prefer methods not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_method = false:suggestion
#prefer properties not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_property = false:suggestion
# Default severity for analyzer diagnostics with category 'Style'
dotnet_analyzer_diagnostic.category-Style.severity = none

View File

@ -189,7 +189,7 @@ namespace Sunny.UI
if (symbolSize != value)
{
symbolSize = Math.Max(value, 16);
symbolSize = Math.Min(value, 64);
symbolSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -69,7 +69,7 @@ namespace Sunny.UI
set
{
symbolSize = Math.Max(value, 16);
symbolSize = Math.Min(value, 64);
symbolSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -87,7 +87,7 @@ namespace Sunny.UI
set
{
_imageSize = Math.Max(value, 16);
_imageSize = Math.Min(value, 64);
_imageSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -105,7 +105,7 @@ namespace Sunny.UI
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
_symbolSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -491,11 +491,13 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
this.SuspendLayout();
UIStyleHelper.SetChildUIStyle(this, style);
UIBaseStyle uiColor = UIStyles.GetStyleColor(style);
if (!uiColor.IsCustom()) SetStyleColor(uiColor);
_style = style;
this.ResumeLayout();
}
public virtual void SetStyleColor(UIBaseStyle uiColor)

View File

@ -104,7 +104,7 @@ namespace Sunny.UI
set
{
_imageSize = Math.Max(value, 16);
_imageSize = Math.Min(value, 64);
_imageSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -49,14 +49,17 @@ namespace Sunny.UI
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
_symbolSize = Math.Min(value, 128);
Invalidate();
}
}
[DefaultValue(null)]
[Description("图片"), Category("SunnyUI")]
public Image Image { get; set; }
public Image Image
{
get; set;
}
private ContentAlignment imageAlign = ContentAlignment.MiddleCenter;

View File

@ -93,7 +93,7 @@ namespace Sunny.UI
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
_symbolSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -21,13 +21,13 @@
* 2020-08-12: V2.2.7
******************************************************************************/
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Sunny.UI.Win32;
namespace Sunny.UI
{
@ -641,7 +641,7 @@ namespace Sunny.UI
List<UIPage> pages;
if (LastIndex != SelectedIndex)
{
if (LastIndex >= 0 && TabPages.Count > 0)
if (LastIndex >= 0 && TabPages.Count > 0 && LastIndex < TabPages.Count)
{
pages = TabPages[LastIndex].GetControls<UIPage>();
foreach (var page in pages)

View File

@ -56,8 +56,10 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
this.SuspendLayout();
UIStyleHelper.SetChildUIStyle(this, style);
_style = style;
this.ResumeLayout();
}
public void SetStyleColor(UIBaseStyle uiColor)

View File

@ -102,10 +102,9 @@ namespace Sunny.UI
/// <param name="symbol">字符</param>
/// <param name="symbolSize">大小</param>
/// <returns>字体大小</returns>
public static SizeF GetFontImageSize(this Graphics graphics, int symbol, int symbolSize,
UISymbolType symbolType = UISymbolType.FontAwesomeV4)
public static SizeF GetFontImageSize(this Graphics graphics, int symbol, int symbolSize)
{
Font font = GetFont(symbol, symbolSize, symbolType);
Font font = GetFont(symbol, symbolSize);
if (font == null)
{
return new SizeF(0, 0);
@ -114,41 +113,14 @@ namespace Sunny.UI
return graphics.MeasureString(char.ConvertFromUtf32(symbol), font);
}
/// <summary>
/// 绘制字体图片
/// </summary>
/// <param name="graphics">GDI绘图</param>
/// <param name="symbol">字符</param>
/// <param name="symbolSize">大小</param>
/// <param name="color">颜色</param>
/// <param name="left">左</param>
/// <param name="top">上</param>
/// <param name="xOffset">左右偏移</param>
/// <param name="yOffSet">上下偏移</param>
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
float left, float top, int xOffset = 0, int yOffSet = 0)
private static UISymbolType GetSymbolType(int symbol)
{
UISymbolType symbolType = (UISymbolType)symbol.Div(100000);
graphics.DrawFontImage(symbol, symbolSize, color, left, top, xOffset, yOffSet, symbolType);
return (UISymbolType)symbol.Div(100000);
}
/// <summary>
/// 绘制字体图片
/// </summary>
/// <param name="graphics">GDI绘图</param>
/// <param name="symbol">字符</param>
/// <param name="symbolSize">大小</param>
/// <param name="color">颜色</param>
/// <param name="rect">区域</param>
/// <param name="xOffset">左右偏移</param>
/// <param name="yOffSet">上下偏移</param>
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
Rectangle rect, int xOffset = 0, int yOffSet = 0)
private static int GetSymbolValue(int symbol)
{
UISymbolType symbolType = (UISymbolType)symbol.Div(100000);
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize, symbolType);
graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(),
rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet, symbolType);
return symbol.Mod(100000);
}
/// <summary>
@ -165,9 +137,9 @@ namespace Sunny.UI
RectangleF rect, int xOffset = 0, int yOffSet = 0)
{
UISymbolType symbolType = (UISymbolType)symbol.Div(100000);
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize, symbolType);
SizeF sf = graphics.GetFontImageSize(symbol, symbolSize);
graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(),
rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet, symbolType);
rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet);
}
/// <summary>
@ -181,18 +153,18 @@ namespace Sunny.UI
/// <param name="top">上</param>
/// <param name="xOffset">左右偏移</param>
/// <param name="yOffSet">上下偏移</param>
private static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
float left, float top, int xOffset, int yOffSet, UISymbolType symbolType)
public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color,
float left, float top, int xOffset = 0, int yOffSet = 0)
{
symbol = symbol.Mod(100000);
//字体
Font font = GetFont(symbol, symbolSize, symbolType);
Font font = GetFont(symbol, symbolSize);
if (font == null)
{
return;
}
string text = char.ConvertFromUtf32(symbol);
var symbolValue = GetSymbolValue(symbol);
string text = char.ConvertFromUtf32(symbolValue);
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
graphics.DrawString(text, font, color, left + xOffset, top + yOffSet);
@ -207,14 +179,14 @@ namespace Sunny.UI
/// <param name="size">大小</param>
/// <param name="color">颜色</param>
/// <returns>图片</returns>
public static Image CreateImage(int symbol, int size, Color color, UISymbolType symbolType = UISymbolType.FontAwesomeV4)
public static Image CreateImage(int symbol, int size, Color color)
{
Bitmap image = new Bitmap(size, size);
using (Graphics g = image.Graphics())
{
SizeF sf = g.GetFontImageSize(symbol, size, symbolType);
g.DrawFontImage(symbol, size, color, (image.Width - sf.Width) / 2.0f, (image.Height - sf.Height) / 2.0f, 0, 0, symbolType);
SizeF sf = g.GetFontImageSize(symbol, size);
g.DrawFontImage(symbol, size, color, (image.Width - sf.Width) / 2.0f, (image.Height - sf.Height) / 2.0f, 0, 0);
}
return image;
@ -226,26 +198,28 @@ namespace Sunny.UI
/// <param name="symbol">字符</param>
/// <param name="imageSize">大小</param>
/// <returns>字体</returns>
public static Font GetFont(int symbol, int imageSize, UISymbolType symbolType = UISymbolType.FontAwesomeV4)
public static Font GetFont(int symbol, int imageSize)
{
var symbolType = GetSymbolType(symbol);
var symbolValue = GetSymbolValue(symbol);
switch (symbolType)
{
case UISymbolType.FontAwesomeV4:
if (symbol > 0xF000)
return FontAwesomeV4.GetFont(symbol, imageSize);
return FontAwesomeV4.GetFont(symbolValue, imageSize);
else
return ElegantIcons.GetFont(symbol, imageSize);
return ElegantIcons.GetFont(symbolValue, imageSize);
case UISymbolType.FontAwesomeV5Brands:
return FontAwesomeV5Brands.GetFont(symbol, imageSize);
return FontAwesomeV5Brands.GetFont(symbolValue, imageSize);
case UISymbolType.FontAwesomeV5Regular:
return FontAwesomeV5Regular.GetFont(symbol, imageSize);
return FontAwesomeV5Regular.GetFont(symbolValue, imageSize);
case UISymbolType.FontAwesomeV5Solid:
return FontAwesomeV5Solid.GetFont(symbol, imageSize);
return FontAwesomeV5Solid.GetFont(symbolValue, imageSize);
default:
if (symbol > 0xF000)
return FontAwesomeV4.GetFont(symbol, imageSize);
return FontAwesomeV4.GetFont(symbolValue, imageSize);
else
return ElegantIcons.GetFont(symbol, imageSize);
return ElegantIcons.GetFont(symbolValue, imageSize);
}
}
}
@ -258,19 +232,9 @@ namespace Sunny.UI
private readonly PrivateFontCollection ImageFont;
private readonly Dictionary<int, Font> Fonts = new Dictionary<int, Font>();
private const int MinFontSize = 8;
private const int MaxFontSize = 43;
private const int MaxFontSize = 88;
private readonly IntPtr memoryFont = IntPtr.Zero;
/// <summary>
/// 大小
/// </summary>
public int IconSize { get; set; } = 128;
/// <summary>
/// 背景色
/// </summary>
public Color BackColor { get; set; } = Color.Transparent;
public FontImages(byte[] buffer)
{
ImageFont = new PrivateFontCollection();
@ -299,7 +263,10 @@ namespace Sunny.UI
/// <summary>
/// 字体加载完成标志
/// </summary>
public bool Loaded { get; }
public bool Loaded
{
get;
}
private void LoadDictionary()
{
@ -349,31 +316,34 @@ namespace Sunny.UI
/// <summary>
/// 获取字体大小
/// </summary>
/// <param name="iconText">图标</param>
/// <param name="symbol">ͼ±ê</param>
/// <param name="imageSize">图标大小</param>
/// <returns>字体大小</returns>
public int GetFontSize(int iconText, int imageSize)
public int GetFontSize(int symbol, int imageSize)
{
int size = MaxFontSize;
int interval = MaxFontSize - MinFontSize;
using (Bitmap bitmap = new Bitmap(48, 48))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
for (int i = 0; i <= interval; i++)
{
Font font = Fonts[size];
SizeF sf = GetIconSize(iconText, graphics, font);
return BinarySearch(graphics, MinFontSize, MaxFontSize, symbol, imageSize);
}
}
if (sf.Width < imageSize && sf.Height < imageSize)
{
break;
}
size -= 1;
}
public int BinarySearch(Graphics graphics, int low, int high, int symbol, int imageSize)
{
int mid = (low + high) / 2;
Font font = Fonts[mid];
SizeF sf = GetIconSize(symbol, graphics, font);
if (low >= high)
{
return mid;
}
return size;
if (sf.Width < imageSize && sf.Height < imageSize)
{
return BinarySearch(graphics, mid + 1, high, symbol, imageSize);
}
return BinarySearch(graphics, low, mid - 1, symbol, imageSize);
}
private Size GetIconSize(int iconText, Graphics graphics, Font font)

View File

@ -239,7 +239,7 @@ namespace Sunny.UI
AutoSize = false,
Size = new Size(32, 32),
ForeColor = UIColor.Blue,
Image = FontImageHelper.CreateImage(icon, 28, UIFontColor.Primary, symbolType),
Image = FontImageHelper.CreateImage(icon + (int)symbolType * 100000, 28, UIFontColor.Primary),
ImageAlign = ContentAlignment.MiddleCenter,
TextAlign = ContentAlignment.MiddleLeft,
Margin = new Padding(2)
@ -256,14 +256,14 @@ namespace Sunny.UI
{
Label lbl = (Label)sender;
SymbolValue symbol = (SymbolValue)lbl.Tag;
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol, 28, UIFontColor.Primary, symbol.SymbolType);
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol + (int)symbol.SymbolType * 100000, 28, UIFontColor.Primary);
}
private void Lbl_MouseEnter(object sender, EventArgs e)
{
Label lbl = (Label)sender;
SymbolValue symbol = (SymbolValue)lbl.Tag;
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol, 28, UIColor.Blue, symbol.SymbolType);
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol + (int)symbol.SymbolType * 100000, 28, UIColor.Blue);
}
public int Symbol { get; set; }

View File

@ -123,7 +123,7 @@ namespace Sunny.UI
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
_symbolSize = Math.Min(value, 128);
Invalidate();
}
}
@ -1074,6 +1074,7 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
this.SuspendLayout();
UIStyleHelper.SetChildUIStyle(this, style);
btn.SetStyle(style);
@ -1081,6 +1082,7 @@ namespace Sunny.UI
if (!uiColor.IsCustom()) SetStyleColor(uiColor);
_style = style;
UIStyleChanged?.Invoke(this, new EventArgs());
this.ResumeLayout();
}
public event EventHandler UIStyleChanged;

View File

@ -77,7 +77,7 @@ namespace Sunny.UI
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
_symbolSize = Math.Min(value, 128);
SymbolChange();
Invalidate();
}
@ -280,12 +280,14 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
this.SuspendLayout();
UIStyleHelper.SetChildUIStyle(this, style);
UIBaseStyle uiColor = UIStyles.GetStyleColor(style);
if (!uiColor.IsCustom()) SetStyleColor(uiColor);
_style = style;
UIStyleChanged?.Invoke(this, new EventArgs());
this.ResumeLayout();
}
public event EventHandler UIStyleChanged;

View File

@ -19,6 +19,7 @@
* 2020-01-01: V2.2.0
******************************************************************************/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
@ -171,7 +172,8 @@ namespace Sunny.UI
get => symbolSize;
set
{
symbolSize = value;
symbolSize = Math.Max(value, 16);
symbolSize = Math.Min(value, 128);
Invalidate();
}
}

View File

@ -741,8 +741,6 @@ namespace Sunny.UI
public static void SetChildUIStyle(Control ctrl, UIStyle style)
{
ctrl.SuspendLayout();
List<Control> controls = ctrl.GetUIStyleControls("IStyleInterface");
foreach (var control in controls)
{
@ -767,8 +765,6 @@ namespace Sunny.UI
}
}
}
ctrl.ResumeLayout();
}
/// <summary>