Posts Categorized: Programming

TCPDF Does not Support Indic scripts

The other day I ran across an interesting question on Stack Overflow regarding the use of indic fonts with TCPDF.  Languages like Tamil and Malayalam fall into this category. [How can I create Malayalam PDF using TCPDF in PHP?] At first I thought it was just a simple font issue, but that was not the case.  Even with font subsetting off, and trying a number of different Malayalam capable fonts, I was having the same problem the question asker was facing. I began googling for information regarding Malayalam and TCPDF, but to no avail.  I found out that Tamil was a related script, so I did searches on that and the outlook was not good regarding proper rendering in TCPDF.

Finally after switching my google queries to specifically search for information about indic script support in TCPDF, I found this comment by a person called “Santhosh” regarding TCPDF’s lack of indic script support:

It is technical limitation. For TCPDF, the true type font need to be converted to afm format first, then for each script, the diacritics or ligature rules are implemented in tcpdf itself. That is what done for adding Arabic/Persian support. For complex scripts this is not a correct approach. Indic shaping engines like Pango has evolved by taking about 10 years. The shaping logic is very complex and duplicating it inside a PDF library is wrong approach. Instead the PDF library should depend on Pango or the upcoming Harfbuzz rendering engines. The PDF export library in Mediawiki uses reportlab pdf library. That also attempts to the rendering by itself. And ended up in having no support for any Indic languages and many bugs for Arabic scripts(Note that this extension is disabled in many Indian wikiprojects). Fonts are not enough for rendering, a shaping engine is also required for complex script to interpret the glyph formation rules. This is what PyPDFLib is trying to solve by using Pango for script rendering and Cairo for graphics.

I’m happy to have come across his posts as I might’ve banged my head against a wall trying to answer this Stack Overflow question for a while.  I don’t know anything about these languages so I don’t think I could have answered the question as quickly or as thoroughly as I did if it weren’t for finding this.

You can read the full blog post and comment thread here: Creating a new Language ecosystem- Sourashtra as example

Laziness

  1. If a task can be automated and done better by a robot. It should. Humans should not perform such tasks.
  2. If making the robot is harder than the task, only make the robot if saved energy over time is greater than doing the task.
  3. If the task is useless, pursue it only if it enables happiness.
  4. Useless tasks that do not promote happiness are scourge and should be eliminated forthright.

Beating FFXIII was clearly category 4.

Rounded Corner Script

Script Download: rounded_corner.sh (v2)

Ever wanted a script that would round the corners of images for you?  Well, if you said yes, I wrote myself a bash script to do just that.  As of this post it can do the following: round of corners of images and it can also add a glass-bubble effect as described in the ImageMagick tutorials.  You can specify the border radius and a background color, which is handy if you are making JPEGs.  The script’s help screen is shown below, as well as a couple of samples.  Radius sizes are in pixels.

./rounded_corner.sh <inputfile> <outputfile> [options]
  -m   Method [plain or glass-bubble]
  -r   Corner Radius
  -b   Background Color
Method can be plain or glass-bubble at the moment. (default: plain)
Radius specifies the radius of the rounded corners. (default: 15)

Note: This should be able to function as filter command, so if you wanted
rounded thumbnails of a particular size you can:
convert <bigfile> -resize 200x200 png:- | ./rounded_corner.sh png:- smallrounded.png" 1>&2

Programmers should strive to Expand their Knowledge Bases

With a title like “Programmers should strive to Expand their Knowledge Bases” you’d think I was referring to things like OOP, DRY, and other acronyms. However, I am not.  I’m not referring to learning additional programming languages or algorithms.  I’m talking about learning things from other domains entirely.  For example: science, knitting, cat photography, cat photograph captioning and so on.  Honestly it’s a little bit of a weak point for me as well.  My grammar is a sore example.  Of course, I’m a mediocre-self-taught-programmer, so that is to be expected anyway.  First off there’s knowledge you can apply directly to programming problems.

Having knowledge about other fields allows you to more readily solve programming problems that involve those fields.  There’s even a term for this: domain knowledge or domain-specific knowledge.  You don’t necessarily need to be an expert either.  For example, with a base level of knowledge it become easier to get input from experts in a particular domain This is because you already have a base understanding.  There are two less-obvious benefits though, and I think they are more important.

First, having a broad base of knowledge to pull from enhances problem solving skills. I don’t have solid numbers to back this statement up though. (This is a blog, not a peer-reviewed paper.) Usually, when confronted with a problem in different domains the manner in which you come to a solution differs based on the domain at hand.  More specifically: you think differently.  Being able to solve problems in programming often requires you to shift your way of thinking and having more experience approaching problems from different angles can be very beneficial.  It can even apply to learning new programming paradigms.  I didn’t fully grasp OOP until I considered things in terms of chemistry.

Second, having a broad knowledge base can make it easier to communicate with people of different backgrounds.  Much like dealing with experts above, but often a little more general.  This is also somewhat tied to the problem solving mentioned previously.  When you can shift thinking readily, it becomes far easier to think like the person you are communicating with and explain things with terms or analogies that that person can understand.  As a personal example of this: I’ve explained the Linux boot process almost entirely with car analogies to a car guy.  I’m pretty certain that had i never taken auto shop, this would have been impossible.

tl;dr version: Learn stuff. It makes you a better problem solver and communicator.  Soft skills for the win.

Zombinanza 2 now in progress

It was mentioned that a sequel to Zombinanza has long been missing, and as a consequence Zombinanza 2 shall be attempted to be started to be made. Harass me if it doesn’t.

Using Python to create command line tools

Was directed to a nifty tutorial regarding Python’s optparse, and how to use it to quickly create handy command-line utilities.   Saves you the trouble of ever having to parse the command line.  Check it out on IBM’s website: http://www.ibm.com/developerworks/aix/library/au-pythocli/

Summary taken from the article:

Summary: If you work in IT, as a UNIX® Sysadmin, a software developer, or even a manager, there a few skills that will set you apart from the crowd. Do you fully understand the OSI model? Are you comfortable with subnetting? Do you understand UNIX permissions? Let me add to this list the humble command line tool. By the end of this article, anyone involved in IT at any capacity should be able to create at least a simple command line tool.