/// <summary>Processes counters.</summary> /// <param name="cssProps">the CSS properties</param> /// <param name="context">the processor context</param> public static void ProcessCounters(IDictionary <String, String> cssProps, CssContext context) { String counterReset = cssProps.Get(CssConstants.COUNTER_RESET); ProcessReset(counterReset, context); String counterIncrement = cssProps.Get(CssConstants.COUNTER_INCREMENT); ProcessIncrement(counterIncrement, context); }
/// <summary>Resets the context.</summary> public virtual void Reset() { this.pdfDocument = null; this.state = new State(); this.resourceResolver.ResetCache(); this.cssContext = new CssContext(); this.linkContext = new LinkContext(); this.formFieldNameResolver.Reset(); //Reset font provider. PdfFonts shall be reseted. this.fontProvider.Reset(); this.tempFonts = null; this.outlineHandler.Reset(); this.processingInlineSvg = false; }
/// <summary> /// Instantiates a new /// <see cref="ProcessorContext"/> /// instance. /// </summary> /// <param name="converterProperties"> /// a /// <see cref="iText.Html2pdf.ConverterProperties"/> /// instance /// </param> public ProcessorContext(ConverterProperties converterProperties) { if (converterProperties == null) { converterProperties = new ConverterProperties(); } state = new State(); deviceDescription = converterProperties.GetMediaDeviceDescription(); if (deviceDescription == null) { deviceDescription = MediaDeviceDescription.GetDefault(); } fontProvider = converterProperties.GetFontProvider(); if (fontProvider == null) { fontProvider = new DefaultFontProvider(); } tagWorkerFactory = converterProperties.GetTagWorkerFactory(); if (tagWorkerFactory == null) { tagWorkerFactory = DefaultTagWorkerFactory.GetInstance(); } cssApplierFactory = converterProperties.GetCssApplierFactory(); if (cssApplierFactory == null) { cssApplierFactory = DefaultCssApplierFactory.GetInstance(); } baseUri = converterProperties.GetBaseUri(); if (baseUri == null) { baseUri = ""; } outlineHandler = converterProperties.GetOutlineHandler(); if (outlineHandler == null) { outlineHandler = new OutlineHandler(); } resourceResolver = new HtmlResourceResolver(baseUri, this, converterProperties.GetResourceRetriever()); limitOfLayouts = converterProperties.GetLimitOfLayouts(); cssContext = new CssContext(); linkContext = new LinkContext(); createAcroForm = converterProperties.IsCreateAcroForm(); formFieldNameResolver = new FormFieldNameResolver(); radioCheckResolver = new RadioCheckResolver(); immediateFlush = converterProperties.IsImmediateFlush(); metaInfo = converterProperties.GetEventCountingMetaInfo(); processingInlineSvg = false; }
private void ResolveStylesForTree(INode node, ICssResolver cssResolver, CssContext context) { if (node is IElementNode) { IElementNode element = (IElementNode)node; element.SetStyles(cssResolver.ResolveStyles((IElementNode)node, context)); if (TagConstants.HTML.Equals(element.Name())) { context.SetRootFontSize(element.GetStyles().Get(CssConstants.FONT_SIZE)); } } foreach (INode child in node.ChildNodes()) { ResolveStylesForTree(child, cssResolver, context); } }
/// <summary>Processes counters.</summary> /// <param name="cssProps">the CSS properties</param> /// <param name="context">the processor context</param> /// <param name="scope">the scope</param> public static void ProcessCounters(IDictionary <String, String> cssProps, CssContext context, INode scope) { String counterReset = cssProps.Get(CssConstants.COUNTER_RESET); if (counterReset != null) { CssCounterManager counterManager = context.GetCounterManager(); String[] @params = iText.IO.Util.StringUtil.Split(counterReset, " "); for (int i = 0; i < @params.Length; i++) { String counterName = @params[i]; int? possibleCounterValue; if (i + 1 < @params.Length && (possibleCounterValue = CssUtils.ParseInteger(@params[i + 1])) != null) { counterManager.ResetCounter(counterName, (int)possibleCounterValue, scope); i++; } else { counterManager.ResetCounter(counterName, scope); } } } String counterIncrement = cssProps.Get(CssConstants.COUNTER_INCREMENT); if (counterIncrement != null) { CssCounterManager counterManager = context.GetCounterManager(); String[] @params = iText.IO.Util.StringUtil.Split(counterIncrement, " "); for (int i = 0; i < @params.Length; i++) { String counterName = @params[i]; int? possibleIncrementValue; if (i + 1 < @params.Length && (possibleIncrementValue = CssUtils.ParseInteger(@params[i + 1])) != null) { counterManager.IncrementCounter(counterName, (int)possibleIncrementValue, scope); i++; } else { counterManager.IncrementCounter(counterName, scope); } } } }
private static void ProcessIncrement(String counterIncrement, CssContext context) { if (counterIncrement != null) { CssCounterManager counterManager = context.GetCounterManager(); String[] @params = iText.IO.Util.StringUtil.Split(counterIncrement, " "); for (int i = 0; i < @params.Length; i++) { String counterName = @params[i]; int? possibleIncrementValue; if (i + 1 < @params.Length && (possibleIncrementValue = CssDimensionParsingUtils.ParseInteger(@params[i + 1])) != null) { counterManager.IncrementCounter(counterName, (int)possibleIncrementValue); i++; } else { counterManager.IncrementCounter(counterName); } } } }
private void Test(String fileName, String elementPath, params String[] expectedStyles) { String filePath = sourceFolder + fileName; IXmlParser parser = new JsoupHtmlParser(); IDocumentNode document = parser.Parse(new FileStream(filePath, FileMode.Open, FileAccess.Read), "UTF-8"); ICssResolver cssResolver = new DefaultCssResolver(document, MediaDeviceDescription.CreateDefault(), new ResourceResolver ("")); CssContext context = new CssContext(); ResolveStylesForTree(document, cssResolver, context); IElementNode element = FindElement(document, elementPath); if (element == null) { NUnit.Framework.Assert.Fail(MessageFormatUtil.Format("Element at path \"{0}\" was not found.", elementPath )); } IDictionary <String, String> elementStyles = element.GetStyles(); ICollection <String> expectedStylesSet = new HashSet <String>(JavaUtil.ArraysAsList(expectedStyles)); ICollection <String> actualStylesSet = StylesMapToHashSet(elementStyles); NUnit.Framework.Assert.IsTrue(SetsAreEqual(expectedStylesSet, actualStylesSet), GetDifferencesMessage(expectedStylesSet , actualStylesSet)); }
/// <summary>Starts processing counters.</summary> /// <remarks> /// Starts processing counters. Pushes current counter values to counters if necessary. /// Usually it is expected that this method should be called before processing children of the element. /// </remarks> /// <param name="context">the processor context</param> /// <param name="element">the element which counters shall be processed</param> public static void StartProcessingCounters(CssContext context, IElementNode element) { CssCounterManager counterManager = context.GetCounterManager(); counterManager.PushEveryCounterToCounters(element); }
public static void ProcessCounters(IDictionary <String, String> cssProps, CssContext context, INode scope) { ProcessCounters(cssProps, context); }
public CssToken(TokenType tokenType, char ch, CssContext context) : this(tokenType, new string(ch, 1), context) { }
public CssToken(TokenType tokenType, string text, CssContext context) { m_tokenType = tokenType; m_text = text; m_context = context.Clone(); }
/// <summary>Gets the resolved page class node.</summary> /// <param name="rootNode">the root node</param> /// <param name="cssResolver">the CSS resolver</param> /// <param name="context">the CSS context</param> /// <param name="pageClasses">the page classes</param> /// <returns>the resolved page class node</returns> private static PageContextNode GetResolvedPageClassNode(INode rootNode, ICssResolver cssResolver, CssContext context, params String[] pageClasses) { PageContextNode pagesClassNode = new PageContextNode(rootNode); foreach (String pageClass in pageClasses) { pagesClassNode.AddPageClass(pageClass); } IDictionary <String, String> pageClassStyles = cssResolver.ResolveStyles(pagesClassNode, context); pagesClassNode.SetStyles(pageClassStyles); return(pagesClassNode); }
/// <summary>Gets the resolved margin boxes.</summary> /// <param name="pageClassNode">the page contex node</param> /// <param name="cssResolver">the CSS resolver</param> /// <param name="context">the CSS context</param> /// <returns>the resolved margin boxes</returns> private static IList <PageMarginBoxContextNode> GetResolvedMarginBoxes(PageContextNode pageClassNode, ICssResolver cssResolver, CssContext context) { IList <PageMarginBoxContextNode> resolvedMarginBoxes = new List <PageMarginBoxContextNode>(); foreach (String pageMarginBoxName in pageMarginBoxNames) { PageMarginBoxContextNode marginBoxNode = new PageMarginBoxContextNode(pageClassNode, pageMarginBoxName); IDictionary <String, String> marginBoxStyles = cssResolver.ResolveStyles(marginBoxNode, context); if (!marginBoxNode.ChildNodes().IsEmpty()) { marginBoxNode.SetStyles(marginBoxStyles); resolvedMarginBoxes.Add(marginBoxNode); } context.SetQuotesDepth(0); } return(resolvedMarginBoxes); }
/// <summary>Ends processing counters.</summary> /// <remarks> /// Ends processing counters. Pops values of given counter list from counters if necessary. /// Usually it is expected that this method should be called after processing cheldren of the element. /// </remarks> /// <param name="context">the processor context</param> /// <param name="element">the element which counters shall be processed</param> public static void EndProcessingCounters(CssContext context, IElementNode element) { CssCounterManager counterManager = context.GetCounterManager(); counterManager.PopEveryCounterFromCounters(element); }
/// <summary> /// Resolves a node with a /// <see cref="PageContextProperties"/> /// instance as result. /// </summary> /// <param name="rootNode">the root node to resolve</param> /// <param name="cssResolver">the CSS resolver</param> /// <param name="context">the CSS context</param> /// <param name="pageClasses">the page classes</param> /// <returns> /// the /// <see cref="PageContextProperties"/> /// for a specific node /// </returns> public static iText.Html2pdf.Attach.Impl.Layout.PageContextProperties Resolve(INode rootNode, ICssResolver cssResolver, CssContext context, params String[] pageClasses) { PageContextNode pageProps = GetResolvedPageClassNode(rootNode, cssResolver, context, pageClasses); IList <PageMarginBoxContextNode> pagesMarginBoxes = GetResolvedMarginBoxes(pageProps, cssResolver, context); return(new iText.Html2pdf.Attach.Impl.Layout.PageContextProperties(pageProps, pagesMarginBoxes)); }
private void ReadBuffer(Char[] buffer, Int32 length) { for (var i = 0; i < length; i++) { currentColumn++; if (buffer[i] == BreakLine) { currentLine++; currentColumn = 1; continue; } var newIndex = commentary.Interpret(buffer, i, length, currentLine, currentColumn); if (newIndex > i) { currentColumn += newIndex - i; i = newIndex; } if (commentary.IsCommentary || commentary.IsOpen || commentary.IsClose) { if (commentary.IsClose) commentary.Reset(); continue; } if (i > length) break; switch (buffer[i]) { case OpenScope: var ctx = CreateInstanceCssContext(GetCurrentContent()); if (context != null) context.SetGraph(ctx); context = ctx; context.Open(currentLine, currentColumn); break; case CloseScope: context.Parse(GetCurrentContent()); context.Close(currentLine, currentColumn); context = context.ParentContext; break; default: sb.Append(buffer[i]); break; } } }