Skip to content

Commit

Permalink
update GetTextSize
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Jul 18, 2021
1 parent 5ba547d commit 1d585b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions contrib/freetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func (f *FreeType2) PutText(img *gocv.Mat, text string, org image.Point,
// For further details, please see:
// https://docs.opencv.org/master/d9/dfa/classcv_1_1freetype_1_1FreeType2.html#af135a132505125bdea74b378dda3bb5d
//
func (f *FreeType2) GetTextSize(text string, fontHeight int, thickness int, baseLine *int) image.Point {
func (f *FreeType2) GetTextSize(text string, fontHeight int, thickness int) (image.Point, int) {
cText := C.CString(text)
defer C.free(unsafe.Pointer(cText))
var cBaseLine C.int = C.int(*baseLine)
cBaseLine := C.int(0)

sz := C.FreeType2_GetTextSize((C.FreeType2)(f.p), cText, C.int(fontHeight), C.int(thickness), &cBaseLine)
*baseLine = int(cBaseLine)
return image.Point{
X: int(sz.width),
Y: int(sz.height),
}
}, int(cBaseLine)
}
3 changes: 1 addition & 2 deletions contrib/freetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func TestFreeTypeGetTextSize(t *testing.T) {

ft.LoadFontData("../fonts/JetBrainsMono-Regular.ttf", 0)

baseLine := 0
size := ft.GetTextSize("test", 60, 2, &baseLine)
size, baseLine := ft.GetTextSize("test", 60, 2)

if size.X != 140 {
t.Error("Invalid text size width")
Expand Down

0 comments on commit 1d585b0

Please sign in to comment.