/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { List<Chunk> sanitizedChunks = HTMLUtils.Sanitize(content, false); List<IElement> l = new List<IElement>(1); foreach (Chunk sanitized in sanitizedChunks) { HtmlPipelineContext myctx; try { myctx = GetHtmlPipelineContext(ctx); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } if (tag.CSS.ContainsKey(CSS.Property.TAB_INTERVAL)) { TabbedChunk tabbedChunk = new TabbedChunk(sanitized.Content); if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT)) { tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]); } l.Add(GetCssAppliers().Apply(tabbedChunk, tag,myctx)); } else if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT)) { TabbedChunk tabbedChunk = new TabbedChunk(sanitized.Content); tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]); l.Add(GetCssAppliers().Apply(tabbedChunk, tag, myctx)); } else { l.Add(GetCssAppliers().Apply(sanitized, tag, myctx)); } } return l; }
/// <summary> /// This method is called when a closing tag has been encountered of the /// ITagProcessor implementation that is mapped to the tag. /// </summary> /// <param name="ctx"></param> /// <param name="tag">the tag encountered</param> /// <param name="currentContent"> /// a list of content possibly created by TagProcessing of inner tags, and by startElement and /// content methods of this ITagProcessor /// </param> /// <returns>the resulting element to add to the document or a content stack.</returns> public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IList<IElement> list = new List<IElement>(); var htmlPipelineContext = GetHtmlPipelineContext(ctx); list.Add(GetCssAppliers().Apply(new Chunk((iTextSharp.text.Image)GetCssAppliers().Apply(_image, tag, htmlPipelineContext), 0, 0, true), tag, htmlPipelineContext)); return list; }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { try { Paragraph p = null; IList<IElement> l = new List<IElement>(1); foreach (IElement e in currentContent) { if (e is Paragraph) { if (p != null) { l.Add(GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx))); p = null; } l.Add(e); } else { if (p == null) { p = new Paragraph(); } p.Add(e); } } if (p != null) { l.Add(GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx))); } return l; } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { if (currentContent.Count > 0) { IDictionary<string, string> attributes = tag.Attributes; var retval = base.End(ctx, tag, currentContent); foreach (PdfPTable table in retval.OfType<PdfPTable>()) { if (attributes.ContainsKey("summary") && attributes.ContainsKey("caption")) { table.SetAccessibleAttribute(PdfName.SUMMARY, new PdfString(attributes["summary"].ToString())); table.SetAccessibleAttribute(PdfName.CAPTION, new PdfString(attributes["caption"].ToString())); table.KeepRowsTogether(0); } else { throw new Exception("Table is missing attributes. Summary and Caption must be available."); } } return retval; } return new List<IElement>(); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.pipeline.IPipeline#open(com.itextpdf.tool. * xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po) { HtmlPipelineContext hcc = (HtmlPipelineContext)GetLocalContext(context); try { ITagProcessor tp = hcc.ResolveProcessor(t.Name, t.NameSpace); 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 { foreach (IElement elem in content) { hcc.CurrentContent().Add(elem); } } } } catch (NoTagProcessorException e) { if (!hcc.AcceptUnknown()) { throw e; } } return GetNext(); }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.ITagProcessor#startElement(com.itextpdf.tool.xml.Tag) */ public override IList<IElement> Start(IWorkerContext ctx, Tag tag) { String enc; tag.Attributes.TryGetValue("encoding", out enc); if (null != enc) { try { Encoding encd = null; try { encd = Encoding.GetEncoding(enc); } catch (ArgumentException) { } if (encd != null) { GetHtmlPipelineContext(ctx).CharSet(encd); if (LOGGER.IsLogging(Level.DEBUG)) { LOGGER.Debug( String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.META_CC), enc)); } } else { if (LOGGER.IsLogging(Level.DEBUG)) { LOGGER.Debug( String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.META_404), GetHtmlPipelineContext(ctx) .CharSet() == null ? "" : GetHtmlPipelineContext(ctx).CharSet().WebName)); } } } catch (NoCustomContextException) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT)); } } return new List<IElement>(0); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { List<IElement> l = new List<IElement>(1); if (currentContent.Count > 0) { IList<IElement> currentContentToParagraph = CurrentContentToParagraph(currentContent, true, true, tag, ctx); foreach (IElement p in currentContentToParagraph) { ((Paragraph) p).Role = (getHeaderRole(GetLevel(tag))); } ParentTreeUtil pt = new ParentTreeUtil(); try { HtmlPipelineContext context = GetHtmlPipelineContext(ctx); bool oldBookmark = context.AutoBookmark(); if (pt.GetParentTree(tag).Contains(HTML.Tag.TD)) context.AutoBookmark(false); if (context.AutoBookmark()) { Paragraph title = new Paragraph(); foreach (IElement w in currentContentToParagraph) { title.Add(w); } l.Add(new WriteH(context, tag, this, title)); } context.AutoBookmark(oldBookmark); } catch (NoCustomContextException e) { if (LOGGER.IsLogging(Level.ERROR)) { LOGGER.Error(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HEADER_BM_DISABLED), e); } } l.AddRange(currentContentToParagraph); } return l; }
public override IList<IElement> Start(IWorkerContext ctx, Tag tag) { List<IElement> l = new List<IElement>(1); try { IDictionary<String, String> css = tag.CSS; if (css.ContainsKey(CSS.Property.BACKGROUND_COLOR)) { Type type = typeof(PdfWriterPipeline); MapContext pipeline = (MapContext)ctx.Get(type.FullName); if (pipeline != null) { Document document = (Document)pipeline[PdfWriterPipeline.DOCUMENT]; if (document != null) { Rectangle rectangle = new Rectangle(document.Left, document.Bottom, document.Right, document.Top, document.PageSize.Rotation); rectangle.BackgroundColor = HtmlUtilities.DecodeColor(css[CSS.Property.BACKGROUND_COLOR]); PdfBody body = new PdfBody(rectangle); l.Add(body); } } } } catch (NoCustomContextException e) {} return l; }
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IDictionary<String, String> attributes = tag.Attributes; if (attributes != null) { float rx = GetAttribute(RX, attributes); float ry = GetAttribute(RY, attributes); if (rx <= 0 || ry <= 0) { return new List<IElement>(0); } float cx = GetAttribute(CX, attributes); float cy = GetAttribute(CY, attributes); IList<IElement> l = new List<IElement>(1); l.Add(new Ellipse(cx, cy, rx, ry, tag.CSS)); return l; } else { return new List<IElement>(0); } }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { TableRowElement row = null; IList<IElement> l = new List<IElement>(1); if (Util.EqualsIgnoreCase(tag.Parent.Name, HTML.Tag.THEAD)) { row = new TableRowElement(currentContent, TableRowElement.Place.HEADER); } else if (Util.EqualsIgnoreCase(tag.Parent.Name, HTML.Tag.TBODY)) { row = new TableRowElement(currentContent, TableRowElement.Place.BODY); } else if (Util.EqualsIgnoreCase(tag.Parent.Name, HTML.Tag.TFOOT)) { row = new TableRowElement(currentContent, TableRowElement.Place.FOOTER); } else { row = new TableRowElement(currentContent, TableRowElement.Place.BODY); } int direction = GetRunDirection(tag); if (direction != PdfWriter.RUN_DIRECTION_DEFAULT) { foreach (HtmlCell cell in row.Content) { if (cell.RunDirection == PdfWriter.RUN_DIRECTION_DEFAULT) { cell.RunDirection = direction; } } } l.Add(row); return l; }
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { if (tag.Name == "th") { IDictionary<string, string> attributes = tag.Attributes; var retval = base.End(ctx, tag, currentContent); PdfPCell cell = (PdfPCell)retval[0]; cell.Role = PdfName.TH; if (attributes.ContainsKey("scope")) { switch (attributes["scope"]) { case "col": cell.SetAccessibleAttribute(PdfName.SCOPE, PdfName.COLUMN); break; case "row": cell.SetAccessibleAttribute(PdfName.SCOPE, PdfName.ROW); break; case "both": cell.SetAccessibleAttribute(PdfName.SCOPE, PdfName.BOTH); break; default: throw new Exception("Scope is missing or unsupported."); } } return retval; } return new List<IElement>(); }
public override IList<IElement> Start(IWorkerContext ctx, Tag tag) { float x = 0, y = 0; IDictionary<String, String> attributes = tag.Attributes; if(attributes != null){ try { if (attributes.ContainsKey(X)) { x = int.Parse(attributes[X]); } } catch { // TODO: handle exception } try { if (attributes.ContainsKey(Y)) { y = int.Parse(attributes[Y]); } } catch { // TODO: handle exception } } IList<IElement> l = new List<IElement>(0); Chunk c = new ChunkCssApplier().Apply(new Chunk(""), tag); l.Add(new Text(c, x, y, tag.CSS, Split(attributes[DX]), Split(attributes[DY]))); return l; }
public void MessageReceived(IWorkerContext workerContext) { var workerQueue = workerContext.InboundSocket.Recv<Queue<Type>>(); var accumulator = workerContext.InboundSocket.Recv<int>(); var operandQueue = workerContext.InboundSocket.Recv<Queue<int>>(); var resultAddress = workerContext.InboundSocket.Recv<string>(); var nextOperand = operandQueue.Dequeue(); accumulator *= nextOperand; using(var outboundSocket = workerContext.ZmqContext.Socket(ZMQ.SocketType.PUSH)) { outboundSocket.HWM = 1000; if(workerQueue.Any()) { outboundSocket.Connect(workerContext.Configuration["outboundAddress"]); outboundSocket.SendMore(workerQueue.Dequeue()); outboundSocket.SendMore(workerQueue); outboundSocket.SendMore(accumulator); outboundSocket.SendMore(operandQueue); outboundSocket.Send(resultAddress); } else { outboundSocket.Connect(resultAddress); outboundSocket.Send(accumulator); } } }
/** * Called in <code>open</code>, <code>content</code> and <code>close</code> to pass the {@link Writable}s to the handler * @param po */ private void Consume(IWorkerContext context, ProcessObject po) { if (po.ContainsWritable()) { IWritable w = null; while ( null != (w =po.Poll())) { handler.Add(w); } } }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { IList<IElement> l = new List<IElement>(1); if (null != content && content.Length > 0) { l.Add(new ChunkCssApplier().Apply(new Chunk(content), tag)); } return l; }
public GameQueueAutoStartCommand(IGameRepository gameRepository, IWorkerContext workerContext, TimeSpan gameQueueTimeoutWaiting, int maxNumberOfPlayersPerGame) { this.gameRepository = gameRepository; this.workerContext = workerContext; this.gameQueueTimeoutWaiting = gameQueueTimeoutWaiting; this.maxNumberOfPlayersPerGame = maxNumberOfPlayersPerGame; }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IDictionary<String, String> attributes = tag.Attributes; String src; attributes.TryGetValue(HTML.Attribute.SRC, out src); iTextSharp.text.Image img = null; IList<IElement> l = new List<IElement>(1); if (!string.IsNullOrEmpty(src)) { src = XMLUtil.UnescapeXML(src); src = src.Trim(); // check if the image was already added once try { if (logger.IsLogging(Level.TRACE)) { logger.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_USE), src)); } try { img = new ImageRetrieve(GetHtmlPipelineContext(ctx).GetImageProvider()).RetrieveImage(src); } catch (NoImageProviderException) { img = new ImageRetrieve().RetrieveImage(src); } } catch (IOException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_RETRIEVE_FAIL), src), e); } } catch (NoImageException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error("", e); } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } if (null != img) { img.ScaleToFitLineWhenOverflow = true; String width; attributes.TryGetValue(HTML.Attribute.WIDTH, out width); float widthInPoints = utils.ParsePxInCmMmPcToPt(width); String height; attributes.TryGetValue(HTML.Attribute.HEIGHT, out height); float heightInPoints = utils.ParsePxInCmMmPcToPt(height); if (widthInPoints > 0 && heightInPoints > 0) { img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (widthInPoints > 0) { heightInPoints = img.Height * widthInPoints / img.Width; img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (heightInPoints > 0) { widthInPoints = img.Width * heightInPoints / img.Height; img.ScaleAbsolute(widthInPoints, heightInPoints); } try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); l.Add(GetCssAppliers().Apply(new Chunk((iTextSharp.text.Image) GetCssAppliers().Apply(img, tag, htmlPipelineContext), 0, 0, true), tag, htmlPipelineContext)); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } } return l; }
public override IPipeline Init(IWorkerContext context) { try { ObjectContext<ICSSResolver> mc = new ObjectContext<ICSSResolver>(resolver.Clear()); context.Put(GetContextKey(), mc); return base.Init(context); } catch (CssResolverException e) { throw new PipelineException(e); } }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IList<IElement> l = new List<IElement>(1); ListItem li = new ListItem(); foreach (IElement e in currentContent) { li.Add(e); } l.Add(li); // css applying is handled in the OrderedUnorderedList Class. return l; }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.SanitizeInline(content); IList<IElement> l = new List<IElement>(1); if (sanitized.Length > 0) { l.Add(new ChunkCssApplier().Apply(new Chunk(sanitized), tag)); } return l; }
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IList<IElement> elems = new List<IElement>(); IDictionary<String, String> attributes = tag.Attributes; if (attributes != null && attributes.ContainsKey(POINTS)) { String str = attributes[POINTS]; StringTokenizer tokenizer = new StringTokenizer(CleanPath(str), ", \t\n\r\f"); IList<String> values = new List<String>(); while (tokenizer.HasMoreTokens()) { String value = tokenizer.NextToken().Trim(); //System.out.Println(value); values.Add(value); } PathBean.Builder pathBuilder = new PathBean.Builder(); if (values.Count % 2 == 1) { values.RemoveAt(values.Count - 1); } if (values.Count % 2 == 0) { for (int i = 0; i < (values.Count / 2); i++) { PathItem.Builder itemBuilder = new PathItem.Builder(); if (i == 0) { itemBuilder.SetType('M'); } else { itemBuilder.SetType('L'); } itemBuilder.AddCoordinate(values[i * 2]); itemBuilder.AddCoordinate(values[(i * 2) + 1]); pathBuilder.SetPathItem(itemBuilder.Build()); } } if (tag.Name.Equals(SvgTagNames.POLYGON)) { PathItem.Builder itemBuilder = new PathItem.Builder(); itemBuilder.SetType('z'); pathBuilder.SetPathItem(itemBuilder.Build()); } elems.Add(new Path(pathBuilder.Build(), tag.CSS)); return elems; } else { return new List<IElement>(0); } }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.TagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { HtmlCell cell = new HtmlCell(); try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); cell = new HtmlCellCssApplier().Apply(cell, tag, htmlPipelineContext, htmlPipelineContext); } catch (NoCustomContextException e1) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1); } IList<IElement> l = new List<IElement>(1); IList<IElement> chunks = new List<IElement>(); foreach (IElement e in currentContent) { if (e is Chunk || e is NoNewLineParagraph || e is LineSeparator) { if (e == Chunk.NEWLINE) { int index = currentContent.IndexOf(e); if (index == currentContent.Count - 1) { continue; } else { IElement nextElement = currentContent[index + 1]; if (nextElement is Paragraph) { continue; } if (chunks.Count == 0) { continue; } } } else if (e is LineSeparator) { chunks.Add(Chunk.NEWLINE); } chunks.Add(e); continue; } else if (chunks.Count > 0) { Paragraph p = new Paragraph(); p.MultipliedLeading = 1.2f; p.AddAll(chunks); p.Alignment = cell.HorizontalAlignment; cell.AddElement(p); chunks.Clear(); } if (e is Paragraph) { ((Paragraph)e).Alignment = cell.HorizontalAlignment; } cell.AddElement(e); } if ( chunks.Count > 0 ) { Paragraph p = new Paragraph(); p.MultipliedLeading = 1.2f; p.AddAll(chunks); p.Alignment = cell.HorizontalAlignment; cell.AddElement(p); } l.Add(cell); return l; }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.SanitizeInline(content); IList<IElement> l = new List<IElement>(1); if (sanitized.Length > 0) { Chunk c = new ChunkCssApplier().Apply(new Chunk(sanitized), tag); // NoNewLineParagraph noNewLineParagraph = new NoNewLineParagraphCssApplier(configuration).Apply(new NoNewLineParagraph(c), tag); l.Add(c); } return l; }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { IList<IElement> l = new List<IElement>(1); if (null != content && content.Length > 0) { try { l.Add(CssAppliers.GetInstance().Apply(new Chunk(content), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } return l; }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { try { IList<IElement> list = new List<IElement>(); HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); LineSeparator lineSeparator = (LineSeparator) GetCssAppliers().Apply(new LineSeparator(), tag, htmlPipelineContext); list.Add(lineSeparator); return list; } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List, com.itextpdf.text.Document) */ public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IList<IElement> l = new List<IElement>(1); try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext); l.Add(newLine); } catch (NoCustomContextException exc) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc); } return l; }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.util.List, * com.itextpdf.text.Document, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.Sanitize(content); IList<IElement> l = new List<IElement>(1); if (sanitized.Length > 0) { try { l.Add(GetCssAppliers().Apply(new NoNewLineParagraph(sanitized), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } } return l; }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.SanitizeInline(content); IList<IElement> l = new List<IElement>(1); if (sanitized.Length > 0) { try { l.Add(GetCssAppliers().Apply(new Chunk(sanitized), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } return l; }
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IDictionary<String, String> attributes = tag.Attributes; if(attributes != null){ IList<IElement> l = new List<IElement>(1); l.Add(new Line(GetAttribute(X1, attributes), GetAttribute(Y1, attributes), GetAttribute(X2, attributes), GetAttribute(Y2, attributes), tag.CSS)); return l; } else { return new List<IElement>(0); } }
public override IList<IElement> Start(IWorkerContext ctx, Tag tag) { try { SvgPipelineContext context = GetSvgPipelineContext(ctx); context.SetDefinition(true); } catch (NoCustomContextException e) { Console.WriteLine(e.StackTrace); } return new List<IElement>(0); }
protected WorkerHandler(IMapper mapper, IComponentContext scope, IWorkerContext <TOut> context) : base(mapper, context, scope) { HandlerDelegates = scope.Resolve <WorkerHandlerDelegates <TRequestDto, TOut> >(); scope.Resolve <IEnumerable <IWorkerHandlerDelegates <TRequestDto, TOut> > >().ToList(); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { return(CurrentContentToParagraph(currentContent, false, true, tag, ctx)); }
/** * Utility method that fetches the CSSResolver from the if any and if it uses the default key. * * @return CSSResolver * @throws NoCustomContextException if the context of the * {@link CssResolverPipeline} could not be found. */ public virtual ICSSResolver GetCSSResolver(IWorkerContext context) { return(((ObjectContext <ICSSResolver>)context.Get(typeof(CssResolverPipeline).FullName)).Get()); //return (ICSSResolver) ((MapContext)ctx.Get(typeof(CssResolverPipeline).FullName))[CssResolverPipeline.CSS_RESOLVER]; }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public virtual IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { return(new List <IElement>(0)); }
public GameQueueAutoStartCommand(IGameRepository gameRepository, IWorkerContext workerContext) : this(gameRepository, workerContext, ConfigurationConstants.WaitingForPlayersTimeout, ConfigurationConstants.MaxNumberOfPlayersPerGame) { }
public StatisticsService(IWorkerContext context) { _context = context; }
//<rect x="60" y="60" width="" height="" rx="5" cy="5"/> public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { IDictionary <String, String> attributes = tag.Attributes; if (attributes != null) { //width and height wrong or not existing -> draw nothing float width, height; try { width = int.Parse(attributes["width"]); } catch { return(new List <IElement>(0)); } try { height = int.Parse(attributes["height"]); } catch { return(new List <IElement>(0)); } if (width <= 0 || height <= 0) { return(new List <IElement>(0)); } //x,y missing or wrong -> just zero, negative value is acceptable float x = 0, y = 0, rx = 0, ry = 0; try { x = int.Parse(attributes["x"]); } catch { // TODO: handle exception } try { y = int.Parse(attributes["y"]); } catch { // TODO: handle exception } //if one of these is wrong or missing, take the other ones value //if the value is specified but less or equal than 0 -> no rounding try { rx = int.Parse(attributes["rx"]); } catch { rx = -1; } try { ry = int.Parse(attributes["ry"]); } catch { ry = -1; } //one out of the two is zero (but was specified) if ((attributes.ContainsKey("rx") && rx == 0) || (attributes.ContainsKey("ry") && ry == 0)) { rx = 0; ry = 0; } else //copy the wrong values { if (rx <= 0) { rx = ry; } if (ry <= 0) { ry = rx; } if (rx <= 0 && ry <= 0) { rx = 0; ry = 0; } } IList <IElement> l = new List <IElement>(1); l.Add(new graphic.Rectangle(x, y, width, height, rx, ry, tag.CSS)); return(l); } else { return(new List <IElement>(0)); } }
/** * Adds currentContent list to a paragraph element. If addNewLines is true a * Paragraph object is returned, else a NoNewLineParagraph object is * returned. * * @param currentContent IList<IElement> of the current elements to be added. * @param addNewLines bool to declare which paragraph element should be * returned, true if new line should be added or not. * @param applyCSS true if CSS should be applied on the paragraph * @param tag the relevant tag * @return a List with paragraphs */ public virtual IList <IElement> CurrentContentToParagraph(IList <IElement> currentContent, bool addNewLines, bool applyCSS, Tag tag, IWorkerContext ctx) { try { IList <IElement> list = new List <IElement>(); if (currentContent.Count > 0) { if (addNewLines) { Paragraph p = new Paragraph(float.NaN); foreach (IElement e in currentContent) { p.Add(e); } if (applyCSS) { p = (Paragraph)CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx)); } list.Add(p); } else { NoNewLineParagraph p = new NoNewLineParagraph(float.NaN); foreach (IElement e in currentContent) { p.Add(e); } p = (NoNewLineParagraph)CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx)); list.Add(p); } } return(list); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { IDictionary <String, String> attributes = tag.Attributes; String src; attributes.TryGetValue(HTML.Attribute.SRC, out src); iTextSharp.text.Image img = null; IList <IElement> l = new List <IElement>(1); if (!string.IsNullOrEmpty(src)) { src = XMLUtil.UnescapeXML(src); src = src.Trim(); // check if the image was already added once try { if (logger.IsLogging(Level.TRACE)) { logger.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_USE), src)); } try { img = new ImageRetrieve(GetHtmlPipelineContext(ctx).GetImageProvider()).RetrieveImage(src); } catch (NoImageProviderException) { img = new ImageRetrieve().RetrieveImage(src); } } catch (IOException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_RETRIEVE_FAIL), src), e); } } catch (NoImageException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error("", e); } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } if (null != img) { img.ScaleToFitLineWhenOverflow = true; String width; attributes.TryGetValue(HTML.Attribute.WIDTH, out width); float widthInPoints = utils.ParsePxInCmMmPcToPt(width); String height; attributes.TryGetValue(HTML.Attribute.HEIGHT, out height); float heightInPoints = utils.ParsePxInCmMmPcToPt(height); if (widthInPoints > 0 && heightInPoints > 0) { img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (widthInPoints > 0) { heightInPoints = img.Height * widthInPoints / img.Width; img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (heightInPoints > 0) { widthInPoints = img.Width * heightInPoints / img.Height; img.ScaleAbsolute(widthInPoints, heightInPoints); } try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); l.Add(GetCssAppliers().Apply(new Chunk((iTextSharp.text.Image)GetCssAppliers().Apply(img, tag, htmlPipelineContext), 0, 0, true), tag, htmlPipelineContext)); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } } return(l); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.TagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { HtmlCell cell = new HtmlCell(); try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); cell = (HtmlCell)GetCssAppliers().Apply(cell, tag, htmlPipelineContext); } catch (NoCustomContextException e1) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1); } IList <IElement> l = new List <IElement>(1); IList <IElement> chunks = new List <IElement>(); IList <ListItem> listItems = new List <ListItem>(); int index = -1; foreach (IElement e in currentContent) { index++; if (e is Chunk || e is NoNewLineParagraph || e is LineSeparator) { if (listItems.Count > 0) { ProcessListItems(ctx, tag, listItems, cell); } if (e is Chunk && Chunk.NEWLINE.Content.Equals(((Chunk)e).Content)) { if (index == currentContent.Count - 1) { continue; } else { IElement nextElement = currentContent[index + 1]; if (chunks.Count > 0 && !(nextElement is Chunk) && !(nextElement is NoNewLineParagraph)) { continue; } } } else if (e is LineSeparator) { try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext); chunks.Add(newLine); } catch (NoCustomContextException exc) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc); } } chunks.Add(e); continue; } else if (e is ListItem) { if (chunks.Count > 0) { ProcessChunkItems(chunks, cell); } listItems.Add((ListItem)e); continue; } else { if (chunks.Count > 0) { ProcessChunkItems(chunks, cell); } if (listItems.Count > 0) { ProcessListItems(ctx, tag, listItems, cell); } } if (e is Paragraph) { ((Paragraph)e).Alignment = cell.HorizontalAlignment; } cell.AddElement(e); } if (chunks.Count > 0) { ProcessChunkItems(chunks, cell); } l.Add(cell); return(l); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.Pipeline#init(com.itextpdf.tool.xml.WorkerContext) */ public virtual IPipeline Init(IWorkerContext context) { return(GetNext()); }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.pipeline.IPipeline#open(com.itextpdf.tool. * xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po) { ((ObjectContext <ICSSResolver>)GetLocalContext(context)).Get().ResolveStyles(t); return(GetNext()); }
public virtual IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { Assert.AreEqual(b, content); return(new List <IElement>(0)); }
public LoginController(IWorkerContext context, IConfiguration configuration) { _context = context; userService = new WorkersService(_context, configuration); }
/* * (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) { Write(context, po, t); //writer.GetDirectContent().RestoreState(); return(GetNext()); }
/** * Calculates top or bottom spacing of the list. In HTML following possibilities exist: * <ul> * <li><b>padding-top of the ul/ol tag == 0.</b><br /> * The margin-top values of the ul/ol tag and its <b>first</b> li tag are <b>compared</b>. The total spacing before is the largest margin value and the first li's padding-top.</li> * <li><b>padding-top of the ul/ol tag != 0.</b><br /> * The margin-top or bottom values of the ul/ol tag and its first li tag are <b>accumulated</b>, along with padding-top values of both tags.</li> * <li><b>padding-bottom of the ul/ol tag == 0.</b><br /> * The margin-bottom values of the ul/ol tag and its <b>last</b> li tag are <b>compared</b>. The total spacing after is the largest margin value and the first li's padding-bottom.</li> * <li><b>padding-bottom of the ul/ol tag != 0.</b><br /> * The margin-bottom or bottom values of the ul/ol tag and its last li tag are <b>accumulated</b>, along with padding-bottom values of both tags.</li> * </ul> * @param isTop bool, if true the top spacing is calculated, if false the bottom spacing is calculated. * @param storeMarginBottom if true the calculated margin bottom value is stored for later comparison with the top margin value of the next tag. * @param tag the ul/ol tag. * @param child first or last li tag of this list. * @return float containing the spacing before or after. */ private float CalculateTopOrBottomSpacing(bool isTop, bool storeMarginBottom, Tag tag, Tag child, IWorkerContext ctx) { float totalSpacing = 0; try { HtmlPipelineContext context = GetHtmlPipelineContext(ctx); String end = isTop?"-top":"-bottom"; float ownFontSize = fst.GetFontSize(tag); float ownMargin = 0; String marginValue; tag.CSS.TryGetValue(CSS.Property.MARGIN + end, out marginValue); if (marginValue == null) { if (null != tag.Parent && GetHtmlPipelineContext(ctx).GetRootTags().Contains(tag.Parent.Name)) { ownMargin = ownFontSize; } } else { ownMargin = utils.ParseValueToPt(marginValue, ownFontSize); } float ownPadding = 0; if (tag.CSS.ContainsKey(CSS.Property.PADDING + end)) { ownPadding = utils.ParseValueToPt(tag.CSS[CSS.Property.PADDING + end], ownFontSize); } float childFontSize = fst.GetFontSize(child); float childMargin = 0; if (child.CSS.ContainsKey(CSS.Property.MARGIN + end)) { childMargin = utils.ParseValueToPt(child.CSS[CSS.Property.MARGIN + end], childFontSize); } //Margin values of this tag and its first child need to be compared if paddingTop or bottom = 0. if (ownPadding == 0) { float margin = 0; if (ownMargin != 0 && childMargin != 0) { margin = ownMargin >= childMargin?ownMargin:childMargin; } else if (ownMargin != 0) { margin = ownMargin; } else if (childMargin != 0) { margin = childMargin; } if (!isTop && storeMarginBottom) { context.GetMemory()[HtmlPipelineContext.LAST_MARGIN_BOTTOM] = margin; } totalSpacing = margin; } else // ownpadding != 0 and all margins and paddings need to be accumulated. { totalSpacing = ownMargin + ownPadding + childMargin; if (!isTop && storeMarginBottom) { context.GetMemory()[HtmlPipelineContext.LAST_MARGIN_BOTTOM] = ownMargin; } } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } return(totalSpacing); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { return(TextContent(ctx, tag, content)); }
public TestCommandHandler(IMapper mapper, IRepository repository, IComponentContext scope, IWorkerContext <ResponseDto> context) : base(mapper, repository, scope, context) { }
/** * Classes extending AbstractTagProcessor should override this method for actions that should be done in * {@link ITagProcessor#startElement(Tag)}. The {@link AbstractTagProcessor#startElement(Tag)} calls this method * after or before doing certain stuff, (see it's description). * * @param tag the tag * @return an element to be added to current content, may be null */ public virtual IList <IElement> Start(IWorkerContext ctx, Tag tag) { return(new List <IElement>(0)); }
/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.pipeline.IPipeline#close(com.itextpdf.tool * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po) { Write(context, po); return(GetNext()); }
/** * Classes extending AbstractTagProcessor should override this method for * actions that should be done in {@link ITagProcessor#endElement(Tag, List)}. * The {@link AbstractTagProcessor#endElement(Tag, List)} calls this method * after or before doing certain stuff, (see it's description). * * @param tag the tag * @param currentContent the content created from e.g. inner tags, inner content and not yet added to document. * @return a List containing iText IElement objects */ public virtual IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { return(new List <IElement>(currentContent)); }
/** * Just calls getNext. * */ public virtual IPipeline Close(IWorkerContext context, Tag t, ProcessObject po) { return(GetNext()); }
/** * Utility method that fetches the HtmlPipelineContext used if any and if it * uses the default key. * @return a HtmlPipelineContext * @throws NoCustomContextException if the context of the * {@link HtmlPipelineContext} could not be found. */ public virtual HtmlPipelineContext GetHtmlPipelineContext(IWorkerContext ctx) { return((HtmlPipelineContext)ctx.Get(typeof(HtmlPipeline).FullName)); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List) */ virtual public IList <IElement> EndElement(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { return(new List <IElement>(0)); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { try { int numberOfColumns = 0; List <TableRowElement> tableRows = new List <TableRowElement>(currentContent.Count); IList <IElement> invalidRowElements = new List <IElement>(1); String repeatHeader; tag.CSS.TryGetValue(CSS.Property.REPEAT_HEADER, out repeatHeader); String repeatFooter; tag.CSS.TryGetValue(CSS.Property.REPEAT_FOOTER, out repeatFooter); int headerRows = 0; int footerRows = 0; foreach (IElement e in currentContent) { int localNumCols = 0; if (e is TableRowElement) { TableRowElement tableRowElement = (TableRowElement)e; foreach (HtmlCell cell in tableRowElement.Content) { localNumCols += cell.Colspan; } if (localNumCols > numberOfColumns) { numberOfColumns = localNumCols; } tableRows.Add(tableRowElement); if (repeatHeader != null && Util.EqualsIgnoreCase(repeatHeader, "yes") && tableRowElement.RowPlace.Equals(TableRowElement.Place.HEADER)) { headerRows++; } if (repeatFooter != null && Util.EqualsIgnoreCase(repeatFooter, "yes") && tableRowElement.RowPlace.Equals(TableRowElement.Place.FOOTER)) { footerRows++; } } else { invalidRowElements.Add(e); } } if (repeatFooter == null || !Util.EqualsIgnoreCase(repeatFooter, "yes")) { InsertionSort <TableRowElement>(tableRows, delegate(TableRowElement o1, TableRowElement o2) { return(o1.RowPlace.Normal.CompareTo(o2.RowPlace.Normal)); }); } else { InsertionSort <TableRowElement>(tableRows, delegate(TableRowElement o1, TableRowElement o2) { return(o1.RowPlace.Repeated.CompareTo(o2.RowPlace.Repeated)); }); } PdfPTable table = new PdfPTable(numberOfColumns); table.HeaderRows = headerRows + footerRows; table.FooterRows = footerRows; TableStyleValues styleValues = SetStyleValues(tag); table.TableEvent = new TableBorderEvent(styleValues); SetVerticalMargin(table, tag, styleValues, ctx); WidenLastCell(tableRows, styleValues.HorBorderSpacing); float[] columnWidths = new float[numberOfColumns]; float[] widestWords = new float[numberOfColumns]; float[] fixedWidths = new float[numberOfColumns]; int[] rowspanValue = new int[numberOfColumns]; float largestColumn = 0; int indexOfLargestColumn = 0; // Initial fill of the widths arrays foreach (TableRowElement row in tableRows) { int column = 0; foreach (HtmlCell cell in row.Content) { // check whether the current column should be skipped due to a // rowspan value of higher cell in this column. while (rowspanValue[column] > 1) { rowspanValue[column] = rowspanValue[column] - 1; ++column; } // sets a rowspan counter for current column (counter not // needed for last column). if (cell.Rowspan > 1 && column != numberOfColumns - 1) { rowspanValue[column] = cell.Rowspan - 1; } int colspan = cell.Colspan; if (cell.FixedWidth != 0) { float fixedWidth = cell.FixedWidth + GetCellStartWidth(cell); fixedWidth /= colspan; for (int i = 0; i < colspan; i++) { int c = column + i; if (fixedWidth > fixedWidths[c]) { fixedWidths[c] = fixedWidth; columnWidths[c] = fixedWidth; } } } if (cell.CompositeElements != null) { float[] widthValues = SetCellWidthAndWidestWord(cell); float cellWidth = widthValues[0] / colspan; float widestWordOfCell = widthValues[1] / colspan; for (int i = 0; i < colspan; i++) { int c = column + i; if (fixedWidths[c] == 0 && cellWidth > columnWidths[c]) { columnWidths[c] = cellWidth; if (cellWidth > largestColumn) { largestColumn = cellWidth; indexOfLargestColumn = c; } } if (widestWordOfCell > widestWords[c]) { widestWords[c] = widestWordOfCell; } } } if (colspan > 1) { if (LOG.IsLogging(Level.TRACE)) { LOG.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.COLSPAN), colspan)); } column += colspan - 1; } column++; } } float outerWidth = GetTableOuterWidth(tag, styleValues.HorBorderSpacing, ctx); float initialTotalWidth = GetTableWidth(columnWidths, 0); // float targetWidth = calculateTargetWidth(tag, columnWidths, outerWidth, ctx); float targetWidth = 0; HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); float max = htmlPipelineContext.GetPageSize().Width - outerWidth; bool tableWidthFixed = false; if (tag.Attributes.ContainsKey(CSS.Property.WIDTH) || tag.CSS.ContainsKey(CSS.Property.WIDTH)) { targetWidth = new WidthCalculator().GetWidth(tag, htmlPipelineContext.GetRootTags(), htmlPipelineContext.GetPageSize().Width); if (targetWidth > max) { targetWidth = max; } tableWidthFixed = true; } else if (initialTotalWidth <= max) { targetWidth = initialTotalWidth; } else if (null == tag.Parent || (null != tag.Parent && htmlPipelineContext.GetRootTags().Contains(tag.Parent.Name))) { targetWidth = max; } else /* this table is an inner table and width adjustment is done in outer table */ { targetWidth = GetTableWidth(columnWidths, outerWidth); } float totalFixedColumnWidth = GetTableWidth(fixedWidths, 0); float targetPercentage = 0; if (totalFixedColumnWidth == initialTotalWidth) // all column widths are fixed { targetPercentage = targetWidth / initialTotalWidth; if (initialTotalWidth > targetWidth) { for (int column = 0; column < columnWidths.Length; column++) { columnWidths[column] *= targetPercentage; } } else if (tableWidthFixed && targetPercentage != 1) { for (int column = 0; column < columnWidths.Length; column++) { columnWidths[column] *= targetPercentage; } } } else { targetPercentage = (targetWidth - totalFixedColumnWidth) / (initialTotalWidth - totalFixedColumnWidth); // Reduce width of columns if the columnWidth array + borders + // paddings // is too large for the given targetWidth. if (initialTotalWidth > targetWidth) { float leftToReduce = 0; for (int column = 0; column < columnWidths.Length; column++) { if (fixedWidths[column] == 0) { // Reduce width of the column to its targetWidth, if // widestWord of column still fits in the targetWidth of // the // column. if (widestWords[column] <= columnWidths[column] * targetPercentage) { columnWidths[column] *= targetPercentage; // else take the widest word and calculate space // left to // reduce. } else { columnWidths[column] = widestWords[column]; leftToReduce += widestWords[column] - columnWidths[column] * targetPercentage; } // if widestWord of a column does not fit in the // fixedWidth, // set the column width to the widestWord. } else if (fixedWidths[column] < widestWords[column]) { columnWidths[column] = widestWords[column]; leftToReduce += widestWords[column] - fixedWidths[column]; } } if (leftToReduce != 0) { // Reduce width of the column with the most text, if its // widestWord still fits in the reduced column. if (widestWords[indexOfLargestColumn] <= columnWidths[indexOfLargestColumn] - leftToReduce) { columnWidths[indexOfLargestColumn] -= leftToReduce; } else // set all columns to their minimum, with the // widestWord array. { for (int column = 0; leftToReduce != 0 && column < columnWidths.Length; column++) { if (fixedWidths[column] == 0 && columnWidths[column] > widestWords[column]) { float difference = columnWidths[column] - widestWords[column]; if (difference <= leftToReduce) { leftToReduce -= difference; columnWidths[column] = widestWords[column]; } else { columnWidths[column] -= leftToReduce; leftToReduce = 0; } } } if (leftToReduce != 0) { // If the table has an insufficient fixed width // by // an // attribute or style, try to enlarge the table // to // its // minimum width (= widestWords array). float pageWidth = GetHtmlPipelineContext(ctx).GetPageSize().Width; if (GetTableWidth(widestWords, outerWidth) < pageWidth) { targetWidth = GetTableWidth(widestWords, outerWidth); leftToReduce = 0; } else { // If all columnWidths are set to the // widestWordWidths and the table is still // to // wide // content will fall off the edge of a page, // which // is similar to HTML. targetWidth = pageWidth - outerWidth; leftToReduce = 0; } } } } // Enlarge width of columns to fit the targetWidth. } else if (initialTotalWidth < targetWidth) { for (int column = 0; column < columnWidths.Length; column++) { if (fixedWidths[column] == 0) { columnWidths[column] *= targetPercentage; } } } } try { table.SetTotalWidth(columnWidths); table.LockedWidth = true; table.DefaultCell.Border = Rectangle.NO_BORDER; } catch (DocumentException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } foreach (TableRowElement row in tableRows) { int columnNumber = -1; foreach (HtmlCell cell in row.Content) { columnNumber += cell.Colspan; IList <IElement> compositeElements = cell.CompositeElements; if (compositeElements != null) { foreach (IElement baseLevel in compositeElements) { if (baseLevel is PdfPTable) { TableStyleValues cellValues = cell.CellValues; float totalBordersWidth = cellValues.IsLastInRow ? styleValues.HorBorderSpacing * 2 : styleValues.HorBorderSpacing; totalBordersWidth += cellValues.BorderWidthLeft + cellValues.BorderWidthRight; float columnWidth = columnWidths[columnNumber]; IPdfPTableEvent tableEvent = ((PdfPTable)baseLevel).TableEvent; TableStyleValues innerStyleValues = ((TableBorderEvent)tableEvent).TableStyleValues; totalBordersWidth += innerStyleValues.BorderWidthLeft; totalBordersWidth += innerStyleValues.BorderWidthRight; ((PdfPTable)baseLevel).TotalWidth = columnWidth - totalBordersWidth; } } } table.AddCell(cell); } table.CompleteRow(); } List <IElement> elems = new List <IElement>(); if (invalidRowElements.Count > 0) { // all invalid row elements taken as caption int i = 0; Tag captionTag = tag.Children[i++]; while (!Util.EqualsIgnoreCase(captionTag.Name, HTML.Tag.CAPTION) && i < tag.Children.Count) { captionTag = tag.Children[i]; i++; } String captionSideValue; captionTag.CSS.TryGetValue(CSS.Property.CAPTION_SIDE, out captionSideValue); if (captionSideValue != null && Util.EqualsIgnoreCase(captionSideValue, CSS.Value.BOTTOM)) { elems.Add(table); elems.AddRange(invalidRowElements); } else { elems.AddRange(invalidRowElements); elems.Add(table); } } else { elems.Add(table); } return(elems); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/** * Just calls getNext. * */ public virtual IPipeline Content(IWorkerContext ctx, Tag currentTag, string text, ProcessObject po) { return(GetNext()); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { try { String name; tag.Attributes.TryGetValue(HTML.Attribute.NAME, out name); IList <IElement> elems = new List <IElement>(0); if (currentContent.Count > 0) { NoNewLineParagraph p = new NoNewLineParagraph(); String url; tag.Attributes.TryGetValue(HTML.Attribute.HREF, out url); foreach (IElement e in currentContent) { if (e is Chunk) { if (null != url) { if (url.StartsWith("#")) { if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_LOCALGOTO), url)); } ((Chunk)e).SetLocalGoto(url.Substring(1)); } else { // TODO check url validity? if (null != GetHtmlPipelineContext(ctx).GetLinkProvider() && !url.StartsWith("http")) { String root = GetHtmlPipelineContext(ctx).GetLinkProvider().GetLinkRoot(); if (root.EndsWith("/") && url.StartsWith("/")) { root = root.Substring(0, root.Length - 1); } url = root + url; } if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_EXTERNAL), url)); } ((Chunk)e).SetAnchor(url); } } else if (null != name) { ((Chunk)e).SetLocalDestination(name); if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_SETLOCALGOTO), name)); } } } p.Add(e); } elems.Add(GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx))); } else // !currentContent > 0 ; An empty "a" tag has been encountered. // we're using an anchor space hack here. without the space, reader // does // not jump to destination if (null != name) { if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.SPACEHACK), name)); } elems.Add(new WriteP(name)); /* * PdfWriter writer = configuration.GetWriter(); ColumnText c = * new ColumnText(writer.GetDirectContent()); * c.SetSimpleColumn(new Phrase(dest), 1, * writer.GetVerticalPosition(false), 1, * writer.GetVerticalPosition(false), 5, Element.ALIGN_LEFT); * try { c.Go(); } catch (DocumentException e) { throw new * RuntimeWorkerException(e); } */ } return(elems); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/** * Sets the top and bottom margin of the given table. * * @param table PdfPTable on which the margins need to be set. * @param t Tag containing the margin styles and font size if needed. * @param values {@link TableStyleValues} containing border widths and border spacing values. * @throws NoCustomContextException */ private void SetVerticalMargin(PdfPTable table, Tag t, TableStyleValues values, IWorkerContext ctx) { float spacingBefore = values.BorderWidthTop; IDictionary <String, Object> memory = GetHtmlPipelineContext(ctx).GetMemory(); Object mb; memory.TryGetValue(HtmlPipelineContext.LAST_MARGIN_BOTTOM, out mb); if (mb != null) { spacingBefore += (float)mb; } float spacingAfter = values.VerBorderSpacing + values.BorderWidthBottom; foreach (KeyValuePair <String, String> css in t.CSS) { String key = css.Key; String value = css.Value; if (Util.EqualsIgnoreCase(CSS.Property.MARGIN_TOP, key)) { spacingBefore += utils.ParseValueToPt(value, fst.GetFontSize(t)); } else if (Util.EqualsIgnoreCase(CSS.Property.MARGIN_BOTTOM, key)) { float marginBottom = utils.ParseValueToPt(value, fst.GetFontSize(t)); spacingAfter += marginBottom; GetHtmlPipelineContext(ctx).GetMemory()[HtmlPipelineContext.LAST_MARGIN_BOTTOM] = marginBottom; } } table.SpacingBefore = spacingBefore; table.SpacingAfter = spacingAfter; }
/** * Sets the top and bottom margin of the given table. * * @param table PdfPTable on which the margins need to be set. * @param t Tag containing the margin styles and font size if needed. * @param values {@link TableStyleValues} containing border widths and border spacing values. * @throws NoCustomContextException */ private void SetVerticalMargin(PdfPTable table, Tag t, TableStyleValues values, IWorkerContext ctx) { float spacingBefore = values.BorderWidthTop; float spacingAfter = values.VerBorderSpacing + values.BorderWidthBottom; foreach (KeyValuePair <String, String> css in t.CSS) { String key = css.Key; String value = css.Value; if (Util.EqualsIgnoreCase(CSS.Property.MARGIN_TOP, key)) { CssUtils utils = CssUtils.GetInstance(); spacingBefore += utils.CalculateMarginTop(value, fst.GetFontSize(t), GetHtmlPipelineContext(ctx)); } else if (Util.EqualsIgnoreCase(CSS.Property.MARGIN_BOTTOM, key)) { float marginBottom = utils.ParseValueToPt(value, fst.GetFontSize(t)); spacingAfter += marginBottom; GetHtmlPipelineContext(ctx).GetMemory()[HtmlPipelineContext.LAST_MARGIN_BOTTOM] = marginBottom; } } table.SpacingBefore = spacingBefore; table.SpacingAfter = spacingAfter; }
public EventLoop(IWorkerContext workerContext, int threadId) { _workerContext = workerContext; _threadId = threadId; }