Comment 7 for bug 1001033

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

I am using the fixed-width length of a character in pixels, to decide where to draw the cursor in an input box. This makes it very easy to quickly see if there are any discrepancies, with only 1 pixel difference between characters as shown below, the cursor can visibly move to the wrong place after only a couple of characters entered into the input box. On all other mono-spaced fonts, this effect does not happen, the cursor renders correctly in the gap between two characters.

I have also confirmed this by printing out some of the sizes of characters and of strings of characters. In all other mono-spaced fonts, all characters have the same length, such as 10 pixels when rendered. And, if 3 different characters are rendered, it will always be 30 pixels wide (for a 10 pixel font). This means I can place the cursor at multiples of 10 pixels (or whatever) and have it always render in the correct place.

I've just got round to getting those lengths for you, using the below code.

lengths = {}
for c in string.letters + string.digits:
    lengths[c] = mono_font.render(c, False, (0,0,0)).get_size()[0]
print lengths

Result:
{'1': 10, '0': 10, '3': 10, '2': 10, '5': 10, '4': 10, '7': 10, '6': 10, '9': 10, '8': 10, 'A': 10, 'C': 10, 'B': 10, 'E': 10, 'D': 10, 'G': 10, 'F': 10, 'I': 9, 'H': 10, 'K': 10, 'J': 9, 'M': 10, 'L': 10, 'O': 10, 'N': 10, 'Q': 10, 'P': 9, 'S': 9, 'R': 10, 'U': 9, 'T': 9, 'W': 10, 'V': 10, 'Y': 9, 'X': 10, 'Z': 10, 'a': 10, 'c': 10, 'b': 10, 'e': 9, 'd': 10, 'g': 10, 'f': 10, 'i': 9, 'h': 10, 'k': 10, 'j': 10, 'm': 9, 'l': 9, 'o': 10, 'n': 10, 'q': 10, 'p': 10, 's': 11, 'r': 10, 'u': 10, 't': 10, 'w': 10, 'v': 10, 'y': 10, 'x': 10, 'z': 10}

As you can see, there's seems to be an inconsistent switch between 9 and 10 pixels wide, while 's' is even 11 pixels wide.

With all other mono-spaced fonts, all characters return the same size, for example with Ubuntu Mono all characters are 8 pixels, Droid Sans Mono is all 10 pixels and Liberation Mono is also all 10 pixels.

I'll ask on the mailing list again to see if any of the developers can add any information.