/*
  ArtToSpr Artworks/Draw to Sprite convertor
  Copyright (c) 1998 Tony Houghton

  This source is distributed under the LGPL. Please see the file
  "COPYINGLIB" for details. However, this file may also be used freely
  in other works, including commercial, provided permission is
  from the author (contact details in the !ArtToSpr application's
  !Help file).
*/

#ifndef __awrender_h
#define __awrender_h
/* Low level Artworks rendering */

/* wimplib needed for BBox, replace with a suitable definition of a
   Wimp rectangle if using some other library */
#ifndef __wimplib_h
#include "wimplib.h"
#endif

enum
{
  awrender_DefaultWorkSpace = 512
};

typedef void *awrender_doc;	/* Pointer to Artworks file in memory */
typedef void *awrender_handle;	/* Misc user data */

/* When initialising a file, resizable block holds file and fixed block
   is disused, but must mirror resizable block on return from calback.
   When rendering, fixed block holds file and resizable block contains
   workspace data for AWRender system.
   Callback is allowed to move resizable block, and presumably even
   fixed block if this is necessitated by a shifting heap, but I haven't
   tested it under those conditions.
*/
typedef struct
{
  void *resizable_block;
  int resizable_size;
  void *fixed_block;
  int fixed_size;
} awrender_callback_regs;

typedef _kernel_oserror *(*awrender_callback_handler)(
	int new_size,		/* Or -1 to request existing values */
	awrender_callback_regs *,	/* To return R0-R3 */
	awrender_handle);

/* NB Artworks' internal units are the same as Draw's */

typedef struct
{
  int dither_x, dither_y;	/* On-screen origin for dithering */
  BBox clip_rect;		/* Clip rect in *document* space */
  int print_lowx, print_lowy;
  int print_handle;
} awrender_info_block;

/* As for Draw */
typedef struct
{
  int a, b, c, d, e, f;
} awrender_matrix;

typedef struct
{
  int xeig, yeig;
  int log2bpp;
  Palette palette;	/* As returned by Wimp_ReadPalette */
} awrender_vdu_block;

typedef enum
{
  awrender_OutputToVDU,
  awrender_OutputToPrinter = 2,
  awrender_OutputToPostScript = 4
} awrender_output;

#ifdef __cplusplus
extern "C" {
#endif

/* Both these functions may call the callback handler to resize the resizable
   block or request its size. It's up to you to use the awrender_handle to
   keep track of important data for this.
*/

extern _kernel_oserror *awrender_file_init(
	awrender_doc,
	awrender_callback_handler,
	int doc_size,
	awrender_handle);

extern _kernel_oserror *awrender_render(
	awrender_doc,
	awrender_info_block *,
	awrender_matrix const *,
	awrender_vdu_block const *,
	void *resizable_block,
	awrender_callback_handler,
	int wysiwyg,
	awrender_output,
	awrender_handle);

/* Returns bounding box in Artworks doc coords */
extern _kernel_oserror *awrender_doc_bounds(awrender_doc, BBox *);

#ifdef __cplusplus
}
#endif

#endif
