From 2c0bcc39bdcac27668034f0c56d4919d681b3bfe Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sun, 15 Sep 2013 01:44:04 +0200 Subject: Added plot_get/set_text_plotter and comments --- atari/plot/fontplot.c | 183 +++++++++++++++++++++++++++----------------------- atari/plot/fontplot.h | 107 +++++++++++++++-------------- atari/plot/plot.c | 10 +++ 3 files changed, 165 insertions(+), 135 deletions(-) (limited to 'atari') diff --git a/atari/plot/fontplot.c b/atari/plot/fontplot.c index b80965bb7..d3420b40b 100644 --- a/atari/plot/fontplot.c +++ b/atari/plot/fontplot.c @@ -1,106 +1,121 @@ -/* - * Copyright 2010 Ole Loots - * - * 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 . +/* + * Copyright 2010 Ole Loots + * + * 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 . */ #include "atari/plot/fontplot.h" -const struct s_font_driver_table_entry font_driver_table[] = +const struct s_font_driver_table_entry font_driver_table[] = { -#ifdef WITH_VDI_FONT_DRIVER - {"vdi", ctor_font_plotter_vdi, 0}, +#ifdef WITH_VDI_FONT_DRIVER + {"vdi", ctor_font_plotter_vdi, 0}, #endif #ifdef WITH_FREETYPE_FONT_DRIVER {"freetype", ctor_font_plotter_freetype, 0}, #endif -#ifdef WITH_INTERNAL_FONT_DRIVER +#ifdef WITH_INTERNAL_FONT_DRIVER {"internal", ctor_font_plotter_internal, 0}, -#endif - {(char*)NULL, NULL, 0} +#endif + {(char*)NULL, NULL, 0} }; -void dump_font_drivers(void) -{ - int i = 0; - while( font_driver_table[i].name != NULL ) { - printf("%s -> flags: %d\n", - font_driver_table[i].name, - font_driver_table[i].flags - ); - i++; - } +void dump_font_drivers(void) +{ + int i = 0; + while( font_driver_table[i].name != NULL ) { + printf("%s -> flags: %d\n", + font_driver_table[i].name, + font_driver_table[i].flags + ); + i++; + } } - -/* - Create an new text plotter object -*/ + +/* + * Create an new text plotter object + * Available: "vdi", "freetype" + * @param vdihandle the vdi handle to act upon, + * @param name selector ID (string) of the font plotter. + * @flags flags configration flags of the plotter, + * available flags: + * FONTPLOT_FLAG_MONOGLYPH - Enable 1 bit font plotting + * @param error set to != 0 when errors occur +*/ FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags, - int * error) -{ - int i=0; - int res = 0-ERR_PLOTTER_NOT_AVAILABLE; - FONT_PLOTTER fplotter = (FONT_PLOTTER)malloc( sizeof(struct s_font_plotter) ); - if( fplotter == NULL ) { - *error = 0-ERR_NO_MEM; - return( NULL ); + int * error) +{ + int i=0; + int res = 0-ERR_PLOTTER_NOT_AVAILABLE; + FONT_PLOTTER fplotter; + + /* allocate the font plotter instance: */ + fplotter = (FONT_PLOTTER)malloc( sizeof(struct s_font_plotter) ); + if( fplotter == NULL ) { + *error = 0-ERR_NO_MEM; + return( NULL ); } - memset( fplotter, 0, sizeof(FONT_PLOTTER)); - fplotter->vdi_handle = vdihandle; + + /* Initialize the font plotter with the requested settings: */ + memset( fplotter, 0, sizeof(FONT_PLOTTER)); + fplotter->vdi_handle = vdihandle; fplotter->name = name; - fplotter->flags = 0; + fplotter->flags = 0; fplotter->flags |= flags; - for( i = 0; ; i++) { - if( font_driver_table[i].name == NULL ) { - res = 0-ERR_PLOTTER_NOT_AVAILABLE; - break; - } else { - if( strcmp(name, font_driver_table[i].name) == 0 ) { - if( font_driver_table[i].ctor ) { - res = font_driver_table[i].ctor( fplotter ); - *error = 0; - } else { - res = 0-ERR_PLOTTER_NOT_AVAILABLE; - *error = res; - return (NULL); - } - break; - } - } - } - if( res < 0 ) { - free( fplotter ); - *error = res; - return( NULL ); - } - return( fplotter ); + + /* Find the selector string in the font plotter table: */ + /* And bail out when the font plotter is not available: */ + for( i = 0; ; i++) { + if( font_driver_table[i].name == NULL ) { + res = 0-ERR_PLOTTER_NOT_AVAILABLE; + break; + } else { + if( strcmp(name, font_driver_table[i].name) == 0 ) { + if( font_driver_table[i].ctor ) { + res = font_driver_table[i].ctor( fplotter ); + *error = 0; + } else { + res = 0-ERR_PLOTTER_NOT_AVAILABLE; + *error = res; + return (NULL); + } + break; + } + } + } + if( res < 0 ) { + free( fplotter ); + *error = res; + return( NULL ); + } + return( fplotter ); } -/* - Free an font plotter -*/ -int delete_font_plotter(FONT_PLOTTER p) -{ - if( p ) { - p->dtor(p); - free( p ); - p = NULL; - } - else - return( -1 ); - return( 0 ); +/* + Free an font plotter +*/ +int delete_font_plotter(FONT_PLOTTER p) +{ + if( p ) { + p->dtor(p); + free( p ); + p = NULL; + } + else + return( -1 ); + return( 0 ); } diff --git a/atari/plot/fontplot.h b/atari/plot/fontplot.h index e4286a961..eab35cba7 100644 --- a/atari/plot/fontplot.h +++ b/atari/plot/fontplot.h @@ -1,79 +1,84 @@ #ifndef FONT_PLOT_H #define FONT_PLOT_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include "desktop/plot_style.h" +#include "desktop/plot_style.h" #include "image/bitmap.h" #include "utils/log.h" -#include "atari/bitmap.h" +#include "atari/bitmap.h" #include "atari/plot/eddi.h" -#include "atari/gui.h" -#include "atari/misc.h" +#include "atari/gui.h" +#include "atari/misc.h" #include "atari/osspec.h" -typedef struct s_font_plotter * FONT_PLOTTER; +typedef struct s_font_plotter * FONT_PLOTTER; -struct s_font_driver_table_entry -{ - const char * name; - int (*ctor)( FONT_PLOTTER self ); - int flags; +struct s_font_driver_table_entry +{ + const char * name; + int (*ctor)( FONT_PLOTTER self ); + int flags; }; - -/* declaration of font plotter member functions: (_fpmf_ prefix) */ -typedef int (*_fpmf_str_width)( FONT_PLOTTER self, const plot_font_style_t *fstyle, - const char * str, size_t length, int * width); -typedef int (*_fpmf_str_split)( FONT_PLOTTER self, const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -typedef int (*_fpmf_pixel_pos)( FONT_PLOTTER self, const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -typedef int (*_fpmf_text)( FONT_PLOTTER self, int x, int y, const char *text, - size_t length, const plot_font_style_t *fstyle); + +/* declaration of font plotter member functions: (_fpmf_ prefix) */ +typedef int (*_fpmf_str_width)( FONT_PLOTTER self, const plot_font_style_t *fstyle, + const char * str, size_t length, int * width); +typedef int (*_fpmf_str_split)( FONT_PLOTTER self, const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); +typedef int (*_fpmf_pixel_pos)( FONT_PLOTTER self, const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); +typedef int (*_fpmf_text)( FONT_PLOTTER self, int x, int y, const char *text, + size_t length, const plot_font_style_t *fstyle); typedef void (*_fpmf_draw_glyph)(FONT_PLOTTER self, GRECT * clip, GRECT * loc, uint8_t * pixdata, int pitch, uint32_t colour); -typedef int (*_fpmf_dtor)( FONT_PLOTTER self ); +typedef int (*_fpmf_dtor)( FONT_PLOTTER self ); + - -/* prototype of the font plotter "object" */ -struct s_font_plotter -{ - char * name; - int flags; - int vdi_handle; - void * priv_data; - - _fpmf_str_width str_width; - _fpmf_str_split str_split; - _fpmf_pixel_pos pixel_pos; +/* prototype of the font plotter "object" */ +struct s_font_plotter +{ + char * name; + int flags; + int vdi_handle; + void * priv_data; + + _fpmf_str_width str_width; + _fpmf_str_split str_split; + _fpmf_pixel_pos pixel_pos; _fpmf_text text; - _fpmf_draw_glyph draw_glyph; - _fpmf_dtor dtor; + _fpmf_draw_glyph draw_glyph; + _fpmf_dtor dtor; }; +FONT_PLOTTER plot_get_text_plotter(void); +/* Set the font plotting engine. +*/ +void plot_set_text_plotter(FONT_PLOTTER font_plotter); void dump_font_drivers(void); FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags, int * error); int delete_font_plotter( FONT_PLOTTER p ); -#ifdef WITH_VDI_FONT_DRIVER - #include "atari/plot/font_vdi.h" -#endif -#ifdef WITH_INTERNAL_FONT_DRIVER - #include "atari/plot/font_internal.h" -#endif -#ifdef WITH_FREETYPE_FONT_DRIVER - #include "atari/plot/font_freetype.h" + +#ifdef WITH_VDI_FONT_DRIVER + #include "atari/plot/font_vdi.h" +#endif +#ifdef WITH_INTERNAL_FONT_DRIVER + #include "atari/plot/font_internal.h" +#endif +#ifdef WITH_FREETYPE_FONT_DRIVER + #include "atari/plot/font_freetype.h" #endif -#endif +#endif diff --git a/atari/plot/plot.c b/atari/plot/plot.c index 33810b74e..80eda6949 100755 --- a/atari/plot/plot.c +++ b/atari/plot/plot.c @@ -1974,6 +1974,16 @@ void plot_get_clip_grect(GRECT * out) out->g_h = clip.y1 - clip.y0; } +FONT_PLOTTER plot_get_text_plotter() +{ + return(fplotter); +} + +void plot_set_text_plotter(FONT_PLOTTER font_plotter) +{ + fplotter = font_plotter; +} + static bool plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle ) { fplotter->text(fplotter, x, y, text, length, fstyle); -- cgit v1.2.3