本文整理汇总了Golang中github.com/signintech/gopdf.GoPdf.MeasureTextWidth方法的典型用法代码示例。如果您正苦于以下问题:Golang GoPdf.MeasureTextWidth方法的具体用法?Golang GoPdf.MeasureTextWidth怎么用?Golang GoPdf.MeasureTextWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/signintech/gopdf.GoPdf
的用法示例。
在下文中一共展示了GoPdf.MeasureTextWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
pdf.AddPage()
err := pdf.AddTTFFont("TakaoPGothic", "../ttf/TakaoPGothic.ttf")
if err != nil {
log.Print(err.Error())
return
}
err = pdf.SetFont("TakaoPGothic", "", 14)
if err != nil {
log.Print(err.Error())
return
}
pdf.SetX(0)
text01 := "こんにちは"
pdf.Cell(nil, text01)
w01, _ := pdf.MeasureTextWidth(text01)
pdf.SetY(20)
pdf.SetX(w01)
text02 := "i am a man."
pdf.Cell(nil, text02)
w02, _ := pdf.MeasureTextWidth(text02)
pdf.SetY(30)
pdf.SetX(w01 + w02)
text03 := "done"
pdf.Cell(nil, text03)
fmt.Printf("MeasureTextWidth = %f\n", w01)
pdf.WritePdf("m.pdf")
}
示例2: main
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
pdf.AddPage()
err := pdf.AddTTFFont("Roboto", "../ttf/Roboto-Regular.ttf")
if err != nil {
log.Print(err.Error())
return
}
fontSize := 24
err = pdf.SetFont("Roboto", "", fontSize)
if err != nil {
log.Print(err.Error())
return
}
//pdf.SetGrayFill(0.5)
//pdf.Cell(nil, "Áa")
//Measure Width
text := "How can I cordinate the text that I want draw?"
pdf.Cell(nil, text)
realWidth, _ := pdf.MeasureTextWidth(text)
fmt.Printf("realWidth = %f", realWidth)
var parser core.TTFParser
err = parser.Parse("../ttf/Roboto-Regular.ttf")
if err != nil {
log.Print(err.Error())
return
}
//Measure Height
//get CapHeight (https://en.wikipedia.org/wiki/Cap_height)
cap := float64(float64(parser.CapHeight()) * 1000.00 / float64(parser.UnitsPerEm()))
//convert
realHeight := cap * (float64(fontSize) / 1000.0)
fmt.Printf("realHeight = %f", realHeight)
//test
pdf.Br(realHeight)
pdf.Cell(nil, "How can I cordinate the text that I want draw?")
pdf.Br(realHeight)
pdf.Cell(nil, "How can I cordinate the text that I want draw?123")
pdf.Br(realHeight)
pdf.Cell(nil, "How can I cordinate the text that I want draw?456")
pdf.WritePdf("hello.pdf")
}