Commits

Peter Froehlich committed 5e3532c

Import of release 0.1.1

  • Participants

Comments (0)

Files changed (16)

+mkhexgrid is written and maintained by Joel Uckelman <uckelman@nomic.net>.
+
+The following people have graciously provided assistance:
+
+Aaron Dalton: FreeBSD ports maintainer, documentation typos
+Steve Huff: OS X Fink maintainer, bug reports 
+Masaki Nakazawa: bug reports, Japanese translation of manual
+
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+mkhexgrid 0.1.1, 10 January 2007
+
+* Now builds properly on Mac OS X.
+* "%c" and "%r" coordinate formats are now rendered properly.
+* Coordinate bearing now defaults to 90 degrees instead of 0. 
+* Various corrections in the documentation.
+* Thanks to Steve Huff and Masaki Nakazawa for finding the bugs corrected
+  in this release.
+
+mkhexgrid 0.1.0, 6 August 2006
+* Initial release.
+DESTDIR=/usr/local
+BINDIR=$(DESTDIR)/bin
+DOCDIR=$(DESTDIR)/share/doc
+MANDIR=$(DESTDIR)/share/man
+
+VERSION=$(shell cat VERSION)
+RELEASE=$(shell sed -n 's/^Release: *\([0-9]*\)/\1/p' mkhexgrid.spec)
+DISTDIR=mkhexgrid-$(VERSION)
+RPMDIR=/home/uckelman/rpmbuild
+
+CC=g++
+CPPFLAGS=-c -g -O2 -W -Wall -DVERSION='"$(VERSION)"'
+LDFLAGS=-lm -lstdc++ -lgd
+
+FILES=grid.h \
+      grid.cpp \
+      mkhexgrid.cpp \
+      png.cpp \
+      ps.cpp \
+      svg.cpp \
+      Makefile \
+      Makefile.win32 \
+      doc/mkhexgrid.1 \
+      $(DOCS) \
+      VERSION
+
+DOCS=AUTHORS \
+     COPYING \
+     HISTORY \
+     README \
+     TODO \
+     doc/mkhexgrid.html
+
+.PHONY: all dist dist-rpm dist-windows dist-source install clean
+
+all: mkhexgrid
+
+mkhexgrid: mkhexgrid.o grid.o png.o ps.o svg.o
+
+mkhexgrid-web: mkhexgrid-web.o grid.o png.o ps.o svg.o split.o urldecode.o
+
+dist: dist-windows dist-source dist-rpm
+
+dist-windows: clean
+	$(MAKE) -f Makefile.win32 dist
+
+dist-rpm: dist-source
+	cp mkhexgrid-$(VERSION).src.tar.gz $(RPMDIR)/SOURCES
+	rpmbuild -ba mkhexgrid.spec
+	rpmbuild --clean --rmsource mkhexgrid.spec
+	mv $(RPMDIR)/RPMS/i386/mkhexgrid-$(VERSION)-$(RELEASE).* .
+	mv $(RPMDIR)/SRPMS/mkhexgrid-$(VERSION)-$(RELEASE).* .
+
+dist-source:
+	mkdir -p $(DISTDIR)
+	cp --parents $(FILES) $(DISTDIR)
+	tar czvf mkhexgrid-$(VERSION).src.tar.gz $(DISTDIR)
+	tar cjvf mkhexgrid-$(VERSION).src.tar.bz2 $(DISTDIR)
+	zip -9r mkhexgrid-$(VERSION).src.zip $(DISTDIR)
+	rm -rf $(DISTDIR)
+
+install:
+	install -m 755 -o 0 -g 0 -d $(BINDIR)
+	install -m 755 -o 0 -g 0 -s mkhexgrid $(BINDIR)
+	install -m 755 -o 0 -g 0 -d $(MANDIR)/man1
+	install -m 644 -o 0 -g 0 doc/mkhexgrid.1 $(MANDIR)/man1
+	install -m 755 -o 0 -g 0 -d $(DOCDIR)/mkhexgrid-$(VERSION) 
+	install -m 644 -o 0 -g 0 $(DOCS) $(DOCDIR)/mkhexgrid-$(VERSION)
+
+clean:
+	rm -rf mkhexgrid mkhexgrid-web mkhexgrid.o grid.o png.o ps.o svg.o \
+          mkhexgrid-$(VERSION).src.* mkhexgrid-$(VERSION).windows.zip \
+          mkhexgrid-$(VERSION)-$(RELEASE).*.rpm $(DISTDIR)

File Makefile.win32

