test-imagemagick.py issue with a font on Ubuntu 18.04

Bug #2004188 reported by Pavel Kopylov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QA Regression Testing
Fix Released
Undecided
Unassigned

Bug Description

I faced two problems in test-imagemagick.py related to the absence of the font to operate.
The following output contains these problems:

------------ Begin console output ----------------
======================================================================
FAIL: test_disabled_text (__main__.ImagemagickTests)
Test to ensure text is disabled entirely
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test-imagemagick.py", line 490, in test_disabled_text
    """
  File "./test-imagemagick.py", line 468, in _test_disabled_format
    self.assertShellExitEquals(expected, ['convert', '%s:%s' % (img_format, infile), outfile])
  File "/home/testuser/qrt-test-imagemagick/testlib.py", line 1249, in assertShellExitEquals
    self.assertEqual(expected, rc, msg + result + report)
AssertionError: Got exit code 1, expected 0
Command: 'convert', 'text:/tmp/imagemagick-64VF09/input.text', '/tmp/imagemagick-64VF09/output.png'
Output:
convert-im6.q16: unable to get type metrics `/tmp/imagemagick-64VF09/input.text' @ error/txt.c/ReadTEXTImage/274.
convert-im6.q16: no images defined `/tmp/imagemagick-64VF09/output.png' @ error/convert.c/ConvertImageCommand/3258.

======================================================================
FAIL: test_lp1646485 (__main__.ImagemagickTests)
Test for LP: #1646485 regression
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test-imagemagick.py", line 286, in test_lp1646485
    self.assertEqual(expected, rc, result + report)
AssertionError: Got exit code 1, expected 0
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1367.
convert: no images defined `/tmp/imagemagick-MRVneN/lp1646485.png' @ error/convert.c/ConvertImageCommand/3258.

------------- End console output -----------------

As I have understood, the convert utility fails because it can not find a font and its metrics to draw text with. My solution is to have both the -font option and the following font name in the command line of the convert utility. This solution works for me.

There is the proposed merge request - https://code.launchpad.net/~pkopylov/qa-regression-testing/+git/qa-regression-testing/+merge/436560

Related branches

Pavel Kopylov (pkopylov)
summary: - test-imagemagick.py issue with a font
+ test-imagemagick.py issue with a font on Ubuntu 18.04
Revision history for this message
Alex Murray (alexmurray) wrote :

I am unable to reproduce this failure on an up-to-date 18.04 VM under LXD - can you provide any more details on the test environment you are using?

Changed in qa-regression-testing:
status: New → Incomplete
Revision history for this message
Pavel Kopylov (pkopylov) wrote :
Download full text (4.1 KiB)

I did some investigation.
So, the problem is located into the convert utility:

------------ Begin console output ----------------
root@unassigned-hostname:~# convert label:aaa x.png
convert-im6.q16: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1367.
convert-im6.q16: no images defined `x.png' @ error/convert.c/ConvertImageCommand/3258.
------------- End console output -----------------

I started the utility mentioned above with strace and noticed that an unsuccessful attempt to open "helvetica" file leads to failure. This file is used without any absolute path, so I think it is the issue, for instance, all other files are opened using an absolute path.

------- Begin strace output (grepped by openat) --
openat(AT_FDCWD, "/usr/share/fonts/truetype", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/var/cache/fontconfig//7ef2298fde41cc6eeb7af42e48b7d293-le64.cache-7", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/share/fonts/truetype/dejavu", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/var/cache/fontconfig//d589a48862398ed80a3d6066f4f56f4c-le64.cache-7", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "helvetica", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/ImageMagick-6/locale.xml", O_RDONLY) = 3
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7//config-Q16/locale.xml", O_RDONLY) = -1 ENOENT
------------- End strace output -----------------

So, I found "helvetica" word in the lib libMagickCore-6.Q16.so.3 which is loaded according to the strace output. Moreover, I found a xml-fragment inside this library:

------------- XML inside the library--------------
<?xml version="1.0"?><typemap> <type stealth="True" name="fixed" family="helvetica"/> <type stealth="True" name="helvetica" family="helvetica"/></typemap>
--------------------------------------------------

I am absolutely sure that this XML fragment is the key to the issue because things changed completely after I had corrected the word "helvetica" to "helvetixa" in the fragment (yes, I did it inside the binary file). So when the family is corrected as mentioned before, the convert utility works well. Right now, I don't understand why, but I am going to solve this problem.

In the end, I listed the font known by convert. There are several available fonts, but helvetica is not mentioned below:

------------ Begin console output ----------------
root@unassigned-hostname:~# convert -list font

Path: System Fonts
  Font: DejaVu-Sans
    family: DejaVu Sans
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
  Font: DejaVu-Sans-Bold
    family: DejaVu Sans
    style: Normal
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
  Font: DejaVu-Sans-Mono
    family: DejaVu Sans Mono
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
  Font: DejaVu-Sans-Mono-Bold
    family: DejaVu Sans Mono
    style: Normal
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf
  Font: DejaVu-Serif
    family: DejaVu Serif
    style: No...

Read more...

Revision history for this message
Pavel Kopylov (pkopylov) wrote :

Here is the second part of the investigation.

I found the XML-block in the sources of ImageMagick, it is a static character pointer in the "type.c" file. Its name is TypeMap:

-------------- type.c fragment ------------------

/*
  Declare type map.
*/
static const char
  *TypeMap = (const char *)
    "<?xml version=\"1.0\"?>"
    "<typemap>"
    " <type stealth=\"True\" name=\"fixed\" family=\"helvetica\"/>"
    " <type stealth=\"True\" name=\"helvetica\" family=\"helvetica\"/>"
    "</typemap>";
-------------------------------------------------

This block is used as a default source block to be loaded into a font cache. However, this loading is performed unless the font cache contains something at that moment. This logic is located in the AcquireTypeCache() function. So, two things could happen before and prevent the default block to be loaded. The first one is loading fonts from "/etc/ImageMagick-6/type.xml" and the second one is loading fonts selected by the environment variable "MAGICK_FONT_PATH". In my case, both of these things didn't happen and the default block was loaded.

There aren't any files mentioned by "/etc/ImageMagick-6/type-ghostscript.xml" included by "/etc/ImageMagick-6/type.xml" on my system. That is why the default block was loaded there for me. Things could be completely different on your system.

So, could you please display "/etc/ImageMagick-6/type.xml" and other files included by themselves, and check if these font files are really present on your system?

Revision history for this message
Alex Murray (alexmurray) wrote :

Thanks for the extra details - I have now merged the associated MR - thanks again for providing this.

Changed in qa-regression-testing:
status: Incomplete → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.