X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Flyr_freetype%2Flyr_freetype.cpp;h=23e9580047367054162ffd80152ab05b1f0258f5;hb=a93e9a8c03f239eb067331491d3a276c696b27ea;hp=875c0ce834bcc81c390507beb6d4ea5eef4e13f2;hpb=9b87e7fe2cab74dc078185c08bf8c51f7ec8c32a;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 875c0ce..23e9580 100644 --- a/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp +++ b/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp @@ -1,6 +1,6 @@ /* === S Y N F I G ========================================================= */ /*! \file lyr_freetype.cpp -** \brief Template Header +** \brief Implementation of the "Text" layer ** ** $Id$ ** @@ -63,8 +63,8 @@ using namespace synfig; SYNFIG_LAYER_INIT(Layer_Freetype); SYNFIG_LAYER_SET_NAME(Layer_Freetype,"text"); -SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Freetype,_("Text")); -SYNFIG_LAYER_SET_CATEGORY(Layer_Freetype,_("Other")); +SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Freetype,N_("Text")); +SYNFIG_LAYER_SET_CATEGORY(Layer_Freetype,N_("Other")); SYNFIG_LAYER_SET_VERSION(Layer_Freetype,"0.2"); SYNFIG_LAYER_SET_CVS_ID(Layer_Freetype,"$Id$"); @@ -148,12 +148,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") { @@ -381,7 +383,7 @@ Layer_Freetype::new_face(const String &newfont) FcResult result; if( !FcInit() ) { - synfig::warning("Layer_Freetype: fontconfig: %s",_("unable to initialise")); + synfig::warning("Layer_Freetype: fontconfig: %s",_("unable to initialize")); error = 1; } else { FcPattern* pat = FcNameParse((FcChar8 *) newfont.c_str()); @@ -463,7 +465,9 @@ Layer_Freetype::set_param(const String & param, const ValueBase &value) 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(color); + 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; } }); IMPORT(invert); IMPORT_PLUS(orient,needs_sync_=true); IMPORT_PLUS(compress,needs_sync_=true); @@ -697,6 +701,9 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, -- ** -- CREATE GLYPHS ------------------------------------------------------- */ + mbstate_t ps; + memset(&ps, 0, sizeof(ps)); + lines.push_front(TextLine()); string::const_iterator iter; for (iter=text.begin(); iter!=text.end(); ++iter) @@ -716,7 +723,29 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, glyph_index = FT_Get_Char_Index( face, ' ' ); } else - glyph_index = FT_Get_Char_Index( face, *iter ); + { + wchar_t wc; + size_t converted = mbrtowc(&wc, &(*iter), text.end() - iter, &ps); + + if(converted == (size_t)(-1)) + { + synfig::warning("Layer_Freetype: multibyte: %s", + _("Invalid multibyte sequence - is the locale set?\n")); + continue; + } + + if(converted == (size_t)(-2)) + { + synfig::warning("Layer_Freetype: multibyte: %s", + _("Can't parse multibyte character.\n")); + continue; + } + + glyph_index = FT_Get_Char_Index( face, wc ); + + if(converted > 1) + iter += converted - 1; + } // retrieve kerning distance and move pen position if ( FT_HAS_KERNING(face) && use_kerning && previous && glyph_index ) @@ -823,13 +852,13 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, 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); - by=round_to_int((pos[1]-renddesc.get_tl()[1])*ph*CHAR_RESOLUTION+(1.0-orient[1])*string_height-line_height*curr_line); - // 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. - if (ph>0) by += line_height/1.5; + 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);