/[gzz]/gzz/gfx/demo/xupdf.py
ViewVC logotype

Diff of /gzz/gfx/demo/xupdf.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35 by tjl, Wed Oct 2 07:07:37 2002 UTC revision 1.36 by tjl, Wed Oct 2 10:32:04 2002 UTC
# Line 88  globalusefancypaper = 1 Line 88  globalusefancypaper = 1
88    
89  globalshowtessel = 0  globalshowtessel = 0
90    
 globalcurlinks = {}  
   
   
 def takeLink(toenf, tocell):  
     """Move along a xu connection to given cell (with given enf).  
   
     Calculates the location in the final cell to use.  
     XXX Assumes that cell contains whole scrollblock  
     """  
     s = enf2span(toenf)  
     page = s.offset()  
     p = s.getLocation()  
     d = s.getSize()  
     scale = 1 / 72.0 / 6  
     x = (p.x  + 0.5*d.width)  
     y = (p.y + 0.5*d.height)  
     (x,y) = globalview.paperpoint(page, x, y)  
     print "Takelink: to ",x,y  
     print ": ",page, p, d, scale, s  
     return (x,y)  
   
   
91  def moveToCell(cell, nx=1, ny=1):  def moveToCell(cell, nx=1, ny=1):
92      global globalcursor, globalx, globaly, globalcurlinks, globalview      global globalcursor, globalx, globaly, globalview
93      global globalforw, globalback, globalspan      global globalforw, globalback, globalspan
94    
95      # Check type      # Check type
96      if 1: # PDF      if 1: # PDF
97          globalview = getCellPDFView(cell)          globalview = getCellPDFView(cell)
98    
   
     linktaken = globalcurlinks.get(cell.getId(), None)  
     if linktaken:  
         (nx, ny) = takeLink(linktaken, cell)  
   
99      globalcursor = cell      globalcursor = cell
100      globalx, globaly = nx, ny      globalx, globaly = nx, ny
101    
   
