本文整理汇总了C#中CGContext.ScaleCTM方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.ScaleCTM方法的具体用法?C# CGContext.ScaleCTM怎么用?C# CGContext.ScaleCTM使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.ScaleCTM方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLayer
public void DrawLayer(CALayer layer, CGContext context)
{
// fill with white background
context.SetFillColor (1f, 1f, 1f, 1f);
context.FillRect (Bounds);
context.SaveState ();
// flip page so we render it as it's meant to be read
context.TranslateCTM (0f, Bounds.Height);
context.ScaleCTM (1f, -1f);
// scale page at the view-zoom level
context.ScaleCTM (MyScale, MyScale);
context.DrawPDFPage (Page);
context.RestoreState ();
}
示例2: DrawLayer
public override void DrawLayer (CALayer layer, CGContext context)
{
// keep a copy since (a) it's a _virtual_ property and (b) it could change between filling and flipping
RectangleF bounds = view.Bounds;
// fill with white background
context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (bounds);
context.SaveState ();
// flip page so we render it as it's meant to be read
context.TranslateCTM (0.0f, bounds.Height);
context.ScaleCTM (1.0f, -1.0f);
// scale page at the view-zoom level
context.ScaleCTM (view.Scale, view.Scale);
context.DrawPDFPage (view.Page);
context.RestoreState ();
}
示例3: DrawLayer
public override void DrawLayer(CALayer layer, CGContext context)
{
context.SaveState ();
context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (context.GetClipBoundingBox ());
context.TranslateCTM (0.0f, layer.Bounds.Size.Height);
context.ScaleCTM (1.0f, -1.0f);
context.ConcatCTM (this.oParentController.currentPDFPage.GetDrawingTransform (CGPDFBox.Crop, layer.Bounds, 0, true));
context.DrawPDFPage (this.oParentController.currentPDFPage);
context.RestoreState ();
}
示例4: MeasureStringWidth
// TODO: Cannot use NSAttributedString in iOS5, only iOS6+
// public static RectangleF MeasureString(SizeF sizeConstraint, string text, string fontName, float fontSize)
// {
// NSMutableDictionary dict = new NSMutableDictionary();
// dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
// NSString nsstr = new NSString(text);
// RectangleF rect = nsstr.BoundingRectWithSize(sizeConstraint, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
// return rect;
// }
public static float MeasureStringWidth(CGContext context, string text, string fontName, float fontSize)
{
if (string.IsNullOrEmpty(text))
return 0;
context.SaveState();
PointF pos = context.TextPosition;
context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
//context.TranslateCTM(0, 20);
context.ScaleCTM(1, -1);
context.SetTextDrawingMode(CGTextDrawingMode.Invisible);
context.ShowTextAtPoint(pos.X, pos.Y, text);
PointF pos2 = context.TextPosition;
context.RestoreState();
return pos2.X - pos.X;
}
示例5: DrawInContext
public override void DrawInContext (CGContext context)
{
// PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system
// before we start drawing.
context.TranslateCTM (0, Bounds.Height);
context.ScaleCTM (1, -1);
// Grab the first PDF page
using (CGPDFPage page = doc.GetPage (1)){
// We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing
context.SaveState ();
// CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any
// base rotations necessary to display the PDF page correctly.
CGAffineTransform pdfTransform = page.GetDrawingTransform (CGPDFBox.Crop, Bounds, 0, true);
// And apply the transform.
context.ConcatCTM (pdfTransform);
// Finally, we draw the page and restore the graphics state for further manipulations!
context.DrawPDFPage (page);
context.RestoreState();
}
}
示例6: Draw
/// <summary>
/// Draws the document page
/// </summary>
private void Draw(CGContext context)
{
if (!PDFDocument.DocumentHasLoaded) {
return;
}
// Draw page
context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
using (CGPDFPage pdfPage = PDFDocument.GetPage(mPageNumber)) {
context.TranslateCTM(0, Bounds.Height);
context.ScaleCTM(1.0f, -1.0f);
context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, Bounds, 0, true));
context.SetRenderingIntent(CGColorRenderingIntent.Default);
context.InterpolationQuality = CGInterpolationQuality.Default;
context.DrawPDFPage(pdfPage);
}
}
示例7: AddRoundedRectToPath
public static void AddRoundedRectToPath(CGContext context, RectangleF rect, float ovalWidth, float ovalHeight)
{
float fw, fh;
if (ovalWidth == 0 || ovalHeight == 0)
{
context.AddRect(rect);
return;
}
context.SaveState();
context.TranslateCTM(rect.GetMinX(), rect.GetMinY());
context.ScaleCTM(ovalWidth, ovalHeight);
fw = rect.Width / ovalWidth;
fh = rect.Height / ovalHeight;
context.MoveTo(fw, fh / 2);
context.AddArcToPoint(fw, fh, fw / 2, fh, 1);
context.AddArcToPoint(0, fh, 0, fh / 2, 1);
context.AddArcToPoint(0, 0, fw / 2, 0, 1);
context.AddArcToPoint(fw, 0, fw, fh / 2, 1);
context.ClosePath();
context.RestoreState();
}
示例8: drawLabel
void drawLabel(CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, CTTextAlignment alignment, UIColor color, string label, bool flipContext = true)
{
Console.WriteLine("Finish Draw code");
var attrString = new NSMutableAttributedString (label);
var range = new NSRange (0, attrString.Length);
var uiFont = UIFont.FromName("HelveticaNeue-Medium", range.Length > 1 ? 15 : 22);
var font = new CTFont (uiFont.Name, uiFont.PointSize); //((uiFont.Name as NSString) as CFString, uiFont.pointSize, nil);
var path = new CGPath ();
var alignStyle = new CTParagraphStyle (new CTParagraphStyleSettings { Alignment = alignment });
var attributes = new CTStringAttributes {
Font = font,
ForegroundColor = color.CGColor,
ParagraphStyle = alignStyle
};
attrString.SetAttributes(attributes, new NSRange (0, attrString.Length));
var target = new CGSize (nfloat.MaxValue, nfloat.MaxValue);
var fit = new NSRange (0, 0);
var framesetter = new CTFramesetter (attrString);
var frameSize = framesetter.SuggestFrameSize(range, null, target, out fit);
var textRect = new CGRect (xCoord - (frameSize.Width / 2), yCoord - (frameSize.Height / 2), frameSize.Width, frameSize.Height);
path.AddRect(textRect);
var frame = framesetter.GetFrame(range, path, null);
if (flipContext) {
ctx.SaveState();
ctx.TranslateCTM(0, rect.Height);
ctx.ScaleCTM(1, -1);
frame.Draw(ctx);
ctx.RestoreState();
} else {
frame.Draw(ctx);
}
}
示例9: drawLabel
void drawLabel (CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
{
// Draw light the sunrise and Sunset labels at the ends of the light box
using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha (0.1f)) {
var fontAttributes = new UIFontAttributes (new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));
using (var desc = UIFont.SystemFontOfSize (fontSize).FontDescriptor.CreateWithAttributes (fontAttributes)) {
using (UIFont font = UIFont.FromDescriptor (desc, fontSize)) {
// calculating the range of our attributed string
var range = new NSRange (0, label.Length);
// set justification for text block
using (var alignStyle = new NSMutableParagraphStyle { Alignment = alignment }) {
// add stylistic attributes to out attributed string
var stringAttributes = new UIStringAttributes {
ForegroundColor = fontColor,
Font = font,
ParagraphStyle = alignStyle
};
var target = new CGSize (float.MaxValue, float.MaxValue);
NSRange fit;
using (NSMutableAttributedString attrString = new NSMutableAttributedString (label, stringAttributes)) {
//creating a container for out attributed string
using (CTFramesetter framesetter = new CTFramesetter (attrString)) {
CGSize frameSize = framesetter.SuggestFrameSize (range, null, target, out fit);
if (alignment == UITextAlignment.Center) xCoord -= (frameSize.Width / 2);
if (alignment == UITextAlignment.Right) xCoord -= frameSize.Width;
// subtract the frameSize so the flipped context behaves as expected
yCoord -= frameSize.Height;
if (centerVertical) yCoord += (frameSize.Height / 2);
var textRect = new CGRect (xCoord, yCoord, frameSize.Width, frameSize.Height);
using (CGPath path = new CGPath ()) {
path.AddRect (textRect);
ctx.SetShadow (new CGSize (0.0f, 1.0f), 0.0f, shadowColor.CGColor);
using (CTFrame frame = framesetter.GetFrame (range, path, null)) {
if (flipContext) {
ctx.SaveState ();
ctx.TranslateCTM (0, rect.Height);
ctx.ScaleCTM (1, -1);
frame.Draw (ctx);
ctx.RestoreState ();
} else {
frame.Draw (ctx);
}
}
}
}
}
}
}
}
}
}
示例10: DrawText
private void DrawText(string text, CGContext context, RectangleF bounds, bool withShadow)
{
// save state and transform
context.SaveState ();
context.TranslateCTM (0, bounds.Height);
context.ScaleCTM (1.0f, -1.0f);
// calculate location
context.SelectFont("Helvetica", UIFont.LabelFontSize,CGTextEncoding.MacRoman);
NSString t = new NSString(text);
var font = UIFont.FromName("Helvetica", UIFont.LabelFontSize);
var size = t.StringSize(font);
var x = bounds.Left;
var y = bounds.Height/2 - size.Height/2;
// draw the shadow at an offset
if (withShadow) {
UIColor.FromRGB(193,193,193).SetFill();
context.ShowTextAtPoint(x+1, y+4, text);
}
// draw the text
if (_parentCell.Highlighted && !_menuItem.IsHeader)
_headerForegroundColor.SetFill ();
else if (_menuItem.IsHeader)
_headerForegroundColor.SetFill ();
else
_foregroundColor.SetFill();
context.ShowTextAtPoint(x, y+5, text);
// restore context
context.RestoreState();
}
示例11: DrawImage
private void DrawImage(UIImage image, CGContext context, RectangleF bounds)
{
// required hack to get the images to draw rightside up
context.SaveState();
context.TranslateCTM(0, bounds.Height);
context.ScaleCTM(1.0f, -1.0f);
bounds.Y = -bounds.Y;
context.DrawImage(bounds, image.CGImage);
context.RestoreState();
}