static bool nsico_convert(struct content *c) { nsico_content *ico = (nsico_content *) c; struct bmp_image *bmp; bmp_result res; union content_msg_data msg_data; const char *data; unsigned long size; char *title; /* set the ico data */ data = content__get_source_data(c, &size); /* analyse the ico */ res = ico_analyse(ico->ico, size, (unsigned char *) data); switch (res) { case BMP_OK: break; case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: msg_data.error = messages_get("BadICO"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } /* Store our content width, height and calculate size */ c->width = ico->ico->width; c->height = ico->ico->height; c->size += (ico->ico->width * ico->ico->height * 4) + 16 + 44; /* set title text */ title = messages_get_buff("ICOTitle", nsurl_access_leaf(llcache_handle_get_url(c->llcache)), c->width, c->height); if (title != NULL) { content__set_title(c, title); free(title); } /* select largest icon to ensure one can be selected */ bmp = ico_find(ico->ico, 255, 255); if (bmp == NULL) { /* return error */ LOG("Failed to select icon"); return false; } content_set_ready(c); content_set_done(c); /* Done: update status bar */ content_set_status(c, ""); return true; }
/** * Handler for low-level cache events * * \param llcache Low-level cache handle * \param event Event details * \param pw Pointer to our context * \return NSERROR_OK on success, appropriate error otherwise */ nserror content_llcache_callback(llcache_handle *llcache, const llcache_event *event, void *pw) { struct content *c = pw; union content_msg_data msg_data; nserror error = NSERROR_OK; switch (event->type) { case LLCACHE_EVENT_HAD_HEADERS: /* Will never happen: handled in hlcache */ break; case LLCACHE_EVENT_HAD_DATA: if (c->handler->process_data != NULL) { if (c->handler->process_data(c, (const char *) event->data.data.buf, event->data.data.len) == false) { llcache_handle_abort(c->llcache); c->status = CONTENT_STATUS_ERROR; /** \todo It's not clear what error this is */ error = NSERROR_NOMEM; } } break; case LLCACHE_EVENT_DONE: { size_t source_size; (void) llcache_handle_get_source_data(llcache, &source_size); content_set_status(c, messages_get("Processing")); msg_data.explicit_status_text = NULL; content_broadcast(c, CONTENT_MSG_STATUS, msg_data); content_convert(c); } break; case LLCACHE_EVENT_ERROR: /** \todo Error page? */ c->status = CONTENT_STATUS_ERROR; msg_data.error = event->data.msg; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); break; case LLCACHE_EVENT_PROGRESS: content_set_status(c, event->data.msg); msg_data.explicit_status_text = NULL; content_broadcast(c, CONTENT_MSG_STATUS, msg_data); break; case LLCACHE_EVENT_REDIRECT: msg_data.redirect.from = event->data.redirect.from; msg_data.redirect.to = event->data.redirect.to; content_broadcast(c, CONTENT_MSG_REDIRECT, msg_data); break; } return error; }
static bool nsbmp_convert(struct content *c) { nsbmp_content *bmp = (nsbmp_content *) c; bmp_result res; union content_msg_data msg_data; uint32_t swidth; const char *data; unsigned long size; char *title; /* set the bmp data */ data = content__get_source_data(c, &size); /* analyse the BMP */ res = bmp_analyse(bmp->bmp, size, (unsigned char *) data); switch (res) { case BMP_OK: break; case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: msg_data.error = messages_get("BadBMP"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } /* Store our content width and description */ c->width = bmp->bmp->width; c->height = bmp->bmp->height; swidth = bmp->bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bmp->bitmap) * bmp->bmp->width; c->size += (swidth * bmp->bmp->height) + 16 + 44; /* set title text */ title = messages_get_buff("BMPTitle", nsurl_access_leaf(llcache_handle_get_url(c->llcache)), c->width, c->height); if (title != NULL) { content__set_title(c, title); free(title); } /* exit as a success */ bmp->bitmap = bmp->bmp->bitmap; guit->bitmap->modified(bmp->bitmap); content_set_ready(c); content_set_done(c); /* Done: update status bar */ content_set_status(c, ""); return true; }
bool nsico_convert(struct content *c) { struct bmp_image *bmp; bmp_result res; ico_collection *ico; union content_msg_data msg_data; const char *data; unsigned long size; char title[100]; /* set the ico data */ ico = c->data.ico.ico; data = content__get_source_data(c, &size); /* analyse the ico */ res = ico_analyse(ico, size, (unsigned char *) data); switch (res) { case BMP_OK: break; case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: msg_data.error = messages_get("BadICO"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } /* Store our content width and description */ c->width = ico->width; c->height = ico->height; snprintf(title, sizeof(title), messages_get("ICOTitle"), c->width, c->height, size); content__set_title(c, title); c->size += (ico->width * ico->height * 4) + 16 + 44; /* exit as a success */ bmp = ico_find(c->data.ico.ico, 255, 255); assert(bmp); c->bitmap = bmp->bitmap; bitmap_modified(c->bitmap); c->status = CONTENT_STATUS_DONE; /* Done: update status bar */ content_set_status(c, ""); return true; }
/** * Handle notification that a CSS object is done * * \param css CSS object * \param pw Private data */ void nscss_content_done(struct content_css_data *css, void *pw) { union content_msg_data msg_data; struct content *c = pw; uint32_t i; size_t size; css_error error; /* Retrieve the size of this sheet */ error = css_stylesheet_size(css->sheet, &size); if (error != CSS_OK) { msg_data.error = "?"; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_set_error(c); return; } c->size += size; /* Add on the size of the imported sheets */ for (i = 0; i < css->import_count; i++) { if (css->imports[i].c != NULL) { struct content *import = hlcache_handle_get_content( css->imports[i].c); if (import != NULL) { c->size += import->size; } } } /* Finally, catch the content's users up with reality */ content_set_ready(c); content_set_done(c); }
static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) { NSLOG(netsurf, INFO, "amiga_dt_picture_cache_convert"); union content_msg_data msg_data; UBYTE *bm_buffer; Object *dto; struct bitmap *bitmap; struct amiga_dt_picture_content *adt = (struct amiga_dt_picture_content *)c; if((dto = amiga_dt_picture_newdtobject(adt))) { bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NEW); if (!bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return NULL; } bm_buffer = amiga_bitmap_get_buffer(bitmap); IDoMethod(dto, PDTM_READPIXELARRAY, bm_buffer, PBPAFMT_RGBA, amiga_bitmap_get_rowstride(bitmap), 0, 0, c->width, c->height); amiga_bitmap_set_opaque(bitmap, amiga_bitmap_test_opaque(bitmap)); DisposeDTObject(dto); adt->dto = NULL; } else return NULL; return bitmap; }
/* Exported function documented in search.h */ void search_step(struct search_context *context, search_flags_t flags, const char *string) { int string_len; int i = 0; if (context == NULL) { warn_user("SearchError", 0); return; } guit->search->add_recent(string, context->gui_p); string_len = strlen(string); for (i = 0; i < string_len; i++) if (string[i] != '#' && string[i] != '*') break; if (i >= string_len) { union content_msg_data msg_data; free_matches(context); guit->search->status(true, context->gui_p); guit->search->back_state(false, context->gui_p); guit->search->forward_state(false, context->gui_p); msg_data.scroll.area = false; msg_data.scroll.x0 = 0; msg_data.scroll.y0 = 0; content_broadcast(context->c, CONTENT_MSG_SCROLL, msg_data); return; } search_text(string, string_len, context, flags); }
/** * Initialise a CSS content * * \param c Content to initialise * \param params Content-Type parameters * \return true on success, false on failure */ nserror nscss_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c) { nscss_content *result; const char *charset = NULL; const char *xnsbase = NULL; lwc_string *charset_value = NULL; union content_msg_data msg_data; nserror error; result = calloc(1, sizeof(nscss_content)); if (result == NULL) return NSERROR_NOMEM; error = content__init(&result->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { free(result); return error; } /* Find charset specified on HTTP layer, if any */ error = http_parameter_list_find_item(params, css_charset, &charset_value); if (error != NSERROR_OK || lwc_string_length(charset_value) == 0) { /* No charset specified, use fallback, if any */ /** \todo libcss will take this as gospel, which is wrong */ charset = fallback_charset; } else { charset = lwc_string_data(charset_value); } /* Compute base URL for stylesheet */ xnsbase = llcache_handle_get_header(llcache, "X-NS-Base"); if (xnsbase == NULL) { xnsbase = nsurl_access(content_get_url(&result->base)); } error = nscss_create_css_data(&result->data, xnsbase, charset, result->base.quirks, nscss_content_done, result); if (error != NSERROR_OK) { msg_data.error = messages_get("NoMemory"); content_broadcast(&result->base, CONTENT_MSG_ERROR, msg_data); if (charset_value != NULL) lwc_string_unref(charset_value); free(result); return error; } if (charset_value != NULL) lwc_string_unref(charset_value); *c = (struct content *) result; return NSERROR_OK; }
/** * Convert a CONTENT_JPEG for display. */ static bool nsjpeg_convert(struct content *c) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; jmp_buf setjmp_buffer; struct jpeg_source_mgr source_mgr = { 0, 0, nsjpeg_init_source, nsjpeg_fill_input_buffer, nsjpeg_skip_input_data, jpeg_resync_to_restart, nsjpeg_term_source }; union content_msg_data msg_data; const char *data; unsigned long size; char title[100]; /* check image header is valid and get width/height */ data = content__get_source_data(c, &size); cinfo.err = jpeg_std_error(&jerr); jerr.error_exit = nsjpeg_error_exit; jerr.output_message = nsjpeg_error_log; if (setjmp(setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); msg_data.error = nsjpeg_error_buffer; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } jpeg_create_decompress(&cinfo); cinfo.client_data = &setjmp_buffer; source_mgr.next_input_byte = (unsigned char *) data; source_mgr.bytes_in_buffer = size; cinfo.src = &source_mgr; jpeg_read_header(&cinfo, TRUE); cinfo.out_color_space = JCS_RGB; cinfo.dct_method = JDCT_ISLOW; jpeg_calc_output_dimensions(&cinfo); c->width = cinfo.output_width; c->height = cinfo.output_height; c->size = c->width * c->height * 4; jpeg_destroy_decompress(&cinfo); image_cache_add(c, NULL, jpeg_cache_convert); snprintf(title, sizeof(title), messages_get("JPEGTitle"), c->width, c->height, size); content__set_title(c, title); content_set_ready(c); content_set_done(c); content_set_status(c, ""); /* Done: update status bar */ return true; }
bool sprite_convert(struct content *c) { os_error *error; int w, h; union content_msg_data msg_data; const char *source_data; unsigned long source_size; const void *sprite_data; char title[100]; source_data = content__get_source_data(c, &source_size); sprite_data = source_data - 4; osspriteop_area *area = (osspriteop_area*) sprite_data; c->data.sprite.data = area; /* check for bad data */ if ((int)source_size + 4 != area->used) { msg_data.error = messages_get("BadSprite"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } error = xosspriteop_read_sprite_info(osspriteop_PTR, (osspriteop_area *)0x100, (osspriteop_id) ((char *) area + area->first), &w, &h, NULL, NULL); if (error) { LOG(("xosspriteop_read_sprite_info: 0x%x: %s", error->errnum, error->errmess)); msg_data.error = error->errmess; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } c->width = w; c->height = h; snprintf(title, sizeof(title), messages_get("SpriteTitle"), c->width, c->height, source_size); content__set_title(c, title); c->status = CONTENT_STATUS_DONE; /* Done: update status bar */ content_set_status(c, ""); return true; }
void content_set_done(struct content *c) { union content_msg_data msg_data; c->status = CONTENT_STATUS_DONE; c->time = wallclock() - c->time; content_update_status(c); content_broadcast(c, CONTENT_MSG_DONE, msg_data); }
static nserror nspng_create_png_data(nspng_content *png_c) { union content_msg_data msg_data; png_c->bitmap = NULL; png_c->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (png_c->png == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); warn_user("NoMemory", 0); return NSERROR_NOMEM; } png_set_error_fn(png_c->png, NULL, nspng_error, nspng_warning); png_c->info = png_create_info_struct(png_c->png); if (png_c->info == NULL) { png_destroy_read_struct(&png_c->png, &png_c->info, 0); msg_data.error = messages_get("NoMemory"); content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); warn_user("NoMemory", 0); return NSERROR_NOMEM; } if (setjmp(png_jmpbuf(png_c->png))) { png_destroy_read_struct(&png_c->png, &png_c->info, 0); LOG(("Failed to set callbacks")); png_c->png = NULL; png_c->info = NULL; msg_data.error = messages_get("PNGError"); content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); return NSERROR_NOMEM; } png_set_progressive_read_fn(png_c->png, png_c, info_callback, row_callback, end_callback); return NSERROR_OK; }
static bool nspng_process_data(struct content *c, const char *data, unsigned int size) { nspng_content *png_c = (nspng_content *)c; union content_msg_data msg_data; volatile bool ret = true; if (png_c->no_process_data) { return ret; } switch (setjmp(png_jmpbuf(png_c->png))) { case CBERR_NONE: /* direct return */ png_process_data(png_c->png, png_c->info, (uint8_t *)data, size); break; case CBERR_NOPRE: /* not going to progressive convert */ png_c->no_process_data = true; break; default: /* fatal error from library processing png */ if (png_c->bitmap != NULL) { /* A bitmap managed to get created so * operation is past header and possibly some * conversion happened before faliure. * * In this case keep the partial * conversion. This is usually seen if a png * has been truncated (often jsut lost its * last byte and hence end of image marker) */ png_c->no_process_data = true; } else { /* not managed to progress past header, clean * up png conversion and signal the content * error */ LOG(("Fatal PNG error during header, error content")); png_destroy_read_struct(&png_c->png, &png_c->info, 0); png_c->png = NULL; png_c->info = NULL; msg_data.error = messages_get("PNGError"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); ret = false; } break; } return ret; }
bool nsico_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; c->data.ico.ico = calloc(sizeof(ico_collection), 1); if (!c->data.ico.ico) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } ico_collection_create(c->data.ico.ico, &bmp_bitmap_callbacks); return true; }
void content_set_ready(struct content *c) { union content_msg_data msg_data; /* The content must be locked at this point, as it can only * become READY after conversion. */ assert(c->locked); c->locked = false; c->status = CONTENT_STATUS_READY; content_update_status(c); content_broadcast(c, CONTENT_MSG_READY, msg_data); }
static nserror nsbmp_create_bmp_data(nsbmp_content *bmp) { union content_msg_data msg_data; bmp_bitmap_callback_vt bmp_bitmap_callbacks = { .bitmap_create = nsbmp_bitmap_create, .bitmap_destroy = guit->bitmap->destroy, .bitmap_get_buffer = guit->bitmap->get_buffer, .bitmap_get_bpp = guit->bitmap->get_bpp }; bmp->bmp = calloc(sizeof(struct bmp_image), 1); if (bmp->bmp == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data); return NSERROR_NOMEM; } bmp_create(bmp->bmp, &bmp_bitmap_callbacks); return NSERROR_OK; } static nserror nsbmp_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c) { nsbmp_content *bmp; nserror error; bmp = calloc(1, sizeof(nsbmp_content)); if (bmp == NULL) return NSERROR_NOMEM; error = content__init(&bmp->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { free(bmp); return error; } error = nsbmp_create_bmp_data(bmp); if (error != NSERROR_OK) { free(bmp); return error; } *c = (struct content *) bmp; return NSERROR_OK; }
/** * Process CSS source data * * \param c Content structure * \param data Data to process * \param size Number of bytes to process * \return true on success, false on failure */ bool nscss_process_data(struct content *c, const char *data, unsigned int size) { nscss_content *css = (nscss_content *) c; union content_msg_data msg_data; css_error error; error = nscss_process_css_data(&css->data, data, size); if (error != CSS_OK && error != CSS_NEEDDATA) { msg_data.error = "?"; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); } return (error == CSS_OK || error == CSS_NEEDDATA); }
static nserror nsgif_create_gif_data(nsgif_content *c) { union content_msg_data msg_data; /* Initialise our data structure */ c->gif = calloc(sizeof(gif_animation), 1); if (c->gif == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); return NSERROR_NOMEM; } gif_create(c->gif, &gif_bitmap_callbacks); return NSERROR_OK; }
/** * Convert a CSS content ready for use * * \param c Content to convert * \return true on success, false on failure */ bool nscss_convert(struct content *c) { nscss_content *css = (nscss_content *) c; union content_msg_data msg_data; css_error error; error = nscss_convert_css_data(&css->data); if (error != CSS_OK) { msg_data.error = "?"; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } return true; }
bool content__add_rfc5988_link(struct content *c, const struct content_rfc5988_link *link) { struct content_rfc5988_link *newlink; union content_msg_data msg_data; /* a link relation must be present for it to be a link */ if (link->rel == NULL) { return false; } /* a link href must be present for it to be a link */ if (link->href == NULL) { return false; } newlink = calloc(1, sizeof(struct content_rfc5988_link)); if (newlink == NULL) { return false; } /* copy values */ newlink->rel = lwc_string_ref(link->rel); newlink->href = nsurl_ref(link->href); if (link->hreflang != NULL) { newlink->hreflang = lwc_string_ref(link->hreflang); } if (link->type != NULL) { newlink->type = lwc_string_ref(link->type); } if (link->media != NULL) { newlink->media = lwc_string_ref(link->media); } if (link->sizes != NULL) { newlink->sizes = lwc_string_ref(link->sizes); } /* add to metadata link to list */ newlink->next = c->links; c->links = newlink; /* broadcast the data */ msg_data.rfc5988_link = newlink; content_broadcast(c, CONTENT_MSG_LINK, msg_data); return true; }
void content_mouse_track(hlcache_handle *h, struct browser_window *bw, browser_mouse_state mouse, int x, int y) { struct content *c = hlcache_handle_get_content(h); assert(c != NULL); if (c->handler->mouse_track != NULL) { c->handler->mouse_track(c, bw, mouse, x, y); } else { union content_msg_data msg_data; msg_data.pointer = BROWSER_POINTER_AUTO; content_broadcast(c, CONTENT_MSG_POINTER, msg_data); } return; }
static bool rsvg_process_data(struct content *c, const char *data, unsigned int size) { rsvg_content *d = (rsvg_content *) c; union content_msg_data msg_data; GError *err = NULL; if (rsvg_handle_write(d->rsvgh, (const guchar *)data, (gsize)size, &err) == FALSE) { LOG(("rsvg_handle_write returned an error: %s", err->message)); msg_data.error = err->message; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } return true; }
bool draw_convert(struct content *c) { union content_msg_data msg_data; const char *source_data; unsigned long source_size; const void *data; os_box bbox; os_error *error; char title[100]; source_data = content__get_source_data(c, &source_size); data = source_data; /* BBox contents in Draw units (256*OS unit) */ error = xdrawfile_bbox(0, (drawfile_diagram *) data, (int) source_size, 0, &bbox); if (error) { LOG(("xdrawfile_bbox: 0x%x: %s", error->errnum, error->errmess)); msg_data.error = error->errmess; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } if (bbox.x1 > bbox.x0 && bbox.y1 > bbox.y0) { /* c->width & c->height stored as (OS units/2) => divide by 512 to convert from draw units */ c->width = ((bbox.x1 - bbox.x0) / 512); c->height = ((bbox.y1 - bbox.y0) / 512); } else /* invalid/undefined bounding box */ c->height = c->width = 0; c->data.draw.x0 = bbox.x0; c->data.draw.y0 = bbox.y0; snprintf(title, sizeof(title), messages_get("DrawTitle"), c->width, c->height, source_size); content__set_title(c, title); c->status = CONTENT_STATUS_DONE; /* Done: update status bar */ content_set_status(c, ""); return true; }
static nserror rsvg_create_svg_data(rsvg_content *c) { union content_msg_data msg_data; c->rsvgh = NULL; c->cs = NULL; c->ct = NULL; c->bitmap = NULL; if ((c->rsvgh = rsvg_handle_new()) == NULL) { LOG(("rsvg_handle_new() returned NULL.")); msg_data.error = messages_get("NoMemory"); content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); return NSERROR_NOMEM; } return NSERROR_OK; }
static nserror svg_create_svg_data(svg_content *c) { union content_msg_data msg_data; c->diagram = svgtiny_create(); if (c->diagram == NULL) goto no_memory; c->current_width = INT_MAX; c->current_height = INT_MAX; return NSERROR_OK; no_memory: msg_data.error = messages_get("NoMemory"); content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); return NSERROR_NOMEM; }
static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) { LOG(("amiga_dt_picture_cache_convert")); union content_msg_data msg_data; const uint8 *data; UBYTE *bm_buffer; ULONG size; Object *dto; struct bitmap *bitmap; unsigned int bm_flags = BITMAP_NEW; int bm_format = PBPAFMT_RGBA; /* This is only relevant for picture datatypes... */ data = (uint8 *)content__get_source_data(c, &size); if(dto = NewDTObject(NULL, DTA_SourceType, DTST_MEMORY, DTA_SourceAddress, data, DTA_SourceSize, size, DTA_GroupID, GID_PICTURE, PDTA_DestMode, PMODE_V43, TAG_DONE)) { bitmap = bitmap_create(c->width, c->height, bm_flags); if (!bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return NULL; } bm_buffer = bitmap_get_buffer(bitmap); IDoMethod(dto, PDTM_READPIXELARRAY, bm_buffer, bm_format, bitmap_get_rowstride(bitmap), 0, 0, c->width, c->height); DisposeDTObject(dto); } else return NULL; return bitmap; }
static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) { LOG(("amiga_dt_picture_cache_convert")); union content_msg_data msg_data; UBYTE *bm_buffer; Object *dto; struct bitmap *bitmap; unsigned int bm_flags = BITMAP_NEW; #ifdef __amigaos4__ int bm_format = PBPAFMT_RGBA; #else int bm_format = PBPAFMT_ARGB; #endif struct amiga_dt_picture_content *adt = (struct amiga_dt_picture_content *)c; if(dto = amiga_dt_picture_newdtobject(adt)) { bitmap = bitmap_create(c->width, c->height, bm_flags); if (!bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return NULL; } bm_buffer = bitmap_get_buffer(bitmap); IDoMethod(dto, PDTM_READPIXELARRAY, bm_buffer, bm_format, bitmap_get_rowstride(bitmap), 0, 0, c->width, c->height); #ifndef __amigaos4__ ami_bitmap_argb_to_rgba(bitmap); #endif bitmap_set_opaque(bitmap, bitmap_test_opaque(bitmap)); DisposeDTObject(dto); adt->dto = NULL; } else return NULL; return bitmap; }
void content__reformat(struct content *c, bool background, int width, int height) { union content_msg_data data; assert(c != 0); assert(c->status == CONTENT_STATUS_READY || c->status == CONTENT_STATUS_DONE); assert(c->locked == false); c->available_width = width; if (c->handler->reformat != NULL) { c->locked = true; c->handler->reformat(c, width, height); c->locked = false; data.background = background; content_broadcast(c, CONTENT_MSG_REFORMAT, data); } }
static dom_hubbub_error exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype) { union content_msg_data msg_data; dom_string *script; dom_exception exc; /* returned by libdom functions */ struct lwc_string_s *lwcmimetype; script_handler_t *script_handler; struct html_script *nscript; /* does not appear to be a src so script is inline content */ exc = dom_node_get_text_content(node, &script); if ((exc != DOM_NO_ERR) || (script == NULL)) { return DOM_HUBBUB_OK; /* no contents, skip */ } nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE); if (nscript == NULL) { dom_string_unref(script); msg_data.error = messages_get("NoMemory"); content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); return DOM_HUBBUB_NOMEM; } nscript->data.string = script; nscript->already_started = true; /* ensure script handler for content type */ dom_string_intern(mimetype, &lwcmimetype); script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype)); lwc_string_unref(lwcmimetype); if (script_handler != NULL) { script_handler(c->jscontext, dom_string_data(script), dom_string_byte_length(script)); } return DOM_HUBBUB_OK; }
/** * process script node parser callback * * */ dom_hubbub_error html_process_script(void *ctx, dom_node *node) { html_content *c = (html_content *)ctx; dom_exception exc; /* returned by libdom functions */ dom_string *src, *mimetype; dom_hubbub_error err = DOM_HUBBUB_OK; /* ensure javascript context is available */ if (c->jscontext == NULL) { union content_msg_data msg_data; msg_data.jscontext = &c->jscontext; content_broadcast(&c->base, CONTENT_MSG_GETCTX, msg_data); LOG(("javascript context %p ", c->jscontext)); if (c->jscontext == NULL) { /* no context and it could not be created, abort */ return DOM_HUBBUB_OK; } } LOG(("content %p parser %p node %p", c, c->parser, node)); exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype); if (exc != DOM_NO_ERR || mimetype == NULL) { mimetype = dom_string_ref(corestring_dom_text_javascript); } exc = dom_element_get_attribute(node, corestring_dom_src, &src); if (exc != DOM_NO_ERR || src == NULL) { err = exec_inline_script(c, node, mimetype); } else { err = exec_src_script(c, node, mimetype, src); dom_string_unref(src); } dom_string_unref(mimetype); return err; }