public Pango.AttrList Copy() { IntPtr raw_ret = pango_attr_list_copy(Handle); Pango.AttrList ret = raw_ret == IntPtr.Zero ? null : (Pango.AttrList)GLib.Opaque.GetOpaque(raw_ret, typeof(Pango.AttrList), true); return(ret); }
internal static EventBox ClickableLabel(string lblTitle) { Gdk.Color lblColour = new Gdk.Color(255, 255, 255); Gdk.Color lblBgColor = new Gdk.Color(36, 36, 36); Pango.AttrList attr = new Pango.AttrList(); attr.Insert(new Pango.AttrUnderline(Pango.Underline.Single)); attr.Insert(new Pango.AttrFontDesc( Pango.FontDescription.FromString("Source Code Pro " + "Regular 14"))); Label label = new Label(lblTitle) { Attributes = attr }; label.ModifyFg(StateType.Active, lblColour); label.ModifyFg(StateType.Normal, lblColour); label.ModifyFg(StateType.Prelight, lblColour); EventBox eventBox = new EventBox { label }; eventBox.ModifyBg(StateType.Active, lblBgColor); eventBox.ModifyBg(StateType.Normal, lblBgColor); return(eventBox); }
public bool HasCharacterRanges(IEnumerable <Range <int> > ranges) { var desc = Control.Describe(); if (noFallbackAttributes == null) { lock (noFallbackLock) { if (noFallbackAttributes != null) { noFallbackAttributes = new Pango.AttrList(); noFallbackAttributes.Change(new Pango.AttrFallback(false)); } } } using (var layout = new Pango.Layout(FontsHandler.Context)) { layout.FontDescription = desc; layout.Attributes = noFallbackAttributes; foreach (var range in ranges) { var text = new string(Enumerable.Range(range.Start, range.Length()).Select(c => (char)c).ToArray()); layout.SetText(text); if (layout.UnknownGlyphsCount > 0) { return(false); } } } return(true); }
public Pango.AttrList Filter(Pango.AttrFilterFunc func) { PangoSharp.AttrFilterFuncWrapper func_wrapper = new PangoSharp.AttrFilterFuncWrapper(func); IntPtr raw_ret = pango_attr_list_filter(Handle, func_wrapper.NativeDelegate, IntPtr.Zero); Pango.AttrList ret = raw_ret == IntPtr.Zero ? null : (Pango.AttrList)GLib.Opaque.GetOpaque(raw_ret, typeof(Pango.AttrList), false); return(ret); }
private Pango.Layout CreateParagraphLayout(Gtk.PrintContext context, Gtk.TextIter p_start, Gtk.TextIter p_end, out int indentation) { Pango.Layout layout = context.CreatePangoLayout(); layout.FontDescription = Window.Editor.Style.FontDesc; int start_index = p_start.LineIndex; indentation = 0; double dpiX = context.DpiX; using (Pango.AttrList attr_list = new Pango.AttrList()) { Gtk.TextIter segm_start = p_start; Gtk.TextIter segm_end; while (segm_start.Compare(p_end) < 0) { segm_end = segm_start; IEnumerable <Pango.Attribute> attrs = GetParagraphAttributes( layout, dpiX, out indentation, ref segm_end, p_end); uint si = (uint)(segm_start.LineIndex - start_index); uint ei = (uint)(segm_end.LineIndex - start_index); foreach (Pango.Attribute a in attrs) { a.StartIndex = si; a.EndIndex = ei; attr_list.Insert(a); } segm_start = segm_end; } layout.Attributes = attr_list; } DepthNoteTag depth = Buffer.FindDepthTag(p_start); if (depth != null) { indentation += ((int)(dpiX / 3)) * depth.Depth; } layout.Width = Pango.Units.FromPixels((int)context.Width - margin_left - margin_right - indentation); layout.Wrap = Pango.WrapMode.WordChar; layout.SetText(Buffer.GetSlice(p_start, p_end, false)); return(layout); }
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; }
public void AssignLayout(Pango.Layout layout) { Pango.FontDescription desc = Pango.FontDescription.FromString(Family.Name); desc.Size = (int)(size * Pango.Scale.PangoScale); desc.Style = style; desc.Weight = (Pango.Weight)Weight; layout.FontDescription = desc; Pango.AttrList attributes = new Pango.AttrList(); attributes.Insert(underline); attributes.Insert(strikeout); attributes.Insert(letterSpacing); layout.Attributes = attributes; }
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); }
public void LoadData(TreeModel treeModel, TreeIter iter) { this.treeModel = treeModel; this.iter = iter; view.Initialize (this); if (view.Markup != null) { FormattedText tx = FormattedText.FromMarkup (view.Markup); Text = tx.Text; var atts = new FastPangoAttrList (); atts.AddAttributes (new TextIndexer (tx.Text), tx.Attributes); Attributes = new Pango.AttrList (atts.Handle); atts.Dispose (); } else { Text = view.Text; } Editable = view.Editable; }
public void Dispose() { if (attributes != null) { attributes.ForEach(attr => attr.Dispose()); attributes.Clear(); attributes = null; } if (attrList != null) { attrList.Dispose(); attrList = null; } if (Layout != null) { Layout.Dispose(); Layout = null; } }
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); }
public void LoadData(TreeModel treeModel, TreeIter iter) { this.treeModel = treeModel; this.iter = iter; view.Initialize(this); if (view.Markup != null) { FormattedText tx = FormattedText.FromMarkup(view.Markup); Text = tx.Text; var atts = new FastPangoAttrList(); atts.AddAttributes(new TextIndexer(tx.Text), tx.Attributes); Attributes = new Pango.AttrList(atts.Handle); atts.Dispose(); } else { Text = view.Text; } Editable = view.Editable; }
/// <summary> /// Like Splice, except it only offsets/clamps the inserted items, doesn't affect items already in the list. /// </summary> public void InsertOffsetList(Pango.AttrList atts, uint startOffset, uint endOffset) { //HACK: atts.Iterator.Attrs broken (throws NRE), so manually P/Invoke var iter = pango_attr_list_get_iterator(atts.Handle); try { do { IntPtr list = pango_attr_iterator_get_attrs(iter); try { int len = g_slist_length(list); for (uint i = 0; i < len; i++) { IntPtr val = g_slist_nth_data(list, i); AddOffsetCopy(val, startOffset, endOffset); } } finally { g_slist_free(list); } } while (pango_attr_iterator_next(iter)); } finally { pango_attr_iterator_destroy(iter); } }
public void SetAttributes () { this.attrList = new Pango.AttrList (); attributes.ForEach (attr => attrList.Insert (attr)); Layout.Attributes = attrList; }
public double ColumnToX (DocumentLine line, int column) { column--; // calculate virtual indentation if (column > 0 && line.Length == 0 && textEditor.GetTextEditorData ().HasIndentationTracker) { using (var l = PangoUtil.CreateLayout (textEditor, textEditor.GetTextEditorData ().IndentationTracker.GetIndentationString (line.Offset))) { l.Alignment = Pango.Alignment.Left; l.FontDescription = textEditor.Options.Font; l.Tabs = tabArray; Pango.Rectangle ink_rect, logical_rect; l.GetExtents (out ink_rect, out logical_rect); return (logical_rect.Width + Pango.Scale.PangoScale - 1) / Pango.Scale.PangoScale; } } if (line == null || line.Length == 0 || column < 0) return 0; int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); int lineOffset = line.Offset; StringBuilder textBuilder = new StringBuilder (); ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document); var startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, lineOffset, line.Length); foreach (Chunk chunk in startChunk) { try { textBuilder.Append (Document.GetTextAt (chunk)); } catch (Exception e) { Console.WriteLine (e); return 0; } } string lineText = textBuilder.ToString (); char[] lineChars = lineText.ToCharArray (); bool containsPreedit = textEditor.ContainsPreedit (lineOffset, line.Length); uint preeditLength = 0; if (containsPreedit) { lineText = lineText.Insert (textEditor.preeditOffset - lineOffset, textEditor.preeditString); preeditLength = (uint)textEditor.preeditString.Length; } if (column < lineText.Length) lineText = lineText.Substring (0, column); var layout = PangoUtil.CreateLayout (textEditor, lineText); layout.Alignment = Pango.Alignment.Left; layout.FontDescription = textEditor.Options.Font; layout.Tabs = tabArray; int startOffset = lineOffset, endOffset = lineOffset + line.Length; uint curIndex = 0, byteIndex = 0; uint curChunkIndex = 0, byteChunkIndex = 0; List<Pango.Attribute> attributes = new List<Pango.Attribute> (); uint oldEndIndex = 0; Cairo.Color curFgColor = textEditor.ColorStyle.PlainText.Foreground; Cairo.Color curBgColor = textEditor.ColorStyle.PlainText.Background; var curWeight = Xwt.Drawing.FontWeight.Normal; var curStyle = Xwt.Drawing.FontStyle.Normal; foreach (Chunk chunk in startChunk) { ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null; foreach (TextLineMarker marker in line.Markers) chunkStyle = marker.GetStyle (chunkStyle); if (chunkStyle != null) { startOffset = chunk.Offset; endOffset = chunk.EndOffset; uint startIndex = (uint)(oldEndIndex); uint endIndex = (uint)(startIndex + chunk.Length); oldEndIndex = endIndex; if (containsPreedit) { if (textEditor.preeditOffset < startOffset) startIndex += preeditLength; if (textEditor.preeditOffset < endOffset) endIndex += preeditLength; } HandleSelection (lineOffset, logicalRulerColumn, - 1, -1, chunk.Offset, chunk.EndOffset, delegate(int start, int end) { var color = textEditor.ColorStyle.GetForeground (chunkStyle); var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); if (!color.Equals (curFgColor)) { curFgColor = color; var foreGround = new Pango.AttrForeground ( (ushort)(color.R * ushort.MaxValue), (ushort)(color.G * ushort.MaxValue), (ushort)(color.B * ushort.MaxValue)); foreGround.StartIndex = si; foreGround.EndIndex = ei; attributes.Add (foreGround); } if (!chunkStyle.TransparentBackground) { color = chunkStyle.Background; if (!color.Equals (curBgColor)) { var background = new Pango.AttrBackground ( (ushort)(color.R * ushort.MaxValue), (ushort)(color.G * ushort.MaxValue), (ushort)(color.B * ushort.MaxValue)); background.StartIndex = si; background.EndIndex = ei; attributes.Add (background); } } }, delegate(int start, int end) { Pango.AttrForeground selectedForeground; if (!SelectionColor.TransparentForeground) { var color = SelectionColor.Foreground; if (color.Equals (curFgColor)) return; curFgColor = color; selectedForeground = new Pango.AttrForeground ( (ushort)(color.R * ushort.MaxValue), (ushort)(color.G * ushort.MaxValue), (ushort)(color.B * ushort.MaxValue)); } else { var color = ColorStyle.GetForeground (chunkStyle); if (color.Equals (curFgColor)) return; curFgColor = color; selectedForeground = new Pango.AttrForeground ( (ushort)(color.R * ushort.MaxValue), (ushort)(color.G * ushort.MaxValue), (ushort)(color.B * ushort.MaxValue)); } selectedForeground.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); selectedForeground.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); attributes.Add (selectedForeground); }); var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex); var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex); if (chunkStyle.FontWeight != curWeight) { curWeight = chunkStyle.FontWeight; var attrWeight = new Pango.AttrWeight ((Pango.Weight)chunkStyle.FontWeight); attrWeight.StartIndex = translatedStartIndex; attrWeight.EndIndex = translatedEndIndex; attributes.Add (attrWeight); } if (chunkStyle.FontStyle != curStyle) { curStyle = chunkStyle.FontStyle; Pango.AttrStyle attrStyle = new Pango.AttrStyle ((Pango.Style)chunkStyle.FontStyle); attrStyle.StartIndex = translatedStartIndex; attrStyle.EndIndex = translatedEndIndex; attributes.Add (attrStyle); } if (chunkStyle.Underline) { var attrUnderline = new Pango.AttrUnderline (Pango.Underline.Single); attrUnderline.StartIndex = translatedStartIndex; attrUnderline.EndIndex = translatedEndIndex; attributes.Add (attrUnderline); } } } Pango.AttrList attributeList = new Pango.AttrList (); attributes.ForEach (attr => attributeList.Insert (attr)); layout.Attributes = attributeList; Pango.Rectangle inkrect, logicalrect; layout.GetExtents (out inkrect, out logicalrect); attributes.ForEach (attr => attr.Dispose ()); attributeList.Dispose (); layout.Dispose (); return (logicalrect.Width + Pango.Scale.PangoScale - 1) / Pango.Scale.PangoScale; }
public void SetAttributes() { this.attrList = new Pango.AttrList(); attributes.ForEach(attr => attrList.Insert(attr)); Layout.Attributes = attrList; }
public double ColumnToX (LineSegment line, int column) { column--; if (line == null || line.Length == 0 || column < 0) return 0; int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); int lineOffset = line.Offset; StringBuilder textBuilder = new StringBuilder (); ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document); var startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, lineOffset, line.Length); foreach (Chunk chunk in startChunk) { try { textBuilder.Append (Document.GetTextAt (chunk)); } catch (Exception e) { Console.WriteLine (e); return 0; } } string lineText = textBuilder.ToString (); char[] lineChars = lineText.ToCharArray (); bool containsPreedit = textEditor.ContainsPreedit (lineOffset, line.Length); uint preeditLength = 0; if (containsPreedit) { lineText = lineText.Insert (textEditor.preeditOffset - lineOffset, textEditor.preeditString); preeditLength = (uint)textEditor.preeditString.Length; } if (column < lineText.Length) lineText = lineText.Substring (0, column); var layout = PangoUtil.CreateLayout (textEditor, lineText); layout.Alignment = Pango.Alignment.Left; layout.FontDescription = textEditor.Options.Font; layout.Tabs = tabArray; int startOffset = lineOffset, endOffset = lineOffset + line.Length; uint curIndex = 0, byteIndex = 0; uint curChunkIndex = 0, byteChunkIndex = 0; List<Pango.Attribute> attributes = new List<Pango.Attribute> (); uint oldEndIndex = 0; foreach (Chunk chunk in startChunk) { ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null; foreach (TextMarker marker in line.Markers) chunkStyle = marker.GetStyle (chunkStyle); if (chunkStyle != null) { startOffset = chunk.Offset; endOffset = chunk.EndOffset; uint startIndex = (uint)(oldEndIndex); uint endIndex = (uint)(startIndex + chunk.Length); oldEndIndex = endIndex; if (containsPreedit) { if (textEditor.preeditOffset < startOffset) startIndex += preeditLength; if (textEditor.preeditOffset < endOffset) endIndex += preeditLength; } HandleSelection (lineOffset, logicalRulerColumn, - 1, -1, chunk.Offset, chunk.EndOffset, delegate(int start, int end) { Pango.AttrForeground foreGround = new Pango.AttrForeground (chunkStyle.Color.Red, chunkStyle.Color.Green, chunkStyle.Color.Blue); foreGround.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); foreGround.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); attributes.Add (foreGround); if (!chunkStyle.TransparentBackround) { var background = new Pango.AttrBackground (chunkStyle.BackgroundColor.Red, chunkStyle.BackgroundColor.Green, chunkStyle.BackgroundColor.Blue); background.StartIndex = foreGround.StartIndex; background.EndIndex = foreGround.EndIndex; attributes.Add (background); } }, delegate(int start, int end) { Pango.AttrForeground selectedForeground = new Pango.AttrForeground (SelectionColor.Color.Red, SelectionColor.Color.Green, SelectionColor.Color.Blue); selectedForeground.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); selectedForeground.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); attributes.Add (selectedForeground); }); var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex); var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex); if (chunkStyle.Bold) { Pango.AttrWeight attrWeight = new Pango.AttrWeight (Pango.Weight.Bold); attrWeight.StartIndex = translatedStartIndex; attrWeight.EndIndex = translatedEndIndex; attributes.Add (attrWeight); } if (chunkStyle.Italic) { Pango.AttrStyle attrStyle = new Pango.AttrStyle (Pango.Style.Italic); attrStyle.StartIndex = translatedStartIndex; attrStyle.EndIndex = translatedEndIndex; attributes.Add (attrStyle); } if (chunkStyle.Underline) { Pango.AttrUnderline attrUnderline = new Pango.AttrUnderline (Pango.Underline.Single); attrUnderline.StartIndex = translatedStartIndex; attrUnderline.EndIndex = translatedEndIndex; attributes.Add (attrUnderline); } } } Pango.AttrList attributeList = new Pango.AttrList (); attributes.ForEach (attr => attributeList.Insert (attr)); layout.Attributes = attributeList; Pango.Rectangle ink_rect, logical_rect; layout.GetExtents (out ink_rect, out logical_rect); attributes.ForEach (attr => attr.Dispose ()); attributeList.Dispose (); layout.Dispose (); return (logical_rect.Width + Pango.Scale.PangoScale - 1) / Pango.Scale.PangoScale; }
public void Splice(Pango.AttrList attrs, int pos, int len) { pango_attr_list_splice(list, attrs.Handle, pos, len); }
public void Dispose () { if (attributes != null) { attributes.ForEach (attr => attr.Dispose ()); attributes.Clear (); attributes = null; } if (attrList != null) { attrList.Dispose (); attrList = null; } if (Layout != null) { Layout.Dispose (); Layout = null; } }
private Pango.Layout CreateParagraphLayout (Gtk.PrintContext context, Gtk.TextIter p_start, Gtk.TextIter p_end, out int indentation) { Pango.Layout layout = context.CreatePangoLayout (); layout.FontDescription = Window.Editor.Style.FontDesc; int start_index = p_start.LineIndex; indentation = 0; double dpiX = context.DpiX; using (Pango.AttrList attr_list = new Pango.AttrList ()) { Gtk.TextIter segm_start = p_start; Gtk.TextIter segm_end; while (segm_start.Compare (p_end) < 0) { segm_end = segm_start; IEnumerable<Pango.Attribute> attrs = GetParagraphAttributes ( layout, dpiX, out indentation, ref segm_end, p_end); uint si = (uint) (segm_start.LineIndex - start_index); uint ei = (uint) (segm_end.LineIndex - start_index); foreach (Pango.Attribute a in attrs) { a.StartIndex = si; a.EndIndex = ei; attr_list.Insert (a); } segm_start = segm_end; } layout.Attributes = attr_list; } DepthNoteTag depth = Buffer.FindDepthTag (p_start); if (depth != null) indentation += ((int) (dpiX / 3)) * depth.Depth; layout.Width = Pango.Units.FromPixels ((int)context.Width - margin_left - margin_right - indentation); layout.Wrap = Pango.WrapMode.WordChar; layout.SetText (Buffer.GetSlice (p_start, p_end, false)); return layout; }
public static GLib.List ItemizeWithBaseDir(Pango.Context context, Pango.Direction base_dir, string text, int start_index, int length, Pango.AttrList attrs, Pango.AttrIterator cached_iter) { IntPtr native_text = GLib.Marshaller.StringToPtrGStrdup(text); IntPtr raw_ret = pango_itemize_with_base_dir(context == null ? IntPtr.Zero : context.Handle, (int)base_dir, native_text, start_index, length, attrs == null ? IntPtr.Zero : attrs.Handle, cached_iter == null ? IntPtr.Zero : cached_iter.Handle); GLib.List ret = new GLib.List(raw_ret); GLib.Marshaller.Free(native_text); return(ret); }
public void Splice(Pango.AttrList other, int pos, int len) { pango_attr_list_splice(Handle, other == null ? IntPtr.Zero : other.Handle, pos, len); }