March 14, 2012, 1:15 am
#include <vector>
#include <iostream>
using namespace std;
void reverse(vector<int> &seq,int n1,int n2) {
for(;(n2-n1)>=1;) {
int temp = seq[n1]; seq[n1] = seq[n2]; seq[n2]=temp;
n1++;
n2--;
}
}
int main() {
int seq_len=4;
vector<int> seq;
for(int n=0;n<seq_len;n++) {seq.push_back(n);}
for(int n=0;n<seq.size();n++) cout << seq[n] << " ";
cout << endl;
for(int n=0;n<seq_len;n++) {
for(bool final=false;final==false;) {
final=true;
int k=0;
for(int n=0;n<(seq.size()-1);n++) {
if(seq[n] < seq[n+1]) {k=n; final=false;}
}
if(!final) {
int l;
for(int n=k+1;n<seq.size();n++) {
if(seq[k] < seq[n]) {
l=n;
}
}
int temp = seq[k]; seq[k] = seq[l]; seq[l] = temp;
reverse(seq,k+1,seq.size()-1);
for(int n=0;n<seq.size();n++) cout << seq[n] << " ";
cout << endl;
}
}
}
}
March 8, 2012, 1:23 am
shellinabox is a web based terminal client, it’s neat and kind of useful for remote access. However, I don’t much like the default fonts (which are limited by want is available to your browser). I therefore modified it to use the Unifont WOFF I previously generated.
It /kind of/ works. The spacing is still off, and the Unifont WOFF only seems to work in Safari at the moment (it is kind of big!). Anyway, moving to Unifont resolved some of the Kanji rendering artifacts I was having:


You can see that the Hanzi in the first example inserts an extra whitespace above the line. In the second example the Hanzi throws the (s out of alignment, due to the Hanzi width being different than the normal text.

This is the version of shellinthebox modified to use Unifont. As you can see it keeps everything nicely in alignment. There’s also no /extra/ white horizontal line. However, every line now gets a whitespace between it, I need to figure out the css padding issues that are causing this.
You can find my shellinthebox fork on github here.
March 8, 2012, 12:43 am
Today I discovered Gnu Unifont. It’s a really cool unicode bitmap font, with a high level of unicode coverage. There was no WOFF version available so I made one using fontforge. The version of fontforge in debian stable doesn’t have WOFF support so it was a build from source job, it’s worth noting that you need libpng-dev and libz-dev installed for WOFF support to be compiled in (otherwise it’s greyed out in the “generate fonts” menu).
You can download my WOFF here. And see it in action:
However, it only seems to work in Safari… which is a shame. 🙁
March 7, 2012, 12:51 am
This evening I’ve been playing with fonts on the web, specifically fixed width terminal fonts. Years ago I was a big fan of Profont and Terminus on Linux, however since moving to a mac I’ve stuck with it’s standard terminal font. I wanted to see if these fonts could be rendered on the web, my first thought was that I could build my own tools to render them to a html5 canvas, that would be a fun project. However with a little further investigation I discovered WOFF. WOFF is a W3C standard which allows browsers to download and render ttf fonts. This isn’t perfect, as Terminus and Profont are generally used as bitmap fonts. However it may mean I can mix those character sets with other, unicode renderings (one of the things I love about OSX is how well the terminal renders Kanji).
So… I found TTF versions of Terminus and Profont on the web. Unfortunately the Terminus TTF renderings seem to be quite bad. In any case I used this tool to convert the ttf files to WOFF files. And then created a couple of simple webpages to test the fonts:
Terminus
Profont
The Profont version looks a lot better to my mind. In firefox/chrome the Kanji gets pulled in from some other font automatically. I think Kanji fonts are fixed width, I think exactly double standard latin characters, at least that’s how it appears on the mac terminal:

You can see the latin characters don’t get pulled out of alignment after the Japanese characters are inserted. The same seems to be stuff of the fixed width fonts in the WOFF webpages above in Firefox and Chrome, however in Safari the hiragana does seem to pull the other characters out of alignment. I’ll have to look in to ways of specifying a fixed width alternative Unicode font…
So, those are my experiments so far. Rendering Profont nicely in the browser seems relatively straight forward, and allows unicode character sets. Next questions is what to do with it!