Convert page dimensions to points. Add auto-layering method to TOC.

This commit is contained in:
Marshall T. Vandegrift 2008-12-16 17:42:11 -05:00
parent 3eaede190c
commit d46abf8c50
2 changed files with 12 additions and 2 deletions

View File

@ -491,6 +491,15 @@ class TOC(object):
def __getitem__(self, index): def __getitem__(self, index):
return self.nodes[index] return self.nodes[index]
def autolayer(self):
prev = None
for node in list(self.nodes):
if prev and urldefrag(prev.href)[0] == urldefrag(node.href)[0]:
self.nodes.remove(node)
prev.nodes.append(node)
else:
prev = node
def depth(self, level=0): def depth(self, level=0):
if self.nodes: if self.nodes:
return self.nodes[0].depth(level+1) return self.nodes[0].depth(level+1)

View File

@ -104,8 +104,8 @@ def xpath(elem, expr):
class Page(object): class Page(object):
def __init__(self, width, height, dpi): def __init__(self, width, height, dpi):
self.width = float(width) self.width = (float(width) / dpi) * 72.
self.height = float(height) self.height = (float(height) / dpi) * 72.
self.dpi = float(dpi) self.dpi = float(dpi)
class Profiles(object): class Profiles(object):
@ -251,6 +251,7 @@ class Stylizer(object):
rules.append('%s {\n %s;\n}' % (selector, style)) rules.append('%s {\n %s;\n}' % (selector, style))
return '\n'.join(rules) return '\n'.join(rules)
class Style(object): class Style(object):
def __init__(self, element, stylizer): def __init__(self, element, stylizer):
self._element = element self._element = element