\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch .\" against that, and send it to the Netpbm maintainer. .TH "Libnetpbm PPM Drawing Function Manual" 3 "April 2018" "netpbm documentation" .PP .UR #toc Table Of Contents .UE \& .SH NAME libnetpbm_draw \e- Libnetpbm PPM Drawing Function Manual .SH DESCRIPTION .PP This reference manual covers functions in the \fBlibnetpbm\fP library for drawing images, using the PPM image format and the \fBlibnetpbm\fP in-memory image formats. .PP We actually have very little information here; this is mainly a framework for adding documentation later if someone becomes interested in this facility. .PP Note that the Netpbm program \fBppmdraw\fP is essentially a command-line interface to the functions of this library. You can use that program's source code as an example, or just invoke that program instead of calling these functions. The netpbm program \fBppmlabel\fP is another good example of using these functions. .UN basicfunctions .SH Basic Functions .PP The functions are all declared in the \fBppmdraw.h\fP header file. .UN ppmd_setlinetype .SS \fBppmd_setlinetype\fP .UN ppmd_setlineclip .SS \fBppmd_setlineclip\fP .UN ppmd_line .SS \fBppmd_line\fP .UN ppmd_spline3 .SS \fBppmd_spline3\fP .UN ppmd_polyspline .SS \fBppmd_polyspline\fP .UN ppmd_circle .SS \fBppmd_circle\fP .UN ppmd_filledrectangle .SS \fBppmd_filledrectangle\fP .UN ppmd_fill .SS \fBppmd_fill\fP .UN ppmd_text .SS \fBppmd_text\fP .UN ppmd_text_box .SS \fBppmd_text_box\fP .UN drawprocs .SH Drawprocs .PP Drawprocs are functions that tell how to draw a point. You pass drawprocs to drawing functions that require them. .PP There are two types: \fBppmd_drawprocp\fP and \fBppmd_drawproc\fP. The only difference is that the former takes the location at which to draw the point as an argument of point type (\fBppmd_point\fP), whereas the latter takes integer column and row arguments. .UN ppmd_point_drawproc .SS \fBppmd_point_drawproc\fP .PP This simply fills in a single pixel. This is usually what you want. .UN ppmd_fill_drawprocp .SS \fBppmd_fill_drawprocp\fP .PP This Drawproc is useful for filling, in that it not only draws on the canvas, but remembers where it's been, outlining an area that you can fill with \fBppmd_fill\fP. .UN ppmd_fill_drawproc .SS \fBppmd_fill_drawproc\fP .PP This is the same thing as \fBppmd_fill_drawprocp\fP except that it is a \fBppmd_drawproc\fP function instead of \fBppmd_drawprocp\fP. .UN pathfill .SH Path Filling Function .UN ppmd_fill_path .SS \fBppmd_fill_path\fP .B Synopsis .nf \f(CW void ppmd_fill_path(pixel ** pixels, int cols, int rows, pixval maxval, ppmd_path * pathP, pixel color); \fP .fi .B Description .PP This fills a closed path. .PP \fIpixels\fP, \fIcols\fP, \fIrows\fP, and \fImaxval\fP describe the canvas on which to draw. .PP \fIpathP\fP identifies a closed path on that canvas. If it does not end on the same point at which it starts, \fBppmd_fill_path\fP aborts the program with a call to \fBpm_error\fP. The path may cross itself, though, creating multiple closed areas, each of which \fBppmd_fill_path\fP fills. The path must fit within the \fIcols\fP x \fIrows\fP dimensions. If it does not, \fBppmd_fill_path\fP aborts the program with a call to \fBpm_error\fP. .PP \fIcolor\fP is the fill color. \fBppmd_fill_path\fP makes every pixel within the closed path that color. .PP \fBppmd_fill\fP is more general, but harder to use. With that, you can fill with a pattern. .PP This function was new in Netpbm 10.34 (June 2006). .UN ppmd_makeLineLeg .SS ppmd_makeLineLeg .PP This function returns a data structure of type \fBppmd_pathleg\fP, to be used in a data structure of type \fBppmd_path\fP, to be use with function \fBppmd_fill_path\fP. .PP This function was new in Netbm 10.78 (March 2017). .UN pathbuilder .SH Path Builder .PP The functions in this section are for building a path (\fBppmd_path\fP) for use with \fBppmd_fill_path\fP. .PP It is an object-oriented set of functions, where the object involved is of type \fBppmd_path_builder\fP. This is an opaque structure that you should not access directly, but only through the functions in this section. .PP Here is an example that generates a filled rectangle: .nf \f(CW pixels = ppm_allocarray(100, 100); unsigned int row; /* Initialize the canvas to all black */ for (row = 0; row < 100; ++row) { unsigned int col; for (col = 0; col < 100; ++col) pixels[row][col] = ppm_blackpixel(); } /* Create a rectangular path */ ppmd_pathbuilder * const pathBuilderP = ppmd_pathbuilder_create(); ppmd_pathbuilder_setBegPoint(pathBuilderP, ppmd_makePoint(5, 5)); ppmd_pathbuilder_addLineLeg(pathBuilderP, ppmd_makeLineLeg(ppmd_makePoint(5, 50))); ppmd_pathbuilder_addLineLeg(pathBuilderP, ppmd_makeLineLeg(ppmd_makePoint(50, 50))); ppmd_pathbuilder_addLineLeg(pathBuilderP, ppmd_makeLineLeg(ppmd_makePoint(50, 5))); ppmd_pathbuilder_addLineLeg(pathBuilderP, ppmd_makeLineLeg(ppmd_makePoint(5, 5))); /* Fill the area enclosed by that path with white */ ppmd_fill_path(pixels, 100, 100, PPM_MAXMAXVAL, ppmd_pathbuilder_pathP(pathBuilderP), ppm_whitepixel(PPM_MAXMAXVAL)); /* Destroy the path */ ppmd_pathbuilder_destroy(pathBuilderP); \fP .fi .PP There are two ways to manage the space in which the leg array of the \fBppmd_path\fP structure resides. Either you supply a fixed-length array and the path builder just uses it or you have the path builder allocate the storage automatically. .PP If you let the path builder allocate the space automatically, you can nonetheless tell the path builder how much space to allocate initially, to make the path building more efficient. .PP This facility was new in Netpbm 10.78 (March 2017). Before that, you have to build the \fBppmd_path\fP by directly setting its members. .UN ppmd_pathbuilder_create .SS ppmd_path_builder .PP This creates a \fBppmd_path_builder\fP object (i.e. allocates memory for it and initializes it). You must ultimately destroy it with \fBppmd_path_builder_destroy\fP. .UN ppmd_pathbuilder_destroy .SS ppmd_path_builder_destroy .PP This destroys a \fBppmd_path_builder\fP object created with \fBppmd_path_builder_create\fP (i.e. frees the memory). .B Synopsis .nf \f(CW void ppmd_pathbuilder_destroy(ppmd_pathbuilder * pathBuilderP); \fP .fi .UN ppmd_pathbuilder_setLegArray .SS ppmd_pathbuilder_setLegArray .PP With this function you supply the array of legs that the path builder will fill. The array has a fixed size, so you must know in advance how long the path you build might be. .B Example .nf \f(CW ppmd_pathleg legs[4]; ppmd_pathbuilder_setLegArray(pathBuilderP, legs, 4); \fP .fi .B Synopsis .nf \f(CW void ppmd_pathbuilder_setLegArray(ppmd_pathbuilder * pathBuilderP, ppmd_pathleg * legs, unsigned int legCount); \fP .fi .B Description .PP \fIpathBuilderP\fP is the handle of the path builder object. .PP \fIlegs\fP is the array you are supplying for the object to fill in. This is just space; no value the array has upon invocation is meaningful. .PP \fIlegCount\fP is the number of elements of space exist in \fIlegs\fP. I.e. this is the maximum number of legs the builder can put in the array. Any attempt to put more legs than this in the array fails. .PP This fails if the leg array is already set up, which could be because you previously called \fBppmd_pathbuilder_setLegArray\fP, \fBppmd_pathbuilder_preallocLegArray\fP, or \fBppmd_pathbuilder_addLineLeg\fP. .UN ppmd_pathbuilder_preallocLegArray .SS ppmd_pathbuilder_preallocLegArray .PP This causes the object to allocate some space for the array of path legs the path builder will create. If it needs more space, it will reallocate. In fact, you need not call this at all, because the path builder will allocate space the first time it needs it. .B Synopsis .nf \f(CW void ppmd_pathbuilder_preallocLegArray(ppmd_pathbuilder * pathBuilderP, unsigned int legCount); \fP .fi .B Description .PP \fIpathBuilderP\fP is the handle of the path builder object. .PP \fIlegCount\fP is how many legs' worth of space to allocate. .PP This fails if the leg array is already set up, which could be because you previously called \fBppmd_pathbuilder_setLegArray\fP, \fBppmd_pathbuilder_preallocLegArray\fP, or \fBppmd_pathbuilder_addLineLeg\fP. .UN ppmd_pathbuilder_setBegPoint .SS ppmd_pathbuilder_setBegPoint .PP This sets the beginning point for the path. Note that to use the path for filling, you must also make this the point at which the last leg of the path ends. .B Synopsis .nf \f(CW void ppmd_pathbuilder_setBegPoint(ppmd_pathbuilder * pathBuilderP, ppmd_piont begPoint); \fP .fi .B Description .PP \fIpathBuilderP\fP is the handle of the path builder object. .PP \fIbegPoint\fP is the beginning point of the path. .UN ppmd_pathbuilder_addLineLeg .SS ppmd_pathbuilder_addLineLeg .PP This adds a line segment leg to the path. .B Synopsis .nf \f(CW void ppmd_pathbuilder_addLineLeg(ppmd_pathbuilder * pathBuilderP, ppmd_pathleg leg); \fP .fi .B Description .PP \fIpathBuilderP\fP is the handle of the path builder object. .PP \fIleg\fP is the leg to add. .PP The leg begins wherever the end of the path currently is (i.e. where the most recently added leg ends, or the beginning point if you have not added any paths yet). .UN ppmd_pathbuilder_pathP .SS ppmd_pathbuilder_pathP .PP This is a pointer to the path that the path builder has built. .B Synopsis .nf \f(CW void ppmd_pathbuilder_pathP(ppmd_pathbuilder * pathBuilderP); \fP .fi .B Description .PP \fIpathBuilderP\fP is the handle of the path builder object. .PP The data structure belongs to the path builder, so you must not use it after you have destroyed the \fBppmd_pathbuilder\fP object. .PP The pointer is valid only until you call the next path builder method other than \fBppmd_pathbuilder_pathP\fP. You normally don't get the pointer until you are done building the path. .UN fonts .SH Fonts .PP The \fBppmd_text\fP and \fBppmd_text_box\fP functions use fonts. You control the fonts using functions described in this section. There is one font that comes with Netpbm, called "standard". It is built into the function library and is the default font. You can create additional fonts and use them instead. .PP In a program that uses Netpbm drawing facilities, there is a "current font." all drawing of text uses the current font. When the program starts, the current font is "standard"; you can change it after that by calling the \fBppmd_set_font\fP function. .PP Other than a built-in font, a font lives in file in a format special to Netpbm called Ppmdfont. The file typically has a name that ends in ".ppmdfont". .PP Use the \fBppmddumpfont\fP program to dump the contents of a Ppmdfont file in human readable format. .PP Use the \fBppmdmkfont\fP program to generate the "standard" font as a Ppmdfont file. You don't normally need to do this, because "standard" is built into \fBlibnetpbm\fP. .PP Use the \fBppmdcfont\fP program to turn a Ppmdfont file into a C source file that you can compile into a program as a built-in font. Though we don't give full instructions here on how to do that, \fBlibnetpbm\fP's built-in "standard" font is a good example. In Netpbm source code, you will find the C source file \fBstandardppmdfont.c\fP, which was generated from the file \fBstandard.ppmdfont\fP by \fBppmdcfont\fP. You simply use a pointer to the structure that the C file defines as a font handle, just like one you would get from \fBppmd_read_font\fP. .UN fontfileformat .SH Font File Format .PP The font file starts with the characters "ppmdfont" (without the quotation marks) in ASCII. .PP The rest of the format is not yet documented, but it generally describes, for each code point, a sequence of straight line plotting commands to form the glyph for the indicated character. I.e. it is a vector, not raster, font. .UN fontcontrol .SH Font Control Functions .PP These functions are declared in the header file \fBppmdfont.h\fP. .SS \fBppmd_read_font\fP .PP This function associates a Ppmdfont file, which you identify by naming the Ppmdfont file, with a handle that you can use to identify the font to other functions. Technically, this function reads the font into memory. .SS \fBppmd_free_font\fP .PP This function releases the handle that you get from \fBppmd_read_font\fP. It frees resources associated with it; you can't use the handle after this. .SS \fBppmd_get_font\fP .PP This function returns the handle of the currently selected font. .SS \fBppmd_set_font\fP .PP This function sets the currently selected font. You identify the font to which to set it with a handle such as you get from \fBppmd_read_font\fP or \fBppmd_get_font\fP. .SH DOCUMENT SOURCE This manual page was generated by the Netpbm tool 'makeman' from HTML source. The master documentation is at .IP .B http://netpbm.sourceforge.net/doc/libnetpbm_draw.html .PP