Exemple #1
0
 public static string Ellipsize(Pango.Layout layout, string newtext, int bound, int ellipsis_width, int en_width)
 {
     int width, tmp;
       layout.SetText (newtext);
       layout.GetPixelSize (out width, out tmp);
       if (width < bound)
        return newtext;
       if (bound <= ellipsis_width)
        return ellipsis;
       string ellipsized = "";
       int i = 0;
       i = (bound - ellipsis_width) / (en_width);
       if (i >= newtext.Length)
        i = 0;
       ellipsized = newtext.Substring (0, i);
       while (true)
       {
        ellipsized = ellipsized + newtext[i];
        layout.SetText (ellipsized);
        layout.GetPixelSize (out width, out tmp);
        if (i == newtext.Length - 1) {
     ellipsized = "";
     i = 0;
     continue;
        }
        if (width > bound - ellipsis_width)
     break;
        i++;
       }
       ellipsized = ellipsized.Remove (ellipsized.Length - 1, 1);
       ellipsized += ellipsis;
       return ellipsized;
 }
        public FormattedTextImpl(
            Pango.Context context,
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(text != null);
            Layout = new Pango.Layout(context);
            _text = text;
            Layout.SetText(text);
            Layout.FontDescription = new Pango.FontDescription
            {
                Family = fontFamily,
                Size = Pango.Units.FromDouble(CorrectScale(fontSize)),
                Style = (Pango.Style)fontStyle,
                Weight = fontWeight.ToCairo()
            };

            Layout.Alignment = textAlignment.ToCairo();
            Layout.Attributes = new Pango.AttrList();
        }
Exemple #3
0
        protected void DrawHorizontalSectionIndicator(string text, Cairo.Context cr, Pango.Layout layout, double x, double y, double w, out double h)
        {
            cr.MoveTo(x,y);
            cr.LineTo(x,y+SectionSerifeWidth*2);
            cr.MoveTo(x,y+SectionSerifeWidth);
            cr.LineTo(x+w,y+SectionSerifeWidth);
            cr.MoveTo(x+w,y);
            cr.LineTo(x+w,y+SectionSerifeWidth*2);
            cr.Color = new Cairo.Color(0, 0, 0);
            cr.LineWidth = 1;
            cr.Stroke();

            layout.Width = (int)(w*Pango.Scale.PangoScale);
            layout.Alignment = Pango.Alignment.Center;
            layout.SetText (text);
            layout.Ellipsize = EllipsizeMode.Middle;
            layout.Justify = true;
            cr.Color = new Cairo.Color(0, 0, 0);
            cr.MoveTo(x,y+SectionSerifeWidth*2);
            Pango.CairoHelper.ShowLayout (cr, layout);

            int lw,lh;
            layout.GetPixelSize(out lw, out lh);
            h=(double)lh+SectionSerifeWidth*2;
        }
Exemple #4
0
 public static void Write(BinaryWriter file, Pango.Rectangle box)
 {
     file.Write(box.X);
     file.Write(box.Y);
     file.Write(box.Width);
     file.Write(box.Height);
 }
Exemple #5
0
		public Layout (Pango.Context context) : base (IntPtr.Zero)
		{
			if (GetType () != typeof (Layout)) {
				throw new InvalidOperationException ("Can't override this constructor.");
			}
			Raw = pango_layout_new(context == null ? IntPtr.Zero : context.Handle);
		}
