GetSingleSpaceWidth() public method

public GetSingleSpaceWidth ( ) : float
return float
コード例 #1
0
        /**
         * Captures text using a simplified algorithm for inserting hard returns and spaces
         * @param   renderInfo  render info
         */
        public virtual void RenderText(TextRenderInfo renderInfo)
        {
            bool firstRender = result.Length == 0;
            bool hardReturn  = false;

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

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

                // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).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() + "'");
                    }
                }
            }
            else
            {
                //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;
        }
コード例 #2
0
        public void RenderText(TextRenderInfo renderInfo)
        {
            bool hardReturn = false;

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

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

                // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
                float dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).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 >>");
                result.Append('\n');
            }
            else if (lastStart != null && lastEnd != null)
            {
                if (result[result.Length - 1] != ' ' && 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)
                    {
                        result.Append('\t');
                        //System.out.Println("Inserting implied space before '" + renderInfo.GetText() + "'");
                    }
                }
            }
            else
            {
                //System.out.Println("Displaying first string of content '" + text + "' :: x1 = " + x1);
            }

            //System.out.Println("[" + renderInfo.GetStartPoint() + "]->[" + renderInfo.GetEndPoint() + "] " + renderInfo.GetText());
            result.Append(renderInfo.GetText());

            lastStart = start;
            lastEnd = end;
        }
コード例 #3
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);
        }
コード例 #4
0
 public ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline)
 {
     return(new TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth()));
 }
コード例 #5
0
        /**
         *
         * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(com.itextpdf.text.pdf.parser.TextRenderInfo)
         */
        public void RenderText(TextRenderInfo renderInfo)
        {
            LineSegment segment  = renderInfo.GetBaseline();
            TextChunk   location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth());

            locationalResult.Add(location);
        }
コード例 #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="renderInfo"></param>
 public override void RenderText(TextRenderInfo renderInfo)
 {
     iTextSharp.text.pdf.parser.LineSegment segment = renderInfo.GetBaseline();
     TextChunkEx location = new TextChunkEx(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine());
     m_locationResult.Add(location);
 }
コード例 #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="renderInfo"></param>
 public override void RenderText(TextRenderInfo renderInfo)
 {
     LineSegment segment = renderInfo.GetBaseline();
     string x = renderInfo.GetText();
     TextChunk location = new TextChunk(renderInfo.GetText(), segment.GetStartPoint(), segment.GetEndPoint(), renderInfo.GetSingleSpaceWidth(), renderInfo.GetAscentLine(), renderInfo.GetDescentLine());
     m_locationResult.Add(location);
 }
コード例 #8
0
ファイル: PDF Reader.cs プロジェクト: ribcesoftware/Converter
        public 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 dist = (x2.Subtract(x1)).Cross((x1.Subtract(x0))).LengthSquared / x2.Subtract(x1).LengthSquared;

                float sameLineThreshold = 1f;
                if (dist <= 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;
        }