/// <summary>
        /// Obtiene el texto contenido en un pdf en función del parámetro facilitado.
        /// </summary>
        /// <param name="renderInfo">Información para la obtención del texto.</param>
        public override void RenderText(TextRenderInfo renderInfo)
        {
            base.RenderText(renderInfo);

            LineSegment segment = renderInfo.GetBaseline();

            if (renderInfo.GetRise() != 0)
            {
                // remove the rise from the baseline - we do this because the text from a
                // super /subscript render operations should probably be considered as part
                // of the baseline of the text the super/sub is relative to
                Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                segment = segment.TransformBy(riseOffsetTransform);
            }

            var ll = renderInfo.GetDescentLine().GetStartPoint();         // lower left
            var ur = renderInfo.GetAscentLine().GetEndPoint();            // upper right

            string text = renderInfo.GetText();                           //mirando

            string fillColor   = renderInfo.GetFillColor()?.ToString();   // Color del texto.
            string strokeColor = renderInfo.GetStrokeColor()?.ToString(); // Color del texto.

            Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
            Vector topRight    = renderInfo.GetAscentLine().GetEndPoint();

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
            double fontSize = Math.Round(rect.Height);                  // Tamaño de la fuente a partir del rectángulo extraído.

            string fontName = renderInfo.GetFont()?.PostscriptFontName; //Nombre de la fuente.

            //base._PdfTextChunks.Add(new PdfTextChunk(renderInfo.GetText(), base.tclStrat.CreateLocation(renderInfo, segment), ll, ur));
            _PdfColorFontTextChunks.Add(new PdfColorFontTextChunk(renderInfo.GetText(), base.tclStrat.CreateLocation(renderInfo, segment), ll, ur, fillColor, strokeColor, fontName, fontSize));
        }
 /// Captures text using a simplified algorithm for inserting hard returns and spaces
 ///             @param   renderInfo  render info
 public virtual void RenderText(TextRenderInfo renderInfo)
 {
     _blocks.Add(new TextBlock
     {
         Text        = renderInfo.GetText(),
         TopLeft     = renderInfo.GetBaseline().GetStartPoint(),
         BottomRight = renderInfo.GetBaseline().GetEndPoint()
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// <see cref="IRenderListener.RenderText"/>
        /// </summary>
        public void RenderText(TextRenderInfo renderInfo)
        {
            output.WriteLine("    <");
            Vector start = renderInfo.GetBaseline().GetStartPoint();

            output.WriteLine(String.Format("        x: {0} y: {1} length: {2} \n        Text: {3}",
                                           start[Vector.I1], start[Vector.I2],
                                           renderInfo.GetBaseline().GetLength(),
                                           renderInfo.GetText()));
            output.WriteLine("    >");
        }
Ejemplo n.º 4
0
        public CharacterRenderInfo(TextRenderInfo tri)
            : base(tri == null ? "" : tri.GetText(), tri == null ? null : GetLocation(tri))
        {
            if (tri == null)
            {
                throw new ArgumentException("TextRenderInfo argument is not nullable.");
            }
            // determine bounding box
            float x0 = tri.GetDescentLine().GetStartPoint().Get(0);
            float y0 = tri.GetDescentLine().GetStartPoint().Get(1);
            float h  = tri.GetAscentLine().GetStartPoint().Get(1) - tri.GetDescentLine().GetStartPoint().Get(1);
            float w  = Math.Abs(tri.GetBaseline().GetStartPoint().Get(0) - tri.GetBaseline().GetEndPoint().Get(0));

            this.boundingBox = new Rectangle(x0, y0, w, h);
        }
Ejemplo n.º 5
0
        private static ITextChunkLocation GetLocation(TextRenderInfo tri)
        {
            LineSegment baseline = tri.GetBaseline();

            return(new TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), tri.GetSingleSpaceWidth
                                                       ()));
        }
Ejemplo n.º 6
0
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment  = renderInfo.GetBaseline();
            TextChunk   location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());

            var _with1 = location;

            //Chunk Location:
            //			Debug.Print(renderInfo.GetText);
            _with1.PosLeft   = renderInfo.GetDescentLine().GetStartPoint()[Vector.I1];
            _with1.PosRight  = renderInfo.GetAscentLine().GetEndPoint()[Vector.I1];
            _with1.PosBottom = renderInfo.GetDescentLine().GetStartPoint()[Vector.I2];
            _with1.PosTop    = renderInfo.GetAscentLine().GetEndPoint()[Vector.I2];
            //Chunk Font Size: (Height)
            _with1.curFontSize = _with1.PosTop - segment.GetStartPoint()[Vector.I2];
            //Use Font name  and Size as Key in the SortedList
            string StrKey = renderInfo.GetFont().PostscriptFontName + _with1.curFontSize.ToString();

            //Add this font to ThisPdfDocFonts SortedList if it's not already present
            if (!ThisPdfDocFonts.ContainsKey(StrKey))
            {
                ThisPdfDocFonts.Add(StrKey, renderInfo.GetFont());
            }
            //Store the SortedList index in this Chunk, so we can get it later
            _with1.FontIndex = ThisPdfDocFonts.IndexOfKey(StrKey);
            locationalResult.Add(location);
        }
        //This is called whenever a run of text is encountered
        public void RenderText(TextRenderInfo renderInfo)
        {
            //This code assumes that if the baseline changes then we're on a newline
            LineSegment curBaseline      = renderInfo.GetBaseline();
            Vector      curBaseLineStart = curBaseline.GetStartPoint();

            if (lastBaseLine != null)
            {
                // Check if text is on a new line or if text is new block of text on the same line
                // Horizontally compare max coordinate of previous block with min of current block
                // For vertical compare max of both to get the base of the textblock
                var horizontalDifference = Math.Abs(Math.Max(lastBaseLine.GetStartPoint()[0], lastBaseLine.GetEndPoint()[0]) - Math.Min(curBaseline.GetStartPoint()[0], curBaseline.GetEndPoint()[0]));
                var verticalDifference   = Math.Abs(Math.Max(lastBaseLine.GetStartPoint()[1], lastBaseLine.GetEndPoint()[1]) - Math.Max(curBaseline.GetStartPoint()[1], curBaseline.GetEndPoint()[1]));
                if (verticalDifference > 1 || horizontalDifference > 20)
                //if ((this.lastBaseLine != null) && (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]))
                {
                    //See if we have text and not just whitespace
                    if ((!String.IsNullOrWhiteSpace(result.ToString())))
                    {
                        //Mark the previous line as done by adding it to our buffers
                        this.baselines.Add(this.lastBaseLine.GetStartPoint()[Vector.I2]);
                        this.strings.Add(this.result.ToString());
                    }
                    //Reset our "line" buffer
                    this.result.Clear();
                }
            }

            //Append the current text to our line buffer
            this.result.Append(renderInfo.GetText());

            //Reset the last used line
            this.lastBaseLine = curBaseline;
        }
