Exemplo n.º 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)
            {
                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);
            }
        }
Exemplo n.º 2
0
        public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context)
        {
            IDictionary <String, String> styles = ResolveNativeStyles(node, context);

            //Load in and merge inherited declarations from parent
            if (node.ParentNode() is IStylesContainer)
            {
                IStylesContainer             parentNode   = (IStylesContainer)node.ParentNode();
                IDictionary <String, String> parentStyles = parentNode.GetStyles();
                if (parentStyles == null && !(node.ParentNode() is IDocumentNode))
                {
                    ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver));
                    logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES);
                }
                ICollection <IStyleInheritance> inheritanceRules = new HashSet <IStyleInheritance>();
                inheritanceRules.Add(new CssInheritance());
                inheritanceRules.Add(new SvgAttributeInheritance());
                if (parentStyles != null)
                {
                    foreach (KeyValuePair <String, String> entry in parentStyles)
                    {
                        String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE);
                        if (parentFontSizeString == null)
                        {
                            parentFontSizeString = "0";
                        }
                        styles = StyleUtil.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString, inheritanceRules
                                                                       );
                    }
                }
            }
            return(styles);
        }
Exemplo n.º 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
                                  )
        {
            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);
            }
        }
Exemplo n.º 4
0
        /* (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 worker)
        {
            base.Apply(context, stylesContainer, worker);
            IPropertyContainer cell = worker.GetElementResult();

            if (cell != null)
            {
                IDictionary <String, String> cssProps = stylesContainer.GetStyles();
                VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForCells(cssProps, context, cell);
                float    em           = CssUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE));
                float    rem          = context.GetCssContext().GetRootFontSize();
                Border[] bordersArray = BorderStyleApplierUtil.GetBordersArray(cssProps, em, rem);
                if (bordersArray[0] == null)
                {
                    cell.SetProperty(Property.BORDER_TOP, Border.NO_BORDER);
                }
                if (bordersArray[1] == null)
                {
                    cell.SetProperty(Property.BORDER_RIGHT, Border.NO_BORDER);
                }
                if (bordersArray[2] == null)
                {
                    cell.SetProperty(Property.BORDER_BOTTOM, Border.NO_BORDER);
                }
                if (bordersArray[3] == null)
                {
                    cell.SetProperty(Property.BORDER_LEFT, Border.NO_BORDER);
                }
            }
        }
        /* (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
                                   )
        {
            if (!(tagWorker.GetElementResult() is List))
            {
                return;
            }
            IDictionary <String, String> css = stylesContainer.GetStyles();
            List list = (List)tagWorker.GetElementResult();

            if (CssConstants.INSIDE.Equals(css.Get(CssConstants.LIST_STYLE_POSITION)))
            {
                list.SetProperty(Property.LIST_SYMBOL_POSITION, ListSymbolPosition.INSIDE);
            }
            else
            {
                list.SetProperty(Property.LIST_SYMBOL_POSITION, ListSymbolPosition.OUTSIDE);
            }
            ListStyleApplierUtil.ApplyListStyleTypeProperty(stylesContainer, css, context, list);
            ListStyleApplierUtil.ApplyListStyleImageProperty(css, context, list);
            base.Apply(context, stylesContainer, tagWorker);
            // process the padding considering the direction
            bool isRtl = BaseDirection.RIGHT_TO_LEFT.Equals(list.GetProperty <BaseDirection?>(Property.BASE_DIRECTION));

            if ((isRtl && !list.HasProperty(Property.PADDING_RIGHT)) || (!isRtl && !list.HasProperty(Property.PADDING_LEFT
                                                                                                     )))
            {
                float     em           = CssDimensionParsingUtils.ParseAbsoluteLength(css.Get(CssConstants.FONT_SIZE));
                float     rem          = context.GetCssContext().GetRootFontSize();
                UnitValue startPadding = CssDimensionParsingUtils.ParseLengthValueToPt(css.Get(CssConstants.PADDING_INLINE_START
                                                                                               ), em, rem);
                list.SetProperty(isRtl ? Property.PADDING_RIGHT : Property.PADDING_LEFT, startPadding);
            }
        }
Exemplo n.º 6
0
            public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
            {
                base.Apply(context, stylesContainer, tagWorker);
                IPropertyContainer container = tagWorker.GetElementResult();

                // Enable default mode
                container.SetProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
            }
Exemplo n.º 7
0
        /// <summary>Calculates the text rise value for &lt;sup&gt; and &lt;sub&gt; tags.</summary>
        /// <param name="stylesContainer">the styles container</param>
        /// <param name="vAlignVal">the vertical alignment value</param>
        /// <returns>the calculated text rise</returns>
        private static float CalcTextRiseForSupSub(IStylesContainer stylesContainer, String vAlignVal)
        {
            float  parentFontSize      = GetParentFontSize(stylesContainer);
            String superscriptPosition = "33%";
            String subscriptPosition   = "-20%";
            String relativeValue       = CssConstants.SUPER.Equals(vAlignVal) ? superscriptPosition : subscriptPosition;

            return(CssDimensionParsingUtils.ParseRelativeValue(relativeValue, parentFontSize));
        }
Exemplo n.º 8
0
        /// <summary>Calculates text rise for percentage value text rise.</summary>
        /// <param name="stylesContainer">the styles container</param>
        /// <param name="rootFontSize">the root font size</param>
        /// <param name="vAlignVal">the vertical alignment value</param>
        /// <returns>the calculated text rise</returns>
        private static float CalcTextRiseForPercentageValue(IStylesContainer stylesContainer, float rootFontSize,
                                                            String vAlignVal)
        {
            String ownFontSizeStr        = stylesContainer.GetStyles().Get(CssConstants.FONT_SIZE);
            float  fontSize              = CssDimensionParsingUtils.ParseAbsoluteLength(ownFontSizeStr);
            String lineHeightStr         = stylesContainer.GetStyles().Get(CssConstants.LINE_HEIGHT);
            float  lineHeightActualValue = GetLineHeightActualValue(fontSize, rootFontSize, lineHeightStr);

            return(CssDimensionParsingUtils.ParseRelativeValue(vAlignVal, lineHeightActualValue));
        }
Exemplo n.º 9
0
        /* (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
                                   )
        {
            base.Apply(context, stylesContainer, tagWorker);
            IPropertyContainer list = tagWorker.GetElementResult();

            if (list != null)
            {
                ListStyleApplierUtil.ApplyListStyleImageProperty(stylesContainer.GetStyles(), context, list);
            }
        }
Exemplo n.º 10
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);
                    }
                }
            }
        }
Exemplo n.º 11
0
            public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                       )
            {
                IDictionary <String, String> styles = stylesContainer.GetStyles();

                if (styles.Get(CssConstants.OVERFLOW) == null)
                {
                    styles.Put(CssConstants.OVERFLOW, CssConstants.VISIBLE);
                }
                base.Apply(context, stylesContainer, tagWorker);
            }
Exemplo n.º 12
0
        /// <summary>Calculates the text rise for top alignment.</summary>
        /// <param name="stylesContainer">the styles container</param>
        /// <param name="rootFontSize">the root font size</param>
        /// <returns>the calculated text rise</returns>
        private static float CalcTextRiseForTextTop(IStylesContainer stylesContainer, float rootFontSize)
        {
            String ownFontSizeStr        = stylesContainer.GetStyles().Get(CssConstants.FONT_SIZE);
            float  fontSize              = CssDimensionParsingUtils.ParseAbsoluteLength(ownFontSizeStr);
            String lineHeightStr         = stylesContainer.GetStyles().Get(CssConstants.LINE_HEIGHT);
            float  lineHeightActualValue = GetLineHeightActualValue(fontSize, rootFontSize, lineHeightStr);
            float  parentFontSize        = GetParentFontSize(stylesContainer);
            float  elementTopEdge        = (float)(fontSize * ASCENDER_COEFFICIENT + (lineHeightActualValue - fontSize) / 2);
            float  parentTextTop         = (float)(parentFontSize * ASCENDER_COEFFICIENT);

            return(parentTextTop - elementTopEdge);
        }
Exemplo n.º 13
0
        /* (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);
            if (CssConstants.BOTTOM.Equals(cssProps.Get(CssConstants.CAPTION_SIDE)))
            {
                IPropertyContainer container = tagWorker.GetElementResult();
                container.SetProperty(Property.CAPTION_SIDE, CaptionSide.BOTTOM);
            }
        }
Exemplo n.º 14
0
        /// <summary>Calculates the text rise for middle alignment.</summary>
        /// <param name="stylesContainer">the styles container</param>
        /// <returns>the calculated text rise</returns>
        private static float CalcTextRiseForMiddle(IStylesContainer stylesContainer)
        {
            String ownFontSizeStr        = stylesContainer.GetStyles().Get(CssConstants.FONT_SIZE);
            float  fontSize              = CssDimensionParsingUtils.ParseAbsoluteLength(ownFontSizeStr);
            float  parentFontSize        = GetParentFontSize(stylesContainer);
            double fontMiddleCoefficient = 0.3;
            float  elementMidPoint       = (float)(fontSize * fontMiddleCoefficient);
            // shift to element mid point from the baseline
            float xHeight = parentFontSize / 4;

            return(xHeight - elementMidPoint);
        }
Exemplo n.º 15
0
            /* (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);
                }
            }
Exemplo n.º 16
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();

            if (cssProps != null && tagWorker is ColgroupTagWorker)
            {
                ((ColgroupTagWorker)tagWorker).GetColgroup().SetCellCssProps(SupportedColColgroupPropertiesUtil.GetCellProperties
                                                                                 (cssProps)).SetOwnCssProps(SupportedColColgroupPropertiesUtil.GetOwnProperties(cssProps)).SetWidth(SupportedColColgroupPropertiesUtil
                                                                                                                                                                                    .GetWidth(cssProps, context));
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
            public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                       )
            {
                base.Apply(context, stylesContainer, tagWorker);
                Paragraph paragraph = (Paragraph)tagWorker.GetElementResult();
                ParagraphWidowsControl widowsControl = paragraph.GetProperty <ParagraphWidowsControl>(Property.WIDOWS_CONTROL
                                                                                                      );

                if (widowsControl != null)
                {
                    widowsControl.SetMinAllowedWidows(widowsControl.GetMinWidows(), 3, true);
                    paragraph.SetProperty(Property.WIDOWS_CONTROL, widowsControl);
                }
            }
Exemplo n.º 19
0
            public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
            {
                base.Apply(context, stylesContainer, tagWorker);
                IPropertyContainer container = tagWorker.GetElementResult();

                if (container != null && container is Cell)
                {
                    Cell cell = (Cell)container;
                    foreach (IElement element in cell.GetChildren())
                    {
                        element.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
                        element.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.FIT);
                    }
                }
            }
Exemplo n.º 20
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 override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker
                                   )
        {
            IDictionary <String, String> originalStyles = stylesContainer.GetStyles();
            IDictionary <String, String> styles         = new Dictionary <String, String>(originalStyles);

            // In general, if border color is not specified, it should take the value from color CSS property.
            // However, <hr> tag is an exception from this rule and color property does not affect the border color.
            // This is a workaround to solve the problem of color property being taken into account for <hr> tag.
            // Please note that this problem might as well be solved at BorderStyleApplierUtil.
            styles.JRemove(CssConstants.COLOR);
            stylesContainer.SetStyles(styles);
            base.Apply(context, stylesContainer, tagWorker);
            stylesContainer.SetStyles(originalStyles);
        }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context)
        {
            IDictionary <String, String> styles = new Dictionary <String, String>();
            //Load in from collected style sheets
            IList <CssDeclaration> styleSheetDeclarations = css.GetCssDeclarations(node, MediaDeviceDescription.CreateDefault
                                                                                       ());

            foreach (CssDeclaration ssd in styleSheetDeclarations)
            {
                styles.Put(ssd.GetProperty(), ssd.GetExpression());
            }
            //Load in attributes declarations
            if (node is IElementNode)
            {
                IElementNode eNode = (IElementNode)node;
                foreach (IAttribute attr in eNode.GetAttributes())
                {
                    ProcessAttribute(attr, styles);
                }
            }
            //Load in and merge inherited declarations from parent
            if (node.ParentNode() is IStylesContainer)
            {
                IStylesContainer             parentNode   = (IStylesContainer)node.ParentNode();
                IDictionary <String, String> parentStyles = parentNode.GetStyles();
                if (parentStyles == null && !(node.ParentNode() is IDocumentNode))
                {
                    ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver));
                    logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES);
                }
                if (parentStyles != null)
                {
                    foreach (KeyValuePair <String, String> entry in parentStyles)
                    {
                        String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE);
                        if (parentFontSizeString == null)
                        {
                            parentFontSizeString = "0";
                        }
                        sru.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString);
                    }
                }
            }
            return(styles);
        }
Exemplo n.º 23
0
        /// <summary>Gets the parent font size.</summary>
        /// <param name="stylesContainer">the styles container</param>
        /// <returns>the parent font size</returns>
        private static float GetParentFontSize(IStylesContainer stylesContainer)
        {
            float parentFontSize;

            if (stylesContainer is INode && ((IElementNode)stylesContainer).ParentNode() is IStylesContainer)
            {
                INode  parent            = ((IElementNode)stylesContainer).ParentNode();
                String parentFontSizeStr = ((IStylesContainer)parent).GetStyles().Get(CssConstants.FONT_SIZE);
                parentFontSize = CssDimensionParsingUtils.ParseAbsoluteLength(parentFontSizeStr);
            }
            else
            {
                // let's take own font size for this unlikely case
                String ownFontSizeStr = stylesContainer.GetStyles().Get(CssConstants.FONT_SIZE);
                parentFontSize = CssDimensionParsingUtils.ParseAbsoluteLength(ownFontSizeStr);
            }
            return(parentFontSize);
        }
Exemplo n.º 24
0
            /* (non-Javadoc)
             * @see iText.Html2pdf.Css.Apply.Impl.BlockCssApplier#apply(iText.Html2pdf.Attach.ProcessorContext, iText.StyledXmlParser.Node.IStylesContainer, iText.Html2pdf.Attach.ITagWorker)
             */
            public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
            {
                IDictionary <String, String> cssStyles = stylesContainer.GetStyles();

                if (cssStyles.ContainsKey("kleur"))
                {
                    cssStyles.Add(CssConstants.COLOR, KLEUR[cssStyles["kleur"]]);
                    stylesContainer.SetStyles(cssStyles);
                }

                if (cssStyles.ContainsKey("achtergrond"))
                {
                    cssStyles.Add(CssConstants.BACKGROUND_COLOR, KLEUR[cssStyles["achtergrond"]]);
                    stylesContainer.SetStyles(cssStyles);
                }

                base.Apply(context, stylesContainer, tagWorker);
            }
