/* (non-Javadoc)
         * @see com.itextpdf.html2pdf.css.apply.ICssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker)
         */
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            IDictionary <String, String> cssProps  = stylesContainer.GetStyles();
            IPropertyContainer           container = tagWorker.GetElementResult();

            if (container != null)
            {
                WidthHeightApplierUtil.ApplyWidthHeight(cssProps, context, container);
                BackgroundApplierUtil.ApplyBackground(cssProps, context, container);
                MarginApplierUtil.ApplyMargins(cssProps, context, container);
                PaddingApplierUtil.ApplyPaddings(cssProps, context, container);
                FontStyleApplierUtil.ApplyFontStyles(cssProps, context, stylesContainer, container);
                BorderStyleApplierUtil.ApplyBorders(cssProps, context, container);
                HyphenationApplierUtil.ApplyHyphenation(cssProps, context, stylesContainer, container);
                FloatApplierUtil.ApplyFloating(cssProps, context, container);
                PositionApplierUtil.ApplyPosition(cssProps, context, container);
                OpacityApplierUtil.ApplyOpacity(cssProps, context, container);
                PageBreakApplierUtil.ApplyPageBreakProperties(cssProps, context, container);
                OverflowApplierUtil.ApplyOverflow(cssProps, container);
                TransformationApplierUtil.ApplyTransformation(cssProps, context, container);
                OutlineApplierUtil.ApplyOutlines(cssProps, context, container);
                OrphansWidowsApplierUtil.ApplyOrphansAndWidows(cssProps, container);
            }
        }
Exemple #2
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.css.apply.ICssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker)
         */
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            IDictionary <String, String> cssProps  = stylesContainer.GetStyles();
            IPropertyContainer           container = tagWorker.GetElementResult();

            if (container != null)
            {
                if (container is Div)
                {
                    if (!cssProps.ContainsKey(CssConstants.WIDTH) || CssConstants.AUTO.Equals(cssProps.Get(CssConstants.WIDTH)
                                                                                              ))
                    {
                        ((Div)container).SetWidth(DEFAULT_CONTENT_WIDTH_PT);
                    }
                    if (!cssProps.ContainsKey(CssConstants.HEIGHT) || CssConstants.AUTO.Equals(cssProps.Get(CssConstants.HEIGHT
                                                                                                            )))
                    {
                        ((Div)container).SetHeight(DEFAULT_CONTENT_HEIGHT_PT);
                    }
                }
                WidthHeightApplierUtil.ApplyWidthHeight(cssProps, context, container);
                BackgroundApplierUtil.ApplyBackground(cssProps, context, container);
            }
        }
Exemple #3
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.css.apply.ICssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker)
         */
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            SpanTagWorker spanTagWorker            = (SpanTagWorker)tagWorker;
            IDictionary <String, String> cssStyles = stylesContainer.GetStyles();

            foreach (IPropertyContainer child in spanTagWorker.GetOwnLeafElements())
            {
                // Workaround for form fields so that SpanTagCssApplier does not apply its font-size to the child.
                // Form fields have their own CSS applier // TODO remove when form fields are not leaf elements anymore
                if (!(child is IFormField))
                {
                    ApplyChildElementStyles(child, cssStyles, context, stylesContainer);
                }
            }
            VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForInlines(cssStyles, context, stylesContainer, spanTagWorker
                                                                          .GetAllElements());
            if (cssStyles.ContainsKey(CssConstants.OPACITY))
            {
                foreach (IPropertyContainer elem in spanTagWorker.GetAllElements())
                {
                    if (elem is Text && !elem.HasProperty(Property.OPACITY))
                    {
                        OpacityApplierUtil.ApplyOpacity(cssStyles, context, elem);
                    }
                }
            }
            // TODO as for now spans are flattened, let's at least make kids of floating spans floating too
            String floatVal = cssStyles.Get(CssConstants.FLOAT);

            if (floatVal != null && !CssConstants.NONE.Equals(floatVal))
            {
                foreach (IPropertyContainer elem in spanTagWorker.GetAllElements())
                {
                    FloatPropertyValue?kidFloatVal = elem.GetProperty <FloatPropertyValue?>(Property.FLOAT);
                    if (kidFloatVal == null || FloatPropertyValue.NONE.Equals(kidFloatVal))
                    {
                        FloatApplierUtil.ApplyFloating(cssStyles, context, elem);
                    }
                }
            }
            if (spanTagWorker.GetAllElements() != null)
            {
                foreach (IPropertyContainer child in spanTagWorker.GetAllElements())
                {
                    FloatPropertyValue?kidFloatVal = child.GetProperty <FloatPropertyValue?>(Property.FLOAT);
                    if (child is Text && !child.HasOwnProperty(Property.BACKGROUND) && (kidFloatVal == null || FloatPropertyValue
                                                                                        .NONE.Equals(kidFloatVal)))
                    {
                        BackgroundApplierUtil.ApplyBackground(cssStyles, context, child);
                    }
                }
            }
        }
