X11/FontConfig: Conditionally compile FontConfig support jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 22 Feb 2016 08:41:04 +0000
branchjv
changeset 7154 f2d585b5f20e
parent 7151 51e71e95c952
child 7155 efc70ec17284
X11/FontConfig: Conditionally compile FontConfig support Compile FontConfig support only if HAVE_FONTCONFIG macro is defined. This allows stx:libview to be compiled without FontConfig. To test whether FontConfig and/or XFT support is compiled in, use ConfigurableFeatures includesFeature: #FontConfig ConfigurableFeatures includesFeature: #XFT
FcPattern.st
Make.spec
XftFontDescription.st
extensions.st
libInit.cc
stx_libview.st
--- a/FcPattern.st	Wed Feb 17 19:33:09 2016 +0000
+++ b/FcPattern.st	Mon Feb 22 08:41:04 2016 +0000
@@ -11,6 +11,7 @@
 
 !FcPattern primitiveDefinitions!
 %{
+#ifdef HAVE_FONTCONFIG
 /*
  * includes, defines, structure definitions
  * and typedefs come here.
@@ -24,6 +25,7 @@
 #include <fontconfig/fontconfig.h>
 
 #define FC_PATTERN_VAL(x) ((FcPattern*)__externalAddressVal(x))
+#endif
 %}
 ! !
 
@@ -202,6 +204,7 @@
     | error |
 
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     FcValue v;
     FcBool b;
 
@@ -244,6 +247,7 @@
     RETURN ( b == FcTrue ? true : false );
 
     err:;
+#endif
 %}.
     self primitiveFailed: error
 
@@ -282,6 +286,7 @@
     | error |
 
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     FcValue v;
     FcResult r;
 
@@ -316,6 +321,7 @@
 	goto err;
     }
     err:;
+#endif
 %}.
     self primitiveFailed: error
 
@@ -341,6 +347,7 @@
 removeKey: attribute
     | error |
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     if ( ! __externalAddressVal ( self ) ) {
 	error = @symbol(Released);
 	goto err;
@@ -352,6 +359,7 @@
     FcPatternDel( FC_PATTERN_VAL(self), __stringVal ( attribute ) );
     RETURN ( self );
     err:;
+#endif
 %}.
     self primitiveFailed: error
 
@@ -362,11 +370,13 @@
 = another
     self class == another class ifFalse:[ ^ false ].
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     FcPattern* pa = FC_PATTERN_VAL(self);
     FcPattern* pb = FC_PATTERN_VAL(another);
     if (pa != NULL && pb != NULL) {
     	RETURN ( FcPatternEqual(pa, pb) == FcTrue ? true : false );
     }
+#endif
 %}.
     ^ false
 
@@ -376,12 +386,14 @@
 hash
 
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     unsigned int h = 0;
     if (__externalAddressVal(self) != NULL) {
         h = FcPatternHash(FC_PATTERN_VAL(self));
         h &= 0x7FFFFFFFU;
     }
     RETURN ( __MKSMALLINT( h ) );	
+#endif
 %}.    
     ^self primitiveFailed
 
@@ -392,6 +404,7 @@
 
 asString
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     char *_s;
     OBJ s;
     if (__externalAddressVal(self) != NULL) {
@@ -400,6 +413,7 @@
     	free(_s);
     	RETURN ( s );
     }   
+#endif
 %}.
     self primitiveFailed
 
@@ -410,21 +424,49 @@
 
 postCopy
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     __externalAddressVal(self) = (void*)FcPatternDuplicate(FC_PATTERN_VAL(self));	
+#endif
 %}.
     self registerForFinalization
 
     "Created: / 17-02-2016 / 10:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!FcPattern methodsFor:'error handling'!
+
+primitiveFailed
+    <resource: #skipInDebuggersWalkBack>
+
+    (ConfigurableFeatures hasFontConfig) ifFalse:[ 
+        super primitiveFailed: 'FontConfig support not compiled in. Recompile with -DHAVE_FONTCONFIG'.        
+    ].
+    ^ super primitiveFailed
+
+    "Created: / 22-02-2016 / 08:12:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+primitiveFailed: message
+    <resource: #skipInDebuggersWalkBack>
+
+    (ConfigurableFeatures hasFontConfig) ifFalse:[ 
+        super primitiveFailed: 'FontConfig support not compiled in. Recompile with -DHAVE_FONTCONFIG'.        
+    ].
+    ^ super primitiveFailed: message
+
+    "Created: / 22-02-2016 / 08:13:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !FcPattern methodsFor:'finalization'!
 
 destroy
     %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     FcPatternDestroy((FcPattern*)__externalAddressVal(self));
     __externalAddressVal(self) = NULL;
     RETURN ( self );
-    %}.
+    #endif
+%}.
     self primitiveFailed.
 !
 
@@ -438,11 +480,13 @@
 
 initialize    
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     __externalAddressVal(self) = (void*)FcPatternCreate();
     __SSEND0(self, @symbol(registerForFinalization), 4);
     RETURN ( self );
     err:;
 
+#endif
 %}.
     self primitiveFailed.
 
@@ -453,6 +497,7 @@
 initializeFromString: aString
     | error |
 %{ /* STACK: 64000 */
+#ifdef HAVE_FONTCONFIG
     if ( ! __isStringLike ( aString ) ) {
 	error = @symbol(BadArg1);
 	goto err;
@@ -461,6 +506,7 @@
     __SSEND0(self, @symbol(registerForFinalization), 4);
     RETURN ( self );
     err:;
+#endif
 %}.
     self primitiveFailed.
 
--- a/Make.spec	Wed Feb 17 19:33:09 2016 +0000
+++ b/Make.spec	Mon Feb 22 08:41:04 2016 +0000
@@ -212,6 +212,6 @@
     $(OUTDIR_SLASH)PopUpView.$(O) \
     $(OUTDIR_SLASH)StandardSystemView.$(O) \
     $(OUTDIR_SLASH)ModalBox.$(O) \
+    $(OUTDIR_SLASH)extensions.$(O) \
 
 
-
--- a/XftFontDescription.st	Wed Feb 17 19:33:09 2016 +0000
+++ b/XftFontDescription.st	Mon Feb 22 08:41:04 2016 +0000
@@ -44,6 +44,9 @@
 #define Time XTime
 
 #ifdef XFT
+#  ifndef HAVE_FONTCONFIG
+#    error "XFT defined but not HAVE_FONTCONFIG. Xft fonts cannot be used without FontConfig support"
+#  endif
 
 extern OBJ __GLOBAL_GET_BY_NAME(char *);
 
@@ -286,14 +289,12 @@
 !XftFontDescription class methodsFor:'primitives'!
 
 xftAvailable
-%{
-#ifdef XFT
-    RETURN ( true )
-#endif
-%}.
-    ^ false
+    <resource: #obsolete>
+
+    ^ ConfigurableFeatures hasXFT
 
     "Created: / 20-12-2013 / 21:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 22-02-2016 / 08:15:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !XftFontDescription class methodsFor:'queries'!
@@ -720,7 +721,7 @@
 primitiveFailed
     <resource: #skipInDebuggersWalkBack>
 
-    self class xftAvailable ifFalse:[
+    ConfigurableFeatures hasXFT ifFalse:[
         super primitiveFailed:'Xft support is not configured'.
     ].
     super primitiveFailed
@@ -729,7 +730,7 @@
 primitiveFailed:errorString
     <resource: #skipInDebuggersWalkBack>
 
-    self class xftAvailable ifFalse:[
+    ConfigurableFeatures hasXFT ifFalse:[
         super primitiveFailed:'Xft support is not configured'.
     ].
     super primitiveFailed:errorString
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions.st	Mon Feb 22 08:41:04 2016 +0000
@@ -0,0 +1,34 @@
+"{ Package: 'stx:libview' }"!
+
+!ConfigurableFeatures class methodsFor:'queries-features'!
+
+hasFontConfig
+%{
+#if defined(HAVE_FONTCONFIG)
+    RETURN ( true );
+#endif	
+%}.
+    ^ false
+
+    "Created: / 22-02-2016 / 08:08:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ConfigurableFeatures class methodsFor:'queries-features'!
+
+hasXFT
+%{
+#if defined(HAVE_FONTCONFIG) && defined(XFT)
+    RETURN ( true );
+#endif	
+%}.
+    ^ false
+
+    "Created: / 22-02-2016 / 08:08:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!stx_libview class methodsFor:'documentation'!
+
+extensionsVersion_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
--- a/libInit.cc	Wed Feb 17 19:33:09 2016 +0000
+++ b/libInit.cc	Mon Feb 22 08:41:04 2016 +0000
@@ -106,6 +106,6 @@
 _WinWorkstation_Init(pass,__pRT__,snd);
 #endif /* WIN32 */
 
-
+_stx_137libview_extensions_Init(pass,__pRT__,snd);
 __END_PACKAGE__();
 }
--- a/stx_libview.st	Wed Feb 17 19:33:09 2016 +0000
+++ b/stx_libview.st	Mon Feb 22 08:41:04 2016 +0000
@@ -487,6 +487,8 @@
      A correponding method with real names must be present in my concrete subclasses"
 
     ^ #(
+        'ConfigurableFeatures class' hasFontConfig
+        'ConfigurableFeatures class' hasXFT
     )
 ! !