Text render not work using bitmap Terminus font

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jpka
Posts: 8
Joined: 2014-01-17T13:56:32-07:00
Authentication code: 6789

Text render not work using bitmap Terminus font

Post by jpka »

Hi! I need to 'write' some text on images with bitmap font without scaling.
I try to do it using Terminus font set. I use command:

Code: Select all

convert -pointsize 16 -font '/usr/share/fonts/X11/misc/ter-u16b_unicode.pcf.gz' label:"YOURTEXT" output.png
but get only trash (totally wrong) image. Almost all other software, except only OpenOffice since version 1.1.5, deal with Terminus font just fine at my current system.
Is ImageMagick capable to use bitmap fonts? Is something wrong with that command? I did not found any working command line examples for convert with bitmap fonts available for Ubuntu.
Thanks!

Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
OS: Ubuntu 12.04.3 LTS
How to install these fonts:

Code: Select all

sudo apt-get install xfonts-terminus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text render not work using bitmap Terminus font

Post by fmw42 »

I think you have to decompress the .gz archive and then reference a specific font. I am not sure about pcf fonts in IM.
jpka
Posts: 8
Joined: 2014-01-17T13:56:32-07:00
Authentication code: 6789

Re: Text render not work using bitmap Terminus font

Post by jpka »

I uncompress font and put to home folder, but output image is a noise, while it is different from previous.

Code: Select all

convert -pointsize 16 -font 'ter-u16b_unicode.pcf' label:"YOURTEXT" output.png
I not get any errors at terminal.
Is there a way how to debug program, something like '-v' or '--verbose' command line switches?
Thank you!
P.S. Can somebody please check my command at other Linux/Ubuntu system and confirm that it is not work?
jpka
Posts: 8
Joined: 2014-01-17T13:56:32-07:00
Authentication code: 6789

Re: Text render not work using bitmap Terminus font

Post by jpka »

I also found something about bitmap font supporting at IM manuals:
In addition to the fonts specified by the above pre-defined list, you can also specify a font from a specific source. For example Arial.ttf is a TrueType font file, ps:helvetica is PostScript font, and x:fixed is X11 font.
Terminus is exactly X11 font set. But how to use this 'x:' prefix? Bruteforcing like

Code: Select all

