| 1 | /* $Id: fontres.cpp,v 1.1 2004-01-11 11:42:13 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | /*
|
|---|
| 5 | * GDI32 font apis
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright 2003 Sander van Leeuwen (sandervl@innotek.de)
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | /*****************************************************************************
|
|---|
| 14 | * Includes *
|
|---|
| 15 | *****************************************************************************/
|
|---|
| 16 |
|
|---|
| 17 | #include <odin.h>
|
|---|
| 18 | #include <odinwrap.h>
|
|---|
| 19 | #include <os2sel.h>
|
|---|
| 20 |
|
|---|
| 21 | #include <os2win.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <stdarg.h>
|
|---|
| 24 | #include <ctype.h>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 | #include <dbglog.h>
|
|---|
| 27 | #include <unicode.h>
|
|---|
| 28 | #include <stats.h>
|
|---|
| 29 | #include <objhandle.h>
|
|---|
| 30 | #include "oslibgpi.h"
|
|---|
| 31 |
|
|---|
| 32 | #define DBG_LOCALLOG DBG_fontres
|
|---|
| 33 | #include "dbglocal.h"
|
|---|
| 34 |
|
|---|
| 35 | #define TESTFONT_RESNAME "TESTFONT"
|
|---|
| 36 |
|
|---|
| 37 | //just picking a reasonable maximum; don't want to mess with linked lists
|
|---|
| 38 | #define MAX_PUBLICFONTS 32
|
|---|
| 39 |
|
|---|
| 40 | typedef struct {
|
|---|
| 41 | char szFaceName[32];
|
|---|
| 42 | char szFontResName[260];
|
|---|
| 43 | char szFileName[260];
|
|---|
| 44 | char *pFontData;
|
|---|
| 45 | DWORD dwFontSize;
|
|---|
| 46 | } SCALABLEFONTS;
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | static SCALABLEFONTS *publicfonts = NULL;
|
|---|
| 50 | static CRITICAL_SECTION fntcritsect = {0};
|
|---|
| 51 |
|
|---|
| 52 | #define FntLock() EnterCriticalSection(&fntcritsect)
|
|---|
| 53 | #define FntUnlock() LeaveCriticalSection(&fntcritsect)
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | // Remember the font filename for GetFontData if this is a font previously
|
|---|
| 58 | // registered with AddFontResource
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | BOOL RegisterFont(HFONT hFont, LPSTR lfFaceName)
|
|---|
| 61 | {
|
|---|
| 62 | if(!publicfonts) {
|
|---|
| 63 | return FALSE;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | FntLock();
|
|---|
| 67 | for(int i=0;i<MAX_PUBLICFONTS;i++) {
|
|---|
| 68 | if(strcmp(publicfonts[i].szFaceName, lfFaceName) == 0) {
|
|---|
| 69 | #ifdef DEBUG
|
|---|
| 70 | dprintf(("Remember font file %s for font %x", publicfonts[i].szFileName, hFont));
|
|---|
| 71 | if(GetFileAttributesA(publicfonts[i].szFileName) == -1) {
|
|---|
| 72 | dprintf(("ERROR: font file does not exist anymore!!!!!!"));
|
|---|
| 73 | }
|
|---|
| 74 | #endif
|
|---|
| 75 | ObjSetHandleGDI32Data(hFont, HNDL_FONT, (DWORD)&publicfonts[i]);
|
|---|
| 76 | break;
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 | FntUnlock();
|
|---|
| 80 | if(i == MAX_PUBLICFONTS) {
|
|---|
| 81 | return FALSE;
|
|---|
| 82 | }
|
|---|
| 83 | return TRUE;
|
|---|
| 84 | }
|
|---|
| 85 | //******************************************************************************
|
|---|
| 86 | //******************************************************************************
|
|---|
| 87 | DWORD WIN32API GetFontData(HDC hdc, DWORD dwTable,
|
|---|
| 88 | DWORD dwOffset,
|
|---|
| 89 | LPVOID lpvBuffer,
|
|---|
| 90 | DWORD dbData)
|
|---|
| 91 | {
|
|---|
| 92 | dprintf(("GDI32: GetFontData, not implemented (GDI_ERROR)\n"));
|
|---|
| 93 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|---|
| 94 |
|
|---|
| 95 | return(GDI_ERROR);
|
|---|
| 96 | }
|
|---|
| 97 | //******************************************************************************
|
|---|
| 98 | //******************************************************************************
|
|---|
| 99 | int WIN32API AddFontResourceA(LPCSTR szFont)
|
|---|
| 100 | {
|
|---|
| 101 | HINSTANCE hInstance;
|
|---|
| 102 |
|
|---|
| 103 | dprintf(("GDI32: AddFontResourceA %s", szFont));
|
|---|
| 104 | hInstance = LoadLibraryA(szFont);
|
|---|
| 105 | if(hInstance) {
|
|---|
| 106 | dprintf(("AddFontResourceA: executable file; NOT IMPLEMENTED"));
|
|---|
| 107 | FreeLibrary(hInstance);
|
|---|
| 108 | return 1;
|
|---|
| 109 | }
|
|---|
| 110 | return 1;
|
|---|
| 111 | }
|
|---|
| 112 | //******************************************************************************
|
|---|
| 113 | //******************************************************************************
|
|---|
| 114 | int WIN32API AddFontResourceW(LPCWSTR szFont)
|
|---|
| 115 | {
|
|---|
| 116 | char *astring = UnicodeToAsciiString((LPWSTR)szFont);
|
|---|
| 117 | BOOL rc;
|
|---|
| 118 |
|
|---|
| 119 | dprintf(("GDI32: AddFontResourceW"));
|
|---|
| 120 | // NOTE: This will not work as is (needs UNICODE support)
|
|---|
| 121 | rc = AddFontResourceA(astring);
|
|---|
| 122 | FreeAsciiString(astring);
|
|---|
| 123 | return rc;
|
|---|
| 124 | }
|
|---|
| 125 | //******************************************************************************
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | BOOL WIN32API RemoveFontResourceA(LPCSTR lpszFont)
|
|---|
| 128 | {
|
|---|
| 129 | dprintf(("GDI32: RemoveFontResourceA %s", lpszFont));
|
|---|
| 130 | return FALSE;
|
|---|
| 131 | }
|
|---|
| 132 | //******************************************************************************
|
|---|
| 133 | //******************************************************************************
|
|---|
| 134 | BOOL WIN32API RemoveFontResourceW(LPCWSTR szFont)
|
|---|
| 135 | {
|
|---|
| 136 | char *astring = UnicodeToAsciiString((LPWSTR)szFont);
|
|---|
| 137 | BOOL rc;
|
|---|
| 138 |
|
|---|
| 139 | dprintf(("GDI32: RemoveFontResourceW"));
|
|---|
| 140 | rc = RemoveFontResourceA(astring);
|
|---|
| 141 | FreeAsciiString(astring);
|
|---|
| 142 | return(rc);
|
|---|
| 143 | }
|
|---|
| 144 | /*****************************************************************************
|
|---|
| 145 | * Name : BOOL CreateScalableFontResourceA
|
|---|
| 146 | * Purpose : The CreateScalableFontResourceA function creates a font resource
|
|---|
| 147 | * file for a scalable font.
|
|---|
| 148 | * Parameters: DWORD fdwHidden flag for read-only embedded font
|
|---|
| 149 | * LPCSTR lpszFontRes address of filename for font resource
|
|---|
| 150 | * LPCSTR lpszFontFile address of filename for scalable font
|
|---|
| 151 | * LPCSTR lpszCurrentPath address of path to font file
|
|---|
| 152 | * Variables :
|
|---|
| 153 | * Result : TRUE / FALSE
|
|---|
| 154 | * Remark :
|
|---|
| 155 | * Status : UNTESTED STUB
|
|---|
| 156 | *
|
|---|
| 157 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
|---|
| 158 | *****************************************************************************/
|
|---|
| 159 |
|
|---|
| 160 | BOOL WIN32API CreateScalableFontResourceA(DWORD fdwHidden,
|
|---|
| 161 | LPCSTR lpszFontRes,
|
|---|
| 162 | LPCSTR lpszFontFile,
|
|---|
| 163 | LPCSTR lpszCurrentPath)
|
|---|
| 164 | {
|
|---|
| 165 | dprintf(("GDI32: CreateScalableFontResourceA %x %s %s %s not implemented", fdwHidden, lpszFontRes, lpszFontFile, lpszCurrentPath));
|
|---|
| 166 |
|
|---|
| 167 | // return OSLibGpiLoadFonts((LPSTR)lpszFontFile);
|
|---|
| 168 | return FALSE;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /*****************************************************************************
|
|---|
| 173 | * Name : BOOL CreateScalableFontResourceW
|
|---|
| 174 | * Purpose : The CreateScalableFontResourceW function creates a font resource
|
|---|
| 175 | * file for a scalable font.
|
|---|
| 176 | * Parameters: DWORD fdwHidden flag for read-only embedded font
|
|---|
| 177 | * LPCSTR lpszFontRes address of filename for font resource
|
|---|
| 178 | * LPCSTR lpszFontFile address of filename for scalable font
|
|---|
| 179 | * LPCSTR lpszCurrentPath address of path to font file
|
|---|
| 180 | * Variables :
|
|---|
| 181 | * Result : TRUE / FALSE
|
|---|
| 182 | * Remark :
|
|---|
| 183 | * Status : UNTESTED STUB
|
|---|
| 184 | *
|
|---|
| 185 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
|---|
| 186 | *****************************************************************************/
|
|---|
| 187 |
|
|---|
| 188 | BOOL WIN32API CreateScalableFontResourceW(DWORD fdwHidden,
|
|---|
| 189 | LPCWSTR lpszFontRes,
|
|---|
| 190 | LPCWSTR lpszFontFile,
|
|---|
| 191 | LPCWSTR lpszCurrentPath)
|
|---|
| 192 | {
|
|---|
| 193 | LPSTR lpszFontFileA = NULL, lpszFontResA = NULL, lpszCurrentPathA = NULL;
|
|---|
| 194 |
|
|---|
| 195 | dprintf(("GDI32: CreateScalableFontResourceW %x %ls %ls %ls not implemented", fdwHidden, lpszFontRes, lpszFontFile, lpszCurrentPath));
|
|---|
| 196 |
|
|---|
| 197 | STACK_strdupWtoA(lpszFontFile, lpszFontFileA);
|
|---|
| 198 | STACK_strdupWtoA(lpszFontRes, lpszFontResA);
|
|---|
| 199 | STACK_strdupWtoA(lpszCurrentPath, lpszCurrentPathA);
|
|---|
| 200 | return CreateScalableFontResourceA(fdwHidden, lpszFontResA, lpszFontFileA, lpszCurrentPathA);
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|