Пример #1
0
 public static bool LayoutFootnote(Page p, FootnoteBody fb, Area area)
 {
     try
     {
         BodyAreaContainer bac = p.getBody();
         AreaContainer footArea = bac.getFootnoteReferenceArea();
         footArea.setIDReferences(bac.getIDReferences());
         int basePos = footArea.GetCurrentYPosition()
             - footArea.GetHeight();
         int oldHeight = footArea.GetHeight();
         if (area != null)
         {
             footArea.setMaxHeight(area.getMaxHeight() - area.GetHeight()
                 + footArea.GetHeight());
         }
         else
         {
             footArea.setMaxHeight(bac.getMaxHeight()
                 + footArea.GetHeight());
         }
         Status status = fb.Layout(footArea);
         if (status.isIncomplete())
         {
             return false;
         }
         else
         {
             if (area != null)
             {
                 area.setMaxHeight(area.getMaxHeight()
                     - footArea.GetHeight() + oldHeight);
             }
             if (bac.getFootnoteState() == 0)
             {
                 Area ar = bac.getMainReferenceArea();
                 DecreaseMaxHeight(ar, footArea.GetHeight() - oldHeight);
                 footArea.setYPosition(basePos + footArea.GetHeight());
             }
         }
     }
     catch (FonetException)
     {
         return false;
     }
     return true;
 }
Пример #2
0
 public virtual void setPage(Page page)
 {
     this.page = page;
 }
Пример #3
0
 public override void setPage(Page page)
 {
     this.page = page;
     foreach (AreaContainer ac in getChildren())
     {
         ac.setPage(page);
     }
 }
Пример #4
0
        /**
        * render page into PDF
        *
        * @param page page to render
        */

        public void RenderPage(Page page) {
            BodyAreaContainer body;
            AreaContainer before, after, start, end;

            currentStream = this.pdfDoc.makeContentStream();
            body = page.getBody();
            before = page.getBefore();
            after = page.getAfter();
            start = page.getStart();
            end = page.getEnd();

            this.currentFontName = "";
            this.currentFontSize = 0;
            this.currentLetterSpacing = Single.NaN;

            currentStream.Write("BT\n");

            RenderBodyAreaContainer(body);

            if (before != null) {
                RenderAreaContainer(before);
            }

            if (after != null) {
                RenderAreaContainer(after);
            }

            if (start != null) {
                RenderAreaContainer(start);
            }

            if (end != null) {
                RenderAreaContainer(end);
            }
            CloseText();

            // Bug fix for issue 1823
            this.currentLetterSpacing = Single.NaN;

            float w = page.getWidth();
            float h = page.GetHeight();
            currentStream.Write("ET\n");

            currentPage = this.pdfDoc.makePage(
                this.pdfResources, currentStream,
                Convert.ToInt32(Math.Round(w/1000)),
                Convert.ToInt32(Math.Round(h/1000)), page);

            if (page.hasLinks() || currentAnnotList != null) {
                if (currentAnnotList == null) {
                    currentAnnotList = this.pdfDoc.makeAnnotList();
                }
                currentPage.SetAnnotList(currentAnnotList);

                ArrayList lsets = page.getLinkSets();
                foreach (LinkSet linkSet in lsets) {
                    linkSet.align();
                    String dest = linkSet.getDest();
                    int linkType = linkSet.getLinkType();
                    ArrayList rsets = linkSet.getRects();
                    foreach (LinkedRectangle lrect in rsets) {
                        currentAnnotList.Add(this.pdfDoc.makeLink(lrect.getRectangle(),
                                                                  dest, linkType).GetReference());
                    }
                }
                currentAnnotList = null;
            }
            else {
                // just to be on the safe side
                currentAnnotList = null;
            }

            // ensures that color is properly reset for blocks that carry over pages
            this.currentFill = null;
        }
Пример #5
0
 public void Render(Page page) {
     this.idReferences = page.getIDReferences();
     this.pdfResources = this.pdfDoc.getResources();
     this.pdfDoc.setIDReferences(idReferences);
     this.RenderPage(page);
     this.pdfDoc.output();
 }
Пример #6
0
        public PdfPage makePage(PdfResources resources, PdfContentStream contents,
                                int pagewidth, int pageheight, Page currentPage)
        {
            PdfPage page = new PdfPage(
                resources, contents,
                pagewidth, pageheight,
                doc.NextObjectId());

            if (currentPage != null)
            {
                foreach (string id in currentPage.getIDList())
                {
                    idReferences.setInternalGoToPageReference(id, page.GetReference());
                }
            }

            /* add it to the list of objects */
            this.objects.Add(page);

            page.SetParent(doc.Pages);
            doc.Pages.Kids.Add(page.GetReference());

            return page;
        }