convert -pointsize 16 -font x:'/usr/share/fonts/X11/misc/ter-u16n_unicode.pcf.gz' label:"YOURTEXT" output.png
immediately giver error
convert: unable to read font `x:/usr/share/fonts/X11/misc/ter-u16n_unicode.pcf.gz' @ warning/annotate.c/RenderType/879. :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text render not work using bitmap Terminus font

Post by fmw42 »

convert -pointsize 16 -font 'ter-u16b_unicode.pcf' label:"YOURTEXT" output.png
Use the full path to the font

Code: Select all

convert -pointsize 16 -font /pathto/ter-u16b_unicode.pcf label:"YOURTEXT" output.png
If that does not work, then perhaps your font is not a valid font for IM or is corrupt. Try a ttf font to see if that works for your system.

What version of IM are you using? Do you have fontconfig and freetype installed as delegate libraries.

convert -version

or

convert -list configure

and look at the line starting with DELEGATES

to see that they are available.


MIne system shows:

Delegates: bzlib cairo fftw fontconfig freetype gslib jbig jng jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib
jpka
Posts: 8
Joined: 2014-01-17T13:56:32-07:00
Authentication code: 6789

Re: Text render not work using bitmap Terminus font

Post by jpka »

I try to use full path and local path, compressed and decompressed font file. It is not helpful. When IM not found a font file, it immediately throw an error. I'm talk only about cases when no any errors from 'convert', so i know it find the font file successfully.
Terminus font is not corrupt, it is quite old, standard and works in system and in graphic software include `gimp`, `mtpaint` etc., and opens in `fontview` and `fontforge` just fine, either in compressed or uncompressed form.
I of course try testing with TTF fonts and see it works fine in IM, so i file this particularly bug.
<small>TTF fonts not suitable for me, because result will be printed on very low resolution device (dot matrix printer) and only bitmap font give each pixel precisely correct today and tomorrow, regardless of changes in rendering/hinting/antialiasing libraries, etc. I need only professional, absolutely perfect result, guaranteed for any future.</small>
Thank you so much!

Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
OS: Ubuntu 12.04.3 LTS
How to install these fonts in Ubuntu:

Code: Select all

sudo apt-get install xfonts-terminus
then use say '/usr/share/fonts/X11/misc/ter-u16b_unicode.pcf.gz' for 16 px height.

Code: Select all

DELEGATES     bzlib djvu fontconfig freetype gvc jpeg jng jp2 lcms lqr openexr png rsvg tiff x11 xml wmf zlib
libfreetype6:
  Installed: 2.4.8-1ubuntu2.1
libfontconfig1:
  Installed: 2.8.0-3ubuntu9.1
EDIT (Added): Also not work (with same result) on other PC:

Code: Select all

Version: ImageMagick 6.5.7-8 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Features: OpenMP 
DISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"
libfontconfig1:
  Installed: 2.8.0-2ubuntu1
libfreetype6:
  Installed: 2.3.11-1ubuntu2.7
DELEGATES     bzlib djvu freetype gvc jpeg jng jp2 lcms openexr png tiff x11 xml wmf zlib
Kernel: special industrial real-time kernel:
Linux test-desktop 2.6.32-122-rtai #rtai SMP Tue Jul 27 12:44:07 CDT 2010 i686 GNU/Linux
jpka
Posts: 8
Joined: 2014-01-17T13:56:32-07:00
Authentication code: 6789

[SOLVED] Re: Text render not work using bitmap Terminus font

Post by jpka »

Hi!
While trying to solve this, i dive into Source Code. I suddenly notice at magick/annotate.c:861

Code: Select all

      if (*draw_info->font == '-')
        return(RenderX11(image,draw_info,offset,metrics));
which may means the font name may be '-' or start from '-'. It is good news, because many X11 bitmap font names start with '-'.
I find some suitable fonts with

Code: Select all

xlsfonts | grep 10646 | grep terminus
which give me, for example,
-xos4-terminus-medium-r-normal--12-120-72-72-c-60-iso10646-1
-xos4-terminus-medium-r-normal--16-160-72-72-c-80-iso10646-1
-xos4-terminus-medium-r-normal--24-240-72-72-c-120-iso10646-1
...
So i try to feed IM with that font name (without path) and it surprisingly work! And also good news that 'pointsize' not make sense here, because font height hardly defined in font file, and we do not need scaling:

Code: Select all

convert -font '-xos4-terminus-medium-r-normal--24-240-72-72-c-120-iso10646-1' label:"YOURTEXT Ё Й が" output.png
Cool! But bad news is Unicode symbols not supported in IM for X11 rendering, unfortunately.
I test it on various versions include 6.5.7-8 and 6.8.8 (latest).
So i consider this bug solved with two limitations:
  • * No unicode;
    * Font names not starting with '-' will not work, as i think.
Unfortunately, looking at source code, it is looks like far not easy to add Unicode support for X11 bitmap font render for IM. But if developers suddenly obtain the time to do it, i can help in form preffered by developers, please PM me then.
Thanks!


P.S. For limited support of international glyphs, particularly Cyrillic as i need, there is (ugly) workaround:
Obtain font names with 1-byte Cyrillic encoding, say KOI:

Code: Select all

xlsfonts | grep koi | grep terminus
Then use

Code: Select all

convert -font '-xos4-terminus-medium-r-normal--24-240-72-72-c-120-koi8-r' label:"$(echo 'Проверка работы' | iconv -f utf8 -t koi8-r)" output.png
This is ugly because most other Unicode symbols will be not available due to 1-byte limitation.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text render not work using bitmap Terminus font

Post by fmw42 »

unicode is supported, but the font must support that.

see
http://www.imagemagick.org/Usage/text/#unicode
Post Reply