public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
     }
 }
示例#2
0
        /// <summary>Applies the default field properties.</summary>
        /// <param name="inputField">the input field</param>
        internal virtual void ApplyDefaultFieldProperties(PdfFormField inputField)
        {
            inputField.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
            inputField.SetBorderWidth(0);
            TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);

            if (color != null)
            {
                inputField.SetColor(color.GetColor());
            }
        }
示例#3
0
 public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
         if (doc.IsTagged())
         {
             TagTreePointer formParentPointer = doc.GetTagStructureContext().GetAutoTaggingPointer();
             IList <String> kidsRoles         = formParentPointer.GetKidsRoles();
             int            lastFormIndex     = kidsRoles.LastIndexOf(StandardRoles.FORM);
             TagTreePointer formPointer       = formParentPointer.MoveToKid(lastFormIndex);
             String         lang = this.GetProperty <String>(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE);
             if (lang != null)
             {
                 formPointer.GetProperties().SetLanguage(lang);
             }
             formParentPointer.MoveToParent();
         }
     }
 }
        private static void ApplyCommonLayoutAttributes(AbstractRenderer renderer, PdfDictionary attributes)
        {
            Background background = renderer.GetProperty <Background>(Property.BACKGROUND);

            if (background != null && background.GetColor() is DeviceRgb)
            {
                attributes.Put(PdfName.BackgroundColor, new PdfArray(background.GetColor().GetColorValue()));
            }
            //TODO NOTE: applying border attributes for cells is temporarily turned off on purpose. Remove this 'if' in future.
            // The reason is that currently, we can't distinguish if all cells have same border style or not.
            // Therefore for every cell in every table we have to write the same border attributes, which creates lots of clutter.
            if (!(renderer.GetModelElement() is Cell))
            {
                ApplyBorderAttributes(renderer, attributes);
            }
            ApplyPaddingAttribute(renderer, attributes);
            TransparentColor transparentColor = renderer.GetPropertyAsTransparentColor(Property.FONT_COLOR);

            if (transparentColor != null && transparentColor.GetColor() is DeviceRgb)
            {
                attributes.Put(PdfName.Color, new PdfArray(transparentColor.GetColor().GetColorValue()));
            }
        }
