font.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ;; Copyright (c) 2001-2003 by Norbert Freudemann, David Frese
  2. (define-enumerated-type font-direction :font-direction
  3. font-direction? font-directions font-direction-name font-direction-index
  4. (left-to-right right-to-left))
  5. (define-exported-binding "scx-font-direction" :font-direction)
  6. (define-exported-binding "scx-font-directions" font-directions)
  7. (define-record-type char-struct :char-struct
  8. (make-char-struct lbearing rbearing width ascent descent attributes)
  9. char-struct?
  10. (lbearing char-struct:lbearing)
  11. (rbearing char-struct:rbearing)
  12. (width char-struct:width)
  13. (ascent char-struct:ascent)
  14. (descent char-struct:descent)
  15. (attributes char-struct:attributes))
  16. (define-exported-binding "scx-char-struct" :char-struct)
  17. (define-record-type font-struct :font-struct
  18. (make-font-struct cpointer
  19. fid direction min-char-or-byte2 max-char-or-byte2
  20. min-byte1 max-byte1 all-char-exist? default-char
  21. properties min-bounds max-bounds per-char ascent descent)
  22. font-struct?
  23. ;; properties is an alist atom -> number
  24. ;; per-char is a vector of char-structs
  25. ;; min-bounds, max-bounds are a char-struct
  26. (cpointer font-struct:cpointer)
  27. (fid font-struct:fid)
  28. (direction font-struct:direction)
  29. (min-char-or-byte2 font-struct:min-char-or-byte2)
  30. (max-char-or-byte2 font-struct:max-char-or-byte2)
  31. (min-byte1 font-struct:min-byte1)
  32. (max-byte1 font-struct:max-byte1)
  33. (all-char-exist? font-struct:all-char-exist?)
  34. (default-char font-struct:default-char)
  35. (properties font-struct:properties)
  36. (min-bounds font-struct:min-bounds)
  37. (max-bounds font-struct:max-bounds)
  38. (per-char font-struct:per-char)
  39. (ascent font-struct:ascent)
  40. (descent font-struct:descent))
  41. (define-exported-binding "scx-fontstruct" :font-struct)
  42. ;; *** load or unload fonts ******************************************
  43. (import-xlib-function load-font (display name)
  44. "scx_Load_Font")
  45. (import-xlib-function unload-font (display font)
  46. "scx_Unload_Font")
  47. ;; returns a font-struct record or #f
  48. (import-xlib-function query-font (display font-id)
  49. "scx_Query_Font")
  50. ;; returns a font-struct record or #f
  51. (import-xlib-function load-query-font (display name)
  52. "scx_Load_Query_Font")
  53. (import-xlib-function free-font (display font-struct)
  54. "scx_Free_Font")
  55. (define (get-font-property font-struct atom)
  56. (let ((a (assq atom (font-struct:properties font-struct)))) ;; assq ??
  57. (and a (cdr a))))
  58. ;; *** obtain or free font names and information *********************
  59. (import-xlib-function list-fonts (display pattern maxnames)
  60. "scx_List_Fonts")
  61. ;; returns an alist mapping name -> font-struct
  62. (import-xlib-function list-fonts-with-info (display pattern maxnames)
  63. "scx_List_Fonts_With_Info")
  64. ;; *** set or get the font search path *******************************
  65. (import-xlib-function set-font-path (display directories)
  66. "scx_Set_Font_Path")
  67. (import-xlib-function get-font-path (display)
  68. "scx_Get_Font_Path")
  69. ;; TODO: ??
  70. ;; calc-index calculates the array-position in XFontStruct.per_char by giving
  71. ;; the character index which ranges between [font-min-byte2...font-max-byte2]
  72. ;; for one-byte fonts or for two-byte fonts the lower 8 bits must be between
  73. ;; [font-min-byte1...font-max-byte1] and the higher 8 bits must be between
  74. ;; [font-min-byte2...font-max-byte2]. An error is raised if the index does not
  75. ;; fit into these boundaries.
  76. ;(define (calc-index font index)
  77. ; (let ((min1 (font-min-byte1 font))
  78. ; (max1 (font-max-byte1 font))
  79. ; (min2 (font-min-byte2 font))
  80. ; (max2 (font-max-byte2 font))
  81. ; (check-bounds
  82. ; (lambda (min max i s)
  83. ; (if (or (< i min)
  84. ; (> i max))
  85. ; (error (string-append s
  86. ; (number->string min)
  87. ; " and "
  88. ; (number->string max)
  89. ; "; given")
  90. ; index)))))
  91. ; (if (and (= 0 min1) (= 0 max1))
  92. ; ;; two-byte font
  93. ; (let ((b1 (bitwise-and index 255))
  94. ; (b2 (bitwise-and (arithmetic-shift index -8) 255)))
  95. ; (check-bounds min1 max1 b1
  96. ; "expected an integer with lower 8 bits between ")
  97. ; (check-bounds min2 max2 b2
  98. ; "expected an integer with higher 8 bits between ")
  99. ; (+ (* b1 (+ (- max2 min2) 1))
  100. ; b2))
  101. ; ;; one-byte font
  102. ; (begin
  103. ; (check-bounds min2 max2 index
  104. ; "expected an integer between ")
  105. ; index))))