예제 #1
0
        public int CalculatePages(Cairo.Context cr)
        {
            _cr = cr;

            // Determine certain extents for all fonts for the current context.
            foreach (FontInfo font in _appSettings.Fonts)
            {
                font.SetExtents(_cr);
            }

            // Generate page nodes
            int      pageNumber  = 0;
            PageNode currentPage = CreateNewPage(pageNumber++);

            foreach (BaseNode line in _rawLineNodes)
            {
                if (line is CommandNode)
                {
                    CommandNode command = (CommandNode)line;
                    switch (command.CommandType)
                    {
                    case CommandType.NewPage:
                        currentPage = CreateNewPage(pageNumber++);
                        break;

                    case CommandType.BeginRegion:
                        currentPage.BeginRegion(command.RegionType);
                        break;

                    case CommandType.EndRegion:
                        currentPage.EndRegion();
                        break;
                    }
                }
                else
                {
                    if (!currentPage.TryAddLine(cr, line))
                    {
                        currentPage = CreateNewPage(pageNumber++);
                        currentPage.TryAddLine(cr, line);
                    }
                }
            }

            if (_renderOption == RenderOption.ScreenView)
            {
                //_displayHeightExtent = ((Y_DISPLAY_MARGIN + _paperHeight) * _pages.Count) + Y_DISPLAY_MARGIN;
                _displayHeightExtent = ((Constants.Y_DISPLAY_MARGIN + _paperHeight) * _pages.Count) + Constants.Y_DISPLAY_MARGIN;
                _displayWidthExtent  = (Constants.X_DISPLAY_MARGIN * 2) + _paperWidth;
            }

            // Now update the total count for each page to render their header/footer information
            foreach (PageNode page in _pages)
            {
                page.SetTotalPageCount(_pages.Count);
            }

            return(_pages.Count);
        }