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); }
private IEnumerable <Pango.Attribute> GetParagraphAttributes( Pango.Layout layout, double dpiX, out int indentation, ref Gtk.TextIter position, Gtk.TextIter limit) { IList <Pango.Attribute> attributes = new List <Pango.Attribute> (); indentation = 0; Gtk.TextTag [] tags = position.Tags; position.ForwardToTagToggle(null); if (position.Compare(limit) > 0) { position = limit; } double screen_dpiX = Note.Window.Screen.WidthMm * 254d / Note.Window.Screen.Width; foreach (Gtk.TextTag tag in tags) { if (tag.BackgroundSet) { Gdk.Color color = tag.BackgroundGdk; attributes.Add(new Pango.AttrBackground( color.Red, color.Green, color.Blue)); } if (tag.ForegroundSet) { Gdk.Color color = tag.ForegroundGdk; attributes.Add(new Pango.AttrForeground( color.Red, color.Green, color.Blue)); } if (tag.IndentSet) { layout.Indent = tag.Indent; } if (tag.LeftMarginSet) { indentation = (int)(tag.LeftMargin / screen_dpiX * dpiX); } if (tag.RightMarginSet) { indentation = (int)(tag.RightMargin / screen_dpiX * dpiX); } if (tag.FontDesc != null) { attributes.Add(new Pango.AttrFontDesc(tag.FontDesc)); } if (tag.FamilySet) { attributes.Add(new Pango.AttrFamily(tag.Family)); } if (tag.SizeSet) { attributes.Add(new Pango.AttrSize(tag.Size)); } if (tag.StyleSet) { attributes.Add(new Pango.AttrStyle(tag.Style)); } if (tag.UnderlineSet && tag.Underline != Pango.Underline.Error) { attributes.Add(new Pango.AttrUnderline(tag.Underline)); } if (tag.WeightSet) { attributes.Add(new Pango.AttrWeight(tag.Weight)); } if (tag.StrikethroughSet) { attributes.Add(new Pango.AttrStrikethrough(tag.Strikethrough)); } if (tag.RiseSet) { attributes.Add(new Pango.AttrRise(tag.Rise)); } if (tag.ScaleSet) { attributes.Add(new Pango.AttrScale(tag.Scale)); } if (tag.StretchSet) { attributes.Add(new Pango.AttrStretch(tag.Stretch)); } } return(attributes); }