14
14
namespace py = pybind11;
15
15
16
16
17
+
17
18
PYBIND11_MODULE (Font,m)
18
19
{
19
20
m.attr (" B_CHAR_SPACING" ) = 0 ;
@@ -236,8 +237,8 @@ py::class_<BFont>(m, "BFont")
236
237
.def (" GetBoundingBoxesAsGlyphs" , &BFont::GetBoundingBoxesAsGlyphs, " " , py::arg (" charArray" ), py::arg (" numChars" ), py::arg (" mode" ), py::arg (" boundingBoxArray" ))
237
238
.def (" GetBoundingBoxesAsString" , &BFont::GetBoundingBoxesAsString, " " , py::arg (" charArray" ), py::arg (" numChars" ), py::arg (" mode" ), py::arg (" delta" ), py::arg (" boundingBoxArray" ))
238
239
// .def("GetBoundingBoxesForStrings", &BFont::GetBoundingBoxesForStrings, "", py::arg("stringArray"), py::arg("numStrings"), py::arg("mode"), py::arg("deltas"), py::arg("boundingBoxArray"))
239
- // TODO TEST THIS, it returns empty boundingBox array DON'T WORK
240
- .def (" GetBoundingBoxesForStrings" , [](const BFont &self, const std::vector<std::string> &stringArray,
240
+ // TODO TEST THIS, it returns empty boundingBox array COMPILES BUT DON'T WORK
241
+ /* .def("GetBoundingBoxesForStrings", [](const BFont &self, const std::vector<std::string> &stringArray,
241
242
int32 numStrings, font_metric_mode mode,
242
243
std::vector<escapement_delta> &deltas,
243
244
std::vector<BRect> &boundingBoxArray) {
@@ -250,22 +251,22 @@ py::class_<BFont>(m, "BFont")
250
251
std::vector<BRect>& constBoundingBoxArray = boundingBoxArray;
251
252
252
253
self.GetBoundingBoxesForStrings(cStrings.data(), numStrings, mode, constDeltas.data(), constBoundingBoxArray.data());
253
- }," " ,py::arg (" stringArray" ),py::arg (" numStrings" ),py::arg (" mode" ),py::arg (" deltas" ),py::arg (" boundingBoxArray" ))
254
- /* .def("GetBoundingBoxesForStrings", [](const BFont &self, const std::vector<std::string> &stringArray,
255
- int32 numStrings, font_metric_mode mode,
256
- std::vector<escapement_delta> &deltas) {
257
- std::vector<BRect> boundingBoxArray;
258
- std::vector<const char*> cStrings;
259
- for (const auto &str : stringArray) {
260
- cStrings.push_back(str.c_str());
254
+ },"",py::arg("stringArray"),py::arg("numStrings"),py::arg("mode"),py::arg("deltas"),py::arg("boundingBoxArray"))*/
255
+ .def (" GetBoundingBoxesForStrings" , [](const BFont &self, const std::vector<std::string> &stringArray, font_metric_mode mode) {
256
+ std::vector<escapement_delta> deltas (stringArray.size ());
257
+ std::vector<BRect> boundingBoxArray (stringArray.size ());
258
+
259
+ // Converte i vettori Python in array C
260
+ const char ** cStringArray = new const char *[stringArray.size ()];
261
+ for (size_t i = 0 ; i < stringArray.size (); ++i) {
262
+ cStringArray[i] = stringArray[i].c_str ();
261
263
}
262
264
263
- std::vector<escapement_delta>& constDeltas = deltas;
264
- // std::vector<BRect>& constBoundingBoxArray = boundingBoxArray;
265
+ self.GetBoundingBoxesForStrings (cStringArray, stringArray.size (), mode, deltas.data (), boundingBoxArray.data ());
265
266
266
- self.GetBoundingBoxesForStrings(cStrings.data(), numStrings, mode, constDeltas.data(), boundingBoxArray.data()) ;
267
- return boundingBoxArray;
268
- },"",py::arg("stringArray"),py::arg("numStrings"),py::arg(" mode"),py::arg("deltas")) */
267
+ delete[] cStringArray ;
268
+ return std::make_tuple ( std::move (deltas), std::move ( boundingBoxArray)) ;
269
+ }," " ,py::arg (" stringArray" ),py::arg (" mode" ))
269
270
// .def("GetGlyphShapes", &BFont::GetGlyphShapes, "", py::arg("charArray"), py::arg("numChars"), py::arg("glyphShapeArray"))
270
271
.def (" GetGlyphShapes" , [](BFont& self, const std::string& charArray){
271
272
py::list glyphShapeList;
0 commit comments