vector.go 976 B

12345678910111213141516171819202122232425262728293031323334
  1. package painter
  2. import (
  3. "fyne.io/fyne/v2"
  4. "fyne.io/fyne/v2/canvas"
  5. )
  6. // VectorPad returns the number of additional points that should be added around a texture.
  7. // This is to accommodate overflow caused by stroke and line endings etc.
  8. // THe result is in fyne.Size type coordinates and should be scaled for output.
  9. func VectorPad(obj fyne.CanvasObject) float32 {
  10. switch co := obj.(type) {
  11. case *canvas.Circle:
  12. if co.StrokeWidth > 0 && co.StrokeColor != nil {
  13. return co.StrokeWidth + 2
  14. }
  15. return 1 // anti-alias on circle fill
  16. case *canvas.Line:
  17. if co.StrokeWidth > 0 {
  18. return co.StrokeWidth + 2
  19. }
  20. case *canvas.Rectangle:
  21. if co.StrokeWidth > 0 && co.StrokeColor != nil {
  22. return co.StrokeWidth + 2
  23. }
  24. case *canvas.Text:
  25. if co.TextStyle.Italic {
  26. return co.TextSize / 5 // make sure that even a 20% lean does not overflow
  27. }
  28. return co.TextSize / 5 // TODO remove after we get our new text rendering all sorted in 2.4 - #3500
  29. }
  30. return 0
  31. }