Welcome to MSDN Blogs Sign in | Join | Help

F# and IronPython Sample Code to List Installed Fonts

In my quest to have a mind-expanding experience this year, I'm learning functional programming. I've started with F# because of its great interop with existing .NET code. I just began my learning this weekend and thought I'd post a *simple*, but real-world example to help anyone else who is learning about F#.

Purpose of sample: List all the fonts installed on my system.

I've provided two samples: one in F# and one in IronPython to help anyone making the transition.

F# Version

open System.Drawing.Text
let ifc = new System.Drawing.Text.InstalledFontCollection() 
let family_names = ifc.Families |> Array.to_list |> List.map (fun f -> f.Name ) 
do List.iter (fun f -> Printf.printf "%s\n" f) family_names

IronPython Version

import clr
clr.AddReference("System.Drawing")
import System.Drawing

ifc = System.Drawing.Text.InstalledFontCollection()
fontnames = [font.Name for font in ifc.Families]
for fn in fontnames:
    print "\"%s\"" % fn

Published Sunday, May 06, 2007 6:28 PM by saveenr

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker