本文整理汇总了C#中System.Windows.Media.Typeface类的典型用法代码示例。如果您正苦于以下问题:C# Typeface类的具体用法?C# Typeface怎么用?C# Typeface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Typeface类属于System.Windows.Media命名空间,在下文中一共展示了Typeface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawHelpText
/// <summary>
/// Draw some helpful text.
/// </summary>
/// <param name="dc"></param>
protected virtual void DrawHelpText(DrawingContext dc)
{
System.Windows.Media.Typeface backType =
new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily("sans courier"),
FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
System.Windows.Media.FormattedText formatted = new System.Windows.Media.FormattedText(
"Click & move the mouse to select a capture area.\nENTER/F10: Capture\nBACKSPACE/DEL: Start over\nESC: Exit",
System.Globalization.CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
backType,
32.0f,
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White));
// Make sure the text shows at 0,0 on the primary screen
System.Drawing.Point primScreen = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Location;
Point clientBase = PointFromScreen(new Point(primScreen.X + 5, primScreen.Y + 5));
Geometry textGeo = formatted.BuildGeometry(clientBase);
dc.DrawGeometry(
System.Windows.Media.Brushes.White,
null,
textGeo);
dc.DrawGeometry(
null,
new System.Windows.Media.Pen(System.Windows.Media.Brushes.White, 1),
textGeo);
}
示例2: FontInfo
public FontInfo(String Name, double Size, FontFamily Family)
{
this.Name = Name;
this.Size = Size;
this.Family = Family;
this.Typeface = Family.GetTypefaces().First();
}
示例3: ValueToProcessConverter
static ValueToProcessConverter()
{
NormalBrush = new SolidColorBrush(Colors.Orange);
WarnBrush = new SolidColorBrush(Colors.White);
TextBrush = new SolidColorBrush(Color.FromRgb(0x74,0x74,0x74));
SuccessRateTypeface = new Typeface(new FontFamily("MSYH"), new FontStyle(), new FontWeight(), new FontStretch());
}
示例4: Font
/// <summary>Creates a new <see cref="Font"/> instance from the given typeface and size.</summary>
public Font(Typeface typeface, double fontSize) {
Family = typeface.FontFamily;
Size = fontSize;
Stretch = typeface.Stretch;
Style = typeface.Style;
Weight = typeface.Weight;
}
示例5: GoBoardPainter
public GoBoardPainter()
{
Resources.Source = new Uri("pack://application:,,,/gui_wpf;component/GoBoardPainterResources.xaml");
m_BlackStoneBrush = (Brush)TryFindResource("blackStoneBrush");
m_WhiteStoneBrush = (Brush)TryFindResource("whiteStoneBrush");
m_BoardBrush = (Brush)TryFindResource("boardBrush");
m_StoneShadowBrush = (Brush)TryFindResource("stoneShadowBrush");
m_WhiteStoneAnnotationPen = (Pen)TryFindResource("whiteStoneAnnotationPen");
m_BlackStoneAnnotationPen = (Pen)TryFindResource("blackStoneAnnotationPen");
m_BoardBlackPen = (Pen)TryFindResource("boardBlackPen");
m_BlackPen = (Pen)TryFindResource("blackPen");
m_RedPen = (Pen)TryFindResource("redPen");
m_BlackStoneShadowBrush = (Brush)TryFindResource("blackStoneShadowBrush");
m_WhiteStoneShadowBrush = (Brush)TryFindResource("whiteStoneShadowBrush");
m_BoardTypeface = new Typeface("Arial");
KoPoint.X = -1;
LastMove.X = -1;
ForbiddenMove.X = -1;
DisplayCountedStones = false;
DisplayMouseOver = true;
InitializeBoard(this.BoardSize - 1);
// init tick for clock update
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(100);
timer.Tick += timer_Tick;
timer.Start();
}
示例6: TypefaceListItem
public TypefaceListItem(Typeface typeface)
{
_displayName = GetDisplayName(typeface);
_simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;
this.FontFamily = typeface.FontFamily;
this.FontWeight = typeface.Weight;
this.FontStyle = typeface.Style;
this.FontStretch = typeface.Stretch;
string itemLabel = _displayName;
//if (_simulated)
//{
// string formatString = EpiDashboard.Properties.Resources.ResourceManager.GetString(
// "simulated",
// CultureInfo.CurrentUICulture
// );
// itemLabel = string.Format(formatString, itemLabel);
//}
this.Text = itemLabel;
this.ToolTip = itemLabel;
// In the case of symbol font, apply the default message font to the text so it can be read.
if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
{
TextRange range = new TextRange(this.ContentStart, this.ContentEnd);
range.ApplyPropertyValue(TextBlock.FontFamilyProperty, SystemFonts.MessageFontFamily);
}
}
示例7: Transform
public override void Transform()
{
base.Transform();
IElementTextBlock elementText = (IElementTextBlock)Element;
var height = Rect.Height > Element.BorderThickness ? Rect.Height - Element.BorderThickness : 0;
var width = Rect.Width > Element.BorderThickness ? Rect.Width - Element.BorderThickness : 0;
Rect bound = new Rect(Rect.Left + Element.BorderThickness / 2, Rect.Top + Element.BorderThickness / 2, width, height);
var typeface = new Typeface(new FontFamily(elementText.FontFamilyName), elementText.FontItalic ? FontStyles.Italic : FontStyles.Normal, elementText.FontBold ? FontWeights.Bold : FontWeights.Normal, new FontStretch());
var formattedText = new FormattedText(elementText.Text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, elementText.FontSize, PainterCache.BlackBrush);
formattedText.TextAlignment = (TextAlignment)elementText.TextAlignment;
Point point = bound.TopLeft;
switch (formattedText.TextAlignment)
{
case TextAlignment.Right:
point = bound.TopRight;
break;
case TextAlignment.Center:
point = new Point(bound.Left + bound.Width / 2, bound.Top);
break;
}
if (_clipGeometry != null)
_clipGeometry.Rect = bound;
if (_scaleTransform != null)
{
_scaleTransform.CenterX = point.X;
_scaleTransform.CenterY = point.Y;
_scaleTransform.ScaleX = bound.Width / formattedText.Width;
_scaleTransform.ScaleY = bound.Height / formattedText.Height;
}
_textDrawing.Geometry = formattedText.BuildGeometry(point);
}
示例8: TypefaceListItem
public TypefaceListItem(Typeface typeface)
{
_displayName = GetDisplayName(typeface);
_simulated = typeface.IsBoldSimulated || typeface.IsObliqueSimulated;
FontFamily = typeface.FontFamily;
FontWeight = typeface.Weight;
FontStyle = typeface.Style;
FontStretch = typeface.Stretch;
var itemLabel = _displayName;
if (_simulated)
{
var formatString = Properties.Resources.ResourceManager.GetString(
"simulated",
CultureInfo.CurrentUICulture
);
itemLabel = string.Format(formatString, itemLabel);
}
Text = itemLabel;
ToolTip = itemLabel;
// In the case of symbol font, apply the default message font to the text so it can be read.
if (FontFamilyListItem.IsSymbolFont(typeface.FontFamily))
{
var range = new TextRange(ContentStart, ContentEnd);
range.ApplyPropertyValue(FontFamilyProperty, SystemFonts.MessageFontFamily);
}
}
示例9: GetPage
public override DocumentPage GetPage(int pageNumber)
{
// Get the requested page.
DocumentPage page = flowDocumentPaginator.GetPage(pageNumber);
// Wrap the page in a Visual. You can then add a transformation and extras.
ContainerVisual newVisual = new ContainerVisual();
newVisual.Children.Add(page.Visual);
// Create a header.
DrawingVisual header = new DrawingVisual();
using (DrawingContext context = header.RenderOpen())
{
Typeface typeface = new Typeface("Times New Roman");
FormattedText text = new FormattedText("Page " + (pageNumber + 1).ToString(),
CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
typeface, 14, Brushes.Black);
// Leave a quarter-inch of space between the page edge and this text.
context.DrawText(text, new Point(96*0.25, 96*0.25));
}
// Add the title to the visual.
newVisual.Children.Add(header);
// Wrap the visual in a new page.
DocumentPage newPage = new DocumentPage(newVisual);
return newPage;
}
示例10: CalculateIsTextTrimmed
/// <summary>
/// Determines whether or not the text in <paramref name="textBlock" /> is currently being
/// trimmed due to width or height constraints.
/// </summary>
/// <remarks>Does not work properly when TextWrapping is set to WrapWithOverflow.</remarks>
/// <param name="textBlock"><see cref="TextBlock" /> to evaluate</param>
/// <returns><c>true</c> if the text is currently being trimmed; otherwise <c>false</c></returns>
static bool CalculateIsTextTrimmed(TextBlock textBlock) {
if (!textBlock.IsArrangeValid)
return GetIsTextTrimmed(textBlock);
var typeface = new Typeface(
textBlock.FontFamily,
textBlock.FontStyle,
textBlock.FontWeight,
textBlock.FontStretch);
// FormattedText is used to measure the whole width of the text held up by TextBlock container
var formattedText = new FormattedText(
textBlock.Text,
Thread.CurrentThread.CurrentCulture,
textBlock.FlowDirection,
typeface,
textBlock.FontSize,
textBlock.Foreground) {MaxTextWidth = textBlock.ActualWidth};
// When the maximum text width of the FormattedText instance is set to the actual
// width of the textBlock, if the textBlock is being trimmed to fit then the formatted
// text will report a larger height than the textBlock. Should work whether the
// textBlock is single or multi-line.
return formattedText.Height > textBlock.ActualHeight;
}
示例11: 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);
}
示例12: GetTypeface
public static Typeface GetTypeface() {
if (typeface == null) {
typeface = CreateTypeface();
}
return typeface;
}
示例13: AddVisualText
public void AddVisualText(String text, String name_of_element, FontFamily fontFamily, Double fontSize, Point location, Double rotateAngle, Brush brush)
{
Typeface typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
DrawingContext dc;
DrawingVisual dv = new DrawingVisual();
FormattedText ft1 = new FormattedText(text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, fontSize, brush);
if (location.X == -1)
{
location = new Point(this.Width / 2 - ft1.Width / 2, location.Y);
}
if (location.Y == -1)
{
location = new Point(location.X, this.Height / 2 - ft1.Height / 2);
}
RotateTransform rt = new RotateTransform(rotateAngle, location.X + ft1.Width / 2, location.Y + ft1.Height / 2);
dc = dv.RenderOpen();
dc.PushTransform(rt);
dc.DrawText(ft1, location);
dc.Close();
this.visuals.Add(new NamedVisual(name_of_element, dv));
this.AddVisualChild(dv);
}
示例14: CreateTypeface
/// <summary>
/// Creates a typeface.
/// </summary>
public static Typeface CreateTypeface(XFontFamily family, XFontStyle style)
{
FontStyle fontStyle = FontStyleFromStyle(style);
FontWeight fontWeight = FontWeightFromStyle(style);
Typeface typeface = new Typeface(family.wpfFamily, fontStyle, fontWeight, FontStretches.Normal);
return typeface;
}
示例15: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var list = value as IReadOnlyCollection<FontFamily>;
if (list == null)
return DependencyProperty.UnsetValue;
var returnList = new List<FontFamily>();
foreach (FontFamily font in list)
{
try
{
// Instantiate a TypeFace object with the font settings you want to use
Typeface ltypFace = new Typeface(font, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
// Try to create a GlyphTypeface object from the TypeFace object
GlyphTypeface lglyphTypeFace;
if (ltypFace.TryGetGlyphTypeface(out lglyphTypeFace))
{
returnList.Add(font);
}
}
catch (Exception) {}
}
return returnList;
}