示例#1
0
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()
示例#2
0
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()
示例#3
0
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,"&alpha; &beta; <chi/> &Delta; <delta/>",x,y, Font(size=16), color = blue)
	print "line starting with alpha should be font size 16"	
	y = y+30
	drawString(canvas,"&epsiv; &eta; &Gamma; <gamma/>",x,y, color = green)	
	y = y+30
	drawString(canvas,"&iota; &kappa; &Lambda; <lambda/>",x,y, color = blue)	
	y = y+30
	drawString(canvas,"<u>&mu;</u> &nu; <b>&Omega;</b> <omega/>",x,y, color = green)	
	print "mu should be underlined, Omega should be big and bold"
	y = y+30
	drawString(canvas,"&omicron; &Phi; &phi; <phiv/>",x,y, color = blue)	
	y = y+30
	drawString(canvas,"&Pi; &pi; &piv; <Psi/> &psi; &rho;",x,y, color = green)	
	y = y+30
	drawString(canvas,"<u>&Sigma; &sigma; &sigmav; <tau/></u>",x,y, color = blue)	
	print "line starting with sigma should be completely underlined"
	y = y+30
	drawString(canvas,"&Theta; &theta; &thetav; <Xi/> &xi; &zeta;",x,y, color = green)	
	y= y+30
	drawString(canvas,"That's &alpha;ll <u>folks</u><super>&omega;</super>",x,y)
	
	canvas.flush()
示例#4
0
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,
               "&alpha; &beta; <chi/> &Delta; <delta/>",
               x,
               y,
               Font(size=16),
               color=blue)
    print("line starting with alpha should be font size 16")
    y = y + 30
    drawString(canvas, "&epsiv; &eta; &Gamma; <gamma/>", x, y, color=green)
    y = y + 30
    drawString(canvas, "&iota; &kappa; &Lambda; <lambda/>", x, y, color=blue)
    y = y + 30
    drawString(canvas,
               "<u>&mu;</u> &nu; <b>&Omega;</b> <omega/>",
               x,
               y,
               color=green)
    print("mu should be underlined, Omega should be big and bold")
    y = y + 30
    drawString(canvas, "&omicron; &Phi; &phi; <phiv/>", x, y, color=blue)
    y = y + 30
    drawString(canvas, "&Pi; &pi; &piv; <Psi/> &psi; &rho;", x, y, color=green)
    y = y + 30
    drawString(canvas,
               "<u>&Sigma; &sigma; &sigmav; <tau/></u>",
               x,
               y,
               color=blue)
    print("line starting with sigma should be completely underlined")
    y = y + 30
    drawString(canvas,
               "&Theta; &theta; &thetav; <Xi/> &xi; &zeta;",
               x,
               y,
               color=green)
    y = y + 30
    drawString(canvas, "That's &alpha;ll <u>folks</u><super>&omega;</super>",
               x, y)

    canvas.flush()