--- On Tue, 8/2/11, Jay Sorg <jay.s...@gmail.com> wrote:

> Try this patch.
> This one was more difficult :)
> 

Fantastic, Jay!

It is working. Next time I'll pay attention to the signed and unsigned encoded 
bytes parsing... there are loads more to come ;)

The attached patch is equal to yours, but I replaced the printf by DEBUG

Thanks very much for the help

Eduardo Fiss Beloni
bel...@ossystems.com.br


      
From 56761e79100c5d35695267f03d44fb9eb2dca773 Mon Sep 17 00:00:00 2001
From: Eduardo Beloni <bel...@ossystems.com.br>
Date: Tue, 8 Feb 2011 09:29:34 -0200
Subject: [PATCH] libfreerdp: FastGlyph capability

---
 libfreerdp/capabilities.c |    2 +-
 libfreerdp/orders.c       |  185 +++++++++++++++++++++++++++++++++++++++++++++
 libfreerdp/orderstypes.h  |   24 ++++++
 3 files changed, 210 insertions(+), 1 deletions(-)

diff --git a/libfreerdp/capabilities.c b/libfreerdp/capabilities.c
index 2d45cbb..328dfa0 100644
--- a/libfreerdp/capabilities.c
+++ b/libfreerdp/capabilities.c
@@ -195,7 +195,7 @@ rdp_out_order_capset(rdpRdp * rdp, STREAM s)
 	orderSupport[NEG_POLYGON_SC_INDEX] = (rdp->settings->polygon_ellipse_orders ? 1 : 0);
 	orderSupport[NEG_POLYGON_CB_INDEX] = (rdp->settings->polygon_ellipse_orders ? 1 : 0);
 	orderSupport[NEG_POLYLINE_INDEX] = 1;
-	// orderSupport[NEG_FAST_GLYPH_INDEX] = 1;
+	orderSupport[NEG_FAST_GLYPH_INDEX] = 1;
 	orderSupport[NEG_ELLIPSE_SC_INDEX] = (rdp->settings->polygon_ellipse_orders ? 1 : 0);
 	orderSupport[NEG_ELLIPSE_CB_INDEX] = (rdp->settings->polygon_ellipse_orders ? 1 : 0);
 	orderSupport[NEG_INDEX_INDEX] = 1;
diff --git a/libfreerdp/orders.c b/libfreerdp/orders.c
index b73637a..73ac32a 100644
--- a/libfreerdp/orders.c
+++ b/libfreerdp/orders.c
@@ -92,6 +92,33 @@ parse_delta(uint8 * buffer, int *offset)
 	return value;
 }
 
+static int
+parse_s2byte(uint8 * buffer, int *offset)
+{
+	int value = buffer[(*offset)++];
+	int two_byte = value & 0x80;
+	int sign = value & 0x40;
+
+	value &= 0x3f;
+	if (two_byte)
+		value = (value << 8) | buffer[(*offset)++];
+	if (sign)
+		value = value * -1;
+	return value;
+}
+
+static int
+parse_u2byte(uint8 * buffer, int *offset)
+{
+	int value = buffer[(*offset)++];
+	int two_byte = value & 0x80;
+
+	value &= 0x7f;
+	if (two_byte)
+		value = (value << 8) | buffer[(*offset)++];
+	return value;
+}
+
 /* Read a color entry */
 static void
 rdp_in_color(STREAM s, uint32 * color)
@@ -1206,6 +1233,159 @@ process_fast_index(rdpOrders * orders, STREAM s, FAST_INDEX_ORDER * os, uint32 p
 		  &os->brush, os->bgcolor, os->fgcolor, os->text, os->length);
 }
 
