Inheritance: XwtObject, IDisposable
Esempio n. 1
0
		protected override LayoutWrapper RenderLine (long line)
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			StringBuilder sb = new StringBuilder ();
			long startOffset = line * Editor.BytesInRow;
			long endOffset   = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length);
			byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset));
			for (int i = 0; i < lineBytes.Length; i++) {
				byte b = lineBytes[i];
				char ch = (char)b;
				if (b < 128 && (Char.IsLetterOrDigit (ch) || Char.IsPunctuation (ch))) {
					sb.Append (ch);
				} else {
					sb.Append (".");
				}
			}
			
			layout.Text = sb.ToString ();
			Margin.LayoutWrapper result = new LayoutWrapper (layout);
			if (Data.IsSomethingSelected) {
				ISegment selection = Data.MainSelection.Segment;
				HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) {
					result.Layout.SetForeground (Style.Selection, (int)(start - startOffset), (int)(end - start));
					result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset), (int)(end - start));
				});
			}
			return result;
		}
Esempio n. 2
0
		protected override LayoutWrapper RenderLine (long line)
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = string.Format ("{0:X}", line * Editor.BytesInRow);
			return new LayoutWrapper (layout);
		}
Esempio n. 3
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            // Line arround
            ctx.SetColor(Colors.DarkGray);

            // Drive line arround
            ctx.Rectangle(Bounds);
            ctx.Fill();

            ctx.SetColor(Colors.Gray);
            ctx.Rectangle(Bounds.Inflate(-margin, -margin));
            ctx.Fill();

            // Draw image
            ctx.DrawImage(Image.FromResource(Logo), 5.0, 5.0);

            // Draw text
            ctx.SetColor(Colors.White);
            TextLayout _layout = new TextLayout();
            _layout.Font = Font.WithSize(22);
            _layout.Text = Label;
            _layout.SetFontWeight(FontWeight.Bold, 0, Label.Length);

            // Cocoa layouts
            ctx.DrawTextLayout(_layout, 45, ((Config.Cocoa || Config.Gtk) ? 5 : 2));
        }
        //public void SetFont (object backend, Xwt.Drawing.Font font) {
        //    var gc = (GdiContext) backend;
        //    gc.Font = font.ToGdi ();
        //}

        public override void DrawTextLayout(object backend, Xwt.Drawing.TextLayout layout, double x, double y)
        {
            if (layout.Text == null)
            {
                return;
            }

            var gc   = (GdiContext)backend;
            var tl   = (GdiTextLayoutBackend)Toolkit.GetBackend(layout);
            var font = tl.Font.ToGdi();
            var w    = layout.Width;
            var h    = layout.Height;

            SD.Drawing2D.GraphicsPath path = null;
            var onPath = (gc.ScaledRotated(gc.Graphics.Transform) || gc.ScaledOrRotated);

            if (w != -1 || h != -1)
            {
                var size = tl.Size;
                w = w == -1 ? size.Width : w;
                h = h == -1 ? size.Height : h;

                var rect = new System.Drawing.RectangleF((float)x, (float)y, (float)w, (float)h);
                if (onPath)
                {
                    path = gc.TextLayoutPath(font, (p, fontSize) =>
                                             p.AddString(tl.Text, font.FontFamily, (int)font.Style, fontSize, rect, tl.Format));
                }
                else
                {
                    gc.Graphics.DrawString(tl.Text, font, gc.Brush, rect, tl.Format);
                }
            }
            else
            {
                var at = new System.Drawing.PointF((float)x, (float)y);
                if (onPath)
                {
                    path = gc.TextLayoutPath(font, (p, fontSize) =>
                                             p.AddString(tl.Text, font.FontFamily, (int)font.Style, fontSize, at, tl.Format));
                }
                else
                {
                    gc.Graphics.DrawString(tl.Text, font, gc.Brush, at, tl.Format);
                }
            }
            if (path != null)
            {
                var s = gc.Graphics.SetQuality(GdiConverter.DrawTextHighQuality);

                var brush = new SD.SolidBrush(gc.Color);
                gc.Graphics.FillPath(brush, path);
                brush.Dispose();

                path.Dispose();
                gc.Graphics.SetQuality(s);
            }
        }
Esempio n. 5
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = ".";
//			int height;
			charWidth = layout.GetSize ().Width;
			layout.Dispose ();
		}
Esempio n. 6
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = string.Format ("0{0:X}", Data.Length) + "_";
//			int height;
			width = layout.GetSize ().Width;
			layout.Dispose ();
		}
        protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (line != null)
            {
                TextLayout layout;
                if (!layoutDict.TryGetValue(line, out layout))
                {
                    var mode = editor.Document.SyntaxMode;
                    var style = SyntaxModeService.DefaultColorStyle;
                    var chunks = GetCachedChunks(mode, editor.Document, style, line, line.Offset, line.Length);

                    layout = new TextLayout();
                    layout.Font = editor.Options.EditorFont;
                    string lineText = editor.Document.GetLineText(lineNumber);
                    var stringBuilder = new StringBuilder(lineText.Length);

                    int currentVisualColumn = 1;
                    for (int i = 0; i < lineText.Length; ++i)
                    {
                        char chr = lineText[i];
                        if (chr == '\t')
                        {
                            int length = GetNextTabstop(editor, currentVisualColumn) - currentVisualColumn;
                            stringBuilder.Append(' ', length);
                            currentVisualColumn += length;
                        }
                        else
                        {
                            stringBuilder.Append(chr);
                            if (!char.IsLowSurrogate(chr))
                            {
                                ++currentVisualColumn;
                            }
                        }
                    }
                    layout.Text = stringBuilder.ToString();

                    int visualOffset = 1;
                    foreach (var chunk in chunks)
                    {
                        var chunkStyle = style.GetChunkStyle(chunk);
                        visualOffset = DrawLinePortion(cr, chunkStyle, layout, line, visualOffset, chunk.Length);
                    }

                    //layoutDict[line] = layout;
                }

                cr.DrawTextLayout(layout, x, y);

                if (editor.CaretVisible && editor.Caret.Line == lineNumber)
                {
                    cr.SetColor(Colors.Black);
                    cr.Rectangle(x + ColumnToX(line, editor.Caret.Column), y, caretWidth, LineHeight);
                    cr.Fill();
                }
            }
        }
