Quicksearch

Maldives Crime Statistics Visualized: 2008 - 2011

The Maldives Police Service revamped their website on the 29th, adding some interesting online services to their website. One of the things that I caught my interest was the crime statistics, a month by month tally of different crime categories from 2008 to 2012. As far as I am aware of, these data has not been easily, publicly available before. The data listing displayed on the site, while interesting, doesn't facilitate an understanding of the trends over the period - which I was more interested to see.

Anyway, I scraped the data from the site, put into a table on Google Spreadsheet and made a small trend chart. I am sharing it here in case anyone else is interested in such too. The data used for the chart can be accessed and downloaded in the related sheet.

There are a few interesting things that can be seen.
- Crime was apparently very low at the beginning of 2008, was high for much of 2009 and came back to 2009 levels in 2011.
- There is a drop in theft from 2009 to 2011.
- Traffic related issues has continued to drop through the years.
- Drug crimes reached a major peak at the end of 2008 and had a significant drop through 2009-2010.

Smoothing the trending lines should give a better view of overall trends but that's for another time...

- View chart on Google Spreadsheet and download data


Thaana on Android: Font Installer update

Early last year, I posted a font installer for Android that replaces the default fallback font with the free FreeSerif font that includes Thaana glyphs. That installer should still work on most older devices.

Here is a repackaged version of that installer which should work on most of the new devices with more recent versions of Android. This version has been tested on a Samsung Galaxy Note running Android 2.3.6 and a Samsung Galaxy S2 running the recently released Android 4.0 Ice Cream Sandwich.

Steps


1. As before, the device needs to be rooted. You can easily root your device using SuperOneClick (free/donationware).

2. Put the update zip file (see below) somewhere on your device. You could do this by downloading the file straight from the web on to the SD card of your device.

3. Power off your phone and boot into recovery mode. The specifics of how you do this depends on which recovery tool was installed during rooting of your phone. Try VolumeUp+Center Button+Power. If that doesn't work, use Google. If you have the CWM app installed, then you could just flash the zip through that.

4. Select the update from Zip option in your recovery tool and select the update_thaanafont_v2_jaa.zip file from the list and OK it.

5. The update should progress and will ask you to reboot once completed.

6. Congratulations you have a Thaana font installed. Thaana text on the Facebook, Twitter and other apps should appear OK now!


- Download update_thaanafont_v2_jaa.zip

Do drop me a message, here or on Twitter, if it works and if there are issues. Enjoy!

Sri Lanka's Killing Fields

I just watched the documentary film "Sri Lanka's Killing fields", Channel 4's investigation into the civil war and the alleged crimes against humanity in Sri Lanka. The conflict in Sri Lanka (which lies just ~700 km from the Maldives), between the majority-Sinhalese Sri Lankan government and the separatist Tamil Tigers began in 1983 and cessation of hostilities was finally declared in 2009. By all accounts, the final several months of the war was intense and produced heavy casualty. The Channel 4 film shows highly highly disturbing footage and pictures of brutal, cold murder and abuse - by both the Sri Lankan army and the rebels. Is the cost of current "peace" in Sri Lanka morally justifiable? The full film is available on Youtube, which I've linked to below.

To put the war into better perspective, it might be helpful to compare it with the Palestine-Israel conflict which is more familiar and evokes louder, more vehement reactions and emotions in Maldivians. The conflict in Sri Lanka resulted in 80,000-100,000 deaths (conservative estimate according to many) in the period 1983-2009, while the Palestine-Israel conflict has resulted in 14,500 deaths in the period 1948-2009. That translates to 3076 deaths/year in Sri Lanka versus 237 deaths/year in Palestine-Israel! By no means do I wish to suggest that the lesser number discounts the killings or belittles the suffering in the Palestine-Israel conflict but I do wish to communicate the scale and the gravity of the situation that was in Sri Lanka...

I am left feeling more misanthropic than ever.

Thaana Text Render class for PHP 5 - v1.0

A (long) while back, I demoed a Thaana text rendering class for PHP I had written years ago that dynamically converts any given Thaana text into a formatted image of given dimensions with configuration options for important properties like font, font size and color. I am now releasing it, slightly improved, publicly for developers to use it in their applications.

Overview

The rationale for the class was that the use of images to display Thaana means that the information can be viewed on a large variety of devices and does away with the requirement for the device to support Thaana fonts. It can also be used for any purpose that requires dynamically generating an image with Thaana text in it, for example watermarking images or nice headings with your Thaana font of choice.

