logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
richard Posted: Tuesday, July 30, 2019 2:34:44 AM(UTC)
 
Thanks Paul,

I've solved my issue (I think) but your code could be useful in future. You're right about using the NormalAppearance PdfTextObject bounding boxes to figure out dimensions, but they can't be used exactly as they sometimes overlap the bottom of the text control.

Regards,

Richard
Paul Rayman Posted: Tuesday, July 30, 2019 12:27:50 AM(UTC)
 
Hi,

I'm sorry to be late with the reply.

I did not quite understand your question. What exactly do you want?
If you want to find the number of lines that are fully displayed in the field, then, I think, that this is possible. Examining of NormalAppearance should help. You can get the bounding boxes of all objects in the NormalAppearance and calculate the number of rows. For example, how we do it in the NormalizeRects function (can be found in the source codes of PdVviewer)
A simplified version of which is
Code:
/// <summary>
/// Calculate rows
/// </summary>
/// <param name="rects">A collection of the bounding boxes of each object in NA</param>
/// <returns>A collection of the bounding boxes of each row</returns>
private List<FS_RECTF> NormalizeRects(IEnumerable<FS_RECTF> rects)
{
    List<FS_RECTF> rows = new List<FS_RECTF>();

    float left, right, top, bottom;
    left = bottom = float.MaxValue;
    right = top = float.MinValue;
    float lowestBottom = float.NaN;
    float highestTop = float.NaN;

    foreach (var rc in rects)
    {
        float h = (highestTop - lowestBottom);
        //check if new row is required
        if (float.IsNaN(lowestBottom))
        {
            lowestBottom = rc.bottom;
            highestTop = rc.top;
        }
        else if (rc.top < lowestBottom + h / 2 || rc.bottom > highestTop - h / 2)
        {
            rows.Add(new FS_RECTF(left, top, right, bottom));
            lowestBottom = rc.bottom;
            highestTop = rc.top;
            left = bottom = float.MaxValue;
            right = top = float.MinValue;
        }
        else
        {
            if (lowestBottom > rc.bottom)
                lowestBottom = rc.bottom;
            if (highestTop < rc.top)
                highestTop = rc.top;
        }

        //concatenate previous and current rectangle
        if (left > rc.left)
            left = rc.left;
        if (right < rc.right)
            right = rc.right;
        if (top < rc.top)
            top = rc.top;
        if (bottom > rc.bottom)
            bottom = rc.bottom;
    }
    rows.Add(new FS_RECTF(left, top, right, bottom));

    return rows;
}


Then you can examine the rectangle of each row and see if it goes beyond the field boundaries or not.
richard Posted: Monday, July 22, 2019 3:49:56 PM(UTC)
 
Hi Paul,

I'm looking to get the number of lines possible in a multiline text field set to DoNotScroll. Here is a text field as I created it in Foxit on the left (max two lines) and as it appears in Pdfium.



Notice the single M character on the fourth line. You're able to type up to this point and not further (always just the one character).

I've examined the NormalAppearance PdfTextObjects for the lines, hoping the bounding boxes dimensions would give me a clue, but it seems to be arbitrary whether a line will be a normal one or that single-character one at the bottom.

I've found this SO question which I'm hoping to try, but having trouble adapting it to Pdfium, mainly how to get that factor to calculate line spacing. Do you think the equivalent is possible with Pdfium?

Regards,

Richard