Esempio n. 8
0
 void UpdateStyle()
 {
     if (layout != null)
     {
         layout.Dispose();
     }
     layout          = new TextLayout(this);
     layout.Trimming = TextTrimming.Word;
 }
Esempio n. 9
0
        public LogLevelChooser(LogLevel selectedLogLevel)
        {
            SelectedLogLevel = selectedLogLevel;

            // prerender
            string[] logNames = Enum.GetNames(typeof(LogLevel));
            int length = logNames.Length;
            renderedImage = new Image[length];

            using (TextLayout text = new TextLayout()) {
                for (int i = 0; i < length; i++) {
                    text.Text = logNames[i];
                    Size size = text.GetSize();
                    using (ImageBuilder ib = new ImageBuilder(size.Width + size.Height*2 + 3, size.Height)) {
                        Color color = Color.FromName(Log.LevelToColorString((LogLevel) i));

                        Draw(ib.Context, (LogLevel) i, color);
                        renderedImage[i] = ib.ToBitmap();

                        Button button = new Button { Image = renderedImage[i], ImagePosition = ContentPosition.Left };
                        button.HorizontalPlacement = WidgetPlacement.Start;
                        button.Margin = 0;
                        button.ExpandHorizontal = true;
                        button.Style = ButtonStyle.Flat;
                        buttons.PackStart(button, true, true);

                        button.CanGetFocus = false;
                        button.Tag = i;
                        button.Clicked += OnLogChange;

                        windowHeight += size.Height * 2;
                    }
                }
            }

            // hide window on lost fokus
            buttons.CanGetFocus = true;
            buttons.LostFocus += delegate {
                if (menuHide != null) {
                    menuHide(this, EventArgs.Empty);
                }

                popupWindow.Hide();
            };
            buttons.ButtonPressed += delegate {
                // do nothing
                // workaround to propagate event to each button
            };

            buttons.Spacing = 0;

            popupWindow.Padding = 0;
            popupWindow.ShowInTaskbar = false;
            popupWindow.Decorated = false;
            popupWindow.Content = buttons;
        }
Esempio n. 10
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = "!";
//			int tmp;
			this.marginWidth = layout.GetSize ().Height;
			marginWidth *= 12;
			marginWidth /= 10;
			layout.Dispose ();
		}
Esempio n. 11
0
		protected override void OnDraw (Context ctx, Rectangle cellArea)
		{
			PackageViewModel packageViewModel = GetValue (PackageField);
			if (packageViewModel == null) {
				return;
			}

			FillCellBackground (ctx);
			UpdateTextColor (ctx);

			DrawCheckBox (ctx, packageViewModel, cellArea);
			DrawPackageImage (ctx, cellArea);

			double packageIdWidth = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;

			// Package download count.
			if (packageViewModel.HasDownloadCount) {
				var downloadCountTextLayout = new TextLayout ();
				downloadCountTextLayout.Text = packageViewModel.GetDownloadCountOrVersionDisplayText ();
				Size size = downloadCountTextLayout.GetSize ();
				Point location = new Point (cellArea.Right - packageDescriptionPadding.Right, cellArea.Top + packageDescriptionPadding.Top);
				Point downloadLocation = location.Offset (-size.Width, 0);
				ctx.DrawTextLayout (downloadCountTextLayout, downloadLocation);

				packageIdWidth = downloadLocation.X - cellArea.Left - packageIdRightHandPaddingWidth - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
			}

			// Package Id.
			var packageIdTextLayout = new TextLayout ();
			packageIdTextLayout.Font = packageIdTextLayout.Font.WithSize (12);
			packageIdTextLayout.Markup = packageViewModel.GetNameMarkup ();
			packageIdTextLayout.Trimming = TextTrimming.WordElipsis;
			Size packageIdTextSize = packageIdTextLayout.GetSize ();
			packageIdTextLayout.Width = packageIdWidth;
			ctx.DrawTextLayout (
				packageIdTextLayout,
				cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
				cellArea.Top + packageDescriptionPadding.Top);

			// Package description.
			var descriptionTextLayout = new TextLayout ();
			descriptionTextLayout.Font = descriptionTextLayout.Font.WithSize (11);
			descriptionTextLayout.Width = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
			descriptionTextLayout.Height = cellArea.Height - packageIdTextSize.Height - packageDescriptionPadding.VerticalSpacing;
			descriptionTextLayout.Text = packageViewModel.Summary;
			descriptionTextLayout.Trimming = TextTrimming.Word;

			ctx.DrawTextLayout (
				descriptionTextLayout,
				cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
				cellArea.Top + packageIdTextSize.Height + packageDescriptionPaddingHeight + packageDescriptionPadding.Top);
		}
