>On Wed, 14 Mar 2001 21:20:46 +0900, Nobumi Iyanaga wrote:
>
> >I have a MacPerl script which gets the 'styl' resource from a file (of
> >SimpleText type), and analyses it (it is a friend of mine who wrote this
> >script)
>
>Some friends you have. I would very much like to see that script.
>
>As for your problem: Perl has good access to the toolbox, so I think it
>must be feasable to make MacPerl get the data directly from the
>clipboard, without aid of Applescript? Anybody?
>

Hello Detlef, Bart, Alan,

Here is what I could get so far:

I run this AppleScript script:

set stxt to the clipboard as styled text
set stxtRecord to stxt as record
set txt to <<class ktxt>> of stxtRecord
set stl to <<class ksty>> of stxtRecord
-- I changed 0xC7 to "<<" and 0xC8 to ">>" because they don't pass through
-- the email communication (Japanese setting...)

set fref to open for access file "Macintosh HD:Desktop Folder:stylres" with 
write permission
try
        write stl to fref
on error
        close access fref
end try
close access fref

tell application "MacJPerl"
        set res to Do Script "Macintosh HD:Desktop Folder:Perl scripts:Read 
StyledText:readStylTest2.pl" mode Batch
end tell
res
--End of AppleScript

And the "readStyleTest2.pl" (that is a modified version of the script my 
friend wrote) is:

#!perl -w
use Mac::Fonts;

my ($buf, $nsty, $ofs, $is, $styl1, $strt, $high, $asct, $font, $face1, 
$delim);
my ($size, $r, $g, $b, $face, $fontname);

open (IN, "Macintosh HD:Desktop Folder:stylres") || die;

while (<IN>) {
        $buf .= $_;
}

close (IN);

$nsty = unpack("n", substr($buf, 0, 2));
print "# styles : $nsty\n";
print "offset\thi\tas\tfontID\tfont name\tstyle\tsize (R,\tG,\tB)
----------------------------------------------------------------------
";
for($ofs=2, $is=0; $is<$nsty; ++$is, $ofs+=20) {
        $styl1 = substr($buf, $ofs, 20);
        ($strt, $high, $asct, $font, $face1, $delim, $size, $r, $g, $b)
                        = unpack("NnnnB8Cnnnn", $styl1);
        $face = "";
        foreach(qw{B I U O S C E R}) { $face .= $_ if chop($face1); }

        $fontname = GetFontName($font);
        print 
"$strt\t$high\t$asct\t$font\t$fontname\t$face\t$size\t$r\t$g\t$b\n";
}
__END__

With the combination of these AppleScript and MacPerl script, I can get 
results like the following:

# styles : 56
offset  hi      as      fontID  font name       style   size (R,        G, 
        B)
----------------------------------------------------------------------
0       13      10      3       Geneva  B       10      0       0       0
3       13      10      3       Geneva          10      0       0       0
9       13      10      3       Geneva  B       10      0       0       0
11      13      10      3       Geneva          10      0       0       0
43      12      10      16384   Osaka   I       9       0       0       0
....

--------

If I could write all this in MacJPerl, I would be very glad.  But it seems 
that the data that I get from (the code by Alan Fry):

        use Mac::LowMem;
         my $lmh = LMGetScrapHandle;
         my $str = $lmh->get;

seems not exactly the same thing as the styled text that I get with the 
AppleScript:

set stxt to the clipboard as styled text

Anyway, I would like to avoid writing styl data to a file and pass that 
data directly to MacJPerl.

By the way, I can do easily the same thing with Frontier:

on styleEditor () {
        local (data);
        with objectModel, verbs.apps.Style {
                if isRunning () {
                        if exists (window [1]) {
                                with window [1] {
                                        data = get (selection, 'STXT');
                                        return (data);
                                        }};
                        return ("")};
                return ("")}};
local (styl = styleEditor (), res);
on STXTtoTEXTAndStyl (STXTData, returnValue = "styl") {
        local (tempRec, tempData);
        tempRec = record (STXTData);
        if returnValue == "" {
                return (tempRec)};
        if returnValue == "styl" {
                tempData = binary (tempRec ['ksty']);
                setBinaryType (@tempData, 'styl');
                return (tempData)};
        if returnValue == "TEXT" {
                tempData = binary (tempRec ['ktxt']);
                setBinaryType (@tempData, 'TEXT');
                return (tempData)};
        };
styl = STXTtoTEXTandStyl (styl);
toys.writeWholeFile ("Macintosh HD:Desktop Folder:stylRes", styl, 'TEXT', 
'????', clock.now ());
res = macJPerl.doScript ({string (styledTextExtra2.getStylePerlScr)}, 
mode:MacJPerl.batch);

But I cannot pass the styl data directly to the Perl script either.

I would appreciate any ideas.

Thank you in advance.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan

Reply via email to