Exemple #4
0
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            IDictionary <String, String> boxStyles = stylesContainer.GetStyles();
            IPropertyContainer           marginBox = tagWorker.GetElementResult();

            BackgroundApplierUtil.ApplyBackground(boxStyles, context, marginBox);
            FontStyleApplierUtil.ApplyFontStyles(boxStyles, context, stylesContainer, marginBox);
            BorderStyleApplierUtil.ApplyBorders(boxStyles, context, marginBox);
            VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForCells(boxStyles, context, marginBox);
            // Set overflow to HIDDEN if it's not explicitly set in css in order to avoid overlapping with page content.
            String overflow = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW)) ? boxStyles.
                              Get(CssConstants.OVERFLOW) : null;
            String overflowX = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW_X)) ? boxStyles
                               .Get(CssConstants.OVERFLOW_X) : overflow;

            if (overflowX == null || CssConstants.HIDDEN.Equals(overflowX))
            {
                marginBox.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.HIDDEN);
            }
            else
            {
                marginBox.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
            }
            String overflowY = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW_Y)) ? boxStyles
                               .Get(CssConstants.OVERFLOW_Y) : overflow;

            if (overflowY == null || CssConstants.HIDDEN.Equals(overflowY))
            {
                marginBox.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.HIDDEN);
            }
            else
            {
                marginBox.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
            }
            // TODO outlines are currently not supported for page margin boxes, because of the outlines handling specificity (they are handled on renderer's parent level)
            OutlineApplierUtil.ApplyOutlines(boxStyles, context, marginBox);
            marginBox.SetProperty(Property.FONT_PROVIDER, context.GetFontProvider());
            marginBox.SetProperty(Property.FONT_SET, context.GetTempFonts());
            if (!(stylesContainer is PageMarginBoxContextNode))
            {
                ILog logger = LogManager.GetLogger(typeof(PageMarginBoxCssApplier));
                logger.Warn(iText.Html2pdf.LogMessageConstant.PAGE_MARGIN_BOX_SOME_PROPERTIES_NOT_PROCESSED);
                return;
            }
            float availableWidth = ((PageMarginBoxContextNode)stylesContainer).GetContainingBlockForMarginBox().GetWidth
                                       ();
            float availableHeight = ((PageMarginBoxContextNode)stylesContainer).GetContainingBlockForMarginBox().GetHeight
                                        ();

            MarginApplierUtil.ApplyMargins(boxStyles, context, marginBox, availableHeight, availableWidth);
            PaddingApplierUtil.ApplyPaddings(boxStyles, context, marginBox, availableHeight, availableWidth);
        }
            /* (non-Javadoc)
             * @see iText.Html2pdf.Css.Apply.ICssApplier#apply(iText.Html2pdf.Attach.ProcessorContext, iText.StyledXmlParser.Node.IStylesContainer, iText.Html2pdf.Attach.ITagWorker)
             */
            public void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
            {
                IDictionary <String, String> cssProps  = stylesContainer.GetStyles();
                IPropertyContainer           container = tagWorker.GetElementResult();

                if (container != null && cssProps.ContainsKey(CssConstants.BACKGROUND_COLOR))
                {
                    cssProps.Remove(CssConstants.BACKGROUND_COLOR);
                    cssProps.Add(CssConstants.BACKGROUND_COLOR, "#dddddd");
                    BackgroundApplierUtil.ApplyBackground(cssProps, context, container);
                }
            }
 /// <summary>Creates the page simulation elements.</summary>
 /// <param name="styles">
 /// a
 /// <see cref="System.Collections.IDictionary{K, V}"/>
 /// containing the styles
 /// </param>
 /// <param name="context">the processor context</param>
 private void CreatePageSimulationElements(IDictionary <String, String> styles, ProcessorContext context)
 {
     pageBackgroundSimulation = new Div().SetFillAvailableArea(true);
     BackgroundApplierUtil.ApplyBackground(styles, context, pageBackgroundSimulation);
     pageBackgroundSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
     pageBordersSimulation = new Div().SetFillAvailableArea(true);
     pageBordersSimulation.SetMargins(margins[0], margins[1], margins[2], margins[3]);
     pageBordersSimulation.SetBorderTop(borders[0]);
     pageBordersSimulation.SetBorderRight(borders[1]);
     pageBordersSimulation.SetBorderBottom(borders[2]);
     pageBordersSimulation.SetBorderLeft(borders[3]);
     pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
 }
