예제 #1
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)
            {
                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);
            }
        }
예제 #2
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);
        }
예제 #3
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);
 }
예제 #4
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();
            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);
                }
            }
        }