Ejemplo n.º 8
0
            //--------------------------------------------------------------------------------------------------
            public void RenderText(TextRenderInfo renderInfo)
            {
                LineSegment segment  = renderInfo.GetBaseline();
                TextChunk   location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());

                location.iPage = Page;

                int renderInfoTextLength = new StringInfo(renderInfo.GetText()).LengthInTextElements;

                if (renderInfoTextLength == 1)
                {
                    location.AscentLines.Add(renderInfo.GetAscentLine());
                    location.DescentLines.Add(renderInfo.GetDescentLine());
                }
                else
                {
                    IList <TextRenderInfo> infos = renderInfo.GetCharacterRenderInfos();
                    System.Diagnostics.Debug.Assert(infos != null);
                    System.Diagnostics.Debug.Assert(renderInfoTextLength == infos.Count);
                    foreach (TextRenderInfo info in infos)
                    {
                        location.AscentLines.Add(info.GetAscentLine());
                        location.DescentLines.Add(info.GetDescentLine());
                    }
                }
                m_LocationalResult.Add(location);
            }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="renderInfo"></param>
        public override void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment  = renderInfo.GetBaseline();
            MyTextChunk location = new MyTextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine());

            m_locationResult.Add(location);
        }
        /// <summary>
        /// Render text.
        /// </summary>
        /// <param name="renderInfo">render text information</param>
        public void RenderText(TextRenderInfo renderInfo)
        {
            var segment  = renderInfo.GetBaseline();
            var location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth())
            {
                PosLeft     = renderInfo.GetDescentLine().GetStartPoint()[Vector.I1],
                PosRight    = renderInfo.GetAscentLine().GetEndPoint()[Vector.I1],
                PosBottom   = renderInfo.GetDescentLine().GetStartPoint()[Vector.I2],
                PosTop      = renderInfo.GetAscentLine().GetEndPoint()[Vector.I2],
                FillColor   = renderInfo.GetFillColor(),
                StrokeColor = renderInfo.GetStrokeColor(),
                Font        = renderInfo.GetFont()
            };

            // Chunk Font Size: (Height)
            location.CurFontSize = location.PosTop - segment.GetStartPoint()[Vector.I2];

            // Use Font name  and Size as Key in the SortedList
            var strKey = renderInfo.GetFont().PostscriptFontName + location.CurFontSize;

            // Add this font to ThisPdfDocFonts SortedList if it's not already present
            if (!_thisPdfDocFonts.ContainsKey(strKey))
            {
                _thisPdfDocFonts.Add(strKey, renderInfo.GetFont());
            }

            // Store the SortedList index in this Chunk, so we can get it later
            location.FontIndex = _thisPdfDocFonts.IndexOfKey(strKey);

            _locationalResult.Add(location);
        }
