~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons/io_export_dxf/primitive_exporters/text_exporter.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from .base_exporter import BasePrimitiveDXFExporter
 
2
 
 
3
 
 
4
class TextDXFExporter(BasePrimitiveDXFExporter):
 
5
    pass
 
6
 
 
7
#-----------------------------------------------------
 
8
def exportText(ob, mx, mw, **common):
 
9
    """converts Text-Object to desired projection and representation(DXF-Entity type)
 
10
    """
 
11
    text3d = ob.getData()
 
12
    textstr = text3d.getText()
 
13
    WCS_loc = ob.loc # WCS_loc is object location in WorldCoordSystem
 
14
    sizeX = ob.SizeX
 
15
    sizeY = ob.SizeY
 
16
    sizeZ = ob.SizeZ
 
17
    rotX  = ob.RotX
 
18
    rotY  = ob.RotY
 
19
    rotZ  = ob.RotZ
 
20
    #print 'deb: sizeX=%s, sizeY=%s' %(sizeX, sizeY) #---------
 
21
 
 
22
    Thickness,Extrusion,ZRotation,Elevation = None,None,None,None
 
23
 
 
24
    AXaxis = mx[0].copy().resize3D() # = ArbitraryXvector
 
25
    if not PROJECTION:
 
26
        #Extrusion, ZRotation, Elevation = getExtrusion(mx)
 
27
        Extrusion, AXaxis = getExtrusion(mx)
 
28
 
 
29
        # no thickness/width for TEXTs converted into ScreenCS
 
30
        if text3d.getExtrudeDepth():
 
31
            Thickness = text3d.getExtrudeDepth() * sizeZ
 
32
 
 
33
    #Horizontal text justification type, code 72, (optional, default = 0)
 
34
    # integer codes (not bit-coded)
 
35
    #0=left, 1=center, 2=right
 
36
    #3=aligned, 4=middle, 5=fit
 
37
    Alignment = None
 
38
    alignment = text3d.getAlignment().value
 
39
    if alignment in {1, 2}: Alignment = alignment
 
40
 
 
41
    textHeight = text3d.getSize() / 1.7
 
42
    textFlag = 0
 
43
    if sizeX < 0.0: textFlag |= 2 # set flag for horizontal mirrored
 
44
    if sizeZ < 0.0: textFlag |= 4 # vertical mirrored
 
45
 
 
46
    entities = []
 
47
    c = text_as_list[GUI_A['text_as'].val]
 
48
 
 
49
    if c=="TEXT": # export text as TEXT
 
50
        if not PROJECTION:
 
51
            ZRotation,Zrotmatrix,OCS_origin,ECS_origin = getTargetOrientation(mx,Extrusion,\
 
52
                AXaxis,WCS_loc,sizeX,sizeY,sizeZ,rotX,rotY,rotZ)
 
53
            ZRotation *= r2d
 
54
            point = ECS_origin
 
55
        else:    #TODO: fails correct location
 
56
            point1 = mathutils.Vector(ob.loc)
 
57
            [point] = projected_co([point1], mx)
 
58
            if PERSPECTIVE:
 
59
                clipStart = 10.0
 
60
                coef = -clipStart / (point1*mx)[2]
 
61
                textHeight *= coef
 
62
                #print 'deb: coef=', coef #--------------
 
63
    
 
64
        #print 'deb: point=', point #--------------
 
65
        [point] = toGlobalOrigin([point])
 
66
        point2 = point
 
67
 
 
68
        #if DEBUG: text_drawBlender(textstr,points,OCS_origin) #deb: draw to scene
 
69
        common['extrusion']= Extrusion
 
70
        #common['elevation']= Elevation
 
71
        common['thickness']= Thickness
 
72
        #print 'deb: common=', common #------------------
 
73
        if 0: #DEBUG
 
74
            #linepoints = [[0,0,0], [AXaxis[0],AXaxis[1],AXaxis[2]]]
 
75
            linepoints = [[0,0,0], point]
 
76
            dxfLINE = DXF.Line(linepoints,**common)
 
77
            entities.append(dxfLINE)
 
78
 
 
79
        dxfTEXT = DXF.Text(text=textstr,point=point,alignment=point2,rotation=ZRotation,\
 
80
            flag=textFlag,height=textHeight,justifyhor=Alignment,**common)
 
81
        entities.append(dxfTEXT)
 
82
        if Thickness:
 
83
            common['thickness']= -Thickness
 
84
            dxfTEXT = DXF.Text(text=textstr,point=point,alignment=point2,rotation=ZRotation,\
 
85
                flag=textFlag,height=textHeight,justifyhor=Alignment,**common)
 
86
            entities.append(dxfTEXT)
 
87
    return entities
 
88
 
 
89