Exemple #1
0
 /// <summary>
 /// Creates a new
 /// <see cref="ThTagWorker"/>
 /// instance.
 /// </summary>
 /// <param name="element">the element</param>
 /// <param name="context">the context</param>
 public ThTagWorker(IElementNode element, ProcessorContext context)
     : base(element, context)
 {
 }
Exemple #2
0
 public void AddParameters(ProcessorContext context, IDictionary <string, object> parameters)
 {
 }
Exemple #3
0
 public override void Initialize(ProcessorContext context)
 {
     base.Initialize(context);
 }
Exemple #4
0
        //            element.setProperty(Property.POSITION, LayoutPosition.FIXED);
        //            float em = CssUtils.parseAbsoluteLength(cssProps.get(CommonCssConstants.FONT_SIZE));
        //            applyLeftProperty(cssProps, element, em, Property.X);
        //            applyTopProperty(cssProps, element, em, Property.Y);
        // TODO
        /// <summary>Applies left, right, top, and bottom properties.</summary>
        /// <param name="cssProps">the CSS properties</param>
        /// <param name="context">the processor context</param>
        /// <param name="element">the element</param>
        /// <param name="position">the position</param>
        private static void ApplyLeftRightTopBottom(IDictionary <String, String> cssProps, ProcessorContext context
                                                    , IPropertyContainer element, String position)
        {
            float em  = CssUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE));
            float rem = context.GetCssContext().GetRootFontSize();

            if (CssConstants.RELATIVE.Equals(position) && cssProps.ContainsKey(CssConstants.LEFT) && cssProps.ContainsKey
                    (CssConstants.RIGHT))
            {
                // When both the right CSS property and the left CSS property are defined, the position of the element is overspecified.
                // In that case, the left value has precedence when the container is left-to-right (that is that the right computed value is set to -left),
                // and the right value has precedence when the container is right-to-left (that is that the left computed value is set to -right).
                bool isRtl = CssConstants.RTL.Equals(cssProps.Get(CssConstants.DIRECTION));
                if (isRtl)
                {
                    ApplyRightProperty(cssProps, element, em, rem, Property.RIGHT);
                }
                else
                {
                    ApplyLeftProperty(cssProps, element, em, rem, Property.LEFT);
                }
            }
            else
            {
                ApplyLeftProperty(cssProps, element, em, rem, Property.LEFT);
                ApplyRightProperty(cssProps, element, em, rem, Property.RIGHT);
            }
            ApplyTopProperty(cssProps, element, em, rem, Property.TOP);
            ApplyBottomProperty(cssProps, element, em, rem, Property.BOTTOM);
        }
Exemple #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  = 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));
            }
        }
Exemple #6
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
 }
        /*TODO Note: visibility doesn't work on "chrome" or "safari" and though it technically works on "firefox" and "edge" the results differ,
         * with "edge" surprisingly giving the closest result to expected one.
         * The supported values are 'collapse' and 'visible'. The expected behaviour for 'collapse' is not to render those cols
         * (the table layout should change ann the width should be diminished), and to clip cells that are spaned to none-collapsed one.
         * The state of the content in clipped cells is not specified*/
        /// <summary>Gets the width.</summary>
        /// <param name="resolvedCssProps">the resolved CSS properties</param>
        /// <param name="context">the processor context</param>
        /// <returns>the width</returns>
        public static UnitValue GetWidth(IDictionary <String, String> resolvedCssProps, ProcessorContext context)
        {
            //The Width is a special case, casue it should be transferred from <colgroup> to <col> but it not applied to <td> or <th>
            float  em    = CssUtils.ParseAbsoluteLength(resolvedCssProps.Get(CssConstants.FONT_SIZE));
            String width = resolvedCssProps.Get(CssConstants.WIDTH);

            return(width != null?CssUtils.ParseLengthValueToPt(width, em, context.GetCssContext().GetRootFontSize())
                       : null);
        }
Exemple #8
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     inlineHelper.FlushHangingLeaves(document);
 }
Exemple #9
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processContent(java.lang.String, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual bool ProcessContent(String content, ProcessorContext context)
 {
     inlineHelper.Add(content);
     return(true);
 }
Exemple #10
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.impl.tags.SpanTagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public override void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     base.ProcessTagChild(this, context);
     base.ProcessEnd(element, context);
 }