+MINGW=/home/uckelman/projects/board/build/mingw
+LIBGD=/home/uckelman/projects/mkhexgrid/gdwin32
+BOOST=/home/uckelman/projects/board/build/boost_1_33_1
+FREETYPE=/home/uckelman/projects/mkhexgrid/freetype-2.1.10/bin
+
+VERSION=$(shell cat VERSION)
+
+CC=$(MINGW)/bin/i686-mingw32-g++
+CXX=$(MINGW)/bin/i686-mingw32-g++
+CPPFLAGS=-c -g -O2 -W -Wall -I$(LIBGD) -I$(BOOST) -DVERSION='"$(VERSION)"'
+LDFLAGS=-lm -lstdc++ -s 
+
+DISTDIR=mkhexgrid-$(VERSION)
+
+TXTDOCS=AUTHORS \
+        COPYING \
+        HISTORY \
+        README \
+        TODO \
+        VERSION
+
+DOCS=$(TXTDOCS) \
+     doc/mkhexgrid.html
+
+LICENSES=$(LIBGD)/gd-license.txt \
+         $(LIBGD)/libpng-license.txt \
+         $(LIBGD)/libfreetype-license.txt \
+         $(LIBGD)/libjpeg-license.txt \
+         $(LIBGD)/zlib-license.txt
+
+FILES=mkhexgrid.exe \
+      $(LIBGD)/bgd.dll \
+      $(FREETYPE)/freetype6.dll \
+      $(DOCS) \
+      $(LICENSES)
+
+.PHONY: all dist clean
+
+all: mkhexgrid.exe
+
+mkhexgrid.exe: mkhexgrid.o grid.o png.o ps.o svg.o $(LIBGD)/libbgd.a
+	$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
+
+dist: mkhexgrid.exe
+	mkdir -p $(DISTDIR)
+	cp $(FILES) $(DISTDIR)
+	cd $(DISTDIR)
+	unix2dos $(TXTDOCS)
+	cd ..
+	zip -9r mkhexgrid-$(VERSION).windows.zip $(DISTDIR)
+	rm -rf $(DISTDIR)
+
+clean:
+	rm -rf mkhexgrid.exe *.o mkhexgrid-$(VERSION).zip $(DISTDIR)
+********************************************************************************
+*                                                                              *
+*                                   mkhexgrid                                  *
+*                                 version 0.1.1                                *
+*                                 Joel Uckelman                                *
+*                                10 January 2007                               *
+*                                                                              *
+********************************************************************************
+
+mkhexgrid is a small, command-line program which generates hex grids of the
+sort used for strategy games.
+
+USAGE
+
+For usage information, see the included documentation, either mkhexgrid.html
+(all platforms) or the man page (unix only).
+
+INSTALLATION
+
+Windows:
+
+Windows users are recommended to use the pre-built version of mkhexgrid.
+No installation is necessary beyond unpacking the ZIP archive.
+
+Unix (including MacOS X):
+
+Binary and source RPMs are provided for users of RPM-based Linux
+distributions. FreeBSD users may build mkhexgrid using the ports system.
+MaxOS X users may build mkhexgrid using Fink (see
+http://fink.sourceforge.net). Other Unix users are recommended to build
+mkhexgrid from source. This should be a near-trivial process in most cases.
+See the next section, Building From Source.
+
+Building From Source:
+
+1. mkhexgrid has been successfully built using GCC on Unix and the
+MinGW port of GCC on Windows. mkhexgrid uses GNU getopt, so building
+mkhexgrid using any compiler which lacks a compatible getopt
+implementation will involve modifying the code somewhat.
+
+2. mkhexgrid requires the Boost and GD libraries. Boost is available
+from http://www.boost.org, and does not need to be built itself, as
+mkhexgrid relies only on headers from Boost. GD is available from
+http://www.libgd.org. mkhexgrid uses GD as the graphics drawing library
+for PNG output. Many Linux and BSD systems will already have Boost
+and GD installed.
+
+3. Build mkhexgrid.
+
+On Unix:
+
+   make
+   make install
+
+On Windows:
+
+   make -f Makefile.win32
+
+You must check that the paths defined in the Makefile are correct for
+your compiler and libraries, and also that you have getopt.h. (MinGW
+does, MSVC++ does not.)
+
+ANNOUNCEMENTS
+
+New versions of mkhexgrid are announced on the
+   
+   mkhexgrid-announce@nomic.net
+
+mailing list. To subscribe, send a message to
+   
+   mkhexgrid-announce-request@nomic.net
+
+with the word 'subscribe' in the message body.
+
+BUGS AND PROBLEMS
+
+Please report bugs, problems, and suggestions to mkhexgrid-bugs@nomic.net.
+
+mkhexgrid TODO list:
+
+* Grid thickness must be 1px with antialiased PNG output due to a limitation
+  in libgd, which we use for PNG drawing. In order to fix this, we need
+  either to write a custom routine for drawing thick antialiased lines or
+  get such a routine added to libgd.
+
+* It would be nice if common paper sizes (letter, legal, A4, D) could be
+  given for the image size for PostScript output.
+
+* Add a center thickness option for cross centers.
+
+* PDF output.
+
+* Do some other check for GDFONTPATH on Windows. Fonts are not always in
+  C:\Windows\Fonts.
+
+* Include tutorial in package. Expand tutorial.
+
+* Include Japanese translation of manual in package.
+
+0.1.1

File doc/mkhexgrid.1

+.\" Process this file with
+.\" groff -man -Tascii mkhexgrid.1
+.\"
+.TH MKHEXGRID 1 "January 2007" "mkhexgrid 0.1.1"
+
+.SH NAME
+mkhexgrid \- make hexagonal grids
+
+.SH SYNOPSIS
+.B mkhexgrid
+.RI [ OPTION "]... [" specfile "[ " outfile ]]
+
+.SH DESCRIPTION
+mkhexgrid creates hexagonal grids in PNG, PostScript, and Scalable Vector
+Graphics (SVG) formats, optionally labeled with coordinates and hex centers.
+.I specfile
+is the name of the file containing hex grid parameters and
+.I outfile
+is the name of the file into which output is written. If
+.I outfile
+is not specified, output will be written to standard output. If
+.I specfile
+is not specified, grid parameters may be read from standard input.
+
+.SH OPTIONS
+.SS Option Syntax
+
+mkhexgrid uses GNU getopt to process command-line arguments. Each option may be given as
+.B --option-name
+for options which take no arguments, or as
+\fB--option-name\fR=\fIargument\fR
+for options which take arguments.
+
+Lengths and sizes are in pixels for PNG and SVG output and are given without specifying the unit. Lengths and sizes may be specified in inches, millimeters, or points (as in, mm, or pt) for PostScript output, and default to points when no unit is given. (1in = 72pt = 25.4mm) Lengths and sizes for PNG output must be integers, with the exception of coordinate size, which may be a decimal. All angles are given as decimals in degrees.
+
+Colors are given in hexadecimal RRGGBB format for PNG and SVG output (e.g., FFFFFF is white, 8C6AC6 is a shade of purple). Colors are given as R,G,B triples for PostScript output, where R, G, and B are values in the interval [0,1] (e.g., 1,0,0 is red, and 0.8,0.8,0.8 is a light grey).
+
+Opacity ranges over integers in [0,127] for PNG output, reals in [0,1] for SVG output, and is ignored for PostScript output.
+
+.SS Output Options
+.TP
+.B --antialias
+Turn on antialiased output. This option has effect for PNG output only, since PostScript and SVG are antialiased by nature.
+
+.TP
+\fB-o\fR \fIfilename\fR, \fB--outfile\fR=\fIfilename\fR
+Write output to the file called \fIfilename\fR. The default is to print to standard output if no output filename is given or if a dash (-) is given as the filename. To write to a file named -, give ./- as the filename.
+
+.TP
+\fB--output\fR=\fItype\fR
+Set the output type to \fItype\fR. Permissible values are 'png' for PNGs, 'ps' for PostScript, and 'svg' for SVG.
+
+.SS Grid Options
+Not all of hex width, hex height, hex side, image width, image height, rows, and columns need be given in order to draw a grid. A grid will be drawn so long as enough of these are specified so that the ones omitted may be calculated.
+
+.TP
+\fB--hex-width\fR=\fIlength\fR
+Set the width of hexes to \fIlength\fR.
+
+.TP
+\fB--hex-height\fR=\fIlength\fR
+Set the height of hexes to \fIlength\fR.
+
+.TP
+\fB--hex-side\fR=\fIlength\fR
+Set the length of hex sides to \fIlength\fR.
+
+.TP
+\fB--image-width\fR=\fIlength\fR
+Set the width of the image to \fIlength\fR.
+
+.TP
+\fB--image-height\fR=\fIlength\fR
+Set the height of the image to \fIlength\fR.
+
+.TP
+\fB--image-margin\fR=\fIm\fR, \fB--image-margin\fR=\fIt,r,b,l\fR
+The first form sets all four margins to \fIm\fR. The second form proceeds clockwise to set the top, right, bottom, and left margins individually to \fIt\fR, \fIr\fR, \fIb\fR, and \fIl\fR, respectively.
+
+.TP
+\fB--centered\fR
+Center grid with respect to the image boundaries less the image margins. Useful when rows and columns are calculated rather than specified.
+
+.TP
+\fB--rows\fR=\fIn\fR
+Draw \fIn\fR rows of hexes. \fIn\fR must be a positive integer.
+
+.TP
+\fB--columns\fR=\fIn\fR
+Draw \fIn\fR columns of hexes. \fIn\fR must be a positive integer.
+
+.TP
+\fB--grid-color\fR=\fIcolor\fR
+Set the color of the grid lines. Default is 50% grey: 808080 for PNG and SVG output, 0.5,0.5,0.5 for PostScript output.
+
+.TP
+\fB--grid-opacity\fR=\fIopacity\fR
+Set the opacity of the grid lines. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.
+
+.TP
+\fB--grid-thickness\fR=\fIsize\fR
+Set the thickness of the grid lines to \fIsize\fR. Defaults to 1px for PNG and SVG output, and 1pt for PostScript. This option is ignored for antialiased PNG output, due to limitations of the underlying GD drawing library.
+
+.TP
+\fB--grid-grain\fR=\fIgrain\fR
+Set the grain of the hex grid. Permissible values are 'h' for horizontal and 'v' for vertical. With horizontal grain, the rows are straight and the columns wavy; vertical grain is the opposite, and is the default.
+
+.TP
+\fB--grid-start\fR=\fIstart\fR
+If the grain is vertical, set whether the first column starts in or out. If the grain is horizontal, set whether the first row starts in or out. Permissible values are 'i' for in, or 'o' for out. Which column or row is the first is fixed by the coordinate origin.
+
+.SS Coordinate Options
+These options affect the appearance and placement of coordinates within hexes.
+
+.TP
+\fB--coord-color\fR=\fIcolor\fR
+Set the color of the hex coordinates. Default is 50% grey: 808080 for PNG and SVG output, 0.5,0.5,0.5 for PostScript output.
+
+
+.TP
+\fB--coord-opacity\fR=\fIopacity\fR
+Set the opacity of the hex coordinates. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.
+
+.TP
+\fB--coord-format\fR=\fIformat\fR
+Set the format of the hex coordinates. The format string syntax is similar to that used by the
+.BR printf (3)
+function in C. The following special markers cause values to be substituted into the format string where they appear:
+
+    \fB%c\fR
+        Prints the hex column as a number.
+    \fB%r\fR
+        Prints the hex row as a number.
+    \fB%C\fR
+        Prints the hex column as a capital letter.
+    \fB%R\fR
+        Prints the hex row as a capital letter.
+
+The field width can be specified for numeric types by inserting a number between the % and the format letter; numeric types can be zero-padded by prepending a 0 to the field width. The alphabetic formats count AB as the successor of AA by default; tally-like counting where BB is the successor of AA can be specified by inserting a t before the format letter. A percent sign may be specified by %%. The default format is %02c%02r. Coordinates may be disabled by giving an empty string ("") as the format.
+
+.TP
+\fB--coord-font\fR=\fIfont\fR
+Set the font for coordinate text.
+
+.TP
+\fB--coord-size\fR=\fIsize\fR
+Set the size, in points, of the coordinate text. Defaults to 8px for SVG, 8pt for PNG and PostScript. This is the only length or size which is measured in points for PNG output.
+
+.TP
+\fB--coord-bearing\fR=\fItheta\fR
+Place coordinates at \fItheta\fR degrees counterclockwise from the hex center. The default bearing is 90 degrees, vertically above the hex center.
+
+.TP
+\fB--coord-distance\fR=\fIlength\fR
+Place coordinates \fIlength\fR away from the hex center. Defaults to 0.
+
+.TP
+\fB--coord-tilt\fR=\fItheta\fR
+Tilt coordinates at \fItheta\fR degrees counterclockwise from the horizontal. The default tilt is 0 degrees, which yields horizontal text.
+
+.TP
+\fB--coord-column-skip\fR=\fIn\fR
+Print coordinates only for columns divisible by \fIn\fR. The default is 1, which prints coordinates for all columns.
+
+.TP
+\fB--coord-row-skip\fR=\fIn\fR
+Print coordinates only for rows divisible by \fIn\fR. The default is 1, which prints coordinates for all rows.
+
+.TP
+\fB--coord-column-start\fR=\fIn\fR
+Number columns starting from \fIn\fR. The default is 1.
+
+.TP
+\fB--coord-row-start\fR=\fIn\fR
+Number rows starting from \fIn\fR. The default is 1.
+
+.TP
+\fB--coord-origin\fR=\fIcorner\fR
+Set location of coordinate origin. Permissible locations are 'ul' for upper left, 'ur' for upper right, 'll' for lower left, and 'lr' for lower right. Upper left is the default.
+
+.SS Hex Center Options
+
+.TP
+
+.TP
+\fBcenter-style\fR=\fIstyle\fR
+Set style of hex centers to \fIstyle\fR. Permissible styles are 'n' for none, 'd' for dots, and 'c' for crosses.
+
+.TP
+\fBcenter-color\fR=\fIcolor\fR
+Set the color of hex centers. Default is 50% grey: 808080 for PNG and SVG output, 0.5,0.5,0.5 for PostScript output.
+
+.TP
+\fBcenter-opacity\fR=\fIopacity\fR
+Set the opacity of hex centers. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.
+
+.TP
+\fBcenter-size\fR=\fIsize\fR
+Set the size of hex centers to \fIsize\fR. Defaults to 3px for PNG and SVG, 3pt for PostScript. Center size must be an integer for PNG output.
+
+.SS Background Options
+
+.TP
+\fB--bg-color\fR=\fIcolor\fR
+Set the background color. Defaults to FFFFFF for PNG output, and to none for SVG and PostScript output.
+
+.TP
+\fB--bg-opacity\fR=\fIopacity\fR
+Set the background opacity. Default is fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.
+
+.TP
+\fB--matte\fR
+Prevent the background from extending into the image margins.
+
+.SS Miscellaneous Options
+
+.TP
+\fB--\fR
+Terminates the list of options. Arguments which appear after a \fB--\fR will not be interpreted as options. This is useful if you want to read a specfile the name of which begins with two dashes.
+
+.TP
+\fB--help\fR
+Display help and exit.
+
+.TP
+\fB--version\fR
+Display version information and exit.
+
+.SS Specfile Syntax
+
+Due to the large number of options which may be necessary to generate a single hex grid, users may also specify hex grid parameters in a specfile which can be read from standard input or named as the first non-option argument on the command line. A specfile contains =-separated option/value pairs, one pair per line. Comments may be preceded by a #, either following an option/value pair or on lines by themselves. Values containing spaces must be double-quoted. Double quotation marks may be included in quoted values by preceding them with a backslash. Options which require no value on the command line must be given a dummy value in a specfile. Options given on the command line override options given in a specfile.
+
+Example:
+
+   # specfile example
+   output = png
+   hex-side = 30     # this is an end-of-line comment
+   coord-format = "%C\\" %02r"
+   antialias = true  # 'true' is a dummy value 
+
+Here, the coordinate format will produce coordinates like A" 01, which isn't something anyone is likely to want, but it illustrates how to include spaces and quotation marks in a quoted value.
+
+.SH EXAMPLES
+
+Fill a 22"x34" sheet with 0.5" hexes, horizontal grain:
+
+.RS 4
+mkhexgrid --output=ps --image-width=34in --image-height=22in --hex-side=0.5in --coord-bearing=0 --coord-dist=0.3in --coord-size=8 --grid-thickness=1 --coord-font=Helvetica --grid-grain=h --grid-start=o --coord-tilt=-90 --centered -o test.ps
+
+.SH AVAILABILITY
+
+mkhexgrid is available from 
+
+         http://www.nomic.net/~uckelman/mkhexgrid.
+
+New releases of mkhexgrid are announced on the
+      
+         mkhexgrid-announce@nomic.net
+
+mailing list. To join, send a message to
+
+         mkhexgrid-announce-request@nomic.net
+
+with the word \fIsubscribe\fR in the message body.
+
+.SH AUTHOR
+
+Written by Joel Uckelman <uckelman@nomic.net>.
+ 
+.SH BUGS
+
+Please report bugs to <mkhexgrid-bugs@nomic.net>.
+
+.SH COPYRIGHT
+
+Copyright \(co 2006, 2007 Joel Uckelman.
+
+This is free software. You may redistribute copies of it under the terms of the GNU General Public License. There is NO WARRANTY, to the extent permitted by law.

File doc/mkhexgrid.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+   <title>mkhexgrid 0.1.1</title>
+   <style type="text/css">
+      body   { margin-left: 10%; margin-right: 10%; }
+      dt.b   { font-weight: bold; }
+      pre    { margin-left: 4em; margin-right: 4em; }
+   </style>
+</head>
+<body>
+<h1>mkhexgrid 0.1.1</h1>
+
+<h2>NAME</h2>
+<p>mkhexgrid &mdash; make hexagonal grids</p>
+
+<h2>SYNOPSIS</h2>
+<p>mkhexgrid [<em>option</em>]... [<em>specfile</em> [<em>outfile</em>]]</p>
+
+<h2>DESCRIPTION</h2>
+<p>mkhexgrid creates hexagonal grids in PNG, PostScript, and Scalable Vector Graphics (SVG) formats, optionally labeled with coordinates and hex centers. <em>specfile</em> is the name of the file containing hex grid parameters and <em>outfile</em> is the name of the file into which output is written. If <em>outfile</em> is not specified, output will be written to standard output. If <em>specfile</em> is not specified, grid parameters may be read from standard input.</p>
+
+<h2>OPTIONS</h2>
+<h3>Option Syntax</h3>
+<p>mkhexgrid uses GNU getopt to process command-line arguments. Each option may be given as <code>--option-name</code> for options which take no arguments, or as <code>--option-name=argument</code> for options which take arguments.</p>
+
+<p>Lengths and sizes are in pixels for PNG and SVG output and are given without specifying the unit. Lengths and sizes may be specified in inches, millimeters, or points (as <code>in</code>, <code>mm</code>, or <code>pt</code>) for PostScript output, and default to points when no unit is given. (1in = 72pt = 25.4mm) Lengths and sizes for PNG output must be integers, with the exception of coordinate size, which may be a decimal. All angles are given as decimals in degrees.</p>
+
+<p>Colors are given in hexadecimal RRGGBB format for PNG and SVG output (e.g., <code>FFFFFF</code> is white, <code>8C6AC6</code> is a shade of purple). Colors are given as R,G,B triples for PostScript output, where R, G, and B are values in the interval [0,1] (e.g., <code>1,0,0</code> is red, and <code>0.8,0.8,0.8</code> is a light grey).</p>
+
+<p>Opacity ranges over integers in [0,127] for PNG output, reals in [0,1] for SVG output, and is ignored for PostScript output.</p>
+
+<h3>Output Options</h3>
+<dl>
+   <dt><b>--antialias</b></dt>
+      <dd>Turn on antialiased output. This option has effect for PNG output only, since PostScript and SVG are antialiased by nature.</dd>
+   <dt><b>-o</b> <em>filename</em>, <b>--outfile</b>=<em>filename</em></dt>
+      <dd>Write output to the file called <em>filename</em>. The default is to print to standard output if no output filename is given or if a dash (<code>-</code>) is given as the filename. To write to a file named <code>-</code>, give <code>./-</code> as the filename.</dd>
+   <dt><b>--output</b>=<em>type</em></dt>
+      <dd>Set the output type to <em>type</em>. Permissible values are <code>png</code> for PNGs, <code>ps</code> for PostScript, and <code>svg</code> for SVG.</dd>
+</dl>
+
+<h3>Grid Options</h3>
+<p>Not all of hex width, hex height, hex side, image width, image height, rows, and columns need be given in order to draw a grid. A grid will be drawn so long as enough of these are specified so that the ones omitted may be calculated.</p>
+<dl>
+   <dt><b>--hex-width</b>=<em>length</em></dt>
+      <dd>Set the width of hexes to <em>length</em>.</dd>
+   <dt><b>--hex-height</b>=<em>length</em></dt>
+      <dd>Set the height of hexes to <em>length</em>.</dd>
+   <dt><b>--hex-side</b>=<em>length</em></dt>
+      <dd>Set the length of hex sides to <em>length</em>.</dd>
+   <dt><b>--image-width</b>=<em>length</em></dt>
+      <dd>Set the width of the image to <em>length</em>.</dd>
+   <dt><b>--image-height</b>=<em>length</em></dt>
+      <dd>Set the height of the image to <em>length</em>.</dd>
+   <dt><b>--image-margin</b>=<em>m</em></dt>
+   <dt><b>--image-margin</b>=<em>t,r,b,l</em></dt>
+      <dd>The first form sets all four margins to <em>m</em>. The second form proceeds clockwise to set the top, right, bottom, and left margins individually to <em>t</em>, <em>r</em>, <em>b</em>, and <em>l</em>, respectively.</dd>
+   <dt><b>--centered</b></dt>
+      <dd>Center grid with respect to the image boundaries less the image margins. Useful when rows and columns are calculated rather than specified.</dd>
+   <dt><b>--rows</b>=<em>n</em></dt>
+      <dd>Draw <em>n</em> rows of hexes. <em>n</em> must be a positive integer.</dd>
+   <dt><b>--columns</b>=<em>n</em></dt>
+      <dd>Draw <em>n</em> columns of hexes. <em>n</em> must be a positive integer.</dd>
+   <dt><b>--grid-color</b>=<em>color</em></dt>
+      <dd>Set the color of the grid lines. Default is 50% grey: <code>808080</code> for PNG and SVG output, <code>0.5,0.5,0.5</code> for PostScript output.</dd>
+   <dt><b>--grid-opacity</b>=<em>opacity</em></dt>
+      <dd>Set the opacity of the grid lines. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.</dd>
+   <dt><b>--grid-thickness</b>=<em>size</em></dt>
+      <dd>Set the thickness of the grid lines to <em>size</em>. Defaults to 1px for PNG and SVG output, and 1pt for PostScript. This option is ignored for antialiased PNG output, due to limitations of the GD drawing library.</dd>
+   <dt><b>--grid-grain</b>=<em>grain</em></dt>
+      <dd>Set the grain of the hex grid. Permissible values are <code>h</code> for horizontal and <code>v</code> for vertical. With horizontal grain, the rows are straight and the columns wavy; vertical grain is the opposite, and is the default.</dd>
+   <dt><b>--grid-start</b>=<em>start</em></dt>
+      <dd>If the grain is vertical, set whether the first column starts in or out. If the grain is horizontal, set whether the first row starts in or out. Permissible values are <code>i</code> for in, or <code>o</code> for out. Which column or row is the first is fixed by the coordinate origin.</dd>
+</dl>
+
+<h3>Coordinate Options</h3>
+<p>These options affect the appearance and placement of coordinates within hexes.</p>
+<dl>
+   <dt><b>--coord-color</b>=<em>color</em></dt>
+      <dd>Set the color of the hex coordinates. Default is 50% grey: <code>808080</code> for PNG and SVG output, <code>0.5,0.5,0.5</code> for PostScript output.</dd>
+   <dt><b>--coord-opacity</b>=<em>opacity</em></dt>
+      <dd>Set the opacity of the hex coordinates. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.</dd>
+   <dt><b>--coord-format</b>=<em>format</em></dt>
+      <dd>Set the format of the hex coordinates. The format string syntax is similar to that used by the <code>printf()</code> function in C. The following special markers cause values to be substituted into the format string where they appear:
+         <dl>
+            <dt><b>%c</b></dt>
+               <dd>Prints the hex column as a number.</dd>
+            <dt><b>%r</b></dt>
+               <dd>Prints the hex row as a number.</dd>
+            <dt><b>%C</b></dt>
+               <dd>Prints the hex column as a capital letter.</dd>
+            <dt><b>%R</b></dt>
+               <dd>Prints the hex row as a capital letter.</dd>
+         </dl>
+The field width can be specified for numeric types by inserting a number between the <code>%</code> and the format letter; numeric types can be zero-padded by prepending a <code>0</code> to the field width. The alphabetic formats count <code>AB</code> as the successor of <code>AA</code> by default; tally-like counting where <code>BB</code> is the successor of <code>AA</code> can be specified by inserting a <code>t</code> before the format letter. A percent sign may be specified by <code>%%</code>. The default format is <code>%02c%02r</code>. Coordinates may be disabled by giving an empty string (<code>""</code>) as the format.</dd>
+   <dt><b>--coord-font</b>=<em>font</em></dt>
+      <dd>Set the font for coordinate text.</dd>
+   <dt><b>--coord-size</b>=<em>size</em></dt>
+      <dd>Set the size, in points, of the coordinate text. Defaults to 8px for SVG, 8pt for PNG and PostScript. This is the only length or size which is measured in points for PNG output.</dd>
+   <dt><b>--coord-bearing</b>=<em>theta</em></dt>
+      <dd>Place coordinates at <em>theta</em> degrees counterclockwise from the hex center. The default bearing is 90 degrees, vertically above the hex center.</dd>
+   <dt><b>--coord-distance</b>=<em>length</em></dt>
+      <dd>Place coordinated <em>length</em> away from the hex center. Defaults to 0.</dd>
+   <dt><b>--coord-tilt</b>=<em>theta</em></dt>
+      <dd>Tilt coordinates at <em>theta</em> degrees counterclockwise from the horizontal. The default tilt is 0 degrees, which yields horizontal text.</dd>
+   <dt><b>--coord-column-skip</b>=<em>n</em></dt>
+      <dd>Print coordinates only for columns divisible by <em>n</em>. The default is 1, which prints coordinates for all columns.</dd>
+   <dt><b>--coord-row-skip</b>=<em>n</em></dt>
+      <dd>Print coordinates only for rows divisible by <em>n</em>. The default is 1, which prints coordinates for all rows.</dd>
+   <dt><b>--coord-column-start</b>=<em>n</em></dt>
+      <dd>Number columns starting from <em>n</em>. The default is 1.</dd>
+   <dt><b>--coord-row-start</b>=<em>n</em></dt>
+      <dd>Number rows starting from <em>n</em>. The default is 1.</dd>
+   <dt><b>--coord-origin</b>=<em>corner</em></dt>
+      <dd>Set location of coordinate origin. Permissible locations are <code>ul</code> for upper left, <code>ur</code> for upper right, <code>ll</code> for lower left, and <code>lr</code> for lower right. Upper left is the default.</dd>
+</dl>
+
+<h3>Hex Center Options</h3>
+<dl>
+   <dt><b>--center-style</b>=<em>style</em></dt>
+      <dd>Set style of hex centers to <em>style</em>. Permissible styles are <code>n</code> for none, <code>d</code> for dots, and <code>c</code> for crosses.</dd>
+   <dt><b>--center-color</b>=<em>color</em></dt>
+      <dd>Set the color of hex centers. Default is 50% grey: <code>808080</code> for PNG and SVG output, <code>0.5,0.5,0.5</code> for PostScript output.</dd>
+   <dt><b>--center-opacity</b>=<em>opacity</em></dt>
+      <dd>Set the opacity of hex centers. Defaults to fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.</dd>
+   <dt><b>--center-size</b>=<em>size</em></dt>
+      <dd>Set the size of hex centers to <em>size</em>. Defaults to 3px for PNG and SVG, 3pt for PostScript. Center size must be an integer for PNG output.</dd>
+</dl>
+
+<h3>Background Options</h3>
+<dl>
+   <dt><b>--bg-color</b>=<em>color</em></dt>
+      <dd>Set the background color. Defaults to <code>FFFFFF</code> for PNG output, and to none for SVG and PostScript output.</dd>
+   <dt><b>--bg-opacity</b>=<em>opacity</em></dt>
+      <dd>Set the background opacity. Default is fully opaque: 0 for PNG output, 1 for SVG output, and is ignored for PostScript output.</dd>
+   <dt><b>--matte</b></dt>
+      <dd>Prevent the background from extending into the image margins.</dd>
+</dl>
+
+<h3>Miscellaneous Options</h3>
+<dl>
+   <dt><b>--</b></dt>
+      <dd>Terminates the list of options. Arguments which appear after a <code>--</code> will not be interpreted as options. This is useful if you want to read a specfile the name of which begins with two dashes.</dd>
+   <dt><b>--help</b></dt>
+      <dd>Display help and exit.</dd>
+   <dt><b>--version</b></dt>
+      <dd>Display version information and exit.</dd>
+</dl>
+
+<h3>Specfile Syntax</h3>
+<p>Due to the large number of options which may be necessary to generate a single hex grid, users may also specify hex grid parameters in a specfile which can be read from standard input or named as the first non-option argument on the command line. A specfile contains <code>=</code>-separated option/value pairs, one pair per line. Comments may be preceded by a <code>#</code>, either following an option/value pair or on lines by themselves. Values containing spaces must be double-quoted. Double quotation marks may be included in quoted values by preceding them with a backslash. Options which require no value on the command line must be given a dummy value in a specfile. Options given on the command line override options given in a specfile.</p>
+
+<p>Example:</p>
+<pre>
+# specfile example
+output = png
+hex-side = 30     # this is an end-of-line comment
+coord-format = "%C\" %02r"
+antialias = true  # 'true' is a dummy value 
+</pre>
+<p>Here, the coordinate format will produce coordinates like <code>A" 01</code>, which isn't something anyone is likely to want, but it illustrates how to include spaces and quotation marks in a quoted value.</p>
+
+<h2>EXAMPLES</h2>
+<dl>
+<dt>Fill a 22"x34" sheet with 0.5" hexes, horizontal grain:</dt>
+   <dd><code>mkhexgrid --output=ps --image-width=34in --image-height=22in --hex-side=0.5in --coord-bearing=0 --coord-dist=0.3in --coord-size=8 --grid-thickness=1 --coord-font=Helvetica --grid-grain=h --grid-start=o --coord-tilt=-90 --centered -o test.ps</code></dd>
+</dl>
+
+<h2>AVAILABILITY</h2>
+<p>mkhexgrid is available from
+<blockquote><a href="http://www.nomic.net/~uckelman/mkhexgrid">http://www.nomic.net/~uckelman/mkhexgrid</a></blockquote>
+New releases of mkhexgrid are announced on the
+<blockquote><a href="mailto:mkhexgrid-announce@nomic.net">mkhexgrid-announce@nomic.net</a></blockquote>
+mailing list. To join, send a message to
+<blockquote><a href="mkhexgrid-announce-request@nomic.net">mkhexgrid-announce-request@nomic.net</a></blockquote>
+with the word <code>subscribe</code> in the message body.</p>
+
+<h2>AUTHOR</h2>
+<p>Written by Joel Uckelman &lt;<a href="mailto:uckelman@nomic.net">uckelman@nomic.net</a>&gt;.</p>
+
+<h2>BUGS</h2>
+<p>Please report bugs to &lt;<a href="mailto:mkhexgrid-bugs@nomic.net">mkhexgrid-bugs@nomic.net</a>&gt;.</p>
+
+<h2>COPYRIGHT</h2>
+<p>Copyright &copy; 2006, 2007 Joel Uckelman.</p>
+<p>This is free software. You may redistribute copies of it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>. There is NO WARRANTY, to the extent permitted by law.</p>
+
+</body>
+</html>
+// $Id$
+/* mkhexgrid -- generates hex grids
+ * Copyright (C) 2006 Joel Uckelman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <cmath>
+#include <iostream>
+#include <iomanip>
+#include <map>
+#include <string>
+#include <exception>
+#include <stdexcept>
+using namespace std;
+
+#include <boost/lexical_cast.hpp>
+using namespace boost;
+
+#include "grid.h"
+
+const double Grid::rad = M_PI/180.0;
+
+Grid::Grid(const map<string, string> &opt)
+{
+   map<string, string>::const_iterator i;
+
+   // 
+   // Output Parameters
+   //
+   i = opt.find("output");
+   if (i == opt.end())          output = PNG;
+   else if (i->second == "png") output = PNG;
+   else if (i->second == "ps")  output = PS;
+   else if (i->second == "svg") output = SVG;
+   else throw runtime_error("unrecognized output type `" + i->second + "'");
+
+   i = opt.find("outfile");
+   if (i != opt.end()) outfile = i->second;
+
+   antialiased = (opt.find("antialias") != opt.end());
+   if (antialiased && output != PNG)
+      cerr << "PostScript and SVG output is always antialiased" << endl;
+
+   // NB: this works because 0 is opaque in PNG, 1 is opaque in SVG, and
+   // opacity is ignored in PostScript.
+   bg_opacity = grid_opacity =
+      coord_opacity = center_opacity = (output == SVG);
+
+   if (output == PS) 
+        grid_color = coord_color = center_color = "0.5 0.5 0.5";
+   else grid_color = coord_color = center_color = "808080";
+
+   if (output == PNG) bg_color = "ffffff";
+ 
+   //
+   // Grid Parameters
+   //
+   i = opt.find("grid-grain");
+   if (i == opt.end())        grain = Vertical;
+   else if (i->second == "h") grain = Horizontal;
+   else if (i->second == "v") grain = Vertical;
+   else
+      throw runtime_error("unrecognized grain direction `" + i->second + "'");
+
+   i = opt.find("grid-start");
+   if (i == opt.end())        lowfirstcol = false;
+   else if (i->second == "i") lowfirstcol = true;
+   else if (i->second == "o") lowfirstcol = false;
+   else throw runtime_error("unrecognized grid start `" + i->second + "'");
+
+   i = opt.find("grid-thickness");
+   if (i == opt.end()) grid_thickness = 1;
+   else parse_length("grid thickness", i->second, grid_thickness);
+   if (grid_thickness < 0)
+      throw range_error("grid thickness is negative");
+   if (output == PNG && grid_thickness != floor(grid_thickness))
+      throw runtime_error("grid thickness is not an integer");
+
+   i = opt.find("grid-color");
+   if (i != opt.end()) parse_color("grid color", i->second, grid_color);
+
+   i = opt.find("grid-opacity");
+   if (i != opt.end()) parse_opacity("grid opactiy", i->second, grid_opacity);
+
+   //
+   // Coordinate Parameters
+   //
+#ifdef WIN32
+   coord_font = "Arial";
+#else
+   coord_font = "sans";
+#endif
+   coord_bearing = 90;
+   coord_tilt = coord_dist = 0;
+   coord_size = 8; 
+
+   i = opt.find("coord-font");
+   if (i != opt.end()) coord_font = i->second;
+
+   i = opt.find("coord-bearing");
+   if (i != opt.end()) {
+      try {
+         coord_bearing = lexical_cast<double>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-bearing is not a number");
+      }
+   }
+
+   i = opt.find("coord-tilt");
+   if (i != opt.end()) {
+      try {
+         coord_tilt = lexical_cast<double>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-tilt is not a number");
+      }
+   }
+
+   i = opt.find("coord-distance");
+   if (i != opt.end())
+      parse_length("coordinate distance", i->second, coord_dist);
+
+   i = opt.find("coord-size");
+   if (i != opt.end())
+      parse_length("coordinate size", i->second, coord_size);
+   if (coord_size <= 0) throw range_error("coordinate size is not positive");
+      
+   i = opt.find("coord-origin");
+   if (i == opt.end())         coord_origin = UpperLeft;
+   else if (i->second == "ul") coord_origin = UpperLeft;
+   else if (i->second == "ll") coord_origin = LowerLeft;
+   else if (i->second == "ur") coord_origin = UpperRight;
+   else if (i->second == "lr") coord_origin = LowerRight;
+   else throw
+      runtime_error("unrecognized coordinate origin `" + i->second + "'"); 
+
+   coord_cskip = coord_rskip = coord_cstart = coord_rstart = 1;
+
+   i = opt.find("coord-column-skip");
+   if (i != opt.end()) {
+      try {
+         coord_cskip = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-column-skip is not an integer");
+      }
+      
+      if (coord_cskip == 0)
+         throw range_error("coord-column-skip is not positive");
+   }
+
+   i = opt.find("coord-row-skip");
+   if (i != opt.end()) {
+      try {
+         coord_rskip = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-row-skip is not an integer");
+      }
+
+      if (coord_rskip == 0)
+         throw range_error("coord-row-skip is not positive");
+   }
+
+   i = opt.find("coord-column-start");
+   if (i != opt.end()) {
+      try {
+         coord_cstart = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-column-start is not a nonnegative integer");
+      }
+   }
+
+   i = opt.find("coord-row-start");
+   if (i != opt.end()) {
+      try {
+         coord_rstart = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("coord-row-start is not a nonnegative integer");
+      }
+   }
+
+   // default format is equivalent to "%02c%02r"
+   coord_display = true;
+   coord_first_width = 2;
+   coord_second_width= 2;
+   coord_first_style = Number;
+   coord_second_style = Number;
+   coord_order = ColumnsFirst;
+   coord_first_fill = true;
+   coord_second_fill = true;
+   
+   i = opt.find("coord-format");
+   if (i != opt.end()) {
+      if (i->second.empty()) coord_display = false;
+      else parse_format(i->second);
+   }
+
+   i = opt.find("coord-color");
+   if (i != opt.end()) parse_color("coordinate color", i->second, coord_color);
+
+   i = opt.find("coord-opacity");
+   if (i != opt.end())
+      parse_opacity("coordinate opacity", i->second, coord_opacity);
+  
+   switch (output) {
+   case PNG:
+      // 90 degrees is down in GD, except for text
+      // for which 90 degrees is up!
+      coord_bearing = -coord_bearing;
+      break;
+   case PS:
+      coord_bearing -= 90;
+      break;
+   case SVG:
+      // 90 degrees is down in SVG
+      coord_bearing = -coord_bearing;
+      coord_tilt = -coord_tilt;
+      break;
+   }
+
+   //
+   // Center Parameters
+   //
+   center_size = 3;
+
+   i = opt.find("center-style");
+   if (i == opt.end())        center_style = Centerless;
+   else if (i->second == "c") center_style = Cross;
+   else if (i->second == "d") center_style = Dot;
+   else if (i->second == "n") center_style = Centerless;
+   else throw runtime_error("unrecognized center style `" + i->second + "'");
+
+   i = opt.find("center-size");
+   if (i != opt.end())
+      parse_length("center size", i->second, center_size);
+   if (center_size < 0)
+      throw range_error("center size is negative");
+   if (output == PNG && center_size != floor(center_size))
+      throw runtime_error("center size is not an integer");
+
+   i = opt.find("center-color");
+   if (i != opt.end()) parse_color("center color", i->second, center_color);
+
+   i = opt.find("center-opacity");
+   if (i != opt.end())
+      parse_opacity("center opacity", i->second, center_opacity);
+
+   //
+   // Background Parameters
+   // 
+   i = opt.find("bg-color");
+   if (i != opt.end()) parse_color("background color", i->second, bg_color);
+
+   i = opt.find("bg-opacity");
+   if (i != opt.end())
+      parse_opacity("background opacity", i->second, bg_opacity);
+
+   matte = (opt.find("matte") != opt.end());
+   if (matte && bg_color.empty())
+      cerr << "matte is useless without background color" << endl;
+
+   //
+   // Size Parameters
+   //
+   i = opt.find("image-margin");
+   if (i == opt.end()) mtop = mright = mbottom = mleft = 0;
+   else {
+      string str;
+      istringstream s(i->second);
+
+      getline(s, str, ',');
+      parse_length("image margin", str.c_str(), mtop);
+
+      // equal margins if only one length given
+      if (s.eof()) mright = mbottom = mleft = mtop;
+      else {
+         getline(s, str, ',');
+         parse_length("image margin", str.c_str(), mright);
+
+         getline(s, str, ',');
+         parse_length("image margin", str.c_str(), mbottom);
+
+         getline(s, str);
+         parse_length("image margin", str.c_str(), mleft);
+      }
+
+      if (s.fail() || !s.eof()) throw runtime_error(
+         "image margins must be given as a single "
+         "value or as four (t,r,b,l)");
+   }
+
+   hw = hh = hs = iw = ih = 0;
+   cols = rows = 0;
+
+   i = opt.find("hex-width");
+   if (i != opt.end()) parse_length("hex width", i->second, hw);
+
+   i = opt.find("hex-height");
+   if (i != opt.end()) parse_length("hex height", i->second, hh);
+   
+   i = opt.find("hex-side");
+   if (i != opt.end()) parse_length("hex side", i->second, hs);
+
+   i = opt.find("columns");
+   if (i != opt.end()) {
+      try {
+         cols = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("number of columns is not an integer");
+      }
+      if (cols == 0) throw range_error("number of columns is not positive");
+   }
+ 
+   i = opt.find("rows");
+   if (i != opt.end()) {
+      try {
+         rows = lexical_cast<unsigned int>(i->second);
+      }
+      catch (bad_lexical_cast &) {
+         throw runtime_error("number of rows is not an integer");
+      }
+      if (rows == 0) throw range_error("number of rows is not positive");
+   }
+
+   i = opt.find("image-width");
+   if (i != opt.end()) parse_length("image width", i->second, iw);
+
+   i = opt.find("image-height");
+   if (i != opt.end()) parse_length("image height", i->second, ih);
+
+   if (grain == Horizontal) {
+      swap(hw, hh);
+      swap(cols, rows);
+
+      // rotate margins
+      double tmp = mright;
+      mright = mtop;
+      mtop = mleft;
+      mleft = mbottom;
+      mbottom = tmp;
+   }
+
+   while (!hs || !hw || !hh || !cols || !rows || !iw || !ih) {
+      bool more = false;
+
+      if (!hs) {                       // calculate hs
+         if (hw) {
+            hs = hw/2;
+            more = true;
+         }
+         else if (hh) {                
+            hs = hh/(2*sin(60*rad));
+            more = true;
+         }
+      }
+   
+      if (!hw) {                       // calculate hw
+         if (hs) {
+            hw = 2*hs;
+            more = true;
+         }
+         else if (hh) {
+            hw = hh/sin(60*rad);
+            more = true;
+         }
+      }
+   
+      if (!hh) {                       // calculate hh
+         if (hs) {
+            hh = 2*hs*sin(60*rad);
+            more = true;
+         }
+         else if (hw) {
+            hh = hw*sin(60*rad);
+            more = true;
+         }
+      }
+   
+      if (hw && cols && !iw) {         // calculate iw
+         iw = mleft + (0.25+0.75*cols)*hw+grid_thickness + mright;
+         more = true;
+      }
+      else if (hw && !cols && iw) {    // calculate cols
+         cols = (int)floor(((iw-mleft-grid_thickness-mright)/hw - 0.25)/0.75); 
+         more = true;
+      }
+      else if (!hw && cols && iw) {    // calculate hw
+         hw = (iw-mleft-grid_thickness-mright)/(0.25+0.75*cols);
+         more = true;
+      }
+   
+      if (hh && rows && cols && !ih) {         // calculate ih
+         if (cols > 1) ih = mtop + (0.5+rows)*hh+grid_thickness + mbottom;
+         else ih = mtop + rows*hh + grid_thickness + mbottom;
+         more = true; 
+      }
+      else if (hh && !rows && cols && ih) {    // calculate rows
+         if (cols > 1)
+            rows = (int)floor((ih-mtop-grid_thickness-mbottom)/hh - 0.5);
+         else rows = (int)floor((ih-mtop-grid_thickness-mbottom)/hh);
+         more = true; 
+      }
+      else if (!hh && rows && cols && ih) {    // calculate hh
+         if (cols > 1) hh = (ih-mtop-grid_thickness-mbottom)/(0.5+rows);
+         else hh = (ih-mtop-grid_thickness-mbottom)/rows;
+         more = true; 
+      }
+
+      if (!more) break;
+   }
+   
+   if (!hs)
+      throw runtime_error("unable to determine hex side from given values");
+   if (!hw)
+      throw runtime_error("unable to determine hex width from given values");
+   if (!hh)
+      throw runtime_error("unable to determine hex height from given values");
+   if (!iw)
+      throw runtime_error("unable to determine image width from given values");
+   if (!ih)
+      throw runtime_error("unable to determine image height from given values");
+   if (!rows)
+      throw runtime_error("unable to determine rows from given values");
+   if (!cols)
+      throw runtime_error("unable to determine columns from given values");
+
+   // adjust for centering
+   if (opt.find("centered") != opt.end()) {
+      // calculate actual grid width, height
+      double aw = (0.25+0.75*cols)*hw+grid_thickness,
+             ah = (0.5+rows)*hh+grid_thickness;
+      
+      // margin adjustment
+      double h = ((iw - mleft - mright) - aw)/2,
+             v = ((ih - mtop - mbottom) - ah)/2; 
+
+      mleft   += h;
+      mright  += h;
+      mtop    += v;
+      mbottom += v;
+   }
+
+   if (grain == Horizontal) {
+      // unrotate margins
+      double tmp = mright;
+      mright = mbottom;
+      mbottom = mleft;
+      mleft = mtop;
+      mtop = tmp;
+
+      swap(iw, ih);
+
+      switch (output) {
+      case PS:
+         coord_bearing += 90;
+         coord_tilt += 90;
+         break;
+      case PNG:
+         coord_bearing -= 90;
+         coord_tilt += 90;
+         break;
+      case SVG:
+         coord_bearing -= 90;
+         coord_tilt -= 90;
+         break;
+      }
+      
+      switch (coord_origin) {
+      case UpperLeft:
+         coord_origin = LowerLeft;
+         lowfirstcol = !lowfirstcol;
+         break;
+      case LowerLeft:
+         coord_origin = LowerRight;
+         if (cols%2) lowfirstcol = !lowfirstcol;
+         break;
+      case UpperRight:
+         coord_origin = UpperLeft;
+         break;
+      case LowerRight:
+         coord_origin = UpperRight;
+         break;
+      }
+   }
+ 
+   // adjust lowfirstcol if even cols and coordinate origin on the right
+   if ((coord_origin == UpperRight || coord_origin == LowerRight) && !(cols%2))
+      lowfirstcol = !lowfirstcol;
+
+   // there is no wave with only one column
+   if (cols == 1) lowfirstcol = false;
+
+   // horizontal grain adjustments
+   if (grain == Horizontal) {
+      if (output == PS) swap(rows, cols);
+      else if (output == PNG) {
+         swap(iw, ih);
+      
+         // rotate margins
+         double tmp = mright;
+         mright = mtop;
+         mtop = mleft;
+         mleft = mbottom;
+         mbottom = tmp;
+
+         swap(mtop, mbottom);
+         swap(mleft, mright);
+      }
+   }
+
+   // clip angles to [0,360) for PNG output
+   if (output == PNG) {
+      coord_bearing = fmod(coord_bearing, 360);
+      if (coord_bearing < 0) coord_bearing += 360;
+      coord_tilt = fmod(coord_tilt, 360);
+      if (coord_tilt < 0) coord_tilt += 360;  
+   }
+}
+
+
+void Grid::draw()
+{
+   switch (output) {
+   case SVG:   draw_svg(); break;
+   case PNG:   draw_png(); break;
+   case PS:    draw_ps();  break;
+   }
+}
+
+
+string Grid::alpha(int m)
+{
+   // A ... Z AA AB ...
+   if (m < 27) return string(1, m > 0 ? m+64 : 'Z');
+   else return alpha((m-1)/26) + string(1, m % 26 ? (m % 26) + 64 : 'Z');
+}
+
+
+string Grid::alpha_tally(int m)
+{
+   // A ... Z AA BB ...
+   return string(int(ceil(m/26.0)), (m-1) % 26 + 65);
+}
+
+
+void Grid::parse_color(const char *o, const string &str, string &c)
+{
+   stringstream s(str);
+
+   if (output == PS) {
+      double r, g, b;
+      char c1, c2;
+      
+      s >> r >> c1 >> g >> c2 >> b;
+      if (s.fail() || !s.eof()  || c1 != ',' || c2 != ',') 
+         throw runtime_error("invalid color format for " + string(o));
+      if (r < 0 || r > 1) throw range_error("red value for " + string(o) +
+         "is not in the range [0,1]");
+      if (g < 0 || g > 1) throw range_error("green value for " + string(o) +
+         "is not in the range [0,1]");
+      if (b < 0 || b > 1) throw range_error("blue value for " + string(o) +
+         "is not in the range [0,1]");
+
+      s.clear();
+      s << r << ' ' << g << ' ' << b;
+   }
+   else {
+      unsigned int h;
+      
+      s >> hex >> h;
+      if (s.fail() || !s.eof())
+         throw runtime_error("invalid color format for " + string(o));
+    
+      if (h > 0xFFFFFF) throw range_error(string(o) +
+         " is not in the range [000000,FFFFFF]");
+ 
+      s.clear(); 
+      s << setfill('0') << setw(6) << hex << h;
+   }
+
+   c = s.str();
+}
+
+
+void Grid::parse_opacity(const char *o, const string &str, double &op)
+{
+   if (output == PS) {
+      cerr << "opacity ignored for PostScript output" << endl; 
+      return;
+   }
+
+   try {
+      op = lexical_cast<double>(str);
+   }
+   catch (bad_lexical_cast &) {
+      throw runtime_error(string(o) + " is not a number");
+   }
+
+   if (output == PNG) {
+      if (op < 0 || op > 127) throw range_error(string(o) +
+         " is not in the allowable range [0,127] for PNG output");
+      if (op != floor(op)) throw runtime_error(string(o) +
+         " is not an integer");
+   }
+   else if (output == SVG) {
+      if (op < 0 || op > 1) throw range_error(string(o) +
+         " is not in the allowable range [0,1] for SVG output");
+   }
+}
+
+
+void Grid::parse_length(const char *o, const string &str, double &d)
+{
+   string tmp(str);
+   istringstream s(tmp);
+   s >> d;
+   if (s.fail()) throw runtime_error(string(o) + " is not a number");
+
+   if (!s.eof()) {
+      string u;
+      s >> u;
+
+      switch (output) {
+      case PNG:
+         if (strcmp(o, "coordinate size") && u != "pt")
+            throw runtime_error(string(o) + " is not in pt");
+         else if (u != "px")
+            throw runtime_error(string(o) + " is not in px");
+         break;
+      case SVG:
+         if (u != "px") throw runtime_error(string(o) + " is not in px");
+         break;
+      case PS:
+         if      (u == "pt") ;               // 1 point per point :)
+         else if (u == "cm") d *= 72/2.54;   // ~28.35 points per cm
+         else if (u == "mm") d *= 72/25.4;   // ~2.835 points per mm
+         else if (u == "in") d *= 72;        // 72 points per inch
+         else throw runtime_error(string(o) +
+            " has unrecognized unit `" + u + "'");
+         break;
+      }
+   }
+}
+
+
+void Grid::parse_format(const string &str)
+{
+   coord_first_style = coord_second_style = Grid::NoCoord;
+   coord_first_fill = coord_second_fill = false;
+   coord_first_width = coord_second_width = 0;
+
+   istringstream i(str);
+
+   // get coord_fmt_pre
+   while (!i.eof()) {
+      string s;
+      getline(i, s, '%');
+      coord_fmt_pre += s;
+      if (i.peek() == '%') coord_fmt_pre += i.get();
+      else break;
+   }
+
+   // get first coord format
+   if (!i.eof()) {
+      if (i.peek() == '0') { coord_first_fill = true; i.get(); }
+      i >> coord_first_width;
+      i.clear();
+      bool tally = false;
+      if (i.peek() == 't') { tally = true; i.get(); }
+      char c = i.get();
+      if (c == 'c' || c == 'C') coord_order = ColumnsFirst;
+      else if (c == 'r' || c == 'R') coord_order = RowsFirst;
+      else throw runtime_error("bad coordinate format string");
+
+      if (c == 'c' || c == 'r') coord_first_style = Number;
+      else coord_first_style = tally ? AlphaTally : Alpha;
+
+      if ((c == 'C' || c == 'R') &&
+          (coord_first_width || coord_first_fill))
+         throw runtime_error("bad coordinate format string");
+   }
+
+   // get coord_fmt_inter
+   while (!i.eof()) {
+      string s;
+      getline(i, s, '%');
+      coord_fmt_inter += s;
+      if (i.peek() == '%') coord_fmt_inter += i.get();
+      else break;
+   }
+
+   // get second coord format
+   if (!i.eof()) {
+      if (i.peek() == '0') { coord_second_fill = true; i.get(); }
+      i >> coord_second_width;
+      i.clear();
+      bool tally = false;
+      if (i.peek() == 't') { tally = true; i.get(); }
+      char c = i.get();
+      if (((c == 'c' || c == 'C') && coord_order == ColumnsFirst) ||
+          ((c == 'r' || c == 'R') && coord_order == RowsFirst))
+         throw runtime_error("bad coordinate format string");
+
+      if (c == 'c' || c == 'r') coord_second_style = Number;
+      else coord_second_style = tally ? AlphaTally : Alpha;
+
+      if ((c == 'C' || c == 'R') &&
+          (coord_second_width || coord_second_fill))
+         throw runtime_error("bad coordinate format string");
+   }
+
+   // get coord_fmt_post
+   while (!i.eof()) {
+      string s;
+      getline(i, s, '%');
+      coord_fmt_post += s;
+      if (i.peek() == '%') coord_fmt_post += i.get();
+      else break;
+   }
+
+   if (!i.eof()) throw runtime_error("bad coordinate format string");   
+}
+// $Id$
+/* mkhexgrid -- generates hex grids
+ * Copyright (C) 2006 Joel Uckelman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GRID_H_
+#define __GRID_H_
+
+#include <map>
+#include <string>
+using namespace std;
+
+class Grid {
+   public:
+      Grid(const map<string, string> &opt);
+      void draw();
+
+   private:
+      // PNG-specific functions
+      void draw_png();
+      void side_png(int n);
+      void side_reverse_png(int n);
+      void side_skip_png(int n);
+      void edge_png(int n);
+      void edge_reverse_png(int n);
+      void cross_png(int c, int r);
+      void dot_png(int c, int r);
+      void line_png(int x1, int y1, int x2, int y2, int c);
+      void pixel_png(int x, int y, int c);
+
+      // PS-specific functions
+      void draw_ps();
+
+      // SVG-specific functions
+      void draw_svg();
+      void side_path_svg(int n);
+      void side_path_reverse_svg(int n);
+      void side_skip_path_svg(int n);
+      void edge_path_svg(int n);
+      void edge_path_reverse_svg(int n);
+
+      // parse functions
+      void parse_length(const char *o, const string &str, double &d);
+      void parse_color(const char *o, const string &str, string &c);
+      void parse_opacity(const char *o, const string &str, double &op);
+      void parse_format(const string &str);
+
+      // utilty functions
+      string alpha(int m);
+      string alpha_tally(int m);
+
+      // image parameters
+      enum OutputType { PNG, PS, SVG } output;  // output type
+      string outfile;   // output filename
+
+      double bg_opacity;        // background opacity
+
+      double grid_thickness,    // hex grid line width
+             grid_opacity;      // hex grid opacity
+
+      bool antialiased,  // antiailiasing
+           lowfirstcol,  // first column is high or low
+           matte;        // matte around background
+
+      enum Grain { Vertical, Horizontal } grain;
+
+      bool coord_display;        // display coordinates if true
+
+      unsigned int coord_rskip,  // number every multiple of ith row
+                   coord_cskip,  // number every multiple of ith column
+                   coord_rstart, // coordinate of first row
+                   coord_cstart; // coordinate of first column
+
+      enum CoordOrigin { UpperLeft, UpperRight, LowerLeft, LowerRight }
+         coord_origin;
+
+      string coord_font,         // coordinate font
+             coord_fmt_pre,      // pre-format text
+             coord_fmt_inter,    // inter-format text
+             coord_fmt_post;     // post-format text
+
+      unsigned int coord_first_width,   // field width, first coordinate
+                   coord_second_width;  // field width, second coordinate
+
+      enum CoordStyle { NoCoord, Number, Alpha, AlphaTally }
+         coord_first_style,
+         coord_second_style;
+
+      enum CoordOrder { OrderUndetermined, ColumnsFirst, RowsFirst }
+         coord_order;
+
+      bool coord_first_fill,    // 0-fill, first coordinate
+           coord_second_fill;   // 0-fill, second coordinate
+
+      double coord_size,         // coordinate font size in points
+             coord_bearing,      // coordinate bearing from hex center
+             coord_dist,         // coordinate distance from hex center
+             coord_tilt,         // tilt of coordinate text from horizontal
+             coord_opacity;      // coordinate opacity
+
+      enum CenterStyle { Centerless, Dot, Cross } center_style;
+
+      double center_size,       // size of center marker
+             center_opacity;    // center marker opacity
+
+      double mleft,    // left marign
+             mright,   // right margin
+             mtop,     // top margin
+             mbottom;  // bottom margin
+
+      string grid_color,      // grid color
+             coord_color,     // coordinate color
+             center_color,    // center color
+             bg_color;        // background color
+
+      double hw,          // hex width
+             hh,          // hex height
+             hs,          // hex side 
+             iw,          // image width
+             ih;          // image height
+
+      int rows,
+          cols;
+
+      // useful constants
+      static const double rad;    // radians per degree
+};
+
+#endif /* __GRID_H_ */

File mkhexgrid.cpp

+// $Id$
+/* mkhexgrid -- generates hex grids
+ * Copyright (C) 2006 Joel Uckelman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <cstdlib>
+#include <exception>
+#include <iostream>
+#include <fstream>
+#include <map>
+#include <stdexcept>
+#include <string>
+using namespace std;
+
+#include <boost/lexical_cast.hpp>
+using namespace boost;
+
+#include <getopt.h>
+
+#include "grid.h"
+
+void parse_spec(istream &in, map<string, string> &opt);
+void print_help();
+
+struct option long_options[] = {
+   { "hex-width",          1, 0, 0 },
+   { "hex-height",         1, 0, 0 },
+   { "hex-side",           1, 0, 0 },
+   { "image-width",        1, 0, 0 },
+   { "image-height",       1, 0, 0 },
+   { "image-margin",       1, 0, 0 },
+   { "rows",               1, 0, 0 },
+   { "columns",            1, 0, 0 },
+   { "grid-color",         1, 0, 0 },
+   { "grid-opacity",       1, 0, 0 },
+   { "grid-thickness",     1, 0, 0 },
+   { "grid-grain",         1, 0, 0 },
+   { "grid-start",         1, 0, 0 },
+   { "coord-color",        1, 0, 0 },
+   { "coord-opacity",      1, 0, 0 },
+   { "coord-format",       1, 0, 0 },
+   { "coord-font",         1, 0, 0 },
+   { "coord-size",         1, 0, 0 },
+   { "coord-bearing",      1, 0, 0 },
+   { "coord-distance",     1, 0, 0 },
+   { "coord-tilt",         1, 0, 0 },
+   { "coord-column-skip",  1, 0, 0 },
+   { "coord-row-skip",     1, 0, 0 },
+   { "coord-column-start", 1, 0, 0 },
+   { "coord-row-start",    1, 0, 0 },
+   { "coord-origin",       1, 0, 0 },
+   { "bg-color",           1, 0, 0 },
+   { "bg-opacity",         1, 0, 0 },
+   { "matte",              0, 0, 0 },
+   { "center-style",       1, 0, 0 },
+   { "center-color",       1, 0, 0 },
+   { "center-opacity",     1, 0, 0 },
+   { "center-size",        1, 0, 0 },
+   { "antialias",          0, 0, 0 },
+   { "centered",           0, 0, 0 },
+   { "output",             1, 0, 0 },
+   { "outfile",            1, 0, 'o' },
+   { "help",               0, 0, 'h' },
+   { "version",            0, 0, 'v' },
+   { 0, 0, 0, 0 }
+};
+
+
+int main(int argc, char **argv)
+{
+   map<string, string> opt;
+
+   int c;
+   int option_index = 0;
+
+   while (1) {
+      c = getopt_long(argc, argv, "i:o:", long_options, &option_index);
+      if (c == -1) break;  // end of options
+
+      switch (c) {
+      case 0:
+         opt[long_options[option_index].name] = optarg ? optarg : "";
+         break;
+      case 'i':
+         opt["infile"] = optarg;
+         break;
+      case 'o':
+         opt["outfile"] = optarg;
+         break;
+      case 'v':
+         cout << "mkhexgrid version " << VERSION << endl;
+         exit(0);
+      case 'h':
+         print_help();
+         exit(0);
+      default:
+         exit(1);    // getopt produces an error message
+      }
+   }
+
+   try {
+      // get name of specfile, if given as a positional parameter
+      if (optind < argc) {
+         if (opt.find("infile") != opt.end())
+            throw runtime_error("specfile specified twice on command line");
+         
+         opt["infile"] = argv[optind++];
+
+         // get name of outfile, if given as a positional parameter
+         if (optind < argc) {
+            if (opt.find("outfile") != opt.end()) 
+             throw runtime_error("output file specified twice on command line");
+            opt["outfile"] = argv[optind++];
+
+            if (optind < argc) throw runtime_error("too many arguments");
+         }
+      }
+
+      // read and parse specfile
+      map<string,string>::const_iterator i = opt.find("infile");
+      if (i != opt.end()) {
+         if (i->second == "-") parse_spec(cin, opt); 
+         else {
+            ifstream in;
+            in.open(i->second.c_str(), ios::in | ios::binary);
+            if (!in)
+             throw runtime_error("cannot read spec file `" + i->second + "'");
+            parse_spec(in, opt);
+            in.close();
+         }
+      } 
+   
+      // draw hex grid
+      Grid g(opt);
+      g.draw();
+   }
+   catch (exception &e) {
+      cerr << argv[0] << ": " << e.what() << endl;
+      exit(1);
+   }
+
+   return 0;
+}
+
+
+void parse_spec(istream &in, map<string, string> &opt)
+{
+   string key, val;
+   unsigned int line = 1, col = 0;
+   char c;
+   enum { START, KEY, PRE_EQ, POST_EQ, VAL, QVAL, GUARD, END }
+      state = START;
+   
+   while (in.get(c)) {
+      ++col;
+      switch (state) {
+      case START:
+         switch (c) {
+         case '\n':
+            ++line;
+            col = 0;
+         case ' ':
+         case '\t':
+         case '\r':
+            break;
+         case '#':
+            do { 
+               in.get(c);
+               if (c == '\n') {
+                  ++line;
+                  col = 0;
+                  break;
+               }
+            } while (in);
+            break;
+         default:
+            key += c;
+            state = KEY;
+            break;
+         }
+         break;
+      case KEY:
+         switch (c) {
+         case ' ':
+         case '\t':
+         {
+            unsigned int i = 0;
+            for ( ; long_options[i].name &&
+                    long_options[i].name != key; ++i);
+            if (!long_options[i].name)
+               throw runtime_error("unrecognized option `" + key +
+                  "' in specfile");
+            state = PRE_EQ;
+            break;
+         }
+         case '\r':
+         case '\n':
+         case '#':
+            throw runtime_error("malformed spec file at"
+               " line " + lexical_cast<string>(line) + ","
+               " column " + lexical_cast<string>(col));
+            break;
+         case '=':
+         {
+            unsigned int i = 0;
+            for ( ; long_options[i].name &&
+                    long_options[i].name != key; ++i);
+            if (!long_options[i].name)
+               throw runtime_error("unrecognized option `" + key +
+                  "' in specfile");
+            state = POST_EQ;
+            break;
+         }
+         default:
+            key += c;
+            break;
+         }
+         break;
+      case PRE_EQ: