def test2(): canvas = PDFCanvas('test2.pdf') drawString(canvas, "<alpha/>", 10, 10) # drawString(canvas, "&", 10, 10) drawString(canvas, "α", 10, 30) # drawString(canvas, "a", 10, 50, Font(face="symbol")) # drawString(canvas, "hello there!", 30, 90, angle= -90) # drawString(canvas, "<b>goodbye!</b> <u>yall</u>", 100, 90, angle= 45) # drawString(canvas, "there is a <u>time</u> and a <b>place</b><super>2</super>", # 100, 90, angle= -75) canvas.flush()
def test1(): canvas = PDFCanvas('test1.pdf') drawString(canvas, "<u><b>hello there</b></u><super>hi</super>", 10, 20) drawString(canvas, "hello!", 10, 40) print("'hello!' width = ", stringWidth(canvas, "hello!")) print("'hello!' SPING width = ", canvas.stringWidth("hello!")) drawString(canvas, "<b>hello!</b> goodbye", 10, 60) print("'<b>hello!</b> goodbye' width = ", stringWidth(canvas, "<b>hello!</b> goodbye")) drawString(canvas, "hello!", 10, 80, Font(bold=1)) print("'hello!' Font(bold=1) SPING width = ", canvas.stringWidth("hello!", Font(bold=1))) drawString(canvas, " goodbye", 10, 100) print("' goodbye' SPING width = ", canvas.stringWidth(" goodbye")) canvas.flush()
def stringformatTest(): # change the following line only to try a different SPING backend canvas = PDFCanvas('bigtest1.pdf') ################################################### testing drawString tags # < b > < /b > - bold # < i > < /i > - italics # < u > < /u > - underline # < super > < /super > - superscript # < sub > < /sub > - subscript x = 10 y = canvas.defaultFont.size * 1.5 ##### try out each possible tags and all combos (x, y) = allTagCombos(canvas, x, y) ##### now try various fonts (x, y) = allTagCombos(canvas, x, y + 30, Font(face="serif")) (x, y) = allTagCombos(canvas, x, y + 30, Font(face="monospaced")) # what about rotated (x, y) = allTagCombos(canvas, x, y + 30, Font(face="serif"), angle=-30) ##### now try a couple of different font sizes (x, y) = allTagCombos(canvas, x, y + 30, Font(size=16)) (x, y) = allTagCombos(canvas, x, y + 30, Font(size=9)) ##### now try a different default style setting (x, y) = allTagCombos(canvas, x, y + 30, Font(underline=1)) ##### now try a combo of the above 4 and a different color (x, y) = allTagCombos(canvas, x, y + 30, color=red) ################################################### testing stringWidth tags sfwidth = stringWidth( canvas, "<b><sub>bold+sub</sub></b> hello <u><super>underline+super</super></u>" ) # break down the various string widths print('sw("<b><sub>bold+sub</sub></b>") = ', stringWidth(canvas, "<b><sub>bold+sub</sub></b>")) print('sw(" hello ") = ', stringWidth(canvas, " hello ")) print('sw("<u><super>underline+super</super></u>") = ', stringWidth(canvas, "<u><super>underline+super</super></u>")) pwidth1 = canvas.stringWidth( "bold+sub", Font(size=canvas.defaultFont.size - sizedelta, bold=1)) print("pwidth1 = ", pwidth1) pwidth2 = canvas.stringWidth(" hello ") print("pwidth2 = ", pwidth2) pwidth3 = canvas.stringWidth( "underline+super", Font(size=canvas.defaultFont.size - sizedelta, underline=1)) print("pwidth3 = ", pwidth3) # these should be the same print("sfwidth = ", sfwidth, " pwidth = ", pwidth1 + pwidth2 + pwidth3) ################################################### testing greek characters # looks better in a larger font canvas = PDFCanvas('bigtest2.pdf') x = 10 y = canvas.defaultFont.size * 1.5 drawString(canvas, "α β <chi/> Δ <delta/>", x, y, Font(size=16), color=blue) print("line starting with alpha should be font size 16") y = y + 30 drawString(canvas, "ϵ η Γ <gamma/>", x, y, color=green) y = y + 30 drawString(canvas, "ι κ Λ <lambda/>", x, y, color=blue) y = y + 30 drawString(canvas, "<u>μ</u> ν <b>Ω</b> <omega/>", x, y, color=green) print("mu should be underlined, Omega should be big and bold") y = y + 30 drawString(canvas, "ο Φ φ <phiv/>", x, y, color=blue) y = y + 30 drawString(canvas, "Π π ϖ <Psi/> ψ ρ", x, y, color=green) y = y + 30 drawString(canvas, "<u>Σ σ ς <tau/></u>", x, y, color=blue) print("line starting with sigma should be completely underlined") y = y + 30 drawString(canvas, "Θ θ ϑ <Xi/> ξ ζ", x, y, color=green) y = y + 30 drawString(canvas, "That's αll <u>folks</u><super>ω</super>", x, y) canvas.flush()
) lines.append("specified in MathML") print(""" This is an example using formatted strings. It renders its output to a portable document file called "formatted-strings.pdf" and a postscript file called "formatted-strings.ps" for viewing with Acrobat Reader or for printing to a postscript printer. """) import sping.stringformat from sping.PDF import PDFCanvas from sping.PS import PSCanvas # Do PDF first canvas = PDFCanvas(size=(350, 200), name="formatted-strings.pdf") y = 20 for line in lines: sping.stringformat.drawString(canvas, line, 10, y) y = y + 20 canvas.flush() canvas.save() # Now do postscript canvas = PSCanvas(size=(350, 200), name="formatted-strings.ps") y = 20 for line in lines: sping.stringformat.drawString(canvas, line, 10, y)