From 54f719aa960159c5b1978846223732c9669ca7fa Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Thu, 31 Jan 2013 19:22:35 +0100 Subject: Some more finetuning... --- atari/plot/font_freetype.c | 7 +- atari/plot/font_internal.c | 16 +++- atari/plot/font_vdi.c | 207 +++++++++++++++++++++++++++++++-------------- atari/plot/plot.c | 72 ++++++++-------- atari/plot/plot.h | 4 +- 5 files changed, 199 insertions(+), 107 deletions(-) (limited to 'atari/plot') diff --git a/atari/plot/font_freetype.c b/atari/plot/font_freetype.c index 2339cd659..8db7cc2c0 100755 --- a/atari/plot/font_freetype.c +++ b/atari/plot/font_freetype.c @@ -607,9 +607,10 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng #ifdef WITH_8BPP_SUPPORT if( app.nplanes > 8 ){ #endif - unsigned short out[4]; - rgb_to_vdi1000( (unsigned char*)&c, (unsigned short*)&out ); - vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0]); + RGB1000 out; + rgb_to_vdi1000( (unsigned char*)&c, &out); + vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, + (unsigned short*)&out); #ifdef WITH_8BPP_SUPPORT } else { c = RGB_TO_VDI(c); diff --git a/atari/plot/font_internal.c b/atari/plot/font_internal.c index 6e6e330ef..3db29eba5 100644 --- a/atari/plot/font_internal.c +++ b/atari/plot/font_internal.c @@ -245,10 +245,18 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng #ifdef WITH_8BPP_SUPPORT if( app.nplanes > 8 ){ #endif - unsigned short out[4]; - rgb_to_vdi1000( (unsigned char*)&fstyle->foreground, (unsigned short*)&out ); - vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0] ); - plot_blit_mfdb(&loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS ); + //unsigned short out[4]; + RGB1000 out; + //rgb_to_vdi1000( (unsigned char*)&fstyle->foreground, (unsigned short*)&out ); + out.blue = 0; + out.green = 1000; + out.red = 0; + vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, (short *)&out); + vq_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, 1, (short *)&out); + //printf("r:%d,g:%d,b:%d", out.red, out.green, out.blue); + //vsl_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR); + //vsf_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR); + plot_blit_mfdb(&loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS); #ifdef WITH_8BPP_SUPPORT } else { unsigned char c = RGB_TO_VDI(fstyle->foreground); diff --git a/atari/plot/font_vdi.c b/atari/plot/font_vdi.c index 89596b38a..4ebab24fb 100755 --- a/atari/plot/font_vdi.c +++ b/atari/plot/font_vdi.c @@ -16,15 +16,20 @@ * along with this program. If not, see . */ -#ifdef WITH_VDI_FONT_DRIVER +#ifdef WITH_VDI_FONT_DRIVER + +#include + #include "atari/plot/plot.h" #include "atari/plot/font_vdi.h" #include "utils/utf8.h" -#include "utils/log.h" +#include "utils/log.h" + -static char * lstr = NULL; + +//static char * lstr = NULL; static int dtor( FONT_PLOTTER self ); @@ -39,6 +44,25 @@ static bool init = false; static int vdih; extern struct s_vdi_sysinfo vdi_sysinfo; + +static inline void atari_to_vdi_str(char *lstr, int length) +{ + int i, z; + + for (i=z=0; iflags & FONTF_ITALIC ) fx |= 4; @@ -79,11 +107,19 @@ static int str_width( FONT_PLOTTER self,const plot_font_style_t *fstyle, const c fx |= 1; vst_effects( self->vdi_handle, fx ); /* TODO: replace 90 with global dpi setting */ - pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); - vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh); + //pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); + //vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh); + pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 ); + vst_point( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh); +/* + if(slen != utf8_bounded_length(str, length)){ + printf("sl: %d, utl: %d\n ", slen, utf8_bounded_length(str, length)); + printf("s: %s // %s\n", str, lstr ); + }*/ + + *width = slen * cellw; - free( (void*)lstr ); - lstr = NULL; + free((void*)lstr); return( 0 ); } @@ -94,15 +130,19 @@ static int str_split( FONT_PLOTTER self, const plot_font_style_t * fstyle, const short pxsize; short fx=0; int i; - lstr = (char*)string; - int slen = 0; + char *lstr = NULL; + size_t slen = 0; int last_space_x = 0; - int last_space_idx = 0; + int last_space_idx = 0; + size_t nxtchr = 0; - utf8_to_enc(string, "ATARIST", length, &lstr ); + utf8_to_local_encoding(string, length, &lstr ); assert( lstr != NULL ); + slen = strlen(lstr); + + + atari_to_vdi_str(lstr, slen); - slen = strlen(lstr); if( fstyle->flags & FONTF_ITALIC ) fx |= 4; if( fstyle->flags & FONTF_OBLIQUE ) @@ -110,27 +150,50 @@ static int str_split( FONT_PLOTTER self, const plot_font_style_t * fstyle, const if( fstyle->weight > 450 ) fx |= 1; vst_effects( self->vdi_handle, fx ); - pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); - vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh); + //pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); + //vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh); + + pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 ); + vst_point( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh); *actual_x = 0; - *char_offset = 0; - int cpos=0; - for( i=0; i x ) { - *actual_x = last_space_x; - *char_offset = last_space_idx; - return true; - } - *actual_x += cellw; - cpos++; - } - *char_offset = cpos; + last_space_idx = nxtchr; + } + *actual_x += cellw; + if (*actual_x > x) { + *actual_x = last_space_x; + *char_offset = last_space_idx; + //printf("at: %s\n", lstr); + return(0); + } + + nxtchr++; + } + if(nxtchr >= length){ + nxtchr = length-1; + } + + *char_offset = nxtchr; + +// for( i=0; i x ) { +// *actual_x = last_space_x; +// *char_offset = last_space_idx; +// return true; +// } +// *actual_x += cellw; +// cpos++; +// } +// *char_offset = cpos; free( (void*)lstr ); - lstr = NULL; return( 0 ); } @@ -141,19 +204,22 @@ static int pixel_pos( FONT_PLOTTER self, const plot_font_style_t * fstyle,const short pxsize=0; short fx=0; - lstr = (char*)string; + char *lstr = NULL; int i=0; int curpx=0; - utf8_to_enc(string, "ATRIST", length, &lstr ); + utf8_to_local_encoding(string, length, &lstr ); assert( lstr != NULL ); - int slen = strlen(lstr); + int slen = strlen(lstr); + + atari_to_vdi_str(lstr, slen); + if( fstyle->flags & FONTF_ITALIC ) fx |= 4; if( fstyle->flags & FONTF_OBLIQUE ) fx |= 16; if( fstyle->weight > 450 ) fx |= 1; - vst_effects( self->vdi_handle, fx ); + vst_effects(self->vdi_handle, fx); pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh); *actual_x = 0; @@ -166,24 +232,30 @@ static int pixel_pos( FONT_PLOTTER self, const plot_font_style_t * fstyle,const break; } } - free( (void*)lstr ); + free((void*)lstr); lstr = NULL; return( 0 ); } static inline void vst_rgbcolor( short vdih, uint32_t cin ) { - if( vdi_sysinfo.scr_bpp > 8 ) { - unsigned short c[4]; - rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c ); - vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0] ); +#ifdef WITH_8BPP_SUPPORT + if( vdi_sysinfo.scr_bpp > 8 ) { +#endif + //unsigned short c[4]; + RGB1000 c; + + rgb_to_vdi1000( (unsigned char*)&cin, &c ); + vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c); vst_color( vdih, OFFSET_CUSTOM_COLOR ); +#ifdef WITH_8BPP_SUPPORT } else { if( vdi_sysinfo.scr_bpp >= 4 ) vst_color( vdih, RGB_TO_VDI(cin) ); else vst_color( vdih, BLACK ); - } + } +#endif } static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t length, @@ -192,16 +264,20 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng /* todo: either limit the string to max 80 chars, or use v_ftext instead of v_gtext */ short cw, ch, cellw, cellh; short pxsize=8; - short fx=0; - lstr = (char*)text; - utf8_to_enc(text, "ATARIST", length, &lstr ); - assert( lstr != NULL ); - int slen = strlen(lstr); - size_t mylen = MIN(511, slen ); - char textcpy[mylen+1]; + short fx=0; + GRECT canvas; + char *lstr = NULL; + assert( utf8_to_local_encoding(text, length, &lstr) == UTF8_CONVERT_OK); + assert( lstr != NULL ); + + int slen = strlen(lstr); + if(slen > 800){ + lstr[800]=0; + } + + + atari_to_vdi_str(lstr, slen); - textcpy[mylen] = 0; - strncpy((char*)&textcpy, lstr, mylen+1 ); if( fstyle != NULL){ if( fstyle->flags & FONTF_ITALIC ) fx |= 4; @@ -212,20 +288,25 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng /* TODO: netsurf uses 90 as default dpi ( somewhere defined in libcss), use that value or pass it as arg, to reduce netsurf dependency */ + //pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 ); - } - x += CURFB(self->plotter).x; - y += CURFB(self->plotter).y; + } + plot_get_dimensions(&canvas); + x += canvas.g_x; + y += canvas.g_y; vst_effects( self->vdi_handle, fx ); - vst_alignment(vdih, 0, 4, &cw, &ch ); - vst_height( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh); + vst_alignment(vdih, 0, 0, &cw, &ch ); + vst_point( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh); + //vst_height( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh); vswr_mode( self->vdi_handle, MD_TRANS ); - vst_rgbcolor(self->vdi_handle, fstyle->foreground ); + vst_rgbcolor(self->vdi_handle, fstyle->foreground); - if( atari_sysinfo.gdos_FSMC ){ - v_ftext( self->vdi_handle, x, y, (char*)&textcpy ); - } else { - v_gtext( self->vdi_handle, x, y, (char*)&textcpy ); + if( atari_sysinfo.gdos_FSMC ){ + //printf("\nftext\n"); + v_ftext( self->vdi_handle, x, y, (char*)lstr ); + } else { + //printf("\ngtext\n"); + v_gtext( self->vdi_handle, x, y, (char*)lstr ); } free( lstr ); return( 0 ); diff --git a/atari/plot/plot.c b/atari/plot/plot.c index eb44e47b8..2a8fd6868 100755 --- a/atari/plot/plot.c +++ b/atari/plot/plot.c @@ -193,9 +193,10 @@ inline static void vsl_rgbcolor(short vdih, colour cin) #ifdef WITH_8BPP_SUPPORT if( vdi_sysinfo.scr_bpp > 8 ) { #endif - unsigned short c[4]; - rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c); - vs_color(vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0]); + //unsigned short c[4]; + RGB1000 c; + rgb_to_vdi1000( (unsigned char*)&cin, &c); + vs_color(vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c); vsl_color(vdih, OFFSET_CUSTOM_COLOR); #ifdef WITH_8BPP_SUPPORT } else { @@ -219,9 +220,9 @@ inline static void vsf_rgbcolor(short vdih, colour cin) #ifdef WITH_8BPP_SUPPORT if( vdi_sysinfo.scr_bpp > 8 ) { #endif - unsigned short c[4]; - rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c ); - vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] ); + RGB1000 c; + rgb_to_vdi1000( (unsigned char*)&cin, &c); + vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c); vsf_color( vdih, OFFSET_CUSTOM_COLOR ); #ifdef WITH_8BPP_SUPPORT } else { @@ -512,14 +513,14 @@ static struct s_vdi_sysinfo * read_vdi_sysinfo(short vdih, struct s_vdi_sysinfo /* Convert an RGB color to an VDI Color */ -inline void rgb_to_vdi1000(unsigned char * in, unsigned short * out) +inline void rgb_to_vdi1000(unsigned char * in, RGB1000 *out) { double r = ((double)in[3]/255); /* prozentsatz red */ double g = ((double)in[2]/255); /* prozentsatz green */ double b = ((double)in[1]/255); /* prozentsatz blue */ - out[0] = 1000 * r + 0.5; - out[1] = 1000 * g + 0.5; - out[2] = 1000 * b + 0.5; + out->red = 1000 * r + 0.5; + out->green = 1000 * g + 0.5; + out->blue = 1000 * b + 0.5; return; } @@ -1441,14 +1442,14 @@ bool plot_blit_bitmap(struct bitmap * bmp, int x, int y, return(true); } -bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor, +bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, short fgcolor, uint32_t flags) { MFDB screen, tran; MFDB * src; short pxy[8]; - short c[2] = {fgcolor, G_WHITE}; + short c[2] = {fgcolor, 0}; GRECT off; plot_get_clip_grect(&off); @@ -1457,29 +1458,30 @@ bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor, } init_mfdb( 0, loc->g_w, loc->g_h, 0, &screen ); - - if( insrc->fd_stand ){ - int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h, - MFDB_FLAG_NOALLOC, - &tran - ); - if( size_buf_scr == 0 ){ - buf_scr.fd_addr = malloc( size ); - size_buf_scr = size; - } else { - if( size > size_buf_scr ) { - buf_scr.fd_addr = realloc( - buf_scr.fd_addr, size - ); - size_buf_scr = size; - } - } - tran.fd_addr = buf_scr.fd_addr; - vr_trnfm(atari_plot_vdi_handle, insrc, &tran ); - src = &tran; - } else { +// +// if( insrc->fd_stand){ +// printf("st\n"); +// int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h, +// MFDB_FLAG_NOALLOC, +// &tran +// ); +// if( size_buf_scr == 0 ){ +// buf_scr.fd_addr = malloc( size ); +// size_buf_scr = size; +// } else { +// if( size > size_buf_scr ) { +// buf_scr.fd_addr = realloc( +// buf_scr.fd_addr, size +// ); +// size_buf_scr = size; +// } +// } +// tran.fd_addr = buf_scr.fd_addr; +// vr_trnfm(atari_plot_vdi_handle, insrc, &tran ); +// src = &tran; +// } else { src = insrc; - } +// } pxy[0] = off.g_x - loc->g_x; pxy[1] = off.g_y - loc->g_y; @@ -1492,7 +1494,7 @@ bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor, if( flags & PLOT_FLAG_TRANS && src->fd_nplanes == 1){ - vrt_cpyfm(atari_plot_vdi_handle, MD_TRANS, (short*)pxy, src, &screen, (short*)&c ); + vrt_cpyfm(atari_plot_vdi_handle, MD_REPLACE/*MD_TRANS*/, (short*)pxy, src, &screen, (short*)&c); } else { /* this method only plots transparent bitmaps, right now... */ } diff --git a/atari/plot/plot.h b/atari/plot/plot.h index df34be4d5..b0ec58b5a 100755 --- a/atari/plot/plot.h +++ b/atari/plot/plot.h @@ -115,7 +115,7 @@ bool plot_rectangle( int x0, int y0, int x1, int y1,const plot_style_t *style ); bool plot_line( int x0, int y0, int x1, int y1, const plot_style_t *style ); bool plot_blit_bitmap(struct bitmap * bmp, int x, int y, unsigned long bg, unsigned long flags); -bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor, +bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, short fgcolor, uint32_t flags); bool plot_copy_rect(GRECT src, GRECT dst); @@ -123,7 +123,7 @@ bool plot_copy_rect(GRECT src, GRECT dst); void vdi1000_to_rgb( unsigned short * in, unsigned char * out ); /* convert an bgra color to vdi1000 color */ -void rgb_to_vdi1000( unsigned char * in, unsigned short * out ); +void rgb_to_vdi1000( unsigned char * in, RGB1000 *out); /* convert an rgb color to an index into the web palette */ short rgb_to_666_index(unsigned char r, unsigned char g, unsigned char b); -- cgit v1.2.3