AcademySoftwareFoundation / OpenImageIO

Reading, writing, and processing images in a wide variety of file formats, using a format-agnostic API, aimed at VFX applications.
https://openimageio.readthedocs.org
Apache License 2.0
1.98k stars 598 forks source link

ImageBufAlgo.render_text error: Could not set font face to "cour" #851

Closed Narann closed 10 years ago

Narann commented 10 years ago

Hello Larry,

I'm currently using OIIO 1.4 Python Binding and get a weird error:

>>> import OpenImageIO
>>> buf = OpenImageIO.ImageBuf(OpenImageIO.ImageSpec(640, 480, 3, OpenImageIO.TypeDesc.TypeFloat))
>>> buf.reset(OpenImageIO.ImageSpec(640, 480, 3, OpenImageIO.TypeDesc.TypeFloat))
>>> OpenImageIO.ImageBufAlgo.fill(buf, (1,0,0), OpenImageIO.ROI(50, 100, 75, 85))
True
>>> OpenImageIO.ImageBufAlgo.render_text(buf, 0, 0, "test")
False #problem?
>>> buf.geterror()
'Could not set font face to "cour"'

This work if fontname is a direct path (the word "fontname" took me time to realize it could be a path, even if I just realize it was written in the documentation).

Reading the OIIO code, it try to get a path for the default font. This logic doesn't seems to work on my current system (Centos 6.5), don't know why.

Can I suggest to improve the error message at the moment it doesn't succeed to find the font path instead of trying to put something that you know will fail. This could save time to the user to realize it could be easier to give a direct font path instead of trying to provide font name (I say this for me of course).

For example here:

Replace:

if (! f.empty())
    font = f;

To:

if (f.empty())
    R.error ("Could not find path for given fontname \"%s\"", font);
    return false;  // couldn't find the font path
font = f;

Or something like this. Is there any reason where "f" could empty but font is still a valid path?

FYI through. Anyway, thanks a lot for OIIO, it save us a lot of time! :)

lgritz commented 10 years ago

Can you please tell me the result of this:

