Пример #1
0
        public static Measurement MeasureLine( ParagraphIterator begin, ParagraphIterator end )
        {
            var m = new Measurement();

            for ( ParagraphIterator i = begin ; i < end ; i.Next() ) {
                var run = i.Paragraph.Run(i.Run).Run;
                char ch = run.Text[i.Character];
                BitmapPage page = run.Font.BitmapPageForOrNul( ref ch );
                m = Measurement.Merge(m,m.Advance.X,0,page.Measurement);
            }

            return m;
        }
Пример #2
0
        public static string GetBackIterators(Paragraph paragraph)
        {
            ParagraphIterator iter = new ParagraphIterator(paragraph.Elements);
            iter = iter.GetLastLeaf();
            string retString = "";
            while (iter != null)
            {
                retString += "[" + iter.Current.GetType().Name + ":]";
                if (iter.Current is Text)
                    retString += ((Text)iter.Current).Content;

                iter = iter.GetPreviousLeaf();
            }
            return retString;
        }
        public static string GetBackIterators(Paragraph paragraph)
        {
            ParagraphIterator iter = new ParagraphIterator(paragraph.Elements);

            iter = iter.GetLastLeaf();
            string retString = "";

            while (iter != null)
            {
                retString += "[" + iter.Current.GetType().Name + ":]";
                if (iter.Current is Text)
                {
                    retString += ((Text)iter.Current).Content;
                }

                iter = iter.GetPreviousLeaf();
            }
            return(retString);
        }
Пример #4
0
        public static IEnumerable<TextRunLine> ToLines( Paragraph para, int maxwidth )
        {
            int length = para.Length;

            var start = new ParagraphIterator() { Paragraph = para };
            if ( !start.TryFindAdvance((ch)=>ch!=' ') ) yield break;

            var end = start;
            end.TryFindAdvance((ch)=>ch==' ');
            start.Rewind();

            for (;;) {
                bool createline = false;
                if ( end.Run >= para.Runs ) createline = true;

                if (!createline) {
                    var possibleend = end;
                    possibleend.TryFindAdvance((ch)=>ch!=' ');
                    possibleend.TryFindAdvance((ch)=>ch==' ');
                    if ( MeasureLine(start,possibleend).Bounds.Width > maxwidth ) {
                        createline = true;
                    } else {
                        end = possibleend;
                        continue;
                    }
                }

                if (createline) {
                    yield return new TextRunLine(start,end);
                    if ( end.Run >= para.Runs ) yield break;

                    start = end;
                    start.TryFindAdvance((ch)=>ch!=' ');
                    if ( start.Run >= para.Runs ) yield break;
                    end = start;
                    end.TryFindAdvance((ch)=>ch==' ');
                }
            }
        }