Пример #1
0
        /// <summary>
        /// Performs a deep clone of the TextEngine instance and returns the clone.
        /// </summary>
        /// <returns>A clone of this TextEngine instance.</returns>
        public TextEngine Clone()
        {
            TextEngine clonedTE = new TextEngine();

            clonedTE.layout   = layout.Copy();
            clonedTE.lines    = lines.ToList();
            clonedTE.textMode = textMode;
            clonedTE.linePos  = linePos;
            clonedTE.textPos  = textPos;
            clonedTE.selectionRelativeIndex = selectionRelativeIndex;
            clonedTE.underline = underline;
            clonedTE.Origin    = new Point(Origin.X, Origin.Y);

            //The rest of the variables are calculated on the spot.

            return(clonedTE);
        }
Пример #2
0
        private void EllipsizeLayout(int width)
        {
            // no room to draw anything
            if (width < 1)
            {
                layout.SetMarkup("");
                return;
            }

            // plenty of room
            int lw, lh;

            layout.GetPixelSize(out lw, out lh);
            if (width > lw)
            {
                return;
            }

            // not enough room for ...
            int ell_w, ell_h;

            Pango.Layout ell = layout.Copy();
            ell.SetMarkup("...");
            ell.GetPixelSize(out ell_w, out ell_h);
            if (width < ell_w)
            {
                layout.SetMarkup("");
                return;
            }

            // subtract ellipses width
            width -= ell_w;

            int index, trailing;

            Pango.LayoutLine line = layout.GetLine(0);
            if (line.XToIndex(width * 1024, out index, out trailing))
            {
                // Console.WriteLine ("length: {0} index: {1} trailing: {2}", layout.Text.Length, index, trailing);
                // FIXME: breaks on accented chars
                if (index < layout.Text.Length)
                {
                    layout.SetMarkup(layout.Text.Substring(0, index) + "...");
                }
            }
        }