]> git.sur5r.net Git - glabels/blob - libglabels/paper.c
Imported Upstream version 2.2.8
[glabels] / libglabels / paper.c
1 /*
2  *  (LIBGLABELS) Template library for GLABELS
3  *
4  *  paper.c:  paper module
5  *
6  *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
7  *
8  *  This file is part of the LIBGLABELS library.
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Library General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2 of the License, or (at your option) any later version.
14  *
15  *  This library is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  Library General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Library General Public
21  *  License along with this library; if not, write to the Free
22  *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23  *  MA 02111-1307, USA
24  */
25 #include <config.h>
26
27 #include "paper.h"
28
29 #include <glib/gi18n.h>
30 #include <glib/gmem.h>
31 #include <glib/gstrfuncs.h>
32 #include <glib/gmessages.h>
33 #include <string.h>
34
35 #include "libglabels-private.h"
36
37 /*===========================================*/
38 /* Private types                             */
39 /*===========================================*/
40
41
42 /*===========================================*/
43 /* Private globals                           */
44 /*===========================================*/
45
46
47 /*===========================================*/
48 /* Local function prototypes                 */
49 /*===========================================*/
50
51
52 /*===========================================*/
53 /* Functions.                                */
54 /*===========================================*/
55
56 /**
57  * lgl_paper_new:
58  * @id:       Id of paper definition. (E.g. US-Letter, A4, etc.)  Should be
59  *            unique.
60  * @name:     Localized name of paper.
61  * @width:    Width of paper in points.
62  * @height:   Height of paper in points.
63  * @pwg_size: PWG 5101.1-2002 size name.
64  *
65  * Allocates and constructs a new #lglPaper structure.
66  *
67  * Returns: a pointer to a newly allocated #lglPaper structure.
68  *
69  */
70 lglPaper *
71 lgl_paper_new (gchar             *id,
72                gchar             *name,
73                gdouble            width,
74                gdouble            height,
75                gchar             *pwg_size)
76 {
77         lglPaper *paper;
78
79         paper           = g_new0 (lglPaper,1);
80
81         paper->id       = g_strdup (id);
82         paper->name     = g_strdup (name);
83         paper->width    = width;
84         paper->height   = height;
85         paper->pwg_size = g_strdup (pwg_size);
86
87         return paper;
88 }
89
90
91 /**
92  * lgl_paper_dup:
93  * @orig:  #lglPaper structure to be duplicated.
94  *
95  * Duplicates an existing #lglPaper structure.
96  *
97  * Returns: a pointer to a newly allocated #lglPaper structure.
98  *
99  */
100 lglPaper *lgl_paper_dup (const lglPaper *orig)
101 {
102         lglPaper       *paper;
103
104         g_return_val_if_fail (orig, NULL);
105
106         paper = g_new0 (lglPaper,1);
107
108         paper->id       = g_strdup (orig->id);
109         paper->name     = g_strdup (orig->name);
110         paper->width    = orig->width;
111         paper->height   = orig->height;
112         paper->pwg_size = g_strdup (orig->pwg_size);
113
114         return paper;
115 }
116
117
118 /**
119  * lgl_paper_free:
120  * @paper:  pointer to #lglPaper structure to be freed.
121  *
122  * Free all memory associated with an existing #lglPaper structure.
123  *
124  */
125 void lgl_paper_free (lglPaper *paper)
126 {
127
128         if ( paper != NULL ) {
129
130                 g_free (paper->id);
131                 paper->id = NULL;
132
133                 g_free (paper->name);
134                 paper->name = NULL;
135
136                 g_free (paper->pwg_size);
137                 paper->pwg_size = NULL;
138
139                 g_free (paper);
140         }
141
142 }
143
144