dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/Xsharp XsharpSupport.c,1.23,1.24


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/Xsharp XsharpSupport.c,1.23,1.24
Date: Sat, 29 Nov 2003 00:49:15 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv24662/Xsharp

Modified Files:
        XsharpSupport.c 
Log Message:


Implement a special case for Latin1 locales to use XFontStruct-based
fonts rather than XFontSet-based fonts.  This should give better performance
on some X systems.


Index: XsharpSupport.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpSupport.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** XsharpSupport.c     26 Nov 2003 09:01:38 -0000      1.23
--- XsharpSupport.c     29 Nov 2003 00:49:13 -0000      1.24
***************
*** 95,102 ****
--- 95,136 ----
  #define       FontStyle_Underline             4
  #define       FontStyle_StrikeOut             8
+ #define       FontStyle_Latin1                0x80
  
  #ifndef USE_XFT_EXTENSION
  
  /*
+  * Determine if the locale looks like Latin1, which we can optimize
+  * by using the XFontStruct version of a font, not the XFontSet version.
+  */
+ static int IsLatin1Locale(void)
+ {
+       char *env = getenv("LANG");
+       if(!env || !strcmp(env, "C") || !strcmp(env, "en_US"))
+       {
+               return 1;
+       }
+       else
+       {
+               return 0;
+       }
+ }
+ 
+ /*
+  * Convert an XFontStruct pointer into an XFontSet.
+  */
+ #define       FontStructToSet(ptr)    ((XFontSet)(((unsigned long)(ptr)) | 1))
+ 
+ /*
+  * Convert an XFontSet into an XFontStruct pointer.
+  */
+ #define       FontSetToStruct(ptr)    \
+                       ((XFontStruct *)(((unsigned long)(ptr)) & ~((unsigned 
long)1)))
+ 
+ /*
+  * Determine if an XFontSet pointer is actually an XFontStruct.
+  */
+ #define       FontSetIsStruct(ptr)    ((((unsigned long)(ptr)) & 1) != 0)
+ 
+ /*
   * Try to create a font with specific parameters.
   */
***************
*** 149,152 ****
--- 183,203 ----
        }
  
+       /* Use the Latin1 XFontStruct creation method if requested */
+       if((style & FontStyle_Latin1) != 0)
+       {
+               XFontStruct *fs;
+               fs = XLoadQueryFont(dpy, name);
+               if(fs)
+               {
+                       free(name);
+                       return FontStructToSet(fs);
+               }
+               else
+               {
+                       free(name);
+                       return 0;
+               }
+       }
+ 
        /* Try to create the font set using just the base name */
        missingCharsets = 0;
***************
*** 230,233 ****
--- 281,290 ----
        XFontSet fontSet;
  
+       /* Force creation of a Latin1 XFontStruct if necessary */
+       if(IsLatin1Locale())
+       {
+               style |= FontStyle_Latin1;
+       }
+ 
        /* Try with the actual parameters first */
        fontSet = TryCreateFont(dpy, family, pointSize, style);
***************
*** 272,276 ****
        XftFontClose(dpy, (XftFont *)fontSet);
  #else
!       XFreeFontSet(dpy, (XFontSet)fontSet);
  #endif
  }
--- 329,340 ----
        XftFontClose(dpy, (XftFont *)fontSet);
  #else
!       if(FontSetIsStruct(fontSet))
!       {
!               XFreeFont(dpy, FontSetToStruct(fontSet));
!       }
!       else
!       {
!               XFreeFontSet(dpy, (XFontSet)fontSet);
!       }
  #endif
  }
***************
*** 299,302 ****
--- 363,367 ----
  #else
        XFontSetExtents *extents;
+       XFontStruct *fs = 0;
  #endif
        int line1, line2;
***************
*** 332,337 ****
  
        /* Draw the string using the core API */
!       XmbDrawString(dpy, drawable, (XFontSet)fontSet, gc, x, y,
!                                 str, strlen(str));
  
  #endif
--- 397,411 ----
  
        /* Draw the string using the core API */
!       if(FontSetIsStruct(fontSet))
!       {
!               fs = FontSetToStruct(fontSet);
!               XSetFont(dpy, gc, fs->fid);
!               XDrawString(dpy, drawable, gc, x, y, str, strlen(str));
!       }
!       else
!       {
!               XmbDrawString(dpy, drawable, (XFontSet)fontSet, gc, x, y,
!                                         str, strlen(str));
!       }
  
  #endif
***************
*** 351,362 ****
                line2 = y + (((XftFont *)fontSet)->height / 2);
        #else
!               extents = XExtentsOfFontSet(fontSet);
!               if(extents)
                {
!                       line2 = y + (extents->max_logical_extent.y / 2);
                }
                else
                {
!                       line2 = y;
                }
        #endif
--- 425,443 ----
                line2 = y + (((XftFont *)fontSet)->height / 2);
        #else
!               if(FontSetIsStruct(fontSet))
                {
!                       line2 = y - (fs->ascent / 2);
                }
                else
                {
!                       extents = XExtentsOfFontSet(fontSet);
!                       if(extents)
!                       {
!                               line2 = y + (extents->max_logical_extent.y / 2);
!                       }
!                       else
!                       {
!                               line2 = y;
!                       }
                }
        #endif
***************
*** 411,416 ****
  
  #else
!       XmbTextExtents((XFontSet)fontSet, str, strlen(str),
!                                  overall_ink_return, overall_logical_return);
  #endif
  }
--- 492,515 ----
  
  #else
!       if(FontSetIsStruct(fontSet))
!       {
!               int direction, ascent, descent;
!               XCharStruct overall;
!               XTextExtents(FontSetToStruct(fontSet), str, strlen(str),
!                                        &direction, &ascent, &descent, 
&overall);
!               overall_ink_return->x = overall.lbearing;
!               overall_ink_return->y = -(overall.ascent);
!               overall_ink_return->width = overall.rbearing - overall.lbearing;
!               overall_ink_return->height = overall.ascent + overall.descent;
!               overall_logical_return->x = 0;
!               overall_logical_return->y = -ascent;
!               overall_logical_return->width = overall.width;
!               overall_logical_return->height = ascent + descent;
!       }
!       else
!       {
!               XmbTextExtents((XFontSet)fontSet, str, strlen(str),
!                                          overall_ink_return, 
overall_logical_return);
!       }
  #endif
  }
***************
*** 436,444 ****
  
        XFontSetExtents *extents;
!       extents = XExtentsOfFontSet((XFontSet)fontSet);
!       if(extents)
        {
!               *max_ink_return = extents->max_ink_extent;
!               *max_logical_return = extents->max_logical_extent;
        }
  
--- 535,560 ----
  
        XFontSetExtents *extents;
!       if(FontSetIsStruct(fontSet))
        {
!               XFontStruct *fs = FontSetToStruct(fontSet);
!               max_ink_return->x = fs->min_bounds.lbearing;
!               max_ink_return->y = -(fs->max_bounds.ascent);
!               max_ink_return->width =
!                       fs->max_bounds.rbearing - fs->min_bounds.lbearing;
!               max_ink_return->height =
!                       fs->max_bounds.ascent + fs->max_bounds.descent;
!               max_logical_return->x = 0;
!               max_logical_return->y = -(fs->ascent);
!               max_logical_return->width = fs->max_bounds.width;
!               max_logical_return->height = fs->ascent + fs->descent;
!       }
!       else
!       {
!               extents = XExtentsOfFontSet((XFontSet)fontSet);
!               if(extents)
!               {
!                       *max_ink_return = extents->max_ink_extent;
!                       *max_logical_return = extents->max_logical_extent;
!               }
        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]