1414namespace py = pybind11;
1515
1616
17+
1718PYBIND11_MODULE (Font,m)
1819{
1920m.attr (" B_CHAR_SPACING" ) = 0 ;
@@ -236,8 +237,8 @@ py::class_<BFont>(m, "BFont")
236237.def (" GetBoundingBoxesAsGlyphs" , &BFont::GetBoundingBoxesAsGlyphs, " " , py::arg (" charArray" ), py::arg (" numChars" ), py::arg (" mode" ), py::arg (" boundingBoxArray" ))
237238.def (" GetBoundingBoxesAsString" , &BFont::GetBoundingBoxesAsString, " " , py::arg (" charArray" ), py::arg (" numChars" ), py::arg (" mode" ), py::arg (" delta" ), py::arg (" boundingBoxArray" ))
238239// .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,
241242 int32 numStrings, font_metric_mode mode,
242243 std::vector<escapement_delta> &deltas,
243244 std::vector<BRect> &boundingBoxArray) {
@@ -250,22 +251,22 @@ py::class_<BFont>(m, "BFont")
250251 std::vector<BRect>& constBoundingBoxArray = boundingBoxArray;
251252
252253 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 ();
261263 }
262264
263- std::vector<escapement_delta>& constDeltas = deltas;
264- // std::vector<BRect>& constBoundingBoxArray = boundingBoxArray;
265+ self.GetBoundingBoxesForStrings (cStringArray, stringArray.size (), mode, deltas.data (), boundingBoxArray.data ());
265266
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" ))
269270// .def("GetGlyphShapes", &BFont::GetGlyphShapes, "", py::arg("charArray"), py::arg("numChars"), py::arg("glyphShapeArray"))
270271.def (" GetGlyphShapes" , [](BFont& self, const std::string& charArray){
271272 py::list glyphShapeList;
0 commit comments