On 2005-03-15 12:38:44 -0500 Adam Fedor <[EMAIL PROTECTED]> wrote:


On Mar 15, 2005, at 7:33 AM, Adrian Robert wrote:

This leads to the next question -- is it possible to detect at runtime whether you are running under Art or Xlib? (So as to change rendering strategies.)


In a way, yes. You can check for the backend contexts, like this:

if (GSClassFromName("ARTContext") != nil)

Thanks.


Is there any more efficient way to render with regular spacing than repeated calls to moveto and show?

Try DPSxyshow and variants.

Ah. Attached is a patch implementing these functions in back-art. ;-)

It modifies the existing DPSshow implementation to handle DPSxyshow,
DPSxshow, and DPSyshow.  Partial support is there for DPSwidthshow.
Right now I just patched ftfont-old.m since that's what I'm using
(freetype-2.1.2), and anyway this patch needs some feedback.

For one thing, I don't check the 'size' argument when deltas are
provided.  I don't know where people are finding DPS documentation
that goes into this sort of detail, but the postscript docs I read
said an error is generated if 'size' isn't the same as the text
length.  Should I check and throw an exception?

For another, I'm not sure when the y advancement should be used.  I
guess even the Japanese are mostly writing horizontally now, at
least on computers?  ;-)


<ARTContext.patch>

<ftfont-old.patch>

Index: Source/art/ARTContext.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/art/ARTContext.m,v
retrieving revision 1.27
diff -a -u -r1.27 ARTContext.m
--- Source/art/ARTContext.m	20 Jan 2005 21:35:23 -0000	1.27
+++ Source/art/ARTContext.m	16 Mar 2005 04:07:00 -0000
@@ -235,6 +235,7 @@
       : (wi->has_alpha? wi->alpha + clip_x0 + clip_y0 * wi->sx : NULL) : wi->sx
     color: fill_color[0]:fill_color[1]:fill_color[2]:fill_color[3]
     transform: ctm
+    deltas: NULL : 0 : 0
     drawinfo: &DI];
   UPDATE_UNBUFFERED
 }
@@ -262,9 +263,11 @@
     drawString: s
     at: x:y
     to: clip_x0:clip_y0:clip_x1:clip_y1 : CLIP_DATA : wi->bytes_per_line
+      : (wi->has_alpha? wi->alpha + clip_x0 + clip_y0 * wi->sx : NULL) : wi->sx
     color: fill_color[0]:fill_color[1]:fill_color[2]:fill_color[3]
     transform: ctm
-    deltas: numarray : size : 1];
+    deltas: numarray : size : 1
+    drawinfo: &DI];
   UPDATE_UNBUFFERED
 }
 
@@ -286,9 +289,11 @@
     drawString: s
     at: x:y
     to: clip_x0:clip_y0:clip_x1:clip_y1 : CLIP_DATA : wi->bytes_per_line
+      : (wi->has_alpha? wi->alpha + clip_x0 + clip_y0 * wi->sx : NULL) : wi->sx
     color: fill_color[0]:fill_color[1]:fill_color[2]:fill_color[3]
     transform: ctm
-    deltas: numarray : size : 3];
+    deltas: numarray : size : 3
+    drawinfo: &DI];
   UPDATE_UNBUFFERED
 }
 
@@ -310,9 +315,11 @@
     drawString: s
     at: x:y
     to: clip_x0:clip_y0:clip_x1:clip_y1 : CLIP_DATA : wi->bytes_per_line
+      : (wi->has_alpha? wi->alpha + clip_x0 + clip_y0 * wi->sx : NULL) : wi->sx
     color: fill_color[0]:fill_color[1]:fill_color[2]:fill_color[3]
     transform: ctm
-    deltas: numarray : size : 2];
+    deltas: numarray : size : 2
+    drawinfo: &DI];
   UPDATE_UNBUFFERED
 }
 
Index: Source/art/ftfont.h
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/art/ftfont.h,v
retrieving revision 1.6
diff -a -u -r1.6 ftfont.h
--- Source/art/ftfont.h	29 Feb 2004 20:45:05 -0000	1.6
+++ Source/art/ftfont.h	16 Mar 2005 04:08:31 -0000
@@ -34,6 +34,7 @@
 	color: (unsigned char)r : (unsigned char)g : (unsigned char)b
 	: (unsigned char)alpha
 	transform: (NSAffineTransform *)transform
