Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/c13977e353dcdc9f8a24ab939f2eeb06cf9330c3
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/c13977e353dcdc9f8a24ab939f2eeb06cf9330c3
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/c13977e353dcdc9f8a24ab939f2eeb06cf9330c3

The branch, chris/quant has been updated
       via  c13977e353dcdc9f8a24ab939f2eeb06cf9330c3 (commit)
       via  5b033bad7b58e738f6053ecadc0c07813f4f161b (commit)
       via  713430f6e5ef49960cb85fa917e73a131d69c7c8 (commit)
       via  f90ed33501485663a091baefe41a87db93d2db91 (commit)
       via  d8b6de50d6da9a965df70ad758e9631c15be9728 (commit)
       via  9ce01d2024e12881e29f4efd28845f12e56e7b67 (commit)
       via  5c567d4f2034ac227350b2d72647cd0d37ebee68 (commit)
       via  7677901edfc72228572e72f0858a55ab012f860a (commit)
       via  6ddb66ccfbf2c5627e04b9fc6a70661b764d9a93 (commit)
       via  c9d9537941a9b5b5a2b2557fd775201a2979f428 (commit)
      from  1ce58404c4adb31eb80a402f8307065c2ccfcc55 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=c13977e353dcdc9f8a24ab939f2eeb06cf9330c3
commit c13977e353dcdc9f8a24ab939f2eeb06cf9330c3
Author: Chris Young <[email protected]>
Commit: Chris Young <[email protected]>

    Map pens using a palette based on the image's one, as the default palette 
only seems to have about four colours in it.

diff --git a/amiga/bitmap.c b/amiga/bitmap.c
index de6f7f8..1d836e3 100644
--- a/amiga/bitmap.c
+++ b/amiga/bitmap.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008, 2009, 2012 Chris Young <[email protected]>
+ * Copyright 2008, 2009, 2012, 2016 Chris Young 
<[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -70,6 +70,7 @@ struct bitmap {
        PLANEPTR native_mask;
        Object *dto;
        APTR drawhandle;
+       APTR psm;
        struct nsurl *url;   /* temporary storage space */
        char *title; /* temporary storage space */
        ULONG *icondata; /* for appicons */
@@ -105,6 +106,7 @@ void *amiga_bitmap_create(int width, int height, unsigned 
int state)
        bitmap->nativebmheight = 0;
        bitmap->native_mask = NULL;
        bitmap->drawhandle = NULL;
+       bitmap->psm = NULL;
        bitmap->url = NULL;
        bitmap->title = NULL;
        bitmap->icondata = NULL;
@@ -150,6 +152,7 @@ void amiga_bitmap_destroy(void *bitmap)
 
                if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, 
bm->height);
                if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
+               if(bm->psm) DeletePenShareMap(bm->psm);
                FreeVec(bm->pixdata);
 
                if(bm->url) nsurl_unref(bm->url);
@@ -159,6 +162,7 @@ void amiga_bitmap_destroy(void *bitmap)
                bm->nativebm = NULL;
                bm->native_mask = NULL;
                bm->drawhandle = NULL;
+               bm->psm = NULL;
                bm->url = NULL;
                bm->title = NULL;
        
@@ -202,9 +206,11 @@ void amiga_bitmap_modified(void *bitmap)
                ami_rtg_freebitmap(bm->nativebm);
                
        if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
+       if(bm->psm) DeletePenShareMap(bm->psm);
        if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, bm->height);
        bm->nativebm = NULL;
        bm->drawhandle = NULL;
+       bm->psm = NULL;
        bm->native_mask = NULL;
        bm->native = AMI_NSBM_NONE;
 }
@@ -412,10 +418,7 @@ static inline struct BitMap *ami_bitmap_get_generic(struct 
bitmap *bitmap, int w
                                (bitmap->nativebmheight == bitmap->height)) { 
// >= width/height ?
                        tbm = bitmap->nativebm;
                } else {
-                       if(bitmap->nativebm) {
-                                       ami_rtg_freebitmap(bitmap->nativebm);
-                       }
-                       bitmap->nativebm = NULL;
+                       if(bitmap->nativebm) amiga_bitmap_modified(bitmap);
                }
        }
 
@@ -448,7 +451,11 @@ static inline struct BitMap *ami_bitmap_get_generic(struct 
bitmap *bitmap, int w
                                        break;
                                }
 
-                               bitmap->drawhandle = ObtainDrawHandle(NULL, 
&rp, scrn->ViewPort.ColorMap,
+                               bitmap->psm = CreatePenShareMap(TAG_DONE);
+                               AddPixelArray(bitmap->psm, (ULONG 
*)amiga_bitmap_get_buffer(bitmap),
+                                                               bitmap->width, 
bitmap->height,
+                                                               
GGFX_PixelFormat, PIXFMT_0RGB_32, TAG_DONE);
+                               bitmap->drawhandle = 
ObtainDrawHandle(bitmap->psm, &rp, scrn->ViewPort.ColorMap,
                                                                                
GGFX_DitherMode, dithermode,
                                                                                
TAG_DONE);
 
diff --git a/amiga/gui.c b/amiga/gui.c
index 012e46c..cdc00fb 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5503,6 +5503,7 @@ int main(int argc, char** argv)
                .search_web = &amiga_search_web_table,
                .llcache = filesystem_llcache_table,
                .bitmap = amiga_bitmap_table,
+               .layout = ami_layout_table,
        };
 
 #ifdef __amigaos4__


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=5b033bad7b58e738f6053ecadc0c07813f4f161b
commit 5b033bad7b58e738f6053ecadc0c07813f4f161b
Merge: 1ce5840 713430f
Author: Chris Young <[email protected]>
Commit: Chris Young <[email protected]>

    Merge branch 'master' of git://git.netsurf-browser.org/netsurf into 