Пример #7
0
            public RenderQueueEntry(StreamRenderer outer, Page page)
            {
                this.outer = outer;
                this.page = page;

                foreach (object o in outer.idReferences.getInvalidElements())
                {
                    unresolvedIdReferences.Add(o);
                }
            }
Пример #8
0
        private void AddToRenderQueue(Page page)
        {
            RenderQueueEntry entry = new RenderQueueEntry(this, page);
            renderQueue.Add(entry);

            // The just-added entry could (possibly) resolve the waiting entries, 
            // so we try to process the queue now to see.
            ProcessQueue(false);
        }
Пример #9
0
        public void QueuePage(Page page)
        {
            // Process markers
            PageSequence pageSequence = page.getPageSequence();
            if (pageSequence != currentPageSequence)
            {
                currentPageSequence = pageSequence;
                currentPageSequenceMarkers = null;
            }
            ArrayList markers = page.getMarkers();
            if (markers != null)
            {
                if (documentMarkers == null)
                {
                    documentMarkers = new ArrayList();
                }
                if (currentPageSequenceMarkers == null)
                {
                    currentPageSequenceMarkers = new ArrayList();
                }
                for (int i = 0; i < markers.Count; i++)
                {
                    Marker marker = (Marker)markers[i];
                    marker.releaseRegistryArea();
                    currentPageSequenceMarkers.Add(marker);
                    documentMarkers.Add(marker);
                }
            }


            // Try to optimise on the common case that there are no pages pending 
            // and that all ID references are valid on the current pages. This 
            // short-cuts the pipeline and renders the area immediately.
            if ((renderQueue.Count == 0) && idReferences.IsEveryIdValid())
            {
                renderer.Render(page);
            }
            else
            {
                AddToRenderQueue(page);
            }

            pageCount++;
        }
Пример #10
0
        private Marker SearchPage(Page page)
        {
            ArrayList pageMarkers = page.getMarkers();
            if (pageMarkers.Count == 0)
            {
                return null;
            }

            if (retrievePosition == RetrievePosition.FIC)
            {
                for (int i = 0; i < pageMarkers.Count; i++)
                {
                    Marker currentMarker = (Marker)pageMarkers[i];
                    if (currentMarker.GetMarkerClassName().Equals(retrieveClassName))
                    {
                        return currentMarker;
                    }
                }
            }
            else if (retrievePosition == RetrievePosition.FSWP)
            {
                for (int c = 0; c < pageMarkers.Count; c++)
                {
                    Marker currentMarker = (Marker)pageMarkers[c];
                    if (currentMarker.GetMarkerClassName().Equals(retrieveClassName))
                    {
                        if (currentMarker.GetRegistryArea().isFirst())
                        {
                            return currentMarker;
                        }
                    }
                }
            }
            else if (retrievePosition == RetrievePosition.LSWP)
            {
                for (int c = pageMarkers.Count - 1; c >= 0; c--)
                {
                    Marker currentMarker = (Marker)pageMarkers[c];
                    if (currentMarker.GetMarkerClassName().Equals(retrieveClassName))
                    {
                        if (currentMarker.GetRegistryArea().isFirst())
                        {
                            return currentMarker;
                        }
                    }
                }

            }
            else if (retrievePosition == RetrievePosition.LEWP)
            {
                for (int c = pageMarkers.Count - 1; c >= 0; c--)
                {
                    Marker currentMarker = (Marker)pageMarkers[c];
                    if (currentMarker.GetMarkerClassName().Equals(retrieveClassName))
                    {
                        if (currentMarker.GetRegistryArea().isLast())
                        {
                            return currentMarker;
                        }
                    }
                }
            }
            else
            {
                throw new FonetException("Illegal 'retrieve-position' value");
            }
            return null;
        }
