Scrambling Text: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(Created page with "{{Scripting Index}} I had a request to write a script that would take a text document with multiple frames and scramble its text. There was a desire to share the document rega...")
 
No edit summary
Line 1: Line 1:
{{Scripting Index}}
{{Scripting Index}}
I had a request to write a script that would take a text document with multiple frames and scramble its text. There was a desire to share the document regarding its layout, but not the actual content. While the text could have been replaced by lorem ipsum, this would have been time-consuming, and various styles would have to be recreated.
I had a request to write a script that would take a text document with multiple frames and scramble its text. There was a desire to share the document regarding its layout, but not the actual content. While the text could have been replaced by lorem ipsum, this would have been time-consuming, and various styles would have to be recreated.
Here is the initial version of this script, which scrambles the text in a selected frame, which must of course be a text frame. The logic begins with the way that '''Autoquote''' takes apart the content of a frame, character by character, but skipping over the characters you're not looking for, leaving everything else, including the markers for character styles, intact.
Here we wish to change all aphabetical characters, but leave numbers, punctuation, carriage returns, and so on unchanged. It uses the python module '''random''' to generate a new random small letter and capital letter each time a new alphabetical character is found, then modifies according to the case of the found letter. This isn't like a cryptographic code using some algorithm for the process, it's as random as the random module can generate, so this will not be reversible. This isn't exactly true – use Undo after running the script to see what I mean. Once to save the document and reopen, it's truly irreversible.
==replacetext.py==

Revision as of 00:32, 8 June 2014

This article is part of the Scripts series.

I had a request to write a script that would take a text document with multiple frames and scramble its text. There was a desire to share the document regarding its layout, but not the actual content. While the text could have been replaced by lorem ipsum, this would have been time-consuming, and various styles would have to be recreated.

Here is the initial version of this script, which scrambles the text in a selected frame, which must of course be a text frame. The logic begins with the way that Autoquote takes apart the content of a frame, character by character, but skipping over the characters you're not looking for, leaving everything else, including the markers for character styles, intact.

Here we wish to change all aphabetical characters, but leave numbers, punctuation, carriage returns, and so on unchanged. It uses the python module random to generate a new random small letter and capital letter each time a new alphabetical character is found, then modifies according to the case of the found letter. This isn't like a cryptographic code using some algorithm for the process, it's as random as the random module can generate, so this will not be reversible. This isn't exactly true – use Undo after running the script to see what I mean. Once to save the document and reopen, it's truly irreversible.

replacetext.py