示例#5
0
        /// <summary>Applies font styles 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 ApplyFontStyles(IDictionary <String, String> cssProps, ProcessorContext context, IStylesContainer
                                           stylesContainer, IPropertyContainer element)
        {
            float em  = CssDimensionParsingUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE));
            float rem = context.GetCssContext().GetRootFontSize();

            if (em != 0)
            {
                element.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(em));
            }
            if (cssProps.Get(CssConstants.FONT_FAMILY) != null)
            {
                // TODO DEVSIX-2534
                IList <String> fontFamilies = FontFamilySplitter.SplitFontFamily(cssProps.Get(CssConstants.FONT_FAMILY));
                element.SetProperty(Property.FONT, fontFamilies.ToArray(new String[fontFamilies.Count]));
            }
            if (cssProps.Get(CssConstants.FONT_WEIGHT) != null)
            {
                element.SetProperty(Property.FONT_WEIGHT, cssProps.Get(CssConstants.FONT_WEIGHT));
            }
            if (cssProps.Get(CssConstants.FONT_STYLE) != null)
            {
                element.SetProperty(Property.FONT_STYLE, cssProps.Get(CssConstants.FONT_STYLE));
            }
            String cssColorPropValue = cssProps.Get(CssConstants.COLOR);

            if (cssColorPropValue != null)
            {
                TransparentColor transparentColor;
                if (!CssConstants.TRANSPARENT.Equals(cssColorPropValue))
                {
                    float[] rgbaColor = CssDimensionParsingUtils.ParseRgbaColor(cssColorPropValue);
                    Color   color     = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
                    float   opacity   = rgbaColor[3];
                    transparentColor = new TransparentColor(color, opacity);
                }
                else
                {
                    transparentColor = new TransparentColor(ColorConstants.BLACK, 0f);
                }
                element.SetProperty(Property.FONT_COLOR, transparentColor);
            }
            // Make sure to place that before text-align applier
            String direction = cssProps.Get(CssConstants.DIRECTION);

            if (CssConstants.RTL.Equals(direction))
            {
                element.SetProperty(Property.BASE_DIRECTION, BaseDirection.RIGHT_TO_LEFT);
                element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT);
            }
            else
            {
                if (CssConstants.LTR.Equals(direction))
                {
                    element.SetProperty(Property.BASE_DIRECTION, BaseDirection.LEFT_TO_RIGHT);
                    element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT);
                }
            }
            if (stylesContainer is IElementNode && ((IElementNode)stylesContainer).ParentNode() is IElementNode && CssConstants
                .RTL.Equals(((IElementNode)((IElementNode)stylesContainer).ParentNode()).GetStyles().Get(CssConstants.
                                                                                                         DIRECTION)) && !element.HasProperty(Property.HORIZONTAL_ALIGNMENT))
            {
                // We should only apply horizontal alignment if parent has dir attribute or direction property
                element.SetProperty(Property.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT);
            }
            // Make sure to place that after direction applier
            String align = cssProps.Get(CssConstants.TEXT_ALIGN);

            if (CssConstants.LEFT.Equals(align))
            {
                element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT);
            }
            else
            {
                if (CssConstants.RIGHT.Equals(align))
                {
                    element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT);
                }
                else
                {
                    if (CssConstants.CENTER.Equals(align))
                    {
                        element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.CENTER);
                    }
                    else
                    {
                        if (CssConstants.JUSTIFY.Equals(align))
                        {
                            element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.JUSTIFIED);
                            element.SetProperty(Property.SPACING_RATIO, 1f);
                        }
                    }
                }
            }
            String whiteSpace           = cssProps.Get(CssConstants.WHITE_SPACE);
            bool   textWrappingDisabled = CssConstants.NOWRAP.Equals(whiteSpace) || CssConstants.PRE.Equals(whiteSpace);

            element.SetProperty(Property.NO_SOFT_WRAP_INLINE, textWrappingDisabled);
            if (!textWrappingDisabled)
            {
                String overflowWrap = cssProps.Get(CssConstants.OVERFLOW_WRAP);
                if (CssConstants.ANYWHERE.Equals(overflowWrap))
                {
                    element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.ANYWHERE);
                }
                else
                {
                    if (CssConstants.BREAK_WORD.Equals(overflowWrap))
                    {
                        element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD);
                    }
                    else
                    {
                        element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.NORMAL);
                    }
                }
                String wordBreak = cssProps.Get(CssConstants.WORD_BREAK);
                if (CssConstants.BREAK_ALL.Equals(wordBreak))
                {
                    element.SetProperty(Property.SPLIT_CHARACTERS, new BreakAllSplitCharacters());
                }
                else
                {
                    if (CssConstants.KEEP_ALL.Equals(wordBreak))
                    {
                        element.SetProperty(Property.SPLIT_CHARACTERS, new KeepAllSplitCharacters());
                    }
                    else
                    {
                        if (CssConstants.BREAK_WORD.Equals(wordBreak))
                        {
                            // CSS specification cite that describes the reason for overflow-wrap overriding:
                            // "For compatibility with legacy content, the word-break property also supports
                            //  a deprecated break-word keyword. When specified, this has the same effect
                            //  as word-break: normal and overflow-wrap: anywhere, regardless of the actual value
                            //  of the overflow-wrap property."
                            element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD);
                            element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
                        }
                        else
                        {
                            element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
                        }
                    }
                }
            }
            float[] colors = new float[4];
            Color   textDecorationColor;
            float   opacity_1 = 1f;
            String  textDecorationColorProp = cssProps.Get(CssConstants.TEXT_DECORATION_COLOR);

            if (textDecorationColorProp == null || CssConstants.CURRENTCOLOR.Equals(textDecorationColorProp))
            {
                if (element.GetProperty <TransparentColor>(Property.FONT_COLOR) != null)
                {
                    TransparentColor transparentColor = element.GetProperty <TransparentColor>(Property.FONT_COLOR);
                    textDecorationColor = transparentColor.GetColor();
                    opacity_1           = transparentColor.GetOpacity();
                }
                else
                {
                    textDecorationColor = ColorConstants.BLACK;
                }
            }
            else
            {
                if (textDecorationColorProp.StartsWith("hsl"))
                {
                    logger.Error(iText.Html2pdf.LogMessageConstant.HSL_COLOR_NOT_SUPPORTED);
                    textDecorationColor = ColorConstants.BLACK;
                }
                else
                {
                    colors = CssDimensionParsingUtils.ParseRgbaColor(textDecorationColorProp);
                    textDecorationColor = new DeviceRgb(colors[0], colors[1], colors[2]);
                    opacity_1           = colors[3];
                }
            }
            String textDecorationLineProp = cssProps.Get(CssConstants.TEXT_DECORATION_LINE);

            if (textDecorationLineProp != null)
            {
                String[]          textDecorationLines = iText.IO.Util.StringUtil.Split(textDecorationLineProp, "\\s+");
                IList <Underline> underlineList       = new List <Underline>();
                foreach (String textDecorationLine in textDecorationLines)
                {
                    if (CssConstants.BLINK.Equals(textDecorationLine))
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.TEXT_DECORATION_BLINK_NOT_SUPPORTED);
                    }
                    else
                    {
                        if (CssConstants.LINE_THROUGH.Equals(textDecorationLine))
                        {
                            underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, 1 / 4f, PdfCanvasConstants.LineCapStyle
                                                            .BUTT));
                        }
                        else
                        {
                            if (CssConstants.OVERLINE.Equals(textDecorationLine))
                            {
                                underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, 9 / 10f, PdfCanvasConstants.LineCapStyle
                                                                .BUTT));
                            }
                            else
                            {
                                if (CssConstants.UNDERLINE.Equals(textDecorationLine))
                                {
                                    underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, -1 / 10f, PdfCanvasConstants.LineCapStyle
                                                                    .BUTT));
                                }
                                else
                                {
                                    if (CssConstants.NONE.Equals(textDecorationLine))
                                    {
                                        underlineList = null;
                                        // if none and any other decoration are used together, none is displayed
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                element.SetProperty(Property.UNDERLINE, underlineList);
            }
            String textIndent = cssProps.Get(CssConstants.TEXT_INDENT);

            if (textIndent != null)
            {
                UnitValue textIndentValue = CssDimensionParsingUtils.ParseLengthValueToPt(textIndent, em, rem);
                if (textIndentValue != null)
                {
                    if (textIndentValue.IsPointValue())
                    {
                        element.SetProperty(Property.FIRST_LINE_INDENT, textIndentValue.GetValue());
                    }
                    else
                    {
                        logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED
                                                              , CssConstants.TEXT_INDENT));
                    }
                }
            }
            String letterSpacing = cssProps.Get(CssConstants.LETTER_SPACING);

            if (letterSpacing != null && !CssConstants.NORMAL.Equals(letterSpacing))
            {
                UnitValue letterSpacingValue = CssDimensionParsingUtils.ParseLengthValueToPt(letterSpacing, em, rem);
                if (letterSpacingValue.IsPointValue())
                {
                    element.SetProperty(Property.CHARACTER_SPACING, letterSpacingValue.GetValue());
                }
            }
            // browsers ignore values in percents
            String wordSpacing = cssProps.Get(CssConstants.WORD_SPACING);

            if (wordSpacing != null)
            {
                UnitValue wordSpacingValue = CssDimensionParsingUtils.ParseLengthValueToPt(wordSpacing, em, rem);
                if (wordSpacingValue != null)
                {
                    if (wordSpacingValue.IsPointValue())
                    {
                        element.SetProperty(Property.WORD_SPACING, wordSpacingValue.GetValue());
                    }
                }
            }
            // browsers ignore values in percents
            String lineHeight = cssProps.Get(CssConstants.LINE_HEIGHT);

            SetLineHeight(element, lineHeight, em, rem);
            SetLineHeightByLeading(element, lineHeight, em, rem);
        }
