From 7f100d8d49ce112c334310ed2623a7a89fb355a8 Mon Sep 17 00:00:00 2001 From: François Revel Date: Thu, 2 Oct 2008 14:10:52 +0000 Subject: - Cleanup: remove dead gtk code and its copyrights - remove unneeded fieltype hashlist code we just use the mime roster - implemented saving bitmaps svn path=/trunk/netsurf/; revision=5469 --- beos/beos_bitmap.cpp | 74 ++++---------------- beos/beos_bitmap.h | 1 - beos/beos_filetype.cpp | 179 +----------------------------------------------- beos/beos_filetype.h | 4 +- beos/beos_font.cpp | 172 +--------------------------------------------- beos/beos_font.h | 1 - beos/beos_gui.cpp | 4 +- beos/beos_thumbnail.cpp | 2 + 8 files changed, 24 insertions(+), 413 deletions(-) diff --git a/beos/beos_bitmap.cpp b/beos/beos_bitmap.cpp index cfb824e25..f6f2e8f5f 100644 --- a/beos/beos_bitmap.cpp +++ b/beos/beos_bitmap.cpp @@ -1,6 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2004 James Bursa * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -28,7 +27,11 @@ #include #include #include +#include +#include #include +#include +#include extern "C" { #include "content/content.h" #include "image/bitmap.h" @@ -63,25 +66,6 @@ struct bitmap { * \param rowstride Number of bytes to skip after each row (this * implementation requires this to be a multiple of 4.) */ -#if 0 -static inline void nsbeos_abgr_to_bgra(void *src, void *dst, int width, int height, - size_t rowstride) -{ - u_int32_t *from = (u_int32_t *)src; - u_int32_t *to = (u_int32_t *)dst; - - rowstride >>= 2; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - u_int32_t e = from[x]; - to[x] = (e >> 24) | (e << 8); - } - from += rowstride; - to += rowstride; - } -} -#endif static inline void nsbeos_rgba_to_bgra(void *src, void *dst, int width, int height, size_t rowstride) { @@ -135,16 +119,6 @@ void *bitmap_create(int width, int height, unsigned int state) bmp->opaque = false; bmp->opaque = (state & BITMAP_OPAQUE) != 0; // XXX store state instead -#if 0 /* GTK */ - bmp->primary = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, - width, height); - - /* fill the pixbuf in with 100% transparent black, as the memory - * won't have been cleared. - */ - gdk_pixbuf_fill(bmp->primary, 0); - bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL; -#endif return bmp; } @@ -281,7 +255,17 @@ void bitmap_destroy(void *vbitmap) bool bitmap_save(void *vbitmap, const char *path, unsigned flags) { struct bitmap *bitmap = (struct bitmap *)vbitmap; -#warning WRITEME + BTranslatorRoster *roster = BTranslatorRoster::Default(); + BBitmapStream stream(bitmap->primary); + BFile file(path, B_WRITE_ONLY | B_CREATE_FILE); + uint32 type = B_PNG_FORMAT; + + if (file.InitCheck() < B_OK) + return false; + + if (roster->Translate(&stream, NULL, NULL, &file, type) < B_OK) + return false; + #if 0 /* GTK */ GError *err = NULL; @@ -359,34 +343,6 @@ nsbeos_bitmap_generate_pretile(BBitmap *primary, int repeat_x, int repeat_y) } return result; -#if 0 /* GTK */ - BBitmap *result = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, - width * repeat_x, height * repeat_y); - char *target_buffer = (char *)gdk_pixbuf_get_pixels(result); - int x,y,row; - /* This algorithm won't work if the strides are not multiples */ - assert((size_t)gdk_pixbuf_get_rowstride(result) == - (primary_stride * repeat_x)); - - if (repeat_x == 1 && repeat_y == 1) { - g_object_ref(primary); - g_object_unref(result); - return primary; - } - - for (y = 0; y < repeat_y; ++y) { - char *primary_buffer = (char *)gdk_pixbuf_get_pixels(primary); - for (row = 0; row < height; ++row) { - for (x = 0; x < repeat_x; ++x) { - memcpy(target_buffer, - primary_buffer, primary_stride); - target_buffer += primary_stride; - } - primary_buffer += primary_stride; - } - } - return result; -#endif } /** diff --git a/beos/beos_bitmap.h b/beos/beos_bitmap.h index beecee2a0..6ec662198 100644 --- a/beos/beos_bitmap.h +++ b/beos/beos_bitmap.h @@ -1,6 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2006 Daniel Silverstone * * This file is part of NetSurf, http://www.netsurf-browser.org/ * diff --git a/beos/beos_filetype.cpp b/beos/beos_filetype.cpp index 1b5b94302..1fa6ff027 100644 --- a/beos/beos_filetype.cpp +++ b/beos/beos_filetype.cpp @@ -1,7 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2007 Rob Kendrick - * Copyright 2007 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -41,11 +39,9 @@ extern "C" { #include "beos/beos_filetype.h" -#warning REMOVEME -static struct hash_table *mime_hash = NULL; - -void beos_fetch_filetype_init(const char *mimefile) +void beos_fetch_filetype_init(void) { +#if 0 BMessage mimes; status_t err; @@ -83,115 +79,11 @@ void beos_fetch_filetype_init(const char *mimefile) hash_add(mime_hash, ext.String(), type.String()); } } - -#warning WRITEME -#if 0 - struct stat statbuf; - FILE *fh = NULL; - - /* first, check to see if /etc/mime.types in preference */ - - if ((stat("/etc/mime.types", &statbuf) == 0) && - S_ISREG(statbuf.st_mode)) { - mimefile = "/etc/mime.types"; - - } - - fh = fopen(mimefile, "r"); - - /* Some OSes (mentioning no Solarises) have a worthlessly tiny - * /etc/mime.types that don't include essential things, so we - * pre-seed our hash with the essentials. These will get - * over-ridden if they are mentioned in the mime.types file. - */ - - hash_add(mime_hash, "css", "text/css"); - hash_add(mime_hash, "htm", "text/html"); - hash_add(mime_hash, "html", "text/html"); - hash_add(mime_hash, "jpg", "image/jpeg"); - hash_add(mime_hash, "jpeg", "image/jpeg"); - hash_add(mime_hash, "gif", "image/gif"); - hash_add(mime_hash, "png", "image/png"); - hash_add(mime_hash, "jng", "image/jng"); - - if (fh == NULL) { - LOG(("Unable to open a mime.types file, so using a minimal one for you.")); - return; - } - - while (!feof(fh)) { - char line[256], *ptr, *type, *ext; - fgets(line, 256, fh); - if (!feof(fh) && line[0] != '#') { - ptr = line; - - /* search for the first non-whitespace character */ - while (isspace(*ptr)) - ptr++; - - /* is this line empty other than leading whitespace? */ - if (*ptr == '\n' || *ptr == '\0') - continue; - - type = ptr; - - /* search for the first non-whitespace char or NUL or - * NL */ - while (*ptr && (!isspace(*ptr)) && *ptr != '\n') - ptr++; - - if (*ptr == '\0' || *ptr == '\n') { - /* this mimetype has no extensions - read next - * line. - */ - continue; - } - - *ptr++ = '\0'; - - /* search for the first non-whitespace character which - * will be the first filename extenion */ - while (isspace(*ptr)) - ptr++; - - while(true) { - ext = ptr; - - /* search for the first whitespace char or - * NUL or NL which is the end of the ext. - */ - while (*ptr && (!isspace(*ptr)) && - *ptr != '\n') - ptr++; - - if (*ptr == '\0' || *ptr == '\n') { - /* special case for last extension on - * the line - */ - *ptr = '\0'; - hash_add(mime_hash, ext, type); - break; - } - - *ptr++ = '\0'; - hash_add(mime_hash, ext, type); - - /* search for the first non-whitespace char or - * NUL or NL, to find start of next ext. - */ - while (*ptr && (isspace(*ptr)) && *ptr != '\n') - ptr++; - } - } - } - - fclose(fh); #endif } void beos_fetch_filetype_fin(void) { - hash_destroy(mime_hash); } const char *fetch_filetype(const char *unix_path) @@ -243,48 +135,6 @@ const char *fetch_filetype(const char *unix_path) } return type; - -#warning WRITEME -#if 0 - struct stat statbuf; - char *ext; - const char *ptr; - char *lowerchar; - const char *type; - - stat(unix_path, &statbuf); - if (S_ISDIR(statbuf.st_mode)) - return "application/x-netsurf-directory"; - - if (strchr(unix_path, '.') == NULL) { - /* no extension anywhere! */ - return "text/plain"; - } - - ptr = unix_path + strlen(unix_path); - while (*ptr != '.' && *ptr != '/') - ptr--; - - if (*ptr != '.') - return "text/plain"; - - ext = strdup(ptr + 1); /* skip the . */ - - /* the hash table only contains lower-case versions - make sure this - * copy is lower case too. - */ - lowerchar = ext; - while(*lowerchar) { - *lowerchar = tolower(*lowerchar); - lowerchar++; - } - - type = hash_get(mime_hash, ext); - free(ext); - - return type != NULL ? type : "text/plain"; -#endif - return NULL; } char *fetch_mimetype(const char *unix_path) @@ -292,28 +142,3 @@ char *fetch_mimetype(const char *unix_path) return strdup(fetch_filetype(unix_path)); } -#ifdef TEST_RIG - -int main(int argc, char *argv[]) -{ - unsigned int c1, *c2; - const char *key; - - beos_fetch_filetype_init("./mime.types"); - - c1 = 0; c2 = 0; - - while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) { - printf("%s ", key); - } - - printf("\n"); - - if (argc > 1) { - printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1])); - } - - beos_fetch_filetype_fin(); -} - -#endif diff --git a/beos/beos_filetype.h b/beos/beos_filetype.h index b5ba0d813..ab0ef410f 100644 --- a/beos/beos_filetype.h +++ b/beos/beos_filetype.h @@ -1,7 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2007 Rob Kendrick - * Copyright 2007 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -18,5 +16,5 @@ * along with this program. If not, see . */ -void beos_fetch_filetype_init(const char *mimefile); +void beos_fetch_filetype_init(void); void beos_fetch_filetype_fin(void); diff --git a/beos/beos_font.cpp b/beos/beos_font.cpp index 70c5be84f..15b865ea8 100644 --- a/beos/beos_font.cpp +++ b/beos/beos_font.cpp @@ -1,6 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2005 James Bursa * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -61,6 +60,7 @@ const struct font_functions nsfont = { nsfont_split }; + /** * Measure the width of a string. * @@ -78,10 +78,6 @@ bool nsfont_width(const struct css_style *style, { //fprintf(stderr, "%s(, '%s', %d, )\n", __FUNCTION__, string, length); BFont font; -#if 0 /* GTK */ - PangoContext *context; - PangoLayout *layout; -#endif if (length == 0) { *width = 0; @@ -91,19 +87,6 @@ bool nsfont_width(const struct css_style *style, nsfont_style_to_font(font, style); *width = (int)font.StringWidth(string, length); return true; -#if 0 /* GTK */ - context = gdk_pango_context_get(); - layout = pango_layout_new(context); - pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, string, length); - - pango_layout_get_pixel_size(layout, width, 0); - - g_object_unref(layout); - g_object_unref(context); - pango_font_description_free(desc); -#endif - return true; } @@ -128,6 +111,7 @@ static int utf8_char_len(const char *c) return i; } + /** * Find the position in a string where an x coordinate falls. * @@ -149,12 +133,6 @@ bool nsfont_position_in_string(const struct css_style *style, //fprintf(stderr, "%s(, '%s', %d, %d, , )\n", __FUNCTION__, string, length, x); int index; BFont font; -#if 0 /* GTK */ - PangoFontDescription *desc; - PangoContext *context; - PangoLayout *layout; - PangoRectangle pos; -#endif nsfont_style_to_font(font, style); BString str(string); @@ -175,26 +153,6 @@ bool nsfont_position_in_string(const struct css_style *style, } *actual_x = (int)current; *char_offset = i; //index; -#if 0 /* GTK */ - context = gdk_pango_context_get(); - layout = pango_layout_new(context); - pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, string, length); - - pango_layout_xy_to_index(layout, x * PANGO_SCALE, 0, &index, 0); - if (pango_layout_xy_to_index(layout, x * PANGO_SCALE, - 0, &index, 0) == 0) - index = length; - - pango_layout_index_to_pos(layout, index, &pos); - - g_object_unref(layout); - g_object_unref(context); - pango_font_description_free(desc); - - *char_offset = index; - *actual_x = PANGO_PIXELS(pos.x); -#endif return true; } @@ -225,14 +183,6 @@ bool nsfont_split(const struct css_style *style, //LOG(("(, '%s', %d, %d, , )", string, length, x)); int index = 0; BFont font; -#if 0 /* GTK */ - PangoFontDescription *desc; - PangoContext *context; - PangoLayout *layout; - PangoLayoutLine *line; - PangoLayoutIter *iter; - PangoRectangle rect; -#endif nsfont_style_to_font(font, style); BString str(string); @@ -261,31 +211,6 @@ bool nsfont_split(const struct css_style *style, } *actual_x = MIN(*actual_x, (int)current); *char_offset = index; - return true; - -#if 0 /* GTK */ - context = gdk_pango_context_get(); - layout = pango_layout_new(context); - pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, string, length); - - pango_layout_set_width(layout, x * PANGO_SCALE); - pango_layout_set_wrap(layout, PANGO_WRAP_WORD); - line = pango_layout_get_line(layout, 1); - if (line) - index = line->start_index - 1; - - iter = pango_layout_get_iter(layout); - pango_layout_iter_get_line_extents(iter, NULL, &rect); - pango_layout_iter_free(iter); - - g_object_unref(layout); - g_object_unref(context); - pango_font_description_free(desc); - - *char_offset = index; - *actual_x = PANGO_PIXELS(rect.width); -#endif return true; } @@ -359,63 +284,6 @@ bool nsfont_paint(const struct css_style *style, //nsbeos_current_gc_unlock(); -#if 0 /* GTK */ - size = (float)((double)pango_font_description_get_size(desc) * nsgtk_plot_get_scale()); - if (pango_font_description_get_size_is_absolute(desc)) - pango_font_description_set_absolute_size(desc, size); - else - pango_font_description_set_size(desc, size); - - PangoFontDescription *desc; - PangoLayout *layout; - gint size; -#ifdef CAIRO_VERSION - int width, height; -#else - PangoLayoutLine *line; - PangoContext *context; - GdkColor colour = { 0, - ((c & 0xff) << 8) | (c & 0xff), - (c & 0xff00) | (c & 0xff00 >> 8), - ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) }; -#endif - - if (length == 0) - return true; - - desc = nsfont_style_to_font(font, style); - size = (gint)((double)pango_font_description_get_size(desc) * nsgtk_plot_get_scale()); - if (pango_font_description_get_size_is_absolute(desc)) - pango_font_description_set_absolute_size(desc, size); - else - pango_font_description_set_size(desc, size); - -#ifdef CAIRO_VERSION - layout = pango_cairo_create_layout(current_cr); -#else - context = gdk_pango_context_get(); - layout = pango_layout_new(context); -#endif - - pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, string, length); - -#ifdef CAIRO_VERSION - pango_layout_get_pixel_size(layout, &width, &height); - cairo_move_to(current_cr, x, y - height); - nsgtk_set_colour(c); - pango_cairo_show_layout(current_cr, layout); -#else - line = pango_layout_get_line(layout, 0); - gdk_draw_layout_line_with_colors(current_drawable, current_gc, - x, y, line, &colour, 0); - - g_object_unref(context); -#endif - g_object_unref(layout); - pango_font_description_free(desc); -#endif - return true; } @@ -434,9 +302,6 @@ static void nsfont_style_to_font(BFont &font, float size; uint16 face = 0; const char *family; -// PangoFontDescription *desc; -// PangoWeight weight = PANGO_WEIGHT_NORMAL; -// PangoStyle styl = PANGO_STYLE_NORMAL; assert(style->font_size.size == CSS_FONT_SIZE_LENGTH); @@ -523,27 +388,6 @@ static void nsfont_style_to_font(BFont &font, font.SetFace(face); } -#if 0 - *font_size = css_len2px(&style->font_size.value.length, style) * - 72.0 / 90.0 * 16.; - if (*font_size < option_font_min_size * 1.6) - *font_size = option_font_min_size * 1.6; - if (1600 < *font_size) - *font_size = 1600; -#endif - -#if 0 /* GTK */ - if (style->font_size.value.length.unit == CSS_UNIT_PX) - size = style->font_size.value.length.value; - else - size = css_len2pt(&style->font_size.value.length, style); - //XXX ? - if (style->font_size.value.length.unit == CSS_UNIT_PX) - font.SetSize(size); - else - font.SetSize(font.Size() + size); -#endif - //fprintf(stderr, "nsfont_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); if (style->font_size.value.length.unit == CSS_UNIT_PT) size = style->font_size.value.length.value; @@ -558,16 +402,4 @@ static void nsfont_style_to_font(BFont &font, //fprintf(stderr, "nsfont_style_to_font: %f %d\n", size, style->font_size.value.length.unit); font.SetSize(size); - - -#if 0 /* GTK */ - switch (style->font_variant) { - case CSS_FONT_VARIANT_SMALL_CAPS: - pango_font_description_set_variant(desc, PANGO_VARIANT_SMALL_CAPS); - break; - case CSS_FONT_VARIANT_NORMAL: - default: - pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL); - } -#endif } diff --git a/beos/beos_font.h b/beos/beos_font.h index d61014900..e6aa39337 100644 --- a/beos/beos_font.h +++ b/beos/beos_font.h @@ -1,6 +1,5 @@ /* * Copyright 2008 François Revol - * Copyright 2005 James Bursa * * This file is part of NetSurf, http://www.netsurf-browser.org/ * diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp index 00feeb8ff..77cb24036 100644 --- a/beos/beos_gui.cpp +++ b/beos/beos_gui.cpp @@ -463,8 +463,8 @@ void gui_init(int argc, char** argv) LOG(("Using '%s' as Messages file", buf)); messages_load(buf); - find_resource(buf, "mime.types", "/etc/mime.types"); - beos_fetch_filetype_init(buf); + //find_resource(buf, "mime.types", "/etc/mime.types"); + beos_fetch_filetype_init(); /* set up stylesheet urls */ diff --git a/beos/beos_thumbnail.cpp b/beos/beos_thumbnail.cpp index af4eab2cc..a9819144a 100644 --- a/beos/beos_thumbnail.cpp +++ b/beos/beos_thumbnail.cpp @@ -45,6 +45,8 @@ extern "C" { // Zeta PRIVATE: in libzeta for now. extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap); +#warning XXX do we need to set bitmap:shadow ? + /** * Create a thumbnail of a page. -- cgit v1.2.3