Beispiel #1
0
        /// <summary>Resolves counters.</summary>
        /// <param name="counterName">the counter name</param>
        /// <param name="counterSeparatorStr">the counter separator</param>
        /// <param name="listSymbolType">the list symbol type</param>
        /// <returns>
        /// the counters as a
        /// <see cref="System.String"/>
        /// </returns>
        public virtual String ResolveCounters(String counterName, String counterSeparatorStr, CounterDigitsGlyphStyle
                                              listSymbolType)
        {
            IList <String> resolvedCounters = new List <String>();

            if (counters.ContainsKey(counterName))
            {
                foreach (int?value in counters.Get(counterName))
                {
                    resolvedCounters.Add(HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, (int)value));
                }
            }
            int?currentValue = counterValues.Get(counterName);

            if (currentValue != null)
            {
                resolvedCounters.Add(HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, (int)currentValue));
            }
            if (resolvedCounters.IsEmpty())
            {
                return(HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, 0));
            }
            else
            {
                return(BuildCountersStringFromList(resolvedCounters, counterSeparatorStr));
            }
        }
Beispiel #2
0
        /// <summary>Gets target-counter value for specified ID and counterName.</summary>
        /// <remarks>Gets target-counter value for specified ID and counterName. Value is converted according to listSymbolType.
        ///     </remarks>
        /// <param name="id">
        /// ID of the element. The first call adds ID to the Map, which means we require its value.
        /// The second call returns corresponding value if we already encountered corresponding element
        /// </param>
        /// <param name="counterName">
        /// name of the counter. The first call adds counterName to the Map,
        /// which means we require its value.
        /// The second call returns corresponding value if we already encountered corresponding element
        /// </param>
        /// <param name="listSymbolType">the list symbol type to convert counter's value. null if conversion is not required.
        ///     </param>
        /// <returns>target-counter value.</returns>
        public virtual String ResolveTargetCounter(String id, String counterName, CounterDigitsGlyphStyle listSymbolType
                                                   )
        {
            int?counterValue = null;

            if (targetCounterMap.ContainsKey(id))
            {
                IDictionary <String, int?> countersForThisId = targetCounterMap.Get(id);
                if (countersForThisId.ContainsKey(counterName))
                {
                    counterValue = countersForThisId.Get(counterName);
                }
                else
                {
                    countersForThisId.Put(counterName, null);
                }
            }
            else
            {
                targetCounterMap.Put(id, new Dictionary <String, int?>());
                targetCounterMap.Get(id).Put(counterName, null);
            }
            return(counterValue == null ? null : HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, (int)counterValue
                                                                                              ));
        }