chris/quant



-----------------------------------------------------------------------

Summary of changes:
 amiga/bitmap.c        |   19 ++--
 amiga/font.c          |   17 ++--
 amiga/font.h          |    3 +
 amiga/font_diskfont.c |    1 -
 amiga/gui.c           |    1 +
 amiga/print.c         |    5 +-
 atari/font.c          |  153 +++++++++++++++++++++++----------
 atari/font.h          |    1 +
 atari/gui.c           |    6 +-
 beos/bitmap.cpp       |    1 -
 beos/font.cpp         |  229 ++++++++++++++++++++++++-------------------------
 beos/font.h           |   11 ++-
 beos/gui.cpp          |    7 +-
 beos/plotters.cpp     |    1 -
 beos/scaffolding.cpp  |    1 -
 beos/window.cpp       |    1 -
 cocoa/NetsurfApp.m    |    2 +
 cocoa/font.h          |    4 +-
 cocoa/font.m          |   53 +++++++-----
 windows/font.c        |   38 ++++----
 windows/font.h        |    1 +
 windows/main.c        |    1 +
 22 files changed, 321 insertions(+), 235 deletions(-)

diff --git a/amiga/bitmap.c b/amiga/bitmap.c
index de6f7f8..1d836e3 100644
--- a/amiga/bitmap.c
+++ b/amiga/bitmap.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008, 2009, 2012 Chris Young <[email protected]>
+ * Copyright 2008, 2009, 2012, 2016 Chris Young 
<[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -70,6 +70,7 @@ struct bitmap {
        PLANEPTR native_mask;
        Object *dto;
        APTR drawhandle;
+       APTR psm;
        struct nsurl *url;   /* temporary storage space */
        char *title; /* temporary storage space */
        ULONG *icondata; /* for appicons */
@@ -105,6 +106,7 @@ void *amiga_bitmap_create(int width, int height, unsigned 
int state)
        bitmap->nativebmheight = 0;
        bitmap->native_mask = NULL;
        bitmap->drawhandle = NULL;
+       bitmap->psm = NULL;
        bitmap->url = NULL;
        bitmap->title = NULL;
        bitmap->icondata = NULL;
@@ -150,6 +152,7 @@ void amiga_bitmap_destroy(void *bitmap)
 
                if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, 
bm->height);
                if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
+               if(bm->psm) DeletePenShareMap(bm->psm);
                FreeVec(bm->pixdata);
 
                if(bm->url) nsurl_unref(bm->url);
@@ -159,6 +162,7 @@ void amiga_bitmap_destroy(void *bitmap)
                bm->nativebm = NULL;
                bm->native_mask = NULL;
                bm->drawhandle = NULL;
+               bm->psm = NULL;
                bm->url = NULL;
                bm->title = NULL;
        
@@ -202,9 +206,11 @@ void amiga_bitmap_modified(void *bitmap)
                ami_rtg_freebitmap(bm->nativebm);
                
        if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
+       if(bm->psm) DeletePenShareMap(bm->psm);
        if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, bm->height);
        bm->nativebm = NULL;
        bm->drawhandle = NULL;
+       bm->psm = NULL;
        bm->native_mask = NULL;
        bm->native = AMI_NSBM_NONE;
 }
@@ -412,10 +418,7 @@ static inline struct BitMap *ami_bitmap_get_generic(struct 
bitmap *bitmap, int w
                                (bitmap->nativebmheight == bitmap->height)) { 
// >= width/height ?
                        tbm = bitmap->nativebm;
                } else {
-                       if(bitmap->nativebm) {
-                                       ami_rtg_freebitmap(bitmap->nativebm);
-                       }
-                       bitmap->nativebm = NULL;
+                       if(bitmap->nativebm) amiga_bitmap_modified(bitmap);
                }
        }
 
@@ -448,7 +451,11 @@ static inline struct BitMap *ami_bitmap_get_generic(struct 
bitmap *bitmap, int w
                                        break;
                                }
 
-                               bitmap->drawhandle = ObtainDrawHandle(NULL, 
&rp, scrn->ViewPort.ColorMap,
+                               bitmap->psm = CreatePenShareMap(TAG_DONE);
+                               AddPixelArray(bitmap->psm, (ULONG 
*)amiga_bitmap_get_buffer(bitmap),
+                                                               bitmap->width, 
bitmap->height,
+                                                               
GGFX_PixelFormat, PIXFMT_0RGB_32, TAG_DONE);
+                               bitmap->drawhandle = 
ObtainDrawHandle(bitmap->psm, &rp, scrn->ViewPort.ColorMap,
                                                                                
GGFX_DitherMode, dithermode,
                                                                                
TAG_DONE);
 
diff --git a/amiga/font.c b/amiga/font.c
index 39cb386..1c9702a 100644
--- a/amiga/font.c
+++ b/amiga/font.c
@@ -25,7 +25,7 @@
 #include "utils/log.h"
 #include "utils/nsoption.h"
 #include "desktop/browser.h"
-#include "desktop/font.h"
+#include "desktop/gui_layout.h"
 
 #include "amiga/font.h"
 #include "amiga/font_bullet.h"
@@ -119,7 +119,7 @@ void ami_font_fini(void)
 }
 
 /* Stub entry points */