Esempio n. 12
0
			protected override void OnDraw (Context ctx, Rectangle dirtyRect)
			{
				base.OnDraw (ctx, dirtyRect);

				ctx.Rectangle (0, 0, Size.Width, Size.Height);
				ctx.SetColor (Colors.LightGray);
				ctx.Fill ();

				ctx.SetColor (Colors.Black);
				using (var layout = new TextLayout (this))
				{
					layout.Text = text;
					ctx.DrawTextLayout (layout, new Point (0, 20));
				}
			}
		protected override LayoutWrapper RenderLine (long line)
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			StringBuilder sb = new StringBuilder ();
			long startOffset = line * Editor.BytesInRow;
			long endOffset   = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length);
			byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset));
			switch (Editor.Options.StringRepresentationType) {
			case StringRepresentationTypes.ASCII:
				for (int i = 0; i < lineBytes.Length; i++) {
					byte b = lineBytes [i];
					char ch = (char)b;
					if (!char.IsControl (ch)) {
						sb.Append (ch);
					} else {
						sb.Append (".");
					}
				}
				break;
			case StringRepresentationTypes.UTF16:
				for (int i = 0; i < lineBytes.Length - 1; i += 2) {

					char ch = Encoding.Unicode.GetChars (lineBytes, i, 2) [0];
					if (char.IsLetterOrDigit (ch) || char.IsWhiteSpace (ch) || char.IsSymbol (ch) || char.IsPunctuation (ch))
						sb.Append (ch);
					else
						sb.Append (".");
				}
				break;
			default:
				throw new NotImplementedException (Editor.Options.StringRepresentationType.ToString ());
			}
			
			layout.Text = sb.ToString ();
			Margin.LayoutWrapper result = new LayoutWrapper (layout);
			if (Data.IsSomethingSelected) {
				ISegment selection = Data.MainSelection.Segment;
				HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) {
					result.Layout.SetForeground (Style.Selection, (int)(start - startOffset)/2, (int)(end - start)/2);
					result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset)/2, (int)(end - start)/2);
				});
			}
			return result;
		}
        protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (lineNumber <= editor.Document.LineCount)
            {
                TextLayout layout;
                if (!layoutDict.TryGetValue(lineNumber, out layout))
                {
                    layout = new TextLayout();
                    layout.Font = editor.Options.EditorFont;
                    layout.Text = lineNumber.ToString();

                    layoutDict[lineNumber] = layout;
                }

                cr.SetColor(Colors.Black);
                cr.DrawTextLayout(layout, x + leftPadding, y);
            }
        }
Esempio n. 15
0
        int DrawLinePortion(Context cr, ChunkStyle style, TextLayout layout, DocumentLine line, int visualOffset, int logicalLength)
        {
            int logicalColumn = line.GetLogicalColumn(editor, visualOffset);
            int logicalEndColumn = logicalColumn + logicalLength;
            int visualEndOffset = line.GetVisualColumn(editor, logicalEndColumn);

            int visualLength = visualEndOffset - visualOffset;

            int indexOffset = visualOffset - 1;

            layout.SetFontStyle(style.FontStyle, indexOffset, visualLength);
            layout.SetFontWeight(style.FontWeight, indexOffset, visualLength);
            if (style.Underline)
                layout.SetUnderline(indexOffset, visualLength);
            layout.SetForeground(style.Foreground, indexOffset, visualLength);

            return visualEndOffset;
        }
Esempio n. 16
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.SetColor(Colors.Gray);
            ctx.SetLineWidth(1);

            ctx.RoundRectangle(0, Padding.Top / 2 - .5, Width - 4.5, Height - Padding.Bottom * 1.5, 3);
            ctx.Stroke();

            var tl = new TextLayout(this) { Text = title, Width = Width - Padding.Left - Padding.Right / 2 };

            ctx.SetColor(Colors.White);
            ctx.Rectangle(Padding.Left, 0, tl.GetSize().Width, Padding.Top);
            ctx.Fill();

            ctx.SetColor(Colors.Black);
            ctx.DrawTextLayout(tl, Padding.Left, 0);
        }
Esempio n. 17
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			string groupString = new string ('0', Editor.Options.GroupBytes * 2);
			layout.Text = groupString + " ";
			double lineHeight;
			var sz = layout.GetSize ();
			groupWidth = sz.Width;
			lineHeight = sz.Height;
			 
			Data.LineHeight = lineHeight;
			
			layout.Text = "00";
			byteWidth = layout.GetSize ().Width;

			layout.Dispose ();
			
//			tabArray = new Pango.TabArray (1, true);
//			tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth);
		}
 public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
 {
     Pango.Layout pl = (Pango.Layout)WidgetRegistry.GetBackend (layout);
     CairoContextBackend ctx = (CairoContextBackend)backend;
     ctx.Context.MoveTo (x, y);
     if (layout.Height <= 0) {
         Pango.CairoHelper.ShowLayout (ctx.Context, pl);
     } else {
         var lc = pl.LineCount;
         var scale = Pango.Scale.PangoScale;
         double h = 0;
         for (int i=0; i<lc; i++) {
             var line = pl.Lines [i];
             var ext = new Pango.Rectangle ();
             var extl = new Pango.Rectangle ();
             line.GetExtents (ref ext, ref extl);
             h += (extl.Height / scale);
             if (h > layout.Height)
                 break;
             ctx.Context.MoveTo (x, y + h);
             Pango.CairoHelper.ShowLayoutLine (ctx.Context, line);
         }
     }
 }
