本文整理汇总了C#中System.Windows.Media.FormattedText.SetForegroundBrush方法的典型用法代码示例。如果您正苦于以下问题:C# FormattedText.SetForegroundBrush方法的具体用法?C# FormattedText.SetForegroundBrush怎么用?C# FormattedText.SetForegroundBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.FormattedText
的用法示例。
在下文中一共展示了FormattedText.SetForegroundBrush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawOutlined
public static void DrawOutlined(FormattedText text, double x, double y, Brush brush)
{
x -= text.Width / 2;
y -= text.Height / 2;
text.SetForegroundBrush(Brushes.Black);
_drawingContext.DrawText(text, new Point(x-1, y-1));
_drawingContext.DrawText(text, new Point(x+1, y+1));
_drawingContext.DrawText(text, new Point(x+1, y-1));
_drawingContext.DrawText(text, new Point(x-1, y+1));
text.SetForegroundBrush(brush);
_drawingContext.DrawText(text, new Point(x, y));
}
示例2: escribeTexto
private void escribeTexto()
{
string texto = "";
FormattedText frmTxt = new FormattedText(texto,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight, new Typeface("Verdana"), 32, Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
frmTxt.MaxTextWidth = 300;
frmTxt.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
frmTxt.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
frmTxt.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
frmTxt.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
frmTxt.SetFontStyle(FontStyles.Italic, 28, 28);
//// Draw the formatted text string to the DrawingContext of the control.
//drawingContext.DrawText(frmTxt, new Point(10, 0));
}
示例3: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
lock (_text)
{
if (RegularFont == null || FixedWidthFont == null) return;
foreach (var at in _text)
{
FontInfo f = RegularFont;
if (at.DisplayInfo.Font == ZFont.FIXED_WIDTH_FONT || at.DisplayInfo.ImplementsStyle(ZStyles.FIXED_WIDTH_STYLE))
{
f = FixedWidthFont;
}
Brush b = ZColorCheck.ZColorToBrush(at.DisplayInfo.ForegroundColor, Support.ColorType.Foreground);
FormattedText ft = new FormattedText(at.Text,
System.Globalization.CultureInfo.CurrentCulture,
FlowDirection.LeftToRight, f.Typeface, f.PointSize, b,
new NumberSubstitution(), TextFormattingMode.Display);
if (at.DisplayInfo.ImplementsStyle(ZStyles.REVERSE_STYLE))
{
drawingContext.DrawRectangle(b, null, new Rect(at.X + 2, at.Y + 2, ft.WidthIncludingTrailingWhitespace, Math.Max(ft.Height, FontHeight)));
ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(at.DisplayInfo.BackgroundColor, Support.ColorType.Background));
}
drawingContext.DrawText(ft, new Point(at.X + 2, at.Y + 2));
// Note: Offsetting positions by 2 to get everything to line up correctly
}
}
}
示例4: GetFormattedText
public static FormattedText GetFormattedText(this FlowDocument doc)
{
if (doc == null)
{
throw new ArgumentNullException("doc");
}
FormattedText output = new FormattedText(
GetText(doc),
CultureInfo.CurrentCulture,
doc.FlowDirection,
new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
doc.FontSize,
doc.Foreground);
int offset = 0;
foreach (TextElement el in GetRunsAndParagraphs(doc))
{
Run run = el as Run;
if (run != null)
{
int count = run.Text.Length;
output.SetFontFamily(run.FontFamily, offset, count);
output.SetFontStyle(run.FontStyle, offset, count);
output.SetFontWeight(run.FontWeight, offset, count);
output.SetFontSize(run.FontSize, offset, count);
output.SetForegroundBrush(run.Foreground, offset, count);
output.SetFontStretch(run.FontStretch, offset, count);
output.SetTextDecorations(run.TextDecorations, offset, count);
offset += count;
}
else
{
offset += Environment.NewLine.Length;
}
}
return output;
}
示例5: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
//drawingContext.DrawRectangle(Brushes.Crimson, null, new Rect(new Point(0, 0), new Point(500, 500)));
//base.OnRender(drawingContext);
//return;
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
32,
Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
// Draw the formatted text string to the DrawingContext of the control.
drawingContext.DrawText(formattedText, new Point(10, 0));
}
示例6: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
FormattedText text = new FormattedText("AZIM",
System.Globalization.CultureInfo.GetCultureInfo("en-US"),
FlowDirection.LeftToRight, new Typeface("LilyUPC"), 256, Brushes.Black);
text.MaxTextWidth = 700;
text.MaxTextHeight = 400;
LinearGradientBrush brush = new LinearGradientBrush(); // Create a LinearGradientBrush
// Set GradientStops
brush.GradientStops.Add(new GradientStop(Colors.Red, 0.2));
brush.GradientStops.Add(new GradientStop(Colors.Green, 0.3));
brush.GradientStops.Add(new GradientStop(Colors.Blue, 0.5));
brush.GradientStops.Add(new GradientStop(Colors.Magenta, 0.7));
brush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.8));
brush.GradientStops.Add(new GradientStop(Colors.Cyan, 0.9));
text.SetForegroundBrush(brush, 0, 4); // Apply formatting to 4 chars starting from first char
drawingContext.DrawText(text, new Point(10, 0)); // Draw text on the Window
base.OnRender(drawingContext);
drawingContext.DrawText(text, new Point(10, 0));
}
示例7: Self_DrawText
public void Self_DrawText()
{
DrawingContext dc = drawvis.RenderOpen();
renderbit.Clear();
// 글씨 쓰기
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
System.Globalization.CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
30,
Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 2, 3);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
// Draw the formatted text string to the DrawingContext of the control.
dc.DrawText(formattedText, new Point(100, 150));
dc.Close();
renderbit.Render(drawvis);
}
示例8: DrawText
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
{
var formattedText = new FormattedText(text, CultureInfo.InvariantCulture, System.Windows.FlowDirection.LeftToRight, font.GetTypeface(), font.Size, null);
formattedText.SetForegroundBrush(brush?.GetBrush());
dc.DrawText(formattedText, frame.BottomLeft.GetPoint());
}
示例9: FormatLine
public void FormatLine(int line, FormattedText text)
{
foreach (var provider in this.providers)
{
TextChange change;
var formatInfos = provider.GetFormatDataForLine(line, out change);
if (formatInfos != null)
{
foreach (var info in formatInfos)
{
var range = info.Range;
if (change != null)
{
for (var c = change.NextChange; c != null; c = c.NextChange)
{
range = c.ApplyTo(range);
}
}
int start = (range.Start.Line < line) ? 0 : range.Start.Index;
int end = (range.End.Line > line) ? this.Buffer.TextData.Lines[line].Length : range.End.Index;
if (end > start && end <= this.Buffer.TextData.Lines[line].Length)
{
if (info.Foreground != null)
{
text.SetForegroundBrush(info.Foreground, start, end - start);
}
if (info.Flags.HasFlag(FormatFlags.Bold))
{
text.SetFontWeight(FontWeights.Bold, start, end - start);
}
if (info.Flags.HasFlag(FormatFlags.Italic))
{
text.SetFontStyle(FontStyles.Italic, start, end - start);
}
if (info.Flags.HasFlag(FormatFlags.Underline))
{
var decorations = new TextDecorationCollection(new TextDecoration[] { new TextDecoration(TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended) });
text.SetTextDecorations(decorations, start, end - start);
}
}
}
}
}
}
示例10: Highlight
public int Highlight(FormattedText text, int previousBlockCode)
{
//
// WORDS RULES
//
Regex wordsRgx = new Regex("[a-zA-Z_][a-zA-Z0-9_]*");
foreach (Match m in wordsRgx.Matches(text.Text))
{
foreach (HighlightWordsRule rule in wordsRules)
{
foreach (string word in rule.Words)
{
if (rule.Options.IgnoreCase)
{
if (m.Value.Equals(word, StringComparison.InvariantCultureIgnoreCase))
{
text.SetForegroundBrush(rule.Options.Foreground, m.Index, m.Length);
text.SetFontWeight(rule.Options.FontWeight, m.Index, m.Length);
text.SetFontStyle(rule.Options.FontStyle, m.Index, m.Length);
}
}
else
{
if (m.Value == word)
{
text.SetForegroundBrush(rule.Options.Foreground, m.Index, m.Length);
text.SetFontWeight(rule.Options.FontWeight, m.Index, m.Length);
text.SetFontStyle(rule.Options.FontStyle, m.Index, m.Length);
}
}
}
}
}
//
// REGEX RULES
//
foreach (AdvancedHighlightRule rule in regexRules)
{
Regex regexRgx = new Regex(rule.Expression);
foreach (Match m in regexRgx.Matches(text.Text))
{
text.SetForegroundBrush(rule.Options.Foreground, m.Index, m.Length);
text.SetFontWeight(rule.Options.FontWeight, m.Index, m.Length);
text.SetFontStyle(rule.Options.FontStyle, m.Index, m.Length);
}
}
//
// LINES RULES
//
foreach (HighlightLineRule rule in lineRules)
{
Regex lineRgx = new Regex(Regex.Escape(rule.LineStart) + ".*");
foreach (Match m in lineRgx.Matches(text.Text))
{
text.SetForegroundBrush(rule.Options.Foreground, m.Index, m.Length);
text.SetFontWeight(rule.Options.FontWeight, m.Index, m.Length);
text.SetFontStyle(rule.Options.FontStyle, m.Index, m.Length);
}
}
return -1;
}
示例11: HighlightSyntax
private void HighlightSyntax(FormattedText formattedText)
{
if (SyntaxParser != null)
{
foreach (var tag in SyntaxParser.Tags)
{
var style = GetHighlightStyleFor(tag.Type);
if (style != null)
{
formattedText.SetForegroundBrush(style.Foreground, tag.StartPosition, tag.Length);
}
}
}
formattedText.Trimming = TextTrimming.None;
}
示例12: GetFormattedText
private static FormattedText GetFormattedText(FlowDocument doc)
{
var output = new FormattedText(
GetText(doc),
CultureInfo.CurrentCulture,
doc.FlowDirection,
new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
doc.FontSize,
doc.Foreground);
int offset = 0;
foreach (TextElement textElement in GetRunsAndParagraphs(doc))
{
var run = textElement as Run;
if (run != null)
{
int count = run.Text.Length;
output.SetFontFamily(run.FontFamily, offset, count);
output.SetFontSize(run.FontSize, offset, count);
output.SetFontStretch(run.FontStretch, offset, count);
output.SetFontStyle(run.FontStyle, offset, count);
output.SetFontWeight(run.FontWeight, offset, count);
output.SetForegroundBrush(run.Foreground, offset, count);
output.SetTextDecorations(run.TextDecorations, offset, count);
offset += count;
}
else
{
offset += Environment.NewLine.Length;
}
}
return output;
}
示例13: _formatBody
private void _formatBody() {
var showMembers = Canvas.DisplayOptions.Has(DisplayOptions.DisplayClassMembers);
var showInherited = Canvas.DisplayOptions.Has(DisplayOptions.DisplayInheritedMembers);
var sortMembers = Canvas.DisplayOptions.Has(DisplayOptions.SortMembersByName);
if (!showMembers) {
_bodyText = null;
return;
}
var bodyParts = new List<string>();
var bodyStyles = new List<TextStyle>();
Action<string, TextStyle> addPart = (t, s) => { bodyParts.Add(t); bodyStyles.Add(s); };
Action addSpacer = () => addPart("-\n", TextStyle.Spacer);
Action<BplClass> addProperties = bplClass => {
var properties = (showInherited ? bplClass.Properties : bplClass.OwnProperties);
if (sortMembers) {
properties = properties.OrderBy(p => p.Name);
}
foreach (var prop in properties) {
var name = prop.Name.At(0).ToUpper() + prop.Name.After(0);
var type = String.Empty;
if (prop.IsPrimitive) {
type = prop.PrimitiveType.Name;
} else {
if (prop.IsReference) {
type = prop.UnderlyingType.Name;
} else if (prop.IsCollection) {
type = prop.UnderlyingItemType.Name + "*";
}
}
addPart("\u2022 " + name, (prop == bplClass.IdentityProperty ? TextStyle.Identity : TextStyle.FieldName));
addPart(" (" + type + ")\n", TextStyle.DataType);
}
};
var operation = Class.Operation;
if (operation == null) {
addProperties(Class);
} else {
addPart("INPUT:\n", TextStyle.Subtitle);
addSpacer();
addProperties(Class);
if (operation.Output != null) {
addSpacer();
addSpacer();
addPart("OUTPUT:\n", TextStyle.Subtitle);
addSpacer();
addProperties(operation.Output);
}
}
_bodyText = ToFormattedText(bodyParts.ToArray().Join(), 14, _normalFG);
for (int i = 0, j = 0; i < bodyParts.Count; i++) {
var k = bodyParts[i].Length;
switch(bodyStyles[i]) {
case TextStyle.Identity:
_bodyText.SetTextDecorations(TextDecorations.Underline, j + 2, k - 2);
break;
case TextStyle.DataType:
_bodyText.SetForegroundBrush(_lightFG, j, k);
_bodyText.SetFontStyle(FontStyles.Italic, j + 2, k - 4);
break;
case TextStyle.Subtitle:
_bodyText.SetFontSize(13, j, k);
_bodyText.SetTextDecorations(TextDecorations.Underline, j, k);
break;
case TextStyle.Spacer:
_bodyText.SetForegroundBrush(_bodyBG.Fill, j, k);
_bodyText.SetFontSize(3, j, k);
break;
}
j += k;
}
}
示例14: setStyle
public void setStyle(CharDisplayInfo fs, int count, FormattedText ft)
{
if ((fs.Style & (int)ZStyles.BOLDFACE_STYLE) > 0)
{
ft.SetFontWeight(FontWeights.Bold);
}
if ((fs.Style & (int)ZStyles.REVERSE_STYLE) > 0)
{
ft.SetFontWeight(FontWeights.Bold);
ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.BackgroundColor, ColorType.Background));
}
else
{
ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.ForegroundColor, ColorType.Foreground));
}
if ((fs.Style & (int)ZStyles.EMPHASIS_STYLE) > 0)
{
ft.SetFontStyle(FontStyles.Italic);
}
if ((fs.Style & (int)ZStyles.FIXED_WIDTH_STYLE) > 0)
{
ft.SetFontFamily(_fixedFont.Family);
}
}
示例15: setStyle
public void setStyle(CharDisplayInfo fs, FontChanges fc, FormattedText ft, DrawingContext dc)
{
int startPos = fc.Offset + fc.StartCol;
if ((fs.Style & (int)ZStyles.BOLDFACE_STYLE) > 0)
{
ft.SetFontWeight(FontWeights.Bold, startPos, fc.Count);
}
int rectColor = -1;
ColorType type = ColorType.Foreground;
if ((fs.Style & (int)ZStyles.REVERSE_STYLE) > 0)
{
ft.SetFontWeight(FontWeights.Bold, startPos, fc.Count);
ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.BackgroundColor, ColorType.Background), startPos, fc.Count);
rectColor = fs.ForegroundColor;
}
else
{
ft.SetForegroundBrush(ZColorCheck.ZColorToBrush(fs.ForegroundColor, ColorType.Foreground), startPos, fc.Count);
if (fs.BackgroundColor > 1 && fs.BackgroundColor != bColor)
{
rectColor = fs.BackgroundColor;
type = ColorType.Background;
}
}
if ((fs.Style & (int)ZStyles.EMPHASIS_STYLE) > 0)
{
ft.SetFontStyle(FontStyles.Italic, startPos, fc.Count);
}
if ((fs.Style & (int)ZStyles.FIXED_WIDTH_STYLE) > 0)
{
ft.SetFontFamily(_fixedFont.Family, startPos, fc.Count);
}
if (dc != null && rectColor != -1)
{
Brush b = ZColorCheck.ZColorToBrush(rectColor, type);
dc.DrawRectangle(b, null,
new Rect(fc.StartCol * charWidth, fc.Line * charHeight,
fc.Count * charWidth, charHeight));
}
}