The class makes use of the powerful image manipulation services provided by the GD library to create images from text and hence inherits the wide range of features it offers. However, since the GD library does not support right-to-left scripts and does not offer line wrapping to fit text within a bounding box, the class requires the use of non-Unicode Thaana fonts and non-Unicode Thaana text. You can make use of my Thaana conversions class for PHP to dynamically convert Unicode Thaana text to ASCII Thaana text before passing it to this class for rendering.

Functions exposed

- render()
- renderImage()
- setFontPath()
- setFont()
- setFontSize()
- setTextColor()
- setTextLineSpacing()
- setBgColor()
- setShadow()

Requirements

- PHP 5
- GD for PHP

Usage


The class is well commented so have a look through the code for more details on the functions and their arguments.

The class takes ASCII Thaana text and an optional width, filename, filetype for the render functions. The render() function returns a handle that can be used with the PHP image functions for further processing if required. The renderImage() allows the output to be returned directly or saved to a file.

If the width is specified, the resultant image will be constraint to that width and text will be wrapped around and split into lines as appropriate. Specify either "gif", "png" or "jpg" for the class to save the rendered output. If the filename is omitted, then it will return the output directly.

The class will accept any HTML/CSS color specification (i.e. "#FFF000", "red", "rgb(127, 127, 127)") as a valid color for use as text color, background color and shadow color. You can also specify alpha values to accompany them in order to have transparency effects. Set the background alpha to 127 to produce text on a transparent background.

All fonts have to be placed in the font path directory and should be named, in lower case, exactly as the font names passed to the class.

Examples


Saving to a file:
This example shows how to render the text and save the output. It sets all the properties for font, background and shadows at object initialization. The renderImage() function has the filename and filetype specified for saving the rendered output.
<?php
// Load the class
include('thaanaTextRender.php');

// Initialize object
$ttr = new ThaanaTextRender('./fonts/', 'a_waheed', 20, 'white', 0, 50, 'rgb(0,0,0)', 0, 2, '#555555', 80);

// Render image and save output
$ttr->renderImage('swaincsc', 300, 'output.png', 'png');


Output directly to browser:
This example is ideal for use in scripts that dynamically generate the required rendering and return the output directly to the browser.
<?php
// Load the class
include('thaanaTextRender.php');

// Initialize object
$ttr = new ThaanaTextRender('./fonts/', 'a_waheed', 16, 'white', 0, 50, 'rgb(0,0,0)', 127);

// Render image and save output
$ttr->renderImage('gUgulunc aepwlc awaimUvIaW vWdwkurW kwhwlw aeve. gUgulc aencDcroaiDc fOnutwkwSc mihWru vwnI mUvI scTUDiaOaeac dIfw aeve.', 300, NULL, 'png');


You could use it by, for example, calling it via the image tag.
<img src="script.php" />


Demo

You can check out the original demo I posted to see it in action.

For a real-world application of the class, check out the Muraasil mobile site which has been making good use of it for almost 2 years now.

License

This script is released under the Open Source MIT License, allowing its use in both personal and commercial applications as long as the copyright and license permission notice remains intact.

Download

- ThaanaTextRender.zip (v1.0, 4.43KB)

Enjoy!

Page to Unicode Thaana 1.0

Here's a nifty little tool I made a few years ago that automatically and intelligently picks out the bits of text that use a non-Unicode Thaana font on any web page and converts it to Unicode. That probably doesn't make much sense to most of you but read on - there's a section for general web users and one for developers.

General users


Take the website of Haveeru Daily as an example. It uses a now-archaic method of displaying Thaana. Browsers cannot and will not substitute an alternative workable font if your computer does not have the exact Thaana fonts it requires and will display as non-sensical English text. But then take Miadhu Daily, which relies on something called Unicode. Browsers can and will load up the site perfectly readable as long as you have any one of the many Unicode Thaana fonts on your system. And in many situations, like at public libraries or on some phones and devices like the Kindle, Unicode-based Thaana web pages will load up just fine as there usually is some Thaana-supporting Unicode font on it while those that use the more archaic method will fail.

I came across this problem a few years ago while at the university lab one day and there was some interesting events taking place in the Maldives which I wanted to read about. Haveeru had the most news articles and was the most up-to-date but I couldn't read any of it as the Thaana fonts were not on the system and I was not allowed to install the fonts. So I wrote some quick code, specifically a bookmarklet, that converted the text on the site on-the-fly to use Unicode.

Anyway, if you find yourself in a similar situation, here is what you could do. Right click the PUT bookmarklet link below and choose to bookmark the link. When on a page, just click the PUT bookmark and the page should convert to Unicode and display Thaana.

