home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / spmio10.zip / gcc2 / stdwin / test3.cc < prev    next >
C/C++ Source or Header  |  1994-08-28  |  3KB  |  108 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef NDEBUG
  4. #define LOG(format, args...)
  5. #else
  6. FILE *logfile;
  7. #define LOG(format, args...) \
  8. fprintf (logfile, "%s:%d: " format "\n", __FILE__, __LINE__ , ##args )
  9. #endif
  10.  
  11.  
  12. #include <stdwin.h>
  13. #include <stdfont.h>
  14. #include <stdlib.h>
  15.  
  16. #define countof(A) (sizeof (A) / sizeof ((A)[0]))
  17.  
  18. const char * const fontnames[] = {
  19.   "10.System Monospaced",
  20.   "12.Courier Bold",
  21.   "8.System VIO",
  22.   "14.Courier",
  23.   "16.System VIO",
  24.   "14.Times New Roman Bold",
  25.   "14.System VIO",
  26.   "12.Helvetica Bold Italic",
  27.   "12.Helv",
  28.   "10.Times New Roman Italic"
  29. };
  30.  
  31. class BlankWindow: public StdWin
  32. {
  33.   typedef StdWin inherited;
  34.   int *f;
  35.   virtual MRESULT msg_paint ();
  36.   virtual MRESULT msg_create ();
  37. };
  38.  
  39. MRESULT BlankWindow::msg_create ()
  40. {
  41.   init_desktop_fontinfo ();
  42.   f = (int *) malloc (countof (fontnames) * sizeof (int));
  43.   for (int i = 0; i < countof (fontnames); i++)
  44.     f[i] = desktop_fontinfo->install_font (fontnames[i]);
  45.   return inherited::msg_create ();
  46. }
  47.  
  48. MRESULT BlankWindow::msg_paint ()
  49. {
  50.   HPS hps = WinBeginPaint (window, 0, 0);
  51.   GpiErase (hps);
  52.   desktop_fontinfo->make_fonts_availible (hps);
  53.  
  54.   const int number_of_lines = countof (fontnames);
  55.   int i;
  56.   POINTL pt;
  57.   pt.x = 0;
  58.   pt.y = 0;
  59.   for (i = 0; i < number_of_lines; i++)
  60.     {
  61.       const int fi = number_of_lines - i - 1; // Invert the print order
  62.       const char * const text = fontnames[fi];
  63.       const int textlen = strlen (text);
  64.       if (f[fi] == 0)
  65.     continue;
  66.       // Set the current font
  67.       desktop_fontinfo->use_font (hps, f[fi]);
  68.       // Then print out the name of the current font at an appropriate place
  69.       pt.y += desktop_fontinfo->get_font_descender (f[fi]);
  70.       LOG ("Output font %d at (%d,%d) text `%s'", f[fi], pt.x, pt.y, text);
  71.       GpiMove (hps, &pt);
  72.       GpiCharString (hps, textlen, text);
  73.       // Then move onwards
  74.       pt.x = 0;
  75.       pt.y -= desktop_fontinfo->get_font_descender (f[fi]);
  76.       pt.y += desktop_fontinfo->get_font_height (f[fi]);
  77.       LOG ("Now at (%d, %d)", pt.x, pt.y);
  78.     }
  79.  
  80.   pt.y += desktop_fontinfo->get_fonts_descender ();
  81.   const char * const sample_text =
  82.     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  83.   for (i = 0; sample_text[i] != '\0'; i++)
  84.     {
  85.       // Set a different font every letter
  86.       desktop_fontinfo->use_font (hps, f[i % number_of_lines]);
  87.       // Move to the right place
  88.       GpiMove (hps, &pt);
  89.       LOG ("Output font %d at (%d,%d) text `%c'", f[i % number_of_lines],
  90.        pt.x, pt.y, sample_text[i]);
  91.       // Print out one character
  92.       GpiCharString (hps, 1, &sample_text[i]);
  93.       // Then advance the insertion point
  94.       pt.x += FontInformation::string_width (hps, 1, &sample_text[i]);
  95.     }
  96.   
  97.   WinEndPaint (hps);
  98.   return 0;
  99. }
  100.  
  101. int main(void)
  102. {
  103.   BlankWindow window;
  104.   window.activate_window ();
  105.   StdWin::StdMessageLoop ();
  106.   return 0;
  107. }
  108.