26#ifdef WITH_DRAW_EXPORT
30#include <oslib/draw.h>
31#include <oslib/osfile.h>
44static struct pencil_diagram *ro_save_draw_diagram;
45static int ro_save_draw_width;
46static int ro_save_draw_height;
55static nserror ro_save_draw_error(pencil_code code)
57 NSLOG(netsurf, INFO,
"code %i", code);
64 case pencil_OUT_OF_MEMORY:
68 case pencil_FONT_MANAGER_ERROR:
72 case pencil_FONT_NOT_FOUND:
75 ro_warn_user(
"SaveError",
"generating the DrawFile failed");
116 int x,
int y,
int radius,
int angle1,
int angle2)
137 int x,
int y,
int radius)
161 draw_MOVE_TO,
line->x0 * 2, -
line->y0 * 2 - 1,
162 draw_LINE_TO,
line->x1 * 2, -
line->y1 * 2 - 1,
166 code = pencil_path(ro_save_draw_diagram,
177 if (code != pencil_OK)
178 return ro_save_draw_error(code);
214 code = pencil_path(ro_save_draw_diagram,
227 if (code != pencil_OK)
228 return ro_save_draw_error(code);
233 code = pencil_path(ro_save_draw_diagram,
247 if (code != pencil_OK)
248 return ro_save_draw_error(code);
278 for (i = 0; i != n; i++) {
279 path[i * 3 + 0] = draw_LINE_TO;
280 path[i * 3 + 1] = p[i * 2 + 0] * 2;
281 path[i * 3 + 2] = -p[i * 2 + 1] * 2;
283 path[0] = draw_MOVE_TO;
284 path[n * 3] = draw_END_PATH;
286 code = pencil_path(ro_save_draw_diagram,
298 if (code != pencil_OK)
299 return ro_save_draw_error(code);
323 const float transform[6])
328 bool empty_path =
true;
334 NSLOG(netsurf, INFO,
"path doesn't start with a move");
338 path = malloc(
sizeof *
path * (n + 10));
340 NSLOG(netsurf, INFO,
"out of memory");
344 for (i = 0; i < n; ) {
346 path[i] = draw_MOVE_TO;
347 path[i + 1] = (transform[0] * p[i + 1] +
348 transform[2] * -p[i + 2] +
350 path[i + 2] = (transform[1] * p[i + 1] +
351 transform[3] * -p[i + 2] +
355 path[i] = draw_CLOSE_LINE;
358 path[i] = draw_LINE_TO;
359 path[i + 1] = (transform[0] * p[i + 1] +
360 transform[2] * -p[i + 2] +
362 path[i + 2] = (transform[1] * p[i + 1] +
363 transform[3] * -p[i + 2] +
368 path[i] = draw_BEZIER_TO;
369 path[i + 1] = (transform[0] * p[i + 1] +
370 transform[2] * -p[i + 2] +
372 path[i + 2] = (transform[1] * p[i + 1] +
373 transform[3] * -p[i + 2] +
375 path[i + 3] = (transform[0] * p[i + 3] +
376 transform[2] * -p[i + 4] +
378 path[i + 4] = (transform[1] * p[i + 3] +
379 transform[3] * -p[i + 4] +
381 path[i + 5] = (transform[0] * p[i + 5] +
382 transform[2] * -p[i + 6] +
384 path[i + 6] = (transform[1] * p[i + 5] +
385 transform[3] * -p[i + 6] +
390 NSLOG(netsurf, INFO,
"bad path command %f", p[i]);
395 path[i] = draw_END_PATH;
402 code = pencil_path(ro_save_draw_diagram,
419 if (code != pencil_OK)
420 return ro_save_draw_error(code);
468 code = pencil_sprite(ro_save_draw_diagram,
473 if (code != pencil_OK)
474 return ro_save_draw_error(code);
500 const char *font_family;
501 unsigned int font_size;
502 rufl_style font_style;
506 code = pencil_text(ro_save_draw_diagram, x * 2, -y * 2, font_family,
507 font_style, font_size,
text, length,
509 if (code != pencil_OK)
510 return ro_save_draw_error(code);
523ro_save_draw_group_start(
const struct redraw_context *ctx,
const char *name)
527 code = pencil_group_start(ro_save_draw_diagram, name);
528 if (code != pencil_OK)
529 return ro_save_draw_error(code);
546 code = pencil_group_end(ro_save_draw_diagram);
547 if (code != pencil_OK)
548 return ro_save_draw_error(code);
556 .line = ro_save_draw_line,
557 .polygon = ro_save_draw_polygon,
558 .clip = ro_save_draw_clip,
559 .text = ro_save_draw_text,
560 .disc = ro_save_draw_disc,
561 .arc = ro_save_draw_arc,
562 .bitmap = ro_save_draw_bitmap,
563 .group_start = ro_save_draw_group_start,
564 .group_end = ro_save_draw_group_end,
565 .path = ro_save_draw_path,
566 .option_knockout =
false,
574 char *drawfile_buffer;
577 size_t drawfile_size;
581 .background_images =
true,
582 .plot = &ro_save_draw_plotters
585 ro_save_draw_diagram = pencil_create();
586 if (!ro_save_draw_diagram) {
598 data.y = -ro_save_draw_height;
599 data.width = ro_save_draw_width;
600 data.height = ro_save_draw_height;
601 data.background_colour = 0xFFFFFF;
603 data.repeat_x =
false;
604 data.repeat_y =
false;
607 pencil_free(ro_save_draw_diagram);
613 code = pencil_save_drawfile(ro_save_draw_diagram,
"NetSurf",
614 &drawfile_buffer, &drawfile_size);
615 if (code != pencil_OK) {
617 pencil_free(ro_save_draw_diagram);
620 assert(drawfile_buffer);
622 error = xosfile_save_stamped(
path, osfile_TYPE_DRAW,
623 (
byte *) drawfile_buffer,
624 (
byte *) drawfile_buffer + drawfile_size);
626 NSLOG(netsurf, INFO,
"xosfile_save_stamped failed: 0x%x: %s",
627 error->errnum, error->errmess);
629 pencil_free(ro_save_draw_diagram);
633 pencil_free(ro_save_draw_diagram);
static osspriteop_area * buffer
The buffer characteristics.
nserror
Enumeration of error codes.
@ NSERROR_INVALID
Invalid data.
unsigned char * riscos_bitmap_get_buffer(void *vbitmap)
Return a pointer to the pixel data in a bitmap.
void nsfont_read_style(const plot_font_style_t *fstyle, const char **font_family, unsigned int *font_size, rufl_style *font_style)
Convert a font style to a font family, size and rufl_style.
Public content interface.
bool content_redraw(struct hlcache_handle *h, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Display content on screen with optional tiling.
int content_get_height(struct hlcache_handle *h)
Retrieve height of content.
int content_get_width(struct hlcache_handle *h)
Retrieve width of content.
Target independent plotting interface.
unsigned long bitmap_flags_t
#define NSLOG(catname, level, logmsg, args...)
#define plot_style_fixed_to_int(v)
@ PLOT_OP_TYPE_NONE
No operation.
#define NS_TRANSPARENT
Transparent colour value.
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
RISC OS wimp toolkit bitmap.
struct osspriteop_area * sprite_area
Uncompressed data, or NULL.
parameters to content redraw
colour foreground
Colour of text.
Plot style for stroke/fill plotters.
colour fill_colour
Colour of fill.
plot_style_fixed stroke_width
Width of stroke, in pixels.
plot_operation_type_t fill_type
Fill plot type.
colour stroke_colour
Colour of stroke.
plot_operation_type_t stroke_type
Stroke plot type.
Plotter operations table.
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
bool interactive
Redraw to show interactive features.
uint32_t colour
Colour type: XBGR.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.