Ejemplo n.º 11
0
        public virtual void ParseText(TextRenderInfo textRenderInfo)
        {
            var         text     = textRenderInfo.GetText();
            LineSegment baseline = textRenderInfo.GetBaseline();

            if (textRenderInfo.GetRise() != 0)
            {
                Matrix m = new Matrix(0.0f, -textRenderInfo.GetRise());
                baseline = baseline.TransformBy(m);
            }
            var          start      = baseline.GetStartPoint();
            LineSegment  ascentLine = textRenderInfo.GetAscentLine();
            PdfTextBlock item       = new PdfTextBlock
            {
                Value        = text,
                Bottom       = pageContext.PageHeight - start.Get(Vector.I2),
                Top          = pageContext.PageHeight - ascentLine.GetStartPoint().Get(Vector.I2),
                Left         = start.Get(Vector.I1),
                Width        = baseline.GetEndPoint().Get(Vector.I1) - start.Get(Vector.I1),
                FontSize     = FontManager.Instance.GetFontSize(textRenderInfo, baseline, ascentLine),
                StrokeColore = ColorManager.Instance.GetColor(textRenderInfo),
                CharSpacing  = textRenderInfo.GetSingleSpaceWidth(),
                Font         = GetFont(textRenderInfo),
            };

            RightToLeftManager.Instance.AssignRtl(item, textRenderInfo.GetUnscaledWidth() < 0);
            pageContext.LinkManager.AssignLink(item);
            texts.Add(item);
        }
