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.
typesetting/pitfall/ptest/testrkt.rkt

90 lines
3.5 KiB
Racket

8 years ago
#lang br
#|
PDFDocument = require 'pdfkit'
tiger = require './tiger'
fs = require 'fs'
# Create a new PDFDocument
doc = new PDFDocument
doc.pipe fs.createWriteStream('out.pdf')
# Set some meta data
doc.info['Title'] = 'Test Document'
doc.info['Author'] = 'Devon Govett'
# Register a font name for use later
6 years ago
doc.register-font('Charter', 'charter.ttf')
8 years ago
# Set the font, draw some text, and embed an image
doc.font('Charter')
6 years ago
.font-size(25)
8 years ago
.text('Some text with an embedded font!', 100, 100)
6 years ago
.font-size(18)
8 years ago
.text('PNG and JPEG images:')
.image('test.png', 100, 160, width: 412)
.image('test.jpeg', 190, 400, height: 300)
# Add another page
6 years ago
doc.add-page()
6 years ago
.font-size(25)
8 years ago
.text 'Here is some vector graphics...', 100, 100
# Draw a triangle and a circle
doc.save()
6 years ago
.move-to(100, 150)
.line-to(100, 250)
.line-to(200, 250)
8 years ago
.fill("#FF3300")
doc.circle(280, 200, 50)
.fill("#6600FF")
doc.scale(0.6)
.translate(470, -380)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z') # render an SVG path
.fill('red', 'even-odd') # fill using the even-odd winding rule
.restore()
loremIpsum = '''
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl. Suspendisse rhoncus nisl posuere tortor tempus et dapibus elit porta. Cras leo neque, elementum a rhoncus ut, vestibulum non nibh. Phasellus pretium justo turpis. Etiam vulputate, odio vitae tincidunt ultricies, eros odio dapibus nisi, ut tincidunt lacus arcu eu elit. Aenean velit erat, vehicula eget lacinia ut, dignissim non tellus. Aliquam nec lacus mi, sed vestibulum nunc. Suspendisse potenti. Curabitur vitae sem turpis. Vestibulum sed neque eget dolor dapibus porttitor at sit amet sem. Fusce a turpis lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Mauris at ante tellus. Vestibulum a metus lectus. Praesent tempor purus a lacus blandit eget gravida ante hendrerit. Cras et eros metus. Sed commodo malesuada eros, vitae interdum augue semper quis. Fusce id magna nunc. Curabitur sollicitudin placerat semper. Cras et mi neque, a dignissim risus. Nulla venenatis porta lacus, vel rhoncus lectus tempor vitae. Duis sagittis venenatis rutrum. Curabitur tempor massa tortor.
'''
# Draw some text wrapped to 412 points wide
doc.text('And here is some wrapped text...', 100, 300)
.font('Charter', 13)
.moveDown() # move down 1 line
.text(loremIpsum, width: 412, align: 'justify', indent: 30, paragraphGap: 5)
# Add another page, and set the font back
6 years ago
doc.add-page()
8 years ago
.font('Charter', 25)
.text('Rendering some SVG paths...', 100, 100)
.translate(220, 300)
# Render each path that makes up the tiger image
for part in tiger
doc.save()
doc.path(part.path) # render an SVG path
if part['stroke-width']
6 years ago
doc.line-width part['stroke-width']
8 years ago
if part.fill isnt 'none' and part.stroke isnt 'none'
6 years ago
doc.fill-and-stroke(part.fill, part.stroke)
8 years ago
else
unless part.fill is 'none'
doc.fill(part.fill)
unless part.stroke is 'none'
doc.stroke(part.stroke)
doc.restore()
# Add some text with annotations
6 years ago
doc.add-page()
6 years ago
.fill-color("blue")
8 years ago
.text('Here is a link!', 100, 100, { link: 'http://google.com/', underline: true })
doc.end()
|#