Viewing the size of stack elements (AKA, where have all the bytes gone?)
Tariel Gogoberidze
tariel at mac.com
Tue May 23 17:31:27 EDT 2006
On May 23, 2006, at 18:33:57 +0100, Ben Rubinstein wrote:
>
> The kind of thing I'd like in an ideal world is something that would
> be able
> to tell me the number of bytes in an (uncompressed, unencrypted) stack
> file
> taken up by an object and then make it possible to drill down. So a
> stack
> file consists of I guess a header which occupies some number of bytes,
> and a
> number of stacks each of which occupy some number of bytes. Similarly
> the
> size of a stack can presumably be broken down into a header,
> properties (inc
> stack script), audioclips, videoclips, cards, and possibly groups?
> Each of
> those values (apart from the header) can similarly be drilled down
> into.
>
> Is there any available that would produce such a report, or the data
> for it?
> If not, how difficult would it be? As far as I can tell, Transcript
> doesn't
> expose much information: there is a "size" property, but according to
> the docs
> it's only applicable to a few objects - and for stacks always returns
> "10000".
> I can iterate over properties and discover their size; but for, say,
> a
> field, I don't know whether how the text is stored differs according
> to eg how
> much of it is styled, whether it contains unicode elements, etc. Also
> AFAICT,
> there isn't even a way to iterate over the properties of an object (is
> this
> right?) - 'the properties' according to the docs is not complete.
'the properties' is pretty much complete, I checked a while ago. The
missing properties are either redundant or introduced for HyperCard /
SyperCard compatibility, like "Size" property you mentioned. For
example, there is no height or width but "the rect" covers them both
and same goes with "the colors" which returns 10 line description of
all separate color properties)
So, you can try something like this..
on GetSizes
repeat with j= 1 to number of controls
put the effective properties of control j into tPropArray
combine tPropArray using numToChar (24) and numToChar (25)
put the short name of control j & " = " & number of chars of
tPropArray & cr after tSizeList
put tPropArray & numToChar (26) after tAllPropArray
end repeat
put number of chars of tAllPropArray & cr & tSizeList
-- write tAllPropArray to file
end GetSizes
and when used in reverse it recreates text styles of field as well
(not sure about unicode stuff but you can check with "reverse" function
below)
on RestoreProps
-- in new stack, read tAllPropArray from file
lock messages
lock screen
set itemDel to numToChar (26)
repeat with j= 1 to number of items of tAllPropArray
put item j of tAllPropArray into tPropArray
split tPropArray using numToChar (24) and numToChar (25)
put tPropArray ["ID"] into tID
set the properties of control ID tID to tPropArray
set the properties of control ID tID to tPropArray -- to overwrite
auto settings
end repeat
unlock screen
unlock messages
end RestoreProps
Of course all above would not account for custom properties, audio /
video clips etc but comparing original and "recreated" stack may give
you some info you need.
I even use similar functions as UNDO engine for relatively small stacks
but there is a catch. Some properties when set would trigger auto
setting of another property so "recreation" should be done in two
passes or in specific order.
best regards
Tariel
More information about the use-livecode
mailing list