fix a fence post error validating a combing mode number
[imager.git] / T1 / T1.xs
1 #define PERL_NO_GET_CONTEXT
2 #ifdef __cplusplus
3 extern "C" {
4 #endif
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8 #include "imext.h"
9 #include "imperl.h"
10 #include "imt1.h"
11
12 DEFINE_IMAGER_CALLBACKS;
13
14 typedef i_t1_font_t Imager__Font__T1xs;
15
16 #define i_t1_DESTROY(font) i_t1_destroy(font)
17
18 MODULE = Imager::Font::T1  PACKAGE = Imager::Font::T1
19
20 undef_int
21 i_init_t1(t1log)
22         int t1log
23
24 MODULE = Imager::Font::T1  PACKAGE = Imager::Font::T1xs PREFIX = i_t1_
25
26 Imager::Font::T1xs
27 i_t1_new(class,pfb,afm)
28               char*    pfb
29               char*    afm
30   C_ARGS:
31     pfb, afm
32
33 void
34 i_t1_DESTROY(font)
35  Imager::Font::T1xs font        
36
37
38 undef_int
39 i_t1_cp(font,im,xb,yb,channel,points,str_sv,align,utf8=0,flags="",aa=1)
40  Imager::Font::T1xs     font
41     Imager::ImgRaw     im
42          i_img_dim     xb
43          i_img_dim     yb
44                int     channel
45             double     points
46                 SV*    str_sv
47                int     align
48                int     utf8
49               char*    flags
50                int     aa
51              PREINIT:
52                char *str;
53                STRLEN len;
54              CODE:
55                str = SvPV(str_sv, len);
56 #ifdef SvUTF8
57                if (SvUTF8(str_sv))
58                  utf8 = 1;
59 #endif
60                RETVAL = i_t1_cp(font, im, xb,yb,channel,points,str,len,align,
61                                   utf8,flags,aa);
62            OUTPUT:
63              RETVAL
64
65
66 void
67 i_t1_bbox(fontnum,point,str_sv,utf8=0,flags="")
68  Imager::Font::T1xs     fontnum
69             double     point
70                 SV*    str_sv
71                int     utf8
72               char*    flags
73              PREINIT:
74                const char *str;
75                STRLEN len;
76                i_img_dim     cords[BOUNDING_BOX_COUNT];
77                int i;
78                int rc;
79              PPCODE:
80                str = SvPV(str_sv, len);
81 #ifdef SvUTF8
82                if (SvUTF8(str_sv))
83                  utf8 = 1;
84 #endif
85                rc = i_t1_bbox(fontnum,point,str,len,cords,utf8,flags);
86                if (rc > 0) {
87                  EXTEND(SP, rc);
88                  for (i = 0; i < rc; ++i)
89                    PUSHs(sv_2mortal(newSViv(cords[i])));
90                }
91
92
93
94 undef_int
95 i_t1_text(font,im,xb,yb,cl,points,str_sv,align,utf8=0,flags="",aa=1)
96  Imager::Font::T1xs font
97     Imager::ImgRaw     im
98          i_img_dim     xb
99          i_img_dim     yb
100      Imager::Color    cl
101             double     points
102                 SV*    str_sv
103                int     align
104                int     utf8
105         const char*    flags
106                int     aa
107              PREINIT:
108                char *str;
109                STRLEN len;
110              CODE:
111                str = SvPV(str_sv, len);
112 #ifdef SvUTF8
113                if (SvUTF8(str_sv))
114                  utf8 = 1;
115 #endif
116                RETVAL = i_t1_text(font,im, xb,yb,cl,points,str,len,align,
117                                   utf8,flags,aa);
118            OUTPUT:
119              RETVAL
120
121 void
122 i_t1_has_chars(font, text_sv, utf8 = 0)
123  Imager::Font::T1xs font
124         SV  *text_sv
125         int utf8
126       PREINIT:
127         char const *text;
128         STRLEN len;
129         char *work;
130         int count;
131         int i;
132       PPCODE:
133         text = SvPV(text_sv, len);
134 #ifdef SvUTF8
135         if (SvUTF8(text_sv))
136           utf8 = 1;
137 #endif
138         work = mymalloc(len);
139         count = i_t1_has_chars(font, text, len, utf8, work);
140         if (GIMME_V == G_ARRAY) {
141           EXTEND(SP, count);
142
143           for (i = 0; i < count; ++i) {
144             PUSHs(boolSV(work[i]));
145           }
146         }
147         else {
148           EXTEND(SP, 1);
149           PUSHs(sv_2mortal(newSVpv(work, count)));
150         }
151         myfree(work);
152
153 void
154 i_t1_face_name(font)
155  Imager::Font::T1xs font
156       PREINIT:
157         char name[255];
158         int len;
159       PPCODE:
160         len = i_t1_face_name(font, name, sizeof(name));
161         if (len) {
162           EXTEND(SP, 1);
163           PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
164         }
165
166 void
167 i_t1_glyph_names(font, text_sv, utf8 = 0)
168  Imager::Font::T1xs font
169         SV *text_sv
170         int utf8
171       PREINIT:
172         char const *text;
173         STRLEN work_len;
174         size_t len;
175         char name[255];
176         SSize_t count = 0;
177       PPCODE:
178         text = SvPV(text_sv, work_len);
179 #ifdef SvUTF8
180         if (SvUTF8(text_sv))
181           utf8 = 1;
182 #endif
183         i_clear_error();
184         len = work_len;
185         while (len) {
186           unsigned long ch;
187           if (utf8) {
188             ch = i_utf8_advance(&text, &len);
189             if (ch == ~0UL) {
190               i_push_error(0, "invalid UTF8 character");
191               XSRETURN(0);
192             }
193           }
194           else {
195             ch = *text++;
196             --len;
197           }
198           EXTEND(SP, count+1);
199           if (i_t1_glyph_name(font, ch, name, sizeof(name))) {
200             ST(count) = sv_2mortal(newSVpv(name, 0));
201           }
202           else {
203             ST(count) = &PL_sv_undef;
204           }
205           ++count;
206         }
207         XSRETURN(count);
208
209 int
210 i_t1_CLONE_SKIP(...)
211     CODE:
212         (void)items; /* avoid unused warning */
213         RETVAL = 1;
214     OUTPUT:
215         RETVAL
216
217 BOOT:
218         PERL_INITIALIZE_IMAGER_CALLBACKS;
219         i_t1_start();