Пример #1
0
            private void PrintWord(string word, Font font,
						bool ignore_split)
            {
                double width_required =
                    font.GetWidthUtf8 (word);
                Tag tag;

                // word fits in the line
                if ((curx + width_required) <
                    (marginx + width))
                  {
                      tag.word = word;
                      tag.font = font;
                      tag.width = width_required;
                      tags.Add (tag);
                      curx += width_required;
                      return;
                  }

                // this is a loooong word.
                if (width_required > width)
                  {
                      if (ignore_split)
                        {	// for tabs we dont need to split
                            FlushLine ();
                        }
                      else
                        {
                            string part, extra;
                            SplitWord (word, font,
                                   marginx +
                                   width - curx,
                                   out part,
                                   out extra);
                            tag.word = part;
                            tag.font = font;
                            tag.width =
                                font.
                                GetWidthUtf8
                                (part);
                            tags.Add (tag);
                            FlushLine ();
                            PrintWord (extra, font, ignore_split);	// recursive!
                        }
                      return;
                  }

                // the 'word' has to go to the next line
                FlushLine ();
                tag.word = word;
                tag.font = font;
                tag.width = width_required;
                curx += width_required;
                tags.Add (tag);
            }
Пример #2
0
            private void SplitWord(string word, Font font,
						double available_width,
						out string left,
						out string right)
            {
                double total_width = 0;
                for (int i = 0; i < word.Length; i++)
                  {
                      char ch = word[i];
                      double char_width =
                          font.GetWidthUtf8 ("" + ch);
                      total_width += char_width;
                      if (total_width > available_width)
                        {
                            left = word.Substring (0,
                                       i);
                            right = word.
                                Substring (i);
                            return;
                        }
                  }

                left = null;
                right = null;
            }