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.

107 lines
3.3 KiB
Python

import re # libary to search and replace strings in the postscript file
from dictionary import font_index
from generate_postscript import generate_postscript
# function with three arguments
def weaver(previous_module, current_module, module):
patch1 = module[1]
patch2 = module[2]
patternFactor = int(module[3])
patchFactor = int(module[4])
patchworkFactor = int(module[5])
#replace a, b, c and d with characters I am using nowhere else
patch1 = patch1.replace("a", ("%"*patternFactor)) #
patch1 = patch1.replace("b", ("$"*patternFactor)) #≈
patch1 = patch1.replace("c", ("§"*patternFactor)) #≅
patch1 = patch1.replace("d", ("#"*patternFactor)) #≡
patch2 = patch2.replace("a", ("%"*patternFactor)) #
patch2 = patch2.replace("b", ("$"*patternFactor)) #≈
patch2 = patch2.replace("c", ("§"*patternFactor)) #≅
patch2 = patch2.replace("d", ("#"*patternFactor)) #≡
#print(patch1)
patchwork = ((patch1*patchFactor) + (patch2*patchFactor)) *patchworkFactor
text = ''
tmp_line = ''
charCount = 0
lineCount = 0
lineWidth = 15
#lineNum = 100 #################################################################################
for character in patchwork:
if len(tmp_line) < lineWidth:
tmp_line += character
if len(patchwork) == charCount+1:
text = text + tmp_line + "\n"
else:
tmp_line += character
text = text + tmp_line + "\n"
tmp_line = ''
lineCount += 1
if lineCount >= 10: #why cannot replace with lineNum?###################################
break
charCount += 1
#print(text)
#split the text into lines to place them separated
text = text.split("\n")
paragraph = ""
for row in text:
paragraph = paragraph + "(" + row + ") true charpath newline-weaver "
#replace the character that I am using nowhere else with the number code of the special characters I want to use in the generate_postscript
#the backsplash needs two escapes (one in the replace operation and one later in the generate_postscript when it is written to the file)
paragraph = paragraph.replace("%", ("\\\\176"*patternFactor)) #
paragraph = paragraph.replace("$", ("\\\\273"*patternFactor)) #≈
paragraph = paragraph.replace("§", ("\\\\100"*patternFactor)) #≅
paragraph = paragraph.replace("#", ("\\\\272"*patternFactor)) #≡
#print(paragraph)
script = """
newpath
% WEAVER
/Symbol
% fontname
36 selectfont
% fontsize in points, establishes the font as the current one
/x-weaver { 10 } def
% define x position
/y-weaver { 700 } def
% define y position
/lg-weaver { 16 } def
% define linespacing
/newline-weaver { y-weaver lg-weaver sub /y-weaver exch def x-weaver y-weaver moveto } def
% define newline (position of new line) by using subtracting linespacing (lg) from y position and define that as the new y position (exch-ange), finally move to x position and re-defined y position
x-weaver y-weaver moveto
% x and y coordinates in px (origin is the lower-left corner of the page)
"""+paragraph+"""
fill
% fill the text in parentheses
showpage
% print all on a page
"""
generate_postscript(previous_module, current_module, script) # call function