View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0011370 | Scribus | Styles | public | 2013-01-14 10:12 | 2014-10-24 23:00 |
Reporter | cezaryece | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | new | Resolution | open | ||
Product Version | 1.5.0svn | ||||
Summary | 0011370: [PATCH] hyphenation control | ||||
Description | Patch with additional hyphenation properties for paragraph style in trunk. With this patch Paragraph Style has hyphenationMode and maxHyphens properties can be set in Style Manager and this way user can controlling hyphenation per paragraph style. Doc preferences are now used for set initial properties values for new styles or styles created while opening/importing files. | ||||
Tags | patch | ||||
Patch | Yes | ||||
|
hyphenationPStyle.patch (18,939 bytes)
diff --git a/Scribus/scribus/pageitem_textframe.cpp b/Scribus/scribus/pageitem_textframe.cpp index 1453685..a684f1c 100644 --- a/Scribus/scribus/pageitem_textframe.cpp +++ b/Scribus/scribus/pageitem_textframe.cpp @@ -2379,7 +2379,7 @@ void PageItem_TextFrame::layout() double overflowWidth = 0.0; double hyphWidth = 0.0; bool inOverflow = false; - if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN) + if ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) && ((hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN))) hyphWidth = font.charWidth('-', hlcsize10) * (charStyle.scaleH() / 1000.0); if ((current.isEndOfLine(style.rightMargin() + hyphWidth)) || current.isEndOfCol(realDesc) || SpecialChars::isBreak(hl->ch, Cols > 1) || (current.xPos - current.maxShrink + hyphWidth) >= current.mustLineEnd) { @@ -2447,10 +2447,12 @@ void PageItem_TextFrame::layout() charEnd = static_cast<int>(ceil(current.xPos - current.maxShrink)); } if (legacy && - (((hl->ch == '-' || (hl->effects() & ScStyle_HyphenationPossible)) && (current.hyphenCount < m_Doc->hyphConsecutiveLines() || m_Doc->hyphConsecutiveLines() == 0)) - || hl->ch == SpecialChars::SHYPHEN)) + (hl->ch == '-' + || ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) + && ((hl->effects() & ScStyle_HyphenationPossible) + && ((current.hyphenCount < style.maxHyphens() || style.maxHyphens() == 0) || hl->ch == SpecialChars::SHYPHEN))))) { - if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN) + if ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) && (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN)) { pt1 = QPoint(charStart, static_cast<int>(floor(maxYAsc))); pt2 = QPoint(static_cast<int>(charEnd + hyphWidth), static_cast<int>(floor(maxYDesc)) -1); @@ -2560,7 +2562,9 @@ void PageItem_TextFrame::layout() } // hyphenation - if (((hl->effects() & ScStyle_HyphenationPossible) || (hl->ch == '-') || hl->ch == SpecialChars::SHYPHEN) && (!outs) && !itemText.text(a-1).isSpace() ) + if (((hl->ch == '-') + || ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) && ((hl->effects() & ScStyle_HyphenationPossible) || hl->ch == SpecialChars::SHYPHEN))) + && (!outs) && !itemText.text(a-1).isSpace() ) { breakPos = current.xPos; if (hl->ch != '-') @@ -2575,7 +2579,7 @@ void PageItem_TextFrame::layout() if (legacy || (breakPos - rightHang < current.colRight - style.rightMargin())) { - if ((current.hyphenCount < m_Doc->hyphConsecutiveLines()) || (m_Doc->hyphConsecutiveLines() == 0) || hl->ch == SpecialChars::SHYPHEN) + if ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) && ((current.hyphenCount < style.maxHyphens()) || (style.maxHyphens() == 0) || hl->ch == SpecialChars::SHYPHEN)) { current.rememberBreak(a, breakPos, style.rightMargin() + hyphWidth); } @@ -2716,7 +2720,7 @@ void PageItem_TextFrame::layout() current.finishLine(EndX); hyphWidth = 0.0; - if ((hl->effects() & ScStyle_HyphenationPossible) || hl->ch == SpecialChars::SHYPHEN) + if ((style.hyphenationMode() != ParagraphStyle::NoHyphenation) && ((hl->effects() & ScStyle_HyphenationPossible) || hl->ch == SpecialChars::SHYPHEN)) { // insert hyphen if (current.lastInRowLine) diff --git a/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp b/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp index 960b9f3..fe3be03 100644 --- a/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp +++ b/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp @@ -4657,6 +4657,8 @@ PageItem* Scribus150Format::pasteItem(ScribusDoc *doc, ScXmlStreamAttributes& at pstyle.setOpticalMargins(attrs.valueAsInt("OpticalMargins")); if (attrs.hasAttribute("HyphenationMode")) pstyle.setHyphenationMode(attrs.valueAsInt("HyphenationMode")); + if (attrs.hasAttribute("MaxHyphens")) + pstyle.setMaxHyphens(attrs.valueAsInt("MaxHyphens")); if (attrs.hasAttribute("leftMargin")) pstyle.setLeftMargin(attrs.valueAsDouble("leftMargin")); if (attrs.hasAttribute("rightMargin")) diff --git a/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp b/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp index 22ceea9..f48ab91 100644 --- a/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp +++ b/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp @@ -677,6 +677,8 @@ void Scribus150Format::putPStyle(ScXmlStreamWriter & docu, const ParagraphStyle docu.writeAttribute("OpticalMargins", style.opticalMargins()); if ( ! style.isInhHyphenationMode()) docu.writeAttribute("HyphenationMode", style.hyphenationMode()); + if ( ! style.isInhMaxHyphens()) + docu.writeAttribute("MaxHyphens", style.maxHyphens()); if ( ! style.isInhMinWordTracking()) docu.writeAttribute("MinWordTrack", style.minWordTracking()); if ( ! style.isInhMinGlyphExtension()) @@ -2562,6 +2564,8 @@ void Scribus150Format::SetItemProps(ScXmlStreamWriter& docu, PageItem* item, con docu.writeAttribute("OpticalMargins", dStyle.opticalMargins()); if ( ! dStyle.isInhHyphenationMode()) docu.writeAttribute("HyphenationMode", dStyle.hyphenationMode()); + if ( ! dStyle.isInhMaxHyphens()) + docu.writeAttribute("MaxHyphens", dStyle.maxHyphens()); if ( ! dStyle.isInhLeftMargin() ) docu.writeAttribute("leftMargin", dStyle.leftMargin()); if ( ! dStyle.isInhRightMargin()) diff --git a/Scribus/scribus/scribusdoc.cpp b/Scribus/scribus/scribusdoc.cpp index 641e1d0..5f5aa16 100644 --- a/Scribus/scribus/scribusdoc.cpp +++ b/Scribus/scribus/scribusdoc.cpp @@ -508,6 +508,15 @@ void ScribusDoc::init() pstyle.setDropCapLines(2); pstyle.setParEffectOffset(0); pstyle.charStyle().setParent(""); + //set hyphenation properties from doc preferences for hyphenation + if (hyphAutomatic()) + { + if (hyphAutoCheck()) + pstyle.setHyphenationMode(ParagraphStyle::AutomaticHyphenation); + else + pstyle.setHyphenationMode(ParagraphStyle::ManualHyphenation); + } //else hyphenationMode is NoHyphenation + pstyle.setMaxHyphens(hyphConsecutiveLines()); CharStyle cstyle; cstyle.setDefaultStyle(true); @@ -1504,6 +1513,15 @@ void ScribusDoc::redefineStyles(const StyleSet<ParagraphStyle>& newStyles, bool else { sty.breakImplicitCharStyleInheritance(false); } + //set HyphenationMode to doc default + if (sty.hyphenationMode() == ParagraphStyle::HyphModeNotSet) + { + if (hyphAutoCheck()) + sty.setHyphenationMode(ParagraphStyle::AutomaticHyphenation); + else + sty.setHyphenationMode(ParagraphStyle::ManualHyphenation); + sty.setMaxHyphens(hyphConsecutiveLines()); + } } docParagraphStyles.invalidate(); if (!isLoading()) diff --git a/Scribus/scribus/styles/paragraphstyle.attrdefs.cxx b/Scribus/scribus/styles/paragraphstyle.attrdefs.cxx index 1a78584..e6c94ad 100644 --- a/Scribus/scribus/styles/paragraphstyle.attrdefs.cxx +++ b/Scribus/scribus/styles/paragraphstyle.attrdefs.cxx @@ -21,6 +21,7 @@ ATTRDEF(double, lineSpacing, LineSpacing, 0.0) ATTRDEF(ParagraphStyle::AlignmentType, alignment, Alignment, Leftaligned) ATTRDEF(int, opticalMargins, OpticalMargins, 0) ATTRDEF(int, hyphenationMode, HyphenationMode, 0) +ATTRDEF(int, maxHyphens, MaxHyphens, -1) ATTRDEF(double, minWordTracking, MinWordTracking, 1.0) //ATTRDEF(double, maxWordTracking, MaxWordTracking, 1.0) ATTRDEF(double, minGlyphExtension, MinGlyphExtension, 1.0) diff --git a/Scribus/scribus/styles/paragraphstyle.h b/Scribus/scribus/styles/paragraphstyle.h index 8030a19..4785c9a 100644 --- a/Scribus/scribus/styles/paragraphstyle.h +++ b/Scribus/scribus/styles/paragraphstyle.h @@ -48,6 +48,7 @@ public: OM_Default = OM_RightProtruding + OM_LeftHangingPunct + OM_RightHangingPunct }; enum HyphenationMode { + HyphModeNotSet = -1, NoHyphenation = 0, ManualHyphenation = 1, AutomaticHyphenation = 2 diff --git a/Scribus/scribus/ui/smpstylewidget.cpp b/Scribus/scribus/ui/smpstylewidget.cpp index fa0afbe..d5cc7f4 100644 --- a/Scribus/scribus/ui/smpstylewidget.cpp +++ b/Scribus/scribus/ui/smpstylewidget.cpp @@ -62,6 +62,9 @@ SMPStyleWidget::SMPStyleWidget(ScribusDoc* doc) : QWidget() fillNumRestartCombo(); dropCapLines_->setMinimum(2); dropCapLines_->setMaximum(99); + fillHyphModeCombo(); + maxHypensSpin->setMinimum(0); + maxHypensSpin->setMaximum(9); minSpaceSpin->setSuffix(unitGetSuffixFromIndex(SC_PERCENT)); minGlyphExtSpin->setSuffix(unitGetSuffixFromIndex(SC_PERCENT)); @@ -203,6 +206,10 @@ void SMPStyleWidget::languageChange() optMarginDefaultButton->setText( tr("Reset to Default") ); optMarginParentButton->setText( tr("Use Parent Value") ); + + hyphBox->setTitle(tr("Hypehantion Settings")); + fillHyphModeCombo(); + maxHyphensLabel->setText(tr("Consecutive Hyphenations Allowed:")); } void SMPStyleWidget::unitChange(double oldRatio, double newRatio, int unitIndex) @@ -261,6 +268,14 @@ void SMPStyleWidget::fillNumRestartCombo() numRestartCombo->addItem(tr("Frame")); } +void SMPStyleWidget::fillHyphModeCombo() +{ + hyphModeCombo->clear(); + hyphModeCombo->addItem(tr("No Hyphenation")); + hyphModeCombo->addItem(tr("Manual Hyphenation")); + hyphModeCombo->addItem(tr("Automatic Hyphenation")); +} + void SMPStyleWidget::checkParEffectState() { bool enable = false; @@ -298,10 +313,11 @@ void SMPStyleWidget::show(ParagraphStyle *pstyle, QList<ParagraphStyle> &pstyles minGlyphExtSpin->setRange(90.0,100.0); maxGlyphExtSpin->setRange(100.0,110.0); - //fillBulletStrEditCombo(); - //fillNumFormatCombo(); - //fillNumerationsCombo(); - //fillNumRestartCombo(); + fillBulletStrEditCombo(); + fillNumFormatCombo(); + fillNumerationsCombo(); + fillNumRestartCombo(); + fillHyphModeCombo(); if (hasParent_) { @@ -425,6 +441,15 @@ void SMPStyleWidget::show(ParagraphStyle *pstyle, QList<ParagraphStyle> &pstyles numRestartOtherBox->setParentValue(parent->numOther()); numRestartHigherBox->setChecked(pstyle->numHigher(), pstyle->isInhNumHigher()); numRestartHigherBox->setParentValue(parent->numHigher()); + + int hm = pstyle->hyphenationMode(); + hyphModeCombo->setCurrentItem(hm, pstyle->isInhHyphenationMode()); + maxHypensSpin->setValue(pstyle->maxHyphens(), pstyle->isInhMaxHyphens()); + maxHypensSpin->setParentValue(parent->maxHyphens()); + if (hm == ParagraphStyle::NoHyphenation) + maxHypensSpin->setEnabled(false); + else + maxHypensSpin->setEnabled(true); } else { @@ -483,6 +508,10 @@ void SMPStyleWidget::show(ParagraphStyle *pstyle, QList<ParagraphStyle> &pstyles keepLinesEnd->setValue (pstyle->keepLinesEnd()); keepTogether->setChecked (pstyle->keepTogether()); keepWithNext->setChecked (pstyle->keepWithNext()); + + int hm = pstyle->hyphenationMode(); + hyphModeCombo->setCurrentItem(hm); + setMaxHyphensSpin(hm, pstyle->maxHyphens()); } lineSpacing_->setEnabled(pstyle->lineSpacingMode() == ParagraphStyle::FixedLineSpacing); @@ -541,6 +570,7 @@ void SMPStyleWidget::show(QList<ParagraphStyle*> &pstyles, QList<ParagraphStyle> showDropCap(pstyles, cstyles, unitIndex); showBullet(pstyles, cstyles, unitIndex); showNumeration(pstyles, cstyles, unitIndex); + showHyphenation(pstyles); showAlignment(pstyles); showOpticalMargin(pstyles); showMinSpace(pstyles); @@ -1004,6 +1034,42 @@ void SMPStyleWidget::setOpticalMargins(int o, bool inhO, const ParagraphStyle *p } } +void SMPStyleWidget::showHyphenation(QList<ParagraphStyle *> &pstyles) +{ + if(pstyles.isEmpty()) + { + qDebug()<<"Warning showMaxGlyphExt called with an empty list of styles"; + return; + } + int hm = pstyles[0]->hyphenationMode(); + int mh = pstyles[0]->maxHyphens(); + for (int i = 0; i < pstyles.count(); ++i) + { + if ((hm != pstyles[i]->hyphenationMode()) || (hm !=ParagraphStyle::NoHyphenation && mh != pstyles[i]->maxHyphens())) + { + hyphModeCombo->setCurrentItem(pstyles[i]->hyphenationMode()); + setMaxHyphensSpin(pstyles[i]->hyphenationMode(),pstyles[i]->maxHyphens()); + return; + } + + } + hyphModeCombo->setCurrentItem(hm); + setMaxHyphensSpin(hm, mh); +} + +void SMPStyleWidget::setMaxHyphensSpin(int hm, int mh) +{ + if (hm == ParagraphStyle::NoHyphenation) + { + maxHypensSpin->setEnabled(false); + } + else + { + maxHypensSpin->setValue(mh); + maxHypensSpin->setEnabled(true); + } +} + void SMPStyleWidget::slotDefaultOpticalMargins() { diff --git a/Scribus/scribus/ui/smpstylewidget.h b/Scribus/scribus/ui/smpstylewidget.h index b46e016..78956fb 100644 --- a/Scribus/scribus/ui/smpstylewidget.h +++ b/Scribus/scribus/ui/smpstylewidget.h @@ -45,6 +45,7 @@ private: void fillNumFormatCombo(); void fillNumerationsCombo(); void fillNumRestartCombo(); + void fillHyphModeCombo(); void checkParEffectState(); void showLineSpacing(QList<ParagraphStyle*> &pstyles); void showSpaceAB(QList<ParagraphStyle*> &pstyles, int unitIndex); @@ -60,6 +61,9 @@ private: void showCStyle(QList<ParagraphStyle*> &pstyles, QList<CharStyle> &cstyles, const QString &defLang, int unitIndex); void showParent(QList<ParagraphStyle*> &pstyles); void setOpticalMargins(int o, bool inhO=false, const ParagraphStyle *parent=NULL); + void showHyphenation(QList<ParagraphStyle*> &pstyles); + + void setMaxHyphensSpin(int, int); void openEnhanced(); void closeEnhanced(bool show = false); diff --git a/Scribus/scribus/ui/smpstylewidget.ui b/Scribus/scribus/ui/smpstylewidget.ui index fea9615..56ada0b 100644 --- a/Scribus/scribus/ui/smpstylewidget.ui +++ b/Scribus/scribus/ui/smpstylewidget.ui @@ -665,6 +665,57 @@ </widget> </item> <item> + <widget class="QGroupBox" name="hyphBox"> + <property name="title"> + <string>Hyphenation</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="SMScComboBox" name="hyphModeCombo"/> + </item> + <item> + <spacer name="horizontalSpacer_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Maximum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="maxHyphensLabel"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + <item> + <widget class="SMSpinBox" name="maxHypensSpin"/> + </item> + <item> + <spacer name="horizontalSpacer_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item> <spacer> <property name="orientation"> <enum>Qt::Vertical</enum> diff --git a/Scribus/scribus/ui/smtextstyles.cpp b/Scribus/scribus/ui/smtextstyles.cpp index ad41c30..c18c3fd 100644 --- a/Scribus/scribus/ui/smtextstyles.cpp +++ b/Scribus/scribus/ui/smtextstyles.cpp @@ -547,6 +547,9 @@ void SMParagraphStyle::setupConnections() connect(pwidget_->tabList_->right_, SIGNAL(valueChanged(double)), this, SLOT(slotRightIndent())); connect(pwidget_->tabList_->first_, SIGNAL(valueChanged(double)), this, SLOT(slotFirstLine())); + connect(pwidget_->hyphModeCombo, SIGNAL(activated(int)), this, SLOT(slotHyphenationMode(int))); + connect(pwidget_->maxHypensSpin, SIGNAL(valueChanged(int)), this, SLOT(slotMaxHyphens(int))); + connect(pwidget_->parentCombo, SIGNAL(activated(const QString&)), this, SLOT(slotParentChanged(const QString&))); // character attributes @@ -621,6 +624,9 @@ void SMParagraphStyle::removeConnections() disconnect(pwidget_->numNewLineEdit, SIGNAL(editingFinished()), this, SLOT(slotNumNew())); disconnect(pwidget_->numNewLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSelectionDirty())); + disconnect(pwidget_->hyphModeCombo, SIGNAL(activated(int)), this, SLOT(slotHyphenationMode(int))); + disconnect(pwidget_->maxHypensSpin, SIGNAL(valueChanged(int)), this, SLOT(slotMaxHyphens(int))); + disconnect(pwidget_->parentCombo, SIGNAL(activated(const QString&)), this, SLOT(slotParentChanged(const QString&))); disconnect(pwidget_->keepLinesStart, SIGNAL(valueChanged(int)), this, SLOT(handleKeepLinesStart())); @@ -1805,6 +1811,46 @@ void SMParagraphStyle::slotCharParentChanged(const QString &parent) } } +void SMParagraphStyle::slotHyphenationMode(int hm) +{ + if (pwidget_->hyphModeCombo->useParentValue()) + for (int i = 0; i < selection_.count(); ++i) + selection_[i]->resetHyphenationMode(); + else + for (int i = 0; i < selection_.count(); ++i) + { + selection_[i]->setHyphenationMode(hm); + } + + if (hm != ParagraphStyle::NoHyphenation) + pwidget_->maxHypensSpin->setEnabled(true); + else + pwidget_->maxHypensSpin->setEnabled(false); + if (!selectionIsDirty_) + { + selectionIsDirty_ = true; + emit selectionDirty(); + } +} + +void SMParagraphStyle::slotMaxHyphens(int mh) +{ + if (pwidget_->maxHypensSpin->useParentValue()) + for (int i = 0; i < selection_.count(); ++i) + selection_[i]->resetMaxHyphens(); + else + for (int i = 0; i < selection_.count(); ++i) + { + selection_[i]->setMaxHyphens(mh); + } + + if (!selectionIsDirty_) + { + selectionIsDirty_ = true; + emit selectionDirty(); + } +} + SMParagraphStyle::~SMParagraphStyle() { diff --git a/Scribus/scribus/ui/smtextstyles.h b/Scribus/scribus/ui/smtextstyles.h index 1dfa578..82e3df9 100644 --- a/Scribus/scribus/ui/smtextstyles.h +++ b/Scribus/scribus/ui/smtextstyles.h @@ -125,6 +125,8 @@ private slots: void slotFont(QString s); void slotParentChanged(const QString &parent); void slotCharParentChanged(const QString &parent); + void slotHyphenationMode(int hm); + void slotMaxHyphens(int mh); }; class SMCharacterStyle : public StyleItem |
|
Reminder sent to: cbradney As you wish I upload patch for trunk. |
|
In addition to patch reported previously for 1.4 this one brings also control of max consecutive hyphens as user may want to have different for various styles. |
|
Memo : The previous version for 1.4 of this patch has been discussed in 0009848 |
Date Modified | Username | Field | Change |
---|---|---|---|
2013-01-14 10:12 | cezaryece | New Issue | |
2013-01-14 10:12 | cezaryece | File Added: hyphenationPStyle.patch | |
2013-01-14 10:14 | cezaryece | Note Added: 0029703 | |
2013-01-14 10:17 | cezaryece | Note Added: 0029704 | |
2014-01-23 12:14 | JLuc | Tag Attached: patch | |
2014-01-23 12:16 | JLuc | Note Added: 0031178 | |
2014-10-24 23:00 | Kunda | Patch | => Yes |