Esempio n. 19
0
        public virtual void Texts(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save ();

            ctx.Translate (x, y);

            ctx.SetColor (Colors.Black);

            var col1 = new Rectangle ();
            var col2 = new Rectangle ();

            var text = new TextLayout ();
            text.Font = this.Font.WithSize (24);
            Console.WriteLine (text.Font.Size);

            // first text
            text.Text = "Lorem ipsum dolor sit amet,";
            var size1 = text.GetSize ();
            col1.Width = size1.Width;
            col1.Height += size1.Height + 10;
            ctx.DrawTextLayout (text, 0, 0);

            // proofing width; test should align with text above
            ctx.SetColor (Colors.DarkMagenta);
            text.Text = "consetetur sadipscing elitr, sed diam nonumy";
            text.Width = col1.Width;
            var size2 = text.GetSize ();

            ctx.DrawTextLayout (text, 0, col1.Bottom);
            col1.Height += size2.Height + 10;

            ctx.SetColor (Colors.Black);

            // proofing scale, on second col
            ctx.Save ();
            ctx.SetColor (Colors.Red);
            col2.Left = col1.Right + 10;

            text.Text = "eirmod tempor invidunt ut.";

            var scale = 1.2;
            text.Width = text.Width / scale;
            var size3 = text.GetSize ();
            col2.Height = size3.Height * scale;
            col2.Width = size3.Width * scale + 5;
            ctx.Scale (scale, scale);
            ctx.DrawTextLayout (text, col2.Left / scale, col2.Top / scale);
            ctx.Restore ();

            // proofing heigth, on second col
            ctx.Save ();
            ctx.SetColor (Colors.DarkCyan);
            text.Text = "Praesent ac lacus nec dolor pulvinar feugiat a id elit.";
            var size4 = text.GetSize ();
            text.Height = size4.Height / 2;
            text.Trimming=TextTrimming.WordElipsis;
            ctx.DrawTextLayout (text, col2.Left, col2.Bottom + 5);

            ctx.SetLineWidth (1);
            ctx.SetColor (Colors.Blue);
            ctx.Rectangle (new Rectangle (col2.Left, col2.Bottom + 5, text.Width, text.Height));
            ctx.Stroke();
            ctx.Restore ();

            // drawing col line
            ctx.SetLineWidth (1);

            ctx.SetColor (Colors.Black.WithAlpha (.5));
            ctx.MoveTo (col1.Right + 5, col1.Top);
            ctx.LineTo (col1.Right + 5, col1.Bottom);
            ctx.Stroke ();
            ctx.MoveTo (col2.Right + 5, col2.Top);
            ctx.LineTo (col2.Right + 5, col2.Bottom);
            ctx.Stroke ();
            ctx.SetColor (Colors.Black);

            // proofing rotate, and printing size to see the values
            ctx.Save ();

            text.Font = this.Font.WithSize (10);
            text.Text = string.Format ("Size 1 {0}\r\nSize 2 {1}\r\nSize 3 {2} Scale {3}",
                                       size1, size2, size3, scale);
            text.Width = -1; // this clears textsize
            text.Height = -1;
            ctx.Rotate (5);
            // maybe someone knows a formula with angle and textsize to calculyte ty
            var ty = 30;
            ctx.DrawTextLayout (text, ty, col1.Bottom + 10);

            ctx.Restore ();

            // scale example here:

            ctx.Restore ();

            TextLayout tl0 = new TextLayout (this);

            tl0.Font = this.Font.WithSize (10);
            tl0.Text = "This text contains attributes.";
            tl0.SetUnderline ( 0, "This".Length);
            tl0.SetForeground (new Color (0, 1.0, 1.0), "This ".Length, "text".Length);
            tl0.SetBackground (new Color (0, 0, 0), "This ".Length, "text".Length);
            tl0.SetFontWeight (FontWeight.Bold, "This text ".Length, "contains".Length);
            tl0.SetFontStyle (FontStyle.Italic, "This text ".Length, "contains".Length);
            tl0.SetStrikethrough ("This text contains ".Length, "attributes".Length);

            ctx.SetColor(Colors.DarkGreen);
            ctx.DrawTextLayout (tl0, col2.Left, col2.Bottom + 100);

            // Text boces

            y = 180;

            // Without wrapping

            TextLayout tl = new TextLayout (this);
            tl.Text = "Stright text";
            DrawText (ctx, tl, ref y);

            // With wrapping

            tl = new TextLayout (this);
            tl.Text = "The quick brown fox jumps over the lazy dog";
            tl.Width = 100;
            DrawText (ctx, tl, ref y);

            // With blank lines

            tl = new TextLayout (this);
            tl.Text = "\nEmpty line above\nLine break above\n\nEmpty line above\n\n\nTwo empty lines above\nEmpty line below\n";
            tl.Width = 200;
            DrawText (ctx, tl, ref y);
        }
Esempio n. 20
0
        void DrawText(Context ctx, TextLayout tl, ref double y)
        {
            double x = 10;
            var s = tl.GetSize ();
            var rect = new Rectangle (x, y, s.Width, s.Height).Inflate (0.5, 0.5);
            ctx.SetLineWidth (1);
            ctx.SetColor (Colors.Blue);
            ctx.Rectangle (rect);
            ctx.Stroke ();
            ctx.SetColor (Colors.Black);
            ctx.DrawTextLayout (tl, x, y);

            y += s.Height + 20;
        }
