Example #1
0
        private static XStringFormat CreateStringFormat(XStringAlignment alignment, XLineAlignment lineAlignment)
        {
            XStringFormat format = new XStringFormat();

            format.Alignment     = alignment;
            format.LineAlignment = lineAlignment;
            return(format);
        }
Example #2
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The text brush.</param>
        /// <param name="layoutRectangle">The layout rectangle.</param>
        /// <param name="format">The format. Must be <c>XStringFormat.TopLeft</c></param>
        public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }
            if (format.Alignment != XStringAlignment.Near)
            {
                throw new ArgumentException("Only Left alignments are currently implemented.");
            }
            _lineAlignment = format.LineAlignment;

            Text            = text;
            Font            = font;
            LayoutRectangle = layoutRectangle;

            if (text.Length == 0)
            {
                return;
            }

            CreateBlocks();

            CreateLayout();

            double dx    = layoutRectangle.Location.X;
            double dy    = layoutRectangle.Location.Y + _cyAscent;
            int    count = _blocks.Count;

            for (int idx = 0; idx < count; idx++)
            {
                Block block = _blocks[idx];
                if (block.Stop)
                {
                    break;
                }
                if (block.Type == BlockType.LineBreak)
                {
                    continue;
                }
                _gfx.DrawString(block.Text, font, brush, dx + block.Location.X, dy + block.Location.Y, format);
            }
        }
Example #3
0
 private static XStringFormat CreateStringFormat(XStringAlignment alignment, XLineAlignment lineAlignment)
 {
     XStringFormat format = new XStringFormat();
     format.Alignment = alignment;
     format.LineAlignment = lineAlignment;
     return format;
 }