Exemple #6
0
		public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
		{
			int markerStart = LineSegment.Offset + System.Math.Max (StartCol - 1, 0);
			int markerEnd = LineSegment.Offset + (EndCol < 1 ? LineSegment.Length : EndCol - 1);
			if (markerEnd < startOffset || markerStart > endOffset) 
				return;
			
			bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut;
			
			if (drawOverlay && editor.IsSomethingSelected) {
				var selectionRange = editor.SelectionRange;
				if (selectionRange.Contains (markerStart) && selectionRange.Contains (markerEnd))
					return;
				if (selectionRange.Contains (markerEnd))
					markerEnd = selectionRange.Offset;
				if (selectionRange.Contains (markerStart))
					markerStart = selectionRange.EndOffset;
				if (markerEnd <= markerStart)
					return;
			}
			
			double drawFrom;
			double drawTo;
				
			if (markerStart < startOffset && endOffset < markerEnd) {
				drawFrom = startXPos;
				drawTo = endXPos;
			} else {
				int start = startOffset < markerStart ? markerStart : startOffset;
				int end = endOffset < markerEnd ? endOffset : markerEnd;
				int /*lineNr,*/ x_pos;
				
				x_pos = layout.IndexToPos (start - startOffset).X;
				drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
				x_pos = layout.IndexToPos (end - startOffset).X;
	
				drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}
			
			drawFrom = System.Math.Max (drawFrom, editor.TextViewMargin.XOffset);
			drawTo = System.Math.Max (drawTo, editor.TextViewMargin.XOffset);
			if (drawFrom >= drawTo)
				return;
			
			double height = editor.LineHeight / 5;
			cr.Color = ColorName == null ? Color : editor.ColorStyle.GetColorFromDefinition (ColorName);
			if (drawOverlay) {
				cr.Rectangle (drawFrom, y, drawTo - drawFrom, editor.LineHeight);
				var color = editor.ColorStyle.Default.CairoBackgroundColor;
				color.A = 0.6;
				cr.Color = color;
				cr.Fill ();
			} else if (Wave) {	
				Pango.CairoHelper.ShowErrorUnderline (cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
			} else {
				cr.MoveTo (drawFrom, y + editor.LineHeight - 1);
				cr.LineTo (drawTo, y + editor.LineHeight - 1);
				cr.Stroke ();
			}
		}
		internal static void RenderPlaceholderText (Gtk.Entry entry, Gtk.ExposeEventArgs args, string placeHolderText, ref Pango.Layout layout)
		{
			// The Entry's GdkWindow is the top level window onto which
			// the frame is drawn; the actual text entry is drawn into a
			// separate window, so we can ensure that for themes that don't
			// respect HasFrame, we never ever allow the base frame drawing
			// to happen
			if (args.Event.Window == entry.GdkWindow)
				return;

			if (entry.Text.Length > 0)
				return;

			if (layout == null) {
				layout = new Pango.Layout (entry.PangoContext);
				layout.FontDescription = entry.PangoContext.FontDescription.Copy ();
			}

			int wh, ww;
			args.Event.Window.GetSize (out ww, out wh);

			int width, height;
			layout.SetText (placeHolderText);
			layout.GetPixelSize (out width, out height);
			using (var gc = new Gdk.GC (args.Event.Window)) {
				gc.Copy (entry.Style.TextGC (Gtk.StateType.Normal));
				Color color_a = entry.Style.Base (Gtk.StateType.Normal).ToXwtValue ();
				Color color_b = entry.Style.Text (Gtk.StateType.Normal).ToXwtValue ();
				gc.RgbFgColor = color_b.BlendWith (color_a, 0.5).ToGtkValue ();

				args.Event.Window.DrawLayout (gc, 2, (wh - height) / 2 + 1, layout);
			}
		}
 /// <summary>
 /// Adds a tag to a text buffer.
 /// </summary>
 public static void AddTag(this TextBuffer buff, string tagName, string foreground, string family, Pango.Style style)
 {
     TextTag tag = new TextTag(tagName);
     tag.Foreground = foreground;
     tag.Family = family;
     tag.Style = style;
     buff.TagTable.Add(tag);
 }
		public void GetRange (out int start, out int len, out Pango.Script script)
		{
			IntPtr start_ptr;
			IntPtr end_ptr;

			pango_script_iter_get_range (Handle, out start_ptr, out end_ptr, out script);
			start = (int)g_utf8_pointer_to_offset (native_text, start_ptr);
			len = (int)g_utf8_pointer_to_offset (start_ptr, end_ptr);
		}
Exemple #10
0
		public void GetGlyphExtents(uint glyph, Pango.Rectangle ink_rect, Pango.Rectangle logical_rect) {
			IntPtr native_ink_rect = GLib.Marshaller.StructureToPtrAlloc (ink_rect);
			IntPtr native_logical_rect = GLib.Marshaller.StructureToPtrAlloc (logical_rect);
			pango_font_get_glyph_extents(Handle, glyph, native_ink_rect, native_logical_rect);
			ink_rect = Pango.Rectangle.New (native_ink_rect);
			Marshal.FreeHGlobal (native_ink_rect);
			logical_rect = Pango.Rectangle.New (native_logical_rect);
			Marshal.FreeHGlobal (native_logical_rect);
		}
Exemple #11
0
			public LayoutProxy (LayoutCache layoutCache, Pango.Layout layout)
			{
				if (layoutCache == null)
					throw new ArgumentNullException ("layoutCache");
				if (layout == null)
					throw new ArgumentNullException ("layout");
				this.layoutCache = layoutCache;
				this.layout = layout;
			}
Exemple #12
0
		public void GetExtents(ref Pango.Rectangle ink_rect, ref Pango.Rectangle logical_rect) {
			IntPtr native_ink_rect = GLib.Marshaller.StructureToPtrAlloc (ink_rect);
			IntPtr native_logical_rect = GLib.Marshaller.StructureToPtrAlloc (logical_rect);
			pango_layout_line_get_extents(Handle, native_ink_rect, native_logical_rect);
			ink_rect = Pango.Rectangle.New (native_ink_rect);
			Marshal.FreeHGlobal (native_ink_rect);
			logical_rect = Pango.Rectangle.New (native_logical_rect);
			Marshal.FreeHGlobal (native_logical_rect);
		}
Exemple #13
0
		public void ExtentsRange(int start, int end, Pango.Font font, Pango.Rectangle ink_rect, Pango.Rectangle logical_rect) {
			IntPtr native_ink_rect = GLib.Marshaller.StructureToPtrAlloc (ink_rect);
			IntPtr native_logical_rect = GLib.Marshaller.StructureToPtrAlloc (logical_rect);
			pango_glyph_string_extents_range(Handle, start, end, font == null ? IntPtr.Zero : font.Handle, native_ink_rect, native_logical_rect);
			ink_rect = Pango.Rectangle.New (native_ink_rect);
			Marshal.FreeHGlobal (native_ink_rect);
			logical_rect = Pango.Rectangle.New (native_logical_rect);
			Marshal.FreeHGlobal (native_logical_rect);
		}
Exemple #14
0
		public void GetClusterExtents(out Pango.Rectangle ink_rect, out Pango.Rectangle logical_rect) {
			IntPtr native_ink_rect = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (Pango.Rectangle)));
			IntPtr native_logical_rect = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (Pango.Rectangle)));
			pango_layout_iter_get_cluster_extents(Handle, native_ink_rect, native_logical_rect);
			ink_rect = Pango.Rectangle.New (native_ink_rect);
			Marshal.FreeHGlobal (native_ink_rect);
			logical_rect = Pango.Rectangle.New (native_logical_rect);
			Marshal.FreeHGlobal (native_logical_rect);
		}
