At 9:09 am -0500 17/03/01, Ronald J Kimball wrote:
>I don't think Bart has misunderstood the problem at all.
With the greatest respect I think you have both misunderstood what I
was driving at.
>Take the first four characters, which indicate the type.
That IS the problem. Those four merry little characters (which may be
'TEXT' or 'styl' or any number of things) are buried contiguously in
a mush of all sorts of other unrelated stuff. The problem is how to
pick them out of the mush.
>Take the next however many bytes, which indicate the length of the
>section of that type. Take the contents of the section, using the
>indicated length.
>
>Repeat as necessary.
Absolutely. If you were to look at the small script in my original
posting, you would see that is exactly what does happen.
> > The first two bytes of a 'styl' record comprise a 'short' which
>> specifies the number of individual styles to be found in the record.
>
>It seems to me that this is the only tricky part; some types use a long for
>the length encoding, and some use a short. There must be a table of these
>somewhere.
That is all set out in IM 'Text' Chapter 2. The structure of the
clipboard style record is the same as the TextEdit style record.
Authors of applications involving text are supposed to implement TE
style records on the clipboard in addition to their own specific
style records. Even MS_Word respects that rule.
>Do you really think that the OS and existing applications uses regexes to
>parse the contents of the clipboard?
This is precisely the dilemma. With the string returned by
LMGetScrapHandle there is no indication of where the 'styl' record is
located so there is no way of isolating it (with MacPerl) except by a
pattern match -- not one that I can think of at any rate.
The Toolbox 'Scrap Manager' (IM MoreMacintoshToolbox Chapter 2),
which put it there in the first place, keeps the address in a
pointer. Unfortunately Scrap Manager routines are not available in
the MacPerl Toolbox.
Maybe it is not possible to acquire the 'styl' record (safely) by
purely MacPerl methods. It is certainly possible to extract it
(safely) with AppleScript but the origin of this thread was a
request for a way of doing it with MacPerl that _didn't_ involve
Applescript.
This does it for instance:
my $str = MacPerl::DoAppleScript qq(
set myRec to the Clipboard as record
styled Clipboard text of myRec
);
print "$str\n";
It would be an improvement as an AEBuild but I haven't been able to
get that to work yet I must confess.
Alan Fry