From dc1c718e3800ffbe7028430b7d01789377b2b3b8 Mon Sep 17 00:00:00 2001 From: Charles Doutriaux Date: Tue, 22 Aug 2017 14:13:23 -0700 Subject: [PATCH] Scalefonts (#236) * fix #234 * fix #235 * missing function for streamlines * adding test --- tests/test_vcs_scalefont_new_to_removed.py | 17 ++++++++++++ vcs/manageElements.py | 31 ++++++++++++++++++++++ vcs/queries.py | 8 ++++++ vcs/template.py | 1 + 4 files changed, 57 insertions(+) create mode 100644 tests/test_vcs_scalefont_new_to_removed.py diff --git a/tests/test_vcs_scalefont_new_to_removed.py b/tests/test_vcs_scalefont_new_to_removed.py new file mode 100644 index 000000000..1bccca978 --- /dev/null +++ b/tests/test_vcs_scalefont_new_to_removed.py @@ -0,0 +1,17 @@ +import vcs +import unittest + +class VCSScaleFOntToRemoved(unittest.TestCase): + def testRemoveTo(self): + #canvas = vcs.init() + nto = vcs.listelements("textorientation") + nt = vcs.listelements("template") + t = vcs.createtemplate() + t.scalefont(.6) + #canvas.removeobect(t) + vcs.removeobject(t) + nto2 = vcs.listelements("textorientation") + nt2 = vcs.listelements("template") + self.assertEqual(len(nto2),len(nto)) + self.assertEqual(len(nt2),len(nt)) + diff --git a/vcs/manageElements.py b/vcs/manageElements.py index f0996ba3c..5dccbbf27 100644 --- a/vcs/manageElements.py +++ b/vcs/manageElements.py @@ -1803,6 +1803,32 @@ def removeCp(obj): def removeP(obj): + # first we need to see if the template was scaled + # If so we need to remove the textorientation objects + # associated with this + if not vcs.istemplate(obj): + if obj not in vcs.elements["template"].keys(): + raise RuntimeError("Cannot remove inexisting template %s" % obj) + if isinstance(obj, str): + obj = vcs.gettemplate(obj) + if obj._scaledFont: + try: + attr = vars(obj).keys() + except: + attr = obj.__slots__ + + if len(attr) == 0: + attr = obj.__slots__ + + for a in attr: + if a[0] == "_": + continue + try: + v = getattr(obj, a) + to = getattr(v, 'textorientation') + removeTo(to) + except: + pass return removeG(obj, "template") @@ -1857,8 +1883,11 @@ def removeobject(obj): msg = vcs.removeG1d(obj.name) elif (obj.g_name == 'Gtd'): msg = vcs.removeGtd(obj.name) + elif (obj.g_name == 'Gs'): + msg = vcs.removeGs(obj.name) else: msg = 'Could not find the correct graphics class object.' + raise vcsError(msg) elif vcs.issecondaryobject(obj): if (obj.s_name == 'Tl'): msg = vcs.removeTl(obj.name) @@ -1878,6 +1907,8 @@ def removeobject(obj): msg = vcs.removeCp(obj.name) else: msg = 'Could not find the correct secondary class object.' + raise vcsError(msg) else: msg = 'This is not a template, graphics method, or secondary method object.' + raise vcsError(msg) return msg diff --git a/vcs/queries.py b/vcs/queries.py index d7566d650..e3093c435 100644 --- a/vcs/queries.py +++ b/vcs/queries.py @@ -323,6 +323,14 @@ def ismeshfill(obj): ismeshfill.__doc__ = xmldocs.is_docs['meshfill'] # noqa +def isstreamline(obj): + if (isinstance(obj, streamline.Gs)): + return 1 + else: + return 0 +isstreamline.__doc__ = xmldocs.is_docs['streamline'] # noqa + + def isboxfill(obj): if (isinstance(obj, boxfill.Gfb)): return 1 diff --git a/vcs/template.py b/vcs/template.py index 2875a48de..25a2bd139 100644 --- a/vcs/template.py +++ b/vcs/template.py @@ -1480,6 +1480,7 @@ def scalefont(self, scale): setattr(v, 'textorientation', to) except: pass + self._scaledFont = True def drawLinesAndMarkersLegend(self, canvas, linecolors, linetypes, linewidths,