コード例 #1
0
ファイル: Table.cs プロジェクト: nholik/Fo.Net
        public override Status Layout(Area area)
        {
            if (this.marker == MarkerBreakAfter)
            {
                return new Status(Status.OK);
            }

            if (this.marker == MarkerStart)
            {
                AccessibilityProps mAccProps = propMgr.GetAccessibilityProps();
                AuralProps mAurProps = propMgr.GetAuralProps();
                BorderAndPadding bap = propMgr.GetBorderAndPadding();
                BackgroundProps bProps = propMgr.GetBackgroundProps();
                MarginProps mProps = propMgr.GetMarginProps();
                RelativePositionProps mRelProps = propMgr.GetRelativePositionProps();

                this.breakBefore = this.properties.GetProperty("break-before").GetEnum();
                this.breakAfter = this.properties.GetProperty("break-after").GetEnum();
                this.spaceBefore =
                    this.properties.GetProperty("space-before.optimum").GetLength().MValue();
                this.spaceAfter =
                    this.properties.GetProperty("space-after.optimum").GetLength().MValue();
                this.ipd =
                    this.properties.GetProperty("inline-progression-dimension").
                        GetLengthRange();
                this.height = this.properties.GetProperty("height").GetLength().MValue();
                this.bAutoLayout = (this.properties.GetProperty("table-layout").GetEnum() ==
                    TableLayout.AUTO);

                this.id = this.properties.GetProperty("id").GetString();

                this.omitHeaderAtBreak =
                    this.properties.GetProperty("table-omit-header-at-break").GetEnum()
                        == TableOmitHeaderAtBreak.TRUE;
                this.omitFooterAtBreak =
                    this.properties.GetProperty("table-omit-footer-at-break").GetEnum()
                        == TableOmitFooterAtBreak.TRUE;

                if (area is BlockArea)
                {
                    area.end();
                }
                if (this.areaContainer
                    == null)
                {
                    area.getIDReferences().CreateID(id);
                }

                this.marker = 0;

                if (breakBefore == BreakBefore.PAGE)
                {
                    return new Status(Status.FORCE_PAGE_BREAK);
                }

                if (breakBefore == BreakBefore.ODD_PAGE)
                {
                    return new Status(Status.FORCE_PAGE_BREAK_ODD);
                }

                if (breakBefore == BreakBefore.EVEN_PAGE)
                {
                    return new Status(Status.FORCE_PAGE_BREAK_EVEN);
                }

            }

            if ((spaceBefore != 0) && (this.marker == 0))
            {
                area.addDisplaySpace(spaceBefore);
            }

            if (marker == 0 && areaContainer == null)
            {
                area.getIDReferences().ConfigureID(id, area);
            }

            int spaceLeft = area.spaceLeft();
            this.areaContainer =
                new AreaContainer(propMgr.GetFontState(area.getFontInfo()), 0, 0,
                                  area.getAllocationWidth(), area.spaceLeft(),
                                  Position.STATIC);

            areaContainer.foCreator = this;
            areaContainer.setPage(area.getPage());
            areaContainer.setParent(area);
            areaContainer.setBackground(propMgr.GetBackgroundProps());
            areaContainer.setBorderAndPadding(propMgr.GetBorderAndPadding());
            areaContainer.start();

            areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
            areaContainer.setIDReferences(area.getIDReferences());

            bool addedHeader = false;
            bool addedFooter = false;
            int numChildren = this.children.Count;

            if (columns.Count == 0)
            {
                FindColumns(areaContainer);
                if (this.bAutoLayout)
                {
                    FonetDriver.ActiveDriver.FireFonetWarning(
                        "table-layout=auto is not supported, using fixed!");
                }
                this.contentWidth =
                    CalcFixedColumnWidths(areaContainer.getAllocationWidth());
            }
            areaContainer.setAllocationWidth(this.contentWidth);
            layoutColumns(areaContainer);

            for (int i = this.marker; i < numChildren; i++)
            {
                FONode fo = (FONode)children[i];
                if (fo is TableHeader)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return new Status(Status.OK);
                    }
                    tableHeader = (TableHeader)fo;
                    tableHeader.SetColumns(columns);
                }
                else if (fo is TableFooter)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return new Status(Status.OK);
                    }
                    tableFooter = (TableFooter)fo;
                    tableFooter.SetColumns(columns);
                }
                else if (fo is TableBody)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return new Status(Status.OK);
                    }
                    Status status;
                    if (tableHeader != null && !addedHeader)
                    {
                        if ((status =
                            tableHeader.Layout(areaContainer)).isIncomplete())
                        {
                            tableHeader.ResetMarker();
                            return new Status(Status.AREA_FULL_NONE);
                        }
                        addedHeader = true;
                        tableHeader.ResetMarker();
                        area.setMaxHeight(area.getMaxHeight() - spaceLeft
                            + this.areaContainer.getMaxHeight());
                    }
                    if (tableFooter != null && !this.omitFooterAtBreak
                        && !addedFooter)
                    {
                        if ((status =
                            tableFooter.Layout(areaContainer)).isIncomplete())
                        {
                            return new Status(Status.AREA_FULL_NONE);
                        }
                        addedFooter = true;
                        tableFooter.ResetMarker();
                    }
                    fo.SetWidows(widows);
                    fo.SetOrphans(orphans);
                    ((TableBody)fo).SetColumns(columns);

                    if ((status = fo.Layout(areaContainer)).isIncomplete())
                    {
                        this.marker = i;
                        if (bodyCount == 0
                            && status.getCode() == Status.AREA_FULL_NONE)
                        {
                            if (tableHeader != null)
                            {
                                tableHeader.RemoveLayout(areaContainer);
                            }
                            if (tableFooter != null)
                            {
                                tableFooter.RemoveLayout(areaContainer);
                            }
                            ResetMarker();
                        }
                        if (areaContainer.getContentHeight() > 0)
                        {
                            area.addChild(areaContainer);
                            area.increaseHeight(areaContainer.GetHeight());
                            if (this.omitHeaderAtBreak)
                            {
                                tableHeader = null;
                            }
                            if (tableFooter != null && !this.omitFooterAtBreak)
                            {
                                ((TableBody)fo).SetYPosition(tableFooter.GetYPosition());
                                tableFooter.SetYPosition(tableFooter.GetYPosition()
                                    + ((TableBody)fo).GetHeight());
                            }
                            SetupColumnHeights();
                            status = new Status(Status.AREA_FULL_SOME);
                        }
                        return status;
                    }
                    else
                    {
                        bodyCount++;
                    }
                    area.setMaxHeight(area.getMaxHeight() - spaceLeft
                        + this.areaContainer.getMaxHeight());
                    if (tableFooter != null && !this.omitFooterAtBreak)
                    {
                        ((TableBody)fo).SetYPosition(tableFooter.GetYPosition());
                        tableFooter.SetYPosition(tableFooter.GetYPosition()
                            + ((TableBody)fo).GetHeight());
                    }
                }
            }

            if (tableFooter != null && this.omitFooterAtBreak)
            {
                if (tableFooter.Layout(areaContainer).isIncomplete())
                {
                    FonetDriver.ActiveDriver.FireFonetWarning(
                        "Footer could not fit on page, moving last body row to next page");
                    area.addChild(areaContainer);
                    area.increaseHeight(areaContainer.GetHeight());
                    if (this.omitHeaderAtBreak)
                    {
                        tableHeader = null;
                    }
                    tableFooter.RemoveLayout(areaContainer);
                    tableFooter.ResetMarker();
                    return new Status(Status.AREA_FULL_SOME);
                }
            }

            if (height != 0)
            {
                areaContainer.SetHeight(height);
            }

            SetupColumnHeights();

            areaContainer.end();
            area.addChild(areaContainer);

            area.increaseHeight(areaContainer.GetHeight());

            if (spaceAfter != 0)
            {
                area.addDisplaySpace(spaceAfter);
            }

            if (area is BlockArea)
            {
                area.start();
            }

            if (breakAfter == BreakAfter.PAGE)
            {
                this.marker = MarkerBreakAfter;
                return new Status(Status.FORCE_PAGE_BREAK);
            }

            if (breakAfter == BreakAfter.ODD_PAGE)
            {
                this.marker = MarkerBreakAfter;
                return new Status(Status.FORCE_PAGE_BREAK_ODD);
            }

            if (breakAfter == BreakAfter.EVEN_PAGE)
            {
                this.marker = MarkerBreakAfter;
                return new Status(Status.FORCE_PAGE_BREAK_EVEN);
            }

            return new Status(Status.OK);
        }