ls /usr/share/fonts/*
Narann commented 10 years ago
/usr/share/fonts/abyssinica:
Abyssinica_SIL.ttf

/usr/share/fonts/bitstream-vera:
VeraBd.ttf
VeraBI.ttf
VeraIt.ttf
VeraMoBd.ttf
VeraMoBI.ttf
VeraMoIt.ttf
VeraMono.ttf
VeraSeBd.ttf
VeraSe.ttf
Vera.ttf

/usr/share/fonts/cjkuni-uming:
fonts.dir
fonts.scale
uming.ttc

/usr/share/fonts/default:
ghostscript
Type1

/usr/share/fonts/dejavu:
DejaVuSans-BoldOblique.ttf
DejaVuSans-Bold.ttf
DejaVuSansCondensed-BoldOblique.ttf
DejaVuSansCondensed-Bold.ttf
DejaVuSansCondensed-Oblique.ttf
DejaVuSansCondensed.ttf
DejaVuSans-ExtraLight.ttf
DejaVuSansMono-BoldOblique.ttf
DejaVuSansMono-Bold.ttf
DejaVuSansMono-Oblique.ttf
DejaVuSansMono.ttf
DejaVuSans-Oblique.ttf
DejaVuSans.ttf
DejaVuSerif-BoldItalic.ttf
DejaVuSerif-Bold.ttf
DejaVuSerifCondensed-BoldItalic.ttf
DejaVuSerifCondensed-Bold.ttf
DejaVuSerifCondensed-Italic.ttf
DejaVuSerifCondensed.ttf
DejaVuSerif-Italic.ttf
DejaVuSerif.ttf

/usr/share/fonts/jomolhari:
Jomolhari-alpha3c-0605331.ttf

/usr/share/fonts/khmeros:
KhmerOS_content.ttf
KhmerOS_sys.ttf
KhmerOS.ttf

/usr/share/fonts/kurdit-unikurd-web:
Unikuweb.ttf

/usr/share/fonts/liberation:
fonts.dir
fonts.scale
LiberationMono-BoldItalic.ttf
LiberationMono-Bold.ttf
LiberationMono-Italic.ttf
LiberationMono-Regular.ttf
LiberationSans-BoldItalic.ttf
LiberationSans-Bold.ttf
LiberationSans-Italic.ttf
LiberationSans-Regular.ttf
LiberationSerif-BoldItalic.ttf
LiberationSerif-Bold.ttf
LiberationSerif-Italic.ttf
LiberationSerif-Regular.ttf

/usr/share/fonts/lklug:
lklug.ttf

/usr/share/fonts/lohit-assamese:
Lohit-Assamese.ttf

/usr/share/fonts/lohit-bengali:
Lohit-Bengali.ttf

/usr/share/fonts/lohit-devanagari:
Lohit-Devanagari.ttf

/usr/share/fonts/lohit-gujarati:
Lohit-Gujarati.ttf

/usr/share/fonts/lohit-kannada:
Lohit-Kannada.ttf

/usr/share/fonts/lohit-oriya:
Lohit-Oriya.ttf

/usr/share/fonts/lohit-punjabi:
Lohit-Punjabi.ttf

/usr/share/fonts/lohit-tamil:
Lohit-Tamil.ttf

/usr/share/fonts/lohit-telugu:
Lohit-Telugu.ttf

/usr/share/fonts/madan:
madan.ttf

/usr/share/fonts/opensymbol:
opens___.ttf

/usr/share/fonts/paktype:
PakTypeNaqsh.ttf
PakTypeTehreer.ttf

/usr/share/fonts/sil-padauk:
Padauk-Bold.ttf
Padauk.ttf

/usr/share/fonts/smc:
Meera.ttf

/usr/share/fonts/stix:
STIXGeneralBolIta.otf
STIXGeneralBol.otf
STIXGeneralItalic.otf
STIXGeneral.otf

/usr/share/fonts/thai-scalable:
Waree-BoldOblique.ttf
Waree-Bold.ttf
Waree-Oblique.ttf
Waree.ttf

/usr/share/fonts/tibetan-machine-uni:
TibMachUni-1.901b.ttf

/usr/share/fonts/un-core:
UnDotumBold.ttf
UnDotum.ttf

/usr/share/fonts/vlgothic:
VL-Gothic-Regular.ttf

/usr/share/fonts/wqy-zenhei:
wqy-zenhei.ttc

Hope this help.

Narann commented 10 years ago

Weird, I couldn't simply click on "Comment" but only "Comment & Close".

Sorry for noise.

lgritz commented 10 years ago

Sorry, one more:

ls /usr/share/fonts/default/*

or, alternately,

ls -R /usr/share/fonts
Narann commented 10 years ago

You're welcome!

$ ls /usr/share/fonts/default/*
/usr/share/fonts/default/ghostscript:
bchb.afm   bchri.pfa  fhirw.gsf    hrgerb.gsf  hrgrrb.gsf  hrpldb.gsf   hrplr.gsf    hrpltb.gsf   hrscc.pfa   putb.pfa      u004006t.afm
bchbi.afm  bchr.pfa   fhirw.pfm    hrgerd.gsf  hrgrro.gsf  hrpldbi.gsf  hrplro.gsf   hrpltbi.gsf  hrscsb.gsf  putri.pfa     u004006t.gsf
bchbi.pfa  fcyr.afm   fkarw.gsf    hrgero.gsf  hrgrr.pfa   hrpldi.pfa   hrplsb.gsf   hrplti.pfa   hrscso.gsf  putr.pfa      u004006t.pfm
bchb.pfa   fcyr.gsf   fkarw.pfm    hrger.pfa   hritrb.gsf  hrpld.pfa    hrplsbo.gsf  hrplt.pfa    hrscs.pfa   u003043t.afm
bchr.afm   fcyri.afm  fonts.dir    hrgkc.gsf   hritro.gsf  hrplrb.gsf   hrpls.gsf    hrsccb.gsf   hrsyr.gsf   u003043t.gsf
bchri.afm  fcyri.gsf  fonts.scale  hrgks.gsf   hritr.pfa   hrplrbo.gsf  hrplso.gsf   hrscco.gsf   putbi.pfa   u003043t.pfm

/usr/share/fonts/default/Type1:
a010013l.afm  b018012l.afm  c059013l.afm  d050000l.afm  n019023l.afm  n019063l.afm  n021023l.afm  n022023l.afm  p052023l.afm
a010013l.pfb  b018012l.pfb  c059013l.pfb  d050000l.pfb  n019023l.pfb  n019063l.pfb  n021023l.pfb  n022023l.pfb  p052023l.pfb
a010015l.afm  b018015l.afm  c059016l.afm  fonts.dir     n019024l.afm  n019064l.afm  n021024l.afm  n022024l.afm  p052024l.afm
a010015l.pfb  b018015l.pfb  c059016l.pfb  fonts.scale   n019024l.pfb  n019064l.pfb  n021024l.pfb  n022024l.pfb  p052024l.pfb
a010033l.afm  b018032l.afm  c059033l.afm  n019003l.afm  n019043l.afm  n021003l.afm  n022003l.afm  p052003l.afm  s050000l.afm
a010033l.pfb  b018032l.pfb  c059033l.pfb  n019003l.pfb  n019043l.pfb  n021003l.pfb  n022003l.pfb  p052003l.pfb  s050000l.pfb
a010035l.afm  b018035l.afm  c059036l.afm  n019004l.afm  n019044l.afm  n021004l.afm  n022004l.afm  p052004l.afm  z003034l.afm
a010035l.pfb  b018035l.pfb  c059036l.pfb  n019004l.pfb  n019044l.pfb  n021004l.pfb  n022004l.pfb  p052004l.pfb  z003034l.pfb

And:

$ ls -R /usr/share/fonts
/usr/share/fonts:
abyssinica      default    kurdit-unikurd-web  lohit-bengali     lohit-oriya    madan       smc                  un-core
bitstream-vera  dejavu     liberation          lohit-devanagari  lohit-punjabi  opensymbol  stix                 vlgothic
cjkuni-uming    jomolhari  lklug               lohit-gujarati    lohit-tamil    paktype     thai-scalable        wqy-zenhei
dd              khmeros    lohit-assamese      lohit-kannada     lohit-telugu   sil-padauk  tibetan-machine-uni

/usr/share/fonts/abyssinica:
Abyssinica_SIL.ttf

/usr/share/fonts/bitstream-vera:
VeraBd.ttf  VeraBI.ttf  VeraIt.ttf  VeraMoBd.ttf  VeraMoBI.ttf  VeraMoIt.ttf  VeraMono.ttf  VeraSeBd.ttf  VeraSe.ttf  Vera.ttf

/usr/share/fonts/cjkuni-uming:
fonts.dir  fonts.scale  uming.ttc

/usr/share/fonts/default:
ghostscript  Type1

/usr/share/fonts/default/ghostscript:
bchb.afm   bchri.pfa  fhirw.gsf    hrgerb.gsf  hrgrrb.gsf  hrpldb.gsf   hrplr.gsf    hrpltb.gsf   hrscc.pfa   putb.pfa      u004006t.afm
bchbi.afm  bchr.pfa   fhirw.pfm    hrgerd.gsf  hrgrro.gsf  hrpldbi.gsf  hrplro.gsf   hrpltbi.gsf  hrscsb.gsf  putri.pfa     u004006t.gsf
bchbi.pfa  fcyr.afm   fkarw.gsf    hrgero.gsf  hrgrr.pfa   hrpldi.pfa   hrplsb.gsf   hrplti.pfa   hrscso.gsf  putr.pfa      u004006t.pfm
bchb.pfa   fcyr.gsf   fkarw.pfm    hrger.pfa   hritrb.gsf  hrpld.pfa    hrplsbo.gsf  hrplt.pfa    hrscs.pfa   u003043t.afm
bchr.afm   fcyri.afm  fonts.dir    hrgkc.gsf   hritro.gsf  hrplrb.gsf   hrpls.gsf    hrsccb.gsf   hrsyr.gsf   u003043t.gsf
bchri.afm  fcyri.gsf  fonts.scale  hrgks.gsf   hritr.pfa   hrplrbo.gsf  hrplso.gsf   hrscco.gsf   putbi.pfa   u003043t.pfm

/usr/share/fonts/default/Type1:
a010013l.afm  b018012l.afm  c059013l.afm  d050000l.afm  n019023l.afm  n019063l.afm  n021023l.afm  n022023l.afm  p052023l.afm
a010013l.pfb  b018012l.pfb  c059013l.pfb  d050000l.pfb  n019023l.pfb  n019063l.pfb  n021023l.pfb  n022023l.pfb  p052023l.pfb
a010015l.afm  b018015l.afm  c059016l.afm  fonts.dir     n019024l.afm  n019064l.afm  n021024l.afm  n022024l.afm  p052024l.afm
a010015l.pfb  b018015l.pfb  c059016l.pfb  fonts.scale   n019024l.pfb  n019064l.pfb  n021024l.pfb  n022024l.pfb  p052024l.pfb
a010033l.afm  b018032l.afm  c059033l.afm  n019003l.afm  n019043l.afm  n021003l.afm  n022003l.afm  p052003l.afm  s050000l.afm
a010033l.pfb  b018032l.pfb  c059033l.pfb  n019003l.pfb  n019043l.pfb  n021003l.pfb  n022003l.pfb  p052003l.pfb  s050000l.pfb
a010035l.afm  b018035l.afm  c059036l.afm  n019004l.afm  n019044l.afm  n021004l.afm  n022004l.afm  p052004l.afm  z003034l.afm
a010035l.pfb  b018035l.pfb  c059036l.pfb  n019004l.pfb  n019044l.pfb  n021004l.pfb  n022004l.pfb  p052004l.pfb  z003034l.pfb

/usr/share/fonts/dejavu:
DejaVuSans-BoldOblique.ttf           DejaVuSansCondensed.ttf         DejaVuSansMono.ttf          DejaVuSerifCondensed-BoldItalic.ttf  DejaVuSerif.ttf
DejaVuSans-Bold.ttf                  DejaVuSans-ExtraLight.ttf       DejaVuSans-Oblique.ttf      DejaVuSerifCondensed-Bold.ttf
DejaVuSansCondensed-BoldOblique.ttf  DejaVuSansMono-BoldOblique.ttf  DejaVuSans.ttf              DejaVuSerifCondensed-Italic.ttf
DejaVuSansCondensed-Bold.ttf         DejaVuSansMono-Bold.ttf         DejaVuSerif-BoldItalic.ttf  DejaVuSerifCondensed.ttf
DejaVuSansCondensed-Oblique.ttf      DejaVuSansMono-Oblique.ttf      DejaVuSerif-Bold.ttf        DejaVuSerif-Italic.ttf

/usr/share/fonts/jomolhari:
Jomolhari-alpha3c-0605331.ttf

/usr/share/fonts/khmeros:
KhmerOS_content.ttf  KhmerOS_sys.ttf  KhmerOS.ttf

/usr/share/fonts/kurdit-unikurd-web:
Unikuweb.ttf

/usr/share/fonts/liberation:
fonts.dir                      LiberationMono-Bold.ttf     LiberationSans-BoldItalic.ttf  LiberationSans-Regular.ttf      LiberationSerif-Italic.ttf
fonts.scale                    LiberationMono-Italic.ttf   LiberationSans-Bold.ttf        LiberationSerif-BoldItalic.ttf  LiberationSerif-Regular.ttf
LiberationMono-BoldItalic.ttf  LiberationMono-Regular.ttf  LiberationSans-Italic.ttf      LiberationSerif-Bold.ttf

/usr/share/fonts/lklug:
lklug.ttf

/usr/share/fonts/lohit-assamese:
Lohit-Assamese.ttf

/usr/share/fonts/lohit-bengali:
Lohit-Bengali.ttf

/usr/share/fonts/lohit-devanagari:
Lohit-Devanagari.ttf

/usr/share/fonts/lohit-gujarati:
Lohit-Gujarati.ttf

/usr/share/fonts/lohit-kannada:
Lohit-Kannada.ttf

/usr/share/fonts/lohit-oriya:
Lohit-Oriya.ttf

/usr/share/fonts/lohit-punjabi:
Lohit-Punjabi.ttf

/usr/share/fonts/lohit-tamil:
Lohit-Tamil.ttf

/usr/share/fonts/lohit-telugu:
Lohit-Telugu.ttf

/usr/share/fonts/madan:
madan.ttf

/usr/share/fonts/opensymbol:
opens___.ttf

/usr/share/fonts/paktype:
PakTypeNaqsh.ttf  PakTypeTehreer.ttf

/usr/share/fonts/sil-padauk:
Padauk-Bold.ttf  Padauk.ttf

/usr/share/fonts/smc:
Meera.ttf

/usr/share/fonts/stix:
STIXGeneralBolIta.otf  STIXGeneralBol.otf  STIXGeneralItalic.otf  STIXGeneral.otf

/usr/share/fonts/thai-scalable:
Waree-BoldOblique.ttf  Waree-Bold.ttf  Waree-Oblique.ttf  Waree.ttf

/usr/share/fonts/tibetan-machine-uni:
TibMachUni-1.901b.ttf

/usr/share/fonts/un-core:
UnDotumBold.ttf  UnDotum.ttf

/usr/share/fonts/vlgothic:
VL-Gothic-Regular.ttf

/usr/share/fonts/wqy-zenhei:
wqy-zenhei.ttc
lgritz commented 10 years ago

Pull request #857 adds an additional, earlier, clearer error message.

I figured everybody had "cour" installed somewhere, but apparently you don't. Not sure how to address that; there is apparently no font that I can truly count on as being on everybody's system (that's an oversight on somebody's part, I think -- there should be a uniform way to request a default font that always works).

Narann commented 10 years ago

Thanks a lot!

About default font, It doesn't seems so obvious.

Maybe this can help:

$ fc-match "cour"
DejaVuSans.ttf: "DejaVu Sans" "Book"
$ fc-match --help
usage: fc-match [-savVh] [-f FORMAT] [--sort] [--all] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}
List best font matching [pattern]

  -s, --sort           display sorted list of matches
  -a, --all            display unpruned sorted list of matches
  -v, --verbose        display entire font pattern verbosely
  -f, --format=FORMAT  use the given output format
  -V, --version        display font config version and exit
  -h, --help           display this help and exit

Don't know if this can be used as I guess it will requiere another lib dep. :(