]> git.sur5r.net Git - glabels/commitdiff
2004-01-06 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Wed, 7 Jan 2004 05:10:22 +0000 (05:10 +0000)
committerJim Evins <evins@snaught.com>
Wed, 7 Jan 2004 05:10:22 +0000 (05:10 +0000)
Split-out template.[ch], paper.[ch], xml-template.[ch], xml-paper.[ch], and
xml.[ch] into a separate library called libglabels, to facilitate third
party use of glabels template files.  This was suggested by Wayne Schuller.
Once split-out, some modifications to the structures and functions to
make a cleaner more useful API, hopefully.  Rather extensive changes have
propogated to other modules.

* src/paper.h:
* src/paper.c:
* src/template.h:
* src/template.c:
* src/xml-paper.h:
* src/xml-paper.c:
* src/xml-template.h:
* src/xml-template.c:
* src/xml.h:
* src/xml.c:
These files have been moved to libglabels/.  API cleanup performed.

* libglabels/libglabels.h:
* libglabels/libglabels-private.h:
* libglabels/Makefile.am:
These files have been added to finish out libglabels.

* Makefile.am:
* configure.in:
* glabels.spec.in:
* po/POTFILES.in:
* src/Makefile.am:
Modified to reflect new sets of files in src/ and libglabels/.

* COPYING.LIBGLABELS:
* COPYING-DOCS:
Added copy of the LGPL for libglabels, and a copy the GFDL for
documentation.

* src/glabels-batch.c:
* src/glabels.c:
* src/label.c: (gl_label_finalize), (gl_label_set_template),
(gl_label_get_size):
* src/label.h:
* src/prefs-model.c: (gl_prefs_model_load_settings):
* src/print-dialog.c:
* src/print.c: (gl_print_simple), (gl_print_merge_collated),
(gl_print_merge_uncollated), (gl_print_batch), (print_info_free),
(print_crop_marks), (print_label), (draw_outline),
(clip_to_outline), (clip_punchouts):
* src/template-designer.c: (construct_pg_size_page),
(pg_size_page_changed_cb), (layout_page_changed_cb),
(print_test_cb), (build_template):
* src/util.c: (gl_util_fraction):
* src/util.h:
* src/view.c: (draw_bg_fg_layers), (draw_bg_fg_rect),
(draw_bg_fg_rounded_rect), (draw_bg_fg_round), (draw_bg_fg_cd),
(draw_bg_fg_cd_bc), (draw_markup_layer), (draw_markup_margin),
(draw_markup_margin_rect), (draw_markup_margin_rounded_rect),
(draw_markup_margin_round), (draw_markup_margin_cd),
(draw_markup_margin_cd_bc), (draw_markup_line),
(draw_markup_circle), (gl_view_copy):
* src/wdgt-media-select.c: (gl_wdgt_media_select_construct),
(page_size_entry_changed_cb), (details_update), (get_layout_desc),
(get_label_size_desc):
* src/wdgt-mini-preview.c:
(gl_wdgt_mini_preview_set_label_by_name), (mini_outline_list_new),
(cdbc_item):
* src/wdgt-print-copies.c: (gl_wdgt_print_copies_construct):
* src/wdgt-print-merge.c: (gl_wdgt_print_merge_construct):
* src/wdgt-rotate-label.c: (mini_preview_canvas_update),
(gl_wdgt_rotate_label_set_template_name), (cdbc_item):
* src/wdgt-rotate-label.h:
* src/xml-label-04.c: (xml04_parse_media_description):
* src/xml-label-191.c: (gl_xml_label_191_parse),
(xml191_parse_sheet), (xml191_parse_label), (xml191_parse_layout),
(xml191_parse_markup), (xml191_parse_alias):
* src/xml-label.c: (xml_doc_to_label), (xml_parse_label),
(xml_label_to_doc):
Various changes to accomodate new libglabels API.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@405 f5e0f49d-192f-0410-a22d-a8d8700d0965

51 files changed:
glabels2/COPYING-DOCS [new file with mode: 0644]
glabels2/COPYING.LIBGLABELS [new file with mode: 0644]
glabels2/ChangeLog
glabels2/Makefile.am
glabels2/configure.in
glabels2/glabels.spec.in
glabels2/libglabels/Makefile.am [new file with mode: 0644]
glabels2/libglabels/libglabels-private.h [new file with mode: 0644]
glabels2/libglabels/libglabels.h [new file with mode: 0644]
glabels2/libglabels/paper.c [new file with mode: 0644]
glabels2/libglabels/paper.h [new file with mode: 0644]
glabels2/libglabels/template.c [new file with mode: 0644]
glabels2/libglabels/template.h [new file with mode: 0644]
glabels2/libglabels/xml-paper.c [new file with mode: 0644]
glabels2/libglabels/xml-paper.h [new file with mode: 0644]
glabels2/libglabels/xml-template.c [new file with mode: 0644]
glabels2/libglabels/xml-template.h [new file with mode: 0644]
glabels2/libglabels/xml.c [new file with mode: 0644]
glabels2/libglabels/xml.h [new file with mode: 0644]
glabels2/po/POTFILES.in
glabels2/src/Makefile.am
glabels2/src/glabels-batch.c
glabels2/src/glabels.c
glabels2/src/label.c
glabels2/src/label.h
glabels2/src/paper.c [deleted file]
glabels2/src/paper.h [deleted file]
glabels2/src/prefs-model.c
glabels2/src/print-dialog.c
glabels2/src/print.c
glabels2/src/template-designer.c
glabels2/src/template.c [deleted file]
glabels2/src/template.h [deleted file]
glabels2/src/util.c
glabels2/src/util.h
glabels2/src/view.c
glabels2/src/wdgt-media-select.c
glabels2/src/wdgt-mini-preview.c
glabels2/src/wdgt-print-copies.c
glabels2/src/wdgt-print-merge.c
glabels2/src/wdgt-rotate-label.c
glabels2/src/wdgt-rotate-label.h
glabels2/src/xml-label-04.c
glabels2/src/xml-label-191.c
glabels2/src/xml-label.c
glabels2/src/xml-paper.c [deleted file]
glabels2/src/xml-paper.h [deleted file]
glabels2/src/xml-template.c [deleted file]
glabels2/src/xml-template.h [deleted file]
glabels2/src/xml.c [deleted file]
glabels2/src/xml.h [deleted file]

diff --git a/glabels2/COPYING-DOCS b/glabels2/COPYING-DOCS
new file mode 100644 (file)
index 0000000..b42936b
--- /dev/null
@@ -0,0 +1,355 @@
+               GNU Free Documentation License
+                  Version 1.1, March 2000
+
+ Copyright (C) 2000  Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+0. PREAMBLE
+
+The purpose of this License is to make a manual, textbook, or other
+written document "free" in the sense of freedom: to assure everyone
+the effective freedom to copy and redistribute it, with or without
+modifying it, either commercially or noncommercially.  Secondarily,
+this License preserves for the author and publisher a way to get
+credit for their work, while not being considered responsible for
+modifications made by others.
+
+This License is a kind of "copyleft", which means that derivative
+works of the document must themselves be free in the same sense.  It
+complements the GNU General Public License, which is a copyleft
+license designed for free software.
+
+We have designed this License in order to use it for manuals for free
+software, because free software needs free documentation: a free
+program should come with manuals providing the same freedoms that the
+software does.  But this License is not limited to software manuals;
+it can be used for any textual work, regardless of subject matter or
+whether it is published as a printed book.  We recommend this License
+principally for works whose purpose is instruction or reference.
+
+
+1. APPLICABILITY AND DEFINITIONS
+
+This License applies to any manual or other work that contains a
+notice placed by the copyright holder saying it can be distributed
+under the terms of this License.  The "Document", below, refers to any
+such manual or work.  Any member of the public is a licensee, and is
+addressed as "you".
+
+A "Modified Version" of the Document means any work containing the
+Document or a portion of it, either copied verbatim, or with
+modifications and/or translated into another language.
+
+A "Secondary Section" is a named appendix or a front-matter section of
+the Document that deals exclusively with the relationship of the
+publishers or authors of the Document to the Document's overall subject
+(or to related matters) and contains nothing that could fall directly
+within that overall subject.  (For example, if the Document is in part a
+textbook of mathematics, a Secondary Section may not explain any
+mathematics.)  The relationship could be a matter of historical
+connection with the subject or with related matters, or of legal,
+commercial, philosophical, ethical or political position regarding
+them.
+
+The "Invariant Sections" are certain Secondary Sections whose titles
+are designated, as being those of Invariant Sections, in the notice
+that says that the Document is released under this License.
+
+The "Cover Texts" are certain short passages of text that are listed,
+as Front-Cover Texts or Back-Cover Texts, in the notice that says that
+the Document is released under this License.
+
+A "Transparent" copy of the Document means a machine-readable copy,
+represented in a format whose specification is available to the
+general public, whose contents can be viewed and edited directly and
+straightforwardly with generic text editors or (for images composed of
+pixels) generic paint programs or (for drawings) some widely available
+drawing editor, and that is suitable for input to text formatters or
+for automatic translation to a variety of formats suitable for input
+to text formatters.  A copy made in an otherwise Transparent file
+format whose markup has been designed to thwart or discourage
+subsequent modification by readers is not Transparent.  A copy that is
+not "Transparent" is called "Opaque".
+
+Examples of suitable formats for Transparent copies include plain
+ASCII without markup, Texinfo input format, LaTeX input format, SGML
+or XML using a publicly available DTD, and standard-conforming simple
+HTML designed for human modification.  Opaque formats include
+PostScript, PDF, proprietary formats that can be read and edited only
+by proprietary word processors, SGML or XML for which the DTD and/or
+processing tools are not generally available, and the
+machine-generated HTML produced by some word processors for output
+purposes only.
+
+The "Title Page" means, for a printed book, the title page itself,
+plus such following pages as are needed to hold, legibly, the material
+this License requires to appear in the title page.  For works in
+formats which do not have any title page as such, "Title Page" means
+the text near the most prominent appearance of the work's title,
+preceding the beginning of the body of the text.
+
+
+2. VERBATIM COPYING
+
+You may copy and distribute the Document in any medium, either
+commercially or noncommercially, provided that this License, the
+copyright notices, and the license notice saying this License applies
+to the Document are reproduced in all copies, and that you add no other
+conditions whatsoever to those of this License.  You may not use
+technical measures to obstruct or control the reading or further
+copying of the copies you make or distribute.  However, you may accept
+compensation in exchange for copies.  If you distribute a large enough
+number of copies you must also follow the conditions in section 3.
+
+You may also lend copies, under the same conditions stated above, and
+you may publicly display copies.
+
+
+3. COPYING IN QUANTITY
+
+If you publish printed copies of the Document numbering more than 100,
+and the Document's license notice requires Cover Texts, you must enclose
+the copies in covers that carry, clearly and legibly, all these Cover
+Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
+the back cover.  Both covers must also clearly and legibly identify
+you as the publisher of these copies.  The front cover must present
+the full title with all words of the title equally prominent and
+visible.  You may add other material on the covers in addition.
+Copying with changes limited to the covers, as long as they preserve
+the title of the Document and satisfy these conditions, can be treated
+as verbatim copying in other respects.
+
+If the required texts for either cover are too voluminous to fit
+legibly, you should put the first ones listed (as many as fit
+reasonably) on the actual cover, and continue the rest onto adjacent
+pages.
+
+If you publish or distribute Opaque copies of the Document numbering
+more than 100, you must either include a machine-readable Transparent
+copy along with each Opaque copy, or state in or with each Opaque copy
+a publicly-accessible computer-network location containing a complete
+Transparent copy of the Document, free of added material, which the
+general network-using public has access to download anonymously at no
+charge using public-standard network protocols.  If you use the latter
+option, you must take reasonably prudent steps, when you begin
+distribution of Opaque copies in quantity, to ensure that this
+Transparent copy will remain thus accessible at the stated location
+until at least one year after the last time you distribute an Opaque
+copy (directly or through your agents or retailers) of that edition to
+the public.
+
+It is requested, but not required, that you contact the authors of the
+Document well before redistributing any large number of copies, to give
+them a chance to provide you with an updated version of the Document.
+
+
+4. MODIFICATIONS
+
+You may copy and distribute a Modified Version of the Document under
+the conditions of sections 2 and 3 above, provided that you release
+the Modified Version under precisely this License, with the Modified
+Version filling the role of the Document, thus licensing distribution
+and modification of the Modified Version to whoever possesses a copy
+of it.  In addition, you must do these things in the Modified Version:
+
+A. Use in the Title Page (and on the covers, if any) a title distinct
+   from that of the Document, and from those of previous versions
+   (which should, if there were any, be listed in the History section
+   of the Document).  You may use the same title as a previous version
+   if the original publisher of that version gives permission.
+B. List on the Title Page, as authors, one or more persons or entities
+   responsible for authorship of the modifications in the Modified
+   Version, together with at least five of the principal authors of the
+   Document (all of its principal authors, if it has less than five).
+C. State on the Title page the name of the publisher of the
+   Modified Version, as the publisher.
+D. Preserve all the copyright notices of the Document.
+E. Add an appropriate copyright notice for your modifications
+   adjacent to the other copyright notices.
+F. Include, immediately after the copyright notices, a license notice
+   giving the public permission to use the Modified Version under the
+   terms of this License, in the form shown in the Addendum below.
+G. Preserve in that license notice the full lists of Invariant Sections
+   and required Cover Texts given in the Document's license notice.
+H. Include an unaltered copy of this License.
+I. Preserve the section entitled "History", and its title, and add to
+   it an item stating at least the title, year, new authors, and
+   publisher of the Modified Version as given on the Title Page.  If
+   there is no section entitled "History" in the Document, create one
+   stating the title, year, authors, and publisher of the Document as
+   given on its Title Page, then add an item describing the Modified
+   Version as stated in the previous sentence.
+J. Preserve the network location, if any, given in the Document for
+   public access to a Transparent copy of the Document, and likewise
+   the network locations given in the Document for previous versions
+   it was based on.  These may be placed in the "History" section.
+   You may omit a network location for a work that was published at
+   least four years before the Document itself, or if the original
+   publisher of the version it refers to gives permission.
+K. In any section entitled "Acknowledgements" or "Dedications",
+   preserve the section's title, and preserve in the section all the
+   substance and tone of each of the contributor acknowledgements
+   and/or dedications given therein.
+L. Preserve all the Invariant Sections of the Document,
+   unaltered in their text and in their titles.  Section numbers
+   or the equivalent are not considered part of the section titles.
+M. Delete any section entitled "Endorsements".  Such a section
+   may not be included in the Modified Version.
+N. Do not retitle any existing section as "Endorsements"
+   or to conflict in title with any Invariant Section.
+
+If the Modified Version includes new front-matter sections or
+appendices that qualify as Secondary Sections and contain no material
+copied from the Document, you may at your option designate some or all
+of these sections as invariant.  To do this, add their titles to the
+list of Invariant Sections in the Modified Version's license notice.
+These titles must be distinct from any other section titles.
+
+You may add a section entitled "Endorsements", provided it contains
+nothing but endorsements of your Modified Version by various
+parties--for example, statements of peer review or that the text has
+been approved by an organization as the authoritative definition of a
+standard.
+
+You may add a passage of up to five words as a Front-Cover Text, and a
+passage of up to 25 words as a Back-Cover Text, to the end of the list
+of Cover Texts in the Modified Version.  Only one passage of
+Front-Cover Text and one of Back-Cover Text may be added by (or
+through arrangements made by) any one entity.  If the Document already
+includes a cover text for the same cover, previously added by you or
+by arrangement made by the same entity you are acting on behalf of,
+you may not add another; but you may replace the old one, on explicit
+permission from the previous publisher that added the old one.
+
+The author(s) and publisher(s) of the Document do not by this License
+give permission to use their names for publicity for or to assert or
+imply endorsement of any Modified Version.
+
+
+5. COMBINING DOCUMENTS
+
+You may combine the Document with other documents released under this
+License, under the terms defined in section 4 above for modified
+versions, provided that you include in the combination all of the
+Invariant Sections of all of the original documents, unmodified, and
+list them all as Invariant Sections of your combined work in its
+license notice.
+
+The combined work need only contain one copy of this License, and
+multiple identical Invariant Sections may be replaced with a single
+copy.  If there are multiple Invariant Sections with the same name but
+different contents, make the title of each such section unique by
+adding at the end of it, in parentheses, the name of the original
+author or publisher of that section if known, or else a unique number.
+Make the same adjustment to the section titles in the list of
+Invariant Sections in the license notice of the combined work.
+
+In the combination, you must combine any sections entitled "History"
+in the various original documents, forming one section entitled
+"History"; likewise combine any sections entitled "Acknowledgements",
+and any sections entitled "Dedications".  You must delete all sections
+entitled "Endorsements."
+
+
+6. COLLECTIONS OF DOCUMENTS
+
+You may make a collection consisting of the Document and other documents
+released under this License, and replace the individual copies of this
+License in the various documents with a single copy that is included in
+the collection, provided that you follow the rules of this License for
+verbatim copying of each of the documents in all other respects.
+
+You may extract a single document from such a collection, and distribute
+it individually under this License, provided you insert a copy of this
+License into the extracted document, and follow this License in all
+other respects regarding verbatim copying of that document.
+
+
+7. AGGREGATION WITH INDEPENDENT WORKS
+
+A compilation of the Document or its derivatives with other separate
+and independent documents or works, in or on a volume of a storage or
+distribution medium, does not as a whole count as a Modified Version
+of the Document, provided no compilation copyright is claimed for the
+compilation.  Such a compilation is called an "aggregate", and this
+License does not apply to the other self-contained works thus compiled
+with the Document, on account of their being thus compiled, if they
+are not themselves derivative works of the Document.
+
+If the Cover Text requirement of section 3 is applicable to these
+copies of the Document, then if the Document is less than one quarter
+of the entire aggregate, the Document's Cover Texts may be placed on
+covers that surround only the Document within the aggregate.
+Otherwise they must appear on covers around the whole aggregate.
+
+
+8. TRANSLATION
+
+Translation is considered a kind of modification, so you may
+distribute translations of the Document under the terms of section 4.
+Replacing Invariant Sections with translations requires special
+permission from their copyright holders, but you may include
+translations of some or all Invariant Sections in addition to the
+original versions of these Invariant Sections.  You may include a
+translation of this License provided that you also include the
+original English version of this License.  In case of a disagreement
+between the translation and the original English version of this
+License, the original English version will prevail.
+
+
+9. TERMINATION
+
+You may not copy, modify, sublicense, or distribute the Document except
+as expressly provided for under this License.  Any other attempt to
+copy, modify, sublicense or distribute the Document 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.
+
+
+10. FUTURE REVISIONS OF THIS LICENSE
+
+The Free Software Foundation may publish new, revised versions
+of the GNU Free Documentation 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.  See
+http://www.gnu.org/copyleft/.
+
+Each version of the License is given a distinguishing version number.
+If the Document specifies that a particular numbered version of this
+License "or any later version" applies to it, you have the option of
+following the terms and conditions either of that specified version or
+of any later version that has been published (not as a draft) by the
+Free Software Foundation.  If the Document does not specify a version
+number of this License, you may choose any version ever published (not
+as a draft) by the Free Software Foundation.
+
+
+ADDENDUM: How to use this License for your documents
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and
+license notices just after the title page:
+
+      Copyright (c)  YEAR  YOUR NAME.
+      Permission is granted to copy, distribute and/or modify this document
+      under the terms of the GNU Free Documentation License, Version 1.1
+      or any later version published by the Free Software Foundation;
+      with the Invariant Sections being LIST THEIR TITLES, with the
+      Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
+      A copy of the license is included in the section entitled "GNU
+      Free Documentation License".
+
+If you have no Invariant Sections, write "with no Invariant Sections"
+instead of saying which ones are invariant.  If you have no
+Front-Cover Texts, write "no Front-Cover Texts" instead of
+"Front-Cover Texts being LIST"; likewise for Back-Cover Texts.
+
+If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License,
+to permit their use in free software.
diff --git a/glabels2/COPYING.LIBGLABELS b/glabels2/COPYING.LIBGLABELS
new file mode 100644 (file)
index 0000000..161a3d1
--- /dev/null
@@ -0,0 +1,482 @@
+                 GNU LIBRARY GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL.  It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it.  You can use it for
+your libraries, 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 library, or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library.  If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+\f
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software.  To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+  Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs.  This
+license, the GNU Library General Public License, applies to certain
+designated libraries.  This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+  The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it.  Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program.  However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+  Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries.  We
+concluded that weaker conditions might promote sharing better.
+
+  However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves.  This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them.  (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.)  The hope is that this
+will lead to faster development of free libraries.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+  Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+\f
+                 GNU LIBRARY GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License").  Each licensee is
+addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, 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 library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete 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 distribute a copy of this License along with the
+Library.
+
+  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.
+\f
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+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 Library, 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 Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+\f
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you 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.
+
+  If distribution of 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 satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+  6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    c) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    d) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  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.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library 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.
+
+  9. 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 Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+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.
+\f
+  11. 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 Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library 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 Library.
+
+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.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library 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.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Library 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 Library
+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 Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+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
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "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
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. 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 LIBRARY 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
+LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+     Appendix: How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  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 library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+    MA 02111-1307, USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
index d5883119db82d0b25c8fc1e5fecac4df5d55f72c..714c367fc96565db313711b36cc397fc63737a6c 100644 (file)
@@ -1,3 +1,83 @@
+2004-01-06  Jim Evins  <evins@snaught.com>
+
+       Split-out template.[ch], paper.[ch], xml-template.[ch], xml-paper.[ch], and
+       xml.[ch] into a separate library called libglabels, to facilitate third
+       party use of glabels template files.  This was suggested by Wayne Schuller.
+       Once split-out, some modifications to the structures and functions to
+       make a cleaner more useful API, hopefully.  Rather extensive changes have
+       propogated to other modules.
+
+       * src/paper.h:
+       * src/paper.c:
+       * src/template.h:
+       * src/template.c:
+       * src/xml-paper.h:
+       * src/xml-paper.c:
+       * src/xml-template.h:
+       * src/xml-template.c:
+       * src/xml.h:
+       * src/xml.c:
+               These files have been moved to libglabels/.  API cleanup performed.
+
+       * libglabels/libglabels.h:
+       * libglabels/libglabels-private.h:
+       * libglabels/Makefile.am:
+               These files have been added to finish out libglabels.
+       
+       * Makefile.am:
+       * configure.in:
+       * glabels.spec.in:
+       * po/POTFILES.in:
+       * src/Makefile.am:
+               Modified to reflect new sets of files in src/ and libglabels/.
+
+       * COPYING.LIBGLABELS:
+       * COPYING-DOCS:
+               Added copy of the LGPL for libglabels, and a copy the GFDL for
+               documentation.
+       
+       * src/glabels-batch.c:
+       * src/glabels.c:
+       * src/label.c: (gl_label_finalize), (gl_label_set_template),
+       (gl_label_get_size):
+       * src/label.h:
+       * src/prefs-model.c: (gl_prefs_model_load_settings):
+       * src/print-dialog.c:
+       * src/print.c: (gl_print_simple), (gl_print_merge_collated),
+       (gl_print_merge_uncollated), (gl_print_batch), (print_info_free),
+       (print_crop_marks), (print_label), (draw_outline),
+       (clip_to_outline), (clip_punchouts):
+       * src/template-designer.c: (construct_pg_size_page),
+       (pg_size_page_changed_cb), (layout_page_changed_cb),
+       (print_test_cb), (build_template):
+       * src/util.c: (gl_util_fraction):
+       * src/util.h:
+       * src/view.c: (draw_bg_fg_layers), (draw_bg_fg_rect),
+       (draw_bg_fg_rounded_rect), (draw_bg_fg_round), (draw_bg_fg_cd),
+       (draw_bg_fg_cd_bc), (draw_markup_layer), (draw_markup_margin),
+       (draw_markup_margin_rect), (draw_markup_margin_rounded_rect),
+       (draw_markup_margin_round), (draw_markup_margin_cd),
+       (draw_markup_margin_cd_bc), (draw_markup_line),
+       (draw_markup_circle), (gl_view_copy):
+       * src/wdgt-media-select.c: (gl_wdgt_media_select_construct),
+       (page_size_entry_changed_cb), (details_update), (get_layout_desc),
+       (get_label_size_desc):
+       * src/wdgt-mini-preview.c:
+       (gl_wdgt_mini_preview_set_label_by_name), (mini_outline_list_new),
+       (cdbc_item):
+       * src/wdgt-print-copies.c: (gl_wdgt_print_copies_construct):
+       * src/wdgt-print-merge.c: (gl_wdgt_print_merge_construct):
+       * src/wdgt-rotate-label.c: (mini_preview_canvas_update),
+       (gl_wdgt_rotate_label_set_template_name), (cdbc_item):
+       * src/wdgt-rotate-label.h:
+       * src/xml-label-04.c: (xml04_parse_media_description):
+       * src/xml-label-191.c: (gl_xml_label_191_parse),
+       (xml191_parse_sheet), (xml191_parse_label), (xml191_parse_layout),
+       (xml191_parse_markup), (xml191_parse_alias):
+       * src/xml-label.c: (xml_doc_to_label), (xml_parse_label),
+       (xml_label_to_doc):
+               Various changes to accomodate new libglabels API.
+       
 2004-01-03  Jim Evins  <evins@snaught.com>
 
        * configure.in:
index 56d5fac55bbf75a84d32a63ca8b38f3474c8e5fb..c3c6a89f3847779aa053b0086a0004f20073b87f 100644 (file)
@@ -2,11 +2,13 @@
 
 LIB_BARCODE_DIR = barcode-0.98
 
-SUBDIRS = po $(LIB_BARCODE_DIR) src data pixmaps doc
+SUBDIRS = po $(LIB_BARCODE_DIR) libglabels src data pixmaps doc
 
 EXTRA_DIST = \
        README \
        COPYING \
+       COPYING-DOCS \
+       COPYING.LIBGLABELS \
        AUTHORS \
        ChangeLog \
        INSTALL \
index 9d9e8fcdd1c571b72452f16dc4424b4e67c9bd5b..c05263ecec74b66d2512ecb67bcbedb3727278e9 100644 (file)
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.52)
 
