本文整理汇总了C#中System.Drawing.Brush.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# Brush.Setup方法的具体用法?C# Brush.Setup怎么用?C# Brush.Setup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Brush
的用法示例。
在下文中一共展示了Brush.Setup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawString
public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format = null)
{
if (font == null)
throw new ArgumentNullException ("font");
if (brush == null)
throw new ArgumentNullException ("brush");
if (s == null || s.Length == 0)
return;
if (format == null)
{
format = StringFormat.GenericDefault;
}
// TODO: Take into consideration units
// Not sure we need the Save and Restore around this yet.
context.SaveState();
// TextMatrix is not part of the Graphics State and Restore
var saveMatrix = context.TextMatrix;
bool layoutAvailable = true;
// context.SelectFont ( font.nativeFont.PostScriptName,
// font.SizeInPoints,
// CGTextEncoding.MacRoman);
//
// context.SetCharacterSpacing(1);
// context.SetTextDrawingMode(CGTextDrawingMode.Fill); // 5
//
// // Setup both the stroke and the fill ?
// brush.Setup(this, true);
// brush.Setup(this, false);
//
// var textMatrix = font.nativeFont.Matrix;
//
// textMatrix.Scale(1,-1);
// context.TextMatrix = textMatrix;
//
// context.ShowTextAtPoint(layoutRectangle.X,
// layoutRectangle.Y + font.nativeFont.CapHeightMetric, s);
//
//
// First we call the brush with a fill of false so the brush can setup the stroke color
// that the text will be using.
// For LinearGradientBrush this will setup a TransparentLayer so the gradient can
// be filled at the end. See comments.
brush.Setup(this, false); // Stroke
// I think we only Fill the text with no Stroke surrounding
context.SetTextDrawingMode(CGTextDrawingMode.Fill);
var attributedString = buildAttributedString(s, font, format, lastBrushColor);
// Work out the geometry
RectangleF insetBounds = layoutRectangle;
if (insetBounds.Size == SizeF.Empty)
{
insetBounds.Width = boundingBox.Width;
insetBounds.Height = boundingBox.Height;
layoutAvailable = false;
}
PointF textPosition = new PointF(insetBounds.X,
insetBounds.Y);
float boundsWidth = insetBounds.Width;
// Calculate the lines
int start = 0;
int length = attributedString.Length;
float baselineOffset = 0;
var typesetter = new CTTypesetter(attributedString);
// First we need to calculate the offset for Vertical Alignment if we
// are using anything but Top
if (layoutAvailable && format.LineAlignment != StringAlignment.Near) {
while (start < length) {
int count = typesetter.SuggestLineBreak (start, boundsWidth);
var line = typesetter.GetLine (new NSRange(start, count));
// Create and initialize some values from the bounds.
float ascent;
float descent;
float leading;
line.GetTypographicBounds (out ascent, out descent, out leading);
baselineOffset += (float)Math.Ceiling (ascent + descent + leading + 1); // +1 matches best to CTFramesetter's behavior
line.Dispose ();
start += count;
}
//textPosition.Y += baselineOffset;
}
// If we are drawing vertial direction then we need to rotate our context transform by 90 degrees
if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
{
//textMatrix.Rotate (ConversionHelpers.DegreesToRadians (90));
var verticalOffset = 0.0f;
//.........这里部分代码省略.........
示例2: FillBrush
void FillBrush(Brush brush, FillMode fillMode = FillMode.Alternate)
{
brush.Setup (this, true);
if (fillMode == FillMode.Alternate)
context.EOFillPath ();
else
context.FillPath ();
}