Page to Unicode Thaana bookmarklet v1.0

Demo

Haveeru before


Haveeru after


Developers


Here's a slightly different version of the above script that can be used on web pages that do not use Unicode Thaana to offer the pages in Unicode without requiring any change to the content management system, editor etc that you have in place already. Add the script to your non-Unicode Thaana based web pages where appropriate and your visitors will get a Unicode-based web page as long they have Javascript enabled.

Usage
I would recommend that it be added towards the end of your page HTML, right before the closing BODY tag.



Download:
- put-1.0.min.js (minified, for production use)
- put-1.0.js (full source)

Enjoy :-)

Thaana on Android: Font installation

I have owned a Google Nexus One device since it came out early this year and I love it for the great hardware specifications of the phone and the customizability of Android. As usual, one of the first things I did when I got it was to explore Thaana usage on the Android OS. I have been meaning to do a write up since, so after almost a year here it is finally! This post addresses getting Thaana to display by installing a Thaana font.

Overview


With a healthy ecosystem of phones and tablets running Android now available, the free and open-source Android mobile operating system seem to be getting more and more popular across the world and in Maldives. Its official app-store hosts a large number of applications, a lot of which are free, and there are a number of third-party app-stores with more relaxed rules around as well. There is a healthy and growing developer community that's taking advantage of the open code to add new features and hack in interesting modifications - like the Nexus One does not officially have a FM radio or support HD video but developers have added code hacks for both into a custom ROM!

As awesome as Android is, unfortunately, all versions of the official Android OS (including the latest version 2.2 (Froyo) release) has limited support for international scripts, which is bad news for Thaana. Android can display Thaana characters as it supports Unicode fonts but it looks all jumbled up when diplayed as Android lacks support for bi-directional text rendering, both in the OS and the included web browser. The lack of BiDi support means Thaana input is also impossible as Thaana is a right-to-left script.

The next version of Android, version 2.3 (Gingerbread), is scheduled to have BiDi support and better support for international scripts, so hopefully that fixes things although it still wouldn't officially support Thaana.

The only easy way currently, as far as I am aware of, of viewing Thaana on Android correctly is by using Opera Mobile browser with Thaana fonts installed in Android. Now, none of the Android-based devices on the market seem to ship with a Thaana-supporting Unicode font preinstalled and Android does not currently provide a mechanism for user installation of fonts which means the process of installing a Thaana font is a little bit convoluted.

Installing Thaana fonts


Next, you need to install the Thaana font. Chopey has already posted a guide on how to do it manually and Gaanagaa has posted a Windows-based software to do automatically for you. I favour a different approach which relies on using a special Zip file to update your Android with the Thaana fonts in a manner similar to how Android devices update themselves with new releases. This method is, in my opinion, a lot easier and you do not need anything other than a rooted phone and the zip file I have prepared to do it. I have packaged the free FreeSerif font which includes beautiful Thaana glyphs as well as a large number of other characters from other writing systems.

Using my Thaana fonts update for Android
1. Make sure your device is rooted. You will need a rooted device to install any font via any method, including this one. There are a number of guides and free software available on the web for various Android phones (try xda-developers.com or modaco.com or samdroid.net) to help you do just that.

2. Put update_thaanafonts(jaa)_signed.zip to the root of the SD card in your device. You can do this by downloading the file straight from the web on to the SD card of your device OR download the file to your computer first and copy it to your device using a cable or Bluetooth.

3. Power off your phone and boot into recovery mode. The specifics of how you do this depends on which recovery tool was installed during rooting of your phone but involves pressing some combination of keys at the same time to start your device in recovery mode. Try the methods listed here if you aren't sure.

4. Select the update from Zip option in your recovery tool and select the update_thaanafonts(jaa)_signed.zip file from the list and OK it.

5. The update should progress and will ask you to reboot once completed.

6. Congratulations you now have a Thaana font installed! To make any practical use of it, you will need to install the Opera Mobile browser application available for free on the Android Market.



Enjoy :-)

Thaana on Amazon Kindle

I tinkered with the Amazon Kindle ebook reader device a few nights back and explored the use of Thaana on it. Here are my findings.

Overview


The Kindle is an amazing product - the screen is extremely easy on the eyes, the device is light and comfortable to handle and the battery lasts for a few weeks without a charge. The software supports MOBI, PRC, TXT, TPZ, AAX and PDF format books and documents and also includes a web browser.

