Switched to calling the Windows MulDiv() function instead of reimplementing it ourselves in prefsize_windows.go.

This commit is contained in:
Pietro Gagliardi 2014-04-02 10:43:28 -04:00
parent fa880a71cc
commit 43311a668f
1 changed files with 11 additions and 6 deletions

View File

@ -112,13 +112,18 @@ func (s *sysData) preferredSize() (width int, height int) {
return width, height return width, height
} }
// attempts to mimic the behavior of kernel32.MulDiv() var (
// caling it directly would be better (TODO) _mulDiv = kernel32.NewProc("MulDiv")
// alternatively TODO make sure the rounding is correct )
func muldiv(ma int, mb int, div int) int { func muldiv(ma int, mb int, div int) int {
xa := int64(ma) * int64(mb) // div will not be 0 in the usages above
xa /= int64(div) // we also ignore overflow; that isn't likely to happen for our use case anytime soon
return int(xa) r1, _, _ := _mulDiv.Call(
uintptr(int32(ma)),
uintptr(int32(mb)),
uintptr(int32(div)))
return int(int32(r1))
} }
type _TEXTMETRICS struct { type _TEXTMETRICS struct {