r23069 by jghali - #15732: setFontSize() changes only 1 character
scribus-commit
scribus-commit at lists.scribus.net
Thu Jul 4 22:04:47 UTC 2019
Author: jghali
Date: Thu Jul 4 22:04:47 2019
New Revision: 23069
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23069
Log:
#15732: setFontSize() changes only 1 character
Modified:
branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
branches/Version14x/Scribus/scribus/scribusdoc.cpp
Modified: branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23069&path=/branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp Thu Jul 4 22:04:47 2019
@@ -20,23 +20,23 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font size of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- if (it->HasSel)
- {
- for (int b = 0; b < it->itemText.length(); b++)
- if (it->itemText.selected(b))
- return PyFloat_FromDouble(static_cast<double>(it->itemText.charStyle(b).fontSize() / 10.0));
+ if (item->HasSel)
+ {
+ for (int b = 0; b < item->itemText.length(); b++)
+ if (item->itemText.selected(b))
+ return PyFloat_FromDouble(static_cast<double>(item->itemText.charStyle(b).fontSize() / 10.0));
return NULL;
}
else
- return PyFloat_FromDouble(static_cast<long>(it->currentCharStyle().fontSize() / 10.0));
+ return PyFloat_FromDouble(static_cast<long>(item->currentCharStyle().fontSize() / 10.0));
}
PyObject *scribus_getfont(PyObject* /* self */, PyObject* args)
@@ -46,23 +46,23 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- if (it->HasSel)
- {
- for (int b = 0; b < it->itemText.length(); b++)
- if (it->itemText.selected(b))
- return PyString_FromString(it->itemText.charStyle(b).font().scName().toUtf8());
+ if (item->HasSel)
+ {
+ for (int b = 0; b < item->itemText.length(); b++)
+ if (item->itemText.selected(b))
+ return PyString_FromString(item->itemText.charStyle(b).font().scName().toUtf8());
return NULL;
}
else
- return PyString_FromString(it->currentCharStyle().font().scName().toUtf8());
+ return PyString_FromString(item->currentCharStyle().font().scName().toUtf8());
}
PyObject *scribus_gettextsize(PyObject* /* self */, PyObject* args)
@@ -72,15 +72,15 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!(i->asTextFrame()) && !(i->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text size of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- return PyInt_FromLong(static_cast<long>(i->itemText.length()));
+ return PyInt_FromLong(static_cast<long>(item->itemText.length()));
}
PyObject *scribus_gettextlines(PyObject* /* self */, PyObject* args)
@@ -90,15 +90,15 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!(i->asTextFrame()) && !(i->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get number of lines of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- return PyInt_FromLong(static_cast<long>(i->itemText.lines()));
+ return PyInt_FromLong(static_cast<long>(item->itemText.lines()));
}
PyObject *scribus_getcolumns(PyObject* /* self */, PyObject* args)
@@ -108,15 +108,15 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- return PyInt_FromLong(static_cast<long>(i->Cols));
+ return PyInt_FromLong(static_cast<long>(item->Cols));
}
PyObject *scribus_getlinespace(PyObject* /* self */, PyObject* args)
@@ -126,15 +126,15 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- return PyFloat_FromDouble(static_cast<double>(i->currentStyle().lineSpacing()));
+ return PyFloat_FromDouble(static_cast<double>(item->currentStyle().lineSpacing()));
}
PyObject *scribus_gettextdistances(PyObject* /* self */, PyObject* args)
@@ -144,19 +144,19 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text distances of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
return Py_BuildValue("(dddd)",
- PointToValue(i->textToFrameDistLeft()),
- PointToValue(i->textToFrameDistRight()),
- PointToValue(i->textToFrameDistTop()),
- PointToValue(i->textToFrameDistBottom()));
+ PointToValue(item->textToFrameDistLeft()),
+ PointToValue(item->textToFrameDistRight()),
+ PointToValue(item->textToFrameDistTop()),
+ PointToValue(item->textToFrameDistBottom()));
}
PyObject *scribus_getcolumngap(PyObject* /* self */, PyObject* args)
@@ -166,15 +166,15 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column gap of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- return PyFloat_FromDouble(PointToValue(static_cast<double>(i->ColGap)));
+ return PyFloat_FromDouble(PointToValue(static_cast<double>(item->ColGap)));
}
PyObject *scribus_getframetext(PyObject* /* self */, PyObject* args)
@@ -185,24 +185,24 @@
if(!checkHaveDocument())
return NULL;
QString text = "";
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- for (int a = it->firstInFrame(); a <= it->lastInFrame(); ++a)
- {
- if (it->HasSel)
+ for (int a = item->firstInFrame(); a <= item->lastInFrame(); ++a)
+ {
+ if (item->HasSel)
{
- if (it->itemText.selected(a))
- text += it->itemText.text(a);
+ if (item->itemText.selected(a))
+ text += item->itemText.text(a);
}
else
{
- text += it->itemText.text(a);
+ text += item->itemText.text(a);
}
}
return PyString_FromString(text.toUtf8());
@@ -216,26 +216,26 @@
if(!checkHaveDocument())
return NULL;
QString text = "";
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
// collect all chars from a storytext
- for (int a = 0; a < it->itemText.length(); a++)
- {
- if (it->HasSel)
+ for (int a = 0; a < item->itemText.length(); a++)
+ {
+ if (item->HasSel)
{
- if (it->itemText.selected(a))
- text += it->itemText.text(a);
+ if (item->itemText.selected(a))
+ text += item->itemText.text(a);
}
else
{
- text += it->itemText.text(a);
+ text += item->itemText.text(a);
}
} // for
return PyString_FromString(text.toUtf8());
@@ -269,8 +269,7 @@
currItem->itemText.insertChars(0, Daten);
currItem->invalidateLayout();
currItem->Dirty = false;
-// Py_INCREF(Py_None);
-// return Py_None;
+
Py_RETURN_NONE;
}
@@ -283,10 +282,10 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData());
return NULL;
@@ -295,23 +294,22 @@
Daten.replace("\r\n", SpecialChars::PARSEP);
Daten.replace(QChar('\n') , SpecialChars::PARSEP);
PyMem_Free(Text);
- if ((pos < -1) || (pos > static_cast<int>(it->itemText.length())))
+ if ((pos < -1) || (pos > static_cast<int>(item->itemText.length())))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error").toLocal8Bit().constData());
return NULL;
}
if (pos == -1)
- pos = it->itemText.length();
- it->itemText.insertChars(pos, Daten);
- it->Dirty = true;
+ pos = item->itemText.length();
+ item->itemText.insertChars(pos, Daten);
+ item->Dirty = true;
if (ScCore->primaryMainWindow()->doc->DoDrawing)
{
// FIXME adapt to Qt-4 painting style
-// it->paintObj();
- it->Dirty = false;
- }
-// Py_INCREF(Py_None);
-// return Py_None;
+// item->paintObj();
+ item->Dirty = false;
+ }
+
Py_RETURN_NONE;
}
@@ -328,24 +326,25 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Alignment out of range. Use one of the scribus.ALIGN* constants.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->setNewAlignment(alignment);
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
-// Py_INCREF(Py_None);
-// return Py_None;
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetAlignment(alignment, &tmpSelection);
+ doc->appMode = oldAppMode;
+
Py_RETURN_NONE;
}
@@ -362,25 +361,26 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Font size out of bounds - must be 1 <= size <= 512.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
-
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->doc->itemSelection_SetFontSize(qRound(size * 10.0));
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
-// Py_INCREF(Py_None);
-// return Py_None;
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetFontSize(qRound(size * 10.0), &tmpSelection);
+ doc->appMode = oldAppMode;
+
Py_RETURN_NONE;
}
@@ -392,32 +392,30 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!(i->asTextFrame()) && !(i->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->isTextFrame()) && !(item->isPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- if (PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Font)))
- {
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->SetNewFont(QString::fromUtf8(Font));
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
- }
- else
- {
- PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.","python error").toLocal8Bit().constData());
- return NULL;
- }
-// Py_INCREF(Py_None);
-// return Py_None;
+ if (!PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Font)))
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.", "python error").toLocal8Bit().constData());
+ return NULL;
+ }
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetFont(QString::fromUtf8(Font), &tmpSelection);
+ doc->appMode = oldAppMode;
+
Py_RETURN_NONE;
}
@@ -434,27 +432,25 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Line space out of bounds, must be >= 0.1.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->isTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
-
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->doc->itemSelection_SetLineSpacing(w);
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
-
-// i->setLineSpacing(w);
-// Py_INCREF(Py_None);
-// return Py_None;
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetLineSpacing(w, &tmpSelection);
+ doc->appMode = oldAppMode;
+
Py_RETURN_NONE;
}
@@ -464,24 +460,24 @@
double l,r,t,b;
if (!PyArg_ParseTuple(args, "dddd|es", &l, &r, &t, &b, "utf-8", &Name))
return NULL;
- if(!checkHaveDocument())
+ if (!checkHaveDocument())
return NULL;
if (l < 0.0 || r < 0.0 || t < 0.0 || b < 0.0)
{
PyErr_SetString(PyExc_ValueError, QObject::tr("Text distances out of bounds, must be positive.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->isTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text distances on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- i->setTextToFrameDist(ValueToPoint(l), ValueToPoint(r), ValueToPoint(t), ValueToPoint(b));
- Py_INCREF(Py_None);
- return Py_None;
+ item->setTextToFrameDist(ValueToPoint(l), ValueToPoint(r), ValueToPoint(t), ValueToPoint(b));
+
+ Py_RETURN_NONE;
}
PyObject *scribus_setcolumngap(PyObject* /* self */, PyObject* args)
@@ -490,24 +486,23 @@
double w;
if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
return NULL;
- if(!checkHaveDocument())
+ if (!checkHaveDocument())
return NULL;
if (w < 0.0)
{
PyErr_SetString(PyExc_ValueError, QObject::tr("Column gap out of bounds, must be positive.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->isTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set column gap on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- i->ColGap = ValueToPoint(w);
-// Py_INCREF(Py_None);
-// return Py_None;
+ item->ColGap = ValueToPoint(w);
+
Py_RETURN_NONE;
}
@@ -524,17 +519,16 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Column count out of bounds, must be > 1.","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- i->Cols = w;
-// Py_INCREF(Py_None);
-// return Py_None;
+ item->Cols = w;
+
Py_RETURN_NONE;
}
@@ -546,24 +540,24 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
return NULL;
if (selcount == -1)
{
// user wants to select all after the start point -- CR
- selcount = it->itemText.length() - start;
+ selcount = item->itemText.length() - start;
if (selcount < 0)
// user passed start that's > text in the frame
selcount = 0;
}
// cr 2005-01-18 fixed off-by-one with end bound that made selecting the last char impossible
- if ((start < 0) || ((start + selcount) > static_cast<int>(it->itemText.length())))
+ if ((start < 0) || ((start + selcount) > static_cast<int>(item->itemText.length())))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Selection index out of bounds", "python error").toLocal8Bit().constData());
return NULL;
}
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error").toLocal8Bit().constData());
return NULL;
@@ -575,18 +569,15 @@
return NULL;
}
*/
- it->itemText.deselectAll();
+ item->itemText.deselectAll();
if (selcount == 0)
{
- it->HasSel = false;
-// Py_INCREF(Py_None);
-// return Py_None;
+ item->HasSel = false;
Py_RETURN_NONE;
}
- it->itemText.select(start, selcount, true);
- it->HasSel = true;
-// Py_INCREF(Py_None);
-// return Py_None;
+ item->itemText.select(start, selcount, true);
+ item->HasSel = true;
+
Py_RETURN_NONE;
}
@@ -597,26 +588,25 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- if (it->HasSel)
- dynamic_cast<PageItem_TextFrame*>(it)->deleteSelectedTextFromFrame();
+ if (item->HasSel)
+ dynamic_cast<PageItem_TextFrame*>(item)->deleteSelectedTextFromFrame();
else
{
- it->itemText.clear();
+ item->itemText.clear();
for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a)
{
ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a;
}
}
-// Py_INCREF(Py_None);
-// return Py_None;
+
Py_RETURN_NONE;
}
@@ -628,31 +618,30 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
else
{
- for (int b = 0; b < it->itemText.length(); b++)
+ for (int b = 0; b < item->itemText.length(); b++)
{
//FIXME: doc method
- if (it->HasSel)
+ if (item->HasSel)
{
- if (it->itemText.selected(b))
- it->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
+ if (item->itemText.selected(b))
+ item->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
}
else
- it->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
+ item->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
}
-// it->TxtFill = QString::fromUtf8(Color);
- }
-// Py_INCREF(Py_None);
-// return Py_None;
+// item->TxtFill = QString::fromUtf8(Color);
+ }
+
Py_RETURN_NONE;
}
@@ -664,31 +653,30 @@
return NULL;
if(!checkHaveDocument())
return NULL;
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && (it->asPathText()))
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && (item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
else
{
- for (int b = 0; b < it->itemText.length(); b++)
+ for (int b = 0; b < item->itemText.length(); b++)
{
//FIXME:NLS use document method for this
- if (it->HasSel)
+ if (item->HasSel)
{
- if (it->itemText.selected(b))
- it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
+ if (item->itemText.selected(b))
+ item->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
}
else
- it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
+ item->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
}
-// it->TxtStroke = QString::fromUtf8(Color);
- }
-// Py_INCREF(Py_None);
-// return Py_None;
+// item->TxtStroke = QString::fromUtf8(Color);
+ }
+
Py_RETURN_NONE;
}
@@ -706,23 +694,24 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Character scaling out of bounds, must be >= 10","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->isTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
-
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->doc->itemSelection_SetScaleH(qRound(sc * 10));
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetScaleH(qRound(sc * 10), &tmpSelection);
+ doc->appMode = oldAppMode;
Py_RETURN_NONE;
}
@@ -741,23 +730,24 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("Character scaling out of bounds, must be >= 10","python error").toLocal8Bit().constData());
return NULL;
}
- PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!item->isTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
-
- int Apm = ScCore->primaryMainWindow()->doc->appMode;
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- if (i->HasSel)
- ScCore->primaryMainWindow()->doc->appMode = modeEdit;
- ScCore->primaryMainWindow()->doc->itemSelection_SetScaleV(qRound(sc * 10));
- ScCore->primaryMainWindow()->doc->appMode = Apm;
- ScCore->primaryMainWindow()->view->Deselect();
+
+ ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+ int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+ Selection tmpSelection(0, false);
+ tmpSelection.addItem(item);
+ if (item->HasSel)
+ doc->appMode = modeEdit;
+ doc->itemSelection_SetScaleV(qRound(sc * 10), &tmpSelection);
+ doc->appMode = oldAppMode;
Py_RETURN_NONE;
}
@@ -772,36 +762,30 @@
if(!checkHaveDocument())
return NULL;
if ((w < 0) || (w > 100))
- {
-// Py_INCREF(Py_None);
-// return Py_None;
Py_RETURN_NONE;
- }
- PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
- if (it == NULL)
- return NULL;
- if (!(it->asTextFrame()) && !(it->asPathText()))
+
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+ if (!(item->asTextFrame()) && !(item->asPathText()))
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text shade on a non-text frame.","python error").toLocal8Bit().constData());
return NULL;
}
- else
- {
- //FIXME:NLS use document method for that
- for (int b = 0; b < it->itemText.length(); ++b)
+
+ //FIXME:NLS use document method for that
+ for (int b = 0; b < item->itemText.length(); ++b)
+ {
+ if (item->HasSel)
{
- if (it->HasSel)
- {
- if (it->itemText.selected(b))
- it->itemText.item(b)->setFillShade(w);
- }
- else
- it->itemText.item(b)->setFillShade(w);
+ if (item->itemText.selected(b))
+ item->itemText.item(b)->setFillShade(w);
}
-// it->ShTxtFill = w;
- }
-// Py_INCREF(Py_None);
-// return Py_None;
+ else
+ item->itemText.item(b)->setFillShade(w);
+ }
+ // item->ShTxtFill = w;
+
Py_RETURN_NONE;
}
@@ -850,8 +834,7 @@
ScCore->primaryMainWindow()->view->DrawNew();
// enable 'save icon' stuff
ScCore->primaryMainWindow()->slotDocCh();
-// Py_INCREF(Py_None);
-// return Py_None;
+
Py_RETURN_NONE;
}
@@ -899,8 +882,7 @@
// enable 'save icon' stuff
ScCore->primaryMainWindow()->slotDocCh();
ScCore->primaryMainWindow()->view->DrawNew();
-// Py_INCREF(Py_None);
-// return Py_None;
+
Py_RETURN_NONE;
}
@@ -930,8 +912,7 @@
ScCore->primaryMainWindow()->view->Deselect(true);
ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr);
ScCore->primaryMainWindow()->view->TextToPath();
-// Py_INCREF(Py_None);
-// return Py_None;
+
Py_RETURN_NONE;
}
@@ -993,15 +974,15 @@
return NULL;
if (!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only hyphenate text frame", "python error").toLocal8Bit().constData());
return NULL;
}
- ScCore->primaryMainWindow()->doc->docHyphenator->slotHyphenate(i);
+ ScCore->primaryMainWindow()->doc->docHyphenator->slotHyphenate(item);
return PyBool_FromLong(1);
}
@@ -1016,15 +997,15 @@
return NULL;
if (!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only dehyphenate text frame", "python error").toLocal8Bit().constData());
return NULL;
}
- ScCore->primaryMainWindow()->doc->docHyphenator->slotDeHyphenate(i);
+ ScCore->primaryMainWindow()->doc->docHyphenator->slotDeHyphenate(item);
return PyBool_FromLong(1);
}
@@ -1036,30 +1017,27 @@
return NULL;
if (!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set bookmark on a non-text frame", "python error").toLocal8Bit().constData());
return NULL;
}
- if (i->isBookmark == toggle)
- {
-// Py_INCREF(Py_None);
-// return Py_None;
+ if (item->isBookmark == toggle)
+ {
Py_RETURN_NONE;
}
if (toggle)
{
- i->setIsAnnotation(false);
- ScCore->primaryMainWindow()->AddBookMark(i);
+ item->setIsAnnotation(false);
+ ScCore->primaryMainWindow()->AddBookMark(item);
}
else
- ScCore->primaryMainWindow()->DelBookMark(i);
- i->isBookmark = toggle;
-// Py_INCREF(Py_None);
-// return Py_None;
+ ScCore->primaryMainWindow()->DelBookMark(item);
+ item->isBookmark = toggle;
+
Py_RETURN_NONE;
}
@@ -1070,15 +1048,15 @@
return NULL;
if (!checkHaveDocument())
return NULL;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == NULL)
- return NULL;
- if (!i->asTextFrame())
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == NULL)
+ return NULL;
+ if (!item->asTextFrame())
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't get info from a non-text frame", "python error").toLocal8Bit().constData());
return NULL;
}
- if (i->isBookmark)
+ if (item->isBookmark)
return PyBool_FromLong(1);
return PyBool_FromLong(0);
}
Modified: branches/Version14x/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23069&path=/branches/Version14x/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scribusdoc.cpp (original)
+++ branches/Version14x/Scribus/scribus/scribusdoc.cpp Thu Jul 4 22:04:47 2019
@@ -5802,14 +5802,36 @@
itemSelection_ApplyParagraphStyle(newStyle, customSelection);
}
-void ScribusDoc::itemSelection_SetFont(QString fon, Selection* customSelection)
-{
+void ScribusDoc::itemSelection_SetFont(QString font, Selection* customSelection)
+{
+ Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+ assert(itemSelection != nullptr);
+
+ uint selectedItemCount = itemSelection->count();
+ if (selectedItemCount == 0)
+ return;
+
+ QString newFont(font);
+ if (!UsedFonts.contains(newFont))
+ {
+ if (!AddFont(font))
+ {
+ PageItem *currItem = m_Selection->itemAt(0);
+ newFont = currItem->currentCharStyle().font().scName();
+ }
+ }
+
CharStyle newStyle;
- newStyle.setFont((*AllFonts)[fon]);
+ newStyle.setFont((*AllFonts)[newFont]);
itemSelection_ApplyCharStyle(newStyle, customSelection);
}
-
+void ScribusDoc::itemSelection_SetFontSize(int size, Selection* customSelection)
+{
+ CharStyle newStyle;
+ newStyle.setFontSize(size);
+ itemSelection_ApplyCharStyle(newStyle, customSelection);
+}
void ScribusDoc::itemSelection_SetNamedCharStyle(const QString& name, Selection* customSelection)
{
@@ -6273,34 +6295,6 @@
itemSelection_ApplyParagraphStyle(newStyle, customSelection);
}
-void ScribusDoc::itemSelection_SetFontSize(int size, Selection* customSelection)
-{
- if (true || appMode == modeEdit)
- {
- CharStyle newStyle;
- newStyle.setFontSize(size);
- itemSelection_ApplyCharStyle(newStyle, customSelection);
- }
- else
- {
- ParagraphStyle storyStyle;
- storyStyle.charStyle().setFontSize(size);
- if (storyStyle.lineSpacingMode() == 0)
- {
- storyStyle.setLineSpacing(((size / 10.0) * static_cast<double>(typographicSettings.autoLineSpacing) / 100) + (size / 10.0));
- }
- else if (storyStyle.lineSpacingMode() == 1)
- {
- storyStyle.setLineSpacing(storyStyle.charStyle().font().height(size));
- }
- else
- {
- storyStyle.setLineSpacing(typographicSettings.valueBaseGrid-1);
- }
- itemSelection_ApplyParagraphStyle(storyStyle, customSelection);
- }
-}
-
void ScribusDoc::itemSelection_SetParagraphStyle(const ParagraphStyle & newStyle, Selection* customSelection)
{
Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
More information about the scribus-commit
mailing list