Commit 14995a22 authored by Tiago Peixoto's avatar Tiago Peixoto

Merge branch 'bugfix/graphviz-draw' into 'master'

Adjust use of libgvc to fix two graphviz_draw issues

Closes #597

See merge request !34
parents 682b4f46 52fe287a
Pipeline #703 passed with stage
in 143 minutes and 5 seconds
...@@ -66,14 +66,17 @@ try: ...@@ -66,14 +66,17 @@ try:
libgv.agedge.restype = ptype libgv.agedge.restype = ptype
libgv.agget.restype = ptype libgv.agget.restype = ptype
libgv.agstrdup_html.restype = ptype libgv.agstrdup_html.restype = ptype
libgv.agstrdup_html.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
libgv.agraphof.restype = ctypes.c_void_p
libgv.agraphof.argtypes = [ctypes.c_void_p]
# create a context to use the whole time (if we keep freeing and recreating # create a context to use the whole time (if we keep freeing and recreating
# it, we will hit a memory leak in graphviz) # it, we will hit a memory leak in graphviz)
gvc = libgv.gvContext() gvc = libgv.gvContext()
try: try:
gv_new_api = True gv_new_api = True
libgv_directed = libgv.Agdirected libgv_directed = ctypes.c_int.in_dll(libgv, "Agdirected")
libgv_undirected = libgv.Agundirected libgv_undirected = ctypes.c_int.in_dll(libgv, "Agundirected")
except AttributeError: except AttributeError:
gv_new_api = False gv_new_api = False
libgv_directed = 1 libgv_directed = 1
...@@ -85,14 +88,15 @@ except OSError: ...@@ -85,14 +88,15 @@ except OSError:
warnings.warn(msg, ImportWarning) warnings.warn(msg, ImportWarning)
def htmlize(val): def htmlize(elem, val):
if len(val) >= 2 and val[0] == "<" and val[-1] == ">": if len(val) >= 2 and val[0] == "<" and val[-1] == ">":
return ctypes.string_at(libgv.agstrdup_html(val[1:-1])) g = libgv.agraphof(elem)
return ctypes.string_at(libgv.agstrdup_html(g, str(val[1:-1]).encode("utf8")))
return val return val
def aset(elem, attr, value): def aset(elem, attr, value):
v = htmlize(str(value)).encode("utf8") v = htmlize(elem, str(value))
libgv.agsafeset(elem, str(attr).encode("utf8"), v, v) libgv.agsafeset(elem, str(attr).encode("utf8"), v, v)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment