@@ -100,15 +100,14 @@ class _object:
100
100
import weakref
101
101
from binascii import hexlify
102
102
import math
103
- import platform
104
- platform_bitness = platform .architecture ()[0 ]
105
- del platform
103
+
104
+ fitz_py2 = str is bytes # if true, this is Python 2
106
105
107
106
108
107
VersionFitz = "1.14.0"
109
- VersionBind = "1.14.3 "
110
- VersionDate = "2018-12-01 18:33:20 "
111
- version = (VersionBind , VersionFitz , "20181201183320 " )
108
+ VersionBind = "1.14.4 "
109
+ VersionDate = "2018-12-18 08:56:44 "
110
+ version = (VersionBind , VersionFitz , "20181218085644 " )
112
111
113
112
114
113
class Matrix ():
@@ -130,8 +129,8 @@ def __init__(self, *args):
130
129
if len (args ) == 1 : # either an angle or a sequ
131
130
if hasattr (args [0 ], "__float__" ):
132
131
theta = args [0 ] * math .pi / 180.0
133
- c = math .cos (theta )
134
- s = math .sin (theta )
132
+ c = round ( math .cos (theta ), 10 )
133
+ s = round ( math .sin (theta ), 10 )
135
134
self .a = self .d = c
136
135
self .b = s
137
136
self .c = - s
@@ -240,19 +239,13 @@ def preRotate(self, theta):
240
239
241
240
def concat (self , one , two ):
242
241
"""Multiply two matrices and replace current one."""
243
- dst = Matrix ()
244
- dst .a = one [0 ] * two [0 ] + one [1 ] * two [2 ]
245
- dst .b = one [0 ] * two [1 ] + one [1 ] * two [3 ]
246
- dst .c = one [2 ] * two [0 ] + one [3 ] * two [2 ]
247
- dst .d = one [2 ] * two [1 ] + one [3 ] * two [3 ]
248
- dst .e = one [4 ] * two [0 ] + one [5 ] * two [2 ] + two [4 ]
249
- dst .f = one [4 ] * two [1 ] + one [5 ] * two [3 ] + two [5 ]
250
- self .a = dst .a
251
- self .b = dst .b
252
- self .c = dst .c
253
- self .d = dst .d
254
- self .e = dst .e
255
- self .f = dst .f
242
+ dst = TOOLS ._concat_matrix (one , two )
243
+ self .a = dst [0 ]
244
+ self .b = dst [1 ]
245
+ self .c = dst [2 ]
246
+ self .d = dst [3 ]
247
+ self .e = dst [4 ]
248
+ self .f = dst [5 ]
256
249
return self
257
250
258
251
def __getitem__ (self , i ):
@@ -285,13 +278,7 @@ def __mul__(self, m):
285
278
if hasattr (m , "__float__" ):
286
279
return Matrix (self .a * m , self .b * m , self .c * m ,
287
280
self .d * m , self .e * m , self .f * m )
288
- a = self .a * m [0 ] + self .b * m [2 ]
289
- b = self .a * m [1 ] + self .b * m [3 ]
290
- c = self .c * m [0 ] + self .d * m [2 ]
291
- d = self .c * m [1 ] + self .d * m [3 ]
292
- e = self .e * m [0 ] + self .f * m [2 ] + m [4 ]
293
- f = self .e * m [1 ] + self .f * m [3 ] + m [5 ]
294
- return Matrix (a , b , c , d , e , f )
281
+ return self .concat (self , m )
295
282
296
283
def __truediv__ (self , m ):
297
284
if hasattr (m , "__float__" ):
@@ -1456,11 +1443,11 @@ def getPDFstr(x):
1456
1443
# require full unicode: make a UTF-16BE hex string with BOM "feff"
1457
1444
r = hexlify (bytearray ([254 , 255 ]) + bytearray (x , "UTF-16BE" ))
1458
1445
# r is 'bytes', so convert to 'str' if Python 3
1459
- t = r if str is bytes else r .decode ()
1446
+ t = r if fitz_py2 else r .decode ()
1460
1447
return "<" + t + ">" # brackets indicate hex
1461
1448
1462
1449
s = x .replace ("\x00 " , " " )
1463
- if str is bytes :
1450
+ if fitz_py2 :
1464
1451
if type (s ) is str :
1465
1452
s = unicode (s , "utf-8" , "replace" )
1466
1453
@@ -1597,9 +1584,9 @@ def CheckMorph(o):
1597
1584
if not bool (o ): return False
1598
1585
if not (type (o ) in (list , tuple ) and len (o ) == 2 ):
1599
1586
raise ValueError ("morph must be a sequence of length 2" )
1600
- if not (type (o [0 ]) == Point and issubclass ( type ( o [1 ]), Matrix ) ):
1587
+ if not (len (o [0 ]) == 2 and len ( o [1 ]) == 6 ):
1601
1588
raise ValueError ("invalid morph parm 0" )
1602
- if not o [1 ]. e == o [1 ]. f == 0 :
1589
+ if not o [1 ][ 4 ] == o [1 ][ 5 ] == 0 :
1603
1590
raise ValueError ("invalid morph parm 1" )
1604
1591
return True
1605
1592
@@ -1718,7 +1705,7 @@ def __init__(self, filename=None, stream=None, filetype=None, rect=None, width=0
1718
1705
if not filename or type (filename ) is str :
1719
1706
pass
1720
1707
else :
1721
- if str is bytes : # Python 2
1708
+ if fitz_py2 : # Python 2
1722
1709
if type (filename ) is unicode :
1723
1710
filename = filename .encode ("utf8" )
1724
1711
else :
@@ -2968,8 +2955,18 @@ def _insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, w
2968
2955
return _fitz .Page__insertFont (self , fontname , bfname , fontfile , fontbuffer , set_simple , idx , wmode , serif , encoding , ordering )
2969
2956
2970
2957
2958
+ def _getTransformation (self ):
2959
+ """_getTransformation(self) -> PyObject *"""
2960
+ CheckParent (self )
2961
+
2962
+ val = _fitz .Page__getTransformation (self )
2963
+ val = Matrix (val )
2964
+
2965
+ return val
2966
+
2967
+
2971
2968
def _getContents (self ):
2972
- """_getContents(self) -> PyObject * """
2969
+ """Return list of /Contents objects as xref integers. """
2973
2970
CheckParent (self )
2974
2971
2975
2972
return _fitz .Page__getContents (self )
@@ -3551,7 +3548,7 @@ def color_string(cs, code):
3551
3548
col = " " .join (map (str , cs )) + app
3552
3549
else :
3553
3550
col = "%g" % cs + app
3554
- return bytes (col , "utf8" ) if str is not bytes else col
3551
+ return bytes (col , "utf8" ) if not fitz_py2 else col
3555
3552
3556
3553
type = self .type [0 ] # get the annot type
3557
3554
dt = self .border ["dashes" ] # get the dashes spec
@@ -3560,6 +3557,8 @@ def color_string(cs, code):
3560
3557
fill = self .colors ["fill" ] # get the fill color
3561
3558
rect = None # used if we change the rect here
3562
3559
bfill = color_string (fill , "f" )
3560
+ p_ctm = self .parent ._getTransformation () # page transformation matrix
3561
+ imat = ~ p_ctm # inverse page transf. matrix
3563
3562
3564
3563
line_end_le , line_end_ri = 0 , 0 # line end codes
3565
3564
if self .lineEnds :
@@ -3626,7 +3625,11 @@ def color_string(cs, code):
3626
3625
ap = b"/Alp0 gs\n " + ap
3627
3626
ap_updated = True
3628
3627
3629
- if line_end_le + line_end_ri > 0 and type in (ANNOT_POLYGON , ANNOT_POLYLINE ):
3628
+ #----------------------------------------------------------------------
3629
+ # the following handles line end symbols for 'Polygon' and 'Polyline
3630
+ #----------------------------------------------------------------------
3631
+ if max (line_end_le , line_end_ri ) > 0 and type in (ANNOT_POLYGON , ANNOT_POLYLINE ):
3632
+
3630
3633
le_funcs = (None , TOOLS ._le_square , TOOLS ._le_circle ,
3631
3634
TOOLS ._le_diamond , TOOLS ._le_openarrow ,
3632
3635
TOOLS ._le_closedarrow , TOOLS ._le_butt ,
@@ -3639,15 +3642,15 @@ def color_string(cs, code):
3639
3642
points = self .vertices
3640
3643
ap = b"q\n " + ap + b"\n Q\n "
3641
3644
if line_end_le in le_funcs_range :
3642
- p1 = Point (points [0 ])
3643
- p2 = Point (points [1 ])
3645
+ p1 = Point (points [0 ]) * imat
3646
+ p2 = Point (points [1 ]) * imat
3644
3647
left = le_funcs [line_end_le ](self , p1 , p2 , False )
3645
- ap += bytes (left , "utf8" ) if str is not bytes else left
3648
+ ap += bytes (left , "utf8" ) if not fitz_py2 else left
3646
3649
if line_end_ri in le_funcs_range :
3647
- p1 = Point (points [- 2 ])
3648
- p2 = Point (points [- 1 ])
3650
+ p1 = Point (points [- 2 ]) * imat
3651
+ p2 = Point (points [- 1 ]) * imat
3649
3652
left = le_funcs [line_end_ri ](self , p1 , p2 , True )
3650
- ap += bytes (left , "utf8" ) if str is not bytes else left
3653
+ ap += bytes (left , "utf8" ) if not fitz_py2 else left
3651
3654
3652
3655
if ap_updated :
3653
3656
if rect : # rect modified here?
@@ -4176,10 +4179,10 @@ def _extractText(self, format):
4176
4179
4177
4180
class b64encode (json .JSONEncoder ):
4178
4181
def default (self ,s ):
4179
- if str is not bytes and type (s ) is bytes :
4182
+ if not fitz_py2 and type (s ) is bytes :
4180
4183
return base64 .b64encode (s ).decode ()
4181
4184
if type (s ) is bytearray :
4182
- if str is bytes :
4185
+ if fitz_py2 :
4183
4186
return base64 .b64encode (s )
4184
4187
else :
4185
4188
return base64 .b64encode (s ).decode ()
@@ -4338,6 +4341,11 @@ def _union_rect(self, r1, r2):
4338
4341
return _fitz .Tools__union_rect (self , r1 , r2 )
4339
4342
4340
4343
4344
+ def _concat_matrix (self , m1 , m2 ):
4345
+ """Concatenate matrices m1, m2."""
4346
+ return _fitz .Tools__concat_matrix (self , m1 , m2 )
4347
+
4348
+
4341
4349
def _invert_matrix (self , matrix ):
4342
4350
"""Invert a matrix."""
4343
4351
return _fitz .Tools__invert_matrix (self , matrix )
@@ -4350,7 +4358,6 @@ def _hor_matrix(self, C, P):
4350
4358
S = (P - C ).unit # unit vector C -> P
4351
4359
return Matrix (1 , 0 , 0 , 1 , - C .x , - C .y ) * Matrix (S .x , - S .y , S .y , S .x , 0 , 0 )
4352
4360
4353
-
4354
4361
def _le_annot_parms (self , annot , p1 , p2 ):
4355
4362
"""Get common parameters for making line end symbols.
4356
4363
"""
@@ -4362,7 +4369,6 @@ def _le_annot_parms(self, annot, p1, p2):
4362
4369
if not fc : fc = (0 ,0 ,0 )
4363
4370
fcol = " " .join (map (str , fc )) + " rg\n "
4364
4371
nr = annot .rect
4365
- h = nr .y1
4366
4372
np1 = p1 # point coord relative to annot rect
4367
4373
np2 = p2 # point coord relative to annot rect
4368
4374
m = self ._hor_matrix (np1 , np2 ) # matrix makes the line horizontal
@@ -4373,10 +4379,9 @@ def _le_annot_parms(self, annot, p1, p2):
4373
4379
opacity = "/Alp0 gs\n "
4374
4380
else :
4375
4381
opacity = ""
4376
- return m , im , L , R , w , h , scol , fcol , opacity
4382
+ return m , im , L , R , w , scol , fcol , opacity
4377
4383
4378
-
4379
- def _oval_string (self , h , p1 , p2 , p3 , p4 ):
4384
+ def _oval_string (self , p1 , p2 , p3 , p4 ):
4380
4385
"""Return /AP string defining an oval within a 4-polygon provided as points
4381
4386
"""
4382
4387
def bezier (p , q , r ):
@@ -4404,11 +4409,10 @@ def bezier(p, q, r):
4404
4409
ap += bezier (ul1 , ul2 , ml )
4405
4410
return ap
4406
4411
4407
-
4408
4412
def _le_diamond (self , annot , p1 , p2 , lr ):
4409
4413
"""Make stream commands for diamond line end symbol. "lr" denotes left (False) or right point.
4410
4414
"""
4411
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4415
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4412
4416
shift = 2.5 # 2*shift*width = length of square edge
4413
4417
d = shift * max (1 , w )
4414
4418
M = R - (d / 2. , 0 ) if lr else L + (d / 2. , 0 )
@@ -4426,11 +4430,10 @@ def _le_diamond(self, annot, p1, p2, lr):
4426
4430
ap += scol + fcol + "b\n Q\n "
4427
4431
return ap
4428
4432
4429
-
4430
4433
def _le_square (self , annot , p1 , p2 , lr ):
4431
4434
"""Make stream commands for square line end symbol. "lr" denotes left (False) or right point.
4432
4435
"""
4433
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4436
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4434
4437
shift = 2.5 # 2*shift*width = length of square edge
4435
4438
d = shift * max (1 , w )
4436
4439
M = R - (d / 2. , 0 ) if lr else L + (d / 2. , 0 )
@@ -4448,25 +4451,23 @@ def _le_square(self, annot, p1, p2, lr):
4448
4451
ap += scol + fcol + "b\n Q\n "
4449
4452
return ap
4450
4453
4451
-
4452
4454
def _le_circle (self , annot , p1 , p2 , lr ):
4453
4455
"""Make stream commands for circle line end symbol. "lr" denotes left (False) or right point.
4454
4456
"""
4455
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4457
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4456
4458
shift = 2.5 # 2*shift*width = length of square edge
4457
4459
d = shift * max (1 , w )
4458
4460
M = R - (d / 2. , 0 ) if lr else L + (d / 2. , 0 )
4459
4461
r = Rect (M , M ) + (- d , - d , d , d ) # the square
4460
- ap = "q\n " + opacity + self ._oval_string (h , r .tl * im , r .tr * im , r .br * im , r .bl * im )
4462
+ ap = "q\n " + opacity + self ._oval_string (r .tl * im , r .tr * im , r .br * im , r .bl * im )
4461
4463
ap += "%g w\n " % w
4462
4464
ap += scol + fcol + "b\n Q\n "
4463
4465
return ap
4464
4466
4465
-
4466
4467
def _le_butt (self , annot , p1 , p2 , lr ):
4467
4468
"""Make stream commands for butt line end symbol. "lr" denotes left (False) or right point.
4468
4469
"""
4469
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4470
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4470
4471
shift = 3
4471
4472
d = shift * max (1 , w )
4472
4473
M = R if lr else L
@@ -4478,11 +4479,10 @@ def _le_butt(self, annot, p1, p2, lr):
4478
4479
ap += scol + "s\n Q\n "
4479
4480
return ap
4480
4481
4481
-
4482
4482
def _le_slash (self , annot , p1 , p2 , lr ):
4483
4483
"""Make stream commands for slash line end symbol. "lr" denotes left (False) or right point.
4484
4484
"""
4485
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4485
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4486
4486
rw = 1.1547 * max (1 , w ) * 1.0 # makes rect diagonal a 30 deg inclination
4487
4487
M = R if lr else L
4488
4488
r = Rect (M .x - rw , M .y - 2 * w , M .x + rw , M .y + 2 * w )
@@ -4494,11 +4494,10 @@ def _le_slash(self, annot, p1, p2, lr):
4494
4494
ap += scol + "s\n Q\n "
4495
4495
return ap
4496
4496
4497
-
4498
4497
def _le_openarrow (self , annot , p1 , p2 , lr ):
4499
4498
"""Make stream commands for open arrow line end symbol. "lr" denotes left (False) or right point.
4500
4499
"""
4501
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4500
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4502
4501
shift = 2.5
4503
4502
d = shift * max (1 , w )
4504
4503
p2 = R + (d / 2. , 0 ) if lr else L - (d / 2. , 0 )
@@ -4514,11 +4513,10 @@ def _le_openarrow(self, annot, p1, p2, lr):
4514
4513
ap += scol + "S\n Q\n "
4515
4514
return ap
4516
4515
4517
-
4518
4516
def _le_closedarrow (self , annot , p1 , p2 , lr ):
4519
4517
"""Make stream commands for closed arrow line end symbol. "lr" denotes left (False) or right point.
4520
4518
"""
4521
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4519
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4522
4520
shift = 2.5
4523
4521
d = shift * max (1 , w )
4524
4522
p2 = R + (d / 2. , 0 ) if lr else L - (d / 2. , 0 )
@@ -4534,11 +4532,10 @@ def _le_closedarrow(self, annot, p1, p2, lr):
4534
4532
ap += scol + fcol + "b\n Q\n "
4535
4533
return ap
4536
4534
4537
-
4538
4535
def _le_ropenarrow (self , annot , p1 , p2 , lr ):
4539
4536
"""Make stream commands for right open arrow line end symbol. "lr" denotes left (False) or right point.
4540
4537
"""
4541
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4538
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4542
4539
shift = 2.5
4543
4540
d = shift * max (1 , w )
4544
4541
p2 = R - (d / 3. , 0 ) if lr else L + (d / 3. , 0 )
@@ -4554,11 +4551,10 @@ def _le_ropenarrow(self, annot, p1, p2, lr):
4554
4551
ap += scol + fcol + "S\n Q\n "
4555
4552
return ap
4556
4553
4557
-
4558
4554
def _le_rclosedarrow (self , annot , p1 , p2 , lr ):
4559
4555
"""Make stream commands for right closed arrow line end symbol. "lr" denotes left (False) or right point.
4560
4556
"""
4561
- m , im , L , R , w , h , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4557
+ m , im , L , R , w , scol , fcol , opacity = self ._le_annot_parms (annot , p1 , p2 )
4562
4558
shift = 2.5
4563
4559
d = shift * max (1 , w )
4564
4560
p2 = R - (2 * d , 0 ) if lr else L + (2 * d , 0 )
@@ -4575,7 +4571,6 @@ def _le_rclosedarrow(self, annot, p1, p2, lr):
4575
4571
return ap
4576
4572
4577
4573
4578
-
4579
4574
def __init__ (self ):
4580
4575
"""__init__(self) -> Tools"""
4581
4576
this = _fitz .new_Tools ()
0 commit comments