home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_16 / EMF / Formator.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  2.8 KB  |  134 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : formator.h                                                             //
  10. //  Description: Text output stream with Win32 data type support                     //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #pragma once
  15.  
  16. #include "..\..\include\lookup.h"
  17. #include "Cache.h"
  18. #include "OutPipe.h"
  19.  
  20.  
  21. class KWinPipe : public KTextPipe
  22. {
  23.     KCache   m_DIBCache;
  24.     long     m_curDIB;
  25.  
  26.     KCache   m_BMICache;
  27.     long     m_curBMI;
  28.  
  29.     KCache   m_PackedDIBCache;
  30.  
  31.     long     m_curRegion;
  32.     
  33. public:
  34.     long     m_curPackedDIB;
  35.  
  36.     KWinPipe()
  37.     {
  38.         m_curBMI = -1;
  39.         m_curDIB = -1;
  40.         m_curPackedDIB = -1 ;
  41.  
  42.         m_curRegion = 0;
  43.     }
  44.  
  45.     void AddBrush(const LOGBRUSH * logbrush, bool create=true);
  46.     void AddColor(COLORREF color);
  47.     
  48.     void AddRegion(unsigned long size, const RGNDATA * data);
  49.  
  50.     const long * Pound(char tag, const long * data, const DicItem * dic);
  51.  
  52.     bool SaveDIB(const BITMAPINFO * bmi, long bmisize, const void * bits, long bitsize);
  53.  
  54.     bool AddDIB(const void * header, 
  55.                 long bmioffset, long bmisize,
  56.                 long bitoffset, long bitsize,
  57.                 TCHAR format[], bool pack = false);
  58. };
  59.  
  60.  
  61. class KofstreamPipe : public KWinPipe 
  62. {
  63.     ofstream m_stream;
  64.     
  65. public:
  66.  
  67.     TCHAR m_buffer[2048];
  68.     int   m_nPos;
  69.  
  70.     KofstreamPipe(void)
  71.     {
  72.         m_nPos = 0;
  73.     }
  74.  
  75.     bool Open(const TCHAR * name)
  76.     {
  77. #ifdef _UNICODE
  78.         return false;
  79. #else
  80.         m_stream.open(name);
  81.         m_bOpened = true;
  82.         
  83.         return true;
  84. #endif
  85.     }
  86.  
  87.     bool Close(void)
  88.     {
  89.         if (m_bOpened)
  90.         {
  91.             m_stream.close();
  92.             m_bOpened = false;
  93.         }
  94.  
  95.         return true;
  96.     }
  97.  
  98.     void Clear(void)
  99.     {
  100.         m_nPos = 0;
  101.         m_buffer[0] = 0;
  102.     }
  103.  
  104.     bool Put(TCHAR ch)
  105.     {
  106.         if ( ch=='\r')     // ignored
  107.             return true;
  108.  
  109.         if ( m_bOpened )
  110.         {
  111.             m_linelen ++;
  112.             m_stream << ch;
  113.         } 
  114.         
  115.         if ( m_nPos < (MAX_PATH-1) )
  116.         {
  117.             if ( ch=='\n' )
  118.                 Clear();
  119.             else
  120.             {
  121.                 m_buffer[m_nPos++] = ch;
  122.                 m_buffer[m_nPos] = 0;
  123.             }
  124.  
  125.             return true;
  126.         }            
  127.         else
  128.             return false;
  129.     }
  130.  
  131. };
  132.  
  133.  
  134.