Esempio n. 21
0
        /// <summary>
        /// Draw a tick on the axis.
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw.</param>
        /// <param name="w">The tick position in world coordinates.</param>
        /// <param name="size">The size of the tick (in pixels)</param>
        /// <param name="text">The text associated with the tick</param>
        /// <param name="textOffset">The Offset to draw from the auto calculated position</param>
        /// <param name="axisPhysMin">The minimum physical extent of the axis</param>
        /// <param name="axisPhysMax">The maximum physical extent of the axis</param>
        /// <param name="boundingBox">out: The bounding rectangle for the tick and tickLabel drawn</param>
        /// <param name="labelOffset">out: offset from the axies required for axis label</param>
        public virtual void DrawTick( 
			Context ctx, 
			double w,
			double size,
			string text,
			Point textOffset,
			Point axisPhysMin,
			Point axisPhysMax,
			out Point labelOffset,
			out Rectangle boundingBox )
        {
            // determine physical location where tick touches axis.
            Point tickStart = WorldToPhysical (w, axisPhysMin, axisPhysMax, true);

            // determine offset from start point.
            Point  axisDir = Utils.UnitVector (axisPhysMin, axisPhysMax);

            // rotate axisDir anti-clockwise by TicksAngle radians to get tick direction. Note that because
            // the physical (pixel) origin is at the top left, a RotationTransform by a positive angle will
            // be clockwise.  Consequently, for anti-clockwise rotations, use cos(A-B), sin(A-B) formulae
            double x1 = Math.Cos (TicksAngle) * axisDir.X + Math.Sin (TicksAngle) * axisDir.Y;
            double y1 = Math.Cos (TicksAngle) * axisDir.Y - Math.Sin (TicksAngle) * axisDir.X;

            // now get the scaled tick vector.
            Point tickVector = new Point (TickScale * size * x1, TickScale * size * y1);

            if (TicksCrossAxis) {
                tickStart.X -= tickVector.X / 2;
                tickStart.Y -= tickVector.Y / 2;
            }

            // and the end point [point off axis] of tick mark.
            Point  tickEnd = new Point (tickStart.X + tickVector.X, tickStart.Y + tickVector.Y);

            // and draw it
            ctx.SetLineWidth (1);
            ctx.SetColor (LineColor);
            ctx.MoveTo (tickStart.X+0.5, tickStart.Y+0.5);
            ctx.LineTo (tickEnd.X+0.5, tickEnd.Y+0.5);
            ctx.Stroke ();

            // calculate bounds of tick.
            double minX = Math.Min (tickStart.X, tickEnd.X);
            double minY = Math.Min (tickStart.Y, tickEnd.Y);
            double maxX = Math.Max (tickStart.X, tickEnd.X);
            double maxY = Math.Max (tickStart.Y, tickEnd.Y);
            boundingBox = new Rectangle (minX, minY, maxX-minX, maxY-minY);

            // by default, label offset from axis is 0. TODO: revise this.
            labelOffset = new Point (-tickVector.X, -tickVector.Y);

            // ------------------------

            // now draw associated text.

            // **** TODO ****
            // The following code needs revising. A few things are hard coded when
            // they should not be. Also, angled tick text currently just works for
            // the bottom x-axis. Also, it's a bit hacky.

            if (text != "" && !HideTickText) {
                TextLayout layout = new TextLayout ();
                layout.Font = tickTextFontScaled;
                layout.Text = text;
                Size textSize = layout.GetSize ();

                // determine the center point of the tick text.
                double textCenterX;
                double textCenterY;

                // if text is at pointy end of tick.
                if (!TickTextNextToAxis) {
                    // offset due to tick.
                    textCenterX = tickStart.X + tickVector.X*1.2;
                    textCenterY = tickStart.Y + tickVector.Y*1.2;

                    // offset due to text box size.
                    textCenterX += 0.5 * x1 * textSize.Width;
                    textCenterY += 0.5 * y1 * textSize.Height;
                }
                    // else it's next to the axis.
                else {
                    // start location.
                    textCenterX = tickStart.X;
                    textCenterY = tickStart.Y;

                    // offset due to text box size.
                    textCenterX -= 0.5 * x1 * textSize.Width;
                    textCenterY -= 0.5 * y1 * textSize.Height;

                    // bring text away from the axis a little bit.
                    textCenterX -= x1*(2.0+FontScale);
                    textCenterY -= y1*(2.0+FontScale);
                }

                // If tick text is angled..
                if (TickTextAngle != 0) {

                    // determine the point we want to rotate text about.
                    Point textScaledTickVector = new Point (
                                                TickScale * x1 * (textSize.Height/2),
                                                TickScale * y1 * (textSize.Height/2) );
                    Point rotatePoint;
                    if (TickTextNextToAxis) {
                        rotatePoint = new Point (
                                            tickStart.X - textScaledTickVector.X,
                                            tickStart.Y - textScaledTickVector.Y);
                    }
                    else {
                        rotatePoint = new Point (
                                            tickEnd.X + textScaledTickVector.X,
                                            tickEnd.Y + textScaledTickVector.Y);
                    }

                    double actualAngle;
                    if (FlipTickText) {
                        double radAngle = TickTextAngle * Math.PI / 180;
                        rotatePoint.X += textSize.Width * Math.Cos (radAngle);
                        rotatePoint.Y += textSize.Width * Math.Sin (radAngle);
                        actualAngle = TickTextAngle + 180;
                    }
                    else {
                        actualAngle = TickTextAngle;
                    }

                    ctx.Save ();

                    ctx.Translate (rotatePoint.X, rotatePoint.Y);
                    ctx.Rotate (actualAngle);

                    Point [] recPoints = new Point [2];
                    recPoints[0] = new Point (0.0, -textSize.Height/2);
                    recPoints[1] = new Point (textSize.Width, textSize.Height);
                    ctx.TransformPoints (recPoints);

                    double t_x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                    double t_x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                    double t_y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                    double t_y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                    boundingBox = Rectangle.Union (boundingBox, new Rectangle (t_x1, t_y1, (t_x2-t_x1), (t_y2-t_y1)));

                    ctx.DrawTextLayout (layout, 0, -textSize.Height/2);

                    t_x2 -= tickStart.X;
                    t_y2 -= tickStart.Y;
                    t_x2 *= 1.25;
                    t_y2 *= 1.25;

                    labelOffset = new Point (t_x2, t_y2);

                    ctx.Restore ();

                    //ctx.Rectangle (boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height);
                    //ctx.Stroke ();

                }
                else 				{
                    double bx1 = (textCenterX - textSize.Width/2);
                    double by1 = (textCenterY - textSize.Height/2);
                    double bx2 = textSize.Width;
                    double by2 = textSize.Height;

                    Rectangle drawRect = new Rectangle (bx1, by1, bx2, by2);
                    // ctx.Rectangle (drawRect);

                    boundingBox = Rectangle.Union (boundingBox, drawRect);

                    // ctx.Rectangle (boundingBox);

                    ctx.DrawTextLayout (layout, bx1, by1);

                    textCenterX -= tickStart.X;
                    textCenterY -= tickStart.Y;
                    textCenterX *= 2.3;
                    textCenterY *= 2.3;

                    labelOffset = new Point (textCenterX, textCenterY);
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Draw the Axis Label
        /// </summary>
        /// <param name="ctx>The Drawing Context with which to draw.</param>
        /// <param name="offset">offset from axis. Should be calculated so as to make sure axis label misses tick labels.</param>
        /// <param name="axisPhysicalMin">The physical position corresponding to the world minimum of the axis.</param>
        /// <param name="axisPhysicalMax">The physical position corresponding to the world maximum of the axis.</param>
        /// <returns>boxed Rectangle indicating bounding box of label. null if no label printed.</returns>
        public object DrawLabel(Context ctx, Point offset, Point axisPhysicalMin, Point axisPhysicalMax)
        {
            if (Label != "") {

                // first calculate any extra offset for axis label spacing.
                double extraOffsetAmount = LabelOffset;
                extraOffsetAmount += 2; // empirically determed - text was too close to axis before this.
                if (AutoScaleText && LabelOffsetScaled) {
                    extraOffsetAmount *= FontScale;
                }
                // now extend offset.
                double offsetLength = Math.Sqrt (offset.X*offset.X + offset.Y*offset.Y);
                if (offsetLength > 0.01) {
                    double x_component = offset.X / offsetLength;
                    double y_component = offset.Y / offsetLength;

                    x_component *= extraOffsetAmount;
                    y_component *= extraOffsetAmount;

                    if (LabelOffsetAbsolute) {
                        offset.X = x_component;
                        offset.Y = y_component;
                    }
                    else {
                        offset.X += x_component;
                        offset.Y += y_component;
                    }
                }

                // determine angle of axis in degrees
                double theta = Math.Atan2 (
                    axisPhysicalMax.Y - axisPhysicalMin.Y,
                    axisPhysicalMax.X - axisPhysicalMin.X);
                theta = theta * 180.0 / Math.PI;

                Point average = new Point (
                    (axisPhysicalMax.X + axisPhysicalMin.X)/2,
                    (axisPhysicalMax.Y + axisPhysicalMin.Y)/2);

                ctx.Save ();

                ctx.Translate (average.X + offset.X , average.Y + offset.Y);	// this is done last.
                ctx.Rotate (theta);												// this is done first.

                TextLayout layout = new TextLayout ();
                layout.Font = labelFontScaled;
                layout.Text = Label;
                Size labelSize = layout.GetSize ();

                //Draw label centered around zero.
                ctx.DrawTextLayout (layout, -labelSize.Width/2, -labelSize.Height/2);

                // now work out physical bounds of Rotated and Translated label.
                Point [] recPoints = new Point [2];
                recPoints[0] = new Point (-labelSize.Width/2, -labelSize.Height/2);
                recPoints[1] = new Point ( labelSize.Width/2, labelSize.Height/2);
                ctx.TransformPoints (recPoints);

                double x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                double x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                double y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                double y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                ctx.Restore ();

                // and return label bounding box.
                return new Rectangle (x1, y1, (x2-x1), (y2-y1));
            }
            return null;
        }
Esempio n. 23
0
 public void DrawTextLayout(TextLayout layout, double x, double y)
 {
     handler.DrawTextLayout(Backend, layout, x, y);
 }
		protected override Size OnGetRequiredSize ()
		{
			var layout = new TextLayout ();
			layout.Text = "W";
			layout.Font = layout.Font.WithScaledSize (0.9);
			Size size = layout.GetSize ();
			return new Size (CellWidth, size.Height * linesDisplayedCount + packageDescriptionPaddingHeight + packageDescriptionPadding.VerticalSpacing);
		}
Esempio n. 25
0
 public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
 {
     CGContext ctx = ((CGContextBackend)backend).Context;
     SetupContextForDrawing (ctx);
     MacTextLayoutBackendHandler.Draw (ctx, Toolkit.GetBackend (layout), x, y);
 }
Esempio n. 26
0
        /// <summary>
        /// Draw The legend
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw</param>
        /// <param name="position">The position of the top left of the axis.</param>
        /// <param name="plots">Array of plot objects to appear in the legend.</param>
        /// <param name="scale">if the legend is set to scale, the amount to scale by.</param>
        /// <returns>bounding box</returns>
        public Rectangle Draw(Context ctx, Point position, ArrayList plots, double scale )
        {
            // first of all determine the Font to use in the legend.
            Font textFont;
            if (AutoScaleText) {
                textFont = font_.WithScaledSize (scale);
            }
            else {
                textFont = font_;
            }

            ctx.Save ();

            // determine max width and max height of label strings and
            // count the labels.
            int labelCount = 0;
            int unnamedCount = 0;
            double maxHt = 0;
            double maxWd = 0;
            TextLayout layout = new TextLayout ();
            layout.Font = textFont;

            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }
                layout.Text = label;
                Size labelSize = layout.GetSize ();
                if (labelSize.Height > maxHt) {
                    maxHt = labelSize.Height;
                }
                if (labelSize.Width > maxWd) {
                    maxWd = labelSize.Width;
                }
                ++labelCount;
            }

            bool extendingHorizontally = numberItemsHorizontally_ == -1;
            bool extendingVertically = numberItemsVertically_ == -1;

            // determine width in legend items count units.
            int widthInItemCount = 0;
            if (extendingVertically) {
                if (labelCount >= numberItemsHorizontally_) {
                    widthInItemCount = numberItemsHorizontally_;
                }
                else {
                    widthInItemCount = labelCount;
                }
            }
            else if (extendingHorizontally) {
                widthInItemCount = labelCount / numberItemsVertically_;
                if (labelCount % numberItemsVertically_ != 0)
                    widthInItemCount += 1;
            }
            else {
                throw new NPlotException( "logic error in legend base" );
            }

            // determine height of legend in items count units.
            int heightInItemCount = 0;
            if (extendingHorizontally) {
                if (labelCount >= numberItemsVertically_) {
                    heightInItemCount = numberItemsVertically_;
                }
                else {
                    heightInItemCount = labelCount;
                }
            }
            else {		// extendingVertically
                heightInItemCount = labelCount / numberItemsHorizontally_;
                if (labelCount % numberItemsHorizontally_ != 0)
                    heightInItemCount += 1;
            }

            double lineLength = 20;
            double hSpacing = (int)(5.0f * scale);
            double vSpacing = (int)(3.0f * scale);
            double boxWidth = (int) ((float)widthInItemCount * (lineLength + maxWd + hSpacing * 2.0f ) + hSpacing);
            double boxHeight = (int)((float)heightInItemCount * (maxHt + vSpacing) + vSpacing);

            double totalWidth = boxWidth;
            double totalHeight = boxHeight;

            // draw box around the legend.
            if (BorderStyle == BorderType.Line) {
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();
            }
            else if (BorderStyle == BorderType.Shadow) {
                double offset = (4.0 * scale);
                Color shade = Colors.Gray;
                shade.Alpha = 0.5;
                ctx.SetColor (Colors.Gray);
                ctx.Rectangle (position.X+offset, position.Y+offset, boxWidth, boxHeight);
                ctx.Fill ();
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();

                totalWidth += offset;
                totalHeight += offset;
            }

            /*
               else if ( this.BorderStyle == BorderType.Curved )
               {
                   // TODO. make this nice.
               }
            */
            else {
                // do nothing.
            }

            // now draw entries in box..
            labelCount = 0;
            unnamedCount = 0;

            int plotCount = -1;
            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }

                plotCount += 1;

                double xpos, ypos;
                if (extendingVertically) {
                    xpos = plotCount % numberItemsHorizontally_;
                    ypos = plotCount / numberItemsHorizontally_;
                }
                else {
                    xpos = plotCount / numberItemsVertically_;
                    ypos = plotCount % numberItemsVertically_;
                }

                double lineXPos = (position.X + hSpacing + xpos * (lineLength + maxWd + hSpacing * 2.0));
                double lineYPos = (position.Y + vSpacing + ypos * (vSpacing + maxHt));
                p.DrawInLegend (ctx, new Rectangle (lineXPos, lineYPos, lineLength, maxHt));

                double textXPos = lineXPos + hSpacing + lineLength;
                double textYPos = lineYPos;
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }

                layout.Text = label;
                ctx.DrawTextLayout (layout, textXPos, textYPos);

                ++labelCount;
            }
            ctx.Restore ();
            return new Rectangle (position.X, position.Y, totalWidth, totalHeight);
        }