+/* Process a fast glyph order */
+static void
+process_fast_glyph(rdpOrders * orders, STREAM s, FAST_GLYPH_ORDER * os, uint32 present, RD_BOOL delta)
+{
+	int x;
+	int y;
+	int clipx1;
+	int clipy1;
+	int clipx2;
+	int clipy2;
+	int clipcx;
+	int clipcy;
+	int boxx1;
+	int boxy1;
+	int boxx2;
+	int boxy2;
+	int boxcx;
+	int boxcy;
+	int character;
+	int offset;
+	int baseline;
+	int width;
+	int height;
+	RD_HGLYPH gl;
+	FONTGLYPH * ft;
+	int gx;
+	int gy;
+	int index;
+
+	if (present & 0x000001)
+		in_uint8(s, os->font);
+	if (present & 0x000002)
+	{
+		in_uint8(s, os->opcode);
+		in_uint8(s, os->flags);
+	}
+	if (present & 0x000004)
+		rdp_in_color(s, &os->fgcolor);
+	if (present & 0x000008)
+		rdp_in_color(s, &os->bgcolor);
+	if (present & 0x000010)
+		rdp_in_coord(s, &os->clipleft, delta);
+	if (present & 0x000020)
+		rdp_in_coord(s, &os->cliptop, delta);
+	if (present & 0x000040)
+		rdp_in_coord(s, &os->clipright, delta);
+	if (present & 0x000080)
+		rdp_in_coord(s, &os->clipbottom, delta);
+	if (present & 0x000100)
+		rdp_in_coord(s, &os->boxleft, delta);
+	if (present & 0x000200)
+		rdp_in_coord(s, &os->boxtop, delta);
+	if (present & 0x000400)
+		rdp_in_coord(s, &os->boxright, delta);
+	if (present & 0x000800)
+		rdp_in_coord(s, &os->boxbottom, delta);
+	if (present & 0x001000)
+		rdp_in_coord(s, &os->x, delta);
+	if (present & 0x002000)
+		rdp_in_coord(s, &os->y, delta);
+	if (present & 0x004000)
+	{
+		in_uint8(s, os->length);
+		in_uint8a(s, os->data, os->length);
+	}
+	x = os->x == -32768 ? os->clipleft : os->x;
+	y = os->y == -32768 ? os->cliptop : os->y;
+	clipx1 = os->clipleft;
+	clipy1 = os->cliptop;
+	clipx2 = os->clipright;
+	clipy2 = os->clipbottom;
+	boxx1 = os->boxleft;
+	boxy1 = os->boxtop;
+	boxx2 = os->boxright;
+	boxy2 = os->boxbottom;
+	if (os->boxleft == 0)
+	{
+		boxx1 = os->clipleft;
+	}
+	if (os->boxright == 0)
+	{
+		boxx2 = os->clipright;
+	}
+	if (os->boxbottom == -32768)
+	{
+		if (os->boxtop & 0x01)
+		{
+			boxy2 = os->clipbottom;
+		}
+		if (os->boxtop & 0x02)
+		{
+			boxx2 = os->clipright;
+		}
+		if (os->boxtop & 0x04)
+		{
+			boxy1 = os->cliptop;
+		}
+		if (os->boxtop & 0x08)
+		{
+			boxx1 = os->clipleft;
+		}
+	}
+	if (!((boxx2 > boxx1) && (boxy2 > boxy1)))
+	{
+		boxx1 = 0;
+		boxy1 = 0;
+		boxx2 = 0;
+		boxy2 = 0;
+	}
+	clipcx = clipx2 - clipx1;
+	clipcy = clipy2 - clipy1;
+	boxcx = boxx2 - boxx1;
+	boxcy = boxy2 - boxy1;
+
+	DEBUG("FAST_GLYPH(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,br=%d,bb=%d,bg=0x%x,fg=0x%x,font=%d,fl=0x%x,op=0x%x,n=%d)\n", x, y, os->clipleft, os->cliptop, os->clipright, os->clipbottom, os->boxleft, os->boxtop, os->boxright, os->boxbottom, os->bgcolor, os->fgcolor, os->font, os->flags, os->opcode, os->length);
+
+	if (os->length < 2)
+	{
+		character = os->data[0];
+	}
+	else
+	{
+		character = os->data[0];
+		index = 1;
+		offset = parse_s2byte(os->data, &index);
+		baseline = parse_s2byte(os->data, &index);
+		width = parse_u2byte(os->data, &index);
+		height = parse_u2byte(os->data, &index);
+		gl = ui_create_glyph(orders->rdp->inst, width, height, os->data + index);
+		cache_put_font(orders->rdp->cache, os->font, character, offset, baseline, width, height, gl);
+	}
+	ft = cache_get_font(orders->rdp->cache, os->font, character);
+	if (ft != NULL)
+	{
+		if (boxcx > 1)
+		{
+			ui_rect(orders->rdp->inst, boxx1, boxy1, boxcx, boxcy, os->bgcolor);
+		}
+		ui_start_draw_glyphs(orders->rdp->inst, os->bgcolor, os->fgcolor);
+		gx = x + ft->offset;
+		gy = y + ft->baseline;
+		ui_draw_glyph(orders->rdp->inst, gx, gy, ft->width, ft->height, ft->pixmap);
+		if (boxcx > 1)
+	  {
+		  ui_end_draw_glyphs(orders->rdp->inst, boxx1, boxy1, boxcx, boxcy);
+	  }
+	  else
+	  {
+		  ui_end_draw_glyphs(orders->rdp->inst, clipx1, clipy1, clipcx, clipcy);
+	  }
+	}
+}
+
 /* Process a raw bitmap cache order */
 static void
 process_cache_bitmap_uncompressed(rdpOrders * orders, STREAM s)
