stringsize 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .TH STRINGSIZE 2
  2. .SH NAME
  3. stringsize, stringwidth, stringnwidth, runestringsize, runestringwidth, runestringnwidth \- graphical size of strings
  4. .SH SYNOPSIS
  5. .nf
  6. .PP
  7. .ft L
  8. #include <u.h>
  9. #include <libc.h>
  10. #include <draw.h>
  11. .ft P
  12. .ta \w'\fLPoint 'u
  13. .PP
  14. .B
  15. Point stringsize(Font *f, char *s)
  16. .PP
  17. .B
  18. int stringwidth(Font *f, char *s)
  19. .PP
  20. .B
  21. int stringnwidth(Font *f, char *s, int n)
  22. .PP
  23. .B
  24. Point runestringsize(Font *f, Rune *s)
  25. .PP
  26. .B
  27. int runestringwidth(Font *f, Rune *s)
  28. .PP
  29. .B
  30. int runestringnwidth(Font *f, Rune *s, int n)
  31. .SH DESCRIPTION
  32. These routines compute the geometrical extent of character strings when drawn on the display. The most straightforward,
  33. .BR stringsize ,
  34. returns a
  35. .B Point
  36. representing the vector from upper left to lower right of the NUL-terminated string
  37. .I s
  38. drawn in font
  39. .IR f .
  40. .B Stringwidth
  41. returns just the
  42. .I x
  43. component.
  44. .B Stringnwidth
  45. returns the width of the first
  46. .I n
  47. characters of
  48. .IR s .
  49. .PP
  50. The routines beginning with
  51. .B rune
  52. are analogous, but accept an array of runes rather than
  53. .SM UTF\c
  54. -encoded bytes.
  55. .SH FILES
  56. .BR /lib/font/bit " directory of fonts
  57. .SH SOURCE
  58. .B /sys/src/libdraw
  59. .SH "SEE ALSO"
  60. .IR addpt (2),
  61. .IR cachechars (2),
  62. .IR subfont (2),
  63. .IR draw (2),
  64. .IR draw (3),
  65. .IR image (6),
  66. .IR font (6)
  67. .SH DIAGNOSTICS
  68. Because strings are loaded dynamically, these routines may generate I/O
  69. to the server and produce calls to the graphics error function.