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

require "ClibPDF"

NUMMARKERS = 11
XBUMP = 0.35

x = 1.0
y1 = 1.0
y2 = 1.0
y0 = 1.0
x0 = 1.0
markersize = 12.0
strbuf = ""

pdf = ClibPDF::PDF.open(0)
pdf.enableCompression(1)
pdf.setCreator("cc*PDF Demo Program: MarkerTest.rb")
pdf.init
pdf.pageInit(1, ClibPDF::PORTRAIT, ClibPDF::LETTER, ClibPDF::LETTER)
pdf.translate(0.0, 6.5)

pdf.setdash("[2 2] 0")
pdf.setlinewidth(0.12)
y1 = 1.3
pdf.moveto(1.1, y1)
pdf.lineto(6.9, y1)
y2 = 1.6
pdf.moveto(1.1, y2)
pdf.lineto(6.9, y2)

y0 = 1.45
for i in 0..NUMMARKERS + 4 -1
  if i < NUMMARKERS
	x = XBUMP * i.to_f + XBUMP + x0
  else
	x = XBUMP * i.to_f + XBUMP*2.0 + x0
  end
  pdf.moveto(x, y0+0.45)
  pdf.lineto(x, y0-0.45)
end
pdf.stroke
pdf.nodash

pdf.setgrayStroke(0.0)
pdf.setgrayFill(0.0)
for i in 0..NUMMARKERS + 4 - 1
  if i < NUMMARKERS
	x = XBUMP * i.to_f + XBUMP + x0
	pdf.marker(x, y1, i, markersize)
  else
	x = XBUMP * i.to_f + XBUMP*2 + x0
	pdf.pointer(x, y1, i-NUMMARKERS, markersize)
  end
end

pdf.setgrayStroke(0.0)
pdf.setgrayFill(1.0)
for i in 0..NUMMARKERS + 4 - 1
  if i < NUMMARKERS
	x = XBUMP * i.to_f + XBUMP + x0
	pdf.marker(x, y2, i, markersize)
  else
	x = XBUMP * i.to_f + XBUMP*2 + x0
	pdf.pointer(x, y2, i-NUMMARKERS, markersize)
  end
end

pdf.setgrayFill(0.0)
pdf.beginText(0)
pdf.setFont("Helvetica", "MacRomanEncoding", 12.0)
for i in 0..NUMMARKERS + 4 - 1
  if i < NUMMARKERS
	x = XBUMP * i.to_f + XBUMP + x0
	x -= 0.06 if i == 10
	sprintf(strbuf, "%d", i)
  else
	x = XBUMP * i.to_f + XBUMP*2 + x0
	sprintf(strbuf, "%d", i-NUMMARKERS)
  end
  pdf.text(x-0.05, y0+0.52, 0.0, strbuf)
end
pdf.endText()

pdf.beginText(0)
pdf.setFont("Times-Roman", "MacRomanEncoding", 14.0)
pdf.text(1.2, 2.6, 0.0, "MarkerTest.c  --   markersize = 12 points")
pdf.text(2.55, 2.24, 0.0, "pdf.marker()")
pdf.text(5.48, 2.24, 0.0, "pdf.pointer()")
pdf.endText

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("MarkerTest.pdf")
pdf.close
#pdf.launchPreview
