Used the following, sort of from user guide section 3.5, but the new
font doesn't show up in the list, and although this sample doesn't
produce an error from the setFont, when I embed in a larger program,
sometimes it does... after the print !?
But the issue is how can I add a TT font and get it registered, and show
up in the list?
#!c:\python26\python.exe
# -*- coding: utf-8 -*-
import sys, os, re, getopt
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import LETTER, A4, LEGAL, ELEVENSEVENTEEN
from reportlab.lib.units import cm, mm, inch, pica
def list_available_fonts():
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Times-New-Roman',
'c:\\windows\\fonts\\times.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBd',
'c:\\windows\\fonts\\timesBd.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanIt',
'c:\\windows\\fonts\\timesI.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBI',
'c:\\windows\\fonts\\timesBI.ttf'))
pdf = Canvas(sys.stdout)
pdf.setFont('Times-New-Roman', 16)
all_fonts = pdf.getAvailableFonts()
print all_fonts
list_available_fonts()
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users
The getAvailableFonts is actually wrong and is being stupid. It turns out that
it defers to PdfDoc.getAvailableFonts which is also stupid and wrong. Both of
these ought to be named something like getUsedFonts or getActualizedFonts or
somesuch. Turns out that except for the standard 14 we don't internalize the
fonts until they're actually used.
Try the script below and you should actually see the font end up in the list. I
think availableFonts should refer to those that have been registered even if not
yet used.
import sys, os, re, getopt
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import LETTER, A4, LEGAL, ELEVENSEVENTEEN
from reportlab.lib.units import cm, mm, inch, pica
def list_available_fonts():
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Times-New-Roman', 'c:\\windows\\fonts\\times.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBd',
'c:\\windows\\fonts\\timesBd.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanIt',
'c:\\windows\\fonts\\timesI.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBI',
'c:\\windows\\fonts\\timesBI.ttf'))
pdf = Canvas(sys.stdout)
pdf.setFont('Times-New-Roman', 16)
pdf.drawString(72,72,'Hello World')
all_fonts = pdf.getAvailableFonts()
print all_fonts
list_available_fonts()
--
Robin Becker
The getAvailableFonts is actually wrong and is being stupid. It turns out that it defers to PdfDoc.getAvailableFonts which is also stupid and wrong. Both of these ought to be named something like getUsedFonts or getActualizedFonts or somesuch. Turns out that except for the standard 14 we don't internalize the fonts until they're actually used.
Try the script below and you should actually see the font end up in the list. I think availableFonts should refer to those that have been registered even if not yet used.