Russ Cox avatar Russ Cox committed 09b6157

devdraw, libdraw: add display->dpi

Fixed at 100 right now, but the plan is to make it accurate
and then use it.

R=rsc
http://codereview.appspot.com/6856091

Comments (0)

Files changed (4)

 	int		_isnewdisplay;
 	struct Mux	*mux;
 	int		srvfd;
+	int		dpi;
 };
 
 struct Image

src/cmd/devdraw/devdraw.c

 #include "devdraw.h"
 
 extern void _flushmemscreen(Rectangle);
+int displaydpi = 100;
 
 #define NHASH (1<<5)
 #define HASHMASK (NHASH-1)
 	DName *dn;
 	DScreen *dscrn;
 	FChar *fc;
+	Fmt fmt;
 	Memimage *dst, *i, *l, **lp, *mask, *src;
 	Memscreen *scrn;
 	Point p, *pp, q, sp;
 			memmove(client->readdata, ibuf, ni);
 			client->nreaddata = ni;
 			client->infoid = -1;
-			continue;	
+			continue;
+		
+		/* query: 'Q' n[1] queryspec[n] */
+		case 'q':
+			if(n < 2)
+				goto Eshortdraw;
+			m = 1+1+a[1];
+			if(n < m)
+				goto Eshortdraw;
+			fmtstrinit(&fmt);
+			for(c=0; c<a[1]; c++) {
+				switch(a[2+c]) {
+				default:
+					err = "unknown query";
+					goto error;
+				case 'd':	/* dpi */
+					fmtprint(&fmt, "%11d ", displaydpi);
+					break;
+				}
+			}
+			client->readdata = (uchar*)fmtstrflush(&fmt);
+			if(client->readdata == nil)
+				goto Enomem;
+			client->nreaddata = strlen((char*)client->readdata);
+			continue;
 
 		/* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
 		case 'l':

src/cmd/devdraw/devdraw.h

 int mouseswap(int);
 void abortcompose(void);
 
-
+extern int displaydpi;

src/libdraw/init.c

 	image->clipr.min.y = atoi(info+9*12);
 	image->clipr.max.x = atoi(info+10*12);
 	image->clipr.max.y = atoi(info+11*12);
+	
+	a = bufimage(d, 3);
+	a[0] = 'q';
+	a[1] = 1;
+	a[2] = 'd';
+	d->dpi = 100;
+	if(flushimage(d, 0) >= 0 && _displayrddraw(d, info, 12) == 12)
+		d->dpi = atoi(info);
+
 	return image;
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.