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

require "ClibPDF"

tposstr = [
  "TEXTPOS_LL", "TEXTPOS_LM", "TEXTPOS_LR",
  "TEXTPOS_ML", "TEXTPOS_MM", "TEXTPOS_MR",
  "TEXTPOS_UL", "TEXTPOS_UM", "TEXTPOS_UR"
]

xlb = 0.5; xle = 6.5
ylb = 0.5; yle = 2.3
x = xlb+0.5
y = ylb+0.5
xbump = 2.5
ybump = 0.4
fontsize = 14.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, 7.0)

pdf.setlinewidth(0.15)
pdf.setdash("[1 2] 0")
for i in 0..2
  pdf.moveto(xlb, y + ybump * i.to_f)
  pdf.lineto(xle, y + ybump * i.to_f)
end
pdf.stroke
for i in 0..2
  pdf.moveto(x + xbump * i.to_f, ylb)
  pdf.lineto(x + xbump * i.to_f, yle)
end
pdf.stroke
pdf.nodash

pdf.beginText(0)
pdf.setFont("Helvetica", "MacRomanEncoding", fontsize)
for i in 0..8
  xp = x + (i % 3).to_f * xbump
  yp = y + (i / 3).to_f * ybump
  pdf.textAligned(xp, yp, 0.0, i, tposstr[i])
end
pdf.endText

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("textalign.pdf")

pdf.close
#pdf.launchPreview()
