Page 1 of 1

New Field Property for accurate rendering information

Posted: Mon Dec 01, 2014 10:04 pm
by mdoub
I would like the forums assistance in flushing out a enhancement request proposal that I would like to make to the development team. Because of a bug in the pageranges function where it did not take into account the spaceabove and spacebelow properties, i attempted to do this manually. I quickly learned that there is no easy way to understand where a line is actually wrapped. I was using the formatted size functions measuring each character and run and getting different answers when measuring the same text. This was attributed to kerning and letter spacing issues by the support folks. This was not a very satisfying answer.

After working on this for several weeks, I have come to the conclusion that we can not accurately reproduce the algorithms of the field object with the current tools available to us. I would loved to be proven wrong here, but I threw in the towel and started thinking about the the information that is really needed to understand what is actually being displayed within a field.

I am proposing that a property or function be added to livecode field object. It would be similar to styled text, but it would provide a PERFECT representation of what is being displayed within a field. The structure returned would include all attributes needed to understand exactly how a field is laid out and how the text was flowed within the field.

For the purposes of this discussion a field is made up of lines.
A line is a string terminated by a return. A line is made up of softlines. A line may contain a single softline or multiple softlines. A softline is single row of text that fits in the visual area within the field. SoftLines are made up of runs as defined in styledtext. A tab character is considered a run.

Ok to be clear, a softline is each segment of a line that was wrapped to fit into the field.

Code: Select all


put the formatedStyledAttributes of fld "foo" into rArray

rArray:
    "height":
    "width":
    "dontwrap":
    "borderwidth":
    "leftMargin":
    "topMargin":
    "rightMargin":
    "bottomMargin":
    [line_Nbr]     --    a number for each string
                        --    terminated by a return
        "borderwidth":
        "leftIndent":
        "rightIndent":
        "padding":
        "spaceAbove":
        "spaceBelow":
        [softline_number]    --    this the segment of the
                                        --    line on a row within a field
            "MaxformattedHeight":      -- of the softline including all runs
            "MaxformattedWidth":       -- of the softline including all runs
                                                       -- these are included to make
                                                       -- calculating scroll positions easier
            "leftIndent":
            "firstIndent":    --    only applicable to the first
                                    --    segment of a paragraph
            "rightIndent":
            "padding":
            "listIndent":        --    listIndent and listdepth are needed
            "listdepth":         --    as part of the softline because lists
                                       --    can wrap
            [run_number]       --    this is the run within the soft line
                                        --    a tab character is considered a run
                "textSize":
                "textFont":
                "textStyle":
                "text":
                formattedHeight:
                formattedWidth:     --     when text = tab, this is the length
                                               --    of space allocated to the tab
            [run_number + 1]
        [softline_number + 1]
    [pgh_Nbr + 1]

Re: New Field Property for accurate rendering information

Posted: Mon Dec 01, 2014 10:15 pm
by dunbarx
Hi.

I want to make sure that I understand the definitions.
A line is a string terminated by a return. A line is made up of softlines. A line may contain a single softline or multiple softlines. A
Am I wrong in thinking that a line may not have any returns or "softLines", that is, a string fits within the formattedWidth of the field, er, period.

As if you had a nice big field "testField" and:

Code: Select all

put "abc" into fld "testField"
Craig Newman

Re: New Field Property for accurate rendering information

Posted: Mon Dec 01, 2014 10:15 pm
by FourthWorld
Would it be simpler to just fix pageRanges and other functions that rely on text metrics?

Re: New Field Property for accurate rendering information

Posted: Mon Dec 01, 2014 10:18 pm
by dunbarx
Does this bear at all on the thread of Nov 17: "Scrolling a field"?

Craig

Re: New Field Property for accurate rendering information

Posted: Tue Dec 02, 2014 2:19 am
by mdoub
Craig, you are correct. All lines don't have returns. So much for my specification writing career. The work that I did trying to address the Scrolling in a Field was a big part of the research that worked up to this proposal. I rarely use fields with fixed line heights to line wrapping is a big deal.

Richard, Yes we still want pageranges fixed as well as all of the other bugs associated with text formatting and measurement. This proposal deals with big picture issue of getting a clear picture of how the text was actually flowed by the engine. The two things that are currently not easily addressed or are not possible are: 1) how lines are exactly wrapped and 2) what was the space actually used for each tab.

-= Mike

Re: New Field Property for accurate rendering information

Posted: Tue Dec 02, 2014 3:48 am
by dunbarx
Mike.

By the way, your writing style is clear, cogent and compelling.

Your gadget contains mainly existing native properties, But I like the idea of the new "soft" ones. These likely would be very handy indeed.

Craig

Re: New Field Property for accurate rendering information

Posted: Tue Dec 02, 2014 6:18 pm
by mdoub
I was contacted directly with an idea that I will explore further. Apparently we can put the formattedText of a line of a field into a variable and it will retain the soft wrap characteristics of the original line. We might be able to derive the formatting information of each soft line as we should now know precicely the last character of each wrapped line.

off to experiment some more...

Re: New Field Property for accurate rendering information

Posted: Tue Dec 02, 2014 7:04 pm
by dunbarx
GodSpeed.

This is mighty weighty work for someone with eight posts. :wink:

Craig

Re: New Field Property for accurate rendering information

Posted: Tue Dec 02, 2014 10:23 pm
by bn
Hi,

I responded to Mike's post to the use-list. I was not aware of this discussion.

Here is the stack that makes an array with line number and for the lines the softLines numbers. Start- and End-Char number and number of chars are given for whole lines and the softLines.

From this information you can derive calls to different "formatted" properties of the field for chars or runs of chars. As well as get the "effective styledText" for a given char or group of chars.

Not very polished but seems to work. Although not extensively tested. For anyone who is interested in softLines :)

Kind regards

Bernd

Re: New Field Property for accurate rendering information

Posted: Wed Dec 03, 2014 4:06 pm
by mdoub
I am very happy to say that I was proven wrong. We ARE able get the information needed to understand how the engine calculated the soft line wraps. Many thanks to Bernd for his tip. If you put the formattedtext of a line that has be wrapped into a variable, the variable will contain the text of each segment of the line that was wrapped with returns inserted appropriately. Based on the number of characters in each line, you know where the line was wrapped.

Rather than asking for a new property, would it make more sense to ask that the styled text properly be updated to include additional information regarding wrapping? I am not so sure that setting this information makes sense but retrieving it seems reasonable.

-= Mike

Re: New Field Property for accurate rendering information

Posted: Wed Dec 03, 2014 5:25 pm
by mdoub
Here is a link to my MasterLibrary. Field formatting is an area that you can test forever, but I think it is good enough to share If there is a corner case that I missed, please let me know.

https://www.dropbox.com/s/3wpwn3hfbmpl7 ... ecode?dl=0

I included a soft break function as well as a function that gives you page ranges that takes into account the spaceabove and spacebelow.