/* (non-Javadoc)
             * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String)
             */
            public virtual IList <CssDeclaration> Convert(IElementNode element, String value)
            {
                // Trim semicolons at the end because they seem to not affect the value in browsers
                String cssEquivalent = iText.IO.Util.StringUtil.ReplaceAll(value, ";+$", "");

                if (!CssTypesValidationUtils.IsMetricValue(cssEquivalent) && !cssEquivalent.EndsWith(CssConstants.PERCENTAGE
                                                                                                     ))
                {
                    cssEquivalent += CssConstants.PX;
                }
                return(JavaUtil.ArraysAsList(new CssDeclaration(CssConstants.HEIGHT, cssEquivalent)));
            }
Example #2
0
        /// <summary>Apply vertical alignment to inline elements.</summary>
        /// <param name="cssProps">the CSS properties</param>
        /// <param name="context">the processor context</param>
        /// <param name="stylesContainer">the styles container</param>
        /// <param name="childElements">the child elements</param>
        public static void ApplyVerticalAlignmentForInlines(IDictionary <String, String> cssProps, ProcessorContext
                                                            context, IStylesContainer stylesContainer, IList <IPropertyContainer> childElements)
        {
            String vAlignVal = cssProps.Get(CssConstants.VERTICAL_ALIGN);

            if (vAlignVal != null)
            {
                // TODO DEVSIX-1750 for inline images and tables (inline-blocks) v-align is not supported
                float textRise = 0;
                // TODO DEVSIX-3757 'top' and 'bottom' values are not supported;
                // 'top' and 'bottom' require information of actual line height, therefore should be applied at layout level;
                // 'sub', 'super' calculations are based on the behaviour of the common browsers (+33% and -20% shift accordingly from the parent's font size);
                // 'middle', 'text-top', 'text-bottom' calculations are based on the approximate assumptions that x-height is 0.5 of the font size
                // and descender and ascender heights are 0.2 and 0.8 of the font size accordingly.
                if (CssConstants.SUB.Equals(vAlignVal) || CssConstants.SUPER.Equals(vAlignVal))
                {
                    textRise = CalcTextRiseForSupSub(stylesContainer, vAlignVal);
                }
                else
                {
                    if (CssConstants.MIDDLE.Equals(vAlignVal))
                    {
                        textRise = CalcTextRiseForMiddle(stylesContainer);
                    }
                    else
                    {
                        if (CssConstants.TEXT_TOP.Equals(vAlignVal))
                        {
                            textRise = CalcTextRiseForTextTop(stylesContainer, context.GetCssContext().GetRootFontSize());
                        }
                        else
                        {
                            if (CssConstants.TEXT_BOTTOM.Equals(vAlignVal))
                            {
                                textRise = CalcTextRiseForTextBottom(stylesContainer, context.GetCssContext().GetRootFontSize());
                            }
                            else
                            {
                                if (CssTypesValidationUtils.IsMetricValue(vAlignVal))
                                {
                                    textRise = CssDimensionParsingUtils.ParseAbsoluteLength(vAlignVal);
                                }
                                else
                                {
                                    if (vAlignVal.EndsWith(CssConstants.PERCENTAGE))
                                    {
                                        textRise = CalcTextRiseForPercentageValue(stylesContainer, context.GetCssContext().GetRootFontSize(), vAlignVal
                                                                                  );
                                    }
                                }
                            }
                        }
                    }
                }
                if (textRise != 0)
                {
                    foreach (IPropertyContainer element in childElements)
                    {
                        if (element is Text)
                        {
                            float?effectiveTr = element.GetProperty <float?>(Property.TEXT_RISE);
                            if (effectiveTr != null)
                            {
                                effectiveTr += textRise;
                            }
                            else
                            {
                                effectiveTr = textRise;
                            }
                            element.SetProperty(Property.TEXT_RISE, effectiveTr);
                        }
                        else
                        {
                            if (element is IBlockElement)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #3
0
 /// <summary>Checks if a string represents length value.</summary>
 /// <param name="pageSizeChunk">the string that possibly represents a length value</param>
 /// <returns>true, if the string represents a length value</returns>
 private static bool IsLengthValue(String pageSizeChunk)
 {
     return(CssTypesValidationUtils.IsMetricValue(pageSizeChunk) || CssTypesValidationUtils.IsRelativeValue(pageSizeChunk
                                                                                                            ));
 }