forked from sk1project/pymfvu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.py
217 lines (196 loc) · 5.48 KB
/
page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# This program was made as part of the sk1project activity to improve UniConvertor
# See http://www.sk1project.org
#
# Copyright (C) 2007, Valek Filippov (frob@df.ru)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 or later of the GNU General Public
# License as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
#
import gtk
import cairo
import math
import pyemf
import pywmf
import wmfdraw
import wmfcmd
import emfdraw
import emfcmd
import hexdump
class Page:
def __init__(self):
self.type = 0
self.alpha = 1
self.fname = ''
self.hadj = None
self.hd = hexdump.hexdump()
self.hdv = 0
self.curdc = 0
self.DCs = []
dc = DC()
self.DCs.append(dc)
self.zoom = 1.
self.scale = 1
self.width = 1.
self.height = 1.
self.kx = 1.
self.ky = 1.
self.VPx = 1.
self.VPy = 1.
self.VPOx = 0.
self.VPOy = 0.
self.maxobj = 0
self.curobj = 0
self.curbg = 0
self.curfg = 0
self.curpal = 0
self.mfobjs = {}
self.palette = {}
self.cmds = []
self.txtclr = color()
self.txtclr.r = 0.
self.txtclr.g = 0.
self.txtclr.b = 0.
self.txtalign = 0
self.bkmode = 0
self.bkcolor = color()
self.bkcolor.r,self.bkcolor.g,self.bkcolor.b = 255.,255.,255.
def usage():
class_cmds = cmd()
class_DCs = DC()
def parse(self):
pass
class DC:
VPx = 1.
VPy = 1.
VPOx = 0.
VPOy = 0.
Wx = 1.
Wy = 1.
x = 0.
y = 0.
class color:
r = 0.
g = 0.
b = 0.
a = 0.
class mfobj:
type = 0 # 1-- pen, 2 -- brush, 3 -- font
clr = color()
width = 5. ## use for pen
font = 'Arial'
italic = 0
size = 20
style = 0
escape = 0
orient = 0
under = 0
strike = 0
charset = 1
hatch = 0
data = None
flag = 0
class cmd:
type = ''
args = ()
class wmfPage(Page):
def __init__(self):
Page.__init__(self)
self.Face = wmfFace(self)
self.file = pywmf.WMF()
self.type = 1
def parse(self):
wmfcmd.parse(self)
class emfPage(Page):
def __init__(self):
Page.__init__(self)
self.Face = emfFace(self)
self.file = pyemf.EMF()
self.type = 2
bgcolor = color()
bgcolor.r,bgcolor.g,bgcolor.b = (255.,255.,255.)
bgcolor2 = color()
bgcolor2.r,bgcolor2.g,bgcolor2.b = (192.,192.,192.)
bgcolor3 = color()
bgcolor3.r,bgcolor3.g,bgcolor3.b = (128.,128.,128.)
bgcolor4 = color()
bgcolor4.r,bgcolor4.g,bgcolor4.b = (64.,64.,64.)
fgcolor = color()
fgcolor.r,fgcolor.g,fgcolor.b = (0,0,0)
eo = mfobj()
eo.clr = bgcolor
eo.type = 2
self.mfobjs[0x80000000] = eo
eo = mfobj()
eo.clr = bgcolor2
eo.type = 2
self.mfobjs[0x80000001] = eo
eo = mfobj()
eo.clr = bgcolor3
eo.type = 2
self.mfobjs[0x80000002] = eo
eo = mfobj()
eo.clr = bgcolor4
eo.type = 2
self.mfobjs[0x80000003] = eo
self.mfobjs[0] = eo
eo = mfobj()
eo.clr = fgcolor
eo.type = 2
self.mfobjs[0x80000004] = eo
self.mfobjs[0x80000005] = eo ## NULL brush -- don't fill
eo = mfobj()
eo.clr = bgcolor
eo.type = 1
self.mfobjs[0x80000006] = eo
eo = mfobj()
eo.clr = fgcolor
eo.type = 1
self.mfobjs[0x80000007] = eo
self.mfobjs[0x80000008] = eo ## NULL pen -- don't stroke
eo = mfobj()
eo.type = 3
self.mfobjs[0x8000000d] = eo ## system font
self.mfobjs[0x8000000e] = eo ## default font
self.cmds = []
def parse(self):
emfcmd.parse(self)
class Face(gtk.DrawingArea):
def __init__(self,page):
self.page = page
self.comms = 10
super(Face, self).__init__()
self.connect("expose_event", self.expose)
self._dragging = False # true if the interface is being dragged
def expose(self, widget, event):
self.ctx = widget.window.cairo_create()
self.ctx.rectangle(event.area.x,event.area.y,event.area.width,event.area.height)
self.ctx.clip()
self.draw(self.ctx)
return False
def draw(self, ctx):
print 'WxH: ',self.page.width,self.page.height
if self.page.width !=1 and self.page.height != 1:
ctx.scale(self.page.width*1.*self.page.zoom,self.page.height*1.*self.page.zoom)
self.render(self,ctx)
def render(self,ctx):
pass
class wmfFace(Face):
def __init__(self,page):
Face.__init__(self,page)
def render(self,ctx):
wmfdraw.render(self,ctx)
class emfFace(Face):
def __init__(self,page):
Face.__init__(self,page)
def render(self,ctx):
emfdraw.render(self,ctx)