Listing the installed font using .NET from APLX

APLX includes the ability to use the Microsoft .NET classes. Here's an example of using .NET to list the fonts installed on your system. See here for other examples.

To list the installed fonts you need the InstalledFontCollection class, which is in the System.Drawing.Text namespace in system.drawing.dll. So you need to add an extra element to the .Net namespace search list. Something like this:

      a←'.net' ⎕setup 'using'
      '.net' ⎕setup (⊂'using'), a,⊂'System.Drawing.Text,system.drawing.dll'

You can now create an InstalledFontCollection object and use it to list the fonts:

      f←'.net' ⎕new 'InstalledFontCollection'
      (f.Families).Name
 Aharoni Amienne Andalus Angsana New AngsanaUPC APL385 Unicode APLX Upright Arab
      ic Typesetting Arial Arial Black Arial Narrow Arial Unicode MS Arnprior Ba
      tang BatangChe Baveuse Berylium Biondi Blue Highway Blue Highway Condensed
.. etc

The only tricky bit of this is that the Families property returns a reference to a .Net array. To pull out the names, you need to get an APL array of references to each of the elements, hence the parentheses in the line:

(f.Families).Name

which gets the Name property of each of the elements in the f.Families array. If you omit the parentheses, APLX would try to get the Name property of the whole of the Families array - which doesn't exist.

Incidentally, you don't need .Net for this - the APLX 'System' class has a 'fonts' property, which will work on all platforms:

'#' ⎕WI 'fonts'

or:

s ← '⎕'  ⎕new 'System'
s.fonts

CategoryAplx CategoryDotNet

FontsNetAplx (last edited 2009-02-02 12:19:50 by SimonMarsden)