本文整理汇总了C#中System.Windows.Media.DrawingContext.PushGuidelineY2方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingContext.PushGuidelineY2方法的具体用法?C# DrawingContext.PushGuidelineY2怎么用?C# DrawingContext.PushGuidelineY2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingContext
的用法示例。
在下文中一共展示了DrawingContext.PushGuidelineY2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
//.........这里部分代码省略.........
new Point(x, y),
charBufferRange,
displayGlyphAdvances,
EmSize,
TextRun.Properties.FontHintingEmSize,
Typeface.NullFont,
CultureMapper.GetSpecificCulture(TextRun.Properties.CultureInfo),
null, // device font name
_textFormatterImp.TextFormattingMode
);
if (glyphRun != null)
{
inkBoundingBox = glyphRun.ComputeInkBoundingBox();
}
else
{
inkBoundingBox = Rect.Empty;
}
if (!inkBoundingBox.IsEmpty)
{
// glyph run's ink bounding box is relative to its origin
inkBoundingBox.X += glyphRun.BaselineOrigin.X;
inkBoundingBox.Y += glyphRun.BaselineOrigin.Y;
}
if (drawingContext != null)
{
if (glyphRun != null)
{
glyphRun.EmitBackground(drawingContext, TextRun.Properties.BackgroundBrush);
drawingContext.DrawGlyphRun(foregroundBrush, glyphRun);
}
// draw underline here
if (Underline != null)
{
// Determine number of characters to underline. We don't underline trailing spaces
// if the TrimTrailingUnderline flag is set.
int underlineLength = Length;
if (TrimTrailingUnderline)
{
while (underlineLength > 0 && IsSpace(charBufferRange[underlineLength - 1]))
{
--underlineLength;
}
}
// Determine the width of the underline.
double dxUnderline = 0;
for (int i = 0; i < underlineLength; ++i)
{
dxUnderline += _textFormatterImp.IdealToReal(NominalAdvances[i]);
}
// We know only TextDecoration.Underline will be handled in Simple Path.
double offset = -Typeface.UnderlinePosition * EmSize;
double penThickness = Typeface.UnderlineThickness * EmSize;
Point lineOrigin = new Point(x, y + offset);
Rect underlineRect = new Rect(
lineOrigin.X,
lineOrigin.Y - penThickness * 0.5,
dxUnderline,
penThickness
);
// Apply the pair of guidelines: one for baseline and another
// for top edge of undelining line. Both will be snapped to pixel grid.
// Guideline pairing algorithm detects the case when these two
// guidelines happen to be close to one another and provides
// synchronous snapping, so that the gap between baseline and
// undelining line does not depend on the position of text line.
drawingContext.PushGuidelineY2(y, lineOrigin.Y - penThickness * 0.5 - y);
try
{
drawingContext.DrawRectangle(
foregroundBrush,
null, // pen
underlineRect
);
}
finally
{
drawingContext.Pop();
}
// underline pen thickness is always positive in fast path
inkBoundingBox.Union(
underlineRect
);
}
}
return inkBoundingBox;
}