本文整理汇总了C#中System.Windows.FontStretch类的典型用法代码示例。如果您正苦于以下问题:C# FontStretch类的具体用法?C# FontStretch怎么用?C# FontStretch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FontStretch类属于System.Windows命名空间,在下文中一共展示了FontStretch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureText
internal Size MeasureText(string text, FontFamily fontFamily, FontStyle fontStyle,
FontWeight fontWeight,
FontStretch fontStretch, double fontSize)
{
var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
{
return MeasureTextSize(text, fontFamily, fontStyle, fontWeight, fontStretch, fontSize);
}
double totalWidth = 0;
double height = 0;
foreach (var t in text)
{
var glyphIndex = glyphTypeface.CharacterToGlyphMap[t];
var width = glyphTypeface.AdvanceWidths[glyphIndex] * fontSize;
var glyphHeight = glyphTypeface.AdvanceHeights[glyphIndex] * fontSize;
if (glyphHeight > height)
{
height = glyphHeight;
}
totalWidth += width;
}
return new Size(totalWidth, height);
}
示例2: SetStretch
public object SetStretch(object handle, FontStretch stretch)
{
var font = (FontData)handle;
font = font.Clone ();
font.Stretch = DataConverter.ToWpfFontStretch (stretch);
return font;
}
示例3: GraphicsText
public GraphicsText(
string text,
double left,
double top,
double right,
double bottom,
Color objectColor,
double textFontSize,
string textFontFamilyName,
FontStyle textFontStyle,
FontWeight textFontWeight,
FontStretch textFontStretch,
double actualScale)
{
this.text = text;
this.rectangleLeft = left;
this.rectangleTop = top;
this.rectangleRight = right;
this.rectangleBottom = bottom;
this.graphicsObjectColor = objectColor;
this.textFontSize = textFontSize;
this.textFontFamilyName = textFontFamilyName;
this.textFontStyle = textFontStyle;
this.textFontWeight = textFontWeight;
this.textFontStretch = textFontStretch;
this.graphicsActualScale = actualScale;
graphicsLineWidth = 2; // used for drawing bounding rectangle when selected
//RefreshDrawng();
}
示例4: WpfFontFamilyInfo
public WpfFontFamilyInfo(FontFamily family, FontWeight weight,
FontStyle style, FontStretch stretch)
{
_family = family;
_weight = weight;
_style = style;
_stretch = stretch;
}
示例5: ToFontAwesomeIcon
public static ImageSource ToFontAwesomeIcon(this string text, Brush foreBrush, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch)
{
var fontFamily = new FontFamily("/GitWorkItems;component/Resources/#FontAwesome");
if (fontFamily != null && !String.IsNullOrEmpty(text))
{
//premier essai, on charge la police directement
Typeface typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
{
//si ça ne fonctionne pas (et pour le mode design dans certains cas) on ajoute l'uri pack://application
typeface = new Typeface(new FontFamily(new Uri("pack://application:,,,"), fontFamily.Source), fontStyle, fontWeight, fontStretch);
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
throw new InvalidOperationException("No glyphtypeface found");
}
//détermination des indices/tailles des caractères dans la police
ushort[] glyphIndexes = new ushort[text.Length];
double[] advanceWidths = new double[text.Length];
for (int n = 0; n < text.Length; n++)
{
ushort glyphIndex;
try
{
glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];
}
catch (Exception)
{
glyphIndex = 42;
}
glyphIndexes[n] = glyphIndex;
double width = glyphTypeface.AdvanceWidths[glyphIndex] * 1.0;
advanceWidths[n] = width;
}
try
{
//création de l'objet DrawingImage (compatible avec Imagesource) à partir d'un glyphrun
GlyphRun gr = new GlyphRun(glyphTypeface, 0, false, 1.0, glyphIndexes,
new Point(0, 0), advanceWidths, null, null, null, null, null, null);
GlyphRunDrawing glyphRunDrawing = new GlyphRunDrawing(foreBrush, gr);
return new DrawingImage(glyphRunDrawing);
}
catch (Exception ex)
{
// ReSharper disable LocalizableElement
Console.WriteLine("Error in generating Glyphrun : " + ex.Message);
// ReSharper restore LocalizableElement
}
}
return null;
}
示例6: Create
public override object Create(string fontName, double size, FontStyle style, FontWeight weight, FontStretch stretch)
{
size = GetPointsFromDeviceUnits (size);
return new FontData (new FontFamily (fontName), size) {
Style = style.ToWpfFontStyle (),
Weight = weight.ToWpfFontWeight (),
Stretch = stretch.ToWpfFontStretch ()
};
}
示例7: Font
public Font(FontFamily family, double size, FontStyle style, FontWeight weight, FontStretch stretch)
: this()
{
this.Family = family;
this.Size = size;
this.Style = style;
this.Weight = weight;
this.Stretch = stretch;
}
示例8: FontInfo
public FontInfo(FontFamily fam, double sz, FontStyle style, FontStretch strc, FontWeight weight, SolidColorBrush c)
{
this.Family = fam;
this.Size = sz;
this.Style = style;
this.Stretch = strc;
this.Weight = weight;
this.BrushColor = c;
}
示例9: GetScreenSize
public static Size GetScreenSize(this string text, FontFamily fontFamily, double fontSize, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch) {
fontFamily = fontFamily ?? new TextBlock().FontFamily;
fontSize = fontSize > 0 ? fontSize : new TextBlock().FontSize;
var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
var ft = new FormattedText(text ?? string.Empty, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black);
return new Size(ft.Width, ft.Height);
}
示例10: MeasureText
public static Size MeasureText(string text, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, double fontSize)
{
FormattedText ft = new FormattedText(text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
fontSize,
Brushes.Black);
return new Size(ft.Width, ft.Height);
}
示例11: Font
public Font(FontFamily family, double size, FontStretch stretch, FontStyle style, FontWeight weight, Color foreground)
: this()
{
this.Family = family;
this.Size = size;
this.Stretch = stretch;
this.Style = style;
this.Weight = weight;
this.Foreground = foreground;
}
示例12: MatchingStyle
internal MatchingStyle(
FontStyle style,
FontWeight weight,
FontStretch stretch
)
{
_vector = new Vector(
(stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * FontStretchScale,
style.GetStyleForInternalConstruction() * FontStyleScale,
(weight.ToOpenTypeWeight() - FontWeights.Normal.ToOpenTypeWeight()) / 100.0 * FontWeightScale
);
}
示例13: ConstructFaceNamesByStyleWeightStretch
internal static IDictionary<XmlLanguage, string> ConstructFaceNamesByStyleWeightStretch(
FontStyle style,
FontWeight weight,
FontStretch stretch)
{
string faceName = BuildFaceName(style, weight, stretch);
// Default comparer calls CultureInfo.Equals, which works for our purposes.
Dictionary<XmlLanguage, string> faceNames = new Dictionary<XmlLanguage, string>(1);
faceNames.Add(XmlLanguage.GetLanguage("en-us"), faceName);
return faceNames;
}
示例14: BuildFaceName
private static string BuildFaceName(
FontStyle fontStyle,
FontWeight fontWeight,
FontStretch fontStretch
)
{
string parsedStyleName = null;
string parsedWeightName = null;
string parsedStretchName = null;
string regularFaceName = "Regular";
if (fontWeight != FontWeights.Normal)
parsedWeightName = ((IFormattable)fontWeight).ToString(null, CultureInfo.InvariantCulture);
if (fontStretch != FontStretches.Normal)
parsedStretchName = ((IFormattable)fontStretch).ToString(null, CultureInfo.InvariantCulture);
if (fontStyle != FontStyles.Normal)
parsedStyleName = ((IFormattable)fontStyle).ToString(null, CultureInfo.InvariantCulture);
// Build correct face string.
// Set the initial capacity to be able to hold the word "Regular".
StringBuilder faceNameBuilder = new StringBuilder(7);
if (parsedStretchName != null)
{
faceNameBuilder.Append(parsedStretchName);
}
if (parsedWeightName != null)
{
if (faceNameBuilder.Length > 0)
{
faceNameBuilder.Append(" ");
}
faceNameBuilder.Append(parsedWeightName);
}
if (parsedStyleName != null)
{
if (faceNameBuilder.Length > 0)
{
faceNameBuilder.Append(" ");
}
faceNameBuilder.Append(parsedStyleName);
}
if (faceNameBuilder.Length == 0)
{
faceNameBuilder.Append(regularFaceName);
}
return faceNameBuilder.ToString();
}
示例15: ToWpfFontStretch
public static SW.FontStretch ToWpfFontStretch(FontStretch value)
{
if (value == FontStretch.UltraCondensed) return SW.FontStretches.UltraCondensed;
if (value == FontStretch.ExtraCondensed) return SW.FontStretches.ExtraCondensed;
if (value == FontStretch.Condensed) return SW.FontStretches.Condensed;
if (value == FontStretch.SemiCondensed) return SW.FontStretches.SemiCondensed;
if (value == FontStretch.SemiExpanded) return SW.FontStretches.SemiExpanded;
if (value == FontStretch.Expanded) return SW.FontStretches.Expanded;
if (value == FontStretch.ExtraExpanded) return SW.FontStretches.ExtraExpanded;
if (value == FontStretch.UltraExpanded) return SW.FontStretches.UltraExpanded;
return SW.FontStretches.Normal;
}