/// <summary>Applies outlines to an element.</summary> /// <param name="cssProps">the CSS properties</param> /// <param name="context">the Processor context</param> /// <param name="element">the element</param> public static void ApplyOutlines(IDictionary <String, String> cssProps, ProcessorContext context, IPropertyContainer element) { float em = CssDimensionParsingUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE)); float rem = context.GetCssContext().GetRootFontSize(); Border outline = GetCertainBorder(cssProps.Get(CssConstants.OUTLINE_WIDTH), cssProps.Get(CssConstants.OUTLINE_STYLE ), GetSpecificOutlineColorOrDefaultColor(cssProps, CssConstants.OUTLINE_COLOR), em, rem); if (outline != null) { element.SetProperty(Property.OUTLINE, outline); } if (cssProps.Get(CssConstants.OUTLINE_OFFSET) != null && element.GetProperty <Border>(Property.OUTLINE) != null) { UnitValue unitValue = CssDimensionParsingUtils.ParseLengthValueToPt(cssProps.Get(CssConstants.OUTLINE_OFFSET ), em, rem); if (unitValue != null) { if (unitValue.IsPercentValue()) { LOGGER.Error("outline-width in percents is not supported"); } else { if (unitValue.GetValue() != 0) { element.SetProperty(Property.OUTLINE_OFFSET, unitValue.GetValue()); } } } } }
public virtual T1 GetProperty <T1>(int key) { Object property; if ((property = properties.Get(key)) != null || properties.ContainsKey(key)) { return((T1)property); } if (modelElement != null && ((property = modelElement.GetProperty <T1>(key)) != null || modelElement.HasProperty(key))) { return((T1)property); } // TODO in some situations we will want to check inheritance with additional info, such as parent and descendant. if (parent != null && Property.IsPropertyInherited(key) && (property = parent.GetProperty <T1>(key)) != null) { return((T1)property); } property = this.GetDefaultProperty <T1>(key); if (property != null) { return((T1)property); } return(modelElement != null?modelElement.GetDefaultProperty <T1>(key) : (T1)(Object )null); }
public virtual void PagesCountElementNodeTest() { PageCountWorker worker = new PageCountWorker(new PageCountElementNode(true, null), null); IPropertyContainer container = worker.GetElementResult(); NUnit.Framework.Assert.IsTrue(container is PageCountElement); NUnit.Framework.Assert.AreEqual(PageCountType.TOTAL_PAGE_COUNT, container.GetProperty <PageCountType?>(Html2PdfProperty .PAGE_COUNT_TYPE)); }
/// <summary>Sets the list symbol indentation.</summary> /// <param name="element">the element</param> /// <param name="em">the em value</param> private static void SetListSymbolIndent(IPropertyContainer element, float em) { if (ListSymbolPosition.INSIDE == element.GetProperty <ListSymbolPosition?>(Property.LIST_SYMBOL_POSITION)) { element.SetProperty(Property.LIST_SYMBOL_INDENT, 1.5f * em); } else { element.SetProperty(Property.LIST_SYMBOL_INDENT, 7.75f); } }
public static float GetBorderWidth(IPropertyContainer element) { Border border = element.GetProperty <Border>(Property.BORDER); Border rightBorder = element.GetProperty <Border>(Property.BORDER_RIGHT); Border leftBorder = element.GetProperty <Border>(Property.BORDER_LEFT); if (!element.HasOwnProperty(Property.BORDER_RIGHT)) { rightBorder = border; } if (!element.HasOwnProperty(Property.BORDER_LEFT)) { leftBorder = border; } float rightBorderWidth = rightBorder != null?rightBorder.GetWidth() : 0; float leftBorderWidth = leftBorder != null?leftBorder.GetWidth() : 0; return(rightBorderWidth + leftBorderWidth); }
public static float GetPaddingWidth(IPropertyContainer element) { UnitValue rightPadding = element.GetProperty <UnitValue>(Property.PADDING_RIGHT); if (null != rightPadding && !rightPadding.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(MinMaxWidthUtils)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .PADDING_RIGHT)); } UnitValue leftPadding = element.GetProperty <UnitValue>(Property.PADDING_LEFT); if (null != leftPadding && !leftPadding.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(MinMaxWidthUtils)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .PADDING_LEFT)); } float rightPaddingWidth = rightPadding != null?rightPadding.GetValue() : 0; float leftPaddingWidth = leftPadding != null?leftPadding.GetValue() : 0; return(rightPaddingWidth + leftPaddingWidth); }
/// <summary> /// Maps a single <paramref name="argument"/> to the /// first property in the <see cref="IPropertyContainer{TAttribute}"/> /// whose name matches the <see cref="KeyValuePair{TKey,TValue}.Key"/> /// </summary> /// <param name="argument"> /// A single <see cref="Argument"/> /// </param> /// <param name="optionProperties"> /// A collection of properties that have an <see cref="OptionAttribute"/> /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the 'Value' of the passed <paramref name="argument"/> /// can not be cast/converted to the type of the property. /// </exception> private static void MapCommandLineValueToOption(Argument argument, IPropertyContainer <OptionAttribute> optionProperties) { if (optionProperties.Properties == 0) { return; } try { var option = optionProperties.GetProperty(argument.CommandWithoutPrefix); option.Assign(argument.HasValue ? argument.Value : string.Empty); argument.IsMapped = true; } catch (PropertyNotFoundException) { argument.IsMapped = false; } }
private static TaggingHintKey GetOrCreateHintKey(IPropertyContainer hintOwner, bool setProperty) { TaggingHintKey hintKey = hintOwner.GetProperty <TaggingHintKey>(Property.TAGGING_HINT_KEY); if (hintKey == null) { IAccessibleElement elem = null; if (hintOwner is IAccessibleElement) { elem = (IAccessibleElement)hintOwner; } else { if (hintOwner is IRenderer && ((IRenderer)hintOwner).GetModelElement() is IAccessibleElement) { elem = (IAccessibleElement)((IRenderer)hintOwner).GetModelElement(); } } hintKey = new TaggingHintKey(elem, hintOwner is IElement); if (elem != null && StandardRoles.ARTIFACT.Equals(elem.GetAccessibilityProperties().GetRole())) { hintKey.SetArtifact(); hintKey.SetFinished(); } if (setProperty) { if (elem is ILargeElement && !((ILargeElement)elem).IsComplete()) { ((ILargeElement)elem).SetProperty(Property.TAGGING_HINT_KEY, hintKey); } else { hintOwner.SetProperty(Property.TAGGING_HINT_KEY, hintKey); } } } return(hintKey); }
/// <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); }
public static TaggingHintKey GetHintKey(IPropertyContainer container) { return(container.GetProperty <TaggingHintKey>(Property.TAGGING_HINT_KEY)); }
/// <summary> /// Gets the a property from a /// <see cref="iText.Layout.Element.ListItem"/> /// , or from the /// <see cref="iText.Layout.Element.List"/> /// (if the property) isn't declared for the list item. /// </summary> /// <param name="listItem">the list item</param> /// <param name="list">the list</param> /// <param name="propertyId">the property id</param> /// <returns>the property value</returns> private static Object GetListItemOrListProperty(IPropertyContainer listItem, IPropertyContainer list, int propertyId) { return(listItem.HasProperty(propertyId) ? listItem.GetProperty <Object>(propertyId) : list.GetProperty <Object >(propertyId)); }