Ejemplo n.º 1
0
        /*
         * (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);
        }
Ejemplo n.º 2
0
        /**
         * Applies the tab interval of the p tag on its {@link TabbedChunk} elements. <br />
         * The style "xfa-tab-count" of the {@link TabbedChunk} is multiplied with the tab interval of the p tag. This width is then added to a new {@link TabbedChunk}.
         *
         * @param currentContent containing the elements inside the p tag.
         * @param p paragraph to which the tabbed chunks will be added.
         * @param value the value of style "tab-interval".
         */
        private void AddTabIntervalContent(IWorkerContext ctx, Tag tag, IList <IElement> currentContent, Paragraph p, String value)
        {
            float width = 0;

            foreach (IElement e in currentContent)
            {
                if (e is TabbedChunk)
                {
                    width += ((TabbedChunk)e).TabCount * CssUtils.GetInstance().ParsePxInCmMmPcToPt(value);
                    TabbedChunk tab = new TabbedChunk(new VerticalPositionMark(), width, false);
                    p.Add(new Chunk(tab));
                    p.Add(new Chunk((TabbedChunk)e));
                }
                else
                {
                    if (e is LineSeparator)
                    {
                        try {
                            HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                            Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext);
                            p.Add(newLine);
                        } catch (NoCustomContextException exc) {
                            throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc);
                        }
                    }
                    p.Add(e);
                }
            }
        }
Ejemplo n.º 3
0
        /*
         * (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)
            {
                if (tag.CSS.ContainsKey(CSS.Property.TAB_INTERVAL))
                {
                    TabbedChunk tabbedChunk = new TabbedChunk(sanitized);
                    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(new ChunkCssApplier().Apply(tabbedChunk, tag));
                }
                else if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT))
                {
                    TabbedChunk tabbedChunk = new TabbedChunk(sanitized);
                    tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]);
                    l.Add(new ChunkCssApplier().Apply(tabbedChunk, tag));
                }
                else
                {
                    l.Add(new ChunkCssApplier().Apply(new Chunk(sanitized), tag));
                }
            }
            return(l);
        }
Ejemplo n.º 4
0
        /**
         * Applies the tab stops of the p tag on its {@link TabbedChunk} elements.
         *
         * @param currentContent containing the elements inside the p tag.
         * @param p paragraph to which the tabbed chunks will be added.
         * @param value the value of style "tab-stops".
         */
        private void AddTabStopsContent(IList <IElement> currentContent, Paragraph p, String value)
        {
            IList <Chunk> tabs = new List <Chunk>();

            String[] alignAndWidth = value.Split(' ');
            float    tabWidth      = 0;

            for (int i = 0, j = 1; j < alignAndWidth.Length; i += 2, j += 2)
            {
                tabWidth += CssUtils.GetInstance().ParsePxInCmMmPcToPt(alignAndWidth[j]);
                TabbedChunk tab = new TabbedChunk(new VerticalPositionMark(), tabWidth, true, alignAndWidth[i]);
                tabs.Add(tab);
            }
            int tabsPerRow = tabs.Count;
            int currentTab = 0;

            foreach (IElement e in currentContent)
            {
                if (e is TabbedChunk)
                {
                    if (currentTab == tabsPerRow)
                    {
                        currentTab = 0;
                    }
                    if (((TabbedChunk)e).TabCount != 0 /* == 1*/)
                    {
                        p.Add(new Chunk(tabs[currentTab]));
                        p.Add(new Chunk((TabbedChunk)e));
                        ++currentTab;
                        //              } else { // wat doet een tabCount van groter dan 1? sla een tab over of count * tabWidth?
                        //                  int widthMultiplier = ((TabbedChunk) e).GetTabCount();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /**
         * Applies the tab interval of the p tag on its {@link TabbedChunk} elements. <br />
         * The style "xfa-tab-count" of the {@link TabbedChunk} is multiplied with the tab interval of the p tag. This width is then added to a new {@link TabbedChunk}.
         *
         * @param currentContent containing the elements inside the p tag.
         * @param p paragraph to which the tabbed chunks will be added.
         * @param value the value of style "tab-interval".
         */
        private void AddTabIntervalContent(IList <IElement> currentContent, Paragraph p, String value)
        {
            float width = 0;

            foreach (IElement e in currentContent)
            {
                if (e is TabbedChunk)
                {
                    width += ((TabbedChunk)e).TabCount * CssUtils.GetInstance().ParsePxInCmMmPcToPt(value);
                    TabbedChunk tab = new TabbedChunk(new VerticalPositionMark(), width, false);
                    p.Add(new Chunk(tab));
                    p.Add(new Chunk((TabbedChunk)e));
                }
            }
        }