@@ -1740,6 +1920,7 @@ process_orders(rdpOrders * orders, STREAM s, uint16 num_orders)
 				case RDP_ORDER_POLYGON_CB:
 				case RDP_ORDER_FAST_INDEX:
 				case RDP_ORDER_ELLIPSE_CB:
+				case RDP_ORDER_FAST_GLYPH:
 					size = 2;
 					break;
 
@@ -1825,6 +2006,10 @@ process_orders(rdpOrders * orders, STREAM s, uint16 num_orders)
 					process_fast_index(orders, s, &os->fast_index, present, delta);
 					break;
 
+				case RDP_ORDER_FAST_GLYPH:
+					process_fast_glyph(orders, s, &os->fast_glyph, present, delta);
+					break;
+
 				default:
 					ui_unimpl(orders->rdp->inst, "order %d\n", os->order_type);
 					return;
diff --git a/libfreerdp/orderstypes.h b/libfreerdp/orderstypes.h
index fe00ce3..304b76e 100644
--- a/libfreerdp/orderstypes.h
+++ b/libfreerdp/orderstypes.h
@@ -52,6 +52,7 @@ enum RDP_ORDER_TYPE
 	RDP_ORDER_POLYGON_SC = 20,
 	RDP_ORDER_POLYGON_CB = 21,
 	RDP_ORDER_POLYLINE = 22,
+	RDP_ORDER_FAST_GLYPH = 24,
 	RDP_ORDER_ELLIPSE_SC = 25,
 	RDP_ORDER_ELLIPSE_CB = 26,
 	RDP_ORDER_GLYPH_INDEX = 27
@@ -323,6 +324,28 @@ typedef struct _FAST_INDEX_ORDER
 }
 FAST_INDEX_ORDER;
 
+typedef struct _FAST_GLYPH_ORDER
+{
+	uint8 font;
+	uint8 flags;
+	uint8 opcode;
+	uint32 bgcolor;
+	uint32 fgcolor;
+	sint16 clipleft;
+	sint16 cliptop;
+	sint16 clipright;
+	sint16 clipbottom;
+	sint16 boxleft;
+	sint16 boxtop;
+	sint16 boxright;
+	sint16 boxbottom;
+	sint16 x;
+	sint16 y;
+	uint8 length;
+	uint8 data[256];
+}
+FAST_GLYPH_ORDER;
+
 typedef struct _RDP_ORDER_STATE
 {
 	uint8 order_type;
@@ -343,6 +366,7 @@ typedef struct _RDP_ORDER_STATE
 	ELLIPSE_CB_ORDER ellipse_cb;
 	GLYPH_INDEX_ORDER glyph_index;
 	FAST_INDEX_ORDER fast_index;
+	FAST_GLYPH_ORDER fast_glyph;
 }
 RDP_ORDER_STATE;
 
-- 
1.6.6.1

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Freerdp-devel mailing list
Freerdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freerdp-devel

Reply via email to