Ejemplo n.º 1
0
        private List <string> WrapTextObject(TextObject obj)
        {
            float         FDpiFX = 96f / DrawUtils.ScreenDpi;
            List <string> result = new List <string>();
            DrawText      drawer = new DrawText();

            using (Bitmap b = new Bitmap(1, 1))
                using (Graphics g = Graphics.FromImage(b))
                    using (Font f = new Font(obj.Font.Name, obj.Font.Size * FDpiFX, obj.Font.Style))
                    {
                        float h         = f.Height - f.Height / 4;
                        float memoWidth = obj.Width - obj.Padding.Horizontal;

                        string text = obj.Text;

                        float memoHeight = drawer.CalcHeight(text, g, f,
                                                             memoWidth, obj.Height - obj.Padding.Vertical,
                                                             obj.HorzAlign, obj.LineHeight, obj.ForceJustify, obj.RightToLeft, obj.WordWrap, obj.Trimming);

                        float         y, prevy = 0;
                        StringBuilder line = new StringBuilder(256);
                        foreach (Paragraph par in drawer.Paragraphs)
                        {
                            foreach (Word word in par.Words)
                            {
                                if (!word.Visible)
                                {
                                    break;
                                }
                                y = word.Top + 1;
                                if (prevy == 0)
                                {
                                    prevy = y;
                                }
                                if (y != prevy)
                                {
                                    result.Add(line.ToString());
                                    line.Length = 0;
                                    prevy       = y;
                                }
                                line.Append(word.Text).Append(' ');
                            }
                        }
                        result.Add(line.ToString());
                    }
            return(result);
        }