@@ -175,7 +175,7 @@ def pdfRepr(obj):
175
175
# A bounding box
176
176
elif isinstance (obj , BboxBase ):
177
177
return fill ([pdfRepr (val ) for val in obj .bounds ])
178
-
178
+
179
179
else :
180
180
raise TypeError , \
181
181
"Don't know a PDF representation for %s objects." \
@@ -341,7 +341,7 @@ def __init__(self, width, height, dpi, filename):
341
341
self .passed_in_file_object = True
342
342
else :
343
343
raise ValueError ("filename must be a path or a file-like object" )
344
-
344
+
345
345
self .fh = fh
346
346
self .currentstream = None # stream object to write to, if any
347
347
fh .write ("%PDF-1.4\n " ) # 1.4 is the first version to have alpha
@@ -530,7 +530,7 @@ def embedType1(self, filename, fontinfo):
530
530
531
531
firstchar = 0
532
532
lastchar = len (fontinfo .widths ) - 1
533
-
533
+
534
534
fontdict = {
535
535
'Type' : Name ('Font' ),
536
536
'Subtype' : Name ('Type1' ),
@@ -575,7 +575,7 @@ def embedType1(self, filename, fontinfo):
575
575
'XHeight' : 500 , # TODO: this one too
576
576
'FontFile' : fontfileObject ,
577
577
'FontFamily' : familyname ,
578
- 'StemV' : 50 , # TODO
578
+ 'StemV' : 50 , # TODO
579
579
# (see also revision 3874; but not all TeX distros have AFM files!)
580
580
#'FontWeight': a number where 400 = Regular, 700 = Bold
581
581
}
@@ -620,7 +620,7 @@ def _get_xobject_symbol_name(self, filename, symbol_name):
620
620
CMapName currentdict /CMap defineresource pop
621
621
end
622
622
end"""
623
-
623
+
624
624
def embedTTF (self , filename , characters ):
625
625
"""Embed the TTF font from the named file into the document."""
626
626
@@ -833,7 +833,7 @@ def embedTTFType42(font, characters, descriptor):
833
833
unicode_cmap = (self ._identityToUnicodeCMap %
834
834
(len (unicode_groups ),
835
835
"\n " .join (unicode_bfrange )))
836
-
836
+
837
837
# CIDToGIDMap stream
838
838
cid_to_gid_map = "" .join (cid_to_gid_map ).encode ("utf-16be" )
839
839
self .beginStream (cidToGidMapObject .id ,
@@ -848,7 +848,7 @@ def embedTTFType42(font, characters, descriptor):
848
848
{'Length' : unicode_cmap })
849
849
self .currentstream .write (unicode_cmap )
850
850
self .endStream ()
851
-
851
+
852
852
descriptor ['MaxWidth' ] = max_width
853
853
854
854
# Write everything out
@@ -902,7 +902,7 @@ def embedTTFType42(font, characters, descriptor):
902
902
warnings .warn (("'%s' can not be subsetted into a Type 3 font. " +
903
903
"The entire font will be embedded in the output." ) %
904
904
os .path .basename (filename ))
905
-
905
+
906
906
if fonttype == 3 :
907
907
return embedTTFType3 (font , characters , descriptor )
908
908
elif fonttype == 42 :
@@ -1054,7 +1054,7 @@ def writeImages(self):
1054
1054
'SMask' : smaskObject })
1055
1055
self .currentstream .write (data ) # TODO: predictors (i.e., output png)
1056
1056
self .endStream ()
1057
-
1057
+
1058
1058
img .flipud_out ()
1059
1059
1060
1060
def markerObject (self , path , trans , fillp , lw ):
@@ -1068,7 +1068,7 @@ def markerObject(self, path, trans, fillp, lw):
1068
1068
else :
1069
1069
name = result [0 ]
1070
1070
return name
1071
-
1071
+
1072
1072
def writeMarkers (self ):
1073
1073
for tup in self .markers .values ():
1074
1074
name , object , path , trans , fillp , lw = tup
@@ -1088,7 +1088,7 @@ def writeMarkers(self):
1088
1088
#@staticmethod
1089
1089
def pathOperations (path , transform ):
1090
1090
tpath = transform .transform_path (path )
1091
-
1091
+
1092
1092
cmds = []
1093
1093
for points , code in tpath .iter_segments ():
1094
1094
if code == Path .MOVETO :
@@ -1109,11 +1109,11 @@ def pathOperations(path, transform):
1109
1109
cmds .append (Op .closepath )
1110
1110
return cmds
1111
1111
pathOperations = staticmethod (pathOperations )
1112
-
1112
+
1113
1113
def writePath (self , path , transform ):
1114
1114
cmds = self .pathOperations (path , transform )
1115
1115
self .output (* cmds )
1116
-
1116
+
1117
1117
def reserveObject (self , name = '' ):
1118
1118
"""Reserve an ID for an indirect object.
1119
1119
The name is used for debugging in case we forget to print out
@@ -1249,7 +1249,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
1249
1249
marker , Op .use_xobject )
1250
1250
lastx , lasty = x , y
1251
1251
output (Op .grestore )
1252
-
1252
+
1253
1253
def _setup_textpos (self , x , y , angle , oldx = 0 , oldy = 0 , oldangle = 0 ):
1254
1254
if angle == oldangle == 0 :
1255
1255
self .file .output (x - oldx , y - oldy , Op .textpos )
@@ -1285,11 +1285,12 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
1285
1285
fonttype = 42
1286
1286
else :
1287
1287
fonttype = global_fonttype
1288
-
1288
+
1289
1289
if fonttype == 42 or num <= 255 :
1290
1290
self ._setup_textpos (ox , oy , 0 , oldx , oldy )
1291
1291
oldx , oldy = ox , oy
1292
1292
if (fontname , fontsize ) != prev_font :
1293
+ fontsize *= self .dpi / 72.0
1293
1294
self .file .output (self .file .fontName (fontname ), fontsize ,
1294
1295
Op .selectfont )
1295
1296
prev_font = fontname , fontsize
@@ -1300,11 +1301,12 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
1300
1301
# as XObjects using the 'Do' command.
1301
1302
if global_fonttype == 3 :
1302
1303
for ox , oy , fontname , fontsize , num , symbol_name in glyphs :
1304
+ fontsize *= self .dpi / 72.0
1303
1305
if is_opentype_cff_font (fontname ):
1304
1306
fonttype = 42
1305
1307
else :
1306
1308
fonttype = global_fonttype
1307
-
1309
+
1308
1310
if fonttype == 3 and num > 255 :
1309
1311
self .file .output (Op .gsave ,
1310
1312
0.001 * fontsize , 0 ,
@@ -1427,7 +1429,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
1427
1429
self .check_gc (gc , gc ._rgb )
1428
1430
if ismath : return self .draw_mathtext (gc , x , y , s , prop , angle )
1429
1431
1430
- fontsize = prop .get_size_in_points ()
1432
+ fontsize = prop .get_size_in_points () * self . dpi / 72.0
1431
1433
1432
1434
if rcParams ['pdf.use14corefonts' ]:
1433
1435
font = self ._get_font_afm (prop )
@@ -1441,12 +1443,12 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
1441
1443
y += font .get_descent () / 64.0
1442
1444
1443
1445
fonttype = rcParams ['pdf.fonttype' ]
1444
-
1446
+
1445
1447
# We can't subset all OpenType fonts, so switch to Type 42
1446
1448
# in that case.
1447
1449
if is_opentype_cff_font (font .fname ):
1448
1450
fonttype = 42
1449
-
1451
+
1450
1452
def check_simple_method (s ):
1451
1453
"""Determine if we should use the simple or woven method
1452
1454
to output this text, and chunks the string into 1-byte and
@@ -1476,7 +1478,7 @@ def draw_text_simple():
1476
1478
"""Outputs text using the simple method."""
1477
1479
self .file .output (Op .begin_text ,
1478
1480
self .file .fontName (prop ),
1479
- prop . get_size_in_points () ,
1481
+ fontsize ,
1480
1482
Op .selectfont )
1481
1483
self ._setup_textpos (x , y , angle )
1482
1484
self .file .output (self .encode_string (s , fonttype ), Op .show , Op .end_text )
@@ -1503,7 +1505,7 @@ def draw_text_woven(chunks):
1503
1505
if mode == 1 :
1504
1506
self .file .output (Op .begin_text ,
1505
1507
self .file .fontName (prop ),
1506
- prop . get_size_in_points () ,
1508
+ fontsize ,
1507
1509
Op .selectfont )
1508
1510
1509
1511
for chunk_type , chunk in chunks :
@@ -1566,18 +1568,19 @@ def get_text_width_height_descent(self, s, prop, ismath):
1566
1568
elif rcParams ['pdf.use14corefonts' ]:
1567
1569
font = self ._get_font_afm (prop )
1568
1570
l , b , w , h , d = font .get_str_bbox_and_descent (s )
1569
- scale = prop .get_size_in_points () / 1000.0
1571
+ scale = prop .get_size_in_points ()
1570
1572
w *= scale
1571
1573
h *= scale
1572
1574
d *= scale
1573
1575
else :
1574
1576
font = self ._get_font_ttf (prop )
1575
1577
font .set_text (s , 0.0 , flags = LOAD_NO_HINTING )
1576
1578
w , h = font .get_width_height ()
1577
- w /= 64.0
1578
- h /= 64.0
1579
+ scale = (1.0 / 64.0 )
1580
+ w *= scale
1581
+ h *= scale
1579
1582
d = font .get_descent ()
1580
- d /= 64.0
1583
+ d *= scale
1581
1584
return w , h , d
1582
1585
1583
1586
def _get_font_afm (self , prop ):
@@ -1780,7 +1783,7 @@ def delta(self, other):
1780
1783
different = ours .shape != theirs .shape or npy .any (ours != theirs )
1781
1784
if different :
1782
1785
break
1783
-
1786
+
1784
1787
if different :
1785
1788
theirs = [getattr (other , p ) for p in params ]
1786
1789
cmds .extend (cmd (self , * theirs ))
@@ -1841,10 +1844,10 @@ def draw(self):
1841
1844
pass
1842
1845
1843
1846
filetypes = {'pdf' : 'Portable Document Format' }
1844
-
1847
+
1845
1848
def get_default_filetype (self ):
1846
1849
return 'pdf'
1847
-
1850
+
1848
1851
def print_pdf (self , filename , ** kwargs ):
1849
1852
dpi = kwargs .get ('dpi' , 72 )
1850
1853
self .figure .set_dpi (dpi ) # Override the dpi kwarg
0 commit comments