public static Rectangle DrawTextBlock(this Context g, TextBlock tb, bool render) { double topBottomSpan = tb.Padding.Top + tb.Padding.Bottom; double leftRightSpan = tb.Padding.Left + tb.Padding.Right; double vertAlgSpan = 0; g.Save(); Pango.Layout layout = createLayoutFromTextBlock(g, tb); g.Color = tb.FontColor.ToCairoColor(); Pango.Rectangle unused; Pango.Rectangle te; layout.GetExtents(out unused, out te); double measuredHeight = te.Height / Pango.Scale.PangoScale; if (tb.VerticalAlignment != VerticalAlignment.Top) { vertAlgSpan = measureVerticlaSpan(tb, measuredHeight); } g.MoveTo(tb.Left + tb.Padding.Left, tb.Top + tb.Padding.Top + vertAlgSpan); if (render) { Pango.CairoHelper.ShowLayout(g, layout); } layout.GetExtents(out unused, out te); (layout as IDisposable).Dispose(); g.Restore(); return(new Rectangle(tb.Left - tb.Padding.Left + te.X / Pango.Scale.PangoScale, tb.Top - tb.Padding.Top + te.Y / Pango.Scale.PangoScale, (te.Width / Pango.Scale.PangoScale) + leftRightSpan, (te.Height / Pango.Scale.PangoScale) + topBottomSpan)); }
public static Rectangle DrawText(this Context g, PointD p, string family, Cairo.FontSlant slant, Cairo.FontWeight weight, double size, Cairo.Color color, double width, string text) { g.Save(); g.MoveTo(p.X, p.Y); g.Color = color; Pango.Layout layout = Pango.CairoHelper.CreateLayout(g); layout.Wrap = Pango.WrapMode.Char; layout.Width = (int)(width * Pango.Scale.PangoScale); Pango.FontDescription fd = new Pango.FontDescription(); fd.Family = family; fd.Style = CairoToPangoSlant(slant); fd.Weight = CairoToPangoWeight(weight); fd.AbsoluteSize = size * Pango.Scale.PangoScale; layout.FontDescription = fd; layout.Spacing = 0; layout.Alignment = Pango.Alignment.Left; layout.SetText(text); Pango.Rectangle unused = Pango.Rectangle.Zero; Pango.Rectangle te = Pango.Rectangle.Zero; layout.GetExtents(out unused, out te); Pango.CairoHelper.ShowLayout(g, layout); layout.GetExtents(out unused, out te); (layout as IDisposable).Dispose(); g.Restore(); return(new Rectangle(p.X + unused.X / Pango.Scale.PangoScale, p.Y + unused.Y / Pango.Scale.PangoScale, (unused.Width / Pango.Scale.PangoScale), (unused.Height / Pango.Scale.PangoScale))); }
internal int CalcWidth() { if (win.DataProvider.IconCount == 0) { return(0); } int longest = 0; string longestText = win.DataProvider.GetMarkup(0) ?? ""; for (int i = 1; i < win.DataProvider.IconCount; i++) { string curText = win.DataProvider.GetMarkup(i) ?? ""; if (curText.Length > longestText.Length) { longestText = curText; longest = i; } } layout.SetMarkup(win.DataProvider.GetMarkup(longest) ?? "<null>"); Pango.Rectangle inkRec, logRect; layout.GetExtents(out inkRec, out logRect); var icon = win.DataProvider.GetIcon(longest); int iconWidth = icon != null ? (int)icon.Width : 24; return(iconWidth + iconTextDistance + padding * 2 + leftXAlignment + (int)(inkRec.Width / Pango.Scale.PangoScale)); }
public static Rectangle DrawText(this Context g, PointD p, string family, FontSlant slant, FontWeight weight, double size, Color color, string text, bool antiAliasing) { g.Save(); g.MoveTo(p.X, p.Y); g.Color = color; g.Antialias = antiAliasing ? Antialias.Subpixel : Antialias.None; Pango.Layout layout = Pango.CairoHelper.CreateLayout(g); Pango.FontDescription fd = new Pango.FontDescription(); fd.Family = family; fd.Style = CairoToPangoSlant(slant); fd.Weight = CairoToPangoWeight(weight); fd.AbsoluteSize = size * Pango.Scale.PangoScale; layout.FontDescription = fd; layout.SetText(text); Pango.CairoHelper.ShowLayoutLine(g, layout.Lines[0]); Pango.Rectangle unused = Pango.Rectangle.Zero; Pango.Rectangle te = Pango.Rectangle.Zero; layout.GetExtents(out unused, out te); (layout as IDisposable).Dispose(); g.Restore(); return(new Rectangle(te.X, te.Y, te.Width, te.Height)); }
/// <summary> /// Gtk seems to have some trouble getting a wrapped label centered within /// the space allocated to it, at least in this context. This is a hack to /// get around the problem. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnLabel_Realized(object sender, EventArgs e) { ((sender as Label).Parent as VBox).Spacing = 0; Pango.Layout layout = (sender as Label).Layout; Pango.Rectangle ink; Pango.Rectangle logical; layout.GetExtents(out ink, out logical); (sender as Label).Xpad = ((layout.Width - logical.Width) / (int)Pango.Scale.PangoScale) / 2; }
private int ComputeFooterHeight(Gtk.PrintContext context) { using (Pango.Layout layout = CreateTimestampLayout(context)) { Pango.Rectangle ink_rect; Pango.Rectangle logical_rect; layout.GetExtents(out ink_rect, out logical_rect); // Compute the footer height, include the space for the horizontal line return(Pango.Units.ToPixels(ink_rect.Height) + CmToPixel(0.5, context.DpiY)); } }
public void GetExtents(out Pango.Rectangle ink_rect, out Pango.Rectangle logical_rect) { if (this.width >= 0) { ink_rect = logical_rect = new Pango.Rectangle { X = 0, Y = 0, Width = width, Height = height }; return; } layout.GetExtents(out ink_rect, out logical_rect); }
/// <summary> /// Get character index after which layout should be broken to not exceed maxHeight /// </summary> /// <returns> /// -1 if maxHeight is smaller than top padding. -2 if maxHeight is after text and character index if maxHeight is in the middle of the text. /// </returns> /// <param name='g'> /// G. /// </param> /// <param name='tb'> /// Tb. /// </param> /// <param name='maxHeight'> /// Max height. /// </param> public static int GetBreakLineCharacterIndexbyMaxHeight(this Context g, TextBlock tb, double maxHeight) { int result = 0; Pango.Rectangle unused; Pango.Rectangle te; double vertAlgSpan = 0; int chi = 0; int gi = 0; if (maxHeight > 0) { Pango.Layout layout = createLayoutFromTextBlock(g, tb); layout.GetExtents(out unused, out te); double measuredHeight = te.Height / Pango.Scale.PangoScale; if (tb.VerticalAlignment != VerticalAlignment.Top) { vertAlgSpan = measureVerticlaSpan(tb, measuredHeight); } double realTbStart = tb.Padding.Top + vertAlgSpan; if (realTbStart >= maxHeight) { result = -1; } else if (maxHeight > realTbStart + measuredHeight) { return(-2); } else { layout.XyToIndex(0, (int)((maxHeight - realTbStart) * Pango.Scale.PangoScale), out chi, out gi); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(tb.Text); int o = System.Text.Encoding.UTF8.GetCharCount(bytes, 0, chi); result = o; } (layout as IDisposable).Dispose(); } return(result); }
/// <summary> /// Gtk seems to have some trouble getting a wrapped label centered within /// the space allocated to it, at least in this context. This is a hack to /// get around the problem. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnLabel_Realized(object sender, EventArgs e) { try { if (sender is Label label && label.Parent is Box vbox) { vbox.Spacing = 0; Pango.Layout layout = label.Layout; Pango.Rectangle ink; Pango.Rectangle logical; layout.GetExtents(out ink, out logical); int xpad = ((layout.Width - logical.Width) / (int)Pango.Scale.PangoScale) / 2; if (xpad > 0) { label.Xpad = xpad; } } } catch (Exception err) { ShowError(err); } }
private void DrawString(PageText pt, Cairo.Context g, Cairo.Rectangle r) { StyleInfo si = pt.SI; string s = pt.Text; g.Save(); layout = Pango.CairoHelper.CreateLayout(g); // Font drawFont = null; // StringFormat drawFormat = null; // Brush drawBrush = null; // STYLE // System.Drawing.FontStyle fs = 0; // if (si.FontStyle == FontStyleEnum.Italic) // fs |= System.Drawing.FontStyle.Italic; //Pango fonts are scaled to 72dpi, Windows fonts uses 96dpi float fontsize = (si.FontSize * 72 / 96); var font = Pango.FontDescription.FromString(string.Format("{0} {1}", si.GetFontFamily().Name, fontsize * PixelsX(1))); if (si.FontStyle == FontStyleEnum.Italic) { font.Style = Pango.Style.Italic; } // // switch (si.TextDecoration) // { // case TextDecorationEnum.Underline: // fs |= System.Drawing.FontStyle.Underline; // break; // case TextDecorationEnum.LineThrough: // fs |= System.Drawing.FontStyle.Strikeout; // break; // case TextDecorationEnum.Overline: // case TextDecorationEnum.None: // break; // } // WEIGHT // switch (si.FontWeight) // { // case FontWeightEnum.Bold: // case FontWeightEnum.Bolder: // case FontWeightEnum.W500: // case FontWeightEnum.W600: // case FontWeightEnum.W700: // case FontWeightEnum.W800: // case FontWeightEnum.W900: // fs |= System.Drawing.FontStyle.Bold; // break; // default: // break; // } // try // { // drawFont = new Font(si.GetFontFamily(), si.FontSize, fs); // si.FontSize already in points // } // catch (ArgumentException) // { // drawFont = new Font("Arial", si.FontSize, fs); // if this fails we'll let the error pass thru // } //font.AbsoluteSize = (int)(PixelsX (si.FontSize)); switch (si.FontWeight) { case FontWeightEnum.Bold: case FontWeightEnum.Bolder: case FontWeightEnum.W500: case FontWeightEnum.W600: case FontWeightEnum.W700: case FontWeightEnum.W800: case FontWeightEnum.W900: font.Weight = Pango.Weight.Bold; break; } Pango.FontDescription oldfont = layout.FontDescription; layout.FontDescription = font; // ALIGNMENT // drawFormat = new StringFormat(); // switch (si.TextAlign) // { // case TextAlignEnum.Right: // drawFormat.Alignment = StringAlignment.Far; // break; // case TextAlignEnum.Center: // drawFormat.Alignment = StringAlignment.Center; // break; // case TextAlignEnum.Left: // default: // drawFormat.Alignment = StringAlignment.Near; // break; // } switch (si.TextAlign) { case TextAlignEnum.Right: layout.Alignment = Pango.Alignment.Right; break; case TextAlignEnum.Center: layout.Alignment = Pango.Alignment.Center; break; case TextAlignEnum.Left: default: layout.Alignment = Pango.Alignment.Left; break; } layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2)); // layout.Width = (int)Pango.Units.FromPixels((int)r.Width); layout.SetText(s); // if (pt.SI.WritingMode == WritingModeEnum.tb_rl) // { // drawFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; // drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical; // } // switch (si.VerticalAlign) // { // case VerticalAlignEnum.Bottom: // drawFormat.LineAlignment = StringAlignment.Far; // break; // case VerticalAlignEnum.Middle: // drawFormat.LineAlignment = StringAlignment.Center; // break; // case VerticalAlignEnum.Top: // default: // drawFormat.LineAlignment = StringAlignment.Near; // break; // } // Pango.Rectangle logical; Pango.Rectangle ink; layout.GetExtents(out ink, out logical); double height = logical.Height / Pango.Scale.PangoScale; double y = 0; switch (si.VerticalAlign) { case VerticalAlignEnum.Top: y = r.Y + si.PaddingTop; break; case VerticalAlignEnum.Middle: y = r.Y + (r.Height - height) / 2; break; case VerticalAlignEnum.Bottom: y = r.Y + (r.Height - height) - si.PaddingBottom; break; } // draw the background DrawBackground(g, r, si); // adjust drawing rectangle based on padding // Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + si.PaddingLeft, // r.Y + si.PaddingTop, // r.Width - si.PaddingLeft - si.PaddingRight, // r.Height - si.PaddingTop - si.PaddingBottom); Cairo.Rectangle box = new Cairo.Rectangle( r.X + si.PaddingLeft + 1, y, r.Width, r.Height); //drawBrush = new SolidBrush(si.Color); g.Color = si.Color.ToCairoColor(); // if (pt.NoClip) // request not to clip text // { // g.DrawString(pt.Text, drawFont, drawBrush, new PointF(r.Left, r.Top), drawFormat); // //HighlightString(g, pt, new RectangleF(r.Left, r.Top, float.MaxValue, float.MaxValue),drawFont, drawFormat); // } // else // { // g.DrawString(pt.Text, drawFont, drawBrush, r2, drawFormat); // //HighlightString(g, pt, r2, drawFont, drawFormat); // } g.MoveTo(box.X, box.Y); Pango.CairoHelper.ShowLayout(g, layout); layout.FontDescription = oldfont; g.Restore(); }
public void OnDrawPage(object sender, Gtk.DrawPageArgs args) { using (Cairo.Context cr = args.Context.CairoContext) { cr.MoveTo(margin_left, margin_top); PageBreak start; if (args.PageNr == 0) { start = new PageBreak(0, 0); } else { start = page_breaks [args.PageNr - 1]; } PageBreak end; if (args.PageNr < page_breaks.Count) { end = page_breaks [args.PageNr]; } else { end = new PageBreak(-1, -1); } Gtk.PrintContext context = args.Context; Gtk.TextIter position; Gtk.TextIter end_iter; Buffer.GetBounds(out position, out end_iter); // Fast-forward to the right starting paragraph while (position.Line < start.Paragraph) { position.ForwardLine(); } bool done = position.Compare(end_iter) >= 0; while (!done) { Gtk.TextIter line_end = position; if (!line_end.EndsLine()) { line_end.ForwardToLineEnd(); } int paragraph_number = position.Line; int indentation; using (Pango.Layout layout = CreateParagraphLayout( context, position, line_end, out indentation)) { for (int line_number = 0; line_number < layout.LineCount && !done; line_number++) { // Skip the lines up to the starting line in the // first paragraph on this page if ((paragraph_number == start.Paragraph) && (line_number < start.Line)) { continue; } // Break as soon as we hit the end line if ((paragraph_number == end.Paragraph) && (line_number == end.Line)) { done = true; break; } Pango.LayoutLine line = layout.Lines [line_number]; Pango.Rectangle ink_rect = Pango.Rectangle.Zero; Pango.Rectangle logical_rect = Pango.Rectangle.Zero; line.GetExtents(ref ink_rect, ref logical_rect); cr.MoveTo(margin_left + indentation, cr.CurrentPoint.Y); int line_height = Pango.Units.ToPixels(logical_rect.Height); Cairo.PointD new_line_point = new Cairo.PointD( margin_left + indentation, cr.CurrentPoint.Y + line_height); Pango.CairoHelper.ShowLayoutLine(cr, line); cr.MoveTo(new_line_point); } } position.ForwardLine(); done = done || position.Compare(end_iter) >= 0; } int total_height = (int)args.Context.Height; int total_width = (int)args.Context.Width; int footer_height = 0; Cairo.PointD footer_anchor; using (Pango.Layout pages_footer = CreatePagenumbersLayout( args.Context, args.PageNr + 1, page_breaks.Count + 1)) { Pango.Rectangle ink_footer_rect; Pango.Rectangle logical_footer_rect; pages_footer.GetExtents(out ink_footer_rect, out logical_footer_rect); footer_anchor = new Cairo.PointD( CmToPixel(0.5, args.Context.DpiX), total_height - margin_bottom); footer_height = Pango.Units.ToPixels(logical_footer_rect.Height); cr.MoveTo( total_width - Pango.Units.ToPixels(logical_footer_rect.Width) - CmToPixel(0.5, args.Context.DpiX), footer_anchor.Y); Pango.CairoHelper.ShowLayoutLine(cr, pages_footer.Lines [0]); } cr.MoveTo(footer_anchor); Pango.CairoHelper.ShowLayoutLine(cr, timestamp_footer.Lines [0]); cr.MoveTo(CmToPixel(0.5, args.Context.DpiX), total_height - margin_bottom - footer_height); cr.LineTo(total_width - CmToPixel(0.5, args.Context.DpiX), total_height - margin_bottom - footer_height); cr.Stroke(); } }
private void DrawString(PageText pt, Cairo.Context g, Cairo.Rectangle r) { StyleInfo si = pt.SI; string s = pt.Text; g.Save(); layout = Pango.CairoHelper.CreateLayout(g); // Font drawFont = null; // StringFormat drawFormat = null; // Brush drawBrush = null; // STYLE // System.Drawing.FontStyle fs = 0; // if (si.FontStyle == FontStyleEnum.Italic) // fs |= System.Drawing.FontStyle.Italic; //Pango fonts are scaled to 72dpi, Windows fonts uses 96dpi float fontsize = (si.FontSize * 72 / 96); var font = Pango.FontDescription.FromString(string.Format("{0} {1}", si.GetFontFamily().Name, fontsize * PixelsX(1))); if (si.FontStyle == FontStyleEnum.Italic) font.Style = Pango.Style.Italic; // // switch (si.TextDecoration) // { // case TextDecorationEnum.Underline: // fs |= System.Drawing.FontStyle.Underline; // break; // case TextDecorationEnum.LineThrough: // fs |= System.Drawing.FontStyle.Strikeout; // break; // case TextDecorationEnum.Overline: // case TextDecorationEnum.None: // break; // } // WEIGHT // switch (si.FontWeight) // { // case FontWeightEnum.Bold: // case FontWeightEnum.Bolder: // case FontWeightEnum.W500: // case FontWeightEnum.W600: // case FontWeightEnum.W700: // case FontWeightEnum.W800: // case FontWeightEnum.W900: // fs |= System.Drawing.FontStyle.Bold; // break; // default: // break; // } // try // { // drawFont = new Font(si.GetFontFamily(), si.FontSize, fs); // si.FontSize already in points // } // catch (ArgumentException) // { // drawFont = new Font("Arial", si.FontSize, fs); // if this fails we'll let the error pass thru // } //font.AbsoluteSize = (int)(PixelsX (si.FontSize)); switch (si.FontWeight) { case FontWeightEnum.Bold: case FontWeightEnum.Bolder: case FontWeightEnum.W500: case FontWeightEnum.W600: case FontWeightEnum.W700: case FontWeightEnum.W800: case FontWeightEnum.W900: font.Weight = Pango.Weight.Bold; break; } Pango.FontDescription oldfont = layout.FontDescription; layout.FontDescription = font; // ALIGNMENT // drawFormat = new StringFormat(); // switch (si.TextAlign) // { // case TextAlignEnum.Right: // drawFormat.Alignment = StringAlignment.Far; // break; // case TextAlignEnum.Center: // drawFormat.Alignment = StringAlignment.Center; // break; // case TextAlignEnum.Left: // default: // drawFormat.Alignment = StringAlignment.Near; // break; // } switch (si.TextAlign) { case TextAlignEnum.Right: layout.Alignment = Pango.Alignment.Right; break; case TextAlignEnum.Center: layout.Alignment = Pango.Alignment.Center; break; case TextAlignEnum.Left: default: layout.Alignment = Pango.Alignment.Left; break; } layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2)); // layout.Width = (int)Pango.Units.FromPixels((int)r.Width); layout.SetText(s); // if (pt.SI.WritingMode == WritingModeEnum.tb_rl) // { // drawFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; // drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical; // } // switch (si.VerticalAlign) // { // case VerticalAlignEnum.Bottom: // drawFormat.LineAlignment = StringAlignment.Far; // break; // case VerticalAlignEnum.Middle: // drawFormat.LineAlignment = StringAlignment.Center; // break; // case VerticalAlignEnum.Top: // default: // drawFormat.LineAlignment = StringAlignment.Near; // break; // } // Pango.Rectangle logical; Pango.Rectangle ink; layout.GetExtents(out ink, out logical); double height = logical.Height / Pango.Scale.PangoScale; double y = 0; switch (si.VerticalAlign) { case VerticalAlignEnum.Top: y = r.Y + si.PaddingTop; break; case VerticalAlignEnum.Middle: y = r.Y + (r.Height - height) / 2; break; case VerticalAlignEnum.Bottom: y = r.Y + (r.Height - height) - si.PaddingBottom; break; } // draw the background DrawBackground(g, r, si); // adjust drawing rectangle based on padding // Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + si.PaddingLeft, // r.Y + si.PaddingTop, // r.Width - si.PaddingLeft - si.PaddingRight, // r.Height - si.PaddingTop - si.PaddingBottom); Cairo.Rectangle box = new Cairo.Rectangle( r.X + si.PaddingLeft + 1, y, r.Width, r.Height); //drawBrush = new SolidBrush(si.Color); g.Color = si.Color.ToCairoColor(); // if (pt.NoClip) // request not to clip text // { // g.DrawString(pt.Text, drawFont, drawBrush, new PointF(r.Left, r.Top), drawFormat); // //HighlightString(g, pt, new RectangleF(r.Left, r.Top, float.MaxValue, float.MaxValue),drawFont, drawFormat); // } // else // { // g.DrawString(pt.Text, drawFont, drawBrush, r2, drawFormat); // //HighlightString(g, pt, r2, drawFont, drawFormat); // } g.MoveTo(box.X, box.Y); Pango.CairoHelper.ShowLayout(g, layout); layout.FontDescription = oldfont; g.Restore(); }
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; }
public void GetExtents(out Pango.Rectangle ink_rect, out Pango.Rectangle logical_rect) { layout.GetExtents(out ink_rect, out logical_rect); }
protected override void PaintWidget(Cairo.Context ctx, int w, int h) { ctx.SetFill(0.0d, 0.0d, 0.0d); ctx.Rectangle(0.0d, Offset, w, h - Offset); ctx.Fill(); ctx.SetFill(BlueprintStyle.BluePrint); ctx.Rectangle(0.0d, 0.0d, w, Offset); ctx.Fill(); double wr = w - 2.0d * Offset; double ew = wr / (max - min + 1 + shaft * (max - min)); this.flapWidth = ew; double xc = Offset; for (int i = min; i <= max; i++) { if (i != current) { ctx.Rectangle(xc, Offset, ew, h - 2.0d * Offset); } xc += (1.0d + shaft) * ew; } ctx.FillPreserve(); LinearGradient p = new LinearGradient(0.0d, Offset, 0.0d, Offset + 10.0d); double fctr = 0.5d; for (double y = 0.0d; y <= 1.0d; y += 0.1d) { p.AddColorStopRgb(y, new Color(fctr * BlueprintStyle.BluePrintShadow.R, fctr * BlueprintStyle.BluePrintShadow.G, fctr * BlueprintStyle.BluePrintShadow.B)); fctr += 0.05d; } ctx.SetFill(p); ctx.Fill(); ctx.Rectangle(Offset + (1.0d + shaft) * ew * (current - min), Offset, ew, h - 2.0d * Offset); ctx.SetFill(BlueprintStyle.BluePrint); ctx.Fill(); xc = Offset; ctx.SetFill(BlueprintStyle.HardWhite); ctx.MoveTo(0.0d, Offset); ctx.LineTo(Offset, Offset); for (int i = min; i <= max; i++) { ctx.LineTo(xc, h - Offset); ctx.LineTo(xc + ew, h - Offset); ctx.LineTo(xc + ew, Offset); xc += (1.0d + shaft) * ew; if (i < max) { ctx.LineTo(xc, Offset); } } ctx.LineTo(w - Offset, Offset); ctx.LineTo(w, Offset); ctx.MoveTo(Offset, Offset); ctx.LineTo(Offset + (1.0d + shaft) * ew * (current - min), Offset); ctx.MoveTo(w - Offset, Offset); ctx.LineTo(w - Offset + (1.0d + shaft) * ew * (current - max), Offset); ctx.Stroke(); xc = Offset + 0.5d * ew; IEnumerable <string> namei = this.names.Skip(this.min); IEnumerator <string> enume = namei.GetEnumerator(); for (int i = min; i <= max && enume.MoveNext(); i++) { string name = enume.Current; if (name != null) { #if PANGO Pango.Layout pglay = Pango.CairoHelper.CreateLayout(ctx); pglay.SetText(name); Pango.Rectangle ra, rb; pglay.GetExtents(out ra, out rb); double tew = rb.Width / 1024.0d; double teh = rb.Height / 1024.0d; #else TextExtents te = ctx.TextExtents(name); double tew = te.Width; double teh = te.Height; #endif ctx.MoveTo(xc - 0.5d * tew, 0.5d * (h + teh)); ctx.ShowText(name); xc += (1.0d + shaft) * ew; } } }