Esempio n. 27
0
        public void TextWordWrap()
        {
            // Transform is saved
            InitBlank (100, 100);
            var la = new TextLayout ();
            la.Font = Font.FromName ("Arial 12");
            la.Text = "One Two Three Four Five Six Seven Eight Nine";
            la.Width = 90;
            la.Trimming = TextTrimming.Word;
            var s = la.GetSize ();
            context.Rectangle (5.5, 5.5, s.Width, s.Height);
            context.SetColor (Colors.Blue);
            context.Stroke ();

            context.SetColor (Colors.Black);
            context.DrawTextLayout (la, 5, 5);
            CheckImage ("TextWordWrap.png");
        }
Esempio n. 28
0
        public void TextWithBlankLines()
        {
            // Transform is saved
            InitBlank (50, 150);
            var la = new TextLayout ();
            la.Font = Font.FromName ("Arial 12");
            la.Text = "\n\nHello\n\n\nWorld\n\n";

            var s = la.GetSize ();
            context.Rectangle (10.5, 10.5, s.Width, s.Height);
            context.SetColor (Colors.Blue);
            context.Stroke ();

            context.SetColor (Colors.Black);
            context.DrawTextLayout (la, 10, 10);
            CheckImage ("TextWithBlankLines.png");
        }
Esempio n. 29
0
 public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
 {
     var be = (GtkTextLayoutBackendHandler.PangoBackend)Toolkit.GetBackend (layout);
     var pl = be.Layout;
     CairoContextBackend ctx = (CairoContextBackend)backend;
     ctx.Context.MoveTo (x, y);
     if (layout.Height <= 0) {
         Pango.CairoHelper.ShowLayout (ctx.Context, pl);
     } else {
         var lc = pl.LineCount;
         var scale = Pango.Scale.PangoScale;
         double h = 0;
         var fe = ctx.Context.FontExtents;
         var baseline = fe.Ascent / (fe.Ascent + fe.Descent);
         for (int i=0; i<lc; i++) {
             var line = pl.Lines [i];
             var ext = new Pango.Rectangle ();
             var extl = new Pango.Rectangle ();
             line.GetExtents (ref ext, ref extl);
             h += h == 0 ? (extl.Height / scale * baseline) : (extl.Height / scale);
             if (h > layout.Height)
                 break;
             ctx.Context.MoveTo (x, y + h);
             Pango.CairoHelper.ShowLayoutLine (ctx.Context, line);
         }
     }
 }