示例#6
0
        /// <summary>Applies font styles 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 ApplyFontStyles(IDictionary <String, String> cssProps, ProcessorContext context, IStylesContainer
                                           stylesContainer, IPropertyContainer element)
        {
            float em  = CssUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE));
            float rem = context.GetCssContext().GetRootFontSize();

            if (em != 0)
            {
                element.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(em));
            }
            if (cssProps.Get(CssConstants.FONT_FAMILY) != null)
            {
                // TODO DEVSIX-2534
                IList <String> fontFamilies = FontFamilySplitter.SplitFontFamily(cssProps.Get(CssConstants.FONT_FAMILY));
                element.SetProperty(Property.FONT, fontFamilies.ToArray(new String[fontFamilies.Count]));
            }
            if (cssProps.Get(CssConstants.FONT_WEIGHT) != null)
            {
                element.SetProperty(Property.FONT_WEIGHT, cssProps.Get(CssConstants.FONT_WEIGHT));
            }
            if (cssProps.Get(CssConstants.FONT_STYLE) != null)
            {
                element.SetProperty(Property.FONT_STYLE, cssProps.Get(CssConstants.FONT_STYLE));
            }
            String cssColorPropValue = cssProps.Get(CssConstants.COLOR);

            if (cssColorPropValue != null)
            {
                TransparentColor transparentColor;
                if (!CssConstants.TRANSPARENT.Equals(cssColorPropValue))
                {
                    float[] rgbaColor = CssUtils.ParseRgbaColor(cssColorPropValue);
                    Color   color     = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
                    float   opacity   = rgbaColor[3];
                    transparentColor = new TransparentColor(color, opacity);
                }
                else
                {
                    transparentColor = new TransparentColor(ColorConstants.BLACK, 0f);
                }
                element.SetProperty(Property.FONT_COLOR, transparentColor);
            }
            // Make sure to place that before text-align applier
            String direction = cssProps.Get(CssConstants.DIRECTION);

            if (CssConstants.RTL.Equals(direction))
            {
                element.SetProperty(Property.BASE_DIRECTION, BaseDirection.RIGHT_TO_LEFT);
                element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT);
            }
            else
            {
                if (CssConstants.LTR.Equals(direction))
                {
                    element.SetProperty(Property.BASE_DIRECTION, BaseDirection.LEFT_TO_RIGHT);
                    element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT);
                }
            }
            if (stylesContainer is IElementNode && ((IElementNode)stylesContainer).ParentNode() is IElementNode && CssConstants
                .RTL.Equals(((IElementNode)((IElementNode)stylesContainer).ParentNode()).GetStyles().Get(CssConstants.
                                                                                                         DIRECTION)) && !element.HasProperty(Property.HORIZONTAL_ALIGNMENT))
            {
                // We should only apply horizontal alignment if parent has dir attribute or direction property
                element.SetProperty(Property.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT);
            }
            // Make sure to place that after direction applier
            String align = cssProps.Get(CssConstants.TEXT_ALIGN);

            if (CssConstants.LEFT.Equals(align))
            {
                element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT);
            }
            else
            {
                if (CssConstants.RIGHT.Equals(align))
                {
                    element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT);
                }
                else
                {
                    if (CssConstants.CENTER.Equals(align))
                    {
                        element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.CENTER);
                    }
                    else
                    {
                        if (CssConstants.JUSTIFY.Equals(align))
                        {
                            element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.JUSTIFIED);
                            element.SetProperty(Property.SPACING_RATIO, 1f);
                        }
                    }
                }
            }
            String whiteSpace = cssProps.Get(CssConstants.WHITE_SPACE);

            element.SetProperty(Property.NO_SOFT_WRAP_INLINE, CssConstants.NOWRAP.Equals(whiteSpace) || CssConstants.PRE
                                .Equals(whiteSpace));
            String textDecorationProp = cssProps.Get(CssConstants.TEXT_DECORATION);

            if (textDecorationProp != null)
            {
                String[]          textDecorations = iText.IO.Util.StringUtil.Split(textDecorationProp, "\\s+");
                IList <Underline> underlineList   = new List <Underline>();
                foreach (String textDecoration in textDecorations)
                {
                    if (CssConstants.BLINK.Equals(textDecoration))
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.TEXT_DECORATION_BLINK_NOT_SUPPORTED);
                    }
                    else
                    {
                        if (CssConstants.LINE_THROUGH.Equals(textDecoration))
                        {
                            underlineList.Add(new Underline(null, .75f, 0, 0, 1 / 4f, PdfCanvasConstants.LineCapStyle.BUTT));
                        }
                        else
                        {
                            if (CssConstants.OVERLINE.Equals(textDecoration))
                            {
                                underlineList.Add(new Underline(null, .75f, 0, 0, 9 / 10f, PdfCanvasConstants.LineCapStyle.BUTT));
                            }
                            else
                            {
                                if (CssConstants.UNDERLINE.Equals(textDecoration))
                                {
                                    underlineList.Add(new Underline(null, .75f, 0, 0, -1 / 10f, PdfCanvasConstants.LineCapStyle.BUTT));
                                }
                                else
                                {
                                    if (CssConstants.NONE.Equals(textDecoration))
                                    {
                                        underlineList = null;
                                        // if none and any other decoration are used together, none is displayed
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                element.SetProperty(Property.UNDERLINE, underlineList);
            }
            String textIndent = cssProps.Get(CssConstants.TEXT_INDENT);

            if (textIndent != null)
            {
                UnitValue textIndentValue = CssUtils.ParseLengthValueToPt(textIndent, em, rem);
                if (textIndentValue != null)
                {
                    if (textIndentValue.IsPointValue())
                    {
                        element.SetProperty(Property.FIRST_LINE_INDENT, textIndentValue.GetValue());
                    }
                    else
                    {
                        logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED
                                                              , CssConstants.TEXT_INDENT));
                    }
                }
            }
            String letterSpacing = cssProps.Get(CssConstants.LETTER_SPACING);

            if (letterSpacing != null && !letterSpacing.Equals(CssConstants.NORMAL))
            {
                UnitValue letterSpacingValue = CssUtils.ParseLengthValueToPt(letterSpacing, em, rem);
                if (letterSpacingValue.IsPointValue())
                {
                    element.SetProperty(Property.CHARACTER_SPACING, letterSpacingValue.GetValue());
                }
            }
            // browsers ignore values in percents
            String wordSpacing = cssProps.Get(CssConstants.WORD_SPACING);

            if (wordSpacing != null)
            {
                UnitValue wordSpacingValue = CssUtils.ParseLengthValueToPt(wordSpacing, em, rem);
                if (wordSpacingValue != null)
                {
                    if (wordSpacingValue.IsPointValue())
                    {
                        element.SetProperty(Property.WORD_SPACING, wordSpacingValue.GetValue());
                    }
                }
            }
            // browsers ignore values in percents
            String lineHeight = cssProps.Get(CssConstants.LINE_HEIGHT);

            // 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 (CssUtils.IsNumericValue(lineHeight))
                {
                    float?mult = CssUtils.ParseFloat(lineHeight);
                    if (mult != null)
                    {
                        element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, (float)mult));
                    }
                }
                else
                {
                    UnitValue lineHeightValue = CssUtils.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, 1.2f));
            }
        }
 /// <summary>Operations to perform before drawing an element.</summary>
 /// <remarks>
 /// Operations to perform before drawing an element.
 /// This includes setting stroke color and width, fill color.
 /// </remarks>
 /// <param name="context">the svg draw context</param>
 internal virtual void PreDraw(SvgDrawContext context)
 {
     if (this.attributesAndStyles != null)
     {
         PdfCanvas    currentCanvas        = context.GetCurrentCanvas();
         PdfExtGState opacityGraphicsState = new PdfExtGState();
         if (!partOfClipPath)
         {
             float generalOpacity = GetOpacity();
             {
                 // fill
                 String fillRawValue = GetAttributeOrDefault(SvgConstants.Attributes.FILL, "black");
                 this.doFill = !SvgConstants.Values.NONE.EqualsIgnoreCase(fillRawValue);
                 if (doFill && CanElementFill())
                 {
                     float            fillOpacity      = GetOpacityByAttributeName(SvgConstants.Attributes.FILL_OPACITY, generalOpacity);
                     Color            fillColor        = null;
                     TransparentColor transparentColor = GetColorFromAttributeValue(context, fillRawValue, 0, fillOpacity);
                     if (transparentColor != null)
                     {
                         fillColor   = transparentColor.GetColor();
                         fillOpacity = transparentColor.GetOpacity();
                     }
                     if (!CssUtils.CompareFloats(fillOpacity, 1f))
                     {
                         opacityGraphicsState.SetFillOpacity(fillOpacity);
                     }
                     // set default if no color has been parsed
                     if (fillColor == null)
                     {
                         fillColor = ColorConstants.BLACK;
                     }
                     currentCanvas.SetFillColor(fillColor);
                 }
             }
             {
                 // stroke
                 String strokeRawValue = GetAttributeOrDefault(SvgConstants.Attributes.STROKE, SvgConstants.Values.NONE);
                 if (!SvgConstants.Values.NONE.EqualsIgnoreCase(strokeRawValue))
                 {
                     String strokeWidthRawValue = GetAttribute(SvgConstants.Attributes.STROKE_WIDTH);
                     // 1 px = 0,75 pt
                     float strokeWidth = 0.75f;
                     if (strokeWidthRawValue != null)
                     {
                         strokeWidth = CssUtils.ParseAbsoluteLength(strokeWidthRawValue);
                     }
                     float            strokeOpacity    = GetOpacityByAttributeName(SvgConstants.Attributes.STROKE_OPACITY, generalOpacity);
                     Color            strokeColor      = null;
                     TransparentColor transparentColor = GetColorFromAttributeValue(context, strokeRawValue, strokeWidth / 2, strokeOpacity
                                                                                    );
                     if (transparentColor != null)
                     {
                         strokeColor   = transparentColor.GetColor();
                         strokeOpacity = transparentColor.GetOpacity();
                     }
                     if (!CssUtils.CompareFloats(strokeOpacity, 1f))
                     {
                         opacityGraphicsState.SetStrokeOpacity(strokeOpacity);
                     }
                     // as default value for stroke is 'none' we should not set
                     // it in case when value obtaining fails
                     if (strokeColor != null)
                     {
                         currentCanvas.SetStrokeColor(strokeColor);
                     }
                     currentCanvas.SetLineWidth(strokeWidth);
                     doStroke = true;
                 }
             }
             {
                 // opacity
                 if (!opacityGraphicsState.GetPdfObject().IsEmpty())
                 {
                     currentCanvas.SetExtGState(opacityGraphicsState);
                 }
             }
         }
     }
 }
示例#8
0
 /// <summary>
 /// Sets the
 /// <see cref="iText.Kernel.Colors.Color">color</see>
 /// of the
 /// <see cref="Border">border</see>
 /// </summary>
 /// <param name="color">The color</param>
 public virtual void SetColor(Color color)
 {
     this.transparentColor = new TransparentColor(color, this.transparentColor.GetOpacity());
 }
示例#9
0
 /// <summary>
 /// Creates a
 /// <see cref="Border">border</see>
 /// with given width,
 /// <see cref="iText.Kernel.Colors.Color">color</see>
 /// and opacity.
 /// </summary>
 /// <param name="color">the color which the border should have</param>
 /// <param name="width">the width which the border should have</param>
 /// <param name="opacity">the opacity which border should have; a float between 0 and 1, where 1 stands for fully opaque color and 0 - for fully transparent
 ///     </param>
 protected internal Border(Color color, float width, float opacity)
 {
     this.transparentColor = new TransparentColor(color, opacity);
     this.width            = width;
 }
示例#10
0
 private bool ShouldSerializeTransparentColor()
 {
     return(!TransparentColor.Equals(Color.LightGray));
 }