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

Notification

Icon
Error

Options
Go to last post Go to first unread
richard  
#1 Posted : Monday, July 22, 2019 6:49:56 PM(UTC)
richard

Rank: Member

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 20
Australia
Location: Sydney

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
Paul Rayman  
#2 Posted : Tuesday, July 30, 2019 3:27:50 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 844

Thanks: 2 times
Was thanked: 103 time(s) in 101 post(s)
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.

Edited by user Tuesday, July 30, 2019 4:15:11 AM(UTC)  | Reason: Fix a bug in the code

richard  
#3 Posted : Tuesday, July 30, 2019 5:34:44 AM(UTC)
richard

Rank: Member

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 20
Australia
Location: Sydney

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
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.