Commit 8d771576 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

view: Make FileIsPlaceable() and GetPlaceableMetaFile() static.

parent e30bb829
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
#include "globals.h" #include "globals.h"
#include <stdio.h> #include <stdio.h>
BOOL FileIsPlaceable( LPCSTR szFileName );
HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName );
HMETAFILE hmf; HMETAFILE hmf;
int deltax = 0, deltay = 0; int deltax = 0, deltay = 0;
int width = 0, height = 0; int width = 0, height = 0;
...@@ -46,6 +43,85 @@ static BOOL FileOpen(HWND hWnd, char *fn, int fnsz) ...@@ -46,6 +43,85 @@ static BOOL FileOpen(HWND hWnd, char *fn, int fnsz)
return GetOpenFileName(&ofn); return GetOpenFileName(&ofn);
} }
static BOOL FileIsPlaceable( LPCSTR szFileName )
{
HFILE hInFile;
APMFILEHEADER apmh;
if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
return FALSE;
if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
!= sizeof(APMFILEHEADER) )
{
_lclose( hInFile );
return FALSE;
}
_lclose( hInFile );
/* Is it placeable? */
return (apmh.key == APMHEADER_KEY);
}
static HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
{
LPBYTE lpData;
METAHEADER mfHeader;
APMFILEHEADER APMHeader;
HFILE fh;
HMETAFILE hmf;
WORD checksum, *p;
HDC hdc;
int i;
if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
_llseek(fh, 0, 0);
if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
_llseek(fh, sizeof(APMFILEHEADER), 0);
checksum = 0;
p = (WORD *) &APMHeader;
for(i=0; i<10; i++)
checksum ^= *p++;
if (checksum != APMHeader.checksum) {
char msg[128];
sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
checksum, APMHeader.checksum);
MessageBox(hwnd, msg, "Checksum failed", MB_OK);
return 0;
}
if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
if (!(lpData = GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
_llseek(fh, sizeof(APMFILEHEADER), 0);
if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
{
GlobalFree((HGLOBAL)lpData);
_lclose(fh);
return 0;
}
_lclose(fh);
if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
return 0;
width = APMHeader.bbox.Right - APMHeader.bbox.Left;
height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;
/* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
hdc = GetDC(hwnd);
width = width * GetDeviceCaps(hdc, LOGPIXELSX)/APMHeader.inch;
height = height * GetDeviceCaps(hdc,LOGPIXELSY)/APMHeader.inch;
ReleaseDC(hwnd, hdc);
deltax = 0;
deltay = 0 ;
return hmf;
}
LRESULT CALLBACK WndProc(HWND hwnd, LRESULT CALLBACK WndProc(HWND hwnd,
UINT uMessage, UINT uMessage,
...@@ -137,82 +213,3 @@ LRESULT CALLBACK WndProc(HWND hwnd, ...@@ -137,82 +213,3 @@ LRESULT CALLBACK WndProc(HWND hwnd,
} }
return 0; return 0;
} }
BOOL FileIsPlaceable( LPCSTR szFileName )
{
HFILE hInFile;
APMFILEHEADER apmh;
if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
return FALSE;
if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
!= sizeof(APMFILEHEADER) )
{
_lclose( hInFile );
return FALSE;
}
_lclose( hInFile );
/* Is it placeable? */
return (apmh.key == APMHEADER_KEY);
}
HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
{
LPBYTE lpData;
METAHEADER mfHeader;
APMFILEHEADER APMHeader;
HFILE fh;
HMETAFILE hmf;
WORD checksum, *p;
HDC hdc;
int i;
if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
_llseek(fh, 0, 0);
if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
_llseek(fh, sizeof(APMFILEHEADER), 0);
checksum = 0;
p = (WORD *) &APMHeader;
for(i=0; i<10; i++)
checksum ^= *p++;
if (checksum != APMHeader.checksum) {
char msg[128];
sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
checksum, APMHeader.checksum);
MessageBox(hwnd, msg, "Checksum failed", MB_OK);
return 0;
}
if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
if (!(lpData = GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
_llseek(fh, sizeof(APMFILEHEADER), 0);
if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
{
GlobalFree((HGLOBAL)lpData);
_lclose(fh);
return 0;
}
_lclose(fh);
if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
return 0;
width = APMHeader.bbox.Right - APMHeader.bbox.Left;
height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;
/* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
hdc = GetDC(hwnd);
width = width * GetDeviceCaps(hdc, LOGPIXELSX)/APMHeader.inch;
height = height * GetDeviceCaps(hdc,LOGPIXELSY)/APMHeader.inch;
ReleaseDC(hwnd, hdc);
deltax = 0;
deltay = 0 ;
return hmf;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment