コード例 #1
0
 public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
 {
     Pango.Layout pl = (Pango.Layout)WidgetRegistry.GetBackend (layout);
     CairoContextBackend ctx = (CairoContextBackend)backend;
     ctx.Context.MoveTo (x, y);
     if (layout.Height <= 0) {
         Pango.CairoHelper.ShowLayout (ctx.Context, pl);
     } else {
         var lc = pl.LineCount;
         var scale = Pango.Scale.PangoScale;
         double h = 0;
         for (int i=0; i<lc; i++) {
             var line = pl.Lines [i];
             var ext = new Pango.Rectangle ();
             var extl = new Pango.Rectangle ();
             line.GetExtents (ref ext, ref extl);
             h += (extl.Height / scale);
             if (h > layout.Height)
                 break;
             ctx.Context.MoveTo (x, y + h);
             Pango.CairoHelper.ShowLayoutLine (ctx.Context, line);
         }
     }
 }
コード例 #2
0
 public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
 {
     var be = (GtkTextLayoutBackendHandler.PangoBackend)Toolkit.GetBackend (layout);
     var pl = be.Layout;
     CairoContextBackend ctx = (CairoContextBackend)backend;
     ctx.Context.MoveTo (x, y);
     if (layout.Height <= 0) {
         Pango.CairoHelper.ShowLayout (ctx.Context, pl);
     } else {
         var lc = pl.LineCount;
         var scale = Pango.Scale.PangoScale;
         double h = 0;
         var fe = ctx.Context.FontExtents;
         var baseline = fe.Ascent / (fe.Ascent + fe.Descent);
         for (int i=0; i<lc; i++) {
             var line = pl.Lines [i];
             var ext = new Pango.Rectangle ();
             var extl = new Pango.Rectangle ();
             line.GetExtents (ref ext, ref extl);
             h += h == 0 ? (extl.Height / scale * baseline) : (extl.Height / scale);
             if (h > layout.Height)
                 break;
             ctx.Context.MoveTo (x, y + h);
             Pango.CairoHelper.ShowLayoutLine (ctx.Context, line);
         }
     }
 }
コード例 #3
0
        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 inkRect1;
            Pango.Rectangle logicalRect;
            layout.GetExtents (out inkRect1, out logicalRect);
            double measuredHeight = (logicalRect.Height) / (Pango.Scale.PangoScale * UnitMultiplier);
            double measuredY = logicalRect.Y / (Pango.Scale.PangoScale * UnitMultiplier);

            if(tb.VerticalAlignment != VerticalAlignment.Top)
                vertAlgSpan = measureVerticlaSpan(tb,measuredHeight);

            g.MoveTo ((tb.Left + tb.Padding.Left) * UnitMultiplier, (tb.Top + tb.Padding.Top + vertAlgSpan - measuredY) * UnitMultiplier);

            if (render) {
                Pango.CairoHelper.ShowLayout(g, layout);
            }

            layout.GetExtents (out inkRect1, out logicalRect);
            measuredHeight = (logicalRect.Height) / (Pango.Scale.PangoScale * UnitMultiplier);
            double measuredWidth = logicalRect.Width / (Pango.Scale.PangoScale * UnitMultiplier);
            measuredY = logicalRect.Y / (Pango.Scale.PangoScale * UnitMultiplier);

            if ( DebugTextBlock && render ) {

                Pango.Rectangle  inklineRect = new Pango.Rectangle();
                Pango.Rectangle logLineRect = new Pango.Rectangle();

                {
                    double span = measuredY;
                    for(int d = 0 ; d < layout.LinesReadOnly.Length;d++){
                        var item = layout.LinesReadOnly[d];

                    item.GetExtents(ref inklineRect,ref logLineRect);
                    //seems like when measuring line logLineRect.Y is not needed but i don't know why
                    double h = ((logLineRect.Height / Pango.Scale.PangoScale));
                    double x = ((tb.Left + tb.Padding.Left) * UnitMultiplier + (logLineRect.X / Pango.Scale.PangoScale));
                    double y = (tb.Top + tb.Padding.Top) * UnitMultiplier  + span;
                    DrawDebugRect(g,
                        new Cairo.Rectangle(
                         x, y,
                        ((logLineRect.Width / Pango.Scale.PangoScale)) ,
                        h
                        ));

                        span += h;
                    }
                }
            }

            (layout as IDisposable).Dispose();
            g.Restore ();
            return new Rectangle( tb.Left , tb.Top, measuredWidth + leftRightSpan , measuredHeight + topBottomSpan);
        }
コード例 #4
0
ファイル: LayoutCache.cs プロジェクト: kdubau/monodevelop
			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); 
			}