Exemple #15
0
        public static FontDescription CopyModified(this FontDescription font, double? scale = null, Pango.Weight? weight = null)
        {
            font = font.Copy ();

            if (scale.HasValue)
                Scale (font, scale.Value);

            if (weight.HasValue)
                font.Weight = weight.Value;

            return font;
        }
Exemple #16
0
        // Pango Style sounds like some sort of dance
        private static FontStyle FromPangoStyle(Pango.Style pangoStyle, Pango.Weight pangoWeight)
        {
            FontStyle result = FontStyle.Regular;

            if (pangoWeight == Pango.Weight.Bold)
                result |= FontStyle.Bold;

            if (pangoStyle == Pango.Style.Italic)
                result |= FontStyle.Italic;

            return FontStyle.Regular;
        }
Exemple #17
0
		public static void ContextSetShapeRenderer(Pango.Context context, Pango.CairoShapeRendererFunc func) {
			PangoSharp.CairoShapeRendererFuncWrapper func_wrapper = new PangoSharp.CairoShapeRendererFuncWrapper (func);
			IntPtr data;
			GLib.DestroyNotify dnotify;
			if (func == null) {
				data = IntPtr.Zero;
				dnotify = null;
			} else {
				data = (IntPtr) GCHandle.Alloc (func_wrapper);
				dnotify = GLib.DestroyHelper.NotifyHandler;
			}
			pango_cairo_context_set_shape_renderer(context == null ? IntPtr.Zero : context.Handle, func_wrapper.NativeDelegate, data, dnotify);
		}
Exemple #18
0
		public static bool ParseMarkup (string markup, char accel_marker, out Pango.AttrList attrs, out string text, out char accel_char)
		{
			uint ucs4_accel_char;
			IntPtr text_as_native;
			IntPtr attrs_handle;
			IntPtr native_markup = GLib.Marshaller.StringToPtrGStrdup (markup);
			bool result = pango_parse_markup (native_markup, -1, GLib.Marshaller.CharToGUnichar (accel_marker), out attrs_handle, out text_as_native, out ucs4_accel_char, IntPtr.Zero);
			GLib.Marshaller.Free (native_markup);
			accel_char = GLib.Marshaller.GUnicharToChar (ucs4_accel_char);
			text = GLib.Marshaller.Utf8PtrToString (text_as_native);
			attrs = new Pango.AttrList (attrs_handle);
			return result;
		}
