IsRelativeValue() public method

public IsRelativeValue ( String value ) : bool
value String
return bool
        virtual public float?GetHeight(Tag tag, float pageHeight)
        {
            float? height      = null;
            String heightValue = null;

            if (tag.CSS.TryGetValue(HTML.Attribute.HEIGHT, out heightValue) || tag.Attributes.TryGetValue(HTML.Attribute.HEIGHT, out heightValue))
            {
                if (utils.IsNumericValue(heightValue) || utils.IsMetricValue(heightValue))
                {
                    height = utils.ParsePxInCmMmPcToPt(heightValue);
                }
                else if (utils.IsRelativeValue(heightValue))
                {
                    Tag   ancestor             = tag;
                    float?firstAncestorsHeight = null;
                    while (firstAncestorsHeight == null && ancestor.Parent != null)
                    {
                        ancestor             = ancestor.Parent;
                        firstAncestorsHeight = GetHeight(ancestor, pageHeight);
                    }
                    if (firstAncestorsHeight == null)
                    {
                        height = utils.ParseRelativeValue(heightValue, pageHeight);
                    }
                    else
                    {
                        height = utils.ParseRelativeValue(heightValue, firstAncestorsHeight.Value);
                    }
                }
            }

            return(height);
        }
Beispiel #2
0
        public virtual float GetWidth(Tag tag, IList <String> rootTags, float pageWidth, float initialTotalWidth)
        {
            float  width = 0;
            String widthValue;

            tag.CSS.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
            if (widthValue == null)
            {
                tag.Attributes.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
            }
            if (widthValue != null)
            {
                if (utils.IsNumericValue(widthValue) || utils.IsMetricValue(widthValue))
                {
                    width = utils.ParsePxInCmMmPcToPt(widthValue);
                }
                else if (utils.IsRelativeValue(widthValue))
                {
                    Tag   ancestor            = tag;
                    float firstAncestorsWidth = 0;
                    while (firstAncestorsWidth == 0 && ancestor.Parent != null)
                    {
                        ancestor            = ancestor.Parent;
                        firstAncestorsWidth = GetWidth(ancestor, rootTags, pageWidth, initialTotalWidth);
                    }
                    if (firstAncestorsWidth == 0)
                    {
                        width = utils.ParseRelativeValue(widthValue, pageWidth);
                    }
                    else
                    {
                        width = utils.ParseRelativeValue(widthValue, firstAncestorsWidth);
                    }
                }
            }
            else if (rootTags.Contains(tag.Name))
            {
                if (Util.compare(initialTotalWidth, -1) == 0)
                {
                    width = pageWidth;
                }
                else
                {
                    width = initialTotalWidth;
                }
            }

            return(width);
        }
Beispiel #3
0
        /**
         * Returns the css value of the style <b>font-size</b> in a pt-value. Possible font-size values:
         * <ul>
         *  <li>a constant in px, in, cm, mm, pc, em or ex,</li>
         *  <li>xx-small,</li>
         *  <li>x-small,</li>
         *  <li>small,</li>
         *  <li>medium,</li>
         *  <li>large,</li>
         *  <li>x-large,</li>
         *  <li>xx-large,</li>
         *  <li>smaller (than tag's parent size),</li>
         *  <li>larger (than tag's parent size),</li>
         *  <li>a percentage (e.g font-size:250%) of tag's parent size,</li>
         * </ul>
         * @param tag to get the font size of.
         * @return float font size of the content of the tag in pt.
         */
        public float TranslateFontSize(Tag tag)
        {
            float size = 12;

            if (tag.CSS.ContainsKey(CSS.Property.FONT_SIZE))
            {
                String value = tag.CSS[CSS.Property.FONT_SIZE];
                if (Util.EqualsIgnoreCase(value, CSS.Value.XX_SMALL))
                {
                    size = 6.75f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.X_SMALL))
                {
                    size = 7.5f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.SMALL))
                {
                    size = 9.75f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.MEDIUM))
                {
                    size = 12f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.LARGE))
                {
                    size = 13.5f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.X_LARGE))
                {
                    size = 18f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.XX_LARGE))
                {
                    size = 24f;
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.SMALLER))
                {
                    if (tag.Parent != null)
                    {
                        float parentSize = GetFontSize(tag.Parent);  // if the font-size of the parent can be set in some memory the translation part is not needed anymore.
                        if (parentSize <= 6.75f)
                        {
                            size = parentSize - 1;
                        }
                        else if (parentSize == 7.5f)
                        {
                            size = 6.75f;
                        }
                        else if (parentSize == 9.75f)
                        {
                            size = 7.5f;
                        }
                        else if (parentSize == 12f)
                        {
                            size = 9.75f;
                        }
                        else if (parentSize == 13.5f)
                        {
                            size = 12f;
                        }
                        else if (parentSize == 18f)
                        {
                            size = 13.5f;
                        }
                        else if (parentSize == 24f)
                        {
                            size = 18f;
                        }
                        else if (parentSize < 24f)
                        {
                            size = parentSize * 0.85f;
                        }
                        else if (parentSize >= 24)
                        {
                            size = parentSize * 2 / 3;
                        }
                    }
                    else
                    {
                        size = 9.75f;
                    }
                }
                else if (Util.EqualsIgnoreCase(value, CSS.Value.LARGER))
                {
                    if (tag.Parent != null)
                    {
                        float parentSize = GetFontSize(tag.Parent);  // if the font-size of the parent can be set in some memory the translation part is not needed anymore.
                        if (parentSize == 6.75f)
                        {
                            size = 7.5f;
                        }
                        else if (parentSize == 7.5f)
                        {
                            size = 9.75f;
                        }
                        else if (parentSize == 9.75f)
                        {
                            size = 12f;
                        }
                        else if (parentSize == 12f)
                        {
                            size = 13.5f;
                        }
                        else if (parentSize == 13.5f)
                        {
                            size = 18f;
                        }
                        else if (parentSize == 18f)
                        {
                            size = 24f;
                        }
                        else
                        {
                            size = parentSize * 1.5f;
                        }
                    }
                    else
                    {
                        size = 13.5f;
                    }
                }
                else if (utils.IsMetricValue(value) || utils.IsNumericValue(value))
                {
                    size = utils.ParsePxInCmMmPcToPt(value);
                }
                else if (utils.IsRelativeValue(value))
                {
                    float baseValue = 0;
                    if (tag.Parent != null)
                    {
                        baseValue = GetFontSize(tag.Parent);
                    }
                    else
                    {
                        baseValue = 12;
                    }
                    size = utils.ParseRelativeValue(value, baseValue);
                }
            }
            return(size);
        }