tlibdraw: add scalesize - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 9f3851871ed6edb544dfe5b518bff0121d6c020b
 (DIR) parent 323e7d0193999a22e605786d06fcff76cb780e38
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Sun, 25 Nov 2012 22:15:57 -0500
       
       libdraw: add scalesize
       
       R=rsc
       http://codereview.appspot.com/6855092
       
       Diffstat:
         M include/draw.h                      |       1 +
         M man/man3/graphics.3                 |      16 ++++++++++++++++
         M src/libdraw/init.c                  |       7 +++++++
       
       3 files changed, 24 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/include/draw.h b/include/draw.h
       t@@ -351,6 +351,7 @@ extern Image*        namedimage(Display*, char*);
        extern int        nameimage(Image*, char*, int);
        extern Image* allocimagemix(Display*, u32int, u32int);
        extern int        drawsetlabel(char*);
       +extern int        scalesize(Display*, int);
        
        /*
         * Colors
 (DIR) diff --git a/man/man3/graphics.3 b/man/man3/graphics.3
       t@@ -62,6 +62,9 @@ int        gengetwindow(Display *d, char *winname,
                   Image **ip, Screen **sp, int ref)
        .PP
        .B
       +int        scalesize(Display *d, int n)
       +.PP
       +.B
        void        cursorswitch(Cursor *curs)
        .PP
        .B
       t@@ -502,6 +505,19 @@ and
        .B Screen
        variables for the new window.
        .PP
       +Historically, Plan 9 graphics programs have used fixed-size graphics features that assume a narrow range of display densities, around 100 dpi: pixels (or dots) per inch.
       +The new field
       +.B display->dpi
       +contains the display's actual density if known, or else
       +.B DefaultDPI
       +(100).
       +.I Scalesize
       +scales the fixed pixel count
       +.I n
       +by
       +.BR display->dpi / DefaultDPI ,
       +rounding appropriately.
       +.PP
        The mouse cursor is always displayed.
        The initial cursor is an arrow.
        .I Cursorswitch
 (DIR) diff --git a/src/libdraw/init.c b/src/libdraw/init.c
       t@@ -428,3 +428,10 @@ bufimage(Display *d, int n)
                return p;
        }
        
       +int
       +scalesize(Display *d, int n)
       +{
       +        if(d == nil || d->dpi <= DefaultDPI)
       +                return n;
       +        return (n*d->dpi+DefaultDPI/2)/DefaultDPI;
       +}