Exemple #19
0
		public GlyphItem[] ApplyAttrs (string text, Pango.AttrList list)
		{
			IntPtr native_text = GLib.Marshaller.StringToPtrGStrdup (text);
			IntPtr list_handle = pango_glyph_item_apply_attrs (ref this, native_text, list.Handle);
			GLib.Marshaller.Free (native_text);
			if (list_handle == IntPtr.Zero)
				return new GlyphItem [0];
			GLib.SList item_list = new GLib.SList (list_handle, typeof (GlyphItem));
			GlyphItem[] result = new GlyphItem [item_list.Count];
			int i = 0;
			foreach (GlyphItem item in item_list)
				result [i++] = item;
			return result;
		}
Exemple #20
0
	public static string Ellipsize (Pango.Layout layout, string newtext, int bound, int ellipsis_width, int en_width)
	{
		int width, tmp;

		layout.SetText (newtext);
		layout.GetPixelSize (out width, out tmp);

		if (width < bound)
			return newtext;

		if (bound <= ellipsis_width)
			return ellipsis;

		string ellipsized = "";
		int i = 0;

		//make a guess of where to start
		i = (bound - ellipsis_width) / (en_width);
		if (i >= newtext.Length)
			i = 0;
		ellipsized = newtext.Substring (0, i);

		//add chars one by one to determine how many are allowed
		while (true)
		{
			ellipsized = ellipsized + newtext[i];
			layout.SetText (ellipsized);
			layout.GetPixelSize (out width, out tmp);

			if (i == newtext.Length - 1) {
				//bad guess, start from the beginning
				ellipsized = "";
				i = 0;
				continue;
			}

			if (width > bound - ellipsis_width)
				break;

			i++;
		}

		ellipsized = ellipsized.Remove (ellipsized.Length - 1, 1);
		ellipsized += ellipsis;

		return ellipsized;
	}
		public void GetFont (out Pango.FontDescription desc, out Pango.Language language, out Pango.Attribute[] extra_attrs)
		{
			desc = new FontDescription ();
			IntPtr language_handle, list_handle;
			pango_attr_iterator_get_font (Handle, desc.Handle, out language_handle, out list_handle);
			desc.Family = desc.Family; // change static string to allocated one
			language = language_handle == IntPtr.Zero ? null : new Language (language_handle);
			if (list_handle == IntPtr.Zero) {
				extra_attrs = new Pango.Attribute [0];
				return;
			}
			GLib.SList list = new GLib.SList (list_handle);
			extra_attrs = new Pango.Attribute [list.Count];
			int i = 0;
			foreach (IntPtr raw_attr in list)
				extra_attrs [i++] = Pango.Attribute.GetAttribute (raw_attr);
		}
Exemple #22
0
 protected void DrawVerticalSectionIndicator(string text, Cairo.Context cr, Pango.Layout layout, double x, double y, out double w, double h)
 {
     cr.MoveTo(x,y);
     cr.LineTo(x+SectionSerifeWidth*2,y);
     cr.MoveTo(x+SectionSerifeWidth,y);
     cr.LineTo(x+SectionSerifeWidth,y+h);
     cr.MoveTo(x,y+h);
     cr.LineTo(x+SectionSerifeWidth*2,y+h);
     cr.Color = new Cairo.Color(0, 0, 0);
     cr.LineWidth = 1;
     layout.Alignment = Pango.Alignment.Left;
     layout.SetText (text);
     layout.Ellipsize = EllipsizeMode.Middle;
     layout.Justify = true;
     int lh,lw;
     layout.GetPixelSize(out lw, out lh);
     w=(double)lw+SectionSerifeWidth*2;
     cr.Color = new Cairo.Color(0, 0, 0);
     cr.MoveTo(x+SectionSerifeWidth*2,y+(h-lh)/2);
     Pango.CairoHelper.ShowLayout (cr, layout);
 }
