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

require "ClibPDF"
require "kconv"

def do_Paragraph(pdf, ybump, alignmode, fontsize, font, encoding, paragraph)
  $y -= ybump
  pdf.beginText(0)
  pdf.setFont("Times-Italic", "WinAnsiEncoding", 10.0)
  buff = sprintf("[Font: %s      Encoding (CMap): %s ]", font, encoding)
  pdf.textAligned($x, $y, 0.0, alignmode, buff)
  $y -= ybump

  pdf.setFont(font, encoding, fontsize)
  for i in paragraph
	pdf.textAligned($x, $y, 0.0, alignmode, Kconv::tosjis(i))
	$y -= ybump
  end
  pdf.endText
end

sjis_text = [
  "ClibPDFをあなたのプログラムに組み込むことにより、",
  "アドビ・システムズのアクロバット等による手作業",
  "無しでＰＤＦファイルを自動的に作成することができます。",
  "ウエブ・サーバ上でユーザからの入力、サーバサイドでの",
  "データベース・アクセスによって、一定の書式の書類を",
  "大量にＰＤＦファイルとして作るような用途に最適です。"]

sjis_english = [
  "By linking ClibPDF into your program,",
  "It is possible to generate PDF files automatically",
  "without manually operating Adobe Systems' Acrobat software",
  "and other related plug-ins.  It is suitable for generating",
  "a large number of documents of a given format based on user",
  "input from Web browsers and server-side data from databases."]


fontsize = 12.0
$x = 2.5
$y = 27.0
alignmode = ClibPDF::TEXTPOS_LL
ybump = 0.5

pdf = ClibPDF::PDF.open(0)
pdf.enableCompression(ClibPDF::YES)
pdf.init
pdf.setDefaultDomainUnit(ClibPDF::POINTSPERCM)
pdf.pageInit(1, ClibPDF::PORTRAIT, ClibPDF::A4, ClibPDF::A4)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "HeiseiKakuGo-W5", "90ms-RKSJ-H", sjis_text)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "HeiseiKakuGo-W5,Italic", "90ms-RKSJ-H", sjis_text)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "HeiseiMin-W3", "90ms-RKSJ-H", sjis_text)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "HeiseiMin-W3,Bold", "90ms-RKSJ-H", sjis_text)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "HeiseiMin-W3,BoldItalic", "90ms-RKSJ-H", sjis_text)

do_Paragraph(pdf, ybump, alignmode, fontsize,
			 "Helvetica", "WinAnsiEncoding", sjis_english)

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("jpntest.pdf")

pdf.close()
#pdf.launchPreview
