/// <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);
        }
        /// <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));
        }
 public CCharacterRenderInfo(TextRenderInfo tri)
     : base(tri)
 {
     /*
      * color matching text redaction
      */
     this.strokeColor = tri.GetStrokeColor();
     this.fillColor   = tri.GetFillColor();
 }
Exemplo n.º 4
0
        public Color?GetColor(TextRenderInfo text)
        {
            iText.Kernel.Colors.Color color;

            float alpha;

            switch (text.GetTextRenderMode())
            {
            case 0:     // Fill text
            case 4:     // Fill text and add to path for clipping
                color = text.GetFillColor();
                alpha = text.GetGraphicsState().GetFillOpacity();
                break;

            case 1:     //  Stroke text
            case 2:     //Fill, then stroke text
            case 5:     // Stroke text and add to path for clipping
            case 6:     // Fill, then stroke text and add to path for clipping
                color = text.GetStrokeColor();
                alpha = text.GetGraphicsState().GetStrokeOpacity();
                break;

            case 3:     // Invisible
                return(System.Drawing.Color.Transparent);

            case 7:     // Add text to padd for clipping
                return(System.Drawing.Color.Black);

            default: throw new ApplicationException("wrong render mode");
            }


//           var value = text.GetStrokeColor().GetColorValue();
//           if(value.Length==1&&value[0]==0)
//               value = text.GetFillColor().GetColorValue();
            return(GetColor(color, alpha));
        }