Exemple #23
0
        public override void Draw(TextEditor editor, Gdk.Drawable win,Pango.Layout layout, bool selected, int startOffset, int endOffset, int y, int startXPos, int endXPos)
        {
            int markerStart = LineSegment.Offset + System.Math.Max (StartCol, 0);
                  int markerEnd   = LineSegment.Offset + (EndCol < 0? LineSegment.Length : EndCol);
                  if (markerEnd < startOffset || markerStart > endOffset)
                        return;

                  int from;
                  int to;

                  if (markerStart < startOffset && endOffset < markerEnd) {
                        from = startXPos;
                        to   = endXPos;
                  } else {
                        int start = startOffset < markerStart ? markerStart : startOffset;
                        int end   = endOffset < markerEnd ? endOffset : markerEnd;
                        from = startXPos + editor.GetWidth (editor.Document.GetTextAt (startOffset, start - startOffset));
                        to   = startXPos + editor.GetWidth (editor.Document.GetTextAt (startOffset, end - startOffset));
                  }
                  from = System.Math.Max (from, editor.TextViewMargin.XOffset);
                  to   = System.Math.Max (to, editor.TextViewMargin.XOffset);
                  if (from >= to) {
                        return;
                  }

                  using (Gdk.GC gc = new Gdk.GC (win)) {
                       // gc.RgbFgColor = ColorName == null ? Color : editor.ColorStyle.GetColorFromDefinition (ColorName);
                        int drawY    = y + editor.LineHeight - 1;

                        win.DrawLine (gc, from, drawY, to, drawY);
            if(@from<to){
                //gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.BackgroundColor;
                //win.DrawRectangle (gc, true, @from + 1, y + 1, to - @from - 1, editor.LineHeight - 2);
                gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.Color;
                win.DrawRectangle (gc, false, @from, y, to - @from, editor.LineHeight - 1);
            }

                  }
        }
Exemple #24
0
        public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            int markerStart = Segment.Offset;
            int markerEnd = Segment.EndOffset;
            if (markerEnd < startOffset || markerStart > endOffset)
                return;

            //            if (editor.IsSomethingSelected)
            //            {
            //                var range = editor.SelectionRange;
            //
            //                if (range.Contains(markerStart))
            //                {
            //                    int end = System.Math.Min (markerEnd, range.EndOffset);
            //                    this.InternalDraw (markerStart, end, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
            //                    this.InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
            //                    return;
            //                }
            //
            //                if (range.Contains(markerEnd))
            //                {
            //                    this.InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
            //                    this.InternalDraw (range.Offset, markerEnd, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
            //                    return;
            //                }
            //
            //                if (markerStart <= range.Offset && range.EndOffset <= markerEnd)
            //                {
            //                    this.InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
            //                    this.InternalDraw (range.Offset, range.EndOffset, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
            //                    this.InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
            //                    return;
            //                }
            //
            //            }

            this.InternalDraw (markerStart, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
        }
		void DrawString (string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg)
		{
			Pango.Layout pl = new Pango.Layout (pango);
			if (isMarkup)
				pl.SetMarkup (text);
			else
				pl.SetText (text);
			pl.FontDescription = Styles.StatusFont;
			pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Styles.StatusFontPixelHeight);
			pl.Ellipsize = Pango.EllipsizeMode.End;
			pl.Width = Pango.Units.FromPixels(width);

			int w, h;
			pl.GetPixelSize (out w, out h);

			context.Save ();
			// use widget height instead of message box height as message box does not have a true height when no widgets are packed in it
			// also ensures animations work properly instead of getting clipped
			context.Rectangle (new Rectangle (x, arg.Allocation.Y, width, arg.Allocation.Height));
			context.Clip ();

			// Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels
			context.MoveTo (x, y - h / 2 - (h % 2));
			context.Color = Styles.WithAlpha (FontColor (), opacity);

			Pango.CairoHelper.ShowLayout (context, pl);
			pl.Dispose ();
			context.Restore ();
		}
 public void GetWidthRange(Pango.Layout layout, out int min, out int max)
 {
     // -1 b/c of 2 public domain entries
     min = max = ICON_SIZE * attributes.Length - 1;
 }
			public LayoutDescriptor (Pango.Layout layout, int width, int height)
			{
				this.Layout = layout;
				this.Width = width;
				this.Height = height;
			}
		public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
		{
			if (LineSegment.Markers.Any (m => m is CurrentDebugLineTextMarker))
				return;
			base.Draw (editor, cr, layout, selected, startOffset, endOffset, y, startXPos, endXPos);
		}
Exemple #29
0
 static extern IntPtr pango_attr_stretch_new(Pango.Stretch stretch);
Exemple #30
0
 public AttrStretch(Pango.Stretch stretch)
     : this(pango_attr_stretch_new (stretch))
 {
 }