本文整理匯總了Golang中bitbucket/org/zombiezen/gopdf/pdf.Path.Curve方法的典型用法代碼示例。如果您正苦於以下問題:Golang Path.Curve方法的具體用法?Golang Path.Curve怎麽用?Golang Path.Curve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitbucket/org/zombiezen/gopdf/pdf.Path
的用法示例。
在下文中一共展示了Path.Curve方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: partialArc
// Approximate a circular arc of fewer than π/2
// radians with cubic Bézier curve.
func partialArc(p *pdf.Path, x, y, r vg.Length, a1, a2 float64) {
a := (a2 - a1) / 2
x4 := r * vg.Length(math.Cos(a))
y4 := r * vg.Length(math.Sin(a))
x1 := x4
y1 := -y4
const k = 0.5522847498 // some magic constant
f := k * vg.Length(math.Tan(a))
x2 := x1 + f*y4
y2 := y1 + f*x4
x3 := x2
y3 := -y2
// Rotate and translate points into position.
ar := a + a1
sinar := vg.Length(math.Sin(ar))
cosar := vg.Length(math.Cos(ar))
x2r := x2*cosar - y2*sinar + x
y2r := x2*sinar + y2*cosar + y
x3r := x3*cosar - y3*sinar + x
y3r := x3*sinar + y3*cosar + y
x4 = r*vg.Length(math.Cos(a2)) + x
y4 = r*vg.Length(math.Sin(a2)) + y
p.Curve(pdfPoint(x2r, y2r), pdfPoint(x3r, y3r), pdfPoint(x4, y4))
}
示例2: traceCurve
func traceCurve(a, b, c, d pdf.Point, canvas *pdf.Canvas) {
path := new(pdf.Path)
path.Move(a)
path.Curve(b, c, d)
canvas.Stroke(path)
}
示例3: main
func main() {
doc := pdf.New()
canvas := doc.NewPage(pdf.A4Width, pdf.A4Height)
path := new(pdf.Path)
bottomLeft := pdf.Point{borderWidth, borderWidth}
topRight := pdf.Point{pdf.A4Width - borderWidth, pdf.A4Height - borderWidth}
path.Rectangle(pdf.Rectangle{bottomLeft, topRight})
canvas.Stroke(path)
left := 5 * pdf.Cm
right := 15 * pdf.Cm
top := 15 * pdf.Cm
bottom := 10 * pdf.Cm
curve := new(pdf.Path)
a := pdf.Point{left, bottom}
b := pdf.Point{left, top}
c := pdf.Point{right, top}
d := pdf.Point{right, bottom}
curve.Move(a)
curve.Curve(b, c, d)
beneath := 5 * pdf.Cm
e := pdf.Point{left, beneath}
f := pdf.Point{right, beneath}
curve.Curve(f, e, a)
left = 6.5 * pdf.Cm
right = 13.5 * pdf.Cm
top = 13.5 * pdf.Cm
bottom = 10 * pdf.Cm
beneath = 6.5 * pdf.Cm
a = pdf.Point{left, 9 * pdf.Cm}
b = pdf.Point{left, top}
c = pdf.Point{right, top}
d = pdf.Point{right, 11 * pdf.Cm}
curve.Move(d)
curve.Curve(c, b, a)
e = pdf.Point{left, beneath}
f = pdf.Point{right, beneath}
curve.Curve(e, f, d)
canvas.FillStroke(curve)
canvas.Close()
file, err := os.Create("curves.pdf")
if err != nil {
log.Fatal(err)
}
err = doc.Encode(file)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
file.Close()
}