Exemplo n.º 5
0
 public CCharacterRenderInfo(TextRenderInfo tri)
     : base(tri)
 {
     this.strokeColor = tri.GetStrokeColor();
     this.fillColor   = tri.GetFillColor();
 }
        /// Captures text using a simplified algorithm for inserting hard returns and spaces
        ///     @param   renderInfo  render info
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            // todo handle adding last line

            string text = renderInfo.GetText().Replace('\t', ' ');

            if (!Utils.FloatsNearlyEqual(renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2), baseline, 0.01f) &&
                !Utils.FloatsNearlyEqual(renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2), ascent, 0.01f))
            {
                startOfNewline = true;
            }

            if (startOfNewline)
            {
                if (currLine != null)
                {
                    if (currChunk.ChunkStr.Length > 0)
                    {
                        StartNewWord();
                        startOfChunk = true;
                    }
                    currLine.RightMostPos     = bottomRight.Get(Vector.I1);
                    currLine.LineSpacingBelow =
                        currLine.Descent - renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2);
                }

                currLine = new LineMetrics();
                pageMetrics.AddLine(currLine);
                currLine.Ascent           = renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2);
                currLine.Descent          = renderInfo.GetDescentLine().GetStartPoint().Get(Vector.I2);
                currLine.Baseline         = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2);
                currLine.LeftMostPos      = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1);
                currLine.LineSpacingAbove = descent - currLine.Ascent;

                startOfNewline = false;
            }

            CharMetrics charMetrics;

            // Check if there is space char required between chunks
            if (GetResultantText().Length > 0 &&
                IsSpaceRequired(bottomRight.Get(Vector.I1), renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1),
                                renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2),
                                renderInfo.GetSingleSpaceWidth())) // todo switch order

            {
                charMetrics             = new CharMetrics(' ');
                charMetrics.BottomLeft  = new Vector3D(bottomLeft);
                charMetrics.TopLeft     = new Vector3D(topLeft);
                charMetrics.BottomRight = new Vector3D(renderInfo.GetBaseline().GetStartPoint());
                charMetrics.TopRight    = new Vector3D(renderInfo.GetAscentLine().GetStartPoint());
                this.charMetrices.Add(charMetrics);
                text = " " + text; // todo extra spacing? e.g. handle if it is 4x singlespace width
            }

            TextRenderInfo lastChar = null;
            int            charInd  = 0;

            foreach (TextRenderInfo charInfo in renderInfo.GetCharacterRenderInfos())
            {
                if (charInfo.GetText().Length == 0)
                {
                    continue;
                }

                if (lastChar != null && IsSpaceRequired(lastChar.GetBaseline().GetEndPoint().Get(Vector.I1),
                                                        charInfo.GetBaseline().GetStartPoint().Get(Vector.I1),
                                                        renderInfo.GetSingleSpaceWidth()))
                {
                    charMetrics             = new CharMetrics(' ');
                    charMetrics.FontSize    = charInfo.GetFontSize();
                    charMetrics.BottomLeft  = new Vector3D(lastChar.GetBaseline().GetEndPoint());
                    charMetrics.TopLeft     = new Vector3D(lastChar.GetAscentLine().GetEndPoint());
                    charMetrics.BottomRight = new Vector3D(charInfo.GetBaseline().GetStartPoint());
                    charMetrics.TopRight    = new Vector3D(charInfo.GetAscentLine().GetStartPoint());
                    charMetrices.Add(charMetrics);
                    text = text.Insert(charInd + 1, " ");
                }

                char c = charInfo.GetText()[0] == '\t' ? ' ' : charInfo.GetText()[0];
                charMetrics             = new CharMetrics(c);
                charMetrics.FontSize    = charInfo.GetFontSize();
                charMetrics.BottomLeft  = new Vector3D(charInfo.GetBaseline().GetStartPoint());
                charMetrics.TopLeft     = new Vector3D(charInfo.GetAscentLine().GetStartPoint());
                charMetrics.BottomRight = new Vector3D(charInfo.GetBaseline().GetEndPoint());
                charMetrics.TopRight    = new Vector3D(charInfo.GetAscentLine().GetEndPoint());
                charMetrices.Add(charMetrics);

                lastChar = charInfo;
                charInd++;
            }

            if (startOfChunk)
            {
                if (Utils.FloatsNearlyEqual(currLine.Baseline, baseline, 0.001f))
                {
                    float horSpacing = Math.Abs(
                        bottomRight.Get(Vector.I1) - renderInfo.GetBaseline().GetStartPoint().Get(Vector.I1));
                    if (horSpacing > spaceWidth)
                    {
                        Console.Write("");
                    }
                }

                bottomLeft           = renderInfo.GetBaseline().GetStartPoint();
                topLeft              = renderInfo.GetAscentLine().GetStartPoint();
                currChunk.BottomLeft = new Vector3D(bottomLeft);
                currChunk.TopLeft    = new Vector3D(topLeft);
                baseline             = renderInfo.GetBaseline().GetStartPoint().Get(Vector.I2);
                ascent     = renderInfo.GetAscentLine().GetStartPoint().Get(Vector.I2);
                descent    = renderInfo.GetDescentLine().GetStartPoint().Get(Vector.I2);
                spaceWidth = renderInfo.GetSingleSpaceWidth();

                startOfChunk = false;
            }

            bottomRight = renderInfo.GetBaseline().GetEndPoint();
            topRight    = renderInfo.GetAscentLine().GetEndPoint();

            string currFont = renderInfo.GetFont() != null?renderInfo.GetFont().ToString() : "";

            if (currChunk.FontFamily == null && currFont.Length > 0)
            {
                currChunk.FontFamily = currFont;
            }

            //Check if faux bold is used
            if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText) || // todo include render mode for outsets etc?
                renderInfo.GetFont().GetFontProgram().GetFontNames().IsBold())
            {
                currChunk.Bold = true;
            }

            if (!(Utils.FloatsNearlyEqual(renderInfo.GetFont().GetFontProgram().GetFontMetrics().GetItalicAngle(), 0, 0.001f)) ||
                renderInfo.GetFont().GetFontProgram().GetFontNames().IsItalic())
            {
                currChunk.Italic = true;
            }

            if (currChunk.FillColor == null && renderInfo.GetFillColor() != null)
            {
                currChunk.FillColor = ProcessColorInfo(renderInfo.GetFillColor());
            }

            if (currChunk.StrokeColor == null && renderInfo.GetStrokeColor() != null)
            {
                currChunk.StrokeColor = ProcessColorInfo(renderInfo.GetStrokeColor());
            }

            currChunk.Append(text);
            result.Append(text); // todo include newlines
        }