/usr/share/doc/libwmf0.2-7/tutapi.html is in libwmf-doc 0.2.8.4-10.6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | <html>
<head>
<title>libwmf-0.2.0 Tutorial 1: The API</title>
</head>
<body link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff"
background="caolan/pics/weave.jpg">
<h1>libwmf-0.2.0 Tutorial 1: The API</h1>
<h2>Contents</h2>
<ul>
<li><a href="#intro">Introduction</a>
<li><a href="#headers">Header Files</a>
<li><a href="#api">Creating The <b>API</b></a>
<li><a href="#devinit">Acknowledging The Device Layer</a>
<li><a href="#scan">Scanning The Metafile</a>
<li><a href="#devsetup">Setting Up The Device Layer</a>
<li><a href="#play">Playing The Metafile</a>
<li><a href="#font">Fonts & libwmf</a>
<li><a href="#fns">Other <b>API</b> Functions</a>
</ul>
<a name="intro"><h2>Introduction</h2></a>
<p>
The figure below illustrates the tripartite division of <b>application</b>,
<b>interpreter</b>, and <b>device layer</b>. The internal workings of each
of the three is irrelevant; all that matters is the three interfaces which
are separate. The core of <tt>libwmf</tt> is the interpreter, and as such
only the interfaces between (a) the interpreter and the application - the
<b>API</b> - and (b) the interpreter and the device layer - the <b>IPA</b>
- are defined. Applications that wish to implement their own new device
layer are free therefore to define whatever interface is suitable.
</p>
<table align=center><tr><td><img src="wmfpic.png"></td></tr></table>
<p>
<tt>libwmf</tt> includes two device layers: <tt>eps</tt> for conversion to
<tt>EPS</tt> (Encapsulated Postscript) or <tt>PS</tt> (Postscript); and
<tt>gd</tt> for conversion to <tt>PNG</tt> or <tt>JPEG</tt> image formats.
Included with <tt>libwmf</tt> are converters for these: <tt>wmf2eps</tt>
and <tt>wmf2gd</tt> respectively. The source-code for these is an excellent
place to see how to use the various features of the <b>API</b> and device-layer
interfaces.
</p>
<a name="headers"><h2>Header Files</h2></a>
<p>
All libwmf header files are now in a <tt>libwmf</tt> subdirectory. In general
you will need to include two. Unless you are writing a new device layer, which
will be discussed later, you should include only <tt>libwmf/api.h</tt> and the
header for whichever device layer you are interested in, for example:
</p>
<font color=blue>
<pre>
#include <libwmf/api.h>
#include <libwmf/gd.h>
</pre>
</font>
<p>
The <tt>gd</tt> device layer uses the <tt>GD</tt> library, included with
<tt>libwmf</tt>, to output images in <tt>PNG</tt> (or possibly in <tt>JPEG</tt>)
format. Alternatively, if you wish the output to be in <tt>PS</tt> or
<tt>EPS</tt> format, you would include:
</p>
<font color=blue>
<pre>
#include <libwmf/api.h>
#include <libwmf/eps.h>
</pre>
</font>
<a name="api"><h2>Creating The API</h2></a>
<p>
For each metafile you wish to process and convert to a given image type, you
must create an instance of the <b>API</b>. This can be sophisticated or simple.
In its simplest form, the only thing that needs to be specified is which
device layer you wish to use. For example, to use <tt>GD</tt>:
</p>
<font color=blue>
<pre>
wmfAPI_Options options;
wmfAPI* API;
wmf_error_t error;
unsigned long flags;
/* */
flags = WMF_OPT_FUNCTION;
options.function = wmf_gd_function;
/* Other Options */
error = wmf_api_create (&API,flags,&options);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
/* */
</pre>
</font>
<p>
The library performs all memory allocation with respect to the <b>API</b>, and
destroying the instance will free up all associated memory:
</p>
<font color=blue>
<pre>
error = wmf_api_destroy (API);
</pre>
</font>
<p>
There are a number of different options which can be used when creating the
<b>API</b>. The structure of <tt>wmfAPI_Options</tt> is:
</p>
<font color=blue>
<pre>
typedef struct _wmfAPI_Options wmfAPI_Options;
struct _wmfAPI_Options
{ void* context;
void* (*malloc) (void* context,size_t size);
void* (*realloc) (void* context,void* mem,size_t size);
void (*free) (void* context,void* mem);
int argc;
char** argv;
char** fontdirs; /* NULL-terminated list of directories to search for font files */
struct
{ wmfFontMap* wmf; /* {0,*}-terminated list: wmf-font-name -> ps-font-name */
wmfMapping* sub; /* {0,*}-terminated list: wmf-font-name substring equiv */
wmfMapping* ps; /* {0,*}-terminated list: ps-font-name -> pfb-file-name */
} font;
char* sys_fontmap_file;
char* xtra_fontmap_file;
void (*function) (wmfAPI*);
char* module;
char** dirs;
FILE* debug_out;
FILE* error_out;
};
</pre>
</font>
<ul>
<li><b>WMF_OPT_ALLOC</b><br>
If you wish to provide your own memory allocation routines for <tt>libwmf</tt>
to use instead of <tt>malloc</tt>, <tt>realloc</tt> and <tt>free</tt>, these
can be specified:
<font color=blue>
<pre>
flags |= WMF_OPT_ALLOC;
options.context = my_memory_manager_data;
options.malloc = my_malloc;
options.realloc = my_realloc;
options.free = my_free;
</pre>
</font>
<li><b>WMF_OPT_ARGS</b><br>
<tt>libwmf</tt> can be allowed to check for certain command line arguments:
<pre>
--wmf-ignore-nonfatal ignore any non-critical errors or unsupported features
--wmf-error=no suppress error reports
--wmf-debug=no suppress debug reports
--wmf-diagnostics emit diagnostic information (for analysis of metafiles)
--wmf-fontdir=<path> add <path> to list of directories searched for fonts
--wmf-sys-fonts use system fonts, if any found
--wmf-sys-fontmap=<file> use system xml-fontmap file <file> (implies --wmf-sys-fonts)
--wmf-xtra-fonts use non-system fonts, if any found
--wmf-xtra-fontmap=<file> use non-system xml-fontmap file <file> (implies --wmf-xtra-fonts)
</pre>
where the command line is specified by:
<font color=blue>
<pre>
int main (int argc,char** argv)
{ /* */
flags |= WMF_OPT_ARGS;
options.argc = argc;
options.argv = argv;
</pre>
</font>
<li><b>WMF_OPT_FONTDIRS</b><br>
A <b>NULL</b>-terminated list of directories to be searched for fonts can be
specified by:
<font color=blue>
<pre>
char* dirs[3] = { "/usr/share/fonts", "/usr/local/share/fonts", NULL };
/* */
flags |= WMF_OPT_FONTDIRS;
options.fontdirs = dirs;
</pre>
</font>
<li><b>WMF_OPT_FONTMAP</b> [UNTESTED]<br>
This is a system for specifying font mappings; see section on fonts.
<li><b>WMF_OPT_SYS_FONTS</b><br>
Use any system fonts found, not just standard 13.
<li><b>WMF_OPT_SYS_FONTMAP</b> [UNTESTED]<br>
Use specified system XML fontmap file:
<font color=blue>
<pre>
flags |= WMF_OPT_SYS_FONTS;
flags |= WMF_OPT_SYS_FONTMAP;
options.sys_fontmap_file = "/usr/local/share/fonts/fontmap";
</pre>
</font>
<li><b>WMF_OPT_XTRA_FONTS</b><br>
Use any system fonts found, not just standard 13.
<li><b>WMF_OPT_XTRA_FONTMAP</b> [UNTESTED]<br>
Use specified non-system XML fontmap file:
<font color=blue>
<pre>
flags |= WMF_OPT_XTRA_FONTS;
flags |= WMF_OPT_XTRA_FONTMAP;
options.xtra_fontmap_file = "/usr/local/share/libwmf/fonts/fontmap";
</pre>
</font>
<li><b>WMF_OPT_FUNCTION</b><br>
This is how to initialize a device-layer with a supplied function. (Currently
this is the only way to initialize a device layer since modules are not yet
implemented.) The function is device-specific. See above.
<li><b>WMF_OPT_MODULE</b> [UNIMPLEMENTED]<br>
initialize device-layer with specified module
<li><b>WMF_OPT_MODULE_DIRS</b> [UNIMPLEMENTED]<br>
check for module also in specified directories
<li><b>WMF_OPT_IGNORE_NONFATAL</b> [HIGHLY RECOMMENDED]<br>
Ignore (some) non-fatal errors, equivalent to --wmf-ignore-nonfatal
<font color=blue>
<pre>
flags |= WMF_OPT_IGNORE_NONFATAL;
</pre>
</font>
<li><b>WMF_OPT_NO_ERROR</b><br>
Suppress all error reports, equivalent to --wmf-error=no
<font color=blue>
<pre>
flags |= WMF_OPT_NO_ERROR;
</pre>
</font>
<li><b>WMF_OPT_NO_DEBUG</b><br>
Suppress all debug reports, equivalent to --wmf-debug=no
<font color=blue>
<pre>
flags |= WMF_OPT_NO_DEBUG;
</pre>
</font>
<li><b>WMF_OPT_LOG_ERROR</b> [UNTESTED]<br>
Divert error reports to specified stream:
<font color=blue>
<pre>
FILE* e_out;
/* */
e_out = fopen ("error.log","w");
if (e_out)
{ flags |= WMF_OPT_LOG_ERROR;
options.error_out = e_out;
}
</pre>
</font>
<li><b>WMF_OPT_LOG_DEBUG</b> [UNTESTED]<br>
Divert debug reports to specified stream:
<font color=blue>
<pre>
FILE* d_out;
/* */
d_out = fopen ("debug.log","w");
if (d_out)
{ flags |= WMF_OPT_LOG_DEBUG;
options.debug_out = d_out;
}
</pre>
</font>
</ul>
<a name="devinit"><h2>Acknowledging The Device Layer</h2></a>
<p>
In addition to creating the <b>API</b>, <tt>wmf_api_create</tt> sets up the
link with the device layer. Device layer data can be accessed through
<tt>API->device_data</tt>, but the implementation will probably provide a
convenient interface. For example, with <tt>GD</tt>:
</p>
<font color=blue>
<pre>
wmfAPI_Options options;
wmfAPI* API;
wmf_error_t error;
wmf_gd_t* ddata;
unsigned long flags;
/* */
flags = WMF_OPT_FUNCTION | WMF_OPT_IGNORE_NONFATAL;
options.function = wmf_gd_function;
/* Other Options */
error = wmf_api_create (&API,flags,&options);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
ddata = WMF_GD_GetData (API);
if ((ddata->flags & WMF_GD_SUPPORTS_JPEG) == 0)
{ fprintf (stderr,"libwmf does not support JPEG conversion!\n");
wmf_api_destroy (API);
/* */
}
/* */
</pre>
</font>
<p>
At this point there is little need to acknowledge the device layer, except if
(as in the above example) the device layer indicates possible restrictions.
</p>
<a name="scan"><h2>Scanning The Metafile</h2></a>
<p>
Before <i>playing</i> the metafile (i.e., rendering the image) it is necessary
first to open the metafile and second to <i>scan</i> it. To open a metafile
that is a file on disc is simple:
</p>
<font color=blue>
<pre>
error = wmf_file_open (API,"file.wmf");
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
</pre>
</font>
<p>
The file needs to be closed later by calling:
</p>
<font color=blue>
<pre>
error = wmf_file_close (API);
</pre>
</font>
<p>
Alternatively, if the metafile is preloaded in memory, it can be opened with:
</p>
<font color=blue>
<pre>
error = wmf_mem_open (API,(unsigned char*) buffer,(long) buffer_length);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
</pre>
</font>
<p>
and closed later by calling:
</p>
<font color=blue>
<pre>
error = wmf_mem_close (API);
</pre>
</font>
<p>
A third, more generic method is available as well, but requires more work. For
example, to `open' an already-open file stream:
</p>
<font color=blue>
<pre>
int my_wmfRead (void*);
int my_wmfSeek (void*,long);
long my_wmfTell (void*);
/* User redefinable functions for input-stream access:
* wmfRead: returns unsigned char cast to int, or EOF
*/
int my_wmfRead (void* context)
{ return (fgetc ((FILE*) context));
}
/* User redefinable functions for input-stream access:
* wmfSeek: returns (-1) on error, else 0
*/
int my_wmfSeek (void* context,long position)
{ return (fseek ((FILE*) context,position,SEEK_SET));
}
/* User redefinable functions for input-stream access:
* wmfTell: returns (-1) on error, else pos
*/
long my_wmfTell (void* context)
{ return (ftell ((FILE*) context));
}
/* */
error = wmf_bbuf_input (API,my_wmfRead,my_wmfSeek,my_wmfTell,(void*) in);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
</pre>
</font>
<p>
Once the metafile has been opened, it must be scanned. Scanning parses the
metafile without any interaction with the device layer, and its purpose is
(a) determine whether it is a valid metafile, and (b) estimate the dimensions
of the metafile.
</p>
<font color=blue>
<pre>
wmfD_Rect bbox;
/* */
error = wmf_scan (API,0,&bbox);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
</pre>
</font>
<p>
A metafile needs to be scanned, but only once. <tt>wmf_scan</tt> will reject
any further attempts to scan; <tt>wmf_play</tt> (see below) will fail unless
the metafile has been scanned.
</p>
<a name="devsetup"><h2>Setting Up The Device Layer</h2></a>
<p>
Metafiles are basically a vector-graphic format and as such they can be scaled
to any size and aspect ratio. The interpreter describes the metafile in a
scaleable manner to the device layer, and the device layer is free to scale
the metafile in any manner it chooses. As such, the device layer will almost
certainly require (a) the dimensions of the metafile found by <tt>wmf_scan</tt>
(see above), and (b) the image width and height desired by the application.
</p>
<p>
<tt>wmfD_Rect</tt> describes a bounding box in the interpreter's device
coordinates, and is defined as:
</p>
<font color=blue>
<pre>
typedef struct _wmfD_Coord wmfD_Coord;
typedef struct _wmfD_Rect wmfD_Rect;
struct _wmfD_Coord
{ float x;
float y;
};
struct _wmfD_Rect
{ wmfD_Coord TL;
wmfD_Coord BR;
};
</pre>
</font>
<p>
and so an application can determine the image's aspect ratio by:
</p>
<font color=blue>
<pre>
float aspect_ratio;
/* */
aspect_ratio = (bbox.BR.y - bbox.TL.y) / (bbox.BR.x - bbox.TL.x);
</pre>
</font>
<p>
<b>Note: By definition bbox.BR.y > bbox.TL.y and bbox.BR.x > bbox.TL.x</b>
</p>
<p>
Putting this all together, and again using <tt>GD</tt> as an example:
</p>
<font color=blue>
<pre>
wmfAPI_Options options;
wmfAPI* API;
wmfD_Rect bbox;
wmf_error_t error;
wmf_gd_t* ddata;
unsigned long flags;
FILE* out;
/* */
flags = WMF_OPT_FUNCTION | WMF_OPT_IGNORE_NONFATAL;
options.function = wmf_gd_function;
/* Other Options */
error = wmf_api_create (&API,flags,&options);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
ddata = WMF_GD_GetData (API);
if ((ddata->flags & WMF_GD_SUPPORTS_JPEG) == 0)
{ fprintf (stderr,"libwmf does not support JPEG conversion!\n");
wmf_api_destroy (API);
/* */
}
error = wmf_file_open (API,"file.wmf");
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
error = wmf_scan (API,0,&bbox);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
out = fopen ("file.jpeg","w");
if (out == 0)
{ wmf_api_destroy (API);
/* */
}
ddata->type = wmf_gd_jpeg;
ddata->flags |= WMF_GD_OUTPUT_FILE;
ddata->file = out;
ddata->bbox = bbox;
ddata->width = (unsigned int) ceil (ddata->bbox.BR.x - ddata->bbox.TL.x);
ddata->height = (unsigned int) ceil (ddata->bbox.BR.y - ddata->bbox.TL.y);
</pre>
</font>
<p>
The above example doesn't do anything intelligent with the size of the image.
The converter <tt>wmf2gd</tt> sets a maximum size and scales the image
accordingly.
</p>
<a name="play"><h2>Playing The Metafile</h2></a>
<p>
The final step is simply to play the metafile:
</p>
<font color=blue>
<pre>
error = wmf_play (API,0,0);
if (error != wmf_E_None)
{ wmf_api_destroy (API);
/* */
}
</pre>
</font>
<p>
This can be done any number of times, with varying device layer settings if
desired.
</p>
<a name="font"><h2>Fonts & libwmf</h2></a>
<p>
There are a number of issues with fonts and <tt>libwmf</tt> to complicate
matters: the first is the need to translate font names specified into font
names recognized by <tt>libwmf</tt>; the second is to find the corresponding
font files; a third is to work out what encoding (char. set) to use. Described
below is <tt>libwmf</tt>'s native mechanism for dealing with these issues.
While versatile, unfortunately it requires significant effort on the part of an
application that seeks to extend the limited font mapping provided by default.
A second (experimental and optional) mechanism is provided also, and this reads
an XML file containing font information (file locations and font names); on
RedHat Linux systems this file is <tt>/usr/share/fonts/fontmap</tt>. No doubt
this is an area that will see considerable future development.
</p>
<p>
Chances are, the metafile will require fonts that are not available to
<tt>libwmf</tt>, and there must be a mechanism, therefore, for translating
metafile fontnames into usable fonts. As noted above, the
<tt>wmfAPI_Options</tt> structure passed to <tt>wmf_api_create</tt> has the
following entries:
</p>
<font color=blue>
<pre>
typedef struct _wmfAPI_Options wmfAPI_Options;
struct _wmfAPI_Options
{ /* */
struct
{ wmfFontMap* wmf; /* {0,*}-terminated list: wmf-font-name -> ps-font-name */
wmfMapping* sub; /* {0,*}-terminated list: wmf-font-name substring equiv */
wmfMapping* ps; /* {0,*}-terminated list: ps-font-name -> pfb-file-name */
} font;
/* */
}
</pre>
</font>
<p>
The two mapping types are defined:
</p>
<font color=blue>
<pre>
typedef struct _wmfMapping wmfMapping;
typedef struct _wmfFontMap wmfFontMap;
struct _wmfMapping
{ char* name;
char* mapping;
FT_Encoding encoding;
};
struct _wmfFontMap
{ char* name; /* wmf font name */
char* normal; /* postscript font names */
char* italic;
char* bold;
char* bolditalic;
};
</pre>
</font>
<p>
Internally <tt>libwmf</tt> has the following default definitions:
</p>
<font color=blue>
<pre>
/* postscript (standard 13) font name mapping to type 1 font file
*/
static wmfMapping PSFontMap[13] = {
{ "Courier", "n022003l.pfb", ft_encoding_adobe_standard },
{ "Courier-Oblique", "n022023l.pfb", ft_encoding_adobe_standard },
{ "Courier-Bold", "n022004l.pfb", ft_encoding_adobe_standard },
{ "Courier-BoldOblique", "n022024l.pfb", ft_encoding_adobe_standard },
{ "Helvetica", "n019003l.pfb", ft_encoding_adobe_standard },
{ "Helvetica-Oblique", "n019023l.pfb", ft_encoding_adobe_standard },
{ "Helvetica-Bold", "n019004l.pfb", ft_encoding_adobe_standard },
{ "Helvetica-BoldOblique","n019024l.pfb", ft_encoding_adobe_standard },
{ "Times-Roman", "n021003l.pfb", ft_encoding_adobe_standard },
{ "Times-Italic", "n021023l.pfb", ft_encoding_adobe_standard },
{ "Times-Bold", "n021004l.pfb", ft_encoding_adobe_standard },
{ "Times-BoldItalic", "n021024l.pfb", ft_encoding_adobe_standard },
{ "Symbol", "s050000l.pfb", ft_encoding_adobe_custom }};
/* exact WMF font name to postscript (standard 13) equivalent...
* well, yeah, I know. :-(
*/
static wmfFontMap WMFFontMap[] = {
{ "Courier", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Helvetica", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique" },
{ "Modern", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Monotype Corsiva", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "News Gothic", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique" },
{ "Symbol", "Symbol", "Symbol", "Symbol", "Symbol" },
{ "System", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Times", "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic" }};
/* Sub-string match if not in the above list;
*/
static wmfMapping SubFontMap[] = {
{ "Arial", "Helvetica" },
{ "Courier", "Courier" },
{ "Fixed", "Courier" },
{ "Helvetica", "Helvetica" },
{ "Sans", "Helvetica" },
{ "Sym", "Symbol" },
{ "Terminal", "Courier" },
{ "Times", "Times" },
{ "Wingdings", "Symbol" }};
/* If all else fails, assume Times
*/
static char* DefaultFontMapping = "Times";
</pre>
</font>
<p>
Bundled with <tt>libwmf</tt> are the thirteen standard <tt>ghostscript</tt>
fonts. Unless the application specifies other fonts, <tt>libwmf</tt> will
attempt to map the metafile's font name to one of these default fonts.
</p>
<p>
First an exact match is sought with the first argument of each font in
<tt>WMFFontMap</tt>. For example, "News Gothic" would be an exact match;
"Arial" would not. If there is no exact match, then a substring search is
performed against the first argument of each font in <tt>SubFontMap</tt>.
For example, this time "Arial" would match; "Zapf Chancery" would not. If
there is still no exact match then "Times" is assumed.
</p>
<p>
Once a font name is found, this is converted to an equivalent name, assumed to
be the postscript font name, using <tt>WMFFontMap</tt>. And finally the
equivalent name is searched for in <tt>PSFontMap</tt>. For example,
"Zapf Chancery" in italics would be mapped to "Times" in italics, then to
"Times-Italic", and finally to "n021023l.pfb".
</p>
<p>
<tt>libwmf</tt> searches through the list of font directories for this file
and loads it using <tt>freetype (2)</tt> with the encoding specified by the
third argument of the <tt>PSFontMap</tt> entry.
</p>
<p>
These three lists can be prepended by using the <b>WMF_OPT_FONTMAP</b> option.
The font files can be any format supported by <tt>freetype (2)</tt>.
</p>
<p>
After the metafile has been scanned, <tt>API->fonts</tt> is a
<tt>NULL</tt>-terminated list of (postscript) font names corresponding to the
fonts selected by the interpreter.
</p>
<a name="fns"><h2>Other API Functions</h2></a>
<p>
<tt>libwmf</tt> performs all memory allocation with respect to the <b>API</b>.
When the <b>API</b> is destroyed, all associated memory is freed. The routines
for allocating and freeing such memory are:
</p>
<font color=blue>
<pre>
extern void* wmf_malloc (wmfAPI*,size_t);
extern void* wmf_calloc (wmfAPI*,size_t,size_t);
extern void* wmf_realloc (wmfAPI*,void*,size_t);
extern void wmf_free (wmfAPI*,void*);
</pre>
</font>
<p>
These behave similarly to the standard <tt>malloc</tt>, etc. Similarly:
</p>
<font color=blue>
<pre>
extern char* wmf_strdup (wmfAPI*,char*);
</pre>
</font>
<p>
is an internal implementation of <tt>strdup</tt> which allocates the copied
string w.r.t. the <b>API</b>. On a related note,
</p>
<font color=blue>
<pre>
extern char* wmf_strstr (const char*,const char*);
</pre>
</font>
<p>
is an internal implementation of <tt>strstr</tt> and may be just a wrapper for
it. This is a special case of a function which does not refer to the
<b>API</b>.
</p>
<p>
Messages can be added to the <i>error</i> and <i>debug</i> streams using:
</p>
<font color=blue>
<pre>
extern void wmf_error (wmfAPI* API,char* srcfilename,int linenumber,char* message);
extern void wmf_debug (wmfAPI* API,char* srcfilename,int linenumber,char* message);
extern void wmf_assert (wmfAPI* API,char* srcfilename,int linenumber);
</pre>
</font>
<p>
but these functions should be used via the macros <tt>WMF_ERROR(API,"mesg")</tt>,
<tt>WMF_DEBUG(API,"mesg")</tt>, and <tt>WMF_ASSERT(API,<expr>)</tt>.
</p>
<p>
Finally, a call-back function can be set. This is called after each metafile
record with an estimate of the proportion of the metafile read; if the return
value is non-zero then the player will exit prematurely.
</p>
<font color=blue>
<pre>
typedef int (*wmfStatus) (void* context,float proportion);
extern void wmf_status_function (wmfAPI* API,void* context,wmfStatus function);
</pre>
</font>
<p>
For example, the following status function is used by <tt>wmf2gd</tt>:
</p>
<font color=blue>
<pre>
int wmf2gd_status (void* context,float p)
{ int percent;
percent = (int) (p * 100);
if (percent < 0) percent = 0;
if (percent > 99) percent = 99;
fprintf (stderr,"%2d%%\b\b\b",percent);
}
</pre>
</font>
<p>
Although there are other functions in the <b>API</b>, their use is <i>not</i>
recommended.
</p>
<hr>
<address>
Copyright 2001 wvWare/libwmf <a href="http://www.wvware.com/">http://www.wvware.com/</a>
</address>
</body>
</html>
|