Page 1 of 1

reading wmf files

Posted: 2008-11-20T16:06:12-07:00
by nomoon
I have been trying to read/convert wmf images of the following type :
Equation 1
Equation 2
Equation 3
which contain text embedded in wmf images. However, each time I tried to read them using display or converting them with convert, ImageMagick would cut off the last "word" in every file: specifically, theta in Equation 1 wouldn't make it through, '111' would be lost from Equation 2, and there wouldn't be any ending '999' in Equation 3.

I tested this behavior on a RedHat 5 server, an Ubuntu desktop (building ImageMagick 6.4.5-7 from sources) and a WindowsXP box using ImageMagick-6.4.6-0-Q16-windows-x64-static.exe.

Thanks

Re: reading wmf files

Posted: 2008-11-21T15:27:24-07:00
by nomoon
Hrm... apparently silence is the answer.

Anyway, just in case anyone else runs into this issue or anyone cares about this enough to patch the code, I post below the needed changes. For some reason in the standard configuration MAGICKCORE_WMFLITE_DELEGATE (wmflite mode in libwmf) is defined, which requires one defines font_map and font_stringwidth callbacks. Unfortunately, lite_font_stringwidth, which I suppose is defined for this purpose, returns 0 on every string --- never mind, even if it would return its stringwidth value, it would be off. That is the reason I used the standard libwmf stringwidth function for the API.

And here are the changes one needs to make to wmf.c:

Code: Select all

#include "libwmf/font.h"

/* ... */

static void lite_font_init( wmfAPI* API, wmfAPI_Options* options){
/*....*/
font_data->stringwidth = wmf_ipa_font_stringwidth;
/*...*/
}
If all this does not seem to fit in, you may check in libwmf sources src/player/meta.h: meta_text() where the API callback stringwidth is used to compute the width of the string bbox and further the bbox width of the entire image.

Cheers

Re: reading wmf files

Posted: 2008-11-21T16:47:07-07:00
by magick
The lite_font_stringwidth() method returns font metrics based on ImageMagick fonts as returned by the Freetype delegate library. When we convert / display your WMF files they return a proper bounding box. We suspect that you might not have Freetype enabled or your Freetype library is older. We're using Freetype 2.2.7. To see which version you are using, type
  • identify -list format
and look at what is associated with the TTF tag.

Re: reading wmf files

Posted: 2008-11-21T17:08:01-07:00
by nomoon
Indeed: I have been using freetype 2.1.10 on one of the machines I tested this with.

However, it still confuses me that lite_font_stringwidth returns 0 always: is this supposed to be the font metric? If I change the last line in the function to "return stringwidth" everything works perfectly. Without this change, I see the incorrect conversion.

Anyway, thanks for the feedback.

Re: reading wmf files

Posted: 2008-11-21T17:17:48-07:00
by magick
In lite_font_stringwidth() return stringwidth instead of 0. Does that fix the problem for you? In our tests it did not make a difference-- either way the WMF images are rendered properly.

Re: reading wmf files

Posted: 2008-11-21T17:31:57-07:00
by nomoon
Yes it does. And the change seems to be mandatory for me.

By the way, thanks for this great piece of software. I am using it as part of a RTF parser that produces custom XML on the fly: being able to convert and transform WMF was essential (not to mention bmp, jpeg, and png support). Also, I am very impressed with the readability of your sources.

Re: reading wmf files

Posted: 2008-11-21T17:56:15-07:00
by magick
Ok, we'll get a patch into the next point release, 6.4.6-1. Thanks for alerting us to the problem.