8000 Simplify ttconv python<->C++ conversion using std::optional. by anntzer · Pull Request #28603 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Simplify ttconv python<->C++ conversion using std::optional. #28603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/_ttconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "pprdrv.h"
#include <vector>

namespace py = pybind11;
using namespace pybind11::literals;
Expand Down Expand Up @@ -40,25 +40,20 @@ static void convert_ttf_to_ps(
const char *filename,
py::object &output,
int fonttype,
py::iterable* glyph_ids)
std::optional<std::vector<int>> glyph_ids_or_none)
{
PythonFileWriter output_(output);

std::vector<int> glyph_ids_;
if (glyph_ids) {
for (py::handle glyph_id: *glyph_ids) {
glyph_ids_.push_back(glyph_id.cast<int>());
}
}

if (fonttype != 3 && fonttype != 42) {
throw py::value_error(
"fonttype must be either 3 (raw Postscript) or 42 (embedded Truetype)");
}

auto glyph_ids = glyph_ids_or_none.value_or(std::vector<int>{});

try
{
insert_ttfont(filename, output_, static_cast<font_type_enum>(fonttype), glyph_ids_);
insert_ttfont(filename, output_, static_cast<font_type_enum>(fonttype), glyph_ids);
}
catch (TTException &e)
{
Expand Down
Loading
0