]> git.sur5r.net Git - glabels/blob - src/str-util.c
Imported Upstream version 3.2.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 #include "label-object.h"
29
30
31 /****************************************************************************/
32 /* Utilities to deal with PangoAlignment types.                             */
33 /****************************************************************************/
34 const gchar *
35 gl_str_util_align_to_string (PangoAlignment align)
36 {
37         switch (align) {
38         case PANGO_ALIGN_LEFT:
39                 return "Left";
40         case PANGO_ALIGN_CENTER:
41                 return "Center";
42         case PANGO_ALIGN_RIGHT:
43                 return "Right";
44         default:
45                 return "?";
46         }
47 }
48
49
50 PangoAlignment
51 gl_str_util_string_to_align (const gchar *string)
52 {
53
54         if (g_ascii_strcasecmp (string, "Left") == 0) {
55                 return PANGO_ALIGN_LEFT;
56         } else if (g_ascii_strcasecmp (string, "Center") == 0) {
57                 return PANGO_ALIGN_CENTER;
58         } else if (g_ascii_strcasecmp (string, "Right") == 0) {
59                 return PANGO_ALIGN_RIGHT;
60         } else {
61                 return PANGO_ALIGN_LEFT;
62         }
63
64 }
65
66
67 /****************************************************************************/
68 /* Utilities to deal with vertical alignment types.                         */
69 /****************************************************************************/
70 const gchar *
71 gl_str_util_valign_to_string (glValignment valign)
72 {
73         switch (valign) {
74         case GL_VALIGN_TOP:
75                 return "Top";
76         case GL_VALIGN_VCENTER:
77                 return "Center";
78         case GL_VALIGN_BOTTOM:
79                 return "Bottom";
80         default:
81                 return "?";
82         }
83 }
84
85
86 glValignment
87 gl_str_util_string_to_valign (const gchar *string)
88 {
89
90         if (g_ascii_strcasecmp (string, "Top") == 0) {
91                 return GL_VALIGN_TOP;
92         } else if (g_ascii_strcasecmp (string, "Center") == 0) {
93                 return GL_VALIGN_VCENTER;
94         } else if (g_ascii_strcasecmp (string, "Bottom") == 0) {
95                 return GL_VALIGN_BOTTOM;
96         } else {
97                 return GL_VALIGN_TOP;
98         }
99
100 }
101
102
103 /****************************************************************************/
104 /* Utilities to deal with PangoWeight types                                 */
105 /****************************************************************************/
106 const gchar *
107 gl_str_util_weight_to_string (PangoWeight weight)
108 {
109         switch (weight) {
110         case PANGO_WEIGHT_NORMAL:
111                 return "Regular";
112         case PANGO_WEIGHT_BOLD:
113                 return "Bold";
114         default:
115                 return "?";
116         }
117 }
118
119
120 PangoWeight
121 gl_str_util_string_to_weight (const gchar *string)
122 {
123
124         if (g_ascii_strcasecmp (string, "Regular") == 0) {
125                 return PANGO_WEIGHT_NORMAL;
126         } else if (g_ascii_strcasecmp (string, "Bold") == 0) {
127                 return PANGO_WEIGHT_BOLD;
128         } else {
129                 return PANGO_WEIGHT_NORMAL;
130         }
131
132 }
133
134
135
136 /*
137  * Local Variables:       -- emacs
138  * mode: C                -- emacs
139  * c-basic-offset: 8      -- emacs
140  * tab-width: 8           -- emacs
141  * indent-tabs-mode: nil  -- emacs
142  * End:                   -- emacs
143  */