View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0009934 | Scribus | General | public | 2011-04-17 19:36 | 2026-09-13 04:00 |
| Reporter | DooFi | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | N/A |
| Status | new | Resolution | open | ||
| Summary | 0009934: [feature request] Automatically insert Section Name and other information | ||||
| Description | This must be a duplicate, maybe I didn't search for the right terms.. I think it would be a useful feature for anthologies and such if you could put a text-frame into your master page and do something like Insert -> Autotext -> Section Name. It would use the name you can specify in Document Setup -> Sections, which right now has no use I know of. I would also put Page Number and Page Count there and perhaps a bunch of the things from Document Setup -> Document Information. | ||||
| Tags | #please_test | ||||
| Patch | |||||
|
|
+1 I would also like autotexts like creation date printing date Thank you |
|
|
Here’s my attempt | `section-name-field-v1.01.patch` Add dynamic Section Name field - Adds Section Name as a page-dependent dynamic text field. - Resolves the value from Document Setup → Sections for the page currently being laid out. - Works in normal text frames and on Master Pages, including different section names across pages sharing the same master. - Adds Insert → Fields → Section Name, alongside Page Number and Number of Pages. - Adds Story Editor support, using `§` as the editing place-holder. - Serializes explicitly as `<var name="sectionname">`. - Hardens variable loading so unknown `<var>` names no longer fall through to Page Count. - Includes Section Name in master-page font/glyph collection so dynamically generated glyphs are preserved in PDF export. - Reuses existing section-layout invalidation, so changing a section name updates existing fields automatically. - Also fixes the existing Story Editor inconsistency where Number of Pages did not use its `%` place holder on insertion. - No changes to section storage or section-range behaviour. section-name-field-v1.01.patch (14,912 bytes)
Index: scribus/text/specialchars.h
===================================================================
--- scribus/text/specialchars.h (revision 27829)
+++ scribus/text/specialchars.h (working copy)
@@ -50,6 +50,7 @@
static QChar ZWJ;
static QChar PAGENUMBER;
static QChar PAGECOUNT;
+ static QChar SECTIONNAME;
static QChar BLANK;
static bool isBreak(QChar c, bool includeColBreak = true);
Index: scribus/text/specialchars.cpp
===================================================================
--- scribus/text/specialchars.cpp (revision 27829)
+++ scribus/text/specialchars.cpp (working copy)
@@ -42,6 +42,8 @@
QChar SpecialChars::ZWJ = QChar(0x200D);
QChar SpecialChars::PAGENUMBER = QChar(30);
QChar SpecialChars::PAGECOUNT = QChar(23);
+// Internal expansion token for the current section name.
+QChar SpecialChars::SECTIONNAME = QChar(22);
QChar SpecialChars::BLANK = QChar(32); // SPACE is some macro on my machine - av
Index: scribus/sctextstruct.h
===================================================================
--- scribus/sctextstruct.h (revision 27829)
+++ scribus/sctextstruct.h (working copy)
@@ -96,7 +96,8 @@
PageRef,
Lookup, // generic lookup
SectionRef,
- MarkCE // deprecated
+ MarkCE, // deprecated
+ SectionName
} ;
ExpansionPoint(ExpansionType t) : m_type(t) {}
Index: scribus/text/storytext.cpp
===================================================================
--- scribus/text/storytext.cpp (revision 27829)
+++ scribus/text/storytext.cpp (working copy)
@@ -1108,7 +1108,10 @@
bool StoryText::hasExpansionPoint(int pos) const
{
- return text(pos) == SpecialChars::PAGENUMBER || text(pos) == SpecialChars::PAGECOUNT || hasMark(pos);
+ return text(pos) == SpecialChars::PAGENUMBER ||
+ text(pos) == SpecialChars::PAGECOUNT ||
+ text(pos) == SpecialChars::SECTIONNAME ||
+ hasMark(pos);
}
@@ -1116,8 +1119,10 @@
{
if (text(pos) == SpecialChars::PAGENUMBER)
return ExpansionPoint(ExpansionPoint::PageNumber);
- if( text(pos) == SpecialChars::PAGECOUNT)
+ if (text(pos) == SpecialChars::PAGECOUNT)
return ExpansionPoint(ExpansionPoint::PageCount);
+ if (text(pos) == SpecialChars::SECTIONNAME)
+ return ExpansionPoint(ExpansionPoint::SectionName);
if (hasMark(pos))
return ExpansionPoint(mark(pos));
return ExpansionPoint(ExpansionPoint::Invalid);
@@ -2307,6 +2312,8 @@
pageno.insert("name", "pgno");
Xml_attr pageco;
pageco.insert("name", "pgco");
+ Xml_attr sectionName;
+ sectionName.insert("name", "sectionname");
handler.begin(elemtag, empty);
defaultStyle().saxx(handler, "defaultstyle");
@@ -2331,6 +2338,7 @@
curr == SpecialChars::FRAMEBREAK ||
curr == SpecialChars::PAGENUMBER ||
curr == SpecialChars::PAGECOUNT ||
+ curr == SpecialChars::SECTIONNAME ||
curr.unicode() < 32 ||
(0xd800 <= curr.unicode() && curr.unicode() < 0xe000) ||
curr.unicode() == 0xfffe || curr.unicode() == 0xffff ||
@@ -2436,6 +2444,10 @@
{
handler.beginEnd("var", pageco);
}
+ else if (curr == SpecialChars::SECTIONNAME)
+ {
+ handler.beginEnd("var", sectionName);
+ }
else if (curr.unicode() < 32 ||
(0xd800 <= curr.unicode() && curr.unicode() < 0xe000) ||
curr.unicode() == 0xfffe || curr.unicode() == 0xffff)
@@ -2523,10 +2535,13 @@
obj->insertChars(-1, QChar(parseUInt(Xml_data(code))));
else if (tag == "var" && name != attr.end())
{
- if (Xml_data(name) == "pgno")
+ const Xml_string varName = Xml_data(name);
+ if (varName == "pgno")
obj->insertChars(-1, SpecialChars::PAGENUMBER);
- else
+ else if (varName == "pgco")
obj->insertChars(-1, SpecialChars::PAGECOUNT);
+ else if (varName == "sectionname")
+ obj->insertChars(-1, SpecialChars::SECTIONNAME);
}
else
obj->insertChars(-1, chr);
Index: scribus/text/textcontext.cpp
===================================================================
--- scribus/text/textcontext.cpp (revision 27829)
+++ scribus/text/textcontext.cpp (working copy)
@@ -65,6 +65,15 @@
return "%";
return QString("%1").arg(getStringFromSequence(doc->sections()[key].type, doc->sections()[key].toindex - doc->sections()[key].fromindex + 1));
}
+ case ExpansionPoint::SectionName:
+ if (m_frame->OwnPage != -1)
+ {
+ int pageNumber = m_frame->OwnPage;
+ if (!m_frame->OnMasterPage.isEmpty() && m_frame->OwnPage >= doc->DocPages.count())
+ pageNumber = 0;
+ return doc->getSectionNameForPageIndex(pageNumber);
+ }
+ return QString::fromUtf8("§");
case ExpansionPoint::MarkCE:
{
Mark* mark = expansion.getMark();
Index: scribus/actionmanager.cpp
===================================================================
--- scribus/actionmanager.cpp (revision 27829)
+++ scribus/actionmanager.cpp (working copy)
@@ -1105,6 +1105,8 @@
actionMap->insert(name, new ScrAction(defaultKey(name), actionParent, SpecialChars::PAGENUMBER.unicode()));
name = "unicodePageCount";
actionMap->insert(name, new ScrAction(defaultKey(name), actionParent, SpecialChars::PAGECOUNT.unicode()));
+ name = "unicodeSectionName";
+ actionMap->insert(name, new ScrAction(defaultKey(name), actionParent, SpecialChars::SECTIONNAME.unicode()));
//Spaces
name = "unicodeSpaceEN";
actionMap->insert(name, new ScrAction(defaultKey(name), actionParent, 0x2002));
@@ -1207,7 +1209,7 @@
//Spaces and special characters
*actionNamesList << "unicodeZWNJ" << "unicodeZWJ";
- *actionNamesList << "unicodeSoftHyphen" << "unicodeNonBreakingHyphen" << "unicodeNonBreakingSpace" << "unicodeNarrowNoBreakSpace" << "unicodePageNumber" << "unicodePageCount";
+ *actionNamesList << "unicodeSoftHyphen" << "unicodeNonBreakingHyphen" << "unicodeNonBreakingSpace" << "unicodeNarrowNoBreakSpace" << "unicodePageNumber" << "unicodePageCount" << "unicodeSectionName";
*actionNamesList << "unicodeSpaceEN" << "unicodeSpaceEM" << "unicodeSpaceThin" << "unicodeSpaceThick" << "unicodeSpaceMid" << "unicodeSpaceHair";
//Breaks
*actionNamesList << "unicodeNewLine" << "unicodeFrameBreak" << "unicodeColumnBreak" << "unicodeZerowidthSpace";
@@ -1484,6 +1486,7 @@
{
int charCode = (*actionMap)[*it]->actionInt();
if (charCode == -1 ||
+ charCode == SpecialChars::SECTIONNAME.unicode() ||
charCode == 23 ||
charCode == 24 ||
charCode == 26 ||
@@ -1947,6 +1950,7 @@
(*actionMap)["unicodeNarrowNoBreakSpace"]->setTexts( tr("Narrow No-Break Space"));
(*actionMap)["unicodePageNumber"]->setText( tr("Page &Number"));
(*actionMap)["unicodePageCount"]->setText( tr("Number of Pages"));
+ (*actionMap)["unicodeSectionName"]->setText( tr("Section Name"));
(*actionMap)["unicodeNewLine"]->setText( tr("New Line"));
(*actionMap)["unicodeFrameBreak"]->setText( tr("Frame Break"));
(*actionMap)["unicodeColumnBreak"]->setText( tr("Column Break"));
@@ -2341,6 +2345,7 @@
<< "unicodeNarrowNoBreakSpace"
<< "unicodePageNumber"
<< "unicodePageCount"
+ << "unicodeSectionName"
<< "unicodeNewLine"
<< "unicodeFrameBreak"
<< "unicodeColumnBreak"
@@ -2391,6 +2396,7 @@
<< "unicodeNarrowNoBreakSpace"
<< "unicodePageNumber"
<< "unicodePageCount"
+ << "unicodeSectionName"
<< "unicodeNewLine"
<< "unicodeFrameBreak"
<< "unicodeColumnBreak";
@@ -2603,6 +2609,7 @@
itnmenua->second << "unicodeNarrowNoBreakSpace";
itnmenua->second << "unicodePageNumber";
itnmenua->second << "unicodePageCount";
+ itnmenua->second << "unicodeSectionName";
itnmenua->second << "unicodeNewLine";
itnmenua->second << "unicodeFrameBreak";
itnmenua->second << "unicodeColumnBreak";
@@ -2652,6 +2659,7 @@
itnmenua->second << "unicodeNonBreakingSpace";
itnmenua->second << "unicodePageNumber";
itnmenua->second << "unicodePageCount";
+ itnmenua->second << "unicodeSectionName";
itnmenua->second << "unicodeNewLine";
itnmenua->second << "unicodeLigature_ff";
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 27829)
+++ scribus/scribus.cpp (working copy)
@@ -1160,10 +1160,14 @@
scrMenuMgr->addMenuItemString("SEPARATOR", "Insert");
scrMenuMgr->addMenuItemString("insertGlyph", "Insert");
+ scrMenuMgr->createMenu("InsertFields", tr("&Fields"), "Insert");
+ scrMenuMgr->addMenuItemString("InsertFields", "Insert");
+ scrMenuMgr->addMenuItemString("unicodePageNumber", "InsertFields");
+ scrMenuMgr->addMenuItemString("unicodePageCount", "InsertFields");
+ scrMenuMgr->addMenuItemString("unicodeSectionName", "InsertFields");
+
scrMenuMgr->createMenu("InsertChar", tr("&Character"), "Insert");
scrMenuMgr->addMenuItemString("InsertChar", "Insert");
- scrMenuMgr->addMenuItemString("unicodePageNumber", "InsertChar");
- scrMenuMgr->addMenuItemString("unicodePageCount", "InsertChar");
scrMenuMgr->addMenuItemString("unicodeSoftHyphen", "InsertChar");
scrMenuMgr->addMenuItemString("unicodeNonBreakingHyphen", "InsertChar");
scrMenuMgr->addMenuItemString("unicodeZWJ", "InsertChar");
Index: scribus/ui/storyeditor.cpp
===================================================================
--- scribus/ui/storyeditor.cpp (revision 27829)
+++ scribus/ui/storyeditor.cpp (working copy)
@@ -763,6 +763,7 @@
ch == SpecialChars::OBJECT ||
ch == SpecialChars::PAGENUMBER ||
ch == SpecialChars::PAGECOUNT ||
+ ch == SpecialChars::SECTIONNAME ||
ch == SpecialChars::NBSPACE ||
ch == SpecialChars::FRAMEBREAK ||
ch == SpecialChars::COLBREAK ||
@@ -794,6 +795,12 @@
insertPlainText("%");
setColor(false);
}
+ else if (ch == SpecialChars::SECTIONNAME)
+ {
+ setColor(true);
+ insertPlainText(QString::fromUtf8("§"));
+ setColor(false);
+ }
else if (ch == SpecialChars::NBSPACE)
{
setColor(true);
@@ -1737,10 +1744,13 @@
seMenuMgr->addMenuItemString("settingsSmartTextSelection", "Edit");
seMenuMgr->createMenu("Insert", tr("&Insert"));
seMenuMgr->addMenuItemString("insertGlyph", "Insert");
+ seMenuMgr->createMenu("InsertFields", tr("&Fields"), "Insert");
+ seMenuMgr->addMenuItemString("InsertFields", "Insert");
+ seMenuMgr->addMenuItemString("unicodePageNumber", "InsertFields");
+ seMenuMgr->addMenuItemString("unicodePageCount", "InsertFields");
+ seMenuMgr->addMenuItemString("unicodeSectionName", "InsertFields");
seMenuMgr->createMenu("InsertChar", tr("Character"), "Insert");
seMenuMgr->addMenuItemString("InsertChar", "Insert");
- seMenuMgr->addMenuItemString("unicodePageNumber", "InsertChar");
- seMenuMgr->addMenuItemString("unicodePageCount", "InsertChar");
seMenuMgr->addMenuItemString("unicodeSoftHyphen", "InsertChar");
seMenuMgr->addMenuItemString("unicodeNonBreakingHyphen", "InsertChar");
seMenuMgr->addMenuItemString("unicodeZWJ", "InsertChar");
@@ -3392,6 +3402,16 @@
setColor = true;
guiInsertString = "#";
}
+ if (unicodevalue == seActions["unicodePageCount"]->actionInt())
+ {
+ setColor = true;
+ guiInsertString = "%";
+ }
+ if (unicodevalue == seActions["unicodeSectionName"]->actionInt())
+ {
+ setColor = true;
+ guiInsertString = QString::fromUtf8("§");
+ }
if (unicodevalue == seActions["unicodeNonBreakingSpace"]->actionInt())
{
setColor = true;
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp (revision 27829)
+++ scribus/scribusdoc.cpp (working copy)
@@ -4494,24 +4494,24 @@
UsedGlyphsPainter p(usedFonts);
it->textLayout.render(&p);
- // Process page numbers and page count special characters on master pages
+ // Process page-dependent expansion points on master pages
if (!it->OnMasterPage.isEmpty())
{
- bool hasPageNumbers = false;
+ bool hasPageDependentExpansion = false;
int start = it->isTextFrame() ? it->firstInFrame() : 0;
int stop = it->isTextFrame() ? it->lastInFrame() + 1 : it->itemText.length();
for (int e = start; e < stop; ++e)
{
QChar chr = it->itemText.text(e);
- if ((chr == SpecialChars::PAGENUMBER) || (chr == SpecialChars::PAGECOUNT))
+ if ((chr == SpecialChars::PAGENUMBER) || (chr == SpecialChars::PAGECOUNT) || (chr == SpecialChars::SECTIONNAME))
{
- hasPageNumbers = true;
+ hasPageDependentExpansion = true;
break;
}
}
- if (hasPageNumbers)
+ if (hasPageDependentExpansion)
{
it->savedOwnPage = it->OwnPage;
int docPageCount = DocPages.count();
Index: scribus/plugins/fileloader/scribus171format/scribus171format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format.cpp (revision 27829)
+++ scribus/plugins/fileloader/scribus171format/scribus171format.cpp (working copy)
@@ -5866,15 +5866,24 @@
}
else if (tName == QLatin1String("var"))
{
- CharStyle newStyle;
- if (tAtt.value("name") == QLatin1String("pgno"))
- story.insertChars(story.length(), SpecialChars::PAGENUMBER);
- else
- story.insertChars(story.length(), SpecialChars::PAGECOUNT);
- readCharacterStyleAttrs(doc, tAtt, newStyle);
- story.setCharStyle(story.length() - 1, 1, newStyle);
- lastStyle->StyleStart = story.length() - 1;
- lastStyle->Style = newStyle;
+ QChar variableChar;
+ const auto variableName = tAtt.value("name");
+ if (variableName == QLatin1String("pgno"))
+ variableChar = SpecialChars::PAGENUMBER;
+ else if (variableName == QLatin1String("pgco"))
+ variableChar = SpecialChars::PAGECOUNT;
+ else if (variableName == QLatin1String("sectionname"))
+ variableChar = SpecialChars::SECTIONNAME;
+
+ if (!variableChar.isNull())
+ {
+ CharStyle newStyle;
+ story.insertChars(story.length(), variableChar);
+ readCharacterStyleAttrs(doc, tAtt, newStyle);
+ story.setCharStyle(story.length() - 1, 1, newStyle);
+ lastStyle->StyleStart = story.length() - 1;
+ lastStyle->Style = newStyle;
+ }
}
if (tName == QLatin1String("MARK"))
Index: scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (revision 27829)
+++ scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (working copy)
@@ -1876,6 +1876,7 @@
ch == SpecialChars::FRAMEBREAK ||
ch == SpecialChars::PAGENUMBER ||
ch == SpecialChars::PAGECOUNT ||
+ ch == SpecialChars::SECTIONNAME ||
ch == SpecialChars::NBHYPHEN ||
ch == SpecialChars::NBSPACE ||
ch == SpecialChars::ZWNBSPACE ||
@@ -1962,6 +1963,12 @@
docu.writeAttribute("name", "pgco");
putCStyle(docu, lastStyle);
}
+ else if (ch == SpecialChars::SECTIONNAME)
+ {
+ docu.writeEmptyElement("var");
+ docu.writeAttribute("name", "sectionname");
+ putCStyle(docu, lastStyle);
+ }
else if (ch.unicode() < 32 ||
(0xd800 <= ch.unicode() && ch.unicode() < 0xe000) ||
ch.unicode() == 0xfffe || ch.unicode() == 0xffff)
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2011-04-17 19:36 | DooFi | New Issue | |
| 2017-01-11 10:10 | harinezumi | Note Added: 0043322 | |
| 2026-09-13 04:00 | buttar | Note Added: 0054462 | |
| 2026-09-13 04:00 | buttar | File Added: section-name-field-v1.01.patch | |
| 2026-09-13 04:00 | buttar | Tag Attached: #please_test |