本文整理汇总了C#中MonoMac.Foundation.NSString.DrawString方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.DrawString方法的具体用法?C# NSString.DrawString怎么用?C# NSString.DrawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoMac.Foundation.NSString
的用法示例。
在下文中一共展示了NSString.DrawString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawText
public static void DrawText(RectangleF rect, float x, float y, string text, string fontName, float fontSize, NSColor fontColor)
{
NSMutableDictionary dict = new NSMutableDictionary();
dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
NSString nsstr = new NSString(text);
RectangleF rectBounds = nsstr.BoundingRectWithSize(new SizeF(rect.Width, rect.Height), NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
rectBounds.X = rect.X + x;
rectBounds.Y = rect.Y + y;
nsstr.DrawString(rectBounds, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
}
示例2: MakeGLDisplayListFirst
// Create the set of display lists for the bitmaps
bool MakeGLDisplayListFirst (char first, int count, int baseDL)
{
int curListIndex;
NSColor blackColor;
NSMutableDictionary attribDict;
int dListNum;
NSString currentChar;
char currentUnichar;
SizeF charSize;
RectangleF charRect;
NSImage theImage;
bool retval;
// Make sure the list isn't already under construction
GL.GetInteger (GetPName.ListIndex, out curListIndex);
if (curListIndex != 0) {
Console.WriteLine ("Display list already under construction");
return false;
}
// Save pixel unpacking state
GL.PushClientAttrib (ClientAttribMask.ClientPixelStoreBit);
GL.PixelStore (PixelStoreParameter.UnpackSwapBytes, 0);
GL.PixelStore (PixelStoreParameter.UnpackLsbFirst, 0);
GL.PixelStore (PixelStoreParameter.UnpackSkipPixels, 0);
GL.PixelStore (PixelStoreParameter.UnpackSkipRows, 0);
GL.PixelStore (PixelStoreParameter.UnpackRowLength, 0);
GL.PixelStore (PixelStoreParameter.UnpackAlignment, 0);
blackColor = NSColor.Black;
attribDict = new NSMutableDictionary ();
attribDict.SetValueForKey (font, NSAttributedString.FontAttributeName);
attribDict.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
attribDict.SetValueForKey (blackColor, NSAttributedString.BackgroundColorAttributeName);
charRect.Location.X = charRect.Location.Y = 0;
theImage = new NSImage (new SizeF (0,0));
retval = true;
for (dListNum = baseDL, currentUnichar = first; currentUnichar < first + count;
dListNum++, currentUnichar++) {
currentChar = new NSString (Char.ToString (currentUnichar));
charSize = currentChar.StringSize (attribDict);
charRect.Size = charSize;
charRect = charRect.Integral ();
if (charRect.Size.Width > 0 && charRect.Size.Height > 0) {
theImage.Size = charRect.Size;
theImage.LockFocus ();
NSGraphicsContext.CurrentContext.ShouldAntialias = false;
blackColor.Set ();
NSBezierPath.FillRect (charRect);
currentChar.DrawString (charRect, attribDict);
theImage.UnlockFocus ();
if (!MakeDisplayList(dListNum, theImage)) {
retval = false;
break;
}
}
}
return retval;
}
示例3: DrawTextInRect
public static void DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, NSColor fontColor)
{
context.SaveState();
NSString str = new NSString(text);
var dict = new NSMutableDictionary();
dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
str.DrawString(rect, dict);
context.RestoreState();
}
示例4: DrawStringOutline
private void DrawStringOutline(string text, NSColor color, RectangleF rect, int align)
{
NSString nsString = new NSString (text);
int halign = align % 3;
int valign = align / 3;
var objectsText = new object[] { m_font, color };
var keysText = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText);
var objectsOutline = new object[] { m_font, NSColor.White };
var keysOutline = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline);
SizeF size = nsString.StringSize (attributesText);
if (halign == 0) {
} else if (halign == 1) {
rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2;
} else if (halign == 2) {
rect.X = rect.Right - size.Width;
}
rect.Width = size.Width;
if (valign == 0) {
} else if (valign == 1) {
rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2;
} else if (valign == 2) {
rect.Y = rect.Bottom - size.Height;
}
rect.Height = size.Height;
NSColor.Black.Set ();
for (int ox = -1; ox <= 1; ox++) {
for (int oy = -1; oy <= 1; oy++) {
RectangleF rectString = rect;
rectString.Offset (new PointF (ox, oy));
nsString.DrawString (Invert (rectString), attributesOutline);
}
}
nsString.DrawString(Invert(rect), attributesText);
}