+	deltas: (const float *)delta_data : (int)delta_size : (int)delta_flags
 	drawinfo: (struct draw_info_s *)di;
 
 -(void) drawGlyphs: (const NSGlyph *)glyphs : (int)length
@@ -55,14 +56,6 @@
 	transform: (NSAffineTransform *)transform
 	drawinfo: (struct draw_info_s *)di;
 
-/* TODO: see if this is really necessary */
--(void) drawString: (const char *)s
-	at: (int)x:(int)y
-	to: (int)x0:(int)y0:(int)x1:(int)y1:(unsigned char *)buf:(int)bpl
-	color:(unsigned char)r:(unsigned char)g:(unsigned char)b:(unsigned char)alpha
-	transform: (NSAffineTransform *)transform
-	deltas: (const float *)delta_data : (int)delta_size : (int)delta_flags;
-
 -(void) outlineString: (const char *)s
 	at: (float)x : (float)y
 	gstate: (void *)func_param;
Index: Source/art/ftfont-old.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/art/ftfont-old.m,v
retrieving revision 1.1
diff -a -u -r1.1 ftfont-old.m
--- Source/art/ftfont-old.m	11 Jan 2005 15:02:29 -0000	1.1
+++ Source/art/ftfont-old.m	16 Mar 2005 04:08:32 -0000
@@ -874,17 +874,12 @@
 
 /* TODO: the current point probably needs updating after drawing is done */
 
--(void) drawString: (const char *)s
-	at: (int)x:(int)y
-	to: (int)x0:(int)y0:(int)x1:(int)y1:(unsigned char *)buf:(int)bpl
-	color:(unsigned char)r:(unsigned char)g:(unsigned char)b:(unsigned char)alpha
-	transform: (NSAffineTransform *)transform
-	deltas: (const float *)delta_data : (int)delta_size : (int)delta_flags;
-{
-/* TODO */
-}
-
-
+/* draw string at point, clipped, w/given color and alpha, and possible deltas:
+   flags & 0x1: data contains x offsets, use instead of glyph x advance
+   flags & 0x2: data contains y offsets, use instead of glyph y advance
+   flags & 0x4: data contains a single x and y offset, which should be added to
+                font's advancements for each glyph; results are undefined if
+                this option is combined with either x or y offsets */
 -(void) drawString: (const char *)s
 	at: (int)x : (int)y
 	to: (int)x0 : (int)y0 : (int)x1 : (int)y1
@@ -892,6 +887,7 @@
 	: (unsigned char *)abuf : (int)abpl
 	color:(unsigned char)r : (unsigned char)g : (unsigned char)b : (unsigned char)alpha
 	transform: (NSAffineTransform *)transform
+	deltas: (const float *)delta_data : (int)delta_size : (int)delta_flags
 	drawinfo: (draw_info_t *)di
 {
 #if 0
@@ -900,6 +896,7 @@
   const unsigned char *c;
   unsigned char ch;
   unsigned int uch;
+  int d;
 
   FTC_CMapDescRec cmap;
   unsigned int glyph;
@@ -1034,6 +1031,7 @@
   cmap.face_id = imgd.font.face_id;
   cmap.u.encoding = ft_encoding_unicode;
   cmap.type = FTC_CMAP_BY_ENCODING;
+  d=0;
 
   for (c = s; *c; c++)
     {
@@ -1109,7 +1107,17 @@
 
 	  if (!sbit->buffer)
 	    {
-	      x += sbit->xadvance;
+	      if (delta_flags & 0x1)
+                  x += delta_data[d++];
+              else
+                  x += sbit->xadvance;
+              if (delta_flags & 0x2)
+                  y += delta_data[d++];
+              if (delta_flags & 0x4)
+                {
+                  x += delta_data[0];
+                  y += delta_data[1];
+                }
 	      continue;
 	    }
 
@@ -1218,7 +1226,17 @@
 	      NSLog(@"unhandled font bitmap format %i", sbit->format);
 	    }
 
-	  x += sbit->xadvance;
+          if (delta_flags & 0x1)
+              x += delta_data[d++];
+          else
+              x += sbit->xadvance;
+          if (delta_flags & 0x2)
+              y += delta_data[d++];
+          if (delta_flags & 0x4)
+            {
+              x += delta_data[0];
+              y += delta_data[1];
+            }
 	}
       else
 	{
_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to