chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / cura_sf / fabmetheus_utilities / geometry / creation / text.py
1 """
2 Text vertexes.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities.geometry.creation import lineation
11 from fabmetheus_utilities.geometry.geometry_tools import path
12 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
13 from fabmetheus_utilities import euclidean
14 from fabmetheus_utilities import svg_reader
15
16
17 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
18 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
19 __date__ = '$Date: 2008/02/05 $'
20 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
21
22
23 def getGeometryOutput(derivation, elementNode):
24         "Get vector3 vertexes from attributes."
25         if derivation == None:
26                 derivation = TextDerivation(elementNode)
27         if derivation.textString == '':
28                 print('Warning, textString is empty in getGeometryOutput in text for:')
29                 print(elementNode)
30                 return []
31         geometryOutput = []
32         for textComplexLoop in svg_reader.getTextComplexLoops(derivation.fontFamily, derivation.fontSize, derivation.textString):
33                 textComplexLoop.reverse()
34                 vector3Path = euclidean.getVector3Path(textComplexLoop)
35                 sideLoop = lineation.SideLoop(vector3Path)
36                 sideLoop.rotate(elementNode)
37                 geometryOutput += lineation.getGeometryOutputByManipulation(elementNode, sideLoop)
38         return geometryOutput
39
40 def getGeometryOutputByArguments(arguments, elementNode):
41         "Get vector3 vertexes from attribute dictionary by arguments."
42         evaluate.setAttributesByArguments(['text', 'fontSize', 'fontFamily'], arguments, elementNode)
43         return getGeometryOutput(None, elementNode)
44
45 def getNewDerivation(elementNode):
46         'Get new derivation.'
47         return TextDerivation(elementNode)
48
49 def processElementNode(elementNode):
50         "Process the xml element."
51         path.convertElementNode(elementNode, getGeometryOutput(None, elementNode))
52
53
54 class TextDerivation:
55         "Class to hold text variables."
56         def __init__(self, elementNode):
57                 'Set defaults.'
58                 self.fontFamily = evaluate.getEvaluatedString('Gentium Basic Regular', elementNode, 'font-family')
59                 self.fontFamily = evaluate.getEvaluatedString(self.fontFamily, elementNode, 'fontFamily')
60                 self.fontSize = evaluate.getEvaluatedFloat(12.0, elementNode, 'font-size')
61                 self.fontSize = evaluate.getEvaluatedFloat(self.fontSize, elementNode, 'fontSize')
62                 self.textString = elementNode.getTextContent()
63                 self.textString = evaluate.getEvaluatedString(self.textString, elementNode, 'text')