https://wiki.scribus.net/wiki/api.php?action=feedcontributions&user=Gpittman&feedformat=atom
Scribus Wiki - User contributions [en]
2024-03-29T15:55:15Z
User contributions
MediaWiki 1.39.1
https://wiki.scribus.net/wiki/index.php?title=Shrinking_a_PDF_from_the_command_line&diff=34609
Shrinking a PDF from the command line
2020-04-13T19:56:13Z
<p>Gpittman: /* ps2pdf */</p>
<hr />
<div>This is a simplified version of the method used in [[Web optimised PDF]].<br />
<br />
That article shows a Perl script, a rather long one at that, to accomplish the task. The actual shrinkage is accomplished by the use of '''pdf2ps''' and '''ps2pdf''', which are utilities which come with ghostscript.<br />
<br />
My reading of the man page for '''pdf2ps''' and a [http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm web reference for '''ps2pdf'''] suggest that the first step, converting to a PostScript file, does not involve any compression. It is only in the conversion back to PDF that various settings allow for shrinking the size of the resulting file.<br />
<br />
===pdf2ps===<br />
Let's say you have a file, '''myfile.pdf''', created by Scribus. About the only setting in '''pdf2ps''' to consider is the language level,<br />
<pre><br />
pdf2ps -dLanguageLevel=3 myfile.pdf<br />
</pre><br />
<br />
which will create '''myfile.ps''', and will be larger than the original PDF.<br />
<br />
===ps2pdf===<br />
On the return trip, there are many settings to consider, but for simplicity's sake you might try using just one:<br />
<pre><br />
ps2pdf -dPDFSETTINGS=/ebook myfile.ps<br />
</pre><br />
Or, to avoid deleting your original '''myfile.pdf''', you might put:<br />
<pre><br />
ps2pdf -dPDFSETTINGS=/ebook -sOutputFile=myshrunkenfile.pdf myfile.ps<br />
</pre><br />
The '''-dPDFSETTINGS''' option has a number of prebuilt subsettings which you will find on the above referenced webpage. Choices are '''/screen''', '''/ebook''', '''/prepress''', and '''/printer'''. I think you will find that using the '''/ebook''' value will give a very good compression, but better resolution than using '''/screen'''.<br />
<br />
If you go to the reference page, you will see a ''very'' large number of other choices for things such as image compression that you may wish to try out, but just using the '''/screen''' setting for an example 126KB file produced a 594KB PostScript file, then a final PDF of only 21KB, so only about 1/6 the size of the original. As always, check the quality of the final to see if it's adequate for your needs.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Setting_Text_Distances_from_a_Script&diff=34587
Setting Text Distances from a Script
2019-12-17T22:30:08Z
<p>Gpittman: /* settextdistance.py */</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the '''value.Dialog()'''.<br />
==settextdistance.py==<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of the selected text frame<br />
<br />
USAGE<br />
<br />
Select a text frame, run script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print ("Unable to import the 'scribus' module. This script will only run within")<br />
print ("the Python interpreter embedded in Scribus. Try Script->Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error',<br />
"There is no object selected.\nPlease select a text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Script Error',<br />
"You have more than one object selected.\nPlease select one text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
distance = scribus.valueDialog("Text Distance", 'Enter your text distance', '10')<br />
distance = float(distance)<br />
distanceleft = distance<br />
distanceright = distance<br />
distancetop = distance<br />
distancebottom = distance<br />
<br />
textbox = scribus.getSelectedObject()<br />
pageitems = scribus.getPageItems()<br />
scribus.setRedraw(False)<br />
<br />
for item in pageitems:<br />
if (item[0] == textbox):<br />
if (item[1] != 4):<br />
scribus.messageBox('Scribus - Script Error', <br />
"This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==More complex but more versatile==<br />
What if we didn't want all the distances to be the same? Look at this modification of the distance '''value.Dialog()''', and subsequent lines:<br />
<syntaxhighlight lang='python'><br />
distances = scribus.valueDialog("Text Distance", 'Enter your text distances,\n white space in between.\nLeft Right Top Bottom', '10 10 10 10')<br />
distance = distances.split()<br />
distanceleft = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancetop = float(distance[2])<br />
distancebottom = float(distance[3])<br />
</syntaxhighlight><br />
We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the '''setTextDistances()''' command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.<br />
<br />
I could save some lines by doing this:<br />
<syntaxhighlight lang='python'><br />
scribus.setTextDistances = (float(distance[0]), float(distance[1]), float(distance[2]), float(distance[3]))<br />
</syntaxhighlight><br />
but this makes later review, editing, and understanding of the script more difficult.<br />
<br />
==Oh yes, there's some ''voodoo'' here too!==<br />
Look at these lines:<br />
<syntaxhighlight lang='python'><br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
</syntaxhighlight><br />
I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the '''redrawAll()''' command, think again. I tried various combinations of '''setRedraw(True/False)''', and nothing worked. <br />
<br />
What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! ''It just works.''<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<pre><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
setmultiframetextdistances.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</pre></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Setting_Text_Distances_from_a_Script&diff=34586
Setting Text Distances from a Script
2019-12-17T19:16:49Z
<p>Gpittman: /* A new version */</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the '''value.Dialog()'''.<br />
==settextdistance.py==<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of the selected text frame<br />
<br />
USAGE<br />
<br />
Select a text frame, run script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error',<br />
"There is no object selected.\nPlease select a text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Script Error',<br />
"You have more than one object selected.\nPlease select one text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
distance = scribus.valueDialog("Text Distance", 'Enter your text distance', '10')<br />
distance = float(distance)<br />
distanceleft = distance<br />
distanceright = distance<br />
distancetop = distance<br />
distancebottom = distance<br />
<br />
textbox = scribus.getSelectedObject()<br />
pageitems = scribus.getPageItems()<br />
scribus.setRedraw(False)<br />
<br />
for item in pageitems:<br />
if (item[0] == textbox):<br />
if (item[1] != 4):<br />
scribus.messageBox('Scribus - Script Error', <br />
"This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==More complex but more versatile==<br />
What if we didn't want all the distances to be the same? Look at this modification of the distance '''value.Dialog()''', and subsequent lines:<br />
<syntaxhighlight lang='python'><br />
distances = scribus.valueDialog("Text Distance", 'Enter your text distances,\n white space in between.\nLeft Right Top Bottom', '10 10 10 10')<br />
distance = distances.split()<br />
distanceleft = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancetop = float(distance[2])<br />
distancebottom = float(distance[3])<br />
</syntaxhighlight><br />
We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the '''setTextDistances()''' command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.<br />
<br />
I could save some lines by doing this:<br />
<syntaxhighlight lang='python'><br />
scribus.setTextDistances = (float(distance[0]), float(distance[1]), float(distance[2]), float(distance[3]))<br />
</syntaxhighlight><br />
but this makes later review, editing, and understanding of the script more difficult.<br />
<br />
==Oh yes, there's some ''voodoo'' here too!==<br />
Look at these lines:<br />
<syntaxhighlight lang='python'><br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
</syntaxhighlight><br />
I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the '''redrawAll()''' command, think again. I tried various combinations of '''setRedraw(True/False)''', and nothing worked. <br />
<br />
What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! ''It just works.''<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<pre><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
setmultiframetextdistances.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</pre></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Setting_Text_Distances_from_a_Script&diff=34585
Setting Text Distances from a Script
2019-12-17T19:15:34Z
<p>Gpittman: /* A new version */</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the '''value.Dialog()'''.<br />
==settextdistance.py==<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of the selected text frame<br />
<br />
USAGE<br />
<br />
Select a text frame, run script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error',<br />
"There is no object selected.\nPlease select a text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Script Error',<br />
"You have more than one object selected.\nPlease select one text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
distance = scribus.valueDialog("Text Distance", 'Enter your text distance', '10')<br />
distance = float(distance)<br />
distanceleft = distance<br />
distanceright = distance<br />
distancetop = distance<br />
distancebottom = distance<br />
<br />
textbox = scribus.getSelectedObject()<br />
pageitems = scribus.getPageItems()<br />
scribus.setRedraw(False)<br />
<br />
for item in pageitems:<br />
if (item[0] == textbox):<br />
if (item[1] != 4):<br />
scribus.messageBox('Scribus - Script Error', <br />
"This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==More complex but more versatile==<br />
What if we didn't want all the distances to be the same? Look at this modification of the distance '''value.Dialog()''', and subsequent lines:<br />
<syntaxhighlight lang='python'><br />
distances = scribus.valueDialog("Text Distance", 'Enter your text distances,\n white space in between.\nLeft Right Top Bottom', '10 10 10 10')<br />
distance = distances.split()<br />
distanceleft = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancetop = float(distance[2])<br />
distancebottom = float(distance[3])<br />
</syntaxhighlight><br />
We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the '''setTextDistances()''' command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.<br />
<br />
I could save some lines by doing this:<br />
<syntaxhighlight lang='python'><br />
scribus.setTextDistances = (float(distance[0]), float(distance[1]), float(distance[2]), float(distance[3]))<br />
</syntaxhighlight><br />
but this makes later review, editing, and understanding of the script more difficult.<br />
<br />
==Oh yes, there's some ''voodoo'' here too!==<br />
Look at these lines:<br />
<syntaxhighlight lang='python'><br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
</syntaxhighlight><br />
I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the '''redrawAll()''' command, think again. I tried various combinations of '''setRedraw(True/False)''', and nothing worked. <br />
<br />
What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! ''It just works.''<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<pre><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</pre></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Setting_Text_Distances_from_a_Script&diff=34584
Setting Text Distances from a Script
2019-12-17T19:14:37Z
<p>Gpittman: /* Oh yes, there's some voodoo here too! */</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the '''value.Dialog()'''.<br />
==settextdistance.py==<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of the selected text frame<br />
<br />
USAGE<br />
<br />
Select a text frame, run script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error',<br />
"There is no object selected.\nPlease select a text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Script Error',<br />
"You have more than one object selected.\nPlease select one text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
distance = scribus.valueDialog("Text Distance", 'Enter your text distance', '10')<br />
distance = float(distance)<br />
distanceleft = distance<br />
distanceright = distance<br />
distancetop = distance<br />
distancebottom = distance<br />
<br />
textbox = scribus.getSelectedObject()<br />
pageitems = scribus.getPageItems()<br />
scribus.setRedraw(False)<br />
<br />
for item in pageitems:<br />
if (item[0] == textbox):<br />
if (item[1] != 4):<br />
scribus.messageBox('Scribus - Script Error', <br />
"This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==More complex but more versatile==<br />
What if we didn't want all the distances to be the same? Look at this modification of the distance '''value.Dialog()''', and subsequent lines:<br />
<syntaxhighlight lang='python'><br />
distances = scribus.valueDialog("Text Distance", 'Enter your text distances,\n white space in between.\nLeft Right Top Bottom', '10 10 10 10')<br />
distance = distances.split()<br />
distanceleft = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancetop = float(distance[2])<br />
distancebottom = float(distance[3])<br />
</syntaxhighlight><br />
We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the '''setTextDistances()''' command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.<br />
<br />
I could save some lines by doing this:<br />
<syntaxhighlight lang='python'><br />
scribus.setTextDistances = (float(distance[0]), float(distance[1]), float(distance[2]), float(distance[3]))<br />
</syntaxhighlight><br />
but this makes later review, editing, and understanding of the script more difficult.<br />
<br />
==Oh yes, there's some ''voodoo'' here too!==<br />
Look at these lines:<br />
<syntaxhighlight lang='python'><br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
</syntaxhighlight><br />
I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the '''redrawAll()''' command, think again. I tried various combinations of '''setRedraw(True/False)''', and nothing worked. <br />
<br />
What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! ''It just works.''<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<pre><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</pre><br />
<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Setting_Text_Distances_from_a_Script&diff=34583
Setting Text Distances from a Script
2019-12-17T19:13:52Z
<p>Gpittman: /* Oh yes, there's some voodoo here too! */</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
Here is a simple script for setting the text distances for a text frame. In this particular version, we set all the distances the same, so only one value is needed for the '''value.Dialog()'''.<br />
==settextdistance.py==<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of the selected text frame<br />
<br />
USAGE<br />
<br />
Select a text frame, run script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error',<br />
"There is no object selected.\nPlease select a text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Script Error',<br />
"You have more than one object selected.\nPlease select one text frame and try again.",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
distance = scribus.valueDialog("Text Distance", 'Enter your text distance', '10')<br />
distance = float(distance)<br />
distanceleft = distance<br />
distanceright = distance<br />
distancetop = distance<br />
distancebottom = distance<br />
<br />
textbox = scribus.getSelectedObject()<br />
pageitems = scribus.getPageItems()<br />
scribus.setRedraw(False)<br />
<br />
for item in pageitems:<br />
if (item[0] == textbox):<br />
if (item[1] != 4):<br />
scribus.messageBox('Scribus - Script Error', <br />
"This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==More complex but more versatile==<br />
What if we didn't want all the distances to be the same? Look at this modification of the distance '''value.Dialog()''', and subsequent lines:<br />
<syntaxhighlight lang='python'><br />
distances = scribus.valueDialog("Text Distance", 'Enter your text distances,\n white space in between.\nLeft Right Top Bottom', '10 10 10 10')<br />
distance = distances.split()<br />
distanceleft = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancetop = float(distance[2])<br />
distancebottom = float(distance[3])<br />
</syntaxhighlight><br />
We could use int(distance...), but using float allows for decimals - whatever you enter into the dialog will be a string until converted, and the '''setTextDistances()''' command needs number values. In case you haven't used the built-in split function in Python, this breaks a series of values or words into a list, eliminating the white space (which can be of variable length). So here we create the list distance[] from the 4 values. I think this is more efficient than making a series of value.Dialogs.<br />
<br />
I could save some lines by doing this:<br />
<syntaxhighlight lang='python'><br />
scribus.setTextDistances = (float(distance[0]), float(distance[1]), float(distance[2]), float(distance[3]))<br />
</syntaxhighlight><br />
but this makes later review, editing, and understanding of the script more difficult.<br />
<br />
==Oh yes, there's some ''voodoo'' here too!==<br />
Look at these lines:<br />
<syntaxhighlight lang='python'><br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
</syntaxhighlight><br />
I move the text frame, then I move it back! Doesn't make sense, does it? For whatever reason, if I didn't put these in there, Scribus wouldn't redraw the frame, and I don't know why. If you're thinking that it's because I forgot the '''redrawAll()''' command, think again. I tried various combinations of '''setRedraw(True/False)''', and nothing worked. <br />
<br />
What I found out was that if I moved the frame after the script ran, Scribus would redraw and place the text inside the distances, but then I'd have to move it back. So here the script does it, and voilà! ''It just works.''<br />
==A new version==<br />
Seth Kenlon has contributed a modified version that will set text distances on a number of selected frames. Note that this version does not check to see if all the selected frames are text frames. If they are not, you will get a WrongFrameType error.<br />
<syntaxhighlight lang="python"><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2015 by Gregory Pittman<br />
* 2019 modified by Seth Kenlon <skenlon@redhat.com> <br />
<br />
settextdistance.py<br />
<br />
Sets the text distances of selected text frames<br />
<br />
USAGE<br />
<br />
Select one or more text frames, and then run this script.<br />
A dialog asks for the amount of text distance.<br />
<br />
"""<br />
<br />
import sys<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print("Unable to import the 'scribus' module. This script only runs within the Python interpreter embedded in Scribus. Try Script → Execute Script.")<br />
sys.exit(1)<br />
<br />
if not scribus.haveDoc():<br />
scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Script Error', "Select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
# use CSS order for values (N E S W)<br />
distances = scribus.valueDialog("Text Distance", 'Enter text padding values (in current page units) delimited by white space.\nTop Right Bottom Left', '0.2 0.2 0.2 0.2')<br />
distance = distances.split()<br />
distancetop = float(distance[0])<br />
distanceright = float(distance[1])<br />
distancebottom = float(distance[2])<br />
distanceleft = float(distance[3])<br />
<br />
n = scribus.selectionCount()<br />
<br />
for i in range(0, n):<br />
textbox = scribus.getSelectedObject(i)<br />
scribus.setRedraw(False)<br />
scribus.setTextDistances(distanceleft,distanceright,distancetop,distancebottom,textbox)<br />
<br />
scribus.moveObject(-4,0,textbox)<br />
scribus.moveObject(4,0,textbox)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=34545
Building SVN versions with CMake
2019-03-15T23:11:20Z
<p>Gpittman: /* Notes on Fedora 28 &amp; 29 */</p>
<hr />
<div>{{Cleanup}}<br />
[[Category:Installation]] [[Category:Development]]<br />
<br />
This page tries to describe how to build Scribus from source.<br />
The instructions mainly refer to building Scribus on Linux. Building on Mac OS and on Windows is not easy; you can find some explanations for Mac OS [[Installing from SVN on Mac OS X|here]], and for Windows [[Building SVN versions on Windows|here]]. <br />
<br />
=TL;DR (Too Long; Didn't Read)=<br />
<big>You know what you are doing already and just want to compile Scribus via SVN, skip the introduction and go to [[{{PAGENAME}}#Version 1.5.x|Installing 1.5svn]]</big><br />
<br />
=Why would I Need or Want to 'Build' Scribus?=<br />
<big><br />
# '''For Necessity:''' You are using the current stable version, but certain bugs are a problem, and you know they have been fixed since the last release.<br />
# '''For Science:''' You have heard about some new features in the development version, and you'd like to try them out.<br />
# '''For the World:''' You're considering helping out the Scribus project and want to see how it's put together to get some idea about how you can help.<br />
</big><br />
==='Or, for that matter, what is this 'Building' you speak of?===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>Expand this content if you need a little bit more background on what Building source code means. ---></big><br />
<div class="mw-collapsible-content"><br />
<big>When you are going to build or compile Scribus, what you have downloaded (if you have downloaded the source code) is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ programming language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your computer can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your computer to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is being written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team requires the use of CMake for this configuring process. It is quick, easy to use, and easy for the developers to write for &ndash; even CMake needs instructions. You can also pass to CMake several special parameters for your particular Computer setup, for example, where you want Scribus to be installed.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.</big><br />
</div><br />
</div><br />
<br />
== Fear is the mind Killer... ==<br />
[[Image:Fear-is-the-mind-killer-Dune.png|500px|thumb|right|"Do not fear building Scribus from source" ~Paul Muad'dib Atreides]]<br />
'''There is nothing to fear here, building Scribus yourself is not as hard as it sounds'''. You will not break your computer.<br />
<br />
This page can teach a beginner many things at once: starting with beginning to comprehend the internals of Scribus to appreciating the Command Line shell and how to invoke commands through it. Learn how to install software libraries (components that Scribus utilizes) and go so far as to modify source code through applying patches. This exposure will help increase your skill set to work on most all platforms and widen your knowledge of software creation and maintenance.<br />
<br />
=1st: Download latest snapshot with Subversion=<br />
Subversion is the versioning control system used for Scribus. This allows multiple developers to hack on Scribus source code simultaneously. Check the [[Subversion]] page for further details on how to use this tool. Make sure you have svn installed. You don't need to learn all subversion commands and options: "svn co" and "svn up" might suffice, see below for examples.<br />
<br />
You should create a directory in which the Scribus source code will be downloaded. Then change to that directory, and once you are there, you can download the source code with a simple command. You have to choose which branch you will download, as shown in the table below:<br />
<br />
{| cellspacing="10" cellpadding="6"<br />
! Status !! Version !! !! SVN Path !! Command to download from SVN<br />
|-<br />
|'''Development''' || '''1.5.x''' || || /trunk/Scribus || <tt><b>svn co svn://scribus.net/trunk/Scribus scribus15</b></tt><br />
|-<br />
|'''Development Snapshot''' || '''1.5.0''' || || /trunk/Scribus revision 20099 || <tt><b>svn co -r 20099 svn://scribus.net/trunk/Scribus scribus150</b></tt><br />
|-<br />
|'''Stable''' || '''1.4.x''' || ||/branches/Version14x/Scribus || <tt><b>svn co svn://scribus.net/branches/Version14x/Scribus scribus14x</b></tt><br />
|-<br />
|Outdated || <strike>v.1.3.3x</strike> || ||<strike>/branches/Version133x/Scribus</strike> || <strike><tt><b>svn co svn://scribus.net/branches/Version13x/Scribus scribus13x</b></tt></strike><br />
|}<br />
<small>'''Important Notes:''' <br />
* All subversion URLs for Scribus anonsvn are based at: '''svn://scribus.net/'''<br />
* Updating your working copy is much the same as cvs - just cd into your working copy and run <tt><b>"svn up"</b></tt>.<br />
* There's also '''http://scribus.net/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.net/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies.<br />
* If you used to check out -r <Version>, check out <SVN Path> instead<br />
</small><br />
<br />
------<br />
<br />
'''Thanks to [http://anduin.net Anduin.net], anonymous SVN access is updated daily.'''<br />
<br />
===Example===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Here is an example of the commands for downloading the source code:<br />
<div class="mw-collapsible-content"><br />
<br />
<small>(This example is for Linux; on other platforms you should use the corresponding commands)</small><br />
<br />
Let's suppose that you want to download the Scribus 1.5.0. source code in a directory called "scribussource" under your home directory. Here are the commands:<br />
<br />
mkdir ~/scribussource<br />
cd ~/scribussource<br />
svn co svn://scribus.net/trunk/Scribus<br />
<br />
When subversion finishes downloading, you will find the source code in ~/scribussource/Scribus<br />
<br />
If you have the source code and you want to update it to the latest version:<br />
<br />
cd ~/scribussource/Scribus<br />
svn up<br />
</div></div><br />
<br />
=2nd: Install methods: Package Manager, Source, Out-of-Source Build=<br />
<br />
==Essential tools==<br />
Before going further, we must understand that in order for anything to get built, tools need to exist. In modern OS's especially Linux many of these are build tools arrive already bundled. If they aren't for some reason you will need to '''install them manually''' (see [[{{PAGENAME}}#Package Manager|package manager]])<br />
* gcc<br />
* gcc-c++<br />
* cmake (version &ge; 2.8.9)<br />
<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
<big>There are several option for installation.<br />
* [[{{PAGENAME}}#Package Managers| Package Manager]]: (difficulty: easy) Does a lot of the heavy lifiting by installing all the components you specify <br />
* [[{{PAGENAME}}#Build from Source| Build from Source]]: (difficulty: intermediate to advanced) Build it the old fashion way<br />
* [[{{PAGENAME}}#Out-of-Source-Builds| Out-of-Source-Builds]]: (difficulty: intermediate) Needs explanation<br />
</big><br />
<br />
==Package Managers==<br />
Note: many Linux distros have their own Package Managers i.e. Debian has '''apt''', Fedora and Centos have '''yum''', more recently superceded by '''dnf''', Redhat uses '''rpm''' etc... On Mac OS X there are several choices, most popular are '''Macports''' and '''Homebrew'''. In general, by utilizing the installed package manager we can streamline the installations through easy one liners which will automate the install. We do this by invoking the following pattern: <br />
<br />
<tt> <b>(package-manager) install (software-or-library-package-name)</b></tt> <br />
<br />
'''Debian'''; &nbsp;&nbsp;&nbsp;'''<code>apt-get install cmake</code>''' <br /><br />
'''Fedora''': &nbsp;&nbsp;&nbsp;'''<code>dnf install cmake</code>''' <br /><br />
'''MacOSX''':&nbsp;'''<code>brew install cmake</code>'''<br />
<br />
==Specific Dependencies== <br />
<!-- This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. --><br />
Dependencies are considered to be 3rd party software libraries or other altogether unique software projects that are have components that are needed to build a specific project from. When we want to build Scribus we need to make sure that we have all the dependencies fulfilled or else it will complain to us about missing components or obsolete ones. The following section assumes you need to manually install dependencies. Here are the list of package names that will be needed to be installed before attempting to build Scribus. Each major version of Scribus will require different dependencies.<br />
<br />
===Version 1.5.x===<br />
Here is a list of dependencies for Scribus 1.5.x:<br />
<br />
Qt (version >= 5.2; see below for details)<br />
Cairo<br />
Pixman<br />
Boost<br />
Cups (not required on Windows)<br />
Fontconfig (not required on Windows)<br />
Freetype<br />
Libhunspell (if missing, spellchecker won't work)<br />
Libjpeg<br />
Libtiff<br />
Libxml2<br />
LittleCMS (version >= 2.1)<br />
Pkgconfig (Linux)<br />
PoDoFo<br />
Poppler, Poppler-data, and Poppler-cpp<br />
Python 2.7<br />
Python-Pillow<br />
Tk and Tkinter (required by some scripts shipped with Scribus)<br />
<br />
For Scribus 1.5.3+<br />
Harfbuzz<br />
ICU (UC module)<br />
Qt 5.5+<br />
<br />
For Scribus 1.5.5+<br />
Qt 5.7+<br />
C++11<br />
<br />
On Linux, for each item you have to install both the main package and the development package (for example: cairo and cairo-devel, pixman and pixman-devel, and so on). Some packages should be already installed (for example, Cairo or CUPS).<br />
<br />
====Getting and installing Qt5====<br />
Starting with rev. 19790 (4 February 2015), Qt 5.2 or later is required.<br />
<br />
If Qt5 is not present on your system, you have to install or build it.<br />
<br />
You can download Qt5 from http://qt-project.org/downloads. Binary installers are available for Windows, Mac&nbsp;OS X and Linux. For Linux, if your distribution provides the latest Qt5, you can install it from its repositories (details for some distributions are listed below).<br />
<br />
Also available is the source code, in case you want to build Qt5 yourself, or if an installer is not available for your operating system.<br />
<br />
If you're using the Qt installer on Linux, make sure to make the file <code>qt-opensource-linux-x**-5.*.*.run</code> executable. You can do this via your chosen UI or the command line. The latter requires the following commands:<br />
<br />
<code>chmode +x /path/to/qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
To start the installation process, use the <code>cd</code> command to move into the installer's directory.<br />
<br />
Next, run the following command:<br />
<br />
<code>./qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
If run without root privileges, the installer will suggest /home/username/Qt5.* as the installation directory. That's fine if you only want to test Scribus 1.5.x. If you also want to test the latest versions of other programmes using Qt5, you should install Qt5 with root privileges.<br />
<br />
If you have Qt4 and Qt5 installed, and/or cmake does not find Qt5, you need to specify its location with the [[CMake_Build_Options#Qt5-Specific|build option]] -DQT_PREFIX="path-to-Qt5" (for example: -DQT_PREFIX="/home/user/Qt/5.1.1/gcc/")<br />
<br />
In case you need a list, the required qt5 libs are : <br />
Qt5Core<br />
Qt5Widgets<br />
Qt5Gui<br />
Qt5Xml<br />
Qt5WebKit<br />
Qt5WebKitWidgets<br />
Qt5Network<br />
Qt5OpenGL<br />
Qt5LinguistTools<br />
Qt5Quick<br />
Qt5PrintSupport<br />
<br />
In case you got problems, Pygmee suggests too : "it build here after i've build sigil where it make a bit changes in QT5 config".<br />
<br />
=====Debian=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
On Debian Testing, on top of the packages pulled in by apt-get build-dep you need. ----><br />
<div class="mw-collapsible-content"><br />
'''sudo apt install libqt5webkit5-dev qtquick1-5-dev qtdeclarative5-dev \'''<br />
'''qttools5-dev-tools qttools5-dev liblcms2-dev'''<br />
'''sudo apt install libpoppler-private-dev''' (3)<br />
Note 1: They are all available in the official Debian repositories.<br />
Note 2: This list should also apply for the latest Ubuntu release.<br />
Note 3: Needed since Ubuntu-16.04 and its derivatives like Linux Mint.<br />
</div></div><br />
<br />
=====Fedora 19 and later=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Fedora 19 and later have Qt5 packages available from their repositories. The requirements seem to be ----><br />
<div class="mw-collapsible-content"><br />
'''yum install qt5-qtbase qt5-qtbase-devel qt5-qtdeclarative qt5-qtdeclarative-devel qt5-qttools \'''<br />
'''qt5-qttools-devel qt5-qtwebkit qt5-qtwebkit-devel qt5-qtbase-static'''<br />
<br />
The above list will bring in '''qt5-qtbase-gui''' and possibly some other packages as dependencies. You might need also to install '''glibc-headers'''.<br />
</div></div><br />
=====Notes on Fedora 28 &amp; 29=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
This will probably also work for Fedora 24 to 27 ----><br />
<div class="mw-collapsible-content"><br />
Fedora now uses '''dnf''' instead of '''yum''' for package management. Using the following command will supply all the needed requirements for Scribus 1.5.x (note that some are optional features, such as OpenSceneGraph). <br />
<br />
'''sudo dnf -y install boost-devel cairo-devel cups-devel fontconfig-devel freetype-devel GraphicsMagick-c++-devel GraphicsMagick-devel harfbuzz-devel hunspell-devel kernel-devel lcms2-devel libfreehand-devel libicu-devel libjpeg-turbo-devel libmspub-devel libpagemaker-devel libpng-devel libqxp-devel librevenge-devel libstdc++-devel libtiff-devel libvisio-devel libwpd-devel libxml2-devel libzmf-devel OpenSceneGraph-devel podofo-devel poppler-devel poppler-data poppler-data-devel poppler-cpp poppler-cpp-devel python-devel python-qt5-devel qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qttools-devel qt5-qtwebkit-devel'''<br />
<br />
Even though all of these are just the -devel packages, dnf will pull in all necessary additional requirements. Note that '''poppler-cpp''' and '''poppler-cpp-devel''' seem to be new requirements.<br />
</div><br />
</div><br />
<br />
=====Ubuntu=====<br />
<br />
'''Firstly, if you are running Ubuntu with version < 15.10, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.04 ----><br />
<div class="mw-collapsible-content"><br />
* Initially install:<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev qttools5'''<br />
* Then, specifically relating to qt5, install: <br />
'''sudo apt-get install libqt5declarative5-dev qtlocation5-dev qtsensors5-dev''' <br />
* Install the usual libs '''not''' related to qt5 : <br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.10 ----><br />
<div class="mw-collapsible-content"><br />
Almost the same as 13.04 except '''no qttools5''' and '''no libqt5declarative5-dev''' instead '''use qtdeclarative5-dev''' <br />
<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev'''<br />
'''sudo apt-get install qtdeclarative5-dev qtlocation5-dev qtsensors5-dev'''<br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
<br />
# Note 1: There are bugs with qt5 version 5.0.2. Install qt5 version 5.2 with the installer found on https://qt-project.org/downloads. <br />
# Note 2: (JLuc, 25 May 2014): I followed this procedure step by step and everything when right out of the box.<br />
# Note 3 (unknown author) : In addition, I had to install: libgl1-mesa-dev and dependencies.<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v14.04 ----><br />
<div class="mw-collapsible-content"><br />
This is how i compiles scribus 1.5 on a quite freshly installed Ubuntu 14.04 :<br />
# Install scribus 1.5 out of the scribus friend's PPA (https://launchpad.net/~scribus/+archive/ubuntu/ppa). There are too many keyboard management bugs with this version, but it maybe installs some usefull libraries. Then uninstall it.<br />
# Install cmake, g++ and subversion in case there are not there allready ("sudo apt-get install cmake" and "sudo apt-get install subversion")<br />
# Install (using synaptics or sudo apt-get) the following libraries and their dependancies : libdrm-dev, libgl1-mesa-dev, libxml2-dev, libzip-dev, libfreetype6-dev, liblcms2-dev, libpodofo-dev, libcairo2-dev, libmagick++dev (maybe useless), libgraphicsmagick++1-dev, libcups2-dev, libpython2.7-dev, libpoppler-qt5-dev (maybe useless), libpoppler-cpp-dev, libpoppler-private-dev, libhunspell-dev<br />
# Compile using maksvn script (https://github.com/JLuc/makscribus/blob/master/maksvn).<br />
That's it !<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v16.04 ----><br />
<div class="mw-collapsible-content"><br />
To compile scribus 1.5 on ubuntu 16.04, you need to follow:<br />
# make sure that you installed QT as mention above.<br />
# executed the the following commands to install required libraries:<br />
'''<code> sudo apt-get update -qq;</code>''' <br /><br />
'''<code> sudo apt-get install --force-yes cmake libboost-python-dev libcups2-dev libhunspell-dev libhyphen-dev liblcms2-dev libpodofo-dev libtiff-dev libxml2-dev python-all-dev zlib1g-dev libgraphicsmagick++1-dev libopenscenegraph-dev libpoppler-dev libpoppler-private-dev libcairo2-dev libwpg-dev libmspub-dev libcdr-dev libvisio-dev libharfbuzz-dev libharfbuzz-icu0 coreutils binutils python-tk</code>'''<br />
<br />
</div></div><br />
<br />
=====OpenSuse=====<br />
'''Firstly, if you are running OpenSUSE with version < 13.2, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
13.2 or newer ----><br />
<div class="mw-collapsible-content"><br />
* Install the OS<br />
* install Qt5 - sudo zypper in -t devel_qt5<br />
* Install these packages via Yast2 or 'zypper in' from the command line:<br />
python-devel <br />
cairo-devel<br />
hunspell-devel<br />
cmake<br />
subversion<br />
cups-devel <br />
libtiff-devel<br />
liblcms2-devel<br />
cups-devel<br />
boost-devel<br />
libjpeg8-devel<br />
libtiff-devel<br />
libpodofo-devel<br />
libpoppler-devel<br />
librevenge-devel<br />
libcdr-devel<br />
libmspub-devel<br />
libvisio-devel<br />
libfreehand-devel<br />
* Proceed with Scribus compilation process.<br />
</div></div><br />
<br />
=====Windows=====<br />
Please refer to [[Building_SVN_versions_on_Windows]]<br />
<br />
=====Mac OSX=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
MacPorts (recommended by Scribus core-devs) ----><br />
<div class="mw-collapsible-content"><br />
Needs details<br />
</div></div><br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Homebrew Package Manager (Scribus community supported effort) ----><br />
<div class="mw-collapsible-content"><br />
FYI, please don't post homebrew bugs on the bugtracker. Instead read the top notice on [[Scribus_and_Homebrew]].<br />
'''1. brew tap scribusproject/scribus'''<br />
'''2. brew install --HEAD scribus --verbose'''<br />
'''3. brew linkapps --local scribus'''<br />
'''4. Invoke with: ~/Applications/Scribus.app/Contents/MacOS/Scribus'''<br />
</div></div><br />
<br />
===Additional dependencies for some graphics formats===<br />
In 1.5.0+, there are a number of vector and bitmap graphics formats which can now be imported into Scribus. Some of these have particular additional dependencies.<br />
<br />
====GraphicsMagick (Optional)====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added import filters will be available if you have it (and cmake will detect it automatically). What Scribus needs are the following packages: graphicsmagick, graphicsmagick-devel, graphicsmagick-c++, and graphicsmagick-c++-devel.<br />
<br />
====OpenSceneGraph (Optional)====<br />
This may be available with your Linux distribution (definitely for Fedora 17 and later). You can also [http://www.openscenegraph.org/projects/osg/wiki/Downloads download and compile] yourself.<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''Fedora'''<br />
<div class="mw-collapsible-content"><br />
'''sudo yum install OpenSceneGraph OpenSceneGraph-devel'''<br />
<br />
should be enough, and will get you the additional requirements of Inventor, OpenThreads, and OpenThreads-devel.<br />
</div></div><br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''OpenSUSE'''<br />
<div class="mw-collapsible-content"><br />
go to http://software.opensuse.org/package/OpenSceneGraph and use the 1-click install procedure.<br />
</div></div><br />
====MS Publisher and WPG Importers====<br />
<br />
To build Scribus with support for MS Publisher and WPG files, you need [http://cgit.freedesktop.org/libreoffice/libmspub/ libmspub], as well as [http://libwpg.sourceforge.net/ libwpg] and [http://libwpd.sourceforge.net/ libwpd]. Note that the minimum version for PUB import is libmspub 0.0.6, and also that you want the development packages (libwpd-devel, libwpg-devel, libmspub-devel, for example in Fedora).<br />
<br />
Update (June 2014): Scribus is now able to import MS Publisher, MS Visio and CorelDraw documents via librevenge. See [[Librevenge|this page]] for details.<br />
<br />
===Scribus 1.4.x===<br />
One method for obtaining and then building Scribus is to download the compressed tar file, for example from [https://sourceforge.net/projects/scribus/files/scribus/1.4.6/ https://sourceforge.net/projects/scribus/files/scribus/1.4.6/].<br />
<br />
Let's imagine you choose the one compressed with 7-zip, which is scribus-1.4.6.7z. Click the link to download, then on the command line go to the directory where it was saved (perhaps Downloads/). To extract this, type<br />
<pre><br />
7z x scribus-1.4.6.7z<br />
</pre><br />
which will create the directory '''scribus-1.4.6''', and inside this will be all the ingredients you need, aside from the dependencies mentioned below. As of this writing, qt4 is probably the basic Qt on your system.<br />
<br />
qt<br />
qt-devel<br />
qtwebkit-devel<br />
poppler-devel (on debian you might need poppler-private-dev too : see http://bugs.scribus.net/view.php?id=11162)<br />
podofo-devel<br />
ghostscript (this should already be bundled)<br />
pkgconfig<br />
lcms2-devel<br />
libjpeg-devel<br />
libtiff-devel<br />
cups-devel<br />
libxml2 and libxml2-devel (libxml2 should already be bundled)<br />
python<br />
python-devel<br />
fontconfig-devel<br />
openssl-devel (?)<br />
freetype<br />
freetype-devel<br />
python-pillow-devel (formerly python-imaging-devel)<br />
tk <br />
tkinter<br />
hunspell <br />
hunspell-devel (as of 1.4.2)<br />
cairo (cairo should already be bundled)<br />
cairo-devel <br />
boost-devel<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>For convenience, here is the above list listed all on the same line ----> </big><br />
<div class="mw-collapsible-content"><br />
apt-get install qt4 qt4-devel qtwebkit-devel poppler-devel podofo-devel ghostscript pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel<br />
</div></div><br />
<br />
Once you have all of these, along with '''cmake''', then cd inside the scribus1.4.6 directory and type<br />
<pre><br />
cmake ./<br />
</pre><br />
for a basic setup so that Scribus 1.4.6 will be installed to the standard location. Scribus is still not built yet, so do this:<br />
<pre><br />
make<br />
</pre><br />
To install in this system location you need root privileges with '''sudo''' or '''su'''. Choose one of these, '''sudo''' will ask for your password (presuming you have administrative privileges), and '''su''' will ask for root's password.<br />
<pre><br />
sudo make install<br />
<br />
su<br />
make install<br />
</pre><br />
<br />
In addition to the above each Linux distrubution has it's own quirks to be aware of. The subsections below work to address them:<br />
====Fedora====<br />
An advantage of building your own Scribus 1.4.6 in Fedora is that, in contrast to the Scribus you may find on the repository, your own built Scribus will have the online manual, which is lacking in Fedora's RPM package. Fedora now uses '''dnf''' for package management. This command should cover all that you need (for 1.4.6 &ndash; see above for the dnf command for 1.5.x):<br />
<br />
'''sudo dnf qt qt-devel qtwebkit-devel poppler-devel podofo-devel ghostscript-devel pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel'''<br />
<br />
Something to note is that if you already have all the dependencies for 1.5.x, all you need to add is '''qt-devel'''.<br />
<br />
====Packages for Ubuntu====<br />
{{Warning|Please update this section}}<br />
To install all the required libraries and packages for Debian or Ubuntu type the following in a terminal:<br />
sudo apt-get build-dep scribus-ng<br />
<br />
In March 2011 the build dependencies for Scribus 1.4.0 on Debian/Ubuntu were: <br />
debhelper (>= 7), cmake (>= 2.4.3), gcc (>=3.3.5), libqt4-dev (>= 4.6), libcairo2-dev, zlib1g-dev,<br />
liblcms1-dev (>= 1.13), libtiff4-dev, libcups2-dev,libxml2-dev (>= 2.6.16), gettext, python-all-dev,<br />
libboost-python-dev, libaspell-dev, libpodofo-dev (>= 0.8.4), quilt<br />
<br />
[http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon).<br />
<br />
==== The easy way for Debian users ====<br />
{{Warning|Please update this section}}<br />
On <strong>Debian</strong>, if you install the develeopment packages as described above(<code>apt-get build-dep scribus-ng</code>) you will need the following packages to build the trunk (status September 2011):<br />
* libqtwebkit-dev<br />
* poppler-private-dev may be needed, see {{b|11162}}<br />
<strike>If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc for instance) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
</strike><br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
</div></div><br />
<br />
== Build from Source ==<br />
<span style="background-color: #FFFF00"><big>Moved from top of the page..being integrated [[User:Kunda|Kunda]] ([[User talk:Kunda|talk]]) 15:07, 29 June 2014 (CEST)</big><br /><br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. </span><br />
<br />
<span style="background-color: #FFFF00">'''Watch out:'''<br />
<span style="background-color: #FFFF00">* Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
<span style="background-color: #FFFF00">* And if you already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
</span><br />
------<br />
Take as an example this following set of commands which are geared towards the Linux environment. Here we see a case in which there is a downloading of the Scribus development version (1.5, not yet stable), building it and then installing it. Note that this assumes that the environment has been prepared previously with all the dependencies installed. <br />
<br />
<big><span style="background-color: #FFFF00">Recently moved from top of page. Still fine tuning how to represent this.</span></big><br />
{{Warning|You must have CMake version &ge; 2.8.9 (Older versions will fail). See: [[Official:Compile with CMake]]}}<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.net/trunk/Scribus<br />
cd ./Scribus<br />
mkdir build<br />
cd build<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn ..<br />
make<br />
sudo make install<br />
</pre><br />
<br />
'''Note:'''<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
* in case you want to install the 1.4 stable version, replace the "svn" instruction with following : svn co svn://scribus.net/branches/Version14x/Scribus<br />
<big><span style="background-color: #FFFF00">End of subsection</span></big><br />
<br />
==Start the Build Process ==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Some options that the Scribus CMake files know about (more can be found here : http://wiki.scribus.net/canvas/CMake_Build_Options):<br />
*-DWANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*-DWANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*<strike>-DWANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+</strike>. ('''DEPRECATED''') <br />
*-DWANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*-DWANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
*-DWANT_HUNSPELL=1: This will enable the new (as of 1.4.2) hunspell-based spell checking capabilities across *all* platforms.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
<strike>For example: to make a cairo debug build, then something like this:</strike><br />
<br />
<strike><code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code></strike><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-Source-Builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Simple!<br />
<br />
==More CMake Options==<br />
[[CMake_Build_Options]]<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
=<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*Prefixes for more packages<br />
<br />
<br />
==Appimages==<br />
<br />
As an alternative to build scribus, you can download and use daily [[AppImages]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=34525
Building SVN versions with CMake
2018-12-08T23:32:25Z
<p>Gpittman: /* Notes on Fedora 26 &amp; 27 */</p>
<hr />
<div>{{Cleanup}}<br />
[[Category:Installation]] [[Category:Development]]<br />
<br />
This page tries to describe how to build Scribus from source.<br />
The instructions mainly refer to building Scribus on Linux. Building on Mac OS and on Windows is not easy; you can find some explanations for Mac OS [[Installing from SVN on Mac OS X|here]], and for Windows [[Building SVN versions on Windows|here]]. <br />
<br />
=TL;DR (Too Long; Didn't Read)=<br />
<big>You know what you are doing already and just want to compile Scribus via SVN, skip the introduction and go to [[{{PAGENAME}}#Version 1.5.x|Installing 1.5svn]]</big><br />
<br />
=Why would I Need or Want to 'Build' Scribus?=<br />
<big><br />
# '''For Necessity:''' You are using the current stable version, but certain bugs are a problem, and you know they have been fixed since the last release.<br />
# '''For Science:''' You have heard about some new features in the development version, and you'd like to try them out.<br />
# '''For the World:''' You're considering helping out the Scribus project and want to see how it's put together to get some idea about how you can help.<br />
</big><br />
==='Or, for that matter, what is this 'Building' you speak of?===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>Expand this content if you need a little bit more background on what Building source code means. ---></big><br />
<div class="mw-collapsible-content"><br />
<big>When you are going to build or compile Scribus, what you have downloaded (if you have downloaded the source code) is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ programming language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your computer can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your computer to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is being written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team requires the use of CMake for this configuring process. It is quick, easy to use, and easy for the developers to write for &ndash; even CMake needs instructions. You can also pass to CMake several special parameters for your particular Computer setup, for example, where you want Scribus to be installed.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.</big><br />
</div><br />
</div><br />
<br />
== Fear is the mind Killer... ==<br />
[[Image:Fear-is-the-mind-killer-Dune.png|500px|thumb|right|"Do not fear building Scribus from source" ~Paul Muad'dib Atreides]]<br />
'''There is nothing to fear here, building Scribus yourself is not as hard as it sounds'''. You will not break your computer.<br />
<br />
This page can teach a beginner many things at once: starting with beginning to comprehend the internals of Scribus to appreciating the Command Line shell and how to invoke commands through it. Learn how to install software libraries (components that Scribus utilizes) and go so far as to modify source code through applying patches. This exposure will help increase your skill set to work on most all platforms and widen your knowledge of software creation and maintenance.<br />
<br />
=1st: Download latest snapshot with Subversion=<br />
Subversion is the versioning control system used for Scribus. This allows multiple developers to hack on Scribus source code simultaneously. Check the [[Subversion]] page for further details on how to use this tool. Make sure you have svn installed. You don't need to learn all subversion commands and options: "svn co" and "svn up" might suffice, see below for examples.<br />
<br />
You should create a directory in which the Scribus source code will be downloaded. Then change to that directory, and once you are there, you can download the source code with a simple command. You have to choose which branch you will download, as shown in the table below:<br />
<br />
{| cellspacing="10" cellpadding="6"<br />
! Status !! Version !! !! SVN Path !! Command to download from SVN<br />
|-<br />
|'''Development''' || '''1.5.x''' || || /trunk/Scribus || <tt><b>svn co svn://scribus.net/trunk/Scribus scribus15</b></tt><br />
|-<br />
|'''Development Snapshot''' || '''1.5.0''' || || /trunk/Scribus revision 20099 || <tt><b>svn co -r 20099 svn://scribus.net/trunk/Scribus scribus150</b></tt><br />
|-<br />
|'''Stable''' || '''1.4.x''' || ||/branches/Version14x/Scribus || <tt><b>svn co svn://scribus.net/branches/Version14x/Scribus scribus14x</b></tt><br />
|-<br />
|Outdated || <strike>v.1.3.3x</strike> || ||<strike>/branches/Version133x/Scribus</strike> || <strike><tt><b>svn co svn://scribus.net/branches/Version13x/Scribus scribus13x</b></tt></strike><br />
|}<br />
<small>'''Important Notes:''' <br />
* All subversion URLs for Scribus anonsvn are based at: '''svn://scribus.net/'''<br />
* Updating your working copy is much the same as cvs - just cd into your working copy and run <tt><b>"svn up"</b></tt>.<br />
* There's also '''http://scribus.net/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.net/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies.<br />
* If you used to check out -r <Version>, check out <SVN Path> instead<br />
</small><br />
<br />
------<br />
<br />
'''Thanks to [http://anduin.net Anduin.net], anonymous SVN access is updated daily.'''<br />
<br />
===Example===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Here is an example of the commands for downloading the source code:<br />
<div class="mw-collapsible-content"><br />
<br />
<small>(This example is for Linux; on other platforms you should use the corresponding commands)</small><br />
<br />
Let's suppose that you want to download the Scribus 1.5.0. source code in a directory called "scribussource" under your home directory. Here are the commands:<br />
<br />
mkdir ~/scribussource<br />
cd ~/scribussource<br />
svn co svn://scribus.net/trunk/Scribus<br />
<br />
When subversion finishes downloading, you will find the source code in ~/scribussource/Scribus<br />
<br />
If you have the source code and you want to update it to the latest version:<br />
<br />
cd ~/scribussource/Scribus<br />
svn up<br />
</div></div><br />
<br />
=2nd: Install methods: Package Manager, Source, Out-of-Source Build=<br />
<br />
==Essential tools==<br />
Before going further, we must understand that in order for anything to get built, tools need to exist. In modern OS's especially Linux many of these are build tools arrive already bundled. If they aren't for some reason you will need to '''install them manually''' (see [[{{PAGENAME}}#Package Manager|package manager]])<br />
* gcc<br />
* gcc-c++<br />
* cmake (version &ge; 2.8.9)<br />
<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
<big>There are several option for installation.<br />
* [[{{PAGENAME}}#Package Managers| Package Manager]]: (difficulty: easy) Does a lot of the heavy lifiting by installing all the components you specify <br />
* [[{{PAGENAME}}#Build from Source| Build from Source]]: (difficulty: intermediate to advanced) Build it the old fashion way<br />
* [[{{PAGENAME}}#Out-of-Source-Builds| Out-of-Source-Builds]]: (difficulty: intermediate) Needs explanation<br />
</big><br />
<br />
==Package Managers==<br />
Note: many Linux distros have their own Package Managers i.e. Debian has '''apt''', Fedora and Centos have '''yum''', more recently superceded by '''dnf''', Redhat uses '''rpm''' etc... On Mac OS X there are several choices, most popular are '''Macports''' and '''Homebrew'''. In general, by utilizing the installed package manager we can streamline the installations through easy one liners which will automate the install. We do this by invoking the following pattern: <br />
<br />
<tt> <b>(package-manager) install (software-or-library-package-name)</b></tt> <br />
<br />
'''Debian'''; &nbsp;&nbsp;&nbsp;'''<code>apt-get install cmake</code>''' <br /><br />
'''Fedora''': &nbsp;&nbsp;&nbsp;'''<code>dnf install cmake</code>''' <br /><br />
'''MacOSX''':&nbsp;'''<code>brew install cmake</code>'''<br />
<br />
==Specific Dependencies== <br />
<!-- This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. --><br />
Dependencies are considered to be 3rd party software libraries or other altogether unique software projects that are have components that are needed to build a specific project from. When we want to build Scribus we need to make sure that we have all the dependencies fulfilled or else it will complain to us about missing components or obsolete ones. The following section assumes you need to manually install dependencies. Here are the list of package names that will be needed to be installed before attempting to build Scribus. Each major version of Scribus will require different dependencies.<br />
<br />
===Version 1.5.x===<br />
Here is a list of dependencies for Scribus 1.5.x:<br />
<br />
Qt (version >= 5.2; see below for details)<br />
Cairo<br />
Pixman<br />
Boost<br />
Cups (not required on Windows)<br />
Fontconfig (not required on Windows)<br />
Freetype<br />
Libhunspell (if missing, spellchecker won't work)<br />
Libjpeg<br />
Libtiff<br />
Libxml2<br />
LittleCMS (version >= 2.1)<br />
Pkgconfig (Linux)<br />
PoDoFo<br />
Poppler, Poppler-data, and Poppler-cpp<br />
Python 2.7<br />
Python-Pillow<br />
Tk and Tkinter (required by some scripts shipped with Scribus)<br />
<br />
For Scribus 1.5.3+<br />
Harfbuzz<br />
ICU (UC module)<br />
Qt 5.5+<br />
<br />
For Scribus 1.5.5+<br />
Qt 5.7+<br />
C++11<br />
<br />
On Linux, for each item you have to install both the main package and the development package (for example: cairo and cairo-devel, pixman and pixman-devel, and so on). Some packages should be already installed (for example, Cairo or CUPS).<br />
<br />
====Getting and installing Qt5====<br />
Starting with rev. 19790 (4 February 2015), Qt 5.2 or later is required.<br />
<br />
If Qt5 is not present on your system, you have to install or build it.<br />
<br />
You can download Qt5 from http://qt-project.org/downloads. Binary installers are available for Windows, Mac&nbsp;OS X and Linux. For Linux, if your distribution provides the latest Qt5, you can install it from its repositories (details for some distributions are listed below).<br />
<br />
Also available is the source code, in case you want to build Qt5 yourself, or if an installer is not available for your operating system.<br />
<br />
If you're using the Qt installer on Linux, make sure to make the file <code>qt-opensource-linux-x**-5.*.*.run</code> executable. You can do this via your chosen UI or the command line. The latter requires the following commands:<br />
<br />
<code>chmode +x /path/to/qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
To start the installation process, use the <code>cd</code> command to move into the installer's directory.<br />
<br />
Next, run the following command:<br />
<br />
<code>./qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
If run without root privileges, the installer will suggest /home/username/Qt5.* as the installation directory. That's fine if you only want to test Scribus 1.5.x. If you also want to test the latest versions of other programmes using Qt5, you should install Qt5 with root privileges.<br />
<br />
If you have Qt4 and Qt5 installed, and/or cmake does not find Qt5, you need to specify its location with the [[CMake_Build_Options#Qt5-Specific|build option]] -DQT_PREFIX="path-to-Qt5" (for example: -DQT_PREFIX="/home/user/Qt/5.1.1/gcc/")<br />
<br />
In case you need a list, the required qt5 libs are : <br />
Qt5Core<br />
Qt5Widgets<br />
Qt5Gui<br />
Qt5Xml<br />
Qt5WebKit<br />
Qt5WebKitWidgets<br />
Qt5Network<br />
Qt5OpenGL<br />
Qt5LinguistTools<br />
Qt5Quick<br />
Qt5PrintSupport<br />
<br />
In case you got problems, Pygmee suggests too : "it build here after i've build sigil where it make a bit changes in QT5 config".<br />
<br />
=====Debian=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
On Debian Testing, on top of the packages pulled in by apt-get build-dep you need. ----><br />
<div class="mw-collapsible-content"><br />
'''sudo apt install libqt5webkit5-dev qtquick1-5-dev qtdeclarative5-dev \'''<br />
'''qttools5-dev-tools qttools5-dev liblcms2-dev'''<br />
'''sudo apt install libpoppler-private-dev''' (3)<br />
Note 1: They are all available in the official Debian repositories.<br />
Note 2: This list should also apply for the latest Ubuntu release.<br />
Note 3: Needed since Ubuntu-16.04 and its derivatives like Linux Mint.<br />
</div></div><br />
<br />
=====Fedora 19 and later=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Fedora 19 and later have Qt5 packages available from their repositories. The requirements seem to be ----><br />
<div class="mw-collapsible-content"><br />
'''yum install qt5-qtbase qt5-qtbase-devel qt5-qtdeclarative qt5-qtdeclarative-devel qt5-qttools \'''<br />
'''qt5-qttools-devel qt5-qtwebkit qt5-qtwebkit-devel qt5-qtbase-static'''<br />
<br />
The above list will bring in '''qt5-qtbase-gui''' and possibly some other packages as dependencies. You might need also to install '''glibc-headers'''.<br />
</div></div><br />
=====Notes on Fedora 28 &amp; 29=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
This will probably also work for Fedora 24 to 27 ----><br />
<div class="mw-collapsible-content"><br />
Fedora now uses '''dnf''' instead of '''yum''' for package management. Using the following command will supply all the needed requirements for Scribus 1.5.x (note that some are optional features, such as OpenSceneGraph). <br />
<br />
'''sudo dnf -y install boost-devel cairo-devel cups-devel fontconfig-devel freetype-devel GraphicsMagick-c++-devel GraphicsMagick-devel harfbuzz-devel hunspell-devel kernel-devel lcms2-devel libicu-devel libjpeg-turbo-devel libmspub-devel libpng-devel librevenge-devel libstdc++-devel libtiff-devel libwpd-devel libxml2-devel OpenSceneGraph-devel podofo-devel poppler-devel poppler-data poppler-data-devel poppler-cpp poppler-cpp-devel python-devel python-qt5-devel qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qttools-devel qt5-qtwebkit-devel'''<br />
<br />
Even though all of these are just the -devel packages, dnf will pull in all necessary additional requirements. Note that '''poppler-cpp''' and '''poppler-cpp-devel''' seem to be new requirements.<br />
</div><br />
</div><br />
<br />
=====Ubuntu=====<br />
<br />
'''Firstly, if you are running Ubuntu with version < 15.10, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.04 ----><br />
<div class="mw-collapsible-content"><br />
* Initially install:<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev qttools5'''<br />
* Then, specifically relating to qt5, install: <br />
'''sudo apt-get install libqt5declarative5-dev qtlocation5-dev qtsensors5-dev''' <br />
* Install the usual libs '''not''' related to qt5 : <br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.10 ----><br />
<div class="mw-collapsible-content"><br />
Almost the same as 13.04 except '''no qttools5''' and '''no libqt5declarative5-dev''' instead '''use qtdeclarative5-dev''' <br />
<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev'''<br />
'''sudo apt-get install qtdeclarative5-dev qtlocation5-dev qtsensors5-dev'''<br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
<br />
# Note 1: There are bugs with qt5 version 5.0.2. Install qt5 version 5.2 with the installer found on https://qt-project.org/downloads. <br />
# Note 2: (JLuc, 25 May 2014): I followed this procedure step by step and everything when right out of the box.<br />
# Note 3 (unknown author) : In addition, I had to install: libgl1-mesa-dev and dependencies.<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v14.04 ----><br />
<div class="mw-collapsible-content"><br />
This is how i compiles scribus 1.5 on a quite freshly installed Ubuntu 14.04 :<br />
# Install scribus 1.5 out of the scribus friend's PPA (https://launchpad.net/~scribus/+archive/ubuntu/ppa). There are too many keyboard management bugs with this version, but it maybe installs some usefull libraries. Then uninstall it.<br />
# Install cmake, g++ and subversion in case there are not there allready ("sudo apt-get install cmake" and "sudo apt-get install subversion")<br />
# Install (using synaptics or sudo apt-get) the following libraries and their dependancies : libdrm-dev, libgl1-mesa-dev, libxml2-dev, libzip-dev, libfreetype6-dev, liblcms2-dev, libpodofo-dev, libcairo2-dev, libmagick++dev (maybe useless), libgraphicsmagick++1-dev, libcups2-dev, libpython2.7-dev, libpoppler-qt5-dev (maybe useless), libpoppler-cpp-dev, libpoppler-private-dev, libhunspell-dev<br />
# Compile using maksvn script (https://github.com/JLuc/makscribus/blob/master/maksvn).<br />
That's it !<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v16.04 ----><br />
<div class="mw-collapsible-content"><br />
To compile scribus 1.5 on ubuntu 16.04, you need to follow:<br />
# make sure that you installed QT as mention above.<br />
# executed the the following commands to install required libraries:<br />
'''<code> sudo apt-get update -qq;</code>''' <br /><br />
'''<code> sudo apt-get install --force-yes cmake libboost-python-dev libcups2-dev libhunspell-dev libhyphen-dev liblcms2-dev libpodofo-dev libtiff-dev libxml2-dev python-all-dev zlib1g-dev libgraphicsmagick++1-dev libopenscenegraph-dev libpoppler-dev libpoppler-private-dev libcairo2-dev libwpg-dev libmspub-dev libcdr-dev libvisio-dev libharfbuzz-dev libharfbuzz-icu0 coreutils binutils python-tk</code>'''<br />
<br />
</div></div><br />
<br />
=====OpenSuse=====<br />
'''Firstly, if you are running OpenSUSE with version < 13.2, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
13.2 or newer ----><br />
<div class="mw-collapsible-content"><br />
* Install the OS<br />
* install Qt5 - sudo zypper in -t devel_qt5<br />
* Install these packages via Yast2 or 'zypper in' from the command line:<br />
python-devel <br />
cairo-devel<br />
hunspell-devel<br />
cmake<br />
subversion<br />
cups-devel <br />
libtiff-devel<br />
liblcms2-devel<br />
cups-devel<br />
boost-devel<br />
libjpeg8-devel<br />
libtiff-devel<br />
libpodofo-devel<br />
libpoppler-devel<br />
librevenge-devel<br />
libcdr-devel<br />
libmspub-devel<br />
libvisio-devel<br />
libfreehand-devel<br />
* Proceed with Scribus compilation process.<br />
</div></div><br />
<br />
=====Windows=====<br />
Please refer to [[Building_SVN_versions_on_Windows]]<br />
<br />
=====Mac OSX=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
MacPorts (recommended by Scribus core-devs) ----><br />
<div class="mw-collapsible-content"><br />
Needs details<br />
</div></div><br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Homebrew Package Manager (Scribus community supported effort) ----><br />
<div class="mw-collapsible-content"><br />
FYI, please don't post homebrew bugs on the bugtracker. Instead read the top notice on [[Scribus_and_Homebrew]].<br />
'''1. brew tap scribusproject/scribus'''<br />
'''2. brew install --HEAD scribus --verbose'''<br />
'''3. brew linkapps --local scribus'''<br />
'''4. Invoke with: ~/Applications/Scribus.app/Contents/MacOS/Scribus'''<br />
</div></div><br />
<br />
===Additional dependencies for some graphics formats===<br />
In 1.5.0+, there are a number of vector and bitmap graphics formats which can now be imported into Scribus. Some of these have particular additional dependencies.<br />
<br />
====GraphicsMagick (Optional)====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added import filters will be available if you have it (and cmake will detect it automatically). What Scribus needs are the following packages: graphicsmagick, graphicsmagick-devel, graphicsmagick-c++, and graphicsmagick-c++-devel.<br />
<br />
====OpenSceneGraph (Optional)====<br />
This may be available with your Linux distribution (definitely for Fedora 17 and later). You can also [http://www.openscenegraph.org/projects/osg/wiki/Downloads download and compile] yourself.<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''Fedora'''<br />
<div class="mw-collapsible-content"><br />
'''sudo yum install OpenSceneGraph OpenSceneGraph-devel'''<br />
<br />
should be enough, and will get you the additional requirements of Inventor, OpenThreads, and OpenThreads-devel.<br />
</div></div><br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''OpenSUSE'''<br />
<div class="mw-collapsible-content"><br />
go to http://software.opensuse.org/package/OpenSceneGraph and use the 1-click install procedure.<br />
</div></div><br />
====MS Publisher and WPG Importers====<br />
<br />
To build Scribus with support for MS Publisher and WPG files, you need [http://cgit.freedesktop.org/libreoffice/libmspub/ libmspub], as well as [http://libwpg.sourceforge.net/ libwpg] and [http://libwpd.sourceforge.net/ libwpd]. Note that the minimum version for PUB import is libmspub 0.0.6, and also that you want the development packages (libwpd-devel, libwpg-devel, libmspub-devel, for example in Fedora).<br />
<br />
Update (June 2014): Scribus is now able to import MS Publisher, MS Visio and CorelDraw documents via librevenge. See [[Librevenge|this page]] for details.<br />
<br />
===Scribus 1.4.x===<br />
One method for obtaining and then building Scribus is to download the compressed tar file, for example from [https://sourceforge.net/projects/scribus/files/scribus/1.4.6/ https://sourceforge.net/projects/scribus/files/scribus/1.4.6/].<br />
<br />
Let's imagine you choose the one compressed with 7-zip, which is scribus-1.4.6.7z. Click the link to download, then on the command line go to the directory where it was saved (perhaps Downloads/). To extract this, type<br />
<pre><br />
7z x scribus-1.4.6.7z<br />
</pre><br />
which will create the directory '''scribus-1.4.6''', and inside this will be all the ingredients you need, aside from the dependencies mentioned below. As of this writing, qt4 is probably the basic Qt on your system.<br />
<br />
qt<br />
qt-devel<br />
qtwebkit-devel<br />
poppler-devel (on debian you might need poppler-private-dev too : see http://bugs.scribus.net/view.php?id=11162)<br />
podofo-devel<br />
ghostscript (this should already be bundled)<br />
pkgconfig<br />
lcms2-devel<br />
libjpeg-devel<br />
libtiff-devel<br />
cups-devel<br />
libxml2 and libxml2-devel (libxml2 should already be bundled)<br />
python<br />
python-devel<br />
fontconfig-devel<br />
openssl-devel (?)<br />
freetype<br />
freetype-devel<br />
python-pillow-devel (formerly python-imaging-devel)<br />
tk <br />
tkinter<br />
hunspell <br />
hunspell-devel (as of 1.4.2)<br />
cairo (cairo should already be bundled)<br />
cairo-devel <br />
boost-devel<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>For convenience, here is the above list listed all on the same line ----> </big><br />
<div class="mw-collapsible-content"><br />
apt-get install qt4 qt4-devel qtwebkit-devel poppler-devel podofo-devel ghostscript pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel<br />
</div></div><br />
<br />
Once you have all of these, along with '''cmake''', then cd inside the scribus1.4.6 directory and type<br />
<pre><br />
cmake ./<br />
</pre><br />
for a basic setup so that Scribus 1.4.6 will be installed to the standard location. Scribus is still not built yet, so do this:<br />
<pre><br />
make<br />
</pre><br />
To install in this system location you need root privileges with '''sudo''' or '''su'''. Choose one of these, '''sudo''' will ask for your password (presuming you have administrative privileges), and '''su''' will ask for root's password.<br />
<pre><br />
sudo make install<br />
<br />
su<br />
make install<br />
</pre><br />
<br />
In addition to the above each Linux distrubution has it's own quirks to be aware of. The subsections below work to address them:<br />
====Fedora====<br />
An advantage of building your own Scribus 1.4.6 in Fedora is that, in contrast to the Scribus you may find on the repository, your own built Scribus will have the online manual, which is lacking in Fedora's RPM package. Fedora now uses '''dnf''' for package management. This command should cover all that you need (for 1.4.6 &ndash; see above for the dnf command for 1.5.x):<br />
<br />
'''sudo dnf qt qt-devel qtwebkit-devel poppler-devel podofo-devel ghostscript-devel pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel'''<br />
<br />
Something to note is that if you already have all the dependencies for 1.5.x, all you need to add is '''qt-devel'''.<br />
<br />
====Packages for Ubuntu====<br />
{{Warning|Please update this section}}<br />
To install all the required libraries and packages for Debian or Ubuntu type the following in a terminal:<br />
sudo apt-get build-dep scribus-ng<br />
<br />
In March 2011 the build dependencies for Scribus 1.4.0 on Debian/Ubuntu were: <br />
debhelper (>= 7), cmake (>= 2.4.3), gcc (>=3.3.5), libqt4-dev (>= 4.6), libcairo2-dev, zlib1g-dev,<br />
liblcms1-dev (>= 1.13), libtiff4-dev, libcups2-dev,libxml2-dev (>= 2.6.16), gettext, python-all-dev,<br />
libboost-python-dev, libaspell-dev, libpodofo-dev (>= 0.8.4), quilt<br />
<br />
[http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon).<br />
<br />
==== The easy way for Debian users ====<br />
{{Warning|Please update this section}}<br />
On <strong>Debian</strong>, if you install the develeopment packages as described above(<code>apt-get build-dep scribus-ng</code>) you will need the following packages to build the trunk (status September 2011):<br />
* libqtwebkit-dev<br />
* poppler-private-dev may be needed, see {{b|11162}}<br />
<strike>If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc for instance) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
</strike><br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
</div></div><br />
<br />
== Build from Source ==<br />
<span style="background-color: #FFFF00"><big>Moved from top of the page..being integrated [[User:Kunda|Kunda]] ([[User talk:Kunda|talk]]) 15:07, 29 June 2014 (CEST)</big><br /><br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. </span><br />
<br />
<span style="background-color: #FFFF00">'''Watch out:'''<br />
<span style="background-color: #FFFF00">* Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
<span style="background-color: #FFFF00">* And if you already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
</span><br />
------<br />
Take as an example this following set of commands which are geared towards the Linux environment. Here we see a case in which there is a downloading of the Scribus development version (1.5, not yet stable), building it and then installing it. Note that this assumes that the environment has been prepared previously with all the dependencies installed. <br />
<br />
<big><span style="background-color: #FFFF00">Recently moved from top of page. Still fine tuning how to represent this.</span></big><br />
{{Warning|You must have CMake version &ge; 2.8.9 (Older versions will fail). See: [[Official:Compile with CMake]]}}<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.net/trunk/Scribus<br />
cd ./Scribus<br />
mkdir build<br />
cd build<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn ..<br />
make<br />
sudo make install<br />
</pre><br />
<br />
'''Note:'''<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
* in case you want to install the 1.4 stable version, replace the "svn" instruction with following : svn co svn://scribus.net/branches/Version14x/Scribus<br />
<big><span style="background-color: #FFFF00">End of subsection</span></big><br />
<br />
==Start the Build Process ==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Some options that the Scribus CMake files know about (more can be found here : http://wiki.scribus.net/canvas/CMake_Build_Options):<br />
*-DWANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*-DWANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*<strike>-DWANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+</strike>. ('''DEPRECATED''') <br />
*-DWANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*-DWANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
*-DWANT_HUNSPELL=1: This will enable the new (as of 1.4.2) hunspell-based spell checking capabilities across *all* platforms.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
<strike>For example: to make a cairo debug build, then something like this:</strike><br />
<br />
<strike><code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code></strike><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-Source-Builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Simple!<br />
<br />
==More CMake Options==<br />
[[CMake_Build_Options]]<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
=<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*Prefixes for more packages<br />
<br />
<br />
==Appimages==<br />
<br />
As an alternative to build scribus, you can download and use daily [[AppImages]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=34524
Building SVN versions with CMake
2018-12-08T23:31:01Z
<p>Gpittman: /* Fedora 1.4.6 */</p>
<hr />
<div>{{Cleanup}}<br />
[[Category:Installation]] [[Category:Development]]<br />
<br />
This page tries to describe how to build Scribus from source.<br />
The instructions mainly refer to building Scribus on Linux. Building on Mac OS and on Windows is not easy; you can find some explanations for Mac OS [[Installing from SVN on Mac OS X|here]], and for Windows [[Building SVN versions on Windows|here]]. <br />
<br />
=TL;DR (Too Long; Didn't Read)=<br />
<big>You know what you are doing already and just want to compile Scribus via SVN, skip the introduction and go to [[{{PAGENAME}}#Version 1.5.x|Installing 1.5svn]]</big><br />
<br />
=Why would I Need or Want to 'Build' Scribus?=<br />
<big><br />
# '''For Necessity:''' You are using the current stable version, but certain bugs are a problem, and you know they have been fixed since the last release.<br />
# '''For Science:''' You have heard about some new features in the development version, and you'd like to try them out.<br />
# '''For the World:''' You're considering helping out the Scribus project and want to see how it's put together to get some idea about how you can help.<br />
</big><br />
==='Or, for that matter, what is this 'Building' you speak of?===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>Expand this content if you need a little bit more background on what Building source code means. ---></big><br />
<div class="mw-collapsible-content"><br />
<big>When you are going to build or compile Scribus, what you have downloaded (if you have downloaded the source code) is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ programming language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your computer can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your computer to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is being written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team requires the use of CMake for this configuring process. It is quick, easy to use, and easy for the developers to write for &ndash; even CMake needs instructions. You can also pass to CMake several special parameters for your particular Computer setup, for example, where you want Scribus to be installed.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.</big><br />
</div><br />
</div><br />
<br />
== Fear is the mind Killer... ==<br />
[[Image:Fear-is-the-mind-killer-Dune.png|500px|thumb|right|"Do not fear building Scribus from source" ~Paul Muad'dib Atreides]]<br />
'''There is nothing to fear here, building Scribus yourself is not as hard as it sounds'''. You will not break your computer.<br />
<br />
This page can teach a beginner many things at once: starting with beginning to comprehend the internals of Scribus to appreciating the Command Line shell and how to invoke commands through it. Learn how to install software libraries (components that Scribus utilizes) and go so far as to modify source code through applying patches. This exposure will help increase your skill set to work on most all platforms and widen your knowledge of software creation and maintenance.<br />
<br />
=1st: Download latest snapshot with Subversion=<br />
Subversion is the versioning control system used for Scribus. This allows multiple developers to hack on Scribus source code simultaneously. Check the [[Subversion]] page for further details on how to use this tool. Make sure you have svn installed. You don't need to learn all subversion commands and options: "svn co" and "svn up" might suffice, see below for examples.<br />
<br />
You should create a directory in which the Scribus source code will be downloaded. Then change to that directory, and once you are there, you can download the source code with a simple command. You have to choose which branch you will download, as shown in the table below:<br />
<br />
{| cellspacing="10" cellpadding="6"<br />
! Status !! Version !! !! SVN Path !! Command to download from SVN<br />
|-<br />
|'''Development''' || '''1.5.x''' || || /trunk/Scribus || <tt><b>svn co svn://scribus.net/trunk/Scribus scribus15</b></tt><br />
|-<br />
|'''Development Snapshot''' || '''1.5.0''' || || /trunk/Scribus revision 20099 || <tt><b>svn co -r 20099 svn://scribus.net/trunk/Scribus scribus150</b></tt><br />
|-<br />
|'''Stable''' || '''1.4.x''' || ||/branches/Version14x/Scribus || <tt><b>svn co svn://scribus.net/branches/Version14x/Scribus scribus14x</b></tt><br />
|-<br />
|Outdated || <strike>v.1.3.3x</strike> || ||<strike>/branches/Version133x/Scribus</strike> || <strike><tt><b>svn co svn://scribus.net/branches/Version13x/Scribus scribus13x</b></tt></strike><br />
|}<br />
<small>'''Important Notes:''' <br />
* All subversion URLs for Scribus anonsvn are based at: '''svn://scribus.net/'''<br />
* Updating your working copy is much the same as cvs - just cd into your working copy and run <tt><b>"svn up"</b></tt>.<br />
* There's also '''http://scribus.net/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.net/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies.<br />
* If you used to check out -r <Version>, check out <SVN Path> instead<br />
</small><br />
<br />
------<br />
<br />
'''Thanks to [http://anduin.net Anduin.net], anonymous SVN access is updated daily.'''<br />
<br />
===Example===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Here is an example of the commands for downloading the source code:<br />
<div class="mw-collapsible-content"><br />
<br />
<small>(This example is for Linux; on other platforms you should use the corresponding commands)</small><br />
<br />
Let's suppose that you want to download the Scribus 1.5.0. source code in a directory called "scribussource" under your home directory. Here are the commands:<br />
<br />
mkdir ~/scribussource<br />
cd ~/scribussource<br />
svn co svn://scribus.net/trunk/Scribus<br />
<br />
When subversion finishes downloading, you will find the source code in ~/scribussource/Scribus<br />
<br />
If you have the source code and you want to update it to the latest version:<br />
<br />
cd ~/scribussource/Scribus<br />
svn up<br />
</div></div><br />
<br />
=2nd: Install methods: Package Manager, Source, Out-of-Source Build=<br />
<br />
==Essential tools==<br />
Before going further, we must understand that in order for anything to get built, tools need to exist. In modern OS's especially Linux many of these are build tools arrive already bundled. If they aren't for some reason you will need to '''install them manually''' (see [[{{PAGENAME}}#Package Manager|package manager]])<br />
* gcc<br />
* gcc-c++<br />
* cmake (version &ge; 2.8.9)<br />
<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
<big>There are several option for installation.<br />
* [[{{PAGENAME}}#Package Managers| Package Manager]]: (difficulty: easy) Does a lot of the heavy lifiting by installing all the components you specify <br />
* [[{{PAGENAME}}#Build from Source| Build from Source]]: (difficulty: intermediate to advanced) Build it the old fashion way<br />
* [[{{PAGENAME}}#Out-of-Source-Builds| Out-of-Source-Builds]]: (difficulty: intermediate) Needs explanation<br />
</big><br />
<br />
==Package Managers==<br />
Note: many Linux distros have their own Package Managers i.e. Debian has '''apt''', Fedora and Centos have '''yum''', more recently superceded by '''dnf''', Redhat uses '''rpm''' etc... On Mac OS X there are several choices, most popular are '''Macports''' and '''Homebrew'''. In general, by utilizing the installed package manager we can streamline the installations through easy one liners which will automate the install. We do this by invoking the following pattern: <br />
<br />
<tt> <b>(package-manager) install (software-or-library-package-name)</b></tt> <br />
<br />
'''Debian'''; &nbsp;&nbsp;&nbsp;'''<code>apt-get install cmake</code>''' <br /><br />
'''Fedora''': &nbsp;&nbsp;&nbsp;'''<code>dnf install cmake</code>''' <br /><br />
'''MacOSX''':&nbsp;'''<code>brew install cmake</code>'''<br />
<br />
==Specific Dependencies== <br />
<!-- This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. --><br />
Dependencies are considered to be 3rd party software libraries or other altogether unique software projects that are have components that are needed to build a specific project from. When we want to build Scribus we need to make sure that we have all the dependencies fulfilled or else it will complain to us about missing components or obsolete ones. The following section assumes you need to manually install dependencies. Here are the list of package names that will be needed to be installed before attempting to build Scribus. Each major version of Scribus will require different dependencies.<br />
<br />
===Version 1.5.x===<br />
Here is a list of dependencies for Scribus 1.5.x:<br />
<br />
Qt (version >= 5.2; see below for details)<br />
Cairo<br />
Pixman<br />
Boost<br />
Cups (not required on Windows)<br />
Fontconfig (not required on Windows)<br />
Freetype<br />
Libhunspell (if missing, spellchecker won't work)<br />
Libjpeg<br />
Libtiff<br />
Libxml2<br />
LittleCMS (version >= 2.1)<br />
Pkgconfig (Linux)<br />
PoDoFo<br />
Poppler, Poppler-data, and Poppler-cpp<br />
Python 2.7<br />
Python-Pillow<br />
Tk and Tkinter (required by some scripts shipped with Scribus)<br />
<br />
For Scribus 1.5.3+<br />
Harfbuzz<br />
ICU (UC module)<br />
Qt 5.5+<br />
<br />
For Scribus 1.5.5+<br />
Qt 5.7+<br />
C++11<br />
<br />
On Linux, for each item you have to install both the main package and the development package (for example: cairo and cairo-devel, pixman and pixman-devel, and so on). Some packages should be already installed (for example, Cairo or CUPS).<br />
<br />
====Getting and installing Qt5====<br />
Starting with rev. 19790 (4 February 2015), Qt 5.2 or later is required.<br />
<br />
If Qt5 is not present on your system, you have to install or build it.<br />
<br />
You can download Qt5 from http://qt-project.org/downloads. Binary installers are available for Windows, Mac&nbsp;OS X and Linux. For Linux, if your distribution provides the latest Qt5, you can install it from its repositories (details for some distributions are listed below).<br />
<br />
Also available is the source code, in case you want to build Qt5 yourself, or if an installer is not available for your operating system.<br />
<br />
If you're using the Qt installer on Linux, make sure to make the file <code>qt-opensource-linux-x**-5.*.*.run</code> executable. You can do this via your chosen UI or the command line. The latter requires the following commands:<br />
<br />
<code>chmode +x /path/to/qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
To start the installation process, use the <code>cd</code> command to move into the installer's directory.<br />
<br />
Next, run the following command:<br />
<br />
<code>./qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
If run without root privileges, the installer will suggest /home/username/Qt5.* as the installation directory. That's fine if you only want to test Scribus 1.5.x. If you also want to test the latest versions of other programmes using Qt5, you should install Qt5 with root privileges.<br />
<br />
If you have Qt4 and Qt5 installed, and/or cmake does not find Qt5, you need to specify its location with the [[CMake_Build_Options#Qt5-Specific|build option]] -DQT_PREFIX="path-to-Qt5" (for example: -DQT_PREFIX="/home/user/Qt/5.1.1/gcc/")<br />
<br />
In case you need a list, the required qt5 libs are : <br />
Qt5Core<br />
Qt5Widgets<br />
Qt5Gui<br />
Qt5Xml<br />
Qt5WebKit<br />
Qt5WebKitWidgets<br />
Qt5Network<br />
Qt5OpenGL<br />
Qt5LinguistTools<br />
Qt5Quick<br />
Qt5PrintSupport<br />
<br />
In case you got problems, Pygmee suggests too : "it build here after i've build sigil where it make a bit changes in QT5 config".<br />
<br />
=====Debian=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
On Debian Testing, on top of the packages pulled in by apt-get build-dep you need. ----><br />
<div class="mw-collapsible-content"><br />
'''sudo apt install libqt5webkit5-dev qtquick1-5-dev qtdeclarative5-dev \'''<br />
'''qttools5-dev-tools qttools5-dev liblcms2-dev'''<br />
'''sudo apt install libpoppler-private-dev''' (3)<br />
Note 1: They are all available in the official Debian repositories.<br />
Note 2: This list should also apply for the latest Ubuntu release.<br />
Note 3: Needed since Ubuntu-16.04 and its derivatives like Linux Mint.<br />
</div></div><br />
<br />
=====Fedora 19 and later=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Fedora 19 and later have Qt5 packages available from their repositories. The requirements seem to be ----><br />
<div class="mw-collapsible-content"><br />
'''yum install qt5-qtbase qt5-qtbase-devel qt5-qtdeclarative qt5-qtdeclarative-devel qt5-qttools \'''<br />
'''qt5-qttools-devel qt5-qtwebkit qt5-qtwebkit-devel qt5-qtbase-static'''<br />
<br />
The above list will bring in '''qt5-qtbase-gui''' and possibly some other packages as dependencies. You might need also to install '''glibc-headers'''.<br />
</div></div><br />
=====Notes on Fedora 26 &amp; 27=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
This will probably also work for Fedora 24 and 25 ----><br />
<div class="mw-collapsible-content"><br />
Fedora now uses '''dnf''' instead of '''yum''' for package management. Using the following command will supply all the needed requirements for Scribus 1.5.x (note that some are optional features, such as OpenSceneGraph). <br />
<br />
'''sudo dnf -y install boost-devel cairo-devel cups-devel fontconfig-devel freetype-devel GraphicsMagick-c++-devel GraphicsMagick-devel harfbuzz-devel hunspell-devel kernel-devel lcms2-devel libicu-devel libjpeg-turbo-devel libmspub-devel libpng-devel librevenge-devel libstdc++-devel libtiff-devel libwpd-devel libxml2-devel OpenSceneGraph-devel podofo-devel poppler-devel poppler-data poppler-data-devel poppler-cpp poppler-cpp-devel python-devel python-qt5-devel qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qttools-devel qt5-qtwebkit-devel'''<br />
<br />
Even though all of these are just the -devel packages, dnf will pull in all necessary additional requirements. Note that '''poppler-cpp''' and '''poppler-cpp-devel''' seem to be new requirements.<br />
</div><br />
</div><br />
<br />
=====Ubuntu=====<br />
<br />
'''Firstly, if you are running Ubuntu with version < 15.10, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.04 ----><br />
<div class="mw-collapsible-content"><br />
* Initially install:<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev qttools5'''<br />
* Then, specifically relating to qt5, install: <br />
'''sudo apt-get install libqt5declarative5-dev qtlocation5-dev qtsensors5-dev''' <br />
* Install the usual libs '''not''' related to qt5 : <br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.10 ----><br />
<div class="mw-collapsible-content"><br />
Almost the same as 13.04 except '''no qttools5''' and '''no libqt5declarative5-dev''' instead '''use qtdeclarative5-dev''' <br />
<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev'''<br />
'''sudo apt-get install qtdeclarative5-dev qtlocation5-dev qtsensors5-dev'''<br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
<br />
# Note 1: There are bugs with qt5 version 5.0.2. Install qt5 version 5.2 with the installer found on https://qt-project.org/downloads. <br />
# Note 2: (JLuc, 25 May 2014): I followed this procedure step by step and everything when right out of the box.<br />
# Note 3 (unknown author) : In addition, I had to install: libgl1-mesa-dev and dependencies.<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v14.04 ----><br />
<div class="mw-collapsible-content"><br />
This is how i compiles scribus 1.5 on a quite freshly installed Ubuntu 14.04 :<br />
# Install scribus 1.5 out of the scribus friend's PPA (https://launchpad.net/~scribus/+archive/ubuntu/ppa). There are too many keyboard management bugs with this version, but it maybe installs some usefull libraries. Then uninstall it.<br />
# Install cmake, g++ and subversion in case there are not there allready ("sudo apt-get install cmake" and "sudo apt-get install subversion")<br />
# Install (using synaptics or sudo apt-get) the following libraries and their dependancies : libdrm-dev, libgl1-mesa-dev, libxml2-dev, libzip-dev, libfreetype6-dev, liblcms2-dev, libpodofo-dev, libcairo2-dev, libmagick++dev (maybe useless), libgraphicsmagick++1-dev, libcups2-dev, libpython2.7-dev, libpoppler-qt5-dev (maybe useless), libpoppler-cpp-dev, libpoppler-private-dev, libhunspell-dev<br />
# Compile using maksvn script (https://github.com/JLuc/makscribus/blob/master/maksvn).<br />
That's it !<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v16.04 ----><br />
<div class="mw-collapsible-content"><br />
To compile scribus 1.5 on ubuntu 16.04, you need to follow:<br />
# make sure that you installed QT as mention above.<br />
# executed the the following commands to install required libraries:<br />
'''<code> sudo apt-get update -qq;</code>''' <br /><br />
'''<code> sudo apt-get install --force-yes cmake libboost-python-dev libcups2-dev libhunspell-dev libhyphen-dev liblcms2-dev libpodofo-dev libtiff-dev libxml2-dev python-all-dev zlib1g-dev libgraphicsmagick++1-dev libopenscenegraph-dev libpoppler-dev libpoppler-private-dev libcairo2-dev libwpg-dev libmspub-dev libcdr-dev libvisio-dev libharfbuzz-dev libharfbuzz-icu0 coreutils binutils python-tk</code>'''<br />
<br />
</div></div><br />
<br />
=====OpenSuse=====<br />
'''Firstly, if you are running OpenSUSE with version < 13.2, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
13.2 or newer ----><br />
<div class="mw-collapsible-content"><br />
* Install the OS<br />
* install Qt5 - sudo zypper in -t devel_qt5<br />
* Install these packages via Yast2 or 'zypper in' from the command line:<br />
python-devel <br />
cairo-devel<br />
hunspell-devel<br />
cmake<br />
subversion<br />
cups-devel <br />
libtiff-devel<br />
liblcms2-devel<br />
cups-devel<br />
boost-devel<br />
libjpeg8-devel<br />
libtiff-devel<br />
libpodofo-devel<br />
libpoppler-devel<br />
librevenge-devel<br />
libcdr-devel<br />
libmspub-devel<br />
libvisio-devel<br />
libfreehand-devel<br />
* Proceed with Scribus compilation process.<br />
</div></div><br />
<br />
=====Windows=====<br />
Please refer to [[Building_SVN_versions_on_Windows]]<br />
<br />
=====Mac OSX=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
MacPorts (recommended by Scribus core-devs) ----><br />
<div class="mw-collapsible-content"><br />
Needs details<br />
</div></div><br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Homebrew Package Manager (Scribus community supported effort) ----><br />
<div class="mw-collapsible-content"><br />
FYI, please don't post homebrew bugs on the bugtracker. Instead read the top notice on [[Scribus_and_Homebrew]].<br />
'''1. brew tap scribusproject/scribus'''<br />
'''2. brew install --HEAD scribus --verbose'''<br />
'''3. brew linkapps --local scribus'''<br />
'''4. Invoke with: ~/Applications/Scribus.app/Contents/MacOS/Scribus'''<br />
</div></div><br />
<br />
===Additional dependencies for some graphics formats===<br />
In 1.5.0+, there are a number of vector and bitmap graphics formats which can now be imported into Scribus. Some of these have particular additional dependencies.<br />
<br />
====GraphicsMagick (Optional)====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added import filters will be available if you have it (and cmake will detect it automatically). What Scribus needs are the following packages: graphicsmagick, graphicsmagick-devel, graphicsmagick-c++, and graphicsmagick-c++-devel.<br />
<br />
====OpenSceneGraph (Optional)====<br />
This may be available with your Linux distribution (definitely for Fedora 17 and later). You can also [http://www.openscenegraph.org/projects/osg/wiki/Downloads download and compile] yourself.<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''Fedora'''<br />
<div class="mw-collapsible-content"><br />
'''sudo yum install OpenSceneGraph OpenSceneGraph-devel'''<br />
<br />
should be enough, and will get you the additional requirements of Inventor, OpenThreads, and OpenThreads-devel.<br />
</div></div><br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''OpenSUSE'''<br />
<div class="mw-collapsible-content"><br />
go to http://software.opensuse.org/package/OpenSceneGraph and use the 1-click install procedure.<br />
</div></div><br />
====MS Publisher and WPG Importers====<br />
<br />
To build Scribus with support for MS Publisher and WPG files, you need [http://cgit.freedesktop.org/libreoffice/libmspub/ libmspub], as well as [http://libwpg.sourceforge.net/ libwpg] and [http://libwpd.sourceforge.net/ libwpd]. Note that the minimum version for PUB import is libmspub 0.0.6, and also that you want the development packages (libwpd-devel, libwpg-devel, libmspub-devel, for example in Fedora).<br />
<br />
Update (June 2014): Scribus is now able to import MS Publisher, MS Visio and CorelDraw documents via librevenge. See [[Librevenge|this page]] for details.<br />
<br />
===Scribus 1.4.x===<br />
One method for obtaining and then building Scribus is to download the compressed tar file, for example from [https://sourceforge.net/projects/scribus/files/scribus/1.4.6/ https://sourceforge.net/projects/scribus/files/scribus/1.4.6/].<br />
<br />
Let's imagine you choose the one compressed with 7-zip, which is scribus-1.4.6.7z. Click the link to download, then on the command line go to the directory where it was saved (perhaps Downloads/). To extract this, type<br />
<pre><br />
7z x scribus-1.4.6.7z<br />
</pre><br />
which will create the directory '''scribus-1.4.6''', and inside this will be all the ingredients you need, aside from the dependencies mentioned below. As of this writing, qt4 is probably the basic Qt on your system.<br />
<br />
qt<br />
qt-devel<br />
qtwebkit-devel<br />
poppler-devel (on debian you might need poppler-private-dev too : see http://bugs.scribus.net/view.php?id=11162)<br />
podofo-devel<br />
ghostscript (this should already be bundled)<br />
pkgconfig<br />
lcms2-devel<br />
libjpeg-devel<br />
libtiff-devel<br />
cups-devel<br />
libxml2 and libxml2-devel (libxml2 should already be bundled)<br />
python<br />
python-devel<br />
fontconfig-devel<br />
openssl-devel (?)<br />
freetype<br />
freetype-devel<br />
python-pillow-devel (formerly python-imaging-devel)<br />
tk <br />
tkinter<br />
hunspell <br />
hunspell-devel (as of 1.4.2)<br />
cairo (cairo should already be bundled)<br />
cairo-devel <br />
boost-devel<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>For convenience, here is the above list listed all on the same line ----> </big><br />
<div class="mw-collapsible-content"><br />
apt-get install qt4 qt4-devel qtwebkit-devel poppler-devel podofo-devel ghostscript pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel<br />
</div></div><br />
<br />
Once you have all of these, along with '''cmake''', then cd inside the scribus1.4.6 directory and type<br />
<pre><br />
cmake ./<br />
</pre><br />
for a basic setup so that Scribus 1.4.6 will be installed to the standard location. Scribus is still not built yet, so do this:<br />
<pre><br />
make<br />
</pre><br />
To install in this system location you need root privileges with '''sudo''' or '''su'''. Choose one of these, '''sudo''' will ask for your password (presuming you have administrative privileges), and '''su''' will ask for root's password.<br />
<pre><br />
sudo make install<br />
<br />
su<br />
make install<br />
</pre><br />
<br />
In addition to the above each Linux distrubution has it's own quirks to be aware of. The subsections below work to address them:<br />
====Fedora====<br />
An advantage of building your own Scribus 1.4.6 in Fedora is that, in contrast to the Scribus you may find on the repository, your own built Scribus will have the online manual, which is lacking in Fedora's RPM package. Fedora now uses '''dnf''' for package management. This command should cover all that you need (for 1.4.6 &ndash; see above for the dnf command for 1.5.x):<br />
<br />
'''sudo dnf qt qt-devel qtwebkit-devel poppler-devel podofo-devel ghostscript-devel pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel'''<br />
<br />
Something to note is that if you already have all the dependencies for 1.5.x, all you need to add is '''qt-devel'''.<br />
<br />
====Packages for Ubuntu====<br />
{{Warning|Please update this section}}<br />
To install all the required libraries and packages for Debian or Ubuntu type the following in a terminal:<br />
sudo apt-get build-dep scribus-ng<br />
<br />
In March 2011 the build dependencies for Scribus 1.4.0 on Debian/Ubuntu were: <br />
debhelper (>= 7), cmake (>= 2.4.3), gcc (>=3.3.5), libqt4-dev (>= 4.6), libcairo2-dev, zlib1g-dev,<br />
liblcms1-dev (>= 1.13), libtiff4-dev, libcups2-dev,libxml2-dev (>= 2.6.16), gettext, python-all-dev,<br />
libboost-python-dev, libaspell-dev, libpodofo-dev (>= 0.8.4), quilt<br />
<br />
[http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon).<br />
<br />
==== The easy way for Debian users ====<br />
{{Warning|Please update this section}}<br />
On <strong>Debian</strong>, if you install the develeopment packages as described above(<code>apt-get build-dep scribus-ng</code>) you will need the following packages to build the trunk (status September 2011):<br />
* libqtwebkit-dev<br />
* poppler-private-dev may be needed, see {{b|11162}}<br />
<strike>If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc for instance) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
</strike><br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
</div></div><br />
<br />
== Build from Source ==<br />
<span style="background-color: #FFFF00"><big>Moved from top of the page..being integrated [[User:Kunda|Kunda]] ([[User talk:Kunda|talk]]) 15:07, 29 June 2014 (CEST)</big><br /><br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. </span><br />
<br />
<span style="background-color: #FFFF00">'''Watch out:'''<br />
<span style="background-color: #FFFF00">* Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
<span style="background-color: #FFFF00">* And if you already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
</span><br />
------<br />
Take as an example this following set of commands which are geared towards the Linux environment. Here we see a case in which there is a downloading of the Scribus development version (1.5, not yet stable), building it and then installing it. Note that this assumes that the environment has been prepared previously with all the dependencies installed. <br />
<br />
<big><span style="background-color: #FFFF00">Recently moved from top of page. Still fine tuning how to represent this.</span></big><br />
{{Warning|You must have CMake version &ge; 2.8.9 (Older versions will fail). See: [[Official:Compile with CMake]]}}<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.net/trunk/Scribus<br />
cd ./Scribus<br />
mkdir build<br />
cd build<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn ..<br />
make<br />
sudo make install<br />
</pre><br />
<br />
'''Note:'''<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
* in case you want to install the 1.4 stable version, replace the "svn" instruction with following : svn co svn://scribus.net/branches/Version14x/Scribus<br />
<big><span style="background-color: #FFFF00">End of subsection</span></big><br />
<br />
==Start the Build Process ==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Some options that the Scribus CMake files know about (more can be found here : http://wiki.scribus.net/canvas/CMake_Build_Options):<br />
*-DWANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*-DWANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*<strike>-DWANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+</strike>. ('''DEPRECATED''') <br />
*-DWANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*-DWANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
*-DWANT_HUNSPELL=1: This will enable the new (as of 1.4.2) hunspell-based spell checking capabilities across *all* platforms.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
<strike>For example: to make a cairo debug build, then something like this:</strike><br />
<br />
<strike><code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code></strike><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-Source-Builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Simple!<br />
<br />
==More CMake Options==<br />
[[CMake_Build_Options]]<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
=<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*Prefixes for more packages<br />
<br />
<br />
==Appimages==<br />
<br />
As an alternative to build scribus, you can download and use daily [[AppImages]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=34523
Building SVN versions with CMake
2018-12-08T23:23:32Z
<p>Gpittman: /* Fedora */</p>
<hr />
<div>{{Cleanup}}<br />
[[Category:Installation]] [[Category:Development]]<br />
<br />
This page tries to describe how to build Scribus from source.<br />
The instructions mainly refer to building Scribus on Linux. Building on Mac OS and on Windows is not easy; you can find some explanations for Mac OS [[Installing from SVN on Mac OS X|here]], and for Windows [[Building SVN versions on Windows|here]]. <br />
<br />
=TL;DR (Too Long; Didn't Read)=<br />
<big>You know what you are doing already and just want to compile Scribus via SVN, skip the introduction and go to [[{{PAGENAME}}#Version 1.5.x|Installing 1.5svn]]</big><br />
<br />
=Why would I Need or Want to 'Build' Scribus?=<br />
<big><br />
# '''For Necessity:''' You are using the current stable version, but certain bugs are a problem, and you know they have been fixed since the last release.<br />
# '''For Science:''' You have heard about some new features in the development version, and you'd like to try them out.<br />
# '''For the World:''' You're considering helping out the Scribus project and want to see how it's put together to get some idea about how you can help.<br />
</big><br />
==='Or, for that matter, what is this 'Building' you speak of?===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>Expand this content if you need a little bit more background on what Building source code means. ---></big><br />
<div class="mw-collapsible-content"><br />
<big>When you are going to build or compile Scribus, what you have downloaded (if you have downloaded the source code) is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ programming language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your computer can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your computer to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is being written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team requires the use of CMake for this configuring process. It is quick, easy to use, and easy for the developers to write for &ndash; even CMake needs instructions. You can also pass to CMake several special parameters for your particular Computer setup, for example, where you want Scribus to be installed.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.</big><br />
</div><br />
</div><br />
<br />
== Fear is the mind Killer... ==<br />
[[Image:Fear-is-the-mind-killer-Dune.png|500px|thumb|right|"Do not fear building Scribus from source" ~Paul Muad'dib Atreides]]<br />
'''There is nothing to fear here, building Scribus yourself is not as hard as it sounds'''. You will not break your computer.<br />
<br />
This page can teach a beginner many things at once: starting with beginning to comprehend the internals of Scribus to appreciating the Command Line shell and how to invoke commands through it. Learn how to install software libraries (components that Scribus utilizes) and go so far as to modify source code through applying patches. This exposure will help increase your skill set to work on most all platforms and widen your knowledge of software creation and maintenance.<br />
<br />
=1st: Download latest snapshot with Subversion=<br />
Subversion is the versioning control system used for Scribus. This allows multiple developers to hack on Scribus source code simultaneously. Check the [[Subversion]] page for further details on how to use this tool. Make sure you have svn installed. You don't need to learn all subversion commands and options: "svn co" and "svn up" might suffice, see below for examples.<br />
<br />
You should create a directory in which the Scribus source code will be downloaded. Then change to that directory, and once you are there, you can download the source code with a simple command. You have to choose which branch you will download, as shown in the table below:<br />
<br />
{| cellspacing="10" cellpadding="6"<br />
! Status !! Version !! !! SVN Path !! Command to download from SVN<br />
|-<br />
|'''Development''' || '''1.5.x''' || || /trunk/Scribus || <tt><b>svn co svn://scribus.net/trunk/Scribus scribus15</b></tt><br />
|-<br />
|'''Development Snapshot''' || '''1.5.0''' || || /trunk/Scribus revision 20099 || <tt><b>svn co -r 20099 svn://scribus.net/trunk/Scribus scribus150</b></tt><br />
|-<br />
|'''Stable''' || '''1.4.x''' || ||/branches/Version14x/Scribus || <tt><b>svn co svn://scribus.net/branches/Version14x/Scribus scribus14x</b></tt><br />
|-<br />
|Outdated || <strike>v.1.3.3x</strike> || ||<strike>/branches/Version133x/Scribus</strike> || <strike><tt><b>svn co svn://scribus.net/branches/Version13x/Scribus scribus13x</b></tt></strike><br />
|}<br />
<small>'''Important Notes:''' <br />
* All subversion URLs for Scribus anonsvn are based at: '''svn://scribus.net/'''<br />
* Updating your working copy is much the same as cvs - just cd into your working copy and run <tt><b>"svn up"</b></tt>.<br />
* There's also '''http://scribus.net/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.net/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies.<br />
* If you used to check out -r <Version>, check out <SVN Path> instead<br />
</small><br />
<br />
------<br />
<br />
'''Thanks to [http://anduin.net Anduin.net], anonymous SVN access is updated daily.'''<br />
<br />
===Example===<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Here is an example of the commands for downloading the source code:<br />
<div class="mw-collapsible-content"><br />
<br />
<small>(This example is for Linux; on other platforms you should use the corresponding commands)</small><br />
<br />
Let's suppose that you want to download the Scribus 1.5.0. source code in a directory called "scribussource" under your home directory. Here are the commands:<br />
<br />
mkdir ~/scribussource<br />
cd ~/scribussource<br />
svn co svn://scribus.net/trunk/Scribus<br />
<br />
When subversion finishes downloading, you will find the source code in ~/scribussource/Scribus<br />
<br />
If you have the source code and you want to update it to the latest version:<br />
<br />
cd ~/scribussource/Scribus<br />
svn up<br />
</div></div><br />
<br />
=2nd: Install methods: Package Manager, Source, Out-of-Source Build=<br />
<br />
==Essential tools==<br />
Before going further, we must understand that in order for anything to get built, tools need to exist. In modern OS's especially Linux many of these are build tools arrive already bundled. If they aren't for some reason you will need to '''install them manually''' (see [[{{PAGENAME}}#Package Manager|package manager]])<br />
* gcc<br />
* gcc-c++<br />
* cmake (version &ge; 2.8.9)<br />
<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
<big>There are several option for installation.<br />
* [[{{PAGENAME}}#Package Managers| Package Manager]]: (difficulty: easy) Does a lot of the heavy lifiting by installing all the components you specify <br />
* [[{{PAGENAME}}#Build from Source| Build from Source]]: (difficulty: intermediate to advanced) Build it the old fashion way<br />
* [[{{PAGENAME}}#Out-of-Source-Builds| Out-of-Source-Builds]]: (difficulty: intermediate) Needs explanation<br />
</big><br />
<br />
==Package Managers==<br />
Note: many Linux distros have their own Package Managers i.e. Debian has '''apt''', Fedora and Centos have '''yum''', more recently superceded by '''dnf''', Redhat uses '''rpm''' etc... On Mac OS X there are several choices, most popular are '''Macports''' and '''Homebrew'''. In general, by utilizing the installed package manager we can streamline the installations through easy one liners which will automate the install. We do this by invoking the following pattern: <br />
<br />
<tt> <b>(package-manager) install (software-or-library-package-name)</b></tt> <br />
<br />
'''Debian'''; &nbsp;&nbsp;&nbsp;'''<code>apt-get install cmake</code>''' <br /><br />
'''Fedora''': &nbsp;&nbsp;&nbsp;'''<code>dnf install cmake</code>''' <br /><br />
'''MacOSX''':&nbsp;'''<code>brew install cmake</code>'''<br />
<br />
==Specific Dependencies== <br />
<!-- This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. --><br />
Dependencies are considered to be 3rd party software libraries or other altogether unique software projects that are have components that are needed to build a specific project from. When we want to build Scribus we need to make sure that we have all the dependencies fulfilled or else it will complain to us about missing components or obsolete ones. The following section assumes you need to manually install dependencies. Here are the list of package names that will be needed to be installed before attempting to build Scribus. Each major version of Scribus will require different dependencies.<br />
<br />
===Version 1.5.x===<br />
Here is a list of dependencies for Scribus 1.5.x:<br />
<br />
Qt (version >= 5.2; see below for details)<br />
Cairo<br />
Pixman<br />
Boost<br />
Cups (not required on Windows)<br />
Fontconfig (not required on Windows)<br />
Freetype<br />
Libhunspell (if missing, spellchecker won't work)<br />
Libjpeg<br />
Libtiff<br />
Libxml2<br />
LittleCMS (version >= 2.1)<br />
Pkgconfig (Linux)<br />
PoDoFo<br />
Poppler, Poppler-data, and Poppler-cpp<br />
Python 2.7<br />
Python-Pillow<br />
Tk and Tkinter (required by some scripts shipped with Scribus)<br />
<br />
For Scribus 1.5.3+<br />
Harfbuzz<br />
ICU (UC module)<br />
Qt 5.5+<br />
<br />
For Scribus 1.5.5+<br />
Qt 5.7+<br />
C++11<br />
<br />
On Linux, for each item you have to install both the main package and the development package (for example: cairo and cairo-devel, pixman and pixman-devel, and so on). Some packages should be already installed (for example, Cairo or CUPS).<br />
<br />
====Getting and installing Qt5====<br />
Starting with rev. 19790 (4 February 2015), Qt 5.2 or later is required.<br />
<br />
If Qt5 is not present on your system, you have to install or build it.<br />
<br />
You can download Qt5 from http://qt-project.org/downloads. Binary installers are available for Windows, Mac&nbsp;OS X and Linux. For Linux, if your distribution provides the latest Qt5, you can install it from its repositories (details for some distributions are listed below).<br />
<br />
Also available is the source code, in case you want to build Qt5 yourself, or if an installer is not available for your operating system.<br />
<br />
If you're using the Qt installer on Linux, make sure to make the file <code>qt-opensource-linux-x**-5.*.*.run</code> executable. You can do this via your chosen UI or the command line. The latter requires the following commands:<br />
<br />
<code>chmode +x /path/to/qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
To start the installation process, use the <code>cd</code> command to move into the installer's directory.<br />
<br />
Next, run the following command:<br />
<br />
<code>./qt-opensource-linux-x**-5.*.*.run</code><br />
<br />
If run without root privileges, the installer will suggest /home/username/Qt5.* as the installation directory. That's fine if you only want to test Scribus 1.5.x. If you also want to test the latest versions of other programmes using Qt5, you should install Qt5 with root privileges.<br />
<br />
If you have Qt4 and Qt5 installed, and/or cmake does not find Qt5, you need to specify its location with the [[CMake_Build_Options#Qt5-Specific|build option]] -DQT_PREFIX="path-to-Qt5" (for example: -DQT_PREFIX="/home/user/Qt/5.1.1/gcc/")<br />
<br />
In case you need a list, the required qt5 libs are : <br />
Qt5Core<br />
Qt5Widgets<br />
Qt5Gui<br />
Qt5Xml<br />
Qt5WebKit<br />
Qt5WebKitWidgets<br />
Qt5Network<br />
Qt5OpenGL<br />
Qt5LinguistTools<br />
Qt5Quick<br />
Qt5PrintSupport<br />
<br />
In case you got problems, Pygmee suggests too : "it build here after i've build sigil where it make a bit changes in QT5 config".<br />
<br />
=====Debian=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
On Debian Testing, on top of the packages pulled in by apt-get build-dep you need. ----><br />
<div class="mw-collapsible-content"><br />
'''sudo apt install libqt5webkit5-dev qtquick1-5-dev qtdeclarative5-dev \'''<br />
'''qttools5-dev-tools qttools5-dev liblcms2-dev'''<br />
'''sudo apt install libpoppler-private-dev''' (3)<br />
Note 1: They are all available in the official Debian repositories.<br />
Note 2: This list should also apply for the latest Ubuntu release.<br />
Note 3: Needed since Ubuntu-16.04 and its derivatives like Linux Mint.<br />
</div></div><br />
<br />
=====Fedora 19 and later=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Fedora 19 and later have Qt5 packages available from their repositories. The requirements seem to be ----><br />
<div class="mw-collapsible-content"><br />
'''yum install qt5-qtbase qt5-qtbase-devel qt5-qtdeclarative qt5-qtdeclarative-devel qt5-qttools \'''<br />
'''qt5-qttools-devel qt5-qtwebkit qt5-qtwebkit-devel qt5-qtbase-static'''<br />
<br />
The above list will bring in '''qt5-qtbase-gui''' and possibly some other packages as dependencies. You might need also to install '''glibc-headers'''.<br />
</div></div><br />
=====Notes on Fedora 26 &amp; 27=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
This will probably also work for Fedora 24 and 25 ----><br />
<div class="mw-collapsible-content"><br />
Fedora now uses '''dnf''' instead of '''yum''' for package management. Using the following command will supply all the needed requirements for Scribus 1.5.x (note that some are optional features, such as OpenSceneGraph). <br />
<br />
'''sudo dnf -y install boost-devel cairo-devel cups-devel fontconfig-devel freetype-devel GraphicsMagick-c++-devel GraphicsMagick-devel harfbuzz-devel hunspell-devel kernel-devel lcms2-devel libicu-devel libjpeg-turbo-devel libmspub-devel libpng-devel librevenge-devel libstdc++-devel libtiff-devel libwpd-devel libxml2-devel OpenSceneGraph-devel podofo-devel poppler-devel poppler-data poppler-data-devel poppler-cpp poppler-cpp-devel python-devel python-qt5-devel qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qttools-devel qt5-qtwebkit-devel'''<br />
<br />
Even though all of these are just the -devel packages, dnf will pull in all necessary additional requirements. Note that '''poppler-cpp''' and '''poppler-cpp-devel''' seem to be new requirements.<br />
</div><br />
</div><br />
<br />
=====Ubuntu=====<br />
<br />
'''Firstly, if you are running Ubuntu with version < 15.10, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.04 ----><br />
<div class="mw-collapsible-content"><br />
* Initially install:<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev qttools5'''<br />
* Then, specifically relating to qt5, install: <br />
'''sudo apt-get install libqt5declarative5-dev qtlocation5-dev qtsensors5-dev''' <br />
* Install the usual libs '''not''' related to qt5 : <br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v13.10 ----><br />
<div class="mw-collapsible-content"><br />
Almost the same as 13.04 except '''no qttools5''' and '''no libqt5declarative5-dev''' instead '''use qtdeclarative5-dev''' <br />
<br />
'''sudo apt-get install qt5-default qttools5-dev-tools libqt5location5 libqt5webkit5-dev libqt5webkit5 \'''<br />
'''qt5-qmake libqt5xml5 libqt5gui5 libqt5core5 qttools5-dev'''<br />
'''sudo apt-get install qtdeclarative5-dev qtlocation5-dev qtsensors5-dev'''<br />
'''sudo apt-get install zlib1g-dev libpng12-dev libjpeg-dev libtiff5-dev libpython-all-dev \'''<br />
'''libfreetype6-dev libcairo2-dev libcups2-dev libxml++2.6-dev liblcms2-dev'''<br />
<br />
# Note 1: There are bugs with qt5 version 5.0.2. Install qt5 version 5.2 with the installer found on https://qt-project.org/downloads. <br />
# Note 2: (JLuc, 25 May 2014): I followed this procedure step by step and everything when right out of the box.<br />
# Note 3 (unknown author) : In addition, I had to install: libgl1-mesa-dev and dependencies.<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v14.04 ----><br />
<div class="mw-collapsible-content"><br />
This is how i compiles scribus 1.5 on a quite freshly installed Ubuntu 14.04 :<br />
# Install scribus 1.5 out of the scribus friend's PPA (https://launchpad.net/~scribus/+archive/ubuntu/ppa). There are too many keyboard management bugs with this version, but it maybe installs some usefull libraries. Then uninstall it.<br />
# Install cmake, g++ and subversion in case there are not there allready ("sudo apt-get install cmake" and "sudo apt-get install subversion")<br />
# Install (using synaptics or sudo apt-get) the following libraries and their dependancies : libdrm-dev, libgl1-mesa-dev, libxml2-dev, libzip-dev, libfreetype6-dev, liblcms2-dev, libpodofo-dev, libcairo2-dev, libmagick++dev (maybe useless), libgraphicsmagick++1-dev, libcups2-dev, libpython2.7-dev, libpoppler-qt5-dev (maybe useless), libpoppler-cpp-dev, libpoppler-private-dev, libhunspell-dev<br />
# Compile using maksvn script (https://github.com/JLuc/makscribus/blob/master/maksvn).<br />
That's it !<br />
</div></div><br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Ubuntu v16.04 ----><br />
<div class="mw-collapsible-content"><br />
To compile scribus 1.5 on ubuntu 16.04, you need to follow:<br />
# make sure that you installed QT as mention above.<br />
# executed the the following commands to install required libraries:<br />
'''<code> sudo apt-get update -qq;</code>''' <br /><br />
'''<code> sudo apt-get install --force-yes cmake libboost-python-dev libcups2-dev libhunspell-dev libhyphen-dev liblcms2-dev libpodofo-dev libtiff-dev libxml2-dev python-all-dev zlib1g-dev libgraphicsmagick++1-dev libopenscenegraph-dev libpoppler-dev libpoppler-private-dev libcairo2-dev libwpg-dev libmspub-dev libcdr-dev libvisio-dev libharfbuzz-dev libharfbuzz-icu0 coreutils binutils python-tk</code>'''<br />
<br />
</div></div><br />
<br />
=====OpenSuse=====<br />
'''Firstly, if you are running OpenSUSE with version < 13.2, upgrade. As of Scribus 1.5.2, Qt 5.3 and cairo 1.14 are required.'''<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
13.2 or newer ----><br />
<div class="mw-collapsible-content"><br />
* Install the OS<br />
* install Qt5 - sudo zypper in -t devel_qt5<br />
* Install these packages via Yast2 or 'zypper in' from the command line:<br />
python-devel <br />
cairo-devel<br />
hunspell-devel<br />
cmake<br />
subversion<br />
cups-devel <br />
libtiff-devel<br />
liblcms2-devel<br />
cups-devel<br />
boost-devel<br />
libjpeg8-devel<br />
libtiff-devel<br />
libpodofo-devel<br />
libpoppler-devel<br />
librevenge-devel<br />
libcdr-devel<br />
libmspub-devel<br />
libvisio-devel<br />
libfreehand-devel<br />
* Proceed with Scribus compilation process.<br />
</div></div><br />
<br />
=====Windows=====<br />
Please refer to [[Building_SVN_versions_on_Windows]]<br />
<br />
=====Mac OSX=====<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
MacPorts (recommended by Scribus core-devs) ----><br />
<div class="mw-collapsible-content"><br />
Needs details<br />
</div></div><br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
Homebrew Package Manager (Scribus community supported effort) ----><br />
<div class="mw-collapsible-content"><br />
FYI, please don't post homebrew bugs on the bugtracker. Instead read the top notice on [[Scribus_and_Homebrew]].<br />
'''1. brew tap scribusproject/scribus'''<br />
'''2. brew install --HEAD scribus --verbose'''<br />
'''3. brew linkapps --local scribus'''<br />
'''4. Invoke with: ~/Applications/Scribus.app/Contents/MacOS/Scribus'''<br />
</div></div><br />
<br />
===Additional dependencies for some graphics formats===<br />
In 1.5.0+, there are a number of vector and bitmap graphics formats which can now be imported into Scribus. Some of these have particular additional dependencies.<br />
<br />
====GraphicsMagick (Optional)====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added import filters will be available if you have it (and cmake will detect it automatically). What Scribus needs are the following packages: graphicsmagick, graphicsmagick-devel, graphicsmagick-c++, and graphicsmagick-c++-devel.<br />
<br />
====OpenSceneGraph (Optional)====<br />
This may be available with your Linux distribution (definitely for Fedora 17 and later). You can also [http://www.openscenegraph.org/projects/osg/wiki/Downloads download and compile] yourself.<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''Fedora'''<br />
<div class="mw-collapsible-content"><br />
'''sudo yum install OpenSceneGraph OpenSceneGraph-devel'''<br />
<br />
should be enough, and will get you the additional requirements of Inventor, OpenThreads, and OpenThreads-devel.<br />
</div></div><br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
'''OpenSUSE'''<br />
<div class="mw-collapsible-content"><br />
go to http://software.opensuse.org/package/OpenSceneGraph and use the 1-click install procedure.<br />
</div></div><br />
====MS Publisher and WPG Importers====<br />
<br />
To build Scribus with support for MS Publisher and WPG files, you need [http://cgit.freedesktop.org/libreoffice/libmspub/ libmspub], as well as [http://libwpg.sourceforge.net/ libwpg] and [http://libwpd.sourceforge.net/ libwpd]. Note that the minimum version for PUB import is libmspub 0.0.6, and also that you want the development packages (libwpd-devel, libwpg-devel, libmspub-devel, for example in Fedora).<br />
<br />
Update (June 2014): Scribus is now able to import MS Publisher, MS Visio and CorelDraw documents via librevenge. See [[Librevenge|this page]] for details.<br />
<br />
===Scribus 1.4.x===<br />
One method for obtaining and then building Scribus is to download the compressed tar file, for example from [https://sourceforge.net/projects/scribus/files/scribus/1.4.6/ https://sourceforge.net/projects/scribus/files/scribus/1.4.6/].<br />
<br />
Let's imagine you choose the one compressed with 7-zip, which is scribus-1.4.6.7z. Click the link to download, then on the command line go to the directory where it was saved (perhaps Downloads/). To extract this, type<br />
<pre><br />
7z x scribus-1.4.6.7z<br />
</pre><br />
which will create the directory '''scribus-1.4.6''', and inside this will be all the ingredients you need, aside from the dependencies mentioned below. As of this writing, qt4 is probably the basic Qt on your system.<br />
<br />
qt<br />
qt-devel<br />
qtwebkit-devel<br />
poppler-devel (on debian you might need poppler-private-dev too : see http://bugs.scribus.net/view.php?id=11162)<br />
podofo-devel<br />
ghostscript (this should already be bundled)<br />
pkgconfig<br />
lcms2-devel<br />
libjpeg-devel<br />
libtiff-devel<br />
cups-devel<br />
libxml2 and libxml2-devel (libxml2 should already be bundled)<br />
python<br />
python-devel<br />
fontconfig-devel<br />
openssl-devel (?)<br />
freetype<br />
freetype-devel<br />
python-pillow-devel (formerly python-imaging-devel)<br />
tk <br />
tkinter<br />
hunspell <br />
hunspell-devel (as of 1.4.2)<br />
cairo (cairo should already be bundled)<br />
cairo-devel <br />
boost-devel<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px;"><br />
<big>For convenience, here is the above list listed all on the same line ----> </big><br />
<div class="mw-collapsible-content"><br />
apt-get install qt4 qt4-devel qtwebkit-devel poppler-devel podofo-devel ghostscript pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel<br />
</div></div><br />
<br />
Once you have all of these, along with '''cmake''', then cd inside the scribus1.4.6 directory and type<br />
<pre><br />
cmake ./<br />
</pre><br />
for a basic setup so that Scribus 1.4.6 will be installed to the standard location. Scribus is still not built yet, so do this:<br />
<pre><br />
make<br />
</pre><br />
To install in this system location you need root privileges with '''sudo''' or '''su'''. Choose one of these, '''sudo''' will ask for your password (presuming you have administrative privileges), and '''su''' will ask for root's password.<br />
<pre><br />
sudo make install<br />
<br />
su<br />
make install<br />
</pre><br />
<br />
In addition to the above each Linux distrubution has it's own quirks to be aware of. The subsections below work to address them:<br />
====Fedora 1.4.6====<br />
An advantage of building your own Scribus 1.4.6 in Fedora is that, in contrast to the Scribus you may find on the repository, your own built Scribus will have the online manual, which is lacking in Fedora's RPM package. Fedora now uses '''dnf''' for package management. This command should cover all that you need:<br />
<br />
'''sudo dnf qt qt-devel qtwebkit-devel poppler-devel podofo-devel ghostscript-devel pkgconfig lcms2-devel libjpeg-devel libtiff-devel cups-devel libxml2 libxml2-devel python python-devel fontconfig-devel openssl-devel freetype freetype-devel python-pillow-devel tk tkinter hunspell hunspell-devel cairo cairo-devel boost-devel'''<br />
<br />
Something to note is that if you already have all the dependencies for 1.5.x, all you need to add is '''qt-devel'''.<br />
<br />
====Packages for Ubuntu====<br />
{{Warning|Please update this section}}<br />
To install all the required libraries and packages for Debian or Ubuntu type the following in a terminal:<br />
sudo apt-get build-dep scribus-ng<br />
<br />
In March 2011 the build dependencies for Scribus 1.4.0 on Debian/Ubuntu were: <br />
debhelper (>= 7), cmake (>= 2.4.3), gcc (>=3.3.5), libqt4-dev (>= 4.6), libcairo2-dev, zlib1g-dev,<br />
liblcms1-dev (>= 1.13), libtiff4-dev, libcups2-dev,libxml2-dev (>= 2.6.16), gettext, python-all-dev,<br />
libboost-python-dev, libaspell-dev, libpodofo-dev (>= 0.8.4), quilt<br />
<br />
[http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon).<br />
<br />
==== The easy way for Debian users ====<br />
{{Warning|Please update this section}}<br />
On <strong>Debian</strong>, if you install the develeopment packages as described above(<code>apt-get build-dep scribus-ng</code>) you will need the following packages to build the trunk (status September 2011):<br />
* libqtwebkit-dev<br />
* poppler-private-dev may be needed, see {{b|11162}}<br />
<strike>If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc for instance) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
</strike><br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
</div></div><br />
<br />
== Build from Source ==<br />
<span style="background-color: #FFFF00"><big>Moved from top of the page..being integrated [[User:Kunda|Kunda]] ([[User talk:Kunda|talk]]) 15:07, 29 June 2014 (CEST)</big><br /><br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. </span><br />
<br />
<span style="background-color: #FFFF00">'''Watch out:'''<br />
<span style="background-color: #FFFF00">* Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
<span style="background-color: #FFFF00">* And if you already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
</span><br />
------<br />
Take as an example this following set of commands which are geared towards the Linux environment. Here we see a case in which there is a downloading of the Scribus development version (1.5, not yet stable), building it and then installing it. Note that this assumes that the environment has been prepared previously with all the dependencies installed. <br />
<br />
<big><span style="background-color: #FFFF00">Recently moved from top of page. Still fine tuning how to represent this.</span></big><br />
{{Warning|You must have CMake version &ge; 2.8.9 (Older versions will fail). See: [[Official:Compile with CMake]]}}<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.net/trunk/Scribus<br />
cd ./Scribus<br />
mkdir build<br />
cd build<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn ..<br />
make<br />
sudo make install<br />
</pre><br />
<br />
'''Note:'''<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
* in case you want to install the 1.4 stable version, replace the "svn" instruction with following : svn co svn://scribus.net/branches/Version14x/Scribus<br />
<big><span style="background-color: #FFFF00">End of subsection</span></big><br />
<br />
==Start the Build Process ==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Some options that the Scribus CMake files know about (more can be found here : http://wiki.scribus.net/canvas/CMake_Build_Options):<br />
*-DWANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*-DWANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*<strike>-DWANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+</strike>. ('''DEPRECATED''') <br />
*-DWANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*-DWANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
*-DWANT_HUNSPELL=1: This will enable the new (as of 1.4.2) hunspell-based spell checking capabilities across *all* platforms.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
<strike>For example: to make a cairo debug build, then something like this:</strike><br />
<br />
<strike><code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code></strike><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-Source-Builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus15svn</code><br />
<br />
Simple!<br />
<br />
==More CMake Options==<br />
[[CMake_Build_Options]]<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
=<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*Prefixes for more packages<br />
<br />
<br />
==Appimages==<br />
<br />
As an alternative to build scribus, you can download and use daily [[AppImages]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_an_Object-sized_Document&diff=34501
Creating an Object-sized Document
2018-05-19T19:01:06Z
<p>Gpittman: /* object2doc.py */</p>
<hr />
<div>{{Scripting Index}}<br />
Here is a small script based on a request from the mail list. What the poster wanted to know was whether there was a way to export a graphics frame to a file of some sort. Although you can export a document page as an image, this then requires some editing afterward. You could also use some type of screen grab software.<br />
<br />
Another method would be to make a copy of the original object, create a new document the same size as the object, and then paste the object to it. This way, you could then either export to PDF or export as an image, with no need to trim the image later.<br />
<br />
Here is a script that does this automatically, following these above steps, using '''copyObject()''' and '''pasteObject()'''.<br />
<br />
==object2doc.py==<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
# File: object2doc.py - <br />
# © 2017.03.28 Gregory Pittman<br />
# This program is free software; you can redistribute it and/or modify<br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
"""<br />
USAGE<br />
<br />
You must have a document open, and an object selected.<br />
<br />
The script copies the object, then creates a new single-page<br />
<br />
document having the width and height of the selected object.<br />
<br />
It then pastes the object to the new document, and moves it to <br />
<br />
the 0,0 position.<br />
<br />
"""<br />
import scribus<br />
<br />
if scribus.haveDoc():<br />
pass<br />
else:<br />
scribus.messageBox('Usage Error', 'You need a Document open', scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
if scribus.selectionCount() == 0:<br />
scribus.messageBox('Scribus - Usage Error',<br />
"There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
if scribus.selectionCount() > 1:<br />
scribus.messageBox('Scribus - Usage Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
sel_obj = scribus.getSelectedObject()<br />
scribus.copyObject(sel_obj)<br />
units = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
objwidth, objheight = scribus.getSize(sel_obj)<br />
scribus.setUnit(units)<br />
scribus.newDocument((objwidth,objheight), (10,10,10,10),scribus.PORTRAIT,1,scribus.UNIT_POINTS,scribus.PAGE_1,0,1)<br />
scribus.pasteObject(sel_obj)<br />
scribus.moveObjectAbs(0,0)<br />
scribus.setRedraw(1)<br />
scribus.docChanged(1)<br />
scribus.messageBox("Finished", "Done!",scribus.ICON_NONE,scribus.BUTTON_OK)<br />
<br />
</syntaxhighlight><br />
===Notes===<br />
* Incidentally, this seems to work not only on image frames, but any other sort of frame, including in imported SVG. It also works for shapes and polygons, render frames or Bezier curves, for example. I notice that with Bezier curves, there is a slight mismatch between the measurements that come from '''getSize()''' and the outer boundaries of the line, so in other words, the document size ended up a bit smaller than the line, even though all the control points of the line were on the page. This is especially noticeable when the stroke width is thick. The same would apply to a shape or polygon with a thick stroke.<br />
* If you run this on a rotated object, a document page will be created that is not rotated, so placement of the rotated copy will be off, though correctable by rotating the object to 0°. Also related to this is that this script assumes a Basepoint in the upper left-hand corner of the object, so that the upper left-hand corner of the object ends up in the upper left hand corner of the page.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Category:Scripts&diff=34463
Category:Scripts
2018-03-01T23:28:37Z
<p>Gpittman: /* Scripter */</p>
<hr />
<div>[[Category:EN]] [[Category:Categories]]<br />
'''Other languages:''' [[:Category:Skrypty_i_wtyczki|Polski (pl)]] [[:Category:Scripts_e_Plugins|Portuguese (pt_BR)]]<br />
{{TOC right}}<br />
= Scripter =<br />
<br />
Here is documentation about the current scripting component in Scribus:<br />
<br />
* [[Scripter API]] -- Routines which can be used in scripts to control Scribus<br />
* [[Scripter/Databases| Databases]] -- Scripts can interact with database software like MySQL or SQLite<br />
<br />
This wiki is capable of letting users download raw code embedded into the pages and have it appear syntax highlighted.<br />
* So as to cite python script code with proper syntax hilight, use the following tag <nowiki><syntaxhighlight lang='python'></nowiki> instead of using the usual HTML tag <nowiki><pre></nowiki>.<br />
* See example and other possible tags : [[Raw_Code_Download| Wikitext for Raw Code Download]]<br />
<br />
Note : A new script engine is currently being integrated into Scribus. The next steps will be to get the script engine to work (should already be ok), get the editor to work, revise the structure of the API, add new functions to the API and mostly : port scripts to the new scripter. See [[Scripter Architecture|Scripter NG non-complete documentation about architecture]]<br />
<br />
== Pure Python Functions ==<br />
<br />
The open() function is a pure python function and does not involve any<br />
Scribus code. Here are some pages with advices on how to handle unicode file<br />
names in python:<br />
<br />
- http://docs.python.org/tutorial/inputoutput.html<br />
- http://www.evanjones.ca/python-utf8.html<br />
- http://boodebr.org/main/python/all-about-python-and-unicode<br />
<br />
The string returned by the Scribus fileDialog() function is always Unicode UTF-8 encoded.<br />
<br />
If file is not closed after python error within Scribus:<br />
This is up to you to handle python exceptions, Scribus cannot do that in your place<br />
<br />
== Script snippets ==<br />
<br />
<div style="border:2px solid lightgrey;padding:2px">Needs some snippets</div><br />
<br />
This section contains snippets you can use to create your own scripts.<br />
<br />
It features:<br />
<br />
* reading a file<br />
* updating a status bar<br />
* selecting a frame<br />
* pausing the screen update<br />
<br />
===Script Template===<br />
Here is a '''script template''' with all setups. Use it as a ''starting point'' for writing your own script, fill in your application specific code.<br />
[[Scripter/Snippet/Main| script template main()]]. There is also a template called [[boilerplate.py]] within Scribus Script directory.<br />
<br />
You might also check out [[scriptmaker.py]], a Python script to run outside of Scribus to make the beginnings of a script that only runs inside of Scribus!<br />
<br />
==[[Troubleshooting Scripts]]==<br />
The content is on another page, since this one has gotten a bit out of control in terms of its size.<br />
===Iterate over all elements on a page===<br />
<syntaxhighlight lang='python'><br />
page = 1<br />
pagenum = scribus.pageCount()<br />
content = []<br />
while (page <= pagenum):<br />
scribus.gotoPage(page)<br />
d = scribus.getPageItems()<br />
for item in d:<br />
// do something<br />
page += 1<br />
</syntaxhighlight><br />
<br />
===Get content like text from a frame===<br />
<syntaxhighlight lang='python'><br />
content = []<br />
d = scribus.getPageItems()<br />
for item in d:<br />
if (item[1] == 4):<br />
contents = scribus.getAllText(item[0])<br />
if (contents in content):<br />
contents = 'Duplication, perhaps linked-to frame'<br />
content.append(contents)<br />
elif (item[1] == 2):<br />
imgname = scribus.getImageFile(item[0])<br />
</syntaxhighlight><br />
<br />
ITEM TYPE<br />
* ItemType1 = 1,<br />
* ImageFrame = 2,<br />
* ItemType3 = 3,<br />
* TextFrame = 4,<br />
* Line = 5,<br />
* Polygon = 6,<br />
* PolyLine = 7,<br />
* PathText = 8,<br />
* LatexFrame = 9,<br />
* Multiple = 99<br />
<br />
===Auto-Output all Scripter Commands===<br />
<br />
From Scribus User http://meiradarocha.jor.br Mailinglist Feb. 2012<br />
<syntaxhighlight lang='python'><br />
d = dir(scribus)<br />
for j in d:<br />
try:<br />
exec 'res = '+j+'.__doc__'<br />
if res[0:5] == 'float':<br />
print '\nCONSTANT:\n',j,'\nVALUE: float'<br />
exec 'print '+j+'\n'<br />
elif res[0:5] == 'int(x':<br />
print '\nCONSTANT:\n',j,'\nVALUE: integer'<br />
exec 'print '+j+'\n'<br />
elif res[0:5] == 'tuple':<br />
print '\nTUPLE:\n',j,'\nVALUE:'<br />
exec 'print repr('+j+')\n'<br />
elif res[0:4] == 'str(':<br />
print '\nSTRING:\n',j,'\nVALUE:'<br />
exec 'print repr('+j+')\n'<br />
else:<br />
print '\nFUNCTION:\n'+j+'\n\nSYNTAX:'<br />
print res<br />
except: pass<br />
</syntaxhighlight><br />
<br />
==Image Manipulation==<br />
<br />
* [[Scripter/Images| Objects: Images]] -- Example Scripts that manipulate images in a Scribus document<br />
<br />
==[[Beginners Scripts]]==<br />
This content has been moved to a separate page to reduce the enormity of this one.<br />
<br />
==Basic scripts==<br />
<br />
Scripts which give you ideas how you can solve your tasks.<br />
<br />
* [[Poor man's mail merge]]<br />
* [[Enlarge2Page]] - Enlarge an object to the size of the page.<br />
* [[Making Guides at an Object's Borders]]<br />
* [[Using the new applyMasterPage() command]]<br />
* [[Swap Images]]<br />
* [[Creating Text Frames for Image Captions]]<br />
* [[Horizontal Rule over Text Frame]]<br />
* [[Creating an Object-sized Document]]<br />
<br />
==Full functional scripts==<br />
<br />
Scripts that are ready for achieving specific tasks<br />
{|<br />
|<br />
* [[Export all text|Export all text]] from a Scribus file<br />
* [[Export list of frames and page numbers]]<br />
* [[Script Resize selected objects|Resize selected objects]]<br />
* [[formatxml|Import XML and apply styles]]<br />
* [[align_to_left_page_margin|Align to the left page margin]] (after adding a new page in a double page document)<br />
* [[Bullets]] Make bulleted list<br />
* [[Bullets_and_numbered_lists|Bullets and numbered lists]]<br />
* [[Scribus_Generator|Scribus Generator]] Extend Scribus with Mail Merge functionality<br />
|<br />
* [[CalendarWizard]]<br />
* [[Image crop, resize and CMYK conversion. Save and reload in TIFF format]]<br />
* [[Image crop, resize and color conversion GUI]]<br />
* [[Apply basic ligatures to a document]]<br />
* [[Import CSV Data]]<br />
* [[Automatic story formatting]]<br />
* [[Clean-up the imported text based on the Slovak typographic rules]]<br />
|}<br />
<br />
==Scripting new Scribus' functions==<br />
<br />
Scripts which sketch new features which may be included in future releases of Scribus<br />
<br />
* [[Adjust a text frame to fit its content|Adjust the text frame size according to various factors]]<br />
<br />
== Extension scripts and PyQt ==<br />
<br />
* [[Extension script discussion]]<br />
* [[Experimental PyQt projects]]<br />
<br />
== Python issues ==<br />
<br />
* [[Known Scripter Issues]]<br />
<br />
= Other =<br />
* [[Extension_script_repository ]]<br />
* [[Web optimised PDF]] &mdash; learn how to minimize PDF size, make your life easier with the included Perl script (runs outside of Scribus)<br />
* [[Imagemagick Imposition]] &ndash; a bash script doing simple imposition of PNG files exported from Scribus<br />
* [[Printing_4-up_tickets_to_hard_copy_printer]] Shows a) automatic numbering in text boxes and b) hard-copy printing from script<br />
* [[Using createParagraphStyle]]<br />
* [[Text and Text Manipulation]]<br />
* Alessandro Rimoldi's blog series on scripter functions - [http://www.graphicslab.org/Blog/Blog a_l_e's blog]<br />
* [[Windows Full Python Integration]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Category:Scripts&diff=34462
Category:Scripts
2018-03-01T23:27:57Z
<p>Gpittman: /* Scripter */</p>
<hr />
<div>[[Category:EN]] [[Category:Categories]]<br />
'''Other languages:''' [[:Category:Skrypty_i_wtyczki|Polski (pl)]] [[:Category:Scripts_e_Plugins|Portuguese (pt_BR)]]<br />
{{TOC right}}<br />
= Scripter =<br />
<br />
Here is documentation about the current scripting component in Scribus: test<br />
<br />
* [[Scripter API]] -- Routines which can be used in scripts to control Scribus<br />
* [[Scripter/Databases| Databases]] -- Scripts can interact with database software like MySQL or SQLite<br />
<br />
This wiki is capable of letting users download raw code embedded into the pages and have it appear syntax highlighted.<br />
* So as to cite python script code with proper syntax hilight, use the following tag <nowiki><syntaxhighlight lang='python'></nowiki> instead of using the usual HTML tag <nowiki><pre></nowiki>.<br />
* See example and other possible tags : [[Raw_Code_Download| Wikitext for Raw Code Download]]<br />
<br />
Note : A new script engine is currently being integrated into Scribus. The next steps will be to get the script engine to work (should already be ok), get the editor to work, revise the structure of the API, add new functions to the API and mostly : port scripts to the new scripter. See [[Scripter Architecture|Scripter NG non-complete documentation about architecture]]<br />
<br />
== Pure Python Functions ==<br />
<br />
The open() function is a pure python function and does not involve any<br />
Scribus code. Here are some pages with advices on how to handle unicode file<br />
names in python:<br />
<br />
- http://docs.python.org/tutorial/inputoutput.html<br />
- http://www.evanjones.ca/python-utf8.html<br />
- http://boodebr.org/main/python/all-about-python-and-unicode<br />
<br />
The string returned by the Scribus fileDialog() function is always Unicode UTF-8 encoded.<br />
<br />
If file is not closed after python error within Scribus:<br />
This is up to you to handle python exceptions, Scribus cannot do that in your place<br />
<br />
== Script snippets ==<br />
<br />
<div style="border:2px solid lightgrey;padding:2px">Needs some snippets</div><br />
<br />
This section contains snippets you can use to create your own scripts.<br />
<br />
It features:<br />
<br />
* reading a file<br />
* updating a status bar<br />
* selecting a frame<br />
* pausing the screen update<br />
<br />
===Script Template===<br />
Here is a '''script template''' with all setups. Use it as a ''starting point'' for writing your own script, fill in your application specific code.<br />
[[Scripter/Snippet/Main| script template main()]]. There is also a template called [[boilerplate.py]] within Scribus Script directory.<br />
<br />
You might also check out [[scriptmaker.py]], a Python script to run outside of Scribus to make the beginnings of a script that only runs inside of Scribus!<br />
<br />
==[[Troubleshooting Scripts]]==<br />
The content is on another page, since this one has gotten a bit out of control in terms of its size.<br />
===Iterate over all elements on a page===<br />
<syntaxhighlight lang='python'><br />
page = 1<br />
pagenum = scribus.pageCount()<br />
content = []<br />
while (page <= pagenum):<br />
scribus.gotoPage(page)<br />
d = scribus.getPageItems()<br />
for item in d:<br />
// do something<br />
page += 1<br />
</syntaxhighlight><br />
<br />
===Get content like text from a frame===<br />
<syntaxhighlight lang='python'><br />
content = []<br />
d = scribus.getPageItems()<br />
for item in d:<br />
if (item[1] == 4):<br />
contents = scribus.getAllText(item[0])<br />
if (contents in content):<br />
contents = 'Duplication, perhaps linked-to frame'<br />
content.append(contents)<br />
elif (item[1] == 2):<br />
imgname = scribus.getImageFile(item[0])<br />
</syntaxhighlight><br />
<br />
ITEM TYPE<br />
* ItemType1 = 1,<br />
* ImageFrame = 2,<br />
* ItemType3 = 3,<br />
* TextFrame = 4,<br />
* Line = 5,<br />
* Polygon = 6,<br />
* PolyLine = 7,<br />
* PathText = 8,<br />
* LatexFrame = 9,<br />
* Multiple = 99<br />
<br />
===Auto-Output all Scripter Commands===<br />
<br />
From Scribus User http://meiradarocha.jor.br Mailinglist Feb. 2012<br />
<syntaxhighlight lang='python'><br />
d = dir(scribus)<br />
for j in d:<br />
try:<br />
exec 'res = '+j+'.__doc__'<br />
if res[0:5] == 'float':<br />
print '\nCONSTANT:\n',j,'\nVALUE: float'<br />
exec 'print '+j+'\n'<br />
elif res[0:5] == 'int(x':<br />
print '\nCONSTANT:\n',j,'\nVALUE: integer'<br />
exec 'print '+j+'\n'<br />
elif res[0:5] == 'tuple':<br />
print '\nTUPLE:\n',j,'\nVALUE:'<br />
exec 'print repr('+j+')\n'<br />
elif res[0:4] == 'str(':<br />
print '\nSTRING:\n',j,'\nVALUE:'<br />
exec 'print repr('+j+')\n'<br />
else:<br />
print '\nFUNCTION:\n'+j+'\n\nSYNTAX:'<br />
print res<br />
except: pass<br />
</syntaxhighlight><br />
<br />
==Image Manipulation==<br />
<br />
* [[Scripter/Images| Objects: Images]] -- Example Scripts that manipulate images in a Scribus document<br />
<br />
==[[Beginners Scripts]]==<br />
This content has been moved to a separate page to reduce the enormity of this one.<br />
<br />
==Basic scripts==<br />
<br />
Scripts which give you ideas how you can solve your tasks.<br />
<br />
* [[Poor man's mail merge]]<br />
* [[Enlarge2Page]] - Enlarge an object to the size of the page.<br />
* [[Making Guides at an Object's Borders]]<br />
* [[Using the new applyMasterPage() command]]<br />
* [[Swap Images]]<br />
* [[Creating Text Frames for Image Captions]]<br />
* [[Horizontal Rule over Text Frame]]<br />
* [[Creating an Object-sized Document]]<br />
<br />
==Full functional scripts==<br />
<br />
Scripts that are ready for achieving specific tasks<br />
{|<br />
|<br />
* [[Export all text|Export all text]] from a Scribus file<br />
* [[Export list of frames and page numbers]]<br />
* [[Script Resize selected objects|Resize selected objects]]<br />
* [[formatxml|Import XML and apply styles]]<br />
* [[align_to_left_page_margin|Align to the left page margin]] (after adding a new page in a double page document)<br />
* [[Bullets]] Make bulleted list<br />
* [[Bullets_and_numbered_lists|Bullets and numbered lists]]<br />
* [[Scribus_Generator|Scribus Generator]] Extend Scribus with Mail Merge functionality<br />
|<br />
* [[CalendarWizard]]<br />
* [[Image crop, resize and CMYK conversion. Save and reload in TIFF format]]<br />
* [[Image crop, resize and color conversion GUI]]<br />
* [[Apply basic ligatures to a document]]<br />
* [[Import CSV Data]]<br />
* [[Automatic story formatting]]<br />
* [[Clean-up the imported text based on the Slovak typographic rules]]<br />
|}<br />
<br />
==Scripting new Scribus' functions==<br />
<br />
Scripts which sketch new features which may be included in future releases of Scribus<br />
<br />
* [[Adjust a text frame to fit its content|Adjust the text frame size according to various factors]]<br />
<br />
== Extension scripts and PyQt ==<br />
<br />
* [[Extension script discussion]]<br />
* [[Experimental PyQt projects]]<br />
<br />
== Python issues ==<br />
<br />
* [[Known Scripter Issues]]<br />
<br />
= Other =<br />
* [[Extension_script_repository ]]<br />
* [[Web optimised PDF]] &mdash; learn how to minimize PDF size, make your life easier with the included Perl script (runs outside of Scribus)<br />
* [[Imagemagick Imposition]] &ndash; a bash script doing simple imposition of PNG files exported from Scribus<br />
* [[Printing_4-up_tickets_to_hard_copy_printer]] Shows a) automatic numbering in text boxes and b) hard-copy printing from script<br />
* [[Using createParagraphStyle]]<br />
* [[Text and Text Manipulation]]<br />
* Alessandro Rimoldi's blog series on scripter functions - [http://www.graphicslab.org/Blog/Blog a_l_e's blog]<br />
* [[Windows Full Python Integration]]</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Working_with_image_frames&diff=34461
Working with image frames
2018-03-01T00:47:07Z
<p>Gpittman: /* Creation */</p>
<hr />
<div>{{HOWTO Index}} [[Category:Images]] [[Category:EN]]<br />
<br />
This article is intended to be a compilation of operations pertaining to image frames. <br />
<br />
'''If you are using 1.3.8/1.3.9, you will find more accurate information in Working with Frames and Working with Images in your handy online manual.'''<br />
{{Working_with_toc}}<br />
==Creation==<br />
Create an image frame by:<br />
# Clicking the [[Toolbars#Toolbar_Icons:_Insert_Objects|'''Insert Image Frame''']] icon on the toolbar<br />
# Selecting '''Insert > Image Frame''' from menu <br />
# Keyboard: I, or Alt+N, I. <br />
This will enable your mouse to place and size the image frame: click-and-hold-down mouse button, then drag diagonally on the page. The click determines one corner of the frame, letting up the diagonally opposite corner. It may be more conventional to start with the upper-left hand corner, but you may start with any corner to its opposite.<br />
<br />
==Context Menu==<br />
Clicking with the right mouse button brings up the Context Menu, which contains several common frame operations, an important one of which is the ability to convert a Image Frame to another type of frame.<br />
<br />
==Size and Position==<br />
At this point you will find that the Properties window is an indispensible item for working with Scribus. If not already present, open it under the menu item '''Windows > Properties'''. The XYZ tab of the Properties window shows very precise information about the X,Y position of the upper left hand corner, the width and height of the frame, and the frame's rotation. Note that information is only displayed for a selected frame -- displayed as a dashed red border. A frame is automatically selected when created. Unselect a frame by clicking on the page outside its borders, select it again by clicking inside. A frame must be selected to be modified or repositioned.<br />
<br />
==Loading an Image into the Frame==<br />
{| cellpadding="15px" |<br />
| When you first create an Image Frame, it will be blank except for an X drawn from opposite corners, denoting the fact that there is no image.<br />
<br />
Acceptable image formats for importing are '''TIFF''', '''JPEG''', '''PNG''', '''GIF''', '''XPM''', and '''EPS'''. You may also import a '''PDF''', although at this time only the first page will be loaded into the frame (but see below to work around this problem). See the Scribus Manual, '''Help > Scribus Manual > Documentation > Importing''' (keyboard: '''F1''' then '''Documentation > Importing''') for advice about use of formats.<br />
<br />
Load an image from the Context Menu (right-click in frame) '''> Get Image''' (keyboard: '''Ctrl+D'''), from the menu '''File > Import > Get Image''' (or its keyboard equivalents). By default, the image will be loaded at its native size, with the upper left corner of the frame the upper left corner of the image. <br />
<br />
It is conceivable that you may be able to simply resize the frame, but most likely you will need to adjust scaling of the image. If you know the final size you want the frame to be, follow the directions in the next section, then go to [[Working_with_image_frames#Properties:_Image_Tab| Properties: Image Tab]].<br />
<br />
| width="400px" bgcolor="bisque" valign="top" | '''What about SVGs?'''<br />
<br />
SVGs are an open source vector graphics format, and in many ways can be an ideal graphics format for DTP. SVGs do not use a frame, but can be imported directly into Scribus using the menu:<br> '''File > Import > Import SVG...'''.<br> SVGs can be resized and repositioned, and some editing capability is also possible. Some file format features are not yet supported in Scribus. At this time the only way to use an SVG file in an image frame is by using a vector-drawing program such as [http://www.inkscape.org Inkscape] to save the file in one of the formats mentioned to the left.<br />
<br />
If you do this, you will want to make the size much bigger (higher DPI) than the default to reduce pixelization in your final Scribus product.<br />
|}<br />
{| cellpadding="10px" |<br />
| bgcolor="palegreen" | '''Importing multiple pages of a PDF'''<br />
<br />
This is possible presently only with external software, such as [http://www.adobe.com/products/ Adobe Acrobat]. There are several opensource projects which can break up your multi-page PDF into single-page PDFs: One program called [http://www.accesspdf.com/pdftk/index.html pdftk], one written in Java Swing (works in Windows) [http://www.pdfsam.org/ PDF Split and Merge] that can both splitt multiple pages into single pages, and merge different pdf-documents into one document. Moreover, [http://kde-apps.org/content/show.php?content=33194 KPDFtool] offers an easy to use GUI for simple PDF operations, such as extracting single pages from multipage PDFs. Finally, keep in mind that Scribus can create multiple single-page PDFs -- look for this option when you export to PDF.<br />
<br />
With Scribus 1.5 you can also open the PDF and save it converted as a SLA file. This creates a multipage SLA document if the PDF has multiple page. It is then possible to copy an paste the content of the required pages to the document where you want them to be. Or to create single page PDFs through scribus aswell, so as to import them as images in another document.<br />
|}<br />
<br />
==Properties: XYZ Tab - Resizing, Repositioning==<br />
[[Image:Properties_xyz_v1331.jpg|thumb|200px|Properties: XYZ tab]]<br />
{| cellpadding="8px"<br />
! ''With the mouse:'' || ''With the Properties window:''<br />
|-<br />
| width="35%" valign="top"|<br />
# Click-and-drag anywhere inside the frame to reposition. Frames may even be positioned off the page, or slid from one page to another (depending on Scribus version).<br />
# Click-and-drag any of the small red rectangles along the border to resize the frame.<br />
||There are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
Also note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties window width and height are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
<hr><br />
'''Some Additional Help'''<br />
* From the Menu, '''Page > Snap to Grid''' will cause your frame to "stick" to the grid lines on the page. '''View > Show Grid''' toggles the grid on and off. (The grid does not print or become part of a PDF.) If you want to adjust the line spacing of the grid, go to '''File > Preferences > Guides'''.<br />
<br />
* From the Menu, '''Page > Snap to Guides''' will cause your frame to "stick" to guide lines on the page. '''View > Show Guides''' toggles them on and off. (Like the grid, guides do not print or become part of a PDF.) If you want to edit or add guides, go to '''Page > Manage Guides''' or '''File > Preferences > Guides''' .<br />
<br />
==Properties: Image Tab==<br />
If your frame is already the correct size, click '''Scale to Frame Size'''. Subsequent adjustments in frame size will adjust scaling to maintain scaling to the frame size. Clicking back to '''Free Scaling''' will allow you to crop edges, reposition, or change scaling.<br />
<br />
'''Scaling, Repositioning -- the Image'''<br />
<br />
''See [[Working_with_image_frames#Properties:_XYZ_Tab_-_Resizing.2C_Repositioning| Resizing, Repositioning]] above for instructions on moving and resizing the frame -- Properties: XYZ Tab.''<br />
{| cellpadding="6px"<br />
! width="45%" |''With the mouse on the frame:'' || ''With the Properties window:''<br />
|-<br />
| valign="top"|<br />
# Hold down '''Shift+Ctrl+Alt'''. Now clicking and dragging inside the frame will allow you to adjust the position of the image inside the frame (frame stays in place). As soon as you let up on the keys, you go back to moving the frame.<br />
# Click on the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Edit Contents of Frame''']] icon on the toolbar (keyboard: E). This works like holding down '''Shift+Ctrl+Alt''', except that you stay in the image-moving mode until you click back to [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Select Item''']] on toolbar, or click outside the frame.<br />
* To resize the image directly with the mouse on the frame first click on the image frame. Then press F2 to open the ''Properties'' window. Select the ''Images'' tab. Turn on the ''Scale to frame size'' option and the ''Proportional'' suboption. Now the image will be resized according to the frame size.<br />
<br />
| valign="top"|Just as in the XYZ tab, there are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
And again note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties, X-Scale, Y-Scale, and X-DPI, Y-DPI are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
'''X-Pos, Y-Pos''': These refer to the offset of the image inside the frame. Negative values will expose the background color of the frame.<br />
<br />
'''X-Scale, Y-Scale, Actual X-DPI, Actual Y-DPI''': Default linked, click the chain to unlink. Obviously, scaling and DPI are inversely related, but for high-quality printed output, knowing the end-product DPI is essential to avoid poor quality results. If your end-product will be a PDF for the web or for a presentation, a lower DPI may suffice. See [http://docs.scribus.net/index.php?lang=en&page=about2 this page] at the Scribus website for more details.<br />
<br />
''Some Additional Info:''<br />
<br />
The Context Menu (right-click in frame) '''> Info''' will give some basic information about your image -- file source, original and final scaling. The menu item '''Extras > Manage Pictures''' may also be of help.<br />
<br />
==Rotation==<br />
''With the mouse:''<br />
<br />
Click the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Rotate Item''']] icon on the toolbar (keyboard: R), then click inside the frame and drag-rotate to desired angle.<br />
<br />
''With the Properties window: XYZ Tab''<br />
<br />
Just like resizing and repositioning, you have the same three ways to change the rotation digitally. There is also an icon just below (looks something like one of a pair of dice) to alter the point around which rotation takes place -- center or one of the four corners.<br />
<br />
==Copying Frames and Similar Operations==<br />
There are several different ways to copy or move frames.<br />
<br />
# You should be familiar with Copy and Paste (keyboard: '''Ctrl+C''', '''Ctrl+V''') and Cut and Paste (keyboard: '''Ctrl+X''', '''Ctrl+V''') -- also accessible from '''Edit''' on the menu, and from the Context Menu (right-click in frame). To paste to another page, move to that page, click on it, then paste -- the frame will have the same coordinates as on the original page.<br />
# There is also Duplicate (keyboard: '''Ctrl+Alt+Shift+D''') '''Item > Duplicate'''. This makes a copy which is slightly offset from the original, and on a layer above it.<br />
# There is Multiple Duplicate, '''Item > Multiple Duplicate''', which brings up a requestor to automatically create as many copies as you wish, with a sequential adjustable offset. You can also use this for a single duplication when you want to set the offset. ''Note that once you set the offset here, '''Item > Duplicate''' will use this same offset.''<br />
# Finally, there is the Scrapbook, '''Item > Send to Scrapbook''' or from Context Menu (right-click in frame). This will make a named copy of the selected frame and its contents to the Scrapbook. To retrieve a saved item from Scrapbook, select from the menu '''Windows > Scrapbook''', to bring up a requestor to paste an item to a page. Also note that you can save your entire Scrapbook to a file, which can then be loaded and used in another document.<br />
<br />
Experimentation will show you that frames can even be outside the document boundaries and still be copied, duplicated and manipulated in various ways. They will even be saved with the document in these locations. If you try to generate a PDF, you will receive error messages about objects not being on the page; if ignored, the PDF will not have these objects. Furthermore, especially in a large multipage document, you may lose track of these off-document objects.<br />
<br />
==Levels & Layers==<br />
Frames in general, not just image frames, represent a two-dimensional space that you manipulate and move around your workspace, much like a small note you can attach and detach. Like small physical notes, they are laid down, one by one, on the page, new ones over the previous ones. The small box labeled '''Level''' in the XYZ tab of Properties allows you to move the selected frame up or down levels; the arrows with bars will move all the way to the top or bottom. Since the background of your frame may be opaque or transparent, the level the frame is at will affect how much of the frame can be visible in relationship to other overlapping or underlying frames.<br />
===Layers===<br />
{|<br />
|[[Image:LayersTool.png|thumb|left|220px|Layers Tool v1.3.x]]<br />
When you start a document in Scribus, you are by default working on the Background Layer. This is your active working space, which in turn can have multiple Levels with which you can work. By clicking the menu '''Windows > Layers''' (keyboard: F6) you can create new '''Layers''' to work on.<br />
Each Layer can have multiple Levels, all of which you can edit. As you see in this Layers Tool, an entire Layer can be visible or invisible, may or may not print, and may be locked to prevent accidental editing. You can only work on one Layer at a time -- either highlight it in the Layers Tool, or select with the requester at the bottom of the main window.<br />
<br />
For further information on the whys and hows of Layers, check the tutorial: [[Get Started With Scribus:5]].<br />
|}<br />
<br />
==XYZ Tab: The Rest==<br />
The remaining buttons in the XYZ tab do the following:<br />
<br />
# Flip the selected frame horizontally or vertically<br />
# Lock a frame in place. ''Everything'' about your frame is locked -- size, position, contents. Copying and pasting a locked frame may produce unexpected results.<br />
# Lock the size of the frame only. Note that the editing tabs disappear from the corners and sides.<br />
# Enable/disable printing of the frame. Why? You may want to have a frame on the page that's a message to yourself or someone else, yet not be part of the printed finished work. Or the frame may just be a space-saver for some other purpose.<br />
<br />
==Properties: Shape Tab==<br />
{| width=95% cellpadding=10px |<br />
|[[Image:properties_shape_v1331.jpg|thumb|250px|Shape tab in Properties, v 1.3.3.x<br>For image frame, Distance of Text section<br>will be greyed out (inactive).]]<br />
| valign=top |Click the Shape tab in Properties. Near the top is a button with a square in the center. If you click that button, you may quickly switch to one of a group of set shapes from your original rectangle. In addition, if you click '''Edit Shape...''', you now have full vector-editing control of your shape.<br />
<br />
''Another angle on shapes and image frames:''<br />
<br />
You may also use the [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Polygon tool''']] on the toolbar (use will be described in detail in another section) to create a regular polygon, which may then be converted using the Context Menu (right-click in the polygon) to '''Convert To > Image Frame'''.<br />
<br />
'''Round Corners'''<br />
<br />
Causes an adjustable degree of rounding of the Image Frame corners. Also note the effect of negative values.<br />
| valign=top |[[Image:Editshape.jpg|thumb|Edit Shape requester<br>v1.3.3.3]]<br />
|}<br />
===Text Flows Around Frame===<br />
{| cellpadding=20px |<br />
| width="350" valign="top" | Use this to determine what happens with text ''underneath'' the selected frame.<br>Remember [[Working_with_image_frames#Levels_.26_Layers|Levels & Layers?]]<br />
<br />
When you create an image frame, the [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box] (of the image) and the Contour Line are the same size and position. But click on '''Edit Shape...''' and you can change this Contour Line's size, position, and shape as desired -- check the '''Edit Contour Line''' box in the Edit Shape requester.<br />
<br />
[[Image:Textflows.png|Close-up in Shape Tab, v1.3.3.x]]<br />
<hr><br />
The appearance in v1.3.4:<br />
<br />
[[Image:Textflow134.png|Close-up in v1.3.4]]<br />
| width="300" |Here is an example: <br />
<br />
[[Image:TextflowsExample.png]]<br />
|-<br />
| Below we see that the shape of the image, the Bounding Box (dotted red line), and Contour Line (faint grey dotted line) can occupy separate spaces. The [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box will always have a rectangular shape.]<br />
<br />
[[Image:Contourbounding.png]]<br />
<br />
|}<br />
<br />
===Flowing the text around the image's clipping path===<br />
==== Prepare the image in a bitmap editor (GIMP for example) ====<br />
* select the relevant part of image<br />
* create a mask from the selection and apply it (for removing background)<br />
* enlarge the selection if in Scribus you want to have a margin between the text and the image<br />
* create a path from selection<br />
* export image to TIF format<br />
<br />
==== Apply the path in Scribus ====<br />
* load the image into the frame<br />
* in the context menu, select the image's extended properties<br />
* select the path you want to use (there may be multiple path stored in the image)<br />
* in the Properties Palette go to the Shape tab and select "Use Clipping Path"<br />
<br />
==== Tip====<br />
The Clipping path is not properly changed when you manually scale the image in the frame. In that case in Scribus 1.4.1 and above you can convert the clipping path to a contour and edit it manually (move, scale).<br />
<br />
==Properties: Line Tab==<br />
The Line of an Image Frame refers to the border of the frame. The first thing to be aware of is that the default setting for Line Color is None, so regardless of the settings in the Line Tab, nothing will show until the Line Color is set.<br />
<br />
Otherwise, the various settings for Line are straightforward. If a setting is greyed-out, it does not apply to frames.<br />
<br />
==Properties: Color Tab==<br />
As noted above, the Line Color refers to the border of the frame, with the default being None.<br />
<br />
Fill Color means background color of the frame. None for a Fill Color means that the background is transparent.<br />
<br />
Shade refers to saturation of the color, so that 0% should represent a neutral grey scale color. Opacity refers to the relative opacity/transparency, with 100% being totally opaque, 0% totally transparent. It is worth noting at this point that some PDF versions and some PDF viewers do not support transparency.<br />
<br />
'''Overprinting''' ''versions 1.3.4 and above''<br />
<br />
''Knockout'' versus ''Overprinting'' are described [http://desktoppub.about.com/od/trapping/ss/trapping_basics.htm here].<br />
<br />
''Please note that you are not limited to colors you see displayed in the Color Tab, nor are you compelled to have all these choices. See the Menu item '''Edit > Colors''' to add, edit, or remove colors. Removing colors can simplify the use of Scribus, and does reduce saved file size.''<br />
<br />
(c) Gregory Pittman, 2006, 2007 <br />
'''The content of this page is licensed under the [http://www.fsf.org/licensing/licenses/fdl.html Free Documentation License].'''</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Working_with_image_frames&diff=34460
Working with image frames
2018-03-01T00:46:39Z
<p>Gpittman: /* Creation */</p>
<hr />
<div>{{HOWTO Index}} [[Category:Images]] [[Category:EN]]<br />
<br />
This article is intended to be a compilation of operations pertaining to image frames. <br />
<br />
'''If you are using 1.3.8/1.3.9, you will find more accurate information in Working with Frames and Working with Images in your handy online manual.'''<br />
{{Working_with_toc}}<br />
==Creation==<br />
test<br />
Create an image frame by:<br />
# Clicking the [[Toolbars#Toolbar_Icons:_Insert_Objects|'''Insert Image Frame''']] icon on the toolbar<br />
# Selecting '''Insert > Image Frame''' from menu <br />
# Keyboard: I, or Alt+N, I. <br />
This will enable your mouse to place and size the image frame: click-and-hold-down mouse button, then drag diagonally on the page. The click determines one corner of the frame, letting up the diagonally opposite corner. It may be more conventional to start with the upper-left hand corner, but you may start with any corner to its opposite.<br />
<br />
==Context Menu==<br />
Clicking with the right mouse button brings up the Context Menu, which contains several common frame operations, an important one of which is the ability to convert a Image Frame to another type of frame.<br />
<br />
==Size and Position==<br />
At this point you will find that the Properties window is an indispensible item for working with Scribus. If not already present, open it under the menu item '''Windows > Properties'''. The XYZ tab of the Properties window shows very precise information about the X,Y position of the upper left hand corner, the width and height of the frame, and the frame's rotation. Note that information is only displayed for a selected frame -- displayed as a dashed red border. A frame is automatically selected when created. Unselect a frame by clicking on the page outside its borders, select it again by clicking inside. A frame must be selected to be modified or repositioned.<br />
<br />
==Loading an Image into the Frame==<br />
{| cellpadding="15px" |<br />
| When you first create an Image Frame, it will be blank except for an X drawn from opposite corners, denoting the fact that there is no image.<br />
<br />
Acceptable image formats for importing are '''TIFF''', '''JPEG''', '''PNG''', '''GIF''', '''XPM''', and '''EPS'''. You may also import a '''PDF''', although at this time only the first page will be loaded into the frame (but see below to work around this problem). See the Scribus Manual, '''Help > Scribus Manual > Documentation > Importing''' (keyboard: '''F1''' then '''Documentation > Importing''') for advice about use of formats.<br />
<br />
Load an image from the Context Menu (right-click in frame) '''> Get Image''' (keyboard: '''Ctrl+D'''), from the menu '''File > Import > Get Image''' (or its keyboard equivalents). By default, the image will be loaded at its native size, with the upper left corner of the frame the upper left corner of the image. <br />
<br />
It is conceivable that you may be able to simply resize the frame, but most likely you will need to adjust scaling of the image. If you know the final size you want the frame to be, follow the directions in the next section, then go to [[Working_with_image_frames#Properties:_Image_Tab| Properties: Image Tab]].<br />
<br />
| width="400px" bgcolor="bisque" valign="top" | '''What about SVGs?'''<br />
<br />
SVGs are an open source vector graphics format, and in many ways can be an ideal graphics format for DTP. SVGs do not use a frame, but can be imported directly into Scribus using the menu:<br> '''File > Import > Import SVG...'''.<br> SVGs can be resized and repositioned, and some editing capability is also possible. Some file format features are not yet supported in Scribus. At this time the only way to use an SVG file in an image frame is by using a vector-drawing program such as [http://www.inkscape.org Inkscape] to save the file in one of the formats mentioned to the left.<br />
<br />
If you do this, you will want to make the size much bigger (higher DPI) than the default to reduce pixelization in your final Scribus product.<br />
|}<br />
{| cellpadding="10px" |<br />
| bgcolor="palegreen" | '''Importing multiple pages of a PDF'''<br />
<br />
This is possible presently only with external software, such as [http://www.adobe.com/products/ Adobe Acrobat]. There are several opensource projects which can break up your multi-page PDF into single-page PDFs: One program called [http://www.accesspdf.com/pdftk/index.html pdftk], one written in Java Swing (works in Windows) [http://www.pdfsam.org/ PDF Split and Merge] that can both splitt multiple pages into single pages, and merge different pdf-documents into one document. Moreover, [http://kde-apps.org/content/show.php?content=33194 KPDFtool] offers an easy to use GUI for simple PDF operations, such as extracting single pages from multipage PDFs. Finally, keep in mind that Scribus can create multiple single-page PDFs -- look for this option when you export to PDF.<br />
<br />
With Scribus 1.5 you can also open the PDF and save it converted as a SLA file. This creates a multipage SLA document if the PDF has multiple page. It is then possible to copy an paste the content of the required pages to the document where you want them to be. Or to create single page PDFs through scribus aswell, so as to import them as images in another document.<br />
|}<br />
<br />
==Properties: XYZ Tab - Resizing, Repositioning==<br />
[[Image:Properties_xyz_v1331.jpg|thumb|200px|Properties: XYZ tab]]<br />
{| cellpadding="8px"<br />
! ''With the mouse:'' || ''With the Properties window:''<br />
|-<br />
| width="35%" valign="top"|<br />
# Click-and-drag anywhere inside the frame to reposition. Frames may even be positioned off the page, or slid from one page to another (depending on Scribus version).<br />
# Click-and-drag any of the small red rectangles along the border to resize the frame.<br />
||There are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
Also note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties window width and height are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
<hr><br />
'''Some Additional Help'''<br />
* From the Menu, '''Page > Snap to Grid''' will cause your frame to "stick" to the grid lines on the page. '''View > Show Grid''' toggles the grid on and off. (The grid does not print or become part of a PDF.) If you want to adjust the line spacing of the grid, go to '''File > Preferences > Guides'''.<br />
<br />
* From the Menu, '''Page > Snap to Guides''' will cause your frame to "stick" to guide lines on the page. '''View > Show Guides''' toggles them on and off. (Like the grid, guides do not print or become part of a PDF.) If you want to edit or add guides, go to '''Page > Manage Guides''' or '''File > Preferences > Guides''' .<br />
<br />
==Properties: Image Tab==<br />
If your frame is already the correct size, click '''Scale to Frame Size'''. Subsequent adjustments in frame size will adjust scaling to maintain scaling to the frame size. Clicking back to '''Free Scaling''' will allow you to crop edges, reposition, or change scaling.<br />
<br />
'''Scaling, Repositioning -- the Image'''<br />
<br />
''See [[Working_with_image_frames#Properties:_XYZ_Tab_-_Resizing.2C_Repositioning| Resizing, Repositioning]] above for instructions on moving and resizing the frame -- Properties: XYZ Tab.''<br />
{| cellpadding="6px"<br />
! width="45%" |''With the mouse on the frame:'' || ''With the Properties window:''<br />
|-<br />
| valign="top"|<br />
# Hold down '''Shift+Ctrl+Alt'''. Now clicking and dragging inside the frame will allow you to adjust the position of the image inside the frame (frame stays in place). As soon as you let up on the keys, you go back to moving the frame.<br />
# Click on the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Edit Contents of Frame''']] icon on the toolbar (keyboard: E). This works like holding down '''Shift+Ctrl+Alt''', except that you stay in the image-moving mode until you click back to [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Select Item''']] on toolbar, or click outside the frame.<br />
* To resize the image directly with the mouse on the frame first click on the image frame. Then press F2 to open the ''Properties'' window. Select the ''Images'' tab. Turn on the ''Scale to frame size'' option and the ''Proportional'' suboption. Now the image will be resized according to the frame size.<br />
<br />
| valign="top"|Just as in the XYZ tab, there are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
And again note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties, X-Scale, Y-Scale, and X-DPI, Y-DPI are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
'''X-Pos, Y-Pos''': These refer to the offset of the image inside the frame. Negative values will expose the background color of the frame.<br />
<br />
'''X-Scale, Y-Scale, Actual X-DPI, Actual Y-DPI''': Default linked, click the chain to unlink. Obviously, scaling and DPI are inversely related, but for high-quality printed output, knowing the end-product DPI is essential to avoid poor quality results. If your end-product will be a PDF for the web or for a presentation, a lower DPI may suffice. See [http://docs.scribus.net/index.php?lang=en&page=about2 this page] at the Scribus website for more details.<br />
<br />
''Some Additional Info:''<br />
<br />
The Context Menu (right-click in frame) '''> Info''' will give some basic information about your image -- file source, original and final scaling. The menu item '''Extras > Manage Pictures''' may also be of help.<br />
<br />
==Rotation==<br />
''With the mouse:''<br />
<br />
Click the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Rotate Item''']] icon on the toolbar (keyboard: R), then click inside the frame and drag-rotate to desired angle.<br />
<br />
''With the Properties window: XYZ Tab''<br />
<br />
Just like resizing and repositioning, you have the same three ways to change the rotation digitally. There is also an icon just below (looks something like one of a pair of dice) to alter the point around which rotation takes place -- center or one of the four corners.<br />
<br />
==Copying Frames and Similar Operations==<br />
There are several different ways to copy or move frames.<br />
<br />
# You should be familiar with Copy and Paste (keyboard: '''Ctrl+C''', '''Ctrl+V''') and Cut and Paste (keyboard: '''Ctrl+X''', '''Ctrl+V''') -- also accessible from '''Edit''' on the menu, and from the Context Menu (right-click in frame). To paste to another page, move to that page, click on it, then paste -- the frame will have the same coordinates as on the original page.<br />
# There is also Duplicate (keyboard: '''Ctrl+Alt+Shift+D''') '''Item > Duplicate'''. This makes a copy which is slightly offset from the original, and on a layer above it.<br />
# There is Multiple Duplicate, '''Item > Multiple Duplicate''', which brings up a requestor to automatically create as many copies as you wish, with a sequential adjustable offset. You can also use this for a single duplication when you want to set the offset. ''Note that once you set the offset here, '''Item > Duplicate''' will use this same offset.''<br />
# Finally, there is the Scrapbook, '''Item > Send to Scrapbook''' or from Context Menu (right-click in frame). This will make a named copy of the selected frame and its contents to the Scrapbook. To retrieve a saved item from Scrapbook, select from the menu '''Windows > Scrapbook''', to bring up a requestor to paste an item to a page. Also note that you can save your entire Scrapbook to a file, which can then be loaded and used in another document.<br />
<br />
Experimentation will show you that frames can even be outside the document boundaries and still be copied, duplicated and manipulated in various ways. They will even be saved with the document in these locations. If you try to generate a PDF, you will receive error messages about objects not being on the page; if ignored, the PDF will not have these objects. Furthermore, especially in a large multipage document, you may lose track of these off-document objects.<br />
<br />
==Levels & Layers==<br />
Frames in general, not just image frames, represent a two-dimensional space that you manipulate and move around your workspace, much like a small note you can attach and detach. Like small physical notes, they are laid down, one by one, on the page, new ones over the previous ones. The small box labeled '''Level''' in the XYZ tab of Properties allows you to move the selected frame up or down levels; the arrows with bars will move all the way to the top or bottom. Since the background of your frame may be opaque or transparent, the level the frame is at will affect how much of the frame can be visible in relationship to other overlapping or underlying frames.<br />
===Layers===<br />
{|<br />
|[[Image:LayersTool.png|thumb|left|220px|Layers Tool v1.3.x]]<br />
When you start a document in Scribus, you are by default working on the Background Layer. This is your active working space, which in turn can have multiple Levels with which you can work. By clicking the menu '''Windows > Layers''' (keyboard: F6) you can create new '''Layers''' to work on.<br />
Each Layer can have multiple Levels, all of which you can edit. As you see in this Layers Tool, an entire Layer can be visible or invisible, may or may not print, and may be locked to prevent accidental editing. You can only work on one Layer at a time -- either highlight it in the Layers Tool, or select with the requester at the bottom of the main window.<br />
<br />
For further information on the whys and hows of Layers, check the tutorial: [[Get Started With Scribus:5]].<br />
|}<br />
<br />
==XYZ Tab: The Rest==<br />
The remaining buttons in the XYZ tab do the following:<br />
<br />
# Flip the selected frame horizontally or vertically<br />
# Lock a frame in place. ''Everything'' about your frame is locked -- size, position, contents. Copying and pasting a locked frame may produce unexpected results.<br />
# Lock the size of the frame only. Note that the editing tabs disappear from the corners and sides.<br />
# Enable/disable printing of the frame. Why? You may want to have a frame on the page that's a message to yourself or someone else, yet not be part of the printed finished work. Or the frame may just be a space-saver for some other purpose.<br />
<br />
==Properties: Shape Tab==<br />
{| width=95% cellpadding=10px |<br />
|[[Image:properties_shape_v1331.jpg|thumb|250px|Shape tab in Properties, v 1.3.3.x<br>For image frame, Distance of Text section<br>will be greyed out (inactive).]]<br />
| valign=top |Click the Shape tab in Properties. Near the top is a button with a square in the center. If you click that button, you may quickly switch to one of a group of set shapes from your original rectangle. In addition, if you click '''Edit Shape...''', you now have full vector-editing control of your shape.<br />
<br />
''Another angle on shapes and image frames:''<br />
<br />
You may also use the [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Polygon tool''']] on the toolbar (use will be described in detail in another section) to create a regular polygon, which may then be converted using the Context Menu (right-click in the polygon) to '''Convert To > Image Frame'''.<br />
<br />
'''Round Corners'''<br />
<br />
Causes an adjustable degree of rounding of the Image Frame corners. Also note the effect of negative values.<br />
| valign=top |[[Image:Editshape.jpg|thumb|Edit Shape requester<br>v1.3.3.3]]<br />
|}<br />
===Text Flows Around Frame===<br />
{| cellpadding=20px |<br />
| width="350" valign="top" | Use this to determine what happens with text ''underneath'' the selected frame.<br>Remember [[Working_with_image_frames#Levels_.26_Layers|Levels & Layers?]]<br />
<br />
When you create an image frame, the [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box] (of the image) and the Contour Line are the same size and position. But click on '''Edit Shape...''' and you can change this Contour Line's size, position, and shape as desired -- check the '''Edit Contour Line''' box in the Edit Shape requester.<br />
<br />
[[Image:Textflows.png|Close-up in Shape Tab, v1.3.3.x]]<br />
<hr><br />
The appearance in v1.3.4:<br />
<br />
[[Image:Textflow134.png|Close-up in v1.3.4]]<br />
| width="300" |Here is an example: <br />
<br />
[[Image:TextflowsExample.png]]<br />
|-<br />
| Below we see that the shape of the image, the Bounding Box (dotted red line), and Contour Line (faint grey dotted line) can occupy separate spaces. The [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box will always have a rectangular shape.]<br />
<br />
[[Image:Contourbounding.png]]<br />
<br />
|}<br />
<br />
===Flowing the text around the image's clipping path===<br />
==== Prepare the image in a bitmap editor (GIMP for example) ====<br />
* select the relevant part of image<br />
* create a mask from the selection and apply it (for removing background)<br />
* enlarge the selection if in Scribus you want to have a margin between the text and the image<br />
* create a path from selection<br />
* export image to TIF format<br />
<br />
==== Apply the path in Scribus ====<br />
* load the image into the frame<br />
* in the context menu, select the image's extended properties<br />
* select the path you want to use (there may be multiple path stored in the image)<br />
* in the Properties Palette go to the Shape tab and select "Use Clipping Path"<br />
<br />
==== Tip====<br />
The Clipping path is not properly changed when you manually scale the image in the frame. In that case in Scribus 1.4.1 and above you can convert the clipping path to a contour and edit it manually (move, scale).<br />
<br />
==Properties: Line Tab==<br />
The Line of an Image Frame refers to the border of the frame. The first thing to be aware of is that the default setting for Line Color is None, so regardless of the settings in the Line Tab, nothing will show until the Line Color is set.<br />
<br />
Otherwise, the various settings for Line are straightforward. If a setting is greyed-out, it does not apply to frames.<br />
<br />
==Properties: Color Tab==<br />
As noted above, the Line Color refers to the border of the frame, with the default being None.<br />
<br />
Fill Color means background color of the frame. None for a Fill Color means that the background is transparent.<br />
<br />
Shade refers to saturation of the color, so that 0% should represent a neutral grey scale color. Opacity refers to the relative opacity/transparency, with 100% being totally opaque, 0% totally transparent. It is worth noting at this point that some PDF versions and some PDF viewers do not support transparency.<br />
<br />
'''Overprinting''' ''versions 1.3.4 and above''<br />
<br />
''Knockout'' versus ''Overprinting'' are described [http://desktoppub.about.com/od/trapping/ss/trapping_basics.htm here].<br />
<br />
''Please note that you are not limited to colors you see displayed in the Color Tab, nor are you compelled to have all these choices. See the Menu item '''Edit > Colors''' to add, edit, or remove colors. Removing colors can simplify the use of Scribus, and does reduce saved file size.''<br />
<br />
(c) Gregory Pittman, 2006, 2007 <br />
'''The content of this page is licensed under the [http://www.fsf.org/licensing/licenses/fdl.html Free Documentation License].'''</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Working_with_image_frames&diff=34459
Working with image frames
2018-03-01T00:38:39Z
<p>Gpittman: /* Loading an Image into the Frame */</p>
<hr />
<div>{{HOWTO Index}} [[Category:Images]] [[Category:EN]]<br />
<br />
This article is intended to be a compilation of operations pertaining to image frames. <br />
<br />
'''If you are using 1.3.8/1.3.9, you will find more accurate information in Working with Frames and Working with Images in your handy online manual.'''<br />
{{Working_with_toc}}<br />
==Creation==<br />
Create an image frame by:<br />
# Clicking the [[Toolbars#Toolbar_Icons:_Insert_Objects|'''Insert Image Frame''']] icon on the toolbar<br />
# Selecting '''Insert > Image Frame''' from menu <br />
# Keyboard: I, or Alt+N, I. <br />
This will enable your mouse to place and size the image frame: click-and-hold-down mouse button, then drag diagonally on the page. The click determines one corner of the frame, letting up the diagonally opposite corner. It may be more conventional to start with the upper-left hand corner, but you may start with any corner to its opposite.<br />
<br />
==Context Menu==<br />
Clicking with the right mouse button brings up the Context Menu, which contains several common frame operations, an important one of which is the ability to convert a Image Frame to another type of frame.<br />
<br />
==Size and Position==<br />
At this point you will find that the Properties window is an indispensible item for working with Scribus. If not already present, open it under the menu item '''Windows > Properties'''. The XYZ tab of the Properties window shows very precise information about the X,Y position of the upper left hand corner, the width and height of the frame, and the frame's rotation. Note that information is only displayed for a selected frame -- displayed as a dashed red border. A frame is automatically selected when created. Unselect a frame by clicking on the page outside its borders, select it again by clicking inside. A frame must be selected to be modified or repositioned.<br />
<br />
==Loading an Image into the Frame==<br />
{| cellpadding="15px" |<br />
| When you first create an Image Frame, it will be blank except for an X drawn from opposite corners, denoting the fact that there is no image.<br />
<br />
Acceptable image formats for importing are '''TIFF''', '''JPEG''', '''PNG''', '''GIF''', '''XPM''', and '''EPS'''. You may also import a '''PDF''', although at this time only the first page will be loaded into the frame (but see below to work around this problem). See the Scribus Manual, '''Help > Scribus Manual > Documentation > Importing''' (keyboard: '''F1''' then '''Documentation > Importing''') for advice about use of formats.<br />
<br />
Load an image from the Context Menu (right-click in frame) '''> Get Image''' (keyboard: '''Ctrl+D'''), from the menu '''File > Import > Get Image''' (or its keyboard equivalents). By default, the image will be loaded at its native size, with the upper left corner of the frame the upper left corner of the image. <br />
<br />
It is conceivable that you may be able to simply resize the frame, but most likely you will need to adjust scaling of the image. If you know the final size you want the frame to be, follow the directions in the next section, then go to [[Working_with_image_frames#Properties:_Image_Tab| Properties: Image Tab]].<br />
<br />
| width="400px" bgcolor="bisque" valign="top" | '''What about SVGs?'''<br />
<br />
SVGs are an open source vector graphics format, and in many ways can be an ideal graphics format for DTP. SVGs do not use a frame, but can be imported directly into Scribus using the menu:<br> '''File > Import > Import SVG...'''.<br> SVGs can be resized and repositioned, and some editing capability is also possible. Some file format features are not yet supported in Scribus. At this time the only way to use an SVG file in an image frame is by using a vector-drawing program such as [http://www.inkscape.org Inkscape] to save the file in one of the formats mentioned to the left.<br />
<br />
If you do this, you will want to make the size much bigger (higher DPI) than the default to reduce pixelization in your final Scribus product.<br />
|}<br />
{| cellpadding="10px" |<br />
| bgcolor="palegreen" | '''Importing multiple pages of a PDF'''<br />
<br />
This is possible presently only with external software, such as [http://www.adobe.com/products/ Adobe Acrobat]. There are several opensource projects which can break up your multi-page PDF into single-page PDFs: One program called [http://www.accesspdf.com/pdftk/index.html pdftk], one written in Java Swing (works in Windows) [http://www.pdfsam.org/ PDF Split and Merge] that can both splitt multiple pages into single pages, and merge different pdf-documents into one document. Moreover, [http://kde-apps.org/content/show.php?content=33194 KPDFtool] offers an easy to use GUI for simple PDF operations, such as extracting single pages from multipage PDFs. Finally, keep in mind that Scribus can create multiple single-page PDFs -- look for this option when you export to PDF.<br />
<br />
With Scribus 1.5 you can also open the PDF and save it converted as a SLA file. This creates a multipage SLA document if the PDF has multiple page. It is then possible to copy an paste the content of the required pages to the document where you want them to be. Or to create single page PDFs through scribus aswell, so as to import them as images in another document.<br />
|}<br />
<br />
==Properties: XYZ Tab - Resizing, Repositioning==<br />
[[Image:Properties_xyz_v1331.jpg|thumb|200px|Properties: XYZ tab]]<br />
{| cellpadding="8px"<br />
! ''With the mouse:'' || ''With the Properties window:''<br />
|-<br />
| width="35%" valign="top"|<br />
# Click-and-drag anywhere inside the frame to reposition. Frames may even be positioned off the page, or slid from one page to another (depending on Scribus version).<br />
# Click-and-drag any of the small red rectangles along the border to resize the frame.<br />
||There are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
Also note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties window width and height are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
<hr><br />
'''Some Additional Help'''<br />
* From the Menu, '''Page > Snap to Grid''' will cause your frame to "stick" to the grid lines on the page. '''View > Show Grid''' toggles the grid on and off. (The grid does not print or become part of a PDF.) If you want to adjust the line spacing of the grid, go to '''File > Preferences > Guides'''.<br />
<br />
* From the Menu, '''Page > Snap to Guides''' will cause your frame to "stick" to guide lines on the page. '''View > Show Guides''' toggles them on and off. (Like the grid, guides do not print or become part of a PDF.) If you want to edit or add guides, go to '''Page > Manage Guides''' or '''File > Preferences > Guides''' .<br />
<br />
==Properties: Image Tab==<br />
If your frame is already the correct size, click '''Scale to Frame Size'''. Subsequent adjustments in frame size will adjust scaling to maintain scaling to the frame size. Clicking back to '''Free Scaling''' will allow you to crop edges, reposition, or change scaling.<br />
<br />
'''Scaling, Repositioning -- the Image'''<br />
<br />
''See [[Working_with_image_frames#Properties:_XYZ_Tab_-_Resizing.2C_Repositioning| Resizing, Repositioning]] above for instructions on moving and resizing the frame -- Properties: XYZ Tab.''<br />
{| cellpadding="6px"<br />
! width="45%" |''With the mouse on the frame:'' || ''With the Properties window:''<br />
|-<br />
| valign="top"|<br />
# Hold down '''Shift+Ctrl+Alt'''. Now clicking and dragging inside the frame will allow you to adjust the position of the image inside the frame (frame stays in place). As soon as you let up on the keys, you go back to moving the frame.<br />
# Click on the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Edit Contents of Frame''']] icon on the toolbar (keyboard: E). This works like holding down '''Shift+Ctrl+Alt''', except that you stay in the image-moving mode until you click back to [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Select Item''']] on toolbar, or click outside the frame.<br />
* To resize the image directly with the mouse on the frame first click on the image frame. Then press F2 to open the ''Properties'' window. Select the ''Images'' tab. Turn on the ''Scale to frame size'' option and the ''Proportional'' suboption. Now the image will be resized according to the frame size.<br />
<br />
| valign="top"|Just as in the XYZ tab, there are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
And again note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties, X-Scale, Y-Scale, and X-DPI, Y-DPI are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
'''X-Pos, Y-Pos''': These refer to the offset of the image inside the frame. Negative values will expose the background color of the frame.<br />
<br />
'''X-Scale, Y-Scale, Actual X-DPI, Actual Y-DPI''': Default linked, click the chain to unlink. Obviously, scaling and DPI are inversely related, but for high-quality printed output, knowing the end-product DPI is essential to avoid poor quality results. If your end-product will be a PDF for the web or for a presentation, a lower DPI may suffice. See [http://docs.scribus.net/index.php?lang=en&page=about2 this page] at the Scribus website for more details.<br />
<br />
''Some Additional Info:''<br />
<br />
The Context Menu (right-click in frame) '''> Info''' will give some basic information about your image -- file source, original and final scaling. The menu item '''Extras > Manage Pictures''' may also be of help.<br />
<br />
==Rotation==<br />
''With the mouse:''<br />
<br />
Click the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Rotate Item''']] icon on the toolbar (keyboard: R), then click inside the frame and drag-rotate to desired angle.<br />
<br />
''With the Properties window: XYZ Tab''<br />
<br />
Just like resizing and repositioning, you have the same three ways to change the rotation digitally. There is also an icon just below (looks something like one of a pair of dice) to alter the point around which rotation takes place -- center or one of the four corners.<br />
<br />
==Copying Frames and Similar Operations==<br />
There are several different ways to copy or move frames.<br />
<br />
# You should be familiar with Copy and Paste (keyboard: '''Ctrl+C''', '''Ctrl+V''') and Cut and Paste (keyboard: '''Ctrl+X''', '''Ctrl+V''') -- also accessible from '''Edit''' on the menu, and from the Context Menu (right-click in frame). To paste to another page, move to that page, click on it, then paste -- the frame will have the same coordinates as on the original page.<br />
# There is also Duplicate (keyboard: '''Ctrl+Alt+Shift+D''') '''Item > Duplicate'''. This makes a copy which is slightly offset from the original, and on a layer above it.<br />
# There is Multiple Duplicate, '''Item > Multiple Duplicate''', which brings up a requestor to automatically create as many copies as you wish, with a sequential adjustable offset. You can also use this for a single duplication when you want to set the offset. ''Note that once you set the offset here, '''Item > Duplicate''' will use this same offset.''<br />
# Finally, there is the Scrapbook, '''Item > Send to Scrapbook''' or from Context Menu (right-click in frame). This will make a named copy of the selected frame and its contents to the Scrapbook. To retrieve a saved item from Scrapbook, select from the menu '''Windows > Scrapbook''', to bring up a requestor to paste an item to a page. Also note that you can save your entire Scrapbook to a file, which can then be loaded and used in another document.<br />
<br />
Experimentation will show you that frames can even be outside the document boundaries and still be copied, duplicated and manipulated in various ways. They will even be saved with the document in these locations. If you try to generate a PDF, you will receive error messages about objects not being on the page; if ignored, the PDF will not have these objects. Furthermore, especially in a large multipage document, you may lose track of these off-document objects.<br />
<br />
==Levels & Layers==<br />
Frames in general, not just image frames, represent a two-dimensional space that you manipulate and move around your workspace, much like a small note you can attach and detach. Like small physical notes, they are laid down, one by one, on the page, new ones over the previous ones. The small box labeled '''Level''' in the XYZ tab of Properties allows you to move the selected frame up or down levels; the arrows with bars will move all the way to the top or bottom. Since the background of your frame may be opaque or transparent, the level the frame is at will affect how much of the frame can be visible in relationship to other overlapping or underlying frames.<br />
===Layers===<br />
{|<br />
|[[Image:LayersTool.png|thumb|left|220px|Layers Tool v1.3.x]]<br />
When you start a document in Scribus, you are by default working on the Background Layer. This is your active working space, which in turn can have multiple Levels with which you can work. By clicking the menu '''Windows > Layers''' (keyboard: F6) you can create new '''Layers''' to work on.<br />
Each Layer can have multiple Levels, all of which you can edit. As you see in this Layers Tool, an entire Layer can be visible or invisible, may or may not print, and may be locked to prevent accidental editing. You can only work on one Layer at a time -- either highlight it in the Layers Tool, or select with the requester at the bottom of the main window.<br />
<br />
For further information on the whys and hows of Layers, check the tutorial: [[Get Started With Scribus:5]].<br />
|}<br />
<br />
==XYZ Tab: The Rest==<br />
The remaining buttons in the XYZ tab do the following:<br />
<br />
# Flip the selected frame horizontally or vertically<br />
# Lock a frame in place. ''Everything'' about your frame is locked -- size, position, contents. Copying and pasting a locked frame may produce unexpected results.<br />
# Lock the size of the frame only. Note that the editing tabs disappear from the corners and sides.<br />
# Enable/disable printing of the frame. Why? You may want to have a frame on the page that's a message to yourself or someone else, yet not be part of the printed finished work. Or the frame may just be a space-saver for some other purpose.<br />
<br />
==Properties: Shape Tab==<br />
{| width=95% cellpadding=10px |<br />
|[[Image:properties_shape_v1331.jpg|thumb|250px|Shape tab in Properties, v 1.3.3.x<br>For image frame, Distance of Text section<br>will be greyed out (inactive).]]<br />
| valign=top |Click the Shape tab in Properties. Near the top is a button with a square in the center. If you click that button, you may quickly switch to one of a group of set shapes from your original rectangle. In addition, if you click '''Edit Shape...''', you now have full vector-editing control of your shape.<br />
<br />
''Another angle on shapes and image frames:''<br />
<br />
You may also use the [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Polygon tool''']] on the toolbar (use will be described in detail in another section) to create a regular polygon, which may then be converted using the Context Menu (right-click in the polygon) to '''Convert To > Image Frame'''.<br />
<br />
'''Round Corners'''<br />
<br />
Causes an adjustable degree of rounding of the Image Frame corners. Also note the effect of negative values.<br />
| valign=top |[[Image:Editshape.jpg|thumb|Edit Shape requester<br>v1.3.3.3]]<br />
|}<br />
===Text Flows Around Frame===<br />
{| cellpadding=20px |<br />
| width="350" valign="top" | Use this to determine what happens with text ''underneath'' the selected frame.<br>Remember [[Working_with_image_frames#Levels_.26_Layers|Levels & Layers?]]<br />
<br />
When you create an image frame, the [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box] (of the image) and the Contour Line are the same size and position. But click on '''Edit Shape...''' and you can change this Contour Line's size, position, and shape as desired -- check the '''Edit Contour Line''' box in the Edit Shape requester.<br />
<br />
[[Image:Textflows.png|Close-up in Shape Tab, v1.3.3.x]]<br />
<hr><br />
The appearance in v1.3.4:<br />
<br />
[[Image:Textflow134.png|Close-up in v1.3.4]]<br />
| width="300" |Here is an example: <br />
<br />
[[Image:TextflowsExample.png]]<br />
|-<br />
| Below we see that the shape of the image, the Bounding Box (dotted red line), and Contour Line (faint grey dotted line) can occupy separate spaces. The [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box will always have a rectangular shape.]<br />
<br />
[[Image:Contourbounding.png]]<br />
<br />
|}<br />
<br />
===Flowing the text around the image's clipping path===<br />
==== Prepare the image in a bitmap editor (GIMP for example) ====<br />
* select the relevant part of image<br />
* create a mask from the selection and apply it (for removing background)<br />
* enlarge the selection if in Scribus you want to have a margin between the text and the image<br />
* create a path from selection<br />
* export image to TIF format<br />
<br />
==== Apply the path in Scribus ====<br />
* load the image into the frame<br />
* in the context menu, select the image's extended properties<br />
* select the path you want to use (there may be multiple path stored in the image)<br />
* in the Properties Palette go to the Shape tab and select "Use Clipping Path"<br />
<br />
==== Tip====<br />
The Clipping path is not properly changed when you manually scale the image in the frame. In that case in Scribus 1.4.1 and above you can convert the clipping path to a contour and edit it manually (move, scale).<br />
<br />
==Properties: Line Tab==<br />
The Line of an Image Frame refers to the border of the frame. The first thing to be aware of is that the default setting for Line Color is None, so regardless of the settings in the Line Tab, nothing will show until the Line Color is set.<br />
<br />
Otherwise, the various settings for Line are straightforward. If a setting is greyed-out, it does not apply to frames.<br />
<br />
==Properties: Color Tab==<br />
As noted above, the Line Color refers to the border of the frame, with the default being None.<br />
<br />
Fill Color means background color of the frame. None for a Fill Color means that the background is transparent.<br />
<br />
Shade refers to saturation of the color, so that 0% should represent a neutral grey scale color. Opacity refers to the relative opacity/transparency, with 100% being totally opaque, 0% totally transparent. It is worth noting at this point that some PDF versions and some PDF viewers do not support transparency.<br />
<br />
'''Overprinting''' ''versions 1.3.4 and above''<br />
<br />
''Knockout'' versus ''Overprinting'' are described [http://desktoppub.about.com/od/trapping/ss/trapping_basics.htm here].<br />
<br />
''Please note that you are not limited to colors you see displayed in the Color Tab, nor are you compelled to have all these choices. See the Menu item '''Edit > Colors''' to add, edit, or remove colors. Removing colors can simplify the use of Scribus, and does reduce saved file size.''<br />
<br />
(c) Gregory Pittman, 2006, 2007 <br />
'''The content of this page is licensed under the [http://www.fsf.org/licensing/licenses/fdl.html Free Documentation License].'''</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Working_with_image_frames&diff=34458
Working with image frames
2018-03-01T00:37:48Z
<p>Gpittman: /* Loading an Image into the Frame */</p>
<hr />
<div>{{HOWTO Index}} [[Category:Images]] [[Category:EN]]<br />
<br />
This article is intended to be a compilation of operations pertaining to image frames. <br />
<br />
'''If you are using 1.3.8/1.3.9, you will find more accurate information in Working with Frames and Working with Images in your handy online manual.'''<br />
{{Working_with_toc}}<br />
==Creation==<br />
Create an image frame by:<br />
# Clicking the [[Toolbars#Toolbar_Icons:_Insert_Objects|'''Insert Image Frame''']] icon on the toolbar<br />
# Selecting '''Insert > Image Frame''' from menu <br />
# Keyboard: I, or Alt+N, I. <br />
This will enable your mouse to place and size the image frame: click-and-hold-down mouse button, then drag diagonally on the page. The click determines one corner of the frame, letting up the diagonally opposite corner. It may be more conventional to start with the upper-left hand corner, but you may start with any corner to its opposite.<br />
<br />
==Context Menu==<br />
Clicking with the right mouse button brings up the Context Menu, which contains several common frame operations, an important one of which is the ability to convert a Image Frame to another type of frame.<br />
<br />
==Size and Position==<br />
At this point you will find that the Properties window is an indispensible item for working with Scribus. If not already present, open it under the menu item '''Windows > Properties'''. The XYZ tab of the Properties window shows very precise information about the X,Y position of the upper left hand corner, the width and height of the frame, and the frame's rotation. Note that information is only displayed for a selected frame -- displayed as a dashed red border. A frame is automatically selected when created. Unselect a frame by clicking on the page outside its borders, select it again by clicking inside. A frame must be selected to be modified or repositioned.<br />
<br />
==Loading an Image into the Frame==<br />
test<br />
{| cellpadding="15px" |<br />
| When you first create an Image Frame, it will be blank except for an X drawn from opposite corners, denoting the fact that there is no image.<br />
<br />
Acceptable image formats for importing are '''TIFF''', '''JPEG''', '''PNG''', '''GIF''', '''XPM''', and '''EPS'''. You may also import a '''PDF''', although at this time only the first page will be loaded into the frame (but see below to work around this problem). See the Scribus Manual, '''Help > Scribus Manual > Documentation > Importing''' (keyboard: '''F1''' then '''Documentation > Importing''') for advice about use of formats.<br />
<br />
Load an image from the Context Menu (right-click in frame) '''> Get Image''' (keyboard: '''Ctrl+D'''), from the menu '''File > Import > Get Image''' (or its keyboard equivalents). By default, the image will be loaded at its native size, with the upper left corner of the frame the upper left corner of the image. <br />
<br />
It is conceivable that you may be able to simply resize the frame, but most likely you will need to adjust scaling of the image. If you know the final size you want the frame to be, follow the directions in the next section, then go to [[Working_with_image_frames#Properties:_Image_Tab| Properties: Image Tab]].<br />
<br />
| width="400px" bgcolor="bisque" valign="top" | '''What about SVGs?'''<br />
<br />
SVGs are an open source vector graphics format, and in many ways can be an ideal graphics format for DTP. SVGs do not use a frame, but can be imported directly into Scribus using the menu:<br> '''File > Import > Import SVG...'''.<br> SVGs can be resized and repositioned, and some editing capability is also possible. Some file format features are not yet supported in Scribus. At this time the only way to use an SVG file in an image frame is by using a vector-drawing program such as [http://www.inkscape.org Inkscape] to save the file in one of the formats mentioned to the left.<br />
<br />
If you do this, you will want to make the size much bigger (higher DPI) than the default to reduce pixelization in your final Scribus product.<br />
|}<br />
{| cellpadding="10px" |<br />
| bgcolor="palegreen" | '''Importing multiple pages of a PDF'''<br />
<br />
This is possible presently only with external software, such as [http://www.adobe.com/products/ Adobe Acrobat]. There are several opensource projects which can break up your multi-page PDF into single-page PDFs: One program called [http://www.accesspdf.com/pdftk/index.html pdftk], one written in Java Swing (works in Windows) [http://www.pdfsam.org/ PDF Split and Merge] that can both splitt multiple pages into single pages, and merge different pdf-documents into one document. Moreover, [http://kde-apps.org/content/show.php?content=33194 KPDFtool] offers an easy to use GUI for simple PDF operations, such as extracting single pages from multipage PDFs. Finally, keep in mind that Scribus can create multiple single-page PDFs -- look for this option when you export to PDF.<br />
<br />
With Scribus 1.5 you can also open the PDF and save it converted as a SLA file. This creates a multipage SLA document if the PDF has multiple page. It is then possible to copy an paste the content of the required pages to the document where you want them to be. Or to create single page PDFs through scribus aswell, so as to import them as images in another document.<br />
|}<br />
<br />
==Properties: XYZ Tab - Resizing, Repositioning==<br />
[[Image:Properties_xyz_v1331.jpg|thumb|200px|Properties: XYZ tab]]<br />
{| cellpadding="8px"<br />
! ''With the mouse:'' || ''With the Properties window:''<br />
|-<br />
| width="35%" valign="top"|<br />
# Click-and-drag anywhere inside the frame to reposition. Frames may even be positioned off the page, or slid from one page to another (depending on Scribus version).<br />
# Click-and-drag any of the small red rectangles along the border to resize the frame.<br />
||There are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
Also note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties window width and height are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
<hr><br />
'''Some Additional Help'''<br />
* From the Menu, '''Page > Snap to Grid''' will cause your frame to "stick" to the grid lines on the page. '''View > Show Grid''' toggles the grid on and off. (The grid does not print or become part of a PDF.) If you want to adjust the line spacing of the grid, go to '''File > Preferences > Guides'''.<br />
<br />
* From the Menu, '''Page > Snap to Guides''' will cause your frame to "stick" to guide lines on the page. '''View > Show Guides''' toggles them on and off. (Like the grid, guides do not print or become part of a PDF.) If you want to edit or add guides, go to '''Page > Manage Guides''' or '''File > Preferences > Guides''' .<br />
<br />
==Properties: Image Tab==<br />
If your frame is already the correct size, click '''Scale to Frame Size'''. Subsequent adjustments in frame size will adjust scaling to maintain scaling to the frame size. Clicking back to '''Free Scaling''' will allow you to crop edges, reposition, or change scaling.<br />
<br />
'''Scaling, Repositioning -- the Image'''<br />
<br />
''See [[Working_with_image_frames#Properties:_XYZ_Tab_-_Resizing.2C_Repositioning| Resizing, Repositioning]] above for instructions on moving and resizing the frame -- Properties: XYZ Tab.''<br />
{| cellpadding="6px"<br />
! width="45%" |''With the mouse on the frame:'' || ''With the Properties window:''<br />
|-<br />
| valign="top"|<br />
# Hold down '''Shift+Ctrl+Alt'''. Now clicking and dragging inside the frame will allow you to adjust the position of the image inside the frame (frame stays in place). As soon as you let up on the keys, you go back to moving the frame.<br />
# Click on the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Edit Contents of Frame''']] icon on the toolbar (keyboard: E). This works like holding down '''Shift+Ctrl+Alt''', except that you stay in the image-moving mode until you click back to [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Select Item''']] on toolbar, or click outside the frame.<br />
* To resize the image directly with the mouse on the frame first click on the image frame. Then press F2 to open the ''Properties'' window. Select the ''Images'' tab. Turn on the ''Scale to frame size'' option and the ''Proportional'' suboption. Now the image will be resized according to the frame size.<br />
<br />
| valign="top"|Just as in the XYZ tab, there are three ways to change the individual settings --<br />
# editing with the keyboard<br />
# clicking on the up or down arrows to the right of each value. The keyboard up and down arrows will accomplish the same thing.<br />
# using the mousewheel on each setting -- usually hovering the cursor will be enough, if not, click on the value first<br />
<br />
And again note that for 2 and 3, holding down Ctrl, Shift, or Ctrl+Shift (works with up and down arrow keys also) will alter which decimal place is affected. In addition, when using the Properties, X-Scale, Y-Scale, and X-DPI, Y-DPI are by default linked, but you need only click the chain icon to the right to unlink them.<br />
|}<br />
'''X-Pos, Y-Pos''': These refer to the offset of the image inside the frame. Negative values will expose the background color of the frame.<br />
<br />
'''X-Scale, Y-Scale, Actual X-DPI, Actual Y-DPI''': Default linked, click the chain to unlink. Obviously, scaling and DPI are inversely related, but for high-quality printed output, knowing the end-product DPI is essential to avoid poor quality results. If your end-product will be a PDF for the web or for a presentation, a lower DPI may suffice. See [http://docs.scribus.net/index.php?lang=en&page=about2 this page] at the Scribus website for more details.<br />
<br />
''Some Additional Info:''<br />
<br />
The Context Menu (right-click in frame) '''> Info''' will give some basic information about your image -- file source, original and final scaling. The menu item '''Extras > Manage Pictures''' may also be of help.<br />
<br />
==Rotation==<br />
''With the mouse:''<br />
<br />
Click the [[Toolbars#Toolbar_Icons:_Modify_Objects| '''Rotate Item''']] icon on the toolbar (keyboard: R), then click inside the frame and drag-rotate to desired angle.<br />
<br />
''With the Properties window: XYZ Tab''<br />
<br />
Just like resizing and repositioning, you have the same three ways to change the rotation digitally. There is also an icon just below (looks something like one of a pair of dice) to alter the point around which rotation takes place -- center or one of the four corners.<br />
<br />
==Copying Frames and Similar Operations==<br />
There are several different ways to copy or move frames.<br />
<br />
# You should be familiar with Copy and Paste (keyboard: '''Ctrl+C''', '''Ctrl+V''') and Cut and Paste (keyboard: '''Ctrl+X''', '''Ctrl+V''') -- also accessible from '''Edit''' on the menu, and from the Context Menu (right-click in frame). To paste to another page, move to that page, click on it, then paste -- the frame will have the same coordinates as on the original page.<br />
# There is also Duplicate (keyboard: '''Ctrl+Alt+Shift+D''') '''Item > Duplicate'''. This makes a copy which is slightly offset from the original, and on a layer above it.<br />
# There is Multiple Duplicate, '''Item > Multiple Duplicate''', which brings up a requestor to automatically create as many copies as you wish, with a sequential adjustable offset. You can also use this for a single duplication when you want to set the offset. ''Note that once you set the offset here, '''Item > Duplicate''' will use this same offset.''<br />
# Finally, there is the Scrapbook, '''Item > Send to Scrapbook''' or from Context Menu (right-click in frame). This will make a named copy of the selected frame and its contents to the Scrapbook. To retrieve a saved item from Scrapbook, select from the menu '''Windows > Scrapbook''', to bring up a requestor to paste an item to a page. Also note that you can save your entire Scrapbook to a file, which can then be loaded and used in another document.<br />
<br />
Experimentation will show you that frames can even be outside the document boundaries and still be copied, duplicated and manipulated in various ways. They will even be saved with the document in these locations. If you try to generate a PDF, you will receive error messages about objects not being on the page; if ignored, the PDF will not have these objects. Furthermore, especially in a large multipage document, you may lose track of these off-document objects.<br />
<br />
==Levels & Layers==<br />
Frames in general, not just image frames, represent a two-dimensional space that you manipulate and move around your workspace, much like a small note you can attach and detach. Like small physical notes, they are laid down, one by one, on the page, new ones over the previous ones. The small box labeled '''Level''' in the XYZ tab of Properties allows you to move the selected frame up or down levels; the arrows with bars will move all the way to the top or bottom. Since the background of your frame may be opaque or transparent, the level the frame is at will affect how much of the frame can be visible in relationship to other overlapping or underlying frames.<br />
===Layers===<br />
{|<br />
|[[Image:LayersTool.png|thumb|left|220px|Layers Tool v1.3.x]]<br />
When you start a document in Scribus, you are by default working on the Background Layer. This is your active working space, which in turn can have multiple Levels with which you can work. By clicking the menu '''Windows > Layers''' (keyboard: F6) you can create new '''Layers''' to work on.<br />
Each Layer can have multiple Levels, all of which you can edit. As you see in this Layers Tool, an entire Layer can be visible or invisible, may or may not print, and may be locked to prevent accidental editing. You can only work on one Layer at a time -- either highlight it in the Layers Tool, or select with the requester at the bottom of the main window.<br />
<br />
For further information on the whys and hows of Layers, check the tutorial: [[Get Started With Scribus:5]].<br />
|}<br />
<br />
==XYZ Tab: The Rest==<br />
The remaining buttons in the XYZ tab do the following:<br />
<br />
# Flip the selected frame horizontally or vertically<br />
# Lock a frame in place. ''Everything'' about your frame is locked -- size, position, contents. Copying and pasting a locked frame may produce unexpected results.<br />
# Lock the size of the frame only. Note that the editing tabs disappear from the corners and sides.<br />
# Enable/disable printing of the frame. Why? You may want to have a frame on the page that's a message to yourself or someone else, yet not be part of the printed finished work. Or the frame may just be a space-saver for some other purpose.<br />
<br />
==Properties: Shape Tab==<br />
{| width=95% cellpadding=10px |<br />
|[[Image:properties_shape_v1331.jpg|thumb|250px|Shape tab in Properties, v 1.3.3.x<br>For image frame, Distance of Text section<br>will be greyed out (inactive).]]<br />
| valign=top |Click the Shape tab in Properties. Near the top is a button with a square in the center. If you click that button, you may quickly switch to one of a group of set shapes from your original rectangle. In addition, if you click '''Edit Shape...''', you now have full vector-editing control of your shape.<br />
<br />
''Another angle on shapes and image frames:''<br />
<br />
You may also use the [[Toolbars#Toolbar_Icons:_Insert_Objects| '''Polygon tool''']] on the toolbar (use will be described in detail in another section) to create a regular polygon, which may then be converted using the Context Menu (right-click in the polygon) to '''Convert To > Image Frame'''.<br />
<br />
'''Round Corners'''<br />
<br />
Causes an adjustable degree of rounding of the Image Frame corners. Also note the effect of negative values.<br />
| valign=top |[[Image:Editshape.jpg|thumb|Edit Shape requester<br>v1.3.3.3]]<br />
|}<br />
===Text Flows Around Frame===<br />
{| cellpadding=20px |<br />
| width="350" valign="top" | Use this to determine what happens with text ''underneath'' the selected frame.<br>Remember [[Working_with_image_frames#Levels_.26_Layers|Levels & Layers?]]<br />
<br />
When you create an image frame, the [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box] (of the image) and the Contour Line are the same size and position. But click on '''Edit Shape...''' and you can change this Contour Line's size, position, and shape as desired -- check the '''Edit Contour Line''' box in the Edit Shape requester.<br />
<br />
[[Image:Textflows.png|Close-up in Shape Tab, v1.3.3.x]]<br />
<hr><br />
The appearance in v1.3.4:<br />
<br />
[[Image:Textflow134.png|Close-up in v1.3.4]]<br />
| width="300" |Here is an example: <br />
<br />
[[Image:TextflowsExample.png]]<br />
|-<br />
| Below we see that the shape of the image, the Bounding Box (dotted red line), and Contour Line (faint grey dotted line) can occupy separate spaces. The [http://amath.colorado.edu/documentation/LaTeX/reference/bbox.html Bounding Box will always have a rectangular shape.]<br />
<br />
[[Image:Contourbounding.png]]<br />
<br />
|}<br />
<br />
===Flowing the text around the image's clipping path===<br />
==== Prepare the image in a bitmap editor (GIMP for example) ====<br />
* select the relevant part of image<br />
* create a mask from the selection and apply it (for removing background)<br />
* enlarge the selection if in Scribus you want to have a margin between the text and the image<br />
* create a path from selection<br />
* export image to TIF format<br />
<br />
==== Apply the path in Scribus ====<br />
* load the image into the frame<br />
* in the context menu, select the image's extended properties<br />
* select the path you want to use (there may be multiple path stored in the image)<br />
* in the Properties Palette go to the Shape tab and select "Use Clipping Path"<br />
<br />
==== Tip====<br />
The Clipping path is not properly changed when you manually scale the image in the frame. In that case in Scribus 1.4.1 and above you can convert the clipping path to a contour and edit it manually (move, scale).<br />
<br />
==Properties: Line Tab==<br />
The Line of an Image Frame refers to the border of the frame. The first thing to be aware of is that the default setting for Line Color is None, so regardless of the settings in the Line Tab, nothing will show until the Line Color is set.<br />
<br />
Otherwise, the various settings for Line are straightforward. If a setting is greyed-out, it does not apply to frames.<br />
<br />
==Properties: Color Tab==<br />
As noted above, the Line Color refers to the border of the frame, with the default being None.<br />
<br />
Fill Color means background color of the frame. None for a Fill Color means that the background is transparent.<br />
<br />
Shade refers to saturation of the color, so that 0% should represent a neutral grey scale color. Opacity refers to the relative opacity/transparency, with 100% being totally opaque, 0% totally transparent. It is worth noting at this point that some PDF versions and some PDF viewers do not support transparency.<br />
<br />
'''Overprinting''' ''versions 1.3.4 and above''<br />
<br />
''Knockout'' versus ''Overprinting'' are described [http://desktoppub.about.com/od/trapping/ss/trapping_basics.htm here].<br />
<br />
''Please note that you are not limited to colors you see displayed in the Color Tab, nor are you compelled to have all these choices. See the Menu item '''Edit > Colors''' to add, edit, or remove colors. Removing colors can simplify the use of Scribus, and does reduce saved file size.''<br />
<br />
(c) Gregory Pittman, 2006, 2007 <br />
'''The content of this page is licensed under the [http://www.fsf.org/licensing/licenses/fdl.html Free Documentation License].'''</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Advanced_Graphing&diff=34457
Advanced Graphing
2018-02-28T00:56:12Z
<p>Gpittman: /* The Current Working Script (subject to change) */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
{| align="right" cellpadding=5px|<br />
| bgcolor="palegreen"|You may also be interested in:<br>[[Automatically Creating a Graph]]<br>[[Creating a Graph, Part 2]]<br> or <br>[[Making a Pie Chart]]<br />
|}<br />
Here are the Scribus operations you will find examples for in this script:<br />
{|<br />
| valign=top|<br />
* Testing for and using an existing document<br />
* Using ''fileDialog'' to open a text file having a predefined structure for data &ndash; some of that parsing uses the Python '''split''' function<br />
* Creating a graph layout with a number of lines &ndash; X and Y axes, plus tick marks (''createLine'')<br />
* Using ''valueDialog'' for user input<br />
* Using ''createPolyLine'' to make a line graph of data according to the scale of the graph<br />
|}<br />
This is an article about a script to create axes with tick marks, then plot data points to the scale of the graph.<br />
<br />
This article explains the workflow that led to the script, and I imagine will continue to suggest improvements. What I wanted to do was to accumulate information about when orders were coming in according to time of day, then see if as data accumulated whether patterns became apparent.<br />
<br />
===Beginnings===<br />
Like many such projects it began quite manually, making a graph structure by hand, trying out and not liking a grid, and in essence making my own grid to lay out data points. I was getting the data from a spreadsheet, collating manually since there wasn't so much at first, then making a polyline, again manually. This gave me an opportunity to fiddle with various parameters to get the look I wanted. This ugly self-created grid would not be printed or exported to the PDF.<br />
<br />
[[Image:Earlygraph.png|250px]]<br />
<br />
The data collection began in mid-April, and continues. Quite early, and you can easily see it in this graph from late April, there was this interesting peak at 4pm, so this led if nothing else to continuing the process to see what would happen with larger numbers.<br />
<br />
As I began updating the graph, I realized I needed some help from the manual drudgery. The first thing I did was to enter the information I wanted into a postgresql database, so I could dissect in various ways, such as by time of day. Later, as the number of data rose, I wanted to be able to look at this by day of week also. This also was helped by having postgresql, where I could for example transform all instances of 23May to M23May, thus making selecting for day of week easier.<br />
<br />
This was still quite manual, since I would export an ordered list to a text file, edit it a bit to making counting how many orders came in per hour, then use Scribus &ndash; Properties > Shape > Edit to manually change the nodes of the graph line as needed. Doable but tedious. What became especially annoying was counting lines of a text file, but of course postgresql can use an external script if you write one.<br />
<pre><br />
select * from orders order by time;<br />
select * from orders where time < '01:00' order by time;<br />
select * from orders where time > '00:59' and time < '02:00' order by time;<br />
select * from orders where time > '01:59' and time < '03:00' order by time;<br />
select * from orders where time > '02:59' and time < '04:00' order by time;<br />
select * from orders where time > '03:59' and time < '05:00' order by time;<br />
select * from orders where time > '04:59' and time < '06:00' order by time;<br />
select * from orders where time > '05:59' and time < '07:00' order by time;<br />
select * from orders where time > '06:59' and time < '08:00' order by time;<br />
select * from orders where time > '07:59' and time < '09:00' order by time;<br />
select * from orders where time > '08:59' and time < '10:00' order by time;<br />
select * from orders where time > '09:59' and time < '11:00' order by time;<br />
select * from orders where time > '10:59' and time < '12:00' order by time;<br />
select * from orders where time > '11:59' and time < '13:00' order by time;<br />
select * from orders where time > '12:59' and time < '14:00' order by time;<br />
select * from orders where time > '13:59' and time < '15:00' order by time;<br />
select * from orders where time > '14:59' and time < '16:00' order by time;<br />
select * from orders where time > '15:59' and time < '17:00' order by time;<br />
select * from orders where time > '16:59' and time < '18:00' order by time;<br />
select * from orders where time > '17:59' and time < '19:00' order by time;<br />
select * from orders where time > '18:59' and time < '20:00' order by time;<br />
select * from orders where time > '19:59' and time < '21:00' order by time;<br />
select * from orders where time > '20:59' and time < '22:00' order by time;<br />
select * from orders where time > '21:59' and time < '23:00' order by time;<br />
select * from orders where time > '22:59' order by time;<br />
</pre><br />
{| cellpadding=10 |<br />
|So what does this get you? Here is a fragment of the output near the end of the list from the first command into the next few lines:<br />
<br />
<pre><br />
A26Jun | 23:29:00<br />
T20Jul | 23:44:00<br />
F28May | 23:48:00<br />
A10Jul | 23:50:00<br />
F21May | 23:55:00<br />
(603 rows)<br />
<br />
date | time <br />
--------+----------<br />
M19Jul | 00:00:00<br />
A22May | 00:07:00<br />
H22Jul | 00:09:00<br />
S27Jun | 00:17:00<br />
A26Jun | 00:17:00<br />
W21Jul | 00:19:00<br />
H3Jun | 00:21:00<br />
M19Apr | 00:25:00<br />
W12May | 00:38:00<br />
F23Jul | 00:38:00<br />
T20Jul | 00:40:00<br />
H24Jun | 00:43:00<br />
W28Apr | 00:43:00<br />
T13Jul | 00:47:00<br />
W21Jul | 00:50:00<br />
T29Jun | 00:51:00<br />
H10Jun | 00:59:00<br />
(17 rows)<br />
<br />
date | time <br />
--------+----------<br />
M19Jul | 01:09:00<br />
T6Jul | 01:16:00<br />
S18Jul | 01:19:00<br />
H15Apr | 01:20:00<br />
H3Jun | 01:20:00<br />
T29Jun | 01:21:00<br />
W23Jun | 01:25:00<br />
H22Jul | 01:38:00<br />
H20May | 01:42:00<br />
H24Jun | 01:43:00<br />
F2Jul | 01:55:00<br />
(11 rows)<br />
</pre><br />
| width=280px |<br />
Now I get the list broken down, and can even use these indicators of the number of items that are in each group, but really that is all that I want. I could edit this list, but much easier is to use ''grep'':<br />
<br />
'''grep row all_orders.txt > data.txt'''<br />
<br />
<pre><br />
(603 rows)<br />
(17 rows)<br />
(11 rows)<br />
(13 rows)<br />
(10 rows)<br />
(17 rows)<br />
(14 rows)<br />
(22 rows)<br />
(17 rows)<br />
(23 rows)<br />
(37 rows)<br />
(36 rows)<br />
(37 rows)<br />
(35 rows)<br />
(29 rows)<br />
(31 rows)<br />
(37 rows)<br />
(42 rows)<br />
(32 rows)<br />
(36 rows)<br />
(35 rows)<br />
(25 rows)<br />
(19 rows)<br />
(17 rows)<br />
(11 rows)<br />
</pre><br />
| width=280px |<br />
Here is the contents of the file '''data.txt''' &ndash; see below and in the script how we can import this line-by-line, process the lines, then create a Python list.<br />
<br />
Incidentally, note that I used ''row'' rather than ''rows'' for grep matching. What I found on smaller lists was that ''postgresql'' has the grammatically correct ''(1 row)'' if there is only one item.<br />
|}<br />
<br />
===Finally, On to the Script===<br />
I went back and looked at [[Creating a Graph, Part 2]], which is simple, and has a number of elements of a graph, but not the actual line itself. I decided not to have the script create headers and labels for the axes, but just focus on the graph. One of the things that happened as time went on was that the Y-axis scale needed to change periodically, so I wanted to make something a bit generic. <br />
<br />
Although up to this point my graphs did not use tick marks, I wanted to add that feature, although I wanted to move them outside the lines rather then inside. So I left 2 value dialogs, one to specify the maximum value on the Y-axis, and then at what interval I wanted tick marks. If I was going to do this, I might as well automatically generate the X-axis, but here I would have a very constant X-axis, denoting the times of day. The times were in a text frame with custom tabs, so I moved that frame to a Master Page, once I had settled on a spacing of the tick marks.<br />
<br />
Why not just have the entire X-axis on the Master Page? Easily enough done, but as I make the PolyLine for the graph I need those X-Pos values for the tick marks, so why not just generate them on the fly for both the graph and tick marks, then I would be sure that they line up every time.<br />
<br />
{| cellpadding=10 |<br />
|[[Image:Latergraph.png|400px]]<br />
|width=350px|<br />
Here is an example of the output from the script along with the other work done in Scribus. <br />
<br />
Just because you could generate the entire page with a script doesn't always make the most sense, since then you may have something good for a single purpose and more difficult to edit for another.<br />
<br />
What the script generates are the X and Y axes with tick marks, then the line graph.<br />
|}<br />
<br />
So now you see the ''current final'' version of the script. One feature of the createPolyLine command is that it wants the values to alternate &ndash; ''x1, y1, x2, y2,'' and so on. Furthermore, when it says it wants a list it means it wants a Python list, i.e., an array name. Otherwise you get an error that it can only have a maximum of 2 elements, the list name and an optional name for the Polyline. This explains the code that creates the ''polyvalue'' list in the script. I also realize that I could have combined this interleaving in the first ''while'' loop, but separating it makes understanding the code easier, in my view.<br />
<br />
'''''Update!'''''<br />
<br />
I decided for the intellectual curiosity to go ahead and import the data from a file, the format of which corresponds to the '''data.txt''' file you see above. First I made a Perl script, and since I could use regexp easily in Perl, I could strip out the parts I needed. But this still leaves me with something I would be running outside of the script in Scribus, so I decided to write a similar function in Python.<br />
<br />
Python can use the '''fileinput''' module to get lines from a file. We skip over the first line, since that is the total number of orders, something not graphed. Next we strip off the initial "(" with '''line[1:]''', and then we can use the '''split''' string function to break the line at the space, putting the parts in the list '''bits[ ]'''. Now '''bits[0]''' will contain the string for our first value, so we convert to integer and append to the '''yvalue[ ]''' list.<br />
<br />
One final nicety was to show our values in the dialog asking about the Y-Axis maximum value, and for this we need the string '''yvalues'''.<br />
<br />
[[Image:Graphdialog.png]]<br />
<br />
A newer addition is the capability to choose to ''not'' draw the axes. A ''Create Axes?'' dialog appears with a 'Yes' default, and changing to anything but that results in only the polyline being created. In case you've seen previous versions, I've also rearranged some lines so that only one test for 'Yes' is needed.<br />
<br />
Some other things we might consider<br />
* adding a line to select the polyline at the end of the script:<br />
<pre>scribus.selectObject(poly)</pre><br />
* adding a line to the '''data.txt''' file which could be imported as a color for the polyline.<br />
* making the script recursive.<br />
* a bigger project, of course, would be to allow for manipulation of the X-axis.<br />
<br />
[[Image:Latergraph2.png]]<br />
<br />
===The Current Working Script (subject to change)===<br />
<syntaxhighlight lang='python'><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
# File: axes_graphing.py<br />
# originally 2006.05.17 as graph2.py on Scribus wiki<br />
# this version 2010.07.29 © Gregory Pittman, 2010<br />
# creates graph with axes and plots Y values<br />
# X values are fixed<br />
<br />
"""<br />
This script as written assumes a US Letter page in landscape orientation.<br />
The various position and dimension values you see are appropriate for page units<br />
of points. If you prefer other units, there are commands to get your units type, switch<br />
to points, and then at the end back to your preferred units.<br />
No headers are created and even the axis labels are not part of this script.<br />
It was written to plot events over a 24 hour day, so the X axis denotes hours<br />
(i.e., 24 tick points), and the Y axis number of events.<br />
<br />
In this latest version, the data is loaded from a file, with the particular logic <br />
meant to handle data on individual lines. Note that this will come in as string<br />
data and needs conversion to integers for the values to work.<br />
<br />
The other user input when the script runs is to specify the range of the Y axis,<br />
and indicate the value of individual tick marks. The reason for not making this <br />
automatic is that you might wish to have a family of graphs with a range of values<br />
from graph to graph, yet keep the same scale. You do get to see your data in this<br />
dialog. Now there is also the option to not draw the axes, in case you might want to<br />
draw multiple polylines on one graph.<br />
<br />
There is also virtually no error detection, or at least no messages other than<br />
the traceback that will show up.<br />
<br />
"""<br />
<br />
import scribus<br />
import fileinput<br />
<br />
xorigin = 64 # x-origin of graph<br />
yorigin = 536 # y-origin of graph<br />
xaxis=637 # x axis length<br />
yaxis=408 # y axis length<br />
color="Black"<br />
a = 1.5 # width of lines<br />
l = 2.0 # width of plotted line<br />
t = 0.8 # width of scale markers<br />
xvalue = []<br />
polyvalue = []<br />
i=1<br />
yvalue = []<br />
yvalues = ''<br />
datafile = scribus.fileDialog('Select Your Data File','Text Files (*.txt)')<br />
for line in fileinput.input(datafile):<br />
if (i > 1):<br />
line = line[1:]<br />
bits = line.split()<br />
yvalue.append(int(bits[0]))<br />
yvalues = yvalues + bits[0] + ' '<br />
i += 1<br />
<br />
if scribus.haveDoc():<br />
scribus.setRedraw(1)<br />
scribus.setUnit(0)<br />
xtick = xorigin<br />
xscale = xaxis/24 # this gives you typographic points per data unit<br />
yrange = int(scribus.valueDialog('Y Axis Maximum', 'Enter Top Value for Y Axis\n'+yvalues+'\n(Here is your data)'))<br />
ytick = yorigin<br />
yscale = yaxis/yrange # this gives you typographic points per data unit<br />
createaxes = scribus.valueDialog('Create Axes?','Do you want to create axes for this graph?\nChanging to anything else means No','Yes')<br />
nticks = 0<br />
while (nticks < 24):<br />
xtick = xtick + xscale<br />
xvalue.append(xtick)<br />
if (createaxes == 'Yes'):<br />
xt = scribus.createLine(xtick, yorigin, xtick, yorigin + 5) # creating X axis tick lines<br />
scribus.setLineWidth(t, xt)<br />
scribus.setLineColor(color, xt)<br />
scribus.setFillColor(color, xt)<br />
if (nticks == 0): # only need to to these once<br />
d = scribus.createLine(xorigin,yorigin,xorigin+xaxis,yorigin) # create X axis<br />
scribus.setLineWidth(a, d)<br />
scribus.setLineColor(color, d)<br />
scribus.setFillColor(color, d)<br />
e = scribus.createLine(xorigin,yorigin,xorigin,yorigin-yaxis) # create Y axis<br />
scribus.setLineWidth(a, e)<br />
scribus.setLineColor(color, e)<br />
scribus.setFillColor(color, e)<br />
ymark = int(scribus.valueDialog('Tick Mark Interval', 'Enter Y Interval for Tick Marks'))<br />
ytick = ytick - ymark * yscale<br />
while (ytick > (yorigin - yaxis)):<br />
yt = scribus.createLine(xorigin, ytick, xorigin - 5, ytick) # creating Y axis tick lines<br />
scribus.setLineWidth(t, yt)<br />
scribus.setLineColor(color, yt)<br />
scribus.setFillColor(color, yt)<br />
ytick = ytick - ymark * yscale<br />
nticks += 1<br />
item = 0<br />
while (item < 24): # this interleaves the X and Y data for createPolyLine<br />
polyvalue.append(xvalue[item])<br />
polyvalue.append((yorigin - yvalue[item] * yscale)) <br />
item += 1<br />
poly = scribus.createPolyLine(polyvalue) # this is the actual plotting<br />
scribus.setLineWidth(l, poly)<br />
scribus.setLineColor(color, poly)<br />
scribus.setFillColor("None",poly)<br />
<br />
scribus.redrawAll()<br />
</syntaxhighlight><br />
<br />
===Variation on a Theme: adv_graphing.py===<br />
Here is a slight variation that is less hardwired in its treatment of the X axis, and looks at the number of data points, then creates the right number of X-axis ticks for the number of points. If nothing else, this avoids a script failure when there is a mismatch in the number of points expected and what actually are in the data file.<br />
<br />
An example data file might look like this:<br />
<pre><br />
(192 rows)<br />
(171 rows)<br />
(184 rows)<br />
(180 rows)<br />
(180 rows)<br />
(167 rows)<br />
(167 rows)<br />
(153 rows)<br />
</pre><br />
so as before, the parsing strips off the first character, then uses the '''split''' string function to choose only the numbers from each line as our data points (Y values), converting the string to integer. This time, we're using all the lines as data, not ignoring the first.<br />
<br />
This version also gives you a dialog for choosing a color of the line. The first step is to see what color choices are available, so we getColorNames() and then display them in the valueDialog. I had thought the script would crash if you misspell a name to something not available, but for whatever reason, Black will be chosen (perhaps some default behavior of Scribus). If you were using the Scribus Gnome color set, this is what it would look like:<br />
<br />
[[File:Linecolorchoices.png]]<br />
<br />
Even if the color name has a space in the middle of it, entering it just as seen in this dialog is necessary and will work (see 'Accent_Red Dark', where presumably a typo left out a second underline character).<br />
<br />
<syntaxhighlight lang='python'><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# File: adv_graphing.py<br />
# originally 2006.05.17 as graph2.py on Scribus wiki<br />
# this version 2011.01.20<br />
# creates graph with axes and plots Y values<br />
# X values are fixed<br />
<br />
"""<br />
This script as written assumes a US Letter page in landscape orientation.<br />
The various position and dimension values you see are appropriate for page units<br />
of points. If you want to use A4, adjust the numbers appropriately.<br />
<br />
If you prefer other units, there are commands to get your units type, switch<br />
to points, and then at the end back to your preferred units.<br />
No headers are created and even the axis labels are not part of this script.<br />
This version will import your data, and note the number of data points (Y-axis values), then create <br />
the correct number of X-axis ticks for your data.<br />
<br />
The data is loaded from a file, with the particular logic <br />
meant to handle data on individual lines. Note that this will come in as string<br />
data and needs conversion to integers for the values to work.<br />
<br />
The other user input when the script runs is to specify the range of the Y axis,<br />
and indicate the value of individual tick marks. The reason for not making this <br />
automatic is that you might wish to have a family of graphs with a range of values<br />
from graph to graph, yet keep the same scale. You do get to see your data in this<br />
dialog. There is an option to not draw the axes, in case you might want to<br />
draw multiple polylines on one graph.<br />
<br />
"""<br />
<br />
import scribus<br />
import fileinput<br />
<br />
xorigin = 64 # x-origin of graph<br />
yorigin = 536 # y-origin of graph<br />
xaxis=637 # x axis length<br />
yaxis=408 # y axis length<br />
color="Black"<br />
colors = ''<br />
linecolor = 'Black'<br />
colorcount = 0<br />
a = 1.5 # width of lines<br />
l = 2.0 # width of plotted line<br />
t = 0.8 # width of scale markers<br />
xvalue = []<br />
polyvalue = []<br />
i=0<br />
yvalue = []<br />
yvalues = ''<br />
datafile = scribus.fileDialog('Select Your Data File','Text Files (*.txt)')<br />
for line in fileinput.input(datafile):<br />
line = line[1:]<br />
bits = line.split()<br />
yvalue.append(int(bits[0]))<br />
yvalues = yvalues + bits[0] + ' '<br />
i += 1<br />
<br />
scribus.messageBox('Your Data','Your data has '+str(i)+' data points') # this line is optional, but I like the information<br />
if scribus.haveDoc():<br />
colornames = scribus.getColorNames()<br />
for coloritem in colornames:<br />
colors = colors + coloritem + ' ' # 3 spaces between names so we can note names with a space in them<br />
colorcount += 1<br />
if (colorcount == 4):<br />
colorcount = 0<br />
colors = colors + '\n'<br />
linecolor = scribus.valueDialog('Enter a Line Color Name',colors,'Black')<br />
scribus.setRedraw(1)<br />
scribus.setUnit(0)<br />
xtick = xorigin<br />
xscale = xaxis/i # this gives you typographic points per data unit<br />
yrange = int(scribus.valueDialog('Y Axis Maximum', 'Enter Top Value for Y Axis\n'+yvalues+'\n(Here is your data)'))<br />
ytick = yorigin<br />
yscale = yaxis/yrange # this gives you typographic points per data unit<br />
createaxes = scribus.valueDialog('Create Axes?','Do you want to create axes for this graph?\nChanging to anything else means No','Yes')<br />
nticks = 0<br />
while (nticks < i):<br />
xtick = xtick + xscale<br />
xvalue.append(xtick)<br />
if (createaxes == 'Yes'):<br />
xt = scribus.createLine(xtick, yorigin, xtick, yorigin + 5) # creating X axis tick lines<br />
scribus.setLineWidth(t, xt)<br />
scribus.setLineColor(color, xt)<br />
scribus.setFillColor(color, xt)<br />
if (nticks == 0): # only need to to these once<br />
d = scribus.createLine(xorigin,yorigin,xorigin+xaxis,yorigin) # create X axis<br />
scribus.setLineWidth(a, d)<br />
scribus.setLineColor(color, d)<br />
scribus.setFillColor(color, d)<br />
e = scribus.createLine(xorigin,yorigin,xorigin,yorigin-yaxis) # create Y axis<br />
scribus.setLineWidth(a, e)<br />
scribus.setLineColor(color, e)<br />
scribus.setFillColor(color, e)<br />
ymark = int(scribus.valueDialog('Tick Mark Interval', 'Enter Y Interval for Tick Marks'))<br />
ytick = ytick - ymark * yscale<br />
while (ytick > (yorigin - yaxis)):<br />
yt = scribus.createLine(xorigin, ytick, xorigin - 5, ytick) # creating Y axis tick lines<br />
scribus.setLineWidth(t, yt)<br />
scribus.setLineColor(color, yt)<br />
scribus.setFillColor(color, yt)<br />
ytick = ytick - ymark * yscale<br />
nticks += 1<br />
item = 0<br />
while (item < i): # this interleaves the X and Y data for createPolyLine<br />
polyvalue.append(xvalue[item])<br />
polyvalue.append((yorigin - yvalue[item] * yscale)) <br />
item += 1<br />
poly = scribus.createPolyLine(polyvalue) # this is the actual plotting<br />
scribus.setLineWidth(l, poly)<br />
scribus.setLineColor(linecolor, poly)<br />
scribus.setFillColor("None",poly)<br />
scribus.selectObject(poly)<br />
<br />
scribus.redrawAll()<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Advanced_Graphing&diff=34456
Advanced Graphing
2018-02-28T00:55:01Z
<p>Gpittman: /* The Current Working Script (subject to change) */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
{| align="right" cellpadding=5px|<br />
| bgcolor="palegreen"|You may also be interested in:<br>[[Automatically Creating a Graph]]<br>[[Creating a Graph, Part 2]]<br> or <br>[[Making a Pie Chart]]<br />
|}<br />
Here are the Scribus operations you will find examples for in this script:<br />
{|<br />
| valign=top|<br />
* Testing for and using an existing document<br />
* Using ''fileDialog'' to open a text file having a predefined structure for data &ndash; some of that parsing uses the Python '''split''' function<br />
* Creating a graph layout with a number of lines &ndash; X and Y axes, plus tick marks (''createLine'')<br />
* Using ''valueDialog'' for user input<br />
* Using ''createPolyLine'' to make a line graph of data according to the scale of the graph<br />
|}<br />
This is an article about a script to create axes with tick marks, then plot data points to the scale of the graph.<br />
<br />
This article explains the workflow that led to the script, and I imagine will continue to suggest improvements. What I wanted to do was to accumulate information about when orders were coming in according to time of day, then see if as data accumulated whether patterns became apparent.<br />
<br />
===Beginnings===<br />
Like many such projects it began quite manually, making a graph structure by hand, trying out and not liking a grid, and in essence making my own grid to lay out data points. I was getting the data from a spreadsheet, collating manually since there wasn't so much at first, then making a polyline, again manually. This gave me an opportunity to fiddle with various parameters to get the look I wanted. This ugly self-created grid would not be printed or exported to the PDF.<br />
<br />
[[Image:Earlygraph.png|250px]]<br />
<br />
The data collection began in mid-April, and continues. Quite early, and you can easily see it in this graph from late April, there was this interesting peak at 4pm, so this led if nothing else to continuing the process to see what would happen with larger numbers.<br />
<br />
As I began updating the graph, I realized I needed some help from the manual drudgery. The first thing I did was to enter the information I wanted into a postgresql database, so I could dissect in various ways, such as by time of day. Later, as the number of data rose, I wanted to be able to look at this by day of week also. This also was helped by having postgresql, where I could for example transform all instances of 23May to M23May, thus making selecting for day of week easier.<br />
<br />
This was still quite manual, since I would export an ordered list to a text file, edit it a bit to making counting how many orders came in per hour, then use Scribus &ndash; Properties > Shape > Edit to manually change the nodes of the graph line as needed. Doable but tedious. What became especially annoying was counting lines of a text file, but of course postgresql can use an external script if you write one.<br />
<pre><br />
select * from orders order by time;<br />
select * from orders where time < '01:00' order by time;<br />
select * from orders where time > '00:59' and time < '02:00' order by time;<br />
select * from orders where time > '01:59' and time < '03:00' order by time;<br />
select * from orders where time > '02:59' and time < '04:00' order by time;<br />
select * from orders where time > '03:59' and time < '05:00' order by time;<br />
select * from orders where time > '04:59' and time < '06:00' order by time;<br />
select * from orders where time > '05:59' and time < '07:00' order by time;<br />
select * from orders where time > '06:59' and time < '08:00' order by time;<br />
select * from orders where time > '07:59' and time < '09:00' order by time;<br />
select * from orders where time > '08:59' and time < '10:00' order by time;<br />
select * from orders where time > '09:59' and time < '11:00' order by time;<br />
select * from orders where time > '10:59' and time < '12:00' order by time;<br />
select * from orders where time > '11:59' and time < '13:00' order by time;<br />
select * from orders where time > '12:59' and time < '14:00' order by time;<br />
select * from orders where time > '13:59' and time < '15:00' order by time;<br />
select * from orders where time > '14:59' and time < '16:00' order by time;<br />
select * from orders where time > '15:59' and time < '17:00' order by time;<br />
select * from orders where time > '16:59' and time < '18:00' order by time;<br />
select * from orders where time > '17:59' and time < '19:00' order by time;<br />
select * from orders where time > '18:59' and time < '20:00' order by time;<br />
select * from orders where time > '19:59' and time < '21:00' order by time;<br />
select * from orders where time > '20:59' and time < '22:00' order by time;<br />
select * from orders where time > '21:59' and time < '23:00' order by time;<br />
select * from orders where time > '22:59' order by time;<br />
</pre><br />
{| cellpadding=10 |<br />
|So what does this get you? Here is a fragment of the output near the end of the list from the first command into the next few lines:<br />
<br />
<pre><br />
A26Jun | 23:29:00<br />
T20Jul | 23:44:00<br />
F28May | 23:48:00<br />
A10Jul | 23:50:00<br />
F21May | 23:55:00<br />
(603 rows)<br />
<br />
date | time <br />
--------+----------<br />
M19Jul | 00:00:00<br />
A22May | 00:07:00<br />
H22Jul | 00:09:00<br />
S27Jun | 00:17:00<br />
A26Jun | 00:17:00<br />
W21Jul | 00:19:00<br />
H3Jun | 00:21:00<br />
M19Apr | 00:25:00<br />
W12May | 00:38:00<br />
F23Jul | 00:38:00<br />
T20Jul | 00:40:00<br />
H24Jun | 00:43:00<br />
W28Apr | 00:43:00<br />
T13Jul | 00:47:00<br />
W21Jul | 00:50:00<br />
T29Jun | 00:51:00<br />
H10Jun | 00:59:00<br />
(17 rows)<br />
<br />
date | time <br />
--------+----------<br />
M19Jul | 01:09:00<br />
T6Jul | 01:16:00<br />
S18Jul | 01:19:00<br />
H15Apr | 01:20:00<br />
H3Jun | 01:20:00<br />
T29Jun | 01:21:00<br />
W23Jun | 01:25:00<br />
H22Jul | 01:38:00<br />
H20May | 01:42:00<br />
H24Jun | 01:43:00<br />
F2Jul | 01:55:00<br />
(11 rows)<br />
</pre><br />
| width=280px |<br />
Now I get the list broken down, and can even use these indicators of the number of items that are in each group, but really that is all that I want. I could edit this list, but much easier is to use ''grep'':<br />
<br />
'''grep row all_orders.txt > data.txt'''<br />
<br />
<pre><br />
(603 rows)<br />
(17 rows)<br />
(11 rows)<br />
(13 rows)<br />
(10 rows)<br />
(17 rows)<br />
(14 rows)<br />
(22 rows)<br />
(17 rows)<br />
(23 rows)<br />
(37 rows)<br />
(36 rows)<br />
(37 rows)<br />
(35 rows)<br />
(29 rows)<br />
(31 rows)<br />
(37 rows)<br />
(42 rows)<br />
(32 rows)<br />
(36 rows)<br />
(35 rows)<br />
(25 rows)<br />
(19 rows)<br />
(17 rows)<br />
(11 rows)<br />
</pre><br />
| width=280px |<br />
Here is the contents of the file '''data.txt''' &ndash; see below and in the script how we can import this line-by-line, process the lines, then create a Python list.<br />
<br />
Incidentally, note that I used ''row'' rather than ''rows'' for grep matching. What I found on smaller lists was that ''postgresql'' has the grammatically correct ''(1 row)'' if there is only one item.<br />
|}<br />
<br />
===Finally, On to the Script===<br />
I went back and looked at [[Creating a Graph, Part 2]], which is simple, and has a number of elements of a graph, but not the actual line itself. I decided not to have the script create headers and labels for the axes, but just focus on the graph. One of the things that happened as time went on was that the Y-axis scale needed to change periodically, so I wanted to make something a bit generic. <br />
<br />
Although up to this point my graphs did not use tick marks, I wanted to add that feature, although I wanted to move them outside the lines rather then inside. So I left 2 value dialogs, one to specify the maximum value on the Y-axis, and then at what interval I wanted tick marks. If I was going to do this, I might as well automatically generate the X-axis, but here I would have a very constant X-axis, denoting the times of day. The times were in a text frame with custom tabs, so I moved that frame to a Master Page, once I had settled on a spacing of the tick marks.<br />
<br />
Why not just have the entire X-axis on the Master Page? Easily enough done, but as I make the PolyLine for the graph I need those X-Pos values for the tick marks, so why not just generate them on the fly for both the graph and tick marks, then I would be sure that they line up every time.<br />
<br />
{| cellpadding=10 |<br />
|[[Image:Latergraph.png|400px]]<br />
|width=350px|<br />
Here is an example of the output from the script along with the other work done in Scribus. <br />
<br />
Just because you could generate the entire page with a script doesn't always make the most sense, since then you may have something good for a single purpose and more difficult to edit for another.<br />
<br />
What the script generates are the X and Y axes with tick marks, then the line graph.<br />
|}<br />
<br />
So now you see the ''current final'' version of the script. One feature of the createPolyLine command is that it wants the values to alternate &ndash; ''x1, y1, x2, y2,'' and so on. Furthermore, when it says it wants a list it means it wants a Python list, i.e., an array name. Otherwise you get an error that it can only have a maximum of 2 elements, the list name and an optional name for the Polyline. This explains the code that creates the ''polyvalue'' list in the script. I also realize that I could have combined this interleaving in the first ''while'' loop, but separating it makes understanding the code easier, in my view.<br />
<br />
'''''Update!'''''<br />
<br />
I decided for the intellectual curiosity to go ahead and import the data from a file, the format of which corresponds to the '''data.txt''' file you see above. First I made a Perl script, and since I could use regexp easily in Perl, I could strip out the parts I needed. But this still leaves me with something I would be running outside of the script in Scribus, so I decided to write a similar function in Python.<br />
<br />
Python can use the '''fileinput''' module to get lines from a file. We skip over the first line, since that is the total number of orders, something not graphed. Next we strip off the initial "(" with '''line[1:]''', and then we can use the '''split''' string function to break the line at the space, putting the parts in the list '''bits[ ]'''. Now '''bits[0]''' will contain the string for our first value, so we convert to integer and append to the '''yvalue[ ]''' list.<br />
<br />
One final nicety was to show our values in the dialog asking about the Y-Axis maximum value, and for this we need the string '''yvalues'''.<br />
<br />
[[Image:Graphdialog.png]]<br />
<br />
A newer addition is the capability to choose to ''not'' draw the axes. A ''Create Axes?'' dialog appears with a 'Yes' default, and changing to anything but that results in only the polyline being created. In case you've seen previous versions, I've also rearranged some lines so that only one test for 'Yes' is needed.<br />
<br />
Some other things we might consider<br />
* adding a line to select the polyline at the end of the script:<br />
<pre>scribus.selectObject(poly)</pre><br />
* adding a line to the '''data.txt''' file which could be imported as a color for the polyline.<br />
* making the script recursive.<br />
* a bigger project, of course, would be to allow for manipulation of the X-axis.<br />
<br />
[[Image:Latergraph2.png]]<br />
<br />
===The Current Working Script (subject to change)===<br />
test<br />
<syntaxhighlight lang='python'><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
# File: axes_graphing.py<br />
# originally 2006.05.17 as graph2.py on Scribus wiki<br />
# this version 2010.07.29 © Gregory Pittman, 2010<br />
# creates graph with axes and plots Y values<br />
# X values are fixed<br />
<br />
"""<br />
This script as written assumes a US Letter page in landscape orientation.<br />
The various position and dimension values you see are appropriate for page units<br />
of points. If you prefer other units, there are commands to get your units type, switch<br />
to points, and then at the end back to your preferred units.<br />
No headers are created and even the axis labels are not part of this script.<br />
It was written to plot events over a 24 hour day, so the X axis denotes hours<br />
(i.e., 24 tick points), and the Y axis number of events.<br />
<br />
In this latest version, the data is loaded from a file, with the particular logic <br />
meant to handle data on individual lines. Note that this will come in as string<br />
data and needs conversion to integers for the values to work.<br />
<br />
The other user input when the script runs is to specify the range of the Y axis,<br />
and indicate the value of individual tick marks. The reason for not making this <br />
automatic is that you might wish to have a family of graphs with a range of values<br />
from graph to graph, yet keep the same scale. You do get to see your data in this<br />
dialog. Now there is also the option to not draw the axes, in case you might want to<br />
draw multiple polylines on one graph.<br />
<br />
There is also virtually no error detection, or at least no messages other than<br />
the traceback that will show up.<br />
<br />
"""<br />
<br />
import scribus<br />
import fileinput<br />
<br />
xorigin = 64 # x-origin of graph<br />
yorigin = 536 # y-origin of graph<br />
xaxis=637 # x axis length<br />
yaxis=408 # y axis length<br />
color="Black"<br />
a = 1.5 # width of lines<br />
l = 2.0 # width of plotted line<br />
t = 0.8 # width of scale markers<br />
xvalue = []<br />
polyvalue = []<br />
i=1<br />
yvalue = []<br />
yvalues = ''<br />
datafile = scribus.fileDialog('Select Your Data File','Text Files (*.txt)')<br />
for line in fileinput.input(datafile):<br />
if (i > 1):<br />
line = line[1:]<br />
bits = line.split()<br />
yvalue.append(int(bits[0]))<br />
yvalues = yvalues + bits[0] + ' '<br />
i += 1<br />
<br />
if scribus.haveDoc():<br />
scribus.setRedraw(1)<br />
scribus.setUnit(0)<br />
xtick = xorigin<br />
xscale = xaxis/24 # this gives you typographic points per data unit<br />
yrange = int(scribus.valueDialog('Y Axis Maximum', 'Enter Top Value for Y Axis\n'+yvalues+'\n(Here is your data)'))<br />
ytick = yorigin<br />
yscale = yaxis/yrange # this gives you typographic points per data unit<br />
createaxes = scribus.valueDialog('Create Axes?','Do you want to create axes for this graph?\nChanging to anything else means No','Yes')<br />
nticks = 0<br />
while (nticks < 24):<br />
xtick = xtick + xscale<br />
xvalue.append(xtick)<br />
if (createaxes == 'Yes'):<br />
xt = scribus.createLine(xtick, yorigin, xtick, yorigin + 5) # creating X axis tick lines<br />
scribus.setLineWidth(t, xt)<br />
scribus.setLineColor(color, xt)<br />
scribus.setFillColor(color, xt)<br />
if (nticks == 0): # only need to to these once<br />
d = scribus.createLine(xorigin,yorigin,xorigin+xaxis,yorigin) # create X axis<br />
scribus.setLineWidth(a, d)<br />
scribus.setLineColor(color, d)<br />
scribus.setFillColor(color, d)<br />
e = scribus.createLine(xorigin,yorigin,xorigin,yorigin-yaxis) # create Y axis<br />
scribus.setLineWidth(a, e)<br />
scribus.setLineColor(color, e)<br />
scribus.setFillColor(color, e)<br />
ymark = int(scribus.valueDialog('Tick Mark Interval', 'Enter Y Interval for Tick Marks'))<br />
ytick = ytick - ymark * yscale<br />
while (ytick > (yorigin - yaxis)):<br />
yt = scribus.createLine(xorigin, ytick, xorigin - 5, ytick) # creating Y axis tick lines<br />
scribus.setLineWidth(t, yt)<br />
scribus.setLineColor(color, yt)<br />
scribus.setFillColor(color, yt)<br />
ytick = ytick - ymark * yscale<br />
nticks += 1<br />
item = 0<br />
while (item < 24): # this interleaves the X and Y data for createPolyLine<br />
polyvalue.append(xvalue[item])<br />
polyvalue.append((yorigin - yvalue[item] * yscale)) <br />
item += 1<br />
poly = scribus.createPolyLine(polyvalue) # this is the actual plotting<br />
scribus.setLineWidth(l, poly)<br />
scribus.setLineColor(color, poly)<br />
scribus.setFillColor("None",poly)<br />
<br />
scribus.redrawAll()<br />
</syntaxhighlight><br />
<br />
===Variation on a Theme: adv_graphing.py===<br />
Here is a slight variation that is less hardwired in its treatment of the X axis, and looks at the number of data points, then creates the right number of X-axis ticks for the number of points. If nothing else, this avoids a script failure when there is a mismatch in the number of points expected and what actually are in the data file.<br />
<br />
An example data file might look like this:<br />
<pre><br />
(192 rows)<br />
(171 rows)<br />
(184 rows)<br />
(180 rows)<br />
(180 rows)<br />
(167 rows)<br />
(167 rows)<br />
(153 rows)<br />
</pre><br />
so as before, the parsing strips off the first character, then uses the '''split''' string function to choose only the numbers from each line as our data points (Y values), converting the string to integer. This time, we're using all the lines as data, not ignoring the first.<br />
<br />
This version also gives you a dialog for choosing a color of the line. The first step is to see what color choices are available, so we getColorNames() and then display them in the valueDialog. I had thought the script would crash if you misspell a name to something not available, but for whatever reason, Black will be chosen (perhaps some default behavior of Scribus). If you were using the Scribus Gnome color set, this is what it would look like:<br />
<br />
[[File:Linecolorchoices.png]]<br />
<br />
Even if the color name has a space in the middle of it, entering it just as seen in this dialog is necessary and will work (see 'Accent_Red Dark', where presumably a typo left out a second underline character).<br />
<br />
<syntaxhighlight lang='python'><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# File: adv_graphing.py<br />
# originally 2006.05.17 as graph2.py on Scribus wiki<br />
# this version 2011.01.20<br />
# creates graph with axes and plots Y values<br />
# X values are fixed<br />
<br />
"""<br />
This script as written assumes a US Letter page in landscape orientation.<br />
The various position and dimension values you see are appropriate for page units<br />
of points. If you want to use A4, adjust the numbers appropriately.<br />
<br />
If you prefer other units, there are commands to get your units type, switch<br />
to points, and then at the end back to your preferred units.<br />
No headers are created and even the axis labels are not part of this script.<br />
This version will import your data, and note the number of data points (Y-axis values), then create <br />
the correct number of X-axis ticks for your data.<br />
<br />
The data is loaded from a file, with the particular logic <br />
meant to handle data on individual lines. Note that this will come in as string<br />
data and needs conversion to integers for the values to work.<br />
<br />
The other user input when the script runs is to specify the range of the Y axis,<br />
and indicate the value of individual tick marks. The reason for not making this <br />
automatic is that you might wish to have a family of graphs with a range of values<br />
from graph to graph, yet keep the same scale. You do get to see your data in this<br />
dialog. There is an option to not draw the axes, in case you might want to<br />
draw multiple polylines on one graph.<br />
<br />
"""<br />
<br />
import scribus<br />
import fileinput<br />
<br />
xorigin = 64 # x-origin of graph<br />
yorigin = 536 # y-origin of graph<br />
xaxis=637 # x axis length<br />
yaxis=408 # y axis length<br />
color="Black"<br />
colors = ''<br />
linecolor = 'Black'<br />
colorcount = 0<br />
a = 1.5 # width of lines<br />
l = 2.0 # width of plotted line<br />
t = 0.8 # width of scale markers<br />
xvalue = []<br />
polyvalue = []<br />
i=0<br />
yvalue = []<br />
yvalues = ''<br />
datafile = scribus.fileDialog('Select Your Data File','Text Files (*.txt)')<br />
for line in fileinput.input(datafile):<br />
line = line[1:]<br />
bits = line.split()<br />
yvalue.append(int(bits[0]))<br />
yvalues = yvalues + bits[0] + ' '<br />
i += 1<br />
<br />
scribus.messageBox('Your Data','Your data has '+str(i)+' data points') # this line is optional, but I like the information<br />
if scribus.haveDoc():<br />
colornames = scribus.getColorNames()<br />
for coloritem in colornames:<br />
colors = colors + coloritem + ' ' # 3 spaces between names so we can note names with a space in them<br />
colorcount += 1<br />
if (colorcount == 4):<br />
colorcount = 0<br />
colors = colors + '\n'<br />
linecolor = scribus.valueDialog('Enter a Line Color Name',colors,'Black')<br />
scribus.setRedraw(1)<br />
scribus.setUnit(0)<br />
xtick = xorigin<br />
xscale = xaxis/i # this gives you typographic points per data unit<br />
yrange = int(scribus.valueDialog('Y Axis Maximum', 'Enter Top Value for Y Axis\n'+yvalues+'\n(Here is your data)'))<br />
ytick = yorigin<br />
yscale = yaxis/yrange # this gives you typographic points per data unit<br />
createaxes = scribus.valueDialog('Create Axes?','Do you want to create axes for this graph?\nChanging to anything else means No','Yes')<br />
nticks = 0<br />
while (nticks < i):<br />
xtick = xtick + xscale<br />
xvalue.append(xtick)<br />
if (createaxes == 'Yes'):<br />
xt = scribus.createLine(xtick, yorigin, xtick, yorigin + 5) # creating X axis tick lines<br />
scribus.setLineWidth(t, xt)<br />
scribus.setLineColor(color, xt)<br />
scribus.setFillColor(color, xt)<br />
if (nticks == 0): # only need to to these once<br />
d = scribus.createLine(xorigin,yorigin,xorigin+xaxis,yorigin) # create X axis<br />
scribus.setLineWidth(a, d)<br />
scribus.setLineColor(color, d)<br />
scribus.setFillColor(color, d)<br />
e = scribus.createLine(xorigin,yorigin,xorigin,yorigin-yaxis) # create Y axis<br />
scribus.setLineWidth(a, e)<br />
scribus.setLineColor(color, e)<br />
scribus.setFillColor(color, e)<br />
ymark = int(scribus.valueDialog('Tick Mark Interval', 'Enter Y Interval for Tick Marks'))<br />
ytick = ytick - ymark * yscale<br />
while (ytick > (yorigin - yaxis)):<br />
yt = scribus.createLine(xorigin, ytick, xorigin - 5, ytick) # creating Y axis tick lines<br />
scribus.setLineWidth(t, yt)<br />
scribus.setLineColor(color, yt)<br />
scribus.setFillColor(color, yt)<br />
ytick = ytick - ymark * yscale<br />
nticks += 1<br />
item = 0<br />
while (item < i): # this interleaves the X and Y data for createPolyLine<br />
polyvalue.append(xvalue[item])<br />
polyvalue.append((yorigin - yvalue[item] * yscale)) <br />
item += 1<br />
poly = scribus.createPolyLine(polyvalue) # this is the actual plotting<br />
scribus.setLineWidth(l, poly)<br />
scribus.setLineColor(linecolor, poly)<br />
scribus.setFillColor("None",poly)<br />
scribus.selectObject(poly)<br />
<br />
scribus.redrawAll()<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&diff=34455
Windows Full Python Integration
2018-02-28T00:49:22Z
<p>Gpittman: /* A simple method for using the system Python in Windows */</p>
<hr />
<div>{{Scripting Index}}<br />
Please see at the bottom of this page how simple it can be to use a system version of Python with Scribus.<br />
<br />
== How to replace the Python Interpreter shipped by Scribus 1.5.x for Windows ==<br />
<br />
The Python interpreter shipped with the Windows build of Scribus 1.5.x is limited by the Python at hand when the build is made by the Scribus developer. The Python interpreter runs off a dynamic linked library (DLL) that is shipped with Scribus. Unfortunately, with a DLL, you cannot expand it and integrate various Python packages like you may in a normal Python environment. The DLL is, in essence, frozen. You may want to have a Python Interpreter that can be expanded to include other packages, e.g. the PostgreSQL database package, which is not included in the DLL version. The way to accomplish this is to replace the DLL interpreter with a full Windows installation of Pyton. This gives you a more robust Python environment allowing you to add whatever packages you want.<br />
<br />
You can replace the Python interpreter by following the steps below.<br />
<br />
First, determine what version of Python has been included with your build of Scribus for Windows:<br />
<br />
Main Menu<br />
Scripter->Show Console<br />
<br />
In top window of Script Console dialog type:<br />
<br />
import sys<br />
print(sys.version)<br />
<br />
Click Script->Run or press F9. The lower window will produce<br />
something like:<br />
<br />
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]<br />
<br />
This is the version of Python that has been bundled with your Scribus. You want to know this so that you can download the full version and not introduce any compatibility issues between Scribus and the Python you're going to integrate.<br />
<br />
At https://www.python.org/download/releases/2.7.8/ there are two choices for either the 32 bit or 64 bit platform. For instance, for the 64 bit platform, there are:<br />
<br />
Windows X86-64 MSI Installer (2.7.8) [1]<br />
Windows X86-64 MSI program database (2.7.8) [1]<br />
<br />
You want the Installer. The "program database" is a larger distribution that is meant to include debugging routines. Download the appropriate installer, we'll run it later down below.<br />
<br />
Open a DOS console and type "set" to obtain a listing of your default environmental variables. We are interested in the "Path" variable. For instance your Path may have two versions of Python already in it (the ellipsis represents other values not relevant to Python):<br />
<br />
Path=...C:\Python32\;C:\Python32\Scripts;...C:\Python27\;C:\Python27\Scripts;...<br />
<br />
You do not want to destabilize your current PATH as you may have other software expecting to find whatever version of Python you have in your "Path" and not 2.7.8. So with the caveat in mind, we'll run their installer, but decline to have the installer modify the "Path" environmental variable.<br />
<br />
Run the Python installer. Create new top level directory, e.g. C:\Python278 and make sure during the installation that you do *NOT* add python.exe to your path. This is because your system may already be set up for Python 3 or other<br />
versions of Python 2 by having their paths be first in your PATH variable. You do not want to destabilize your current system<br />
by altering values in your default "Path" value. Instead, we'll set up a special DOS environment which calls Python 2.7.8 when running Scribus.<br />
<br />
Here is a batch script that you should copy and place in your Scribus home directory where the main executable Scribus.exe resides, e.g. C:\Program Files\Scribus 1.5.0. Name this batch script: scribus.bat<br />
<br />
<nowiki><br />
@echo off<br />
::<br />
:: special run of Scribus that uses Python installed on the<br />
:: users system that matches the build of the Python interpreter<br />
:: shipped with Scribus rather than the Python Interpreter shipped<br />
:: with Scribus' build.<br />
::<br />
:: See: http://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&action=edit&redlink=1<br />
::<br />
echo.<br />
echo Running Scribus ***without*** its shipped Python Interpreter<br />
echo.<br />
::<br />
:: Hide the shipped version of the Python interpreter so Scribus will use<br />
:: the "same" version we have built on Windows <br />
::<br />
if exist python (<br />
echo masking Scribus Python directory<br />
ren python python.SUSPEND<br />
)<br />
if exist python27.dll (<br />
echo masking Scribus library python27.dll<br />
ren python27.dll python27.dll.SUSPEND<br />
)<br />
echo.<br />
::<br />
:: point to our custom Python which should match the build of<br />
:: Python shipped with this version of Scribus<br />
:: See:<br />
::<br />
PATH=C:\Python278;.<br />
::<br />
:: run it!<br />
::<br />
echo. <br />
echo Launching Scribus...<br />
scribus.exe<br />
echo.<br />
::<br />
:: undo our temporary masks so we don't run Scribus in the future<br />
:: forgetting that we have this special hack to replace the Python<br />
:: interpreter shipped with it<br />
::<br />
if exist python.SUSPEND (<br />
echo restoring Scribus Python directory<br />
ren python.SUSPEND python<br />
)<br />
if exist python27.dll.SUSPEND (<br />
echo restoring Scribus library python.dll<br />
ren python27.dll.SUSPEND python27.dll<br />
)<br />
echo.<br />
::<br />
:: remind our user that we're cleaning up<br />
::<br />
pause<br />
<br />
</nowiki><br />
==A simple method for using the system Python in Windows==<br />
First of all, as the above section indicates, you must have the appropriate version of Python on your system (currently 2.7). Once you have installed Python, go to the directory C:\Program Files, and find your Scribus directory, for example Scribus 1.5.3.<br />
<br />
Inside this Scribus 1.5.3 directory, you will see a directory named '''python'''. Right-click on this to bring up the context menu, and choose Rename, and rename the directory to anything else, like '''pythonold'''. Now when you start up Scribus, when it fails to find this directory named python, it will then look to the system for Python. That's all there is to it.<br />
<br />
A major advantage of using the system Python is that you can easily add other packages that may not be included with Scribus, such as '''re''' or '''datetime'''.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&diff=34454
Windows Full Python Integration
2018-02-28T00:34:25Z
<p>Gpittman: /* How to replace the Python Interpreter shipped by Scribus 1.5.x for Windows */</p>
<hr />
<div>{{Scripting Index}}<br />
Please see at the bottom of this page how simple it can be to use a system version of Python with Scribus.<br />
<br />
== How to replace the Python Interpreter shipped by Scribus 1.5.x for Windows ==<br />
<br />
The Python interpreter shipped with the Windows build of Scribus 1.5.x is limited by the Python at hand when the build is made by the Scribus developer. The Python interpreter runs off a dynamic linked library (DLL) that is shipped with Scribus. Unfortunately, with a DLL, you cannot expand it and integrate various Python packages like you may in a normal Python environment. The DLL is, in essence, frozen. You may want to have a Python Interpreter that can be expanded to include other packages, e.g. the PostgreSQL database package, which is not included in the DLL version. The way to accomplish this is to replace the DLL interpreter with a full Windows installation of Pyton. This gives you a more robust Python environment allowing you to add whatever packages you want.<br />
<br />
You can replace the Python interpreter by following the steps below.<br />
<br />
First, determine what version of Python has been included with your build of Scribus for Windows:<br />
<br />
Main Menu<br />
Scripter->Show Console<br />
<br />
In top window of Script Console dialog type:<br />
<br />
import sys<br />
print(sys.version)<br />
<br />
Click Script->Run or press F9. The lower window will produce<br />
something like:<br />
<br />
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]<br />
<br />
This is the version of Python that has been bundled with your Scribus. You want to know this so that you can download the full version and not introduce any compatibility issues between Scribus and the Python you're going to integrate.<br />
<br />
At https://www.python.org/download/releases/2.7.8/ there are two choices for either the 32 bit or 64 bit platform. For instance, for the 64 bit platform, there are:<br />
<br />
Windows X86-64 MSI Installer (2.7.8) [1]<br />
Windows X86-64 MSI program database (2.7.8) [1]<br />
<br />
You want the Installer. The "program database" is a larger distribution that is meant to include debugging routines. Download the appropriate installer, we'll run it later down below.<br />
<br />
Open a DOS console and type "set" to obtain a listing of your default environmental variables. We are interested in the "Path" variable. For instance your Path may have two versions of Python already in it (the ellipsis represents other values not relevant to Python):<br />
<br />
Path=...C:\Python32\;C:\Python32\Scripts;...C:\Python27\;C:\Python27\Scripts;...<br />
<br />
You do not want to destabilize your current PATH as you may have other software expecting to find whatever version of Python you have in your "Path" and not 2.7.8. So with the caveat in mind, we'll run their installer, but decline to have the installer modify the "Path" environmental variable.<br />
<br />
Run the Python installer. Create new top level directory, e.g. C:\Python278 and make sure during the installation that you do *NOT* add python.exe to your path. This is because your system may already be set up for Python 3 or other<br />
versions of Python 2 by having their paths be first in your PATH variable. You do not want to destabilize your current system<br />
by altering values in your default "Path" value. Instead, we'll set up a special DOS environment which calls Python 2.7.8 when running Scribus.<br />
<br />
Here is a batch script that you should copy and place in your Scribus home directory where the main executable Scribus.exe resides, e.g. C:\Program Files\Scribus 1.5.0. Name this batch script: scribus.bat<br />
<br />
<nowiki><br />
@echo off<br />
::<br />
:: special run of Scribus that uses Python installed on the<br />
:: users system that matches the build of the Python interpreter<br />
:: shipped with Scribus rather than the Python Interpreter shipped<br />
:: with Scribus' build.<br />
::<br />
:: See: http://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&action=edit&redlink=1<br />
::<br />
echo.<br />
echo Running Scribus ***without*** its shipped Python Interpreter<br />
echo.<br />
::<br />
:: Hide the shipped version of the Python interpreter so Scribus will use<br />
:: the "same" version we have built on Windows <br />
::<br />
if exist python (<br />
echo masking Scribus Python directory<br />
ren python python.SUSPEND<br />
)<br />
if exist python27.dll (<br />
echo masking Scribus library python27.dll<br />
ren python27.dll python27.dll.SUSPEND<br />
)<br />
echo.<br />
::<br />
:: point to our custom Python which should match the build of<br />
:: Python shipped with this version of Scribus<br />
:: See:<br />
::<br />
PATH=C:\Python278;.<br />
::<br />
:: run it!<br />
::<br />
echo. <br />
echo Launching Scribus...<br />
scribus.exe<br />
echo.<br />
::<br />
:: undo our temporary masks so we don't run Scribus in the future<br />
:: forgetting that we have this special hack to replace the Python<br />
:: interpreter shipped with it<br />
::<br />
if exist python.SUSPEND (<br />
echo restoring Scribus Python directory<br />
ren python.SUSPEND python<br />
)<br />
if exist python27.dll.SUSPEND (<br />
echo restoring Scribus library python.dll<br />
ren python27.dll.SUSPEND python27.dll<br />
)<br />
echo.<br />
::<br />
:: remind our user that we're cleaning up<br />
::<br />
pause<br />
<br />
</nowiki><br />
==A simple method for using the system Python in Windows==</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&diff=34453
Windows Full Python Integration
2018-02-28T00:32:54Z
<p>Gpittman: </p>
<hr />
<div>{{Scripting Index}}<br />
Please see at the bottom of this page how simple it can be to use a system version of Python with Scribus.<br />
<br />
== How to replace the Python Interpreter shipped by Scribus 1.5.x for Windows ==<br />
<br />
The Python interpreter shipped with the Windows build of Scribus 1.5.x is limited by the Python at hand when the build is made by the Scribus developer. The Python interpreter runs off a dynamic linked library (DLL) that is shipped with Scribus. Unfortunately, with a DLL, you cannot expand it and integrate various Python packages like you may in a normal Python environment. The DLL is, in essence, frozen. You may want to have a Python Interpreter that can be expanded to include other packages, e.g. the PostgreSQL database package, which is not included in the DLL version. The way to accomplish this is to replace the DLL interpreter with a full Windows installation of Pyton. This gives you a more robust Python environment allowing you to add whatever packages you want.<br />
<br />
You can replace the Python interpreter by following the steps below.<br />
<br />
First, determine what version of Python has been included with your build of Scribus for Windows:<br />
<br />
Main Menu<br />
Scripter->Show Console<br />
<br />
In top window of Script Console dialog type:<br />
<br />
import sys<br />
print(sys.version)<br />
<br />
Click Script->Run or press F9. The lower window will produce<br />
something like:<br />
<br />
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]<br />
<br />
This is the version of Python that has been bundled with your Scribus. You want to know this so that you can download the full version and not introduce any compatibility issues between Scribus and the Python you're going to integrate.<br />
<br />
At https://www.python.org/download/releases/2.7.8/ there are two choices for either the 32 bit or 64 bit platform. For instance, for the 64 bit platform, there are:<br />
<br />
Windows X86-64 MSI Installer (2.7.8) [1]<br />
Windows X86-64 MSI program database (2.7.8) [1]<br />
<br />
You want the Installer. The "program database" is a larger distribution that is meant to include debugging routines. Download the appropriate installer, we'll run it later down below.<br />
<br />
Open a DOS console and type "set" to obtain a listing of your default environmental variables. We are interested in the "Path" variable. For instance your Path may have two versions of Python already in it (the ellipsis represents other values not relevant to Python):<br />
<br />
Path=...C:\Python32\;C:\Python32\Scripts;...C:\Python27\;C:\Python27\Scripts;...<br />
<br />
You do not want to destabilize your current PATH as you may have other software expecting to find whatever version of Python you have in your "Path" and not 2.7.8. So with the caveat in mind, we'll run their installer, but decline to have the installer modify the "Path" environmental variable.<br />
<br />
Run the Python installer. Create new top level directory, e.g. C:\Python278 and make sure during the installation that you do *NOT* add python.exe to your path. This is because your system may already be set up for Python 3 or other<br />
versions of Python 2 by having their paths be first in your PATH variable. You do not want to destabilize your current system<br />
by altering values in your default "Path" value. Instead, we'll set up a special DOS environment which calls Python 2.7.8 when running Scribus.<br />
<br />
Here is a batch script that you should copy and place in your Scribus home directory where the main executable Scribus.exe resides, e.g. C:\Program Files\Scribus 1.5.0. Name this batch script: scribus.bat<br />
<br />
<nowiki><br />
@echo off<br />
::<br />
:: special run of Scribus that uses Python installed on the<br />
:: users system that matches the build of the Python interpreter<br />
:: shipped with Scribus rather than the Python Interpreter shipped<br />
:: with Scribus' build.<br />
::<br />
:: See: http://wiki.scribus.net/wiki/index.php?title=Windows_Full_Python_Integration&action=edit&redlink=1<br />
::<br />
echo.<br />
echo Running Scribus ***without*** its shipped Python Interpreter<br />
echo.<br />
::<br />
:: Hide the shipped version of the Python interpreter so Scribus will use<br />
:: the "same" version we have built on Windows <br />
::<br />
if exist python (<br />
echo masking Scribus Python directory<br />
ren python python.SUSPEND<br />
)<br />
if exist python27.dll (<br />
echo masking Scribus library python27.dll<br />
ren python27.dll python27.dll.SUSPEND<br />
)<br />
echo.<br />
::<br />
:: point to our custom Python which should match the build of<br />
:: Python shipped with this version of Scribus<br />
:: See:<br />
::<br />
PATH=C:\Python278;.<br />
::<br />
:: run it!<br />
::<br />
echo. <br />
echo Launching Scribus...<br />
scribus.exe<br />
echo.<br />
::<br />
:: undo our temporary masks so we don't run Scribus in the future<br />
:: forgetting that we have this special hack to replace the Python<br />
:: interpreter shipped with it<br />
::<br />
if exist python.SUSPEND (<br />
echo restoring Scribus Python directory<br />
ren python.SUSPEND python<br />
)<br />
if exist python27.dll.SUSPEND (<br />
echo restoring Scribus library python.dll<br />
ren python27.dll.SUSPEND python27.dll<br />
)<br />
echo.<br />
::<br />
:: remind our user that we're cleaning up<br />
::<br />
pause<br />
<br />
</nowiki></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Generating_a_Code39_Barcode&diff=34450
Generating a Code39 Barcode
2018-02-11T23:46:35Z
<p>Gpittman: /* code39.py */</p>
<hr />
<div>{{Scripting Index}}<br />
Here are the Scribus operations you will find examples for in this script:<br />
{|<br />
| valign=top|<br />
* Testing for and using an existing document<br />
* Creating a number of lines using a standardized scheme (Code 39 specifications)<br />
* Using valueDialog for user input, also for more than one value per dialog, using the Python '''split''' function<br />
|<br />
* Some limited testing for valid user input &ndash; encodable characters<br />
* Creating a text frame at a specified relative page location and with a size defined by the barcode width<br />
* Setting fonts, and font characteristics, such as its size and alignment of text in the frame<br />
* Using messageBox for user feedback<br />
|}<br />
====How this script came to be====<br />
The reason for writing this script was that I had already written a script for modifying a form we use, and on this form are barcodes, one of which indicates the type of form, but the other is variable according to the content of the page.<br />
<br />
The script creates that custom part, which has a 10-digit number, then underneath is the barcode. By trial and error I determined that this was a Code39 barcode. Unfortunately, the barcode generator in Scribus cannot be scripted, and in fact you cannot make a custom size for the barcode, so I was copying the 10-digit number, then running Barcode generator, then resizing the created code, which is a PostScript creation, so when it's resized, the width of the bars may change. So far it's been Ok, but this might affect the scanning process.<br />
<br />
So here is a first attempt, '''code39.py'''. I had thought it was rather slow, but rechecking shows acceptable speed on various computers. The first iterations would only generate a code for digits and uppercase letters (plus the start/stop character), but now it's complete.<br />
<br />
====Oh, Why Not?====<br />
{| width=80% |<br />
|In keeping with the way that sometimes scripts keep getting things added, now we have added the ability to print human-readable characters under the code, decided with a third dialog. This takes your entry, creates a text frame as wide as the code but 3 points below the bottom, enters the text, centers it, with an 8-point Deja Vu Sans Book font.<br />
<br />
I see examples where the numbers are more spaced out than this, but of course you can make this adjustment afterward according to your own taste, so it helps to have the frame be as wide as the entire code. This is another advantage of doing this as a script rather than with some outside utility that creates an image of the code.<br />
|[[Image:Code39_results.png]]<br />
|-<br />
|I've also added a warning when you try to code a character that this script won't, so you get a message like this:<br />
<br />
As written, it stops at the first non-codable character, even though it does show you your entire entry. In this example '^' would also not be encodable.<br />
<br />
|[[Image:Code39_error.png]]<br />
|}<br />
<br />
====Maybe I've Got It Done Now====<br />
{| width=80% |<br />
|The final itch to scratch were those remaining characters, so now the Code 39 set is complete. <br />
<br />
The python is a bit clumsy, but it works.<br />
<br />
|[[Image:Code39_results2.png]]<br />
|}<br />
====Somebody Please STOP Me!====<br />
{| width=80% |<br />
|valign=top|Ok, now let's make it more flexible. Instead of hard-coded X-Pos and Y-Pos, we'll add the ability to assign these. By using the Python string '''split''' function, we can enter both values with one dialog, and for those times when you just want to get it on the page and then move it later, we'll put in some default values. Note the '''split''' syntax, and also that it discards however much whitespace there is between your values. These will be strings, so we need to convert to integer.<br />
<br />
I also have added a bailout if you run the script with no document open, since otherwise Scribus will just hang when ''if scribus.haveDoc()'' fails.<br />
| [[Image:Code39_location.png]]<br />
|}<br />
<br />
====code39.py====<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
# File: code39.py<br />
# Based on postnet2.py originally 2006.03.06 Gregory Pittman<br />
# this version 2010.08.05 © Gregory Pittman, 2010<br />
# encodes numbers and letters, plus all other Code 39 characters<br />
<br />
"""<br />
Simple operation.<br />
First dialog asks for your code (numbers and uppercase letters, plus space, period,<br />
-,*,$,/,+,%) i.e., all characters allowed by Code 39, as many characters as you want.<br />
Second dialog asks for height of bars in points.<br />
Third dialog asks for the X-Pos and Y-Pos, separated only be whitespace, no comma!<br />
Fourth dialog confirms that you want to print the characters underneath.<br />
The start/stop character (*) is automatically added and does not show in the <br />
human-readable sequence.<br />
<br />
"""<br />
<br />
import scribus<br />
import sys<br />
<br />
# first the codes for numbers 0-9<br />
code39 = ['nnswwn','wnsnnw','nwsnnw','wwsnnn','nnswnw','wnswnn','nwswnn','nnsnww','wnsnwn','nwsnwn']<br />
# next add the codes for A-Z<br />
code39.extend(['wnnsnw','nwnsnw','wwnsnn','nnwsnw','wnwsnn','nwwsnn','nnnsww','wnnswn','nwnswn'])<br />
code39.extend(['nnwswn','wnnnsw','nwnnsw','wwnnsn','nnwnsw','wnwnsn','nwwnsn','nnnwsw','wnnwsn'])<br />
code39.extend(['nwnwsn','nnwwsn','wsnnnw','nswnnw','wswnnn','nsnwnw','wsnwnn','nswwnn'])<br />
# and these are for the rest<br />
code39.extend(['nswnwn','nsnsnsnn','nnsnsnsn','nsnnww','wsnnwn','nsnsnnsn','nsnnsnsn'])<br />
<br />
startstop = 'nsnwwn'<br />
narrow = 1.0 # narrow line width<br />
wide = 2.2 # wide line width<br />
b="Black" #line color<br />
<br />
if scribus.haveDoc():<br />
S = scribus.valueDialog('Code 39','Enter Numbers or Uppercase Letters')<br />
height = scribus.valueDialog('Code 39','Enter Height of Bars (Points)')<br />
height = int(height)<br />
location = scribus.valueDialog('Code 39','Enter New X-Pos Y-Pos\n(No Comma, just space between)', '200 100')<br />
relpos = location.split()<br />
relx = int(relpos[0])<br />
rely = int(relpos[1])<br />
origx = relx<br />
humanread = scribus.valueDialog('Code 39','Print Human-Readable Code Too?\n(Any change means no)', 'Yes')<br />
scribus.setRedraw(1)<br />
scribus.setUnit(0)<br />
<br />
code = startstop<br />
<br />
for x in S[0:]:<br />
if x.isdigit():<br />
xnum = int(x)<br />
code = code + code39[xnum]<br />
elif ((ord(x) > 64) and (ord(x) < 91)): # ord(character) yields the ascii value<br />
xnum = ord(x) - 55<br />
code = code + code39[xnum]<br />
elif (ord(x) == 32): # space<br />
code = code + code39[36]<br />
elif ((ord(x) == 36) or (ord(x) == 37)): # $ and %<br />
xnum = ord(x) + 1<br />
code = code + code39[xnum]<br />
elif ((ord(x) > 44) and (ord(x) < 48)): # - . /<br />
xnum = ord(x) - 6<br />
code = code + code39[xnum]<br />
elif (ord(x) == 43): # +<br />
code = code + code39[42]<br />
elif (ord(x) == 42):<br />
code = code + startstop # * (adding for completeness)<br />
else:<br />
scribus.messageBox('OOPS!',S + '\nCode 39 does not encode this character: ' + x,scribus.ICON_WARNING,button1=scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
code = code + startstop<br />
<br />
for y in code[0:]:<br />
if y == 'n':<br />
relx = relx + narrow/2<br />
d = scribus.createLine(relx,rely,relx,rely + height,) #narrow line<br />
scribus.setLineWidth(narrow, d)<br />
scribus.setLineColor(b, d)<br />
scribus.setFillColor(b, d)<br />
relx = relx + narrow + narrow/2<br />
elif y == 'w':<br />
relx = relx + wide/2<br />
d = scribus.createLine(relx,rely,relx,rely + height,) #wide line<br />
scribus.setLineWidth(wide, d)<br />
scribus.setLineColor(b, d)<br />
scribus.setFillColor(b, d)<br />
relx = relx + narrow + wide/2<br />
elif y == 's': #for wide space<br />
relx = relx + wide<br />
if (humanread == 'Yes'):<br />
t = scribus.createText(origx, rely+height+3, relx - origx, 15)<br />
scribus.setText(S, t)<br />
scribus.setFont("DejaVu Sans Book", t)<br />
scribus.setFontSize(8, t)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, t)<br />
<br />
scribus.redrawAll()<br />
scribus.docChanged(1)<br />
<br />
else:<br />
scribus.messageBox('OOPS!','You must have a document open to run this script',scribus.ICON_WARNING,button1=scribus.BUTTON_OK)<br />
sys.exit(1)<br />
<br />
</syntaxhighlight><br />
<br />
====Line Positions====<br />
Something worth mentioning here is that the precise position of the endpoints of lines is in the middle of the line. Thus, when I was creating lines of a particular width with very specific spacing in between, I had to account for the width of the lines or otherwise they would encroach on the space, and so you see these weird arithmetic additions in the if/elif loops.<br />
<br />
====About Code39====<br />
Code 39 is a widely used code consisting of a series of narrow and wide black lines, alternating with narrow or wide white spaces. Each character is denoted by a sequence of 5 lines and 4 intervening spaces, with a narrow space in between characters. The digits 0-9 and capital letters A-Z, plus *, hyphen, period, $, /, % and space are defined. The * character is also known as the start/stop character, since all codes should begin and end with it to orient the scanner.<br />
<br />
Narrow and wide lines, and narrow and wide spaces have corresponding width values, and the relative ratios are generally 1:2.2 to 1:3 (narrow:wide).</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Win32_version_of_Scribus&diff=34445
Win32 version of Scribus
2018-01-14T21:49:54Z
<p>Gpittman: /* Native Windows version release information */</p>
<hr />
<div>[[Category:Windows]][[Category:Installation]][[Category:EN]]<br />
==Native Windows version release information==<br />
* [[Official:Windows|Scribus on Windows]] -- See this page first for all the important install info on the native Windows version.<br />
** This '''will not run''' on Win95, Win98 or WinME. Scribus requires the capabilities of Windows 2000, XP, Vista, Server 200x, or Windows 7, 8, or 10. Attempts to run Scribus on Win9x or WinME will fail due to the absence of a number of system requirements which cannot practically be met.<br />
** With the release of 1.3.2, help documentation from [http://docs.scribus.net docs.scribus.net] has been integrated with the main package across all platforms.<br />
<br />
==64-bit Windows (of any of those compatible versions mentioned above)==<br />
Scribus 1.4.6 is available as a 64-bit version that can be installed on Windows Vista 64-bit, Microsoft Windows 7 64-bit, and Microsoft Windows 8 64-bit.<br><br />
For previous versions, there is no 64-bit version of Scribus. Nonetheless, the 32-bit version works without a hitch, and without any other considerations as you use the installer for your Windows machine.<br />
<br />
==Python==<br />
If you install Scribus using the installer from Sourceforge, you should have a working version of Python 2.7 with Scribus 1.5.x. Some scripts that you may wish to use or write yourself may need Python packages not supplied with Scribus, and you cannot add them yourself. The answer in this situation is to install Python 2.7 on your system, along with any necessary or desired packages, such as PIL (Python Imaging Library).<br />
<br />
In order for Scribus to use this system-based Python you need to deactivate the version included with Scribus. This is actually a simple matter. Go to C:\Program Files\Scribus 1.5.3\ (or whatever Scribus version you have installed), and look for a directory named python\. Just change its name to anything else, like oldpython\, and when you next start Scribus it will use the system Python.<br />
<br />
== Notes ==<br />
<br />
* [http://sourceforge.net/project/showfiles.php?group_id=1897 Ghostscript 8.53] or newer required for EPS, PS import and printing.<br />
** When you first run Scribus, you must go to Edit>Preferences>External Tools and change "name of executable" to wherever you have installed Ghostscript to. You must choose the "gswin32c.exe" version for Scribus to run! For example, set it to: "C:/Program Files/gs/gs8.53/bin/gswin32c.exe"<br />
<br />
== Obtaining GDI+ ==<br />
<br />
Scribus under Windows 2000 requires the [http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en GDI+ library] from Microsoft. There are other legal sources for the library for those who don't use IE or don't want to go through the "Genuine Windows" validation process — which has come under severe criticism and has been reported to produces false negatives in some cases (at the [http://go.microsoft.com/fwlink/?linkid=63634 Windows Genuine Advantage Forum], for example):<br />
<br />
* GDI+ is also distributed [http://download.freenet.de/archiv_g/gdi+_6816.html here]. This is part of the download archive within the portal of one of Germany's major ISPs. You don't need to understand German to use the page, just find the "zum Download" button and then, on the next page, the "Download starten" button. This will download Microsoft's own installer for the US English version of the library.<br />
<br />
* Possibly the simplest way of meeting the GDI+ requirement is to search the file gdiplus.dll on your hard disk and copy it into the directory that contains the Scribus executable. (The "official" download does not install any files beyond gdiplus.dll either.) There are freely available applications whose installer puts the file into their application directory. Such applications are:<br />
** [http://www.mp3tag.de/en/ Mp3Tag]<br />
<br />
When obtaining GDI+ from an "unofficial" source such as one of the above, it is important to remember that older versions of the file were suffering from a [http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx critical bug] that affected the processing of JPEG files. The bug was reported in September 2004, and as of September 2006, the current version is of gdiplus.dll is 5.1.3102.1360.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Win32_version_of_Scribus&diff=34444
Win32 version of Scribus
2018-01-14T21:47:39Z
<p>Gpittman: /* Native Windows version release information */</p>
<hr />
<div>[[Category:Windows]][[Category:Installation]][[Category:EN]]<br />
==Native Windows version release information==<br />
* [[Official:Windows|Scribus on Windows]] -- See this page first for all the important install info on the native Windows version.<br />
** This '''will not run''' on Win95, Win98 or WinME. Scribus requires the capabilities of Windows 2000, XP, Vista, Server 200x, or Windows 7, 8, or 10. Attempts to run Scribus on Win9x or WinME will fail. We have coded it this way and requests for support will be met with a firm refusal.<br />
** With the release of 1.3.2, help documentation from [http://docs.scribus.net docs.scribus.net] has been integrated with the main package across all platforms.<br />
<br />
==64-bit Windows (of any of those compatible versions mentioned above)==<br />
Scribus 1.4.6 is available as a 64-bit version that can be installed on Windows Vista 64-bit, Microsoft Windows 7 64-bit, and Microsoft Windows 8 64-bit.<br><br />
For previous versions, there is no 64-bit version of Scribus. Nonetheless, the 32-bit version works without a hitch, and without any other considerations as you use the installer for your Windows machine.<br />
<br />
==Python==<br />
If you install Scribus using the installer from Sourceforge, you should have a working version of Python 2.7 with Scribus 1.5.x. Some scripts that you may wish to use or write yourself may need Python packages not supplied with Scribus, and you cannot add them yourself. The answer in this situation is to install Python 2.7 on your system, along with any necessary or desired packages, such as PIL (Python Imaging Library).<br />
<br />
In order for Scribus to use this system-based Python you need to deactivate the version included with Scribus. This is actually a simple matter. Go to C:\Program Files\Scribus 1.5.3\ (or whatever Scribus version you have installed), and look for a directory named python\. Just change its name to anything else, like oldpython\, and when you next start Scribus it will use the system Python.<br />
<br />
== Notes ==<br />
<br />
* [http://sourceforge.net/project/showfiles.php?group_id=1897 Ghostscript 8.53] or newer required for EPS, PS import and printing.<br />
** When you first run Scribus, you must go to Edit>Preferences>External Tools and change "name of executable" to wherever you have installed Ghostscript to. You must choose the "gswin32c.exe" version for Scribus to run! For example, set it to: "C:/Program Files/gs/gs8.53/bin/gswin32c.exe"<br />
<br />
== Obtaining GDI+ ==<br />
<br />
Scribus under Windows 2000 requires the [http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en GDI+ library] from Microsoft. There are other legal sources for the library for those who don't use IE or don't want to go through the "Genuine Windows" validation process — which has come under severe criticism and has been reported to produces false negatives in some cases (at the [http://go.microsoft.com/fwlink/?linkid=63634 Windows Genuine Advantage Forum], for example):<br />
<br />
* GDI+ is also distributed [http://download.freenet.de/archiv_g/gdi+_6816.html here]. This is part of the download archive within the portal of one of Germany's major ISPs. You don't need to understand German to use the page, just find the "zum Download" button and then, on the next page, the "Download starten" button. This will download Microsoft's own installer for the US English version of the library.<br />
<br />
* Possibly the simplest way of meeting the GDI+ requirement is to search the file gdiplus.dll on your hard disk and copy it into the directory that contains the Scribus executable. (The "official" download does not install any files beyond gdiplus.dll either.) There are freely available applications whose installer puts the file into their application directory. Such applications are:<br />
** [http://www.mp3tag.de/en/ Mp3Tag]<br />
<br />
When obtaining GDI+ from an "unofficial" source such as one of the above, it is important to remember that older versions of the file were suffering from a [http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx critical bug] that affected the processing of JPEG files. The bug was reported in September 2004, and as of September 2006, the current version is of gdiplus.dll is 5.1.3102.1360.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Win32_version_of_Scribus&diff=34443
Win32 version of Scribus
2018-01-14T21:45:38Z
<p>Gpittman: /* 64-bit Windows (of any of those compatible versions mentioned above) */</p>
<hr />
<div>[[Category:Windows]][[Category:Installation]][[Category:EN]]<br />
==Native Windows version release information==<br />
* [[Official:Windows|Scribus on Windows]] -- See this page first for all the important install info on the native Windows version.<br />
** This '''will not run''' on Win95, Win98 or WinME - ''Only'' Windows 2000, XP, Vista, Server 200x, or Windows 7. Scribus requires the capabilities of Windows 2000, XP, Vista, Server 200x, or Windows 7. Attempts to run Scribus on Win9x or WinME will fail. We have coded it this way and requests for support will be met with a firm refusal.<br />
** With the release of 1.3.2, help documentation from [http://docs.scribus.net docs.scribus.net] has been integrated with the main package across all platforms.<br />
<br />
==64-bit Windows (of any of those compatible versions mentioned above)==<br />
Scribus 1.4.6 is available as a 64-bit version that can be installed on Windows Vista 64-bit, Microsoft Windows 7 64-bit, and Microsoft Windows 8 64-bit.<br><br />
For previous versions, there is no 64-bit version of Scribus. Nonetheless, the 32-bit version works without a hitch, and without any other considerations as you use the installer for your Windows machine.<br />
<br />
==Python==<br />
If you install Scribus using the installer from Sourceforge, you should have a working version of Python 2.7 with Scribus 1.5.x. Some scripts that you may wish to use or write yourself may need Python packages not supplied with Scribus, and you cannot add them yourself. The answer in this situation is to install Python 2.7 on your system, along with any necessary or desired packages, such as PIL (Python Imaging Library).<br />
<br />
In order for Scribus to use this system-based Python you need to deactivate the version included with Scribus. This is actually a simple matter. Go to C:\Program Files\Scribus 1.5.3\ (or whatever Scribus version you have installed), and look for a directory named python\. Just change its name to anything else, like oldpython\, and when you next start Scribus it will use the system Python.<br />
<br />
== Notes ==<br />
<br />
* [http://sourceforge.net/project/showfiles.php?group_id=1897 Ghostscript 8.53] or newer required for EPS, PS import and printing.<br />
** When you first run Scribus, you must go to Edit>Preferences>External Tools and change "name of executable" to wherever you have installed Ghostscript to. You must choose the "gswin32c.exe" version for Scribus to run! For example, set it to: "C:/Program Files/gs/gs8.53/bin/gswin32c.exe"<br />
<br />
== Obtaining GDI+ ==<br />
<br />
Scribus under Windows 2000 requires the [http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en GDI+ library] from Microsoft. There are other legal sources for the library for those who don't use IE or don't want to go through the "Genuine Windows" validation process — which has come under severe criticism and has been reported to produces false negatives in some cases (at the [http://go.microsoft.com/fwlink/?linkid=63634 Windows Genuine Advantage Forum], for example):<br />
<br />
* GDI+ is also distributed [http://download.freenet.de/archiv_g/gdi+_6816.html here]. This is part of the download archive within the portal of one of Germany's major ISPs. You don't need to understand German to use the page, just find the "zum Download" button and then, on the next page, the "Download starten" button. This will download Microsoft's own installer for the US English version of the library.<br />
<br />
* Possibly the simplest way of meeting the GDI+ requirement is to search the file gdiplus.dll on your hard disk and copy it into the directory that contains the Scribus executable. (The "official" download does not install any files beyond gdiplus.dll either.) There are freely available applications whose installer puts the file into their application directory. Such applications are:<br />
** [http://www.mp3tag.de/en/ Mp3Tag]<br />
<br />
When obtaining GDI+ from an "unofficial" source such as one of the above, it is important to remember that older versions of the file were suffering from a [http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx critical bug] that affected the processing of JPEG files. The bug was reported in September 2004, and as of September 2006, the current version is of gdiplus.dll is 5.1.3102.1360.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Win32_version_of_Scribus&diff=34442
Win32 version of Scribus
2018-01-14T21:42:45Z
<p>Gpittman: /* Python */</p>
<hr />
<div>[[Category:Windows]][[Category:Installation]][[Category:EN]]<br />
==Native Windows version release information==<br />
* [[Official:Windows|Scribus on Windows]] -- See this page first for all the important install info on the native Windows version.<br />
** This '''will not run''' on Win95, Win98 or WinME - ''Only'' Windows 2000, XP, Vista, Server 200x, or Windows 7. Scribus requires the capabilities of Windows 2000, XP, Vista, Server 200x, or Windows 7. Attempts to run Scribus on Win9x or WinME will fail. We have coded it this way and requests for support will be met with a firm refusal.<br />
** With the release of 1.3.2, help documentation from [http://docs.scribus.net docs.scribus.net] has been integrated with the main package across all platforms.<br />
<br />
==64-bit Windows (of any of those compatible versions mentioned above)==<br />
Scribus 1.4.2 is available as a 64-bit version that can be installed on Windows Vista 64-bit, Microsoft Windows 7 64-bit, and Microsoft Windows 8 64-bit.<br><br />
For previous versions, there is no 64-bit version of Scribus. Nonetheless, the 32-bit version works without a hitch, and without any other considerations as you use the installer for your Windows machine.<br />
==Python==<br />
If you install Scribus using the installer from Sourceforge, you should have a working version of Python 2.7 with Scribus 1.5.x. Some scripts that you may wish to use or write yourself may need Python packages not supplied with Scribus, and you cannot add them yourself. The answer in this situation is to install Python 2.7 on your system, along with any necessary or desired packages, such as PIL (Python Imaging Library).<br />
<br />
In order for Scribus to use this system-based Python you need to deactivate the version included with Scribus. This is actually a simple matter. Go to C:\Program Files\Scribus 1.5.3\ (or whatever Scribus version you have installed), and look for a directory named python\. Just change its name to anything else, like oldpython\, and when you next start Scribus it will use the system Python.<br />
<br />
== Notes ==<br />
<br />
* [http://sourceforge.net/project/showfiles.php?group_id=1897 Ghostscript 8.53] or newer required for EPS, PS import and printing.<br />
** When you first run Scribus, you must go to Edit>Preferences>External Tools and change "name of executable" to wherever you have installed Ghostscript to. You must choose the "gswin32c.exe" version for Scribus to run! For example, set it to: "C:/Program Files/gs/gs8.53/bin/gswin32c.exe"<br />
<br />
== Obtaining GDI+ ==<br />
<br />
Scribus under Windows 2000 requires the [http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en GDI+ library] from Microsoft. There are other legal sources for the library for those who don't use IE or don't want to go through the "Genuine Windows" validation process — which has come under severe criticism and has been reported to produces false negatives in some cases (at the [http://go.microsoft.com/fwlink/?linkid=63634 Windows Genuine Advantage Forum], for example):<br />
<br />
* GDI+ is also distributed [http://download.freenet.de/archiv_g/gdi+_6816.html here]. This is part of the download archive within the portal of one of Germany's major ISPs. You don't need to understand German to use the page, just find the "zum Download" button and then, on the next page, the "Download starten" button. This will download Microsoft's own installer for the US English version of the library.<br />
<br />
* Possibly the simplest way of meeting the GDI+ requirement is to search the file gdiplus.dll on your hard disk and copy it into the directory that contains the Scribus executable. (The "official" download does not install any files beyond gdiplus.dll either.) There are freely available applications whose installer puts the file into their application directory. Such applications are:<br />
** [http://www.mp3tag.de/en/ Mp3Tag]<br />
<br />
When obtaining GDI+ from an "unofficial" source such as one of the above, it is important to remember that older versions of the file were suffering from a [http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx critical bug] that affected the processing of JPEG files. The bug was reported in September 2004, and as of September 2006, the current version is of gdiplus.dll is 5.1.3102.1360.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Win32_version_of_Scribus&diff=34441
Win32 version of Scribus
2018-01-14T21:36:35Z
<p>Gpittman: /* 64-bit Windows (of any of those compatible versions mentioned above) */</p>
<hr />
<div>[[Category:Windows]][[Category:Installation]][[Category:EN]]<br />
==Native Windows version release information==<br />
* [[Official:Windows|Scribus on Windows]] -- See this page first for all the important install info on the native Windows version.<br />
** This '''will not run''' on Win95, Win98 or WinME - ''Only'' Windows 2000, XP, Vista, Server 200x, or Windows 7. Scribus requires the capabilities of Windows 2000, XP, Vista, Server 200x, or Windows 7. Attempts to run Scribus on Win9x or WinME will fail. We have coded it this way and requests for support will be met with a firm refusal.<br />
** With the release of 1.3.2, help documentation from [http://docs.scribus.net docs.scribus.net] has been integrated with the main package across all platforms.<br />
<br />
==64-bit Windows (of any of those compatible versions mentioned above)==<br />
Scribus 1.4.2 is available as a 64-bit version that can be installed on Windows Vista 64-bit, Microsoft Windows 7 64-bit, and Microsoft Windows 8 64-bit.<br><br />
For previous versions, there is no 64-bit version of Scribus. Nonetheless, the 32-bit version works without a hitch, and without any other considerations as you use the installer for your Windows machine.<br />
==Python==<br />
<br />
== Notes ==<br />
<br />
* [http://sourceforge.net/project/showfiles.php?group_id=1897 Ghostscript 8.53] or newer required for EPS, PS import and printing.<br />
** When you first run Scribus, you must go to Edit>Preferences>External Tools and change "name of executable" to wherever you have installed Ghostscript to. You must choose the "gswin32c.exe" version for Scribus to run! For example, set it to: "C:/Program Files/gs/gs8.53/bin/gswin32c.exe"<br />
<br />
== Obtaining GDI+ ==<br />
<br />
Scribus under Windows 2000 requires the [http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en GDI+ library] from Microsoft. There are other legal sources for the library for those who don't use IE or don't want to go through the "Genuine Windows" validation process — which has come under severe criticism and has been reported to produces false negatives in some cases (at the [http://go.microsoft.com/fwlink/?linkid=63634 Windows Genuine Advantage Forum], for example):<br />
<br />
* GDI+ is also distributed [http://download.freenet.de/archiv_g/gdi+_6816.html here]. This is part of the download archive within the portal of one of Germany's major ISPs. You don't need to understand German to use the page, just find the "zum Download" button and then, on the next page, the "Download starten" button. This will download Microsoft's own installer for the US English version of the library.<br />
<br />
* Possibly the simplest way of meeting the GDI+ requirement is to search the file gdiplus.dll on your hard disk and copy it into the directory that contains the Scribus executable. (The "official" download does not install any files beyond gdiplus.dll either.) There are freely available applications whose installer puts the file into their application directory. Such applications are:<br />
** [http://www.mp3tag.de/en/ Mp3Tag]<br />
<br />
When obtaining GDI+ from an "unofficial" source such as one of the above, it is important to remember that older versions of the file were suffering from a [http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx critical bug] that affected the processing of JPEG files. The bug was reported in September 2004, and as of September 2006, the current version is of gdiplus.dll is 5.1.3102.1360.</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_Text_Frames_for_Image_Captions&diff=34440
Creating Text Frames for Image Captions
2018-01-08T19:45:39Z
<p>Gpittman: /* Adding a caption style */</p>
<hr />
<div>{{Scripting_Index}}<br />
<br />
Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.<br />
<br />
I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.<br />
<br />
In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).<br />
<br />
[[File:Image_captions.png]]<br />
<br />
===bcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
"""<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===tcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
tcaption.py<br />
<br />
Creates a text frame (caption) above one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===rcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
rcaption.py<br />
<br />
Creates a text frame (caption) to the right of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===lcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
lcaption.py<br />
<br />
Creates a text frame (caption) to the left of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===caption.py===<br />
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.<br />
<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
caption.py<br />
<br />
Creates a text frame (caption) in selected location relative to <br />
one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")<br />
captionloc = captionloc[0]<br />
location = captionloc.upper()<br />
<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
if location == "B":<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)# frame height set at 24 points<br />
elif location == "T":<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
elif location == "L":<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) # frame width set at 150, height at 40 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===Additional mods===<br />
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single '''valueDialog()''' for this, then use the python '''.split()''' operator.<br />
Here is the original script section:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
</syntaxhighlight><br />
<br />
Let's change it to this by adding four lines, and use the variables instead of numbers in the '''createText()''' command:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx + fwidth, fy, cwidth, cheight)<br />
</syntaxhighlight><br />
Remember that everything entered into a '''valueDialog()''' is a string, so after splitting to 2 separate values, we then need to convert to '''float()''' since this is what '''createText()''' requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.<br />
<syntaxhighlight lang=python><br />
elif location == "L":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx-cwidth, fy + fheight - cheight, cwidth, cheight)<br />
</syntaxhighlight><br />
===Adding a caption style===<br />
Here is another modification to the '''bcaption.py''' script &ndash; let's call it '''bcaption_style.py'''. We add 2 things here &ndash; one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named '''Caption''', and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption_style.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
This version also creates a Paragraph Style named Caption (if it does not already exist), and <br />
<br />
then uses it in the frames. A small Top Distance (4 pts) is also created for these caption frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
createcaptionstyle = "yes"<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
captionstyle = "Caption" <br />
stylelist = scribus.getAllStyles()<br />
for style in stylelist:<br />
if style =="Caption":<br />
createcaptionstyle = "no"<br />
if createcaptionstyle == "yes":<br />
scribus.createCharStyle("captionchar","Liberation Serif Italic", 10.0, 'Black')<br />
scribus.createParagraphStyle("Caption",1,10.0, 0,0,0,0,0,0,0,0,0,"captionchar")<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
scribus.setTextDistances(0,0,4,0,textf)<br />
scribus.setText(textf,textf)<br />
scribus.setStyle("Caption",textf)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_Text_Frames_for_Image_Captions&diff=34439
Creating Text Frames for Image Captions
2018-01-08T19:45:14Z
<p>Gpittman: /* Adding a caption style */</p>
<hr />
<div>{{Scripting_Index}}<br />
<br />
Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.<br />
<br />
I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.<br />
<br />
In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).<br />
<br />
[[File:Image_captions.png]]<br />
<br />
===bcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
"""<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===tcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
tcaption.py<br />
<br />
Creates a text frame (caption) above one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===rcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
rcaption.py<br />
<br />
Creates a text frame (caption) to the right of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===lcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
lcaption.py<br />
<br />
Creates a text frame (caption) to the left of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===caption.py===<br />
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.<br />
<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
caption.py<br />
<br />
Creates a text frame (caption) in selected location relative to <br />
one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")<br />
captionloc = captionloc[0]<br />
location = captionloc.upper()<br />
<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
if location == "B":<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)# frame height set at 24 points<br />
elif location == "T":<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
elif location == "L":<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) # frame width set at 150, height at 40 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===Additional mods===<br />
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single '''valueDialog()''' for this, then use the python '''.split()''' operator.<br />
Here is the original script section:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
</syntaxhighlight><br />
<br />
Let's change it to this by adding four lines, and use the variables instead of numbers in the '''createText()''' command:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx + fwidth, fy, cwidth, cheight)<br />
</syntaxhighlight><br />
Remember that everything entered into a '''valueDialog()''' is a string, so after splitting to 2 separate values, we then need to convert to '''float()''' since this is what '''createText()''' requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.<br />
<syntaxhighlight lang=python><br />
elif location == "L":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx-cwidth, fy + fheight - cheight, cwidth, cheight)<br />
</syntaxhighlight><br />
===Adding a caption style===<br />
Here is another modification to the '''bcaption.py''' script &ndash; let's call it bcaption_style.py. We add 2 things here &ndash; one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named '''Caption''', and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption_style.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
This version also creates a Paragraph Style named Caption (if it does not already exist), and <br />
<br />
then uses it in the frames. A small Top Distance (4 pts) is also created for these caption frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
createcaptionstyle = "yes"<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
captionstyle = "Caption" <br />
stylelist = scribus.getAllStyles()<br />
for style in stylelist:<br />
if style =="Caption":<br />
createcaptionstyle = "no"<br />
if createcaptionstyle == "yes":<br />
scribus.createCharStyle("captionchar","Liberation Serif Italic", 10.0, 'Black')<br />
scribus.createParagraphStyle("Caption",1,10.0, 0,0,0,0,0,0,0,0,0,"captionchar")<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
scribus.setTextDistances(0,0,4,0,textf)<br />
scribus.setText(textf,textf)<br />
scribus.setStyle("Caption",textf)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_Text_Frames_for_Image_Captions&diff=34438
Creating Text Frames for Image Captions
2018-01-08T19:44:38Z
<p>Gpittman: /* Adding a caption style */</p>
<hr />
<div>{{Scripting_Index}}<br />
<br />
Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.<br />
<br />
I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.<br />
<br />
In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).<br />
<br />
[[File:Image_captions.png]]<br />
<br />
===bcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
"""<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===tcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
tcaption.py<br />
<br />
Creates a text frame (caption) above one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===rcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
rcaption.py<br />
<br />
Creates a text frame (caption) to the right of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===lcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
lcaption.py<br />
<br />
Creates a text frame (caption) to the left of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===caption.py===<br />
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.<br />
<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
caption.py<br />
<br />
Creates a text frame (caption) in selected location relative to <br />
one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")<br />
captionloc = captionloc[0]<br />
location = captionloc.upper()<br />
<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
if location == "B":<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)# frame height set at 24 points<br />
elif location == "T":<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
elif location == "L":<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) # frame width set at 150, height at 40 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===Additional mods===<br />
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single '''valueDialog()''' for this, then use the python '''.split()''' operator.<br />
Here is the original script section:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
</syntaxhighlight><br />
<br />
Let's change it to this by adding four lines, and use the variables instead of numbers in the '''createText()''' command:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx + fwidth, fy, cwidth, cheight)<br />
</syntaxhighlight><br />
Remember that everything entered into a '''valueDialog()''' is a string, so after splitting to 2 separate values, we then need to convert to '''float()''' since this is what '''createText()''' requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.<br />
<syntaxhighlight lang=python><br />
elif location == "L":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx-cwidth, fy + fheight - cheight, cwidth, cheight)<br />
</syntaxhighlight><br />
===Adding a caption style===<br />
Here is another modification to the '''bcaption.py''' script. We add 2 things here &ndash; one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named '''Caption''', and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption_style.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
This version also creates a Paragraph Style named Caption (if it does not already exist), and <br />
<br />
then uses it in the frames. A small Top Distance (4 pts) is also created for these caption frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
createcaptionstyle = "yes"<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
captionstyle = "Caption" <br />
stylelist = scribus.getAllStyles()<br />
for style in stylelist:<br />
if style =="Caption":<br />
createcaptionstyle = "no"<br />
if createcaptionstyle == "yes":<br />
scribus.createCharStyle("captionchar","Liberation Serif Italic", 10.0, 'Black')<br />
scribus.createParagraphStyle("Caption",1,10.0, 0,0,0,0,0,0,0,0,0,"captionchar")<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
scribus.setTextDistances(0,0,4,0,textf)<br />
scribus.setText(textf,textf)<br />
scribus.setStyle("Caption",textf)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_Text_Frames_for_Image_Captions&diff=34437
Creating Text Frames for Image Captions
2018-01-08T19:43:56Z
<p>Gpittman: /* Adding a caption style */</p>
<hr />
<div>{{Scripting_Index}}<br />
<br />
Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.<br />
<br />
I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.<br />
<br />
In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).<br />
<br />
[[File:Image_captions.png]]<br />
<br />
===bcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
"""<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===tcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
tcaption.py<br />
<br />
Creates a text frame (caption) above one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===rcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
rcaption.py<br />
<br />
Creates a text frame (caption) to the right of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===lcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
lcaption.py<br />
<br />
Creates a text frame (caption) to the left of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===caption.py===<br />
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.<br />
<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
caption.py<br />
<br />
Creates a text frame (caption) in selected location relative to <br />
one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")<br />
captionloc = captionloc[0]<br />
location = captionloc.upper()<br />
<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
if location == "B":<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)# frame height set at 24 points<br />
elif location == "T":<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
elif location == "L":<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) # frame width set at 150, height at 40 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===Additional mods===<br />
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single '''valueDialog()''' for this, then use the python '''.split()''' operator.<br />
Here is the original script section:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
</syntaxhighlight><br />
<br />
Let's change it to this by adding four lines, and use the variables instead of numbers in the '''createText()''' command:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx + fwidth, fy, cwidth, cheight)<br />
</syntaxhighlight><br />
Remember that everything entered into a '''valueDialog()''' is a string, so after splitting to 2 separate values, we then need to convert to '''float()''' since this is what '''createText()''' requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.<br />
<syntaxhighlight lang=python><br />
elif location == "L":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx-cwidth, fy + fheight - cheight, cwidth, cheight)<br />
</syntaxhighlight><br />
===Adding a caption style===<br />
Here is another modification to the '''bcaption.py''' script. We add 2 things here &ndash; one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named '''Caption''', and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
This version also creates a Paragraph Style named Caption (if it does not already exist), and <br />
<br />
then uses it in the frames. A small Top Distance (4 pts) is also created for these caption frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
createcaptionstyle = "yes"<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
captionstyle = "Caption" <br />
stylelist = scribus.getAllStyles()<br />
for style in stylelist:<br />
if style =="Caption":<br />
createcaptionstyle = "no"<br />
if createcaptionstyle == "yes":<br />
scribus.createCharStyle("captionchar","Liberation Serif Italic", 10.0, 'Black')<br />
scribus.createParagraphStyle("Caption",1,10.0, 0,0,0,0,0,0,0,0,0,"captionchar")<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
scribus.setTextDistances(0,0,4,0,textf)<br />
scribus.setText(textf,textf)<br />
scribus.setStyle("Caption",textf)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Creating_Text_Frames_for_Image_Captions&diff=34436
Creating Text Frames for Image Captions
2018-01-08T19:43:12Z
<p>Gpittman: /* Adding a caption style */</p>
<hr />
<div>{{Scripting_Index}}<br />
<br />
Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.<br />
<br />
I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.<br />
<br />
In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).<br />
<br />
[[File:Image_captions.png]]<br />
<br />
===bcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
"""<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===tcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
tcaption.py<br />
<br />
Creates a text frame (caption) above one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===rcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
rcaption.py<br />
<br />
Creates a text frame (caption) to the right of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight><br />
<br />
===lcaption.py===<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
lcaption.py<br />
<br />
Creates a text frame (caption) to the left of one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===caption.py===<br />
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.<br />
<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
caption.py<br />
<br />
Creates a text frame (caption) in selected location relative to <br />
one or more selected frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
<br />
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")<br />
captionloc = captionloc[0]<br />
location = captionloc.upper()<br />
<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
if location == "B":<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)# frame height set at 24 points<br />
elif location == "T":<br />
textf = scribus.createText(fx, fy-24, fwidth, 24) # frame height set at 24 points<br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
elif location == "L":<br />
textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) # frame width set at 150, height at 40 points<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
</syntaxhighlight><br />
<br />
===Additional mods===<br />
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single '''valueDialog()''' for this, then use the python '''.split()''' operator.<br />
Here is the original script section:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
textf = scribus.createText(fx + fwidth, fy, 150, 40)# frame width set at 150, height at 40 points<br />
</syntaxhighlight><br />
<br />
Let's change it to this by adding four lines, and use the variables instead of numbers in the '''createText()''' command:<br />
<syntaxhighlight lang=python><br />
elif location == "R":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx + fwidth, fy, cwidth, cheight)<br />
</syntaxhighlight><br />
Remember that everything entered into a '''valueDialog()''' is a string, so after splitting to 2 separate values, we then need to convert to '''float()''' since this is what '''createText()''' requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.<br />
<syntaxhighlight lang=python><br />
elif location == "L":<br />
cdimensions = scribus.valueDialog("Width/Height of Caption","Enter the width and height of the caption,\n in points (only space between values)", "150 40")<br />
cwidth, cheight = cdimensions.split()<br />
cwidth = float(cwidth)<br />
cheight = float(cheight)<br />
textf = scribus.createText(fx-cwidth, fy + fheight - cheight, cwidth, cheight)<br />
</syntaxhighlight><br />
===Adding a caption style===<br />
Here is another modification to the '''bcaption.py''' script. We add 2 things here &ndash; one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named '''Caption''', and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.<br />
<syntaxhighlight lang=python><br />
#!/usr/bin/env python<br />
# -*- coding: utf-8 -*-<br />
<br />
# ****************************************************************************<br />
# This program is free software; you can redistribute it and/or modify <br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software<br />
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
# <br />
# ****************************************************************************<br />
<br />
<br />
"""<br />
<br />
© 2017 Gregory Pittman<br />
<br />
bcaption.py<br />
<br />
Creates a text frame (caption) below one or more selected frames.<br />
<br />
This version also creates a Paragraph Style named Caption (if it does not already exist), and <br />
<br />
then uses it in the frames. A small Top Distance (4 pts) is also created for these caption frames.<br />
<br />
"""<br />
<br />
try:<br />
import scribus<br />
except ImportError:<br />
print "Unable to import the 'scribus' module. This script will only run within"<br />
print "the Python interpreter embedded in Scribus. Try Script->Execute Script."<br />
sys.exit(1)<br />
<br />
numselect = scribus.selectionCount()<br />
count = 0<br />
frames = []<br />
createcaptionstyle = "yes"<br />
<br />
if numselect == 0:<br />
scribus.messageBox('Selection Count', "You must have at least one image frame selected",<br />
scribus.ICON_WARNING, scribus.BUTTON_OK)<br />
sys.exit(2)<br />
captionstyle = "Caption" <br />
stylelist = scribus.getAllStyles()<br />
for style in stylelist:<br />
if style =="Caption":<br />
createcaptionstyle = "no"<br />
if createcaptionstyle == "yes":<br />
scribus.createCharStyle("captionchar",font= "Liberation Serif Italic", 10.0, 'Black')<br />
scribus.createParagraphStyle("Caption",1,10.0, 0,0,0,0,0,0,0,0,0,"captionchar")<br />
pageunits = scribus.getUnit()<br />
scribus.setUnit(scribus.UNIT_POINTS)<br />
<br />
while count < numselect:<br />
frames.append(scribus.getSelectedObject(count))<br />
count += 1<br />
<br />
for frame in frames:<br />
fwidth, fheight = scribus.getSize(frame)<br />
fx, fy = scribus.getPosition(frame)<br />
textf = scribus.createText(fx, fy+fheight, fwidth, 24)<br />
scribus.setTextDistances(0,0,4,0,textf)<br />
scribus.setText(textf,textf)<br />
scribus.setStyle("Caption",textf)<br />
<br />
scribus.setUnit(pageunits)<br />
<br />
scribus.setRedraw(True)<br />
<br />
<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34434
Text and Text Manipulation
2018-01-02T18:25:43Z
<p>Gpittman: /* Creating the Colors */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
==The Setting==<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
==Parsing the Color Data==<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
==Creating the Colors==<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
It's worth mentioning that this command is only available as of Scribus version 1.5.4svn.<br />
<br />
==Now the Document==<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
==Working with Fonts and Styles==<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
==The Challenge of Character Styles==<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
===Problem Solved!===<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
==A Funny Thing Happened on the Way to the Paragraph Styles==<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
===So, You Use a Stopwatch with Scripts?===<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
==Special Characters==<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
===Now Add Page Count===<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23) or in hex 0x17:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) + ' of ' + chr(23), textframe)<br />
</syntaxhighlight><br />
or<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e of \x17', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34433
Text and Text Manipulation
2018-01-02T18:25:09Z
<p>Gpittman: /* Creating the Colors */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
==The Setting==<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
==Parsing the Color Data==<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
==Creating the Colors==<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
It's worth mentioning that this command is only available as of version 1.5.4svn.<br />
<br />
==Now the Document==<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
==Working with Fonts and Styles==<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
==The Challenge of Character Styles==<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
===Problem Solved!===<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
==A Funny Thing Happened on the Way to the Paragraph Styles==<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
===So, You Use a Stopwatch with Scripts?===<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
==Special Characters==<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
===Now Add Page Count===<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23) or in hex 0x17:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) + ' of ' + chr(23), textframe)<br />
</syntaxhighlight><br />
or<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e of \x17', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Announcements&diff=34432
Announcements
2018-01-01T01:00:43Z
<p>Gpittman: /* 1.5.0 Series */</p>
<hr />
<div>==List of Scribus Announcements==<br />
===1.4.0 Series===<br />
<br />
* '''[[Scribus_1.4.6_Release|1.4.6 Release]]''' &mdash; current stable version<br />
* [[1.4.5 Release]]<br />
* [[1.4.4 Release]]<br />
* [[1.4.3 Release]]<br />
* [[1.4.2_Portable,_OS/2_and_eComStation_Release|1.4.2 Portable, OS/2 and eComStation Release]]<br />
* [[1.4.2 Release]]<br />
* [[1.4.1 Release]]<br />
* [[1.4.0 Release]]<br />
* [[1.4.0.rc3 Release]]<br />
<!--* [[1.4.0.rc2 Release]] Page doesn't exist, obsolete after the release of 1.4 --><br />
<br />
===1.5.0 Series===<br />
* [https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/ https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/] &mdash; snapshots of 1.5.4.svn for installing on MacOS and Windows<br />
* [[1.5.3 Release]] — development version<br />
* [[1.5.2 Release]] — development version<br />
* [[1.5.1 Release]] — development version<br />
* [[1.5.0 Release]] — development version</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Announcements&diff=34431
Announcements
2018-01-01T00:58:47Z
<p>Gpittman: /* 1.5.0 Series */</p>
<hr />
<div>==List of Scribus Announcements==<br />
===1.4.0 Series===<br />
<br />
* '''[[Scribus_1.4.6_Release|1.4.6 Release]]''' &mdash; current stable version<br />
* [[1.4.5 Release]]<br />
* [[1.4.4 Release]]<br />
* [[1.4.3 Release]]<br />
* [[1.4.2_Portable,_OS/2_and_eComStation_Release|1.4.2 Portable, OS/2 and eComStation Release]]<br />
* [[1.4.2 Release]]<br />
* [[1.4.1 Release]]<br />
* [[1.4.0 Release]]<br />
* [[1.4.0.rc3 Release]]<br />
<!--* [[1.4.0.rc2 Release]] Page doesn't exist, obsolete after the release of 1.4 --><br />
<br />
===1.5.0 Series===<br />
* [https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/ https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/] &mdash; snapshots of 1.5.4.svn<br />
* [[1.5.3 Release]] — development version<br />
* [[1.5.2 Release]] — development version<br />
* [[1.5.1 Release]] — development version<br />
* [[1.5.0 Release]] — development version</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Announcements&diff=34430
Announcements
2018-01-01T00:57:56Z
<p>Gpittman: /* 1.5.0 Series */</p>
<hr />
<div>==List of Scribus Announcements==<br />
===1.4.0 Series===<br />
<br />
* '''[[Scribus_1.4.6_Release|1.4.6 Release]]''' &mdash; current stable version<br />
* [[1.4.5 Release]]<br />
* [[1.4.4 Release]]<br />
* [[1.4.3 Release]]<br />
* [[1.4.2_Portable,_OS/2_and_eComStation_Release|1.4.2 Portable, OS/2 and eComStation Release]]<br />
* [[1.4.2 Release]]<br />
* [[1.4.1 Release]]<br />
* [[1.4.0 Release]]<br />
* [[1.4.0.rc3 Release]]<br />
<!--* [[1.4.0.rc2 Release]] Page doesn't exist, obsolete after the release of 1.4 --><br />
<br />
===1.5.0 Series===<br />
* [https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/ https://sourceforge.net/projects/scribus/files/scribus-svn/1.5.4.svn/] &mdash; snapshots of 1.5.4svn<br />
* [[1.5.3 Release]] — development version<br />
* [[1.5.2 Release]] — development version<br />
* [[1.5.1 Release]] — development version<br />
* [[1.5.0 Release]] — development version</div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34429
Text and Text Manipulation
2017-12-31T23:42:19Z
<p>Gpittman: /* Now Add Page Count */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
==The Setting==<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
==Parsing the Color Data==<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
==Creating the Colors==<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
==Now the Document==<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
==Working with Fonts and Styles==<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
==The Challenge of Character Styles==<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
===Problem Solved!===<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
==A Funny Thing Happened on the Way to the Paragraph Styles==<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
===So, You Use a Stopwatch with Scripts?===<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
==Special Characters==<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
===Now Add Page Count===<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23) or in hex 0x17:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) + ' of ' + chr(23), textframe)<br />
</syntaxhighlight><br />
or<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e of \x17', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34428
Text and Text Manipulation
2017-12-31T23:41:36Z
<p>Gpittman: </p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
==The Setting==<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
==Parsing the Color Data==<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
==Creating the Colors==<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
==Now the Document==<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
==Working with Fonts and Styles==<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
==The Challenge of Character Styles==<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
===Problem Solved!===<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
==A Funny Thing Happened on the Way to the Paragraph Styles==<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
===So, You Use a Stopwatch with Scripts?===<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
==Special Characters==<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
====Now Add Page Count====<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23) or in hex 0x17:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) + ' of ' + chr(23), textframe)<br />
</syntaxhighlight><br />
or<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e of \x17', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34427
Text and Text Manipulation
2017-12-29T15:09:24Z
<p>Gpittman: /* Now Add Page Count */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
====Now Add Page Count====<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23) or in hex 0x17:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) + ' of ' + chr(23), textframe)<br />
</syntaxhighlight><br />
or<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e of \x17', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34426
Text and Text Manipulation
2017-12-29T14:59:15Z
<p>Gpittman: /* Special Characters */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight><br />
====Now Add Page Count====<br />
We can also use a special character for the page count, the number of pages in the document. This is chr(23):<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30) = ' of ' + chr(23), textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34425
Text and Text Manipulation
2017-12-29T01:40:32Z
<p>Gpittman: /* A Funny Thing Happened on the Way to the Paragraph Styles */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements, and if you have 2000 colors, you have 2000 associated text frames.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34424
Text and Text Manipulation
2017-12-29T01:33:05Z
<p>Gpittman: /* So, You Use a Stopwatch with Scripts? */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run, looking something like 00:02:18, which would indicate 2 minutes, 18 seconds.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34423
Text and Text Manipulation
2017-12-29T01:31:02Z
<p>Gpittman: /* So, You Use a Stopwatch with Scripts? */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
and somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34422
Text and Text Manipulation
2017-12-29T01:30:23Z
<p>Gpittman: /* A Funny Thing Happened on the Way to the Paragraph Styles */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements.<br />
====So, You Use a Stopwatch with Scripts?====<br />
Actually, at first I was, but then I built in to the script a timing mechanism, using the Python module '''datetime'''. At the top of the script you add:<br />
<syntaxhighlight lang=python><br />
import datetime<br />
</syntaxhighlight><br />
Then somewhere early in the script you put this line:<br />
<syntaxhighlight lang=python><br />
start = datetime.datetime.now().replace(microsecond=0)<br />
</syntaxhighlight><br />
Then somewhere near the end:<br />
<syntaxhighlight lang=python><br />
finish = datetime.datetime.now().replace(microsecond=0)<br />
interval = finish - start<br />
scribus.messageBox("Interval",'This took ' + str(interval) + ' to finish',button1=scribus.BUTTON_OK)<br />
</syntaxhighlight><br />
which gives you a nice little '''messageBox()''' telling you how long it took the script to run.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34421
Text and Text Manipulation
2017-12-29T01:21:22Z
<p>Gpittman: /* Special Characters */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page in Story Editor, it shows up as a red '#', and of course in the document it shows up as the page number for the page that it is on. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34420
Text and Text Manipulation
2017-12-29T01:18:57Z
<p>Gpittman: /* The Challenge of Character Styles */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
===A Funny Thing Happened on the Way to the Paragraph Styles===<br />
I wasn't expecting it, but a "side-effect" of creating and using these styles instead of setting fonts and font sizes manually was a tremendous increase in the speed of the script. If you can imagine running this script on a file that might have hundreds or thousands of colors in it, you wouldn't be surprised at a long running time. In a few cases it was more than an hour. The largest file I have took 2 hrs, 21 min, and 19 sec to run, creating a document of 110 pages. After using styles this was reduced to 26 min, 59 seconds. Another file that took 5 minutes, 31 seconds, was reduced to 27 seconds. It's not quite clear to me why and where this speed-up occurs, but somehow applying a style with all of its features at once is much faster than applying its individual elements.<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page on the canvas, it shows up as a red '#'. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34419
Text and Text Manipulation
2017-12-29T00:43:05Z
<p>Gpittman: /* Special Characters */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page on the canvas, it shows up as a red '#'. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this in a script you would specify '''chr(30)''':<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman
https://wiki.scribus.net/wiki/index.php?title=Text_and_Text_Manipulation&diff=34418
Text and Text Manipulation
2017-12-29T00:40:48Z
<p>Gpittman: /* The Challenge of Character Styles */</p>
<hr />
<div>{{Scripting Index}}[[Category:EN]][[Category:Graphics]]<br />
After having just finished a script which involved creating a variable number, sometimes large number of text frames, along the way I learned quite a bit about how to use the various commands for styles and text. Some of this is not found in the online manual, and would be difficult to include there. What I'd like to do here is save others the time it took me to find out these important aspects of scripting.<br />
<br />
===The Setting===<br />
The particular project I was involved with took color data from a file, creating colors from that data, then making a document which displayed those colors with an informational label underneath. Here is a small detail from the eventually created pages:<br />
<br />
[[File:colorpatches.png]]<br />
<br />
This is the appearance in Scribus, so in the actual document these text frames will have no color to the border. The top line in the text frame is the name of the color, then the column of numbers underneath represent the L, a, and b values that created the above color. The input came from a plain text file, where entries look like this:<br />
<br />
<pre><br />
HLC 010 50 60 50 59,1 10,4<br />
HLC 010 50 70 50 68,9 12,2<br />
</pre><br />
To the left we see the color name, represented by 3 letters followed by 7 digits with some intervening spaces. Although not visible here, there are tabs separating the name from the 3 following numbers and the numbers from each other. This helps as we try to parse these lines with Python. Notice that the numbers use a comma as a decimal separator, something else we will need to contend with, since to create a color from these Python will need to have floating point numbers.<br />
===Parsing the Color Data===<br />
<br />
<syntaxhighlight lang=python><br />
for line in open(colorfile).xreadlines():<br />
content = line.split('\t')<br />
fields = len(content)<br />
if (fields == 4):<br />
colors.append(content[0])<br />
Lval = content[fields - 3]<br />
Lval = re.sub(r',','.',Lval)<br />
Lval = float(Lval)<br />
L.append(Lval)<br />
aval = content[fields - 2]<br />
aval = re.sub(r',','.',aval)<br />
aval = float(aval)<br />
a.append(aval)<br />
bval = content[fields - 1]<br />
bval = re.sub(r',','.',bval)<br />
bval = float(bval)<br />
b.append(bval)<br />
</syntaxhighlight><br />
The first line opens the file that we have identified in a '''fileDialog()''' line by line. This line is imported as a string. The string is then split using a tab ('\t') as the separator, and assigned as a list to the variable '''content'''. We have previously created empty lists, color[], L[], a[], and b[]. The color name remains a string appended to '''colors[]'''. The '''L''' value is contained in the part of '''content[]''' which is 3rd from the end, the '''a''' value 2nd from the end, and '''b''' from the last item in '''contents'''. From the '''re''' module that was imported at the beginning of the script ('''re''' contains regex operations) we use the '''re.sub''' method to change the commas to periods, but of course this remains a string, so then we must convert each to a float value, which we append to the appropriate list.<br />
<br />
===Creating the Colors===<br />
This is one of the simplest parts of the script, accomplished by looping through our color data lists, then using this command:<br />
<syntaxhighlight lang=python><br />
scribus.defineColorLab(colors[index], float(L[index]), float(a[index]), float(b[index]))<br />
</syntaxhighlight><br />
===Now the Document===<br />
Once we have the colors, the next step is to go on to the display of the colors and information about them. It was desired that the document be A4 paper, with units in millimeters. Looping through the colors list creates the color patches:<br />
<syntaxhighlight lang=python><br />
newrectangle = scribus.createRect(xpos,ypos,22,12)<br />
scribus.setLineColor("None",newrectangle)<br />
scribus.setFillColor(colors[index], newrectangle)<br />
</syntaxhighlight><br />
The variables '''xpos''' and '''ypos''' begin at 25, 30, after which the array is formed mathematically, jumping 25 mm in the X direction to complete a row, and 35 mm in the Y direction to jump to the next row.<br />
<br />
Creating the associated label text frames is best done after each color patch is created, since we can use its '''xpos''', '''ypos''' values as a reference:<br />
<syntaxhighlight lang=python><br />
newtext = scribus.createText(xpos, ypos + 13.5, 22, 15)<br />
if (len(colors[index])<18):<br />
spacer = '\n'<br />
else:<br />
spacer = ''<br />
data = str(L[index]) + '\n' + str(a[index]) + '\n' + str(b[index])<br />
scribus.setText(colors[index]+spacer+'\n'+ data, newtext)<br />
</syntaxhighlight><br />
Notice this variable '''spacer'''. This was created because of the variability in the length of color names; some used only one line, some two, a few three, and rarely four. Trial and error came up with this scheme to use 18 characters as the decision point to add an extra newline character or not. It's imperfect, since a proportional font is used and also since line breaks depend on length of and spacing between parts of the name. This label size will take care of most situations, but occasionally the height was too small. The answer came from check for overflowing text:<br />
<syntaxhighlight lang=python><br />
overflow = scribus.textOverflows(newtext)<br />
if overflow == 1:<br />
scribus.sizeObject(22,20, newtext)<br />
</syntaxhighlight><br />
This needed to be done ''after'' the particular font and font size were set.<br />
<br />
===Working with Fonts and Styles===<br />
Early on in the development of this script, I had the idea of using styles. The main reason was that the user could change fonts as desired after the script ran much easier with styles, just as on the main canvas. Setting up styles is ''relatively'' straightforward, but does have some particulars about it.<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5)<br />
scribus.createParagraphStyle("keystyle",0,7.0,1,0,0,0,0,0,0,0,0,"keychar")<br />
</syntaxhighlight><br />
Notice that the process here is to first create a Character Style, where you assign a particular font and its size. Next you create a Paragraph Style using that Character Style. All of these settings in the Paragraph Style must have an entry if you are going to use the last one, the Character Style name. From left to right, the settings are: name for the style (string), linespacingmode (integer), linespacing (float), alignment (integer), left margin (float), gap before (float), first indent (float), haddropcap (binary integer), dropcaplines (integer), dropcapoffset (float), character style name (string).<br />
<br />
If you look at the labels in the image up higher on this page, you see I've used a bold font for the name, and regular or book style for the L, a, and b values. When I started out, I was only using one style for the entire label, and this is where I ran into a problem. On the main canvas, when you select a text frame, then select a Paragraph Style, it's applied to all the text in the frame. Unfortunately, on trying this in the script, only the last line received the assigned Paragraph Style, so it seemed that the newline character is a barrier to setting all the text. I even tried to deselect all objects, then select the frame, but this was of no help.<br />
<br />
The initial fall back plan was to assign a font to the frame, using '''setFont()''', then '''setFontSize''', clumsier, but it did work. Eventually I did find the solution, which came from selecting all the text of the frame, and to do this easily and repeatedly throughout the script I made a function, since there is no built-in command in Scribus to select all the text in a frame. '''selectText()''' requires you to specify a starting point and number of characters to select:<br />
<syntaxhighlight lang=python><br />
def SelectAllText(textframe):<br />
texlen = scribus.getTextLength(textframe)<br />
scribus.selectText(0,texlen,textframe)<br />
return<br />
</syntaxhighlight><br />
After this, I could then first apply the bold text style to the entire frame, then apply the book style to a subset:<br />
<syntaxhighlight lang=python><br />
datalen = len(data)<br />
scribus.selectText(textlen - datalen, datalen, newtext)<br />
scribus.setStyle('keyLabstyle', newtext)<br />
</syntaxhighlight><br />
The variable '''data''' is the entire string of the L, a, b values, including necessary newline characters, which must be considered when counting characters in a text frame.<br />
<br />
===The Challenge of Character Styles===<br />
Something I tried and ultimately failed at was to see if I could manage to set kerning for a character style. There is something called "tracking" in the specifications, but that apparently isn't it. In the meantime, if you are going try to set more variables for '''createCharStyle90''', this is a "legal" format:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,-5.00)<br />
</syntaxhighlight><br />
Just like '''createParagraphStyle()''', you have to fill in all these variables until you get to the last one you wish to set. Notice the first 2 are strings, the third is a floating point number, next a string, then a string, floating point, string, num, num, num, num, num, then float. This last one is called tracking, but has no apparent effect that I can see onscreen although it changes something called '''TXTULP''' in the saved SLA file. ''In retrospect, I think this is the value for underline offset &ndash; see below.''<br />
====Problem Solved!====<br />
Here is what '''''finally''''' worked:<br />
<syntaxhighlight lang=python><br />
scribus.createCharStyle("keychar", "DejaVu Sans Condensed Bold", 6.5,'','Black',1.0,'',0,0,0,0,0,0,0,0,0,1,1,-50)<br />
</syntaxhighlight><br />
It turns out that changing the tracking (kerning) is the 19th value for this command. It's also important to set the two preceding values correctly. These are respectively horizontal scaling and vertical scaling of the characters. We want to leave these alone, i.e., at the normal 100%, and the percentage is this value times 100. Weirder than this is that -50 is the setting to create a Kerning of -5.0% (!).<br />
<br />
===Special Characters===<br />
One of the things I wanted to do was to enter the special page number character on a Master Page I created for the script. When you edit a page on the canvas, it shows up as a red '#'. In a text file saved from Story Editor, it only showed up as '^^' though the color was purple. I asked one of the devs what it was, and he told me the decimal value was 30. To use this a script you would specify '''chr(30)'''.<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page ' + chr(30), textframe)<br />
</syntaxhighlight><br />
Later I found out that in hex it is '0x1e', so in Python you could alternatively say:<br />
<syntaxhighlight lang=python><br />
scribus.setText('Page \x1e', textframe)<br />
</syntaxhighlight></div>
Gpittman