Skip to content

Commit

Permalink
Scalefonts (#236)
Browse files Browse the repository at this point in the history
* fix #234

* fix #235

* missing function for streamlines

* adding test
  • Loading branch information
doutriaux1 authored Aug 22, 2017
1 parent cb4cbeb commit dc1c718
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_vcs_scalefont_new_to_removed.py
Original file line number Diff line number Diff line change
@@ -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))

31 changes: 31 additions & 0 deletions vcs/manageElements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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)
Expand All @@ -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
8 changes: 8 additions & 0 deletions vcs/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vcs/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ def scalefont(self, scale):
setattr(v, 'textorientation', to)
except:
pass
self._scaledFont = True

def drawLinesAndMarkersLegend(self, canvas,
linecolors, linetypes, linewidths,
Expand Down

0 comments on commit dc1c718

Please sign in to comment.