Пример #11
0
        private void ForcePage(AreaTree areaTree, int firstAvailPageNumber)
        {
            bool bmakePage = false;
            if (this.forcePageCount == ForcePageCount.AUTO)
            {
                PageSequence nextSequence =
                    this.root.getSucceedingPageSequence(this);
                if (nextSequence != null)
                {
                    if (nextSequence.IpnValue.Equals("auto"))
                    {
                        // do nothing
                    }
                    else if (nextSequence.IpnValue.Equals("auto-odd"))
                    {
                        if (firstAvailPageNumber % 2 == 0)
                        {
                            bmakePage = true;
                        }
                    }
                    else if (nextSequence.IpnValue.Equals("auto-even"))
                    {
                        if (firstAvailPageNumber % 2 != 0)
                        {
                            bmakePage = true;
                        }
                    }
                    else
                    {
                        int nextSequenceStartPageNumber =
                            nextSequence.CurrentPageNumber;
                        if ((nextSequenceStartPageNumber % 2 == 0)
                            && (firstAvailPageNumber % 2 == 0))
                        {
                            bmakePage = true;
                        }
                        else if ((nextSequenceStartPageNumber % 2 != 0)
                            && (firstAvailPageNumber % 2 != 0))
                        {
                            bmakePage = true;
                        }
                    }
                }
            }
            else if ((this.forcePageCount == ForcePageCount.EVEN)
                && (this.pageCount % 2 != 0))
            {
                bmakePage = true;
            }
            else if ((this.forcePageCount == ForcePageCount.ODD)
                && (this.pageCount % 2 == 0))
            {
                bmakePage = true;
            }
            else if ((this.forcePageCount == ForcePageCount.END_ON_EVEN)
                && (firstAvailPageNumber % 2 == 0))
            {
                bmakePage = true;
            }
            else if ((this.forcePageCount == ForcePageCount.END_ON_ODD)
                && (firstAvailPageNumber % 2 != 0))
            {
                bmakePage = true;
            }
            else if (this.forcePageCount == ForcePageCount.NO_FORCE)
            {
                // do nothing
            }

            if (bmakePage)
            {
                try
                {
                    this.isForcing = true;
                    this.currentPageNumber++;
                    firstAvailPageNumber = this.currentPageNumber;
                    currentPage = MakePage(areaTree, firstAvailPageNumber, false, true);
                    string formattedPageNumber =
                        pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
                    currentPage.setFormattedNumber(formattedPageNumber);
                    currentPage.setPageSequence(this);
                    FormatStaticContent(areaTree);

                    FonetDriver.ActiveDriver.FireFonetInfo(
                        "[forced-" + firstAvailPageNumber + "]");

                    areaTree.addPage(currentPage);
                    this.root.setRunningPageNumberCounter(this.currentPageNumber);
                    this.isForcing = false;
                }
                catch (FonetException)
                {
                    FonetDriver.ActiveDriver.FireFonetInfo(
                        "'force-page-count' failure");
                }
            }
        }
Пример #12
0
        public void Format(AreaTree areaTree)
        {
            Status status = new Status(Status.OK);

            this.layoutMasterSet.resetPageMasters();

            int firstAvailPageNumber = 0;
            do
            {
                firstAvailPageNumber = this.root.getRunningPageNumberCounter();
                bool tempIsFirstPage = false;

                if (thisIsFirstPage)
                {
                    tempIsFirstPage = thisIsFirstPage;
                    if (pageNumberType == AUTO)
                    {
                        this.currentPageNumber =
                            this.root.getRunningPageNumberCounter();
                    }
                    else if (pageNumberType == AUTO_ODD)
                    {
                        this.currentPageNumber =
                            this.root.getRunningPageNumberCounter();
                        if (this.currentPageNumber % 2 == 1)
                        {
                            this.currentPageNumber++;
                        }
                    }
                    else if (pageNumberType == AUTO_EVEN)
                    {
                        this.currentPageNumber =
                            this.root.getRunningPageNumberCounter();
                        if (this.currentPageNumber % 2 == 0)
                        {
                            this.currentPageNumber++;
                        }
                    }
                    thisIsFirstPage = false;
                }

                this.currentPageNumber++;
                bool isEmptyPage = false;

                if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN)
                    && ((currentPageNumber % 2) == 1))
                {
                    isEmptyPage = true;
                }
                else if ((status.getCode() == Status.FORCE_PAGE_BREAK_ODD)
                    && ((currentPageNumber % 2) == 0))
                {
                    isEmptyPage = true;
                }
                else
                {
                    isEmptyPage = false;
                }

                currentPage = MakePage(areaTree, firstAvailPageNumber,
                                       tempIsFirstPage, isEmptyPage);

                currentPage.setNumber(this.currentPageNumber);
                string formattedPageNumber =
                    pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
                currentPage.setFormattedNumber(formattedPageNumber);
                this.root.setRunningPageNumberCounter(this.currentPageNumber);

                FonetDriver.ActiveDriver.FireFonetInfo(
                    "[" + currentPageNumber + "]");

                if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN)
                    && ((currentPageNumber % 2) == 1)) { }
                else if ((status.getCode() == Status.FORCE_PAGE_BREAK_ODD)
                    && ((currentPageNumber % 2) == 0)) { }
                else
                {
                    BodyAreaContainer bodyArea = currentPage.getBody();
                    bodyArea.setIDReferences(areaTree.getIDReferences());

                    Flow.Flow flow = GetCurrentFlow(RegionBody.REGION_CLASS);

                    if (flow == null)
                    {
                        FonetDriver.ActiveDriver.FireFonetError(
                            "No flow found for region-body in page-master '" + currentPageMasterName + "'");
                        break;
                    }
                    else
                    {
                        status = flow.Layout(bodyArea);
                    }

                }

                currentPage.setPageSequence(this);
                FormatStaticContent(areaTree);

                areaTree.addPage(currentPage);
                this.pageCount++;
            } while (FlowsAreIncomplete());
            ForcePage(areaTree, firstAvailPageNumber);
            currentPage = null;
        }