#!/usr/local/bin/ruby
#
#
# ./beziertest.rb

require "ClibPDF"

x0 = 1.0; y0 = 1.0
x1 = 1.2; y1 = 1.5
x2 = 2.8; y2 = 2.2
x3 = 3.0; y3 = 1.2
fontsize = 12.0
markersize = 4.0


pdf = ClibPDF::PDF.open(0)
pdf.enableCompression(ClibPDF::YES)
pdf.init
pdf.pageInit(1, ClibPDF::PORTRAIT, ClibPDF::LETTER, ClibPDF::LETTER)
pdf.translate(0.0, 6.5)

pdf.setgray(0.0)
pdf.setlinewidth(1.5)
pdf.moveto(x0, y0)
pdf.curveto(x1, y1, x2, y2, x3, y3)
pdf.stroke

pdf.setdash("[2 3] 0")
pdf.setlinewidth(0.3)
pdf.moveto(x0, y0)
pdf.lineto(x1, y1)
pdf.moveto(x3, y3)
pdf.lineto(x2, y2)
pdf.stroke
pdf.nodash

pdf.marker(x1, y1, 0, markersize)
pdf.marker(x2, y2, 0, markersize)

pdf.setgrayFill(1.0)
pdf.marker(x0, y0, 3, markersize)
pdf.marker(x3, y3, 3, markersize)

pdf.setgrayFill(0.0)
pdf.beginText(0)
pdf.setFont("Helvetica-Oblique", "MacRomanEncoding", fontsize)
pdf.text(x0-0.15, y0-0.25, 0.0, "x0, y0")
pdf.text(x3-0.15, y3-0.25, 0.0, "x3, y3")
pdf.text(x1-0.15, y1+0.1, 0.0, "x1, y1")
pdf.text(x2-0.15, y2+0.1, 0.0, "x2, y2")
pdf.endText

x0 = 4.0; y0 = 1.0
x1 = 4.3; y1 = 2.2
x2 = 5.8; y2 = 0.7
x3 = 6.0; y3 = 1.7

pdf.setgray(0.0)
pdf.nodash
pdf.setlinewidth(1.5)
pdf.moveto(x0, y0)
pdf.curveto(x1, y1, x2, y2, x3, y3)
pdf.stroke

pdf.setdash("[2 3] 0")
pdf.setlinewidth(0.3)
pdf.moveto(x0, y0)
pdf.lineto(x1, y1)
pdf.moveto(x3, y3)
pdf.lineto(x2, y2)
pdf.stroke
pdf.nodash

pdf.marker(x1, y1, 0, markersize)
pdf.marker(x2, y2, 0, markersize)

pdf.setgrayFill(1.0)
pdf.marker(x0, y0, 3, markersize)
pdf.marker(x3, y3, 3, markersize)

pdf.setgrayFill(0.0)
pdf.beginText(0)
pdf.setFont("Helvetica-Oblique", "MacRomanEncoding", fontsize)
pdf.text(x0-0.15, y0-0.25, 0.0, "x0, y0")
pdf.text(x1-0.15, y1+0.1, 0.0, "x1, y1")
pdf.text(x2-0.15, y2-0.25, 0.0, "x2, y2")
pdf.text(x3-0.15, y3+0.1, 0.0, "x3, y3")
pdf.endText

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("beziertest.pdf")

pdf.close()
#pdf.launchPreview