Exemplo n.º 25
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);
                }
            }
        }
        /* (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);
                }
            }
        }
        public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
        {
            IDictionary <string, string> cssStyles = stylesContainer.GetStyles();

            if (cssStyles.ContainsKey(CssConstants.COLOR))
            {
                string newColor = TransformColor(cssStyles[CssConstants.COLOR]);
                cssStyles[CssConstants.COLOR] = newColor;
                stylesContainer.SetStyles(cssStyles);
            }

            if (cssStyles.ContainsKey(CssConstants.BACKGROUND_COLOR))
            {
                string newColor = TransformColor(cssStyles[CssConstants.BACKGROUND_COLOR]);
                cssStyles[CssConstants.BACKGROUND_COLOR] = newColor;
                stylesContainer.SetStyles(cssStyles);
            }

            base.Apply(context, stylesContainer, tagWorker);
        }
Exemplo n.º 28
0
        /* (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 worker)
        {
            base.Apply(context, stylesContainer, worker);
            Table table = (Table)worker.GetElementResult();

            if (table != null)
            {
                String tableLayout = stylesContainer.GetStyles().Get(CssConstants.TABLE_LAYOUT);
                if (tableLayout != null)
                {
                    table.SetProperty(Property.TABLE_LAYOUT, tableLayout);
                }
                String borderCollapse = stylesContainer.GetStyles().Get(CssConstants.BORDER_COLLAPSE);
                // BorderCollapsePropertyValue.COLLAPSE is default in iText layout
                if (null == borderCollapse || CssConstants.SEPARATE.Equals(borderCollapse))
                {
                    table.SetBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
                }
                String borderSpacing = stylesContainer.GetStyles().Get(CssConstants.BORDER_SPACING);
                if (null != borderSpacing)
                {
                    String[] props = iText.IO.Util.StringUtil.Split(borderSpacing, "\\s+");
                    if (1 == props.Length)
                    {
                        table.SetHorizontalBorderSpacing(CssUtils.ParseAbsoluteLength(props[0]));
                        table.SetVerticalBorderSpacing(CssUtils.ParseAbsoluteLength(props[0]));
                    }
                    else
                    {
                        if (2 == props.Length)
                        {
                            table.SetHorizontalBorderSpacing(CssUtils.ParseAbsoluteLength(props[0]));
                            table.SetVerticalBorderSpacing(CssUtils.ParseAbsoluteLength(props[1]));
                        }
                    }
                }
            }
        }
Exemplo n.º 29
0
        /* (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
                                   )
        {
            base.Apply(context, stylesContainer, tagWorker);
            IPropertyContainer propertyContainer = tagWorker.GetElementResult();

            if (propertyContainer != null && stylesContainer is INode)
            {
                INode parent     = ((INode)stylesContainer).ParentNode();
                bool  parentIsDl = parent is IElementNode && TagConstants.DL.Equals(((IElementNode)parent).Name());
                if (CssConstants.INSIDE.Equals(stylesContainer.GetStyles().Get(CssConstants.LIST_STYLE_POSITION)) || parentIsDl
                    )
                {
                    propertyContainer.SetProperty(Property.LIST_SYMBOL_POSITION, ListSymbolPosition.INSIDE);
                }
                else
                {
                    propertyContainer.SetProperty(Property.LIST_SYMBOL_POSITION, ListSymbolPosition.OUTSIDE);
                }
                ListStyleApplierUtil.ApplyListStyleTypeProperty(stylesContainer, stylesContainer.GetStyles(), context, propertyContainer
                                                                );
                ListStyleApplierUtil.ApplyListStyleImageProperty(stylesContainer.GetStyles(), context, propertyContainer);
            }
        }
Exemplo n.º 30
0
        // TODO these are css properties actually, but it is not supported by the browsers currently
        /// <summary>Applies hyphenation to an element.</summary>
        /// <param name="cssProps">the CSS props</param>
        /// <param name="context">the processor context</param>
        /// <param name="stylesContainer">the styles container</param>
        /// <param name="element">the element</param>
        public static void ApplyHyphenation(IDictionary <String, String> cssProps, ProcessorContext context, IStylesContainer
                                            stylesContainer, IPropertyContainer element)
        {
            String value = cssProps.Get(CssConstants.HYPHENS);

            if (value == null)
            {
                value = CssDefaults.GetDefaultValue(CssConstants.HYPHENS);
            }
            if (CssConstants.NONE.Equals(value))
            {
                element.SetProperty(Property.HYPHENATION, null);
            }
            else
            {
                if (CssConstants.MANUAL.Equals(value))
                {
                    element.SetProperty(Property.HYPHENATION, new HyphenationConfig(HYPHENATE_BEFORE, HYPHENATE_AFTER));
                }
                else
                {
                    if (CssConstants.AUTO.Equals(value) && stylesContainer is IElementNode)
                    {
                        String lang = ((IElementNode)stylesContainer).GetLang();
                        if (lang != null && lang.Length > 0)
                        {
                            element.SetProperty(Property.HYPHENATION, new HyphenationConfig(lang.JSubstring(0, 2), "", HYPHENATE_BEFORE
                                                                                            , HYPHENATE_AFTER));
                        }
                    }
                }
            }
        }