r17279 by fschmid - Fixed Bug 10336: "Inserted glyph is not of the requested font" by backporting the relevant changes from 1.5.0svn
scribus-commit
scribus-commit at lists.scribus.net
Sat Feb 4 23:06:22 UTC 2012
Author: fschmid
Date: Sat Feb 4 23:06:22 2012
New Revision: 17279
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17279
Log:
Fixed Bug 10336: "Inserted glyph is not of the requested font" by backporting the relevant changes from 1.5.0svn
Modified:
branches/Version14x/Scribus/scribus/charselect.cpp
branches/Version14x/Scribus/scribus/charselect.h
branches/Version14x/Scribus/scribus/charselectenhanced.cpp
branches/Version14x/Scribus/scribus/charselectenhanced.h
branches/Version14x/Scribus/scribus/chartablemodel.cpp
branches/Version14x/Scribus/scribus/chartablemodel.h
branches/Version14x/Scribus/scribus/chartableview.cpp
branches/Version14x/Scribus/scribus/chartableview.h
branches/Version14x/Scribus/scribus/storyeditor.cpp
branches/Version14x/Scribus/scribus/storyeditor.h
Modified: branches/Version14x/Scribus/scribus/charselect.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/charselect.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/charselect.cpp (original)
+++ branches/Version14x/Scribus/scribus/charselect.cpp Sat Feb 4 23:06:22 2012
@@ -45,8 +45,8 @@
m_userTable->setAcceptDrops(true);
// signals and slots connections
- connect(m_userTable, SIGNAL(selectChar(uint)),
- this, SLOT(userNewChar(uint)));
+ connect(m_userTable, SIGNAL(selectChar(uint, QString)),
+ this, SLOT(userNewChar(uint, QString)));
connect(m_userTableModel, SIGNAL(selectionChanged(QItemSelectionModel*)),
m_userTable, SLOT(modelSelectionChanged(QItemSelectionModel*)));
connect(m_userTableModel, SIGNAL(rowAppended()),
@@ -55,8 +55,8 @@
m_userTableModel, SLOT(appendUnicode(const QString &)));
connect(hideButton, SIGNAL(toggled(bool)),
this, SLOT(hideButton_toggled(bool)));
- connect(this, SIGNAL(insertUserSpecialChar(QChar)),
- this, SLOT(slot_insertUserSpecialChar(QChar)));
+ connect(this, SIGNAL(insertUserSpecialChar(QChar, QString)),
+ this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
connect(uniLoadButton, SIGNAL(clicked()),
this, SLOT(uniLoadButton_clicked()));
connect(uniSaveButton, SIGNAL(clicked()),
@@ -93,9 +93,9 @@
return chToIns;
}
-void CharSelect::userNewChar(uint i)
-{
- emit insertUserSpecialChar(QChar(i));
+void CharSelect::userNewChar(uint i, QString font)
+{
+ emit insertUserSpecialChar(QChar(i), font);
}
void CharSelect::slot_insertSpecialChars(const QString & chars)
@@ -120,6 +120,9 @@
//CB: Avox please make text->insertchar(char) so none of this happens in gui code, and item can tell doc its changed so the view and mainwindow slotdocch are not necessary
QChar ch;
QString txtIns;
+ QString fontName = m_doc->currentStyle.charStyle().font().scName();
+ if (m_enhanced)
+ fontName = m_enhanced->getUsedFont();
m_Item->oldCPos = m_Item->itemText.cursorPosition();
for (int a=0; a<chToIns.length(); ++a)
{
@@ -128,7 +131,11 @@
ch = QChar(13);
if (ch == QChar(9))
ch = QChar(32);
+ int pot = m_Item->itemText.cursorPosition();
m_Item->itemText.insertChars(ch, true);
+ CharStyle nstyle = m_Item->itemText.charStyle(pot);
+ nstyle.setFont((*m_doc->AllFonts)[fontName]);
+ m_Item->itemText.applyCharStyle(pot, 1, nstyle);
txtIns.append(ch);
}
if (m_Item->itemTextSaxed.isEmpty())
@@ -141,7 +148,7 @@
// delEdit();
}
-void CharSelect::slot_insertUserSpecialChar(QChar ch)
+void CharSelect::slot_insertUserSpecialChar(QChar ch, QString font)
{
if (!m_Item)
return;
@@ -159,7 +166,11 @@
if (ch == QChar(9))
ch = QChar(32);
m_Item->oldCPos = m_Item->itemText.cursorPosition();
+ int pot = m_Item->itemText.cursorPosition();
m_Item->itemText.insertChars(ch, true);
+ CharStyle nstyle = m_Item->itemText.charStyle(pot);
+ nstyle.setFont((*m_doc->AllFonts)[font]);
+ m_Item->itemText.applyCharStyle(pot, 1, nstyle);
if (m_Item->itemTextSaxed.isEmpty())
m_Item->asTextFrame()->updateUndo(PageItem::INS, QString(ch));
else
@@ -178,6 +189,7 @@
m_enhanced = new CharSelectEnhanced(this);
connect(m_enhanced, SIGNAL(insertSpecialChars(const QString &)),
this, SLOT(slot_insertSpecialChars(const QString &)));
+ connect(m_enhanced, SIGNAL(paletteShown(bool)), hideButton, SLOT(setChecked(bool)));
m_enhanced->setDoc(m_doc);
m_enhanced->setEnabled(this->isEnabled());
m_enhanced->show();
@@ -195,6 +207,7 @@
disconnect(m_enhanced, SIGNAL(insertSpecialChars(const QString &)),
this, SLOT(slot_insertSpecialChars(const QString &)));
+ disconnect(m_enhanced, SIGNAL(paletteShown(bool)), hideButton, SLOT(setChecked(bool)));
m_enhanced->close();
delete m_enhanced;
m_enhanced = 0;
@@ -257,16 +270,24 @@
if (file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
- QString line;
+ QString line = stream.readLine();
+ if (line != "# Character palette file for Scribus")
+ {
+ file.close();
+ return;
+ }
+ m_userTableModel->setCharacters(CharClassDef());
while (!stream.atEnd())
{
bool ok = false;
line = stream.readLine();
if (line.left(1) == "#")
continue; // don't mess with a comment
- int val = line.toInt(&ok, 10);
+ int a = line.indexOf(" ");
+ QString si = line.left(a);
+ si.toInt(&ok, 10);
if (ok)
- newChars.append(val);
+ m_userTableModel->addCharacter(line);
else
{
QMessageBox::warning(this, tr("Error"),
@@ -276,7 +297,6 @@
}
}
file.close();
- m_userTableModel->setCharacters(newChars);
}
// tDebug("loadUserContent end");
}
@@ -306,9 +326,12 @@
{
QTextStream stream(&file);
CharClassDef chars = m_userTableModel->characters();
- stream << "# This is a character palette file for Scribus\n";
- for (CharClassDef::Iterator it = chars.begin(); it != chars.end(); ++it)
- stream << (*it) << "\n";
+ QStringList fonts = m_userTableModel->fonts();
+ stream << "# Character palette file for Scribus\n";
+ for (int a = 0; a < chars.count(); a++)
+ {
+ stream << chars[a] << " " << fonts[a] << "\n";
+ }
file.close();
}
else
Modified: branches/Version14x/Scribus/scribus/charselect.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/charselect.h
==============================================================================
--- branches/Version14x/Scribus/scribus/charselect.h (original)
+++ branches/Version14x/Scribus/scribus/charselect.h Sat Feb 4 23:06:22 2012
@@ -57,7 +57,7 @@
in StoryEditor workaround. */
void insertSpecialChar();
/*! Internal signal for one glyph only */
- void insertUserSpecialChar(QChar);
+ void insertUserSpecialChar(QChar, QString);
private:
@@ -81,11 +81,11 @@
void closeEnhanced();
private slots:
- void userNewChar(uint i);
+ void userNewChar(uint i, QString);
void hideButton_toggled(bool);
void slot_insertSpecialChar();
void slot_insertSpecialChars(const QString & chars);
- void slot_insertUserSpecialChar(QChar);
+ void slot_insertUserSpecialChar(QChar, QString);
void uniLoadButton_clicked();
void uniSaveButton_clicked();
void uniClearButton_clicked();
Modified: branches/Version14x/Scribus/scribus/charselectenhanced.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/charselectenhanced.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/charselectenhanced.cpp (original)
+++ branches/Version14x/Scribus/scribus/charselectenhanced.cpp Sat Feb 4 23:06:22 2012
@@ -33,7 +33,7 @@
// signals and slots connections
connect(deleteButton, SIGNAL(clicked()), this, SLOT(delEdit()));
connect(insertButton, SIGNAL(clicked()), this, SLOT(insChar()));
- connect(m_charTable, SIGNAL(selectChar(uint)), this, SLOT(newChar(uint)));
+ connect(m_charTable, SIGNAL(selectChar(uint, QString)), this, SLOT(newChar(uint, QString)));
connect(fontSelector, SIGNAL(activated(int)), this, SLOT(newFont(int)));
connect(rangeSelector, SIGNAL(activated(int)), this, SLOT(newCharClass(int)));
connect(hexLineEdit, SIGNAL(returnPressed()),
@@ -64,6 +64,11 @@
newFont(fontSelector->currentIndex());
}
// tDebug("CharSelectEnhanced setDoc end");
+}
+
+QString CharSelectEnhanced::getUsedFont()
+{
+ return m_fontInUse;
}
void CharSelectEnhanced::scanFont()
@@ -410,7 +415,7 @@
// tDebug("newFont end");
}
-void CharSelectEnhanced::newChar(uint i)
+void CharSelectEnhanced::newChar(uint i, QString)
{
chToIns += QChar(i);
sample->setPixmap(FontSample((*m_doc->AllFonts)[m_fontInUse], 28, chToIns, palette().color(QPalette::Window), true));
@@ -456,7 +461,7 @@
bool ok = false;
uint code = tx.arg(hexLineEdit->text()).toUInt(&ok, 16);
if ((ok) && (code > 31))
- newChar(code);
+ newChar(code, m_fontInUse);
}
void CharSelectEnhanced::changeEvent(QEvent *e)
Modified: branches/Version14x/Scribus/scribus/charselectenhanced.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/charselectenhanced.h
==============================================================================
--- branches/Version14x/Scribus/scribus/charselectenhanced.h (original)
+++ branches/Version14x/Scribus/scribus/charselectenhanced.h Sat Feb 4 23:06:22 2012
@@ -26,6 +26,7 @@
~CharSelectEnhanced();
void setDoc(ScribusDoc* doc);
+ QString getUsedFont();
signals:
/*! \brief A signall emitted when press the "Insert" button.
@@ -34,7 +35,7 @@
void insertSpecialChars(const QString & chars);
public slots:
- void newChar(uint i);
+ void newChar(uint i, QString);
void delChar();
void newFont(int font);
void newCharClass(int c);
Modified: branches/Version14x/Scribus/scribus/chartablemodel.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/chartablemodel.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/chartablemodel.cpp (original)
+++ branches/Version14x/Scribus/scribus/chartablemodel.cpp Sat Feb 4 23:06:22 2012
@@ -21,6 +21,7 @@
{
m_selectionModel = new QItemSelectionModel(this);
m_characters.clear();
+ m_fonts.clear();
}
int CharTableModel::rowCount(const QModelIndex & parent) const
@@ -40,14 +41,18 @@
int ix = index.row() * m_cols + index.column();
int currentChar;
+ QString currentFont = m_fontInUse;
if (ix < m_characters.count())
- currentChar = m_characters[ix];
+ {
+ currentChar = m_characters[ix];
+ currentFont = m_fonts[ix];
+ }
else
return QVariant();
// for mimeData()
if (role == Qt::AccessibleTextRole)
- return m_characters[ix];
+ return QString("%1#%2").arg(currentChar).arg(currentFont);
// tooltip
if (role == Qt::ToolTipRole)
@@ -65,7 +70,7 @@
QMatrix chma;
chma.scale(baseSize/10, baseSize/10);
- ScFace face = (*m_doc->AllFonts)[m_fontInUse];
+ ScFace face = (*m_doc->AllFonts)[currentFont];
uint gl = face.char2CMap(currentChar);
int size = baseSize + qRound(-face.descent() * baseSize) + 1;
double ww = baseSize - face.glyphWidth(gl, baseSize);
@@ -109,8 +114,39 @@
void CharTableModel::setCharacters(CharClassDef ch)
{
m_characters.clear();
+ m_fonts.clear();
m_characters = ch;
+ for (int a = 0; a < m_characters.count(); a++)
+ {
+ m_fonts.append(m_fontInUse);
+ }
reset();
+}
+
+void CharTableModel::setCharactersAndFonts(CharClassDef ch, QStringList fonts)
+{
+ m_characters.clear();
+ m_fonts.clear();
+ m_characters = ch;
+ m_fonts = fonts;
+ reset();
+}
+
+void CharTableModel::addCharacter(QString ch)
+{
+ int orig = rowCount();
+ bool ok;
+ int a = ch.indexOf(" ");
+ QString si = ch.left(a);
+ QString sf = ch.mid(a+1);
+ int val = si.toInt(&ok, 10);
+ if (!ok)
+ return;
+ m_characters.append(val);
+ m_fonts.append(sf);
+ reset();
+ if (orig < rowCount())
+ emit rowAppended();
}
void CharTableModel::setFontInUse(QString font)
@@ -126,13 +162,17 @@
{
int orig = rowCount();
bool ok;
- int val = s.toInt(&ok, base);
+ int a = s.indexOf("#");
+ QString si = s.left(a);
+ QString sf = s.mid(a+1);
+ int val = si.toInt(&ok, base);
if (!ok)
return;
- if (!m_characters.contains(val))
+ if ((!m_characters.contains(val)) || (!m_fonts.contains(sf)))
{
m_characters.append(val);
+ m_fonts.append(sf);
reset();
}
else
@@ -154,6 +194,7 @@
if (index >= 0 && index < m_characters.size())
{
m_characters.removeAt(index);
+ m_fonts.removeAt(index);
reset();
return true;
}
Modified: branches/Version14x/Scribus/scribus/chartablemodel.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/chartablemodel.h
==============================================================================
--- branches/Version14x/Scribus/scribus/chartablemodel.h (original)
+++ branches/Version14x/Scribus/scribus/chartablemodel.h Sat Feb 4 23:06:22 2012
@@ -8,6 +8,7 @@
#define CHARTABLEMODEL_H
#include <QAbstractTableModel>
+#include <QStringList>
#include "scribusapi.h"
@@ -44,9 +45,12 @@
ScFace fontFace();
void setCharacters(CharClassDef ch);
+ void setCharactersAndFonts(CharClassDef ch, QStringList fonts);
+ void addCharacter(QString ch);
CharClassDef characters() {
return m_characters;
};
+ QStringList fonts() { return m_fonts; }
//! \brief called to erase glyph at index from table.
bool removeCharacter(int index);
@@ -84,6 +88,7 @@
QString m_fontInUse;
CharClassDef m_characters;
+ QStringList m_fonts;
//! \brief Internal selection handling. See selectionChanged().
QItemSelectionModel * m_selectionModel;
Modified: branches/Version14x/Scribus/scribus/chartableview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/chartableview.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/chartableview.cpp (original)
+++ branches/Version14x/Scribus/scribus/chartableview.cpp Sat Feb 4 23:06:22 2012
@@ -77,7 +77,7 @@
int index = currenCharactersIndex();
int currentChar = -1;
- if (index < model()->characters().count())
+ if ((index < model()->characters().count()) && (model()->characters().count() > 0))
currentChar = model()->characters()[index];
if (e->button() == Qt::RightButton && currentChar > -1)
@@ -117,7 +117,7 @@
void CharTableView::viewDoubleClicked(const QModelIndex & /*index*/)
{
if (model()->characters().count() > currenCharactersIndex())
- emit selectChar(model()->characters()[currenCharactersIndex()]);
+ emit selectChar(model()->characters()[currenCharactersIndex()], model()->fonts()[currenCharactersIndex()]);
}
int CharTableView::currenCharactersIndex()
Modified: branches/Version14x/Scribus/scribus/chartableview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/chartableview.h
==============================================================================
--- branches/Version14x/Scribus/scribus/chartableview.h (original)
+++ branches/Version14x/Scribus/scribus/chartableview.h Sat Feb 4 23:06:22 2012
@@ -29,7 +29,7 @@
CharTableView(QWidget * parent = 0);
signals:
- void selectChar(uint);
+ void selectChar(uint, QString);
//! \brief When user press the DELETE/BACKSPACE key
void delChar();
Modified: branches/Version14x/Scribus/scribus/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/storyeditor.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/storyeditor.cpp (original)
+++ branches/Version14x/Scribus/scribus/storyeditor.cpp Sat Feb 4 23:06:22 2012
@@ -1570,12 +1570,11 @@
void StoryEditor::showEvent(QShowEvent *)
{
charSelect = new CharSelect(this);
- charSelect->userTableModel()->setCharacters(
- ScCore->primaryMainWindow()->charPalette->userTableModel()->characters());
+ charSelect->userTableModel()->setCharactersAndFonts(ScCore->primaryMainWindow()->charPalette->userTableModel()->characters(), ScCore->primaryMainWindow()->charPalette->userTableModel()->fonts());
connect(charSelect, SIGNAL(insertSpecialChar()),
this, SLOT(slot_insertSpecialChar()));
- connect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
- this, SLOT(slot_insertUserSpecialChar(QChar)));
+ connect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)),
+ this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
}
void StoryEditor::hideEvent(QHideEvent *)
@@ -1584,15 +1583,14 @@
{
if (charSelectUsed)
{
- ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharacters(
- charSelect->userTableModel()->characters());
+ ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharactersAndFonts(charSelect->userTableModel()->characters(), charSelect->userTableModel()->fonts());
}
if (charSelect->isVisible())
charSelect->close();
disconnect(charSelect, SIGNAL(insertSpecialChar()),
this, SLOT(slot_insertSpecialChar()));
- disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
- this, SLOT(slot_insertUserSpecialChar(QChar)));
+ disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)),
+ this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
delete charSelect;
charSelect = NULL;
}
@@ -2684,7 +2682,7 @@
blockUpdate = false;
}
-void StoryEditor::slot_insertUserSpecialChar(QChar c)
+void StoryEditor::slot_insertUserSpecialChar(QChar c, QString)
{
blockUpdate = true;
Editor->insertPlainText(c);
Modified: branches/Version14x/Scribus/scribus/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17279&path=/branches/Version14x/Scribus/scribus/storyeditor.h
==============================================================================
--- branches/Version14x/Scribus/scribus/storyeditor.h (original)
+++ branches/Version14x/Scribus/scribus/storyeditor.h Sat Feb 4 23:06:22 2012
@@ -472,7 +472,7 @@
void specialActionKeyEvent(const QString& actionName, int unicodevalue);
/*! \brief Slot to insert special characters from charSelect widget. */
void slot_insertSpecialChar();
- void slot_insertUserSpecialChar(QChar);
+ void slot_insertUserSpecialChar(QChar, QString);
// 10/12/2004 - pv - #1203: wrong selection on double click
void doubleClick(int para, int pos);
More information about the scribus-commit
mailing list