Ejemplo n.º 1
0
 private static void SetLineHeight(IPropertyContainer elementToSet, String lineHeight, float em, float rem)
 {
     if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight)
         )
     {
         if (CssTypesValidationUtils.IsNumericValue(lineHeight))
         {
             float?number = CssDimensionParsingUtils.ParseFloat(lineHeight);
             if (number != null)
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue((float)number));
             }
             else
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
             }
         }
         else
         {
             UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeight, em, rem);
             if (lineHeightValue != null && lineHeightValue.IsPointValue())
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(lineHeightValue.GetValue()));
             }
             else
             {
                 if (lineHeightValue != null)
                 {
                     elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue(lineHeightValue.GetValue()
                                                                                                     / 100f));
                 }
                 else
                 {
                     elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
                 }
             }
         }
     }
     else
     {
         elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
     }
 }
Ejemplo n.º 2
0
 private static void SetLineHeightByLeading(IPropertyContainer element, String lineHeight, float em, float
                                            rem)
 {
     // specification does not give auto as a possible lineHeight value
     // nevertheless some browsers compute it as normal so we apply the same behaviour.
     // What's more, it's basically the same thing as if lineHeight is not set in the first place
     if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight)
         )
     {
         if (CssTypesValidationUtils.IsNumericValue(lineHeight))
         {
             float?mult = CssDimensionParsingUtils.ParseFloat(lineHeight);
             if (mult != null)
             {
                 element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, (float)mult));
             }
         }
         else
         {
             UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeight, em, rem);
             if (lineHeightValue != null && lineHeightValue.IsPointValue())
             {
                 element.SetProperty(Property.LEADING, new Leading(Leading.FIXED, lineHeightValue.GetValue()));
             }
             else
             {
                 if (lineHeightValue != null)
                 {
                     element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, lineHeightValue.GetValue() / 100));
                 }
             }
         }
     }
     else
     {
         element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, DEFAULT_LINE_HEIGHT));
     }
 }
Ejemplo n.º 3
0
        /// <summary>Gets the actual value of the line height.</summary>
        /// <param name="fontSize">the font size</param>
        /// <param name="rootFontSize">the root font size</param>
        /// <param name="lineHeightStr">
        /// the line height as a
        /// <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// the actual line height as a
        /// <c>float</c>
        /// </returns>
        private static float GetLineHeightActualValue(float fontSize, float rootFontSize, String lineHeightStr)
        {
            float lineHeightActualValue;

            if (lineHeightStr != null)
            {
                if (CssConstants.NORMAL.Equals(lineHeightStr) || CssConstants.AUTO.Equals(lineHeightStr))
                {
                    lineHeightActualValue = (float)(fontSize * 1.2);
                }
                else
                {
                    UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeightStr, fontSize, rootFontSize
                                                                                              );
                    if (CssTypesValidationUtils.IsNumericValue(lineHeightStr))
                    {
                        lineHeightActualValue = fontSize * lineHeightValue.GetValue();
                    }
                    else
                    {
                        if (lineHeightValue.IsPointValue())
                        {
                            lineHeightActualValue = lineHeightValue.GetValue();
                        }
                        else
                        {
                            lineHeightActualValue = fontSize * lineHeightValue.GetValue() / 100;
                        }
                    }
                }
            }
            else
            {
                lineHeightActualValue = (float)(fontSize * 1.2);
            }
            return(lineHeightActualValue);
        }