-static bool nsfont_width(const plot_font_style_t *fstyle,
+static nserror ami_font_width(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int *width)
 {
@@ -127,7 +127,7 @@ static bool nsfont_width(const plot_font_style_t *fstyle,
        return ami_nsfont->width(fstyle, string, length, width);
 }
 
-static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
+static nserror ami_font_position(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int x, size_t *char_offset, int *actual_x)
 {
@@ -135,7 +135,7 @@ static bool nsfont_position_in_string(const 
plot_font_style_t *fstyle,
        return ami_nsfont->posn(fstyle, string, length, x, char_offset, 
actual_x);
 }
 
-static bool nsfont_split(const plot_font_style_t *fstyle,
+static nserror ami_font_split(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int x, size_t *char_offset, int *actual_x)
 {
@@ -143,9 +143,10 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
        return ami_nsfont->split(fstyle, string, length, x, char_offset, 
actual_x);
 }
 
-const struct font_functions nsfont = {
-       nsfont_width,
-       nsfont_position_in_string,
-       nsfont_split
+static struct gui_layout_table layout_table = {
+       .width = ami_font_width,
+       .position = ami_font_position,
+       .split = ami_font_split,
 };
 
+struct gui_layout_table *ami_layout_table = &layout_table;
diff --git a/amiga/font.h b/amiga/font.h
index da23b59..a0b63d0 100755
--- a/amiga/font.h
+++ b/amiga/font.h
@@ -55,5 +55,8 @@ struct ami_font_functions {
 };
 
 const struct ami_font_functions *ami_nsfont;
+
+struct gui_layout_table *ami_layout_table;
+
 #endif
 
diff --git a/amiga/font_diskfont.c b/amiga/font_diskfont.c
index 6ad6e79..91bec20 100644
--- a/amiga/font_diskfont.c
+++ b/amiga/font_diskfont.c
@@ -30,7 +30,6 @@
 #include "utils/log.h"
 #include "utils/utf8.h"
 #include "utils/nsoption.h"
-#include "desktop/font.h"
 
 #include "amiga/font.h"
 #include "amiga/font_diskfont.h"
diff --git a/amiga/gui.c b/amiga/gui.c
index 012e46c..cdc00fb 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -5503,6 +5503,7 @@ int main(int argc, char** argv)
                .search_web = &amiga_search_web_table,
                .llcache = filesystem_llcache_table,
                .bitmap = amiga_bitmap_table,
+               .layout = ami_layout_table,
        };
 
 #ifdef __amigaos4__
diff --git a/amiga/print.c b/amiga/print.c
index 72b83e8..908b026 100644
--- a/amiga/print.c
+++ b/amiga/print.c
@@ -50,12 +50,13 @@
 #include "utils/messages.h"
 #include "utils/utils.h"
 #include "desktop/printer.h"
-#include "desktop/font.h"
+#include "desktop/gui_layout.h"
 #include "desktop/mouse.h"
 #include "desktop/gui_window.h"
 #include "content/hlcache.h"
 
 #include "amiga/plotters.h"
+#include "amiga/font.h"
 #include "amiga/gui.h"
 #include "amiga/libs.h"
 #include "amiga/misc.h"
@@ -414,7 +415,7 @@ void ami_print(struct hlcache_handle *c, int copies)
        ami_print_info.PD = (struct PrinterData 
*)ami_print_info.PReq->io_Device;
        ami_print_info.PED = &ami_print_info.PD->pd_SegmentData->ps_PED;
 
-       ami_print_info.ps = print_make_settings(PRINT_DEFAULT, 
nsurl_access(hlcache_handle_get_url(c)), &nsfont);
+       ami_print_info.ps = print_make_settings(PRINT_DEFAULT, 
nsurl_access(hlcache_handle_get_url(c)), ami_layout_table);
        ami_print_info.ps->page_width = ami_print_info.PED->ped_MaxXDots;
        ami_print_info.ps->page_height = ami_print_info.PED->ped_MaxYDots;
        ami_print_info.ps->scale = scale;
diff --git a/atari/font.c b/atari/font.c
index 729986c..cb0c574 100644
--- a/atari/font.c
+++ b/atari/font.c
@@ -19,11 +19,12 @@
 #include <inttypes.h>
 #include <assert.h>
 #include <stdbool.h>
+#include <stdlib.h>
 
-#include "desktop/font.h"
 #include "utils/utf8.h"
 #include "utils/log.h"
 #include "utils/nsoption.h"
+#include "desktop/gui_layout.h"
 #include "desktop/mouse.h"
 #include "desktop/plotters.h"
 
@@ -35,61 +36,121 @@
 
 extern FONT_PLOTTER fplotter;
 
-static bool atari_font_position_in_string(const plot_font_style_t * 
fstyle,const char *string,
-                                               size_t length,int x, size_t 
*char_offset, int *actual_x )
-{
-    float scale = plot_get_scale();
-
-    if (scale != 1.0) {
-        plot_font_style_t newstyle = *fstyle;
-        newstyle.size = (int)((float)fstyle->size*scale);
-        fplotter->pixel_pos(fplotter, &newstyle, string, length, x, 
char_offset, actual_x);
-    } else {
-        fplotter->pixel_pos(fplotter, fstyle, string, length, x, char_offset, 
actual_x);
-    }
 
-       return( true );
-}
-
-static bool atari_font_split( const plot_font_style_t * fstyle, const char 
*string,
-                                         size_t length,int x, size_t 
*char_offset, int *actual_x )
+/**
+ * Find the position in a string where an x coordinate falls.
+ *
+ * \param[in] fstyle style for this text
+ * \param[in] string UTF-8 string to measure
+ * \param[in] length length of string, in bytes
+ * \param[in] x coordinate to search for
+ * \param[out] char_offset updated to offset in string of actual_x, [0..length]
+ * \param[out] actual_x updated to x coordinate of character closest to x
+ * \return NSERROR_OK and char_offset and actual_x updated or appropriate 
error code on faliure
+ */
+static nserror
+atari_font_position(const plot_font_style_t *fstyle,
+                   const char *string,
+                   size_t length,
+                   int x,
+                   size_t *char_offset,
+                   int *actual_x)
 {
-    float scale = plot_get_scale();
-
-    if (scale != 1.0) {
-        plot_font_style_t newstyle = *fstyle;
-        newstyle.size = (int)((float)fstyle->size*scale);
-        fplotter->str_split(fplotter, &newstyle, string, length, x, 
char_offset,
-                            actual_x);
-    } else {
-        fplotter->str_split(fplotter, fstyle, string, length, x, char_offset,
-                            actual_x);
-    }
+       float scale = plot_get_scale();
+
+       if (scale != 1.0) {
+               plot_font_style_t newstyle = *fstyle;
+               newstyle.size = (int)((float)fstyle->size*scale);
+               fplotter->pixel_pos(fplotter, &newstyle, string, length, x,
+                                   char_offset, actual_x);
+       } else {
+               fplotter->pixel_pos(fplotter, fstyle, string, length, x,
+                                   char_offset, actual_x);
+       }
+
+       return NSERROR_OK;
+}
 
 
-       return( true );
+/**
+ * Find where to split a string to make it fit a width.
+ *
+ * \param[in] fstyle       style for this text
+ * \param[in] string       UTF-8 string to measure
+ * \param[in] length       length of string, in bytes
+ * \param[in] x            width available
+ * \param[out] char_offset updated to offset in string of actual_x, [1..length]
+ * \param[out] actual_x updated to x coordinate of character closest to x
+ * \return NSERROR_OK or appropriate error code on faliure
+ *
+ * On exit, char_offset indicates first character after split point.
+ *
+ * \note char_offset of 0 must never be returned.
+ *
+ *   Returns:
+ *     char_offset giving split point closest to x, where actual_x <= x
+ *   else
+ *     char_offset giving split point closest to x, where actual_x > x
+ *
+ * Returning char_offset == length means no split possible
+ */
+static nserror
+atari_font_split(const plot_font_style_t *fstyle,
+                const char *string,
+                size_t length,
+                int x,
+                size_t *char_offset,
+                int *actual_x)
+{
+       float scale = plot_get_scale();
+
+       if (scale != 1.0) {
+               plot_font_style_t newstyle = *fstyle;
+               newstyle.size = (int)((float)fstyle->size*scale);
+               fplotter->str_split(fplotter, &newstyle, string, length, x,
+                                   char_offset, actual_x);
+       } else {
+               fplotter->str_split(fplotter, fstyle, string, length, x,
+                                   char_offset, actual_x);
+       }
+
+       return NSERROR_OK;
 }
 
-static bool atari_font_width( const plot_font_style_t *fstyle, const char * 
str,
-                                         size_t length, int * width  )
-{
-    float scale = plot_get_scale();
 
-    if (scale != 1.0) {
-        plot_font_style_t newstyle = *fstyle;
-        newstyle.size = (int)((float)fstyle->size*scale);
-        fplotter->str_width(fplotter, &newstyle, str, length, width);
-    } else {
-        fplotter->str_width(fplotter, fstyle, str, length, width);
-    }
+/**
+ * Measure the width of a string.
+ *
+ * \param[in] fstyle plot style for this text
+ * \param[in] string UTF-8 string to measure
+ * \param[in] length length of string, in bytes
+ * \param[out] width updated to width of string[0..length)
+ * \return NSERROR_OK and width updated or appropriate error code on faliure
+ */
+static nserror
+atari_font_width(const plot_font_style_t *fstyle,
+                const char *str,
+                size_t length,
+                int * width)
+{
+       float scale = plot_get_scale();
 
+       if (scale != 1.0) {
+               plot_font_style_t newstyle = *fstyle;
+               newstyle.size = (int)((float)fstyle->size*scale);
+               fplotter->str_width(fplotter, &newstyle, str, length, width);
+       } else {
+               fplotter->str_width(fplotter, fstyle, str, length, width);
+       }
 
-       return( true );
+       return NSERROR_OK;
 }
 
-const struct font_functions nsfont = {
-       atari_font_width,
-       atari_font_position_in_string,
-       atari_font_split
+
+static struct gui_layout_table layout_table = {
+       .width = atari_font_width,
+       .position = atari_font_position,
+       .split = atari_font_split,
 };
 
+struct gui_layout_table *atari_layout_table = &layout_table;
diff --git a/atari/font.h b/atari/font.h
index 065a35a..a01d000 100644
--- a/atari/font.h
+++ b/atari/font.h
@@ -19,6 +19,7 @@
 #ifndef NS_ATARI_FONT_H
 #define NS_ATARI_FONT_H
 
+struct gui_layout_table *atari_layout_table;
 
 #endif /* NETSURF_FB_FONT_H */
 
diff --git a/atari/gui.c b/atari/gui.c
index 5e5ef19..47b6693 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -35,7 +35,7 @@
 #include "content/hlcache.h"
 #include "desktop/treeview.h"
 #include "desktop/browser.h"
-#include "desktop/font.h"
+#include "desktop/gui_layout.h"
 #include "desktop/gui_window.h"
 #include "desktop/gui_clipboard.h"
 #include "desktop/gui_fetch.h"
@@ -66,6 +66,7 @@
 #include "atari/file.h"
 #include "atari/filetype.h"
 #include "atari/bitmap.h"
+#include "atari/font.h"
 #include "cflib.h"
 
 static bool atari_quit = false;
@@ -1118,7 +1119,8 @@ int main(int argc, char** argv)
        .utf8 = atari_utf8_table,
        .search = atari_search_table,
        .llcache = filesystem_llcache_table,
-       .bitmap = atari_bitmap_table
+       .bitmap = atari_bitmap_table,
+       .layout = atari_layout_table
     };
 
     ret = netsurf_register(&atari_table);
diff --git a/beos/bitmap.cpp b/beos/bitmap.cpp
index 53bf594..26b7a39 100644
--- a/beos/bitmap.cpp
+++ b/beos/bitmap.cpp
@@ -42,7 +42,6 @@ extern "C" {
 #include "content/urldb.h"
 #include "desktop/plotters.h"
 #include "desktop/browser.h"
-#include "desktop/font.h"
 #include "image/bitmap.h"
 }
 
diff --git a/beos/font.cpp b/beos/font.cpp
index cba3e4d..87c2346 100644
--- a/beos/font.cpp
+++ b/beos/font.cpp
@@ -30,33 +30,112 @@
 #include <Font.h>
 #include <String.h>
 #include <View.h>
+
 extern "C" {
-#include "desktop/font.h"
 #include "utils/utils.h"
 #include "utils/log.h"
 #include "utils/nsoption.h"
 #include "utils/nsurl.h"
+#include "desktop/gui_layout.h"
 }
 
 #include "beos/gui.h"
 #include "beos/font.h"
 #include "beos/plotters.h"
 
-static bool nsfont_width(const plot_font_style_t *fstyle,
-               const char *string, size_t length,
-               int *width);
-static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
-               const char *string, size_t length,
-               int x, size_t *char_offset, int *actual_x);
-static bool nsfont_split(const plot_font_style_t *fstyle,
-               const char *string, size_t length,
-               int x, size_t *char_offset, int *actual_x);
 
-const struct font_functions nsfont = {
-       nsfont_width,
-       nsfont_position_in_string,
-       nsfont_split
-};
+/**
+ * Convert a font style to a PangoFontDescription.
+ *
+ * \param font Beos font object.
+ * \param fstyle style for this text
+ */
+void nsbeos_style_to_font(BFont &font, const struct plot_font_style *fstyle)
+{
+       float size;
+       uint16 face = 0;
+       const char *family;
+
+       switch (fstyle->family) {
+       case PLOT_FONT_FAMILY_SERIF:
+               family = nsoption_charp(font_serif);
+               break;
+       case PLOT_FONT_FAMILY_MONOSPACE:
+               family = nsoption_charp(font_mono);
+               break;
+       case PLOT_FONT_FAMILY_CURSIVE:
+               family = nsoption_charp(font_cursive);
+               break;
+       case PLOT_FONT_FAMILY_FANTASY:
+               family = nsoption_charp(font_fantasy);
+               break;
+       case PLOT_FONT_FAMILY_SANS_SERIF:
+       default:
+               family = nsoption_charp(font_sans);
+               break;
+       }
+
+       if ((fstyle->flags & FONTF_ITALIC)) {
+               face = B_ITALIC_FACE;
+       } else if ((fstyle->flags & FONTF_OBLIQUE)) {
+               face = B_ITALIC_FACE;
+               // XXX: no OBLIQUE flag ??
+               // maybe find "Oblique" style
+               // or use SetShear() ?
+       }
+
+#ifndef __HAIKU__XXX
+       if (fstyle->weight >= 600) {
+               face |= B_BOLD_FACE;
+       }
+#else
+       if (fstyle->weight >= 600) {
+               if (fstyle->weight >= 800)
+                       face |= B_HEAVY_FACE;
+               else
+                       face |= B_BOLD_FACE;
+       } else if (fstyle->weight <= 300) {
+               face |= B_LIGHT_FACE;
+       }
+#endif
+/*
+       case CSS_FONT_WEIGHT_100: weight = 100; break;
+       case CSS_FONT_WEIGHT_200: weight = 200; break;
+       case CSS_FONT_WEIGHT_300: weight = 300; break;
+       case CSS_FONT_WEIGHT_400: weight = 400; break;
+       case CSS_FONT_WEIGHT_500: weight = 500; break;
+       case CSS_FONT_WEIGHT_600: weight = 600; break;
+       case CSS_FONT_WEIGHT_700: weight = 700; break;
+       case CSS_FONT_WEIGHT_800: weight = 800; break;
+       case CSS_FONT_WEIGHT_900: weight = 900; break;
+*/
+
+       if (!face)
+               face = B_REGULAR_FACE;
+
+//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", 
style->font_family, style->font_style, style->font_weight, family, face);
+
+       if (family) {
+               font_family beos_family;
+
+               strncpy(beos_family, family, B_FONT_FAMILY_LENGTH);
+               // Ensure it's terminated
+               beos_family[B_FONT_FAMILY_LENGTH] = '\0';
+
+               font.SetFamilyAndFace(beos_family, face);
+       } else {
+               //XXX not used
+               font = be_plain_font;
+               font.SetFace(face);
+       }
+
+//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", 
style->font_size.value.length.value, style->font_size.value.length.unit);
+       size = fstyle->size / FONT_SIZE_SCALE;
+
+//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, 
style->font_size.value.length.unit);
+
+       font.SetSize(size);
+}
 
 
 /**
@@ -68,8 +147,7 @@ const struct font_functions nsfont = {
  * \param  width   updated to width of string[0..length)
  * \return  true on success, false on error and error reported
  */
-
-bool nsfont_width(const plot_font_style_t *fstyle,
+static nserror beos_font_width(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int *width)
 {
@@ -78,12 +156,13 @@ bool nsfont_width(const plot_font_style_t *fstyle,
 
        if (length == 0) {
                *width = 0;
-               return true;
+               return NSERROR_OK;
        }
 
        nsbeos_style_to_font(font, fstyle);
        *width = (int)font.StringWidth(string, length);
-       return true;
+
+       return NSERROR_OK;
 }
 
 
@@ -93,6 +172,7 @@ static int utf8_char_len(const char *c)
        uint8 m = 0xE0;
        uint8 v = 0xC0;
        int i;
+
        if (!*p)
                return 0;
        if ((*p & 0x80) == 0)
@@ -120,8 +200,7 @@ static int utf8_char_len(const char *c)
  * \param  actual_x    updated to x coordinate of character closest to x
  * \return  true on success, false on error and error reported
  */
-
-bool nsfont_position_in_string(const plot_font_style_t *fstyle,
+static nserror beos_font_position(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int x, size_t *char_offset, int *actual_x)
 {
@@ -137,6 +216,7 @@ bool nsfont_position_in_string(const plot_font_style_t 
*fstyle,
        float esc = 0.0;
        float current = 0.0;
        int i;
+
        index = 0;
        font.GetEscapements(string, len, escapements);
        // slow but it should work
@@ -151,7 +231,7 @@ bool nsfont_position_in_string(const plot_font_style_t 
*fstyle,
        *actual_x = (int)current;
        *char_offset = i; //index;
 
-       return true;
+       return NSERROR_OK;
 }
 
 
@@ -177,8 +257,7 @@ bool nsfont_position_in_string(const plot_font_style_t 
*fstyle,
  *
  * Returning char_offset == length means no split possible
  */
-
-bool nsfont_split(const plot_font_style_t *fstyle,
+static nserror beos_font_split(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int x, size_t *char_offset, int *actual_x)
 {
@@ -196,6 +275,7 @@ bool nsfont_split(const plot_font_style_t *fstyle,
        float last_x = 0.0;
        int i;
        int last_space = 0;
+
        font.GetEscapements(string, len, escapements);
        // very slow but it should work
        for (i = 0; string[index] && i < len; i++) {
@@ -206,7 +286,7 @@ bool nsfont_split(const plot_font_style_t *fstyle,
                if (x < current && last_space != 0) {
                        *actual_x = (int)last_x;
                        *char_offset = last_space;
-                       return true;
+                       return NSERROR_OK;;
                }
                esc += escapements[i];
                current = font.Size() * esc;
@@ -215,7 +295,7 @@ bool nsfont_split(const plot_font_style_t *fstyle,
        *actual_x = MIN(*actual_x, (int)current);
        *char_offset = index;
 
-       return true;
+       return NSERROR_OK;
 }
 
 
@@ -285,95 +365,10 @@ bool nsfont_paint(const plot_font_style_t *fstyle,
 }
 
 
-/**
- * Convert a font style to a PangoFontDescription.
- *
- * \param font Beos font object.
- * \param fstyle style for this text
- */
-void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle)
-{
-       float size;
-       uint16 face = 0;
-       const char *family;
-
-       switch (fstyle->family) {
-       case PLOT_FONT_FAMILY_SERIF:
-               family = nsoption_charp(font_serif);
-               break;
-       case PLOT_FONT_FAMILY_MONOSPACE:
-               family = nsoption_charp(font_mono);
-               break;
-       case PLOT_FONT_FAMILY_CURSIVE:
-               family = nsoption_charp(font_cursive);
-               break;
-       case PLOT_FONT_FAMILY_FANTASY:
-               family = nsoption_charp(font_fantasy);
-               break;
-       case PLOT_FONT_FAMILY_SANS_SERIF:
-       default:
-               family = nsoption_charp(font_sans);
-               break;
-       }
-
-       if ((fstyle->flags & FONTF_ITALIC)) {
-               face = B_ITALIC_FACE;
-       } else if ((fstyle->flags & FONTF_OBLIQUE)) {
-               face = B_ITALIC_FACE;
-               // XXX: no OBLIQUE flag ??
-               // maybe find "Oblique" style
-               // or use SetShear() ?
-       }
-
-#ifndef __HAIKU__XXX
-       if (fstyle->weight >= 600) {
-               face |= B_BOLD_FACE;
-       }
-#else
-       if (fstyle->weight >= 600) {
-               if (fstyle->weight >= 800)
-                       face |= B_HEAVY_FACE;
-               else
-                       face |= B_BOLD_FACE;
-       } else if (fstyle->weight <= 300) {
-               face |= B_LIGHT_FACE;
-       }
-#endif
-/*
-       case CSS_FONT_WEIGHT_100: weight = 100; break;
-       case CSS_FONT_WEIGHT_200: weight = 200; break;
-       case CSS_FONT_WEIGHT_300: weight = 300; break;
-       case CSS_FONT_WEIGHT_400: weight = 400; break;
-       case CSS_FONT_WEIGHT_500: weight = 500; break;
-       case CSS_FONT_WEIGHT_600: weight = 600; break;
-       case CSS_FONT_WEIGHT_700: weight = 700; break;
-       case CSS_FONT_WEIGHT_800: weight = 800; break;
-       case CSS_FONT_WEIGHT_900: weight = 900; break;
-*/
-
-       if (!face)
-               face = B_REGULAR_FACE;
-
-//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", 
style->font_family, style->font_style, style->font_weight, family, face);
-
-       if (family) {
-               font_family beos_family;
-
-               strncpy(beos_family, family, B_FONT_FAMILY_LENGTH);
-               // Ensure it's terminated
-               beos_family[B_FONT_FAMILY_LENGTH] = '\0';
-
-               font.SetFamilyAndFace(beos_family, face);
-       } else {
-               //XXX not used
-               font = be_plain_font;
-               font.SetFace(face);
-       }
-
-//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", 
style->font_size.value.length.value, style->font_size.value.length.unit);
-       size = fstyle->size / FONT_SIZE_SCALE;
-
-//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, 
style->font_size.value.length.unit);
+static struct gui_layout_table layout_table = {
+  /*.width = */beos_font_width,
+  /*.position = */beos_font_position,
+  /*.split = */beos_font_split
+};
 
-       font.SetSize(size);
-}
+struct gui_layout_table *beos_layout_table = &layout_table;
diff --git a/beos/font.h b/beos/font.h
index aefd898..75f0c3a 100644
--- a/beos/font.h
+++ b/beos/font.h
@@ -17,9 +17,12 @@
  */
 
 /** \file
- * Font handling (GTK interface).
+ * Beos font layout handling interface.
  */
 
+#ifndef NS_BEOS_FONT_H
+#define NS_BEOS_FONT_H
+
 #include <stdbool.h>
 
 #include "desktop/plotters.h"
@@ -28,4 +31,8 @@ bool nsfont_paint(const plot_font_style_t *fstyle,
                const char *string, size_t length,
                int x, int y);
 
-void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle);
+void nsbeos_style_to_font(BFont &font, const struct plot_font_style *fstyle);
+
+extern struct gui_layout_table *beos_layout_table;
+
+#endif
diff --git a/beos/gui.cpp b/beos/gui.cpp
index c91cc43..5171b21 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -82,6 +82,7 @@ extern "C" {
 #include "beos/fetch_rsrc.h"
 #include "beos/scaffolding.h"
 #include "beos/bitmap.h"
+#include "beos/font.h"
 
 //TODO: use resources
 // enable using resources instead of files
@@ -989,7 +990,8 @@ int main(int argc, char** argv)
                 NULL, /* default search */
                 NULL, /* default web search */
                 NULL, /* default low level cache persistant storage */
-                beos_bitmap_table
+                beos_bitmap_table,
+                beos_layout_table
        };
 
         ret = netsurf_register(&beos_table);
@@ -1069,7 +1071,8 @@ int gui_init_replicant(int argc, char** argv)
                 NULL, /* default search */
                 NULL, /* default web search */
                 NULL, /* default low level cache persistant storage */
-                beos_bitmap_table
+                beos_bitmap_table,
+                beos_layout_table
        };
 
         ret = netsurf_register(&beos_table);
diff --git a/beos/plotters.cpp b/beos/plotters.cpp
index f63d734..b7d1a2b 100644
--- a/beos/plotters.cpp
+++ b/beos/plotters.cpp
@@ -32,7 +32,6 @@
 #include <Shape.h>
 extern "C" {
 #include "desktop/plotters.h"
-#include "desktop/font.h"
 #include "utils/log.h"
 #include "utils/utils.h"
 #include "utils/nsoption.h"
diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp
index 61e5f13..d189e9a 100644
--- a/beos/scaffolding.cpp
+++ b/beos/scaffolding.cpp
@@ -62,7 +62,6 @@ extern "C" {
 #include "desktop/plotters.h"
 #include "utils/nsoption.h"
 #include "desktop/textinput.h"
-#include "desktop/font.h"
 #include "render/form.h"
 #include "utils/messages.h"
 #include "utils/utils.h"
diff --git a/beos/window.cpp b/beos/window.cpp
index f6fc504..23ae283 100644
--- a/beos/window.cpp
+++ b/beos/window.cpp
@@ -28,7 +28,6 @@ extern "C" {
 #include "desktop/mouse.h"
 #include "utils/nsoption.h"
 #include "desktop/textinput.h"
-#include "desktop/font.h"
 #include "utils/log.h"
 #include "utils/utf8.h"
 #include "utils/utils.h"
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 3d5ff06..ec798be 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -25,6 +25,7 @@
 #import "cocoa/selection.h"
 #import "cocoa/fetch.h"
 #import "cocoa/bitmap.h"
+#import "cocoa/font.h"
 
 #import "utils/filename.h"
 #import "utils/log.h"
@@ -235,6 +236,7 @@ int main( int argc, char **argv )
                 .fetch = cocoa_fetch_table,
                 .search = cocoa_search_table,
                 .bitmap = cocoa_bitmap_table,
+                .layout = cocoa_layout_table,
         };
 
         error = netsurf_register(&cocoa_table);
diff --git a/cocoa/font.h b/cocoa/font.h
index 2a31e2c..cabd2b9 100644
--- a/cocoa/font.h
+++ b/cocoa/font.h
@@ -21,6 +21,8 @@
 
 #import "desktop/plot_style.h"
 
-void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t 
length, const plot_font_style_t *style );
+void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t 
length, const struct plot_font_style *style );
+
+struct gui_layout_table *cocoa_layout_table;
 
 #endif
diff --git a/cocoa/font.m b/cocoa/font.m
index 338339b..f52ec85 100644
--- a/cocoa/font.m
+++ b/cocoa/font.m
@@ -22,7 +22,7 @@
 #import "cocoa/font.h"
 
 #import "utils/nsoption.h"
-#import "desktop/font.h"
+#import "desktop/gui_layout.h"
 #import "desktop/plotters.h"
 
 
@@ -38,21 +38,24 @@ static NSDictionary *cocoa_font_attributes( const 
plot_font_style_t *style );
 static NSTextStorage *cocoa_text_storage = nil;
 static NSTextContainer *cocoa_text_container = nil;
 
-static bool nsfont_width(const plot_font_style_t *style,
-                                                const char *string, size_t 
length,
-                                                int *width)
+static nserror cocoa_font_width(const plot_font_style_t *style,
+                            const char *string, size_t length,
+                            int *width)
 {
-       NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, 
style );
+       NSLayoutManager *layout;
+        layout = cocoa_prepare_layout_manager( string, length, style );
        *width = cocoa_layout_width( layout );
-       return true;
+       return NSERROR_OK;
 }
 
-static bool nsfont_position_in_string(const plot_font_style_t *style,
-                                                                         const 
char *string, size_t length,
-                                                                         int 
x, size_t *char_offset, int *actual_x)
+static nserror cocoa_font_position(const plot_font_style_t *style,
+                                   const char *string, size_t length,
+                                   int x, size_t *char_offset, int *actual_x)
 {
        NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, 
style );
-       if (layout == nil) return false;
+       if (layout == nil) {
+                return NSERROR_BAD_PARAMETER;
+        }
        
        NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
        NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
@@ -61,17 +64,17 @@ static bool nsfont_position_in_string(const 
plot_font_style_t *style,
        else *char_offset = cocoa_bytes_for_characters( string, chars );
        
        *actual_x = cocoa_pt_to_px( NSMaxX( [layout boundingRectForGlyphRange: 
NSMakeRange( glyphIndex - 1, 1 ) 
-                                                                               
  inTextContainer: cocoa_text_container] ) );
+                                                              inTextContainer: 
cocoa_text_container] ) );
        
-       return true;
+       return NSERROR_OK;
 }
 
-static bool nsfont_split(const plot_font_style_t *style,
-                                                const char *string, size_t 
length,
-                                                int x, size_t *char_offset, 
int *actual_x)
+static nserror cocoa_font_split(const plot_font_style_t *style,
+                                const char *string, size_t length,
+                                int x, size_t *char_offset, int *actual_x)
 {
        NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, 
style );
-       if (layout == nil) return false;
+       if (layout == nil) return NSERROR_BAD_PARAMETER;
 
        NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
        NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
@@ -79,7 +82,7 @@ static bool nsfont_split(const plot_font_style_t *style,
        if (chars >= [cocoa_text_storage length]) {
                *char_offset = length;
                *actual_x = cocoa_layout_width( layout );
-               return true;
+               return NSERROR_OK;
        }
        
 
@@ -87,21 +90,25 @@ static bool nsfont_split(const plot_font_style_t *style,
        if (chars == NSNotFound) {
                *char_offset = 0;
                *actual_x = 0;
-               return true;
+               return NSERROR_OK;
        }
        
        *char_offset = cocoa_bytes_for_characters( string, chars );
        *actual_x = cocoa_layout_width_chars( layout, chars );
        
-       return true;
+       return NSERROR_OK;
 }
 
-const struct font_functions nsfont = {
-       nsfont_width,
-       nsfont_position_in_string,
-       nsfont_split
+
+static struct gui_layout_table layout_table = {
+       .width = cocoa_font_width,
+       .position = cocoa_font_position,
+       .split = cocoa_font_split,
 };
 
+struct gui_layout_table *cocoa_layout_table = &layout_table;
+
+
 #pragma mark -
 
 void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t 
length, const plot_font_style_t *style )
diff --git a/windows/font.c b/windows/font.c
index 9358d1a..f67205a 100644
--- a/windows/font.c
+++ b/windows/font.c
@@ -30,7 +30,7 @@
 #include "utils/log.h"
 #include "utils/nsoption.h"
 #include "utils/utf8.h"
-#include "desktop/font.h"
+#include "desktop/gui_layout.h"
 #include "desktop/gui_utf8.h"
 
 #include "windows/font.h"
@@ -140,8 +140,8 @@ HFONT get_font(const plot_font_style_t *style)
  * \param[out] width updated to width of string[0..length)
  * \return true on success and width updated else false
  */
-static bool
-nsfont_width(const plot_font_style_t *style,
+static nserror
+win32_font_width(const plot_font_style_t *style,
             const char *string,
             size_t length,
             int *width)
@@ -185,8 +185,8 @@ nsfont_width(const plot_font_style_t *style,
  * \param  actual_x    updated to x coordinate of character closest to x
  * \return  true on success, false on error and error reported
  */
-static bool
-nsfont_position_in_string(const plot_font_style_t *style,
+static nserror
+win32_font_position(const plot_font_style_t *style,
                          const char *string,
                          size_t length,
                          int x,
@@ -240,8 +240,8 @@ nsfont_position_in_string(const plot_font_style_t *style,
  *        string[char_offset] == ' ' ||
  *        char_offset == length]
  */
-static bool
-nsfont_split(const plot_font_style_t *style,
+static nserror
+win32_font_split(const plot_font_style_t *style,
             const char *string,
             size_t length,
             int x,
@@ -251,12 +251,7 @@ nsfont_split(const plot_font_style_t *style,
        int c_off;
        bool ret = false;
 
-       if (nsfont_position_in_string(style,
-                                     string,
-                                     length,
-                                     x,
-                                     char_offset,
-                                     actual_x)) {
+       if (win32_font_position(style, string, length, x, char_offset, 
actual_x)) {
                c_off = *char_offset;
                if (*char_offset == length) {
                        ret = true;
@@ -274,10 +269,7 @@ nsfont_split(const plot_font_style_t *style,
                                }
                        }
 
-                       ret = nsfont_width(style,
-                                          string,
-                                          *char_offset,
-                                          actual_x);
+                       ret = win32_font_width(style, string, *char_offset, 
actual_x);
                }
        }
 
@@ -288,12 +280,16 @@ nsfont_split(const plot_font_style_t *style,
        return ret;
 }
 
-const struct font_functions nsfont = {
-       nsfont_width,
-       nsfont_position_in_string,
-       nsfont_split
+
+static struct gui_layout_table layout_table = {
+       .width = win32_font_width,
+       .position = win32_font_position,
+       .split = win32_font_split,
 };
 
+struct gui_layout_table *win32_layout_table = &layout_table;
+
+
 static struct gui_utf8_table utf8_table = {
        .utf8_to_local = utf8_to_local_encoding,
        .local_to_utf8 = utf8_from_local_encoding,
diff --git a/windows/font.h b/windows/font.h
index ec596f3..f2128af 100644
--- a/windows/font.h
+++ b/windows/font.h
@@ -33,6 +33,7 @@ struct font_desc {
     const char *encoding;
 };
 
+struct gui_layout_table *win32_layout_table;
 struct gui_utf8_table *win32_utf8_table;
 
 extern nserror utf8_to_font_encoding(const struct font_desc* font,
diff --git a/windows/main.c b/windows/main.c
index dfb3ad1..d2d0544 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -161,6 +161,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR 
lpcli, int ncmd)
                .file = win32_file_table,
                .utf8 = win32_utf8_table,
                .bitmap = win32_bitmap_table,
+               .layout = win32_layout_table,
        };
        win32_fetch_table->get_resource_url = gui_get_resource_url;
 


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to