Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Port PDF generation to reportlab #59

Merged
merged 24 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b1cc1b0
Create a reportlab canvas without a file name
janopae Mar 12, 2023
7611aa0
Generate broken PDFs through reportlab by passing PDF instructions th…
janopae Mar 12, 2023
4a56b85
Remove manual xref-Table-generation
janopae Mar 12, 2023
740167c
Fix PDF version in reportlab
janopae Mar 12, 2023
2667f74
Port table of contents/"Outline" to reportlab
janopae Mar 12, 2023
3849d43
Port rendering of pages to reportlab
janopae Mar 12, 2023
b234f93
Port setting PDF information/metadata to reportlab
janopae Mar 12, 2023
c934be2
Pass reportlabs canvas to PDFDrawOp
janopae Mar 12, 2023
78cc336
Port PDFQuarterCircleOp to reportlab canvas
janopae Mar 12, 2023
d54d906
Port PDFArbitraryOp to reportlab canvas
janopae Mar 12, 2023
763b51e
Port PDFRectOp to reportlab canvas
janopae Mar 12, 2023
474cda4
Port PDFLineOp to reportlab canvas
janopae Mar 12, 2023
dd08568
Port PDFTextOp to reportlab canvas
janopae Mar 13, 2023
b71f28d
Remove unnecessary escaping
janopae Mar 13, 2023
be69199
Remove output-string parameter from PDFDrawOp
janopae Mar 13, 2023
7ffc986
Move table of contents bookmark rendering to PDFTextOp
janopae Mar 13, 2023
f703f83
Inline variable
janopae Mar 13, 2023
ee8dc43
Don't set Helvetica as BaseFont
janopae Mar 13, 2023
f4651ea
Merge branch 'main' into port-pdf-generation-to-reportlab
janopae Mar 26, 2023
290c4fd
Improve error message when font can't be loaded
janopae Apr 7, 2023
ec0a481
I know this works
janopae Sep 17, 2023
1200ac3
Fall back to default font when user has set font name without font file
janopae Sep 17, 2023
23bf453
Adjust configuration dialogue to custom fonts without files being for…
janopae Sep 17, 2023
f5f089d
Merge branch 'main' into port-pdf-generation-to-reportlab
janopae Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions doc/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1396,24 +1396,16 @@
Bold-Italic).</para>

<para>Each font setting has two parts: a 'Name' field and a 'File'
field. The 'Name' field is the Postscript name of the font and is
used by the PDF viewer application to recognize the font to use.
Some examples of the names that would go here are 'AndaleMono',
'CourierNewPSMT', and 'BitstreamVeraSansMono-Roman'. These names
are, in general, impossible for human beings to know for arbitrary
fonts. See the next paragraphs for ways around this.</para>
field. The 'Name' field is the internal Postscript name of the font and
is used by the PDF viewer application to recognize the font to use.
</para>

<para>The 'File' field is the filename of the TrueType font to
use. If you fill in this field, the font file is embedded in the
generated PDF files. If you leave this field empty but fill in the
'Name' field, the font file is not embedded in the PDF file, just
the 'Name' reference is used to indicate what font the PDF viewer
application should use.</para>

<para>There are many factors affecting whether you should embed a
font or not. Embedding a font makes it much more likely that the
PDF file will display properly on other people's computers and/or
print properly. However, it will also increase the size of the PDF
generated PDF files.
</para>

<para>Embedding a font will increase the size of the PDF
files drastically, and not all fonts allow embedding in their
license terms.</para>

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
setuptools
wxPython
lxml
reportlab
pytest>=7.0
16 changes: 12 additions & 4 deletions src/cfgdlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,10 +1401,8 @@ def __init__(self, parent, id, cfg):
"Leave all the fields empty to use the default PDF Courier\n"
"fonts. This is highly recommended.\n"
"\n"
"Otherwise, fill in the font name (e.g. AndaleMono) to use\n"
"the specified TrueType font. If you want to embed the font\n"
"in the generated PDF files, fill in the font filename as well.\n"
"\n"
"Otherwise, fill in the the font filename to use\n"
"the specified TrueType font. \n"
"See the manual for the full details.\n"))

hsizer = wx.BoxSizer(wx.HORIZONTAL)
Expand Down Expand Up @@ -1449,12 +1447,22 @@ def __init__(self, parent, id, cfg):

# check that all embedded TrueType fonts are OK
def checkForErrors(self):
userHasSetFontNameWithoutFile = False

for pfi in self.cfg.getPDFFontIds():
pf = self.cfg.getPDFFont(pfi)

if pf.name and not pf.filename:
userHasSetFontNameWithoutFile = True

if pf.filename:
self.getFontPostscriptName(pf.filename)

if userHasSetFontNameWithoutFile:
wx.MessageBox(
'You need to select a file when specifying a custom font. Select a file or remove the font name you provided.',
'Error', wx.OK, cfgFrame)

def addEntry(self, name, descr, parent, sizer):
sizer.Add(wx.StaticText(parent, -1, descr), 0,
wx.ALIGN_CENTER_VERTICAL)
Expand Down
2 changes: 0 additions & 2 deletions src/characterreport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import AnyStr

import misc
import pdf
import pml
Expand Down
2 changes: 1 addition & 1 deletion src/dialoguechart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, AnyStr
from typing import List

import gutil
import misc
Expand Down
7 changes: 4 additions & 3 deletions src/gutil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import AnyStr

import config
from error import MiscError,TrelbyError
import misc
Expand Down Expand Up @@ -84,7 +82,10 @@ def showTempPDF(pdfData: bytes, cfgGl: 'config.ConfigGlobal', mainFrame: wx.TopL
suffix = ".pdf")

try:
os.write(fd, pdfData)
if isinstance(pdfData, str):
os.write(fd, pdfData)
else:
os.write(fd, pdfData)
finally:
os.close(fd)

Expand Down
2 changes: 0 additions & 2 deletions src/locationreport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import AnyStr

import misc
import pdf
import pml
Expand Down
Loading
Loading