public Pango.FontMetrics GetMetrics(Pango.FontDescription desc, Pango.Language language) { IntPtr raw_ret = pango_context_get_metrics(Handle, desc == null ? IntPtr.Zero : desc.Handle, language == null ? IntPtr.Zero : language.Handle); Pango.FontMetrics ret = raw_ret == IntPtr.Zero ? null : (Pango.FontMetrics)GLib.Opaque.GetOpaque(raw_ret, typeof(Pango.FontMetrics), false); return(ret); }
private void OnTextViewSizeRequested(object o, SizeRequestedArgs args) { Pango.FontMetrics metrics = PangoContext.GetMetrics(entry.Style.FontDescription, PangoContext.Language); int line_height = ((int)(metrics.Ascent + metrics.Descent) + 512) >> 10; // PANGO_PIXELS(d) metrics.Dispose(); HeightRequest = (line_height + 2) * 2; }
protected override void OnGetPreferredHeight(out int minimum_height, out int natural_height) { int line_height; using (Pango.FontMetrics metrics = PangoContext.GetMetrics( entry.StyleContext.GetFont(StateFlags.Normal), PangoContext.Language)) { line_height = ((metrics.Ascent + metrics.Descent) + 512) >> 10; // PANGO_PIXELS(d) } minimum_height = natural_height = (line_height + 2) * 2; }
protected override void UpdateLayout() { System.Console.WriteLine("in update layout {0}", Allocation.ToString()); int num_thumbnails; if (collection != null) { num_thumbnails = collection.Count; } else { num_thumbnails = 0; } cells_per_row = System.Math.Max(num_thumbnails, 1); int num_rows = 1; int num_cols = num_thumbnails; int available_height = Allocation.Height - 2 * BORDER_SIZE; if (DisplayTags) { available_height -= tag_icon_size + tag_icon_vspacing; } if (DisplayDates && this.Style != null) { Pango.FontMetrics metrics = this.PangoContext.GetMetrics(this.Style.FontDescription, Pango.Language.FromString("en_US")); available_height -= PangoPixels(metrics.Ascent + metrics.Descent); } thumbnail_width = (int)(available_height / thumbnail_ratio); cell_width = ThumbnailWidth + 2 * cell_border_width; cell_height = ThumbnailHeight + 2 * cell_border_width; SetSize(System.Math.Max(((uint)(num_cols * cell_width + 2 * BORDER_SIZE)), (uint)Allocation.Width), (uint)(num_rows * cell_height + 2 * BORDER_SIZE)); Vadjustment.StepIncrement = cell_height; Vadjustment.Change(); Hadjustment.StepIncrement = cell_width; Hadjustment.Change(); }
public TextBox(int nlines) { ShadowType = Gtk.ShadowType.In; SetPolicy(Gtk.PolicyType.Never, Gtk.PolicyType.Automatic); textview = new Gtk.TextView(); textview.WrapMode = Gtk.WrapMode.Word; textview.Show(); Add(textview); Pango.Context ctx = textview.PangoContext; Pango.FontMetrics metrics = ctx.GetMetrics(textview.Style.FontDescription, ctx.Language); int lineHeight = (metrics.Ascent + metrics.Descent) / (int)Pango.Scale.PangoScale; SetSizeRequest(-1, lineHeight * nlines); textview.Buffer.Changed += Buffer_Changed; }
private int LegendHeight() { int max_height = 0; Pango.FontMetrics metrics = this.PangoContext.GetMetrics(this.Style.FontDescription, Pango.Language.FromString("en_US")); max_height += PangoPixels(metrics.Ascent + metrics.Descent); foreach (Pango.Layout l in tick_layouts) { if (l != null) { int width, height; l.GetPixelSize(out width, out height); max_height = Math.Max(height, max_height); } } return((int)(max_height * 1.5)); }
protected override void OnSizeRequested(ref Gtk.Requisition requisition) { EnsureStyle(); Pango.FontMetrics metrics = PangoContext.GetMetrics(Style.FontDescription, PangoContext.Language); renderer.Size = ((int)(metrics.Ascent + metrics.Descent) + 512) >> 10; // PANGO_PIXELS(d) metrics.Dispose(); if (HasFrame) { renderer.Xpad = Style.Xthickness + (interior_focus ? focus_width : 0) + 2; renderer.Ypad = Style.Ythickness + (interior_focus ? focus_width : 0) + 2; } else { renderer.Xpad = 0; renderer.Ypad = 0; } requisition.Width = renderer.Width; requisition.Height = renderer.Height; }
protected Requisition SizeRequested() { var requisition = new Requisition(); Pango.FontMetrics metrics = PangoContext.GetMetrics(StyleContext.GetFont(StateFlags), PangoContext.Language); renderer.Size = ((int)(metrics.Ascent + metrics.Descent) + 512) >> 10; // PANGO_PIXELS(d) metrics.Dispose(); if (HasFrame) { renderer.Xpad = MarginLeft + (interior_focus ? focus_width : 0) + 2; renderer.Ypad = MarginTop + (interior_focus ? focus_width : 0) + 2; } else { renderer.Xpad = 0; renderer.Ypad = 0; } requisition.Width = renderer.Width; requisition.Height = renderer.Height; return(requisition); }
public void DrawText(int x, int y, String text, TextAlign align) { Pango.FontDescription fd = Pango.FontDescription.FromString(FontFamily); fd.Size = Pango.Units.FromPixels(FontSize); if ((FontStyle & FontStyle.Bold) != 0) { fd.Weight = Pango.Weight.Bold; } if ((FontStyle & FontStyle.Italic) != 0) { fd.Style = Pango.Style.Italic; } Pango.Font font = parent.PangoContext.LoadFont(fd); Pango.Language lang = Pango.Language.FromString("en"); Pango.FontMetrics metrics = font.GetMetrics(lang); int estWidth = text.Length * metrics.ApproximateCharWidth * 3 / 2; Pango.Context pango = parent.PangoContext; Pango.Layout layout = new Pango.Layout(pango) { Width = estWidth, Wrap = Pango.WrapMode.Word, Alignment = Pango.Alignment.Left, FontDescription = fd }; int color = this.Color; ushort cRed = (ushort)((color >> 16) & 0xFF); ushort cGreen = (ushort)((color >> 8) & 0xFF); ushort cBlue = (ushort)(color & 0xFF); layout.Attributes = new Pango.AttrList(); layout.Attributes.Insert(new Pango.AttrForeground(cRed, cGreen, cBlue)); layout.SetText(text); double x0; double y0; double scale = 1.0 / Pango.Scale.PangoScale; Pango.Rectangle dummy; Pango.Rectangle extents; layout.GetExtents(out dummy, out extents); switch ((TextAlign)((int)align & 7)) { case TextAlign.Right: x0 = x - scale * extents.Width; break; case TextAlign.Center: x0 = x - 0.5 * scale * extents.Width; break; default: x0 = x; break; } switch ((TextAlign)((int)align & ~7)) { case TextAlign.Top: y0 = y; break; case TextAlign.Bottom: y0 = y - scale * (metrics.Ascent + metrics.Descent); break; case TextAlign.VCenter: y0 = y - 0.5 * scale * metrics.Ascent; break; default: y0 = y - scale * metrics.Ascent; break; } Matrix srcM = Context.Matrix; Pango.Matrix dstM; dstM.X0 = 0.0; dstM.Xx = srcM.Xx; dstM.Xy = srcM.Xy; dstM.Y0 = 0.0; dstM.Yx = srcM.Yx; dstM.Yy = srcM.Yy; parent.PangoContext.Matrix = dstM; srcM.TransformPoint(ref x0, ref y0); parent.GdkWindow.DrawLayout(parent.Style.TextGC(StateType.Normal), (int)(0.5 + x0), (int)(0.5 + y0), layout); dstM.Xx = 1.0; dstM.Yy = 1.0; parent.PangoContext.Matrix = dstM; }