8000 SC 2005/03/07 · matplotlib/matplotlib@4f93d04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f93d04

Browse files
author
Steve Chaplin
committed
SC 2005/03/07
svn path=/trunk/matplotlib/; revision=1048
1 parent f45538e commit 4f93d04

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
5757

5858
DEBUG = False
5959

60-
# the true dots per inch on the screen; should be display dependent
61-
PIXELS_PER_INCH = 96
62-
6360
# Image formats that this backend supports - for print_figure()
6461
IMAGE_FORMAT = ['eps', 'png', 'ps', 'svg']
6562
#IMAGE_FORMAT = ['eps', 'pdf', 'png', 'ps', 'svg'] # pdf not ready yet
@@ -321,9 +318,10 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
321318
ctx.select_font (prop.get_name(),
322319
self.fontangles [prop.get_style()],
323320
self.fontweights[prop.get_weight()])
324-
# 1.4 scales font to a similar size to GTK / GTKAgg backends
325-
size = prop.get_size_in_points() * self.dpi.get() / PIXELS_PER_INCH * 1.4
326321

322+
# size = prop.get_size_in_points() * self.dpi.get() / 96.0
323+
size = prop.get_size_in_points() * self.dpi.get() / 72.0
324+
327325
ctx.save()
328326
if angle:
329327
ctx.rotate (-angle * pi / 180)
@@ -408,8 +406,12 @@ def get_text_width_height(self, s, prop, ismath):
408406
self.fontangles [prop.get_style()],
409407
self.fontweights[prop.get_weight()])
410408

411-
# 1.4 scales font to a similar size to GTK / GTKAgg backends
412-
size = prop.get_size_in_points() * self.dpi.get() / PIXELS_PER_INCH * 1.4
409+
# Cairo (says it) uses 1/96 inch user space units, ref: cairo_gstate.c
410+
# but if /96.0 is used the font is too small
411+
412+
#size = prop.get_size_in_points() * self.dpi.get() / 96.0
413+
size = prop.get_size_in_points() * self.dpi.get() / 72.0
414+
413415
# problem - scale remembers last setting and font can become
414416
# enormous causing program to crash
415417
# save/restore prevents the problem
@@ -431,9 +433,8 @@ def new_gc(self):
431433

432434
def points_to_pixels(self, points):
433435
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
434-
# is this correct for cairo? (copied from gtk)
435-
return points * PIXELS_PER_INCH/72.0 * self.dpi.get()/72.0
436-
436+
return points/72.0 * self.dpi.get()
437+
437438

438439
class GraphicsContextCairo(GraphicsContextBase):
439440
_joind = {

lib/matplotlib/backends/backend_gdk.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def fn_name(): return sys._getframe(1).f_code.co_name
4040

4141
DEBUG = False
4242

43-
# the true dots per inch on the screen; should be display dependent
44-
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
45-
#PIXELS_PER_INCH = 96
46-
4743
# Image formats that this backend supports - for FileChooser and print_figure()
4844
IMAGE_FORMAT = ['eps', 'jpg', 'png', 'ps', 'svg'] + ['bmp'] # , 'raw', 'rgb']
4945
IMAGE_FORMAT.sort()
@@ -319,7 +315,7 @@ def _get_pango_layout(self, s, prop):
319315
Return - pango layout (from cache if already exists)
320316
321317
Note that pango assumes a logical DPI of 96
322-
Ref: pango_font_description_set_size() manual page
318+
Ref: pango/fonts.c/pango_font_description_set_size() manual page
323319
"""
324320
# problem? - cache gets bigger and bigger, is never cleared out
325321
# two (not one) layouts are created for every text item s (then they are cached) - why?
@@ -329,7 +325,6 @@ def _get_pango_layout(self, s, prop):
329325
if value != None:
330326
return value
331327

332-
#size = prop.get_size_in_points() * self.dpi.get() / PIXELS_PER_INCH
333328
size = prop.get_size_in_points() * self.dpi.get() / 96.0
334329
size = round(size)
335330

@@ -368,7 +363,6 @@ def new_gc(self):
368363

369364

370365
def points_to_pixels(self, points):
371-
#return points * PIXELS_PER_INCH/72.0 * self.dpi.get()/72.0
372366
return points/72.0 * self.dpi.get()
373367

374368

0 commit comments

Comments
 (0)
0