/**************************************************************************/
/*                            GetPicSize.ucwx                             */
/*                                                                        */
/*                    Copyright ©1998 by Dick Whiting                     */
/*                                                                        */
/*------------------------------------------------------------------------*/
/* Used with UrbCedWWW for getting HEIGHT,WIDTH info of a pic.            */
/* This uses Visage - By Magnus Holmgren, but could be modified for use   */
/* with other users supporting similar commands.                          */   
/* See the UrbCedWWW Readme for a more complete description.              */
/**************************************************************************/
/*
$VER: 1.0 Copyright ©1998 by Dick Whiting
*/

viewer='UTILS:VISAGE %f INFO'     /* command for getting info             */
ENABLED=0                         /* change to ENABLED=1 to enable script */


/**************************************************************************/
/*                      Nothing to change below here                      */
/**************************************************************************/
if ~enabled then exit                       /* not enabled...exit         */

options results
Address CYGNUSED

'CEDTOFRONT'

'STATUS CURSORLINE'
origline=result+1

'STATUS CURSORCOLUMN'
origcol=result+1

'SEARCH FOR' 'SRC=' 1 0 0 0 1
found=result

if ~found then do
   'OKAY1' 'Cannot locate SRC= for picture'
   exit
end

'STATUS CURSORLINE'
startline=result+1

'STATUS CURSORCOLUMN'
startcol=result+6

'LL' startline startcol

'MARK'
on=result
if ~on then 'MARK'

'SEARCH FOR' '"""' 0 0 1 0 1
found=result

if ~found then do
   'OKAY1' 'Cannot locate end of name for picture'
   exit
end

'STATUS CURSORLINE'
endline=result+1

'STATUS CURSORCOLUMN'
endcol=result

'COPY'
if ~result then do
   'OKAY1' 'Copy name to clip failed'
   exit
end

'STATUS BLOCKBUFFER'
filename=result

'STATUS RESTNAME'
rest=result
if rest='' then do
   'OKAY1' "You must save the file first"
   exit
end

'STATUS FILENAME'
fullfn=result

path=substr(fullfn,1,pos(rest,fullfn)-1)

select
   when substr(filename,1,3)='../' then do
      path=substr(path,1,length(path)-1)
      path=substr(path,1,lastpos('/',path))
      filename=path||substr(filename,4)
   end
   otherwise filename=path||filename
end

'STATUS INSERTMODE'
ison=result

if ~ison then 'INSERT MODE'

found=0

do i=1 to words(viewer)
   if word(viewer,i)="%f" then do
      found=1
      leave i
   end
end

if found then do
   viewer=subword(viewer,1,i-1)||' "'||filename||'" '||subword(viewer,i+1)
   viewer=viewer||' >T:getpic.txt'
   Address Command viewer
   goodopen=open('IN','T:getpic.txt','R')
   if goodopen then do
      titleline=readln('IN')
      message=readln('IN')
      message=substr(message,4)
      if word(message,1)="Couldn't" then do
         'OKAY1' message
         exit
      end
      type=strip(word(message,1))
      size=strip(word(message,2))
      name=strip(subword(message,4))
      parse var size width'x'height'x'depth
      'LL' origline origcol
      'TEXT' ' WIDTH="'strip(width)'" HEIGHT="'strip(height)'"'
   end
   else do
      'OKAY1' 'Unable to open T:getpic.txt'
      exit
   end
   foo=close('IN')
   Address Command 'DELETE T:getpic.txt QUIET'
end
else do
   'OKAY1' 'Viewer command is invalid'
   exit
end

return width height
