Автор: Zloy_Gelud
Дата сообщения: 19.12.2011 08:13
ubian
Robby
Функа для получения названия шрифта.
Код: -- #FUNCTION# ====================================================================================================================
-- Name...........: System.GetFontName
-- Description....: Возвращает индексированную числами таблицу
-- Syntax.........: System.GetFontName (tFontsPath)
-- Parameters.....: tFontsPath - таблица, содержащая полные пути шрифтов
-- Return values..: tRet[i].Name - Название шрифта.
-- tRet[i].Path - Путь к шрифту.
-- ===============================================================================================================================
System.GetFontsName = function (tFontsPath)
local tFontsName = {};
if type(tFontsPath) ~= "table" then return nil; end
Memory.OpenLibrary(0, _SystemFolder.."\\kernel32.dll");
Memory.OpenLibrary(1, _SystemFolder.."\\gdi32.dll");
local nF1 = Memory.OpenFunction(0, "MultiByteToWideChar", DLL_CALL_STDCALL, DLL_RETURN_INT);
local nF2 = Memory.OpenFunction(1, "GetFontResourceInfoW", DLL_CALL_STDCALL, DLL_RETURN_INT);
for i = 1, #tFontsPath do
local pTmp, pTmp2 = Memory.Allocate(4), Memory.Allocate(4);
if DLL.CallFunction("gdi32.dll", "AddFontResourceExA", "\""..tFontsPath[i].."\",32,0", 0, 1) ~= "0" then
local nBuffersize = Memory.CallFunction(nF1, 0, 1, tFontsPath[i], -1, 0, 0);
local pWideString = Memory.Allocate(2 * nBuffersize);
Memory.CallFunction(nF1, 0, 1, tFontsPath[i], -1, pWideString, nBuffersize);
---------------------------------------------------
Memory.CallFunction(nF2, pWideString, pTmp, 0, 1);
local pBuffer = Memory.Allocate(2 * Memory.GetInt(pTmp));
Memory.PutLong(pTmp2, Memory.GetInt(pTmp));
Memory.CallFunction(nF2, pWideString, pTmp2, pBuffer, 1);
tFontsName[Table.Count(tFontsName) + 1] = {Name = Memory.GetString(pBuffer, -1, "Unicode"), Path = tFontsPath[i]};
Memory.Free(pTmp); Memory.Free(pTmp2); Memory.Free(pBuffer); Memory.Free(pWideString);
DLL.CallFunction("gdi32.dll", "RemoveFontResourceEx", "\""..tFontsPath[i].."\",32,0", 0, 1);
end
end
Memory.CloseLibrary(1);
Memory.CloseLibrary(0);
return tFontsName;
end
-- Sample
local tSystemFonts = File.Find(Shell.GetFolder(SHF_FONTS), "*.*", false, false, nil, nil);
if tSystemFonts then
local tFonts = System.GetFontsName(tSystemFonts);
for i = 1, #tFonts do
ListBox.AddItem("ListBox1", tFonts[i].Name.." - "..tFonts[i].Path, tFonts[i].Path);
end
end