git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14320
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#include <wx/ogl/mfutils.h>
#include <stdio.h>
#include <wx/ogl/mfutils.h>
#include <stdio.h>
+static char _buf[1024]; // a temp buffer to use inplace of wxBuffer, which is deprecated.
+
static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F' };
static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F' };
buf[1] = hexArray[secondDigit];
buf[2] = 0;
}
buf[1] = hexArray[secondDigit];
buf[2] = 0;
}
// 16-bit unsigned integer
static unsigned int getshort(FILE *fp)
{
// 16-bit unsigned integer
static unsigned int getshort(FILE *fp)
{
int c, c1, c2, c3;
c = getc(fp); c1 = getc(fp); c2 = getc(fp); c3 = getc(fp);
long res = (long)((long) c) +
int c, c1, c2, c3;
c = getc(fp); c1 = getc(fp); c2 = getc(fp); c3 = getc(fp);
long res = (long)((long) c) +
(((long) c2) << 16) +
(((long) c3) << 24);
return res;
(((long) c2) << 16) +
(((long) c3) << 24);
return res;
bottom = 0.0;
left = 0.0;
right = 0.0;
bottom = 0.0;
left = 0.0;
right = 0.0;
if (file)
ok = ReadFile(file);
}
if (file)
ok = ReadFile(file);
}
[1]----param2--- wxBrush
[2] | wxFont
[3] | -> wxPen
[1]----param2--- wxBrush
[2] | wxFont
[3] | -> wxPen
The handle table works as follows.
When a GDI object is created whilst reading in the
metafile, the (e.g.) createpen record is added to the
The handle table works as follows.
When a GDI object is created whilst reading in the
metafile, the (e.g.) createpen record is added to the
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.)
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,
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,
allows us to create all GDI objects in advance of playing the
metafile).
*/
allows us to create all GDI objects in advance of playing the
metafile).
*/
static wxMetaRecord *HandleTable[100];
static int HandleTableSize = 0;
static wxMetaRecord *HandleTable[100];
static int HandleTableSize = 0;
return i;
}
// No free spaces in table, so append.
return i;
}
// No free spaces in table, so append.
HandleTable[HandleTableSize] = record;
HandleTableSize ++;
return (HandleTableSize - 1);
HandleTable[HandleTableSize] = record;
HandleTableSize ++;
return (HandleTableSize - 1);
bool wxXMetaFile::ReadFile(char *file)
{
HandleTableSize = 0;
bool wxXMetaFile::ReadFile(char *file)
{
HandleTableSize = 0;
FILE *handle = fopen(file, "rb");
if (!handle) return FALSE;
// Read placeable metafile header, if any
long key = getint(handle);
FILE *handle = fopen(file, "rb");
if (!handle) return FALSE;
// Read placeable metafile header, if any
long key = getint(handle);
if (key == (long) 0x9AC6CDD7)
{
long hmf = getshort(handle);
if (key == (long) 0x9AC6CDD7)
{
long hmf = getshort(handle);
fclose(handle);
return FALSE;
}
fclose(handle);
return FALSE;
}
long mtSize = getint(handle);
int mtNoObjects = getshort(handle);
long mtMaxRecord = getint(handle);
long mtSize = getint(handle);
int mtNoObjects = getshort(handle);
long mtMaxRecord = getint(handle);
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
metaRecords.Append(rec);
break;
}
metaRecords.Append(rec);
break;
}
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
metaRecords.Append(rec);
break;
}
metaRecords.Append(rec);
break;
}
case META_DIBCREATEPATTERNBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_DIBCREATEPATTERNBRUSH);
case META_DIBCREATEPATTERNBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_DIBCREATEPATTERNBRUSH);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
-
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
+
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
case META_CREATEPALETTE:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
case META_CREATEPALETTE:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
-
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
+
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
case META_CREATEBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSH);
case META_CREATEBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSH);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
case META_CREATEPATTERNBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEPATTERNBRUSH);
case META_CREATEPATTERNBRUSH:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEPATTERNBRUSH);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
AddMetaRecordHandle(rec);
rec->param2 = (long)(gdiObjects.Number() - 1);
AddMetaRecordHandle(rec);
rec->param2 = (long)(gdiObjects.Number() - 1);
// For some reason, the size of this record is sometimes 9 words!!!
// instead of the usual 8. So read 2 characters extra.
if (rdSize == 9)
// For some reason, the size of this record is sometimes 9 words!!!
// instead of the usual 8. So read 2 characters extra.
if (rdSize == 9)
case META_CREATEBITMAPINDIRECT:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAPINDIRECT);
case META_CREATEBITMAPINDIRECT:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAPINDIRECT);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
-
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
+
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
case META_CREATEBITMAP:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAP);
case META_CREATEBITMAP:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAP);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
-
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
+
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
AddMetaRecordHandle(rec);
case META_CREATEREGION:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEREGION);
case META_CREATEREGION:
{
wxMetaRecord *rec = new wxMetaRecord(META_CREATEREGION);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
metaRecords.Append(rec);
gdiObjects.Append(rec);
metaRecords.Append(rec);
gdiObjects.Append(rec);
- fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
break;
}
case META_POLYLINE:
break;
}
case META_POLYLINE:
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
rec->points[i].x = getshort(handle);
rec->points[i].y = getshort(handle);
}
break;
}
// case META_ESCAPE:
break;
}
// case META_ESCAPE:
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
break;
}
// case META_STRETCHDIB:
break;
}
// case META_STRETCHDIB:
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
break;
}
case META_CREATEBITMAP:
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
break;
}
case META_CREATEBITMAP:
{
/*
fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
break;
}
case META_CREATEREGION:
break;
}
case META_CREATEREGION: