![]() |
WGX library Architecture - Reference Manual - Guides |
|
00001 /* 00002 * WGX - Windows GUI Extended Library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #define WIN32_NO_STATUS 00028 #include <windows.h> 00029 00030 #include "wgx.h" 00031 00032 /* Uses Lua */ 00033 #define lua_c 00034 #include "../../lua5.1/lua.h" 00035 #include "../../lua5.1/lauxlib.h" 00036 #include "../../lua5.1/lualib.h" 00037 00038 char err_msg[1024]; 00039 00040 /* returns 0 if variable is not defined */ 00041 static int getint(lua_State *L, char *variable) 00042 { 00043 int ret; 00044 00045 lua_getglobal(L, variable); 00046 ret = (int)lua_tointeger(L, lua_gettop(L)); 00047 lua_pop(L, 1); 00048 return ret; 00049 } 00050 00074 BOOL __stdcall WgxGetLogFontStructureFromFile(char *path,LOGFONT *lf) 00075 { 00076 lua_State *L; 00077 int status; 00078 char *string; 00079 00080 L = lua_open(); /* create state */ 00081 if(!L) return FALSE; 00082 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ 00083 luaL_openlibs(L); /* open libraries */ 00084 lua_gc(L, LUA_GCRESTART, 0); 00085 00086 status = luaL_dofile(L,path); 00087 if(!status){ /* successful */ 00088 lf->lfHeight = getint(L,"height"); 00089 lf->lfWidth = getint(L,"width"); 00090 lf->lfEscapement = getint(L,"escapement"); 00091 lf->lfOrientation = getint(L,"orientation"); 00092 lf->lfWeight = getint(L,"weight"); 00093 lf->lfItalic = (BYTE)getint(L,"italic"); 00094 lf->lfUnderline = (BYTE)getint(L,"underline"); 00095 lf->lfStrikeOut = (BYTE)getint(L,"strikeout"); 00096 lf->lfCharSet = (BYTE)getint(L,"charset"); 00097 lf->lfOutPrecision = (BYTE)getint(L,"outprecision"); 00098 lf->lfClipPrecision = (BYTE)getint(L,"clipprecision"); 00099 lf->lfQuality = (BYTE)getint(L,"quality"); 00100 lf->lfPitchAndFamily = (BYTE)getint(L,"pitchandfamily"); 00101 lua_getglobal(L, "facename"); 00102 string = (char *)lua_tostring(L, lua_gettop(L)); 00103 if(string){ 00104 (void)strncpy(lf->lfFaceName,string,LF_FACESIZE); 00105 lf->lfFaceName[LF_FACESIZE - 1] = 0; 00106 } 00107 lua_pop(L, 1); 00108 } 00109 lua_close(L); 00110 return TRUE; 00111 } 00112 00122 BOOL __stdcall WgxSaveLogFontStructureToFile(char *path,LOGFONT *lf) 00123 { 00124 FILE *pf; 00125 int result; 00126 00127 pf = fopen(path,"wt"); 00128 if(!pf){ 00129 (void)_snprintf(err_msg,sizeof(err_msg) - 1, 00130 "Can't save font preferences to %s!\n%s", 00131 path,_strerror(NULL)); 00132 err_msg[sizeof(err_msg) - 1] = 0; 00133 MessageBox(0,err_msg,"Warning!",MB_OK | MB_ICONWARNING); 00134 return FALSE; 00135 } 00136 00137 result = fprintf(pf, 00138 "height = %li\n" 00139 "width = %li\n" 00140 "escapement = %li\n" 00141 "orientation = %li\n" 00142 "weight = %li\n" 00143 "italic = %i\n" 00144 "underline = %i\n" 00145 "strikeout = %i\n" 00146 "charset = %i\n" 00147 "outprecision = %i\n" 00148 "clipprecision = %i\n" 00149 "quality = %i\n" 00150 "pitchandfamily = %i\n" 00151 "facename = \"%s\"\n", 00152 lf->lfHeight, 00153 lf->lfWidth, 00154 lf->lfEscapement, 00155 lf->lfOrientation, 00156 lf->lfWeight, 00157 lf->lfItalic, 00158 lf->lfUnderline, 00159 lf->lfStrikeOut, 00160 lf->lfCharSet, 00161 lf->lfOutPrecision, 00162 lf->lfClipPrecision, 00163 lf->lfQuality, 00164 lf->lfPitchAndFamily, 00165 lf->lfFaceName 00166 ); 00167 fclose(pf); 00168 if(result < 0){ 00169 (void)_snprintf(err_msg,sizeof(err_msg) - 1, 00170 "Can't write gui preferences to %s!\n%s", 00171 path,_strerror(NULL)); 00172 err_msg[sizeof(err_msg) - 1] = 0; 00173 MessageBox(0,err_msg,"Warning!",MB_OK | MB_ICONWARNING); 00174 return FALSE; 00175 } 00176 return TRUE; 00177 } 00178