added helloworld sample
This commit is contained in:
parent
be91a632c9
commit
244893c6ab
3 changed files with 39 additions and 0 deletions
38
pdf2d/samples/helloworld/helloworld.go
Normal file
38
pdf2d/samples/helloworld/helloworld.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||
// created: 21/11/2010 by Laurent Le Goff, Stani Michiels
|
||||
|
||||
// Display Hello world in a Rectangle save it to a png
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/stanim/draw2d"
|
||||
"github.com/stanim/draw2d/pdf2d"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Set the global folder for searching fonts
|
||||
// The pdf backend needs for every ttf file its corresponding json
|
||||
// file which is generated by gofpdf/makefont.
|
||||
draw2d.SetFontFolder(".")
|
||||
|
||||
// Initialize the graphic context on a pdf document
|
||||
dest := pdf2d.NewPdf("P", "mm", "A4")
|
||||
gc := pdf2d.NewGraphicContext(dest)
|
||||
|
||||
// Draw a rounded rectangle using default colors
|
||||
draw2d.RoundRect(gc, 5, 5, 135, 95, 10, 10)
|
||||
gc.FillStroke()
|
||||
|
||||
// Set the font luximbi.ttf
|
||||
gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
|
||||
// Set the fill text color to black
|
||||
gc.SetFillColor(image.Black)
|
||||
gc.SetFontSize(14)
|
||||
// Display Hello World
|
||||
gc.FillStringAt("Hello World", 8, 52)
|
||||
|
||||
// Save to pdf
|
||||
pdf2d.SaveToPdfFile("helloworld.pdf", dest)
|
||||
}
|
1
pdf2d/samples/helloworld/luximbi.json
Normal file
1
pdf2d/samples/helloworld/luximbi.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"Tp":"TrueType","Name":"LuxiMono-BoldOblique","Desc":{"Ascent":783,"Descent":-205,"CapHeight":783,"Flags":97,"FontBBox":{"Xmin":-29,"Ymin":-211,"Xmax":764,"Ymax":1012},"ItalicAngle":-8,"StemV":120,"MissingWidth":600},"Up":0,"Ut":0,"Cw":[600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,653,600,653,600,600,653,600,653,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600],"Enc":"cp1252","Diff":"","File":"","Size1":0,"Size2":0,"OriginalSize":0,"I":0,"N":0,"DiffN":0}
|
BIN
pdf2d/samples/helloworld/luximbi.ttf
Normal file
BIN
pdf2d/samples/helloworld/luximbi.ttf
Normal file
Binary file not shown.
Loading…
Reference in a new issue