⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfutils.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        mfutils.cpp// Purpose:     Metafile utillities// Author:      Julian Smart// Modified by:// Created:     12/07/98// RCS-ID:      $Id: mfutils.cpp,v 1.18 2005/10/06 18:17:22 ABX Exp $// Copyright:   (c) Julian Smart// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__#pragma hdrstop#endif#ifndef WX_PRECOMP#include "wx/wx.h"#endif#include "wx/metafile.h"#include "wx/utils.h"#include "wx/ogl/ogl.h"#include <stdio.h>static char _buf[1024]; // a temp buffer to use inplace of wxBuffer, which is deprecated.// 16-bit unsigned integerstatic unsigned int getshort(FILE *fp){  int c, c1;  c = getc(fp);  c1 = getc(fp);  unsigned int res = ((unsigned int) c) + (((unsigned int) c1) << 8);  return res;}// 16-bit signed integerstatic int getsignedshort(FILE *fp){  int c, c1;  c = getc(fp);  c1 = getc(fp);#if 0   // this is not used value, no need to execute it  int testRes = ((unsigned int) c) + (((unsigned int) c1) << 8);#endif  unsigned long res1 = ((unsigned int) c) + (((unsigned int) c1) << 8);  int res;  if (res1 > 32767)    res = (int)(res1 - 65536);  else    res = (int)(res1);  return res;}// 32-bit integerstatic long getint(FILE *fp){  int c, c1, c2, c3;  c = getc(fp);  c1 = getc(fp);  c2 = getc(fp);  c3 = getc(fp);  long res = (long)((long) c) +         (((long) c1) << 8) +         (((long) c2) << 16) +         (((long) c3) << 24);  return res;}/* Placeable metafile headerstruct mfPLACEABLEHEADER {    DWORD  key;         // 32-bit    HANDLE hmf;         // 16-bit    RECT   bbox;        // 4x16 bit    WORD   inch;        // 16-bit    DWORD  reserved;    // 32-bit    WORD   checksum;    // 16-bit};*/wxMetaRecord::~wxMetaRecord(void){  if (points) delete[] points;  if (stringParam) delete[] stringParam;}wxXMetaFile::wxXMetaFile(const wxChar *file){  ok = false;  top = 0.0;  bottom = 0.0;  left = 0.0;  right = 0.0;  if (file)    ok = ReadFile(file);}/*  Handle table       gdiObjects  ------------       ----------  [0]                  wxPen  [1]----param2---     wxBrush  [2]             |    wxFont  [3]             | -> wxPen The handle table works as follows. When a GDI object is created while reading in the metafile, the (e.g.) createpen record is added to the first free entry in the handle table. The createpen record's param1 is a pointer to the actual wxPen, and its param2 is the index into the gdiObjects list, which only grows and never shrinks (unlike the handle table.) When SelectObject(index) is found, the index in the file refers to the position in the handle table. BUT we then set param2 to be the position of the wxPen in gdiObjects, i.e. to param2 of the CreatePen record, itself found in the handle table. When an object is deleted, the entry in the handletable is NULLed but the gdiObjects entry is not removed (no point, and allows us to create all GDI objects in advance of playing the metafile).*/static wxMetaRecord *HandleTable[100];static int HandleTableSize = 0;void DeleteMetaRecordHandle(int index){  HandleTable[index] = NULL;}int AddMetaRecordHandle(wxMetaRecord *record){  for (int i = 0; i < HandleTableSize; i++)    if (!HandleTable[i])    {      HandleTable[i] = record;      return i;    }  // No free spaces in table, so append.  HandleTable[HandleTableSize] = record;  HandleTableSize ++;  return (HandleTableSize - 1);}bool wxXMetaFile::ReadFile(const wxChar *file){  HandleTableSize = 0;  FILE *handle = wxFopen(file, wxT("rb"));  if (!handle) return false;  // Read placeable metafile header, if any  long key = getint(handle);  if (key == (long) 0x9AC6CDD7)  {    /* long hmf = */ getshort(handle);    int iLeft, iTop, iRight, iBottom;    iLeft = getsignedshort(handle);    iTop = getsignedshort(handle);    iRight = getsignedshort(handle);    iBottom = getsignedshort(handle);    left = (double)iLeft;    top = (double)iTop;    right = (double)iRight;    bottom = (double)iBottom;    /* int inch = */ getshort(handle);    /* long reserved = */ getint(handle);    /* int checksum = */ getshort(handle);/*      double widthInUnits = (double)right - left;      double heightInUnits = (double)bottom - top;      *width = (int)((widthInUnits*1440.0)/inch);      *height = (int)((heightInUnits*1440.0)/inch);*/  }  else rewind(handle);  // Read METAHEADER  int mtType = getshort(handle);  if (mtType != 1 && mtType != 2)  {    fclose(handle);    return false;  }  /* int mtHeaderSize = */ getshort(handle);  int mtVersion = getshort(handle);  if (mtVersion != 0x0300 && mtVersion != 0x0100)  {    fclose(handle);    return false;  }  /* long mtSize = */ getint(handle);  /* int mtNoObjects = */ getshort(handle);  /* long mtMaxRecord = */ getint(handle);  /* int mtNoParameters = */ getshort(handle);  while (!feof(handle))  {    long rdSize = getint(handle);      // 4 bytes    int rdFunction = getshort(handle); // 2 bytes    if (feof(handle))      break;    switch (rdFunction)    {      case META_SETBKCOLOR:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETBKCOLOR);        long colorref = getint(handle); // COLORREF        rec->param1 = GetRValue(colorref);        rec->param2 = GetGValue(colorref);        rec->param3 = GetBValue(colorref);        metaRecords.Append(rec);        break;      }      case META_SETBKMODE:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETBKMODE);        rec->param1 = getshort(handle); // Background mode        if (rec->param1 == OPAQUE) rec->param1 = wxSOLID;        else rec->param1 = wxTRANSPARENT;        metaRecords.Append(rec);        break;      }      case META_SETMAPMODE:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETMAPMODE);        rec->param1 = getshort(handle);        metaRecords.Append(rec);        break;      }//      case META_SETROP2://      case META_SETRELABS://      case META_SETPOLYFILLMODE://      case META_SETSTRETCHBLTMODE://      case META_SETTEXTCHAREXTRA:      case META_SETTEXTCOLOR:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETTEXTCOLOR);        long colorref = getint(handle); // COLORREF        rec->param1 = GetRValue(colorref);        rec->param2 = GetGValue(colorref);        rec->param3 = GetBValue(colorref);        metaRecords.Append(rec);        break;      }//      case META_SETTEXTJUSTIFICATION:      case META_SETWINDOWORG:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWORG);        rec->param2 = getshort(handle);        rec->param1 = getshort(handle);        metaRecords.Append(rec);        break;      }      case META_SETWINDOWEXT:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWEXT);        rec->param2 = getshort(handle);        rec->param1 = getshort(handle);        metaRecords.Append(rec);        break;      }//      case META_SETVIEWPORTORG://      case META_SETVIEWPORTEXT://      case META_OFFSETWINDOWORG://      case META_SCALEWINDOWEXT://      case META_OFFSETVIEWPORTORG://      case META_SCALEVIEWPORTEXT:      case META_LINETO:      {        wxMetaRecord *rec = new wxMetaRecord(META_LINETO);        rec->param1 = getshort(handle); // x1        rec->param2 = getshort(handle); // y1        metaRecords.Append(rec);        break;      }      case META_MOVETO:      {        wxMetaRecord *rec = new wxMetaRecord(META_MOVETO);        rec->param1 = getshort(handle); // x1        rec->param2 = getshort(handle); // y1        metaRecords.Append(rec);        break;      }      case META_EXCLUDECLIPRECT:      {        wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);        rec->param4 = getshort(handle); // y2        rec->param3 = getshort(handle); // x2        rec->param2 = getshort(handle); // y1        rec->param1 = getshort(handle); // x1        metaRecords.Append(rec);        break;      }      case META_INTERSECTCLIPRECT:      {        wxMetaRecord *rec = new wxMetaRecord(META_INTERSECTCLIPRECT);        rec->param4 = getshort(handle); // y2        rec->param3 = getshort(handle); // x2        rec->param2 = getshort(handle); // y1        rec->param1 = getshort(handle); // x1        metaRecords.Append(rec);        break;      }//      case META_ARC: // DO!!!      case META_ELLIPSE:      {        wxMetaRecord *rec = new wxMetaRecord(META_ELLIPSE);        rec->param4 = getshort(handle); // y2        rec->param3 = getshort(handle); // x2        rec->param2 = getshort(handle); // y1        rec->param1 = getshort(handle); // x1        metaRecords.Append(rec);        break;      }//      case META_FLOODFILL://      case META_PIE: // DO!!!      case META_RECTANGLE:      {        wxMetaRecord *rec = new wxMetaRecord(META_RECTANGLE);        rec->param4 = getshort(handle); // y2        rec->param3 = getshort(handle); // x2        rec->param2 = getshort(handle); // y1        rec->param1 = getshort(handle); // x1        metaRecords.Append(rec);        break;      }      case META_ROUNDRECT:      {        wxMetaRecord *rec = new wxMetaRecord(META_ROUNDRECT);        rec->param6 = getshort(handle); // width        rec->param5 = getshort(handle); // height        rec->param4 = getshort(handle); // y2        rec->param3 = getshort(handle); // x2        rec->param2 = getshort(handle); // y1        rec->param1 = getshort(handle); // x1        metaRecords.Append(rec);        break;      }//      case META_PATBLT://      case META_SAVEDC:      case META_SETPIXEL:      {        wxMetaRecord *rec = new wxMetaRecord(META_SETPIXEL);        rec->param1 = getshort(handle); // x1        rec->param2 = getshort(handle); // y1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -