From d5608581b926a28d738451ed7617354cbdaf4f7e Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 5 May 2012 15:58:17 +0000 Subject: Integrate Unicode font scanner into NetSurf. NetSurf will now use any available font when trying to print characters that are missing from the current font. TODO: Preferred font list. svn path=/trunk/netsurf/; revision=13905 --- amiga/Makefile.target | 2 +- amiga/font.c | 38 ++++++++++++++++++++++++++------------ amiga/font_scan.c | 29 ++++++++++++++++++++--------- amiga/font_scan.h | 29 +++++++++++++++++++++++++++++ amiga/gui.c | 8 ++++---- amiga/options.h | 3 +++ 6 files changed, 83 insertions(+), 26 deletions(-) create mode 100755 amiga/font_scan.h (limited to 'amiga') diff --git a/amiga/Makefile.target b/amiga/Makefile.target index 0899b6066..2930b6952 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -77,7 +77,7 @@ S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \ launch.c search.c history_local.c download.c iff_dr2d.c \ sslcert.c gui_options.c print.c theme.c drag.c icon.c system_colour.c \ datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \ - stringview/stringview.c stringview/urlhistory.c + stringview/stringview.c stringview/urlhistory.c font_scan.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # This is the final source build list diff --git a/amiga/font.c b/amiga/font.c index ef35cb23b..d75a2770c 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -1,5 +1,5 @@ /* - * Copyright 2008 - 2011 Chris Young + * Copyright 2008 - 2012 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -19,6 +19,7 @@ #include #include "amiga/font.h" +#include "amiga/font_scan.h" #include "amiga/gui.h" #include "amiga/utf8.h" #include "amiga/object.h" @@ -73,6 +74,7 @@ struct ami_font_node struct MinList *ami_font_list = NULL; struct List ami_diskfontlib_list; +lwc_string *glypharray[0xffff + 1]; ULONG ami_devicedpi; ULONG ami_xdpi; @@ -81,7 +83,7 @@ int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, int32 ami_font_width_glyph(struct OutlineFont *ofont, uint16 char1, uint16 char2, uint32 emwidth); struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, - BOOL fallback); + uint16 codepoint); static void ami_font_cleanup(struct MinList *ami_font_list); static bool nsfont_width(const plot_font_style_t *fstyle, @@ -148,7 +150,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; - if(!(ofont = ami_open_outline_font(fstyle, FALSE))) return false; + if(!(ofont = ami_open_outline_font(fstyle, 0))) return false; *char_offset = length; @@ -169,7 +171,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, { if(ufont == NULL) { - ufont = ami_open_outline_font(fstyle, TRUE); + ufont = ami_open_outline_font(fstyle, *utf16); } if(ufont) @@ -252,7 +254,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, len = utf8_bounded_length(string, length); if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; - if(!(ofont = ami_open_outline_font(fstyle, FALSE))) return false; + if(!(ofont = ami_open_outline_font(fstyle, 0))) return false; *char_offset = 0; *actual_x = 0; @@ -287,7 +289,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, { if(ufont == NULL) { - ufont = ami_open_outline_font(fstyle, TRUE); + ufont = ami_open_outline_font(fstyle, *utf16); } if(ufont) @@ -375,10 +377,11 @@ struct ami_font_node *ami_font_open(const char *font) * Open an outline font in the specified size and style * * \param fstyle font style structure - * \param default open a default font instead of the one specified by fstyle + * \param codepoint open a default font instead of the one specified by fstyle * \return outline font or NULL on error */ -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, BOOL fallback) +struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, + uint16 codepoint) { struct ami_font_node *node; struct OutlineFont *ofont; @@ -391,7 +394,7 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, BOOL ULONG shearsin = 0; ULONG shearcos = (1 << 16); - if(fallback) fontfamily = NSA_UNICODE_FONT; + if(codepoint) fontfamily = NSA_UNICODE_FONT; else fontfamily = fstyle->family; switch(fontfamily) @@ -413,7 +416,8 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, BOOL break; case NSA_UNICODE_FONT: default: - fontname = nsoption_charp(font_unicode); + fontname = ami_font_scan_lookup(codepoint, glypharray); +printf("FONT::: %s\n", fontname); break; } @@ -706,7 +710,7 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return 0; outf16 = utf16; - if(!(ofont = ami_open_outline_font(fstyle, FALSE))) return 0; + if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0; if(rp) SetRPAttrs(rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,fstyle->foreground),TAG_DONE); @@ -744,7 +748,7 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const { if(ufont == NULL) { - ufont = ami_open_outline_font(fstyle, TRUE); + ufont = ami_open_outline_font(fstyle, *utf16); } if(ufont) @@ -780,6 +784,15 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const void ami_init_fonts(void) { + struct MinList *list; + + /* Initialise Unicode font scanner */ + list = NewObjList(); + /** TODO: add font_unicode and other preferred fonts to the list here */ + ami_font_scan_init(nsoption_charp(font_unicode_file), list, glypharray); + FreeObjList(list); + + /* Initialise font caching etc lists */ ami_font_list = NewObjList(); NewList(&ami_diskfontlib_list); @@ -792,6 +805,7 @@ void ami_close_fonts(void) LOG(("Cleaning up font cache")); FreeObjList(ami_font_list); ami_font_list = NULL; + ami_font_scan_fini(glypharray); } void ami_font_close(struct ami_font_node *node) diff --git a/amiga/font_scan.c b/amiga/font_scan.c index e9b4c7711..d5e84e7be 100644 --- a/amiga/font_scan.c +++ b/amiga/font_scan.c @@ -21,6 +21,7 @@ */ #include +#include #include #include @@ -29,10 +30,22 @@ #include #include -#include - +#include "amiga/font_scan.h" #include "amiga/object.h" +/** + * Lookup a font that contains a UTF-16 codepoint + * + * \param code UTF-16 codepoint to lookup + * \param glypharray an array of 0xffff lwc_string pointers + * \return font name or NULL + */ +const char *ami_font_scan_lookup(uint16 code, lwc_string **glypharray) +{ + if(glypharray[code] == NULL) return NULL; + else return lwc_string_data(glypharray[code]); +} + /** * Scan a font for glyphs not present in glypharray. * @@ -51,7 +64,7 @@ ULONG ami_font_scan_font(const char *fontname, lwc_string **glypharray) ofont = OpenOutlineFont(fontname, NULL, OFF_OPEN); - if(!ofont) return; + if(!ofont) return 0; if(ESetInfo(&ofont->olf_EEngine, OT_PointHeight, 10 * (1 << 16), @@ -202,7 +215,7 @@ ULONG ami_font_scan_load(const char *filename, lwc_string **glypharray) { lerror = lwc_intern_string((const char *)rarray[A_FONT], strlen((const char *)rarray[A_FONT]), - &glypharray[strtoul(rarray[A_CODE], NULL, 0)]); + &glypharray[strtoul((const char *)rarray[A_CODE], NULL, 0)]); if(lerror != lwc_error_ok) continue; found++; } @@ -226,7 +239,7 @@ void ami_font_scan_save(const char *filename, lwc_string **glypharray) if(fh = FOpen(filename, MODE_NEWFILE, 0)) { printf("Writing %s\n", filename); - FPrintf(fh, "; This file is auto-generated. To recreate the cache, delete this file.\n"); + FPrintf(fh, "; This file is auto-generated. To re-create the cache, delete this file.\n"); FPrintf(fh, "; This file is parsed using ReadArgs() with the following template:\n"); FPrintf(fh, "; CODE/A,FONT/A\n;\n"); @@ -234,7 +247,6 @@ void ami_font_scan_save(const char *filename, lwc_string **glypharray) { if(glypharray[i]) { FPrintf(fh, "0x%04lx \"%s\"\n", i, lwc_string_data(glypharray[i])); - lwc_string_unref(glypharray[i]); } } FClose(fh); @@ -302,12 +314,11 @@ int main(int argc, char** argv) printf("%s\n",argv[1]); list = NewObjList(); - ami_font_scan_init(argv[1], list, glypharray); - ami_font_scan_fini(glypharray); - FreeObjList(list); + ami_font_scan_fini(glypharray); + return 0; } diff --git a/amiga/font_scan.h b/amiga/font_scan.h new file mode 100755 index 000000000..8b0ecc7ce --- /dev/null +++ b/amiga/font_scan.h @@ -0,0 +1,29 @@ +/* + * Copyright 2012 Chris Young + * + * 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 AMIGA_FONT_SCAN_H +#define AMIGA_FONT_SCAN_H + +#include + +void ami_font_scan_init(const char *filename, struct MinList *list, + lwc_string **glypharray); +void ami_font_scan_fini(lwc_string **glypharray); +const char *ami_font_scan_lookup(uint16 code, lwc_string **glypharray); + +#endif diff --git a/amiga/gui.c b/amiga/gui.c index 2c1364372..a21c20ee1 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -438,6 +438,10 @@ void ami_set_options(void) search_engines_file_location = nsoption_charp(search_engines_file); + sprintf(temp, "%s/UnicodeFontCache", current_user_dir); + nsoption_setnull_charp(font_unicode_file, + (char *)strdup(temp)); + /* font defaults */ nsoption_setnull_charp(font_sans, (char *)strdup("DejaVu Sans")); nsoption_setnull_charp(font_serif, (char *)strdup("DejaVu Serif")); @@ -461,10 +465,6 @@ void ami_set_options(void) nsoption_set_charp(font_unicode, (char *)strdup("Bitstream Cyberbit")); } - else { - nsoption_set_charp(font_unicode, - (char *)strdup("DejaVu Sans")); - } } nsoption_setnull_charp(theme, diff --git a/amiga/options.h b/amiga/options.h index c686108b1..6d4211892 100644 --- a/amiga/options.h +++ b/amiga/options.h @@ -55,6 +55,7 @@ bool close_no_quit; \ bool hide_docky_icon; \ char *font_unicode; \ + char *font_unicode_file; \ bool drag_save_icons; \ int hotlist_window_xpos; \ int hotlist_window_ypos; \ @@ -111,6 +112,7 @@ .close_no_quit = false, \ .hide_docky_icon = false, \ .font_unicode = NULL, \ + .font_unicode_file = NULL, \ .drag_save_icons = true, \ .hotlist_window_xpos = 0, \ .hotlist_window_ypos = 0, \ @@ -166,6 +168,7 @@ { "close_no_quit", OPTION_BOOL, &nsoptions.close_no_quit}, \ { "hide_docky_icon", OPTION_BOOL, &nsoptions.hide_docky_icon}, \ { "font_unicode", OPTION_STRING, &nsoptions.font_unicode }, \ +{ "font_unicode_file", OPTION_STRING, &nsoptions.font_unicode_file }, \ { "drag_save_icons", OPTION_BOOL, &nsoptions.drag_save_icons}, \ { "hotlist_window_xpos", OPTION_INTEGER, &nsoptions.hotlist_window_xpos}, \ { "hotlist_window_ypos", OPTION_INTEGER, &nsoptions.hotlist_window_ypos}, \ -- cgit v1.2.3