[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.10, 1.11 Xlib.cs.in, 1.
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.10, 1.11 Xlib.cs.in, 1.20, 1.21 XsharpPCF.c, 1.1, 1.2 |
Date: |
Mon, 01 Dec 2003 07:40:00 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv28372/Xsharp
Modified Files:
Font.cs Xlib.cs.in XsharpPCF.c
Log Message:
Continue with the PCF font rendering engine (still disabled for now).
Index: XsharpPCF.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpPCF.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** XsharpPCF.c 1 Dec 2003 02:48:42 -0000 1.1
--- XsharpPCF.c 1 Dec 2003 07:39:58 -0000 1.2
***************
*** 32,35 ****
--- 32,37 ----
#define PCF_BYTEORDER_MSBFIRST 0x00000004
#define PCF_BITORDER_MSBFIRST 0x00000008
+ #define PCF_GLYPH_PADDING_MASK 0x00000003
+ #define PCF_SCAN_PADDING_MASK 0x00000030
/*
***************
*** 251,254 ****
--- 253,257 ----
image->fs.ascent = PCFReadInt32(image);
image->fs.descent = PCFReadInt32(image);
+ PCFSkipBytes(image, 4);
PCFReadFullMetrics(image, &(image->fs.min_bounds));
PCFReadFullMetrics(image, &(image->fs.max_bounds));
***************
*** 278,282 ****
return 0;
}
! for(temp = 0; temp < image->numGlyphs; ++image)
{
PCFReadFullMetrics(image,
&(image->fs.per_char[temp]));
--- 281,285 ----
return 0;
}
! for(temp = 0; temp < image->numGlyphs; ++temp)
{
PCFReadFullMetrics(image,
&(image->fs.per_char[temp]));
***************
*** 293,297 ****
return 0;
}
! for(temp = 0; temp < image->numGlyphs; ++image)
{
PCFReadCompressedMetrics(image,
&(image->fs.per_char[temp]));
--- 296,300 ----
return 0;
}
! for(temp = 0; temp < image->numGlyphs; ++temp)
{
PCFReadCompressedMetrics(image,
&(image->fs.per_char[temp]));
***************
*** 334,337 ****
--- 337,351 ----
return 0;
}
+ if((image->glyphFormat & (PCF_BITORDER_MSBFIRST |
+
PCF_GLYPH_PADDING_MASK |
+
PCF_SCAN_PADDING_MASK))
+ != PCF_BITORDER_MSBFIRST)
+ {
+ fprintf(stderr, "XSharpPCFCreateImage: currently, we only
support "
+ "PCF fonts built with\n");
+ fprintf(stderr, "the command-line `bdftopcf -p1 -u1 -m
font.bdf'\n");
+ PCFFontFree(image);
+ return 0;
+ }
/* Return the PCF font image to the caller */
***************
*** 396,402 ****
prior to being sent to the X server */
width = image->fs.max_bounds.width * 33;
height = image->fs.ascent + image->fs.descent;
renderer->ximage = XCreateImage
! (dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1,
XYBitmap,
0, 0, width, height, 8, 0);
if(!(renderer->ximage))
--- 410,417 ----
prior to being sent to the X server */
width = image->fs.max_bounds.width * 33;
+ width = (width + 31) & ~31;
height = image->fs.ascent + image->fs.descent;
renderer->ximage = XCreateImage
! (dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1,
ZPixmap,
0, 0, width, height, 8, 0);
if(!(renderer->ximage))
***************
*** 464,471 ****
PCFFontImage *image = renderer->image;
XImage *ximage = renderer->ximage;
! int posn;
int width, height, line;
XGCValues values;
ILChar *buffer = ILStringToBuffer(str) + offset;
XRectangle overall_ink;
XRectangle overall_logical;
--- 479,487 ----
PCFFontImage *image = renderer->image;
XImage *ximage = renderer->ximage;
! int posn, num;
int width, height, line;
XGCValues values;
ILChar *buffer = ILStringToBuffer(str) + offset;
+ unsigned ch;
XRectangle overall_ink;
XRectangle overall_logical;
***************
*** 474,477 ****
--- 490,498 ----
long origLength = length;
int origX = x;
+ int xposn;
+ unsigned char *glyph;
+ XCharStruct *cs;
+ int gx, gy, gwidth, gheight;
+ int bytesPerLine, xrel;
/* Save the current GC fill settings */
***************
*** 503,508 ****
}
/* Render the bitmaps for the characters into the XImage */
! /* TODO */
/* Write the XImage into the stipple pixmap */
--- 524,578 ----
}
+ printf("%c %d\n", buffer[0], overall_ink.x);
/* Render the bitmaps for the characters into the XImage */
! xposn = -(overall_ink.x);
! num = posn;
! while(num > 0)
! {
! /* Fetch the next character from the string and convert
! into into a glyph index */
! ch = *buffer++;
! --num;
! if(ch >= 0x0100)
! {
! ch = '?';
! }
! if(ch < image->fs.min_char_or_byte2 ||
! ch > image->fs.max_char_or_byte2)
! {
! ch = image->fs.default_char;
! }
! else
! {
! ch -= image->fs.min_char_or_byte2;
! }
!
! /* Get the bitmap and the dimensions for the glyph */
! glyph = image->glyphs[ch];
! cs = &(image->fs.per_char[ch]);
! gx = xposn + cs->lbearing;
! gy = image->fs.ascent - cs->ascent;
! gwidth = cs->rbearing - cs->lbearing;
! gheight = cs->ascent + cs->descent;
!
! /* Render the glyph into the XImage (TODO: make this
faster) */
! bytesPerLine = (gwidth + 7) / 8;
! while(gheight > 0)
! {
! for(xrel = 0; xrel < gwidth; ++xrel)
! {
! if((glyph[xrel / 8] & (0x80 >> (xrel %
8))) != 0)
! {
! XPutPixel(ximage, gx + xrel,
gy, 1);
! }
! }
! glyph += bytesPerLine;
! ++gy;
! --gheight;
! }
!
! /* Move on to the next character */
! xposn += cs->width;
! }
/* Write the XImage into the stipple pixmap */
Index: Font.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Font.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Font.cs 1 Dec 2003 02:03:46 -0000 1.10
--- Font.cs 1 Dec 2003 07:39:58 -0000 1.11
***************
*** 262,265 ****
--- 262,269 ----
(String family, int pointSize, FontStyle style)
{
+ // Determine if we are running in a Latin1
locale.
+ bool latin1 = IsLatin1();
+
+ #if false
// Do we have a registered font for this name,
size, and style?
RegisteredFont font;
***************
*** 279,285 ****
}
}
! if(font != null)
{
! // TODO: create a font based on a
registered font image.
}
--- 283,309 ----
}
}
! if(latin1 && font != null)
{
! // Create the font image if necessary.
! if(font.loadedData == IntPtr.Zero)
! {
! font.loadedData =
Xlib.XSharpPCFCreateImage
! (font.data,
(uint)(font.data.Length));
! }
!
! // Create a PCF font based on a
registered font image.
! if(font.loadedData != IntPtr.Zero)
! {
! return new PCFFont
! (family, pointSize,
style, font.loadedData);
! }
! }
! #endif
!
! // Re-adjust point sizes for Windows vs X
differences.
! // "Microsoft Sans Serif 8.25" is approx
"Helvetica 12".
! if(pointSize == 82)
! {
! pointSize = 120;
}
***************
*** 293,297 ****
return new XftFont(family, pointSize,
style);
}
! else if(IsLatin1())
{
return new FontStructFont(family,
pointSize, style);
--- 317,321 ----
return new XftFont(family, pointSize,
style);
}
! else if(latin1)
{
return new FontStructFont(family,
pointSize, style);
***************
*** 592,602 ****
// 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;
}
}
--- 616,626 ----
// Increase the descent to account for
underlining.
! // We always draw the underline on pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 771,781 ****
// 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;
}
}
--- 795,805 ----
// Increase the descent to account for
underlining.
! // We always draw the underline one pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 914,924 ****
// 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;
}
}
--- 938,948 ----
// Increase the descent to account for
underlining.
! // We always draw the underline one
pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 989,999 ****
// 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;
}
}
--- 1013,1023 ----
// Increase the descent to account for
underlining.
! // We always draw the underline one
pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 1076,1086 ****
// 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;
}
}
--- 1100,1110 ----
// Increase the descent to account for
underlining.
! // We always draw the underline one
pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 1147,1157 ****
// 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;
}
}
--- 1171,1181 ----
// Increase the descent to account for
underlining.
! // We always draw the underline one
pixel below
// the font base line.
if((style & FontStyle.Underlined) != 0)
{
! if(descent < 2)
{
! descent = 2;
}
}
***************
*** 1202,1205 ****
--- 1226,1397 ----
} // class XftFont
+
+ // Font class that uses a client-side PCF font renderer.
+ private class PCFFont : Font
+ {
+ // Internal state.
+ private IntPtr loadedData;
+
+ // Constructor.
+ public PCFFont(String family, int pointSize, FontStyle style,
+ IntPtr loadedData)
+ : base(family, pointSize, style)
+ {
+ this.loadedData = loadedData;
+ }
+
+ // 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.XSharpPCFCreate(display,
loadedData);
+
+ // Get the extent information for the
font.
+ Xlib.XSharpFontExtentsPCF
+ (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 one
pixel below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 2)
+ {
+ descent = 2;
+ }
+ }
+
+ // 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.XSharpPCFDestroy(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;
+ }
+ if(index < 0 || index >= str.Length ||
+ count > (str.Length - index))
+ {
+ width = 0;
+ ascent = 0;
+ descent = 0;
+ return;
+ }
+
+ // 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.XSharpTextExtentsPCF
+ (display, fontSet, str,
index, count,
+ 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 one
pixel below
+ // the font base line.
+ if((style & FontStyle.Underlined) != 0)
+ {
+ if(descent < 2)
+ {
+ descent = 2;
+ }
+ }
+ }
+ 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;
+ }
+ if(index < 0 || index >= str.Length ||
+ count > (str.Length - index))
+ {
+ return;
+ }
+
+ // 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.XSharpDrawStringPCF
+ (display,
graphics.drawableHandle, graphics.gc,
+ fontSet, x, y,
str, index, count,
+ (int)style);
+ }
+ finally
+ {
+ graphics.dpy.Unlock();
+ }
+ }
+
+ } // class PCFFont
} // class Font
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** Xlib.cs.in 30 Nov 2003 09:40:55 -0000 1.20
--- Xlib.cs.in 1 Dec 2003 07:39:58 -0000 1.21
***************
*** 620,623 ****
--- 620,657 ----
[DllImport("XsharpSupport")]
+ extern public static IntPtr XSharpPCFCreateImage
+ (byte[] data, @X_ulong@ length);
+
+ [DllImport("XsharpSupport")]
+ extern public static void XSharpPCFDestroyImage(IntPtr fontImage);
+
+ [DllImport("XsharpSupport")]
+ extern public static IntPtr XSharpPCFCreate(IntPtr dpy, IntPtr
fontImage);
+
+ [DllImport("XsharpSupport")]
+ extern public static void XSharpPCFDestroy(IntPtr dpy, IntPtr renderer);
+
+ [DllImport("XsharpSupport")]
+ extern public static void XSharpDrawStringPCF
+ (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 XSharpTextExtentsPCF
+ (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);
+
+ [DllImport("XsharpSupport")]
+ extern public static void XSharpFontExtentsPCF
+ (IntPtr fontSet,
+ out XRectangle max_ink_return,
+ out XRectangle max_logical_return);
+
+ [DllImport("XsharpSupport")]
extern public static IntPtr XSharpGetResources(IntPtr dpy, Window w);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/Xsharp Font.cs, 1.10, 1.11 Xlib.cs.in, 1.20, 1.21 XsharpPCF.c, 1.1, 1.2,
Rhys Weatherley <address@hidden> <=