Esempio n. 30
0
 void DrawGradientButton(Xwt.Drawing.Context G, GradientButton B)
 {
     DrawingPath P = new DrawingPath();
     P.Rectangle(new Xwt.Rectangle(B.Position, B.Size));
     LinearGradient gr;
     G.AppendPath(P);
     Pattern pat = gr = new LinearGradient(B.Position.X, B.Position.Y, B.Position.X + B.Size.Width, B.Position.Y + B.Size.Height);
     gr.AddColorStop(0, B.Color.BlendWith(Colors.White, 0.8));
     gr.AddColorStop(0.5, B.Color);
     gr.AddColorStop(1, B.Color.BlendWith(Colors.White, 0.8));
     G.Pattern = pat;
     G.Fill();
     G.AppendPath(P);
     G.SetColor(Xwt.Drawing.Colors.Black);
     G.SetLineWidth(1);
     G.Stroke();
     TextLayout L = new TextLayout()
     {
         Font = B.Font,
         Text = B.Text
     };
     Size TextSize = new Size(0.6 * L.Font.Size * L.Text.Count(), L.Font.Size);
     G.DrawTextLayout(L, new Xwt.Point(B.Position.X + B.Size.Width / 2 - TextSize.Width / 2, B.Position.Y + B.Size.Height / 2 - TextSize.Height / 2));
 }
