/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.pipeline.Pipeline#close(com.itextpdf.tool * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po) { SvgPipelineContext hcc = (SvgPipelineContext)GetLocalContext(context); ITagProcessor tp; IList <IElement> elements = null; try { tp = hcc.ResolveProcessor(t.Name, t.NameSpace); if (tp.IsStackOwner()) { // remove the element from the StackKeeper Queue if end tag is found StackKeeper tagStack; try { tagStack = hcc.Poll(); } catch (NoStackException e) { throw new PipelineException(String.Format( LocaleMessages.GetInstance().GetMessage(LocaleMessages.STACK_404), t.ToString()), e); } elements = tp.EndElement(context, t, tagStack.GetElements()); } else { elements = tp.EndElement(context, t, hcc.CurrentContent()); hcc.CurrentContent().Clear(); } if (elements != null && elements.Count > 0) { try { StackKeeper stack = hcc.Peek(); foreach (IElement elem in elements) { stack.Add(elem); } } catch (NoStackException) { //don't write definities, part of defs if (!hcc.IsDefinition()) { foreach (IElement elem in elements) { po.Add((IWritable)elem); } } } } } catch (NoTagProcessorException e) { if (!hcc.AcceptUnknown()) { throw e; } } return(GetNext()); }
public override IPipeline Init(IWorkerContext context) { try { SvgPipelineContext clone = (SvgPipelineContext)hpc.Clone(); context.Put(GetContextKey(), clone); } catch (Exception e) { String message = String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.UNSUPPORTED_CLONING), hpc.GetType().FullName); throw new PipelineException(message, e); } return(GetNext()); }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.pipeline.Pipeline#content(com.itextpdf.tool * .xml.Tag, java.lang.String, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Content(IWorkerContext context, Tag t, String text, ProcessObject po) { SvgPipelineContext hcc = (SvgPipelineContext)GetLocalContext(context); ITagProcessor tp; try { tp = hcc.ResolveProcessor(t.Name, t.NameSpace); // String ctn = null; // if (null != hcc.CharSet()) { // try { // ctn = new String(b, hcc.CharSet().Name()); // } catch (UnsupportedEncodingException e) { // throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage( // LocaleMessages.UNSUPPORTED_CHARSET), e); // } // } else { // ctn = new String(b); // } IList <IElement> elements = tp.Content(context, t, text); if (elements.Count > 0) { StackKeeper peek; try { peek = hcc.Peek(); foreach (IElement e in elements) { peek.Add(e); } } catch (NoStackException) { if (!hcc.IsDefinition()) { foreach (IElement elem in elements) { po.Add((IWritable)elem); } } // po.Add(writableElement); } } } catch (NoTagProcessorException e) { if (!hcc.AcceptUnknown()) { throw e; } } return(GetNext()); }
public Object Clone() { SvgPipelineContext newCtx = new SvgPipelineContext(); if (this.imageProvider != null) { newCtx.SetImageProvider(new CloneImageProvider(imageProvider.GetImageRootPath())); } if (null != this.charset) { newCtx.CharSet(Encoding.GetEncoding(this.charset.EncodingName)); } newCtx.SetPageSize(new Rectangle(this.pageSize)).SetLinkProvider(this.linkprovider) .SetRootTags(new List <String>(this.roottags)).AutoBookmark(this.autoBookmark) .SetTagFactory(this.tagFactory).SetAcceptUnknown(this.acceptUnknown); return(newCtx); }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.pipeline.Pipeline#open(com.itextpdf.tool. * xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po) { SvgPipelineContext hcc = (SvgPipelineContext)GetLocalContext(context); try { ITagProcessor tp = hcc.ResolveProcessor(t.Name, t.Name); if (tp.IsStackOwner()) { hcc.AddFirst(new StackKeeper(t)); } IList <IElement> content = tp.StartElement(context, t); if (content.Count > 0) { if (tp.IsStackOwner()) { StackKeeper peek; try { peek = hcc.Peek(); foreach (IElement elem in content) { peek.Add(elem); } } catch (NoStackException e) { throw new PipelineException(String.Format(LocaleMessages.STACK_404, t.ToString()), e); } } else { if (!hcc.IsDefinition()) { foreach (IElement elem in content) { po.Add((Graphic)elem); } } } } } catch (NoTagProcessorException e) { if (!hcc.AcceptUnknown()) { throw e; } } return(GetNext()); }
/** * Parses the xml data. This method configures the XMLWorker to parse * (X)HTML/CSS and accept unknown tags. Writes the output in the given * PdfWriter with the given document. * * @param writer the PdfWriter * @param doc the Document * @param in the reader * @throws IOException thrown when something went wrong with the IO */ public PdfTemplate ParseToTemplate(PdfContentByte cb, TextReader input) { CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(GetDefaultCSS()); ICSSResolver cssResolver = new StyleAttrSvgCSSResolver(cssFiles); SvgPipelineContext hpc = new SvgPipelineContext(); hpc.SetTagFactory(GetDefaultTagProcessorFactory()); PdfTemplatePipeline templatePipeline = new PdfTemplatePipeline(cb); IPipeline pipeline = new CssResolverPipeline(cssResolver, new SvgPipeline(hpc, templatePipeline)); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(); p.AddListener(worker); p.Parse(input); return(templatePipeline.GetTemplate()); }
public void AddElementsToMemoryWithId(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { //add the list of elements to the memory, for later use (see useTag) try { IDictionary <String, String> attributes = tag.Attributes; if (attributes != null) { //TODO think : what if the attribute doesn't exist or the content is the same as a previous one String id; if (attributes.TryGetValue("id", out id) && id != null) { SvgPipelineContext context = GetSvgPipelineContext(ctx); context.AddSymbolById(id, currentContent); } } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } }
public SvgPipeline(SvgPipelineContext hpc, IPipeline next) : base(next) { this.hpc = hpc; }
public Object Clone() { SvgPipelineContext newCtx = new SvgPipelineContext(); if (this.imageProvider != null) { newCtx.SetImageProvider(new CloneImageProvider(imageProvider.GetImageRootPath())); } if (null != this.charset) { newCtx.CharSet(Encoding.GetEncoding(this.charset.EncodingName)); } newCtx.SetPageSize(new Rectangle(this.pageSize)).SetLinkProvider(this.linkprovider) .SetRootTags(new List<String>(this.roottags)).AutoBookmark(this.autoBookmark) .SetTagFactory(this.tagFactory).SetAcceptUnknown(this.acceptUnknown); return newCtx; }
/** * Parses the xml data. This method configures the XMLWorker to parse * (X)HTML/CSS and accept unknown tags. Writes the output in the given * PdfWriter with the given document. * * @param writer the PdfWriter * @param doc the Document * @param in the reader * @throws IOException thrown when something went wrong with the IO */ public PdfTemplate ParseToTemplate(PdfContentByte cb, TextReader input) { CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(GetDefaultCSS()); ICSSResolver cssResolver = new StyleAttrSvgCSSResolver(cssFiles); SvgPipelineContext hpc = new SvgPipelineContext(); hpc.SetTagFactory(GetDefaultTagProcessorFactory()); PdfTemplatePipeline templatePipeline = new PdfTemplatePipeline(cb); IPipeline pipeline = new CssResolverPipeline(cssResolver, new SvgPipeline(hpc, templatePipeline)); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(); p.AddListener(worker); p.Parse(input); return templatePipeline.GetTemplate(); }
public SvgPipeline(SvgPipelineContext hpc, IPipeline next) : base(next) { this.hpc = hpc; }