~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/mb/mb-gs.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # mb-gs.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1997-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/mb/mb-gs.tcl,v 1.8 2002/02/03 04:27:17 lim Exp $
 32 
 33 
 34 import GPSinterp
 35 
 36 #
 37 # customized interpreter to work with MBPSProcessor
 38 #
 39 Class MBPSInterp -superclass GPSinterp
 40 
 41 MBPSInterp instproc init pswin {
 42     $self instvar orient_ pswin_ path_ width_ height_
 43 
 44     $self next $pswin
 45     set width_ 0
 46     set height_ 0
 47 
 48     $pswin_ Init $self
 49 }
 50 
 51 #$MBPSInterp instproc destroy {} {
 52 #    DbgOut "in MBPSInterp instproc destroy"
 53 #    $self next
 54 #}
 55 
 56 MBPSInterp instproc get_pixmap {args} {
 57     $self instvar pswin_
 58     return [eval $pswin_ get_pixmap $args]
 59 }
 60 
 61 MBPSInterp instproc pixmap-id {} {
 62      $self instvar pswin_
 63      return [expr [$pswin_ pixmap-id]]
 64 }
 65 
 66 MBPSInterp instproc width {} {
 67     $self instvar width_
 68     return $width_
 69 }
 70 
 71 MBPSInterp instproc height {} {
 72     $self instvar height_
 73     return $height_
 74 }
 75 
 76 MBPSInterp instproc set-bbox {bbox} {
 77     $self instvar bbox_
 78     set bbox_ $bbox
 79 }
 80 
 81 MBPSInterp instproc resize {width height} {
 82     $self instvar path_ width_ height_ pipe_
 83     if {$width_!=$width || $height_!=$height} {
 84         $self kill
 85         set width_ $width
 86         set height_ $height
 87     }
 88     $self fork
 89 }
 90 
 91 # customized PostscriptWindow that calls MBPSInterp to
 92 # get the pixmaps (does not do the displaying)
 93 
 94 MBPSProcessor superclass PostscriptWindow
 95 
 96 MBPSProcessor instproc Init {interp} {
 97     $self instvar busy_ waiting_ curr_file_ curr_pm_ busy_ gs_
 98     set gs_ $interp
 99     set busy_ 0
100     set waiting_ ""
101 }
102 
103 MBPSProcessor instproc pixmap-id {} {
104     $self instvar pixmap_id_
105     DbgOut "returning tcl bitmap"
106     return $pixmap_id_
107 }
108 
109 DSC_Parser instproc get_bbox {file} {
110     seek $file 0 start
111     set contents [read $file 4096]
112     set found [regexp "%%BoundingBox: (\[(\]atend\[)\]|\[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]*)" $contents dummy bbox]
113     if {$found == 0} {
114         DbgOut "Cannot find bounding box"
115         return ""
116     }
117     if {[string compare "(atend)" $bbox] == 0} {
118         seek $file "-4096" end
119         set contents [read $file 4096]
120         set found [regexp "%%BoundingBox: (\[0-9\]* \[0-9\]* \[0-9\]* \[0-9\]*)" $contents dummy bbox]
121         if {$found == 0} {
122             DbgOut "Cannot find bbox at end"
123             return ""
124         }
125     }
126     DbgOut "bbox of ps: $bbox"
127     seek $file 0 start
128     return $bbox
129 }
130 
131 MBPSProcessor instproc get_next_req { } {
132     $self instvar waiting_ file_ pixmap_id_ pmSize_ busy_ gs_
133 
134     if {$busy_ == 1} {
135         return
136     }
137     if {[llength $waiting_] <= 0} {
138         return
139     }
140     set currPS [lindex $waiting_ 0]
141     set waiting_ [lrange $waiting_ 1 end]
142 
143     set busy_ 1
144     set file_ [lindex $currPS 0]
145     set pixmap_id_ [lindex $currPS 1]
146     $self set_pixmap $pixmap_id_
147     set pmSize_ [lrange $currPS 2 3]
148 
149     set psFile [open $file_ r]
150 
151     set psp [new DSC_Parser]
152     $psp set-file $psFile
153     set bbox [$psp get_bbox $psFile]
154     $gs_ set-bbox $bbox
155     eval $gs_ resize $pmSize_
156 
157     set npage [$psp set npage_]
158     set tmpFile /tmp/mbps.[pid].ps
159     set f [open $tmpFile w]
160     $psp dump 1 $f
161     close $f
162     DbgOut "calling render-file $tmpFile"
163     $gs_ render-file $tmpFile
164 }
165 
166 MBPSProcessor instproc get_pixmap {pixmap_id width height filename } {
167     $self instvar waiting_ file_ pixmap_id_ busy_
168 
169 #    set pixmap_id [eval $self create_pixmap $width $height]
170     lappend waiting_ [list $filename $pixmap_id $width $height]
171     DbgOut "busy=$busy_, \$waiting_=$waiting_"
172 
173     $self get_next_req
174 
175     return $pixmap_id
176 }
177 
178 MBPSProcessor instproc recv-page w {
179     # force a redraw
180     # $self damage
181     $self instvar mwin_ path_ busy_ pixmap_id_ pmSize_
182 #    set mwin_ $w
183     #FIXME our widget doesn't support tk configuration
184     [winfo parent $path_] configure -cursor ""
185     DbgOut "\n\n ------- recv-page called --------- "
186 
187         #update
188     set busy_ 0
189     $self get_next_req
190 }
191 
192 MBPSProcessor instproc recv-done w {
193     # force a redraw
194     # $self damage
195     DbgOut "\n\n ------- recv-done called --------- \n\n"
196 }
197 
198 MBPSProcessor instproc destroy {} {
199     DbgOut "in MBPSInterp instproc destroy"
200     $self next
201 }
202 
203 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.