Esempio n. 31
0
 public void DrawTextLayout(TextLayout layout, Point location)
 {
     handler.DrawTextLayout (Backend, layout, location.X, location.Y);
 }
Esempio n. 32
0
 public void DrawTextLayout(TextLayout layout, Point location)
 {
     handler.DrawTextLayout(Backend, layout, location.X, location.Y);
 }
Esempio n. 33
0
 public void DrawTextLayout(TextLayout layout, double x, double y)
 {
     handler.DrawTextLayout (Backend, layout, x, y);
 }
        internal void Draw(DrawingPathBackendHandler targetHandler, object ctx, VectorImageData cm)
        {
            int di  = 0;
            int ci  = 0;
            int ii  = 0;
            int ri  = 0;
            int oi  = 0;
            int imi = 0;
            int ti  = 0;

            ContextBackendHandler     handler     = targetHandler as ContextBackendHandler;
            DrawingPathBackendHandler pathHandler = targetHandler;

            for (int n = 0; n < cm.Commands.Length; n++)
            {
                switch (cm.Commands [n])
                {
                case DrawingCommand.AppendPath:
                    var p = cm.Objects [oi++];
                    if (p is VectorImageData)
                    {
                        Draw(targetHandler, ctx, (VectorImageData)p);
                    }
                    else
                    {
                        pathHandler.AppendPath(ctx, p);
                    }
                    break;

                case DrawingCommand.Arc:
                    pathHandler.Arc(ctx, cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.ArcNegative:
                    pathHandler.ArcNegative(ctx, cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.Clip:
                    handler.Clip(ctx);
                    break;

                case DrawingCommand.ClipPreserve:
                    handler.ClipPreserve(ctx);
                    break;

                case DrawingCommand.ClosePath:
                    pathHandler.ClosePath(ctx);
                    break;

                case DrawingCommand.CurveTo:
                    pathHandler.CurveTo(ctx, cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.DrawImage2:
                    handler.DrawImage(ctx, cm.Images [imi++], cm.Rectangles [ri++], cm.Rectangles [ri++]);
                    break;

                case DrawingCommand.DrawImage:
                    handler.DrawImage(ctx, cm.Images [imi++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.DrawTextLayout:
                    var lad = (TextLayoutData)cm.TextLayouts [ti++];
                    var la  = new TextLayout(toolkit);
                    lad.InitLayout(la);
                    handler.DrawTextLayout(ctx, la, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.Fill:
                    handler.Fill(ctx);
                    break;

                case DrawingCommand.FillPreserve:
                    handler.FillPreserve(ctx);
                    break;

                case DrawingCommand.LineTo:
                    pathHandler.LineTo(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.MoveTo:
                    pathHandler.MoveTo(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.NewPath:
                    handler.NewPath(ctx);
                    break;

                case DrawingCommand.Rectangle:
                    pathHandler.Rectangle(ctx, cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.RelCurveTo:
                    pathHandler.RelCurveTo(ctx, cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.RelLineTo:
                    pathHandler.RelLineTo(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.RelMoveTo:
                    pathHandler.RelMoveTo(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.Restore:
                    handler.Restore(ctx);
                    break;

                case DrawingCommand.Rotate:
                    handler.Rotate(ctx, cm.Doubles [di++]);
                    break;

                case DrawingCommand.Save:
                    handler.Save(ctx);
                    break;

                case DrawingCommand.Scale:
                    handler.Scale(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.SetColor:
                    handler.SetColor(ctx, cm.Colors [ci++]);
                    break;

                case DrawingCommand.SetGlobalAlpha:
                    handler.SetGlobalAlpha(ctx, cm.Doubles [di++]);
                    break;

                case DrawingCommand.SetLineDash:
                    var off = cm.Doubles [di++];
                    var ds  = new double [cm.Ints [ii++]];
                    for (int i = 0; i < ds.Length; i++)
                    {
                        ds [i] = cm.Doubles [di++];
                    }
                    handler.SetLineDash(ctx, off, ds);
                    break;

                case DrawingCommand.SetLineWidth:
                    handler.SetLineWidth(ctx, cm.Doubles [di++]);
                    break;

                case DrawingCommand.SetPattern:
                    handler.SetPattern(ctx, cm.Objects [oi++]);
                    break;

                case DrawingCommand.Stroke:
                    handler.Stroke(ctx);
                    break;

                case DrawingCommand.StrokePreserve:
                    handler.StrokePreserve(ctx);
                    break;

                case DrawingCommand.Translate:
                    handler.Translate(ctx, cm.Doubles [di++], cm.Doubles [di++]);
                    break;

                case DrawingCommand.SetStyles:
                    handler.SetStyles(ctx, (StyleSet)cm.Objects [oi++]);
                    break;
                }
            }
        }
Esempio n. 35
0
 public void InitLayout(TextLayout la)
 {
     if (Width != -1)
         la.Width = Width;
     if (Height != -1)
         la.Height = Height;
     if (Text != null)
         la.Text = Text;
     if (Font != null)
         la.Font = Font;
     if (TextTrimming != default(TextTrimming))
         la.Trimming = TextTrimming;
     if (Attributes != null) {
         foreach (var at in Attributes)
             la.AddAttribute (at);
     }
 }