Beispiel #3
0
        /* (non-Javadoc)
         * @see com.itextpdf.layout.renderer.TextRenderer#layout(com.itextpdf.layout.layout.LayoutContext)
         */
        public override LayoutResult Layout(LayoutContext layoutContext)
        {
            PageCountType pageCountType = (PageCountType)this.GetProperty <PageCountType?>(Html2PdfProperty.PAGE_COUNT_TYPE
                                                                                           );
            String previousText = GetText().ToString();
            // If typography is enabled and the page counter element has a non-default direction,
            // iText processes its content (see LineRenderer#updateBidiLevels) before layouting it.
            // This might result in an ArrayIndexOutOfBounds exception, because currently iText updates the page counter's content on layout.
            // To solve this, this workaround has been implemented: the renderer's strToBeConverted shouldn't be updated by layout.
            bool textHasBeenReplaced = false;

            if (pageCountType == PageCountType.CURRENT_PAGE_NUMBER)
            {
                SetText(HtmlUtils.ConvertNumberAccordingToGlyphStyle(digitsGlyphStyle, layoutContext.GetArea().GetPageNumber
                                                                         ()));
                textHasBeenReplaced = true;
            }
            else
            {
                if (pageCountType == PageCountType.TOTAL_PAGE_COUNT)
                {
                    IRenderer rootRenderer = this;
                    while (rootRenderer is AbstractRenderer && ((AbstractRenderer)rootRenderer).GetParent() != null)
                    {
                        rootRenderer = ((AbstractRenderer)rootRenderer).GetParent();
                    }
                    if (rootRenderer is HtmlDocumentRenderer && ((HtmlDocumentRenderer)rootRenderer).GetEstimatedNumberOfPages
                            () > 0)
                    {
                        SetText(HtmlUtils.ConvertNumberAccordingToGlyphStyle(digitsGlyphStyle, ((HtmlDocumentRenderer)rootRenderer
                                                                                                ).GetEstimatedNumberOfPages()));
                        textHasBeenReplaced = true;
                    }
                    else
                    {
                        if (rootRenderer is DocumentRenderer && rootRenderer.GetModelElement() is Document)
                        {
                            SetText(HtmlUtils.ConvertNumberAccordingToGlyphStyle(digitsGlyphStyle, ((Document)rootRenderer.GetModelElement
                                                                                                        ()).GetPdfDocument().GetNumberOfPages()));
                            textHasBeenReplaced = true;
                        }
                    }
                }
            }
            LayoutResult result = base.Layout(layoutContext);

            if (textHasBeenReplaced)
            {
                SetText(previousText);
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>Resolves a counter.</summary>
        /// <param name="counterName">the counter name</param>
        /// <param name="listSymbolType">the list symbol type</param>
        /// <returns>
        /// the counter value as a
        /// <see cref="System.String"/>
        /// </returns>
        public virtual String ResolveCounter(String counterName, CounterDigitsGlyphStyle listSymbolType)
        {
            int?result = counterValues.Get(counterName);

            if (result == null)
            {
                if (!counters.ContainsKey(counterName) || counters.Get(counterName).IsEmpty())
                {
                    result = 0;
                }
                else
                {
                    result = counters.Get(counterName).JGetLast();
                }
            }
            return(HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, (int)result));
        }
        /// <summary><inheritDoc/></summary>
        public override LayoutResult Layout(LayoutContext layoutContext)
        {
            String previousText = GetText().ToString();
            int?   page         = TargetCounterHandler.GetPageByID(this, target);

            if (page == null)
            {
                SetText(UNDEFINED_VALUE);
            }
            else
            {
                SetText(HtmlUtils.ConvertNumberAccordingToGlyphStyle(digitsGlyphStyle, (int)page));
            }
            LayoutResult result = base.Layout(layoutContext);

            SetText(previousText);
            return(result);
        }
Beispiel #6
0
        /// <summary>Gets target-counter value for specified ID and counterName.</summary>
        /// <remarks>Gets target-counter value for specified ID and counterName. Value is converted according to listSymbolType.
        ///     </remarks>
        /// <param name="id">
        /// ID of the element. The first call adds ID at the Map,
        /// which means we require its value. The second call returns corresponding value
        /// if we already encountered this element
        /// </param>
        /// <param name="counterName">
        /// name of the counter. The first call adds name at the Map,
        /// which means we require its value. The second call returns corresponding value
        /// if we already encountered this element
        /// </param>
        /// <param name="counterSeparatorStr">separator to separate counters values.</param>
        /// <param name="listSymbolType">the list symbol type to convert counter's value. null if conversion is not required.
        ///     </param>
        /// <returns>target-counter value.</returns>
        public virtual String ResolveTargetCounters(String id, String counterName, String counterSeparatorStr, CounterDigitsGlyphStyle
                                                    listSymbolType)
        {
            String countersStr = null;

            if (targetCountersMap.ContainsKey(id))
            {
                IDictionary <String, String> countersForThisId = targetCountersMap.Get(id);
                if (countersForThisId.ContainsKey(counterName))
                {
                    countersStr = countersForThisId.Get(counterName);
                }
                else
                {
                    countersForThisId.Put(counterName, null);
                }
            }
            else
            {
                targetCountersMap.Put(id, new Dictionary <String, String>());
                targetCountersMap.Get(id).Put(counterName, null);
            }
            if (countersStr == null)
            {
                return(null);
            }
            else
            {
                String[]       resolvedCounters  = iText.IO.Util.StringUtil.Split(countersStr, "\\.");
                IList <String> convertedCounters = new List <String>();
                foreach (String counter in resolvedCounters)
                {
                    convertedCounters.Add(HtmlUtils.ConvertNumberAccordingToGlyphStyle(listSymbolType, Convert.ToInt32(counter
                                                                                                                       , System.Globalization.CultureInfo.InvariantCulture)));
                }
                return(BuildCountersStringFromList(convertedCounters, counterSeparatorStr));
            }
        }