def getLeaf(l, e0, llen): ei = e0 # ith run eij = e0 # loop counter eijprev = e0 # one before eij dir = 0 # 1 or -1 origlen = llen res = layout.Rect() while llen > 0: if ei + 1 >= len(l.exts): break if l.exts[ei].head == l.exts[ei + 1].head: dir = l.exts[ei + 1].cyl - l.exts[ei].cyl if dir == 1 or dir == -1: eij = ei + 1 eijprev = ei # accumulate a cyl run on a given surface # print "new run %s" % (l.exts[ei]) while eij < len(l.exts) \ and l.exts[eij].head == l.exts[ei].head \ and l.exts[eij].cyl == l.exts[eijprev].cyl + dir \ and l.exts[eij].tp == l.exts[eijprev].tp: # print "add to run %s" % (l.exts[eij]) eij += 1 eijprev += 1 # runs must be of len > 2 if eij - ei < 3: eij = ei else: eij -= 1 cylrunlen = abs(l.exts[eij].cyl - l.exts[ei].cyl) + 1 res.ents.append((l.exts[ei], \ cylrunlen * (l.exts[ei].tp[1] - l.exts[ei].tp[0]), dir * cylrunlen)) llen -= 1 eij += 1 ei = eij if ei > e0: res.exts = l.exts[e0:ei] # if no runs -- all ents are singletons, we have to make this up here if ei - e0 == origlen: res.ents = map(lambda x: (x, x.tp[1] - x.tp[0], 1), res.exts) res.cylwidth = max(map( (lambda (x): x.cyl), res.exts)) - min(map((lambda (x): x.cyl), res.exts)) + 1 res.lbnwidth = reduce((lambda x, y: x + y.tp[1]), res.exts, 0) # print "getLeaf %d - %d" % (e0,ei) else: res = None return res
def render_borders(dispaylist, layout_box): color = get_color(layout_box, 'border-color') if color == None: return d = layout_box.dimensions border_box = d.border_box() #Left border dispaylist.append(SolidColor(color, layout.Rect(border_box.x, border_box.y, d.border.left, border_box.height))) #Right border dispaylist.append(SolidColor(color, layout.Rect(border_box.x + border_box.width - d.border.right, border_box.y, d.border.right, border_box.height))) #Top border dispaylist.append(SolidColor(color, layout.Rect(border_box.x, border_box.y, border_box.width, d.border.top))) #Bottom border dispaylist.append(SolidColor(color, layout.Rect(border_box.x, border_box.y + border_box.height - d.border.bottom, border_box.width, d.border.bottom)))
def outer(l): # result list of index nodes idxen = [] i = 0 junkleaf = None while i < len(l.exts): res = findRect(l, i, lout.rects) if res != None: if junkleaf: (rent, li) = makejunkrent(junkleaf) # print "junk rent %d %d" % (rent[3], rent[6]) # print rent rent[-1] = len(lout.rects) # print "Junk leaf (len %d)" % (len(junkleaf.exts)) root.append(rent) assert (li != []) idxen.append(libparam.List(li, 11)) # placeholder for idx lout.rects.append(layout.Rect([])) junkleaf = None (r, inst, lastgood) = res newidx = not (r in lout.rects) if newidx: lout.rects.append(r) # for e in r.exts: print e (rent, li) = printIDX(lout, r, len(inst), i, newidx) rent[-1] = idx(r, lout.rects) if newidx: assert (li != []) idxen.append(libparam.List(li, 11)) root.append(rent) i = lastgood + 1 # print "next ext %d" % (i) else: if not junkleaf: junkleaf = layout.Rect([l.exts[i]]) else: junkleaf.exts.append(l.exts[i]) # print "gave up on %s" % (l.exts[i]) i += 1 sys.stdout.flush() if i > lastgood + 1: junkleaf = layout.Rect(l.exts[lastgood + 1:i]) (rent, li) = makejunkrent(junkleaf) # print "junk rent %d %d" % (rent[3], rent[6]) rent[-1] = len(lout.rects) assert (li != []) idxen.append(libparam.List(li, 11)) root.append(rent) ln = [] for i in range(0, len(root)): (loff, coff, aoff, llen, clen, alen, lrunlen, crunlen, childtype, child) = root[i] if i == len(root) - 1: slips = reduce(lambda x, y: x + y.tp[1], lin.slips, 0) slips *= 2 # XXX magic llen += slips lrunlen += slips ln += [ loff, coff, aoff, llen, clen, alen, lrunlen, crunlen, childtype, child ] assert (ln != []) idxen.append(libparam.List(ln, 10)) return idxen