[plt-scheme] Re: True Type Fonts

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Mar 9 16:50:39 EST 2004

At Mon, 08 Mar 2004 23:42:42 +0000, Guenther Schmidt wrote:
> actually I need to write an image manipulation app and I have 3 ttf files.
> 
> My app needs to use the font to embed text in that font into an image.

Below is the source of a module that provides `add-font-resource' and
`remove-font-resource'. Both functions take a pathname string (which
probably should be normalized with `simplify-path').

Loading a file with `add-font-resource' makes new font names available
to MrEd. I'm not sure how you discover the font name(s), except by
comparing the result of `(get-face-list)' before and after calling
`add-font-resource'.

After the font is loaded you can create an appropriate font% object
using the font name, load a bitmap and attach it to a bitmap-dc%, draw
text into the bitmap-dc% with the font% object, and then save the
bitmap.

A binary version of the module (for v206p1) is here:

   http://www.cs.utah.edu/~mflatt/tmp/loadfont.dll

Matthew

----------------------------------------

; Compile like this:
;    mzc ++ldf gdi32.lib loadfont.ss
; to get loadfont.dll
(module loadfont mzscheme
  (require (lib "cffi.ss" "compiler"))
  (provide add-font-resource
	   remove-font-resource)

  (c-declare "#include <windows.h>")

  (define add-font-resource
    (c-lambda (char-string) int "AddFontResource"))
  (define remove-font-resource
    (c-lambda (char-string) bool "RemoveFontResource")))

  


Posted on the users mailing list.