scripter-image-resolution.diff (8,325 bytes)
From e88ef59811d5f154dbb1435469c2a6807599c2d3 Mon Sep 17 00:00:00 2001
From: ale rimoldi <ale@graphicslab.org>
Date: Sat, 28 Jun 2025 14:30:10 +0200
Subject: scripter's setImagePreviewResolution and getImagePreviewResolution
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.cpp b/scribus/plugins/scriptplugin/cmdgetprop.cpp
index 83d04b121..1be121241 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.cpp
+++ b/scribus/plugins/scriptplugin/cmdgetprop.cpp
@@ -345,6 +345,27 @@ PyObject *scribus_getimagepagecount(PyObject* /* self */, PyObject* args)
return PyLong_FromLong(static_cast<long>(item->pixm.imgInfo.numberOfPages));
}
+PyObject *scribus_getimagepreviewresolution(PyObject* /* self */, PyObject* args)
+{
+ if (!checkHaveDocument())
+ return nullptr;
+
+ char *name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+ return nullptr;
+
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == nullptr)
+ return nullptr;
+ if (!item->isImageFrame())
+ {
+ PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ return PyLong_FromLong(static_cast<long>(item->pixm.imgInfo.lowResType));
+}
+
PyObject *scribus_getimagescale(PyObject* /* self */, PyObject* args)
{
PyESString name;
@@ -608,6 +629,7 @@ void cmdgetpropdocwarnings()
<< scribus_getimageoffset__doc__
<< scribus_getimagepage__doc__
<< scribus_getimagepagecount__doc__
+ << scribus_getimagepreviewresolution__doc__
<< scribus_getimagescale__doc__
<< scribus_getlinecolor__doc__
<< scribus_getlineblendmode__doc__
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.h b/scribus/plugins/scriptplugin/cmdgetprop.h
index 028bc576a..428d0a1eb 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.h
+++ b/scribus/plugins/scriptplugin/cmdgetprop.h
@@ -251,6 +251,22 @@ If \"name\" is not given the currently selected item is used.\n\
/*! Returns the number of pages of the object */
PyObject *scribus_getimagepagecount(PyObject * /*self*/, PyObject* args);
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagepreviewresolution__doc__,
+QT_TR_NOOP("getImagePreviewResolution([\"name\"]) -> integer (Scribus resolution constant)\n\
+\n\
+Gets preview resolution of the picture in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+The returned value is one of:\n\
+- IMAGE_PREVIEW_RESOLUTION_FULL,\n\
+- IMAGE_PREVIEW_RESOLUTION_NORMAL,\n\
+- IMAGE_PREVIEW_RESOLUTION_LOW,\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame.\n\
+"));
+/*! Scale Image. */
+PyObject *scribus_getimagepreviewresolution(PyObject * /*self*/, PyObject* args);
+
/*! docstring */
PyDoc_STRVAR(scribus_getimagescale__doc__,
QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index 52895b0bd..58275704e 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -112,6 +112,38 @@ PyObject *scribus_setimagepage(PyObject* /* self */, PyObject* args)
Py_RETURN_NONE;
}
+PyObject *scribus_setimagepreviewresolution(PyObject* /* self */, PyObject* args)
+{
+ if (!checkHaveDocument())
+ return nullptr;
+
+ char *name = const_cast<char*>("");
+ int resolutionType;
+ if (!PyArg_ParseTuple(args, "i|es", &resolutionType, "utf-8", &name))
+ return nullptr;
+
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == nullptr)
+ return nullptr;
+ if (!item->isImageFrame())
+ {
+ PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ if (resolutionType < 0 || resolutionType > 2)
+ {
+ PyErr_SetString(ScribusException, QObject::tr("The resolution shall be one of: IMAGE_PREVIEW_RESOLUTION_FULL, IMAGE_PREVIEW_RESOLUTION_NORMAL, IMAGE_PREVIEW_RESOLUTION_LOW. %1 is an invalid value.", "python error").arg(resolutionType).toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ item->pixm.imgInfo.lowResType = resolutionType;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ currentDoc->updatePic();
+
+ Py_RETURN_NONE;
+}
+
PyObject *scribus_setimagescale(PyObject* /* self */, PyObject* args)
{
PyESString name;
@@ -826,6 +858,7 @@ void cmdmanidocwarnings()
<< scribus_setimagegrayscale__doc__
<< scribus_setimageoffset__doc__
<< scribus_setimagepage__doc__
+ << scribus_setimagepreviewresolution__doc__
<< scribus_setimagescale__doc__
<< scribus_setnormalmode__doc__
<< scribus_setrotation__doc__
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index a15df7dd8..270ef7158 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -234,6 +234,22 @@ May raise WrongFrameTypeError if the target frame is not an image frame\n\
"));
PyObject *scribus_setimagepage(PyObject * /*self*/, PyObject* args);
+/*! docstring */
+PyDoc_STRVAR(scribus_setimagepreviewresolution__doc__,
+QT_TR_NOOP("setImagePreviewResolution(resolutionType, [, \"name\"])\n\
+\n\
+Sets preview resolution of the picture in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+The resolutionType shall be one of:\n\
+- IMAGE_PREVIEW_RESOLUTION_FULL,\n\
+- IMAGE_PREVIEW_RESOLUTION_NORMAL,\n\
+- IMAGE_PREVIEW_RESOLUTION_LOW,\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+/*! Scale Image. */
+PyObject *scribus_setimagepreviewresolution(PyObject * /*self*/, PyObject* args);
+
/*! docstring */
PyDoc_STRVAR(scribus_setimagescale__doc__,
QT_TR_NOOP("setImageScale(x, y [, \"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 3eaf7f337..20f2b34cb 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -378,6 +378,7 @@ PyMethodDef scribus_methods[] = {
{ "getImageFile", scribus_getimagefile, METH_VARARGS, tr(scribus_getimagefile__doc__)},
{ "getImageOffset", scribus_getimageoffset, METH_VARARGS, tr(scribus_getimageoffset__doc__)},
{ "getImagePage", scribus_getimagepage, METH_VARARGS, tr(scribus_getimagepage__doc__)},
+ { "getImagePreviewResolution", scribus_getimagepreviewresolution, METH_VARARGS, tr(scribus_getimagepreviewresolution__doc__)},
{ "getImagePageCount", scribus_getimagepagecount, METH_VARARGS, tr(scribus_getimagepagecount__doc__)},
{ "getImageScale", scribus_getimagescale, METH_VARARGS, tr(scribus_getimagescale__doc__)},
{ "getInfo", (PyCFunction) scribus_getinfo, METH_VARARGS, tr(scribus_getinfo__doc__)},
@@ -559,6 +560,7 @@ PyMethodDef scribus_methods[] = {
{ "setImageGrayscale", scribus_setimagegrayscale, METH_VARARGS, tr(scribus_setimagegrayscale__doc__)},
{ "setImageOffset", scribus_setimageoffset, METH_VARARGS, tr(scribus_setimageoffset__doc__)},
{ "setImagePage", scribus_setimagepage, METH_VARARGS, tr(scribus_setimagepage__doc__)},
+ { "setImagePreviewResolution", scribus_setimagepreviewresolution, METH_VARARGS, tr(scribus_setimagepreviewresolution__doc__)},
{ "setImageScale", scribus_setimagescale, METH_VARARGS, tr(scribus_setimagescale__doc__)},
{ "setInfo", scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)},
{ "setItemName", scribus_setitemname, METH_VARARGS, tr(scribus_setitemname__doc__)},
@@ -951,6 +953,10 @@ PyObject* PyInit_scribus(void)
PyDict_SetItemString(d, "BASEPOINT_BOTTOMLEFT", Py_BuildValue("i", (int) AnchorPoint::BottomLeft));
PyDict_SetItemString(d, "BASEPOINT_BOTTOM", Py_BuildValue("i", (int) AnchorPoint::Bottom));
PyDict_SetItemString(d, "BASEPOINT_BOTTOMRIGHT", Py_BuildValue("i", (int) AnchorPoint::BottomRight));
+ // Image frames
+ PyDict_SetItemString(d, "IMAGE_PREVIEW_RESOLUTION_FULL", Py_BuildValue("i", 0));
+ PyDict_SetItemString(d, "IMAGE_PREVIEW_RESOLUTION_NORMAL", Py_BuildValue("i", 1));
+ PyDict_SetItemString(d, "IMAGE_PREVIEW_RESOLUTION_LOW", Py_BuildValue("i", 2));
// Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
// factors to be used from Python.