Kindle 2 devices do not come with any Thaana Unicode fonts bundled in, hence making it impossible to view Thaana documents on a vanilla device. Kindle 3 does come with the impressive Code2000 Unicode font bundled in. This is good news for Thaana support as Code2000 currently contains over 61,000 glyphs from a huge range of writing systems and has supported Thaana for what must be close to a decade. However, the use of Code2000 seems to be limited to the web browser and is not involved in rendering ebooks.

It is possible to use either of the Kindle font hacks (see "Adding a Thaana font" below) to replace the system's ebook reader font to get Thaana to display within the reader component for all of the supported ebook formats. But this turns out to be pointless as neither device has proper support for handling right-to-left scripts like Thaana and hence words and paragraphs are all jumbled up in reverse.

Kindle screenshot: No Thaana characters in a vanilla device
Kindle screenshot: No Thaana characters in a vanilla device

Kindle screenshot: Thaana characters display after hack
Kindle screenshot: Thaana characters display after hack


PDF with font-embedding: The only thing that works!


The only ebook format that worked for Thaana was PDF with font-embedding (PDFs without the fonts embedded fails to render Thaana correctly even when the device was loaded with a Thaana Unicode font). Many of the existing Thaana PDF documents work just fine (see the screenshots below) as most of them have the required Thaana fonts embedded.

Kindle screenshot: PDF with Thaana fonts embedded
Kindle screenshot: PDF with Thaana fonts embedded

Kindle screenshot: Thaana Quran translation PDF
Kindle screenshot: Thaana Quran translation PDF.


Thaana in the browser


Thaana viewing via the WebKit-based web browser in Kindle was flawless in websites using Unicode Thaana (hence Haveeru Daily website is excluded). Code2000 has decent Thaana glyphs and looks very much readable on the device.

Kindle screenshot: Muraasil.com on Kindle
Kindle screenshot: Muraasil.com on Kindle


Unlike desktop systems, there is no native option to switch to a Thaana keyboard but because Javascript works, Thaana entry on websites using my Javascript Thaana Keyboard handler works just fine.

Kindle screenshot: Thaana entry using JTK
Kindle screenshot: Thaana entry using JTK


Adding a Thaana font


There are two ways of loading a Kindle with a Thaana font, though it is quite pointless for ebook reading purposes due to the reasons above. The rooted device method can be used to replace Code2000 with a font of your liking within the browser but keep in mind that Kindle will use the same font for the glyphs for English, numbers and puncuation and hence the font should be easy on the eye. In my opinion, this rules out most of the existing Thaana fonts, especially the common ones such as Faruma and the MV series of Thaana Unicode fonts. The best font I could find was the opensourced GNU Freefont which has very nice English glyphs and also includes the Thaana glyphs from Mohamed Ishan's Thaana Unicode Akeh font.

Rooted device + font replacement method
This method makes permanent changes to the Kindle and requires that you root your Kindle through a very simple procedure and install an associated custom fonts hack. The details are available here.

User fonts method
This method only works for Kindle 3 devices and does not require rooting the device and makes temporary changes to the Kindle by enabling a hidden user font mode in the device. The changes persist as long as you do not alter the font-face settings on the Kindle. Details on how to do this are available here.

Creating Thaana ebooks


For now, the only method for getting Thaana to work on Kindle devices seem to be via font-embedding in PDF documents. The easiest, and perhaps the most cost effective, method of producing such documents would be to prepare the document using your choice of document editor (like MS Word or OpenOffice) and printing out the document to the virtual printer provided by print-to-PDF software such as the free PDFCreator applications.

How-to for Windows:
1. Download and install the PDFCreator application.
2. Go to the print function in whichever software you are using and select the PDFCreator virual printer.



3. When the PDFCreator print window comes up, click the "Options" button.



4. On the PDFCreator print options window that comes up. Select "PDF" under "Formats" from the left, switch the "Fonts" tab and make sure "Embed all fonts" is ticked. Customise the "Subset font..." option if you would like and click "Save".


5. You only need to set font embedding as above once and the program will use it in future prints. When you are back at the print screen, set the Document title and other details as you please and click "Save".

To ensure that the PDF you saved (or any other PDF that you may have) has the Thaana fonts embedded, load it up your favourite PDF viewer software and check the document properties.



Conclusion?


Thaana on Kindle is very limited for now. The only option to produce and read Thaana ebooks is using the PDF ebook format with the Thaana fonts embedded in the PDF. This does mean that Kindle devices can be used to read Thaana without rooting or any hacks. Thaana usage on the web browser in Kindle matches that of a mobile device or even a desktop or laptop computer.

Toodles.