PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ginfo.sc

https://bitbucket.org/bunny351/ezd
Scala | 388 lines | 335 code | 53 blank | 0 comment | 5 complexity | fa34a1e49e4d8c549a9a73957ee6d71f MD5 | raw file
  1. ;;; ezd - easy drawing for X11.
  2. ;;;
  3. ;;; Color, Stipple, Font, and Cursor information.
  4. ;* Copyright 1990-1993 Digital Equipment Corporation
  5. ;* All Rights Reserved
  6. ;*
  7. ;* Permission to use, copy, and modify this software and its documentation is
  8. ;* hereby granted only under the following terms and conditions. Both the
  9. ;* above copyright notice and this permission notice must appear in all copies
  10. ;* of the software, derivative works or modified versions, and any portions
  11. ;* thereof, and both notices must appear in supporting documentation.
  12. ;*
  13. ;* Users of this software agree to the terms and conditions set forth herein,
  14. ;* and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free
  15. ;* right and license under any changes, enhancements or extensions made to the
  16. ;* core functions of the software, including but not limited to those affording
  17. ;* compatibility with other hardware or software environments, but excluding
  18. ;* applications which incorporate this software. Users further agree to use
  19. ;* their best efforts to return to Digital any such changes, enhancements or
  20. ;* extensions that they make and inform Digital of noteworthy uses of this
  21. ;* software. Correspondence should be provided to Digital at:
  22. ;*
  23. ;* Director of Licensing
  24. ;* Western Research Laboratory
  25. ;* Digital Equipment Corporation
  26. ;* 250 University Avenue
  27. ;* Palo Alto, California 94301
  28. ;*
  29. ;* This software may be distributed (but not offered for sale or transferred
  30. ;* for compensation) to third parties, provided such third parties agree to
  31. ;* abide by the terms and conditions of this notice.
  32. ;*
  33. ;* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  34. ;* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  35. ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  36. ;* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  37. ;* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  38. ;* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  39. ;* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  40. ;* SOFTWARE.
  41. (module ginfo)
  42. (include "struct.sch")
  43. (include "commands.sch")
  44. (include "display.sch")
  45. (include "xternal.sch")
  46. ;;; Set the ISA-COLOR property to the RGB values for X colors as they are
  47. ;;; found in the input stream. N.B. Color names are those recognized by
  48. ;;; the X server.
  49. (define (COLOR? x)
  50. (and (symbol? x)
  51. (or (eq? x 'clear)
  52. (getprop x 'isa-color)
  53. (let* ((return (xparsecolor *dpy*
  54. (display-colormap *display*)
  55. (symbol->string x)))
  56. (status (car return))
  57. (c (cadr return)))
  58. (if (zero? status)
  59. #f
  60. (begin (putprop x 'isa-color
  61. (list (quotient (xcolor-red c) 256)
  62. (quotient (xcolor-green c) 256)
  63. (quotient (xcolor-blue c) 256)))
  64. #t))))))
  65. ;;; A color value is either a color name other than clear or an RGB value.
  66. (define (COLOR-VALUE? x)
  67. (and (not (eq? x 'clear)) (or (color? x) (and (exact? x) (>= x 0)))))
  68. (define (NEW-COLOR? x) (and (symbol? x) (not (color? x))))
  69. (define (VARIABLE-COLOR? x) (getprop x 'variable-color))
  70. ;;; Converts RGB color values to HSV values.
  71. (define (CONVERT-RGB->HSV r g b)
  72. (let* ((r (/ r 255))
  73. (g (/ g 255))
  74. (b (/ b 255))
  75. (maxrgb (max r g b))
  76. (minrgb (min r g b))
  77. (delta (- maxrgb minrgb))
  78. (value maxrgb)
  79. (saturation (if (positive? maxrgb)
  80. (/ delta maxrgb)
  81. 0))
  82. (hue 0))
  83. (if (not (zero? saturation))
  84. (let ((rc (/ (- maxrgb r) delta))
  85. (gc (/ (- maxrgb g) delta))
  86. (bc (/ (- maxrgb b) delta)))
  87. (cond ((= r maxrgb)
  88. (set! hue (- bc gc)))
  89. ((= g maxrgb)
  90. (set! hue (+ 2 (- rc bc))))
  91. (else (set! hue (+ 4 (- gc rc)))))
  92. (set! hue (* hue 60))
  93. (if (negative? hue)
  94. (set! hue (+ hue 360)))))
  95. (list hue saturation value)))
  96. ;;; Converts HSV color values to RGB values.
  97. (define (CONVERT-HSV->RGB h s v)
  98. (let ((scaled-v (inexact->exact (* v 255))))
  99. (if (zero? s)
  100. (list scaled-v scaled-v scaled-v)
  101. (let* ((h (/ (if (= h 360) 0 h) 60))
  102. (i (inexact->exact (floor h)))
  103. (f (- h i))
  104. (p (inexact->exact (* 255 v (- 1 s))))
  105. (q (inexact->exact (* 255 v (- 1 (* s f)))))
  106. (t (inexact->exact (* 255 v (- 1 (* s (- 1 f)))))))
  107. (case i
  108. ((0) (list scaled-v t p))
  109. ((1) (list q scaled-v p))
  110. ((2) (list p scaled-v t))
  111. ((3) (list p q scaled-v))
  112. ((4) (list t p scaled-v))
  113. ((5) (list scaled-v p q)))))))
  114. ;;; Users can define their own colors using the DEFINE-COLOR command.
  115. (define (COMMAND-COLOR-VALUE value)
  116. (if (pair? value)
  117. (let ((v 0))
  118. (for-each
  119. (lambda (x) (set! v (+ (* v 256) x)))
  120. (apply convert-hsv->rgb value))
  121. v)
  122. value))
  123. (define-ezd-command
  124. `(define-color ,new-color?
  125. (or (,number? ,number? ,number?) (,color-value?)))
  126. "(define-color color-name { #xRRGGBB | color-name | H S V })"
  127. (lambda (name value)
  128. (display-define-color *display* name (command-color-value value))))
  129. ;;; Users can define modifiable colors by DEFINE-VARIABLE-COLOR.
  130. (define-ezd-command
  131. `(define-variable-color ,new-color?
  132. (or (,number? ,number? ,number?) (,color-value?)))
  133. "(define-variable-color color-name { #xRRGGBB | color-name | H S V })"
  134. (lambda (name value)
  135. (display-define-variable-color *display* name
  136. (command-color-value value))))
  137. ;;; Users can set the value of a variable color by SET-VARIABLE-COLOR.
  138. (define-ezd-command
  139. `(set-variable-color ,variable-color?
  140. (or (,number? ,number? ,number?) (,color-value?)))
  141. "(set-variable-color color-name { #xRRGGBB | color-name | H S V })"
  142. (lambda (name value)
  143. (display-set-variable-color *display* name
  144. (command-color-value value))))
  145. ;;; Color values are returned in a message on stdout by the following
  146. ;;; command.
  147. (define-ezd-command
  148. `(get-color-value ,color?)
  149. "(get-color-value color-name)"
  150. (lambda (name)
  151. (let ((rgb (color? name)))
  152. (write `(color-value * * * 0 0 0 0 ,name ,@rgb
  153. ,@(apply convert-rgb->hsv rgb)) stdout-port)
  154. (newline stdout-port))))
  155. ;;; Color values are returned by the following Scheme procedures.
  156. (define (GET-HSV-COLOR-VALUE name)
  157. (and (color? name) (apply convert-rgb->hsv (color? name))))
  158. (define (GET-RGB-COLOR-VALUE name)
  159. (color? name))
  160. ;;; A stipple is defined by the following procedure that takes a stipple name
  161. ;;; and a list of 4, 8, or 16 bit row values. The bit values are saved on
  162. ;;; the ISA-STIPPLE property of the name.
  163. (define (DEFINE-STIPPLE name rows)
  164. (define (TWO-WIDE x) (bit-or (bit-lsh x 8) x))
  165. (define (FOUR-WIDE x)
  166. (bit-or (bit-lsh x 12) (bit-lsh x 8) (bit-lsh x 4) x))
  167. (case (length rows)
  168. ((4)
  169. (putprop name 'isa-stipple
  170. (let ((r0 (four-wide (car rows)))
  171. (r1 (four-wide (cadr rows)))
  172. (r2 (four-wide (caddr rows)))
  173. (r3 (four-wide (cadddr rows))))
  174. (list r0 r1 r2 r3 r0 r1 r2 r3 r0 r1 r2 r3 r0 r1 r2 r3))))
  175. ((8)
  176. (putprop name 'isa-stipple
  177. (let ((r0 (two-wide (list-ref rows 0)))
  178. (r1 (two-wide (list-ref rows 1)))
  179. (r2 (two-wide (list-ref rows 2)))
  180. (r3 (two-wide (list-ref rows 3)))
  181. (r4 (two-wide (list-ref rows 4)))
  182. (r5 (two-wide (list-ref rows 5)))
  183. (r6 (two-wide (list-ref rows 6)))
  184. (r7 (two-wide (list-ref rows 7))))
  185. (list r0 r1 r2 r3 r4 r5 r6 r7 r0 r1 r2 r3 r4 r5 r6 r7))))
  186. ((16)
  187. (putprop name 'isa-stipple rows))
  188. (else (ezd-error 'define-stipple
  189. "Incorrect number of rows: ~s" (length rows)))))
  190. ;;; Define the predefined 4x4 stipples that are named sn and reflect the
  191. ;;; fact that n of the 16 bits are set.
  192. (for-each
  193. define-stipple
  194. '( s0
  195. s1 s2 s3 s4
  196. s4a s4b s4c s4d
  197. s5 s6 s7 s8
  198. s8a s8b
  199. s9 s10 s11 s12
  200. s13 s14 s15 s16)
  201. '( (0 0 0 0)
  202. (8 0 0 0) (8 0 2 0) (#xa 0 2 0) (#xa 0 #xa 0)
  203. (#xa 0 #xa 0) (0 #xa 0 #xa) (5 0 5 0) (0 5 0 5)
  204. (#xa 0 #xa 1) (#xa 1 #xa 1) (#xa 5 #xa 1) (#xa 5 #xa 5)
  205. (#xa 5 #xa 5) (5 #xa 5 #xa)
  206. (#xe 5 #xa 5) (#xe 5 #xa 7) (#xe #xd #xa 7) (#xe #xd #xb 7)
  207. (#xe #xf #xb 7) (#xe #xf #xf 7) (#xe #xf #xf #xf) (#xf #xf #xf #xf)))
  208. ;;; Predicate to test for a stipple and return its bit values when true.
  209. (define (STIPPLE? x) (and (symbol? x) (getprop x 'isa-stipple)))
  210. ;;; Users define their own stipples with DEFINE-STIPPLE.
  211. (define-ezd-command
  212. `(define-stipple ,symbol? (repeat ,integer?))
  213. "(define-stipple name row-values...)"
  214. define-stipple)
  215. ;;; Font translation from X to Postscript is handled by this table. Each
  216. ;;; X font name is associated with a face and size.
  217. (define *TRANSLATE-FONTS*
  218. '(("6x10" "Courier" 10)
  219. ("6x12" "Helvetica" 12)
  220. ("6x13" "Helvetica" 13)
  221. ("8x13" "Courier" 13)
  222. ("8x13bold" "Courier-Bold" 13)
  223. ("9x15" "Courier" 15)
  224. ("fixed" "Helvetica" 12)
  225. ("serif10" "Times-Roman" 10)
  226. ("serifb10" "Times-Bold" 10)
  227. ("serifi10" "Times-Italic" 10)
  228. ("sans12" "Helvetica" 12)
  229. ("sansb12" "Helvetica-Bold" 12)
  230. ("sansi12" "Helvetica-Oblique" 12)
  231. ("serif12" "Times-Roman" 12)
  232. ("serifb12" "Times-Bold" 12)
  233. ("serifi12" "Times-Italic" 12)
  234. ("courier8" "Courier" 8)
  235. ("courier10" "Courier" 10)
  236. ("courier12" "Courier" 12)
  237. ("courier14" "Courier" 14)
  238. ("courier18" "Courier" 18)
  239. ("courier24" "Courier" 24)
  240. ("courier_bold8" "Courier-Bold" 8)
  241. ("courier_bold10" "Courier-Bold" 10)
  242. ("courier_bold12" "Courier-Bold" 12)
  243. ("courier_bold14" "Courier-Bold" 14)
  244. ("courier_bold18" "Courier-Bold" 18)
  245. ("courier_bold24" "Courier-Bold" 24)
  246. ("courier_oblique8" "Courier-Oblique" 8)
  247. ("courier_oblique10" "Courier-Oblique" 10)
  248. ("courier_oblique12" "Courier-Oblique" 12)
  249. ("courier_oblique14" "Courier-Oblique" 14)
  250. ("courier_oblique18" "Courier-Oblique" 18)
  251. ("courier_oblique24" "Courier-Oblique" 24)
  252. ("courier_boldoblique8" "Courier-BoldOblique" 8)
  253. ("courier_boldoblique10" "Courier-BoldOblique" 10)
  254. ("courier_boldoblique12" "Courier-BoldOblique" 12)
  255. ("courier_boldoblique14" "Courier-BoldOblique" 14)
  256. ("courier_boldoblique18" "Courier-BoldOblique" 18)
  257. ("courier_boldoblique24" "Courier-BoldOblique" 24)
  258. ("helvetica8" "Helvetica" 8)
  259. ("helvetica10" "Helvetica" 10)
  260. ("helvetica12" "Helvetica" 12)
  261. ("helvetica14" "Helvetica" 14)
  262. ("helvetica18" "Helvetica" 18)
  263. ("helvetica24" "Helvetica" 24)
  264. ("helvetica_bold8" "Helvetica-Bold" 8)
  265. ("helvetica_bold10" "Helvetica-Bold" 10)
  266. ("helvetica_bold12" "Helvetica-Bold" 12)
  267. ("helvetica_bold14" "Helvetica-Bold" 14)
  268. ("helvetica_bold18" "Helvetica-Bold" 18)
  269. ("helvetica_bold24" "Helvetica-Bold" 24)
  270. ("helvetica_oblique8" "Helvetica-Oblique" 8)
  271. ("helvetica_oblique10" "Helvetica-Oblique" 10)
  272. ("helvetica_oblique12" "Helvetica-Oblique" 12)
  273. ("helvetica_oblique14" "Helvetica-Oblique" 14)
  274. ("helvetica_oblique18" "Helvetica-Oblique" 18)
  275. ("helvetica_oblique24" "Helvetica-Oblique" 24)
  276. ("helvetica_boldoblique8" "Helvetica-BoldOblique" 8)
  277. ("helvetica_boldoblique10" "Helvetica-BoldOblique" 10)
  278. ("helvetica_boldoblique12" "Helvetica-BoldOblique" 12)
  279. ("helvetica_boldoblique14" "Helvetica-BoldOblique" 14)
  280. ("helvetica_boldoblique18" "Helvetica-BoldOblique" 18)
  281. ("helvetica_boldoblique24" "Helvetica-BoldOblique" 24)
  282. ("times_roman8" "Times-Roman" 8)
  283. ("times_roman10" "Times-Roman" 10)
  284. ("times_roman12" "Times-Roman" 12)
  285. ("times_roman14" "Times-Roman" 14)
  286. ("times_roman18" "Times-Roman" 18)
  287. ("times_roman24" "Times-Roman" 24)
  288. ("times_bold8" "Times-Bold" 8)
  289. ("times_bold10" "Times-Bold" 10)
  290. ("times_bold12" "Times-Bold" 12)
  291. ("times_bold14" "Times-Bold" 14)
  292. ("times_bold18" "Times-Bold" 18)
  293. ("times_bold24" "Times-Bold" 24)
  294. ("times_italic8" "Times-Italic" 8)
  295. ("times_italic10" "Times-Italic" 10)
  296. ("times_italic12" "Times-Italic" 12)
  297. ("times_italic14" "Times-Italic" 14)
  298. ("times_italic18" "Times-Italic" 18)
  299. ("times_italic24" "Times-Italic" 24)
  300. ("times_bolditalic8" "Times-BoldItalic" 8)
  301. ("times_bolditalic10" "Times-BoldItalic" 10)
  302. ("times_bolditalic12" "Times-BoldItalic" 12)
  303. ("times_bolditalic14" "Times-BoldItalic" 14)
  304. ("times_bolditalic18" "Times-BoldItalic" 18)
  305. ("times_bolditalic24" "Times-BoldItalic" 24)))
  306. ;;; Define an X to Postscript font translation.
  307. (define (DEFINE-FONT xfont psfont size)
  308. (set! *translate-fonts* (cons (list xfont psfont size) *translate-fonts*)))
  309. (define-ezd-command
  310. `(define-font ,string? ,string? ,number?)
  311. "(define-font \"X11-name\" \"Postscript-name\" size)"
  312. define-font)
  313. ;;; Cursor names are names of characters in the cursor font. Their names are
  314. ;;; in the list *CURSORS*. The boolean CURSOR-NAME? confirms that a name
  315. ;;; is a cursor name.
  316. (define (CURSOR-NAME? x)
  317. (let ((name (memq x *cursors*)))
  318. (if name (top-level-value (car name)) #f)))
  319. (define *CURSORS*
  320. '(XC_num_glyphs XC_X_cursor XC_arrow XC_based_arrow_down XC_based_arrow_up
  321. XC_boat XC_bogosity XC_bottom_left_corner XC_bottom_right_cornor
  322. XC_button_side XC_bottom_tee XC_box_spiral XC_center_ptr XC_circle
  323. XC_clock XC_coffee_mug XC_cross XC_cross_reverse XC_crosshair
  324. XC_diamond_cross XC_dot XC_dotbox XC_double_arrow XC_draft_large
  325. XC_draft_small XC_draped_box XC_exchange XC_fleur XC_gobbler XC_gumby
  326. XC_hand1 XC_hand2 XC_heart XC_icon XC_iron_cross XC_left_ptr
  327. XC_left_side XC_left_tee XC_leftbutton XC_ll_angle XC_lr_angle
  328. XC_man XC_middlebutton XC_mouse XC_pencil XC_pirate XC_plus
  329. XC_question_arrow XC_right_ptr XC_right_side XC_right_tee XC_rightbutton
  330. XC_rtl_logo XC_sailboat XC_sb_down_arrow XC_sb_h_double_arrow
  331. XC_sb_left_arrow XC_sb_right_arrow XC_sb_up_arrow XC_sb_v_double_arrow
  332. XC_shuttle XC_sizing XC_spider XC_spraycan XC_star XC_target XC_tcross
  333. XC_top_left_arrow XC_top_left_corner XC_top_right_corner
  334. XC_top_side XC_top_tee XC_trek XC_ul_angle XC_umbrella XC_ur_angle
  335. XC_ur_angle XC_watch XC_xterm))