home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / Mftobdf / dpi.c < prev    next >
C/C++ Source or Header  |  1991-04-15  |  3KB  |  93 lines

  1. /*
  2.  * Copyright 1989 Dirk Grunwald
  3.  * 
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Dirk Grunwald or M.I.T.
  9.  * not be used in advertising or publicity pertaining to distribution of
  10.  * the software without specific, written prior permission.  Dirk
  11.  * Grunwald and M.I.T. makes no representations about the suitability of
  12.  * this software for any purpose.  It is provided "as is" without express
  13.  * or implied warranty.
  14.  * 
  15.  * DIRK GRUNWALD AND M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL M.I.T.  BE LIABLE FOR ANY SPECIAL, INDIRECT
  18.  * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  19.  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  21.  * OR PERFORMANCE OF THIS SOFTWARE.
  22.  * 
  23.  * Author:
  24.  *     Dr. Dirk Grunwald
  25.  *     Dept. of Computer Science
  26.  *     Campus Box 430
  27.  *     Univ. of Colorado, Boulder
  28.  *     Boulder, CO 80309
  29.  * 
  30.  *     grunwald@colorado.edu
  31.  *     
  32.  */ 
  33. #include <X11/Xlib.h>
  34. #include <X11/Xutil.h>
  35. #include <X11/cursorfont.h>
  36. #include <stdio.h>
  37.  
  38. #define MM_PER_INCH 25.4
  39.  
  40. /*
  41.  *    A program for computing the dots-per-inch on a display for
  42.  *    use in generating metafont programs. However,  don't believe
  43.  *    what it says. E.g. for the 19" decstation monitor, this returns
  44.  *    70dpi, but measurements by hand show that (75h, 78w) is closer.
  45.  */
  46.  
  47. main()
  48. {
  49.   Display *DISP;
  50.   int defaultScreen;
  51.   Screen *screen;
  52.   char *display = NULL;
  53.   int maxHeight;
  54.   int maxWidth;
  55.  
  56.   int mmHeight;
  57.   int mmWidth;
  58.  
  59.   double inHeight;
  60.   double inWidth;
  61.  
  62.   if ((DISP = XOpenDisplay(display)) == NULL) {
  63.     
  64.     fprintf(stderr, "[%s] Can't open display '%s'\n",
  65.         "dpi", XDisplayName(display));
  66.     exit(1);
  67.   }
  68.   
  69.   defaultScreen = XDefaultScreen(DISP);
  70.   screen = ScreenOfDisplay(DISP, defaultScreen);
  71.   
  72.   maxHeight = XDisplayHeight(DISP, defaultScreen);
  73.   maxWidth = XDisplayWidth(DISP, defaultScreen);
  74.  
  75.   mmWidth = WidthMMOfScreen( screen );
  76.   mmHeight = HeightMMOfScreen( screen );
  77.  
  78.   inWidth = mmWidth / MM_PER_INCH;
  79.   inHeight = mmHeight / MM_PER_INCH;
  80.  
  81.   fprintf(stderr,"height = %3d dots, width = %3d dots\n", maxHeight, maxWidth);
  82.   fprintf(stderr,"height = %3d mm, width = %3d mm\n",
  83.       mmHeight, mmWidth);
  84.  
  85.   fprintf(stderr,"height = %3f in, width = %3f in\n",
  86.       inHeight, inWidth);
  87.  
  88.   fprintf(stderr,"dpi_h = %3f in, dpi_w = %3f in\n",
  89.       ( (double) maxHeight ) / ( inHeight ),
  90.       ( (double) maxWidth) / (inWidth) );
  91.  
  92. }
  93.