[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.6, 1.7 Xlib.cs.in, 1.19,
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.6, 1.7 Xlib.cs.in, 1.19, 1.20 XsharpSupport.c, 1.26, 1.27 |
Date: |
Sun, 30 Nov 2003 09:40:57 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv6001/Xsharp
Modified Files:
Font.cs Xlib.cs.in XsharpSupport.c
Log Message:
Modify the font struct based rendering system to directly access
the contents of a "System.String" value for measuring and drawing,
rather than requiring PInvoke to copy and convert the string.
Index: XsharpSupport.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpSupport.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** XsharpSupport.c 30 Nov 2003 07:10:16 -0000 1.26
--- XsharpSupport.c 30 Nov 2003 09:40:55 -0000 1.27
***************
*** 103,106 ****
--- 103,136 ----
/*
+ * Structure of Portable.NET's "System.String" object for direct
+ * access to the Unicode contents, bypassing PInvoke string conversion.
+ *
+ * Use the "ILStringLength" and "ILStringToBuffer" macros, so that
+ * 32-bit vs 64-bit system differences are properly dealt with.
+ */
+ typedef unsigned short ILChar;
+ typedef struct _tagILString ILString;
+ typedef struct
+ {
+ int capacity;
+ int length;
+
+ } System_String_int;
+ typedef struct
+ {
+ long capacity;
+ long length;
+
+ } System_String_long;
+ #define ILStringLength(str) \
+ (sizeof(int) == 4 \
+ ? ((System_String_int *)(str))->length \
+ : ((System_String_long *)(str))->length)
+ #define ILStringToBuffer(str) \
+ (sizeof(int) == 4 \
+ ? (ILChar *)(((System_String_int *)(str)) + 1) \
+ : (ILChar *)(((System_String_long *)(str)) + 1))
+
+ /*
* Determine if we can use the Xft extension.
*/
***************
*** 349,354 ****
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,
--- 379,385 ----
XRectangle *overall_ink_return,
XRectangle
*overall_logical_return);
! void XSharpTextExtentsStruct(Display *dpy, void *fontSet,
! ILString *str, long offset,
long count,
! XRectangle
*overall_ink_return,
XRectangle
*overall_logical_return);
void XSharpTextExtentsXft(Display *dpy, void *fontSet, const char *str,
***************
*** 361,366 ****
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;
--- 392,396 ----
void XSharpDrawStringSet(Display *dpy, Drawable drawable, GC gc,
void *fontSet, int x, int y,
! const char *str, int style)
{
XRectangle overall_ink_return;
***************
*** 418,437 ****
}
/*
* 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 */
--- 448,500 ----
}
+ #define XSHARP_BUFSIZ 128
+
/*
* Draw a string using a font struct.
*/
void XSharpDrawStringStruct(Display *dpy, Drawable drawable, GC gc,
! void *fontSet, int x, int y,
ILString *str,
! long offset, long
count, int style)
{
+ XFontStruct *fs = (XFontStruct *)fontSet;
+ ILChar *buffer = ILStringToBuffer(str) + offset;
XRectangle overall_ink_return;
XRectangle overall_logical_return;
int line1, line2;
+ ILChar ch;
+ long ct;
+ int posn;
+ char latinBuffer[XSHARP_BUFSIZ];
/* Draw the string using the core API */
XSetFont(dpy, gc, fs->fid);
! ct = count;
! while(ct > 0)
! {
! /* Convert a run of text into Latin1 */
! posn = 0;
! while(ct > 0 && posn < XSHARP_BUFSIZ)
! {
! ch = *buffer++;
! --ct;
! if(ch < 0x0100)
! {
! latinBuffer[posn++] = (char)ch;
! }
! else
! {
! latinBuffer[posn++] = (char)'?';
! }
! }
!
! /* Draw the text run */
! XDrawString(dpy, drawable, gc, x, y, latinBuffer, posn);
!
! /* Advance past the text run so that we can draw the next one */
! if(ct > 0)
! {
! x += XTextWidth(fs, latinBuffer, posn);
! }
! }
/* Calculate the positions of the underline and strike-out */
***************
*** 456,461 ****
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)
--- 519,524 ----
if(line1 != y || line2 != y)
{
! XSharpTextExtentsStruct(dpy, fontSet, str, offset, count,
!
&overall_ink_return, &overall_logical_return);
XSetLineAttributes(dpy, gc, 1, LineSolid, CapNotLast,
JoinMiter);
if(line1 != y)
***************
*** 564,577 ****
/*
* 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);
--- 627,774 ----
/*
+ * Some helper macros from the Xlib code. Copyright by various authors
+ * and distributed under the MIT/X11 license. See the Xlib source for
+ * further details (Xlibint.h and TextExt.c).
+ */
+ #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
+ (((cs)->rbearing|(cs)->lbearing| \
+ (cs)->ascent|(cs)->descent) == 0))
+ #define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
+ { \
+ cs = def; \
+ if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
+ if (fs->per_char == NULL) { \
+ cs = &fs->min_bounds; \
+ } else { \
+ cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
+ if (CI_NONEXISTCHAR(cs)) cs = def; \
+ } \
+ } \
+ }
+ #define CI_GET_DEFAULT_INFO_1D(fs,cs) \
+ CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
+ #define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
+ { \
+ cs = def; \
+ if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
+ col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
+ if (fs->per_char == NULL) { \
+ cs = &fs->min_bounds; \
+ } else { \
+ cs = &fs->per_char[((row - fs->min_byte1) * \
+ (fs->max_char_or_byte2 - \
+ fs->min_char_or_byte2 + 1)) + \
+ (col - fs->min_char_or_byte2)]; \
+ if (CI_NONEXISTCHAR(cs)) cs = def; \
+ } \
+ } \
+ }
+ #define CI_GET_DEFAULT_INFO_2D(fs,cs) \
+ { \
+ unsigned int r = (fs->default_char >> 8); \
+ unsigned int c = (fs->default_char & 0xff); \
+ CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
+ }
+ #define CI_GET_ROWZERO_CHAR_INFO_2D(fs,col,def,cs) \
+ { \
+ cs = def; \
+ if (fs->min_byte1 == 0 && \
+ col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
+ if (fs->per_char == NULL) { \
+ cs = &fs->min_bounds; \
+ } else { \
+ cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
+ if (CI_NONEXISTCHAR(cs)) cs = def; \
+ } \
+ } \
+ }
+
+ /*
* Calculate the extent information for a string in a font struct.
+ *
+ * This is based on the code for the "XTextExtents" function in Xlib.
+ * We expand it inline so that we can convert from Unicode to Latin1 on
+ * the fly, rather than having to convert into a separate buffer first.
*/
! void XSharpTextExtentsStruct(Display *dpy, void *fontSet, ILString *str,
! long offset, long count,
! XRectangle
*overall_ink_return,
XRectangle
*overall_logical_return)
{
! ILChar *buffer = ILStringToBuffer(str) + offset;
! XFontStruct *fs = (XFontStruct *)fontSet;
! int isSingleRow = (fs->max_byte1 == 0);
! int first = 1;
! XCharStruct *defaultSize;
! XCharStruct *charSize;
XCharStruct overall;
! unsigned ch;
! int temp;
!
! /* Get the metrics for the default character */
! if(isSingleRow)
! {
! CI_GET_DEFAULT_INFO_1D(fs, defaultSize);
! }
! else
! {
! CI_GET_DEFAULT_INFO_2D(fs, defaultSize);
! }
!
! /* Iterate over the characters and measure them */
! overall.width = 0;
! overall.ascent = 0;
! overall.descent = 0;
! overall.lbearing = 0;
! overall.rbearing = 0;
! while(count-- > 0)
! {
! ch = (unsigned)(*buffer++);
! if(ch >= 0x0100)
! {
! /* Convert non-Latin1 characters into '?' */
! ch = '?';
! }
! if(isSingleRow)
! {
! CI_GET_CHAR_INFO_1D(fs, ch, defaultSize, charSize);
! }
! else
! {
! CI_GET_ROWZERO_CHAR_INFO_2D(fs, ch, defaultSize, charSize);
! }
! if(charSize)
! {
! if(first)
! {
! overall = *charSize;
! first = 0;
! }
! else
! {
! if(charSize->ascent > overall.ascent)
! {
! overall.ascent = charSize->ascent;
! }
! if(charSize->descent > overall.descent)
! {
! overall.descent = charSize->descent;
! }
! temp = overall.width + charSize->lbearing;
! if(temp < overall.lbearing)
! {
! overall.lbearing = temp;
! }
! temp = overall.width + charSize->rbearing;
! if(temp > overall.rbearing)
! {
! overall.rbearing = temp;
! }
! overall.width += charSize->width;
! }
! }
! }
!
! /* Convert the raw extent information into the desired return values */
overall_ink_return->x = overall.lbearing;
overall_ink_return->y = -(overall.ascent);
***************
*** 579,585 ****
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;
}
--- 776,782 ----
overall_ink_return->height = overall.ascent + overall.descent;
overall_logical_return->x = 0;
! overall_logical_return->y = -(fs->ascent);
overall_logical_return->width = overall.width;
! overall_logical_return->height = fs->ascent + fs->descent;
}
***************
*** 1509,1514 ****
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 */
--- 1706,1710 ----
void XSharpDrawStringSet(void *dpy, unsigned long drawable, void *gc,
void *fontSet, int x, int y,
! const char *str, int style)
{
/* Nothing to do here */
***************
*** 1543,1553 ****
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)
--- 1739,1749 ----
void XSharpDrawStringStruct(void *dpy, unsigned long drawable, void *gc,
void *fontSet, int x, int y,
! void *str, long offset, long
count, int style)
{
/* Nothing to do here */
}
! void XSharpTextExtentsStruct(void *dpy, void *fontSet,
! void *str, long
offset, long count,
void *overall_ink_return,
void *overall_logical_return)
Index: Font.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Font.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Font.cs 30 Nov 2003 07:10:16 -0000 1.6
--- Font.cs 30 Nov 2003 09:40:55 -0000 1.7
***************
*** 515,520 ****
Xlib.XSharpDrawStringSet
(display,
graphics.drawableHandle, graphics.gc,
! fontSet, x, y, str,
(int)style,
! IntPtr.Zero,
graphics.Foreground.value);
}
finally
--- 515,519 ----
Xlib.XSharpDrawStringSet
(display,
graphics.drawableHandle, graphics.gc,
! fontSet, x, y, str,
(int)style);
}
finally
***************
*** 783,787 ****
throw new
ArgumentNullException("graphics");
}
! if(str == null || count == 0)
{
width = 0;
--- 782,794 ----
throw new
ArgumentNullException("graphics");
}
! if(str == null || count <= 0)
! {
! width = 0;
! ascent = 0;
! descent = 0;
! return;
! }
! if(index < 0 || index >= str.Length ||
! count > (str.Length - index))
{
width = 0;
***************
*** 790,797 ****
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.
--- 797,800 ----
***************
*** 812,816 ****
IntPtr display =
graphics.dpy.Lock();
Xlib.XSharpTextExtentsStruct
! (display, fontSet, str,
out overall_ink, out
overall_logical);
}
--- 815,819 ----
IntPtr display =
graphics.dpy.Lock();
Xlib.XSharpTextExtentsStruct
! (display, fontSet, str,
index, count,
out overall_ink, out
overall_logical);
}
***************
*** 847,858 ****
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.
--- 850,862 ----
throw new
ArgumentNullException("graphics");
}
! if(str == null || count <= 0)
! {
! return;
! }
! if(index < 0 || index >= str.Length ||
! count > (str.Length - index))
{
return;
}
// Get the font set to use for the font.
***************
*** 869,874 ****
Xlib.XSharpDrawStringStruct
(display,
graphics.drawableHandle, graphics.gc,
! fontSet, x, y,
str, (int)style,
! IntPtr.Zero,
graphics.Foreground.value);
}
finally
--- 873,878 ----
Xlib.XSharpDrawStringStruct
(display,
graphics.drawableHandle, graphics.gc,
! fontSet, x, y,
str, index, count,
! (int)style);
}
finally
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** Xlib.cs.in 30 Nov 2003 07:10:16 -0000 1.19
--- Xlib.cs.in 30 Nov 2003 09:40:55 -0000 1.20
***************
*** 576,581 ****
(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")]
--- 576,580 ----
(IntPtr display, Drawable drawable, IntPtr gc,
IntPtr fontSet, @X_int@ x, @X_int@ y,
! String str, @X_int@ style);
[DllImport("XsharpSupport")]
***************
*** 603,612 ****
(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);
--- 602,613 ----
(IntPtr display, Drawable drawable, IntPtr gc,
IntPtr fontSet, @X_int@ x, @X_int@ y,
! [MarshalAs(UnmanagedType.Interface)] String str,
! @X_long@ offset, @X_long@ count, @X_int@ style);
[DllImport("XsharpSupport")]
extern public static void XSharpTextExtentsStruct
! (IntPtr display, IntPtr fontSet,
! [MarshalAs(UnmanagedType.Interface)] String str,
! @X_long@ offset, @X_long@ count,
out XRectangle overall_ink_return,
out XRectangle overall_logical_return);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.6, 1.7 Xlib.cs.in, 1.19, 1.20 XsharpSupport.c, 1.26, 1.27,
Rhys Weatherley <address@hidden> <=