(rt #127575) link to Imager::Install from Imager::Files
[imager.git] / T1 / T1.xs
CommitLineData
a556912d
TC
1#define PERL_NO_GET_CONTEXT
2#ifdef __cplusplus
3extern "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
12DEFINE_IMAGER_CALLBACKS;
13
1aaae40f
TC
14typedef i_t1_font_t Imager__Font__T1xs;
15
16#define i_t1_DESTROY(font) i_t1_destroy(font)
17
a556912d
TC
18MODULE = Imager::Font::T1 PACKAGE = Imager::Font::T1
19
20undef_int
21i_init_t1(t1log)
22 int t1log
23
1aaae40f 24MODULE = Imager::Font::T1 PACKAGE = Imager::Font::T1xs PREFIX = i_t1_
a556912d 25
1aaae40f
TC
26Imager::Font::T1xs
27i_t1_new(class,pfb,afm)
a556912d
TC
28 char* pfb
29 char* afm
1aaae40f
TC
30 C_ARGS:
31 pfb, afm
a556912d 32
1aaae40f
TC
33void
34i_t1_DESTROY(font)
35 Imager::Font::T1xs font
a556912d
TC
36
37
38undef_int
b3f71a5b 39i_t1_cp(font,im,xb,yb,channel,points,str_sv,align,utf8=0,flags="",aa=1)
1aaae40f 40 Imager::Font::T1xs font
a556912d 41 Imager::ImgRaw im
8d14daab
TC
42 i_img_dim xb
43 i_img_dim yb
a556912d 44 int channel
8d14daab 45 double points
a556912d
TC
46 SV* str_sv
47 int align
48 int utf8
49 char* flags
1aaae40f 50 int aa
a556912d
TC
51 PREINIT:
52 char *str;
53 STRLEN len;
54 CODE:
b3f71a5b 55 str = SvPV(str_sv, len);
a556912d
TC
56#ifdef SvUTF8
57 if (SvUTF8(str_sv))
58 utf8 = 1;
59#endif
1aaae40f
TC
60 RETVAL = i_t1_cp(font, im, xb,yb,channel,points,str,len,align,
61 utf8,flags,aa);
a556912d
TC
62 OUTPUT:
63 RETVAL
64
65
66void
b3f71a5b 67i_t1_bbox(fontnum,point,str_sv,utf8=0,flags="")
1aaae40f 68 Imager::Font::T1xs fontnum
8d14daab 69 double point
a556912d
TC
70 SV* str_sv
71 int utf8
72 char* flags
73 PREINIT:
b3f71a5b 74 const char *str;
a556912d 75 STRLEN len;
8d14daab 76 i_img_dim cords[BOUNDING_BOX_COUNT];
a556912d
TC
77 int i;
78 int rc;
79 PPCODE:
b3f71a5b 80 str = SvPV(str_sv, len);
a556912d
TC
81#ifdef SvUTF8
82 if (SvUTF8(str_sv))
83 utf8 = 1;
84#endif
a556912d
TC
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
94undef_int
b3f71a5b 95i_t1_text(font,im,xb,yb,cl,points,str_sv,align,utf8=0,flags="",aa=1)
1aaae40f 96 Imager::Font::T1xs font
a556912d 97 Imager::ImgRaw im
8d14daab
TC
98 i_img_dim xb
99 i_img_dim yb
a556912d 100 Imager::Color cl
8d14daab 101 double points
a556912d
TC
102 SV* str_sv
103 int align
104 int utf8
1aaae40f
TC
105 const char* flags
106 int aa
a556912d
TC
107 PREINIT:
108 char *str;
109 STRLEN len;
110 CODE:
b3f71a5b 111 str = SvPV(str_sv, len);
a556912d
TC
112#ifdef SvUTF8
113 if (SvUTF8(str_sv))
114 utf8 = 1;
115#endif
1aaae40f
TC
116 RETVAL = i_t1_text(font,im, xb,yb,cl,points,str,len,align,
117 utf8,flags,aa);
a556912d
TC
118 OUTPUT:
119 RETVAL
120
121void
1aaae40f
TC
122i_t1_has_chars(font, text_sv, utf8 = 0)
123 Imager::Font::T1xs font
a556912d
TC
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:
b3f71a5b 133 text = SvPV(text_sv, len);
a556912d
TC
134#ifdef SvUTF8
135 if (SvUTF8(text_sv))
136 utf8 = 1;
137#endif
a556912d 138 work = mymalloc(len);
1aaae40f 139 count = i_t1_has_chars(font, text, len, utf8, work);
a556912d
TC
140 if (GIMME_V == G_ARRAY) {
141 EXTEND(SP, count);
1aaae40f 142
a556912d 143 for (i = 0; i < count; ++i) {
6e938c74 144 PUSHs(boolSV(work[i]));
a556912d
TC
145 }
146 }
147 else {
148 EXTEND(SP, 1);
149 PUSHs(sv_2mortal(newSVpv(work, count)));
150 }
151 myfree(work);
152
153void
1aaae40f
TC
154i_t1_face_name(font)
155 Imager::Font::T1xs font
a556912d
TC
156 PREINIT:
157 char name[255];
158 int len;
159 PPCODE:
1aaae40f 160 len = i_t1_face_name(font, name, sizeof(name));
a556912d
TC
161 if (len) {
162 EXTEND(SP, 1);
163 PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
164 }
165
166void
b3f71a5b 167i_t1_glyph_names(font, text_sv, utf8 = 0)
1aaae40f 168 Imager::Font::T1xs font
a556912d
TC
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];
932f9afb 176 SSize_t count = 0;
a556912d 177 PPCODE:
b3f71a5b 178 text = SvPV(text_sv, work_len);
a556912d
TC
179#ifdef SvUTF8
180 if (SvUTF8(text_sv))
181 utf8 = 1;
182#endif
932f9afb 183 i_clear_error();
a556912d
TC
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");
932f9afb 191 XSRETURN(0);
a556912d
TC
192 }
193 }
194 else {
195 ch = *text++;
196 --len;
197 }
c028aa12 198 EXTEND(SP, 1);
1aaae40f 199 if (i_t1_glyph_name(font, ch, name, sizeof(name))) {
c028aa12 200 PUSHs(sv_2mortal(newSVpv(name, 0)));
a556912d
TC
201 }
202 else {
c028aa12 203 PUSHs(&PL_sv_undef);
932f9afb 204 }
a556912d
TC
205 }
206
1aaae40f
TC
207int
208i_t1_CLONE_SKIP(...)
209 CODE:
210 (void)items; /* avoid unused warning */
211 RETVAL = 1;
212 OUTPUT:
213 RETVAL
214
a556912d
TC
215BOOT:
216 PERL_INITIALIZE_IMAGER_CALLBACKS;
c028aa12 217 i_t1_start();