Ejemplo n.º 12
0
        /**
         *
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment = renderInfo.GetBaseline();

            if (renderInfo.GetRise() != 0)
            { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
                Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                segment = segment.TransformBy(riseOffsetTransform);
            }
            //TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());
            //locationalResult.Add(location);

            //base.RenderText(renderInfo);


            //Get the bounding box for the chunk of text
            var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
            var topRight   = renderInfo.GetAscentLine().GetEndPoint();

            //Create a rectangle from it
            var rect = new iTextSharp.text.Rectangle(
                bottomLeft[Vector.I1],
                bottomLeft[Vector.I2],
                topRight[Vector.I1],
                topRight[Vector.I2]
                );

            TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), rect);

            locationalResult.Add(location);
        }
Ejemplo n.º 13
0
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            bool firstRender = results.Count == 0;

            LineSegment segment = renderInfo.GetBaseline();
            Vector      start   = segment.GetStartPoint();
            Vector      end     = segment.GetEndPoint();

            //Use the Y value of the bottom left corner of the text for the key
            int currentLineKey = (int)start[1];

            if (!firstRender)
            {
                Vector x0 = start;
                Vector x1 = lastStart;
                Vector x2 = lastEnd;

                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f;
                //If we've detected that we're still on the same
                if (dist <= sameLineThreshold)
                {
                    //Use the previous Y coordinate
                    currentLineKey = (int)lastStart[1];
                }
            }
            //Hack: PDFs start with zero at the bottom so our keys will be upside down. Using negative keys cheats this.
            currentLineKey = currentLineKey * -1;

            //If this line hasn't been used before add a new line to our collection
            if (!results.ContainsKey(currentLineKey))
            {
                results.Add(currentLineKey, new StringBuilder());
            }

            //Insert a space between blocks of text if it appears there should be
            if (!firstRender &&                                      //First pass never needs a leading space
                results[currentLineKey].Length != 0 &&               //Don't append a space to the begining of a line
                !results[currentLineKey].ToString().EndsWith(" ") && //Don't append if the current buffer ends in a space already
                renderInfo.GetText().Length > 0 &&                   //Don't append if the new next is empty
                !renderInfo.GetText().StartsWith(" "))
            {                                                        //Don't append if the new text starts with a space
                //Calculate the distance between the two blocks
                float spacing = lastEnd.Subtract(start).Length;
                //If it "looks" like it should be a space
                if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                {
                    //Add a space
                    results[currentLineKey].Append(" ");
                }
            }

            //Add the text to the line in our collection
            results[currentLineKey].Append(renderInfo.GetText());

            lastStart = start;
            lastEnd   = end;
        }
    public override void RenderText(TextRenderInfo renderInfo)
    {
        LineSegment baseline = renderInfo.GetBaseline();
        //Create ExtendedChunk
        ExtendedTextChunk aExtendedChunk = new ExtendedTextChunk(renderInfo.GetText(), baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetCharacterRenderInfos().ToList());

        this.m_DocChunks.Add(aExtendedChunk);
    }
Ejemplo n.º 15
0
            // x-height?
            // cap-height?

            public bool TrySet(TextRenderInfo renderInfo)
            {
                var p1 = renderInfo.GetBaseline().GetStartPoint();
                var p2 = renderInfo.GetBaseline().GetEndPoint();

                if (p1[1] != p2[1] ||
                    p1[2] != p2[2] ||
                    p1[2] != 1)
                {
                    return(false);
                }
                OriginX     = p1[0];
                OriginY     = p1[1];
                Advancement = p2[0] - p1[0];
                p1          = renderInfo.GetAscentLine().GetStartPoint();
                p2          = renderInfo.GetAscentLine().GetEndPoint();
                if (p1[1] != p2[1] ||
                    p1[2] != p2[2] ||
                    p1[2] != 1 ||
                    Advancement != p2[0] - p1[0])
                {
                    return(false);
                }
                Ascent = p1[1] - OriginY;
                if (Ascent < 0)
                {
                    return(false);
                }
                p1 = renderInfo.GetDescentLine().GetStartPoint();
                p2 = renderInfo.GetDescentLine().GetEndPoint();
                if (p1[1] != p2[1] ||
                    p1[2] != p2[2] ||
                    p1[2] != 1 ||
                    Advancement != p2[0] - p1[0])
                {
                    return(false);
                }
                Descent = OriginY - p1[1];
                if (Descent < 0)
                {
                    return(false);
                }
                return(true);
            }
Ejemplo n.º 16
0
        /// <summary>
        /// Determines the color that will mark the text snippet based on the
        /// position of the snippet (in case it's an artifact) or it's style
        /// (font name and size).
        /// </summary>
        /// <param name="textRenderInfo">the TextRenderInfo object</param>
        /// <param name="top">the Y position of the top margin</param>
        /// <returns>a color that will be used to mark the text snippet</returns>
        static BaseColor GetColor(TextRenderInfo textRenderInfo, float top)
        {
            if (textRenderInfo.GetBaseline().GetStartPoint()[1] > top)
            {
                return(artifactColor);
            }
            TextStyle ts = new TextStyle(textRenderInfo);

            return(textStyles[ts]);
        }
Ejemplo n.º 17
0
        private static LineSegment GetSegment(TextRenderInfo info)
        {
            var segment = info.GetBaseline();

            if (Math.Abs(info.GetRise()) > 0.01)
            {
                segment.TransformBy(new Matrix(0, -info.GetRise()));
            }
            return(segment);
        }
Ejemplo n.º 18
0
        public CharacterRenderInfo(TextRenderInfo tri)
            : base(tri == null ? "" : tri.GetText(), tri == null ? null : GetLocation(tri))
        {
            if (tri == null)
            {
                throw new ArgumentException("TextRenderInfo argument is not nullable.");
            }
            if (tri.GetText().Length != 1)
            {
                throw new ArgumentException("CharacterRenderInfo objects represent a single character. They should not be made from TextRenderInfo objects containing more than a single character of text."
                                            );
            }
            // determine bounding box
            float x0 = tri.GetDescentLine().GetStartPoint().Get(0);
            float y0 = tri.GetDescentLine().GetStartPoint().Get(1);
            float h  = tri.GetAscentLine().GetStartPoint().Get(1) - tri.GetDescentLine().GetStartPoint().Get(1);
            float w  = Math.Abs(tri.GetBaseline().GetStartPoint().Get(0) - tri.GetBaseline().GetEndPoint().Get(0));

            this.boundingBox = new Rectangle(x0, y0, w, h);
        }
 public virtual void EventOccurred(IEventData data, EventType type)
 {
     if (type.Equals(EventType.RENDER_TEXT))
     {
         TextRenderInfo renderInfo  = (TextRenderInfo)data;
         bool           firstRender = result.Length == 0;
         bool           hardReturn  = false;
         LineSegment    segment     = renderInfo.GetBaseline();
         Vector         start       = segment.GetStartPoint();
         Vector         end         = segment.GetEndPoint();
         if (!firstRender)
         {
             Vector x1 = lastStart;
             Vector x2 = lastEnd;
             // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
             float dist = (x2.Subtract(x1)).Cross((x1.Subtract(start))).LengthSquared() / x2.Subtract(x1).LengthSquared
                              ();
             float sameLineThreshold = 1f;
             // we should probably base this on the current font metrics, but 1 pt seems to be sufficient for the time being
             if (dist > sameLineThreshold)
             {
                 hardReturn = true;
             }
         }
         // Note:  Technically, we should check both the start and end positions, in case the angle of the text changed without any displacement
         // but this sort of thing probably doesn't happen much in reality, so we'll leave it alone for now
         if (hardReturn)
         {
             //System.out.println("<< Hard Return >>");
             AppendTextChunk("\n");
         }
         else
         {
             if (!firstRender)
             {
                 if (result[result.Length - 1] != ' ' && renderInfo.GetText().Length > 0 && renderInfo.GetText()[0] != ' ')
                 {
                     // we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
                     float spacing = lastEnd.Subtract(start).Length();
                     if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                     {
                         AppendTextChunk(" ");
                     }
                 }
             }
         }
         //System.out.println("Inserting implied space before '" + renderInfo.getText() + "'");
         //System.out.println("Displaying first string of content '" + text + "' :: x1 = " + x1);
         //System.out.println("[" + renderInfo.getStartPoint() + "]->[" + renderInfo.getEndPoint() + "] " + renderInfo.getText());
         AppendTextChunk(renderInfo.GetText());
         lastStart = start;
         lastEnd   = end;
     }
 }
Ejemplo n.º 20
0
            public override void RenderText(TextRenderInfo renderInfo)
            {
                base.RenderText(renderInfo);

                //Vector bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
                Vector    bottomLeft = renderInfo.GetBaseline().GetStartPoint();
                Vector    topRight   = renderInfo.GetAscentLine().GetEndPoint();
                TextChunk tc         = new TextChunk(renderInfo.GetText(), bottomLeft, topRight, renderInfo.GetSingleSpaceWidth());

                TextChunks.Add(tc);
            }
Ejemplo n.º 21
0
        public void RenderText(TextRenderInfo renderInfo)
        {
            var a           = renderInfo.GetBaseline();
            var ascentLine  = renderInfo.GetAscentLine();
            var a2          = renderInfo.GetSingleSpaceWidth();
            var descentLine = renderInfo.GetDescentLine();
            var a4          = renderInfo.GetUnscaledBaseline();
            var a5          = renderInfo.GetFont();
            var a6          = renderInfo.GetRise();
            var a7          = renderInfo.GetText();

            bool        flag1      = this.result.Length == 0;
            bool        flag2      = false;
            LineSegment baseline   = renderInfo.GetBaseline();
            Vector      startPoint = baseline.GetStartPoint();
            Vector      endPoint   = baseline.GetEndPoint();

            if (!flag1)
            {
                Vector v         = startPoint;
                Vector lastStart = this.lastStart;
                Vector lastEnd   = this.lastEnd;
                if ((double)(lastEnd.Subtract(lastStart).Cross(lastStart.Subtract(v)).LengthSquared / lastEnd.Subtract(lastStart).LengthSquared) > 1.0)
                {
                    flag2 = true;
                }
            }

            RectangleF rectCurrent = getRenderRectangleF(renderInfo);


            if (flag2)
            {
                this.AppendTextChunk('\n');
            }
            //else if (!flag1 && this.result[this.result.Length - 1] != ' ' && (renderInfo.GetText().Length > 0 && renderInfo.GetText()[0] != ' ') && (double)this.lastEnd.Subtract(startPoint).Length > (double)renderInfo.GetSingleSpaceWidth() / 2.0)
            //    this.AppendTextChunk(' ');
            this.AppendTextChunk(renderInfo.GetText());
            this.lastStart = startPoint;
            this.lastEnd   = endPoint;
        }
            public void RenderText(TextRenderInfo renderInfo)
            {
                Text.Append(renderInfo.GetText());
                LineSegment segment = renderInfo.GetBaseline();
                Vector      start   = segment.GetStartPoint();

                Text.Append(Constants.CharSeparator);
                Text.Append(start[Vector.I1]);
                Text.Append(Constants.PointSeparator);
                Text.Append(start[Vector.I2]);
                Text.Append(Constants.MainSeparator);
            }
 public virtual void EventOccurred(IEventData data, EventType type)
 {
     if (type.Equals(EventType.RENDER_TEXT))
     {
         TextRenderInfo         renderInfo = (TextRenderInfo)data;
         IList <TextRenderInfo> subs       = renderInfo.GetCharacterRenderInfos();
         for (int i = 0; i < subs.Count; i++)
         {
             TextRenderInfo charInfo = subs[i];
             glyphWith = charInfo.GetBaseline().GetLength();
         }
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a TextItem based on a TextRenderInfo object.
        /// </summary>
        /// <param name="textRenderInfo">the TextRenderInfo object</param>
        /// <param name="top">the Y coordinate of the top margin</param>
        public TextItem(TextRenderInfo textRenderInfo, float top)
        {
            textStyles.Add(new TextStyle("FranklinGothic", 10.5f), BaseColor.ORANGE);
            textStyles.Add(new TextStyle("FranklinGothic", 8f), BaseColor.GREEN);
            textStyles.Add(new TextStyle("NewBaskerville", 10f), BaseColor.BLUE);
            textStyles.Add(new TextStyle("Courier", 9.5f), BaseColor.BLUE);
            textStyles.Add(new TextStyle("CombiNumerals", 13.5f), BaseColor.PINK);


            baseline  = textRenderInfo.GetBaseline().GetStartPoint()[1];
            rectangle = GetRectangle(textRenderInfo);
            color     = GetColor(textRenderInfo, top);
        }
        public override void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment = renderInfo.GetBaseline();

            if (renderInfo.GetRise() != 0)
            { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
                Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                segment = segment.TransformBy(riseOffsetTransform);
            }
            TextChunk tc = new TextChunk(renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment));

            locationalResult.Add(tc);
        }
            public void RenderText(TextRenderInfo renderInfo)
            {
                Vector start = renderInfo.GetBaseline().GetStartPoint();
                float  x     = start[Vector.I1];
                float  y     = start[Vector.I2];

                //        System.out.println("Display text: '" + renderInfo.getText() + "' (" + x + "," + y + ")");
                if (y > _lastY)
                {
                    Assert.Fail("Text has jumped back up the page");
                }
                _lastY = y;
            }
Ejemplo n.º 27
0
            public virtual void RenderText(TextRenderInfo renderInfo)
            {
                IList <TextRenderInfo> subs             = renderInfo.GetCharacterRenderInfos();
                TextRenderInfo         previousCharInfo = subs[0];

                for (int i = 1; i < subs.Count; i++)
                {
                    TextRenderInfo charInfo          = subs[i];
                    Vector         previousEndPoint  = previousCharInfo.GetBaseline().GetEndPoint();
                    Vector         currentStartPoint = charInfo.GetBaseline().GetStartPoint();
                    AssertVectorsEqual(previousEndPoint, currentStartPoint, charInfo.GetText());
                    previousCharInfo = charInfo;
                }
            }
Ejemplo n.º 28
0
    public override void RenderText(TextRenderInfo renderInfo)
    {
        textLineFinder.RenderText(renderInfo);
        LineSegment segment = renderInfo.GetBaseline();

        if (renderInfo.GetRise() != 0)      // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
        {
            Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
            segment = segment.TransformBy(riseOffsetTransform);
        }
        TextChunk location = new HorizontalTextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), textLineFinder);

        getLocationalResult().Add(location);
    }
Ejemplo n.º 29
0
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            bool firstRender = results.Count == 0;

            LineSegment segment = renderInfo.GetBaseline();
            Vector      start   = segment.GetStartPoint();
            Vector      end     = segment.GetEndPoint();

            int currentLineKey = (int)start[1];

            if (!firstRender)
            {
                Vector x0 = start;
                Vector x1 = lastStart;
                Vector x2 = lastEnd;

                float distance = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f;
                if (distance <= sameLineThreshold)
                {
                    currentLineKey = (int)lastStart[1];
                }
            }
            currentLineKey = currentLineKey * -1;

            if (!results.ContainsKey(currentLineKey))
            {
                results.Add(currentLineKey, new StringBuilder());
            }

            if (!firstRender &&
                results[currentLineKey].Length != 0 &&
                !results[currentLineKey].ToString().EndsWith(" ") &&
                renderInfo.GetText().Length > 0 &&
                !renderInfo.GetText().StartsWith(" "))
            {
                float spacing = lastEnd.Subtract(start).Length;
                if (spacing > renderInfo.GetSingleSpaceWidth() / 2f)
                {
                    results[currentLineKey].Append(" ");
                }
            }

            results[currentLineKey].Append(renderInfo.GetText());

            lastStart = start;
            lastEnd   = end;
        }
Ejemplo n.º 30
0
        public virtual void EventOccurred(IEventData data, EventType type)
        {
            if (type.Equals(EventType.RENDER_TEXT))
            {
                TextRenderInfo renderInfo = (TextRenderInfo)data;
                LineSegment    segment    = renderInfo.GetBaseline();
                if (renderInfo.GetRise() != 0)
                {
                    // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to
                    Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise());
                    segment = segment.TransformBy(riseOffsetTransform);
                }
                if (useActualText)
                {
                    CanvasTag lastTagWithActualText = lastTextRenderInfo != null?FindLastTagWithActualText(lastTextRenderInfo
                                                                                                           .GetCanvasTagHierarchy()) : null;

                    if (lastTagWithActualText != null && lastTagWithActualText == FindLastTagWithActualText(renderInfo.GetCanvasTagHierarchy
                                                                                                                ()))
                    {
                        // Merge two text pieces, assume they will be in the same line
                        LocationTextExtractionStrategy.TextChunk lastTextChunk = locationalResult[locationalResult.Count - 1];
                        Vector mergedStart = new Vector(Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(0), segment.GetStartPoint
                                                                     ().Get(0)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(1), segment.GetStartPoint().Get
                                                                                              (1)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(2), segment.GetStartPoint().Get(2)));
                        Vector mergedEnd = new Vector(Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(0), segment.GetEndPoint
                                                                   ().Get(0)), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(1), segment.GetEndPoint().Get(1)
                                                                                        ), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(2), segment.GetEndPoint().Get(2)));
                        LocationTextExtractionStrategy.TextChunk merged = new LocationTextExtractionStrategy.TextChunk(lastTextChunk
                                                                                                                       .GetText(), tclStrat.CreateLocation(renderInfo, new LineSegment(mergedStart, mergedEnd)));
                        locationalResult[locationalResult.Count - 1] = merged;
                    }
                    else
                    {
                        String actualText = renderInfo.GetActualText();
                        LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(actualText != null
                             ? actualText : renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment));
                        locationalResult.Add(tc);
                    }
                }
                else
                {
                    LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(renderInfo.GetText
                                                                                                                   (), tclStrat.CreateLocation(renderInfo, segment));
                    locationalResult.Add(tc);
                }
                lastTextRenderInfo = renderInfo;
            }
        }