r5392 vince - in /branches/vince/netsurf-fb/framebuffer: fb_16bpp_plotters.c fb_32bpp_plotters.c fb_8bpp_plotters.c fb_font.h font_8x16.c

netsurf at semichrome.net netsurf at semichrome.net
Sun Sep 21 23:11:52 BST 2008


Author: vince
Date: Sun Sep 21 17:11:51 2008
New Revision: 5392

URL: http://source.netsurf-browser.org?rev=5392&view=rev
Log:
Improve text plotters

Modified:
    branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c
    branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c
    branches/vince/netsurf-fb/framebuffer/fb_8bpp_plotters.c
    branches/vince/netsurf-fb/framebuffer/fb_font.h
    branches/vince/netsurf-fb/framebuffer/font_8x16.c

Modified: branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c?rev=5392&r1=5391&r2=5392&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c Sun Sep 21 17:11:51 2008
@@ -200,9 +200,9 @@
 			const char *text, size_t length, colour bg, colour c)
 {
         const struct fb_font_desc* fb_font = fb_get_font(style);
-        const uint8_t *font_data;
+        const uint32_t *font_data;
         int xloop, yloop;
-        unsigned char row;
+        uint32_t row;
         size_t chr;
 
         uint16_t *pvideo;
@@ -212,7 +212,7 @@
 	char *buffer = NULL;
         int x0,y0,x1,y1;
 	int xoff, yoff; /* x and y offset into image */
-        int width, height;
+        int height = fb_font->height;
 
         /* aquire thge text in local font encoding */
 	utf8_to_font_encoding(fb_font, text, length, &buffer);
@@ -240,9 +240,6 @@
         /* find width and height to plot */
         if (height > (y1 - y0))
                 height = (y1 - y0);
-
-        if (width > (x1 - x0))
-                width = (x1 - x0);
 
 	xoff = x0 - x;
 	yoff = y0 - y;

Modified: branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c?rev=5392&r1=5391&r2=5392&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c Sun Sep 21 17:11:51 2008
@@ -107,61 +107,68 @@
 			const char *text, size_t length, colour bg, colour c)
 {
         const struct fb_font_desc* fb_font = fb_get_font(style);
-        const uint8_t *font_data;
+        const uint32_t *font_data;
+        uint32_t row;
         int xloop, yloop;
-        unsigned char row;
         size_t chr;
 
         uint32_t *pvideo;
         uint32_t fgcol;
 
 	char *buffer = NULL;
-
-        /* y is given to the fonts baseline we need it to the fonts top */
-        y-=(fb_font->height * 75)/100;
-
-        y+=1; /* he coord is the bottom-left of the pixels offset by 1 to make
-                  it work since fb coords are the top-left of pixels 
-              */
-
-        if (y + fb_font->height > fb_plot_ctx.y1)
-                return true;
-
-        if (y > fb_plot_ctx.y1)
-                return true;
-
-        if (x > fb_plot_ctx.x1)
-                return true;
-
-        if (y < fb_plot_ctx.y0)
-                return true;
-
-        if (x < fb_plot_ctx.x0)
-                return true;
-
-	utf8_to_local_encoding(text, length, &buffer);
+        int x0,y0,x1,y1;
+	int xoff, yoff; /* x and y offset into image */
+        int height = fb_font->height;
+
+        /* aquire thge text in local font encoding */
+	utf8_to_font_encoding(fb_font, text, length, &buffer);
 	if (!buffer) 
                 return true;
-
         length = strlen(buffer);
 
-        fgcol = ((c & 0xFF) << 16) | 
-                ((c & 0xFF00)) | 
-                ((c & 0xFF0000) >> 16);
-
-
+
+        /* y is given to the fonts baseline we need it to the fonts top */
+        y-=((fb_font->height * 75)/100);
+
+        y+=1; /* the coord is the bottom-left of the pixels offset by 1 to make
+               *   it work since fb coords are the top-left of pixels 
+               */
+
+        /* The part of the text displayed is cropped to the current context. */
+        x0 = x;
+        y0 = y;
+        x1 = x + (fb_font->width * length);
+        y1 = y + fb_font->height;
+
+        if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
+                return true; /* text lies outside current clipping region */
+
+        /* find width and height to plot */
+        if (height > (y1 - y0))
+                height = (y1 - y0);
+
+	xoff = x0 - x;
+	yoff = y0 - y;
+
+        fgcol = ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
 
         /*LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx",
           x,y,style,length,text,length,bg,c));*/
 
-        for (chr=0; chr < length; chr++) {
-                pvideo = fb_32bpp_get_xy_loc(x + (chr * (fb_font->width)), y);
+        for (chr = 0; chr < length; chr++, x += fb_font->width) {
+                if ((x + fb_font->width) > x1)
+                        break;
+
+                if (x < x0) 
+                        continue;
+
+                pvideo = fb_32bpp_get_xy_loc(x, y0);
 
                 /* move our font-data to the correct position */
                 font_data = fb_font->data + (buffer[chr] * fb_font->height);
 
-                for (yloop = 0; yloop < fb_font->height; yloop++) {
-                        row = font_data[yloop];
+                for (yloop = 0; yloop < height; yloop++) {
+                        row = font_data[yoff + yloop];
                         for (xloop = fb_font->width; xloop > 0 ; xloop--) {
                                 if ((row & 1) != 0)
                                         *(pvideo + xloop) = fgcol;
@@ -169,7 +176,6 @@
                         }
                         pvideo += (framebuffer->linelen >> 2);
                 }
-
         }
 
 	free(buffer);

Modified: branches/vince/netsurf-fb/framebuffer/fb_8bpp_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_8bpp_plotters.c?rev=5392&r1=5391&r2=5392&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_8bpp_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_8bpp_plotters.c Sun Sep 21 17:11:51 2008
@@ -129,59 +129,85 @@
 }
 
 static bool fb_8bpp_text(int x, int y, const struct css_style *style,
-                 const char *text, size_t length, colour bg, colour c)
+			const char *text, size_t length, colour bg, colour c)
 {
         const struct fb_font_desc* fb_font = fb_get_font(style);
-        const uint8_t *font_data;
+        const uint32_t *font_data;
+        uint32_t row;
+
         int xloop, yloop;
-        unsigned char row;
-        int fg_pent;
-        int bg_pent;
         size_t chr;
+
         uint8_t *pvideo;
-
-        if (y > fb_plot_ctx.y1)
+        uint8_t fgcol;
+
+	char *buffer = NULL;
+        int x0,y0,x1,y1;
+	int xoff, yoff; /* x and y offset into image */
+        int height = fb_font->height;
+
+        /* aquire thge text in local font encoding */
+	utf8_to_font_encoding(fb_font, text, length, &buffer);
+	if (!buffer) 
                 return true;
-
-        if (x > fb_plot_ctx.x1)
-                return true;
-
-        if (y < fb_plot_ctx.y0)
-                return true;
-
-        if (x < fb_plot_ctx.x0)
-                return true;
+        length = strlen(buffer);
+
 
         /* y is given to the fonts baseline we need it to the fonts top */
-        y-=(fb_font->height * 75)/100;
-
-
-        LOG(("x %d, y %d, style %p, txt %.*s , len %zu, bg 0x%lx, fg 0x%lx",
-             x,y,style,(int)length,text,length,bg,c));
-
-        fg_pent = find_closest_palette_entry(c);
-        bg_pent = find_closest_palette_entry(bg);
-
-        for (chr=0; chr < length; chr++) {
-                pvideo = fb_8bpp_get_xy_loc(x + (chr * (fb_font->width)), y);
+        y-=((fb_font->height * 75)/100);
+
+        y+=1; /* the coord is the bottom-left of the pixels offset by 1 to make
+               *   it work since fb coords are the top-left of pixels 
+               */
+
+        /* The part of the text displayed is cropped to the current context. */
+        x0 = x;
+        y0 = y;
+        x1 = x + (fb_font->width * length);
+        y1 = y + fb_font->height;
+
+        if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
+                return true; /* text lies outside current clipping region */
+
+        /* find width and height to plot */
+        if (height > (y1 - y0))
+                height = (y1 - y0);
+
+	xoff = x0 - x;
+	yoff = y0 - y;
+
+        fgcol = find_closest_palette_entry(c);
+
+        /*LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx",
+          x,y,style,length,text,length,bg,c));*/
+
+        for (chr = 0; chr < length; chr++, x += fb_font->width) {
+                if ((x + fb_font->width) > x1)
+                        break;
+
+                if (x < x0) 
+                        continue;
+
+                pvideo = fb_8bpp_get_xy_loc(x, y0);
 
                 /* move our font-data to the correct position */
-                font_data = fb_font->data + (text[chr] * fb_font->height);
-
-                for (yloop = 0; yloop < fb_font->height; yloop++) {
-                        row = font_data[yloop];
-                        for (xloop = fb_font->width; xloop > 0; xloop--) {
-                                if ((row & 1) == 0)
-                                        pvideo[xloop] = bg_pent;
-                                else
-                                        pvideo[xloop] = fg_pent;
-                                row >>= 1;
+                font_data = fb_font->data + (buffer[chr] * fb_font->height);
+
+                for (yloop = 0; yloop < height; yloop++) {
+                        row = font_data[yoff + yloop];
+                        for (xloop = fb_font->width; xloop > 0 ; xloop--) {
+                                if ((row & 1) != 0)
+                                        *(pvideo + xloop) = fgcol;
+                                row = row >> 1;
                         }
                         pvideo += framebuffer->linelen;
                 }
         }
-        return true;
-}
+
+	free(buffer);
+	return true;
+}
+
 
 static bool fb_8bpp_disc(int x, int y, int radius, colour c, bool filled)
 {

Modified: branches/vince/netsurf-fb/framebuffer/fb_font.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_font.h?rev=5392&r1=5391&r2=5392&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_font.h (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_font.h Sun Sep 21 17:11:51 2008
@@ -21,7 +21,7 @@
     const char *name;
     int width, height;
     const char *encoding;
-    const uint8_t *data;
+    const uint32_t *data;
 };
 
 extern const struct fb_font_desc font_vga_8x16;

Modified: branches/vince/netsurf-fb/framebuffer/font_8x16.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/font_8x16.c?rev=5392&r1=5391&r2=5392&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/font_8x16.c (original)
+++ branches/vince/netsurf-fb/framebuffer/font_8x16.c Sun Sep 21 17:11:51 2008
@@ -23,7 +23,7 @@
 
 #define FONTDATAMAX 4096
 
-static const unsigned char fontdata_8x16[FONTDATAMAX] = {
+static const uint32_t fontdata_8x16[FONTDATAMAX] = {
 
 	/* 0 0x00 '^@' */
 	0x00, /* 00000000 */




More information about the netsurf-commits mailing list