You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
import re # libary to search and replace strings in the postscript file
|
|
from dictionary import font_index
|
|
|
|
# function with two arguments
|
|
def future_relics(previous_module, module):
|
|
#text = input("Enter text:") # create input field for text input
|
|
text = "enter text here"
|
|
submit="0"
|
|
|
|
font = font_index[module[1]] # use font_index from dictionary to translate the fontname
|
|
|
|
fontsize = module[2] # sensor3
|
|
linewidth = module[3] # sensor2
|
|
x = module[4]
|
|
y = module[5] # sensor4
|
|
submit = module[6] # sensor 4, same the exact same value
|
|
|
|
|
|
script = """
|
|
|
|
newpath
|
|
|
|
/"""+font+"""
|
|
% fontname
|
|
|
|
"""+fontsize+""" selectfont
|
|
% fontsize in points, establishes the font as the current one
|
|
|
|
"""+x+""" """+y+""" moveto
|
|
% x and y coordinates in px (origin is the lower-left corner of the page)
|
|
|
|
("""+text+""") true charpath
|
|
% normally text works with "show", but to use the characters in the string as a path that can be stroked and filled use "true charpath"
|
|
|
|
gsave
|
|
% save the current path to apply stroke first and then go back to the saved path to apply fill (Both drawing commands destroy the current path)
|
|
|
|
"""+linewidth+""" setlinewidth
|
|
% linewidth for the outline of the text
|
|
|
|
stroke
|
|
% stroke (outline) the text in parentheses
|
|
|
|
showpage
|
|
% print all on a page
|
|
"""
|
|
|
|
if submit == "1": # sensor6
|
|
print("starting to write the ps-file")
|
|
if previous_module == "":
|
|
#input file
|
|
fileInput = open("empty.ps", "rt") # rt = read text mode
|
|
#output file to write the result to
|
|
fileOutput = open("future_relics.ps", "wt") # wt = write text mode
|
|
|
|
else:
|
|
#input file
|
|
fileInput = open(previous_module + ".ps", "rt") # rt = read text mode
|
|
#output file to write the result to
|
|
fileOutput = open("future_relics.ps", "wt") # wt = write text mode
|
|
|
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
|
# uses regular expressions library (re)
|
|
content = fileInput.read()
|
|
content = re.sub(r"showpage\n% print all on a page", (script), content)
|
|
|
|
# write the new text to the output file
|
|
fileOutput.write(content)
|
|
#close input and output files
|
|
fileInput.close()
|
|
fileOutput.close()
|