iTextSharp.text.pdf.PdfDiv.layout C# (CSharp) Метод

layout() публичный Метод

public layout ( ColumnText compositeColumn, bool simulate, float llx, float lly, float urx, float ury ) : int
compositeColumn ColumnText
simulate bool
llx float
lly float
urx float
ury float
Результат int
        public int layout(ColumnText compositeColumn, bool simulate, float llx, float lly, float urx, float ury)
        {
            float leftX = Math.Min(llx, urx);
            float maxY = Math.Max(lly, ury);
            float minY = Math.Min(lly, ury);
            float rightX = Math.Max(llx, urx);
            float yLine = maxY;
            bool contentCutByFixedHeight = false;

            if (width != null && width > 0) {
                if (width < rightX - leftX) {
                    rightX = leftX + (float)width;
                } else if (width > rightX - leftX) {
                    return ColumnText.NO_MORE_COLUMN;
                }
            } else if (percentageWidth != null) {
                contentWidth = (rightX - leftX) * (float)percentageWidth;
                rightX = leftX + contentWidth;
            }

            if (height != null && height > 0) {
                if (height < maxY - minY) {
                    contentCutByFixedHeight = true;
                    minY = maxY - (float)height;
                } else if (height > maxY - minY) {
                    return ColumnText.NO_MORE_COLUMN;
                }
            } else if (percentageHeight != null) {
                if (percentageHeight < 1.0) {
                    contentCutByFixedHeight = true;
                }
                contentHeight = (maxY - minY) * (float)percentageHeight;
                minY = maxY - contentHeight;
            }

            if (!simulate && position == PdfDiv.PositionType.RELATIVE) {
                float? translationX = null;
                if (left != null) {
                    translationX = left;
                } else if (right != null) {
                    translationX = -right;
                } else {
                    translationX = 0f;
                }

                float? translationY = null;
                if (top != null) {
                    translationY = -top;
                } else if (bottom != null) {
                    translationY = bottom;
                } else {
                    translationY = 0f;
                }
                compositeColumn.Canvas.SaveState();
                //compositeColumn.Canvas.Transform(new System.Drawing.Drawing2D.Matrix(1f, 0, 0, 1f, (float)translationX, (float)translationY));
            }

            if (!simulate) {
                if (backgroundColor != null && getActualWidth() > 0  && getActualHeight() > 0) {
                    float backgroundWidth = getActualWidth();
                    float backgroundHeight = getActualHeight();
                    if (width != null) {
                        backgroundWidth = width > 0 ? (float)width : 0;
                    }

                    if (height != null) {
                        backgroundHeight = height > 0 ? (float)height : 0;
                    }
                    if (backgroundWidth > 0 && backgroundHeight > 0) {
                        Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY);
                        background.BackgroundColor = backgroundColor;
                        compositeColumn.Canvas.Rectangle(background);
                    }
                }
            }

            if (percentageWidth == null) {
                contentWidth = 0;
            }
            if (percentageHeight == null) {
                contentHeight = 0;
            }

            minY += paddingBottom;
            leftX += paddingLeft;
            rightX -= paddingRight;

            yLine -= paddingTop;

            int status = ColumnText.NO_MORE_TEXT;

            if (content.Count > 0)
            {
                FloatLayout floatLay = null;
                if (this.floatLayout == null) {
                    List<IElement> floatingElements = new List<IElement>(content);
                    if (simulate){
                        floatLay = new FloatLayout(compositeColumn, floatingElements);
                    }
                    else{
                        floatLay = this.floatLayout = new FloatLayout(compositeColumn, floatingElements);
                    }
                }
                else{
                    if (simulate){
                        List<IElement> floatingElements = new List<IElement>(this.floatLayout.content);
                        floatLay = new FloatLayout(this.floatLayout.compositeColumn, floatingElements);
                    }
                    else
                    {
                        floatLay = this.floatLayout;
                    }
                }

                floatLay.SetSimpleColumn(leftX, minY, rightX, yLine);
                status = floatLay.layout(simulate);
                yLine = floatLay.getYLine();
                if (percentageWidth == null && contentWidth < floatLay.getFilledWidth()) {
                    contentWidth = floatLay.getFilledWidth();
                }
            }

            if (!simulate && position == PdfDiv.PositionType.RELATIVE) {
                compositeColumn.Canvas.RestoreState();
            }

            yLine -= paddingBottom;
            if (percentageHeight == null) {
                contentHeight = maxY - yLine;
            }

            if (percentageWidth == null) {
                contentWidth += paddingLeft + paddingRight;
            }

            return contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status;
        }

Usage Example

Пример #1
0
        public int layout(bool simulate)
        {
            int status = ColumnText.NO_MORE_TEXT;

            filledWidth = 0;

            List <IElement> floatingElements = new List <IElement>();

            while (content.Count > 0)
            {
                if (content[0] is PdfDiv)
                {
                    PdfDiv floatingElement = (PdfDiv)content[0];
                    if (floatingElement.Float == PdfDiv.FloatType.LEFT || floatingElement.Float == PdfDiv.FloatType.RIGHT)
                    {
                        floatingElements.Add(floatingElement);
                        content.RemoveAt(0);
                    }
                    else
                    {
                        if (floatingElements.Count > 0)
                        {
                            status = floatingLayout(floatingElements, simulate);
                            //if ((status & ColumnText.NO_MORE_TEXT) == 0) {
                            //    break;
                            //}
                        }

                        status = floatingElement.layout(compositeColumn, true, floatLeftX, minY, floatRightX, yLine);

                        if (!simulate)
                        {
                            status = floatingElement.layout(compositeColumn, simulate, floatLeftX, minY, floatRightX, yLine);
                        }

                        yLine -= floatingElement.getActualHeight();

                        if (floatingElement.getActualWidth() > filledWidth)
                        {
                            filledWidth = floatingElement.getActualWidth();
                        }
                        //if ((status & ColumnText.NO_MORE_TEXT) == 0) {
                        //    break;
                        //}
                        content.RemoveAt(0);
                    }
                }
                else
                {
                    floatingElements.Add(content[0]);
                    content.RemoveAt(0);
                }
            }

            if (/*(status & ColumnText.NO_MORE_TEXT) != 0 && */ floatingElements.Count > 0)
            {
                status = floatingLayout(floatingElements, simulate);
            }

            //foreach (IElement floatingElement in floatingElements) {
            //    content.Add(floatingElement);
            //}


            return(status);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfDiv::layout