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

require "ClibPDF"

dashpattern = [
  "[2  2] 0",
  "[4  4] 0",
  "[8  8] 0",
  "[8  8] 4",
  "[8  8] 8",
  "[12  4] 0",
  "[16  3  4  3] 0",
  "[13  3  2  3  2  3] 0",
  "[ ] 0"
]

Ndash = 9

ybump = 0.22
x = 1.0; y = 3.0
fontsize = 12.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);
for i in 0..Ndash-1
  pdf.setdash(dashpattern[i]);
  pdf.moveto(x, y)
  pdf.lineto(x+2.0, y)
  pdf.stroke
  y -= ybump
end
    
x = 3.1; y = 3.0 - fontsize * 0.3 / ClibPDF::INCH
pdf.beginText(0)
pdf.setFont("Helvetica", "MacRomanEncoding", fontsize)
for i in 0..Ndash-1
  pdf.text(x, y, 0.0, dashpattern[i])
  y -= ybump;
end
pdf.endText

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("dashtest.pdf")


pdf.close
#pdf.launchPreview
