2011-01-06 00:02:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <windom.h>
|
|
|
|
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
|
|
|
|
#include "atari/bitmap.h"
|
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/plot.h"
|
|
|
|
#include "atari/options.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "atari/plot.h"
|
|
|
|
|
|
|
|
GEM_PLOTTER plotter = NULL;
|
|
|
|
GEM_FONT_PLOTTER fplotter = NULL;
|
|
|
|
|
|
|
|
extern short vdih;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Init screen and font driver objects.
|
|
|
|
Returns non-zero value > -1 when the objects could be succesfully created.
|
|
|
|
Returns value < 0 to indicate an error
|
|
|
|
*/
|
|
|
|
|
|
|
|
int atari_plotter_init( char* drvrname, char * fdrvrname )
|
|
|
|
{
|
2011-01-22 19:38:26 +03:00
|
|
|
GRECT loc_pos={0,0,360,400};
|
2011-01-06 00:02:22 +03:00
|
|
|
int err=0;
|
|
|
|
struct s_driver_table_entry * drvinfo;
|
2012-01-07 02:06:31 +04:00
|
|
|
int flags = 0;
|
|
|
|
unsigned long font_flags = 0;
|
2011-01-06 00:02:22 +03:00
|
|
|
|
2011-11-24 02:37:29 +04:00
|
|
|
if( option_atari_dither == 1)
|
2011-01-06 00:02:22 +03:00
|
|
|
flags |= PLOT_FLAG_DITHER;
|
2011-11-24 02:37:29 +04:00
|
|
|
if( option_atari_transparency == 1 )
|
2012-01-07 02:06:31 +04:00
|
|
|
flags |= PLOT_FLAG_TRANS;
|
|
|
|
if( option_atari_font_monochrom == 1 )
|
|
|
|
font_flags |= FONTPLOT_FLAG_MONOGLYPH;
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
vdih = app.graf.handle;
|
|
|
|
if( verbose_log ) {
|
|
|
|
dump_vdi_info( vdih ) ;
|
|
|
|
dump_plot_drivers();
|
|
|
|
dump_font_drivers();
|
|
|
|
}
|
|
|
|
drvinfo = get_screen_driver_entry( drvrname );
|
|
|
|
|
|
|
|
LOG(("using plotters: %s, %s", drvrname, fdrvrname));
|
2012-01-07 02:06:31 +04:00
|
|
|
fplotter = new_font_plotter(vdih, fdrvrname, font_flags, &err );
|
2011-12-07 01:06:41 +04:00
|
|
|
if(err){
|
2012-03-22 01:19:30 +04:00
|
|
|
const char * desc = plotter_err_str(err);
|
2011-12-07 01:06:41 +04:00
|
|
|
die(("Unable to load font plotter %s -> %s", fdrvrname, desc ));
|
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
plotter = new_plotter( vdih, drvrname, &loc_pos, drvinfo->max_bpp,
|
|
|
|
flags, fplotter, &err );
|
2011-12-07 01:06:41 +04:00
|
|
|
if(err){
|
2012-03-22 01:19:30 +04:00
|
|
|
const char * desc = plotter_err_str(err);
|
2011-12-07 01:06:41 +04:00
|
|
|
die(("Unable to load graphics plotter %s -> %s", drvrname, desc ));
|
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
return( err );
|
|
|
|
}
|
|
|
|
|
|
|
|
int atari_plotter_finalise( void )
|
|
|
|
{
|
|
|
|
delete_plotter( plotter );
|
|
|
|
delete_font_plotter( fplotter );
|
|
|
|
}
|
|
|
|
|
2011-11-24 02:37:29 +04:00
|
|
|
bool plot_rectangle( int x0, int y0, int x1, int y1,
|
2011-06-30 23:16:11 +04:00
|
|
|
const plot_style_t *style )
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
plotter->rectangle( plotter, x0, y0, x1, y1, style );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
2011-11-24 02:37:29 +04:00
|
|
|
bool plot_line( int x0, int y0, int x1, int y1,
|
2011-06-30 23:16:11 +04:00
|
|
|
const plot_style_t *style )
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
plotter->line( plotter, x0, y0, x1, y1, style );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plot_polygon(const int *p, unsigned int n,
|
2011-06-30 23:16:11 +04:00
|
|
|
const plot_style_t *style)
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
plotter->polygon( plotter, p, n, style );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
2011-02-15 01:05:39 +03:00
|
|
|
bool plot_clip(const struct rect *clip)
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
2012-03-22 01:19:30 +04:00
|
|
|
plotter->set_clip( plotter, clip );
|
2011-01-06 00:02:22 +03:00
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:19:56 +03:00
|
|
|
|
2012-03-22 01:19:30 +04:00
|
|
|
bool plot_get_clip(struct rect * out)
|
|
|
|
{
|
|
|
|
plotter->get_clip( plotter, out );
|
2011-01-06 00:02:22 +03:00
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:19:56 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
static bool plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle )
|
|
|
|
{
|
|
|
|
plotter->text( plotter, x, y, text, length, fstyle );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plot_disc(int x, int y, int radius, const plot_style_t *style)
|
|
|
|
{
|
|
|
|
plotter->disc(plotter, x, y, radius, style );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plot_arc(int x, int y, int radius, int angle1, int angle2,
|
|
|
|
const plot_style_t *style)
|
|
|
|
{
|
|
|
|
plotter->arc( plotter, x, y, radius, angle1, angle2, style );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plot_bitmap(int x, int y, int width, int height,
|
|
|
|
struct bitmap *bitmap, colour bg,
|
|
|
|
bitmap_flags_t flags)
|
|
|
|
{
|
|
|
|
struct bitmap * bm = NULL;
|
|
|
|
bool repeat_x = (flags & BITMAPF_REPEAT_X);
|
|
|
|
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
|
2011-02-12 22:26:49 +03:00
|
|
|
int bmpw,bmph;
|
2012-01-07 02:06:31 +04:00
|
|
|
struct rect clip;
|
2011-11-24 02:37:29 +04:00
|
|
|
|
|
|
|
bmpw = bitmap_get_width(bitmap);
|
2012-01-07 02:06:31 +04:00
|
|
|
bmph = bitmap_get_height(bitmap);
|
|
|
|
|
2011-11-24 02:37:29 +04:00
|
|
|
if ( repeat_x || repeat_y ) {
|
2012-03-22 01:19:30 +04:00
|
|
|
plotter->get_clip( plotter, &clip );
|
2011-11-24 02:37:29 +04:00
|
|
|
if( repeat_x && width == 1 && repeat_y && height == 1 ){
|
2011-02-12 22:26:49 +03:00
|
|
|
width = MAX( width, clip.x1 - x );
|
|
|
|
height = MAX( height, clip.y1 - y );
|
|
|
|
}
|
|
|
|
else if( repeat_x && width == 1 ){
|
|
|
|
width = MAX( width, clip.x1 - x);
|
2011-11-24 02:37:29 +04:00
|
|
|
}
|
2011-02-12 22:26:49 +03:00
|
|
|
else if( repeat_y && height == 1){
|
|
|
|
height = MAX( height, clip.y1 - y );
|
2011-11-24 02:37:29 +04:00
|
|
|
}
|
2011-02-12 22:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if( width != bmpw || height != bmph ) {
|
2011-04-11 01:49:27 +04:00
|
|
|
plotter->bitmap_resize(plotter, bitmap, width, height );
|
|
|
|
if( bitmap->resized )
|
|
|
|
bm = bitmap->resized;
|
2011-11-24 02:37:29 +04:00
|
|
|
else
|
2011-04-11 01:49:27 +04:00
|
|
|
bm = bitmap;
|
2011-01-06 00:02:22 +03:00
|
|
|
} else {
|
|
|
|
bm = bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* out of memory? */
|
2011-03-01 22:31:28 +03:00
|
|
|
if( bm == NULL ) {
|
2011-04-11 01:49:27 +04:00
|
|
|
printf("plot: out of memory! bmp: %p, bmpres: %p\n", bitmap, bitmap->resized );
|
2011-01-06 00:02:22 +03:00
|
|
|
return( true );
|
2011-03-01 22:31:28 +03:00
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
if (!(repeat_x || repeat_y)) {
|
|
|
|
plotter->bitmap( plotter, bm, x, y, bg, flags );
|
|
|
|
} else {
|
|
|
|
int xf,yf;
|
|
|
|
int xoff = x;
|
|
|
|
int yoff = y;
|
2011-11-24 02:37:29 +04:00
|
|
|
|
2011-03-01 22:31:28 +03:00
|
|
|
if (yoff > clip.y0 )
|
|
|
|
yoff = (clip.y0 - height) + ((yoff - clip.y0) % height);
|
|
|
|
if (xoff > clip.x0 )
|
|
|
|
xoff = (clip.x0 - width) + ((xoff - clip.x0) % width);
|
2011-01-06 00:02:22 +03:00
|
|
|
/* for now, repeating just works in the rigth / down direction */
|
|
|
|
/*
|
|
|
|
if( repeat_x == true )
|
|
|
|
xoff = clip.x0;
|
|
|
|
if(repeat_y == true )
|
|
|
|
yoff = clip.y0;
|
2011-04-11 01:49:27 +04:00
|
|
|
*/
|
2011-03-01 22:31:28 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
for( xf = xoff; xf < clip.x1; xf += width ) {
|
|
|
|
for( yf = yoff; yf < clip.y1; yf += height ) {
|
|
|
|
plotter->bitmap( plotter, bm, xf, yf, bg, flags );
|
|
|
|
if (!repeat_y)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!repeat_x)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool plot_path(const float *p, unsigned int n, colour fill, float width,
|
|
|
|
colour c, const float transform[6])
|
|
|
|
{
|
|
|
|
plotter->path( plotter, p, n, fill, width, c, transform );
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-30 23:16:11 +04:00
|
|
|
const struct plotter_table atari_plotters = {
|
2011-01-06 00:02:22 +03:00
|
|
|
.rectangle = plot_rectangle,
|
|
|
|
.line = plot_line,
|
|
|
|
.polygon = plot_polygon,
|
|
|
|
.clip = plot_clip,
|
|
|
|
.text = plot_text,
|
|
|
|
.disc = plot_disc,
|
|
|
|
.arc = plot_arc,
|
|
|
|
.bitmap = plot_bitmap,
|
|
|
|
.path = plot_path,
|
|
|
|
.flush = NULL,
|
|
|
|
.group_start = NULL,
|
|
|
|
.group_end = NULL,
|
2011-12-10 04:38:21 +04:00
|
|
|
.option_knockout = true
|
2011-01-06 00:02:22 +03:00
|
|
|
};
|