Wednesday, 12 August 2009

Embedding the SimPL APL font on a web page using Cufón

I came across Cufón a while ago whilst browsing the excellent nettuts+ website.

Having started coding in APL I was wondering about the best way to present developed code on my blog. One option is to use my java transcoding technique to load my Soliton Sharp APL code into jEdit (my favourite editor) using my custom character set transcoder to convert the custom eight-bit ASCII encoding used by Soliton into standard Unicode APL characters.

Cufón allows you to embed any arbitrary truetype font or fonts into a webpage via javascript and then use the font directly within the html by replacing a standard html tag. You can either download the utility or use their website to process a truetype font located on your hard disk to generate a javascript file containing your selected truetype glyphs. The generated file in this example is simpl_400.font.js (see code below).

I chose the excellent free font created by Phil Chasney called SImPL to embed within this blog.

The code required within the head tag of this page to embed the font is very simple:

<script src="http://www.wickensonline.co.uk/styles/cufon-yui.js" type="text/javascript"></script>
<script src="http://www.wickensonline.co.uk/styles/simpl_400.font.js" type="text/javascript"></script>
<script type="text/javascript">
Cufon.replace('h1');
</script>


The results can be seen with the following APL characters above ASCII location 127 in the SOLITON-APL encoding:


¨¯≤≥≠∨×⍪⌹∵⌿
⍲¡€£¥¬⍱⌻⍂≡⌷¿
⍺⊥∩⌊∊∇∆⍳∘⎕∣⊤○
⍴⌈↓∪⍵⊃↑⊂⊢⍀⊣÷
⌶⊖⍎⍝⍷⍫⍒⍋⍸⍤⍞⍕⍥
⍟⍉⌽⍧←⍙→⋄



and an example of some APL code:


∇mbrt1[⎕]∇
[0] z←mbrt1
[1] rrz←(0.1×⍳21)−1 ⍝ array from ¯1 to +1 stepsize 0.1
[2] iiz←(0.1×⍳21)−1 ⍝ array from ¯1 to +1 stepsize 0.1


∇cmplsq[⎕]∇
[0] z← cmplsq ⍵
[1]
[2] ⍝ Function: Complex Square
[3] ⍝ Perform a complex square of the argument ⍵, returning array r,i in z
[4]
[5] r←⍵[0] ⍝ extract real part into r
[6] i←⍵[1] ⍝ extract imaginary part into i
[7] rn←(r⋆2)−(i⋆2) ⍝ real result
[8] in←r×i×2 ⍝ imaginary result
[9] z←rn,in ⍝ z is array of real and imaginary results

2 comments:

Andrew Beacock said...

This code just looks so unlike code that we know today that I want to marvel it as a thing of beauty! Great post.

Mark Wickens said...

It is a beautiful language and the inventor, Kenneth Iverson received the Turing Award for its' development. His seminal paper Notation as a Tool of Thought provides justification that George Booles assertion 'That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted' applies equally to both mathematics and computer languages.