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]