make a module

This commit is contained in:
Mara Karagianni 2021-12-08 14:56:42 +02:00
parent 5c0882156d
commit 5b507017a6
5 changed files with 187 additions and 671 deletions

View file

@ -1,297 +1,39 @@
#!/bin/python
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni May 2021
"""
import glob
import re
import sys import sys
import subprocess from zine_maker import Zine
from fpdf import FPDF
# ref https://pyfpdf.readthedocs.io/en/latest/
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font_size = 12
top_margin = 20
left_margin = 20
right_margin = 20
left_max_margin = 160
max_height = 190
left_x = 20
top_y = 30
cell_width = 110
cell_header_height = 16
cell_height = 6
# Image variables
img_x = 20
img_y = 80
img_len = 120
# file to get the text
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = "./notes_sample"
class Zine(FPDF): def make_colophon():
def add_new_signature(self, top_margin, left_margin, right_margin): # Variables
# create new page/signature text_font_size = 12
self.add_page()
self.set_margins(left_margin, top_margin, right_margin)
self.set_xy(left_margin, top_margin)
print('NEW SIGNATURE')
def move_to_page_right(self, top_margin, left_max_margin, right_margin): # set font for all text
print('*****') zine = Zine(orientation="P", unit="mm", format="A5")
print("BOTTOM OF LEFT PAGE, height is {}".format(self.get_y()))
print('*****')
self.set_margins(top_margin, left_max_margin, right_margin)
self.set_xy(left_max_margin, top_margin)
def position_img(self, img_filename, img_x, img_y, **kwargs): # cover font
img_size = subprocess.run( zine.add_font(
["identify", "-format", 'CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True)
"%[fx:w/72] by %[fx:h/72] inches", cover_font = 'CasaleNBP'
"./%s" % img_filename],
stdout=subprocess.PIPE, text=True)
img_height_inches = img_size.stdout.split(' ')[2] # text font
img_width_inches = img_size.stdout.split(' ')[0] zine.add_font(
img_height_mm = float(img_height_inches) * float(24.5) 'Kpalter', '',
img_width_mm = float(img_width_inches) * float(24.5) r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True)
text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size)
if kwargs: zine.colophon(inputfile)
max_height = kwargs["max_height"] zine.output(output)
left_margin = kwargs["left_margin"]
top_margin = kwargs["top_margin"]
if self.get_y() + img_height_mm >= max_height:
self.add_page()
self.set_xy(left_margin, top_margin)
img_y = top_margin
previous_y = self.get_y()
# center image
img_x = (150 - img_width_mm) / 2
self.image(img_filename, img_x, img_y, img_width_mm)
# move y at the bottom of the image
# TODO check if get_y() would do the same job
self.set_xy(self.get_x(), previous_y+img_height_mm)
def shuffle_chapters(self, pdfinput):
subprocess.run(
["pdfseparate", "./%s" % pdfinput, "./%02d_chapter.pdf"],
stdout=subprocess.PIPE, text=True)
pages = glob.glob("./*_chapter.pdf")
pages.sort()
print("CHAPTERS {}".format(pages))
shuffled_list = []
count = 0
while count < (len(pages))/2:
shuffled_list.append(pages[-(count+1)])
shuffled_list.append(pages[count])
count += 1
# reverse
if count != len(pages)/2:
shuffled_list.append(pages[count])
shuffled_list.append(pages[-(count+1)])
count += 1
return shuffled_list
def create_pages(self, filename, max_height, left_margin,
left_max_margin, top_margin, right_margin,
cell_width, cell_height, cell_header_height,
header_font, text_font):
chapter = 0
lines = open(filename).readlines()
print(filename)
# first page
print("FIRST PAGE")
self.set_margins(left_margin, top_margin,
right_margin)
self.set_xy(left_margin, top_margin)
self.add_page()
for line in lines:
if ">>" in line:
self.set_font(text_font, '', size=16)
self.cell(cell_width, cell_height, line,
0, ln=1, align='L')
self.set_font(text_font, '', size=text_font_size)
# check if we have an image
elif line.startswith("<img>"):
img_filename = line.split("<img>")[1]
kwargs = {
"max_height": max_height,
"left_margin": left_margin,
"top_margin": top_margin
}
self.position_img(
img_filename, self.get_x(), self.get_y(), **kwargs)
# check if we have a title
elif line.startswith("<h2>"):
line = re.sub('((<h2>)|(</h2>$))', '', line)
self.set_text_color(255, 0, 255)
self.set_font(text_font, size=22)
if self.get_y() > top_margin:
self.set_xy(left_margin, top_margin+9)
self.add_page()
self.cell(cell_width, cell_header_height, line,
0, ln=1, align='C')
left_x = self.get_x()
top_y = self.get_y()
self.dashed_line(
left_x, top_y, left_x+cell_width, top_y,
dash_length=3, space_length=3)
self.set_text_color(0, 0, 0)
self.set_font(text_font, size=text_font_size)
elif line.startswith("<b>"):
line = re.sub('((<b>)|(</b>$))', '', line)
self.set_font(text_font, '', size=18)
self.cell(cell_width, cell_height, line,
0, ln=1, align='L')
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("#"):
self.set_font('helvetica', 'B', size=9)
self.set_text_color(209, 17, 65)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
# go back to text font
self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("$") or line.startswith("(venv)"):
self.set_font('helvetica', 'B', size=9)
self.set_text_color(0, 30, 255)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
# go back to text font
self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("<conf>"):
#line = re.sub('(<conf>$)', '', line)
self.set_font('helvetica', 'B', size=9)
self.set_text_color(0,80,115)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
elif line.startswith("</conf>"):
#line = re.sub('(</conf>$)', '', line)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
self.set_font(text_font, '', text_font_size)
self.set_text_color(0, 0, 0)
elif "<index>" in line:
line = re.sub('(<index>$)', '', line)
self.set_font(text_font, '', size=18)
self.set_text_color(0, 0, 0)
self.set_text_color(41, 98, 255)
self.cell(cell_width/8, cell_height, line, 0, align='C')
elif "</index>" in line:
line = re.sub('(</index>$)', '', line)
self.set_font(text_font, '', size=text_font_size)
self.set_text_color(0, 0, 0)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
else:
# check if we need the following
variable_x = self.get_x()
self.multi_cell(cell_width, cell_height, line, 0, align='L')
self.set_xy(variable_x, self.get_y())
#self.footer()
def cover(self, title, cover_font, max_height):
col = 10
margin = 15
import random
self.set_margins(margin, margin, margin)
self.add_page()
for letter in title:
if self.get_y() >= max_height:
self.set_xy(margin+col, margin)
col += 40
size = random.randrange(30, 50, 15)
self.set_font(cover_font, '', size)
variable_x = margin+col
print("LETTER {}, POSITION Y {}".format(letter, self.get_y()))
print("VAR X {}".format(variable_x))
self.set_xy(variable_x, self.get_y())
self.cell(size, size, letter)
self.line(size, size, self.get_x(), self.get_y())
if(size % 2 == 0):
var = "DF"
#r = 138, 43, 226
R = random.randrange(30, 255, 40)
G = random.randrange(0, 55, 55)
B = random.randrange(0, 155, 50)
self.set_fill_color(R, G, 255)
else:
var = "D"
print(var)
self.rect(
float(self.get_x()), float(self.get_y()),
float(size/2), float(size*4), style = var)
self.ln(size/2)
def colophon(self, text):
lines = open(text, 'r').readlines()
top_margin = 20
margin = 25
self.add_font(
'CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf",
uni=True)
self.set_margins(margin, top_margin, margin)
size = 11
cover_font = 'CasaleNBP'
self.set_font(cover_font, '', size)
self.add_page()
for line in lines:
self.multi_cell(100, size, line, 0, align='C')
# def footer(self):
# # Go to 1.5 cm from bottom
# self.set_y(-15)
# # Select Arial italic 8
# #self.set_font('Arial', 'I', 8)
# self.set_text_color(0, 0, 0)
# self.set_font(text_font, '', size=text_font_size)
# # Print current and total page numbers
# self.cell(0, 10, '%s' % self.page_no(), 0, 0, 'C')
# set font for all text if __name__ == '__main__':
zine = Zine(orientation="P", unit="mm", format="A5") # input text and output pdf
if len(sys.argv) > 1:
if len(sys.argv) == 3:
output = sys.argv[2]
inputfile = sys.argv[1]
else:
inputfile = "./text/colophon.txt"
output = './covers/colophon.pdf'
# cover font make_colophon()
zine.add_font('CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True)
cover_font = 'CasaleNBP'
# text font
zine.add_font(
'Kpalter', '', r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True)
text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size)
zine.colophon("./colophon.txt")
zine.output("colophon.pdf")

326
cover.py
View file

@ -1,298 +1,52 @@
#!/bin/python
"""
A script for generating A5 size pdf zines
with a text-file input, under development,
GPL3 Licence, Mara Karagianni May 2021
"""
import glob
import re
import sys import sys
import subprocess from zine_maker import Zine
from fpdf import FPDF
# ref https://pyfpdf.readthedocs.io/en/latest/
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font_size = 12
top_margin = 20
left_margin = 20
right_margin = 20
left_max_margin = 160
max_height = 190
left_x = 20
top_y = 30
cell_width = 110
cell_header_height = 16
cell_height = 6
# Image variables
img_x = 20
img_y = 80
img_len = 120
# file to get the text
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = "./notes_sample"
class Zine(FPDF): def make_cover():
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font_size = 12
def add_new_signature(self, top_margin, left_margin, right_margin): top_margin = 20
# create new page/signature left_margin = 20
self.add_page() right_margin = 20
self.set_margins(left_margin, top_margin, right_margin) left_max_margin = 160
self.set_xy(left_margin, top_margin)
print('NEW SIGNATURE')
def move_to_page_right(self, top_margin, left_max_margin, right_margin): max_height = 190
print('*****') left_x = 20
print("BOTTOM OF LEFT PAGE, height is {}".format(self.get_y())) top_y = 30
print('*****') cell_width = 110
self.set_margins(top_margin, left_max_margin, right_margin) cell_header_height = 16
self.set_xy(left_max_margin, top_margin) cell_height = 6
def position_img(self, img_filename, img_x, img_y, **kwargs): # set font for all text
img_size = subprocess.run( zine = Zine(orientation="P", unit="mm", format="A5")
["identify", "-format",
"%[fx:w/72] by %[fx:h/72] inches",
"./%s" % img_filename],
stdout=subprocess.PIPE, text=True)
img_height_inches = img_size.stdout.split(' ')[2] # cover font
img_width_inches = img_size.stdout.split(' ')[0] zine.add_font('CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True)
img_height_mm = float(img_height_inches) * float(24.5) cover_font = 'CasaleNBP'
img_width_mm = float(img_width_inches) * float(24.5)
if kwargs: # text font
max_height = kwargs["max_height"] zine.add_font(
left_margin = kwargs["left_margin"] 'Kpalter', '', r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True)
top_margin = kwargs["top_margin"] text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size)
if self.get_y() + img_height_mm >= max_height: zine.cover("deconstruct mailman", cover_font, max_height=140)
self.add_page() # import random
self.set_xy(left_margin, top_margin) # zine.output("cover{}.pdf".format(random.randint(10, 20)))
img_y = top_margin zine.output(output)
previous_y = self.get_y()
# center image
img_x = (150 - img_width_mm) / 2
self.image(img_filename, img_x, img_y, img_width_mm)
# move y at the bottom of the image
# TODO check if get_y() would do the same job
self.set_xy(self.get_x(), previous_y+img_height_mm)
def shuffle_chapters(self, pdfinput):
subprocess.run(
["pdfseparate", "./%s" % pdfinput, "./%02d_chapter.pdf"],
stdout=subprocess.PIPE, text=True)
pages = glob.glob("./*_chapter.pdf")
pages.sort()
print("CHAPTERS {}".format(pages))
shuffled_list = []
count = 0
while count < (len(pages))/2:
shuffled_list.append(pages[-(count+1)])
shuffled_list.append(pages[count])
count += 1
# reverse
if count != len(pages)/2:
shuffled_list.append(pages[count])
shuffled_list.append(pages[-(count+1)])
count += 1
return shuffled_list
def create_pages(self, filename, max_height, left_margin,
left_max_margin, top_margin, right_margin,
cell_width, cell_height, cell_header_height,
header_font, text_font):
chapter = 0
lines = open(filename).readlines()
print(filename)
# first page
print("FIRST PAGE")
self.set_margins(left_margin, top_margin,
right_margin)
self.set_xy(left_margin, top_margin)
self.add_page()
for line in lines:
if ">>" in line:
self.set_font(text_font, '', size=16)
self.cell(cell_width, cell_height, line,
0, ln=1, align='L')
self.set_font(text_font, '', size=text_font_size)
# check if we have an image
elif line.startswith("<img>"):
img_filename = line.split("<img>")[1]
kwargs = {
"max_height": max_height,
"left_margin": left_margin,
"top_margin": top_margin
}
self.position_img(
img_filename, self.get_x(), self.get_y(), **kwargs)
# check if we have a title
elif line.startswith("<h2>"):
line = re.sub('((<h2>)|(</h2>$))', '', line)
self.set_text_color(255, 0, 255)
self.set_font(text_font, size=22)
if self.get_y() > top_margin:
self.set_xy(left_margin, top_margin+9)
self.add_page()
self.cell(cell_width, cell_header_height, line,
0, ln=1, align='C')
left_x = self.get_x()
top_y = self.get_y()
self.dashed_line(
left_x, top_y, left_x+cell_width, top_y,
dash_length=3, space_length=3)
self.set_text_color(0, 0, 0)
self.set_font(text_font, size=text_font_size)
elif line.startswith("<b>"):
line = re.sub('((<b>)|(</b>$))', '', line)
self.set_font(text_font, '', size=18)
self.cell(cell_width, cell_height, line,
0, ln=1, align='L')
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("#"):
self.set_font('helvetica', 'B', size=9)
self.set_text_color(209, 17, 65)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
# go back to text font
self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("$") or line.startswith("(venv)"):
self.set_font('helvetica', 'B', size=9)
self.set_text_color(0, 30, 255)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
# go back to text font
self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("<conf>"):
#line = re.sub('(<conf>$)', '', line)
self.set_font('helvetica', 'B', size=9)
self.set_text_color(0,80,115)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
elif line.startswith("</conf>"):
#line = re.sub('(</conf>$)', '', line)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
self.set_font(text_font, '', text_font_size)
self.set_text_color(0, 0, 0)
elif "<index>" in line:
line = re.sub('(<index>$)', '', line)
self.set_font(text_font, '', size=18)
self.set_text_color(0, 0, 0)
self.set_text_color(41, 98, 255)
self.cell(cell_width/8, cell_height, line, 0, align='C')
elif "</index>" in line:
line = re.sub('(</index>$)', '', line)
self.set_font(text_font, '', size=text_font_size)
self.set_text_color(0, 0, 0)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
else:
# check if we need the following
variable_x = self.get_x()
self.multi_cell(cell_width, cell_height, line, 0, align='L')
self.set_xy(variable_x, self.get_y())
#self.footer()
def cover(self, title, cover_font, max_height):
col = 10
margin = 15
import random
self.set_margins(margin, margin, margin)
self.add_page()
for letter in title:
if self.get_y() >= max_height:
self.set_xy(margin+col, margin)
col += 40
size = random.randrange(30, 50, 15)
self.set_font(cover_font, '', size)
variable_x = margin+col
print("LETTER {}, POSITION Y {}".format(letter, self.get_y()))
print("VAR X {}".format(variable_x))
self.set_xy(variable_x, self.get_y())
self.cell(size, size, letter)
self.line(size, size, self.get_x(), self.get_y())
if(size % 2 == 0):
var = "DF"
#r = 138, 43, 226
R = random.randrange(0, 255, 40)
G = random.randrange(25, 255, 50)
B = random.randrange(0, 155, 50)
self.set_fill_color(R, G, 255)
else:
var = "D"
print(var)
self.rect(
float(self.get_x()), float(self.get_y()),
float(size/2), float(size*4), style = var)
self.ln(size/2)
def colophon(self, text):
lines = open(text, 'r').readlines()
top_margin = 20
margin = 25
self.add_font(
'CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf",
uni=True)
self.set_margins(margin, top_margin, margin)
size = 11
cover_font = 'CasaleNBP'
self.set_font(cover_font, '', size)
self.add_page()
for line in lines:
self.multi_cell(100, size, line, 0, align='C')
# def footer(self):
# # Go to 1.5 cm from bottom
# self.set_y(-15)
# # Select Arial italic 8
# #self.set_font('Arial', 'I', 8)
# self.set_text_color(0, 0, 0)
# self.set_font(text_font, '', size=text_font_size)
# # Print current and total page numbers
# self.cell(0, 10, '%s' % self.page_no(), 0, 0, 'C')
# set font for all text if __name__ == '__main__':
zine = Zine(orientation="P", unit="mm", format="A5") # input text and output pdf
if len(sys.argv) > 1:
if len(sys.argv) == 3:
output = sys.argv[2]
inputfile = sys.argv[1]
else:
inputfile = "./text/cover.txt"
output = './covers/cover.pdf'
# cover font make_cover()
zine.add_font('CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True)
cover_font = 'CasaleNBP'
# text font
zine.add_font(
'Kpalter', '', r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True)
text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size)
zine.cover("deconstruct mailman", cover_font, max_height=140)
import random
zine.output("cover{}.pdf".format(random.randint(10, 20)))

63
doc_pdf.py Normal file
View file

@ -0,0 +1,63 @@
import sys
from zine_maker import Zine
def make():
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font_size = 11
top_margin = 20
left_margin = 20
right_margin = 20
left_max_margin = 160
max_height = 190
left_x = 20
top_y = 30
cell_width = 110
cell_header_height = 16
cell_height = 6
# Image variables
# img_x = 20
# img_y = 80
# img_len = 120
# set font for all text
zine = Zine(orientation="P", unit="mm", format="A5")
# cover font
zine.add_font(
'CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True
)
cover_font = 'CasaleNBP'
# text font
zine.add_font(
'Kpalter', '',
r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True
)
text_font = 'Helvetica'
zine.set_font(text_font, '', size=text_font_size)
zine.create_pages(inputfile, max_height, left_margin,
left_max_margin, top_margin, right_margin,
cell_width, cell_height, cell_header_height,
header_font, text_font, text_font_size)
zine.output(output)
if __name__ == '__main__':
# input text and output pdf
if len(sys.argv) > 1:
if len(sys.argv) == 3:
output = sys.argv[2]
inputfile = sys.argv[1]
else:
inputfile = "./text/notes_sample"
output = './finals/test.pdf'
make()

View file

@ -33,12 +33,6 @@ img_x = 20
img_y = 80 img_y = 80
img_len = 120 img_len = 120
# file to get the text
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = "./notes_sample"
class Zine(FPDF): class Zine(FPDF):
@ -280,6 +274,16 @@ class Zine(FPDF):
self.cell(0, 10, '%s' % self.page_no(), 0, 0, 'C') self.cell(0, 10, '%s' % self.page_no(), 0, 0, 'C')
# file to get the text
if len(sys.argv) > 1:
if len(sys.argv) == 3:
output = sys.argv[2]
filename = sys.argv[1]
else:
filename = "./finals/test.pdf"
output = './finals/trial.pdf'
# set font for all text # set font for all text
zine = Zine(orientation="P", unit="mm", format="A5") zine = Zine(orientation="P", unit="mm", format="A5")
@ -293,6 +297,5 @@ zine.add_font(
text_font = 'Kpalter' text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size) zine.set_font(text_font, '', size=text_font_size)
pdf = './finals/aug_trial.pdf' chapter_list = zine.shuffle_chapters(filename)
chapter_list = zine.shuffle_chapters(pdf) subprocess.Popen(["pdfunite"] + chapter_list + [output])
subprocess.Popen(["pdfunite"] + chapter_list + ["final_aug.pdf"])

View file

@ -1,44 +1,15 @@
#!/bin/python #!/bin/python
""" """
A script for generating A5 size pdf zines A module for generating A5 size pdf zines
with a text-file input, under development, based on pyFPDF.
GPL3 Licence, Mara Karagianni May 2021 GPL3 License, Mara Karagianni May 2021
""" """
import glob import glob
import re import re
import sys
import subprocess import subprocess
from fpdf import FPDF from fpdf import FPDF
# ref https://pyfpdf.readthedocs.io/en/latest/ # ref https://pyfpdf.readthedocs.io/en/latest/
# Variables
header_font = 'helvetica'
header_font_size = 14
text_font_size = 12
top_margin = 20
left_margin = 20
right_margin = 20
left_max_margin = 160
max_height = 190
left_x = 20
top_y = 30
cell_width = 110
cell_header_height = 16
cell_height = 6
# Image variables
img_x = 20
img_y = 80
img_len = 120
# file to get the text
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = "./notes_sample"
class Zine(FPDF): class Zine(FPDF):
@ -58,9 +29,8 @@ class Zine(FPDF):
def position_img(self, img_filename, img_x, img_y, **kwargs): def position_img(self, img_filename, img_x, img_y, **kwargs):
img_size = subprocess.run( img_size = subprocess.run(
["identify", "-format", ["identify", "-format", "%[fx:w/72] by %[fx:h/72] inches",
"%[fx:w/72] by %[fx:h/72] inches", "%s" % img_filename],
"./%s" % img_filename],
stdout=subprocess.PIPE, text=True) stdout=subprocess.PIPE, text=True)
img_height_inches = img_size.stdout.split(' ')[2] img_height_inches = img_size.stdout.split(' ')[2]
@ -108,17 +78,21 @@ class Zine(FPDF):
return shuffled_list return shuffled_list
def create_pages(self, filename, max_height, left_margin, def create_pages(self, filename, max_height, left_margin,
left_max_margin, top_margin, right_margin, left_max_margin, top_margin, right_margin, *args):
cell_width, cell_height, cell_header_height, if args:
header_font, text_font): cell_width = args[0]
chapter = 0 cell_height = args[1]
cell_header_height = args[2]
header_font = args[3]
text_font = args[4]
text_font_size = args[5]
lines = open(filename).readlines() lines = open(filename).readlines()
print(filename) print(filename)
# first page # first page
print("FIRST PAGE") print("FIRST PAGE")
self.set_margins(left_margin, top_margin, self.set_margins(left_margin, top_margin, right_margin)
right_margin)
self.set_xy(left_margin, top_margin) self.set_xy(left_margin, top_margin)
self.add_page() self.add_page()
@ -144,8 +118,9 @@ class Zine(FPDF):
# check if we have a title # check if we have a title
elif line.startswith("<h2>"): elif line.startswith("<h2>"):
line = re.sub('((<h2>)|(</h2>$))', '', line) line = re.sub('((<h2>)|(</h2>$))', '', line)
self.set_text_color(255, 0, 255) self.set_text_color(130, 50, 250)
self.set_font(text_font, size=22) # self.set_text_color(255, 0, 255)
self.set_font(header_font, size=22)
if self.get_y() > top_margin: if self.get_y() > top_margin:
self.set_xy(left_margin, top_margin+9) self.set_xy(left_margin, top_margin+9)
self.add_page() self.add_page()
@ -159,11 +134,18 @@ class Zine(FPDF):
self.set_text_color(0, 0, 0) self.set_text_color(0, 0, 0)
self.set_font(text_font, size=text_font_size) self.set_font(text_font, size=text_font_size)
elif line.startswith("<i>"):
line = re.sub('((<i>)|(</i>$))', '', line)
self.set_font('helvetica', 'I', size=19)
self.multi_cell(cell_width, cell_height, line,
0, align='L')
self.set_font(text_font, '', size=text_font_size)
elif line.startswith("<b>"): elif line.startswith("<b>"):
line = re.sub('((<b>)|(</b>$))', '', line) line = re.sub('((<b>)|(</b>$))', '', line)
self.set_font(text_font, '', size=18) self.set_font('helvetica', 'B', size=13)
self.cell(cell_width, cell_height, line, self.cell(cell_width, cell_height, line,
0, ln=1, align='L') 0, ln=1, align='C')
self.set_font(text_font, '', size=text_font_size) self.set_font(text_font, '', size=text_font_size)
elif line.startswith("#"): elif line.startswith("#"):
@ -185,14 +167,14 @@ class Zine(FPDF):
self.set_text_color(0, 0, 0) self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size) self.set_font(text_font, '', size=text_font_size)
elif line.startswith("<conf>"): elif line.startswith("<quote>"):
#line = re.sub('(<conf>$)', '', line) line = re.sub('(<quote>$)', '', line)
self.set_font('helvetica', 'B', size=9) self.set_font(text_font, '', size=13)
self.set_text_color(0,80,115) self.set_text_color(0, 80, 115)
self.multi_cell(cell_width, cell_height, line, self.multi_cell(cell_width, cell_height, line,
0, align='L') 0, align='C')
elif line.startswith("</conf>"): elif line.startswith("</quote>"):
#line = re.sub('(</conf>$)', '', line) line = re.sub('(</quote>$)', '', line)
self.multi_cell(cell_width, cell_height, line, self.multi_cell(cell_width, cell_height, line,
0, align='L') 0, align='L')
self.set_font(text_font, '', text_font_size) self.set_font(text_font, '', text_font_size)
@ -218,7 +200,7 @@ class Zine(FPDF):
self.multi_cell(cell_width, cell_height, line, 0, align='L') self.multi_cell(cell_width, cell_height, line, 0, align='L')
self.set_xy(variable_x, self.get_y()) self.set_xy(variable_x, self.get_y())
self.footer() # self.footer()
def cover(self, title, cover_font, max_height): def cover(self, title, cover_font, max_height):
col = 10 col = 10
@ -241,17 +223,17 @@ class Zine(FPDF):
self.line(size, size, self.get_x(), self.get_y()) self.line(size, size, self.get_x(), self.get_y())
if(size % 2 == 0): if(size % 2 == 0):
var = "DF" var = "DF"
#r = 138, 43, 226 # r = 138, 43, 226
R = random.randrange(30, 255, 40) R = random.randrange(30, 255, 40)
G = random.randrange(0, 55, 55) G = random.randrange(0, 55, 55)
B = random.randrange(0, 155, 50) B = random.randrange(0, 155, 50)
self.set_fill_color(R, G, 255) self.set_fill_color(R, G, B)
else: else:
var = "D" var = "D"
print(var) print(var)
self.rect( self.rect(
float(self.get_x()), float(self.get_y()), float(self.get_x()), float(self.get_y()),
float(size/2), float(size*4), style = var) float(size/2), float(size*4), style=var)
self.ln(size/2) self.ln(size/2)
def colophon(self, text): def colophon(self, text):
@ -270,39 +252,11 @@ class Zine(FPDF):
self.multi_cell(100, size, line, 0, align='C') self.multi_cell(100, size, line, 0, align='C')
def footer(self): def footer(self):
text_font = 'Helvetica'
# Go to 1.5 cm from bottom # Go to 1.5 cm from bottom
self.set_y(-15) self.set_y(-12)
# Select Arial italic 8
#self.set_font('Arial', 'I', 8)
self.set_text_color(0, 0, 0) self.set_text_color(0, 0, 0)
self.set_font(text_font, '', size=text_font_size) self.set_font(text_font, '', size=7)
# Print current and total page numbers # Print current page number
self.cell(0, 10, '%s' % self.page_no(), 0, 0, 'C') # self.cell(0, 7, '%s' % self.page_no(), 0, 0, 'C')
self.cell(0, 7, '%s' % self.page_no(), 0, 0, 'C')
# set font for all text
zine = Zine(orientation="P", unit="mm", format="A5")
# cover font
zine.add_font('CasaleNBP', '', r"/home/mara/.fonts/CasaletwoNbp-Bp4V.ttf", uni=True)
cover_font = 'CasaleNBP'
# text font
zine.add_font(
'Kpalter', '', r"/home/mara/.fonts/KpProgrammerAlternatesNbp-Zg1q.ttf", uni=True)
text_font = 'Kpalter'
zine.set_font(text_font, '', size=text_font_size)
zine.create_pages(filename, max_height, left_margin, left_max_margin,
top_margin, right_margin, cell_width,
cell_height, cell_header_height, header_font, text_font)
pdf = './finals/aug_trial1.pdf'
zine.output(pdf)
#chapter_list = zine.shuffle_chapters(pdf)
#print(chapter_list)
#subprocess.Popen(["pdfunite"] + chapter_list + ["final_aug.pdf"])
#zine.cover("deconstruct mailman", cover_font, max_height=140)
#zine.output("cover.pdf")
#zine.colophon("./colophon.txt")
#zine.output("colophon.pdf")