Skip to content

Commit

Permalink
Check xdotversion attribute.
Browse files Browse the repository at this point in the history
And warn about unsupported versions.
  • Loading branch information
jrfonseca committed Nov 5, 2013
1 parent 8328431 commit 3617a10
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions xdot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ def handle_edge(self, src_id, dst_id, attrs):

class XDotParser(DotParser):

XDOTVERSION = '1.6'

def __init__(self, xdotcode):
lexer = DotLexer(buf = xdotcode)
DotParser.__init__(self, lexer)
Expand All @@ -1158,26 +1160,34 @@ def __init__(self, xdotcode):

def handle_graph(self, attrs):
if self.top_graph:
# Check xdot version
try:
bb = attrs['bb']
xdotversion = attrs['xdotversion']
except KeyError:
return
pass
else:
if float(xdotversion) > float(self.XDOTVERSION):
sys.stderr.write('warning: xdot version %s, but supported is %s\n' % (xdotversion, self.XDOTVERSION))

if not bb:
# Parse bounding box
try:
bb = attrs['bb']
except KeyError:
return

xmin, ymin, xmax, ymax = map(float, bb.split(","))
if bb:
xmin, ymin, xmax, ymax = map(float, bb.split(","))

self.xoffset = -xmin
self.yoffset = -ymax
self.xscale = 1.0
self.yscale = -1.0
# FIXME: scale from points to pixels
self.xoffset = -xmin
self.yoffset = -ymax
self.xscale = 1.0
self.yscale = -1.0
# FIXME: scale from points to pixels

self.width = max(xmax - xmin, 1)
self.height = max(ymax - ymin, 1)
self.width = max(xmax - xmin, 1)
self.height = max(ymax - ymin, 1)

self.top_graph = False
self.top_graph = False

for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"):
if attr in attrs:
Expand Down

0 comments on commit 3617a10

Please sign in to comment.