View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0017156 | Scribus | Scripter | public | 2024-02-08 11:19 | 2024-02-08 21:38 |
| Reporter | ale | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | N/A |
| Status | new | Resolution | open | ||
| Product Version | 1.7.0.svn | ||||
| Summary | 0017156: setting the text formatting for text in table cells | ||||
| Description | - it should be possible to select text inside of table cells - it should be possible to apply text formatting to the text inside of the table cells - modify the cell's text | ||||
| Tags | No tags attached. | ||||
| Patch | No | ||||
|
|
Here is a patch to enable setTextColor() on the current text selection in a table cell. The patch adds GetUniqueItemAsText(), that is like (and calls) GetUniqueItem() but returns nullptr if the PageItem cannot be used for text operations. Please review this approach. If it's a good idea, using GetUniqueItemAsText() (and replacing / simplifying the check for the matching item type) should allow to select text inside of the active cell and apply formatting to it. p.s.: the patch does not consider the case where a table is get by name but is not currently selected and has no active cell. i will add it later. set-table-cell-text-color.diff (3,031 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp
index f09c93848..a2dab83ff 100644
--- a/scribus/plugins/scriptplugin/cmdtext.cpp
+++ b/scribus/plugins/scriptplugin/cmdtext.cpp
@@ -17,7 +17,6 @@ for which a new license (GPL+exception) is in place.
#include "selection.h"
#include "util.h"
-
template<typename T>
class ApplyCharstyleHelper
{
@@ -1149,18 +1148,58 @@ PyObject *scribus_settextfill(PyObject* /* self */, PyObject* args)
return nullptr;
if (!checkHaveDocument())
return nullptr;
- PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ PageItem *item = GetUniqueItemAsText(QString::fromUtf8(Name));
if (item == nullptr)
- return nullptr;
- if (!item->isTextFrame() && !item->isPathText())
{
- PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error").toLocal8Bit().constData());
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only set text color on an item that behaves as a text frame.","python error").toLocal8Bit().constData());
return nullptr;
}
ApplyCharstyleHelper<QString>(item, QString::fromUtf8(Color)).apply(&CharStyle::setFillColor, 0, item->itemText.length());
Py_RETURN_NONE;
}
PyObject *scribus_settextstroke(PyObject* /* self */, PyObject* args)
{
char *Name = const_cast<char*>("");
diff --git a/scribus/plugins/scriptplugin/cmdutil.cpp b/scribus/plugins/scriptplugin/cmdutil.cpp
index bbb26392d..6a1ddb643 100644
--- a/scribus/plugins/scriptplugin/cmdutil.cpp
+++ b/scribus/plugins/scriptplugin/cmdutil.cpp
@@ -6,6 +6,7 @@ for which a new license (GPL+exception) is in place.
*/
#include "cmdutil.h"
+#include "pageitem_table.h"
#include "prefsmanager.h"
#include "resourcecollection.h"
#include "scpage.h"
@@ -109,6 +110,26 @@ PageItem* GetUniqueItem(const QString& name)
return getPageItemByName(name);
}
+PageItem* GetUniqueItemAsText(const QString& name)
+{
+ PageItem * item = GetUniqueItem(name);
+
+ if (item == nullptr)
+ return nullptr;
+
+ if (!item->isTextFrame() && !item->isPathText() && !item->isTable())
+ return nullptr;
+
+ if (item->isTable())
+ {
+ auto tableItem = item->asTable();
+ const auto& cell = tableItem->activeCell();
+ item = static_cast<PageItem *>(cell.textFrame());
+ }
+
+ return item;
+}
+
PageItem* getPageItemByName(const QString& name)
{
if (name.length() == 0)
diff --git a/scribus/plugins/scriptplugin/cmdutil.h b/scribus/plugins/scriptplugin/cmdutil.h
index fc2f3f2cd..642fc3699 100644
--- a/scribus/plugins/scriptplugin/cmdutil.h
+++ b/scribus/plugins/scriptplugin/cmdutil.h
@@ -43,6 +43,13 @@ void ReplaceColor(const QString& col, const QString& rep);
*/
PageItem* GetUniqueItem(const QString& name);
+/*!
+ * @brief Returns PageItem if GetUniqueItem returns a PageItem that can be used as a TextFrame.
+ *
+ * @author 2024-02-08 ale rimoldi
+ */
+PageItem* GetUniqueItemAsText(const QString& name);
+
/*!
* @brief Returns named PageItem, or exception and NULL if not found.
*
|
|
|
@jghali / @mrb what do you think about creating the GetUniqueItemAsText() function that returns nullptr if the item cannot be used as a text frame? i'd like to prepare a patch that i can give to zinal (and let them help out for patching all formatting function to get support for tables) |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2024-02-08 11:19 | ale | New Issue | |
| 2024-02-08 11:23 | ale | Note Added: 0050972 | |
| 2024-02-08 11:23 | ale | File Added: set-table-cell-text-color.diff | |
| 2024-02-08 13:58 | ale | Description Updated | |
| 2024-02-08 14:49 | ale | Note Edited: 0050972 | |
| 2024-02-08 14:49 | ale | Note Edited: 0050972 | |
| 2024-02-08 21:38 | ale | Note Added: 0050973 |