18 #undef True |
19 #undef True |
19 #undef False |
20 #undef False |
20 #undef Time |
21 #undef Time |
21 #define Time XTime |
22 #define Time XTime |
22 |
23 |
23 #ifdef XFT |
24 |
|
25 #ifdef XFT |
|
26 # define __externalAddressValCasted(type, externalAddress) \ |
|
27 ((type)__externalAddressVal(externalAddress)) |
|
28 # define DISPLAY(x) __externalAddressValCasted(Display*, x) |
|
29 # define SCREEN(x) ((int)(__intVal(x))) |
|
30 # define DRAWABLE(x) __externalAddressValCasted(Drawable, x) |
|
31 # define GC(x) __externalAddressValCasted(GC, x) |
|
32 # define VISUAL(x) __externalAddressValCasted(Visual*, x) |
|
33 # define COLORMAP(x) __externalAddressValCasted(Colormap, x) |
|
34 # define XFT_FONT(x) __externalAddressValCasted(XftFont*, x) |
|
35 # define XFT_PATTERN(x) __externalAddressValCasted(XftPattern*, x) |
|
36 # define XFT_DRAW(x) __externalAddressValCasted(XftDraw*, x) |
|
37 # define XFT_COLOR(x) __externalAddressValCasted(XftColor*, x) |
|
38 |
24 # include <X11/Xft/Xft.h> |
39 # include <X11/Xft/Xft.h> |
25 # include <X11/Xft/XftCompat.h> |
40 # include <X11/Xft/XftCompat.h> |
26 # define __XftFontVal(handle) ((XftFont*)__externalAddressVal(handle)) |
41 |
27 # define __XftPatternVal(handle) ((XftPattern*)__externalAddressVal(handle)) |
|
28 # define __XftDrawVal(handle) ((XftDraw*)__externalAddressVal(handle)) |
|
29 # define __XftColorVal(handle) ((XftColor*)__externalAddressVal(handle)) |
|
30 #endif |
42 #endif |
31 |
43 |
32 %} |
44 %} |
33 ! ! |
45 ! ! |
34 |
46 |
79 top := StandardSystemView new. |
91 top := StandardSystemView new. |
80 top extent:300@200. |
92 top extent:300@200. |
81 |
93 |
82 textView := EditTextView new. |
94 textView := EditTextView new. |
83 textView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
95 textView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
84 textView basicFont: (XftFontDescription family: 'helvetica' size: 30). |
96 textView basicFont: (XftFontDescription family: 'helvetica' size: 16). |
85 |
97 |
86 top addSubView:textView. |
98 top addSubView:textView. |
87 |
99 |
88 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
100 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
89 |
101 |
90 top open. |
102 top open. |
91 |
103 |
92 "Created: / 20-12-2013 / 00:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
104 "Created: / 20-12-2013 / 00:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
105 "Modified: / 29-12-2013 / 10:28:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
106 ! ! |
|
107 |
|
108 !XftFontDescription methodsFor:'displaying'! |
|
109 |
|
110 displayString:aString from:index1 to:index2 x:x y:y in:aGC opaque:opaque |
|
111 "display a partial string at some position in aGC." |
|
112 |
|
113 | y0 extents | |
|
114 |
|
115 y0 := y - self ascent. |
|
116 |
|
117 drawId isNil ifTrue:[ |
|
118 drawId := self xftDrawCreate: device displayId screen: device screen drawable: aGC id. |
|
119 ] ifFalse:[ |
|
120 self xftDrawChange: drawId drawable: aGC id |
|
121 ]. |
|
122 lasrFgColor ~= aGC paint ifTrue:[ |
|
123 lastFgColorId notNil ifTrue:[ |
|
124 self xftColorDestroy: device displayId screen: device screen color: lastFgColorId. |
|
125 ]. |
|
126 lasrFgColor := aGC paint. |
|
127 lastFgColorId := self xftColorCreate: device displayId screen: device screen color: lasrFgColor. |
|
128 ]. |
|
129 extents := self xftTextExtents: device displayId font: fontId string: aString from: index1 to: index2. |
|
130 |
|
131 opaque ifTrue:[ |
|
132 |
|
133 lastBgColor ~= aGC backgroundPaint ifTrue:[ |
|
134 lastBgColorId notNil ifTrue:[ |
|
135 self xftColorDestroy: device displayId screen: device screen color: lastBgColorId. |
|
136 ]. |
|
137 lastBgColor := aGC backgroundPaint. |
|
138 lastBgColorId := self xftColorCreate: device displayId screen: device screen color: lastBgColor. |
|
139 ]. |
|
140 self xftDrawRect: drawId color: lastBgColorId x: x y:y0 width: extents first height: extents second |
|
141 |
|
142 ]. |
|
143 "true"false ifTrue:[ |
|
144 | w p | |
|
145 |
|
146 w := self widthOf: aString from: index1 to: index2. |
|
147 p := aGC paint. |
|
148 aGC paint: Color red. |
|
149 aGC displayLineFromX: x y: y toX: x + w y: y. |
|
150 aGC paint: Color blue. |
|
151 aGC displayLineFromX: x y: y - self ascent toX: x + w y: y - self ascent. |
|
152 aGC paint: Color yellow. |
|
153 aGC displayLineFromX: x y: y + self descent toX: x + w y: y + self descent. |
|
154 |
|
155 |
|
156 aGC paint: p. |
|
157 |
|
158 |
|
159 ]. |
|
160 self xftDrawString: drawId color: lastFgColorId font: fontId x: x y: y string: aString from: index1 to: index2 |
|
161 |
|
162 "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
163 "Modified: / 29-12-2013 / 11:38:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
93 ! ! |
164 ! ! |
94 |
165 |
95 !XftFontDescription methodsFor:'error reporting'! |
166 !XftFontDescription methodsFor:'error reporting'! |
96 |
167 |
97 primitiveFailedIfNoXft |
168 primitiveFailedIfNoXft |
217 ^ false |
288 ^ false |
218 |
289 |
219 "Created: / 20-12-2013 / 21:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
290 "Created: / 20-12-2013 / 21:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
220 ! |
291 ! |
221 |
292 |
|
293 xftColorCreate: displayId screen: screen color: color |
|
294 |
|
295 | error r g b a | |
|
296 |
|
297 self primitiveFailedIfNoXft. |
|
298 |
|
299 r := color scaledRed. |
|
300 g := color scaledGreen. |
|
301 b := color scaledBlue. |
|
302 a := color alpha * 65535. |
|
303 %{ |
|
304 #ifdef XFT |
|
305 XRenderColor xrcolor; |
|
306 XftColor *xftcolor; |
|
307 |
|
308 if ( ! __isExternalAddressLike(displayId) ) { |
|
309 error = @symbol(BadArg1); |
|
310 goto err; |
|
311 } |
|
312 if ( ! __isSmallInteger(screen) ) { |
|
313 error = @symbol(BadArg2); |
|
314 goto err; |
|
315 } |
|
316 xrcolor.red = __intVal(r); |
|
317 xrcolor.green = __intVal(g); |
|
318 xrcolor.blue = __intVal(b); |
|
319 xrcolor.alpha = __intVal(a); |
|
320 |
|
321 xftcolor = (XftColor*) malloc( sizeof( XftColor ) ); |
|
322 XftColorAllocValue ( DISPLAY( displayId ) , |
|
323 DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) , |
|
324 DefaultColormap( DISPLAY( displayId), SCREEN (screen) ), |
|
325 &xrcolor, |
|
326 xftcolor ); |
|
327 RETURN ( __MKEXTERNALADDRESS( xftcolor ) ); |
|
328 err:; |
|
329 #endif |
|
330 %}. |
|
331 self primitiveFailed: error |
|
332 |
|
333 "Created: / 28-12-2013 / 11:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
334 ! |
|
335 |
|
336 xftColorDestroy: displayId screen: screen color: xftColorId |
|
337 |
|
338 | error | |
|
339 |
|
340 self primitiveFailedIfNoXft. |
|
341 |
|
342 %{ |
|
343 #ifdef XFT |
|
344 XRenderColor xrcolor; |
|
345 XftColor *xftcolor; |
|
346 |
|
347 if ( ! __isExternalAddressLike(displayId) ) { |
|
348 error = @symbol(BadArg1); |
|
349 goto err; |
|
350 } |
|
351 if ( ! __isSmallInteger(screen) ) { |
|
352 error = @symbol(BadArg2); |
|
353 goto err; |
|
354 } |
|
355 if ( ! __isExternalAddressLike(xftColorId) ) { |
|
356 error = @symbol(BadArg3); |
|
357 goto err; |
|
358 } |
|
359 |
|
360 XftColorFree ( DISPLAY( displayId ) , |
|
361 DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) , |
|
362 DefaultColormap( DISPLAY( displayId), SCREEN (screen) ), |
|
363 XFT_COLOR( xftColorId ) ); |
|
364 free( __externalAddressVal( xftColorId ) ); |
|
365 __externalAddressVal( xftColorId ) = NULL; |
|
366 RETURN ( self ); |
|
367 err:; |
|
368 #endif |
|
369 %}. |
|
370 self primitiveFailed: error |
|
371 |
|
372 "Created: / 28-12-2013 / 12:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
373 ! |
|
374 |
|
375 xftDrawChange: xftDrawId drawable: drawableId |
|
376 |
|
377 | error | |
|
378 |
|
379 self primitiveFailedIfNoXft. |
|
380 %{ |
|
381 #ifdef XFT |
|
382 if ( ! __isExternalAddressLike(xftDrawId) ) { |
|
383 error = @symbol(BadArg1); |
|
384 goto err; |
|
385 } |
|
386 if ( ! __isExternalAddressLike(drawableId) ) { |
|
387 error = @symbol(BadArg2); |
|
388 goto err; |
|
389 } |
|
390 if (XftDrawDrawable( XFT_DRAW(xftDrawId) ) != DRAWABLE( drawableId ) ) { |
|
391 XftDrawChange( XFT_DRAW(xftDrawId) , DRAWABLE( drawableId ) ); |
|
392 } |
|
393 RETURN ( self ); |
|
394 err:; |
|
395 #endif |
|
396 %}. |
|
397 self primitiveFailed: error |
|
398 |
|
399 "Created: / 26-12-2013 / 12:17:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
400 ! |
|
401 |
|
402 xftDrawCreate: displayId screen: screen drawable: drawableId |
|
403 |
|
404 | error | |
|
405 |
|
406 self primitiveFailedIfNoXft. |
|
407 %{ |
|
408 #ifdef XFT |
|
409 if ( ! __isExternalAddressLike(displayId) ) { |
|
410 error = @symbol(BadArg1); |
|
411 goto err; |
|
412 } |
|
413 if ( ! __isSmallInteger(screen) ) { |
|
414 error = @symbol(BadArg2); |
|
415 goto err; |
|
416 } |
|
417 if ( ! __isExternalAddressLike(drawableId) ) { |
|
418 error = @symbol(BadArg3); |
|
419 goto err; |
|
420 } |
|
421 RETURN ( __MKEXTERNALADDRESS( XftDrawCreate ( DISPLAY( displayId ) , |
|
422 DRAWABLE( drawableId ) , |
|
423 DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) , |
|
424 DefaultColormap( DISPLAY( displayId), SCREEN (screen) ) ) ) ); |
|
425 err:; |
|
426 #endif |
|
427 %}. |
|
428 self primitiveFailed: error |
|
429 |
|
430 "Created: / 21-12-2013 / 21:12:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
431 ! |
|
432 |
|
433 xftDrawRect: drawIdArg color: colorIdArg x: x y: y width: w height: h |
|
434 |
|
435 | error extents | |
|
436 |
|
437 self primitiveFailedIfNoXft. |
|
438 %{ |
|
439 #ifdef XFT |
|
440 if ( ! __isExternalAddressLike(drawIdArg) ) { |
|
441 error = @symbol(BadArg1); |
|
442 goto err; |
|
443 } |
|
444 if ( ! __isExternalAddressLike(colorIdArg) ) { |
|
445 error = @symbol(BadArg2); |
|
446 goto err; |
|
447 } |
|
448 if ( ! __isSmallInteger(x) ) { |
|
449 error = @symbol(BadArg3); |
|
450 goto err; |
|
451 } |
|
452 if ( ! __isSmallInteger(y) ) { |
|
453 error = @symbol(BadArg4); |
|
454 goto err; |
|
455 } |
|
456 if ( ! __isSmallInteger(w) ) { |
|
457 error = @symbol(BadArg5); |
|
458 goto err; |
|
459 } |
|
460 if ( ! __isSmallInteger(h) ) { |
|
461 error = @symbol(BadArg6); |
|
462 goto err; |
|
463 } |
|
464 XftDrawRect(XFT_DRAW(drawIdArg), XFT_COLOR(colorIdArg), |
|
465 __intVal(x), __intVal(y), __intVal(w) ,__intVal(h)); |
|
466 |
|
467 RETURN ( self ); |
|
468 err:; |
|
469 #endif |
|
470 %}. |
|
471 self primitiveFailed: error. |
|
472 |
|
473 "Created: / 28-12-2013 / 23:35:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
474 ! |
|
475 |
|
476 xftDrawString: drawIdArg color: colorIdArg font: fontIdArg x: x y: y string: text from: start to: stop |
|
477 |
|
478 | error extents | |
|
479 |
|
480 self primitiveFailedIfNoXft. |
|
481 %{ |
|
482 #ifdef XFT |
|
483 int _start, _stop; |
|
484 int _x, _y; |
|
485 if ( ! __isExternalAddressLike(drawIdArg) ) { |
|
486 error = @symbol(BadArg1); |
|
487 goto err; |
|
488 } |
|
489 if ( ! __isExternalAddressLike(colorIdArg) ) { |
|
490 error = @symbol(BadArg2); |
|
491 goto err; |
|
492 } |
|
493 if ( ! __isExternalAddressLike(fontIdArg) ) { |
|
494 error = @symbol(BadArg3); |
|
495 goto err; |
|
496 } |
|
497 if ( ! __isSmallInteger(x) ) { |
|
498 error = @symbol(BadArg4); |
|
499 goto err; |
|
500 } |
|
501 _x = __intVal(x); |
|
502 if ( ! __isSmallInteger(y) ) { |
|
503 error = @symbol(BadArg5); |
|
504 goto err; |
|
505 } |
|
506 _y = __intVal(y); |
|
507 |
|
508 |
|
509 if ( ! __isSmallInteger(start) ) { |
|
510 error = @symbol(BadArg6); |
|
511 goto err; |
|
512 } |
|
513 _start = __intVal(start); |
|
514 if ( ! __isSmallInteger(stop) ) { |
|
515 error = @symbol(BadArg7); |
|
516 goto err; |
|
517 } |
|
518 _stop = __intVal(stop); |
|
519 |
|
520 if ( __isString(text) ) { |
|
521 XftDrawString8(XFT_DRAW(drawIdArg), XFT_COLOR(colorIdArg), XFT_FONT(fontIdArg), |
|
522 _x, _y, |
|
523 __stringVal(text) + (_start - 1), _stop - _start + 1); |
|
524 RETURN ( self ); |
|
525 } else { |
|
526 error = @symbol(BadArg5); |
|
527 goto err; |
|
528 } |
|
529 err:; |
|
530 #endif |
|
531 %}. |
|
532 self primitiveFailed: error. |
|
533 |
|
534 "Created: / 28-12-2013 / 12:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
535 "Modified: / 29-12-2013 / 11:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
536 ! |
|
537 |
222 xftFontGetAscent: fontIdArg |
538 xftFontGetAscent: fontIdArg |
223 |
539 |
224 | error | |
540 | error | |
225 |
541 |
226 self primitiveFailedIfNoXft. |
542 self primitiveFailedIfNoXft. |
582 %}. |
898 %}. |
583 self primitiveFailed: error |
899 self primitiveFailed: error |
584 |
900 |
585 "Created: / 20-12-2013 / 21:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
901 "Created: / 20-12-2013 / 21:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
586 "Modified: / 21-12-2013 / 01:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
902 "Modified: / 21-12-2013 / 01:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
903 ! |
|
904 |
|
905 xftTextExtents: displayIdArg font: fontIdArg string: text from: start to: stop |
|
906 |
|
907 | error extents | |
|
908 |
|
909 self primitiveFailedIfNoXft. |
|
910 extents := Array new: 6. |
|
911 %{ |
|
912 #ifdef XFT |
|
913 XGlyphInfo info; |
|
914 int _start, _stop; |
|
915 if ( ! __isExternalAddressLike(displayIdArg) ) { |
|
916 error = @symbol(BadArg1); |
|
917 goto err; |
|
918 } |
|
919 if ( ! __isExternalAddressLike(fontIdArg) ) { |
|
920 error = @symbol(BadArg2); |
|
921 goto err; |
|
922 } |
|
923 if ( ! __isSmallInteger(start) ) { |
|
924 error = @symbol(BadArg4); |
|
925 goto err; |
|
926 } |
|
927 _start = __intVal(start); |
|
928 if ( ! __isSmallInteger(stop) ) { |
|
929 error = @symbol(BadArg5); |
|
930 goto err; |
|
931 } |
|
932 _stop = __intVal(stop); |
|
933 if ( __isString(text) ) { |
|
934 XftTextExtents8(DISPLAY(displayIdArg), XFT_FONT(fontIdArg), |
|
935 __stringVal(text) + (_start - 1), _stop - _start + 1, &info); |
|
936 } else { |
|
937 error = @symbol(BadArg3); |
|
938 goto err; |
|
939 } |
|
940 __ArrayInstPtr(extents)->a_element[0] = __MKSMALLINT(info.width); |
|
941 __ArrayInstPtr(extents)->a_element[1] = __MKSMALLINT(info.height); |
|
942 __ArrayInstPtr(extents)->a_element[2] = __MKSMALLINT(info.x); |
|
943 __ArrayInstPtr(extents)->a_element[3] = __MKSMALLINT(info.y); |
|
944 __ArrayInstPtr(extents)->a_element[4] = __MKSMALLINT(info.xOff); |
|
945 __ArrayInstPtr(extents)->a_element[5] = __MKSMALLINT(info.yOff); |
|
946 error = nil; |
|
947 err:; |
|
948 #endif |
|
949 %}. |
|
950 error notNil ifTrue:[ |
|
951 self primitiveFailed: error. |
|
952 ^ nil. |
|
953 ]. |
|
954 ^ extents |
|
955 |
|
956 "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
957 "Modified: / 21-12-2013 / 20:53:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
587 ! ! |
958 ! ! |
588 |
959 |
589 !XftFontDescription methodsFor:'queries-dimensions'! |
960 !XftFontDescription methodsFor:'queries-dimensions'! |
590 |
961 |
591 ascent |
962 ascent |
608 "return the height - the number of pixels above plus below the baseLine." |
979 "return the height - the number of pixels above plus below the baseLine." |
609 |
980 |
610 ^ self xftFontGetHeight: fontId |
981 ^ self xftFontGetHeight: fontId |
611 |
982 |
612 "Created: / 21-12-2013 / 01:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
983 "Created: / 21-12-2013 / 01:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
984 ! |
|
985 |
|
986 isFixedWidth |
|
987 "return true, if this is a fixed pitch font (i.e. all characters |
|
988 are of the same width)" |
|
989 |
|
990 ^ false "/ How to check? |
|
991 |
|
992 "Created: / 21-12-2013 / 10:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
993 ! |
|
994 |
|
995 widthOf:aString from:start to:stop |
|
996 "return the width of a sub string" |
|
997 |
|
998 | extents | |
|
999 |
|
1000 extents := self xftTextExtents: device displayId font: fontId string: aString from: start to: stop. |
|
1001 "/ extents --> #(width height x y xOff yOff) |
|
1002 ^ extents first. |
|
1003 |
|
1004 "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
613 ! ! |
1005 ! ! |
614 |
1006 |
615 !XftFontDescription class methodsFor:'documentation'! |
1007 !XftFontDescription class methodsFor:'documentation'! |
616 |
1008 |
617 version |
1009 version |
618 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.3 2013-12-21 00:21:22 vrany Exp $' |
1010 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.4 2013-12-29 11:03:28 vrany Exp $' |
619 ! |
1011 ! |
620 |
1012 |
621 version_CVS |
1013 version_CVS |
622 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.3 2013-12-21 00:21:22 vrany Exp $' |
1014 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.4 2013-12-29 11:03:28 vrany Exp $' |
623 ! ! |
1015 ! ! |
624 |
1016 |