Exemple #7
0
 /// <summary>Applies styles to child elements.</summary>
 /// <param name="element">the element</param>
 /// <param name="css">the CSS mapping</param>
 /// <param name="context">the processor context</param>
 /// <param name="stylesContainer">the styles container</param>
 protected internal virtual void ApplyChildElementStyles(IPropertyContainer element, IDictionary <String, String
                                                                                                  > css, ProcessorContext context, IStylesContainer stylesContainer)
 {
     FontStyleApplierUtil.ApplyFontStyles(css, context, stylesContainer, element);
     BackgroundApplierUtil.ApplyBackground(css, context, element);
     //TODO: Border-applying currently doesn't work in html way for spans inside other spans.
     BorderStyleApplierUtil.ApplyBorders(css, context, element);
     OutlineApplierUtil.ApplyOutlines(css, context, element);
     HyphenationApplierUtil.ApplyHyphenation(css, context, stylesContainer, element);
     //TODO: Margins-applying currently doesn't work in html way for spans inside other spans. (see SpanTest#spanTest07)
     MarginApplierUtil.ApplyMargins(css, context, element);
     PositionApplierUtil.ApplyPosition(css, context, element);
     FloatApplierUtil.ApplyFloating(css, context, element);
     PaddingApplierUtil.ApplyPaddings(css, context, element);
 }
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            IDictionary <String, String> cssStyles           = stylesContainer.GetStyles();
            IStylesContainer             parentToBeProcessed = (IStylesContainer)((CssPseudoElementNode)stylesContainer).ParentNode
                                                                   ();
            IPropertyContainer elementResult = context.GetState().Top().GetElementResult();

            if (elementResult is IPlaceholderable)
            {
                IPropertyContainer element = ((IPlaceholderable)elementResult).GetPlaceholder();
                FontStyleApplierUtil.ApplyFontStyles(cssStyles, context, parentToBeProcessed, element);
                BackgroundApplierUtil.ApplyBackground(cssStyles, context, element);
                OpacityApplierUtil.ApplyOpacity(cssStyles, context, element);
            }
        }
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.css.apply.ICssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker)
         */
        public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                  )
        {
            IDictionary <String, String> cssProps      = stylesContainer.GetStyles();
            BodyHtmlStylesContainer      styleProperty = new BodyHtmlStylesContainer();
            IPropertyContainer           container     = tagWorker.GetElementResult();

            if (container != null)
            {
                BackgroundApplierUtil.ApplyBackground(cssProps, context, styleProperty);
                MarginApplierUtil.ApplyMargins(cssProps, context, styleProperty);
                PaddingApplierUtil.ApplyPaddings(cssProps, context, styleProperty);
                BorderStyleApplierUtil.ApplyBorders(cssProps, context, styleProperty);
                if (styleProperty.HasStylesToApply())
                {
                    container.SetProperty(Html2PdfProperty.HTML_STYLING, styleProperty);
                }
            }
        }
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.css.apply.impl.BlockCssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker)
         */
        public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                   )
        {
            IDictionary <String, String> cssProps = stylesContainer.GetStyles();

            base.Apply(context, stylesContainer, tagWorker);
            TableRowWrapper rowWrapper = ((DisplayTableRowTagWorker)tagWorker).GetTableRowWrapper();

            foreach (Cell cell in rowWrapper.GetCells())
            {
                if (!cell.HasProperty(Property.BACKGROUND))
                {
                    BackgroundApplierUtil.ApplyBackground(cssProps, context, cell);
                }
                if (!cell.HasProperty(Property.OPACITY))
                {
                    OpacityApplierUtil.ApplyOpacity(cssProps, context, cell);
                }
            }
        }
 /// <summary>Creates the page simulation elements.</summary>
 /// <param name="styles">
 /// a
 /// <see cref="System.Collections.IDictionary{K, V}"/>
 /// containing the styles
 /// </param>
 /// <param name="context">the processor context</param>
 private void CreatePageSimulationElements(IDictionary <String, String> styles, ProcessorContext context)
 {
     pageBackgroundSimulation = new Div().SetFillAvailableArea(true);
     BackgroundApplierUtil.ApplyBackground(styles, context, pageBackgroundSimulation);
     pageBackgroundSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
     if (!pageBackgroundSimulation.HasOwnProperty(Property.BACKGROUND) && !pageBackgroundSimulation.HasOwnProperty
             (Property.BACKGROUND_IMAGE))
     {
         pageBackgroundSimulation = null;
     }
     if (borders[0] == null && borders[1] == null && borders[2] == null && borders[3] == null)
     {
         pageBordersSimulation = null;
         return;
     }
     pageBordersSimulation = new Div().SetFillAvailableArea(true);
     pageBordersSimulation.SetMargins(margins[0], margins[1], margins[2], margins[3]);
     pageBordersSimulation.SetBorderTop(borders[0]);
     pageBordersSimulation.SetBorderRight(borders[1]);
     pageBordersSimulation.SetBorderBottom(borders[2]);
     pageBordersSimulation.SetBorderLeft(borders[3]);
     pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
 }