X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Flyr_freetype%2Flyr_freetype.cpp;h=2da592a16e4827b31d79f95719247216693a8e8b;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=b721476025c3176b68a80bfab48c1201ddbe05c2;hpb=5f7270118adc2dfb2ee86d869e2de55d91b557e5;p=synfig.git diff --git a/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp b/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp index b721476..2da592a 100644 --- a/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp +++ b/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp @@ -7,7 +7,7 @@ ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** Copyright (c) 2006 Paul Wise -** Copyright (c) 2007 Chris Moore +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -39,8 +39,6 @@ #endif #include "lyr_freetype.h" - - #endif using namespace std; @@ -55,7 +53,6 @@ using namespace synfig; #define PANGO_STYLE_OBLIQUE (1) #define PANGO_STYLE_ITALIC (2) - #define WEIGHT_NORMAL (400) #define WEIGHT_BOLD (700) @@ -96,7 +93,7 @@ Layer_Freetype::Layer_Freetype() size=Vector(0.25,0.25); text=_("Text Layer"); color=Color::black(); - pos=Vector(0,0); + origin=Vector(0,0); orient=Vector(0.5,0.5); compress=1.0; vcompress=1.0; @@ -148,12 +145,14 @@ Layer_Freetype::new_font_(const synfig::String &font_fam_, int style, int weight //end evil hack if(font_fam=="arial black") + { #ifndef __APPLE__ - if(new_face("ariblk")) + if(new_face("ariblk")) return true; else #endif font_fam="sans serif"; + } if(font_fam=="sans serif" || font_fam=="arial") { @@ -228,7 +227,6 @@ Layer_Freetype::new_font_(const synfig::String &font_fam_, int style, int weight return true; } - if(font_fam=="sans serif" || font_fam=="luxi sans") { { @@ -240,7 +238,6 @@ Layer_Freetype::new_font_(const synfig::String &font_fam_, int style, int weight if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE) luxi+='i'; - if(new_face(luxi)) return true; } @@ -370,7 +367,6 @@ Layer_Freetype::new_face(const String &newfont) synfig::info(__FILE__":%d: \"%s\" -- ft_error=%d",__LINE__,newfont.c_str(),error); // Unable to generate fs_spec } - } #endif @@ -462,10 +458,10 @@ Layer_Freetype::set_param(const String & param, const ValueBase &value) IMPORT_PLUS(style,new_font(family,style,weight)); IMPORT_PLUS(size, if(old_version){size/=2.0;} needs_sync_=true ); IMPORT_PLUS(text,needs_sync_=true); - IMPORT_PLUS(pos,needs_sync_=true); - IMPORT_PLUS(color, { if (color.get_a() == 0) if (converted_blend_) { + IMPORT_PLUS(origin,needs_sync_=true); + IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) { set_blend_method(Color::BLEND_ALPHA_OVER); - color.set_a(1); } else transparent_color_ = true; }); + color.set_a(1); } else transparent_color_ = true; } }); IMPORT(invert); IMPORT_PLUS(orient,needs_sync_=true); IMPORT_PLUS(compress,needs_sync_=true); @@ -473,6 +469,8 @@ Layer_Freetype::set_param(const String & param, const ValueBase &value) IMPORT_PLUS(use_kerning,needs_sync_=true); IMPORT_PLUS(grid_fit,needs_sync_=true); + IMPORT_AS(origin,"pos"); + return Layer_Composite::set_param(param,value); } @@ -486,7 +484,7 @@ Layer_Freetype::get_param(const String& param)const EXPORT(size); EXPORT(text); EXPORT(color); - EXPORT(pos); + EXPORT(origin); EXPORT(orient); EXPORT(compress); EXPORT(vcompress); @@ -553,7 +551,7 @@ Layer_Freetype::get_param_vocab(void)const .set_local_name(_("Size")) .set_description(_("Size of the text")) .set_hint("size") - .set_origin("pos") + .set_origin("origin") .set_scalar(1) ); @@ -563,8 +561,8 @@ Layer_Freetype::get_param_vocab(void)const .set_invisible_duck() ); - ret.push_back(ParamDesc("pos") - .set_local_name(_("Position")) + ret.push_back(ParamDesc("origin") + .set_local_name(_("Origin")) .set_description(_("Text Position")) ); @@ -595,10 +593,15 @@ void Layer_Freetype::sync() { needs_sync_=false; +} - - - +inline Color +Layer_Freetype::color_func(const Point &point_ __attribute__ ((unused)), int quality __attribute__ ((unused)), float supersample __attribute__ ((unused)))const +{ + if (invert) + return color; + else + return Color::alpha(); } Color @@ -607,9 +610,15 @@ Layer_Freetype::get_color(Context context, const synfig::Point &pos)const if(needs_sync_) const_cast(this)->sync(); + const Color color(color_func(pos,0)); + if(!face) return context.get_color(pos); - return context.get_color(pos); + + if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + return color; + else + return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method()); } bool @@ -620,9 +629,6 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, if(needs_sync_) const_cast(this)->sync(); - - - int error; Vector size(Layer_Freetype::size*2); @@ -653,8 +659,8 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, int w=abs(round_to_int(size[0]*pw)); int h=abs(round_to_int(size[1]*ph)); - //int bx=(int)((pos[0]-renddesc.get_tl()[0])*pw*64+0.5); - //int by=(int)((pos[1]-renddesc.get_tl()[1])*ph*64+0.5); + //int bx=(int)((origin[0]-renddesc.get_tl()[0])*pw*64+0.5); + //int by=(int)((origin[1]-renddesc.get_tl()[1])*ph*64+0.5); int bx=0; int by=0; @@ -804,7 +810,6 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, } - //float string_height; //string_height=(((lines.size()-1)*face->size->metrics.height+lines.back().actual_height())); @@ -845,63 +850,62 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, } { - std::list::iterator iter; - int curr_line; - for(curr_line=0,iter=lines.begin();iter!=lines.end();++iter,curr_line++) - { - bx=round_to_int((pos[0]-renddesc.get_tl()[0])*pw*CHAR_RESOLUTION-orient[0]*iter->width); - // I've no idea why 1.5, but it kind of works. Otherwise, - // rendering to .bmp (which renders from bottom to top, due to - // the .bmp format describing the image from bottom to top, - // renders text in the wrong place. - by=round_to_int((pos[1]-renddesc.get_tl()[1])*ph*CHAR_RESOLUTION + - (1.0-orient[1])*string_height-line_height*curr_line + - ((ph>0) ? line_height/1.5 : 0)); - - //by=round_to_int(vcompress*((pos[1]-renddesc.get_tl()[1])*ph*64+(1.0-orient[1])*string_height-face->size->metrics.height*curr_line)); - //synfig::info("curr_line=%d, bx=%d, by=%d",curr_line,bx,by); - - std::vector::iterator iter2; - for(iter2=iter->glyph_table.begin();iter2!=iter->glyph_table.end();++iter2) + std::list::iterator iter; + int curr_line; + for(curr_line=0,iter=lines.begin();iter!=lines.end();++iter,curr_line++) { - FT_Glyph image(iter2->glyph); - FT_Vector pen; - FT_BitmapGlyph bit; + bx=round_to_int((origin[0]-renddesc.get_tl()[0])*pw*CHAR_RESOLUTION-orient[0]*iter->width); + // I've no idea why 1.5, but it kind of works. Otherwise, + // rendering to .bmp (which renders from bottom to top, due to + // the .bmp format describing the image from bottom to top, + // renders text in the wrong place. + by=round_to_int((origin[1]-renddesc.get_tl()[1])*ph*CHAR_RESOLUTION + + (1.0-orient[1])*string_height-line_height*curr_line + + ((ph>0) ? line_height/1.5 : 0)); + + //by=round_to_int(vcompress*((origin[1]-renddesc.get_tl()[1])*ph*64+(1.0-orient[1])*string_height-face->size->metrics.height*curr_line)); + //synfig::info("curr_line=%d, bx=%d, by=%d",curr_line,bx,by); + + std::vector::iterator iter2; + for(iter2=iter->glyph_table.begin();iter2!=iter->glyph_table.end();++iter2) + { + FT_Glyph image(iter2->glyph); + FT_Vector pen; + FT_BitmapGlyph bit; - pen.x = bx + iter2->pos.x; - pen.y = by + iter2->pos.y; + pen.x = bx + iter2->pos.x; + pen.y = by + iter2->pos.y; - //synfig::info("GLYPH: line %d, pen.x=%d, pen,y=%d",curr_line,(pen.x+32)>>6,(pen.y+32)>>6); + //synfig::info("GLYPH: line %d, pen.x=%d, pen,y=%d",curr_line,(pen.x+32)>>6,(pen.y+32)>>6); - error = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal,0/*&pen*/, 1 ); - if(error) { FT_Done_Glyph( image ); continue; } + error = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal,0/*&pen*/, 1 ); + if(error) { FT_Done_Glyph( image ); continue; } - bit = (FT_BitmapGlyph)image; + bit = (FT_BitmapGlyph)image; - for(v=0;vbitmap.rows;v++) - for(u=0;ubitmap.width;u++) - { - int x=u+((pen.x+32)>>6)+ bit->left; - int y=((pen.y+32)>>6) + (bit->top - v) * ((ph<0) ? -1 : 1); - if( y>=0 && - x>=0 && - yget_h() && - xget_w()) + for(v=0;vbitmap.rows;v++) + for(u=0;ubitmap.width;u++) { - float myamount=(float)bit->bitmap.buffer[v*bit->bitmap.pitch+u]/255.0f; - if(invert) - myamount=1.0f-myamount; - (*surface)[y][x]=Color::blend(color,(*src_surface)[y][x],myamount*get_amount(),get_blend_method()); + int x=u+((pen.x+32)>>6)+ bit->left; + int y=((pen.y+32)>>6) + (bit->top - v) * ((ph<0) ? -1 : 1); + if( y>=0 && + x>=0 && + yget_h() && + xget_w()) + { + float myamount=(float)bit->bitmap.buffer[v*bit->bitmap.pitch+u]/255.0f; + if(invert) + myamount=1.0f-myamount; + (*surface)[y][x]=Color::blend(color,(*src_surface)[y][x],myamount*get_amount(),get_blend_method()); + } } - } - FT_Done_Glyph( image ); + FT_Done_Glyph( image ); + } + //iter->clear_and_free(); } - //iter->clear_and_free(); - } } - return true; }