'''
Copyright (C) 2010 Craig Marshall, craig9 [at] gmail.com
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-----------------------
This script finds all fonts in the current drawing that match the
specified find font, and replaces them with the specified replacement
font.
It can also replace all fonts indiscriminately, and list all fonts
currently being used.
'''
# standard library
import os
import sys
# local library
import inkex
import simplestyle
'{http://www.w3.org/2000/svg}text',
'{http://www.w3.org/2000/svg}flowRoot',
'{http://www.w3.org/2000/svg}flowPara',
'{http://www.w3.org/2000/svg}flowSpan']
'''
Sets the font attribute in the style attribute of node, using the
font name stored in new_font. If the style dict is open already,
it can be passed in, otherwise it will be optned anyway.
Returns a dirty boolean flag
'''
if not style:
if style:
for att in font_attributes:
return dirty
'''
Searches the relevant font attributes/styles of node for find, and
replaces them with replace.
Returns a dirty boolean flag
'''
if style:
for att in font_attributes:
return dirty
'''
Returns true if the tag in question is a "styled" element that
can hold text.
'''
'''
Returns true if the tag in question is an element that
can hold text.
'''
'''
Sugar coated way to get style dict from a node
'''
'''
Sugar coated way to set the style dict, for node
'''
'''
Given a node, returns a list containing all the fonts that
the node is using.
'''
fonts = []
if not s:
return fonts
for a in font_attributes:
if a in s:
return fonts
'''
Sends a message to the end user showing success of failure
of the font replacement
'''
if num == 0:
die(_('Couldn\'t find anything using that font, please ensure the spelling and spacing is correct.'))
'''
Tells the user which fonts were found, if any
'''
else:
else:
'''
Replaces all instances of one font with another
'''
'''
Recursive method for appending all text-type elements
to self.selected_items
'''
'''
Depending on the scope, returns all text elements, or all
selected text elements including nested children
'''
items = []
to_return = []
if scope == "selection_only":
self.selected_items = []
die(_("There was nothing selected"))
else:
return to_return
'''
Walks through nodes, replacing fonts as it goes according
to find and replace
'''
replacements = 0
replacements += 1
'''
Walks through nodes, setting fonts indiscriminately.
'''
replacements = 0
replacements += 1
'''
Walks through nodes, building a list of all fonts found, then
reports to the user with that list
'''
fonts_found = []
if not f in fonts_found:
if action == "find_replace":
die(_("Please enter a search string in the find box."));
die(_("Please enter a replacement font in the replace with box."));
elif action == "replace_all":
die(_("Please enter a replacement font in the replace all box."));
elif action == "list_only":
if __name__ == "__main__":
e = ReplaceFont()
e.affect()