8000 Merge pull request #28603 from anntzer/ttconv-optional · matplotlib/matplotlib@e6f2b0c · GitHub
[go: up one dir, main page]

Skip to content

Commit e6f2b0c

Browse files
authored
Merge pull request #28603 from anntzer/ttconv-optional
Simplify ttconv python<->C++ conversion using std::optional.
2 parents 0eb624d + 32e9fba commit e6f2b0c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/_ttconv.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
#include <pybind11/pybind11.h>
10+
#include <pybind11/stl.h>
1011
#include "pprdrv.h"
11-
#include <vector>
1212

1313
namespace py = pybind11;
1414
using namespace pybind11::literals;
@@ -40,25 +40,20 @@ static void convert_ttf_to_ps(
4040
const char *filename,
4141
py::object &output,
4242
int fonttype,
43-
py::iterable* glyph_ids)
43+
std::optional<std::vector<int>> glyph_ids_or_none)
4444
{
4545
PythonFileWriter output_(output);
4646

47-
std::vector<int> glyph_ids_;
48-
if (glyph_ids) {
49-
for (py::handle glyph_id: *glyph_ids) {
50-
glyph_ids_.push_back(glyph_id.cast<int>());
51-
}
52-
}
53-
5447
if (fonttype != 3 && fonttype != 42) {
5548
throw py::value_error(
5649
"fonttype must be either 3 (raw Postscript) or 42 (embedded Truetype)");
5750
}
5851

52+
auto glyph_ids = glyph_ids_or_none.value_or(std::vector<int>{});
53+
5954
try
6055
{
61-
insert_ttfont(filename, output_, static_cast<font_type_enum>(fonttype), glyph_ids_);
56+
insert_ttfont(filename, output_, static_cast<font_type_enum>(fonttype), glyph_ids);
6257
}
6358
catch (TTException &e)
6459
{

0 commit comments

Comments
 (0)
0