VASmalltalk – pdf and libHaru 0.4

After the font demo was working yesterday, now with published version 0.4 the line demo is working and a more OO like interface has been introduced. The example from yesterday now looks like:

ExampleFontDemo
"MSKHaruInterface ExampleFontDemo"
|  aHPDFDoc aHPDFPage aHPDFFont height width  tw pageTitle |
		
pageTitle := 'Font Demo'. 
		
aHPDFDoc := HPDFDoc newDocument.

"add a new page"
aHPDFPage := aHPDFDoc addPage.

height := aHPDFPage height.
width :=  aHPDFPage width.
	
"Print the lines of the page"
aHPDFPage
  lineWidth: 1 ;
  drawRectangleX: 50 y: 50 width: width - 100 height: height - 110 ;
  stroke.
					
"Print the title of the page (with positioning center)."		
aHPDFFont := aHPDFDoc getFontNamed: 'Helvetica'.
aHPDFPage
  font: aHPDFFont size: 24.
		
tw := aHPDFPage textWidth: pageTitle.
		
aHPDFPage
  drawText: pageTitle atX: (width - tw) / 2 y: (height - 50);
"output subtitle."
  drawText: '' atX: 60 y: (height - 80)  font: aHPDFFont size: 16;
  beginText ;
  moveTextPosToX: 60 y: (height - 105).
			
self getFontList do: [ :eachFontName |
  | sampText font |			
  sampText := 'abcdefgABCDEFG12345!#$%&+-@?'.
  font := aHPDFDoc getFontNamed:  eachFontName.
			
  " print a label of text"
  aHPDFPage
    drawText: eachFontName font: aHPDFFont size: 9 ;
    moveTextPosToX: 0 y: -18 ;
  "print a sample text"
    drawText: sampText font: font size: 20 ;
    moveTextPosToX: 0 y: -20.
].
			
aHPDFPage
  endText.
		
aHPDFDoc 
  saveToFile: 'm:\test.pdf';
  free
This entry was posted in Smalltalk and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s