protected internal override IRenderer CreateFlatRenderer()
        {
            AbstractSelectField   selectField = (AbstractSelectField)modelElement;
            IList <IBlockElement> options     = selectField.GetOptions();
            Div optionsContainer = new Div();

            foreach (IBlockElement option in options)
            {
                optionsContainer.Add(option);
            }
            IRenderer rendererSubTree;

            if (optionsContainer.GetChildren().IsEmpty())
            {
                Paragraph pStub = new Paragraph("\u00A0").SetMargin(0);
                pStub.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
                pStub.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
                pStub.SetProperty(Html2PdfProperty.FORM_FIELD_SELECTED, false);
                // applying this property for the sake of finding this element as option
                optionsContainer.Add(pStub);
                rendererSubTree = optionsContainer.CreateRendererSubTree();
            }
            else
            {
                rendererSubTree = optionsContainer.CreateRendererSubTree();
                IList <IRenderer> selectedOptions = GetSelectedOptions(rendererSubTree);
                foreach (IRenderer selectedOption in selectedOptions)
                {
                    ApplySelectedStyle(selectedOption);
                }
            }
            return(rendererSubTree);
        }
示例#2
0
        // TODO DEVSIX-1901
        private IRenderer CreateFlatRenderer(bool addAllOptionsToChildren)
        {
            AbstractSelectField   selectField = (AbstractSelectField)modelElement;
            IList <IBlockElement> options     = selectField.GetOptions();
            Div pseudoContainer = new Div();

            foreach (IBlockElement option in options)
            {
                pseudoContainer.Add(option);
            }
            IList <Paragraph> allOptions;
            IRenderer         pseudoRendererSubTree = pseudoContainer.CreateRendererSubTree();

            if (addAllOptionsToChildren)
            {
                allOptions = GetAllOptionsFlatElements(pseudoRendererSubTree);
            }
            else
            {
                allOptions = GetSingleSelectedOptionFlatRenderer(pseudoRendererSubTree);
            }
            if (allOptions.IsEmpty())
            {
                allOptions.Add(CreateComboBoxOptionFlatElement());
            }
            pseudoContainer.GetChildren().Clear();
            foreach (Paragraph option in allOptions)
            {
                pseudoContainer.Add(option);
            }
            AccessiblePropHelper.TrySetLangAttribute(pseudoContainer, GetLang());
            IRenderer rendererSubTree = pseudoContainer.CreateRendererSubTree();

            return(rendererSubTree);
        }
