[Bf-python] Width of Blender fonts

Manuel manuelbastioni at tin.it
Thu Jun 26 01:15:11 CEST 2003


I think this can be little OT...excuse me, but in other
place I don't find any solution.

In makehuman, I must use this function to get the width of fonts.
All values is determinate empirically, there are some erros, and
the code is really not elegant :-(

Exist an alternative to get the width values from API?

thx,

         Manuel

THE CODE 

def getLenght(string): 
 
 # Simple function to calculate the exact lenght of a string
 # using the default Blender 2.26 font. Thx Theeth. I'm not sure 
 # about the caps letter width.

 len = 0 
 LW = {"a":7, "b":7, "c":7, "d":7, "e":7, "f":3, \
   "g":7, "h":7, "i":3, "j":3, "k":6, "l":3, \
   "m":9, "n":7, "o":7, "p":7, "q":7, "r":4, \
   "s":6, "t":3, "u":7, "v":7, "w":9, "x":6, \
   "y":7, "z":6, "A":9, "B":8, "C":9, "D":9, \
   "E":8, "F":8, "G":9, "H":9, "I":3, "J":7, \
   "K":9, "L":7, "M":11,"N":9, "O":10, "P":8, \
   "Q":10, "R":8, "S":8, "T":7, "U":8, "V":9, \
   "W":11,"X":9, "Y":9, "Z":9, "0":7, "1":7, \
   "2":7, "3":7, "4":7, "5":7, "6":7, "7":7, \
   "8":7, "9":7, " ":3, "!":3, "?":6, "(":4, \
   ")":4, "\\":4,"/":4, "'":3, ":":3, ";":4, \
   "|":3, ">":7, "<":7, ".":3, ",":4, "*":8, \
   "-":8, "+":8, "=":8, "@":13,"#":10,"$":9, \
   "%":12,"^":7, "&":11,"~":8, "`":5, "_":8, \
   "{":5, "}":5, "":0, "\t":16 } 
 for s in string: 
  try: 
   len += LW[s] 
  except: 
   print "missing: ", repr(s) 
 return len 




More information about the Bf-python mailing list