-AC_INIT(glabels, 1.93.2, http://sourceforge.net/tracker/?func=add&group_id=46122&atid=445116)
+AC_INIT(glabels, 1.93.3cvs, http://sourceforge.net/tracker/?func=add&group_id=46122&atid=445116)
 AC_CONFIG_SRCDIR(src/glabels.c)
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 
@@ -19,7 +19,6 @@ AM_PROG_CC_STDC
 AC_HEADER_STDC
 
 GNOME_COMPILE_WARNINGS
-GNOME_X_CHECKS
 
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 
@@ -28,6 +27,7 @@ dnl *******************************************************************
 dnl * Check for required package and version
 dnl *******************************************************************
 dnl Minimum versions of libraries
+GLIB_REQUIRED=2.2.0
 GTK_REQUIRED=2.0.5
 LIBGNOMEUI_REQUIRED=2.0.1
 LIBBONOBO_REQUIRED=2.0.0
@@ -37,7 +37,9 @@ LIBGNOMEPRINTUI_REQUIRED=2.2.0
 LIBGNOMECANVAS_REQUIRED=2.0.1
 LIBGLADE_REQUIRED=2.0.1
                
-PKG_CHECK_MODULES(GLABELS, gtk+-2.0 >= $GTK_REQUIRED \
+PKG_CHECK_MODULES(GLABELS, \
+glib-2.0 >= $GLIB_REQUIRED \
+gtk+-2.0 >= $GTK_REQUIRED \
 libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED \
 libbonobo-2.0 >= $LIBBONOBO_REQUIRED \
 libxml-2.0 >= $LIBXML_REQUIRED \
@@ -50,6 +52,14 @@ libglade-2.0 >= $LIBGLADE_REQUIRED \
 AC_SUBST(GLABELS_CFLAGS)
 AC_SUBST(GLABELS_LIBS)
 
+PKG_CHECK_MODULES(LIBGLABELS, \
+glib-2.0 >= $GLIB_REQUIRED \
+libxml-2.0 >= $LIBXML_REQUIRED \
+)
+
+AC_SUBST(LIBGLABELS_CFLAGS)
+AC_SUBST(LIBGLABELS_LIBS)
+
 dnl ****************************************
 dnl * Supported languages
 dnl ****************************************
@@ -68,6 +78,7 @@ dnl ****************************************
 AC_OUTPUT([
 Makefile
 barcode-0.98/Makefile
+libglabels/Makefile
 src/Makefile
 src/pixmaps/Makefile
 src/stock-pixmaps/Makefile
index 31685dac78da47d7cbe9f8bb41e94861264a97ef..b8cc2102a7682af2f80973a3c392c79ed252b0ca 100644 (file)
@@ -54,7 +54,7 @@ scrollkeeper-update
 
 %files -f %{name}.lang
 %defattr(-, root, root)
-%doc README COPYING ChangeLog NEWS AUTHORS INSTALL
+%doc README COPYING COPYING-DOCS COPYING.LIBGLABELS ChangeLog NEWS AUTHORS INSTALL
 %doc %{_datadir}/gnome/help/glabels/
 %{_bindir}/*
 %{_datadir}/glabels/
diff --git a/glabels2/libglabels/Makefile.am b/glabels2/libglabels/Makefile.am
new file mode 100644 (file)
index 0000000..7da5174
--- /dev/null
@@ -0,0 +1,33 @@
+INCLUDES = \
+       $(LIBGLABELS_CFLAGS)            \
+       -DDATADIR=\""$(datadir)"\"      
+
+libglabels_la_LDFLAGS=\
+        -version-info 0:0:0 \
+        $(LIBGLABELS_LIBS) \
+        -no-undefined 
+
+lib_LTLIBRARIES = libglabels.la
+
+libglabelsincludedir=$(includedir)/libglabels
+
+libglabels_la_SOURCES =                \
+       libglabels-private.h    \
+       paper.h                 \
+       paper.c                 \
+       template.h              \
+       template.c              \
+       xml-paper.h             \
+       xml-paper.c             \
+       xml-template.h          \
+       xml-template.c          \
+       xml.h                   \
+       xml.c                   
+
+libglabelsinclude_HEADERS =    \
+       libglabels.h            \
+       paper.h                 \
+       template.h              \
+       xml-paper.h             \
+       xml-template.h          \
+       xml.h                   
diff --git a/glabels2/libglabels/libglabels-private.h b/glabels2/libglabels/libglabels-private.h
new file mode 100644 (file)
index 0000000..fc44e17
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  libglabels-private.h:  libglabels private header file
+ *
+ *  Copyright (C) 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __LIBGLABELS_PRIVATE_H__
+#define __LIBGLABELS_PRIVATE_H__
+
+#include <config.h>
+
+#if ENABLE_NLS
+
+#       include <libintl.h>
+#       define _(x) dgettext (GETTEXT_PACKAGE, x)
+#       define N_(x) x
+
+#else
+
+#       define _(x) x
+#       define N_(x) x
+
+#endif
+
+/* Data system and user data directories.  (must free w/ g_free()) */
+#define GL_SYSTEM_DATA_DIR g_build_filename (DATADIR, "glabels", NULL)
+#define GL_USER_DATA_DIR   g_build_filename (g_get_home_dir (), ".glabels", NULL)
+
+#endif /* __LIBGLABELS_PRIVATE_H__ */
diff --git a/glabels2/libglabels/libglabels.h b/glabels2/libglabels/libglabels.h
new file mode 100644 (file)
index 0000000..bc2ba99
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  libglabels.h:  libglabels master header file
+ *
+ *  Copyright (C) 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __LIBGLABELS_H__
+#define __LIBGLABELS_H__
+
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
+#include <libglabels/xml-paper.h>
+#include <libglabels/xml-template.h>
+#include <libglabels/xml.h>
+
+#endif /* __LIBGLABELS_H__ */
diff --git a/glabels2/libglabels/paper.c b/glabels2/libglabels/paper.c
new file mode 100644 (file)
index 0000000..0e3ed41
--- /dev/null
@@ -0,0 +1,448 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  paper.c:  paper module
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#include "libglabels-private.h"
+
+#include <string.h>
+
+#include "paper.h"
+#include "xml-paper.h"
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+static GList *papers = NULL;
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static GList *read_papers (void);
+static GList *read_paper_files_from_dir (GList       *papers,
+                                        const gchar *dirname);
+
+\f
+/*****************************************************************************/
+/* Initialize module.                                                        */
+/*****************************************************************************/
+void
+gl_paper_init (void)
+{
+       glPaper *other;
+
+       if (papers) {
+               return; /* Already initialized. */
+       }
+
+       papers = read_papers ();
+
+       /* Create and append an "Other" entry. */
+       other = gl_paper_new ("Other", _("Other"), 0.0, 0.0);
+       papers = g_list_append (papers, other);
+}
+
+/*****************************************************************************/
+/* Create a new paper structure.                                             */
+/*****************************************************************************/
+glPaper *
+gl_paper_new (gchar             *id,
+             gchar             *name,
+             gdouble            width,
+             gdouble            height)
+{
+       glPaper *paper;
+
+       paper         = g_new0 (glPaper,1);
+       paper->id     = g_strdup (id);
+       paper->name   = g_strdup (name);
+       paper->width  = width;
+       paper->height = height;
+
+       return paper;
+}
+
+/*****************************************************************************/
+/* Copy a paper.                                                          */
+/*****************************************************************************/
+glPaper *gl_paper_dup (const glPaper *orig_paper)
+{
+       glPaper       *paper;
+
+       g_return_val_if_fail (orig_paper, NULL);
+
+       paper = g_new0 (glPaper,1);
+
+       paper->id     = g_strdup (orig_paper->id);
+       paper->name   = g_strdup (orig_paper->name);
+       paper->width  = orig_paper->width;
+       paper->height = orig_paper->height;
+
+       return paper;
+}
+
+/*****************************************************************************/
+/* Free up a paper.                                                       */
+/*****************************************************************************/
+void gl_paper_free (glPaper *paper)
+{
+
+       if ( paper != NULL ) {
+
+               g_free (paper->id);
+               paper->name = NULL;
+
+               g_free (paper->name);
+               paper->name = NULL;
+
+               g_free (paper);
+       }
+
+}
+
+/*****************************************************************************/
+/* Get a list of known page size ids                                         */
+/*****************************************************************************/
+GList *
+gl_paper_get_id_list (void)
+{
+       GList           *ids = NULL;
+       GList           *p;
+       glPaper         *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       for ( p=papers; p != NULL; p=p->next ) {
+               paper = (glPaper *)p->data;
+               ids = g_list_append (ids, g_strdup (paper->id));
+       }
+
+       return ids;
+}
+
+/*****************************************************************************/
+/* Free a list of page size ids.                                             */
+/*****************************************************************************/
+void
+gl_paper_free_id_list (GList *ids)
+{
+       GList *p;
+
+       for (p = ids; p != NULL; p = p->next) {
+               g_free (p->data);
+               p->data = NULL;
+       }
+
+       g_list_free (ids);
+}
+
+/*****************************************************************************/
+/* Get a list of known page size names                                       */
+/*****************************************************************************/
+GList *
+gl_paper_get_name_list (void)
+{
+       GList           *names = NULL;
+       GList           *p;
+       glPaper         *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       for ( p=papers; p != NULL; p=p->next ) {
+               paper = (glPaper *)p->data;
+               names = g_list_append (names, g_strdup (paper->name));
+       }
+
+       return names;
+}
+
+/*****************************************************************************/
+/* Free a list of page size names.                                           */
+/*****************************************************************************/
+void
+gl_paper_free_name_list (GList *names)
+{
+       GList *p;
+
+       for (p = names; p != NULL; p = p->next) {
+               g_free (p->data);
+               p->data = NULL;
+       }
+
+       g_list_free (names);
+}
+
+/*****************************************************************************/
+/* Is page size id known?                                                    */
+/*****************************************************************************/
+gboolean
+gl_paper_is_id_known (const gchar *id)
+{
+       GList       *p;
+       glPaper     *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       if (id == NULL) {
+               return FALSE;
+       }
+
+       for (p = papers; p != NULL; p = p->next) {
+               paper = (glPaper *) p->data;
+               if (g_strcasecmp (paper->id, id) == 0) {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+/*****************************************************************************/
+/* Is page size id "Other?"                                                  */
+/*****************************************************************************/
+gboolean
+gl_paper_is_id_other (const gchar *id)
+{
+       if (id == NULL) {
+               return FALSE;
+       }
+
+       return (g_strcasecmp (id, "Other") == 0);
+}
+
+/*****************************************************************************/
+/* Return a paper structure from id.                                         */
+/*****************************************************************************/
+glPaper *
+gl_paper_from_id (const gchar *id)
+{
+       GList       *p;
+       glPaper     *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       if (id == NULL) {
+               /* If no id, return first paper as a default */
+               return gl_paper_dup ((glPaper *) papers->data);
+       }
+
+       for (p = papers; p != NULL; p = p->next) {
+               paper = (glPaper *) p->data;
+               if (g_strcasecmp (paper->id, id) == 0) {
+                       return gl_paper_dup (paper);
+               }
+       }
+
+       return NULL;
+}
+
+/*****************************************************************************/
+/* Return a paper structure from name.                                       */
+/*****************************************************************************/
+glPaper *
+gl_paper_from_name (const gchar *name)
+{
+       GList       *p;
+       glPaper     *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       if (name == NULL) {
+               /* If no name, return first paper as a default */
+               return gl_paper_dup ((glPaper *) papers->data);
+       }
+
+       for (p = papers; p != NULL; p = p->next) {
+               paper = (glPaper *) p->data;
+               if (g_strcasecmp (paper->name, name) == 0) {
+                       return gl_paper_dup (paper);
+               }
+       }
+
+       return NULL;
+}
+
+/*****************************************************************************/
+/* Lookup paper id from name.                                                */
+/*****************************************************************************/
+gchar *
+gl_paper_lookup_id_from_name (const gchar       *name)
+{
+       glPaper *paper = NULL;
+       gchar   *id = NULL;
+
+       g_return_val_if_fail (name, NULL);
+
+       paper = gl_paper_from_name (name);
+       if ( paper != NULL ) {
+               id = g_strdup (paper->id);
+               gl_paper_free (paper);
+               paper = NULL;
+       }
+
+       return id;
+}
+
+/*****************************************************************************/
+/* Lookup paper name from id.                                                */
+/*****************************************************************************/
+gchar *
+gl_paper_lookup_name_from_id (const gchar       *id)
+{
+       glPaper *paper = NULL;
+       gchar   *name = NULL;
+
+       g_return_val_if_fail (id, NULL);
+
+       paper = gl_paper_from_id (id);
+       if ( paper != NULL ) {
+               name = g_strdup (paper->name);
+               gl_paper_free (paper);
+               paper = NULL;
+       }
+
+       return name;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Read papers from various  files.                            */
+/*--------------------------------------------------------------------------*/
+static GList *
+read_papers (void)
+{
+       gchar *data_dir;
+       GList *papers = NULL;
+
+       data_dir = GL_SYSTEM_DATA_DIR;
+       papers = read_paper_files_from_dir (papers, data_dir);
+       g_free (data_dir);
+
+       data_dir = GL_USER_DATA_DIR;
+       papers = read_paper_files_from_dir (papers, data_dir);
+       g_free (data_dir);
+
+       if (papers == NULL) {
+               g_warning (_("No paper files found!"));
+       }
+
+       return papers;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Read all paper files from given directory.  Append to list. */
+/*--------------------------------------------------------------------------*/
+static GList *
+read_paper_files_from_dir (GList       *papers,
+                          const gchar *dirname)
+{
+       GDir        *dp;
+       const gchar *filename, *extension;
+       gchar       *full_filename = NULL;
+       GError      *gerror = NULL;
+       GList       *new_papers = NULL;
+
+       if (dirname == NULL) {
+               return papers;
+       }
+
+       if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
+               return papers;
+       }
+
+       dp = g_dir_open (dirname, 0, &gerror);
+       if (gerror != NULL) {
+               g_warning ("cannot open data directory: %s", gerror->message );
+               return papers;
+       }
+
+       while ((filename = g_dir_read_name (dp)) != NULL) {
+
+               extension = strrchr (filename, '.');
+
+               if (extension != NULL) {
+
+                       if ( (g_strcasecmp (extension, ".paper") == 0)
+                            || (g_strcasecmp (filename, "paper-sizes.xml") == 0) ) {
+
+                               full_filename =
+                                   g_build_filename (dirname, filename, NULL);
+                               new_papers =
+                                   gl_xml_paper_read_papers_from_file (full_filename);
+                               g_free (full_filename);
+
+                               papers = g_list_concat (papers, new_papers);
+                               new_papers = NULL;
+
+                       }
+
+               }
+
+       }
+
+       g_dir_close (dp);
+
+       return papers;
+}
+
+/*****************************************************************************/
+/* Print known papers (for debugging purposes)                               */
+/*****************************************************************************/
+void
+gl_paper_print_known_papers (void)
+{
+       GList       *p;
+       glPaper     *paper;
+
+       if (!papers) {
+               gl_paper_init ();
+       }
+
+       g_print ("%s():\n", __FUNCTION__);
+       for (p = papers; p != NULL; p = p->next) {
+               paper = (glPaper *) p->data;
+
+               g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n",
+                        paper->id, paper->name, paper->width, paper->height);
+
+       }
+       g_print ("\n");
+
+}
+
+
diff --git a/glabels2/libglabels/paper.h b/glabels2/libglabels/paper.h
new file mode 100644 (file)
index 0000000..aeb1bce
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  paper.h:  paper module header file
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __PAPER_H__
+#define __PAPER_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+
+/*
+ *   glPaper structure
+ */
+typedef struct _glPaper glPaper;
+
+struct _glPaper {
+       gchar               *id;
+       gchar               *name;
+       gdouble              width;
+       gdouble              height;
+};
+
+
+/*
+ * Module initialization
+ */
+void                 gl_paper_init                (void);
+
+
+/*
+ * Paper construction
+ */
+glPaper             *gl_paper_new                 (gchar           *id,
+                                                  gchar           *name,
+                                                  gdouble          width,
+                                                  gdouble          height);
+
+glPaper             *gl_paper_dup                 (const glPaper   *orig);
+
+void                 gl_paper_free                (glPaper         *paper);
+
+
+/*
+ * ID lists
+ */
+GList               *gl_paper_get_id_list         (void);
+void                 gl_paper_free_id_list        (GList           *ids);
+
+
+/*
+ * Name lists
+ */
+GList               *gl_paper_get_name_list       (void);
+void                 gl_paper_free_name_list      (GList           *names);
+
+
+/*
+ * Query functions
+ */
+gboolean             gl_paper_is_id_known         (const gchar     *id);
+gboolean             gl_paper_is_id_other         (const gchar     *id);
+
+glPaper             *gl_paper_from_id             (const gchar     *id);
+glPaper             *gl_paper_from_name           (const gchar     *name);
+
+gchar               *gl_paper_lookup_id_from_name (const gchar     *name);
+gchar               *gl_paper_lookup_name_from_id (const gchar     *id);
+
+
+/*
+ * Debugging
+ */
+void                 gl_paper_print_known_papers  (void);
+
+
+G_END_DECLS
+
+#endif
diff --git a/glabels2/libglabels/template.c b/glabels2/libglabels/template.c
new file mode 100644 (file)
index 0000000..248d785
--- /dev/null
@@ -0,0 +1,1017 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  template.c:  template module
+ *
+ *  Copyright (C) 2001-2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#include "libglabels-private.h"
+
+#include <string.h>
+
+#include "xml.h"
+#include "template.h"
+#include "xml-template.h"
+#include "paper.h"
+
+#define FULL_PAGE "Full-page"
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+static GList *templates = NULL;
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+static glTemplate *template_full_page           (const gchar            *page_size);
+
+static GList      *read_templates               (void);
+
+static GList      *read_template_files_from_dir (GList                  *templates,
+                                                const gchar            *dirname);
+static gint        compare_origins              (gconstpointer           a,
+                                                gconstpointer           b,
+                                                gpointer                user_data);
+
+/*****************************************************************************/
+/* Initialize module.                                                        */
+/*****************************************************************************/
+void
+gl_template_init (void)
+{
+       GList *page_sizes, *p;
+
+       if (templates) {
+               return; /* Already initialized */
+       }
+
+       templates = read_templates ();
+
+       page_sizes = gl_paper_get_id_list ();
+       for ( p=page_sizes; p != NULL; p=p->next ) {
+               if ( !gl_paper_is_id_other (p->data) ) {
+                       templates = g_list_append (templates,
+                                                  template_full_page (p->data));
+               }
+       }
+       gl_paper_free_id_list (page_sizes);
+}
+
+/*****************************************************************************/
+/* Register template: if not in current list, add it.                        */
+/*****************************************************************************/
+void
+gl_template_register (const glTemplate  *template)
+{
+       GList      *p_tmplt, *pa1;
+       glTemplate *template1;
+
+       if (!templates) {
+               gl_template_init ();
+       }
+
+       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
+               template1 = (glTemplate *) p_tmplt->data;
+
+               for (pa1=template1->aliases; pa1!=NULL; pa1=pa1->next) {
+                       
+                       if (g_strcasecmp (template->name, pa1->data) == 0) {
+
+                               /* FIXME: make sure templates are really identical */
+                               /*        if not, apply hash to name to make unique. */
+                               return;
+                       }
+                               
+               }
+
+       }
+
+       if (gl_paper_is_id_known (template->page_size)) {
+
+               gchar *dir, *filename, *abs_filename;
+
+               templates = g_list_append (templates,
+                                          gl_template_dup (template));
+
+               /* FIXME: make sure filename is unique */
+               dir = GL_USER_DATA_DIR;
+               mkdir (dir, 0775); /* Try to make sure directory exists. */
+               filename = g_strconcat (template->name, ".template", NULL);
+               abs_filename = g_build_filename (dir, filename, NULL);
+               gl_xml_template_write_template_to_file (template, abs_filename);
+               g_free (dir);
+               g_free (filename);
+               g_free (abs_filename);
+
+       } else {
+               g_warning ("Cannot register new template with unknown page size.");
+       }
+
+}
+
+/*****************************************************************************/
+/* Get a list of valid template names for given page size                    */
+/*****************************************************************************/
+GList *
+gl_template_get_name_list (const gchar *page_size)
+{
+       GList      *p_tmplt, *p_alias;
+       glTemplate *template;
+       gchar      *str;
+       GList      *names = NULL;
+
+       if (!templates) {
+               gl_template_init ();
+       }
+
+       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
+               template = (glTemplate *) p_tmplt->data;
+               if (g_strcasecmp (page_size, template->page_size) == 0) {
+                       for (p_alias = template->aliases; p_alias != NULL;
+                            p_alias = p_alias->next) {
+                               str = g_strdup_printf("%s: %s",
+                                                     (gchar *) p_alias->data,
+                                                     template->description);
+                               names = g_list_insert_sorted (names, str,
+                                                            (GCompareFunc)g_strcasecmp);
+                       }
+               }
+       }
+
+       return names;
+}
+
+/*****************************************************************************/
+/* Free a list of template names.                                            */
+/*****************************************************************************/
+void
+gl_template_free_name_list (GList *names)
+{
+       GList *p_name;
+
+       for (p_name = names; p_name != NULL; p_name = p_name->next) {
+               g_free (p_name->data);
+               p_name->data = NULL;
+       }
+
+       g_list_free (names);
+}
+
+/*****************************************************************************/
+/* Return a template structure from a name.                                  */
+/*****************************************************************************/
+glTemplate *
+gl_template_from_name (const gchar *name)
+{
+       GList       *p_tmplt, *p_alias;
+       glTemplate  *template, *new_template;
+       gchar      **split_name;
+
+       if (!templates) {
+               gl_template_init ();
+       }
+
+       if (name == NULL) {
+               /* If no name, return first template as a default */
+               return gl_template_dup ((glTemplate *) templates->data);
+       }
+
+       /* Strip off any descriptions */
+       split_name = g_strsplit (name, ":", 2);
+
+       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
+               template = (glTemplate *) p_tmplt->data;
+               for (p_alias = template->aliases; p_alias != NULL;
+                    p_alias = p_alias->next) {
+                       if (g_strcasecmp (p_alias->data, split_name[0]) == 0) {
+
+                               new_template = gl_template_dup (template);
+
+                               /* Use the real name */
+                               g_free (new_template->name);
+                               new_template->name = g_strdup (split_name[0]);
+
+                               g_strfreev (split_name);
+
+                               return new_template;
+                       }
+               }
+       }
+
+       g_strfreev (split_name);
+
+       /* No matching template has been found so return the first template */
+       return gl_template_dup ((glTemplate *) templates->data);
+}
+
+/*****************************************************************************/
+/* Get name and format with description.                                     */
+/*****************************************************************************/
+gchar *
+gl_template_get_name_with_desc (const glTemplate  *template)
+{
+       g_return_val_if_fail (template, NULL);
+
+       return g_strdup_printf("%s: %s", template->name, template->description);
+}
+
+/*****************************************************************************/
+/* Get first label type in template.                                         */
+/*****************************************************************************/
+const glTemplateLabelType *
+gl_template_get_first_label_type (const glTemplate *template)
+{
+       g_return_val_if_fail (template, NULL);
+
+       return (glTemplateLabelType *)template->label_types->data;
+}
+
+/****************************************************************************/
+/* Get raw label size (width and height).                                   */
+/****************************************************************************/
+void
+gl_template_get_label_size (const glTemplateLabelType *label_type,
+                           gdouble                   *w,
+                           gdouble                   *h)
+{
+       g_return_if_fail (label_type);
+
+       switch (label_type->shape) {
+       case GL_TEMPLATE_SHAPE_RECT:
+               *w = label_type->size.rect.w;
+               *h = label_type->size.rect.h;
+               break;
+       case GL_TEMPLATE_SHAPE_ROUND:
+               *w = 2.0 * label_type->size.round.r;
+               *h = 2.0 * label_type->size.round.r;
+               break;
+       case GL_TEMPLATE_SHAPE_CD:
+               if (label_type->size.cd.w == 0.0) {
+                       *w = 2.0 * label_type->size.cd.r1;
+               } else {
+                       *w = label_type->size.cd.w;
+               }
+               if (label_type->size.cd.h == 0.0) {
+                       *h = 2.0 * label_type->size.cd.r1;
+               } else {
+                       *h = label_type->size.cd.h;
+               }
+               break;
+       default:
+               *w = 0.0;
+               *h = 0.0;
+               break;
+       }
+}
+
+/****************************************************************************/
+/* Get total number of labels per sheet of a label type.                    */
+/****************************************************************************/
+gint
+gl_template_get_n_labels (const glTemplateLabelType *label_type)
+{
+       gint              n_labels = 0;
+       GList            *p;
+       glTemplateLayout *layout;
+
+       g_return_val_if_fail (label_type, 0);
+
+       for ( p=label_type->layouts; p != NULL; p=p->next ) {
+               layout = (glTemplateLayout *)p->data;
+
+               n_labels += layout->nx * layout->ny;
+       }
+
+       return n_labels;
+}
+
+/****************************************************************************/
+/* Get array of origins of individual labels.                               */
+/****************************************************************************/
+glTemplateOrigin *
+gl_template_get_origins (const glTemplateLabelType *label_type)
+{
+       gint              i_label, n_labels, ix, iy;
+       glTemplateOrigin *origins;
+       GList            *p;
+       glTemplateLayout *layout;
+
+       g_return_val_if_fail (label_type, NULL);
+
+       n_labels = gl_template_get_n_labels (label_type);
+       origins = g_new0 (glTemplateOrigin, n_labels);
+
+       i_label = 0;
+       for ( p=label_type->layouts; p != NULL; p=p->next ) {
+               layout = (glTemplateLayout *)p->data;
+
+               for (iy = 0; iy < layout->ny; iy++) {
+                       for (ix = 0; ix < layout->nx; ix++, i_label++) {
+                               origins[i_label].x = ix*layout->dx + layout->x0;
+                               origins[i_label].y = iy*layout->dy + layout->y0;
+                       }
+               }
+       }
+
+       g_qsort_with_data (origins, n_labels, sizeof(glTemplateOrigin),
+                          compare_origins, NULL);
+
+       return origins;
+}
+
+/*****************************************************************************/
+/* Create a new template with given properties.                              */
+/*****************************************************************************/
+glTemplate *
+gl_template_new (const gchar         *name,
+                const gchar         *description,
+                const gchar         *page_size,
+                gdouble              page_width,
+                gdouble              page_height)
+{
+       glTemplate *template;
+
+       template = g_new0 (glTemplate,1);
+
+       template->name        = g_strdup (name);
+       template->description = g_strdup (description);
+       template->page_size   = g_strdup (page_size);
+       template->page_width  = page_width;
+       template->page_height = page_height;
+
+       /* Always include primary name in alias list. */
+       template->aliases = NULL;
+       template->aliases = g_list_append (template->aliases, g_strdup (name));
+
+       return template;
+}
+
+/*****************************************************************************/
+/* Add label type structure to label type list of template.                  */
+/*****************************************************************************/
+void
+gl_template_add_label_type (glTemplate          *template,
+                           glTemplateLabelType *label_type)
+{
+       g_return_if_fail (template);
+       g_return_if_fail (label_type);
+
+       template->label_types = g_list_append (template->label_types,
+                                              label_type);
+}
+/*****************************************************************************/
+/* Add alias to alias list of template.                                      */
+/*****************************************************************************/
+void
+gl_template_add_alias (glTemplate          *template,
+                      const gchar         *alias)
+{
+       g_return_if_fail (template);
+       g_return_if_fail (alias);
+
+       template->aliases = g_list_append (template->aliases,
+                                          g_strdup (alias));
+}
+/*****************************************************************************/
+/* Create a new label type structure for a rectangular label.                */
+/*****************************************************************************/
+glTemplateLabelType *
+gl_template_rect_label_type_new  (const gchar         *id,
+                                 gdouble              w,
+                                 gdouble              h,
+                                 gdouble              r,
+                                 gdouble              waste)
+{
+       glTemplateLabelType *label_type;
+
+       label_type = g_new0 (glTemplateLabelType, 1);
+
+       label_type->id    = g_strdup (id);
+       label_type->waste = waste;
+       label_type->shape = GL_TEMPLATE_SHAPE_RECT;
+
+       label_type->size.rect.w = w;
+       label_type->size.rect.h = h;
+       label_type->size.rect.r = r;
+
+       return label_type;
+}
+                                                                               
+/*****************************************************************************/
+/* Create a new label type structure for a round label.                      */
+/*****************************************************************************/
+glTemplateLabelType *
+gl_template_round_label_type_new (const gchar         *id,
+                                 gdouble              r,
+                                 gdouble              waste)
+{
+       glTemplateLabelType *label_type;
+
+       label_type = g_new0 (glTemplateLabelType, 1);
+
+       label_type->id    = g_strdup (id);
+       label_type->waste = waste;
+       label_type->shape = GL_TEMPLATE_SHAPE_ROUND;
+
+       label_type->size.round.r = r;
+
+       return label_type;
+}
+                                                                               
+/*****************************************************************************/
+/* Create a new label type structure for a CD/DVD label.                     */
+/*****************************************************************************/
+glTemplateLabelType *
+gl_template_cd_label_type_new (const gchar         *id,
+                              gdouble              r1,
+                              gdouble              r2,
+                              gdouble              w,
+                              gdouble              h,
+                              gdouble              waste)
+{
+       glTemplateLabelType *label_type;
+
+       label_type = g_new0 (glTemplateLabelType, 1);
+
+       label_type->id    = g_strdup (id);
+       label_type->waste = waste;
+       label_type->shape = GL_TEMPLATE_SHAPE_CD;
+
+       label_type->size.cd.r1 = r1;
+       label_type->size.cd.r2 = r2;
+       label_type->size.cd.w  = w;
+       label_type->size.cd.h  = h;
+
+       return label_type;
+}
+
+/*****************************************************************************/
+/* Add a layout to a label type.                                             */
+/*****************************************************************************/
+void
+gl_template_add_layout (glTemplateLabelType *label_type,
+                       glTemplateLayout    *layout)
+{
+       g_return_if_fail (label_type);
+       g_return_if_fail (layout);
+
+       label_type->layouts = g_list_append (label_type->layouts,
+                                            layout);
+}
+/*****************************************************************************/
+/* Add a markup item to a label type.                                        */
+/*****************************************************************************/
+void
+gl_template_add_markup (glTemplateLabelType *label_type,
+                       glTemplateMarkup    *markup)
+{
+       g_return_if_fail (label_type);
+       g_return_if_fail (markup);
+
+       label_type->markups = g_list_append (label_type->markups,
+                                            markup);
+}
+/*****************************************************************************/
+/* Create new layout structure.                                              */
+/*****************************************************************************/
+glTemplateLayout *
+gl_template_layout_new (gdouble nx,
+                       gdouble ny,
+                       gdouble x0,
+                       gdouble y0,
+                       gdouble dx,
+                       gdouble dy)
+{
+       glTemplateLayout *layout;
+
+       layout = g_new0 (glTemplateLayout, 1);
+
+       layout->nx = nx;
+       layout->ny = ny;
+       layout->x0 = x0;
+       layout->y0 = y0;
+       layout->dx = dx;
+       layout->dy = dy;
+
+       return layout;
+}
+
+/*****************************************************************************/
+/* Create new margin markup structure.                                       */
+/*****************************************************************************/
+glTemplateMarkup *
+gl_template_markup_margin_new (gdouble size)
+{
+       glTemplateMarkup *markup;
+
+       markup = g_new0 (glTemplateMarkup, 1);
+
+       markup->type             = GL_TEMPLATE_MARKUP_MARGIN;
+       markup->data.margin.size = size;
+
+       return markup;
+}
+
+/*****************************************************************************/
+/* Create new markup line structure.                                         */
+/*****************************************************************************/
+glTemplateMarkup *
+gl_template_markup_line_new (gdouble x1,
+                            gdouble y1,
+                            gdouble x2,
+                            gdouble y2)
+{
+       glTemplateMarkup *markup;
+
+       markup = g_new0 (glTemplateMarkup, 1);
+
+       markup->type             = GL_TEMPLATE_MARKUP_LINE;
+       markup->data.line.x1     = x1;
+       markup->data.line.y1     = y1;
+       markup->data.line.x2     = x2;
+       markup->data.line.y2     = y2;
+
+       return markup;
+}
+
+/*****************************************************************************/
+/* Create new markup circle structure.                                       */
+/*****************************************************************************/
+glTemplateMarkup *
+gl_template_markup_circle_new (gdouble x0,
+                              gdouble y0,
+                              gdouble r)
+{
+       glTemplateMarkup *markup;
+
+       markup = g_new0 (glTemplateMarkup, 1);
+
+       markup->type             = GL_TEMPLATE_MARKUP_CIRCLE;
+       markup->data.circle.x0   = x0;
+       markup->data.circle.y0   = y0;
+       markup->data.circle.r    = r;
+
+       return markup;
+}
+
+
+/*****************************************************************************/
+/* Copy a template.                                                          */
+/*****************************************************************************/
+glTemplate *
+gl_template_dup (const glTemplate *orig_template)
+{
+       glTemplate          *template;
+       GList               *p;
+       glTemplateLabelType *label_type;
+
+       g_return_val_if_fail (orig_template, NULL);
+
+       template = gl_template_new (orig_template->name,
+                                   orig_template->description,
+                                   orig_template->page_size,
+                                   orig_template->page_width,
+                                   orig_template->page_height);
+
+       for ( p=orig_template->label_types; p != NULL; p=p->next ) {
+
+               label_type = (glTemplateLabelType *)p->data;
+
+               gl_template_add_label_type (template,
+                                           gl_template_label_type_dup (label_type));
+       }
+
+       for ( p=orig_template->aliases; p != NULL; p=p->next ) {
+
+               if (g_strcasecmp (template->name, p->data) != 0) {
+                       gl_template_add_alias (template, p->data);
+               }
+
+       }
+
+       return template;
+}
+
+/*****************************************************************************/
+/* Free up a template.                                                       */
+/*****************************************************************************/
+void
+gl_template_free (glTemplate *template)
+{
+       GList               *p;
+       glTemplateLabelType *label_type;
+
+       if ( template != NULL ) {
+
+               g_free (template->name);
+               template->name = NULL;
+
+               g_free (template->description);
+               template->description = NULL;
+
+               g_free (template->page_size);
+               template->page_size = NULL;
+
+               for ( p=template->label_types; p != NULL; p=p->next ) {
+
+                       label_type = (glTemplateLabelType *)p->data;
+
+                       gl_template_label_type_free (label_type);
+                       p->data = NULL;
+               }
+               g_list_free (template->label_types);
+               template->label_types = NULL;
+
+               for ( p=template->aliases; p != NULL; p=p->next ) {
+
+                       g_free (p->data);
+                       p->data = NULL;
+
+               }
+               g_list_free (template->aliases);
+               template->aliases = NULL;
+
+               g_free (template);
+
+       }
+
+}
+
+/*****************************************************************************/
+/* Copy a template label type.                                               */
+/*****************************************************************************/
+glTemplateLabelType *
+gl_template_label_type_dup (const glTemplateLabelType *orig_label_type)
+{
+       glTemplateLabelType *label_type;
+       GList               *p;
+       glTemplateLayout    *layout;
+       glTemplateMarkup    *markup;
+
+       g_return_val_if_fail (orig_label_type, NULL);
+
+       switch (orig_label_type->shape) {
+
+       case GL_TEMPLATE_SHAPE_RECT:
+               label_type =
+                       gl_template_rect_label_type_new (orig_label_type->id,
+                                                        orig_label_type->size.rect.w,
+                                                        orig_label_type->size.rect.h,
+                                                        orig_label_type->size.rect.r,
+                                                        orig_label_type->waste);
+               break;
+
+       case GL_TEMPLATE_SHAPE_ROUND:
+               label_type =
+                       gl_template_round_label_type_new (orig_label_type->id,
+                                                         orig_label_type->size.round.r,
+                                                         orig_label_type->waste);
+               break;
+
+       case GL_TEMPLATE_SHAPE_CD:
+               label_type =
+                       gl_template_cd_label_type_new (orig_label_type->id,
+                                                      orig_label_type->size.cd.r1,
+                                                      orig_label_type->size.cd.r2,
+                                                      orig_label_type->size.cd.w,
+                                                      orig_label_type->size.cd.h,
+                                                      orig_label_type->waste);
+               break;
+
+       default:
+               return NULL;
+               break;
+       }
+
+       for ( p=orig_label_type->layouts; p != NULL; p=p->next ) {
+
+               layout = (glTemplateLayout *)p->data;
+
+               gl_template_add_layout (label_type,
+                                       gl_template_layout_dup (layout));
+       }
+
+       for ( p=orig_label_type->markups; p != NULL; p=p->next ) {
+
+               markup = (glTemplateMarkup *)p->data;
+
+               gl_template_add_markup (label_type,
+                                       gl_template_markup_dup (markup));
+       }
+
+       return label_type;
+}
+
+/*****************************************************************************/
+/* Free up a template label type.                                            */
+/*****************************************************************************/
+void
+gl_template_label_type_free (glTemplateLabelType *label_type)
+{
+       GList               *p;
+       glTemplateLayout    *layout;
+       glTemplateMarkup    *markup;
+
+       if ( label_type != NULL ) {
+
+               g_free (label_type->id);
+               label_type->id = NULL;
+
+               for ( p=label_type->layouts; p != NULL; p=p->next ) {
+
+                       layout = (glTemplateLayout *)p->data;
+
+                       gl_template_layout_free (layout);
+                       p->data = NULL;
+               }
+               g_list_free (label_type->layouts);
+               label_type->layouts = NULL;
+
+               for ( p=label_type->markups; p != NULL; p=p->next ) {
+
+                       markup = (glTemplateMarkup *)p->data;
+
+                       gl_template_markup_free (markup);
+                       p->data = NULL;
+               }
+               g_list_free (label_type->markups);
+               label_type->markups = NULL;
+
+               g_free (label_type);
+
+       }
+
+}
+
+/*****************************************************************************/
+/* Duplicate layout structure.                                               */
+/*****************************************************************************/
+glTemplateLayout *
+gl_template_layout_dup (const glTemplateLayout *orig_layout)
+{
+       glTemplateLayout *layout;
+
+       g_return_val_if_fail (orig_layout, NULL);
+
+       layout = g_new0 (glTemplateLayout, 1);
+
+       /* copy contents */
+       *layout = *orig_layout;
+
+       return layout;
+}
+
+/*****************************************************************************/
+/* Free layout structure.                                                    */
+/*****************************************************************************/
+void
+gl_template_layout_free (glTemplateLayout *layout)
+{
+       g_free (layout);
+}
+
+/*****************************************************************************/
+/* Duplicate markup structure.                                               */
+/*****************************************************************************/
+glTemplateMarkup *
+gl_template_markup_dup (const glTemplateMarkup *orig_markup)
+{
+       glTemplateMarkup *markup;
+
+       g_return_val_if_fail (orig_markup, NULL);
+
+       markup = g_new0 (glTemplateMarkup, 1);
+
+       *markup = *orig_markup;
+
+       return markup;
+}
+
+/*****************************************************************************/
+/* Free markup structure.                                                    */
+/*****************************************************************************/
+void
+gl_template_markup_free (glTemplateMarkup *markup)
+{
+       g_free (markup);
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Make a template for a full page of the given page size.        */
+/*--------------------------------------------------------------------------*/
+static glTemplate *
+template_full_page (const gchar *page_size)
+{
+       glPaper               *paper = NULL;
+       glTemplate            *template = NULL;
+       glTemplateLabelType   *label_type = NULL;
+       gchar                 *name;
+
+       g_return_val_if_fail (page_size, NULL);
+
+       paper = gl_paper_from_id (page_size);
+       if ( paper == NULL ) {
+               return NULL;
+       }
+
+       name         = g_strdup_printf (_("Generic %s full page"), page_size);
+
+       template = gl_template_new (name,
+                                   FULL_PAGE,
+                                   page_size,
+                                   paper->width,
+                                   paper->height);
+
+
+       label_type = gl_template_rect_label_type_new ("0",
+                                                     paper->width,
+                                                     paper->height,
+                                                     0.0,
+                                                     0.0);
+       gl_template_add_label_type (template, label_type);
+
+       gl_template_add_layout (label_type,
+                               gl_template_layout_new (1, 1, 0., 0., 0., 0.));
+
+       gl_template_add_markup (label_type,
+                               gl_template_markup_margin_new (9.0));
+
+       g_free (name);
+       name = NULL;
+       gl_paper_free (paper);
+       paper = NULL;
+
+       return template;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Read templates from various  files.                            */
+/*--------------------------------------------------------------------------*/
+static GList *
+read_templates (void)
+{
+       gchar *data_dir;
+       GList *templates = NULL;
+
+       data_dir = GL_SYSTEM_DATA_DIR;
+       templates = read_template_files_from_dir (templates, data_dir);
+       g_free (data_dir);
+
+       data_dir = GL_USER_DATA_DIR;
+       templates = read_template_files_from_dir (templates, data_dir);
+       g_free (data_dir);
+
+       if (templates == NULL) {
+               g_warning (_("No template files found!"));
+       }
+
+       return templates;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Read all template files from given directory.  Append to list. */
+/*--------------------------------------------------------------------------*/
+static GList *
+read_template_files_from_dir (GList       *templates,
+                             const gchar *dirname)
+{
+       GDir        *dp;
+       const gchar *filename, *extension, *extension2;
+       gchar       *full_filename = NULL;
+       GError      *gerror = NULL;
+       GList       *new_templates = NULL;
+
+       if (dirname == NULL)
+               return templates;
+
+       if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
+               return templates;
+       }
+
+       dp = g_dir_open (dirname, 0, &gerror);
+       if (gerror != NULL) {
+               g_warning ("cannot open data directory: %s", gerror->message );
+               return templates;
+       }
+
+       while ((filename = g_dir_read_name (dp)) != NULL) {
+
+               extension = strrchr (filename, '.');
+               extension2 = strrchr (filename, '-');
+
+               if (extension != NULL) {
+
+                       if ( (g_strcasecmp (extension, ".template") == 0)
+                            || (g_strcasecmp (extension2, "-templates.xml") == 0) ) {
+
+                               full_filename =
+                                   g_build_filename (dirname, filename, NULL);
+                               new_templates =
+                                   gl_xml_template_read_templates_from_file (full_filename);
+                               g_free (full_filename);
+
+                               templates = g_list_concat (templates, new_templates);
+                               new_templates = NULL;
+                       }
+
+               }
+
+       }
+
+       g_dir_close (dp);
+
+       return templates;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Sort origins comparison function, first by y then by x.        */
+/*--------------------------------------------------------------------------*/
+static gint
+compare_origins (gconstpointer a,
+                gconstpointer b,
+                gpointer      user_data)
+{
+       const glTemplateOrigin *a_origin = a, *b_origin = b;
+
+       if ( a_origin->y < b_origin->y ) {
+               return -1;
+       } else if ( a_origin->y > b_origin->y ) {
+               return +1;
+       } else {
+               if ( a_origin->x < b_origin->x ) {
+                       return -1;
+               } else if ( a_origin->x > b_origin->x ) {
+                       return +1;
+               } else {
+                       return 0; /* hopefully 2 labels won't have the same origin */
+               }
+       }
+}
+
+/*****************************************************************************/
+/* Print all known templates (for debugging purposes).                       */
+/*****************************************************************************/
+void
+gl_template_print_known_templates (void)
+{
+       GList      *p;
+       glTemplate *template;
+
+       g_print ("%s():\n", __FUNCTION__);
+       for (p=templates; p!=NULL; p=p->next) {
+               template = (glTemplate *)p->data;
+
+               g_print("TEMPLATE name=\"%s\", description=\"%s\"\n",
+                       template->name, template->description);
+
+       }
+       g_print ("\n");
+
+}
+
+/*****************************************************************************/
+/* Print all aliases of a template (for debugging purposes).                 */
+/*****************************************************************************/
+void
+gl_template_print_aliases (const glTemplate *template)
+{
+       GList *p;
+
+       g_print ("%s():\n", __FUNCTION__);
+       for (p=template->aliases; p!=NULL; p=p->next) {
+               
+               g_print("Alias = \"%s\"\n", p->data);
+
+       }
+       g_print ("\n");
+
+}
+
diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h
new file mode 100644 (file)
index 0000000..38f4c55
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  template.h:  template module header file
+ *
+ *  Copyright (C) 2001-2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __TEMPLATE_H__
+#define __TEMPLATE_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _glTemplate          glTemplate;
+typedef struct _glTemplateLabelType glTemplateLabelType;
+typedef struct _glTemplateLayout    glTemplateLayout;
+typedef struct _glTemplateMarkup    glTemplateMarkup;
+typedef struct _glTemplateOrigin    glTemplateOrigin;
+
+
+/*
+ *   Top-level Template Structure
+ */
+struct _glTemplate {
+
+       gchar               *name;
+       gchar               *description;
+       gchar               *page_size;
+       gdouble              page_width;
+       gdouble              page_height;
+
+       /* List of (glTemplateLabelType *) label type structures.
+        * Currently glabels only supports a single label type per
+        * template. */
+       GList               *label_types;
+
+       /* List of (gchar *) aliases. */
+       GList               *aliases;
+
+};
+
+
+/*
+ *   Possible Label Shapes
+ */
+typedef enum {
+       GL_TEMPLATE_SHAPE_RECT,
+       GL_TEMPLATE_SHAPE_ROUND,
+       GL_TEMPLATE_SHAPE_CD,
+} glTemplateLabelShape;
+
+
+/*
+ *   Label Type Structure
+ */
+struct _glTemplateLabelType{
+
+       gchar                *id;       /* Id, currently always "0" */
+       GList                *layouts;  /* List of glTemplateLayouts */
+       GList                *markups;  /* List of glTemplateMarkups */
+
+       gdouble               waste;    /* Amount of overprint allowed. */
+
+       glTemplateLabelShape  shape;
+
+       union {
+
+               struct {
+                       gdouble        w;  /* Width */
+                       gdouble        h;  /* Height */
+                       gdouble        r;  /* Corner radius */
+               } rect;
+
+               struct {
+                       gdouble        r;  /* Radius */
+               } round;
+
+               struct {
+                       gdouble        r1; /* Outer radius */
+                       gdouble        r2; /* Inner radius (hole) */
+                       gdouble        w;  /* Clip width, business card CDs */
+                       gdouble        h;  /* Clip height, business card CDs */
+               } cd;
+
+       } size;
+
+};
+
+
+/*
+ *   Label Layout Structure
+ */
+struct _glTemplateLayout {
+
+       gint                  nx;  /* Number of labels across */
+       gint                  ny;  /* Number of labels up and down */
+
+       gdouble               x0;  /* Left of grid from left edge of paper */
+       gdouble               y0;  /* Top of grid from top edge of paper */
+
+       gdouble               dx;  /* Horizontal pitch of grid */
+       gdouble               dy;  /* Vertical pitch of grid */
+
+};
+
+
+/*
+ * Possible Markup Types
+ */
+typedef enum {
+       GL_TEMPLATE_MARKUP_MARGIN,
+       GL_TEMPLATE_MARKUP_LINE,
+       GL_TEMPLATE_MARKUP_CIRCLE,
+} glTemplateMarkupType;
+
+
+/*
+ *   Label Markup Structure (Helpful lines drawn in glabels to help locate objects)
+ */
+struct _glTemplateMarkup {
+
+       glTemplateMarkupType   type;
+
+       union {
+
+               struct {
+                       gdouble                size;  /* Margin size */
+               } margin;
+
+               struct {
+                       gdouble                x1, y1; /* 1st endpoint */
+                       gdouble                x2, y2; /* 2nd endpoint */
+               } line;
+
+               struct {
+                       gdouble                x0, y0; /* Center of circle */
+                       gdouble                r;      /* Radius of circle */
+               } circle;
+               
+       } data;
+
+};
+
+
+/*
+ *  Origin coordinates
+ */
+struct _glTemplateOrigin {
+
+       gdouble               x, y; /* Label origin relative to upper 
+                                    * upper left hand corner of paper */
+
+};
+
+
+
+/*
+ * Module Initialization
+ */
+void                 gl_template_init                 (void);
+
+void                 gl_template_register             (const glTemplate    *template);
+
+/*
+ * Known templates query functions
+ */
+GList               *gl_template_get_name_list        (const gchar         *page_size);
+
+void                 gl_template_free_name_list       (GList               *names);
+
+glTemplate          *gl_template_from_name            (const gchar         *name);
+
+
+/* 
+ * Template query functions
+ */
+gchar                     *gl_template_get_name_with_desc   (const glTemplate   *template);
+
+const glTemplateLabelType *gl_template_get_first_label_type (const glTemplate   *template);
+
+
+/*
+ * Label Type query functions
+ */
+void                 gl_template_get_label_size  (const glTemplateLabelType *label_type,
+                                                 gdouble                   *w,
+                                                 gdouble                   *h);
+
+gint                 gl_template_get_n_labels    (const glTemplateLabelType *label_type);
+
+glTemplateOrigin    *gl_template_get_origins     (const glTemplateLabelType *label_type);
+
+
+/*
+ * Template Construction
+ */
+glTemplate          *gl_template_new                  (const gchar         *name,
+                                                      const gchar         *description,
+                                                      const gchar         *page_size,
+                                                      gdouble              page_width,
+                                                      gdouble              page_height);
+
+void                 gl_template_add_label_type       (glTemplate          *template,
+                                                      glTemplateLabelType *label_type);
+
+void                 gl_template_add_alias            (glTemplate          *template,
+                                                      const gchar         *alias);
+
+glTemplateLabelType *gl_template_rect_label_type_new  (const gchar         *id,
+                                                      gdouble              w,
+                                                      gdouble              h,
+                                                      gdouble              r,
+                                                      gdouble              waste);
+
+glTemplateLabelType *gl_template_round_label_type_new (const gchar         *id,
+                                                      gdouble              r,
+                                                      gdouble              waste);
+
+glTemplateLabelType *gl_template_cd_label_type_new    (const gchar         *id,
+                                                      gdouble              r1,
+                                                      gdouble              r2,
+                                                      gdouble              w,
+                                                      gdouble              h,
+                                                      gdouble              waste);
+
+void                 gl_template_add_layout           (glTemplateLabelType *label_type,
+                                                      glTemplateLayout    *layout);
+
+void                 gl_template_add_markup           (glTemplateLabelType *label_type,
+                                                      glTemplateMarkup    *markup);
+
+glTemplateLayout    *gl_template_layout_new           (gdouble              nx,
+                                                      gdouble              ny,
+                                                      gdouble              x0,
+                                                      gdouble              y0,
+                                                      gdouble              dx,
+                                                      gdouble              dy);
+
+glTemplateMarkup    *gl_template_markup_margin_new    (gdouble              size);
+
+glTemplateMarkup    *gl_template_markup_line_new      (gdouble              x1,
+                                                      gdouble              y1,
+                                                      gdouble              x2,
+                                                      gdouble              y2);
+
+glTemplateMarkup    *gl_template_markup_circle_new    (gdouble              x0,
+                                                      gdouble              y0,
+                                                      gdouble              r);
+
+glTemplate          *gl_template_dup                  (const glTemplate    *orig);
+
+void                 gl_template_free                 (glTemplate          *template);
+
+glTemplateLabelType *gl_template_label_type_dup       (const glTemplateLabelType *orig_ltype);
+void                 gl_template_label_type_free      (glTemplateLabelType       *ltype);
+
+glTemplateLayout    *gl_template_layout_dup           (const glTemplateLayout    *orig_layout);
+void                 gl_template_layout_free          (glTemplateLayout          *layout);
+
+glTemplateMarkup    *gl_template_markup_dup           (const glTemplateMarkup    *orig_markup);
+void                 gl_template_markup_free          (glTemplateMarkup          *markup);
+
+
+/*
+ * Debugging functions
+ */
+void                 gl_template_print_known_templates (void);
+void                 gl_template_print_aliases         (const glTemplate    *template);
+
+
+G_END_DECLS
+
+#endif
diff --git a/glabels2/libglabels/xml-paper.c b/glabels2/libglabels/xml-paper.c
new file mode 100644 (file)
index 0000000..7bf1628
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml-paper.c:  paper xml module
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#include "libglabels-private.h"
+
+#include <string.h>
+#include <libintl.h>
+
+#include "xml.h"
+#include "xml-paper.h"
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+\f
+/*****************************************************************************/
+/* Read papers from paper file.                                              */
+/*****************************************************************************/
+GList *
+gl_xml_paper_read_papers_from_file (gchar *utf8_filename)
+{
+       gchar      *filename;
+       GList      *papers;
+       xmlDocPtr   papers_doc;
+
+       LIBXML_TEST_VERSION;
+
+       filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+       if (!filename) {
+               g_warning ("Utf8 filename conversion error");
+               return NULL;
+       }
+
+       papers_doc = xmlParseFile (filename);
+       if (!papers_doc) {
+               g_warning ("\"%s\" is not a glabels paper file (not XML)",
+                          filename);
+               return NULL;
+       }
+
+       papers = gl_xml_paper_parse_papers_doc (papers_doc);
+
+       g_free (filename);
+       xmlFreeDoc (papers_doc);
+
+       return papers;
+}
+
+/*****************************************************************************/
+/* Read papers from paper xml doc tree.                                      */
+/*****************************************************************************/
+GList *
+gl_xml_paper_parse_papers_doc (xmlDocPtr  papers_doc)
+{
+       GList      *papers = NULL;
+       xmlNodePtr  root, node;
+       glPaper    *paper;
+
+       LIBXML_TEST_VERSION;
+
+       root = xmlDocGetRootElement (papers_doc);
+       if (!root || !root->name) {
+               g_warning ("\"%s\" is not a glabels paper file (no root node)",
+                          papers_doc->name);
+               xmlFreeDoc (papers_doc);
+               return papers;
+       }
+       if (!xmlStrEqual (root->name, "Glabels-paper-sizes")) {
+               g_warning ("\"%s\" is not a glabels paper file (wrong root node)",
+                          papers_doc->name);
+               xmlFreeDoc (papers_doc);
+               return papers;
+       }
+
+       for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
+
+               if (xmlStrEqual (node->name, "Paper-size")) {
+                       paper = gl_xml_paper_parse_paper_node (node);
+                       papers = g_list_append (papers, paper);
+               } else {
+                       if ( !xmlNodeIsText(node) ) {
+                               if (!xmlStrEqual (node->name,"comment")) {
+                                       g_warning ("bad node =  \"%s\"",node->name);
+                               }
+                       }
+               }
+       }
+
+       return papers;
+}
+
+/*****************************************************************************/
+/* Parse XML paper Node.                                                     */
+/*****************************************************************************/
+glPaper *
+gl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
+{
+       glPaper               *paper;
+       gchar                 *id, *name;
+       gdouble                width, height;
+
+       LIBXML_TEST_VERSION;
+
+       id   = xmlGetProp (paper_node, "id");
+
+       name = xmlGetProp (paper_node, "_name");
+       if (name != NULL) {
+               name = gettext (name);
+       } else {
+               name = xmlGetProp (paper_node, "name");
+       }
+
+       width  = gl_xml_get_prop_length (paper_node, "width", 0);
+       height = gl_xml_get_prop_length (paper_node, "height", 0);
+
+       paper = gl_paper_new (id, name, width, height);
+
+       g_free (id);
+       g_free (name);
+
+       return paper;
+}
+
diff --git a/glabels2/libglabels/xml-paper.h b/glabels2/libglabels/xml-paper.h
new file mode 100644 (file)
index 0000000..5ec02b7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml-paper.h:  paper xml module header file
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __XML_PAPER_H__
+#define __XML_PAPER_H__
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+#include "paper.h"
+
+G_BEGIN_DECLS
+
+GList       *gl_xml_paper_read_papers_from_file (gchar        *utf8_filename);
+
+GList       *gl_xml_paper_parse_papers_doc      (xmlDocPtr     papers_doc);
+
+glPaper     *gl_xml_paper_parse_paper_node      (xmlNodePtr    paper_node);
+
+
+G_END_DECLS
+
+#endif /* __XML_PAPER_H__ */
diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c
new file mode 100644 (file)
index 0000000..92d87cc
--- /dev/null
@@ -0,0 +1,754 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml-template.c:  template xml module
+ *
+ *  Copyright (C) 2001-2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#include "libglabels-private.h"
+
+#include <string.h>
+#include <libintl.h>
+
+#include "paper.h"
+#include "xml.h"
+#include "xml-template.h"
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+static void  xml_parse_label_rectangle_node (xmlNodePtr              label_node,
+                                            glTemplate             *template);
+static void  xml_parse_label_round_node     (xmlNodePtr              label_node,
+                                            glTemplate             *template);
+static void  xml_parse_label_cd_node        (xmlNodePtr              label_node,
+                                            glTemplate             *template);
+static void  xml_parse_layout_node          (xmlNodePtr              layout_node,
+                                            glTemplateLabelType    *label_type);
+static void  xml_parse_markup_margin_node   (xmlNodePtr              markup_node,
+                                            glTemplateLabelType    *label_type);
+static void  xml_parse_markup_line_node     (xmlNodePtr              markup_node,
+                                            glTemplateLabelType    *label_type);
+static void  xml_parse_markup_circle_node   (xmlNodePtr              markup_node,
+                                            glTemplateLabelType    *label_type);
+static void  xml_parse_alias_node           (xmlNodePtr              alias_node,
+                                            glTemplate             *template);
+
+static void  xml_create_label_node          (const glTemplateLabelType    *label_type,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+static void  xml_create_layout_node         (const glTemplateLayout       *layout,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+static void  xml_create_markup_margin_node  (const glTemplateMarkup       *margin,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+static void  xml_create_markup_line_node    (const glTemplateMarkup       *line,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+static void  xml_create_markup_circle_node  (const glTemplateMarkup       *circle,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+static void  xml_create_alias_node          (const gchar                  *name,
+                                            xmlNodePtr                    root,
+                                            const xmlNsPtr                ns);
+
+
+/*****************************************************************************/
+/* Read templates from template file.                                        */
+/*****************************************************************************/
+GList *
+gl_xml_template_read_templates_from_file (const gchar *utf8_filename)
+{
+       gchar      *filename;
+       xmlDocPtr   templates_doc;
+       GList      *templates = NULL;
+
+       LIBXML_TEST_VERSION;
+
+       filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+       if (!filename) {
+               g_warning ("Utf8 filename conversion error");
+               return NULL;
+       }
+
+       templates_doc = xmlParseFile (filename);
+       if (!templates_doc) {
+               g_warning ("\"%s\" is not a glabels template file (not XML)",
+                     filename);
+               return templates;
+       }
+
+       templates = gl_xml_template_parse_templates_doc (templates_doc);
+
+       g_free (filename);
+       xmlFreeDoc (templates_doc);
+
+       return templates;
+}
+
+/*****************************************************************************/
+/* Read templates from templates xml doc tree.                               */
+/*****************************************************************************/
+GList *
+gl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc)
+{
+       
+       GList      *templates = NULL;
+       xmlNodePtr  root, node;
+       glTemplate *template;
+
+       LIBXML_TEST_VERSION;
+
+       root = xmlDocGetRootElement (templates_doc);
+       if (!root || !root->name) {
+               g_warning ("\"%s\" is not a glabels template file (no root node)",
+                          templates_doc->name);
+               xmlFreeDoc (templates_doc);
+               return templates;
+       }
+       if (!xmlStrEqual (root->name, "Glabels-templates")) {
+               g_warning ("\"%s\" is not a glabels template file (wrong root node)",
+                     templates_doc->name);
+               xmlFreeDoc (templates_doc);
+               return templates;
+       }
+
+       for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
+
+               if (xmlStrEqual (node->name, "Template")) {
+                       template = gl_xml_template_parse_template_node (node);
+                       templates = g_list_append (templates, template);
+               } else {
+                       if ( !xmlNodeIsText(node) ) {
+                               if (!xmlStrEqual (node->name,"comment")) {
+                                       g_warning ("bad node =  \"%s\"",node->name);
+                               }
+                       }
+               }
+       }
+
+       return templates;
+}
+
+/*****************************************************************************/
+/* Parse XML template Node.                                                  */
+/*****************************************************************************/
+glTemplate *
+gl_xml_template_parse_template_node (const xmlNodePtr template_node)
+{
+       gchar                 *name;
+       gchar                 *description;
+       gchar                 *page_size;
+       gdouble                page_width, page_height;
+       glPaper               *paper = NULL;
+       glTemplate            *template;
+       xmlNodePtr             node;
+
+       name  = xmlGetProp (template_node, "name");
+
+       description = xmlGetProp (template_node, "_description");
+       if (description != NULL) {
+               description = gettext (description);
+       } else {
+               description = xmlGetProp (template_node, "description");
+       }
+
+       page_size = xmlGetProp (template_node, "size");
+       if (gl_paper_is_id_other (page_size)) {
+
+               page_width = gl_xml_get_prop_length (template_node, "width", 0);
+               page_height = gl_xml_get_prop_length (template_node, "height", 0);
+
+       } else {
+               paper = gl_paper_from_id (page_size);
+               if (paper == NULL) {
+                       /* This should always be an id, but just in case a name
+                          slips by! */
+                       g_warning (_("Unknown page size id \"%s\", trying as name"),
+                                  page_size);
+                       paper = gl_paper_from_name (page_size);
+                       g_free (page_size);
+                       page_size = g_strdup (paper->id);
+               }
+               if (paper != NULL) {
+                       page_width  = paper->width;
+                       page_height = paper->height;
+               } else {
+                       g_warning (_("Unknown page size id or name \"%s\""),
+                                  page_size);
+               }
+               gl_paper_free (paper);
+               paper = NULL;
+       }
+
+       template = gl_template_new (name,
+                                   description,
+                                   page_size,
+                                   page_width, page_height);
+
+       for (node = template_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (xmlStrEqual (node->name, "Label-rectangle")) {
+                       xml_parse_label_rectangle_node (node, template);
+               } else if (xmlStrEqual (node->name, "Label-round")) {
+                       xml_parse_label_round_node (node, template);
+               } else if (xmlStrEqual (node->name, "Label-cd")) {
+                       xml_parse_label_cd_node (node, template);
+               } else if (xmlStrEqual (node->name, "Alias")) {
+                       xml_parse_alias_node (node, template);
+               } else {
+                       if (!xmlNodeIsText (node)) {
+                               if (!xmlStrEqual (node->name,"comment")) {
+                                       g_warning ("bad node =  \"%s\"",node->name);
+                               }
+                       }
+               }
+       }
+
+       return template;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label-rectangle Node.                      */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_label_rectangle_node (xmlNodePtr  label_node,
+                               glTemplate *template)
+{
+       gchar               *id;
+       gdouble              waste;
+       gdouble              w, h, r;
+       glTemplateLabelType *label_type;
+       xmlNodePtr           node;
+
+       id    = xmlGetProp (label_node, "id");
+       waste = gl_xml_get_prop_length (label_node, "waste", 0);
+       w     = gl_xml_get_prop_length (label_node, "width", 0);
+       h     = gl_xml_get_prop_length (label_node, "height", 0);
+       r     = gl_xml_get_prop_length (label_node, "round", 0);
+
+       label_type = gl_template_rect_label_type_new (id, w, h, r, waste);
+       gl_template_add_label_type (template, label_type);
+
+       for (node = label_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (xmlStrEqual (node->name, "Layout")) {
+                       xml_parse_layout_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-margin")) {
+                       xml_parse_markup_margin_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-line")) {
+                       xml_parse_markup_line_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-circle")) {
+                       xml_parse_markup_circle_node (node, label_type);
+               } else if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label-round Node.                          */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_label_round_node (xmlNodePtr  label_node,
+                           glTemplate *template)
+{
+       gchar               *id;
+       gdouble              waste;
+       gdouble              r;
+       glTemplateLabelType *label_type;
+       xmlNodePtr           node;
+
+       id    = xmlGetProp (label_node, "id");
+       waste = gl_xml_get_prop_length (label_node, "waste", 0);
+       r     = gl_xml_get_prop_length (label_node, "radius", 0);
+
+       label_type = gl_template_round_label_type_new (id, r, waste);
+       gl_template_add_label_type (template, label_type);
+
+       for (node = label_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (xmlStrEqual (node->name, "Layout")) {
+                       xml_parse_layout_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-margin")) {
+                       xml_parse_markup_margin_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-line")) {
+                       xml_parse_markup_line_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-circle")) {
+                       xml_parse_markup_circle_node (node, label_type);
+               } else if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label-cd Node.                             */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_label_cd_node (xmlNodePtr  label_node,
+                        glTemplate *template)
+{
+       gchar               *id;
+       gdouble              waste;
+       gdouble              r1, r2, w, h;
+       glTemplateLabelType *label_type;
+       xmlNodePtr           node;
+
+       id    = xmlGetProp (label_node, "id");
+       waste = gl_xml_get_prop_length (label_node, "waste", 0);
+       r1    = gl_xml_get_prop_length (label_node, "radius", 0);
+       r2    = gl_xml_get_prop_length (label_node, "hole", 0);
+       w     = gl_xml_get_prop_length (label_node, "width", 0);
+       h     = gl_xml_get_prop_length (label_node, "height", 0);
+
+       label_type = gl_template_cd_label_type_new (id, r1, r2, w, h, waste);
+       gl_template_add_label_type (template, label_type);
+
+       for (node = label_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (xmlStrEqual (node->name, "Layout")) {
+                       xml_parse_layout_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-margin")) {
+                       xml_parse_markup_margin_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-line")) {
+                       xml_parse_markup_line_node (node, label_type);
+               } else if (xmlStrEqual (node->name, "Markup-circle")) {
+                       xml_parse_markup_circle_node (node, label_type);
+               } else if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label->Layout Node.                        */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_layout_node (xmlNodePtr              layout_node,
+                      glTemplateLabelType    *label_type)
+{
+       gint        nx, ny;
+       gdouble     x0, y0, dx, dy;
+       xmlNodePtr  node;
+
+       nx = gl_xml_get_prop_int (layout_node, "nx", 1);
+       ny = gl_xml_get_prop_int (layout_node, "ny", 1);
+
+       x0 = gl_xml_get_prop_length (layout_node, "x0", 0);
+       y0 = gl_xml_get_prop_length (layout_node, "y0", 0);
+
+       dx = gl_xml_get_prop_length (layout_node, "dx", 0);
+       dy = gl_xml_get_prop_length (layout_node, "dy", 0);
+
+       gl_template_add_layout (label_type,
+                               gl_template_layout_new (nx, ny, x0, y0, dx, dy));
+
+       for (node = layout_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label->Markup-margin Node.                 */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_markup_margin_node (xmlNodePtr              markup_node,
+                             glTemplateLabelType    *label_type)
+{
+       gdouble     size;
+       xmlNodePtr  node;
+
+       size = gl_xml_get_prop_length (markup_node, "size", 0);
+
+       gl_template_add_markup (label_type,
+                               gl_template_markup_margin_new (size));
+
+       for (node = markup_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label->Markup-line Node.                   */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_markup_line_node (xmlNodePtr              markup_node,
+                           glTemplateLabelType    *label_type)
+{
+       gdouble     x1, y1, x2, y2;
+       xmlNodePtr  node;
+
+       x1 = gl_xml_get_prop_length (markup_node, "x1", 0);
+       y1 = gl_xml_get_prop_length (markup_node, "y1", 0);
+       x2 = gl_xml_get_prop_length (markup_node, "x2", 0);
+       y2 = gl_xml_get_prop_length (markup_node, "y2", 0);
+
+       gl_template_add_markup (label_type,
+                               gl_template_markup_line_new (x1, y1, x2, y2));
+
+       for (node = markup_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Label->Markup-circle Node.                 */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_markup_circle_node (xmlNodePtr              markup_node,
+                             glTemplateLabelType    *label_type)
+{
+       gdouble     x0, y0, r;
+       xmlNodePtr  node;
+
+       x0 = gl_xml_get_prop_length (markup_node, "x0", 0);
+       y0 = gl_xml_get_prop_length (markup_node, "y0", 0);
+       r  = gl_xml_get_prop_length (markup_node, "radius", 0);
+
+       gl_template_add_markup (label_type,
+                               gl_template_markup_circle_new (x0, y0, r));
+
+       for (node = markup_node->xmlChildrenNode; node != NULL;
+            node = node->next) {
+               if (!xmlNodeIsText (node)) {
+                       if (!xmlStrEqual (node->name,"comment")) {
+                               g_warning ("bad node =  \"%s\"",node->name);
+                       }
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Parse XML Template->Alias Node.                                */
+/*--------------------------------------------------------------------------*/
+static void
+xml_parse_alias_node (xmlNodePtr  alias_node,
+                     glTemplate *template)
+{
+       gchar       *name;
+
+       name = xmlGetProp (alias_node, "name");
+
+       gl_template_add_alias (template, name);
+
+       g_free (name);
+}
+
+/****************************************************************************/
+/* Write a list of templates to XML file.                                   */
+/****************************************************************************/
+void
+gl_xml_template_write_templates_to_file (GList       *templates,
+                                        const gchar *utf8_filename)
+{
+       xmlDocPtr    doc;
+       xmlNsPtr     ns;
+       gint         xml_ret;
+       GList       *p;
+       glTemplate  *template;
+       gchar       *filename;
+
+       doc = xmlNewDoc ("1.0");
+       doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Glabels-templates", NULL);
+
+       ns = xmlNewNs (doc->xmlRootNode, GL_XML_NAME_SPACE, NULL);
+       xmlSetNs (doc->xmlRootNode, ns);
+
+       for (p=templates; p!=NULL; p=p->next) {
+               template = (glTemplate *)p->data;
+               gl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
+       }
+
+       filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+       if (!filename)
+               g_warning (_("Utf8 conversion error."));
+       else {
+               xmlSetDocCompressMode (doc, 0);
+               xml_ret = xmlSaveFormatFile (filename, doc, TRUE);
+               xmlFreeDoc (doc);
+               if (xml_ret == -1) {
+
+                       g_warning (_("Problem saving xml file."));
+
+               }
+               g_free (filename);
+       }
+
+}
+
+/****************************************************************************/
+/* Write single template to XML file.                                       */
+/****************************************************************************/
+void
+gl_xml_template_write_template_to_file (const glTemplate  *template,
+                                       const gchar       *utf8_filename)
+{
+       GList     *templates = NULL;
+
+       templates = g_list_append (templates, (gpointer)template);
+
+       gl_xml_template_write_templates_to_file (templates, utf8_filename);
+
+       g_list_free (templates);
+}
+
+/****************************************************************************/
+/* Add XML Template Node                                                    */
+/****************************************************************************/
+void
+gl_xml_template_create_template_node (const glTemplate *template,
+                                     xmlNodePtr        root,
+                                     const xmlNsPtr    ns)
+{
+       xmlNodePtr              node;
+       GList                  *p;
+       glTemplateLabelType    *label_type;
+
+       node = xmlNewChild (root, ns, "Template", NULL);
+
+       xmlSetProp (node, "name", template->name);
+
+       xmlSetProp (node, "size", template->page_size);
+       if (xmlStrEqual (template->page_size, "Other")) {
+
+               gl_xml_set_prop_length (node, "width", template->page_width);
+               gl_xml_set_prop_length (node, "height", template->page_height);
+
+       }
+
+       xmlSetProp (node, "description", template->description);
+
+       for ( p=template->label_types; p != NULL; p=p->next ) {
+               label_type = (glTemplateLabelType *)p->data;
+               xml_create_label_node (label_type, node, ns);
+       }
+
+       for ( p=template->aliases; p != NULL; p=p->next ) {
+               if (!xmlStrEqual (template->name, p->data)) {
+                       xml_create_alias_node ( p->data, node, ns );
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Label Node.                                  */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_label_node (const glTemplateLabelType  *label_type,
+                      xmlNodePtr                  root,
+                      const xmlNsPtr              ns)
+{
+       xmlNodePtr        node;
+       GList            *p;
+       glTemplateMarkup *markup;
+       glTemplateLayout *layout;
+
+       switch (label_type->shape) {
+
+       case GL_TEMPLATE_SHAPE_RECT:
+               node = xmlNewChild(root, ns, "Label-rectangle", NULL);
+               xmlSetProp (node, "id", label_type->id);
+               gl_xml_set_prop_length (node, "width",  label_type->size.rect.w);
+               gl_xml_set_prop_length (node, "height", label_type->size.rect.h);
+               gl_xml_set_prop_length (node, "round",  label_type->size.rect.r);
+               gl_xml_set_prop_length (node, "waste",  label_type->waste);
+               break;
+
+       case GL_TEMPLATE_SHAPE_ROUND:
+               node = xmlNewChild(root, ns, "Label-round", NULL);
+               xmlSetProp (node, "id", label_type->id);
+               gl_xml_set_prop_length (node, "radius",  label_type->size.round.r);
+               gl_xml_set_prop_length (node, "waste",   label_type->waste);
+               break;
+
+       case GL_TEMPLATE_SHAPE_CD:
+               node = xmlNewChild(root, ns, "Label-cd", NULL);
+               xmlSetProp (node, "id", label_type->id);
+               gl_xml_set_prop_length (node, "radius",  label_type->size.cd.r1);
+               gl_xml_set_prop_length (node, "hole",    label_type->size.cd.r2);
+               if (label_type->size.cd.w != 0.0) {
+                       gl_xml_set_prop_length (node, "width",  label_type->size.cd.w);
+               }
+               if (label_type->size.cd.h != 0.0) {
+                       gl_xml_set_prop_length (node, "height", label_type->size.cd.h);
+               }
+               gl_xml_set_prop_length (node, "waste",  label_type->waste);
+               break;
+
+       default:
+               g_warning ("Unknown label style");
+               return;
+               break;
+
+       }
+
+       for ( p=label_type->layouts; p != NULL; p=p->next ) {
+               layout = (glTemplateLayout *)p->data;
+               xml_create_layout_node (layout, node, ns);
+       }
+
+       for ( p=label_type->markups; p != NULL; p=p->next ) {
+               markup = (glTemplateMarkup *)p->data;
+               switch (markup->type) {
+               case GL_TEMPLATE_MARKUP_MARGIN:
+                       xml_create_markup_margin_node (markup, node, ns);
+                       break;
+               case GL_TEMPLATE_MARKUP_LINE:
+                       xml_create_markup_line_node (markup, node, ns);
+                       break;
+               case GL_TEMPLATE_MARKUP_CIRCLE:
+                       xml_create_markup_circle_node (markup, node, ns);
+                       break;
+               default:
+                       g_warning ("Unknown markup type");
+                       break;
+               }
+       }
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Label->Layout Node.                          */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_layout_node (const glTemplateLayout *layout,
+                       xmlNodePtr              root,
+                       const xmlNsPtr          ns)
+{
+       xmlNodePtr  node;
+
+       node = xmlNewChild(root, ns, "Layout", NULL);
+       gl_xml_set_prop_int (node, "nx", layout->nx);
+       gl_xml_set_prop_int (node, "ny", layout->ny);
+       gl_xml_set_prop_length (node, "x0", layout->x0);
+       gl_xml_set_prop_length (node, "y0", layout->y0);
+       gl_xml_set_prop_length (node, "dx", layout->dx);
+       gl_xml_set_prop_length (node, "dy", layout->dy);
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Label->Markup-margin Node.                   */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_markup_margin_node (const glTemplateMarkup  *markup,
+                              xmlNodePtr               root,
+                              const xmlNsPtr           ns)
+{
+       xmlNodePtr  node;
+
+       node = xmlNewChild(root, ns, "Markup-margin", NULL);
+
+       gl_xml_set_prop_length (node, "size", markup->data.margin.size);
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Label->Markup-line Node.                     */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_markup_line_node (const glTemplateMarkup *markup,
+                            xmlNodePtr              root,
+                            const xmlNsPtr          ns)
+{
+       xmlNodePtr  node;
+
+       node = xmlNewChild(root, ns, "Markup-line", NULL);
+
+       gl_xml_set_prop_length (node, "x1", markup->data.line.x1);
+       gl_xml_set_prop_length (node, "y1", markup->data.line.y1);
+       gl_xml_set_prop_length (node, "x2", markup->data.line.x2);
+       gl_xml_set_prop_length (node, "y2", markup->data.line.y2);
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Label->Markup-circle Node.                   */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_markup_circle_node (const glTemplateMarkup *markup,
+                              xmlNodePtr              root,
+                              const xmlNsPtr          ns)
+{
+       xmlNodePtr  node;
+
+       node = xmlNewChild(root, ns, "Markup-circle", NULL);
+
+       gl_xml_set_prop_length (node, "x0",     markup->data.circle.x0);
+       gl_xml_set_prop_length (node, "y0",     markup->data.circle.y0);
+       gl_xml_set_prop_length (node, "radius", markup->data.circle.r);
+
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Add XML Template->Alias Node.                                  */
+/*--------------------------------------------------------------------------*/
+static void
+xml_create_alias_node (const gchar      *name,
+                      xmlNodePtr        root,
+                      const xmlNsPtr    ns)
+{
+       xmlNodePtr node;
+
+       node = xmlNewChild (root, ns, "Alias", NULL);
+       xmlSetProp (node, "name", name);
+
+}
+
diff --git a/glabels2/libglabels/xml-template.h b/glabels2/libglabels/xml-template.h
new file mode 100644 (file)
index 0000000..1d1632f
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml-template.h:  template xml module header file
+ *
+ *  Copyright (C) 2001-2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __XML_TEMPLATE_H__
+#define __XML_TEMPLATE_H__
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+#include "template.h"
+
+G_BEGIN_DECLS
+
+GList       *gl_xml_template_read_templates_from_file (const gchar       *utf8_filename);
+
+GList       *gl_xml_template_parse_templates_doc      (const xmlDocPtr    templates_doc);
+
+glTemplate  *gl_xml_template_parse_template_node      (const xmlNodePtr   template_node);
+
+
+void         gl_xml_template_write_templates_to_file  (GList             *templates,
+                                                      const gchar       *utf8_filename);
+
+void         gl_xml_template_write_template_to_file   (const glTemplate  *template,
+                                                      const gchar       *utf8_filename);
+
+xmlDocPtr    gl_xml_template_create_templates_doc     (GList             *templates);
+
+void         gl_xml_template_create_template_node     (const glTemplate  *template,
+                                                      xmlNodePtr         root,
+                                                      const xmlNsPtr     ns);
+
+G_END_DECLS
+
+#endif /* __XML_TEMPLATE_H__ */
diff --git a/glabels2/libglabels/xml.c b/glabels2/libglabels/xml.c
new file mode 100644 (file)
index 0000000..ea48335
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml.c:  GLabels xml utilities module
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#include "libglabels-private.h"
+
+#include "xml.h"
+
+/*========================================================*/
+/* Private macros and constants.                          */
+/*========================================================*/
+
+#define POINTS_PER_POINT    1.0 /* internal units are points. */
+#define POINTS_PER_INCH    72.0
+#define POINTS_PER_MM       2.83464566929
+#define POINTS_PER_CM       (10.0*POINTS_PER_MM)
+#define POINTS_PER_PICA     (1.0/12.0)
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+typedef struct {
+       gchar  *name;
+       gdouble points_per_unit;
+} UnitTableEntry;
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static UnitTableEntry unit_table[] = {
+
+       /* These names are identical to the absolute length units supported in
+          the CSS2 Specification (Section 4.3.2) */
+
+       {"pt",           POINTS_PER_POINT},
+       {"in",           POINTS_PER_INCH},
+       {"mm",           POINTS_PER_MM},
+       {"cm",           POINTS_PER_CM},
+       {"pc",           POINTS_PER_PICA},
+
+       {NULL, 0}
+};
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+\f
+/****************************************************************************/
+/* Return value of property as a double.                                    */
+/****************************************************************************/
+gdouble
+gl_xml_get_prop_double (xmlNodePtr   node,
+                       const gchar *property,
+                       gdouble      default_val)
+{
+       gdouble  val;
+       gchar   *string;
+
+       string = xmlGetProp (node, property);
+       if ( string != NULL ) {
+               val = g_strtod (string, NULL);
+               g_free (string);
+               return val;
+       }
+
+       return default_val;
+}
+
+/****************************************************************************/
+/* Return value of property as a boolean.                                   */
+/****************************************************************************/
+gboolean
+gl_xml_get_prop_boolean (xmlNodePtr   node,
+                        const gchar *property,
+                        gboolean     default_val)
+{
+       gboolean  val;
+       gchar    *string;
+
+       string = xmlGetProp (node, property);
+       if ( string != NULL ) {
+               val = !((xmlStrcasecmp (string, "false") == 0) ||
+                       xmlStrEqual (string, "0"));;
+               g_free (string);
+               return val;
+       }
+
+       return default_val;
+}
+
+
+/****************************************************************************/
+/* Return value of property as an int. .                                    */
+/****************************************************************************/
+gint
+gl_xml_get_prop_int (xmlNodePtr   node,
+                    const gchar *property,
+                    gint         default_val)
+{
+       gint     val;
+       gchar   *string;
+
+       string = xmlGetProp (node, property);
+       if ( string != NULL ) {
+               val = strtol (string, NULL, 0);
+               g_free (string);
+               return val;
+       }
+
+       return default_val;
+}
+
+
+/****************************************************************************/
+/* Return value of hex property as an unsigned int.                         */
+/****************************************************************************/
+guint
+gl_xml_get_prop_uint (xmlNodePtr   node,
+                     const gchar *property,
+                     guint        default_val)
+{
+       guint    val;
+       gchar   *string;
+
+       string = xmlGetProp (node, property);
+       if ( string != NULL ) {
+               val = strtoul (string, NULL, 0);
+               g_free (string);
+               return val;
+       }
+
+       return default_val;
+}
+
+
+/****************************************************************************/
+/* Return value of length property as a double, converting to internal units*/
+/****************************************************************************/
+gdouble
+gl_xml_get_prop_length (xmlNodePtr   node,
+                       const gchar *property,
+                       gdouble      default_val)
+{
+       gdouble  val;
+       gchar   *string, *unit;
+       gint     i;
+
+       string = xmlGetProp (node, property);
+       if ( string != NULL ) {
+
+               val = g_strtod (string, &unit);
+
+               if (unit != string) {
+                       unit = g_strchug (unit);
+                       if (strlen (unit) > 0 ) {
+                               for (i=0; unit_table[i].name != NULL; i++) {
+                                       if (xmlStrcasecmp (unit, unit_table[i].name) == 0) {
+                                               val *= unit_table[i].points_per_unit;
+                                               break;
+                                       }
+                               }
+                               if (unit_table[i].name == NULL) {
+                                       g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
+                                                  xmlGetLineNo (node), node->name, property,
+                                                  unit);
+                               }
+                       }
+               }
+               else {
+                       val = 0.0;
+               }
+
+               g_free (string);
+               return val;
+       }
+
+       return default_val;
+}
+
+/****************************************************************************/
+/* Set property from double.                                                */
+/****************************************************************************/
+void
+gl_xml_set_prop_double (xmlNodePtr    node,
+                       const gchar  *property,
+                       gdouble       val)
+{
+       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+
+       /* Guarantee "C" locale by use of g_ascii_formatd */
+       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
+
+       xmlSetProp (node, property, string);
+}
+
+/****************************************************************************/
+/* Set property from boolean.                                               */
+/****************************************************************************/
+void
+gl_xml_set_prop_boolean (xmlNodePtr    node,
+                        const gchar  *property,
+                        gboolean      val)
+{
+       xmlSetProp (node, property, (val ? "True" : "False"));
+}
+
+/****************************************************************************/
+/* Set property from int.                                                   */
+/****************************************************************************/
+void
+gl_xml_set_prop_int (xmlNodePtr    node,
+                    const gchar  *property,
+                    gint          val)
+{
+       gchar  *string;
+
+       string = g_strdup_printf ("%d", val);
+       xmlSetProp (node, property, string);
+       g_free (string);
+}
+
+/****************************************************************************/
+/* Set property from uint in hex.                                           */
+/****************************************************************************/
+void
+gl_xml_set_prop_uint_hex (xmlNodePtr    node,
+                         const gchar  *property,
+                         guint         val)
+{
+       gchar  *string;
+
+       string = g_strdup_printf ("0x%08x", val);
+       xmlSetProp (node, property, string);
+       g_free (string);
+}
+
+/****************************************************************************/
+/* Set property from length.                                                */
+/****************************************************************************/
+void
+gl_xml_set_prop_length (xmlNodePtr    node,
+                       const gchar  *property,
+                       gdouble       val)
+{
+       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+       gchar  *string_unit;
+
+       /* Guarantee "C" locale by use of g_ascii_formatd */
+       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
+
+       string_unit = g_strdup_printf ("%spt", string);
+       xmlSetProp (node, property, string_unit);
+        g_free (string_unit);
+}
+
diff --git a/glabels2/libglabels/xml.h b/glabels2/libglabels/xml.h
new file mode 100644 (file)
index 0000000..11c3a48
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  xml.h:  GLabels xml utilities header file
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of the LIBGLABELS library.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ *  MA 02111-1307, USA
+ */
+
+#ifndef __XML_H__
+#define __XML_H__
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+#define GL_XML_NAME_SPACE "http://snaught.com/glabels/2.0/"
+
+G_BEGIN_DECLS
+
+gdouble  gl_xml_get_prop_double   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       default_val);
+
+gboolean gl_xml_get_prop_boolean  (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gboolean      default_val);
+
+gint     gl_xml_get_prop_int      (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gint          default_val);
+
+guint    gl_xml_get_prop_uint     (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  guint         default_val);
+
+gdouble  gl_xml_get_prop_length   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       default_val);
+
+
+void     gl_xml_set_prop_double   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       val);
+
+void     gl_xml_set_prop_boolean  (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gboolean      val);
+
+void     gl_xml_set_prop_int      (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gint          val);
+
+void     gl_xml_set_prop_uint_hex (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  guint         val);
+
+void     gl_xml_set_prop_length   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       val);
+
+G_END_DECLS
+
+
+#endif /* __XML_H__ */
index fdfda28e09565c574aaf3e9a01330b0b694e6b57..a07b81d116a81a52cb3b31f22b21b4db7effd976 100644 (file)
@@ -97,22 +97,22 @@ src/label-image.c
 src/label-image.h
 src/label-barcode.c
 src/label-barcode.h
-src/template.c
-src/template.h
-src/paper.c
-src/paper.h
 src/xml-label.c
 src/xml-label.h
 src/xml-label-04.c
 src/xml-label-04.h
 src/xml-label-191.c
 src/xml-label-191.h
-src/xml-template.c
-src/xml-template.h
-src/xml-paper.c
-src/xml-paper.h
-src/xml.c
-src/xml.h
+libglabels/template.c
+libglabels/template.h
+libglabels/paper.c
+libglabels/paper.h
+libglabels/xml-template.c
+libglabels/xml-template.h
+libglabels/xml-paper.c
+libglabels/xml-paper.h
+libglabels/xml.c
+libglabels/xml.h
 src/pixbuf-cache.c
 src/pixbuf-cache.h
 src/base64.c
index fe27a4f02f70a51526defa6e7ac4d4da185ddbd7..d97c7d306e7650033d5098affa70f3246b4273ed 100644 (file)
@@ -25,6 +25,7 @@ glabels_LDFLAGS = -export-dynamic
 
 glabels_LDADD =                        \
        $(GLABELS_LIBS)                 \
+       ../libglabels/libglabels.la     \
        mygal/libmygal.la               \
        recent-files/librecent.la       \
        $(LIB_BARCODE_DIR)/libbarcode.la
@@ -33,6 +34,7 @@ glabels_batch_LDFLAGS = -export-dynamic
 
 glabels_batch_LDADD =                  \
        $(GLABELS_LIBS)                 \
+       ../libglabels/libglabels.la     \
        $(LIB_BARCODE_DIR)/libbarcode.la
 
 BUILT_SOURCES =                        \
@@ -132,22 +134,12 @@ glabels_SOURCES =                         \
        label-image.h                   \
        label-barcode.c                 \
        label-barcode.h                 \
-       template.c                      \
-       template.h                      \
-       paper.c                         \
-       paper.h                         \
        xml-label.c                     \
        xml-label.h                     \
        xml-label-04.c                  \
        xml-label-04.h                  \
        xml-label-191.c                 \
        xml-label-191.h                 \
-       xml-template.c                  \
-       xml-template.h                  \
-       xml-paper.c                     \
-       xml-paper.h                     \
-       xml.c                           \
-       xml.h                           \
        pixbuf-cache.c                  \
        pixbuf-cache.h                  \
        base64.c                        \
@@ -208,22 +200,12 @@ glabels_batch_SOURCES =           \
        label-image.h                   \
        label-barcode.c                 \
        label-barcode.h                 \
-       template.c                      \
-       template.h                      \
-       paper.c                         \
-       paper.h                         \
        xml-label.c                     \
        xml-label.h                     \
        xml-label-04.c                  \
        xml-label-04.h                  \
        xml-label-191.c                 \
        xml-label-191.h                 \
-       xml-template.c                  \
-       xml-template.h                  \
-       xml-paper.c                     \
-       xml-paper.h                     \
-       xml.c                           \
-       xml.h                           \
        pixbuf-cache.c                  \
        pixbuf-cache.h                  \
        base64.c                        \
@@ -273,3 +255,6 @@ $(bin_PROGRAMS): $(LIB_BARCODE_DIR)/libbarcode.la
 $(LIB_BARCODE_DIR)/libbarcode.la:
        cd $(LIB_BARCODE_DIR); $(MAKE)
 
+../libglabels/libglabels.la:
+       cd ../libglabels; $(MAKE)
+
index ff71acf0b741c64d6a9f0be056f63f260f365d90..c93ee4fde1aef3faff0ca486b97bb347a0f8ad55 100644 (file)
@@ -27,9 +27,9 @@
 
 #include "merge-init.h"
 #include "xml-label.h"
-#include "paper.h"
-#include "template.h"
 #include "print.h"
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
 #include "util.h"
 
 /*============================================*/
index 5472a016f6ac725b7ba64c856c2dfe2ad754e213..d3603e1cdac720331e0ed2234c19af4e0d9237e3 100644 (file)
@@ -29,8 +29,8 @@
 #include "splash.h"
 #include "stock.h"
 #include "merge-init.h"
-#include "paper.h"
-#include "template.h"
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
 #include "prefs.h"
 #include "debug.h"
 #include "window.h"
index 1f75df3e4537e4a2cef91b1c31c9bbec661813a4..84a3620f9251090fa09aef7fbb3a7d8953e5e2a6 100644 (file)
@@ -201,7 +201,7 @@ gl_label_finalize (GObject *object)
 
        label = GL_LABEL (object);
 
-       gl_template_free (&label->private->template);
+       gl_template_free (label->private->template);
 
        for (p = label->objects; p != NULL; p = p_next) {
                p_next = p->next;       /* NOTE: p will be left dangling */
@@ -395,7 +395,7 @@ gl_label_set_template (glLabel    *label,
        if ((label->private->template == NULL) ||
            (g_strcasecmp (template->name, label->private->template->name) != 0)) {
 
-               gl_template_free (&label->private->template);
+               gl_template_free (label->private->template);
                label->private->template = gl_template_dup (template);
 
                label->private->modified_flag = TRUE;
@@ -473,7 +473,8 @@ gl_label_get_size (glLabel *label,
                   gdouble *w,
                   gdouble *h)
 {
-       glTemplate *template;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
 
        gl_debug (DEBUG_LABEL, "START");
 
@@ -485,11 +486,12 @@ gl_label_get_size (glLabel *label,
                *w = *h = 0;
                return;
        }
+       label_type = gl_template_get_first_label_type (template);
 
        if (!label->private->rotate_flag) {
-               gl_template_get_label_size (template, w, h);
+               gl_template_get_label_size (label_type, w, h);
        } else {
-               gl_template_get_label_size (template, h, w);
+               gl_template_get_label_size (label_type, h, w);
        }
 
        gl_debug (DEBUG_LABEL, "END");
index b225fee5171c3c308238cd30bd226ec266682bc4..f901180b97f425c6ffec65de87abe408912d2d79 100644 (file)
@@ -24,8 +24,8 @@
 
 #include <glib-object.h>
 
+#include <libglabels/template.h>
 #include "merge.h"
-#include "template.h"
 #include "pixbuf-cache.h"
 
 G_BEGIN_DECLS
diff --git a/glabels2/src/paper.c b/glabels2/src/paper.c
deleted file mode 100644 (file)
index 652eb6c..0000000
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  paper.c:  paper module
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#include <config.h>
-
-#include <string.h>
-#include <libgnome/libgnome.h>
-
-#include "paper.h"
-#include "xml-paper.h"
-#include "util.h"
-
-#include "debug.h"
-
-#define GL_DATA_DIR gnome_program_locate_file (NULL,\
-                                        GNOME_FILE_DOMAIN_APP_DATADIR,\
-                                        "glabels",\
-                                        FALSE, NULL)
-
-
-/*===========================================*/
-/* Private types                             */
-/*===========================================*/
-
-/*===========================================*/
-/* Private globals                           */
-/*===========================================*/
-
-static GList *papers = NULL;
-
-/*===========================================*/
-/* Local function prototypes                 */
-/*===========================================*/
-
-static GList *read_papers (void);
-static GList *read_paper_files_from_dir (GList       *papers,
-                                        const gchar *dirname);
-
-\f
-/*****************************************************************************/
-/* Initialize module.                                                        */
-/*****************************************************************************/
-void
-gl_paper_init (void)
-{
-       glPaper *other;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       papers = read_papers ();
-
-       /* Create and append an "Other" entry. */
-       other = g_new0 (glPaper,1);
-       other->id   = g_strdup ("Other");
-       other->name = g_strdup (_("Other"));
-       papers = g_list_append (papers, other);
-
-       gl_debug (DEBUG_PAPER, "END");
-}
-
-/*****************************************************************************/
-/* Get a list of valid page size ids                                         */
-/*****************************************************************************/
-GList *
-gl_paper_get_id_list (void)
-{
-       GList           *ids = NULL;
-       GList           *p;
-       glPaper         *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       for ( p=papers; p != NULL; p=p->next ) {
-               paper = (glPaper *)p->data;
-               ids = g_list_append (ids, g_strdup (paper->id));
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return ids;
-}
-
-/*****************************************************************************/
-/* Free a list of page size ids.                                             */
-/*****************************************************************************/
-void
-gl_paper_free_id_list (GList **ids)
-{
-       GList *p;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       for (p = *ids; p != NULL; p = p->next) {
-               g_free (p->data);
-               p->data = NULL;
-       }
-
-       g_list_free (*ids);
-       *ids = NULL;
-
-       gl_debug (DEBUG_PAPER, "END");
-}
-
-/*****************************************************************************/
-/* Get a list of valid page size names                                       */
-/*****************************************************************************/
-GList *
-gl_paper_get_name_list (void)
-{
-       GList           *names = NULL;
-       GList           *p;
-       glPaper         *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       for ( p=papers; p != NULL; p=p->next ) {
-               paper = (glPaper *)p->data;
-               names = g_list_append (names, g_strdup (paper->name));
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return names;
-}
-
-/*****************************************************************************/
-/* Free a list of page size names.                                           */
-/*****************************************************************************/
-void
-gl_paper_free_name_list (GList **names)
-{
-       GList *p;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       for (p = *names; p != NULL; p = p->next) {
-               g_free (p->data);
-               p->data = NULL;
-       }
-
-       g_list_free (*names);
-       *names = NULL;
-
-       gl_debug (DEBUG_PAPER, "END");
-}
-
-/*****************************************************************************/
-/* Is page size id known?                                                    */
-/*****************************************************************************/
-gboolean
-gl_paper_is_id_known (const gchar *id)
-{
-       GList       *p;
-       glPaper     *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       if (id == NULL) {
-               gl_debug (DEBUG_PAPER, "END (false, id=NULL)");
-               return FALSE;
-       }
-
-       for (p = papers; p != NULL; p = p->next) {
-               paper = (glPaper *) p->data;
-               if (g_strcasecmp (paper->id, id) == 0) {
-                       gl_debug (DEBUG_PAPER, "END (true)");
-                       return TRUE;
-               }
-       }
-
-       gl_debug (DEBUG_PAPER, "END (false)");
-       return FALSE;
-}
-
-/*****************************************************************************/
-/* Return a paper structure from id.                                         */
-/*****************************************************************************/
-glPaper *
-gl_paper_from_id (const gchar *id)
-{
-       GList       *p;
-       glPaper     *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       if (id == NULL) {
-               /* If no id, return first paper as a default */
-               return gl_paper_dup ((glPaper *) papers->data);
-       }
-
-       for (p = papers; p != NULL; p = p->next) {
-               paper = (glPaper *) p->data;
-               if (g_strcasecmp (paper->id, id) == 0) {
-                       gl_debug (DEBUG_PAPER, "END");
-                       return gl_paper_dup (paper);
-               }
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return NULL;
-}
-
-/*****************************************************************************/
-/* Return a paper structure from name.                                       */
-/*****************************************************************************/
-glPaper *
-gl_paper_from_name (const gchar *name)
-{
-       GList       *p;
-       glPaper     *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       if (name == NULL) {
-               /* If no name, return first paper as a default */
-               return gl_paper_dup ((glPaper *) papers->data);
-       }
-
-       for (p = papers; p != NULL; p = p->next) {
-               paper = (glPaper *) p->data;
-               if (g_strcasecmp (paper->name, name) == 0) {
-                       gl_debug (DEBUG_PAPER, "END");
-                       return gl_paper_dup (paper);
-               }
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return NULL;
-}
-
-/*****************************************************************************/
-/* Lookup paper id from name.                                                */
-/*****************************************************************************/
-gchar *
-gl_paper_lookup_id_from_name (const gchar       *name)
-{
-       glPaper *paper;
-       gchar   *id = NULL;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       paper = gl_paper_from_name (name);
-       if ( paper != NULL ) {
-               id = g_strdup (paper->id);
-               gl_paper_free (&paper);
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return id;
-}
-
-/*****************************************************************************/
-/* Lookup paper name from id.                                                */
-/*****************************************************************************/
-gchar *
-gl_paper_lookup_name_from_id (const gchar       *id)
-{
-       glPaper *paper;
-       gchar   *name = NULL;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       paper = gl_paper_from_id (id);
-       if ( paper != NULL ) {
-               name = g_strdup (paper->name);
-               gl_paper_free (&paper);
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return name;
-}
-
-/*****************************************************************************/
-/* Copy a paper.                                                          */
-/*****************************************************************************/
-glPaper *gl_paper_dup (const glPaper *orig_paper)
-{
-       glPaper       *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       paper = g_new0 (glPaper,1);
-
-       paper->id     = g_strdup (orig_paper->id);
-       paper->name   = g_strdup (orig_paper->name);
-       paper->width  = orig_paper->width;
-       paper->height = orig_paper->height;
-
-       gl_debug (DEBUG_PAPER, "END");
-       return paper;
-}
-
-/*****************************************************************************/
-/* Free up a paper.                                                       */
-/*****************************************************************************/
-void gl_paper_free (glPaper **paper)
-{
-       GList *p;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       if ( *paper != NULL ) {
-
-               g_free ((*paper)->id);
-               (*paper)->name = NULL;
-
-               g_free ((*paper)->name);
-               (*paper)->name = NULL;
-
-               g_free (*paper);
-               *paper = NULL;
-
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Read papers from various  files.                            */
-/*--------------------------------------------------------------------------*/
-static GList *
-read_papers (void)
-{
-       gchar *home_data_dir = gl_util_get_home_data_dir ();
-       GList *papers = NULL;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       papers = read_paper_files_from_dir (papers, GL_DATA_DIR);
-       papers = read_paper_files_from_dir (papers, home_data_dir);
-
-       g_free (home_data_dir);
-
-       if (papers == NULL) {
-               g_warning (_("No paper files found!"));
-       }
-
-       gl_debug (DEBUG_PAPER, "END");
-       return papers;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Read all paper files from given directory.  Append to list. */
-/*--------------------------------------------------------------------------*/
-static GList *
-read_paper_files_from_dir (GList       *papers,
-                          const gchar *dirname)
-{
-       GDir        *dp;
-       const gchar *filename, *extension;
-       gchar       *full_filename = NULL;
-       GError      *gerror = NULL;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       if (dirname == NULL)
-               return papers;
-
-       dp = g_dir_open (dirname, 0, &gerror);
-       if (gerror != NULL) {
-               g_warning ("cannot open data directory: %s", gerror->message );
-               gl_debug (DEBUG_PAPER, "END");
-               return papers;
-       }
-
-       while ((filename = g_dir_read_name (dp)) != NULL) {
-
-               extension = strrchr (filename, '.');
-
-               if (extension != NULL) {
-
-                       if ( (g_strcasecmp (extension, ".paper") == 0)
-                            || (g_strcasecmp (filename, "paper-sizes.xml") == 0) ) {
-
-                               full_filename =
-                                   g_build_filename (dirname, filename, NULL);
-                               papers =
-                                   gl_xml_paper_read_papers_from_file (papers,
-                                                                       full_filename);
-                               g_free (full_filename);
-
-                       }
-
-               }
-
-       }
-
-       g_dir_close (dp);
-
-       gl_debug (DEBUG_PAPER, "END");
-       return papers;
-}
-
diff --git a/glabels2/src/paper.h b/glabels2/src/paper.h
deleted file mode 100644 (file)
index ce418d5..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  paper.h:  paper module header file
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#ifndef __PAPER_H__
-#define __PAPER_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/*
- *   Paper
- */
-typedef struct {
-       gchar               *id;
-       gchar               *name;
-       gdouble              width;
-       gdouble              height;
-} glPaper;
-
-
-void                 gl_paper_init                (void);
-
-GList               *gl_paper_get_id_list         (void);
-void                 gl_paper_free_id_list        (GList            **ids);
-
-GList               *gl_paper_get_name_list       (void);
-void                 gl_paper_free_name_list      (GList            **names);
-
-gboolean             gl_paper_is_id_known         (const gchar       *id);
-
-glPaper             *gl_paper_from_id             (const gchar       *id);
-glPaper             *gl_paper_from_name           (const gchar       *name);
-
-gchar               *gl_paper_lookup_id_from_name (const gchar       *name);
-gchar               *gl_paper_lookup_name_from_id (const gchar       *id);
-
-glPaper             *gl_paper_dup                 (const glPaper     *orig);
-void                 gl_paper_free                (glPaper          **paper);
-
-G_END_DECLS
-
-#endif
index 0ec867ae278c65c4b60444bd982544ab46ae7410..5abf224d4ddc8b4d7e954aef7fb102456964fbb8 100644 (file)
@@ -25,7 +25,7 @@
 #include "marshal.h"
 #include "prefs-model.h"
 #include "util.h"
-#include "paper.h"
+#include <libglabels/paper.h>
 #include "color.h"
 
 #include "debug.h"
@@ -544,7 +544,8 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model)
        if ( paper == NULL ) {
                prefs_model->default_page_size = g_strdup (DEFAULT_PAGE_SIZE);
        } else {
-               gl_paper_free (&paper);
+               gl_paper_free (paper);
+               paper = NULL;
        }
 
        gl_debug (DEBUG_PREFS, "max_recents = %d", prefs_model->max_recents);
index 11e46d18d6e254fbab83cdaa074e7b5ead61e06e..b25fe51a62f87ca0025d935fd90ab84be377f961 100644 (file)
@@ -32,7 +32,6 @@
 #include "print-dialog.h"
 #include "print.h"
 #include "label.h"
-#include "template.h"
 
 #include "wdgt-print-copies.h"
 #include "wdgt-print-merge.h"
index 6a4a73b6c1316bc29308c6043d2c9019a1fb519d..a45ce8eff6f4adccc58b4eb812196f12f1d778fc 100644 (file)
@@ -35,7 +35,7 @@
 #include "label-image.h"
 #include "label-barcode.h"
 #include "bc.h"
-#include "template.h"
+#include <libglabels/template.h>
 #include "color.h"
 
 #include "debug.h"
@@ -177,15 +177,17 @@ gl_print_simple (GnomePrintJob    *job,
                 gint              last,
                 glPrintFlags     *flags)
 {
-       PrintInfo *pi;
-       gint i_sheet, i_label;
-       glTemplateOrigin *origins;
+       PrintInfo                 *pi;
+       const glTemplateLabelType *label_type;
+       gint                       i_sheet, i_label;
+       glTemplateOrigin          *origins;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       pi = print_info_new (job, label);
+       pi         = print_info_new (job, label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
-       origins = gl_template_get_origins (pi->template);
+       origins = gl_template_get_origins (label_type);
 
        for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) {
 
@@ -222,13 +224,14 @@ gl_print_merge_collated (GnomePrintJob    *job,
                         gint              first,
                         glPrintFlags     *flags)
 {
-       glMerge                *merge;
-       const GList            *record_list;
-       PrintInfo              *pi;
-       gint                    i_sheet, i_label, n_labels_per_page, i_copy;
-       glMergeRecord          *record;
-       GList                  *p;
-       glTemplateOrigin       *origins;
+       glMerge                   *merge;
+       const GList               *record_list;
+       PrintInfo                 *pi;
+       const glTemplateLabelType *label_type;
+       gint                       i_sheet, i_label, n_labels_per_page, i_copy;
+       glMergeRecord             *record;
+       GList                     *p;
+       glTemplateOrigin          *origins;
 
        gl_debug (DEBUG_PRINT, "START");
 
@@ -236,9 +239,10 @@ gl_print_merge_collated (GnomePrintJob    *job,
        record_list = gl_merge_get_record_list (merge);
 
        pi = print_info_new (job, label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
-       n_labels_per_page = gl_template_get_n_labels (pi->template);
-       origins = gl_template_get_origins (pi->template);
+       n_labels_per_page = gl_template_get_n_labels (label_type);
+       origins = gl_template_get_origins (label_type);
 
        i_sheet = 0;
        i_label = first - 1;
@@ -292,13 +296,14 @@ gl_print_merge_uncollated (GnomePrintJob    *job,
                           gint              first,
                           glPrintFlags     *flags)
 {
-       glMerge                *merge;
-       const GList            *record_list;
-       PrintInfo              *pi;
-       gint                    i_sheet, i_label, n_labels_per_page, i_copy;
-       glMergeRecord          *record;
-       GList                  *p;
-       glTemplateOrigin       *origins;
+       glMerge                   *merge;
+       const GList               *record_list;
+       PrintInfo                 *pi;
+       const glTemplateLabelType *label_type;
+       gint                       i_sheet, i_label, n_labels_per_page, i_copy;
+       glMergeRecord             *record;
+       GList                     *p;
+       glTemplateOrigin          *origins;
 
        gl_debug (DEBUG_PRINT, "START");
 
@@ -306,9 +311,10 @@ gl_print_merge_uncollated (GnomePrintJob    *job,
        record_list = gl_merge_get_record_list (merge);
 
        pi = print_info_new (job, label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
-       n_labels_per_page = gl_template_get_n_labels (pi->template);
-       origins = gl_template_get_origins (pi->template);
+       n_labels_per_page = gl_template_get_n_labels (label_type);
+       origins = gl_template_get_origins (label_type);
 
        i_sheet = 0;
        i_label = first - 1;
@@ -364,23 +370,25 @@ gl_print_batch (GnomePrintJob    *job,
                gint              n_copies,
                glPrintFlags     *flags)
 {
-       gint n_per_page;
-       glMerge *merge;
-       glTemplate *template;
+       glMerge                   *merge;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gint                       n_per_page;
        
        gl_debug (DEBUG_PRINT, "START");
 
        merge = gl_label_get_merge (label);
        template = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
        if ( merge == NULL ) {
-               n_per_page = gl_template_get_n_labels(template);
+               n_per_page = gl_template_get_n_labels(label_type);
 
                gl_print_simple (job, label, n_sheets, 1, n_per_page, flags);
        } else {
                gl_print_merge_collated (job, label, n_copies, 1, flags);
        }
-       gl_template_free (&template);
+       gl_template_free (template);
 
        gl_debug (DEBUG_PRINT, "END");
 }
@@ -443,7 +451,8 @@ print_info_free (PrintInfo **pi)
 {
        gl_debug (DEBUG_PRINT, "START");
 
-       gl_template_free (&(*pi)->template);
+       gl_template_free ((*pi)->template);
+       (*pi)->template = NULL;
 
        gnome_print_context_close ((*pi)->pc);
 
@@ -495,16 +504,19 @@ print_page_end (PrintInfo *pi)
 static void
 print_crop_marks (PrintInfo *pi)
 {
-       gdouble           w, h, page_w, page_h;
-       GList            *p;
-       glTemplateLayout *layout;
-       gdouble           xmin, ymin, xmax, ymax, dx, dy;
-       gdouble           x1, y1, x2, y2, x3, y3, x4, y4;
-       gint              ix, iy, nx, ny;
+       const glTemplateLabelType *label_type;
+       gdouble                    w, h, page_w, page_h;
+       GList                     *p;
+       glTemplateLayout          *layout;
+       gdouble                    xmin, ymin, xmax, ymax, dx, dy;
+       gdouble                    x1, y1, x2, y2, x3, y3, x4, y4;
+       gint                       ix, iy, nx, ny;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       gl_template_get_label_size (pi->template, &w, &h);
+       label_type = gl_template_get_first_label_type (pi->template);
+
+       gl_template_get_label_size (label_type, &w, &h);
 
        page_w = pi->page_width;
        page_h = pi->page_height;
@@ -513,7 +525,7 @@ print_crop_marks (PrintInfo *pi)
        gnome_print_setopacity (pi->pc, 1.0);
        gnome_print_setlinewidth (pi->pc, 0.25);
 
-       for (p=pi->template->label.any.layouts; p != NULL; p=p->next) {
+       for (p=label_type->layouts; p != NULL; p=p->next) {
 
                layout = (glTemplateLayout *)p->data;
 
@@ -603,12 +615,12 @@ print_label (PrintInfo     *pi,
             gboolean       outline_flag,
             gboolean       reverse_flag)
 {
-       gdouble width, height;
-       glTemplate *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    width, height;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       template = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
        gl_label_get_size (label, &width, &height);
 
@@ -636,8 +648,6 @@ print_label (PrintInfo     *pi,
 
        gnome_print_grestore (pi->pc);
 
-       gl_template_free (&template);
-
        gl_debug (DEBUG_PRINT, "END");
 }
 
@@ -1093,23 +1103,23 @@ static void
 draw_outline (PrintInfo *pi,
              glLabel   *label)
 {
-       gdouble w, h, r;
-       gdouble r1, r2;
-       glTemplate *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    w, h, r;
+       gdouble                    r1, r2;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       template = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
        gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
        gnome_print_setopacity (pi->pc, 1.0);
        gnome_print_setlinewidth (pi->pc, 0.25);
 
-       switch (template->label.style) {
+       switch (label_type->shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
+       case GL_TEMPLATE_SHAPE_RECT:
                gl_label_get_size (label, &w, &h);
-               r = template->label.rect.r;
+               r = label_type->size.rect.r;
                if (r == 0.0) {
                        /* simple rectangle */
                        create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
@@ -1121,18 +1131,18 @@ draw_outline (PrintInfo *pi,
                gnome_print_stroke (pi->pc);
                break;
 
-       case GL_TEMPLATE_STYLE_ROUND:
+       case GL_TEMPLATE_SHAPE_ROUND:
                /* Round style */
-               r1 = template->label.round.r;
+               r1 = label_type->size.round.r;
                create_ellipse_path (pi->pc, r1, r1, r1, r1);
                gnome_print_stroke (pi->pc);
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
-               if ((template->label.cd.h == 0) && (template->label.cd.w == 0)) {
+       case GL_TEMPLATE_SHAPE_CD:
+               if ((label_type->size.cd.h == 0) && (label_type->size.cd.w == 0)) {
                        /* CD style, round label w/ concentric round hole */
-                       r1 = template->label.cd.r1;
-                       r2 = template->label.cd.r2;
+                       r1 = label_type->size.cd.r1;
+                       r2 = label_type->size.cd.r2;
                        create_ellipse_path (pi->pc, r1, r1, r1, r1);
                        gnome_print_stroke (pi->pc);
                        create_ellipse_path (pi->pc, r1, r1, r2, r2);
@@ -1140,8 +1150,8 @@ draw_outline (PrintInfo *pi,
                } else {
                        /* Business Card CD style, clipped round label w/ hole */
                        gl_label_get_size (label, &w, &h);
-                       r1 = template->label.cd.r1;
-                       r2 = template->label.cd.r2;
+                       r1 = label_type->size.cd.r1;
+                       r2 = label_type->size.cd.r2;
                        create_clipped_circle_path (pi->pc, w/2, h/2, w, h, r1);
                        gnome_print_stroke (pi->pc);
                        create_ellipse_path (pi->pc, w/2, h/2, r2, r2);
@@ -1154,8 +1164,6 @@ draw_outline (PrintInfo *pi,
                break;
        }
 
-       gl_template_free (&template);
-
        gl_debug (DEBUG_PRINT, "END");
 }
 
@@ -1166,21 +1174,21 @@ static void
 clip_to_outline (PrintInfo *pi,
                 glLabel   *label)
 {
-       gdouble w, h, r;
-       gdouble r1;
-       gdouble waste;
-       glTemplate *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    w, h, r;
+       gdouble                    r1;
+       gdouble                    waste;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       template = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
-       switch (template->label.style) {
+       switch (label_type->shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
+       case GL_TEMPLATE_SHAPE_RECT:
                gl_label_get_size (label, &w, &h);
-               r = template->label.rect.r;
-               waste = template->label.rect.waste;
+               r = label_type->size.rect.r;
+               waste = label_type->waste;
                if (r == 0.0) {
                        /* simple rectangle */
                        create_rectangle_path (pi->pc,
@@ -1193,23 +1201,23 @@ clip_to_outline (PrintInfo *pi,
                gnome_print_clip (pi->pc);
                break;
 
-       case GL_TEMPLATE_STYLE_ROUND:
-               r1 = template->label.round.r;
-               waste = template->label.round.waste;
+       case GL_TEMPLATE_SHAPE_ROUND:
+               r1 = label_type->size.round.r;
+               waste = label_type->waste;
                create_ellipse_path (pi->pc, r1, r1, r1+waste, r1+waste);
                gnome_print_clip (pi->pc);
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
-               waste = template->label.cd.waste;
-               if ((template->label.cd.h == 0) && (template->label.cd.w == 0)) {
+       case GL_TEMPLATE_SHAPE_CD:
+               waste = label_type->waste;
+               if ((label_type->size.cd.h == 0) && (label_type->size.cd.w == 0)) {
                        /* CD style, round label w/ concentric round hole */
-                       r1 = template->label.cd.r1;
+                       r1 = label_type->size.cd.r1;
                        create_ellipse_path (pi->pc, r1, r1, r1+waste, r1+waste);
                } else {
                        /* Business Card CD style, clipped round label w/ hole */
                        gl_label_get_size (label, &w, &h);
-                       r1 = template->label.cd.r1;
+                       r1 = label_type->size.cd.r1;
                        create_clipped_circle_path (pi->pc,
                                                    w/2, h/2,
                                                    w+2*waste, h+2*waste,
@@ -1223,8 +1231,6 @@ clip_to_outline (PrintInfo *pi,
                break;
        }
 
-       gl_template_free (&template);
-
        gl_debug (DEBUG_PRINT, "END");
 }
 
@@ -1239,24 +1245,24 @@ static void
 clip_punchouts (PrintInfo *pi,
                glLabel   *label)
 {
-       gdouble w, h, r2;
-       gdouble waste;
-       glTemplate *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    w, h, r2;
+       gdouble                    waste;
 
        gl_debug (DEBUG_PRINT, "START");
 
-       template = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (pi->template);
 
-       switch (template->label.style) {
+       switch (label_type->shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
-       case GL_TEMPLATE_STYLE_ROUND:
+       case GL_TEMPLATE_SHAPE_RECT:
+       case GL_TEMPLATE_SHAPE_ROUND:
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
+       case GL_TEMPLATE_SHAPE_CD:
                gl_label_get_size (label, &w, &h);
-               waste = template->label.cd.waste;
-               r2    = template->label.cd.r2;
+               waste = label_type->waste;
+               r2    = label_type->size.cd.r2;
                create_ellipse_path (pi->pc, w/2, h/2, r2-waste, r2-waste);
                gnome_print_setrgbcolor (pi->pc, 1.0, 1.0, 1.0);
                gnome_print_setopacity (pi->pc, 1.0);
@@ -1268,8 +1274,6 @@ clip_punchouts (PrintInfo *pi,
                break;
        }
 
-       gl_template_free (&template);
-
        gl_debug (DEBUG_PRINT, "END");
 }
 
index ed4df5ba3d79401c53a32508a7a351ceaee01385..cfb7ad6618e722aec7762a1784c81b6554a51dd3 100644 (file)
@@ -28,7 +28,8 @@
 
 #include "template-designer.h"
 #include "prefs.h"
-#include "paper.h"
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
 #include "wdgt-mini-preview.h"
 #include "print-dialog.h"
 
@@ -512,7 +513,7 @@ construct_pg_size_page (glTemplateDesigner      *dlg,
        /* Load page size combo */
        page_sizes = gl_paper_get_name_list ();
        gtk_combo_set_popdown_strings (GTK_COMBO(dlg->priv->pg_size_combo), page_sizes);
-       gl_paper_free_name_list (&page_sizes);
+       gl_paper_free_name_list (page_sizes);
        default_page_size_id = gl_prefs_get_page_size ();
        default_page_size_name = gl_paper_lookup_name_from_id (default_page_size_id);
        gtk_entry_set_text (GTK_ENTRY(dlg->priv->pg_size_entry), default_page_size_name);
@@ -1137,7 +1138,7 @@ pg_size_page_changed_cb (glTemplateDesigner *dlg)
                                                   paper->height * dlg->priv->units_per_point);
                }
 
-               gl_paper_free (&paper);
+               gl_paper_free (paper);
        }
 
        g_free (page_size_name);
@@ -1455,7 +1456,7 @@ layout_page_changed_cb (glTemplateDesigner *dlg)
        gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(dlg->priv->layout_mini_preview),
                                           template);
 
-       gl_template_free (&template);
+       gl_template_free (template);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -1477,7 +1478,7 @@ print_test_cb (glTemplateDesigner      *dlg)
        gl_print_dialog_force_outline_flag (GL_PRINT_DIALOG(print_dialog));
        gtk_widget_show (print_dialog);
 
-       gl_template_free (&template);
+       gl_template_free (template);
        g_object_unref (G_OBJECT(label));
 }
 
@@ -1502,18 +1503,23 @@ finish_cb (glTemplateDesigner *dlg)
 static glTemplate *
 build_template (glTemplateDesigner      *dlg)
 {
-       gchar                *brand, *part_num, *desc;
+       gdouble               upp;
+       gchar                *brand, *part_num, *name, *desc;
        gchar                *page_size_name;
        glPaper              *paper;
-       glTemplateLabelStyle  shape;
+       glTemplateLabelShape  shape;
+       glTemplateLabelType  *label_type;
        gdouble               w, h, r, radius, hole, waste, margin;
        gint                  nlayouts;
        gdouble               nx_1, ny_1, x0_1, y0_1, dx_1, dy_1;
        gdouble               nx_2, ny_2, x0_2, y0_2, dx_2, dy_2;
        glTemplate           *template;
 
+       upp = dlg->priv->units_per_point;
+
        brand    = gtk_editable_get_chars (GTK_EDITABLE(dlg->priv->brand_entry), 0, -1);
        part_num = gtk_editable_get_chars (GTK_EDITABLE(dlg->priv->part_num_entry), 0, -1);
+       name     = g_strdup_printf ("%s %s", brand, part_num);
        desc     = gtk_editable_get_chars (GTK_EDITABLE(dlg->priv->description_entry), 0, -1);
 
        page_size_name =
@@ -1522,14 +1528,14 @@ build_template (glTemplateDesigner      *dlg)
        if ( g_strcasecmp (paper->id, "Other") == 0 ) {
                paper->width =
                        gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->pg_w_spin))
-                       / dlg->priv->units_per_point;
+                       / upp;
                paper->height =
                        gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->pg_h_spin))
-                        / dlg->priv->units_per_point;
+                        / upp;
        }
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->priv->shape_rect_radio))) {
-               shape = GL_TEMPLATE_STYLE_RECT;
+               shape = GL_TEMPLATE_SHAPE_RECT;
                w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->rect_w_spin));
                h = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->rect_h_spin));
                r = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->rect_r_spin));
@@ -1538,14 +1544,14 @@ build_template (glTemplateDesigner      *dlg)
        }
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->priv->shape_round_radio))) {
-               shape = GL_TEMPLATE_STYLE_ROUND;
+               shape = GL_TEMPLATE_SHAPE_ROUND;
                r = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->round_r_spin));
                waste = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->round_waste_spin));
                margin = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->round_margin_spin));
        }
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->priv->shape_cd_radio))) {
-               shape = GL_TEMPLATE_STYLE_CD;
+               shape = GL_TEMPLATE_SHAPE_CD;
                radius = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->cd_radius_spin));
                hole = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->cd_hole_spin));
                w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->cd_w_spin));
@@ -1568,61 +1574,55 @@ build_template (glTemplateDesigner      *dlg)
        dx_2 = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->layout2_dx_spin));
        dy_2 = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dlg->priv->layout2_dy_spin));
 
-       template = g_new0 (glTemplate, 1);
 
-       template->name = g_strdup_printf ("%s %s", brand, part_num);
-       template->alias = g_list_append (template->alias, g_strdup (template->name));
-       template->page_size = g_strdup (paper->id);
-       template->page_width = paper->width;
-       template->page_height = paper->height;
-       template->description = g_strdup (desc);
+       template = gl_template_new (name, desc, paper->id, paper->width, paper->height);
 
-       template->label.style = shape;
        switch (shape) {
-       case GL_TEMPLATE_STYLE_RECT:
-               template->label.rect.w = w / dlg->priv->units_per_point;
-               template->label.rect.h = h / dlg->priv->units_per_point;
-               template->label.rect.r = r / dlg->priv->units_per_point;
-               template->label.rect.waste = waste / dlg->priv->units_per_point;
+       case GL_TEMPLATE_SHAPE_RECT:
+               label_type =
+                       gl_template_rect_label_type_new ("0",
+                                                        w/upp, h/upp, r/upp,
+                                                        waste/upp);
                break;
-       case GL_TEMPLATE_STYLE_ROUND:
-               template->label.round.r = r / dlg->priv->units_per_point;
-               template->label.round.waste = waste / dlg->priv->units_per_point;
+       case GL_TEMPLATE_SHAPE_ROUND:
+               label_type =
+                       gl_template_round_label_type_new ("0", r/upp, waste/upp);
                break;
-       case GL_TEMPLATE_STYLE_CD:
-               template->label.cd.r1 = radius / dlg->priv->units_per_point;
-               template->label.cd.r2 = hole / dlg->priv->units_per_point;
-               template->label.cd.w = w / dlg->priv->units_per_point;
-               template->label.cd.h = h / dlg->priv->units_per_point;
-               template->label.cd.waste = waste / dlg->priv->units_per_point;
+       case GL_TEMPLATE_SHAPE_CD:
+               label_type =
+                       gl_template_cd_label_type_new ("0",
+                                                      radius/upp, hole/upp,
+                                                      w/upp, h/upp,
+                                                      waste/upp);
                break;
        }
-       template->label.any.markups =
-               g_list_append (template->label.any.markups,
-                              gl_template_markup_margin_new (margin / dlg->priv->units_per_point));
-       template->label.any.layouts =
-               g_list_append (template->label.any.layouts,
-                              gl_template_layout_new (nx_1, ny_1,
-                                                      x0_1 / dlg->priv->units_per_point,
-                                                      y0_1 / dlg->priv->units_per_point,
-                                                      dx_1 / dlg->priv->units_per_point,
-                                                      dy_1 / dlg->priv->units_per_point));
+       gl_template_add_label_type (template, label_type);
+
+       gl_template_add_markup (label_type,
+                               gl_template_markup_margin_new (margin/upp));
+
+       gl_template_add_layout (label_type,
+                               gl_template_layout_new (nx_1, ny_1,
+                                                       x0_1/upp,
+                                                       y0_1/upp,
+                                                       dx_1/upp,
+                                                       dy_1/upp));
        if (nlayouts > 1) {
-               template->label.any.layouts =
-                       g_list_append (template->label.any.layouts,
-                                      gl_template_layout_new (nx_2, ny_2,
-                                                              x0_2 / dlg->priv->units_per_point,
-                                                              y0_2 / dlg->priv->units_per_point,
-                                                              dx_2 / dlg->priv->units_per_point,
-                                                              dy_2 / dlg->priv->units_per_point));
+               gl_template_add_layout (label_type,
+                                       gl_template_layout_new (nx_2, ny_2,
+                                                               x0_2/upp,
+                                                               y0_2/upp,
+                                                               dx_2/upp,
+                                                               dy_2/upp));
        }
 
        g_free (brand);
        g_free (part_num);
+       g_free (name);
        g_free (desc);
 
        g_free (page_size_name);
-       gl_paper_free (&paper);
+       gl_paper_free (paper);
 
        return template;
 }
diff --git a/glabels2/src/template.c b/glabels2/src/template.c
deleted file mode 100644 (file)
index 9fa6887..0000000
+++ /dev/null
@@ -1,815 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  template.c:  template module
- *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#include <config.h>
-
-#include <string.h>
-
-#include "prefs.h"
-#include "util.h"
-#include "xml.h"
-#include "template.h"
-#include "xml-template.h"
-#include "paper.h"
-
-#include "debug.h"
-
-#define GL_DATA_DIR gnome_program_locate_file (NULL,\
-                                        GNOME_FILE_DOMAIN_APP_DATADIR,\
-                                        "glabels",\
-                                        FALSE, NULL)
-
-#define FULL_PAGE "Full-page"
-
-/*===========================================*/
-/* Private types                             */
-/*===========================================*/
-
-/*===========================================*/
-/* Private globals                           */
-/*===========================================*/
-
-static GList *templates = NULL;
-
-/*===========================================*/
-/* Local function prototypes                 */
-/*===========================================*/
-static glTemplate *template_full_page           (const gchar            *page_size);
-
-static GList      *read_templates               (void);
-
-static GList      *read_template_files_from_dir (GList                  *templates,
-                                                const gchar            *dirname);
-static gint        compare_origins              (gconstpointer           a,
-                                                gconstpointer           b,
-                                                gpointer                user_data);
-
-static glTemplateLayout *layout_dup             (glTemplateLayout       *orig_layout);
-static void              layout_free            (glTemplateLayout      **layout);
-
-static glTemplateMarkup *markup_dup             (glTemplateMarkup       *orig_markup);
-static void              markup_free            (glTemplateMarkup      **markup);
-
-/*****************************************************************************/
-/* Initialize module.                                                        */
-/*****************************************************************************/
-void
-gl_template_init (void)
-{
-       GList *page_sizes, *p;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       templates = read_templates ();
-
-       page_sizes = gl_paper_get_id_list ();
-       for ( p=page_sizes; p != NULL; p=p->next ) {
-               if ( g_strcasecmp(p->data, "Other") != 0 ) {
-                       templates = g_list_append (templates,
-                                                  template_full_page (p->data));
-               }
-       }
-       gl_paper_free_id_list (&page_sizes);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*****************************************************************************/
-/* Get a list of valid template names for given page size                    */
-/*****************************************************************************/
-GList *
-gl_template_get_name_list (const gchar *page_size)
-{
-       GList      *p_tmplt, *p_alias;
-       glTemplate *template;
-       gchar      *str;
-       GList      *names = NULL;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
-               template = (glTemplate *) p_tmplt->data;
-               if (g_strcasecmp (page_size, template->page_size) == 0) {
-                       for (p_alias = template->alias; p_alias != NULL;
-                            p_alias = p_alias->next) {
-                               str = g_strdup_printf("%s: %s",
-                                                     (gchar *) p_alias->data,
-                                                     template->description);
-                               names = g_list_insert_sorted (names, str,
-                                                            (GCompareFunc)g_strcasecmp);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "templates = %p", templates);
-       gl_debug (DEBUG_TEMPLATE, "names = %p", names);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-       return names;
-}
-
-/*****************************************************************************/
-/* Free a list of template names.                                            */
-/*****************************************************************************/
-void
-gl_template_free_name_list (GList **names)
-{
-       GList *p_name;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       for (p_name = *names; p_name != NULL; p_name = p_name->next) {
-               g_free (p_name->data);
-               p_name->data = NULL;
-       }
-
-       g_list_free (*names);
-       *names = NULL;
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*****************************************************************************/
-/* Register template: if not in current list, add it.                        */
-/*****************************************************************************/
-void
-gl_template_register (const glTemplate  *template)
-{
-       GList      *p_tmplt, *pa1;
-       glTemplate *template1;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
-               template1 = (glTemplate *) p_tmplt->data;
-
-               for (pa1=template1->alias; pa1!=NULL; pa1=pa1->next) {
-                       
-                       gl_debug (DEBUG_TEMPLATE, "comparing \"%s\" & \"%s\"",
-                                 template->name, pa1->data);
-
-                       if (g_strcasecmp (template->name, pa1->data) == 0) {
-
-                               /* FIXME: make sure templates are really identical */
-                               /*        if not, apply hash to name to make unique. */
-
-                               gl_debug (DEBUG_TEMPLATE, "END (found)");
-                               return;
-                       }
-                               
-               }
-
-       }
-
-       if (gl_paper_is_id_known (template->page_size)) {
-
-               gchar *dir, *filename, *abs_filename;
-
-               gl_debug (DEBUG_TEMPLATE, "adding \"%s\"", template->name);
-               templates = g_list_prepend (templates, gl_template_dup (template));
-
-               /* FIXME: make sure filename is unique */
-               dir = gl_util_get_home_data_dir ();
-               filename = g_strconcat (template->name, ".template", NULL);
-               abs_filename = g_build_filename (dir, filename, NULL);
-               gl_xml_template_write_template_to_file (template, abs_filename);
-               g_free (dir);
-               g_free (filename);
-               g_free (abs_filename);
-
-       } else {
-               g_warning ("Cannot register new template with unknown page size.");
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*****************************************************************************/
-/* Return a template structure from a name.                                  */
-/*****************************************************************************/
-glTemplate *
-gl_template_from_name (const gchar *name)
-{
-       GList       *p_tmplt, *p_alias;
-       glTemplate  *template, *new_template;
-       gchar      **split_name;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       if (name == NULL) {
-               /* If no name, return first template as a default */
-               return gl_template_dup ((glTemplate *) templates->data);
-       }
-
-       split_name = g_strsplit (name, ":", 2);
-
-       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
-               template = (glTemplate *) p_tmplt->data;
-               for (p_alias = template->alias; p_alias != NULL;
-                    p_alias = p_alias->next) {
-                       if (g_strcasecmp (p_alias->data, split_name[0]) == 0) {
-
-                               new_template = gl_template_dup (template);
-
-                               /* Use the real name */
-                               g_free (new_template->name);
-                               new_template->name = g_strdup (split_name[0]);
-
-                               g_strfreev (split_name);
-                               gl_debug (DEBUG_TEMPLATE, "END");
-
-                               return new_template;
-                       }
-               }
-       }
-
-       g_strfreev (split_name);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-
-       /* No matching template has been found so return the first template */
-       return gl_template_dup ((glTemplate *) templates->data);
-}
-
-/*****************************************************************************/
-/* Get name and format with description.                                     */
-/*****************************************************************************/
-gchar *
-gl_template_get_name_with_desc (const glTemplate  *template)
-{
-       return g_strdup_printf("%s: %s", template->name, template->description);
-}
-
-
-/*****************************************************************************/
-/* Copy a template.                                                          */
-/*****************************************************************************/
-glTemplate *gl_template_dup (const glTemplate *orig_template)
-{
-       glTemplate       *template;
-       GList            *p;
-       glTemplateLayout *layout;
-       glTemplateMarkup *markup;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template = g_new0 (glTemplate,1);
-
-       template->name = g_strdup (orig_template->name);
-
-       template->alias = NULL;
-       for ( p=orig_template->alias; p != NULL; p=p->next ) {
-               template->alias = g_list_append (template->alias,
-                                               g_strdup (p->data));
-       }
-       template->description = g_strdup (orig_template->description);
-       template->page_size   = g_strdup (orig_template->page_size);
-       template->page_width  = orig_template->page_width;
-       template->page_height = orig_template->page_height;
-
-       template->label       = orig_template->label;
-
-       template->label.any.layouts = NULL;
-       for ( p=orig_template->label.any.layouts; p != NULL; p=p->next ) {
-               layout = (glTemplateLayout *)p->data;
-               template->label.any.layouts =
-                       g_list_append (template->label.any.layouts,
-                                      layout_dup (layout));
-       }
-
-       template->label.any.markups = NULL;
-       for ( p=orig_template->label.any.markups; p != NULL; p=p->next ) {
-               markup = (glTemplateMarkup *)p->data;
-               template->label.any.markups =
-                       g_list_append (template->label.any.markups,
-                                      markup_dup (markup));
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-       return template;
-}
-
-/*****************************************************************************/
-/* Free up a template.                                                       */
-/*****************************************************************************/
-void gl_template_free (glTemplate **template)
-{
-       GList *p;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       if ( *template != NULL ) {
-
-               g_free ((*template)->name);
-               (*template)->name = NULL;
-
-               for ( p=(*template)->alias; p != NULL; p=p->next ) {
-                       g_free (p->data);
-                       p->data = NULL;
-               }
-               g_list_free ((*template)->alias);
-               (*template)->alias = NULL;
-
-               g_free ((*template)->description);
-               (*template)->description = NULL;
-
-               g_free ((*template)->page_size);
-               (*template)->page_size = NULL;
-
-               for ( p=(*template)->label.any.layouts; p != NULL; p=p->next ) {
-                       layout_free ((glTemplateLayout **)&p->data);
-               }
-               g_list_free ((*template)->label.any.layouts);
-               (*template)->label.any.layouts = NULL;
-
-               for ( p=(*template)->label.any.markups; p != NULL; p=p->next ) {
-                       markup_free ((glTemplateMarkup **)&p->data);
-               }
-               g_list_free ((*template)->label.any.markups);
-               (*template)->label.any.markups = NULL;
-
-               g_free (*template);
-               *template = NULL;
-
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Make a template for a full page of the given page size.        */
-/*--------------------------------------------------------------------------*/
-static glTemplate *
-template_full_page (const gchar *page_size)
-{
-       glPaper               *paper;
-       glTemplate            *template;
-
-       paper = gl_paper_from_id (page_size);
-       if ( paper == NULL ) {
-               return NULL;
-       }
-
-       template = g_new0 (glTemplate, 1);
-
-       template->name         = g_strdup_printf (_("Generic %s full page"), page_size);
-
-       template->alias        = g_list_append (template->alias, template->name);
-
-       template->page_size    = g_strdup(page_size);
-       template->page_width   = paper->width;
-       template->page_height  = paper->height;
-       template->description  = g_strdup(FULL_PAGE);
-
-       template->label.style  = GL_TEMPLATE_STYLE_RECT;
-       template->label.rect.w = paper->width;
-       template->label.rect.h = paper->height;
-       template->label.rect.r = 0.0;
-
-       template->label.any.layouts =
-               g_list_append (template->label.any.layouts,
-                              gl_template_layout_new (1, 1, 0., 0., 0., 0.));
-
-       template->label.any.markups =
-               g_list_append (template->label.any.markups,
-                              gl_template_markup_margin_new (5.0));
-
-       gl_paper_free (&paper);
-
-       return template;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Read templates from various  files.                            */
-/*--------------------------------------------------------------------------*/
-static GList *
-read_templates (void)
-{
-       gchar *home_data_dir = gl_util_get_home_data_dir ();
-       GList *templates = NULL;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       templates = read_template_files_from_dir (templates, GL_DATA_DIR);
-       templates = read_template_files_from_dir (templates, home_data_dir);
-
-       g_free (home_data_dir);
-
-       if (templates == NULL) {
-               g_warning (_("No template files found!"));
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-       return templates;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Read all template files from given directory.  Append to list. */
-/*--------------------------------------------------------------------------*/
-static GList *
-read_template_files_from_dir (GList       *templates,
-                             const gchar *dirname)
-{
-       GDir        *dp;
-       const gchar *filename, *extension, *extension2;
-       gchar       *full_filename = NULL;
-       GError      *gerror = NULL;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       if (dirname == NULL)
-               return templates;
-
-       dp = g_dir_open (dirname, 0, &gerror);
-       if (gerror != NULL) {
-               g_warning ("cannot open data directory: %s", gerror->message );
-               gl_debug (DEBUG_TEMPLATE, "END");
-               return templates;
-       }
-
-       while ((filename = g_dir_read_name (dp)) != NULL) {
-
-               extension = strrchr (filename, '.');
-               extension2 = strrchr (filename, '-');
-
-               if (extension != NULL) {
-
-                       if ( (g_strcasecmp (extension, ".template") == 0)
-                            || (g_strcasecmp (extension2, "-templates.xml") == 0) ) {
-
-                               full_filename =
-                                   g_build_filename (dirname, filename, NULL);
-                               templates =
-                                   gl_xml_template_read_templates_from_file (templates,
-                                                                             full_filename);
-                               g_free (full_filename);
-
-                       }
-
-               }
-
-       }
-
-       g_dir_close (dp);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-       return templates;
-}
-
-/****************************************************************************/
-/* Get label size description.                                              */ 
-/****************************************************************************/
-gchar *
-gl_template_get_label_size_desc (const glTemplate *template)
-{
-       glPrefsUnits  units;
-       const gchar  *units_string;
-       gdouble       units_per_point;
-       gchar        *string = NULL;
-
-       units           = gl_prefs_get_units ();
-       units_string    = gl_prefs_get_units_string ();
-       units_per_point = gl_prefs_get_units_per_point ();
-
-       switch (template->label.style) {
-       case GL_TEMPLATE_STYLE_RECT:
-               if ( units == GL_UNITS_INCHES ) {
-                       gchar *xstr, *ystr;
-
-                       xstr = gl_util_fraction (template->label.rect.w * units_per_point);
-                       ystr = gl_util_fraction (template->label.rect.h * units_per_point);
-                       string = g_strdup_printf (_("%s x %s %s"),
-                                                 xstr, ystr, units_string);
-                       g_free (xstr);
-                       g_free (ystr);
-               } else {
-                       string = g_strdup_printf (_("%.5g x %.5g %s"),
-                                                 template->label.rect.w * units_per_point,
-                                                 template->label.rect.h * units_per_point,
-                                                 units_string);
-               }
-               break;
-       case GL_TEMPLATE_STYLE_ROUND:
-               if ( units == GL_UNITS_INCHES ) {
-                       gchar *dstr;
-
-                       dstr = gl_util_fraction (2.0 * template->label.round.r * units_per_point);
-                       string = g_strdup_printf (_("%s %s diameter"),
-                                                 dstr, units_string);
-                       g_free (dstr);
-               } else {
-                       string = g_strdup_printf (_("%.5g %s diameter"),
-                                                 2.0 * template->label.round.r * units_per_point,
-                                                 units_string);
-               }
-               break;
-       case GL_TEMPLATE_STYLE_CD:
-               if ( units == GL_UNITS_INCHES ) {
-                       gchar *dstr;
-
-                       dstr = gl_util_fraction (2.0 * template->label.cd.r1 * units_per_point);
-                       string = g_strdup_printf (_("%s %s diameter"),
-                                                 dstr, units_string);
-                       g_free (dstr);
-               } else {
-                       string = g_strdup_printf (_("%.5g %s diameter"),
-                                                 2.0 * template->label.cd.r1 * units_per_point,
-                                                 units_string);
-               }
-               break;
-       default:
-               break;
-       }
-
-       return string;
-}
-
-/****************************************************************************/
-/* Get raw label size (width and height).                                   */
-/****************************************************************************/
-void
-gl_template_get_label_size (const glTemplate *template,
-                           gdouble          *w,
-                           gdouble          *h)
-{
-       switch (template->label.style) {
-       case GL_TEMPLATE_STYLE_RECT:
-               *w = template->label.rect.w;
-               *h = template->label.rect.h;
-               break;
-       case GL_TEMPLATE_STYLE_ROUND:
-               *w = 2.0 * template->label.round.r;
-               *h = 2.0 * template->label.round.r;
-               break;
-       case GL_TEMPLATE_STYLE_CD:
-               if (template->label.cd.w == 0.0) {
-                       *w = 2.0 * template->label.cd.r1;
-               } else {
-                       *w = template->label.cd.w;
-               }
-               if (template->label.cd.h == 0.0) {
-                       *h = 2.0 * template->label.cd.r1;
-               } else {
-                       *h = template->label.cd.h;
-               }
-               break;
-       default:
-               *w = 0.0;
-               *h = 0.0;
-               break;
-       }
-}
-
-/****************************************************************************/
-/* Get total number of labels per sheet.                                    */
-/****************************************************************************/
-gint
-gl_template_get_n_labels (const glTemplate *template)
-{
-       gint              n_labels = 0;
-       GList            *p;
-       glTemplateLayout *layout;
-
-       for ( p=template->label.any.layouts; p != NULL; p=p->next ) {
-               layout = (glTemplateLayout *)p->data;
-
-               n_labels += layout->nx * layout->ny;
-       }
-
-       return n_labels;
-}
-
-/****************************************************************************/
-/* Get array of origins of individual labels.                               */
-/****************************************************************************/
-glTemplateOrigin *
-gl_template_get_origins (const glTemplate *template)
-{
-       gint              i_label, n_labels, ix, iy;
-       glTemplateOrigin *origins;
-       GList            *p;
-       glTemplateLayout *layout;
-
-       n_labels = gl_template_get_n_labels (template);
-       origins = g_new0 (glTemplateOrigin, n_labels);
-
-       i_label = 0;
-       for ( p=template->label.any.layouts; p != NULL; p=p->next ) {
-               layout = (glTemplateLayout *)p->data;
-
-               for (iy = 0; iy < layout->ny; iy++) {
-                       for (ix = 0; ix < layout->nx; ix++, i_label++) {
-                               origins[i_label].x = ix*layout->dx + layout->x0;
-                               origins[i_label].y = iy*layout->dy + layout->y0;
-                       }
-               }
-       }
-
-       g_qsort_with_data (origins, n_labels, sizeof(glTemplateOrigin),
-                          compare_origins, NULL);
-
-       return origins;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Sort origins comparison function, first by y then by x.        */
-/*--------------------------------------------------------------------------*/
-static gint
-compare_origins (gconstpointer a,
-                gconstpointer b,
-                gpointer      user_data)
-{
-       const glTemplateOrigin *a_origin = a, *b_origin = b;
-
-       if ( a_origin->y < b_origin->y ) {
-               return -1;
-       } else if ( a_origin->y > b_origin->y ) {
-               return +1;
-       } else {
-               if ( a_origin->x < b_origin->x ) {
-                       return -1;
-               } else if ( a_origin->x > b_origin->x ) {
-                       return +1;
-               } else {
-                       return 0; /* hopefully 2 labels won't have the same origin */
-               }
-       }
-}
-
-/****************************************************************************/
-/* Get a description of the layout and number of labels.                    */
-/****************************************************************************/
-gchar *
-gl_template_get_layout_desc (const glTemplate *template)
-{
-       gint              n_labels;
-       glTemplateLayout *layout;
-       gchar            *string;
-
-       n_labels = gl_template_get_n_labels (template);
-
-       if ( template->label.any.layouts->next == NULL ) {
-               layout = (glTemplateLayout *)template->label.any.layouts->data;
-               string = g_strdup_printf (_("%d x %d  (%d per sheet)"),
-                                         layout->nx, layout->ny,
-                                         n_labels);
-       } else {
-               string = g_strdup_printf (_("%d per sheet"),
-                                         n_labels);
-       }
-
-       return string;
-}
-
-/*****************************************************************************/
-/* Create new layout structure.                                              */
-/*****************************************************************************/
-glTemplateLayout *
-gl_template_layout_new (gdouble nx,
-                       gdouble ny,
-                       gdouble x0,
-                       gdouble y0,
-                       gdouble dx,
-                       gdouble dy)
-{
-       glTemplateLayout *layout;
-
-       layout = g_new0 (glTemplateLayout, 1);
-
-       layout->nx = nx;
-       layout->ny = ny;
-       layout->x0 = x0;
-       layout->y0 = y0;
-       layout->dx = dx;
-       layout->dy = dy;
-
-       return layout;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Duplicate layout structure.                                    */
-/*--------------------------------------------------------------------------*/
-static glTemplateLayout *
-layout_dup (glTemplateLayout *orig_layout)
-{
-       glTemplateLayout *layout;
-
-       layout = g_new0 (glTemplateLayout, 1);
-
-       /* copy contents */
-       *layout = *orig_layout;
-
-       return layout;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Free layout structure.                                         */
-/*--------------------------------------------------------------------------*/
-static void
-layout_free (glTemplateLayout **layout)
-{
-       g_free (*layout);
-       *layout = NULL;
-}
-
-/*****************************************************************************/
-/* Create new margin markup structure.                                       */
-/*****************************************************************************/
-glTemplateMarkup *
-gl_template_markup_margin_new (gdouble size)
-{
-       glTemplateMarkup *markup;
-
-       markup = g_new0 (glTemplateMarkup, 1);
-
-       markup->type        = GL_TEMPLATE_MARKUP_MARGIN;
-       markup->margin.size = size;
-
-       return markup;
-}
-
-/*****************************************************************************/
-/* Create new markup line structure.                                         */
-/*****************************************************************************/
-glTemplateMarkup *
-gl_template_markup_line_new (gdouble x1,
-                            gdouble y1,
-                            gdouble x2,
-                            gdouble y2)
-{
-       glTemplateMarkup *markup;
-
-       markup = g_new0 (glTemplateMarkup, 1);
-
-       markup->type        = GL_TEMPLATE_MARKUP_LINE;
-       markup->line.x1     = x1;
-       markup->line.y1     = y1;
-       markup->line.x2     = x2;
-       markup->line.y2     = y2;
-
-       return markup;
-}
-
-/*****************************************************************************/
-/* Create new markup circle structure.                                       */
-/*****************************************************************************/
-glTemplateMarkup *
-gl_template_markup_circle_new (gdouble x0,
-                              gdouble y0,
-                              gdouble r)
-{
-       glTemplateMarkup *markup;
-
-       markup = g_new0 (glTemplateMarkup, 1);
-
-       markup->type        = GL_TEMPLATE_MARKUP_CIRCLE;
-       markup->circle.x0   = x0;
-       markup->circle.y0   = y0;
-       markup->circle.r    = r;
-
-       return markup;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Duplicate markup structure.                                    */
-/*--------------------------------------------------------------------------*/
-static glTemplateMarkup *
-markup_dup (glTemplateMarkup *orig_markup)
-{
-       glTemplateMarkup *markup;
-
-       markup = g_new0 (glTemplateMarkup, 1);
-
-       *markup = *orig_markup;
-
-       return markup;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Free markup structure.                                         */
-/*--------------------------------------------------------------------------*/
-static void
-markup_free (glTemplateMarkup **markup)
-{
-       g_free (*markup);
-       *markup = NULL;
-}
diff --git a/glabels2/src/template.h b/glabels2/src/template.h
deleted file mode 100644 (file)
index 95bd47f..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  template.h:  template module header file
- *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#ifndef __TEMPLATE_H__
-#define __TEMPLATE_H__
-
-#include <libgnome/libgnome.h>
-
-G_BEGIN_DECLS
-
-/*
- *   Template Label Structure
- */
-typedef enum {
-       GL_TEMPLATE_STYLE_RECT,
-       GL_TEMPLATE_STYLE_ROUND,
-       GL_TEMPLATE_STYLE_CD,
-} glTemplateLabelStyle;
-
-typedef struct {
-       glTemplateLabelStyle  style;
-       GList                *layouts;  /* List of glTemplateLayouts */
-       GList                *markups;  /* List of glTemplateMarkups */
-} glTemplateLabelParent;
-
-typedef struct {
-       glTemplateLabelParent parent;
-
-       gdouble               w, h, r;  /* Dimensions */
-       gdouble               waste;
-} glTemplateLabelRect;
-
-typedef struct {
-       glTemplateLabelParent parent;
-
-       gdouble               r;        /* Dimensions */
-       gdouble               waste;
-} glTemplateLabelRound;
-
-typedef struct {
-       glTemplateLabelParent parent;
-
-       gdouble               r1, r2, w, h; /* Dimensions, w&h are for business card CDs */
-       gdouble               waste;
-} glTemplateLabelCD;
-
-typedef union {
-       glTemplateLabelStyle  style;
-       glTemplateLabelParent any;
-       glTemplateLabelRect   rect;
-       glTemplateLabelRound  round;
-       glTemplateLabelCD     cd;
-} glTemplateLabel;
-
-
-/*
- *   Label Markup
- */
-typedef enum {
-       GL_TEMPLATE_MARKUP_MARGIN,
-       GL_TEMPLATE_MARKUP_LINE,
-       GL_TEMPLATE_MARKUP_CIRCLE,
-} glTemplateMarkupType;
-
-typedef struct {
-       /* NOTE: These fields are common to all union members. */
-       glTemplateMarkupType   type;
-} glTemplateMarkupParent;
-
-typedef struct {
-       glTemplateMarkupParent parent;
-
-       gdouble                size;
-} glTemplateMarkupMargin;
-
-typedef struct {
-       glTemplateMarkupParent parent;
-
-       gdouble                x1, y1, x2, y2;
-} glTemplateMarkupLine;
-
-typedef struct {
-       glTemplateMarkupParent parent;
-
-       gdouble                x0, y0, r;
-} glTemplateMarkupCircle;
-
-typedef union {
-       glTemplateMarkupType   type;
-       glTemplateMarkupParent any;
-       glTemplateMarkupMargin margin;
-       glTemplateMarkupLine   line;
-       glTemplateMarkupCircle circle;
-} glTemplateMarkup;
-
-
-/*
- *   Label layout
- */
-typedef struct {
-       gint nx, ny;
-       gdouble x0, y0, dx, dy;
-} glTemplateLayout;
-
-
-/*
- *   Template
- */
-typedef struct {
-       gchar               *name;
-       gchar               *description;
-       gchar               *page_size;
-       gdouble              page_width;
-       gdouble              page_height;
-
-       glTemplateLabel      label;
-
-       GList               *alias;
-} glTemplate;
-
-
-/*
- *  Origin coordinates
- */
-typedef struct {
-       gdouble x, y;
-} glTemplateOrigin;
-
-
-void                 gl_template_init                (void);
-
-GList               *gl_template_get_name_list       (const gchar       *page_size);
-void                 gl_template_free_name_list      (GList            **names);
-
-void                 gl_template_register            (const glTemplate  *template);
-
-glTemplate          *gl_template_from_name           (const gchar       *name);
-
-gchar               *gl_template_get_name_with_desc  (const glTemplate  *template);
-
-glTemplate          *gl_template_dup                 (const glTemplate  *orig);
-void                 gl_template_free                (glTemplate       **template);
-
-gchar               *gl_template_get_label_size_desc (const glTemplate  *template);
-void                 gl_template_get_label_size      (const glTemplate  *template,
-                                                     gdouble           *w,
-                                                     gdouble           *h);
-
-gint                 gl_template_get_n_labels        (const glTemplate  *template);
-glTemplateOrigin    *gl_template_get_origins         (const glTemplate  *template);
-gchar               *gl_template_get_layout_desc     (const glTemplate  *template);
-
-glTemplateLayout    *gl_template_layout_new          (gdouble            nx,
-                                                     gdouble            ny,
-                                                     gdouble            x0,
-                                                     gdouble            y0,
-                                                     gdouble            dx,
-                                                     gdouble            dy);
-
-glTemplateMarkup    *gl_template_markup_margin_new   (gdouble            size);
-glTemplateMarkup    *gl_template_markup_line_new     (gdouble            x1,
-                                                     gdouble            y1,
-                                                     gdouble            x2,
-                                                     gdouble            y2);
-glTemplateMarkup    *gl_template_markup_circle_new   (gdouble            x0,
-                                                     gdouble            y0,
-                                                     gdouble            r);
-
-
-G_END_DECLS
-
-#endif
index 124d492c86bcc23bfa47ad8054cd2895e5be4df1..ea92bf56b90bb121112cff52447c3056147c66d9 100644 (file)
 
 #include "util.h"
 
-#define FRAC_DELTA 0.00005
-
-\f
-/****************************************************************************/
-/* Get '~/.glabels' directory path.                                         */
-/****************************************************************************/
-gchar *
-gl_util_get_home_data_dir (void)
-{
-        gchar *dir = gnome_util_prepend_user_home (".glabels");
-        /* Try to create ~/.glabels directory.  If it exists, no problem. */
-        mkdir (dir, 0775);
-        return dir;
-}
-
+#define FRAC_EPSILON 0.00005
 
 \f
 /****************************************************************************/
@@ -125,7 +109,7 @@ gl_util_fraction (gdouble x)
        for ( i=0; denom[i] != 0.0; i++ ) {
                product = x * denom[i];
                remainder = fabs(product - ((gint)(product+0.5)));
-               if ( remainder < FRAC_DELTA ) break;
+               if ( remainder < FRAC_EPSILON ) break;
        }
 
        if ( denom[i] == 0.0 ) {
index 73366d150c981cdcdb4559ed6d3d379c7bfe8c05..8e6942ed35ed959cd8608713346f710704aacc69 100644 (file)
@@ -28,8 +28,6 @@
 
 G_BEGIN_DECLS
 
-gchar              *gl_util_get_home_data_dir     (void);
-
 gchar              *gl_util_add_extension         (const gchar       *orig_filename);
 gchar              *gl_util_remove_extension      (const gchar       *orig_filename);
 
index 5fd87105dccf50c406f646b02e5a0b066c897c1c..142d868519f53b6eb27233767448f33c601ffc49 100644 (file)
@@ -147,23 +147,23 @@ static void       draw_grid_layer                 (glView *view);
 static void       draw_markup_layer               (glView *view);
 
 static void       draw_markup_margin              (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 static void       draw_markup_margin_rect         (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 static void       draw_markup_margin_rounded_rect (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 static void       draw_markup_margin_round        (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 static void       draw_markup_margin_cd           (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 static void       draw_markup_margin_cd_bc        (glView *view,
-                                                  glTemplateMarkupMargin *margin);
+                                                  glTemplateMarkup *margin);
 
 static void       draw_markup_line                (glView *view,
-                                                  glTemplateMarkupLine   *line);
+                                                  glTemplateMarkup *line);
 
 static void       draw_markup_circle              (glView *view,
-                                                  glTemplateMarkupCircle *circle);
+                                                  glTemplateMarkup *circle);
 
 
 static void       select_object_real              (glView *view,
@@ -668,9 +668,10 @@ draw_highlight_layer (glView *view)
 static void
 draw_bg_fg_layers (glView *view)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       GnomeCanvasGroup *group;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GnomeCanvasGroup          *group;
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
@@ -689,13 +690,14 @@ draw_bg_fg_layers (glView *view)
                                       "y", 0.0,
                                       NULL));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       switch (template->label.style) {
+       switch (label_type->shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
-               if (template->label.rect.r == 0.0) {
+       case GL_TEMPLATE_SHAPE_RECT:
+               if (label_type->size.rect.r == 0.0) {
                        /* Square corners. */
                        draw_bg_fg_rect (view);
                } else {
@@ -704,12 +706,12 @@ draw_bg_fg_layers (glView *view)
                }
                break;
 
-       case GL_TEMPLATE_STYLE_ROUND:
+       case GL_TEMPLATE_SHAPE_ROUND:
                draw_bg_fg_round (view);
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
-               if ((template->label.cd.w == 0.0) && (template->label.cd.h == 0.0) ) {
+       case GL_TEMPLATE_SHAPE_CD:
+               if ((label_type->size.cd.w == 0.0) && (label_type->size.cd.h == 0.0) ) {
                        draw_bg_fg_cd (view);
                } else {
                        draw_bg_fg_cd_bc (view);
@@ -729,7 +731,6 @@ static void
 draw_bg_fg_rect (glView *view)
 {
        glLabel          *label;
-       glTemplate       *template;
        gdouble           w, h;
        GnomeCanvasItem  *item;
 
@@ -741,7 +742,6 @@ draw_bg_fg_rect (glView *view)
        label = view->label;
 
        gl_label_get_size (label, &w, &h);
-       template = gl_label_get_template (label);
 
        /* Background */
        item = gnome_canvas_item_new (view->bg_group,
@@ -773,23 +773,25 @@ draw_bg_fg_rect (glView *view)
 static void
 draw_bg_fg_rounded_rect (glView *view)
 {
-       glLabel           *label;
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       glTemplate        *template;
-       gdouble            r, w, h;
-       GnomeCanvasItem   *item;
+       glLabel                   *label;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    r, w, h;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label = view->label;
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
        gl_label_get_size (label, &w, &h);
-       template = gl_label_get_template (label);
-       r = template->label.rect.r;
+       r = label_type->size.rect.r;
 
        points = gnome_canvas_points_new (4 * (1 + 90 / ARC_COURSE));
        i_coords = 0;
@@ -844,20 +846,22 @@ draw_bg_fg_rounded_rect (glView *view)
 static void
 draw_bg_fg_round (glView *view)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       gdouble           r;
-       GnomeCanvasItem  *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    r;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL(view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       r = template->label.round.r;
+       r = label_type->size.round.r;
 
        /* Background */
        item = gnome_canvas_item_new (view->bg_group,
@@ -889,21 +893,23 @@ draw_bg_fg_round (glView *view)
 static void
 draw_bg_fg_cd (glView *view)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       gdouble           r1, r2;
-       GnomeCanvasItem  *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    r1, r2;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       r1 = template->label.cd.r1;
-       r2 = template->label.cd.r2;
+       r1 = label_type->size.cd.r1;
+       r2 = label_type->size.cd.r2;
 
        /* Background */
        /* outer circle */
@@ -956,28 +962,30 @@ draw_bg_fg_cd (glView *view)
 static void
 draw_bg_fg_cd_bc (glView *view)
 {
-       glLabel           *label;
-       glTemplate        *template;
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       gdouble            theta1, theta2;
-       gdouble            x0, y0, w, h, r1, r2;
-       GnomeCanvasItem   *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       gdouble                    theta1, theta2;
+       gdouble                    x0, y0, w, h, r1, r2;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       template = gl_label_get_template (label);
        gl_label_get_size (label, &w, &h);
        x0 = w/2.0;
        y0 = h/2.0;
 
-       r1 = template->label.cd.r1;
-       r2 = template->label.cd.r2;
+       r1 = label_type->size.cd.r1;
+       r2 = label_type->size.cd.r2;
 
        theta1 = (180.0/G_PI) * acos (w / (2.0*r1));
        theta2 = (180.0/G_PI) * asin (h / (2.0*r1));
@@ -1157,11 +1165,12 @@ draw_grid_layer (glView *view)
 static void
 draw_markup_layer (glView *view)
 {
-       GnomeCanvasGroup *group;
-       glLabel          *label;
-       glTemplate       *template;
-       GList            *p;
-       glTemplateMarkup *markup;
+       GnomeCanvasGroup          *group;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GList                     *p;
+       glTemplateMarkup          *markup;
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
@@ -1174,24 +1183,22 @@ draw_markup_layer (glView *view)
                                       "y", 0.0,
                                       NULL));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       for ( p=template->label.any.markups; p != NULL; p=p->next ) {
+       for ( p=label_type->markups; p != NULL; p=p->next ) {
                markup = (glTemplateMarkup *)p->data;
 
                switch (markup->type) {
                case GL_TEMPLATE_MARKUP_MARGIN:
-                       draw_markup_margin (view,
-                                           (glTemplateMarkupMargin *)markup);
+                       draw_markup_margin (view, markup);
                        break;
                case GL_TEMPLATE_MARKUP_LINE:
-                       draw_markup_line (view,
-                                         (glTemplateMarkupLine *)markup);
+                       draw_markup_line (view, markup);
                        break;
                case GL_TEMPLATE_MARKUP_CIRCLE:
-                       draw_markup_circle (view,
-                                           (glTemplateMarkupCircle *)markup);
+                       draw_markup_circle (view, markup);
                        break;
                default:
                        g_warning ("Unknown template markup type");
@@ -1204,44 +1211,46 @@ draw_markup_layer (glView *view)
 /* PRIVATE.  Draw margin markup.                                             */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin (glView                 *view,
-                   glTemplateMarkupMargin *margin)
+draw_markup_margin (glView           *view,
+                   glTemplateMarkup *markup)
 {
-       glLabel    *label;
-       glTemplate *template;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       switch (template->label.style) {
+       switch (label_type->shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
-               if (template->label.rect.r == 0.0) {
+       case GL_TEMPLATE_SHAPE_RECT:
+               if (label_type->size.rect.r == 0.0) {
                        /* Square corners. */
-                       draw_markup_margin_rect (view, margin);
+                       draw_markup_margin_rect (view, markup);
                } else {
-                       if ( margin->size < template->label.rect.r) {
+                       if ( markup->data.margin.size < label_type->size.rect.r) {
                                /* Rounded corners. */
-                               draw_markup_margin_rounded_rect (view, margin);
+                               draw_markup_margin_rounded_rect (view, markup);
                        } else {
                                /* Square corners. */
-                               draw_markup_margin_rect (view, margin);
+                               draw_markup_margin_rect (view, markup);
                        }
                }
                break;
 
-       case GL_TEMPLATE_STYLE_ROUND:
-               draw_markup_margin_round (view, margin);
+       case GL_TEMPLATE_SHAPE_ROUND:
+               draw_markup_margin_round (view, markup);
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
-               if ((template->label.cd.w == 0.0) && (template->label.cd.h == 0.0) ) {
-                       draw_markup_margin_cd (view, margin);
+       case GL_TEMPLATE_SHAPE_CD:
+               if ((label_type->size.cd.w == 0.0) && (label_type->size.cd.h == 0.0) ) {
+                       draw_markup_margin_cd (view, markup);
                } else {
-                       draw_markup_margin_cd_bc (view, margin);
+                       draw_markup_margin_cd_bc (view, markup);
                }
                break;
 
@@ -1255,24 +1264,26 @@ draw_markup_margin (glView                 *view,
 /* PRIVATE.  Draw simple recangular margin.                                  */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin_rect (glView                 *view,
-                        glTemplateMarkupMargin *margin)
+draw_markup_margin_rect (glView           *view,
+                        glTemplateMarkup *markup)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       gdouble           w, h, m;
-       GnomeCanvasItem  *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    w, h, m;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label = view->label;
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
        gl_label_get_size (label, &w, &h);
-       template = gl_label_get_template (label);
-       m = margin->size;
+       m = markup->data.margin.size;
 
        /* Bounding box @ margin */
        gnome_canvas_item_new (view->markup_group,
@@ -1292,27 +1303,29 @@ draw_markup_margin_rect (glView                 *view,
 /* PRIVATE.  Draw rounded recangular markup.                                 */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin_rounded_rect (glView                 *view,
-                                glTemplateMarkupMargin *margin)
+draw_markup_margin_rounded_rect (glView           *view,
+                                glTemplateMarkup *markup)
 {
-       glLabel           *label;
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       glTemplate        *template;
-       gdouble            r, w, h, m;
-       GnomeCanvasItem   *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       gdouble                    r, w, h, m;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label = view->label;
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
        gl_label_get_size (label, &w, &h);
-       template = gl_label_get_template (label);
-       r = template->label.rect.r;
-       m = margin->size;
+       r = label_type->size.rect.r;
+       m = markup->data.margin.size;
 
        r = r - m;
        w = w - 2 * m;
@@ -1360,24 +1373,26 @@ draw_markup_margin_rounded_rect (glView                 *view,
 /* PRIVATE.  Draw round margin.                                              */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin_round (glView                 *view,
-                         glTemplateMarkupMargin *margin)
+draw_markup_margin_round (glView           *view,
+                         glTemplateMarkup *markup)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       gdouble           r, m;
-       GnomeCanvasItem  *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    r, m;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       r = template->label.round.r;
-       m = margin->size;
+       r = label_type->size.round.r;
+       m = markup->data.margin.size;
 
        /* Margin outline */
        item = gnome_canvas_item_new (view->markup_group,
@@ -1397,25 +1412,27 @@ draw_markup_margin_round (glView                 *view,
 /* PRIVATE.  Draw CD margins.                                                */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin_cd (glView                 *view,
-                      glTemplateMarkupMargin *margin)
+draw_markup_margin_cd (glView           *view,
+                      glTemplateMarkup *markup)
 {
-       glLabel          *label;
-       glTemplate       *template;
-       gdouble           m, r1, r2;
-       GnomeCanvasItem  *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    m, r1, r2;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
 
-       r1 = template->label.cd.r1;
-       r2 = template->label.cd.r2;
-       m  = margin->size;
+       r1 = label_type->size.cd.r1;
+       r2 = label_type->size.cd.r2;
+       m  = markup->data.margin.size;
 
        /* outer margin */
        item = gnome_canvas_item_new (view->markup_group,
@@ -1445,32 +1462,35 @@ draw_markup_margin_cd (glView                 *view,
 /* PRIVATE.  Draw Business Card CD margins.                                  */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_margin_cd_bc (glView                 *view,
-                         glTemplateMarkupMargin *margin)
+draw_markup_margin_cd_bc (glView           *view,
+                         glTemplateMarkup *markup)
 {
-       glLabel           *label;
-       glTemplate        *template;
-       gdouble            m, r1, r2;
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       gdouble            theta1, theta2;
-       gdouble            x0, y0, w, h, r;
-       GnomeCanvasItem   *item;
+       glLabel                   *label;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    m, r1, r2;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       gdouble                    theta1, theta2;
+       gdouble                    x0, y0, w, h, r;
+       GnomeCanvasItem           *item;
 
        gl_debug (DEBUG_VIEW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-       label    = view->label;
-       template = gl_label_get_template (label);
+       label      = view->label;
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
+
        gl_label_get_size (label, &w, &h);
        x0 = w/2.0;
        y0 = h/2.0;
 
-       r1 = template->label.cd.r1;
-       r2 = template->label.cd.r2;
-       m  = margin->size;
+       r1 = label_type->size.cd.r1;
+       r2 = label_type->size.cd.r2;
+       m  = markup->data.margin.size;
 
        /* outer margin */
        r = r1 - m;
@@ -1562,8 +1582,8 @@ draw_markup_margin_cd_bc (glView                 *view,
 /* PRIVATE.  Draw line markup.                                               */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_line (glView               *view,
-                 glTemplateMarkupLine *line)
+draw_markup_line (glView           *view,
+                 glTemplateMarkup *markup)
 {
        GnomeCanvasPoints *points;
 
@@ -1572,12 +1592,11 @@ draw_markup_line (glView               *view,
        g_return_if_fail (view && GL_IS_VIEW (view));
 
        points = gnome_canvas_points_new (2);
-       points->coords[0] = line->x1;
-       points->coords[1] = line->y1;
-       points->coords[2] = line->x2;
-       points->coords[3] = line->y2;
+       points->coords[0] = markup->data.line.x1;
+       points->coords[1] = markup->data.line.y1;
+       points->coords[2] = markup->data.line.x2;
+       points->coords[3] = markup->data.line.y2;
 
-       /* Bounding box @ margin */
        gnome_canvas_item_new (view->markup_group,
                               gnome_canvas_line_get_type (),
                               "points", points,
@@ -1594,8 +1613,8 @@ draw_markup_line (glView               *view,
 /* PRIVATE.  Draw circle markup.                                             */
 /*---------------------------------------------------------------------------*/
 static void
-draw_markup_circle (glView                 *view,
-                   glTemplateMarkupCircle *circle)
+draw_markup_circle (glView           *view,
+                   glTemplateMarkup *markup)
 {
        gl_debug (DEBUG_VIEW, "START");
 
@@ -1604,10 +1623,10 @@ draw_markup_circle (glView                 *view,
        /* Circle outline */
        gnome_canvas_item_new (view->markup_group,
                               gnome_canvas_ellipse_get_type (),
-                              "x1", circle->x0 - circle->r,
-                              "y1", circle->y0 - circle->r,
-                              "x2", circle->x0 + circle->r,
-                              "y2", circle->y0 + circle->r,
+                              "x1", markup->data.circle.x0 - markup->data.circle.r,
+                              "y1", markup->data.circle.y0 - markup->data.circle.r,
+                              "x2", markup->data.circle.x0 + markup->data.circle.r,
+                              "y2", markup->data.circle.y0 + markup->data.circle.r,
                               "width_pixels", 1,
                               "outline_color_rgba", MARKUP_COLOR,
                               NULL);
@@ -2984,7 +3003,7 @@ gl_view_copy (glView *view)
                view->selection_data = GL_LABEL(gl_label_new ());
                gl_label_set_template (view->selection_data, template);
                gl_label_set_rotate_flag (view->selection_data, rotate_flag);
-               gl_template_free (&template);
+               gl_template_free (template);
 
                for (p = view->selected_object_list; p != NULL; p = p->next) {
 
index 4ec6b35f94965eca9fe400972b5ea4326c40e751..c0e15f0ce978d57dc4e807de40cb366425f35eb1 100644 (file)
 
 #include "wdgt-media-select.h"
 #include "hig.h"
-#include "template.h"
 #include "wdgt-mini-preview.h"
 #include "prefs.h"
 #include "util.h"
-#include "paper.h"
 #include "marshal.h"
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
 
 #include "debug.h"
 
@@ -74,6 +74,9 @@ static void prefs_changed_cb                   (glPrefsModel           *gl_prefs
 
 static void details_update                     (glWdgtMediaSelect      *media_select,
                                                gchar                  *name);
+
+static gchar *get_layout_desc                  (const glTemplate       *template);
+static gchar *get_label_size_desc              (const glTemplate       *template);
 \f
 /****************************************************************************/
 /* Boilerplate Object stuff.                                                */
@@ -213,7 +216,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
        wcombo = gtk_combo_new ();
        page_sizes = gl_paper_get_name_list ();
        gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), page_sizes);
-       gl_paper_free_name_list (&page_sizes);
+       gl_paper_free_name_list (page_sizes);
        media_select->page_size_entry = GTK_COMBO (wcombo)->entry;
        gtk_entry_set_editable (GTK_ENTRY (media_select->page_size_entry),
                                FALSE);
@@ -241,7 +244,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
                            template_names->data);
        gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox),
                                media_select->template_combo);
-       gl_template_free_name_list (&template_names);
+       gl_template_free_name_list (template_names);
 
        whbox = gl_hig_hbox_new ();
        gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox);
@@ -360,7 +363,7 @@ page_size_entry_changed_cb (GtkEntry *entry,
                                               template_names);
                gtk_entry_set_text (GTK_ENTRY (media_select->template_entry),
                                    template_names->data);
-               gl_template_free_name_list (&template_names);
+               gl_template_free_name_list (template_names);
                g_free (page_size_id);
        }
        g_free (page_size_name);
@@ -451,15 +454,15 @@ details_update (glWdgtMediaSelect *media_select,
        gtk_label_set_text (GTK_LABEL (media_select->sheet_size_label),
                            template->page_size);
 
-       text = gl_template_get_layout_desc (template);
+       text = get_layout_desc (template);
        gtk_label_set_text (GTK_LABEL (media_select->number_label), text);
        g_free (text);
 
-       text = gl_template_get_label_size_desc (template);
+       text = get_label_size_desc (template);
        gtk_label_set_text (GTK_LABEL (media_select->label_size_label), text);
        g_free (text);
 
-       gl_template_free( &template );
+       gl_template_free (template);
 
        gl_debug (DEBUG_MEDIA_SELECT, "END");
 }
@@ -555,3 +558,103 @@ gl_wdgt_media_select_set_page_size (glWdgtMediaSelect *media_select,
 
        gl_debug (DEBUG_MEDIA_SELECT, "END");
 }
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Get a description of the layout and number of labels.          */
+/*--------------------------------------------------------------------------*/
+static gchar *
+get_layout_desc (const glTemplate *template)
+{
+       const glTemplateLabelType *label_type;
+       gint                       n_labels;
+       glTemplateLayout          *layout;
+       gchar                     *string;
+
+       label_type = gl_template_get_first_label_type (template);
+
+       n_labels = gl_template_get_n_labels (label_type);
+
+       if ( label_type->layouts->next == NULL ) {
+               layout = (glTemplateLayout *)label_type->layouts->data;
+               string = g_strdup_printf (_("%d x %d  (%d per sheet)"),
+                                         layout->nx, layout->ny,
+                                         n_labels);
+       } else {
+               string = g_strdup_printf (_("%d per sheet"),
+                                         n_labels);
+       }
+
+       return string;
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Get label size description.                                    */ 
+/*--------------------------------------------------------------------------*/
+static gchar *
+get_label_size_desc (const glTemplate *template)
+{
+       glPrefsUnits               units;
+       const gchar               *units_string;
+       gdouble                    units_per_point;
+       const glTemplateLabelType *label_type;
+       gchar                     *string = NULL;
+
+       units           = gl_prefs_get_units ();
+       units_string    = gl_prefs_get_units_string ();
+       units_per_point = gl_prefs_get_units_per_point ();
+
+       label_type = gl_template_get_first_label_type (template);
+
+       switch (label_type->shape) {
+       case GL_TEMPLATE_SHAPE_RECT:
+               if ( units == GL_UNITS_INCHES ) {
+                       gchar *xstr, *ystr;
+
+                       xstr = gl_util_fraction (label_type->size.rect.w*units_per_point);
+                       ystr = gl_util_fraction (label_type->size.rect.h*units_per_point);
+                       string = g_strdup_printf (_("%s x %s %s"),
+                                                 xstr, ystr, units_string);
+                       g_free (xstr);
+                       g_free (ystr);
+               } else {
+                       string = g_strdup_printf (_("%.5g x %.5g %s"),
+                                                 label_type->size.rect.w*units_per_point,
+                                                 label_type->size.rect.h*units_per_point,
+                                                 units_string);
+               }
+               break;
+       case GL_TEMPLATE_SHAPE_ROUND:
+               if ( units == GL_UNITS_INCHES ) {
+                       gchar *dstr;
+
+                       dstr = gl_util_fraction (2.0*label_type->size.round.r*units_per_point);
+                       string = g_strdup_printf (_("%s %s diameter"),
+                                                 dstr, units_string);
+                       g_free (dstr);
+               } else {
+                       string = g_strdup_printf (_("%.5g %s diameter"),
+                                                 2.0*label_type->size.round.r*units_per_point,
+                                                 units_string);
+               }
+               break;
+       case GL_TEMPLATE_SHAPE_CD:
+               if ( units == GL_UNITS_INCHES ) {
+                       gchar *dstr;
+
+                       dstr = gl_util_fraction (2.0*label_type->size.cd.r1*units_per_point);
+                       string = g_strdup_printf (_("%s %s diameter"),
+                                                 dstr, units_string);
+                       g_free (dstr);
+               } else {
+                       string = g_strdup_printf (_("%.5g %s diameter"),
+                                                 2.0*label_type->size.cd.r1*units_per_point,
+                                                 units_string);
+               }
+               break;
+       default:
+               break;
+       }
+
+       return string;
+}
+
index bb46cc09d331b9b49fe732c18dfde8751004f4b1..ffc6b30ead31cfef92e8b0ca10d20bd13f91f632 100644 (file)
@@ -285,7 +285,7 @@ void gl_wdgt_mini_preview_set_label_by_name (glWdgtMiniPreview *preview,
 
        gl_wdgt_mini_preview_set_template (preview, template);
 
-       gl_template_free( &template );
+       gl_template_free (template);
 
        gl_debug (DEBUG_MINI_PREVIEW, "END");
 }
@@ -357,21 +357,24 @@ static GList *
 mini_outline_list_new (GnomeCanvas       *canvas,
                       const glTemplate  *template)
 {
-       GnomeCanvasGroup      *group = NULL;
-       GnomeCanvasItem       *item = NULL;
-       GList                 *list = NULL;
-       gint                   i, n_labels;
-       glTemplateOrigin      *origins;
-       gdouble                x1, y1, x2, y2, w, h;
+       GnomeCanvasGroup          *group = NULL;
+       const glTemplateLabelType *label_type;
+       GnomeCanvasItem           *item = NULL;
+       GList                     *list = NULL;
+       gint                       i, n_labels;
+       glTemplateOrigin          *origins;
+       gdouble                    x1, y1, x2, y2, w, h;
 
        gl_debug (DEBUG_MINI_PREVIEW, "START");
 
        group = gnome_canvas_root (canvas);
 
+       label_type = gl_template_get_first_label_type (template);
+
        /* draw mini label outlines */
-       n_labels = gl_template_get_n_labels (template);
-       origins  = gl_template_get_origins (template);
-       gl_template_get_label_size (template, &w, &h);
+       n_labels = gl_template_get_n_labels (label_type);
+       origins  = gl_template_get_origins (label_type);
+       gl_template_get_label_size (label_type, &w, &h);
        for ( i=0; i < n_labels; i++ ) {
 
                x1 = origins[i].x;
@@ -379,8 +382,8 @@ mini_outline_list_new (GnomeCanvas       *canvas,
                x2 = x1 + w;
                y2 = y1 + h;
 
-               switch (template->label.style) {
-               case GL_TEMPLATE_STYLE_RECT:
+               switch (label_type->shape) {
+               case GL_TEMPLATE_SHAPE_RECT:
                        item = gnome_canvas_item_new (group,
                                                      gnome_canvas_rect_get_type(),
                                                      "x1", x1,
@@ -392,7 +395,7 @@ mini_outline_list_new (GnomeCanvas       *canvas,
                                                      "fill_color", "white",
                                                      NULL);
                        break;
-               case GL_TEMPLATE_STYLE_ROUND:
+               case GL_TEMPLATE_SHAPE_ROUND:
                        item = gnome_canvas_item_new (group,
                                                      gnome_canvas_ellipse_get_type(),
                                                      "x1", x1,
@@ -404,7 +407,7 @@ mini_outline_list_new (GnomeCanvas       *canvas,
                                                      "fill_color", "white",
                                                      NULL);
                        break;
-               case GL_TEMPLATE_STYLE_CD:
+               case GL_TEMPLATE_SHAPE_CD:
                        if ( w == h ) {
                                item = gnome_canvas_item_new (group,
                                                              gnome_canvas_ellipse_get_type(),
@@ -646,14 +649,17 @@ cdbc_item (GnomeCanvasGroup *group,
           gdouble           y1,
           const glTemplate *template)
 {
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       gdouble            theta1, theta2;
-       gdouble            x0, y0, w, h, r;
-       GnomeCanvasItem   *item;
-
-       gl_template_get_label_size (template, &w, &h);
-       r = template->label.cd.r1;
+       const glTemplateLabelType *label_type;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       gdouble                    theta1, theta2;
+       gdouble                    x0, y0, w, h, r;
+       GnomeCanvasItem           *item;
+
+       label_type = gl_template_get_first_label_type (template);
+
+       gl_template_get_label_size (label_type, &w, &h);
+       r = label_type->size.cd.r1;
        x0 = x1 + (w/2.0);
        y0 = y1 + (h/2.0);
 
index 4166ec860b303d6ead2d3fa18f337461f52eb2ed..09899f801b91bed969a4d5c0c1156c458bced05c 100644 (file)
@@ -150,15 +150,18 @@ static void
 gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
                                glLabel           *label)
 {
-       GtkWidget *whbox, *wvbox, *whbox1;
-       GSList *radio_group = NULL;
-       GtkObject *adjust;
-       const glTemplate *template;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GtkWidget                 *whbox, *wvbox, *whbox1;
+       GSList                    *radio_group = NULL;
+       GtkObject                 *adjust;
 
        whbox = GTK_WIDGET (copies);
 
-       template = gl_label_get_template (label);
-       copies->labels_per_sheet = gl_template_get_n_labels (template);
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
+
+       copies->labels_per_sheet = gl_template_get_n_labels (label_type);
 
        /* mini_preview canvas */
        copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
@@ -221,6 +224,8 @@ gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
                          G_CALLBACK (first_spin_cb), copies);
        g_signal_connect (G_OBJECT (copies->last_spin), "changed",
                          G_CALLBACK (last_spin_cb), copies);
+
+       gl_template_free (template);
 }
 
 /*--------------------------------------------------------------------------*/
index 4b4e6f3e67fe82d5f70b99c7280c9ded1e21e26f..51a0143250bacf421aa54c99f6af5fd618182556 100644 (file)
@@ -147,15 +147,18 @@ static void
 gl_wdgt_print_merge_construct (glWdgtPrintMerge * merge,
                               glLabel * label)
 {
-       GtkWidget *whbox, *wvbox, *whbox1;
-       GtkObject *adjust;
-       GdkPixbuf *pixbuf;
-       const glTemplate *template;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       GtkWidget                 *whbox, *wvbox, *whbox1;
+       GtkObject                 *adjust;
+       GdkPixbuf                 *pixbuf;
 
        whbox = GTK_WIDGET (merge);
 
-       template = gl_label_get_template (label);
-       merge->labels_per_sheet = gl_template_get_n_labels (template);
+       template   = gl_label_get_template (label);
+       label_type = gl_template_get_first_label_type (template);
+
+       merge->labels_per_sheet = gl_template_get_n_labels (label_type);
 
        /* mini_preview canvas */
        merge->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
@@ -214,6 +217,8 @@ gl_wdgt_print_merge_construct (glWdgtPrintMerge * merge,
                          G_CALLBACK (spin_cb), merge);
        g_signal_connect (G_OBJECT (merge->first_spin), "changed",
                          G_CALLBACK (spin_cb), merge);
+
+       gl_template_free (template);
 }
 
 /*--------------------------------------------------------------------------*/
index 283b2b7527a8f2e9b671470782b2c39d4f896229..e5100c8252910be06d6bbdf454c0ef028254d6be 100644 (file)
@@ -26,9 +26,9 @@
 
 #include "wdgt-rotate-label.h"
 #include "hig.h"
-#include "template.h"
 #include "marshal.h"
 #include "color.h"
+#include <libglabels/template.h>
 
 #include "debug.h"
 
@@ -259,16 +259,19 @@ mini_preview_canvas_update (GnomeCanvas *canvas,
                            glTemplate  *template,
                            gboolean     rotate_flag)
 {
-       gdouble           canvas_scale;
-       GnomeCanvasGroup *group = NULL;
-       GnomeCanvasItem  *label_item = NULL;
-       gdouble           m, m_canvas, w, h;
-       guint             line_color, fill_color;
+       const glTemplateLabelType *label_type;
+       gdouble                    canvas_scale;
+       GnomeCanvasGroup          *group = NULL;
+       GnomeCanvasItem           *label_item = NULL;
+       gdouble                    m, m_canvas, w, h;
+       guint                      line_color, fill_color;
 
        /* Fetch our data from canvas */
        label_item = g_object_get_data (G_OBJECT (canvas), "label_item");
 
-       gl_template_get_label_size (template, &w, &h);
+       label_type = gl_template_get_first_label_type (template);
+
+       gl_template_get_label_size (label_type, &w, &h);
        m = MAX (w, h);
        canvas_scale = MINI_PREVIEW_MAX_PIXELS / m;
        m_canvas = MINI_PREVIEW_CANVAS_PIXELS / canvas_scale;
@@ -295,8 +298,8 @@ mini_preview_canvas_update (GnomeCanvas *canvas,
        }
 
        /* draw mini label outline */
-       switch (template->label.style) {
-       case GL_TEMPLATE_STYLE_RECT:
+       switch (label_type->shape) {
+       case GL_TEMPLATE_SHAPE_RECT:
                label_item = gnome_canvas_item_new (group,
                                                    gnome_canvas_rect_get_type(),
                                                    "x1", -w / 2.0,
@@ -308,7 +311,7 @@ mini_preview_canvas_update (GnomeCanvas *canvas,
                                                    "fill_color_rgba", fill_color,
                                                    NULL);
                break;
-       case GL_TEMPLATE_STYLE_ROUND:
+       case GL_TEMPLATE_SHAPE_ROUND:
                label_item = gnome_canvas_item_new (group,
                                                    gnome_canvas_ellipse_get_type(),
                                                    "x1", -w / 2.0,
@@ -320,7 +323,7 @@ mini_preview_canvas_update (GnomeCanvas *canvas,
                                                    "fill_color_rgba", fill_color,
                                                    NULL);
                break;
-       case GL_TEMPLATE_STYLE_CD:
+       case GL_TEMPLATE_SHAPE_CD:
                if ( w == h ) {
                        label_item = gnome_canvas_item_new (group,
                                                            gnome_canvas_ellipse_get_type(),
@@ -334,7 +337,7 @@ mini_preview_canvas_update (GnomeCanvas *canvas,
                                                            NULL);
                } else {
                        label_item = cdbc_item (group,
-                                               w, h, template->label.cd.r1,
+                                               w, h, label_type->size.cd.r1,
                                                1, line_color, fill_color);
                }
                break;
@@ -383,12 +386,15 @@ void
 gl_wdgt_rotate_label_set_template_name (glWdgtRotateLabel *rotate_select,
                                        gchar             *name)
 {
-       glTemplate *template;
-       gdouble     raw_w, raw_h;
+       glTemplate                *template;
+       const glTemplateLabelType *label_type;
+       gdouble                    raw_w, raw_h;
+
+       template   = gl_template_from_name (name);
+       label_type = gl_template_get_first_label_type (template);
 
-       template = gl_template_from_name (name);
        rotate_select->template = template;
-       gl_template_get_label_size (template, &raw_w, &raw_h);
+       gl_template_get_label_size (label_type, &raw_w, &raw_h);
 
        gtk_widget_set_sensitive (rotate_select->rotate_check,
                                  (raw_w != raw_h));
@@ -411,10 +417,10 @@ cdbc_item (GnomeCanvasGroup *group,
           guint             line_color,
           guint             fill_color)
 {
-       GnomeCanvasPoints *points;
-       gint               i_coords, i_theta;
-       gdouble            theta1, theta2;
-       GnomeCanvasItem   *item;
+       GnomeCanvasPoints         *points;
+       gint                       i_coords, i_theta;
+       gdouble                    theta1, theta2;
+       GnomeCanvasItem           *item;
 
        theta1 = (180.0/G_PI) * acos (w / (2.0*r));
        theta2 = (180.0/G_PI) * asin (h / (2.0*r));
index eb318f21ba1fb9735751073348cdacb4d7f7fc51..fc5661cd681aeb4b9a2500815aa361e74c35e36d 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <gnome.h>
 #include "hig.h"
-#include "template.h"
+#include <libglabels/template.h>
 
 #define GL_TYPE_WDGT_ROTATE_LABEL (gl_wdgt_rotate_label_get_type ())
 #define GL_WDGT_ROTATE_LABEL(obj) \
index 1d3a206353e9f9cc970ce950593041077da85e99..26f9835b9baf1e5bb23d8c36d69e934ec78168a4 100644 (file)
@@ -31,7 +31,7 @@
 #include "label-ellipse.h"
 #include "label-image.h"
 #include "label-barcode.h"
-#include "xml.h"
+#include <libglabels/xml.h>
 
 #include "debug.h"
 
@@ -157,7 +157,7 @@ xml04_parse_media_description (xmlNodePtr node,
 
        gl_label_set_template (label, template);
 
-       gl_template_free (&template);
+       gl_template_free (template);
        g_free (template_name);
 
        gl_debug (DEBUG_XML, "END");
index 09552b5cd41b9abdc42301e1432b1496b6520302..731c866f1c763040a5c94b6074b39205780be9a9 100644 (file)
 #include "label-ellipse.h"
 #include "label-image.h"
 #include "label-barcode.h"
-#include "paper.h"
-#include "template.h"
 #include "base64.h"
 #include "xml-label.h"
 #include "xml-label-04.h"
-#include "xml-template.h"
-#include "xml.h"
+#include <libglabels/paper.h>
+#include <libglabels/template.h>
+#include <libglabels/xml-template.h>
+#include <libglabels/xml.h>
 #include "util.h"
 
 #include "debug.h"
@@ -101,11 +101,11 @@ static glTemplate    *xml191_parse_sheet          (xmlNodePtr        node);
 static void           xml191_parse_label          (xmlNodePtr        label_node,
                                                   glTemplate       *template);
 
-static void           xml191_parse_layout         (xmlNodePtr        layout_node,
-                                                  glTemplate       *template);
+static void           xml191_parse_layout         (xmlNodePtr           layout_node,
+                                                  glTemplateLabelType *label_type);
 
-static void           xml191_parse_markup         (xmlNodePtr        markup_node,
-                                                  glTemplate       *template);
+static void           xml191_parse_markup         (xmlNodePtr           markup_node,
+                                                  glTemplateLabelType *label_type);
 
 static void           xml191_parse_alias          (xmlNodePtr        alias_node,
                                                   glTemplate       *template);
@@ -153,7 +153,7 @@ gl_xml_label_191_parse (xmlNodePtr        root,
                        }
                        gl_template_register (template);
                        gl_label_set_template (label, template);
-                       gl_template_free (&template);
+                       gl_template_free (template);
                } else if (xmlStrEqual (node->name, "Objects")) {
                        xml191_parse_objects (node, label);
                } else if (xmlStrEqual (node->name, "Merge_Fields")) {
@@ -657,24 +657,21 @@ xml191_parse_pixdata (xmlNodePtr  node,
 static glTemplate *
 xml191_parse_sheet (xmlNodePtr sheet_node)
 {
+       gchar                 *name, *description, *page_size;
+       gdouble                page_width, page_height;
        glTemplate            *template;
        xmlNodePtr             node;
-       gchar                 *description;
        glPaper               *paper;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
-       template = g_new0 (glTemplate, 1);
-
-       template->name  = xmlGetProp (sheet_node, "name");
-       template->alias = g_list_append (template->alias, g_strdup (template->name));
-       gl_debug (DEBUG_TEMPLATE, "Sheet = %s", template->name);
+       name  = xmlGetProp (sheet_node, "name");
 
-       template->page_size = xmlGetProp (sheet_node, "size");
-       if (xmlStrEqual (template->page_size, "Other")) {
+       page_size = xmlGetProp (sheet_node, "size");
+       if (gl_paper_is_id_other (page_size)) {
 
-               template->page_width = gl_xml_get_prop_length (sheet_node, "width", 0);
-               template->page_height = gl_xml_get_prop_length (sheet_node, "height", 0);
+               page_width = gl_xml_get_prop_length (sheet_node, "width", 0);
+               page_height = gl_xml_get_prop_length (sheet_node, "height", 0);
 
        } else {
                paper = gl_paper_from_id (template->page_size);
@@ -688,13 +685,13 @@ xml191_parse_sheet (xmlNodePtr sheet_node)
                        template->page_size = g_strdup (paper->id);
                }
                if (paper != NULL) {
-                       template->page_width  = paper->width;
-                       template->page_height = paper->height;
+                       page_width  = paper->width;
+                       page_height = paper->height;
                } else {
                        g_warning (_("Unknown page size id or name \"%s\""),
-                                  template->page_size);
+                                  page_size);
                }
-               gl_paper_free (&paper);
+               gl_paper_free (paper);
        }
 
        description = xmlGetProp (sheet_node, "_description");
@@ -704,6 +701,9 @@ xml191_parse_sheet (xmlNodePtr sheet_node)
                template->description = xmlGetProp (sheet_node, "description");
        }
 
+       template = gl_template_new (name, description,
+                                   page_size, page_width, page_height);
+
        for (node = sheet_node->xmlChildrenNode; node != NULL;
             node = node->next) {
                if (xmlStrEqual (node->name, "Label")) {
@@ -717,6 +717,10 @@ xml191_parse_sheet (xmlNodePtr sheet_node)
                }
        }
 
+       g_free (name);
+       g_free (description);
+       g_free (page_size);
+
        gl_debug (DEBUG_TEMPLATE, "END");
 
        return template;
@@ -729,41 +733,50 @@ static void
 xml191_parse_label (xmlNodePtr  label_node,
                    glTemplate *template)
 {
-       xmlNodePtr  node;
-       gchar      *style;
+       gchar                *style;
+       glTemplateLabelShape  shape;
+       gdouble               w, h, r, r1, r2;
+       glTemplateLabelType  *label_type;
+       xmlNodePtr            node;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
        style = xmlGetProp (label_node, "style");
        if (xmlStrEqual (style, "rectangle")) {
-               template->label.style = GL_TEMPLATE_STYLE_RECT;
+               shape = GL_TEMPLATE_SHAPE_RECT;
        } else if (xmlStrEqual (style, "round")) {
-               template->label.style = GL_TEMPLATE_STYLE_ROUND;
+               shape = GL_TEMPLATE_SHAPE_ROUND;
        } else if (xmlStrEqual (style, "cd")) {
-               template->label.style = GL_TEMPLATE_STYLE_CD;
+               shape = GL_TEMPLATE_SHAPE_CD;
        } else {
-               template->label.style = GL_TEMPLATE_STYLE_RECT;
+               shape = GL_TEMPLATE_SHAPE_RECT;
                g_warning ("Unknown label style in template");
        }
        g_free (style);
 
-       switch (template->label.style) {
+       switch (shape) {
 
-       case GL_TEMPLATE_STYLE_RECT:
-               template->label.rect.w = gl_xml_get_prop_length (label_node, "width", 0);
-               template->label.rect.h = gl_xml_get_prop_length (label_node, "height", 0);
-               template->label.rect.r = gl_xml_get_prop_length (label_node, "round", 0);
+       case GL_TEMPLATE_SHAPE_RECT:
+               w = gl_xml_get_prop_length (label_node, "width", 0);
+               h = gl_xml_get_prop_length (label_node, "height", 0);
+               r = gl_xml_get_prop_length (label_node, "round", 0);
+               label_type =
+                       gl_template_rect_label_type_new ("0", w, h, r, 0.0);
                break;
 
-       case GL_TEMPLATE_STYLE_ROUND:
-               template->label.round.r = gl_xml_get_prop_length (label_node, "radius", 0);
+       case GL_TEMPLATE_SHAPE_ROUND:
+               r = gl_xml_get_prop_length (label_node, "round", 0);
+               label_type =
+                       gl_template_round_label_type_new ("0", r, 0.0);
                break;
 
-       case GL_TEMPLATE_STYLE_CD:
-               template->label.cd.r1 = gl_xml_get_prop_length (label_node, "radius", 0);
-               template->label.cd.r2 = gl_xml_get_prop_length (label_node, "hole", 0);
-               template->label.cd.w  = gl_xml_get_prop_length (label_node, "width", 0);
-               template->label.cd.h  = gl_xml_get_prop_length (label_node, "height", 0);
+       case GL_TEMPLATE_SHAPE_CD:
+               r1 = gl_xml_get_prop_length (label_node, "radius", 0);
+               r2 = gl_xml_get_prop_length (label_node, "hole", 0);
+               w  = gl_xml_get_prop_length (label_node, "width", 0);
+               h  = gl_xml_get_prop_length (label_node, "height", 0);
+               label_type =
+                       gl_template_cd_label_type_new ("0", r1, r2, w, h, 0.0);
                break;
 
        default:
@@ -771,12 +784,14 @@ xml191_parse_label (xmlNodePtr  label_node,
 
        }
 
+       gl_template_add_label_type (template, label_type);
+
        for (node = label_node->xmlChildrenNode; node != NULL;
             node = node->next) {
                if (xmlStrEqual (node->name, "Layout")) {
-                       xml191_parse_layout (node, template);
+                       xml191_parse_layout (node, label_type);
                } else if (xmlStrEqual (node->name, "Markup")) {
-                       xml191_parse_markup (node, template);
+                       xml191_parse_markup (node, label_type);
                } else if (!xmlNodeIsText (node)) {
                        g_warning ("bad node =  \"%s\"", node->name);
                }
@@ -789,8 +804,8 @@ xml191_parse_label (xmlNodePtr  label_node,
 /* PRIVATE.  Parse XML Sheet->Label->Layout Node.                           */
 /*--------------------------------------------------------------------------*/
 static void
-xml191_parse_layout (xmlNodePtr  layout_node,
-                    glTemplate *template)
+xml191_parse_layout (xmlNodePtr           layout_node,
+                    glTemplateLabelType *label_type)
 {
        gint        nx, ny;
        gdouble     x0, y0, dx, dy;
@@ -814,9 +829,8 @@ xml191_parse_layout (xmlNodePtr  layout_node,
                }
        }
 
-       template->label.any.layouts =
-               g_list_append (template->label.any.layouts,
-                              gl_template_layout_new (nx, ny, x0, y0, dx, dy));
+       gl_template_add_layout (label_type,
+                               gl_template_layout_new (nx, ny, x0, y0, dx, dy));
 
        gl_debug (DEBUG_TEMPLATE, "END");
 }
@@ -826,7 +840,7 @@ xml191_parse_layout (xmlNodePtr  layout_node,
 /*--------------------------------------------------------------------------*/
 static void
 xml191_parse_markup (xmlNodePtr  markup_node,
-                    glTemplate *template)
+                    glTemplateLabelType *label_type)
 {
        gchar      *type;
        gdouble     size;
@@ -840,9 +854,8 @@ xml191_parse_markup (xmlNodePtr  markup_node,
 
                size = gl_xml_get_prop_length (markup_node, "size", 0);
 
-               template->label.any.markups =
-                       g_list_append (template->label.any.markups,
-                                      gl_template_markup_margin_new (size));
+               gl_template_add_markup (label_type,
+                                       gl_template_markup_margin_new (size));
 
        } else if (xmlStrEqual (type, "line")) {
 
@@ -851,9 +864,8 @@ xml191_parse_markup (xmlNodePtr  markup_node,
                x2 = gl_xml_get_prop_length (markup_node, "x2", 0);
                y2 = gl_xml_get_prop_length (markup_node, "y2", 0);
 
-               template->label.any.markups =
-                       g_list_append (template->label.any.markups,
-                                      gl_template_markup_line_new (x1, y1, x2, y2));
+               gl_template_add_markup (label_type,
+                                       gl_template_markup_line_new (x1, y1, x2, y2));
        }
        g_free (type);
 
@@ -874,10 +886,13 @@ static void
 xml191_parse_alias (xmlNodePtr  alias_node,
                    glTemplate *template)
 {
+       gchar       *name;
+
        gl_debug (DEBUG_TEMPLATE, "START");
 
-       template->alias = g_list_append (template->alias,
-                                       xmlGetProp (alias_node, "name"));
+       name = xmlGetProp (alias_node, "name");
+       gl_template_add_alias (template, name);
+       g_free (name);
 
        gl_debug (DEBUG_TEMPLATE, "END");
 }
index 8a97ca687f8169351a838a88ab535722be499deb..452678837bda7b4136f9742c887337b845fc6475 100644 (file)
 #include "label-ellipse.h"
 #include "label-image.h"
 #include "label-barcode.h"
-#include "template.h"
 #include "base64.h"
 #include "xml-label.h"
 #include "xml-label-04.h"
 #include "xml-label-191.h"
-#include "xml-template.h"
-#include "xml.h"
+#include <libglabels/template.h>
+#include <libglabels/xml-template.h>
+#include <libglabels/xml.h>
 #include "util.h"
 
 #include "debug.h"
@@ -252,7 +252,7 @@ xml_doc_to_label (xmlDocPtr         doc,
                return NULL;
        }
 
-       ns = xmlSearchNsByHref (doc, root, XML_NAME_SPACE);
+       ns = xmlSearchNsByHref (doc, root, GL_XML_NAME_SPACE);
        if (ns != NULL) {
                label = xml_parse_label (root, status);
        } else {
@@ -326,7 +326,7 @@ xml_parse_label (xmlNodePtr        root,
             child_node = child_node->next) {
 
                if (xmlStrEqual (child_node->name, "Template")) {
-                       template = gl_xml_template_parse_template (child_node);
+                       template = gl_xml_template_parse_template_node (child_node);
                        if (!template) {
                                g_object_unref (label);
                                *status = XML_LABEL_UNKNOWN_MEDIA;
@@ -334,7 +334,7 @@ xml_parse_label (xmlNodePtr        root,
                        }
                        gl_template_register (template);
                        gl_label_set_template (label, template);
-                       gl_template_free (&template);
+                       gl_template_free (template);
                } else if (xmlStrEqual (child_node->name, "Objects")) {
                        xml_parse_objects (child_node, label);
                } else if (xmlStrEqual (child_node->name, "Merge")) {
@@ -1017,11 +1017,11 @@ xml_label_to_doc (glLabel          *label,
        doc = xmlNewDoc ("1.0");
        doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Glabels-document", NULL);
 
-       ns = xmlNewNs (doc->xmlRootNode, XML_NAME_SPACE, NULL);
+       ns = xmlNewNs (doc->xmlRootNode, GL_XML_NAME_SPACE, NULL);
        xmlSetNs (doc->xmlRootNode, ns);
 
        template = gl_label_get_template (label);
-       gl_xml_template_add_template (template, doc->xmlRootNode, ns);
+       gl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
 
        xml_create_objects (doc->xmlRootNode, ns, label);
 
diff --git a/glabels2/src/xml-paper.c b/glabels2/src/xml-paper.c
deleted file mode 100644 (file)
index eee5db6..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml-paper.c:  paper xml module
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#include <config.h>
-
-#include <string.h>
-#include <libintl.h>
-
-#include "xml.h"
-#include "xml-paper.h"
-
-#include "debug.h"
-
-/*===========================================*/
-/* Private types                             */
-/*===========================================*/
-
-/*===========================================*/
-/* Private globals                           */
-/*===========================================*/
-
-/*===========================================*/
-/* Local function prototypes                 */
-/*===========================================*/
-
-glPaper *gl_xml_paper_parse_paper (xmlNodePtr paper_node);
-
-
-\f
-/*****************************************************************************/
-/* Read papers from paper file.                                        */
-/*****************************************************************************/
-GList *
-gl_xml_paper_read_papers_from_file (GList *papers,
-                                   gchar *xml_filename)
-{
-       xmlDocPtr   doc;
-       xmlNodePtr  root, node;
-       glPaper *paper;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       LIBXML_TEST_VERSION;
-
-       doc = xmlParseFile (xml_filename);
-       if (!doc) {
-               g_warning ("\"%s\" is not a glabels paper file (not XML)",
-                     xml_filename);
-               return papers;
-       }
-
-       root = xmlDocGetRootElement (doc);
-       if (!root || !root->name) {
-               g_warning ("\"%s\" is not a glabels paper file (no root node)",
-                     xml_filename);
-               xmlFreeDoc (doc);
-               return papers;
-       }
-       if (!xmlStrEqual (root->name, "Glabels-paper-sizes")) {
-               g_warning ("\"%s\" is not a glabels paper file (wrong root node)",
-                     xml_filename);
-               xmlFreeDoc (doc);
-               return papers;
-       }
-
-       for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
-               if (xmlStrEqual (node->name, "Paper-size")) {
-                       paper = gl_xml_paper_parse_paper (node);
-                       papers = g_list_append (papers, paper);
-               } else {
-                       if ( !xmlNodeIsText(node) ) {
-                               if (!xmlStrEqual (node->name,"comment")) {
-                                       g_warning ("bad node =  \"%s\"",node->name);
-                               }
-                       }
-               }
-       }
-
-       xmlFreeDoc (doc);
-
-       gl_debug (DEBUG_PAPER, "END");
-       return papers;
-}
-
-/*****************************************************************************/
-/* Parse XML paper Node.                                                  */
-/*****************************************************************************/
-glPaper *
-gl_xml_paper_parse_paper (xmlNodePtr paper_node)
-{
-       glPaper               *paper;
-       gchar                 *name;
-
-       gl_debug (DEBUG_PAPER, "START");
-
-       paper = g_new0 (glPaper, 1);
-
-       paper->id   = xmlGetProp (paper_node, "id");
-
-       name = xmlGetProp (paper_node, "_name");
-       if (name != NULL) {
-               paper->name = gettext (name);
-       } else {
-               paper->name = xmlGetProp (paper_node, "name");
-       }
-
-       paper->width  = gl_xml_get_prop_length (paper_node, "width", 0);
-       paper->height = gl_xml_get_prop_length (paper_node, "height", 0);
-
-       gl_debug (DEBUG_PAPER, "END");
-
-       return paper;
-}
-
diff --git a/glabels2/src/xml-paper.h b/glabels2/src/xml-paper.h
deleted file mode 100644 (file)
index 6bae508..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml-paper.h:  paper xml module header file
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#ifndef __XML_PAPER_H__
-#define __XML_PAPER_H__
-
-#include <libgnome/libgnome.h>
-
-#include "paper.h"
-
-G_BEGIN_DECLS
-
-GList       *gl_xml_paper_read_papers_from_file (GList             *papers,
-                                                gchar             *xml_filename);
-
-G_END_DECLS
-
-#endif /* __XML_PAPER_H__ */
diff --git a/glabels2/src/xml-template.c b/glabels2/src/xml-template.c
deleted file mode 100644 (file)
index c4e985f..0000000
+++ /dev/null
@@ -1,739 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml-template.c:  template xml module
- *
- *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#include <config.h>
-
-#include <string.h>
-#include <libintl.h>
-
-#include "util.h"
-#include "paper.h"
-#include "xml.h"
-#include "xml-template.h"
-
-#include "debug.h"
-
-/*===========================================*/
-/* Private types                             */
-/*===========================================*/
-
-/*===========================================*/
-/* Private globals                           */
-/*===========================================*/
-
-/*===========================================*/
-/* Local function prototypes                 */
-/*===========================================*/
-static void        xml_parse_label_rectangle    (xmlNodePtr              layout_node,
-                                                glTemplate             *template);
-static void        xml_parse_label_round        (xmlNodePtr              layout_node,
-                                                glTemplate             *template);
-static void        xml_parse_label_cd           (xmlNodePtr              layout_node,
-                                                glTemplate             *template);
-static void        xml_parse_layout             (xmlNodePtr              label_node,
-                                                glTemplate             *template);
-static void        xml_parse_markup_margin      (xmlNodePtr              markup_node,
-                                                glTemplate             *template);
-static void        xml_parse_markup_line        (xmlNodePtr              markup_node,
-                                                glTemplate             *template);
-static void        xml_parse_markup_circle      (xmlNodePtr              markup_node,
-                                                glTemplate             *template);
-static void        xml_parse_alias              (xmlNodePtr              alias_node,
-                                                glTemplate             *template);
-
-static void        xml_add_label                (const glTemplate       *template,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-static void        xml_add_layout               (glTemplateLayout       *layout,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-static void        xml_add_markup_margin        (glTemplateMarkupMargin *margin,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-static void        xml_add_markup_line          (glTemplateMarkupLine   *line,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-static void        xml_add_markup_circle        (glTemplateMarkupCircle *circle,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-static void        xml_add_alias                (gchar                  *name,
-                                                xmlNodePtr              root,
-                                                xmlNsPtr                ns);
-
-
-/*****************************************************************************/
-/* Read templates from template file.                                        */
-/*****************************************************************************/
-GList *
-gl_xml_template_read_templates_from_file (GList *templates,
-                                         gchar *xml_filename)
-{
-       xmlDocPtr   doc;
-       xmlNodePtr  root, node;
-       glTemplate *template;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       LIBXML_TEST_VERSION;
-
-       doc = xmlParseFile (xml_filename);
-       if (!doc) {
-               g_warning ("\"%s\" is not a glabels template file (not XML)",
-                     xml_filename);
-               return templates;
-       }
-
-       root = xmlDocGetRootElement (doc);
-       if (!root || !root->name) {
-               g_warning ("\"%s\" is not a glabels template file (no root node)",
-                     xml_filename);
-               xmlFreeDoc (doc);
-               return templates;
-       }
-       if (!xmlStrEqual (root->name, "Glabels-templates")) {
-               g_warning ("\"%s\" is not a glabels template file (wrong root node)",
-                     xml_filename);
-               xmlFreeDoc (doc);
-               return templates;
-       }
-
-       for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
-               if (xmlStrEqual (node->name, "Template")) {
-                       template = gl_xml_template_parse_template (node);
-                       templates = g_list_append (templates, template);
-               } else {
-                       if ( !xmlNodeIsText(node) ) {
-                               if (!xmlStrEqual (node->name,"comment")) {
-                                       g_warning ("bad node =  \"%s\"",node->name);
-                               }
-                       }
-               }
-       }
-
-       xmlFreeDoc (doc);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-       return templates;
-}
-
-/*****************************************************************************/
-/* Parse XML template Node.                                                  */
-/*****************************************************************************/
-glTemplate *
-gl_xml_template_parse_template (xmlNodePtr template_node)
-{
-       glTemplate            *template;
-       xmlNodePtr             node;
-       gchar                 *description;
-       glPaper               *paper;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template = g_new0 (glTemplate, 1);
-
-       template->name  = xmlGetProp (template_node, "name");
-       template->alias = g_list_append (template->alias, g_strdup (template->name));
-       gl_debug (DEBUG_TEMPLATE, "Template = %s", template->name);
-
-       template->page_size = xmlGetProp (template_node, "size");
-       if (xmlStrEqual (template->page_size, "Other")) {
-
-               template->page_width = gl_xml_get_prop_length (template_node, "width", 0);
-               template->page_height = gl_xml_get_prop_length (template_node, "height", 0);
-
-       } else {
-               paper = gl_paper_from_id (template->page_size);
-               if (paper == NULL) {
-                       /* This should always be an id, but just in case a name
-                          slips by! */
-                       g_warning (_("Unknown page size id \"%s\", trying as name"),
-                                  template->page_size);
-                       paper = gl_paper_from_name (template->page_size);
-                       g_free (template->page_size);
-                       template->page_size = g_strdup (paper->id);
-               }
-               if (paper != NULL) {
-                       template->page_width  = paper->width;
-                       template->page_height = paper->height;
-               } else {
-                       g_warning (_("Unknown page size id or name \"%s\""),
-                                  template->page_size);
-               }
-               gl_paper_free (&paper);
-       }
-
-       description = xmlGetProp (template_node, "_description");
-       if (description != NULL) {
-               template->description = gettext (description);
-       } else {
-               template->description = xmlGetProp (template_node, "description");
-       }
-
-       for (node = template_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (xmlStrEqual (node->name, "Label-rectangle")) {
-                       xml_parse_label_rectangle (node, template);
-               } else if (xmlStrEqual (node->name, "Label-round")) {
-                       xml_parse_label_round (node, template);
-               } else if (xmlStrEqual (node->name, "Label-cd")) {
-                       xml_parse_label_cd (node, template);
-               } else if (xmlStrEqual (node->name, "Alias")) {
-                       xml_parse_alias (node, template);
-               } else {
-                       if (!xmlNodeIsText (node)) {
-                               if (!xmlStrEqual (node->name,"comment")) {
-                                       g_warning ("bad node =  \"%s\"",node->name);
-                               }
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-
-       return template;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label-rectangle Node.                      */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_label_rectangle (xmlNodePtr  label_node,
-                          glTemplate *template)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template->label.style = GL_TEMPLATE_STYLE_RECT;
-
-       template->label.rect.w = gl_xml_get_prop_length (label_node, "width", 0);
-       template->label.rect.h = gl_xml_get_prop_length (label_node, "height", 0);
-       template->label.rect.r = gl_xml_get_prop_length (label_node, "round", 0);
-
-       template->label.rect.waste = gl_xml_get_prop_length (label_node, "waste", 0);
-
-       for (node = label_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (xmlStrEqual (node->name, "Layout")) {
-                       xml_parse_layout (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-margin")) {
-                       xml_parse_markup_margin (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-line")) {
-                       xml_parse_markup_line (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-circle")) {
-                       xml_parse_markup_circle (node, template);
-               } else if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label-round Node.                          */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_label_round (xmlNodePtr  label_node,
-                      glTemplate *template)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template->label.style = GL_TEMPLATE_STYLE_ROUND;
-
-       template->label.round.r = gl_xml_get_prop_length (label_node, "radius", 0);
-
-       template->label.round.waste = gl_xml_get_prop_length (label_node, "waste", 0);
-
-       for (node = label_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (xmlStrEqual (node->name, "Layout")) {
-                       xml_parse_layout (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-margin")) {
-                       xml_parse_markup_margin (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-line")) {
-                       xml_parse_markup_line (node, template);
-               } else if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label-cd Node.                             */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_label_cd (xmlNodePtr  label_node,
-                   glTemplate *template)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template->label.style = GL_TEMPLATE_STYLE_CD;
-
-       template->label.cd.r1 = gl_xml_get_prop_length (label_node, "radius", 0);
-       template->label.cd.r2 = gl_xml_get_prop_length (label_node, "hole", 0);
-       template->label.cd.w  = gl_xml_get_prop_length (label_node, "width", 0);
-       template->label.cd.h  = gl_xml_get_prop_length (label_node, "height", 0);
-
-       template->label.cd.waste = gl_xml_get_prop_length (label_node, "waste", 0);
-
-       for (node = label_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (xmlStrEqual (node->name, "Layout")) {
-                       xml_parse_layout (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-margin")) {
-                       xml_parse_markup_margin (node, template);
-               } else if (xmlStrEqual (node->name, "Markup-line")) {
-                       xml_parse_markup_line (node, template);
-               } else if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label->Layout Node.`                        */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_layout (xmlNodePtr  layout_node,
-                 glTemplate *template)
-{
-       gint        nx, ny;
-       gdouble     x0, y0, dx, dy;
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       nx = gl_xml_get_prop_int (layout_node, "nx", 1);
-       ny = gl_xml_get_prop_int (layout_node, "ny", 1);
-
-       x0 = gl_xml_get_prop_length (layout_node, "x0", 0);
-       y0 = gl_xml_get_prop_length (layout_node, "y0", 0);
-
-       dx = gl_xml_get_prop_length (layout_node, "dx", 0);
-       dy = gl_xml_get_prop_length (layout_node, "dy", 0);
-
-       for (node = layout_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       template->label.any.layouts =
-               g_list_append (template->label.any.layouts,
-                              gl_template_layout_new (nx, ny, x0, y0, dx, dy));
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label->Markup-margin Node.                 */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_markup_margin (xmlNodePtr  markup_node,
-                        glTemplate *template)
-{
-       gdouble     size;
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       size = gl_xml_get_prop_length (markup_node, "size", 0);
-
-       template->label.any.markups =
-               g_list_append (template->label.any.markups,
-                              gl_template_markup_margin_new (size));
-
-       for (node = markup_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label->Markup-line Node.                   */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_markup_line (xmlNodePtr  markup_node,
-                      glTemplate *template)
-{
-       gdouble     x1, y1, x2, y2;
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       x1 = gl_xml_get_prop_length (markup_node, "x1", 0);
-       y1 = gl_xml_get_prop_length (markup_node, "y1", 0);
-       x2 = gl_xml_get_prop_length (markup_node, "x2", 0);
-       y2 = gl_xml_get_prop_length (markup_node, "y2", 0);
-
-       template->label.any.markups =
-               g_list_append (template->label.any.markups,
-                              gl_template_markup_line_new (x1, y1, x2, y2));
-
-       for (node = markup_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Label->Markup-circle Node.                 */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_markup_circle (xmlNodePtr  markup_node,
-                      glTemplate *template)
-{
-       gdouble     x0, y0, r;
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       x0 = gl_xml_get_prop_length (markup_node, "x0", 0);
-       y0 = gl_xml_get_prop_length (markup_node, "y0", 0);
-       r  = gl_xml_get_prop_length (markup_node, "radius", 0);
-
-       template->label.any.markups =
-               g_list_append (template->label.any.markups,
-                              gl_template_markup_circle_new (x0, y0, r));
-
-       for (node = markup_node->xmlChildrenNode; node != NULL;
-            node = node->next) {
-               if (!xmlNodeIsText (node)) {
-                       if (!xmlStrEqual (node->name,"comment")) {
-                               g_warning ("bad node =  \"%s\"",node->name);
-                       }
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Parse XML Template->Alias Node.                                */
-/*--------------------------------------------------------------------------*/
-static void
-xml_parse_alias (xmlNodePtr  alias_node,
-                glTemplate *template)
-{
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       template->alias = g_list_append (template->alias,
-                                       xmlGetProp (alias_node, "name"));
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/****************************************************************************/
-/* Write single template to XML file.                                       */
-/****************************************************************************/
-void
-gl_xml_template_write_template_to_file (const glTemplate  *template,
-                                       const gchar       *utf8_filename)
-{
-       xmlDocPtr  doc;
-       xmlNsPtr   ns;
-       gint       xml_ret;
-       gchar     *filename;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       doc = xmlNewDoc ("1.0");
-       doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Glabels-templates", NULL);
-
-       ns = xmlNewNs (doc->xmlRootNode, XML_NAME_SPACE, NULL);
-       xmlSetNs (doc->xmlRootNode, ns);
-
-       gl_xml_template_add_template (template, doc->xmlRootNode, ns);
-
-       filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
-       if (!filename)
-               g_warning (_("Utf8 conversion error."));
-       else {
-               xmlSetDocCompressMode (doc, 0);
-               xml_ret = xmlSaveFormatFile (filename, doc, TRUE);
-               xmlFreeDoc (doc);
-               if (xml_ret == -1) {
-
-                       g_warning (_("Problem saving xml file."));
-
-               }
-               g_free (filename);
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/****************************************************************************/
-/* Add XML Template Node                                                    */
-/****************************************************************************/
-void
-gl_xml_template_add_template (const glTemplate *template,
-                             xmlNodePtr        root,
-                             xmlNsPtr          ns)
-{
-       xmlNodePtr  node;
-       GList      *p;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild (root, ns, "Template", NULL);
-
-       xmlSetProp (node, "name", template->name);
-
-       xmlSetProp (node, "size", template->page_size);
-       if (xmlStrEqual (template->page_size, "Other")) {
-
-               gl_xml_set_prop_length (node, "width", template->page_width);
-               gl_xml_set_prop_length (node, "height", template->page_height);
-
-       }
-
-       xmlSetProp (node, "description", template->description);
-
-       xml_add_label (template, node, ns);
-
-       for ( p=template->alias; p != NULL; p=p->next ) {
-               if (!xmlStrEqual (template->name, p->data)) {
-                       xml_add_alias( p->data, node, ns );
-               }
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Label Node.                                     */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_label (const glTemplate *template,
-              xmlNodePtr        root,
-              xmlNsPtr          ns)
-{
-       xmlNodePtr        node;
-       GList            *p;
-       glTemplateMarkup *markup;
-       glTemplateLayout *layout;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       switch (template->label.style) {
-
-       case GL_TEMPLATE_STYLE_RECT:
-               node = xmlNewChild(root, ns, "Label-rectangle", NULL);
-               xmlSetProp (node, "id", "0");
-               gl_xml_set_prop_length (node, "width",  template->label.rect.w);
-               gl_xml_set_prop_length (node, "height", template->label.rect.h);
-               gl_xml_set_prop_length (node, "round",  template->label.rect.r);
-               gl_xml_set_prop_length (node, "waste",  template->label.rect.waste);
-               break;
-
-       case GL_TEMPLATE_STYLE_ROUND:
-               node = xmlNewChild(root, ns, "Label-round", NULL);
-               xmlSetProp (node, "id", "0");
-               gl_xml_set_prop_length (node, "radius",  template->label.round.r);
-               gl_xml_set_prop_length (node, "waste",   template->label.round.waste);
-               break;
-
-       case GL_TEMPLATE_STYLE_CD:
-               node = xmlNewChild(root, ns, "Label-cd", NULL);
-               xmlSetProp (node, "id", "0");
-               gl_xml_set_prop_length (node, "radius",  template->label.cd.r1);
-               gl_xml_set_prop_length (node, "hole",    template->label.cd.r2);
-               if (template->label.cd.w != 0.0) {
-                       gl_xml_set_prop_length (node, "width",  template->label.cd.w);
-               }
-               if (template->label.cd.h != 0.0) {
-                       gl_xml_set_prop_length (node, "height", template->label.cd.h);
-               }
-               gl_xml_set_prop_length (node, "waste",  template->label.cd.waste);
-               break;
-
-       default:
-               g_warning ("Unknown label style");
-               return;
-               break;
-
-       }
-
-       for ( p=template->label.any.markups; p != NULL; p=p->next ) {
-               markup = (glTemplateMarkup *)p->data;
-               switch (markup->type) {
-               case GL_TEMPLATE_MARKUP_MARGIN:
-                       xml_add_markup_margin ((glTemplateMarkupMargin *)markup,
-                                              node, ns);
-                       break;
-               case GL_TEMPLATE_MARKUP_LINE:
-                       xml_add_markup_line ((glTemplateMarkupLine *)markup,
-                                            node, ns);
-                       break;
-               case GL_TEMPLATE_MARKUP_CIRCLE:
-                       xml_add_markup_circle ((glTemplateMarkupCircle *)markup,
-                                              node, ns);
-                       break;
-               default:
-                       g_warning ("Unknown markup type");
-                       break;
-               }
-       }
-
-       for ( p=template->label.any.layouts; p != NULL; p=p->next ) {
-               layout = (glTemplateLayout *)p->data;
-               xml_add_layout (layout, node, ns);
-       }
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Label->Layout Node.                             */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_layout (glTemplateLayout *layout,
-               xmlNodePtr        root,
-               xmlNsPtr          ns)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild(root, ns, "Layout", NULL);
-       gl_xml_set_prop_int (node, "nx", layout->nx);
-       gl_xml_set_prop_int (node, "ny", layout->ny);
-       gl_xml_set_prop_length (node, "x0", layout->x0);
-       gl_xml_set_prop_length (node, "y0", layout->y0);
-       gl_xml_set_prop_length (node, "dx", layout->dx);
-       gl_xml_set_prop_length (node, "dy", layout->dy);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Label->Markup-margin Node.                   */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_markup_margin (glTemplateMarkupMargin *margin,
-                      xmlNodePtr              root,
-                      xmlNsPtr                ns)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild(root, ns, "Markup-margin", NULL);
-
-       gl_xml_set_prop_length (node, "size", margin->size);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Label->Markup-line Node.                     */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_markup_line (glTemplateMarkupLine *line,
-                    xmlNodePtr            root,
-                    xmlNsPtr              ns)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild(root, ns, "Markup-line", NULL);
-
-       gl_xml_set_prop_length (node, "x1", line->x1);
-       gl_xml_set_prop_length (node, "y1", line->y1);
-       gl_xml_set_prop_length (node, "x2", line->x2);
-       gl_xml_set_prop_length (node, "y2", line->y2);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Label->Markup-circle Node.                   */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_markup_circle (glTemplateMarkupCircle *circle,
-                      xmlNodePtr            root,
-                      xmlNsPtr              ns)
-{
-       xmlNodePtr  node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild(root, ns, "Markup-circle", NULL);
-
-       gl_xml_set_prop_length (node, "x0", circle->x0);
-       gl_xml_set_prop_length (node, "y0", circle->y0);
-       gl_xml_set_prop_length (node, "radius", circle->r);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Add XML Template->Alias Node.                                     */
-/*--------------------------------------------------------------------------*/
-static void
-xml_add_alias (gchar      *name,
-              xmlNodePtr  root,
-              xmlNsPtr    ns)
-{
-       xmlNodePtr node;
-
-       gl_debug (DEBUG_TEMPLATE, "START");
-
-       node = xmlNewChild (root, ns, "Alias", NULL);
-       xmlSetProp (node, "name", name);
-
-       gl_debug (DEBUG_TEMPLATE, "END");
-}
-
diff --git a/glabels2/src/xml-template.h b/glabels2/src/xml-template.h
deleted file mode 100644 (file)
index bf4c9ca..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml-template.h:  template xml module header file
- *
- *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#ifndef __XML_TEMPLATE_H__
-#define __XML_TEMPLATE_H__
-
-#include <libgnome/libgnome.h>
-#include <libxml/tree.h>
-#include <libxml/parser.h>
-
-#include "template.h"
-
-G_BEGIN_DECLS
-
-GList       *gl_xml_template_read_templates_from_file (GList             *templates,
-                                                      gchar             *xml_filename);
-
-glTemplate  *gl_xml_template_parse_template           (xmlNodePtr         template_node);
-
-void         gl_xml_template_write_template_to_file   (const glTemplate  *template,
-                                                      const gchar       *utf8_filename);
-
-void         gl_xml_template_add_template             (const glTemplate  *template,
-                                                      xmlNodePtr         root,
-                                                      xmlNsPtr           ns);
-
-G_END_DECLS
-
-#endif /* __XML_TEMPLATE_H__ */
diff --git a/glabels2/src/xml.c b/glabels2/src/xml.c
deleted file mode 100644 (file)
index b8bcd74..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml.c:  GLabels xml utilities module
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-#include <config.h>
-
-#include "xml.h"
-
-/*========================================================*/
-/* Private macros and constants.                          */
-/*========================================================*/
-
-#define POINTS_PER_POINT    1.0 /* internal units are points. */
-#define POINTS_PER_INCH    72.0
-#define POINTS_PER_MM       2.83464566929
-#define POINTS_PER_CM       (10.0*POINTS_PER_MM)
-#define POINTS_PER_PICA     (1.0/12.0)
-
-/*========================================================*/
-/* Private types.                                         */
-/*========================================================*/
-
-typedef struct {
-       gchar  *name;
-       gdouble points_per_unit;
-} UnitTableEntry;
-
-/*========================================================*/
-/* Private globals.                                       */
-/*========================================================*/
-
-static UnitTableEntry unit_table[] = {
-
-       /* These names are identical to the absolute length units supported in
-          the CSS2 Specification (Section 4.3.2) */
-
-       {"pt",           POINTS_PER_POINT},
-       {"in",           POINTS_PER_INCH},
-       {"mm",           POINTS_PER_MM},
-       {"cm",           POINTS_PER_CM},
-       {"pc",           POINTS_PER_PICA},
-
-       {NULL, 0}
-};
-
-/*========================================================*/
-/* Private function prototypes.                           */
-/*========================================================*/
-
-\f
-/****************************************************************************/
-/* Return value of property as a double.                                    */
-/****************************************************************************/
-gdouble
-gl_xml_get_prop_double (xmlNodePtr   node,
-                       const gchar *property,
-                       gdouble      default_val)
-{
-       gdouble  val;
-       gchar   *string;
-
-       string = xmlGetProp (node, property);
-       if ( string != NULL ) {
-               val = g_strtod (string, NULL);
-               g_free (string);
-               return val;
-       }
-
-       return default_val;
-}
-
-/****************************************************************************/
-/* Return value of property as a boolean.                                   */
-/****************************************************************************/
-gboolean
-gl_xml_get_prop_boolean (xmlNodePtr   node,
-                        const gchar *property,
-                        gboolean     default_val)
-{
-       gboolean  val;
-       gchar    *string;
-
-       string = xmlGetProp (node, property);
-       if ( string != NULL ) {
-               val = !((xmlStrcasecmp (string, "false") == 0) ||
-                       xmlStrEqual (string, "0"));;
-               g_free (string);
-               return val;
-       }
-
-       return default_val;
-}
-
-
-/****************************************************************************/
-/* Return value of property as an int. .                                    */
-/****************************************************************************/
-gint
-gl_xml_get_prop_int (xmlNodePtr   node,
-                    const gchar *property,
-                    gint         default_val)
-{
-       gint     val;
-       gchar   *string;
-
-       string = xmlGetProp (node, property);
-       if ( string != NULL ) {
-               val = strtol (string, NULL, 0);
-               g_free (string);
-               return val;
-       }
-
-       return default_val;
-}
-
-
-/****************************************************************************/
-/* Return value of hex property as an unsigned int.                         */
-/****************************************************************************/
-guint
-gl_xml_get_prop_uint (xmlNodePtr   node,
-                     const gchar *property,
-                     guint        default_val)
-{
-       guint    val;
-       gchar   *string;
-
-       string = xmlGetProp (node, property);
-       if ( string != NULL ) {
-               val = strtoul (string, NULL, 0);
-               g_free (string);
-               return val;
-       }
-
-       return default_val;
-}
-
-
-/****************************************************************************/
-/* Return value of length property as a double, converting to internal units*/
-/****************************************************************************/
-gdouble
-gl_xml_get_prop_length (xmlNodePtr   node,
-                       const gchar *property,
-                       gdouble      default_val)
-{
-       gdouble  val;
-       gchar   *string, *unit;
-       gint     i;
-
-       string = xmlGetProp (node, property);
-       if ( string != NULL ) {
-
-               val = g_strtod (string, &unit);
-
-               if (unit != string) {
-                       unit = g_strchug (unit);
-                       if (strlen (unit) > 0 ) {
-                               for (i=0; unit_table[i].name != NULL; i++) {
-                                       if (xmlStrcasecmp (unit, unit_table[i].name) == 0) {
-                                               val *= unit_table[i].points_per_unit;
-                                               break;
-                                       }
-                               }
-                               if (unit_table[i].name == NULL) {
-                                       g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
-                                                  xmlGetLineNo (node), node->name, property,
-                                                  unit);
-                               }
-                       }
-               }
-               else {
-                       val = 0.0;
-               }
-
-               g_free (string);
-               return val;
-       }
-
-       return default_val;
-}
-
-/****************************************************************************/
-/* Set property from double.                                                */
-/****************************************************************************/
-void
-gl_xml_set_prop_double (xmlNodePtr    node,
-                       const gchar  *property,
-                       gdouble       val)
-{
-       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
-
-       /* Guarantee "C" locale by use of g_ascii_formatd */
-       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
-
-       xmlSetProp (node, property, string);
-}
-
-/****************************************************************************/
-/* Set property from boolean.                                               */
-/****************************************************************************/
-void
-gl_xml_set_prop_boolean (xmlNodePtr    node,
-                        const gchar  *property,
-                        gboolean      val)
-{
-       xmlSetProp (node, property, (val ? "True" : "False"));
-}
-
-/****************************************************************************/
-/* Set property from int.                                                   */
-/****************************************************************************/
-void
-gl_xml_set_prop_int (xmlNodePtr    node,
-                    const gchar  *property,
-                    gint          val)
-{
-       gchar  *string;
-
-       string = g_strdup_printf ("%d", val);
-       xmlSetProp (node, property, string);
-       g_free (string);
-}
-
-/****************************************************************************/
-/* Set property from uint in hex.                                           */
-/****************************************************************************/
-void
-gl_xml_set_prop_uint_hex (xmlNodePtr    node,
-                         const gchar  *property,
-                         guint         val)
-{
-       gchar  *string;
-
-       string = g_strdup_printf ("0x%08x", val);
-       xmlSetProp (node, property, string);
-       g_free (string);
-}
-
-/****************************************************************************/
-/* Set property from length.                                                */
-/****************************************************************************/
-void
-gl_xml_set_prop_length (xmlNodePtr    node,
-                       const gchar  *property,
-                       gdouble       val)
-{
-       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
-       gchar  *string_unit;
-
-       /* Guarantee "C" locale by use of g_ascii_formatd */
-       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
-
-       string_unit = g_strdup_printf ("%spt", string);
-       xmlSetProp (node, property, string_unit);
-        g_free (string_unit);
-}
-
diff --git a/glabels2/src/xml.h b/glabels2/src/xml.h
deleted file mode 100644 (file)
index 28d87e6..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  xml.h:  GLabels xml utilities header file
- *
- *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
- *
- *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-#ifndef __XML_H__
-#define __XML_H__
-
-#include <glib.h>
-#include <libxml/tree.h>
-
-#define XML_NAME_SPACE "http://snaught.com/glabels/2.0/"
-
-G_BEGIN_DECLS
-
-gdouble  gl_xml_get_prop_double   (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gdouble       default_val);
-
-gboolean gl_xml_get_prop_boolean  (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gboolean      default_val);
-
-gint     gl_xml_get_prop_int      (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gint          default_val);
-
-guint    gl_xml_get_prop_uint     (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  guint         default_val);
-
-gdouble  gl_xml_get_prop_length   (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gdouble       default_val);
-
-
-void     gl_xml_set_prop_double   (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gdouble       val);
-
-void     gl_xml_set_prop_boolean  (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gboolean      val);
-
-void     gl_xml_set_prop_int      (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gint          val);
-
-void     gl_xml_set_prop_uint_hex (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  guint         val);
-
-void     gl_xml_set_prop_length   (xmlNodePtr    node,
-                                  const gchar  *property,
-                                  gdouble       val);
-
-G_END_DECLS
-
-
-#endif /* __XML_H__ */