From 886a3106db6d6a60d2d706d2caad3e883dd70b14 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 1 Feb 2014 22:17:36 +0000 Subject: move utf8 local conversion operations to table --- amiga/clipboard.c | 25 +++++++------- amiga/gui.c | 1 + amiga/utf8.c | 65 ++++++++++++++++++++--------------- amiga/utf8.h | 7 ++++ atari/encoding.c | 6 ++++ atari/encoding.h | 47 +++++++++++++------------ atari/gui.c | 14 ++++---- atari/plot/font_vdi.c | 2 ++ atari/toolbar.c | 1 + beos/gui.cpp | 29 ---------------- cocoa/Makefile.target | 1 - cocoa/utf8.m | 40 ---------------------- desktop/gui_factory.c | 83 ++++++++++++++++++++++++++++++++++++++------- desktop/save_text.c | 12 ++++--- framebuffer/font.h | 2 ++ framebuffer/font_freetype.c | 33 ++++-------------- framebuffer/font_internal.c | 19 ++++++++--- framebuffer/gui.c | 1 + gtk/gui.c | 31 ----------------- monkey/utils.c | 18 ---------- render/html.c | 34 ++++++++++--------- riscos/download.c | 1 + riscos/gui.c | 3 +- riscos/gui/url_bar.c | 1 + riscos/help.c | 1 + riscos/menus.c | 13 ++++--- riscos/query.c | 1 + riscos/save.c | 1 + riscos/textselection.c | 1 + riscos/ucstables.c | 8 +++++ riscos/ucstables.h | 5 +++ riscos/wimp.c | 1 + riscos/window.c | 1 + utils/utf8.c | 5 +-- utils/utf8.h | 5 --- windows/font.c | 11 ++++-- windows/gui.h | 1 + windows/main.c | 1 + 38 files changed, 262 insertions(+), 269 deletions(-) delete mode 100644 cocoa/utf8.m diff --git a/amiga/clipboard.c b/amiga/clipboard.c index d39e89e4a..6768dde17 100644 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -16,10 +16,21 @@ * along with this program. If not, see . */ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "utils/nsoption.h" +#include "utils/utf8.h" #include "desktop/gui.h" #include "desktop/plotters.h" #include "desktop/textinput.h" -#include "utils/nsoption.h" #include "amiga/bitmap.h" #include "amiga/clipboard.h" @@ -31,18 +42,6 @@ #include "amiga/menu.h" #include "amiga/utf8.h" -#include "utils/utf8.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - #define ID_UTF8 MAKE_ID('U','T','F','8') struct IFFHandle *iffh = NULL; diff --git a/amiga/gui.c b/amiga/gui.c index 074dfafa6..f186328fe 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5223,6 +5223,7 @@ int main(int argc, char** argv) .clipboard = amiga_clipboard_table, .download = amiga_download_table, .fetch = &amiga_fetch_table, + .utf8 = amiga_utf8_table, }; /* Open popupmenu.library just to check the version. diff --git a/amiga/utf8.c b/amiga/utf8.c index d182492e9..a8e415d45 100755 --- a/amiga/utf8.c +++ b/amiga/utf8.c @@ -18,13 +18,44 @@ #include #include - #include + #include "utils/utf8.h" +#include "desktop/gui.h" #include #include #include +#include "amiga/utf8.h" + +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) +{ + const char *encname = "ISO-8859-1"; + +#ifdef __amigaos4__ + LONG charset; + + charset = GetDiskFontCtrl(DFCTRL_CHARSET); + encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); +#endif + + return utf8_from_enc(string,encname,len,result,NULL); +} + +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) +{ + const char *encname = "ISO-8859-1"; + +#ifdef __amigaos4__ + LONG charset; + + charset = GetDiskFontCtrl(DFCTRL_CHARSET); + encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); +#endif + + return utf8_to_enc(string,encname,len,result); +} + void ami_utf8_free(char *ptr) { if(ptr) free(ptr); @@ -58,32 +89,10 @@ char *ami_to_utf8_easy(const char *string) } } -nserror utf8_from_local_encoding(const char *string, size_t len, char **result) -{ - const char *encname = "ISO-8859-1"; - -#ifdef __amigaos4__ - LONG charset; - - charset = GetDiskFontCtrl(DFCTRL_CHARSET); - encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); -#endif - - return utf8_from_enc(string,encname,len,result,NULL); -} - -nserror utf8_to_local_encoding(const char *string, size_t len, char **result) -{ - const char *encname = "ISO-8859-1"; - -#ifdef __amigaos4__ - LONG charset; - - charset = GetDiskFontCtrl(DFCTRL_CHARSET); - encname = (const char *) ObtainCharsetInfo(DFCS_NUMBER, charset, DFCS_MIMENAME); -#endif - - return utf8_to_enc(string,encname,len,result); -} +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; +struct gui_utf8_table *amiga_utf8_table = &utf8_table; diff --git a/amiga/utf8.h b/amiga/utf8.h index 7956523ee..065a149f2 100755 --- a/amiga/utf8.h +++ b/amiga/utf8.h @@ -18,7 +18,14 @@ #ifndef AMIGA_UTF8_H #define AMIGA_UTF8_H + +extern struct gui_utf8_table *ami_utf8_table; + char *ami_utf8_easy(const char *string); void ami_utf8_free(char *ptr); char *ami_to_utf8_easy(const char *string); + +nserror utf8_from_local_encoding(const char *string, size_t len, char **result); +nserror utf8_to_local_encoding(const char *string, size_t len, char **result); + #endif diff --git a/atari/encoding.c b/atari/encoding.c index 626f57ae8..f57a3d770 100644 --- a/atari/encoding.c +++ b/atari/encoding.c @@ -67,3 +67,9 @@ int atari_to_ucs4(unsigned char atari) } +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; + +struct gui_utf8_table *atari_utf8_table = &utf8_table; diff --git a/atari/encoding.h b/atari/encoding.h index c85bac9fc..d0289b613 100644 --- a/atari/encoding.h +++ b/atari/encoding.h @@ -1,32 +1,37 @@ -/* - * Copyright 2012 Ole Loots - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* + * Copyright 2012 Ole Loots + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #ifndef NS_ATARI_ENCODING_H #define NS_ATARI_ENCODING_H -#include -#include +#include +#include #include -#include "css/css.h" +#include "css/css.h" #include "render/font.h" -#include "utils/utf8.h" - +#include "utils/utf8.h" + +struct gui_utf8_table *atari_utf8_table; + +nserror utf8_to_local_encoding(const char *string, size_t len, char **result); +nserror utf8_from_local_encoding(const char *string, size_t len, char **result); + int atari_to_ucs4( unsigned char atarichar); #endif diff --git a/atari/gui.c b/atari/gui.c index af5e1f8ba..afd3be57b 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -30,6 +30,12 @@ #include #include +#include "utils/schedule.h" +#include "utils/url.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/nsoption.h" #include "content/urldb.h" #include "content/fetch.h" #include "content/fetchers/resource.h" @@ -38,8 +44,6 @@ #include "desktop/local_history.h" #include "desktop/plotters.h" #include "desktop/netsurf.h" - -#include "utils/nsoption.h" #include "desktop/save_complete.h" #include "desktop/textinput.h" #include "desktop/treeview.h" @@ -47,11 +51,6 @@ #include "desktop/browser_private.h" #include "desktop/mouse.h" #include "render/font.h" -#include "utils/schedule.h" -#include "utils/url.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" #include "atari/gemtk/gemtk.h" #include "atari/gui.h" @@ -1113,6 +1112,7 @@ int main(int argc, char** argv) .clipboard = &atari_clipboard_table, .download = atari_download_table, .fetch = &atari_fetch_table, + .utf8 = atari_utf8_table, }; /* @todo logging file descriptor update belongs in a nslog_init callback */ diff --git a/atari/plot/font_vdi.c b/atari/plot/font_vdi.c index 0c914b82b..a73300c58 100755 --- a/atari/plot/font_vdi.c +++ b/atari/plot/font_vdi.c @@ -26,6 +26,8 @@ #include "utils/utf8.h" #include "utils/log.h" +#include "atari/encoding.h" + diff --git a/atari/toolbar.c b/atari/toolbar.c index 8044d160d..f40c07a65 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -55,6 +55,7 @@ #include "desktop/textarea.h" #include "desktop/textinput.h" #include "content/hlcache.h" +#include "atari/encoding.h" #define TB_BUTTON_WIDTH 32 diff --git a/beos/gui.cpp b/beos/gui.cpp index 97117e04b..07bbc3eab 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -963,35 +963,6 @@ static void nsbeos_create_ssl_verify_window(struct browser_window *bw, CALLED(); } - -nserror utf8_to_local_encoding(const char *string, size_t len, char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return NSERROR_NOMEM; - - return NSERROR_OK; -} - -nserror utf8_from_local_encoding(const char *string, size_t len, char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return NSERROR_NOMEM; - - return NSERROR_OK; -} - static char *path_to_url(const char *path) { int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index 49f67f085..40e8d432a 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -95,7 +95,6 @@ S_COCOA := \ schedule.m \ selection.m \ thumbnail.m \ - utf8.m \ utils.m \ ArrowBox.m \ ArrowWindow.m \ diff --git a/cocoa/utf8.m b/cocoa/utf8.m deleted file mode 100644 index 7b69918d0..000000000 --- a/cocoa/utf8.m +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2011 Sven Weidauer - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#import - -#import "utils/utf8.h" - -nserror utf8_to_local_encoding(const char *string, size_t len, - char **result) -{ - NSCParameterAssert( NULL != result ); - - char *newString = malloc( len + 1 ); - if (NULL == newString) return NSERROR_NOMEM; - memcpy( newString, string, len ); - newString[len] = 0; - *result = newString; - return NSERROR_OK; -} - -nserror utf8_from_local_encoding(const char *string, size_t len, char **result) -{ - /* same function, local encoding = UTF-8 */ - return utf8_to_local_encoding( string, len, result ); -} diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index b61fdf0be..8996ab5d6 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -272,6 +272,11 @@ static void gui_default_set_clipboard(const char *buffer, size_t length, { } +static struct gui_clipboard_table default_clipboard_table = { + .get = gui_default_get_clipboard, + .set = gui_default_set_clipboard, +}; + /** verify clipboard table is valid */ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) { @@ -290,6 +295,54 @@ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) return NSERROR_OK; } +/** + * The default utf8 conversion implementation. + * + * The default implementation assumes the local encoding is utf8 + * allowing the conversion to be a simple copy. + * + * @param [in] string The source string. + * @param [in] len The \a string length or 0 to compute it. + * @param [out] result A pointer to the converted string. + * @result NSERROR_OK or NSERROR_NOMEM if memory could not be allocated. + */ +static nserror gui_default_utf8(const char *string, size_t len, char **result) +{ + assert(string && result); + + if (len == 0) + len = strlen(string); + + *result = strndup(string, len); + if (!(*result)) + return NSERROR_NOMEM; + + return NSERROR_OK; +} + +static struct gui_utf8_table default_utf8_table = { + .utf8_to_local = gui_default_utf8, + .local_to_utf8 = gui_default_utf8, +}; + +/** verify clipboard table is valid */ +static nserror verify_utf8_register(struct gui_utf8_table *gut) +{ + /* check table is present */ + if (gut == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* mandantory operations */ + if (gut->utf8_to_local == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gut->local_to_utf8 == NULL) { + return NSERROR_BAD_PARAMETER; + } + return NSERROR_OK; +} + static nsurl *gui_default_get_resource_url(const char *path) { return NULL; @@ -370,6 +423,13 @@ static void gui_default_401login_open(nsurl *url, const char *realm, cb(false, cbpw); } +static struct gui_download_table default_download_table = { + .create = gui_default_download_create, + .data = gui_default_download_data, + .error = gui_default_download_error, + .done = gui_default_download_done, +}; + /** verify browser table is valid */ static nserror verify_browser_register(struct gui_browser_table *gbt) { @@ -406,19 +466,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) } - -static struct gui_download_table default_download_table = { - .create = gui_default_download_create, - .data = gui_default_download_data, - .error = gui_default_download_error, - .done = gui_default_download_done, -}; - -static struct gui_clipboard_table default_clipboard_table = { - .get = gui_default_get_clipboard, - .set = gui_default_set_clipboard, -}; - /* exported interface documented in desktop/gui_factory.h */ nserror gui_factory_register(struct gui_table *gt) { @@ -472,6 +519,16 @@ nserror gui_factory_register(struct gui_table *gt) return err; } + /* utf8 table */ + if (gt->utf8 == NULL) { + /* set default clipboard table */ + gt->utf8 = &default_utf8_table; + } + err = verify_utf8_register(gt->utf8); + if (err != NSERROR_OK) { + return err; + } + guit = gt; return NSERROR_OK; diff --git a/desktop/save_text.c b/desktop/save_text.c index 38f8c5334..bc4d4c57a 100644 --- a/desktop/save_text.c +++ b/desktop/save_text.c @@ -28,14 +28,16 @@ #include #include "utils/config.h" +#include "utils/log.h" +#include "utils/utf8.h" +#include "utils/utils.h" #include "content/content.h" #include "content/hlcache.h" -#include "desktop/save_text.h" #include "render/box.h" #include "render/html.h" -#include "utils/log.h" -#include "utils/utf8.h" -#include "utils/utils.h" + +#include "desktop/gui_factory.h" +#include "desktop/save_text.h" static void extract_text(struct box *box, bool *first, save_text_whitespace *before, struct save_text_state *save); @@ -69,7 +71,7 @@ void save_as_text(hlcache_handle *c, char *path) if (!save.block) return; - ret = utf8_to_local_encoding(save.block, save.length, &result); + ret = guit->utf8->utf8_to_local(save.block, save.length, &result); free(save.block); if (ret != NSERROR_OK) { diff --git a/framebuffer/font.h b/framebuffer/font.h index 5ae5bb3ad..6350421e7 100644 --- a/framebuffer/font.h +++ b/framebuffer/font.h @@ -21,6 +21,8 @@ #include "utils/utf8.h" +extern struct gui_utf8_table *framebuffer_utf8_table; + bool fb_font_init(void); bool fb_font_finalise(void); diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c index eb7278c81..4381db62a 100644 --- a/framebuffer/font_freetype.c +++ b/framebuffer/font_freetype.c @@ -23,13 +23,14 @@ #include #include FT_CACHE_H -#include "css/css.h" -#include "css/utils.h" -#include "render/font.h" #include "utils/filepath.h" #include "utils/utf8.h" #include "utils/log.h" #include "utils/nsoption.h" +#include "css/css.h" +#include "css/utils.h" +#include "render/font.h" +#include "desktop/gui.h" #include "framebuffer/gui.h" #include "framebuffer/font.h" @@ -74,30 +75,6 @@ enum fb_face_e { static fb_faceid_t *fb_faces[FB_FACE_COUNT]; - -nserror utf8_to_local_encoding(const char *string, - size_t len, - char **result) -{ - return utf8_to_enc(string, "UTF-8", len, result); -} - -nserror utf8_from_local_encoding(const char *string, - size_t len, - char **result) -{ - *result = malloc(len + 1); - if (*result == NULL) { - return NSERROR_NOMEM; - } - - memcpy(*result, string, len); - - (*result)[len] = '\0'; - - return NSERROR_OK; -} - /* map cache manager handle to face id */ static FT_Error ft_face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face ) { @@ -581,6 +558,8 @@ const struct font_functions nsfont = { nsfont_split }; +struct gui_utf8_table *framebuffer_utf8_table = NULL; + /* * Local Variables: * c-basic-offset:8 diff --git a/framebuffer/font_internal.c b/framebuffer/font_internal.c index 1eed00684..da5ca92a3 100644 --- a/framebuffer/font_internal.c +++ b/framebuffer/font_internal.c @@ -19,12 +19,13 @@ #include #include - #include -#include "css/css.h" -#include "render/font.h" + #include "utils/nsoption.h" #include "utils/utf8.h" +#include "desktop/gui.h" +#include "css/css.h" +#include "render/font.h" #include "framebuffer/gui.h" #include "framebuffer/font.h" @@ -68,7 +69,7 @@ nserror utf8_to_font_encoding(const struct fb_font_desc* font, } -nserror utf8_to_local_encoding(const char *string, +static nserror utf8_to_local(const char *string, size_t len, char **result) { @@ -76,7 +77,7 @@ nserror utf8_to_local_encoding(const char *string, } -nserror utf8_from_local_encoding(const char *string, +static nserror utf8_from_local(const char *string, size_t len, char **result) { @@ -183,6 +184,14 @@ const struct font_functions nsfont = { nsfont_split }; +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local, + .local_to_utf8 = utf8_from_local, +}; + +struct gui_utf8_table *framebuffer_utf8_table = &utf8_table; + + /* * Local Variables: * c-basic-offset:8 diff --git a/framebuffer/gui.c b/framebuffer/gui.c index e7f456d8b..678010dfd 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1815,6 +1815,7 @@ main(int argc, char** argv) .window = &framebuffer_window_table, .clipboard = framebuffer_clipboard_table, .fetch = framebuffer_fetch_table, + .utf8 = framebuffer_utf8_table, }; respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); diff --git a/gtk/gui.c b/gtk/gui.c index fdf64ad25..74da73321 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -788,37 +788,6 @@ gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event, gpointer data) return FALSE; } -nserror utf8_to_local_encoding(const char *string, size_t len, char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return NSERROR_NOMEM; - - return NSERROR_OK; -} - - -nserror utf8_from_local_encoding(const char *string, size_t len, char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return NSERROR_NOMEM; - - return NSERROR_OK; -} - - - #ifdef WITH_PDF_EXPORT void PDF_Password(char **owner_pass, char **user_pass, char *path) diff --git a/monkey/utils.c b/monkey/utils.c index 742c300f1..e1a702f2f 100644 --- a/monkey/utils.c +++ b/monkey/utils.c @@ -22,10 +22,6 @@ #include "utils/config.h" #include "utils/utils.h" -#include "utils/url.h" -#include "utils/utf8.h" - - void warn_user(const char *warning, const char *detail) { @@ -37,17 +33,3 @@ void die(const char * const error) fprintf(stderr, "DIE %s\n", error); exit(EXIT_FAILURE); } - -nserror utf8_to_local_encoding(const char *string, size_t len, char **result) -{ - *result = strndup(string, len); - return (*result == NULL) ? NSERROR_NOMEM : NSERROR_OK; -} - -nserror utf8_from_local_encoding(const char *string, size_t len, char **result) -{ - *result = strndup(string, len); - return (*result == NULL) ? NSERROR_NOMEM : NSERROR_OK; -} - - diff --git a/render/html.c b/render/html.c index bd23aaca4..f9d885856 100644 --- a/render/html.c +++ b/render/html.c @@ -29,14 +29,27 @@ #include #include "utils/config.h" +#include "utils/corestrings.h" +#include "utils/http.h" +#include "utils/libdom.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/schedule.h" +#include "utils/talloc.h" +#include "utils/url.h" +#include "utils/utf8.h" +#include "utils/utils.h" +#include "utils/nsoption.h" #include "content/content_protected.h" #include "content/fetch.h" #include "content/hlcache.h" -#include "utils/nsoption.h" #include "desktop/selection.h" #include "desktop/scrollbar.h" #include "desktop/textarea.h" #include "image/bitmap.h" +#include "javascript/js.h" +#include "desktop/gui_factory.h" + #include "render/box.h" #include "render/font.h" #include "render/form.h" @@ -44,17 +57,6 @@ #include "render/imagemap.h" #include "render/layout.h" #include "render/search.h" -#include "javascript/js.h" -#include "utils/corestrings.h" -#include "utils/http.h" -#include "utils/libdom.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/talloc.h" -#include "utils/url.h" -#include "utils/utf8.h" -#include "utils/utils.h" #define CHUNK 4096 @@ -1770,10 +1772,10 @@ static void html__set_file_gadget_filename(struct content *c, html_content *html = (html_content *)c; struct box *file_box = gadget->box; - ret = utf8_from_local_encoding(fn,0, &utf8_fn); + ret = guit->utf8->local_to_utf8(fn,0, &utf8_fn); if (ret != NSERROR_OK) { assert(ret != NSERROR_BAD_ENCODING); - LOG(("utf8_from_local_encoding failed")); + LOG(("utf8 to local encoding conversion failed")); /* Load was for us - just no memory */ return; } @@ -1915,11 +1917,11 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) /* TODO: Sniff for text? */ /* Convert to UTF-8 */ - ret = utf8_from_local_encoding(buffer, file_len, &utf8_buff); + ret = guit->utf8->local_to_utf8(buffer, file_len, &utf8_buff); if (ret != NSERROR_OK) { /* bad encoding shouldn't happen */ assert(ret != NSERROR_BAD_ENCODING); - LOG(("utf8_from_local_encoding failed")); + LOG(("local to utf8 encoding failed")); free(buffer); warn_user("NoMemory", NULL); return true; diff --git a/riscos/download.c b/riscos/download.c index b89334f2c..b10c6c1d4 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -58,6 +58,7 @@ #include "utils/url.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" #define ICON_DOWNLOAD_ICON 0 #define ICON_DOWNLOAD_URL 1 diff --git a/riscos/gui.c b/riscos/gui.c index a5a9c94c2..83add251f 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -99,7 +99,7 @@ #include "riscos/wimp_event.h" #include "riscos/wimputils.h" #include "riscos/window.h" - +#include "riscos/ucstables.h" #ifndef FILETYPE_ACORN_URI @@ -2389,6 +2389,7 @@ int main(int argc, char** argv) .clipboard = riscos_clipboard_table, .download = riscos_download_table, .fetch = &riscos_fetch_table, + .utf8 = riscos_utf8_table, }; /* Consult NetSurf$Logging environment variable to decide if logging diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 681824d89..b898e6f6c 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -42,6 +42,7 @@ #include "utils/messages.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" #define URLBAR_HEIGHT 52 #define URLBAR_FAVICON_SIZE 16 diff --git a/riscos/help.c b/riscos/help.c index 9da52f3e6..3c74e5419 100644 --- a/riscos/help.c +++ b/riscos/help.c @@ -44,6 +44,7 @@ #include "utils/log.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" /* Recognised help keys diff --git a/riscos/menus.c b/riscos/menus.c index d8e2f2c16..a0baca087 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -31,6 +31,12 @@ #include "oslib/osgbpb.h" #include "oslib/territory.h" #include "oslib/wimp.h" + +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "utils/utils.h" +#include "utils/utf8.h" #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" @@ -40,6 +46,7 @@ #include "desktop/local_history.h" #include "desktop/netsurf.h" #include "desktop/textinput.h" + #include "riscos/dialog.h" #include "riscos/configure.h" #include "riscos/cookies.h" @@ -56,11 +63,7 @@ #include "riscos/url_suggest.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" -#include "utils/utf8.h" +#include "riscos/ucstables.h" struct menu_definition_entry { menu_action action; /**< menu action */ diff --git a/riscos/query.c b/riscos/query.c index 226849462..2be2e2a3d 100644 --- a/riscos/query.c +++ b/riscos/query.c @@ -29,6 +29,7 @@ #include "utils/messages.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" #define ICON_QUERY_MESSAGE 0 #define ICON_QUERY_YES 1 diff --git a/riscos/save.c b/riscos/save.c index d58da1a91..fa638d37d 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -69,6 +69,7 @@ #include "riscos/thumbnail.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" +#include "riscos/ucstables.h" //typedef enum //{ diff --git a/riscos/textselection.c b/riscos/textselection.c index 68e71a9f5..5215a62c9 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -39,6 +39,7 @@ #include "riscos/mouse.h" #include "riscos/save.h" #include "riscos/textselection.h" +#include "riscos/ucstables.h" #ifndef wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX diff --git a/riscos/ucstables.c b/riscos/ucstables.c index b9f196df0..3b7f8a42b 100644 --- a/riscos/ucstables.c +++ b/riscos/ucstables.c @@ -31,6 +31,7 @@ #include "utils/log.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "desktop/gui.h" /* Common values (ASCII) */ #define common \ @@ -684,3 +685,10 @@ nserror utf8_from_local_encoding(const char *string, size_t len, char **result) return NSERROR_OK; } + +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; + +struct gui_utf8_table *riscos_utf8_table = &utf8_table; diff --git a/riscos/ucstables.h b/riscos/ucstables.h index 0be065897..e5d838249 100644 --- a/riscos/ucstables.h +++ b/riscos/ucstables.h @@ -21,4 +21,9 @@ * This is only used if nothing claims Service_International,8 */ +struct gui_utf8_table *riscos_utf8_table; + +nserror utf8_to_local_encoding(const char *string, size_t len, char **result); +nserror utf8_from_local_encoding(const char *string, size_t len, char **result); + const int *ucstable_from_alphabet(int alphabet); diff --git a/riscos/wimp.c b/riscos/wimp.c index 2e488918d..f59fa675a 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -40,6 +40,7 @@ #include "utils/log.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" static void ro_gui_wimp_cache_furniture_sizes(wimp_w w); diff --git a/riscos/window.c b/riscos/window.c index 72230a7fd..0116a9721 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -90,6 +90,7 @@ #include "riscos/wimp_event.h" #include "riscos/wimputils.h" #include "riscos/window.h" +#include "riscos/ucstables.h" void gui_window_redraw_window(struct gui_window *g); diff --git a/utils/utf8.c b/utils/utf8.c index ab7bbae06..cc8039c85 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -29,6 +29,8 @@ #include +#include "desktop/gui_factory.h" + #include "utils/config.h" #include "utils/log.h" #include "utils/utf8.h" @@ -463,8 +465,7 @@ bool utf8_save_text(const char *utf8_text, const char *path) char *conv; FILE *out; - ret = utf8_to_local_encoding(utf8_text, strlen(utf8_text), &conv); - + ret = guit->utf8->utf8_to_local(utf8_text, strlen(utf8_text), &conv); if (ret != NSERROR_OK) { LOG(("failed to convert to local encoding, return %d", ret)); return false; diff --git a/utils/utf8.h b/utils/utf8.h index 7c450b5c3..7509dde52 100644 --- a/utils/utf8.h +++ b/utils/utf8.h @@ -161,9 +161,4 @@ bool utf8_save_text(const char *utf8_text, const char *path); */ nserror utf8_finalise(void); -/* These two are platform specific */ -nserror utf8_to_local_encoding(const char *string, size_t len, char **result); -nserror utf8_from_local_encoding(const char *string, size_t len, char **result); - - #endif diff --git a/windows/font.c b/windows/font.c index 98269a35f..09adeeda7 100644 --- a/windows/font.c +++ b/windows/font.c @@ -43,14 +43,14 @@ nserror utf8_to_font_encoding(const struct font_desc* font, return utf8_to_enc(string, font->encoding, len, result); } -nserror utf8_to_local_encoding(const char *string, +static nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { return utf8_to_enc(string, "UCS-2", len, result); } -nserror utf8_from_local_encoding(const char *string, size_t len, +static nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { assert(string && result); @@ -234,3 +234,10 @@ const struct font_functions nsfont = { nsfont_position_in_string, nsfont_split }; + +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; + +struct gui_utf8_table *win32_utf8_table = &utf8_table; diff --git a/windows/gui.h b/windows/gui.h index 1ff849d73..d8e1b1d0b 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -28,6 +28,7 @@ extern struct gui_window_table *win32_window_table; extern struct gui_clipboard_table *win32_clipboard_table; extern struct gui_fetch_table *win32_fetch_table; extern struct gui_browser_table *win32_browser_table; +extern struct gui_utf8_table *win32_utf8_table; extern HINSTANCE hInstance; diff --git a/windows/main.c b/windows/main.c index 94e0eee2e..6a53e0c72 100644 --- a/windows/main.c +++ b/windows/main.c @@ -111,6 +111,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .clipboard = win32_clipboard_table, .download = win32_download_table, .fetch = win32_fetch_table, + .utf8 = win32_utf8_table, }; win32_fetch_table->get_resource_url = gui_get_resource_url; -- cgit v1.2.3