mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-20 00:16:36 +08:00
xx
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Helpers
|
||||
{
|
||||
public class GetTextDisplayWidthHelper
|
||||
{
|
||||
public static Double GetTextDisplayWidth(Label label)
|
||||
{
|
||||
|
||||
return GetTextDisplayWidth(label.Content.ToString(), label.FontFamily, label.FontStyle, label.FontWeight, label.FontStretch, label.FontSize);
|
||||
|
||||
}
|
||||
|
||||
public static Double GetTextDisplayWidth(string str, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, double fontSize)
|
||||
{
|
||||
|
||||
var formattedText = new FormattedText(
|
||||
str,
|
||||
CultureInfo.CurrentUICulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
|
||||
fontSize,
|
||||
Brushes.Black
|
||||
);
|
||||
|
||||
Size size = new Size(formattedText.Width, formattedText.Height);
|
||||
|
||||
return size.Width;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user