102      content = space.cellTexter.getEnfilade(cell, None)      content = space.cellTexter.getEnfilade(cell, None)
103      globalspan = enf2span(content)      globalspan = enf2span(content)
104      globalforw = xuindexer.getForwardIndex().getMatches(content)      globalforw = xuindexer.getForwardIndex().getMatches(content)
# Line 192  def bg(vs): Line 164  def bg(vs):
164    
165  lineconn = GLRen.createLineConnector(0,0)  lineconn = GLRen.createLineConnector(0,0)
166    
167  def addbuoy(vs, anchorX, anchorY, importance, floater, linkindex, link, maincs = None):  class XuPDFBuoy:
168      print "Addbuoy ",link      def __init__(self, linkindex, link):
169      linkspan = link[linkindex].getList()[0]          self.link = link
170      mat = enfoverlap.getMatches(link[linkindex])          self.linkindex = linkindex
171      l = []          self.linkspan = link[linkindex].getList()[0]
172      for m in mat: l.append(m)          self.mat = enfoverlap.getMatches(link[linkindex])
173      print l          l = [m for m in self.mat]
174      if len(l) == 0: return          if len(l) == 0:
175      m = l[0]              self.cell = None
176      print m              return
177      cell = m          m = l[0]
178      global globalcurlinks          print m
179      globalcurlinks[m.getId()] = link[linkindex]          self.cell = m
180      view = getCellPDFView(m)          self.view = getCellPDFView(self.cell)
181    
182      p = linkspan.getLocation()          p = self.linkspan.getLocation()
183      d = linkspan.getSize()          d = self.linkspan.getSize()
184            o = self.linkspan.offset()
185      p0 = view.paperpoint(linkspan.offset(), p.x, p.y)          # print "page, loc, size: ", linkspan.offset(), p, d
186      p1 = view.paperpoint(linkspan.offset(), p.x+d.width, p.y+d.height)          # print "P0, P1: ",p0, p1
187    
188      print "page, loc, size: ", linkspan.offset(), p, d          self.p0 = self.view.paperpoint(o, p.x, p.y)
189      print "P0, P1: ",p0, p1          self.p1 = self.view.paperpoint(o, p.x+d.width, p.y+d.height)
190            self.pctr = [0.5 * (self.p0[i] + self.p1[i]) for i in range(0,2)]
191      cs1 = floater.addBuoy(anchorX, anchorY, importance, m.getId(), 0, 0)  
192      eye = 0.2          self.eye = 0.2
193      buoyscale = 400          self.buoyscale = 400
194      cs1_zoom= vs.coords.distort(cs1, 0, 0, eye, eye, buoyscale, buoyscale)  
195      vs.matcher.add(cs1_zoom, cell.getId()+"__bulg")      def add(self, vs, anchorX, anchorY, importance, floater,
196                            maincs = None):
197      cs1_trans = vs.coords.translateXY(cs1_zoom, - (p0[0]+p1[0])/2, - (p0[1]+p1[1])/2)          if not self.cell:
198      # cs1_trans = vs.coords.translateXY(cs1_zoom, 0, 0)              return
199      vs.matcher.add(cs1_trans, cell.getId()+"__trans")          cell = self.cell
200    
201      view.placepapers(vs, cs1_trans, cliprect = (p0[0], p0[1], p1[0], p1[1]),          cs1 = floater.addBuoy(anchorX, anchorY, importance, self.cell.getId(), 0, 0)
202              fancy = globalusefancypaper, showTessel = globalshowtessel)          cs1_zoom= vs.coords.distort(cs1, 0, 0, self.eye, self.eye, self.buoyscale, self.buoyscale)
203            vs.matcher.add(cs1_zoom, cell.getId()+"__bulg")
204      # Then, the xu link connector  
205      if maincs != None:          cs1_trans = vs.coords.translateXY(cs1_zoom, -self.pctr[0], -self.pctr[1])
206          mainlinkspan = link[1-linkindex].getList()[0]          # cs1_trans = vs.coords.translateXY(cs1_zoom, 0, 0)
207          # XXX if cell not everything...          vs.matcher.add(cs1_trans, cell.getId()+"__trans")
208          mainpage = mainlinkspan.offset() - globalspan.offset()  
209          mainp = mainlinkspan.getLocation()          self.cliprect = (self.p0[0], self.p0[1], self.p1[0], self.p1[1])
210          mainoffsp = globalspan.getLocation()  
211          maind = mainlinkspan.getSize()          self.view.placepapers(vs, cs1_trans, cliprect = self.cliprect,
212          mainpoint = globalview.paperpoint(mainpage,  mainp.x-mainoffsp.x+0.5*maind.width,                  fancy = globalusefancypaper, showTessel = globalshowtessel)
213                                                      mainp.y-mainoffsp.y+0.5*maind.height)  
214            # Then, the xu link connector
215          main_end_cs = vs.coords.coordsys(maincs, -20, mainpoint[0], mainpoint[1], 0, 0)          if maincs != None:
216                mainlinkspan = self.link[1-self.linkindex].getList()[0]
217          link_end_cs = vs.coords.coordsys(cs1_trans, -20, 0.5*(p0[0]+p1[0]), 0.5*(p0[1]+p1[1]), 0, 0)              # XXX if cell not everything...
218                mainpage = mainlinkspan.offset() - globalspan.offset()
219          vs.matcher.add(main_end_cs, "link"+str(link)+str(linkindex))              mainp = mainlinkspan.getLocation()
220          vs.matcher.add(link_end_cs, "link"+str(link)+str(1-linkindex))              mainoffsp = globalspan.getLocation()
221                maind = mainlinkspan.getSize()
222          print "lineconn!"              mainpoint = globalview.paperpoint(mainpage,  mainp.x-mainoffsp.x+0.5*maind.width,
223          putnoc(vs, getDListNocoords("""                                                          mainp.y-mainoffsp.y+0.5*maind.height)
224              PushAttrib ENABLE_BIT  
225              Disable TEXTURE_2D              main_end_cs = vs.coords.coordsys(maincs, -20, mainpoint[0], mainpoint[1], 0, 0)
226              LineWidth 5  
227              Enable BLEND              link_end_cs = vs.coords.coordsys(cs1_trans, -20, self.pctr[0], self.pctr[1], 0, 0)
228              Color 0 0 0 0.6  
229          """))              vs.matcher.add(main_end_cs, "link"+str(self.link)+str(self.linkindex))
230          vs.map.put(lineconn, main_end_cs, link_end_cs)              vs.matcher.add(link_end_cs, "link"+str(self.link)+str(1-self.linkindex))
231          putnoc(vs, getDListNocoords("""  
232              PopAttrib              print "lineconn!"
233          """))              putnoc(vs, getDListNocoords("""
234                    PushAttrib ENABLE_BIT
235                    Disable TEXTURE_2D
236                    LineWidth 5
237                    Enable BLEND
238                    Color 0 0 0 0.6
239                """))
240                vs.map.put(lineconn, main_end_cs, link_end_cs)
241                putnoc(vs, getDListNocoords("""
242                    PopAttrib
243                """))
244    
245        def hit(self, coords, point3):
246            return self.view.hitClip(coords, point3, self.cliprect)
247    
248  class XuPDFScene_PDFContext:  class XuPDFScene_PDFContext:
249      def __init__(self):      def __init__(self):
# Line 283  class XuPDFScene_PDFContext: Line 267  class XuPDFScene_PDFContext:
267      def mouse(self, ev):      def mouse(self, ev):
268          global globalx, globaly          global globalx, globaly
269          if ev.getID() == ev.MOUSE_CLICKED:          if ev.getID() == ev.MOUSE_CLICKED:
270              scale = 0.01  #           scale = 0.01
271              globalx += (ev.getX() - screensize[0]/2) * scale  #           globalx += (ev.getX() - screensize[0]/2) * scale
272              globaly += (ev.getY() - screensize[1]/2)  * scale  #           globaly += (ev.getY() - screensize[1]/2)  * scale
273                point = array([ev.getX(), ev.getY(), 0], 'f')
274                for b in self.buoys:
275                    h = b.hit(self.currentvs.coords, point)
276                    if h:
277                        print "BUOY HIT!\n"
278                        moveToCell(b.cell, *h)
279                        AbstractUpdateManager.chg()
280                        return
281                h = globalview.hitClip(self.currentvs.coords, point, None)
282                if h:
283                    globalx,globaly = h
284                else:
285                    print "Didn't hit anything"
286              checkGlobalCoords()              checkGlobalCoords()
287              print "Mouse ",globalx, globaly              print "Mouse ",globalx, globaly
288              AbstractUpdateManager.chg()              AbstractUpdateManager.chg()
# Line 308  class XuPDFScene_PDFContext: Line 305  class XuPDFScene_PDFContext:
305    
306          if self.clip:          if self.clip:
307              clip = (-0.2+globalx, -0.2+globaly, 0.2+globalx, 0.2+globaly)              clip = (-0.2+globalx, -0.2+globaly, 0.2+globalx, 0.2+globaly)
308                self.cliprect = cliprect
309          else:          else:
310              w = globalview.papersize[0]              w = globalview.papersize[0]
311              extrax = 0.1              extrax = 0.1
312              extray = 0.1              extray = 0.1
313              clip = (0-extrax, -extray, w+extrax, 1+extray)              clip = (0-extrax, -extray, w+extrax, 1+extray)
314                self.cliprect = None
315    
316          globalview.placepapers(vs, cs1_trans, cliprect = clip,          globalview.placepapers(vs, cs1_trans, cliprect = clip,
317                  fancy = globalusefancypaper, showTessel = globalshowtessel)                  fancy = globalusefancypaper, showTessel = globalshowtessel)
318    
319            self.buoys = []
320                            
321          if self.showcontext:          if self.showcontext:
322              for forwlink in globalforw:              for forwlink in globalforw:
323                  addbuoy(vs, 0, 0, 1, bfforw, 1, (getattr(forwlink, "from"), forwlink.to),                  b = XuPDFBuoy(1, (getattr(forwlink, "from"), forwlink.to))
324                                                  maincs = cs1_trans)                  b.add(vs, 0, 0, 1, bfforw, maincs = cs1_trans)
325                    self.buoys.append(b)
326              for backlink in globalback:              for backlink in globalback:
327                  addbuoy(vs, 0, 0, 1, bf, 0, (getattr(backlink,"from"), backlink.to),                  b = XuPDFBuoy(0,(getattr(backlink,"from"), backlink.to))
328                                                  maincs = cs1_trans)                  b.add(vs, 0, 0, 1, bf, maincs = cs1_trans)
329                    self.buoys.append(b)
330            self.currentvs = vs
331    
332  class XuPDFScene_PDFZoom:  class XuPDFScene_PDFZoom:
333      def __init__(self):      def __init__(self):

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26