コード例 #1
0
        /// <summary>Gets the ascentline for the text (i.e.</summary>
        /// <remarks>
        /// Gets the ascentline for the text (i.e. the line that represents the topmost extent that a string of the current font could have)
        /// This value includes the Rise of the draw operation - see
        /// <see cref="GetRise()"/>
        /// for the amount added by Rise
        /// </remarks>
        /// <returns>the ascentline line segment</returns>
        public virtual LineSegment GetAscentLine()
        {
            float ascent = gs.GetFont().GetFontProgram().GetFontMetrics().GetTypoAscender() * gs.GetFontSize() / 1000f;

            return(GetUnscaledBaselineWithOffset(ascent + gs.GetTextRise()).TransformBy(textToUserSpaceTransformMatrix
                                                                                        ));
        }
コード例 #2
0
        private void WriteText(String @operator, IList <PdfObject> operands, PdfArray cleanedText, PdfCanvas canvas
                               )
        {
            CanvasGraphicsState canvasGs = canvas.GetGraphicsState();
            bool newLineShowText         = "'".Equals(@operator) || "\"".Equals(@operator);

            if (newLineShowText)
            {
                if (canvasGs.GetLeading() != currLeading)
                {
                    canvas.SetLeading((float)currLeading);
                }
                // after new line operator, removed text shift doesn't matter
                removedTextShift = null;
            }
            PdfTextArray tjShiftArray = null;

            if (removedTextShift != null)
            {
                float tjShift = (float)removedTextShift * 1000 / (canvasGs.GetFontSize() * canvasGs.GetHorizontalScaling()
                                                                  / 100);
                tjShiftArray = new PdfTextArray();
                tjShiftArray.Add(new PdfNumber(tjShift));
            }
            if (cleanedText != null)
            {
                if (newLineShowText)
                {
                    // char spacing and word spacing are set via writeNotAppliedTextStateParams() method
                    canvas.NewlineText();
                }
                if (removedTextShift != null)
                {
                    tjShiftArray.AddAll(cleanedText);
                    cleanedText = tjShiftArray;
                }
                canvas.ShowText(cleanedText);
            }
            else
            {
                if (removedTextShift != null)
                {
                    canvas.ShowText(tjShiftArray);
                }
                PdfCleanUpProcessor.WriteOperands(canvas, operands);
            }
        }
コード例 #3
0
        /// <summary>Provides detail useful if a listener needs access to the position of each individual glyph in the text render operation
        ///     </summary>
        /// <returns>
        /// A list of
        /// <see cref="TextRenderInfo"/>
        /// objects that represent each glyph used in the draw operation. The next effect is if there was a separate Tj opertion for each character in the rendered string
        /// </returns>
        public virtual IList <iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo> GetCharacterRenderInfos()
        {
            IList <iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo> rslt = new List <iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo
                                                                                        >(@string.GetValue().Length);

            PdfString[] strings    = SplitString(@string);
            float       totalWidth = 0;

            foreach (PdfString str in strings)
            {
                float[] widthAndWordSpacing = GetWidthAndWordSpacing(str);
                iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo subInfo = new iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo
                                                                                 (this, str, totalWidth);
                rslt.Add(subInfo);
                totalWidth += (widthAndWordSpacing[0] * gs.GetFontSize() + gs.GetCharSpacing() + widthAndWordSpacing[1]) *
                              (gs.GetHorizontalScaling() / 100f);
            }
            foreach (iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo tri in rslt)
            {
                tri.GetUnscaledWidth();
            }
            return(rslt);
        }