示例#3
0
        public virtual void MultipleDivTest()
        {
            String      outFileName = destinationFolder + "multipleDivTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_multipleDivTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDocument);

            Border[] borders = new Border[] { new SolidBorder(ColorConstants.BLUE, 2f), new SolidBorder(ColorConstants
                                                                                                        .RED, 2f), new SolidBorder(ColorConstants.GREEN, 2f) };
            Div externalDiv = new Div().SetPadding(2f).SetBorder(borders[2]);
            Div curr        = externalDiv;

            for (int i = 0; i < 100; ++i)
            {
                Div d = new Div().SetBorder(borders[i % 3]);
                curr.Add(d);
                curr = d;
            }
            String    str = "Hello. I am a fairly long paragraph. I really want you to process me correctly. You heard that? Correctly!!! Even if you will have to wrap me.";
            Paragraph p   = new Paragraph(new Text(str)).SetPadding(1f).SetBorder(new SolidBorder(ColorConstants.BLACK,
                                                                                                  2)).SetMargin(3).SetBackgroundColor(ColorConstants.LIGHT_GRAY);

            curr.Add(p);
            MinMaxWidth result = ((AbstractRenderer)externalDiv.CreateRendererSubTree().SetParent(doc.GetRenderer())).
                                 GetMinMaxWidth();

            externalDiv.SetWidth(ToEffectiveWidth(externalDiv, result.GetMinWidth()));
            doc.Add(externalDiv);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
示例#4
0
        public virtual void DivWithRotatedPercentImage()
        {
            String          outFileName  = destinationFolder + "divRotatedPercentImage.pdf";
            String          cmpFileName  = sourceFolder + "cmp_divRotatedPercentImage.pdf";
            PdfDocument     pdfDocument  = new PdfDocument(new PdfWriter(outFileName));
            Document        doc          = new Document(pdfDocument);
            PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "itis.jpg"));

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(imageXObject).SetRotationAngle(Math.PI * 3
                                                                                                           / 8);
            Div d = new Div().Add(img).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f)).SetMarginBottom(10);

            iText.Layout.Element.Image imgPercent = new iText.Layout.Element.Image(imageXObject).SetWidth(UnitValue.CreatePercentValue
                                                                                                              (50)).SetRotationAngle(Math.PI * 3 / 8);
            Div         dPercent = new Div().Add(imgPercent).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f));
            MinMaxWidth result   = ((AbstractRenderer)d.CreateRendererSubTree().SetParent(doc.GetRenderer())).GetMinMaxWidth
                                       ();

            d.SetWidth(ToEffectiveWidth(d, result.GetMinWidth()));
            MinMaxWidth resultPercent = ((AbstractRenderer)dPercent.CreateRendererSubTree().SetParent(doc.GetRenderer(
                                                                                                          ))).GetMinMaxWidth();

            dPercent.SetWidth(ToEffectiveWidth(dPercent, resultPercent.GetMaxWidth()));
            doc.Add(d);
            doc.Add(dPercent);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        public virtual void InlineBlockWithBigMinWidth01()
        {
            Document     dummyDocument       = CreateDocument();
            LineRenderer lineRenderer        = (LineRenderer) new LineRenderer().SetParent(dummyDocument.GetRenderer());
            Div          div                 = new Div().SetMinWidth(2000).SetHeight(100);
            DivRenderer  inlineBlockRenderer = (DivRenderer)div.CreateRendererSubTree();

            lineRenderer.AddChild(inlineBlockRenderer);
            LayoutResult result = lineRenderer.Layout(new LayoutContext(CreateLayoutArea(1000, 1000)));

            // In case there is an inline block child with large min-width, the inline block child will be force placed (not layouted properly)
            NUnit.Framework.Assert.AreEqual(LayoutResult.FULL, result.GetStatus());
            NUnit.Framework.Assert.AreEqual(0, result.GetOccupiedArea().GetBBox().GetHeight(), EPS);
            NUnit.Framework.Assert.AreEqual(true, inlineBlockRenderer.GetPropertyAsBoolean(Property.FORCED_PLACEMENT));
        }
示例#6
0
        public virtual void ApplyMinHeightForSpecificDimensionsCausingFloatPrecisionError()
        {
            float divHeight = 42.55f;
            Div   div       = new Div();

            div.SetHeight(UnitValue.CreatePointValue(divHeight));
            float occupiedHeight = 17.981995f;
            float leftHeight     = 24.567993f;

            NUnit.Framework.Assert.IsTrue(occupiedHeight + leftHeight < divHeight);
            BlockRenderer blockRenderer = (BlockRenderer)div.CreateRendererSubTree();

            blockRenderer.occupiedArea = new LayoutArea(1, new Rectangle(0, 267.9681f, 0, occupiedHeight));
            AbstractRenderer renderer = blockRenderer.ApplyMinHeight(OverflowPropertyValue.FIT, new Rectangle(0, 243.40012f
                                                                                                              , 0, leftHeight));

            NUnit.Framework.Assert.IsNull(renderer);
        }
示例#7
0
        public virtual void DivTest()
        {
            String      outFileName = destinationFolder + "divTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_divTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDocument);
            String      str         = "Hello. I am a fairly long paragraph. I really want you to process me correctly. You heard that? Correctly!!! Even if you will have to wrap me.";
            Paragraph   p           = new Paragraph(new Text(str)).SetPadding(1f).SetBorder(new SolidBorder(ColorConstants.BLACK,
                                                                                                            2)).SetMargin(3).SetBackgroundColor(ColorConstants.LIGHT_GRAY);
            Div d = new Div().SetPadding(4f).SetBorder(new SolidBorder(ColorConstants.GREEN, 5)).SetMargin(6);

            d.Add(p);
            MinMaxWidth result = ((AbstractRenderer)d.CreateRendererSubTree().SetParent(doc.GetRenderer())).GetMinMaxWidth
                                     ();

            d.SetWidth(ToEffectiveWidth(d, result.GetMinWidth()));
            doc.Add(d);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }