Practically Perfect Printing - Progress

Lynch, Jonathan BNZ2 at CDC.GOV
Mon Jan 10 16:41:31 EST 2005


I have a script worked out that seems to print nearly perfectly.

Occassionally, the second line of a field will get shifted upwards by 2
pixels, and I am not sure why that happens.

I am sure much tweaking will need to be done to enable this script to
apply to all situations. I am posting it here - but I imagine it will
get a little garbled by the automatic word-wrap. If anyone would like me
to Email it to them directly, just Email me, and I will do so.

It would be great if a few others could test this script on their
stacks, find bugs, and in general help make it perfect.

The basic principle is that it replaces characters in a field for small
fields in a group, with a single character in each field. This way, if a
character expands during printing, it does not shift around the other
characters on that line.


======================================================================

on mouseUp
  
  -- 1) create new stack with same properties as the original stack
  put the properties of this stack into myArray
  delete variable myArray[Name]
  Delete variable myArray[ID]
  Delete variable myArray[visible]
  put "pr" & the milliseconds into P
  create invisible stack P
  set the properties of stack P to myArray
  
  -- 2) copy the cards of the original stack to the new stack
  put the number of cards in this stack into Z
  repeat with X = 1 to Z
    copy card X of this stack to stack P
  end repeat
  
  -- 3) For every card in the new stack, replace fields with groups with
a separate field for each character
  put the number of cards in stack p into Z
  repeat with X = 1 to Z
    go card X of stack P
    
    -- 3.1) create an array with the id of each field on the card
    put the number of fields in Card X of stack P into ZZ
    repeat with XX = 1 to ZZ
      put the id of field XX into FID[XX]
    end repeat
    
    -- 3.2) group/field replacement process
    repeat with XX = 1 to ZZ
      -- 3.2.1) if field is owned by a group, create the new group
inside the group that owns the field
      if word 1 of (the long id of the owner of field ID FID[XX]) =
"group" then
        put "PG" & (the milliseconds) & XX into GF
        create group GF in group id (the id of the owner of field ID
FID[XX])
        set the relayergroupedcontrols to true
        set the layer of group GF to (the layer of field ID FID[XX]) + 1
        set the relayergroupedcontrols to false
        -- 3.2.1a) otherwise, just create the new group on the same page
as the field
      else
        put "PG" & (the milliseconds) & XX into GF
        create group GF
        set the layer of group GF to (the layer of field ID FID[XX]) + 1
      end if
      
      -- 3.2.3) set the rect of the new group to the rect of the
original field (minus borderwidth, if the border is visible)
      put the rect of field ID FID[XX] into FXXR
      if the showborder of field ID FID[XX] = true then
        put the borderwidth of field ID FID[XX] into BW
        add BW to item 1 of FXXR
        add BW to item 2 of FXXR
        subtract BW from item 3 of FXXR
        subtract BW from item 4 of FXXR
        set the rect of group GF to FXXR
      else
        set the rect of group GF to the rect of field ID FID[XX]
      end if
      set the locklocation of group GF to true
      set the margins of group GF to 0 --the margins of field XX 
      
      --3.3.3) for each character in the original field, create a field
that contains that character
      put the number of characters in field ID FID[XX] into ZZZ
      repeat with XXX = 1 to ZZZ
        create field ("C" & GF & XXX) in group GF
        set the showborder of field ("C" & GF & XXX) to false
        -- 3.3.3.1) the borderwidth affects the location of a character,
but not the formattedrect, so this must be compensated for
        set the borderwidth of field ("C" & GF & XXX) to the borderwidth
of field ID FID[XX]
        -- 3.3.3.2) the margins are set wide enough to allow for a
little expansion room when converted to printer font
        set the margins of field ("C" & GF & XXX) to 8
        set the fixedlineheight of field ("C" & GF & XXX) to false
        
        -- 3.3.3.3) the character is put into the new single-character
field
        put character XXX of field ID FID[XX] into field ("C" & GF &
XXX)
        
        -- 3.3.3.4) the defining information for the field is copied
        set the textsize of field ("C" & GF & XXX) to the effective
textsize of field ID FID[XX]
        set the textstyle of field ("C" & GF & XXX) to the effective
textstyle of field ID FID[XX]
        set the textfont of field ("C" & GF & XXX) to the effective
textfont of field ID FID[XX]
        set the textcolor of field ("C" & GF & XXX) to the effective
textcolor of field ID FID[XX] 
        
        -- 3.3.3.5) the defining information for the character is copied
        set the textsize of character 1 of field ("C" & GF & XXX) to the
textsize of character XXX of field ID FID[XX]
        set the textstyle of character 1 of field ("C" & GF & XXX) to
the textstyle of character XXX of field ID FID[XX]
        set the textfont of character 1 of field ("C" & GF & XXX) to the
textfont of character XXX of field ID FID[XX]
        set the textcolor of character 1 of field ("C" & GF & XXX) to
the textcolor of character XXX of field ID FID[XX] 
        set the backgroundcolor of character 1 of field ("C" & GF & XXX)
to the backgroundcolor of character XXX of field ID FID[XX]
        
        -- 3.3.3.6) the new single-character field is made transparent
        set the opaque of field ("C" & GF & XXX) to false
        
        -- 3.3.3.7) the location of the new single-character field is
set such that the formattedrect of the copied character is the same as
for the original character
        put the formattedrect of character 1 of field ("C" & GF & XXX)
into NFR
        put the formattedrect of character XXX of field ID FID[XX] into
FR
        put (item 1 of FR) + (the left of field ("C" & GF & XXX)) -
(item 1 of NFR) into item 1 of NFR
        put (item 2 of FR) + (the top of field ("C" & GF & XXX)) - (item
2 of NFR) into item 2 of NFR
        put (item 1 of NFR) + (the formattedwidth of field ("C" & GF &
XXX)) into item 3 of NFR
        put (item 2 of FR) + (the formattedheight of field ("C" & GF &
XXX)) + 10 into item 4 of NFR
        set the rect of field ("C" & GF & XXX) to NFR
        put the formattedrect of character 1 of field ("C" & GF & XXX)
into NNFR
      end repeat
      
      -- 3.3.4) the original field is emptied, but left in place in
order to use its border and background information
      --put empty into field ID FID[XX]
    end repeat
  end repeat
  
  -- 4) the first card of stack p is one that was not copied over - so
it is deleted
  delete card 1 of stack p
 -- set the visible of stack p to true
  print stack p
  delete stack p 
  
end mouseUp


More information about the use-livecode mailing list