SaveState() 공개 메소드

public SaveState ( ) : void
리턴 void
예제 #1
0
 public static void FillEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddEllipseInRect(rect);
     context.FillPath();
     context.RestoreState();
 }
예제 #2
0
 public static void FillRect(CGContext context, RectangleF rect, CGColor color)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetFillColor(color);
     context.FillRect(rect);
     context.RestoreState();
 }
예제 #3
0
 public static void DrawEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetStrokeColor(color);
     context.SetLineWidth(lineWidth);
     context.AddEllipseInRect(rect);
     context.StrokePath();
     context.RestoreState();
 }
예제 #4
0
 public static void DrawRect(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetLineWidth(lineWidth);
     context.SetStrokeColor(color);
     context.StrokeRect(rect);
     context.RestoreState();
 }
예제 #5
0
		internal static void Draw (CGContext ctx, GradientInfo gradient)
		{
			ctx.SaveState ();
			ctx.Clip ();
			using (var cg = new CGGradient (Util.DeviceRGBColorSpace, gradient.Colors.ToArray (), gradient.Stops.ToArray ())) {
				if (gradient.Linear)
					ctx.DrawLinearGradient (cg, gradient.Start, gradient.End, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
				else
					ctx.DrawRadialGradient (cg, gradient.Start, gradient.StartRadius, gradient.End, gradient.EndRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
			}
			ctx.RestoreState ();
		}
예제 #6
0
        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;
        }
예제 #7
0
        public static void DrawLine(CGContext context, List<PointF> points, CGColor color, float lineWidth, bool closePath, bool dashed)
        {
            if (points == null)
                throw new NullReferenceException();

            if (points.Count == 0)
                throw new ArgumentException("The line must have at least one point.");

            context.SaveState();
            context.SetStrokeColor(color);
            context.SetLineWidth(lineWidth);
            context.MoveTo(points[0].X, points[0].Y);
            for(int a = 1; a < points.Count; a++)
                context.AddLineToPoint(points[a].X, points[a].Y);
            if (dashed)
                context.SetLineDash(0, new float[2] { 1, 2 }, 2);
            if (closePath)
                context.ClosePath();
            context.StrokePath();
            context.RestoreState();
        }
예제 #8
0
 public static void DrawText(CGContext context, string text, string fontName, float fontSize, float translateHeight, float x, float y)
 {
     context.SaveState();
     context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
     context.SetTextDrawingMode(CGTextDrawingMode.Fill);
     context.SetFillColor(new CGColor(1, 1));
     context.SetStrokeColor(new CGColor(1.0f, 1.0f));
     //context.AddRect(rectText);
     //context.Clip();
     context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
     context.TranslateCTM(0, translateHeight);
     context.ScaleCTM(1, -1);
     context.ShowTextAtPoint(x, y, text);
     context.RestoreState();
 }
예제 #9
0
 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();
 }
예제 #10
0
 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2, bool isHorizontal)
 {
     CGGradient gradientBackground;
     CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
     
     float[] locationListBackground = new float[] { 1.0f, 0.0f };
     List<float> colorListBackground = new List<float>();
     colorListBackground.AddRange(color1.Components);
     colorListBackground.AddRange(color2.Components);
     gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
     
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     //context.ScaleCTM(1, -1);
     if(isHorizontal)
         context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     else
         context.DrawLinearGradient(gradientBackground, new PointF(0, 0), new PointF(0, rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
예제 #11
0
 public static void EOFillPath(CGContext context, CGPath path, CGColor color)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddPath(path);
     context.EOFillPath();
     context.RestoreState();
 }
예제 #12
0
 public static void StrokePath(CGContext context, CGPath path, float pathWidth, CGColor color)
 {
     context.SaveState();
     context.SetLineWidth(pathWidth);
     context.SetStrokeColor(color);
     context.AddPath(path);
     context.StrokePath();
     context.RestoreState();
 }
예제 #13
0
 public static void DrawLine(CGContext context, PointF[] points, float lineWidth, CGColor color)
 {
     context.SaveState();
     var path = new CGPath();
     path.AddLines(points);
     context.AddPath(path);
     context.SetLineWidth(lineWidth);
     context.SetStrokeColor(color);
     context.StrokePath();
     context.RestoreState();
 }
예제 #14
0
		internal static void Draw (CGContext ctx, object layout, double x, double y)
		{
			LayoutInfo li = (LayoutInfo)layout;
			using (CTFrame frame = CreateFrame (li)) {
				if (frame == null)
					return;

				CTLine ellipsis = null;
				bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis;
				if (ellipsize)
					ellipsis = new CTLine (CreateAttributedString (li, "..."));

				float lineHeight = li.Font.Ascender - li.Font.Descender + li.Font.Leading;

				ctx.SaveState ();
				ctx.TextMatrix = CGAffineTransform.MakeScale (1f, -1f);
				ctx.TranslateCTM ((float)x, (float)y + li.Font.Ascender);
				foreach (var line in frame.GetLines ()) {
					ctx.TextPosition = PointF.Empty;
					if (ellipsize) // we need to create a new CTLine here because the framesetter already truncated the text for the line
						new CTLine (CreateAttributedString (li, li.Text.Substring (line.StringRange.Location)))
							.GetTruncatedLine (li.Width.Value, CTLineTruncation.End, ellipsis).Draw (ctx);
					else
						line.Draw (ctx);
					ctx.TranslateCTM (0, lineHeight);
				}
				ctx.RestoreState ();
			}
		}
예제 #15
0
        internal static void Draw(CGContext ctx, object layout, double x, double y)
        {
            LayoutInfo li = (LayoutInfo)layout;
            if (li.Framesetter == null)
                return;

            CGPath path = new CGPath ();
            path.AddRect (new RectangleF (0, 0, li.Width ?? float.MaxValue, li.Height ?? float.MaxValue));
            CTFrame frame = li.Framesetter.GetFrame (new NSRange (0, li.Text.Length), path, null);

            CTLine ellipsis = null;
            bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis;
            if (ellipsize)
                ellipsis = new CTLine (CreateAttributedString (li, "..."));

            float lineHeight = layoutManager.DefaultLineHeightForFont (li.Font);

            ctx.SaveState ();
            ctx.TextMatrix = CGAffineTransform.MakeScale (1f, -1f);
            ctx.TranslateCTM ((float)x, (float)y + li.Font.Ascender);
            foreach (var line in frame.GetLines ()) {
                ctx.TextPosition = PointF.Empty;
                if (ellipsize) // we need to create a new CTLine here because the framesetter already truncated the text for the line
                    new CTLine (CreateAttributedString (li, li.Text.Substring (line.StringRange.Location)))
                        .GetTruncatedLine (li.Width.Value, CTLineTruncation.End, ellipsis).Draw (ctx);
                else
                    line.Draw (ctx);
                ctx.TranslateCTM (0, lineHeight);
            }
            ctx.RestoreState ();
        }