Commit Diff


commit - 323e7d0193999a22e605786d06fcff76cb780e38
commit + 9f3851871ed6edb544dfe5b518bff0121d6c020b
blob - 9bf5ce12e6527dd922e058de94a8e56a76c9c91d
blob + fe059acac824fa413ee3d88bda06d5a99a9d5e0f
--- include/draw.h
+++ include/draw.h
@@ -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
blob - 4b39332d7585a5c99a6e55b514484c702cc2107a
blob + d07c269acfedef5fa46f0b1d1462cc50186d81c2
--- man/man3/graphics.3
+++ man/man3/graphics.3
@@ -60,6 +60,9 @@ int	gengetwindow(Display *d, char *winname,
 .br
 .B
 	   Image **ip, Screen **sp, int ref)
+.PP
+.B
+int	scalesize(Display *d, int n)
 .PP
 .B
 void	cursorswitch(Cursor *curs)
@@ -501,6 +504,19 @@ file and pointers to be overwritten with the values of
 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.
blob - c698ec68aa040f75c8d24fdfe812ce5433cf871b
blob + b2df7fd780abe136744bb02658c283569b841ad7
--- src/libdraw/init.c
+++ src/libdraw/init.c
@@ -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;
+}