[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.5, 1.6 FontExtents.cs, 1
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.5, 1.6 FontExtents.cs, 1.2, 1.3 Xlib.cs.in, 1.18, 1.19 XsharpSupport.c, 1.25, 1.26 |
Date: |
Sun, 30 Nov 2003 07:10:18 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv22067/Xsharp
Modified Files:
Font.cs FontExtents.cs Xlib.cs.in XsharpSupport.c
Log Message:
Rearrange Xsharp font handling into three separate rendering systems:
font set, font struct, and Xft.
Index: FontExtents.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/FontExtents.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FontExtents.cs 7 Jun 2003 09:59:18 -0000 1.2
--- FontExtents.cs 30 Nov 2003 07:10:16 -0000 1.3
***************
*** 38,64 ****
// Constructor.
! internal FontExtents(Font font, IntPtr fontSet)
{
! XRectangle max_ink;
! XRectangle max_logical;
!
! // Get the extent information for the font.
! Xlib.XSharpFontExtents(fontSet, out max_ink,
out max_logical);
!
! // Convert the extent information into values
that make sense.
! ascent = -(max_logical.y);
! descent = max_logical.height + max_logical.y;
! maxWidth = max_logical.width;
!
! // Increase the descent to account for
underlining.
! // We always draw the underline two pixels below
! // the font base line.
! if((font.Style & FontStyle.Underlined) != 0)
! {
! if(descent < 3)
! {
! descent = 3;
! }
! }
}
--- 38,46 ----
// Constructor.
! internal FontExtents(int ascent, int descent, int maxWidth)
{
! this.ascent = ascent;
! this.descent = descent;
! this.maxWidth = maxWidth;
}
Index: XsharpSupport.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpSupport.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** XsharpSupport.c 29 Nov 2003 10:34:54 -0000 1.25
--- XsharpSupport.c 30 Nov 2003 07:10:16 -0000 1.26
***************
*** 100,145 ****
#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.
*/
! static XFontSet TryCreateFont(Display *dpy, const char *family,
! int pointSize, int
style)
{
XFontSet fontSet;
--- 100,122 ----
#define FontStyle_Underline 4
#define FontStyle_StrikeOut 8
! #define FontStyle_FontStruct 0x80
/*
! * Determine if we can use the Xft extension.
*/
! int XSharpUseXft()
{
! #ifdef USE_XFT_EXTENSION
! return 1;
! #else
! return 0;
! #endif
}
/*
* Try to create a font with specific parameters.
*/
! static void *TryCreateFont(Display *dpy, const char *family,
! int pointSize, int style)
{
XFontSet fontSet;
***************
*** 189,193 ****
/* Use the Latin1 XFontStruct creation method if requested */
! if((style & FontStyle_Latin1) != 0)
{
XFontStruct *fs;
--- 166,170 ----
/* Use the Latin1 XFontStruct creation method if requested */
! if((style & FontStyle_FontStruct) != 0)
{
XFontStruct *fs;
***************
*** 196,200 ****
{
free(name);
! return FontStructToSet(fs);
}
else
--- 173,177 ----
{
free(name);
! return (void *)fs;
}
else
***************
*** 214,218 ****
{
free(name);
! return fontSet;
}
/* TODO: process the missing charsets */
--- 191,195 ----
{
free(name);
! return (void *)fontSet;
}
/* TODO: process the missing charsets */
***************
*** 223,233 ****
}
! #endif /* USE_XFT_EXTENSION */
/*
! * Create a font from a description.
*/
! void *XSharpCreateFont(Display *dpy, const char *family,
! int pointSize, int style)
{
#ifdef USE_XFT_EXTENSION
--- 200,260 ----
}
! /*
! * Create a font set from a description.
! */
! void *XSharpCreateFontSet(Display *dpy, const char *family,
! int pointSize, int style)
! {
! XFontSet fontSet;
! int structStyle = (style & FontStyle_FontStruct);
!
! /* Try with the actual parameters first */
! fontSet = TryCreateFont(dpy, family, pointSize, style);
! if(fontSet)
! {
! return fontSet;
! }
!
! /* Remove the style, but keep the family */
! fontSet = TryCreateFont(dpy, family, pointSize,
! FontStyle_Normal |
structStyle);
! if(fontSet)
! {
! return fontSet;
! }
!
! /* Remove the family, but keep the style */
! fontSet = TryCreateFont(dpy, 0, pointSize, style);
! if(fontSet)
! {
! return fontSet;
! }
!
! /* Remove the point size and the style, but keep the family */
! fontSet = TryCreateFont(dpy, family, -1, FontStyle_Normal |
structStyle);
! if(fontSet)
! {
! return fontSet;
! }
!
! /* Remove everything - this will succeed unless X has no fonts at all!
*/
! return TryCreateFont(dpy, 0, -1, FontStyle_Normal | structStyle);
! }
/*
! * Create a font struct from a description.
*/
! void *XSharpCreateFontStruct(Display *dpy, const char *family,
! int pointSize, int style)
! {
! return XSharpCreateFontSet(dpy, family, pointSize,
! style |
FontStyle_FontStruct);
! }
!
! /*
! * Create an Xft font from a description.
! */
! void *XSharpCreateFontXft(Display *dpy, const char *family,
! int pointSize, int style)
{
#ifdef USE_XFT_EXTENSION
***************
*** 284,377 ****
#else /* !USE_XFT_EXTENSION */
! 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);
! if(fontSet)
{
! return fontSet;
}
!
! /* Remove the style, but keep the family */
! fontSet = TryCreateFont(dpy, family, pointSize, FontStyle_Normal);
! if(fontSet)
{
! return fontSet;
}
!
! /* Remove the family, but keep the style */
! fontSet = TryCreateFont(dpy, 0, pointSize, style);
! if(fontSet)
{
! return fontSet;
}
! /* Remove the point size and the style, but keep the family */
! fontSet = TryCreateFont(dpy, family, -1, FontStyle_Normal);
! if(fontSet)
{
! return fontSet;
}
-
- /* Remove everything - this will succeed unless X has no fonts at all!
*/
- return TryCreateFont(dpy, 0, -1, FontStyle_Normal);
-
- #endif
}
/*
! * Free a font set.
*/
! void XSharpFreeFont(Display *dpy, void *fontSet)
{
! #ifdef USE_XFT_EXTENSION
! XftFontClose(dpy, (XftFont *)fontSet);
! #else
! if(FontSetIsStruct(fontSet))
{
! XFreeFont(dpy, FontSetToStruct(fontSet));
}
else
{
! XFreeFontSet(dpy, (XFontSet)fontSet);
}
- #endif
- }
! /*
! * Forward declaration.
! */
! void XSharpTextExtents(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle *overall_logical_return);
/*
! * Draw a string using a font set.
*/
! void XSharpDrawString(Display *dpy, Drawable drawable, GC gc,
! void *fontSet, int x, int y,
! const char *str, int style, Region
clipRegion,
! unsigned long colorValue)
{
XRectangle overall_ink_return;
XRectangle overall_logical_return;
- #ifdef USE_XFT_EXTENSION
XftDraw *draw;
XftColor color;
XGCValues values;
- #else
- XFontSetExtents *extents;
- XFontStruct *fs = 0;
- #endif
int line1, line2;
- #ifdef USE_XFT_EXTENSION
-
/* TODO: 16-bit fonts */
--- 311,492 ----
#else /* !USE_XFT_EXTENSION */
! /* Don't have Xft support on this platform */
! return 0;
! #endif /* !USE_XFT_EXTENSION */
! }
!
! /*
! * Free a font set.
! */
! void XSharpFreeFontSet(Display *dpy, void *fontSet)
! {
! XFreeFontSet(dpy, (XFontSet)fontSet);
! }
!
! /*
! * Free a font struct.
! */
! void XSharpFreeFontStruct(Display *dpy, void *fontSet)
! {
! XFreeFont(dpy, (XFontStruct *)fontSet);
! }
!
! /*
! * Free an Xft font.
! */
! void XSharpFreeFont(Display *dpy, void *fontSet)
! {
! #ifdef USE_XFT_EXTENSION
! XftFontClose(dpy, (XftFont *)fontSet);
! #endif
! }
!
! /*
! * Forward declarations.
! */
! void XSharpTextExtentsSet(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return);
! void XSharpTextExtentsStruct(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return);
! void XSharpTextExtentsXft(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return);
!
! /*
! * Draw a string using a font set.
! */
! void XSharpDrawStringSet(Display *dpy, Drawable drawable, GC gc,
! void *fontSet, int x, int y,
! const char *str, int style, Region
clipRegion,
! unsigned long colorValue)
! {
! XRectangle overall_ink_return;
! XRectangle overall_logical_return;
! XFontSetExtents *extents;
! int line1, line2;
!
! /* Draw the string using the core API */
! XmbDrawString(dpy, drawable, (XFontSet)fontSet, gc, x, y,
! str, strlen(str));
!
! /* Calculate the positions of the underline and strike-out */
! if((style & FontStyle_Underline) != 0)
{
! line1 = y + 2;
}
! else
{
! line1 = y;
}
! if((style & FontStyle_StrikeOut) != 0)
{
! extents = XExtentsOfFontSet((XFontSet)fontSet);
! if(extents)
! {
! line2 = y + (extents->max_logical_extent.y / 2);
! }
! else
! {
! line2 = y;
! }
}
! else
{
! line2 = y;
}
! /* Draw the underline and strike-out */
! if(line1 != y || line2 != y)
{
! XSharpTextExtentsSet(dpy, fontSet, str,
! &overall_ink_return,
&overall_logical_return);
! XSetLineAttributes(dpy, gc, 1, LineSolid, CapNotLast,
JoinMiter);
! if(line1 != y)
! {
! XDrawLine(dpy, drawable, gc, x, line1,
! x + overall_logical_return.width,
line1);
! }
! if(line2 != y)
! {
! XDrawLine(dpy, drawable, gc, x, line2,
! x + overall_logical_return.width,
line2);
! }
}
}
/*
! * Draw a string using a font struct.
*/
! void XSharpDrawStringStruct(Display *dpy, Drawable drawable, GC gc,
! void *fontSet, int x, int y,
! const char *str, int style,
Region clipRegion,
! unsigned long colorValue)
{
! XRectangle overall_ink_return;
! XRectangle overall_logical_return;
! XFontStruct *fs = (XFontStruct *)fontSet;
! int line1, line2;
!
! /* Draw the string using the core API */
! XSetFont(dpy, gc, fs->fid);
! XDrawString(dpy, drawable, gc, x, y, str, strlen(str));
!
! /* Calculate the positions of the underline and strike-out */
! if((style & FontStyle_Underline) != 0)
{
! line1 = y + 2;
}
else
{
! line1 = y;
! }
! if((style & FontStyle_StrikeOut) != 0)
! {
! line2 = y - (fs->ascent / 2);
! }
! else
! {
! line2 = y;
}
! /* Draw the underline and strike-out */
! if(line1 != y || line2 != y)
! {
! XSharpTextExtentsStruct(dpy, fontSet, str,
! &overall_ink_return,
&overall_logical_return);
! XSetLineAttributes(dpy, gc, 1, LineSolid, CapNotLast,
JoinMiter);
! if(line1 != y)
! {
! XDrawLine(dpy, drawable, gc, x, line1,
! x + overall_logical_return.width,
line1);
! }
! if(line2 != y)
! {
! XDrawLine(dpy, drawable, gc, x, line2,
! x + overall_logical_return.width,
line2);
! }
! }
! }
/*
! * Draw a string using an Xft font.
*/
! void XSharpDrawStringXft(Display *dpy, Drawable drawable, GC gc,
! void *fontSet, int x, int y,
! const char *str, int style, Region
clipRegion,
! unsigned long colorValue)
{
+ #ifdef USE_XFT_EXTENSION
+
XRectangle overall_ink_return;
XRectangle overall_logical_return;
XftDraw *draw;
XftColor color;
XGCValues values;
int line1, line2;
/* TODO: 16-bit fonts */
***************
*** 399,419 ****
}
- #else
-
- /* 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
-
/* Calculate the positions of the underline and strike-out */
if((style & FontStyle_Underline) != 0)
--- 514,517 ----
***************
*** 427,450 ****
if((style & FontStyle_StrikeOut) != 0)
{
- #ifdef USE_XFT_EXTENSION
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
}
else
--- 525,529 ----
***************
*** 456,461 ****
if(line1 != y || line2 != y)
{
! XSharpTextExtents(dpy, fontSet, str,
! &overall_ink_return,
&overall_logical_return);
XSetLineAttributes(dpy, gc, 1, LineSolid, CapNotLast,
JoinMiter);
if(line1 != y)
--- 535,540 ----
if(line1 != y || line2 != y)
{
! XSharpTextExtentsXft(dpy, fontSet, str,
! &overall_ink_return,
&overall_logical_return);
XSetLineAttributes(dpy, gc, 1, LineSolid, CapNotLast,
JoinMiter);
if(line1 != y)
***************
*** 470,481 ****
}
}
}
/*
! * Calculate the extent information for a string.
*/
! void XSharpTextExtents(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle *overall_logical_return)
{
#ifdef USE_XFT_EXTENSION
--- 549,593 ----
}
}
+ #endif /* USE_XFT_EXTENSION */
}
/*
! * Calculate the extent information for a string in a font set.
*/
! void XSharpTextExtentsSet(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return)
! {
! XmbTextExtents((XFontSet)fontSet, str, strlen(str),
! overall_ink_return, overall_logical_return);
! }
!
! /*
! * Calculate the extent information for a string in a font struct.
! */
! void XSharpTextExtentsStruct(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return)
! {
! int direction, ascent, descent;
! XCharStruct overall;
! XTextExtents((XFontStruct *)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;
! }
!
! /*
! * Calculate the extent information for a string in an Xft font.
! */
! void XSharpTextExtentsXft(Display *dpy, void *fontSet, const char *str,
! XRectangle *overall_ink_return,
! XRectangle
*overall_logical_return)
{
#ifdef USE_XFT_EXTENSION
***************
*** 496,529 ****
overall_logical_return->height = extents.y + extents.yOff;
! #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
}
/*
! * Calculate the extent information for a font.
*/
! void XSharpFontExtents(void *fontSet,
! XRectangle *max_ink_return,
! XRectangle *max_logical_return)
{
#ifdef USE_XFT_EXTENSION
--- 608,656 ----
overall_logical_return->height = extents.y + extents.yOff;
! #endif
! }
!
! /*
! * Calculate the extent information for a font set.
! */
! void XSharpFontExtentsSet(void *fontSet,
! XRectangle *max_ink_return,
! XRectangle *max_logical_return)
! {
! XFontSetExtents *extents;
! extents = XExtentsOfFontSet((XFontSet)fontSet);
! if(extents)
{
! *max_ink_return = extents->max_ink_extent;
! *max_logical_return = extents->max_logical_extent;
}
}
/*
! * Calculate the extent information for a font struct.
*/
! void XSharpFontExtentsStruct(void *fontSet,
! XRectangle *max_ink_return,
! XRectangle *max_logical_return)
! {
! XFontStruct *fs = (XFontStruct *)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;
! }
!
! /*
! * Calculate the extent information for an Xft font.
! */
! void XSharpFontExtentsXft(void *fontSet,
! XRectangle *max_ink_return,
! XRectangle *max_logical_return)
{
#ifdef USE_XFT_EXTENSION
***************
*** 537,567 ****
*max_ink_return = *max_logical_return;
- #else
-
- 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;
- }
- }
-
#endif
}
--- 664,667 ----
***************
*** 1389,1393 ****
}
! void *XSharpCreateFont(void *dpy, const char *family, int pointSize, int
style)
{
/* Nothing to do here */
--- 1489,1493 ----
}
! int XSharpUseXft()
{
/* Nothing to do here */
***************
*** 1395,1421 ****
}
! void XSharpFreeFont(void *dpy, void *fontSet)
{
/* Nothing to do here */
}
! void XSharpDrawString(void *dpy, unsigned long drawable, void *gc,
! void *fontSet, int x, int y,
! const char *str, int style, void
*clipRegion,
! unsigned long colorValue)
{
/* Nothing to do here */
}
! void XSharpTextExtents(void *dpy, void *fontSet, const char *str,
! void *overall_ink_return,
! void *overall_logical_return)
{
/* Nothing to do here */
}
! void XSharpFontExtents(void *fontSet,
! void *max_ink_return,
! void *max_logical_return)
{
/* Nothing to do here */
--- 1495,1596 ----
}
! void *XSharpCreateFontSet(void *dpy, const char *family,
! int pointSize, int style)
{
/* Nothing to do here */
+ return 0;
}
! void XSharpFreeFontSet(void *dpy, void *fontSet)
{
/* Nothing to do here */
}
! void XSharpDrawStringSet(void *dpy, unsigned long drawable, void *gc,
! void *fontSet, int x, int y,
! const char *str, int style, void
*clipRegion,
! unsigned long colorValue)
{
/* Nothing to do here */
}
! void XSharpTextExtentsSet(void *dpy, void *fontSet, const char *str,
! void *overall_ink_return,
! void *overall_logical_return)
! {
! /* Nothing to do here */
! }
!
! void XSharpFontExtentsSet(void *fontSet,
! void *max_ink_return,
! void *max_logical_return)
! {
! /* Nothing to do here */
! }
!
! void *XSharpCreateFontStruct(void *dpy, const char *family,
! int pointSize, int
style)
! {
! /* Nothing to do here */
! return 0;
! }
!
! void XSharpFreeFontStruct(void *dpy, void *fontSet)
! {
! /* Nothing to do here */
! }
!
! void XSharpDrawStringStruct(void *dpy, unsigned long drawable, void *gc,
! void *fontSet, int x, int y,
! const char *str, int style,
void *clipRegion,
! unsigned long colorValue)
! {
! /* Nothing to do here */
! }
!
! void XSharpTextExtentsStruct(void *dpy, void *fontSet, const char *str,
! void *overall_ink_return,
! void *overall_logical_return)
! {
! /* Nothing to do here */
! }
!
! void XSharpFontExtentsStruct(void *fontSet,
! void *max_ink_return,
! void *max_logical_return)
! {
! /* Nothing to do here */
! }
!
! void *XSharpCreateFontXft(void *dpy, const char *family,
! int pointSize, int style)
! {
! /* Nothing to do here */
! return 0;
! }
!
! void XSharpFreeFontXft(void *dpy, void *fontSet)
! {
! /* Nothing to do here */
! }
!
! void XSharpDrawStringXft(void *dpy, unsigned long drawable, void *gc,
! void *fontSet, int x, int y,
! const char *str, int style, void
*clipRegion,
! unsigned long colorValue)
! {
! /* Nothing to do here */
! }
!
! void XSharpTextExtentsXft(void *dpy, void *fontSet, const char *str,
! void *overall_ink_return,
! void *overall_logical_return)
! {
! /* Nothing to do here */
! }
!
! void XSharpFontExtentsXft(void *fontSet,
! void *max_ink_return,
! void *max_logical_return)
{
/* Nothing to do here */
Index: Font.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Font.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Font.cs 30 Nov 2003 05:41:31 -0000 1.5
--- Font.cs 30 Nov 2003 07:10:16 -0000 1.6
***************
*** 23,26 ****
--- 23,27 ----
using System;
+ using System.Text;
using Xsharp.Types;
***************
*** 42,50 ****
// Internal state.
! private String family;
! private int pointSize;
! private FontStyle style;
! private String xname;
! private FontInfo infoList;
/// <summary>
--- 43,51 ----
// Internal state.
! internal String family;
! internal int pointSize;
! internal FontStyle style;
! internal String xname;
! internal FontInfo infoList;
/// <summary>
***************
*** 203,206 ****
--- 204,226 ----
}
+ // Determine if we appear to be running in a Latin1 locale.
+ // We can optimize font handling a little if we are.
+ private static bool IsLatin1()
+ {
+ #if !ECMA_COMPAT
+ int codePage = Encoding.Default.WindowsCodePage;
+ #else
+ int codePage = Encoding.Default.GetHashCode();
+ #endif
+ if(codePage == 1252 || codePage == 28591)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
/// <summary>
/// <para>Constructs a new instance of <see cref="T:Xsharp.Font"/>.
***************
*** 231,235 ****
family = SansSerif;
}
! return new Font(family, pointSize, style);
}
--- 251,266 ----
family = SansSerif;
}
! if(Xlib.XSharpUseXft() != 0)
! {
! return new XftFont(family, pointSize,
style);
! }
! else if(IsLatin1())
! {
! return new FontStructFont(family,
pointSize, style);
! }
! else
! {
! return new Font(family, pointSize,
style);
! }
}
***************
*** 386,390 ****
{
IntPtr display = graphics.dpy.Lock();
! Xlib.XSharpTextExtents
(display, fontSet, str,
out overall_ink, out
overall_logical);
--- 417,421 ----
{
IntPtr display = graphics.dpy.Lock();
! Xlib.XSharpTextExtentsSet
(display, fontSet, str,
out overall_ink, out
overall_logical);
***************
*** 482,486 ****
{
IntPtr display = graphics.dpy.Lock();
! Xlib.XSharpDrawString
(display,
graphics.drawableHandle, graphics.gc,
fontSet, x, y, str,
(int)style,
--- 513,517 ----
{
IntPtr display = graphics.dpy.Lock();
! Xlib.XSharpDrawStringSet
(display,
graphics.drawableHandle, graphics.gc,
fontSet, x, y, str,
(int)style,
***************
*** 523,527 ****
// Normalize a point size to make it match a nearby X font size so
// that we don't get unsightly stretching.
! private static int NormalizePointSize(int pointSize)
{
if(pointSize < 90)
--- 554,558 ----
// Normalize a point size to make it match a nearby X font size so
// that we don't get unsightly stretching.
! internal static int NormalizePointSize(int pointSize)
{
if(pointSize < 90)
***************
*** 555,558 ****
--- 586,627 ----
}
+ // Create a native "font set" structure.
+ internal virtual IntPtr CreateFontSet
+ (IntPtr display, out int ascent, out int
descent,
+ out int maxWidth)
+ {
+ XRectangle max_ink;
+ XRectangle max_logical;
+ IntPtr fontSet;
+
+ // Create the raw X font set structure.
+ fontSet = Xlib.XSharpCreateFontSet
+ (display, family,
+ NormalizePointSize(pointSize),
(int)style);
+
+ // Get the extent information for the font.
+ Xlib.XSharpFontExtentsSet
+ (fontSet, out max_ink, out max_logical);
+
+ // Convert the extent information into values
that make sense.
+ ascent = -(max_logical.y);
+ descent = max_logical.height + max_logical.y;
+ maxWidth = max_logical.width;
+
+ // Increase the descent to account for
underlining.
+ // We always draw the underline two pixels below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 3)
+ {
+ descent = 3;
+ }
+ }
+
+ // Return the font set structure to the caller.
+ return fontSet;
+ }
+
// Get the XFontSet structure for this font on a particular display.
internal IntPtr GetFontSet(Display dpy)
***************
*** 588,597 ****
// Create a new font set.
IntPtr fontSet;
try
{
IntPtr display = dpy.Lock();
! fontSet = Xlib.XSharpCreateFont
! (display, family,
!
NormalizePointSize(pointSize), (int)style);
if(fontSet == IntPtr.Zero)
{
--- 657,666 ----
// Create a new font set.
IntPtr fontSet;
+ int ascent, descent, maxWidth;
try
{
IntPtr display = dpy.Lock();
! fontSet = CreateFontSet
! (display, out ascent,
out descent, out maxWidth);
if(fontSet == IntPtr.Zero)
{
***************
*** 608,612 ****
info = new FontInfo();
info.next = font.infoList;
! info.extents = new FontExtents(font,
fontSet);
info.dpy = dpy;
info.fontSet = fontSet;
--- 677,681 ----
info = new FontInfo();
info.next = font.infoList;
! info.extents = new FontExtents(ascent,
descent, maxWidth);
info.dpy = dpy;
info.fontSet = fontSet;
***************
*** 619,622 ****
--- 688,697 ----
}
+ // Free a native "font set" structure.
+ internal virtual void FreeFontSet(IntPtr display, IntPtr fontSet)
+ {
+ Xlib.XSharpFreeFontSet(display, fontSet);
+ }
+
// Disassociate this font from a particular display.
internal void Disassociate(Display dpy)
***************
*** 642,649 ****
infoList = info.next;
}
! Xlib.XSharpFreeFont(dpy.dpy,
info.fontSet);
}
}
}
} // class Font
--- 717,1040 ----
infoList = info.next;
}
! FreeFontSet(dpy.dpy,
info.fontSet);
}
}
}
+
+ // Font class that uses XFontStruct values instead of XFontSet values.
+ private class FontStructFont : Font
+ {
+ // Constructor.
+ public FontStructFont(String family, int pointSize, FontStyle
style)
+ : base(family, pointSize, style) {}
+
+ // Create a native "font set" structure.
+ internal override IntPtr CreateFontSet
+ (IntPtr display, out int ascent, out
int descent,
+ out int maxWidth)
+ {
+ XRectangle max_ink;
+ XRectangle max_logical;
+ IntPtr fontSet;
+
+ // Create the raw X font set structure.
+ fontSet = Xlib.XSharpCreateFontStruct
+ (display, family,
+ NormalizePointSize(pointSize),
(int)style);
+
+ // Get the extent information for the
font.
+ Xlib.XSharpFontExtentsStruct
+ (fontSet, out max_ink, out
max_logical);
+
+ // Convert the extent info into values
that make sense.
+ ascent = -(max_logical.y);
+ descent = max_logical.height +
max_logical.y;
+ maxWidth = max_logical.width;
+
+ // Increase the descent to account for
underlining.
+ // We always draw the underline two
pixels below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 3)
+ {
+ descent = 3;
+ }
+ }
+
+ // Return the font set structure to the
caller.
+ return fontSet;
+ }
+
+ // Free a native "font set" structure.
+ internal override void FreeFontSet(IntPtr display, IntPtr
fontSet)
+ {
+ Xlib.XSharpFreeFontStruct(display,
fontSet);
+ }
+
+ // Override the font drawing primitives.
+ public override void MeasureString
+ (Graphics graphics, String str, int
index, int count,
+ out int width, out int ascent, out int
descent)
+ {
+ // Validate the parameters.
+ if(graphics == null)
+ {
+ throw new
ArgumentNullException("graphics");
+ }
+ if(str == null || count == 0)
+ {
+ width = 0;
+ ascent = 0;
+ descent = 0;
+ return;
+ }
+
+ // Extract the substring to be measured.
+ // TODO: make this more efficient by
avoiding the data copy.
+ str = str.Substring(index, count);
+
+ // Get the font set to use to measure
the string.
+ IntPtr fontSet =
GetFontSet(graphics.dpy);
+ if(fontSet == IntPtr.Zero)
+ {
+ width = 0;
+ ascent = 0;
+ descent = 0;
+ return;
+ }
+
+ // Get the text extents and decode them
into useful values.
+ XRectangle overall_ink;
+ XRectangle overall_logical;
+ try
+ {
+ IntPtr display =
graphics.dpy.Lock();
+ Xlib.XSharpTextExtentsStruct
+ (display, fontSet, str,
+ out overall_ink, out
overall_logical);
+ }
+ finally
+ {
+ graphics.dpy.Unlock();
+ }
+ width = overall_logical.width;
+ ascent = -(overall_logical.y);
+ descent = overall_logical.height +
overall_logical.y;
+
+ // Increase the descent to account for
underlining.
+ // We always draw the underline two
pixels below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 3)
+ {
+ descent = 3;
+ }
+ }
+ }
+ public override void DrawString
+ (Graphics graphics, int x, int y,
+ String str, int index, int count)
+ {
+ // Validate the parameters.
+ if(x < -32768 || x > 32767 || y <
-32768 || y > 32767)
+ {
+ throw new
XException(S._("X_PointCoordRange"));
+ }
+ if(graphics == null)
+ {
+ throw new
ArgumentNullException("graphics");
+ }
+ if(str == null || count == 0)
+ {
+ return;
+ }
+
+ // Extract the substring to be measured.
+ // TODO: make this more efficient by
avoiding the data copy.
+ str = str.Substring(index, count);
+
+ // Get the font set to use for the font.
+ IntPtr fontSet =
GetFontSet(graphics.dpy);
+ if(fontSet == IntPtr.Zero)
+ {
+ return;
+ }
+
+ // Draw the string using the specified
font set.
+ try
+ {
+ IntPtr display =
graphics.dpy.Lock();
+ Xlib.XSharpDrawStringStruct
+ (display,
graphics.drawableHandle, graphics.gc,
+ fontSet, x, y,
str, (int)style,
+ IntPtr.Zero,
graphics.Foreground.value);
+ }
+ finally
+ {
+ graphics.dpy.Unlock();
+ }
+ }
+
+ } // class FontStructFont
+
+ // Font class that uses Xft to perform the rendering operations.
+ private class XftFont : Font
+ {
+ // Constructor.
+ public XftFont(String family, int pointSize, FontStyle style)
+ : base(family, pointSize, style) {}
+
+ // Create a native "font set" structure.
+ internal override IntPtr CreateFontSet
+ (IntPtr display, out int ascent, out
int descent,
+ out int maxWidth)
+ {
+ XRectangle max_ink;
+ XRectangle max_logical;
+ IntPtr fontSet;
+
+ // Create the raw X font set structure.
+ fontSet = Xlib.XSharpCreateFontXft
+ (display, family,
+ NormalizePointSize(pointSize),
(int)style);
+
+ // Get the extent information for the
font.
+ Xlib.XSharpFontExtentsXft
+ (fontSet, out max_ink, out
max_logical);
+
+ // Convert the extent info into values
that make sense.
+ ascent = -(max_logical.y);
+ descent = max_logical.height +
max_logical.y;
+ maxWidth = max_logical.width;
+
+ // Increase the descent to account for
underlining.
+ // We always draw the underline two
pixels below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 3)
+ {
+ descent = 3;
+ }
+ }
+
+ // Return the font set structure to the
caller.
+ return fontSet;
+ }
+
+ // Free a native "font set" structure.
+ internal override void FreeFontSet(IntPtr display, IntPtr
fontSet)
+ {
+ Xlib.XSharpFreeFontXft(display,
fontSet);
+ }
+
+ // Override the font drawing primitives.
+ public override void MeasureString
+ (Graphics graphics, String str, int
index, int count,
+ out int width, out int ascent, out int
descent)
+ {
+ // Validate the parameters.
+ if(graphics == null)
+ {
+ throw new
ArgumentNullException("graphics");
+ }
+ if(str == null || count == 0)
+ {
+ width = 0;
+ ascent = 0;
+ descent = 0;
+ return;
+ }
+
+ // Extract the substring to be measured.
+ // TODO: make this more efficient by
avoiding the data copy.
+ str = str.Substring(index, count);
+
+ // Get the font set to use to measure
the string.
+ IntPtr fontSet =
GetFontSet(graphics.dpy);
+ if(fontSet == IntPtr.Zero)
+ {
+ width = 0;
+ ascent = 0;
+ descent = 0;
+ return;
+ }
+
+ // Get the text extents and decode them
into useful values.
+ XRectangle overall_ink;
+ XRectangle overall_logical;
+ try
+ {
+ IntPtr display =
graphics.dpy.Lock();
+ Xlib.XSharpTextExtentsXft
+ (display, fontSet, str,
+ out overall_ink, out
overall_logical);
+ }
+ finally
+ {
+ graphics.dpy.Unlock();
+ }
+ width = overall_logical.width;
+ ascent = -(overall_logical.y);
+ descent = overall_logical.height +
overall_logical.y;
+
+ // Increase the descent to account for
underlining.
+ // We always draw the underline two
pixels below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 3)
+ {
+ descent = 3;
+ }
+ }
+ }
+ public override void DrawString
+ (Graphics graphics, int x, int y,
+ String str, int index, int count)
+ {
+ // Validate the parameters.
+ if(x < -32768 || x > 32767 || y <
-32768 || y > 32767)
+ {
+ throw new
XException(S._("X_PointCoordRange"));
+ }
+ if(graphics == null)
+ {
+ throw new
ArgumentNullException("graphics");
+ }
+ if(str == null || count == 0)
+ {
+ return;
+ }
+
+ // Extract the substring to be measured.
+ // TODO: make this more efficient by
avoiding the data copy.
+ str = str.Substring(index, count);
+
+ // Get the font set to use for the font.
+ IntPtr fontSet =
GetFontSet(graphics.dpy);
+ if(fontSet == IntPtr.Zero)
+ {
+ return;
+ }
+
+ // Draw the string using the specified
font set.
+ try
+ {
+ IntPtr display =
graphics.dpy.Lock();
+ Xlib.XSharpDrawStringXft
+ (display,
graphics.drawableHandle, graphics.gc,
+ fontSet, x, y,
str, (int)style,
+ IntPtr.Zero,
graphics.Foreground.value);
+ }
+ finally
+ {
+ graphics.dpy.Unlock();
+ }
+ }
+
+ } // class XftFont
} // class Font
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** Xlib.cs.in 29 Nov 2003 10:34:54 -0000 1.18
--- Xlib.cs.in 30 Nov 2003 07:10:16 -0000 1.19
***************
*** 535,546 ****
[DllImport("XsharpSupport")]
! extern public static IntPtr XSharpCreateFont
(IntPtr display, String family, @X_int@ pointSize,
@X_int@ style);
[DllImport("XsharpSupport")]
! extern public static void XSharpFreeFont(IntPtr display, IntPtr
fontSet);
[DllImport("XsharpSupport")]
! extern public static void XSharpDrawString
(IntPtr display, Drawable drawable, IntPtr gc,
IntPtr fontSet, @X_int@ x, @X_int@ y,
--- 535,550 ----
[DllImport("XsharpSupport")]
! extern public static @X_int@ XSharpUseXft();
!
! [DllImport("XsharpSupport")]
! extern public static IntPtr XSharpCreateFontXft
(IntPtr display, String family, @X_int@ pointSize,
@X_int@ style);
[DllImport("XsharpSupport")]
! extern public static void XSharpFreeFontXft
! (IntPtr display, IntPtr fontSet);
[DllImport("XsharpSupport")]
! extern public static void XSharpDrawStringXft
(IntPtr display, Drawable drawable, IntPtr gc,
IntPtr fontSet, @X_int@ x, @X_int@ y,
***************
*** 549,553 ****
[DllImport("XsharpSupport")]
! extern public static void XSharpTextExtents
(IntPtr display, IntPtr fontSet, String str,
out XRectangle overall_ink_return,
--- 553,557 ----
[DllImport("XsharpSupport")]
! extern public static void XSharpTextExtentsXft
(IntPtr display, IntPtr fontSet, String str,
out XRectangle overall_ink_return,
***************
*** 555,559 ****
[DllImport("XsharpSupport")]
! extern public static void XSharpFontExtents
(IntPtr fontSet,
out XRectangle max_ink_return,
--- 559,617 ----
[DllImport("XsharpSupport")]
! extern public static void XSharpFontExtentsXft
! (IntPtr fontSet,
! out XRectangle max_ink_return,
! out XRectangle max_logical_return);
!
! [DllImport("XsharpSupport")]
! extern public static IntPtr XSharpCreateFontSet
! (IntPtr display, String family, @X_int@ pointSize,
@X_int@ style);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpFreeFontSet
! (IntPtr display, IntPtr fontSet);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpDrawStringSet
! (IntPtr display, Drawable drawable, IntPtr gc,
! IntPtr fontSet, @X_int@ x, @X_int@ y,
! String str, @X_int@ style, IntPtr clipRegion,
! @X_ulong@ colorValue);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpTextExtentsSet
! (IntPtr display, IntPtr fontSet, String str,
! out XRectangle overall_ink_return,
! out XRectangle overall_logical_return);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpFontExtentsSet
! (IntPtr fontSet,
! out XRectangle max_ink_return,
! out XRectangle max_logical_return);
!
! [DllImport("XsharpSupport")]
! extern public static IntPtr XSharpCreateFontStruct
! (IntPtr display, String family, @X_int@ pointSize,
@X_int@ style);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpFreeFontStruct
! (IntPtr display, IntPtr fontSet);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpDrawStringStruct
! (IntPtr display, Drawable drawable, IntPtr gc,
! IntPtr fontSet, @X_int@ x, @X_int@ y,
! String str, @X_int@ style, IntPtr clipRegion,
! @X_ulong@ colorValue);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpTextExtentsStruct
! (IntPtr display, IntPtr fontSet, String str,
! out XRectangle overall_ink_return,
! out XRectangle overall_logical_return);
!
! [DllImport("XsharpSupport")]
! extern public static void XSharpFontExtentsStruct
(IntPtr fontSet,
out XRectangle max_ink_return,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.5, 1.6 FontExtents.cs, 1.2, 1.3 Xlib.cs.in, 1.18, 1.19 XsharpSupport.c, 1.25, 1.26,
Rhys Weatherley <address@hidden> <=