http://www.fileformat.info/format/wmf/egff.htm
They specifically mention that the HeaderSize field should have the
value 9. But while I try reading it I am getting some other value.
Don't know why it is so. Similarly all the other fields are
inconsistent with respect to the documentation mentioned in the web
page. Here is the code I've used.
<code>
CFile file;
CFileException fexp;
cout << "Opening file...\n";
//char* filepath = "C:\\Program Files\\Microsoft Office\\Office12\
\BITMAPS\\STYLES\\GLOBE.WMF";
if( !file.Open( _T("C:\\Program Files\\Microsoft Office\\Office12\
\BITMAPS\\STYLES\\GLOBE.WMF"), CFile::modeRead, &fexp) )
{
fexp.ReportError();
return 1;
}
cout << "Reading information...\n" ;
WMFHEAD* head = new _WindowsMetaHeader;
//reading 18 bytes
file.Read((void*) head, 18);
cout << "head->FileType : " << head->FileType << '\n' <<
"head->HeaderSize : " << head->HeaderSize << '\n' <<
"head->Version : " << head->Version << '\n' <<
"head->FileSize : " << head->FileSize << '\n' <<
"head->NumOfObjects : " << head->NumOfObjects << '\n' <<
"head->MaxRecordSize : " << head->MaxRecordSize << '\n' <<
"head->NoParameters : " << head->NoParameters << '\n';
delete head;
cout <<"Closing file...\n";
file.Close();
</code>
Hope someone can guide me on this...
--deostroll
Could it be that your wmf file has a portability header prepended?
See the "Porting WMF Files Between Applications" of your link for more
info.
Here is what I got as output:
pmh->Key = 2596720087
pmh->Handle = 0
pmh->Left = -1458
pmh->Top = -666
pmh->Right = 1458
pmh->Bottom = 1344
pmh->Inch = 576
pmh->Reserved = 0
pmh->Checksum = 21131
Not sure if pmh->Left and pmh->Right are showing the correct values?
--deostroll
Well Key, Handle, and Reserved are the exact values they should be, so
that makes me think you are reading it ok. Inch looks reasonable.
The Checksum is correct for the values listed. As for left, top,
right, bottom... not really sure.
> Plus, I have the doubt
> 'what comes next'? So after this portability header is read, should I
> expect a WMFRECORD or the actual WMFHEADER?
I suspect WMFHEADER is next.
--deostroll
The process is described in your link. Checksum contains a checksum
value for the previous 10 WORDs in the header, calculated by XORing
each WORD value to 0. i.e.
WORD checksum = 0;
checksum ^= 2596720087;
checksum ^= 0;
checksum ^= -1458;
etc.
More precisely:
#include <iostream>
int main()
{
unsigned short s = 0u;
s ^= 2596720087L & 0x0000FFFFL;
s ^= (2596720087L & 0xFFFF0000L) >> 16;
s ^= 0;
s ^= -1458;
s ^= -666;
s ^= 1458;
s ^= 1344;
s ^= 576;
s ^= 0;
std::cout << s << std::endl;
return 0;
}