]> git.sur5r.net Git - glabels/blob - src/str-util.c
Imported Upstream version 3.0.0
[glabels] / src / str-util.c
1 /*
2  *  str-util.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "str-util.h"
24
25 #include <string.h>
26 #include <math.h>
27
28
29 /****************************************************************************/
30 /* Utilities to deal with PangoAlignment types.                             */
31 /****************************************************************************/
32 const gchar *
33 gl_str_util_align_to_string (PangoAlignment align)
34 {
35         switch (align) {
36         case PANGO_ALIGN_LEFT:
37                 return "Left";
38         case PANGO_ALIGN_CENTER:
39                 return "Center";
40         case PANGO_ALIGN_RIGHT:
41                 return "Right";
42         default:
43                 return "?";
44         }
45 }
46
47
48 PangoAlignment
49 gl_str_util_string_to_align (const gchar *string)
50 {
51
52         if (g_ascii_strcasecmp (string, "Left") == 0) {
53                 return PANGO_ALIGN_LEFT;
54         } else if (g_ascii_strcasecmp (string, "Center") == 0) {
55                 return PANGO_ALIGN_CENTER;
56         } else if (g_ascii_strcasecmp (string, "Right") == 0) {
57                 return PANGO_ALIGN_RIGHT;
58         } else {
59                 return PANGO_ALIGN_LEFT;
60         }
61
62 }
63
64
65 /****************************************************************************/
66 /* Utilities to deal with PangoWeight types                                 */
67 /****************************************************************************/
68 const gchar *
69 gl_str_util_weight_to_string (PangoWeight weight)
70 {
71         switch (weight) {
72         case PANGO_WEIGHT_NORMAL:
73                 return "Regular";
74         case PANGO_WEIGHT_BOLD:
75                 return "Bold";
76         default:
77                 return "?";
78         }
79 }
80
81
82 PangoWeight
83 gl_str_util_string_to_weight (const gchar *string)
84 {
85
86         if (g_ascii_strcasecmp (string, "Regular") == 0) {
87                 return PANGO_WEIGHT_NORMAL;
88         } else if (g_ascii_strcasecmp (string, "Bold") == 0) {
89                 return PANGO_WEIGHT_BOLD;
90         } else {
91                 return PANGO_WEIGHT_NORMAL;
92         }
93
94 }
95
96
97
98 /*
99  * Local Variables:       -- emacs
100  * mode: C                -- emacs
101  * c-basic-offset: 8      -- emacs
102  * tab-width: 8           -- emacs
103  * indent-tabs-mode: nil  -- emacs
104  * End:                   -- emacs
105  */