示例#1
0
        public void SetHeight(object backend, double value)
        {
            LayoutBackend la = (LayoutBackend)backend;

            la.Heigth   = value;
            la.Measured = false;
        }
示例#2
0
        public void SetText(object backend, string text)
        {
            LayoutBackend la = (LayoutBackend)backend;

            la.Text     = text;
            la.Measured = false;
        }
示例#3
0
        public void SetFont(object backend, Font font)
        {
            LayoutBackend la = (LayoutBackend)backend;

            la.Measured = false;
            la.Font     = font;
        }
示例#4
0
        public void SetWidth(object backend, double value)
        {
            LayoutBackend la = (LayoutBackend)backend;

            la.Width    = value;
            la.Measured = false;
        }
示例#5
0
        public object Create(Context context)
        {
            CairoContextBackend c = (CairoContextBackend)WidgetRegistry.GetBackend(context);
            LayoutBackend       b = new LayoutBackend();

            b.Context = c;
            return(b);
        }
示例#6
0
        public object Create(ICanvasBackend canvas)
        {
            LayoutBackend       b  = new LayoutBackend();
            CairoContextBackend ba = new CairoContextBackend();

            ba.Context = SharedContext;
            b.Context  = ba;
            return(b);
        }
示例#7
0
        static Size Measure(object backend)
        {
            LayoutBackend la   = (LayoutBackend)backend;
            var           ctx  = la.Context.Context;
            var           text = la.Text;

            if (la.Font != null)
            {
                ctx.SelectFont(la.Font);
                ctx.SetFontSize(la.Font.Size);
            }

            if (la.Width == -1)
            {
                var te = ctx.TextExtents(text);
                return(new Size(te.Width, te.Height));
            }

            // Measure word by word

            double totalHeight   = 0;
            double currentWidth  = 0;
            double currentHeight = 0;

            la.LineBreaks.Clear();

            double spaceWidth   = ctx.TextExtents(" ").XAdvance;
            double spaceHeight  = ctx.FontExtents.Height;
            var    spaceExtents = new Cairo.TextExtents()
            {
                Width    = spaceWidth,
                Height   = spaceHeight,
                XAdvance = spaceWidth
            };

            int    pos         = 0;
            bool   inLineStart = true;
            int    prevPos     = 0;
            string word        = NextWord(text, ref pos);

            for (; word != null; prevPos = pos, word = NextWord(text, ref pos))
            {
                if (word.Length == 1 && word [0] == '\n')
                {
                    if (inLineStart)
                    {
                        // Empty line
                        currentHeight = spaceHeight;
                    }
                    totalHeight += currentHeight;
                    la.LineBreaks.Add(pos);
                    la.LineHeights.Add(currentHeight);
                    currentHeight = 0;
                    currentWidth  = 0;
                    inLineStart   = true;
                    continue;
                }

                inLineStart = false;
                bool isSpace = word.Length == 1 && word[0] == ' ';

                Cairo.TextExtents te;
                if (isSpace)
                {
                    te = spaceExtents;
                }
                else
                {
                    te = ctx.TextExtents(word);
                }

                if (currentWidth + te.Width > la.Width)
                {
                    la.LineHeights.Add(currentHeight);
                    la.LineBreaks.Add(isSpace ? pos : prevPos);                      // If a space causes a line break, we can ignore that space
                    totalHeight  += currentHeight;
                    currentHeight = te.Height;
                    if (isSpace)
                    {
                        currentWidth = 0;
                    }
                    else
                    {
                        currentWidth = te.Width;
                    }
                }
                else
                {
                    currentWidth += te.XAdvance;
                    if (te.Height > currentHeight)
                    {
                        currentHeight = te.Height;
                    }
                }
            }

            la.Measured = true;
            return(new Size(la.Width, totalHeight));
        }
示例#8
0
        public void SetTrimming(object backend, TextTrimming textTrimming)
        {
            LayoutBackend la = (LayoutBackend)backend;

            la.TextTrimming = textTrimming;
        }
 public override object Create(ICanvasBackend canvas)
 {
     LayoutBackend b = new LayoutBackend ();
     CairoContextBackend ba = new CairoContextBackend ();
     ba.Context = SharedContext;
     b.Context = ba;
     return b;
 }
示例#10
0
 public override object Create(Context context)
 {
     CairoContextBackend c = (CairoContextBackend) Toolkit.GetBackend (context);
     LayoutBackend b = new LayoutBackend ();
     b.Context = c;
     return b;
 }
 public object Create(Context context)
 {
     CairoContextBackend c = (CairoContextBackend) WidgetRegistry.GetBackend (context);
     LayoutBackend b = new LayoutBackend ();
     b.Context = c;
     return b;
 }