37 |
dbg = config.dbg.shorthand('mp') |
dbg = config.dbg.shorthand('mp') |
38 |
dbg_fail = config.dbg.shorthand('mp.fail') |
dbg_fail = config.dbg.shorthand('mp.fail') |
39 |
|
|
40 |
|
|
41 |
|
def link_draw_code(self, target, title, bbox, focus=0, rough_edge=1, error=0): |
42 |
|
if error: return 'showlinkerror("'target+'", '+title+', ('+box+'));' |
43 |
|
if not focus: return 'showlink("'target+'", '+title+', ('+box+'));' |
44 |
|
else: |
45 |
|
if rough_edge: return 'showfocus("'+target+'", '+title+', ('+box+'));'+"\n"+'drawRoughEdge(('+box+'));' |
46 |
|
else: return 'showfocus("'target+'", '+title+', ('+box+'));' |
47 |
|
navidoc.parser.Link.draw_code = link_draw_code |
48 |
|
|
49 |
class NamedMPElement(NamedElement): |
class NamedMPElement(NamedElement): |
50 |
def repl(self, s): |
def repl(self, s): |
51 |
s = s.replace("%%", self.var) |
s = s.replace("%%", self.var) |
86 |
gen1.close() |
gen1.close() |
87 |
gen2 = open(dir+diagram+extension+'.gen.mp.2', 'w') |
gen2 = open(dir+diagram+extension+'.gen.mp.2', 'w') |
88 |
gen2.write(m.drawCode()+"\n") |
gen2.write(m.drawCode()+"\n") |
89 |
|
gen2.write("showlinksize(\"bbox\", (bbox currentpicture));\n") |
90 |
gen2.close() |
gen2.close() |
91 |
gen3 = open(dir+diagram+extension+".gen.mp.3", "w") |
gen3 = open(dir+diagram+extension+".gen.mp.3", "w") |
92 |
gen3.write(""" |
gen3.write(""" |
134 |
els = link.split(',') |
els = link.split(',') |
135 |
if els[0] == '"bbox"': |
if els[0] == '"bbox"': |
136 |
bbox = els |
bbox = els |
137 |
|
else: |
138 |
|
links.append(MPLink(els)) |
139 |
dbg(bbox) |
dbg(bbox) |
140 |
|
|
141 |
# scales the bounding box and prepares it for pstopnm |
# scales the bounding box and prepares it for pstopnm |
142 |
if (bbox): |
if (bbox): |
143 |
bbox = psbbox(bbox[1:]) |
bbox = psbbox(bbox[2:]) |
144 |
list = bbox.pstopnm(scaling) |
list = bbox.pstopnm(scaling) |
145 |
dbg(bbox) |
dbg(bbox) |
146 |
|
|
173 |
"-xsize", self.w * scale, "-ysize", self.h * scale, |
"-xsize", self.w * scale, "-ysize", self.h * scale, |
174 |
"-xborder", 0, "-yborder", 0]] |
"-xborder", 0, "-yborder", 0]] |
175 |
|
|
176 |
|
class MPLink: |
177 |
|
def __init__(self, elements): |
178 |
|
""" |
179 |
|
Initilize MetaPost link. Parse link target, title and corners |
180 |
|
of linked area from elements read from MP log file. |
181 |
|
""" |
182 |
|
self.target = re.match('^"(.*)"$', elements[0]).group(1) |
183 |
|
self.title = re.match('^"(.*)"$', elements[1]).group(1) |
184 |
|
self.corners = [float(element) for element in elements[2:]] |
185 |
|
dbg("Link init: "+self.title) |
186 |
|
|
187 |
|
def map_corners(self, mapper): |
188 |
|
""" |
189 |
|
Map exact coordinates from corner elements using |
190 |
|
provided mapper. |
191 |
|
""" |
192 |
|
dbg("Unmapped corners: "+self.corners) |
193 |
|
self.corners = [int(element) for element in ( |
194 |
|
mapper(self.corners[0], self.corners[1]) + |
195 |
|
mapper(self.corners[2], self.corners[3]) |
196 |
|
)] |
197 |
|
dbg("Mapped corners: "+self.corners) |
198 |
|
|
199 |
|
def imgmapanchor(self, scale=1.0): |
200 |
|
return """<area href="%s" shape="rect" coords="%s" target="_top" title="%s" alt="%s" />\n""" \ |
201 |
|
% (self.target, |
202 |
|
",".join(["%s"%(int(c*scale)) for c in self.corners]), |
203 |
|
self.title, |
204 |
|
self.title) |
205 |
|
|
206 |
class MetapostException(Exception): |
class MetapostException(Exception): |
207 |
def __init__(self, value): |
def __init__(self, value): |
208 |
self.value = value |
self.value = value |