[rt #75560] don't fallback to using DynaLoader when XSLoader fails
[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 MODULE = Imager::Font::T1  PACKAGE = Imager::Font::T1
15
16 undef_int
17 i_init_t1(t1log)
18         int t1log
19
20 void
21 i_t1_set_aa(st)
22                int     st
23
24 int
25 i_t1_new(pfb,afm)
26               char*    pfb
27               char*    afm
28
29 int
30 i_t1_destroy(font_id)
31                int     font_id
32
33
34 undef_int
35 i_t1_cp(im,xb,yb,channel,fontnum,points,str_sv,len_ignored,align,utf8=0,flags="")
36     Imager::ImgRaw     im
37          i_img_dim     xb
38          i_img_dim     yb
39                int     channel
40                int     fontnum
41             double     points
42                 SV*    str_sv
43                int     align
44                int     utf8
45               char*    flags
46              PREINIT:
47                char *str;
48                STRLEN len;
49              CODE:
50 #ifdef SvUTF8
51                if (SvUTF8(str_sv))
52                  utf8 = 1;
53 #endif
54                str = SvPV(str_sv, len);
55                RETVAL = i_t1_cp(im, xb,yb,channel,fontnum,points,str,len,align,
56                                   utf8,flags);
57            OUTPUT:
58              RETVAL
59
60
61 void
62 i_t1_bbox(fontnum,point,str_sv,len_ignored,utf8=0,flags="")
63                int     fontnum
64             double     point
65                 SV*    str_sv
66                int     utf8
67               char*    flags
68              PREINIT:
69                char *str;
70                STRLEN len;
71                i_img_dim     cords[BOUNDING_BOX_COUNT];
72                int i;
73                int rc;
74              PPCODE:
75 #ifdef SvUTF8
76                if (SvUTF8(str_sv))
77                  utf8 = 1;
78 #endif
79                str = SvPV(str_sv, len);
80                rc = i_t1_bbox(fontnum,point,str,len,cords,utf8,flags);
81                if (rc > 0) {
82                  EXTEND(SP, rc);
83                  for (i = 0; i < rc; ++i)
84                    PUSHs(sv_2mortal(newSViv(cords[i])));
85                }
86
87
88
89 undef_int
90 i_t1_text(im,xb,yb,cl,fontnum,points,str_sv,len_ignored,align,utf8=0,flags="")
91     Imager::ImgRaw     im
92          i_img_dim     xb
93          i_img_dim     yb
94      Imager::Color    cl
95                int     fontnum
96             double     points
97                 SV*    str_sv
98                int     align
99                int     utf8
100               char*    flags
101              PREINIT:
102                char *str;
103                STRLEN len;
104              CODE:
105 #ifdef SvUTF8
106                if (SvUTF8(str_sv))
107                  utf8 = 1;
108 #endif
109                str = SvPV(str_sv, len);
110                RETVAL = i_t1_text(im, xb,yb,cl,fontnum,points,str,len,align,
111                                   utf8,flags);
112            OUTPUT:
113              RETVAL
114
115 void
116 i_t1_has_chars(handle, text_sv, utf8 = 0)
117         int handle
118         SV  *text_sv
119         int utf8
120       PREINIT:
121         char const *text;
122         STRLEN len;
123         char *work;
124         int count;
125         int i;
126       PPCODE:
127 #ifdef SvUTF8
128         if (SvUTF8(text_sv))
129           utf8 = 1;
130 #endif
131         text = SvPV(text_sv, len);
132         work = mymalloc(len);
133         count = i_t1_has_chars(handle, text, len, utf8, work);
134         if (GIMME_V == G_ARRAY) {
135           EXTEND(SP, count);
136           for (i = 0; i < count; ++i) {
137             PUSHs(boolSV(work[i]));
138           }
139         }
140         else {
141           EXTEND(SP, 1);
142           PUSHs(sv_2mortal(newSVpv(work, count)));
143         }
144         myfree(work);
145
146 void
147 i_t1_face_name(handle)
148         int handle
149       PREINIT:
150         char name[255];
151         int len;
152       PPCODE:
153         len = i_t1_face_name(handle, name, sizeof(name));
154         if (len) {
155           EXTEND(SP, 1);
156           PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
157         }
158
159 void
160 i_t1_glyph_name(handle, text_sv, utf8 = 0)
161         int handle
162         SV *text_sv
163         int utf8
164       PREINIT:
165         char const *text;
166         STRLEN work_len;
167         size_t len;
168         char name[255];
169       PPCODE:
170 #ifdef SvUTF8
171         if (SvUTF8(text_sv))
172           utf8 = 1;
173 #endif
174         text = SvPV(text_sv, work_len);
175         len = work_len;
176         while (len) {
177           unsigned long ch;
178           if (utf8) {
179             ch = i_utf8_advance(&text, &len);
180             if (ch == ~0UL) {
181               i_push_error(0, "invalid UTF8 character");
182               break;
183             }
184           }
185           else {
186             ch = *text++;
187             --len;
188           }
189           EXTEND(SP, 1);
190           if (i_t1_glyph_name(handle, ch, name, sizeof(name))) {
191             PUSHs(sv_2mortal(newSVpv(name, 0)));
192           }
193           else {
194             PUSHs(&PL_sv_undef);
195           } 
196         }
197
198 BOOT:
199         PERL_INITIALIZE_IMAGER_CALLBACKS;