diff --git a/ChangeLog b/ChangeLog index c857757..ace20a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-08-21 14:52 Alexander Malmberg + + * Source/art/blit.h, Source/art/blit.m, Source/art/ftfont.h, + Source/art/ftfont.m: Reformat to fit coding standards better. + 2002-08-21 13:50 Alexander Malmberg * Source/art/ARTContext.m: Move common code from _fill and DPSstroke diff --git a/Source/art/blit.h b/Source/art/blit.h index 204f98b..d2f2b61 100644 --- a/Source/art/blit.h +++ b/Source/art/blit.h @@ -36,27 +36,27 @@ copyright 2002 Alexander Malmberg typedef struct render_run_s { - unsigned char r,g,b,a,real_a; - unsigned char *dst,*dsta; + unsigned char r, g, b, a, real_a; + unsigned char *dst, *dsta; - /* the following fields are only used by the svp rendering helpers */ - int x0,x1; - int rowstride,arowstride,bpp; - void (*run_alpha)(struct render_run_s *ri,int num); - void (*run_opaque)(struct render_run_s *ri,int num); + /* the following fields are only used by the svp rendering helpers */ + int x0, x1; + int rowstride, arowstride, bpp; + void (*run_alpha)(struct render_run_s *ri, int num); + void (*run_opaque)(struct render_run_s *ri, int num); } render_run_t; typedef struct { - unsigned char *dst,*dsta; - unsigned char *src,*srca; + unsigned char *dst, *dsta; + unsigned char *src, *srca; } composite_run_t; typedef struct draw_info_s { - int how; + int how; #define DI_FALLBACK 0 /* counting from lsb */ @@ -72,64 +72,65 @@ typedef struct draw_info_s #define DI_NUM 9 - int bytes_per_pixel; - int drawing_depth; - int inline_alpha,inline_alpha_ofs; + int bytes_per_pixel; + int drawing_depth; + int inline_alpha, inline_alpha_ofs; - void (*render_run_alpha)(render_run_t *ri,int num); - void (*render_run_opaque)(render_run_t *ri,int num); - void (*render_run_alpha_a)(render_run_t *ri,int num); - void (*render_run_opaque_a)(render_run_t *ri,int num); + void (*render_run_alpha)(render_run_t *ri, int num); + void (*render_run_opaque)(render_run_t *ri, int num); + void (*render_run_alpha_a)(render_run_t *ri, int num); + void (*render_run_opaque_a)(render_run_t *ri, int num); - void (*render_blit_alpha_opaque)(unsigned char *dst, - const unsigned char *src, - unsigned char r,unsigned char g,unsigned char b,int num); - void (*render_blit_mono_opaque)(unsigned char *dst, - const unsigned char *src,int src_ofs, - unsigned char r,unsigned char g,unsigned char b, - int num); + void (*render_blit_alpha_opaque)(unsigned char *dst, + const unsigned char *src, + unsigned char r, unsigned char g, + unsigned char b, int num); + void (*render_blit_mono_opaque)(unsigned char *dst, + const unsigned char *src, int src_ofs, + unsigned char r, unsigned char g, + unsigned char b, int num); - void (*render_blit_alpha)(unsigned char *dst,const unsigned char *src, - unsigned char r,unsigned char g,unsigned char b, - unsigned char alpha,int num); - void (*render_blit_mono)(unsigned char *dst, - const unsigned char *src,int src_ofs, - unsigned char r,unsigned char g,unsigned char b, - unsigned char alpha,int num); + void (*render_blit_alpha)(unsigned char *dst, const unsigned char *src, + unsigned char r, unsigned char g, unsigned char b, + unsigned char alpha, int num); + void (*render_blit_mono)(unsigned char *dst, + const unsigned char *src, int src_ofs, + unsigned char r, unsigned char g, unsigned char b, + unsigned char alpha, int num); - void (*composite_sover_aa)(composite_run_t *c,int num); - void (*composite_sover_ao)(composite_run_t *c,int num); + void (*composite_sover_aa)(composite_run_t *c, int num); + void (*composite_sover_ao)(composite_run_t *c, int num); - void (*composite_sin_aa)(composite_run_t *c,int num); - void (*composite_sin_oa)(composite_run_t *c,int num); + void (*composite_sin_aa)(composite_run_t *c, int num); + void (*composite_sin_oa)(composite_run_t *c, int num); - void (*composite_sout_aa)(composite_run_t *c,int num); - void (*composite_sout_oa)(composite_run_t *c,int num); + void (*composite_sout_aa)(composite_run_t *c, int num); + void (*composite_sout_oa)(composite_run_t *c, int num); - void (*composite_satop_aa)(composite_run_t *c,int num); + void (*composite_satop_aa)(composite_run_t *c, int num); - void (*composite_dover_aa)(composite_run_t *c,int num); - void (*composite_dover_oa)(composite_run_t *c,int num); + void (*composite_dover_aa)(composite_run_t *c, int num); + void (*composite_dover_oa)(composite_run_t *c, int num); - void (*composite_din_aa)(composite_run_t *c,int num); + void (*composite_din_aa)(composite_run_t *c, int num); - void (*composite_dout_aa)(composite_run_t *c,int num); + void (*composite_dout_aa)(composite_run_t *c, int num); - void (*composite_datop_aa)(composite_run_t *c,int num); + void (*composite_datop_aa)(composite_run_t *c, int num); - void (*composite_xor_aa)(composite_run_t *c,int num); + void (*composite_xor_aa)(composite_run_t *c, int num); - void (*composite_plusl_aa)(composite_run_t *c,int num); - void (*composite_plusl_oa)(composite_run_t *c,int num); - void (*composite_plusl_ao)(composite_run_t *c,int num); - void (*composite_plusl_oo)(composite_run_t *c,int num); + void (*composite_plusl_aa)(composite_run_t *c, int num); + void (*composite_plusl_oa)(composite_run_t *c, int num); + void (*composite_plusl_ao)(composite_run_t *c, int num); + void (*composite_plusl_oo)(composite_run_t *c, int num); - void (*composite_plusd_aa)(composite_run_t *c,int num); - void (*composite_plusd_oa)(composite_run_t *c,int num); - void (*composite_plusd_ao)(composite_run_t *c,int num); - void (*composite_plusd_oo)(composite_run_t *c,int num); + void (*composite_plusd_aa)(composite_run_t *c, int num); + void (*composite_plusd_oa)(composite_run_t *c, int num); + void (*composite_plusd_ao)(composite_run_t *c, int num); + void (*composite_plusd_oo)(composite_run_t *c, int num); } draw_info_t; #define RENDER_RUN_ALPHA (DI.render_run_alpha) @@ -143,13 +144,13 @@ typedef struct draw_info_s #define RENDER_BLIT_MONO DI.render_blit_mono void artcontext_setup_draw_info(draw_info_t *di, - unsigned int red_mask,unsigned int green_mask,unsigned int blue_mask, + unsigned int red_mask, unsigned int green_mask, unsigned int blue_mask, int bpp); -void artcontext_render_svp(const ArtSVP *svp,int x0,int y0,int x1,int y1, - unsigned char r,unsigned char g,unsigned char b,unsigned char a, - unsigned char *dst,int rowstride, - unsigned char *dsta,int arowstride,int has_alpha, +void artcontext_render_svp(const ArtSVP *svp, int x0, int y0, int x1, int y1, + unsigned char r, unsigned char g, unsigned char b, unsigned char a, + unsigned char *dst, int rowstride, + unsigned char *dsta, int arowstride, int has_alpha, draw_info_t *di); #endif diff --git a/Source/art/blit.m b/Source/art/blit.m index 7b9906a..a2b9fcd 100644 --- a/Source/art/blit.m +++ b/Source/art/blit.m @@ -1356,58 +1356,58 @@ ourself. static void render_svp_callback(void *data,int y,int start, ArtSVPRenderAAStep *steps,int n_steps) { - render_run_t *ri=data; - int x0=ri->x0,x1; - int num; - int alpha; - unsigned char *dst,*dsta; + render_run_t *ri=data; + int x0=ri->x0,x1; + int num; + int alpha; + unsigned char *dst,*dsta; - alpha=start; + alpha=start; - /* empty line; very common case */ - if (alpha<0x10000 && !n_steps) + /* empty line; very common case */ + if (alpha<0x10000 && !n_steps) + { + ri->dst+=ri->rowstride; + ri->dsta+=ri->arowstride; + return; + } + + dst=ri->dst+ri->rowstride; + dsta=ri->dsta+ri->arowstride; + + for (;n_steps;n_steps--,steps++) + { + x1=steps->x; + num=x1-x0; + + ri->a=(alpha*ri->real_a+0x800000)>>24; + if (ri->a && num) { - ri->dst+=ri->rowstride; - ri->dsta+=ri->arowstride; - return; + if (ri->a==255) + ri->run_opaque(ri,num); + else + ri->run_alpha(ri,num); } + ri->dst+=ri->bpp*num; + ri->dsta+=num; - dst=ri->dst+ri->rowstride; - dsta=ri->dsta+ri->arowstride; + alpha+=steps->delta; + x0=x1; + } - for (;n_steps;n_steps--,steps++) - { - x1=steps->x; - num=x1-x0; + x1=ri->x1; + num=x1-x0; + ri->a=(alpha*ri->real_a+0x800000)>>24; + if (ri->a && num) + { + if (ri->a==255) + ri->run_opaque(ri,num); + else + ri->run_alpha(ri,num); + } - ri->a=(alpha*ri->real_a+0x800000)>>24; - if (ri->a && num) - { - if (ri->a==255) - ri->run_opaque(ri,num); - else - ri->run_alpha(ri,num); - } - ri->dst+=ri->bpp*num; - ri->dsta+=num; - - alpha+=steps->delta; - x0=x1; - } - - x1=ri->x1; - num=x1-x0; - ri->a=(alpha*ri->real_a+0x800000)>>24; - if (ri->a && num) - { - if (ri->a==255) - ri->run_opaque(ri,num); - else - ri->run_alpha(ri,num); - } - - ri->dst=dst; - ri->dsta=dsta; + ri->dst=dst; + ri->dsta=dsta; } void artcontext_render_svp(const ArtSVP *svp,int x0,int y0,int x1,int y1, @@ -1416,35 +1416,35 @@ void artcontext_render_svp(const ArtSVP *svp,int x0,int y0,int x1,int y1, unsigned char *dsta,int arowstride,int has_alpha, draw_info_t *di) { - render_run_t ri; + render_run_t ri; - ri.x0=x0; - ri.x1=x1; + ri.x0=x0; + ri.x1=x1; - ri.r=r; - ri.g=g; - ri.b=b; - ri.real_a=ri.a=a; + ri.r=r; + ri.g=g; + ri.b=b; + ri.real_a=ri.a=a; - ri.bpp=di->bytes_per_pixel; + ri.bpp=di->bytes_per_pixel; - ri.dst=dst; - ri.rowstride=rowstride; + ri.dst=dst; + ri.rowstride=rowstride; - if (has_alpha) - { - ri.dsta=dsta; - ri.arowstride=arowstride; - ri.run_alpha=di->render_run_alpha_a; - ri.run_opaque=di->render_run_opaque_a; - } - else - { - ri.run_alpha=di->render_run_alpha; - ri.run_opaque=di->render_run_opaque; - } + if (has_alpha) + { + ri.dsta=dsta; + ri.arowstride=arowstride; + ri.run_alpha=di->render_run_alpha_a; + ri.run_opaque=di->render_run_opaque_a; + } + else + { + ri.run_alpha=di->render_run_alpha; + ri.run_opaque=di->render_run_opaque; + } - art_svp_render_aa(svp,x0,y0,x1,y1,render_svp_callback,&ri); + art_svp_render_aa(svp,x0,y0,x1,y1,render_svp_callback,&ri); } @@ -1504,84 +1504,84 @@ might eventually need to be fixed */ static int byte_ofs_of_mask(unsigned int m) { - union - { - unsigned char b[4]; - unsigned int m; - } tmp; + union + { + unsigned char b[4]; + unsigned int m; + } tmp; - tmp.m=m; - if (tmp.b[0]==0xff && !tmp.b[1] && !tmp.b[2] && !tmp.b[3]) - return 0; - else if (tmp.b[1]==0xff && !tmp.b[0] && !tmp.b[2] && !tmp.b[3]) - return 1; - else if (tmp.b[2]==0xff && !tmp.b[0] && !tmp.b[1] && !tmp.b[3]) - return 2; - else if (tmp.b[3]==0xff && !tmp.b[0] && !tmp.b[1] && !tmp.b[2]) - return 3; - else - return -1; + tmp.m=m; + if (tmp.b[0]==0xff && !tmp.b[1] && !tmp.b[2] && !tmp.b[3]) + return 0; + else if (tmp.b[1]==0xff && !tmp.b[0] && !tmp.b[2] && !tmp.b[3]) + return 1; + else if (tmp.b[2]==0xff && !tmp.b[0] && !tmp.b[1] && !tmp.b[3]) + return 2; + else if (tmp.b[3]==0xff && !tmp.b[0] && !tmp.b[1] && !tmp.b[2]) + return 3; + else + return -1; } void artcontext_setup_draw_info(draw_info_t *di, unsigned int red_mask,unsigned int green_mask,unsigned int blue_mask, int bpp) { - int t=DI_FALLBACK; + int t=DI_FALLBACK; - if (bpp==16 && red_mask==0xf800 && green_mask==0x7e0 && - blue_mask==0x1f) + if (bpp==16 && red_mask==0xf800 && green_mask==0x7e0 && + blue_mask==0x1f) + { + t=DI_16_B5_G6_R5; + } + else if (bpp==16 && red_mask==0x7c00 && green_mask==0x3e0 && + blue_mask==0x1f) + { + t=DI_16_B5_G5_R5_A1; + } + else if (bpp==24 || bpp==32) + { + int r,g,b; + + r=byte_ofs_of_mask(red_mask); + g=byte_ofs_of_mask(green_mask); + b=byte_ofs_of_mask(blue_mask); + + if (bpp==24) { - t=DI_16_B5_G6_R5; + if (r==0 && g==1 && b==2) + t=DI_24_RGB; + else if (r==2 && g==1 && b==0) + t=DI_24_BGR; } - else if (bpp==16 && red_mask==0x7c00 && green_mask==0x3e0 && - blue_mask==0x1f) + else if (bpp==32) { - t=DI_16_B5_G5_R5_A1; + if (r==0 && g==1 && b==2) + t=DI_32_RGBA; + else if (r==2 && g==1 && b==0) + t=DI_32_BGRA; + else if (r==1 && g==2 && b==3) + t=DI_32_ARGB; + else if (r==3 && g==2 && b==1) + t=DI_32_ABGR; } - else if (bpp==24 || bpp==32) - { - int r,g,b; + } - r=byte_ofs_of_mask(red_mask); - g=byte_ofs_of_mask(green_mask); - b=byte_ofs_of_mask(blue_mask); + // t=DI_32_ARGB; /* HACK */ - if (bpp==24) - { - if (r==0 && g==1 && b==2) - t=DI_24_RGB; - else if (r==2 && g==1 && b==0) - t=DI_24_BGR; - } - else if (bpp==32) - { - if (r==0 && g==1 && b==2) - t=DI_32_RGBA; - else if (r==2 && g==1 && b==0) - t=DI_32_BGRA; - else if (r==1 && g==2 && b==3) - t=DI_32_ARGB; - else if (r==3 && g==2 && b==1) - t=DI_32_ABGR; - } - } - -// t=DI_32_ARGB; /* HACK */ - - *di=draw_infos[t]; - if (!di->render_run_alpha) - *di=draw_infos[DI_FALLBACK]; - if (di->how==DI_FALLBACK) - { - NSLog(@"Unrecognized color masks: %08x:%08x:%08x %i", - red_mask,green_mask,blue_mask,bpp); -// NSLog(@"Attempting to use fallback code (currently unimplemented). This will be _very_ slow!"); - NSLog(@"Please report this along with details on your pixel format " - @"(ie. the four numbers above). (Or better yet, implement it " - @"and send me a patch.)"); - exit(1); - } + *di=draw_infos[t]; + if (!di->render_run_alpha) + *di=draw_infos[DI_FALLBACK]; + if (di->how==DI_FALLBACK) + { + NSLog(@"Unrecognized color masks: %08x:%08x:%08x %i", + red_mask,green_mask,blue_mask,bpp); + // NSLog(@"Attempting to use fallback code (currently unimplemented). This will be _very_ slow!"); + NSLog(@"Please report this along with details on your pixel format " + @"(ie. the four numbers above). (Or better yet, implement it " + @"and send me a patch.)"); + exit(1); + } } #endif diff --git a/Source/art/ftfont.h b/Source/art/ftfont.h index 4eb931f..a4bb1be 100644 --- a/Source/art/ftfont.h +++ b/Source/art/ftfont.h @@ -25,12 +25,15 @@ copyright 2002 Alexander Malmberg @protocol FTFontInfo -(void) drawString: (const char *)s - at: (int)x:(int)y - to: (int)x0:(int)y0:(int)x1:(int)y1:(unsigned char *)buf:(int)bpl - color:(unsigned char)r:(unsigned char)g:(unsigned char)b:(unsigned char)alpha + at: (int)x : (int)y + to: (int)x0 : (int)y0 : (int)x1 : (int)y1 + : (unsigned char *)buf : (int)bpl + color: (unsigned char)r : (unsigned char)g : (unsigned char)b + : (unsigned char)alpha transform: (NSAffineTransform *)transform drawinfo: (struct draw_info_s *)di; +/* TODO: see if this is really necessary */ -(void) drawString: (const char *)s at: (int)x:(int)y to: (int)x0:(int)y0:(int)x1:(int)y1:(unsigned char *)buf:(int)bpl @@ -39,7 +42,7 @@ copyright 2002 Alexander Malmberg deltas: (const float *)delta_data : (int)delta_size : (int)delta_flags; -(void) outlineString: (const char *)s - at: (float)x:(float)y + at: (float)x : (float)y gstate: (void *)func_param; +(void) initializeBackend; diff --git a/Source/art/ftfont.m b/Source/art/ftfont.m index 9cfd32d..e732f68 100644 --- a/Source/art/ftfont.m +++ b/Source/art/ftfont.m @@ -57,10 +57,10 @@ copyright 2002 Alexander Malmberg @interface FTFontInfo : GSFontInfo { - const char *filename; - FTC_ImageDesc imgd; + const char *filename; + FTC_ImageDesc imgd; - FTC_ImageDesc fallback; + FTC_ImageDesc fallback; } @end @@ -70,15 +70,15 @@ static NSMutableDictionary *fcfg_allFontFamilies; static NSMutableDictionary *fcfg_all_fonts; -static NSMutableSet *families_seen,*families_pending; +static NSMutableSet *families_seen, *families_pending; @interface FTFaceInfo : NSObject { @public - NSArray *files; - int weight; - unsigned int traits; + NSArray *files; + int weight; + unsigned int traits; } @end @@ -86,22 +86,21 @@ static NSMutableSet *families_seen,*families_pending; -(NSString *) description { - return [NSString stringWithFormat: - @"", - self,files,weight,traits]; + return [NSString stringWithFormat: @"", + self, files, weight, traits]; } @end -static int traits_from_string(NSString *s,unsigned int *traits,unsigned int *weight) +static int traits_from_string(NSString *s, unsigned int *traits, unsigned int *weight) { static struct { - NSString *str; - unsigned int trait; - int weight; -} suffix[]={ + NSString *str; + unsigned int trait; + int weight; +} suffix[] = { /* TODO */ {@"Normal" ,0 ,-1}, @@ -140,252 +139,251 @@ static struct {@"Condensed" ,NSCondensedFontMask ,-1}, {nil,0,-1} }; - int i; + int i; - *weight=5; - *traits=0; -// printf("do '%@'\n",s); - while ([s length]>0) + *weight = 5; + *traits = 0; +// printf("do '%@'\n", s); + while ([s length] > 0) + { +// printf(" got '%@'\n", s); + if ([s hasSuffix: @"-"]) { -// printf(" got '%@'\n",s); - if ([s hasSuffix: @"-"]) - { -// printf(" do -\n"); - s=[s substringToIndex: [s length]-1]; - continue; - } - for (i=0;suffix[i].str;i++) - { - if (![s hasSuffix: suffix[i].str]) - continue; -// printf(" found '%@'\n",suffix[i].str); - if (suffix[i].weight!=-1) - *weight=suffix[i].weight; - (*traits)|=suffix[i].trait; - s=[s substringToIndex: [s length]-[suffix[i].str length]]; - break; - } - if (!suffix[i].str) - break; +// printf(" do -\n"); + s = [s substringToIndex: [s length] - 1]; + continue; } -// printf("end up with '%@'\n",s); - return [s length]; + for (i = 0; suffix[i].str; i++) + { + if (![s hasSuffix: suffix[i].str]) + continue; +// printf(" found '%@'\n", suffix[i].str); + if (suffix[i].weight != -1) + *weight = suffix[i].weight; + (*traits) |= suffix[i].trait; + s = [s substringToIndex: [s length] - [suffix[i].str length]]; + break; + } + if (!suffix[i].str) + break; + } +// printf("end up with '%@'\n", s); + return [s length]; } -static void add_face(NSString *family,NSString *face,NSDictionary *d, - NSString *path,BOOL valid_face) +static void add_face(NSString *family, NSString *face, NSDictionary *d, + NSString *path, BOOL valid_face) { - FTFaceInfo *fi; - int weight; - unsigned int traits; - NSString *full_name; + FTFaceInfo *fi; + int weight; + unsigned int traits; + NSString *full_name; -// printf("'%@'-'%@' |%@|\n",family,face,d); +// printf("'%@'-'%@' |%@|\n", family, face, d); - if (valid_face) + if (valid_face) + { + int p; + if ([face isEqual: @"Normal"]) + full_name = family; + else + full_name = [NSString stringWithFormat: @"%@-%@", family, face]; + p = traits_from_string(face, &traits, &weight); +/* if (p > 0) + NSLog(@"failed to split: %@ to %i %04x %i", face, p, traits, weight); + else + NSLog(@"got %04x %i for %@", traits, weight, face);*/ + } + else + { + int p = traits_from_string(family, &traits, &weight); + full_name = family; + if (p > 0) { - int p; - if ([face isEqual: @"Normal"]) - full_name=family; - else - full_name=[NSString stringWithFormat: @"%@-%@",family,face]; - p=traits_from_string(face,&traits,&weight); -/* if (p>0) - NSLog(@"failed to split: %@ to %i %04x %i",face,p,traits,weight); - else - NSLog(@"got %04x %i for %@",traits,weight,face);*/ + face = [family substringFromIndex: p]; + family = [family substringToIndex: p]; + if ([face length] <= 0) + face = @"Normal"; + else + full_name = [NSString stringWithFormat: @"%@-%@", family, face]; } - else - { - int p=traits_from_string(family,&traits,&weight); - full_name=family; - if (p>0) - { - face=[family substringFromIndex: p]; - family=[family substringToIndex: p]; - if ([face length]<=0) - face=@"Normal"; - else - full_name=[NSString stringWithFormat: @"%@-%@",family,face]; - } - else - face=@"Normal"; + else + face = @"Normal"; - if ([families_seen member: family]) - { -// NSLog(@"#2 already seen %@",family); - return; - } - [families_pending addObject: family]; -// NSLog(@"split %@ to '%@' '%@' %04x %i",full_name,family,face,traits,weight); + if ([families_seen member: family]) + { +// NSLog(@"#2 already seen %@", family); + return; + } + [families_pending addObject: family]; +// NSLog(@"split %@ to '%@' '%@' %04x %i", full_name, family, face, traits, weight); + } + + if ([fcfg_allFontNames containsObject: full_name]) + return; + + fi = [[FTFaceInfo alloc] init]; + + { + NSArray *files = [d objectForKey: @"Files"]; + int i, c = [files count]; + + if (!files) + { + NSLog(@"No filename specified for font '%@'!", full_name); + DESTROY(fi); + return; } - if ([fcfg_allFontNames containsObject: full_name]) - return; - - fi=[[FTFaceInfo alloc] init]; - + fi->files = [[NSMutableArray alloc] init]; + for (i = 0; i < c; i++) { - NSArray *files=[d objectForKey: @"Files"]; - int i,c=[files count]; - - if (!files) - { - NSLog(@"No filename specified for font '%@'!", - full_name); - DESTROY(fi); - return; - } - - fi->files=[[NSMutableArray alloc] init]; - for (i=0;ifiles addObject: - [path stringByAppendingPathComponent: - [files objectAtIndex: i]]]; - } + [(NSMutableArray *)fi->files addObject: + [path stringByAppendingPathComponent: + [files objectAtIndex: i]]]; } + } - if ([d objectForKey: @"Weight"]) - weight=[[d objectForKey: @"Weight"] intValue]; - fi->weight=weight; + if ([d objectForKey: @"Weight"]) + weight = [[d objectForKey: @"Weight"] intValue]; + fi->weight = weight; - if ([d objectForKey: @"Traits"]) - traits=[[d objectForKey: @"Traits"] intValue]; - fi->traits=traits; + if ([d objectForKey: @"Traits"]) + traits = [[d objectForKey: @"Traits"] intValue]; + fi->traits = traits; - NSDebugLLog(@"ftfont",@"adding '%@' '%@'",full_name,fi); + NSDebugLLog(@"ftfont", @"adding '%@' '%@'", full_name, fi); -// printf("'%@' fi=|%@|\n",full_name,fi); - [fcfg_all_fonts setObject: fi forKey: full_name]; - [fcfg_allFontNames addObject: full_name]; +// printf("'%@' fi=|%@|\n", full_name, fi); + [fcfg_all_fonts setObject: fi forKey: full_name]; + [fcfg_allFontNames addObject: full_name]; + { + NSArray *a; + NSMutableArray *ma; + a = [NSArray arrayWithObjects: + full_name, + face, + [NSNumber numberWithInt: weight], + [NSNumber numberWithUnsignedInt: traits], + nil]; + ma = [fcfg_allFontFamilies objectForKey: family]; + if (!ma) { - NSArray *a; - NSMutableArray *ma; - a=[NSArray arrayWithObjects: - full_name, - face, - [NSNumber numberWithInt: weight], - [NSNumber numberWithUnsignedInt: traits], - nil]; - ma=[fcfg_allFontFamilies objectForKey: family]; - if (!ma) - { - ma=[[NSMutableArray alloc] init]; - [fcfg_allFontFamilies setObject: ma forKey: family]; - [ma release]; - } - [ma addObject: a]; + ma = [[NSMutableArray alloc] init]; + [fcfg_allFontFamilies setObject: ma forKey: family]; + [ma release]; } + [ma addObject: a]; + } - DESTROY(fi); + DESTROY(fi); } static void load_font_configuration(void) { - int i,j,c; - NSArray *paths; - NSString *path,*font_path; - NSFileManager *fm=[NSFileManager defaultManager]; - NSArray *files; - NSDictionary *d; + int i, j, c; + NSArray *paths; + NSString *path, *font_path; + NSFileManager *fm = [NSFileManager defaultManager]; + NSArray *files; + NSDictionary *d; - fcfg_all_fonts=[[NSMutableDictionary alloc] init]; - fcfg_allFontFamilies=[[NSMutableDictionary alloc] init]; - fcfg_allFontNames=[[NSMutableArray alloc] init]; + fcfg_all_fonts = [[NSMutableDictionary alloc] init]; + fcfg_allFontFamilies = [[NSMutableDictionary alloc] init]; + fcfg_allFontNames = [[NSMutableArray alloc] init]; - families_seen=[[NSMutableSet alloc] init]; - families_pending=[[NSMutableSet alloc] init]; + families_seen = [[NSMutableSet alloc] init]; + families_pending = [[NSMutableSet alloc] init]; - paths=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSAllDomainsMask,YES); - for (i=0;i<[paths count];i++) + paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES); + for (i = 0; i < [paths count]; i++) + { + path = [paths objectAtIndex: i]; + path = [path stringByAppendingPathComponent: @"Fonts"]; +// printf("try %@\n", path); + files = [fm directoryContentsAtPath: path]; + c = [files count]; + + for (j = 0; j < c; j++) { - path=[paths objectAtIndex: i]; - path=[path stringByAppendingPathComponent: @"Fonts"]; -// printf("try %@\n",path); - files=[fm directoryContentsAtPath: path]; - c=[files count]; + NSString *family, *face; + NSEnumerator *e; + NSDictionary *face_info; + NSString *font_info_path; - for (j=0;jfiles; - weight=font_entry->weight; - traits=font_entry->traits; + rfi = font_entry->files; + weight = font_entry->weight; + traits = font_entry->traits; - fontName=[name copy]; - memcpy(matrix,fmatrix,sizeof(matrix)); + fontName = [name copy]; + memcpy(matrix, fmatrix, sizeof(matrix)); - /* TODO: somehow make gnustep-gui send unicode our way. utf8? ugly, but it works */ - mostCompatibleStringEncoding=NSUTF8StringEncoding; - encodingScheme=@"iso10646-1"; + /* TODO: somehow make gnustep-gui send unicode our way. utf8? ugly, but it works */ + mostCompatibleStringEncoding = NSUTF8StringEncoding; + encodingScheme = @"iso10646-1"; - imgd.font.pix_width=matrix[0]; - imgd.font.pix_height=matrix[3]; - imgd.font.face_id=(FTC_FaceID)rfi; + imgd.font.pix_width = matrix[0]; + imgd.font.pix_height = matrix[3]; + imgd.font.face_id = (FTC_FaceID)rfi; - /* TODO: make this configurable */ -/* fallback=imgd; - fallback.font.face_id=@"/usr/local/share/fonts/truetype/CODE2000.TTF";*/ + /* TODO: make this configurable */ +/* fallback = imgd; + fallback.font.face_id = @"/usr/local/share/fonts/truetype/CODE2000.TTF";*/ - if (FTC_Manager_Lookup_Size(ftc_manager,&imgd.font,&face,&size)) - { - NSLog(@"FTC_Manager_Lookup_Size failed for '%@'!\n",name); - return self; - } + if (FTC_Manager_Lookup_Size(ftc_manager, &imgd.font, &face, &size)) + { + NSLog(@"FTC_Manager_Lookup_Size failed for '%@'!\n", name); + return self; + } -// xHeight=size->metrics.height/64.0; - ascender=fabs(size->metrics.ascender/64.0); - descender=fabs(size->metrics.descender/64.0); - xHeight=ascender+descender; /* TODO */ - maximumAdvancement=NSMakeSize((size->metrics.max_advance/64.0),ascender+descender); +// xHeight = size->metrics.height / 64.0; + ascender = fabs(size->metrics.ascender / 64.0); + descender = fabs(size->metrics.descender / 64.0); + xHeight = ascender + descender; /* TODO */ + maximumAdvancement = NSMakeSize((size->metrics.max_advance / 64.0), ascender + descender); - fontBBox=NSMakeRect(0,descender,maximumAdvancement.width,ascender+descender); - descender=-descender; + fontBBox = NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender); + descender = -descender; /* printf("h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n", - xHeight,ascender,descender, - maximumAdvancement.width,maximumAdvancement.height, - fontBBox.origin.x,fontBBox.origin.y, - fontBBox.size.width,fontBBox.size.height);*/ + xHeight, ascender, descender, + maximumAdvancement.width, maximumAdvancement.height, + fontBBox.origin.x, fontBBox.origin.y, + fontBBox.size.width, fontBBox.size.height);*/ - return self; + return self; } -(void) set { - NSLog(@"ignore -set method of font '%@'\n",fontName); + NSLog(@"ignore -set method of font '%@'\n", fontName); } @@ -527,381 +524,380 @@ extern void GSToUnicode(); -(void) drawString: (const char *)s - at: (int)x:(int)y - to: (int)x0:(int)y0:(int)x1:(int)y1:(unsigned char *)buf:(int)bpl - color:(unsigned char)r:(unsigned char)g:(unsigned char)b:(unsigned char)alpha + at: (int)x : (int)y + to: (int)x0 : (int)y0 : (int)x1 : (int)y1 : (unsigned char *)buf : (int)bpl + color:(unsigned char)r : (unsigned char)g : (unsigned char)b : (unsigned char)alpha transform: (NSAffineTransform *)transform drawinfo: (draw_info_t *)di { #if 0 - NSLog(@"ignoring drawString"); + NSLog(@"ignoring drawString"); #else - const unsigned char *c; - unsigned char ch; - unsigned int uch; + const unsigned char *c; + unsigned char ch; + unsigned int uch; - FTC_CMapDescRec cmap; - unsigned int glyph; + FTC_CMapDescRec cmap; + unsigned int glyph; - int use_sbit; + int use_sbit; - FTC_SBit sbit; - FTC_ImageDesc cur; + FTC_SBit sbit; + FTC_ImageDesc cur; - FT_Matrix ftmatrix; - FT_Vector ftdelta; + FT_Matrix ftmatrix; + FT_Vector ftdelta; - if (!alpha) - return; + if (!alpha) + return; - /* TODO: if we had guaranteed upper bounds on glyph image size we - could do some basic clipping here */ + /* TODO: if we had guaranteed upper bounds on glyph image size we + could do some basic clipping here */ - x1-=x0; - y1-=y0; - x-=x0; - y-=y0; + x1 -= x0; + y1 -= y0; + x -= x0; + y -= y0; /* NSLog(@"[%@ draw using matrix: (%g %g %g %g %g %g)]\n", self, - matrix[0],matrix[1],matrix[2], - matrix[3],matrix[4],matrix[5] + matrix[0], matrix[1], matrix[2], + matrix[3], matrix[4], matrix[5] );*/ - cur=imgd; - { - float xx,xy,yx,yy; + cur = imgd; + { + float xx, xy, yx, yy; - xx=matrix[0]*transform->matrix.m11+matrix[1]*transform->matrix.m21; - yx=matrix[0]*transform->matrix.m12+matrix[1]*transform->matrix.m22; - xy=matrix[2]*transform->matrix.m11+matrix[3]*transform->matrix.m21; - yy=matrix[2]*transform->matrix.m12+matrix[3]*transform->matrix.m22; + xx = matrix[0] * transform->matrix.m11 + matrix[1] * transform->matrix.m21; + yx = matrix[0] * transform->matrix.m12 + matrix[1] * transform->matrix.m22; + xy = matrix[2] * transform->matrix.m11 + matrix[3] * transform->matrix.m21; + yy = matrix[2] * transform->matrix.m12 + matrix[3] * transform->matrix.m22; - /* if we're drawing 'normal' text (unscaled, unrotated, reasonable - size), we can and should use the sbit cache */ - if (fabs(xx-((int)xx))<0.01 && fabs(yy-((int)yy))<0.01 && - fabs(xy)<0.01 && fabs(yx)<0.01 && - xx<72 && yy<72 && xx>0.5 && yy>0.5) - { - use_sbit=1; - cur.font.pix_width=xx; - cur.font.pix_height=yy; + /* if we're drawing 'normal' text (unscaled, unrotated, reasonable + size), we can and should use the sbit cache */ + if (fabs(xx - ((int)xx)) < 0.01 && fabs(yy - ((int)yy)) < 0.01 && + fabs(xy) < 0.01 && fabs(yx) < 0.01 && + xx < 72 && yy < 72 && xx > 0.5 && yy > 0.5) + { + use_sbit = 1; + cur.font.pix_width = xx; + cur.font.pix_height = yy; - if (cur.font.pix_width<16 && cur.font.pix_height<16 && - cur.font.pix_width>6 && cur.font.pix_height>6) - cur.type=ftc_image_mono; - else - cur.type=ftc_image_grays; + if (cur.font.pix_width < 16 && cur.font.pix_height < 16 && + cur.font.pix_width > 6 && cur.font.pix_height > 6) + cur.type = ftc_image_mono; + else + cur.type = ftc_image_grays; // imgd.type|=|ftc_image_flag_unhinted; /* TODO? when? */ + } + else + { + float f; + use_sbit = 0; - } - else - { - float f; - use_sbit=0; + f = fabs(xx * yy - xy * yx); + if (f > 1) + f = sqrt(f); + else + f = 1.0; - f=fabs(xx*yy-xy*yx); - if (f>1) - f=sqrt(f); - else - f=1.0; + f = (int)f; - f=(int)f; - - cur.font.pix_width=cur.font.pix_height=f; - ftmatrix.xx=xx/f*65536.0; - ftmatrix.xy=xy/f*65536.0; - ftmatrix.yx=yx/f*65536.0; - ftmatrix.yy=yy/f*65536.0; - ftdelta.x=ftdelta.y=0; - } - } + cur.font.pix_width = cur.font.pix_height = f; + ftmatrix.xx = xx / f * 65536.0; + ftmatrix.xy = xy / f * 65536.0; + ftmatrix.yx = yx / f * 65536.0; + ftmatrix.yy = yy / f * 65536.0; + ftdelta.x = ftdelta.y = 0; + } + } /* NSLog(@"drawString: '%s' at: %i:%i to: %i:%i:%i:%i:%p\n", - s,x,y,x0,y0,x1,y1,buf);*/ + s, x, y, x0, y0, x1, y1, buf);*/ - cmap.face_id=imgd.font.face_id; - cmap.u.encoding=ft_encoding_unicode; - cmap.type=FTC_CMAP_BY_ENCODING; + cmap.face_id = imgd.font.face_id; + cmap.u.encoding = ft_encoding_unicode; + cmap.type = FTC_CMAP_BY_ENCODING; - for (c=s;*c;c++) - { + for (c = s; *c; c++) + { /* TODO: do the same thing in outlineString:... */ - ch=*c; - if (ch<0x80) - { - uch=ch; - } - else if (ch<0xc0) - { - uch=0xfffd; - } - else if (ch<0xe0) - { -#define ADD_UTF_BYTE(shift,internal) \ - ch=*++c; \ - if (ch>=0x80 && ch<0xc0) \ - { \ - uch|=(ch&0x3f)<= 0x80 && ch < 0xc0) \ + { \ + uch |= (ch & 0x3f) << shift; \ + internal \ + } \ + else \ + { \ + uch = 0xfffd; \ + c--; \ + } - uch=(ch&0x1f)<<6; - ADD_UTF_BYTE(0,) - } - else if (ch<0xf0) - { - uch=(ch&0x0f)<<12; - ADD_UTF_BYTE(6,ADD_UTF_BYTE(0,)) - } - else if (ch<0xf8) - { - uch=(ch&0x07)<<18; - ADD_UTF_BYTE(12,ADD_UTF_BYTE(6,ADD_UTF_BYTE(0,))) - } - else if (ch<0xfc) - { - uch=(ch&0x03)<<24; - ADD_UTF_BYTE(18,ADD_UTF_BYTE(12,ADD_UTF_BYTE(6,ADD_UTF_BYTE(0,)))) - } - else if (ch<0xfe) - { - uch=(ch&0x01)<<30; - ADD_UTF_BYTE(24,ADD_UTF_BYTE(18,ADD_UTF_BYTE(12,ADD_UTF_BYTE(6,ADD_UTF_BYTE(0,))))) - } - else - uch=0xfffd; + uch = (ch & 0x1f) << 6; + ADD_UTF_BYTE(0, ) + } + else if (ch < 0xf0) + { + uch = (ch & 0x0f) << 12; + ADD_UTF_BYTE(6, ADD_UTF_BYTE(0, )) + } + else if (ch < 0xf8) + { + uch = (ch & 0x07) << 18; + ADD_UTF_BYTE(12, ADD_UTF_BYTE(6, ADD_UTF_BYTE(0, ))) + } + else if (ch < 0xfc) + { + uch = (ch & 0x03) << 24; + ADD_UTF_BYTE(18, ADD_UTF_BYTE(12, ADD_UTF_BYTE(6, ADD_UTF_BYTE(0, )))) + } + else if (ch < 0xfe) + { + uch = (ch & 0x01) << 30; + ADD_UTF_BYTE(24, ADD_UTF_BYTE(18, ADD_UTF_BYTE(12, ADD_UTF_BYTE(6, ADD_UTF_BYTE(0, ))))) + } + else + uch = 0xfffd; #undef ADD_UTF_BYTE - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,uch); - cur.font.face_id=imgd.font.face_id; - if (!glyph) + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, uch); + cur.font.face_id = imgd.font.face_id; + if (!glyph) + { + cmap.face_id = fallback.font.face_id; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, uch); + if (glyph) + cur.font.face_id = fallback.font.face_id; + cmap.face_id = imgd.font.face_id; + } + + if (use_sbit) + { + if (FTC_SBitCache_Lookup(ftc_sbitcache, &cur, glyph, &sbit, NULL)) + continue; + + if (!sbit->buffer) + { + x += sbit->xadvance; + continue; + } + + if (sbit->format == ft_pixel_mode_grays) + { + int gx = x + sbit->left, gy = y - sbit->top; + int sbpl = sbit->pitch; + int sx = sbit->width, sy = sbit->height; + const unsigned char *src = sbit->buffer; + unsigned char *dst = buf; + + if (gy < 0) { - cmap.face_id=fallback.font.face_id; - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,uch); - if (glyph) - cur.font.face_id=fallback.font.face_id; - cmap.face_id=imgd.font.face_id; + sy += gy; + src -= sbpl * gy; + gy = 0; + } + else if (gy > 0) + { + dst += bpl * gy; } - if (use_sbit) + sy += gy; + if (sy > y1) + sy = y1; + + if (gx < 0) { - if (FTC_SBitCache_Lookup(ftc_sbitcache,&cur,glyph,&sbit,NULL)) - continue; - - if (!sbit->buffer) - { - x+=sbit->xadvance; - continue; - } - - if (sbit->format==ft_pixel_mode_grays) - { - int gx=x+sbit->left,gy=y-sbit->top; - int sbpl=sbit->pitch; - int sx=sbit->width,sy=sbit->height; - const unsigned char *src=sbit->buffer; - unsigned char *dst=buf; - - if (gy<0) - { - sy+=gy; - src-=sbpl*gy; - gy=0; - } - else if (gy>0) - { - dst+=bpl*gy; - } - - sy+=gy; - if (sy>y1) - sy=y1; - - if (gx<0) - { - sx+=gx; - src-=gx; - gx=0; - } - else if (gx>0) - { - dst+=DI.bytes_per_pixel*gx; - } - - sx+=gx; - if (sx>x1) - sx=x1; - sx-=gx; - - if (sx>0) - { - if (alpha>=255) - for (;gyformat==ft_pixel_mode_mono) - { - int gx=x+sbit->left,gy=y-sbit->top; - int sbpl=sbit->pitch; - int sx=sbit->width,sy=sbit->height; - const unsigned char *src=sbit->buffer; - unsigned char *dst=buf; - int src_ofs=0; - - if (gy<0) - { - sy+=gy; - src-=sbpl*gy; - gy=0; - } - else if (gy>0) - { - dst+=bpl*gy; - } - - sy+=gy; - if (sy>y1) - sy=y1; - - if (gx<0) - { - sx+=gx; - src-=gx/8; - src_ofs=(-gx)&7; - gx=0; - } - else if (gx>0) - { - dst+=DI.bytes_per_pixel*gx; - } - - sx+=gx; - if (sx>x1) - sx=x1; - sx-=gx; - - if (sx>0) - { - if (alpha>=255) - for (;gyformat); - } - - x+=sbit->xadvance; + sx += gx; + src -= gx; + gx = 0; } - else + else if (gx > 0) { - FT_Face face; - FT_Glyph gl; - FT_BitmapGlyph gb; + dst += DI.bytes_per_pixel * gx; + } - if (FTC_Manager_Lookup_Size(ftc_manager,&cur.font,&face,0)) - continue; + sx += gx; + if (sx > x1) + sx = x1; + sx -= gx; - /* TODO: for rotations of 90, 180, 270, and integer - scales hinting might still be a good idea. */ - if (FT_Load_Glyph(face,glyph,FT_LOAD_NO_HINTING|FT_LOAD_NO_BITMAP)) - continue; + if (sx > 0) + { + if (alpha >= 255) + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_ALPHA_OPAQUE(dst, src, r, g, b, sx); + else + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_ALPHA(dst, src, r, g, b, alpha, sx); + } + } + else if (sbit->format == ft_pixel_mode_mono) + { + int gx = x + sbit->left, gy = y - sbit->top; + int sbpl = sbit->pitch; + int sx = sbit->width, sy = sbit->height; + const unsigned char *src = sbit->buffer; + unsigned char *dst = buf; + int src_ofs = 0; - if (FT_Get_Glyph(face->glyph,&gl)) - continue; + if (gy < 0) + { + sy += gy; + src -= sbpl * gy; + gy = 0; + } + else if (gy > 0) + { + dst += bpl * gy; + } - if (FT_Glyph_Transform(gl,&ftmatrix,&ftdelta)) - { - NSLog(@"glyph transformation failed!"); - continue; - } - if (FT_Glyph_To_Bitmap(&gl,ft_render_mode_normal,0,1)) - { - FT_Done_Glyph(gl); - continue; - } - gb=(FT_BitmapGlyph)gl; + sy += gy; + if (sy > y1) + sy = y1; + + if (gx < 0) + { + sx += gx; + src -= gx / 8; + src_ofs = (-gx) & 7; + gx = 0; + } + else if (gx > 0) + { + dst += DI.bytes_per_pixel * gx; + } + + sx += gx; + if (sx > x1) + sx = x1; + sx -= gx; + + if (sx > 0) + { + if (alpha >= 255) + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_MONO_OPAQUE(dst, src, src_ofs, r, g, b, sx); + else + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_MONO(dst, src, src_ofs, r, g, b, alpha, sx); + } + } + else + { + NSLog(@"unhandled font bitmap format %i", sbit->format); + } + + x += sbit->xadvance; + } + else + { + FT_Face face; + FT_Glyph gl; + FT_BitmapGlyph gb; + + if (FTC_Manager_Lookup_Size(ftc_manager, &cur.font, &face, 0)) + continue; + + /* TODO: for rotations of 90, 180, 270, and integer + scales hinting might still be a good idea. */ + if (FT_Load_Glyph(face, glyph, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP)) + continue; + + if (FT_Get_Glyph(face->glyph, &gl)) + continue; + + if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta)) + { + NSLog(@"glyph transformation failed!"); + continue; + } + if (FT_Glyph_To_Bitmap(&gl, ft_render_mode_normal, 0, 1)) + { + FT_Done_Glyph(gl); + continue; + } + gb = (FT_BitmapGlyph)gl; - if (gb->bitmap.pixel_mode==ft_pixel_mode_grays) - { - int gx=x+gb->left,gy=y-gb->top; - int sbpl=gb->bitmap.pitch; - int sx=gb->bitmap.width,sy=gb->bitmap.rows; - const unsigned char *src=gb->bitmap.buffer; - unsigned char *dst=buf; + if (gb->bitmap.pixel_mode == ft_pixel_mode_grays) + { + int gx = x + gb->left, gy = y - gb->top; + int sbpl = gb->bitmap.pitch; + int sx = gb->bitmap.width, sy = gb->bitmap.rows; + const unsigned char *src = gb->bitmap.buffer; + unsigned char *dst = buf; - if (gy<0) - { - sy+=gy; - src-=sbpl*gy; - gy=0; - } - else if (gy>0) - { - dst+=bpl*gy; - } + if (gy < 0) + { + sy += gy; + src -= sbpl * gy; + gy = 0; + } + else if (gy > 0) + { + dst += bpl * gy; + } - sy+=gy; - if (sy>y1) - sy=y1; + sy += gy; + if (sy > y1) + sy = y1; - if (gx<0) - { - sx+=gx; - src-=gx; - gx=0; - } - else if (gx>0) - { - dst+=DI.bytes_per_pixel*gx; - } + if (gx < 0) + { + sx += gx; + src -= gx; + gx = 0; + } + else if (gx > 0) + { + dst += DI.bytes_per_pixel * gx; + } - sx+=gx; - if (sx>x1) - sx=x1; - sx-=gx; + sx += gx; + if (sx > x1) + sx = x1; + sx -= gx; - if (sx>0) - { - if (alpha>=255) - for (;gy 0) + { + if (alpha >= 255) + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_ALPHA_OPAQUE(dst, src, r, g, b, sx); + else + for (; gy < sy; gy++, src += sbpl, dst += bpl) + RENDER_BLIT_ALPHA(dst, src, r, g, b, alpha, sx); + } + } /* TODO: will this case ever appear? */ /* else if (gb->bitmap.pixel_mode==ft_pixel_mode_mono)*/ - else - { - NSLog(@"unhandled font bitmap format %i",gb->bitmap.pixel_mode); - } + else + { + NSLog(@"unhandled font bitmap format %i", gb->bitmap.pixel_mode); + } - ftdelta.x+=gl->advance.x>>10; - ftdelta.y+=gl->advance.y>>10; + ftdelta.x += gl->advance.x >> 10; + ftdelta.y += gl->advance.y >> 10; - FT_Done_Glyph(gl); - } + FT_Done_Glyph(gl); } + } #endif } @@ -909,124 +905,124 @@ extern void GSToUnicode(); - (NSSize) advancementForGlyph: (NSGlyph)aGlyph { - FTC_CMapDescRec cmap; - unsigned int glyph; + FTC_CMapDescRec cmap; + unsigned int glyph; - FT_Glyph g; + FT_Glyph g; - FTC_ImageDesc *cur; + FTC_ImageDesc *cur; - cmap.face_id=imgd.font.face_id; - cmap.u.encoding=ft_encoding_unicode; - cmap.type=FTC_CMAP_BY_ENCODING; + cmap.face_id = imgd.font.face_id; + cmap.u.encoding = ft_encoding_unicode; + cmap.type = FTC_CMAP_BY_ENCODING; - cur=&imgd; - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,aGlyph); - if (!glyph) - { - cmap.face_id=fallback.font.face_id; - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,aGlyph); - if (glyph) - cur=&fallback; - } + cur = &imgd; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, aGlyph); + if (!glyph) + { + cmap.face_id = fallback.font.face_id; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, aGlyph); + if (glyph) + cur = &fallback; + } - if (FTC_ImageCache_Lookup(ftc_imagecache,cur,glyph,&g,NULL)) - { -// NSLog(@"advancementForGlyph: %04x -> %i not found\n",aGlyph,glyph); - return NSZeroSize; - } + if (FTC_ImageCache_Lookup(ftc_imagecache, cur, glyph, &g, NULL)) + { +// NSLog(@"advancementForGlyph: %04x -> %i not found\n", aGlyph, glyph); + return NSZeroSize; + } /* NSLog(@"advancementForGlyph: %04x -> %i %08xx%08x\n", - aGlyph,glyph,g->advance.x,g->advance.y);*/ + aGlyph, glyph, g->advance.x, g->advance.y);*/ - return NSMakeSize(g->advance.x/65536.0,g->advance.y/65536.0); + return NSMakeSize(g->advance.x / 65536.0, g->advance.y / 65536.0); } - (NSRect) boundingRectForGlyph: (NSGlyph)aGlyph { - FTC_CMapDescRec cmap; - FTC_ImageDesc *cur; - unsigned int glyph; - FT_BBox bbox; + FTC_CMapDescRec cmap; + FTC_ImageDesc *cur; + unsigned int glyph; + FT_BBox bbox; - FT_Glyph g; + FT_Glyph g; - cmap.face_id=imgd.font.face_id; - cmap.u.encoding=ft_encoding_unicode; - cmap.type=FTC_CMAP_BY_ENCODING; + cmap.face_id = imgd.font.face_id; + cmap.u.encoding = ft_encoding_unicode; + cmap.type = FTC_CMAP_BY_ENCODING; - cur=&imgd; - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,aGlyph); - if (!glyph) - { - cmap.face_id=fallback.font.face_id; - glyph=FTC_CMapCache_Lookup(ftc_cmapcache,&cmap,aGlyph); - if (glyph) - cur=&fallback; - } + cur = &imgd; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, aGlyph); + if (!glyph) + { + cmap.face_id = fallback.font.face_id; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, aGlyph); + if (glyph) + cur = &fallback; + } - if (FTC_ImageCache_Lookup(ftc_imagecache,cur,glyph,&g,NULL)) - { -// NSLog(@"boundingRectForGlyph: %04x -> %i\n",aGlyph,glyph); - return fontBBox; - } + if (FTC_ImageCache_Lookup(ftc_imagecache, cur, glyph, &g, NULL)) + { +// NSLog(@"boundingRectForGlyph: %04x -> %i\n", aGlyph, glyph); + return fontBBox; + } - FT_Glyph_Get_CBox(g,ft_glyph_bbox_gridfit,&bbox); + FT_Glyph_Get_CBox(g, ft_glyph_bbox_gridfit, &bbox); -/* printf("got cbox for %04x: %i,%i - %i,%i\n", - aGlyph,bbox.xMin,bbox.yMin,bbox.xMax,bbox.yMax);*/ +/* printf("got cbox for %04x: %i, %i - %i, %i\n", + aGlyph, bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax);*/ - return NSMakeRect(bbox.xMin/64.0,bbox.yMin/64.0, - (bbox.xMax-bbox.xMin)/64.0,(bbox.yMax-bbox.yMin)/64.0); + return NSMakeRect(bbox.xMin / 64.0, bbox.yMin / 64.0, + (bbox.xMax - bbox.xMin) / 64.0, (bbox.yMax - bbox.yMin) / 64.0); } - (float) widthOfString: (NSString*)string { - unichar ch; - int i,c=[string length]; - int total; + unichar ch; + int i, c = [string length]; + int total; - FTC_CMapDescRec cmap; - unsigned int glyph; + FTC_CMapDescRec cmap; + unsigned int glyph; - FTC_SBit sbit; + FTC_SBit sbit; - FTC_ImageDesc *cur; + FTC_ImageDesc *cur; - cmap.face_id=imgd.font.face_id; - cmap.u.encoding=ft_encoding_unicode; - cmap.type=FTC_CMAP_BY_ENCODING; + cmap.face_id = imgd.font.face_id; + cmap.u.encoding = ft_encoding_unicode; + cmap.type = FTC_CMAP_BY_ENCODING; - total=0; - for (i=0;ixadvance; - } - else - { - NSLog(@"non-sbit code not implemented"); - } + cmap.face_id = fallback.font.face_id; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, ch); + if (glyph) + cur = &fallback; + cmap.face_id = imgd.font.face_id; } - return total; + + /* TODO: shouldn't use sbit cache for this */ + if (1) + { + if (FTC_SBitCache_Lookup(ftc_sbitcache, cur, glyph, &sbit, NULL)) + continue; + + total += sbit->xadvance; + } + else + { + NSLog(@"non-sbit code not implemented"); + } + } + return total; } @@ -1127,60 +1123,60 @@ p(t)=q(t) */ -static int charpath_move_to(FT_Vector *to,void *user) +static int charpath_move_to(FT_Vector *to, void *user) { - GSGState *self=(GSGState *)user; - NSPoint d; - d.x=to->x/65536.0; - d.y=to->y/65536.0; - [self DPSclosepath]; /* TODO: this isn't completely correct */ - [self DPSmoveto: d.x:d.y]; - return 0; + GSGState *self = (GSGState *)user; + NSPoint d; + d.x = to->x / 65536.0; + d.y = to->y / 65536.0; + [self DPSclosepath]; /* TODO: this isn't completely correct */ + [self DPSmoveto: d.x:d.y]; + return 0; } -static int charpath_line_to(FT_Vector *to,void *user) +static int charpath_line_to(FT_Vector *to, void *user) { - GSGState *self=(GSGState *)user; - NSPoint d; - d.x=to->x/65536.0; - d.y=to->y/65536.0; - [self DPSlineto: d.x:d.y]; - return 0; + GSGState *self = (GSGState *)user; + NSPoint d; + d.x = to->x / 65536.0; + d.y = to->y / 65536.0; + [self DPSlineto: d.x:d.y]; + return 0; } -static int charpath_conic_to(FT_Vector *c1,FT_Vector *to,void *user) +static int charpath_conic_to(FT_Vector *c1, FT_Vector *to, void *user) { - GSGState *self=(GSGState *)user; - NSPoint a,b,c,d; - [self DPScurrentpoint: &a.x:&a.y]; - d.x=to->x/65536.0; - d.y=to->y/65536.0; - b.x=c1->x/65536.0; - b.y=c1->y/65536.0; - c.x=(b.x*2+d.x)/3.0; - c.y=(b.y*2+d.y)/3.0; - b.x=(b.x*2+a.x)/3.0; - b.y=(b.y*2+a.y)/3.0; - [self DPScurveto: b.x:b.y : c.x:c.y : d.x:d.y]; - return 0; + GSGState *self = (GSGState *)user; + NSPoint a, b, c, d; + [self DPScurrentpoint: &a.x:&a.y]; + d.x = to->x / 65536.0; + d.y = to->y / 65536.0; + b.x = c1->x / 65536.0; + b.y = c1->y / 65536.0; + c.x = (b.x * 2 + d.x) / 3.0; + c.y = (b.y * 2 + d.y) / 3.0; + b.x = (b.x * 2 + a.x) / 3.0; + b.y = (b.y * 2 + a.y) / 3.0; + [self DPScurveto: b.x:b.y : c.x:c.y : d.x:d.y]; + return 0; } -static int charpath_cubic_to(FT_Vector *c1,FT_Vector *c2,FT_Vector *to,void *user) +static int charpath_cubic_to(FT_Vector *c1, FT_Vector *c2, FT_Vector *to, void *user) { - GSGState *self=(GSGState *)user; - NSPoint b,c,d; - b.x=c1->x/65536.0; - b.y=c1->y/65536.0; - c.x=c2->x/65536.0; - c.y=c2->y/65536.0; - d.x=to->x/65536.0; - d.y=to->y/65536.0; - [self DPScurveto: b.x:b.y : c.x:c.y : d.x:d.y]; - return 0; + GSGState *self = (GSGState *)user; + NSPoint b, c, d; + b.x = c1->x / 65536.0; + b.y = c1->y / 65536.0; + c.x = c2->x / 65536.0; + c.y = c2->y / 65536.0; + d.x = to->x / 65536.0; + d.y = to->y / 65536.0; + [self DPScurveto: b.x:b.y : c.x:c.y : d.x:d.y]; + return 0; } -static FT_Outline_Funcs funcs={ +static FT_Outline_Funcs funcs = { move_to:charpath_move_to, line_to:charpath_line_to, conic_to:charpath_conic_to, @@ -1193,104 +1189,104 @@ delta:0, /* TODO: sometimes gets 'glyph transformation failed', probably need to add code to avoid loading bitmaps for glyphs */ -(void) outlineString: (const char *)s - at: (float)x:(float)y - gstate: (void *)func_param + at: (float)x : (float)y + gstate: (void *)func_param { - unichar *c; - int i; - FTC_CMapDescRec cmap; - unsigned int glyph; + unichar *c; + int i; + FTC_CMapDescRec cmap; + unsigned int glyph; - unichar *uch; - int ulen; + unichar *uch; + int ulen; - FTC_ImageDesc cur; + FTC_ImageDesc cur; - FT_Matrix ftmatrix; - FT_Vector ftdelta; + FT_Matrix ftmatrix; + FT_Vector ftdelta; - ftmatrix.xx=65536; - ftmatrix.xy=0; - ftmatrix.yx=0; - ftmatrix.yy=65536; - ftdelta.x=x*64.0; - ftdelta.y=y*64.0; + ftmatrix.xx = 65536; + ftmatrix.xy = 0; + ftmatrix.yx = 0; + ftmatrix.yy = 65536; + ftdelta.x = x * 64.0; + ftdelta.y = y * 64.0; - uch=NULL; - ulen=0; - GSToUnicode(&uch,&ulen,s,strlen(s),NSUTF8StringEncoding,NSDefaultMallocZone(),0); + uch = NULL; + ulen = 0; + GSToUnicode(&uch, &ulen, s, strlen(s), NSUTF8StringEncoding, NSDefaultMallocZone(), 0); - cur=imgd; + cur = imgd; - cmap.face_id=imgd.font.face_id; - cmap.u.encoding=ft_encoding_unicode; - cmap.type=FTC_CMAP_BY_ENCODING; + cmap.face_id = imgd.font.face_id; + cmap.u.encoding = ft_encoding_unicode; + cmap.type = FTC_CMAP_BY_ENCODING; - for (c=uch,i=0;iglyph,&gl)) - continue; - - if (FT_Glyph_Transform(gl,&ftmatrix,&ftdelta)) - { - NSLog(@"glyph transformation failed!"); - continue; - } - og=(FT_OutlineGlyph)gl; - - ftdelta.x+=gl->advance.x>>10; - ftdelta.y+=gl->advance.y>>10; - - FT_Outline_Decompose(&og->outline,&funcs,func_param); - - FT_Done_Glyph(gl); - + cmap.face_id = fallback.font.face_id; + glyph = FTC_CMapCache_Lookup(ftc_cmapcache, &cmap, *c); + if (glyph) + cur.font.face_id = fallback.font.face_id; + cmap.face_id = imgd.font.face_id; } - free(uch); + if (FTC_Manager_Lookup_Size(ftc_manager, &cur.font, &face, 0)) + continue; + if (FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT)) + continue; + + if (FT_Get_Glyph(face->glyph, &gl)) + continue; + + if (FT_Glyph_Transform(gl, &ftmatrix, &ftdelta)) + { + NSLog(@"glyph transformation failed!"); + continue; + } + og = (FT_OutlineGlyph)gl; + + ftdelta.x += gl->advance.x >> 10; + ftdelta.y += gl->advance.y >> 10; + + FT_Outline_Decompose(&og->outline, &funcs, func_param); + + FT_Done_Glyph(gl); + + } + + free(uch); } +(void) initializeBackend { - [GSFontEnumerator setDefaultClass: [FTFontEnumerator class]]; - [GSFontInfo setDefaultClass: [FTFontInfo class]]; + [GSFontEnumerator setDefaultClass: [FTFontEnumerator class]]; + [GSFontInfo setDefaultClass: [FTFontInfo class]]; - if (FT_Init_FreeType(&ft_library)) - NSLog(@"FT_Init_FreeType failed"); - if (FTC_Manager_New(ft_library,0,0,4096*24,ft_get_face,0,&ftc_manager)) - NSLog(@"FTC_Manager_New failed"); - if (FTC_SBitCache_New(ftc_manager,&ftc_sbitcache)) - NSLog(@"FTC_SBitCache_New failed"); - if (FTC_ImageCache_New(ftc_manager,&ftc_imagecache)) - NSLog(@"FTC_ImageCache_New failed"); - if (FTC_CMapCache_New(ftc_manager,&ftc_cmapcache)) - NSLog(@"FTC_CMapCache_New failed"); + if (FT_Init_FreeType(&ft_library)) + NSLog(@"FT_Init_FreeType failed"); + if (FTC_Manager_New(ft_library, 0, 0, 4096 * 24, ft_get_face, 0, &ftc_manager)) + NSLog(@"FTC_Manager_New failed"); + if (FTC_SBitCache_New(ftc_manager, &ftc_sbitcache)) + NSLog(@"FTC_SBitCache_New failed"); + if (FTC_ImageCache_New(ftc_manager, &ftc_imagecache)) + NSLog(@"FTC_ImageCache_New failed"); + if (FTC_CMapCache_New(ftc_manager, &ftc_cmapcache)) + NSLog(@"FTC_CMapCache_New failed"); - load_font_configuration(); + load_font_configuration(); }