Exemple #11
0
 public override bool ProcessContent(String content, ProcessorContext context)
 {
     return(content == null || String.IsNullOrEmpty(content.Trim()));
 }
 public override void Init(ProcessorContext context, IStateStore root)
 {
     base.Init(context, root);
     InitStoreSerDes(context);
 }
 public virtual void InitStoreSerDes(ProcessorContext context)
 {
     keySerdes   = keySerdes == null ? context.Configuration.DefaultKeySerDes as ISerDes <K> : keySerdes;
     valueSerdes = valueSerdes == null ? context.Configuration.DefaultValueSerDes as ISerDes <V> : valueSerdes;
 }
 public override bool CanExecute(ProcessorContext context)
 {
     return(true);
 }
Exemple #15
0
 public GlobalStateUpdateTask(IGlobalStateManager globalStateManager, ProcessorTopology topology, ProcessorContext context)
 {
     this.globalStateManager = globalStateManager;
     this.topology           = topology;
     this.context            = context;
 }
Exemple #16
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.ITagWorker#processTagChild(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.html2pdf.attach.ProcessorContext)
         */
        public virtual bool ProcessTagChild(ITagWorker childTagWorker, ProcessorContext context)
        {
            bool processed = false;

            if (childTagWorker is SpanTagWorker)
            {
                bool allChildrenProcessed = true;
                foreach (IPropertyContainer propertyContainer in ((SpanTagWorker)childTagWorker).GetAllElements())
                {
                    if (propertyContainer is ILeafElement)
                    {
                        inlineHelper.Add((ILeafElement)propertyContainer);
                    }
                    else
                    {
                        if (propertyContainer is IBlockElement && CssConstants.INLINE_BLOCK.Equals(((SpanTagWorker)childTagWorker)
                                                                                                   .GetElementDisplay(propertyContainer)))
                        {
                            inlineHelper.Add((IBlockElement)propertyContainer);
                        }
                        else
                        {
                            allChildrenProcessed = ProcessBlockChild(propertyContainer) && allChildrenProcessed;
                        }
                    }
                }
                processed = allChildrenProcessed;
            }
            else
            {
                if (childTagWorker.GetElementResult() is IFormField && !(childTagWorker is IDisplayAware && CssConstants.BLOCK
                                                                         .Equals(((IDisplayAware)childTagWorker).GetDisplay())))
                {
                    inlineHelper.Add((IBlockElement)childTagWorker.GetElementResult());
                    processed = true;
                }
                else
                {
                    if (childTagWorker.GetElementResult() is AreaBreak)
                    {
                        PostProcessInlineGroup();
                        document.Add((AreaBreak)childTagWorker.GetElementResult());
                        processed = true;
                    }
                    else
                    {
                        if (childTagWorker is IDisplayAware && CssConstants.INLINE_BLOCK.Equals(((IDisplayAware)childTagWorker).GetDisplay
                                                                                                    ()) && childTagWorker.GetElementResult() is IBlockElement)
                        {
                            inlineHelper.Add((IBlockElement)childTagWorker.GetElementResult());
                            processed = true;
                        }
                        else
                        {
                            if (childTagWorker is BrTagWorker)
                            {
                                inlineHelper.Add((ILeafElement)childTagWorker.GetElementResult());
                                processed = true;
                            }
                            else
                            {
                                if (childTagWorker is ImgTagWorker && childTagWorker.GetElementResult() is IElement && !CssConstants.BLOCK
                                    .Equals(((ImgTagWorker)childTagWorker).GetDisplay()))
                                {
                                    inlineHelper.Add((ILeafElement)childTagWorker.GetElementResult());
                                    processed = true;
                                }
                                else
                                {
                                    if (childTagWorker.GetElementResult() != null)
                                    {
                                        processed = ProcessBlockChild(childTagWorker.GetElementResult());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(processed);
        }
Exemple #17
0
 /// <summary>
 /// Creates a new
 /// <see cref="TitleTagWorker"/>
 /// instance.
 /// </summary>
 /// <param name="element">the element</param>
 /// <param name="context">the context</param>
 public TitleTagWorker(IElementNode element, ProcessorContext context)
 {
 }
Exemple #18
0
 /// <summary>Processes the page rules.</summary>
 /// <param name="rootNode">the root node</param>
 /// <param name="cssResolver">the css resolver</param>
 /// <param name="context">the context</param>
 public virtual void ProcessPageRules(INode rootNode, ICssResolver cssResolver, ProcessorContext context)
 {
     ((HtmlDocumentRenderer)document.GetRenderer()).ProcessPageRules(rootNode, cssResolver, context);
 }
Exemple #19
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processTagChild(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual bool ProcessTagChild(ITagWorker childTagWorker, ProcessorContext context)
 {
     return(false);
 }
        /// <summary>Adds the outline.</summary>
        /// <param name="tagWorker">the tag worker</param>
        /// <param name="element">the element</param>
        /// <param name="context">the processor context</param>
        /// <returns>the outline handler</returns>
        internal virtual OutlineHandler AddOutline(ITagWorker tagWorker, IElementNode element, ProcessorContext context
                                                   )
        {
            String tagName = element.Name();

            if (null != tagWorker && HasTagPriorityMapping(tagName) && context.GetPdfDocument() != null)
            {
                int level = (int)GetTagPriorityMapping(tagName);
                if (null == currentOutline)
                {
                    currentOutline = context.GetPdfDocument().GetOutlines(false);
                }
                PdfOutline parent = currentOutline;
                while (!levelsInProcess.IsEmpty() && level <= levelsInProcess.JGetFirst())
                {
                    parent = parent.GetParent();
                    levelsInProcess.JRemoveFirst();
                }
                String content = ((JsoupElementNode)element).Text();
                if (String.IsNullOrEmpty(content))
                {
                    content = GetUniqueID(tagName);
                }
                PdfOutline outline     = parent.AddOutline(content);
                String     destination = DESTINATION_PREFIX + GetUniqueID(DESTINATION_PREFIX);
                outline.AddDestination(PdfDestination.MakeDestination(new PdfString(destination)));
                destinationsInProcess.AddFirst(destination);
                levelsInProcess.AddFirst(level);
                currentOutline = outline;
            }
            return(this);
        }
Exemple #21
0
 ///<inheritdoc/>
 public bool ShouldProcess(PropertyInfo property, ProcessorContext context)
 {
     return(property.IsAutomatic);
 }
        private static IList <BackgroundImage> GetBackgroundImagesList(IList <String> backgroundImagesArray, ProcessorContext
                                                                       context, float em, float rem, IList <String> backgroundPositionXArray, IList <String> backgroundPositionYArray
                                                                       , IList <IList <String> > backgroundSizeArray, IList <String> backgroundBlendModeArray, IList <String> backgroundRepeatArray
                                                                       , IList <String> backgroundClipArray, IList <String> backgroundOriginArray)
        {
            IList <BackgroundImage> backgroundImagesList = new List <BackgroundImage>();

            for (int i = 0; i < backgroundImagesArray.Count; ++i)
            {
                String backgroundImage = backgroundImagesArray[i];
                if (backgroundImage == null || CssConstants.NONE.Equals(backgroundImage))
                {
                    continue;
                }
                BackgroundPosition position = ApplyBackgroundPosition(backgroundPositionXArray, backgroundPositionYArray,
                                                                      i, em, rem);
                BlendMode        blendMode    = ApplyBackgroundBlendMode(backgroundBlendModeArray, i);
                bool             imageApplied = false;
                BackgroundRepeat repeat       = ApplyBackgroundRepeat(backgroundRepeatArray, i);
                BackgroundBox    clip         = GetBackgroundBoxProperty(backgroundClipArray, i, BackgroundBox.BORDER_BOX);
                BackgroundBox    origin       = GetBackgroundBoxProperty(backgroundOriginArray, i, BackgroundBox.PADDING_BOX);
                if (CssGradientUtil.IsCssLinearGradientValue(backgroundImage))
                {
                    imageApplied = ApplyLinearGradient(backgroundImage, backgroundImagesList, blendMode, position, em, rem, repeat
                                                       , clip, origin);
                }
                else
                {
                    PdfXObject image = context.GetResourceResolver().RetrieveImageExtended(CssUtils.ExtractUrl(backgroundImage
                                                                                                               ));
                    imageApplied = ApplyBackgroundImage(image, backgroundImagesList, repeat, blendMode, position, clip, origin
                                                        );
                }
                if (imageApplied)
                {
                    ApplyBackgroundSize(backgroundSizeArray, em, rem, i, backgroundImagesList[backgroundImagesList.Count - 1]);
                }
            }
            return(backgroundImagesList);
        }
 public void SetGlobalProcessorContext(ProcessorContext processorContext)
 {
     context = processorContext;
 }
Exemple #24
0
 /// <summary>Instantiates a new default html processor.</summary>
 /// <param name="converterProperties">the converter properties</param>
 public DefaultHtmlProcessor(ConverterProperties converterProperties)
 {
     this.context = new ProcessorContext(converterProperties);
 }
Exemple #25
0
 public virtual void Init(ProcessorContext context, IStateStore root) => wrapped.Init(context, root);
Exemple #26
0
        /// <summary>Sets properties to top-level layout elements converted from HTML.</summary>
        /// <remarks>
        /// Sets properties to top-level layout elements converted from HTML.
        /// This enables features set by user via HTML converter API and also changes properties defaults
        /// to the ones specific to HTML-like behavior.
        /// </remarks>
        /// <param name="cssProperties">HTML document-level css properties.</param>
        /// <param name="context">processor context specific to the current HTML conversion.</param>
        /// <param name="propertyContainer">top-level layout element converted from HTML.</param>
        public static void SetConvertedRootElementProperties(IDictionary <String, String> cssProperties, ProcessorContext
                                                             context, IPropertyContainer propertyContainer)
        {
            propertyContainer.SetProperty(Property.COLLAPSING_MARGINS, true);
            propertyContainer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
            propertyContainer.SetProperty(Property.FONT_PROVIDER, context.GetFontProvider());
            if (context.GetTempFonts() != null)
            {
                propertyContainer.SetProperty(Property.FONT_SET, context.GetTempFonts());
            }
            // TODO DEVSIX-2534
            IList <String> fontFamilies = FontFamilySplitter.SplitFontFamily(cssProperties.Get(CssConstants.FONT_FAMILY
                                                                                               ));

            if (fontFamilies != null && !propertyContainer.HasOwnProperty(Property.FONT))
            {
                propertyContainer.SetProperty(Property.FONT, fontFamilies.ToArray(new String[0]));
            }
        }
Exemple #27
0
 public bool CanBeExecuted(ProcessorContext context, object parameter = null)
 {
     return(true);
 }
Exemple #28
0
        private ITagWorker ProcessRunningElement(ITagWorker tagWorker, IElementNode element, ProcessorContext context
                                                 )
        {
            String runningPrefix = CssConstants.RUNNING + "(";
            String positionVal;
            int    endBracketInd;

            if (element.GetStyles() == null || (positionVal = element.GetStyles().Get(CssConstants.POSITION)) == null ||
                !positionVal.StartsWith(runningPrefix) ||
                // closing bracket should be there and there should be at least one symbol between brackets
                (endBracketInd = positionVal.IndexOf(")", StringComparison.Ordinal)) <= runningPrefix.Length)
            {
                return(tagWorker);
            }
            String runningElemName = positionVal.JSubstring(runningPrefix.Length, endBracketInd).Trim();

            if (String.IsNullOrEmpty(runningElemName))
            {
                return(tagWorker);
            }
            // TODO For now the whole ITagWorker of the running element is preserved inside RunningElementContainer
            // for the sake of future processing in page margin box. This is somewhat a workaround and storing
            // tag workers might be easily seen as something undesirable, however at least for now it seems to be
            // most suitable solution because:
            // - in any case, processing of the whole running element with it's children should be done in
            //   "normal flow", i.e. in DefaultHtmlProcessor, based on the spec that says that element should be
            //   processed as it was still in the same position in DOM, but visually as if "display: none" was set.
            // - the whole process would need to be repeated in PageContextProcessor again, so it's a double work;
            //   also currently there is still no convenient way for unifying the processing here and in
            //   PageContextProcessor, currently only running elements require processing of the whole hierarchy of
            //   children outside of the default DOM processing and also it's unclear whether this code would be suitable
            //   for the simplified approach of processing all other children of page margin boxes.
            // - ITagWorker is only publicly passed to the constructor, but there is no exposed way to get it out of
            //   RunningElementContainer, so it would be fairly easy to change this approach in future if needed.
            RunningElementContainer runningElementContainer = new RunningElementContainer(element, tagWorker);

            context.GetCssContext().GetRunningManager().AddRunningElement(runningElemName, runningElementContainer);
            return(new RunningElementTagWorker(runningElementContainer));
        }
Exemple #29
0
 public override bool CanExecute(ProcessorContext context)
 {
     return(context.Configuration.WriteStampFile);
 }
 /// <summary>
 /// Creates a new
 /// <see cref="DefaultCssResolver"/>
 /// instance.
 /// </summary>
 /// <param name="treeRoot">the root node</param>
 /// <param name="context">the processor context</param>
 public DefaultCssResolver(INode treeRoot, ProcessorContext context)
 {
     this.deviceDescription = context.GetDeviceDescription();
     CollectCssDeclarations(treeRoot, context.GetResourceResolver(), context.GetCssContext());
     CollectFonts();
 }