From: Pat T. <pat...@us...> - 2009-03-26 00:39:39
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pat Thoyts wrote: > Brian Griffin wrote: >> On Tue, Mar 24, 2009 at 4:28 PM, T. Horsnell <ts...@mr... >> <mailto:ts...@mr...>> wrote: > >> Jeff Hobbs wrote: >> > On 24/03/2009 9:46 AM, T. Horsnell wrote: >> >> Is there a way in TCLTK to use fontfiles from a private directory? >> >> Preferably a way in which one can refer to such files by an explicit >> >> file-path. >> > >> > Tk is directed by the fonts the X server (or OS system) says are >> > available. Just make that font available through the X server and Tk >> > will see it. >> > >> > Jeff > >> Yes, but I want to do this under Windows as well as Linux and I dont >> want the user to have to install this private fontset in either case. >> I want to be able to distribute them along with the application. > >> Sounds like a good GSoC project :-) > > > This can probably be achieved using AddFontResourceEx or > AddFontMemResourceEx which is what is used to load fonts embedded in PDF > documents and other such things. I should think it will be fairly simple > to do. > > Pat Thoyts In fact the following code does the job: critcl::cproc AddFontResource {Tcl_Interp* interp Tcl_Obj* pathObj} ok { Tcl_DString ds; Tcl_Encoding unicode; int len, r = TCL_OK; const char *path = Tcl_GetStringFromObj(pathObj, &len); Tcl_DStringInit(&ds); unicode = Tcl_GetEncoding(interp, "unicode"); Tcl_UtfToExternalDString(unicode, path, len, &ds); if (AddFontResourceExW(Tcl_DStringValue(&ds), FR_PRIVATE, NULL) == 0) { r = TCL_ERROR; } Tcl_DStringFree(&ds); Tcl_FreeEncoding(unicode); return r; } given this function in an extension it will add a font from a .ttf file to the set available shown in [font families]. The FR_PRIVATE means the font is only made available to this process and is not installed into the system permanently. Pat Thoyts -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBScrOuWB90JXwhOSJAQIuxwP/cAez+yR0BueZ+4uMigH6OcL5SFRoE8S2 6PktMMlE0CrFQnfknHUXeHpH/HpgDUFhhikZld9SboiyDZAx7PSt+L0cGbHe/eYA 392Ilywyn0yXoFBcIawe6+UlTcKRRgu8lGz6p80rtQp9uNVCccY8kL6Nagjceqrx mAienWG9668= =aVuu -----END PGP SIGNATURE----- |