Load Fonts Demo(Win2k or later)

Hi,

This script is a Load Font demo for Blender 2.4 or later.
It uses Win32API to get registerd font list by Windows .

[How to use]
1.Copy this script , and save to a file.
2.Open Blender.exe
3.Load script On Text Wondow
4.Push [ALT-P] and Wait…

# 
# Font Loading Sample For Windows 2000/XP/Vista
#    [Blender pyton] 2.40 or later
#    2007.11.24 namda


import sys
import os
import Blender 
from Blender import Curve, Object, Scene, Text3d , Text

try:
  import _winreg
except:
  print "Does it support Win32API?" 
  exit()

#Retry count
# for _winreg ( accessing non-ascii code name)
RETRYMAX=20

# Object Name
DEFAULTTXTNAME="TTxt"
DEFAULTOBJNAME="Text"

FONTDIR = "FONTS"

if os.sys.platform == 'win32' and \
   os.sys.getwindowsversion()[0] >= 5:
   print "Your OS is Windows 2000 or Later"
   
fontdir = os.environ['SystemRoot'] + "\\FONTS\\"

reg_fonts = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts")
# list values owned by this registry key

flist = []

###
#

i = -1
r = 0
while 1:
  try:
    i = i + 1
    name, value, type = _winreg.EnumValue(reg_fonts, i)
  except OSError,e:
    r= r + 1
    #print "***E*R*R*O*R***"e.errno,r,i
    if r < RETRYMAX :
       continue
    else:
       break

  print repr(name),repr(value)
  flist.append((name,value))


###
#

cnt = 1
for x in flist :
  name, value = x
  if(value[-4:] == ".ttf" or value[-4:] == ".ttc" or \
     value[-4:] == ".TTF" or value[-4:] == ".TTC" ):
    if os.path.exists(value):
      fontpath = value
    else:
	  fontpath = fontdir + value

    txt = Text3d.New(DEFAULTTXTNAME)
    cur = Scene.GetCurrent()
    obj = Object.New(DEFAULTOBJNAME)
    obj.link(txt)
    cur.link(obj)
    obj.setLocation((0,-cnt,0))

    #txt.setText(name)
    txt.setText(unicode(name,encoding = sys.stdout.encoding))

    print fontpath
    font = Text3d.LoadFont(fontpath)
    txt.setFont(font)
    cnt = cnt + 1


obj.makeDisplayList()

Blender.Redraw()

BTW, Do you know how to get ‘registerd’ fonts on X11 or Mac OS X ?

Thanks.