[TD]add label translation for Page and Template

This commit is contained in:
wandererfan
2023-08-17 17:26:08 -04:00
committed by WandererFan
parent 414e06d54d
commit 49a9442d61
14 changed files with 152 additions and 21 deletions

View File

@@ -121,6 +121,49 @@ PyObject* DrawPagePy::requestPaint(PyObject* args)
Py_Return;
}
//! replace the current Label with a translated version
PyObject* DrawPagePy::translateLabel(PyObject *args)
{
PyObject* pyContext;
PyObject* pyBaseName;
PyObject* pyUniqueName;
std::string context;
std::string baseName;
std::string uniqueName;
if (!PyArg_ParseTuple(args, "OOO", &pyContext, &pyBaseName, &pyUniqueName)) {
throw Py::TypeError("Could not translate label - bad parameters.");
}
Py_ssize_t size = 0;
const char* cContext = PyUnicode_AsUTF8AndSize(pyContext, &size);
if (cContext) {
context = std::string(cContext, size);
} else {
throw Py::TypeError("Could not translate label - context not available.");
}
const char* cBaseName = PyUnicode_AsUTF8AndSize(pyBaseName, &size);
if (cBaseName) {
baseName = std::string(cBaseName, size);
} else {
throw Py::TypeError("Could not translate label - base name not available.");
}
const char* cUniqueName = PyUnicode_AsUTF8AndSize(pyUniqueName, &size);
if (cUniqueName) {
uniqueName = std::string(cUniqueName, size);
} else {
throw Py::TypeError("Could not translate label - unique name not available.");
}
// we have the 3 parameters we need for DrawPage::translateLabel
DrawPage* page = getDrawPagePtr();
page->translateLabel(context, baseName, uniqueName);
Py_Return;
}
Py::Float DrawPagePy::getPageWidth() const
{
return Py::Float(getDrawPagePtr()->getPageWidth());