1 /* === S Y N F I G ========================================================= */
2 /*! \file lyr_freetype.cpp
3 ** \brief Implementation of the "Text" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2006 Paul Wise
10 ** Copyright (c) 2007, 2008 Chris Moore
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 ** === N O T E S ===========================================================
25 ** ========================================================================= */
27 /* === H E A D E R S ======================================================= */
37 #ifdef WITH_FONTCONFIG
38 #include <fontconfig/fontconfig.h>
41 #include "lyr_freetype.h"
46 using namespace synfig;
48 /* === M A C R O S ========================================================= */
50 #define MAX_GLYPHS 2000
52 #define PANGO_STYLE_NORMAL (0)
53 #define PANGO_STYLE_OBLIQUE (1)
54 #define PANGO_STYLE_ITALIC (2)
56 #define WEIGHT_NORMAL (400)
57 #define WEIGHT_BOLD (700)
59 /* === G L O B A L S ======================================================= */
61 SYNFIG_LAYER_INIT(Layer_Freetype);
62 SYNFIG_LAYER_SET_NAME(Layer_Freetype,"text");
63 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Freetype,N_("Text"));
64 SYNFIG_LAYER_SET_CATEGORY(Layer_Freetype,N_("Other"));
65 SYNFIG_LAYER_SET_VERSION(Layer_Freetype,"0.2");
66 SYNFIG_LAYER_SET_CVS_ID(Layer_Freetype,"$Id$");
68 /* === P R O C E D U R E S ================================================= */
72 if(glyph)FT_Done_Glyph(glyph);
76 TextLine::clear_and_free()
78 std::vector<Glyph>::iterator iter;
79 for(iter=glyph_table.begin();iter!=glyph_table.end();++iter)
81 if(iter->glyph)FT_Done_Glyph(iter->glyph);
87 /* === M E T H O D S ======================================================= */
89 Layer_Freetype::Layer_Freetype()
93 size=Vector(0.25,0.25);
97 orient=Vector(0.5,0.5);
100 weight=WEIGHT_NORMAL;
101 style=PANGO_STYLE_NORMAL;
106 set_blend_method(Color::BLEND_COMPOSITE);
109 new_font(family,style,weight);
112 Layer::Vocab voc(get_param_vocab());
113 Layer::fill_static(voc);
116 Layer_Freetype::~Layer_Freetype()
123 Layer_Freetype::new_font(const synfig::String &family, int style, int weight)
126 !new_font_(family,style,weight) &&
127 !new_font_(family,style,WEIGHT_NORMAL) &&
128 !new_font_(family,PANGO_STYLE_NORMAL,weight) &&
129 !new_font_(family,PANGO_STYLE_NORMAL,WEIGHT_NORMAL) &&
130 !new_font_("sans serif",style,weight) &&
131 !new_font_("sans serif",style,WEIGHT_NORMAL) &&
132 !new_font_("sans serif",PANGO_STYLE_NORMAL,weight)
134 new_font_("sans serif",PANGO_STYLE_NORMAL,WEIGHT_NORMAL);
138 Layer_Freetype::new_font_(const synfig::String &font_fam_, int style, int weight)
140 synfig::String font_fam(font_fam_);
142 if(new_face(font_fam_))
146 for(unsigned int i=0;i<font_fam.size();i++)font_fam[i]=tolower(font_fam[i]);
149 if(font_fam=="arial black")
152 if(new_face("ariblk"))
156 font_fam="sans serif";
159 if(font_fam=="sans serif" || font_fam=="arial")
161 String arial("arial");
162 if(weight>WEIGHT_NORMAL)
164 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
167 if(weight>WEIGHT_NORMAL) arial+='d';
172 if(new_face("Helvetica RO"))
177 if(font_fam=="comic" || font_fam=="comic sans")
179 String filename("comic");
180 if(weight>WEIGHT_NORMAL)
182 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
184 else if(weight>WEIGHT_NORMAL) filename+='d';
186 if(new_face(filename))
190 if(font_fam=="courier" || font_fam=="courier new")
192 String filename("cour");
193 if(weight>WEIGHT_NORMAL)
195 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
197 else if(weight>WEIGHT_NORMAL) filename+='d';
199 if(new_face(filename))
203 if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman")
205 String filename("times");
206 if(weight>WEIGHT_NORMAL)
208 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
210 else if(weight>WEIGHT_NORMAL) filename+='d';
212 if(new_face(filename))
216 if(font_fam=="trebuchet")
218 String filename("trebuc");
219 if(weight>WEIGHT_NORMAL)
221 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
224 if(weight<=WEIGHT_NORMAL) filename+='t';
226 else if(weight>WEIGHT_NORMAL) filename+='d';
228 if(new_face(filename))
232 if(font_fam=="sans serif" || font_fam=="luxi sans")
235 String luxi("luxis");
236 if(weight>WEIGHT_NORMAL)
240 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
246 if(new_face("arial"))
248 if(new_face("Arial"))
251 if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman" || font_fam=="luxi serif")
254 String luxi("luxir");
255 if(weight>WEIGHT_NORMAL)
259 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
265 if(new_face("Times New Roman"))
267 if(new_face("Times"))
273 String luxi("luxim");
274 if(weight>WEIGHT_NORMAL)
278 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
285 if(new_face("Times New Roman"))
287 if(new_face("Times"))
291 return new_face(font_fam_) || new_face(font_fam);
296 #ifdef USE_MAC_FT_FUNCS
297 void fss2path(char *path, FSSpec *fss)
299 int l; //fss->name contains name of last item in path
300 for(l=0; l<(fss->name[0]); l++) path[l] = fss->name[l + 1];
303 if(fss->parID != fsRtParID) //path is more than just a volume name
308 pb.dirInfo.ioNamePtr = fss->name;
309 pb.dirInfo.ioVRefNum = fss->vRefNum;
310 pb.dirInfo.ioDrParID = fss->parID;
313 pb.dirInfo.ioFDirIndex = -1; //get parent directory name
314 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
315 if(PBGetCatInfoSync(&pb) != noErr) break;
317 len = fss->name[0] + 1;
318 for(i=l; i>=0; i--) path[i + len] = path[i];
319 for(i=1; i<len; i++) path[i - 1] = fss->name[i]; //add to start of path
322 } while(pb.dirInfo.ioDrDirID != fsRtDirID); //while more directory levels
328 Layer_Freetype::new_face(const String &newfont)
331 FT_Long face_index=0;
333 // If we are already loaded, don't bother reloading.
334 if(face && font==newfont)
343 error=FT_New_Face(ft_library,newfont.c_str(),face_index,&face);
344 if(error)error=FT_New_Face(ft_library,(newfont+".ttf").c_str(),face_index,&face);
348 if(error)error=FT_New_Face(ft_library,(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPARATOR+newfont).c_str(),face_index,&face);
349 if(error)error=FT_New_Face(ft_library,(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPARATOR+newfont+".ttf").c_str(),face_index,&face);
352 #ifdef USE_MAC_FT_FUNCS
356 error=FT_GetFile_From_Mac_Name(newfont.c_str(),&fs_spec,&face_index);
360 fss2path(filename,&fs_spec);
361 //FSSpecToNativePathName(fs_spec,filename,sizeof(filename)-1, 0);
363 error=FT_New_Face(ft_library, filename, face_index,&face);
364 //error=FT_New_Face_From_FSSpec(ft_library, &fs_spec, face_index,&face);
365 synfig::info(__FILE__":%d: \"%s\" (%s) -- ft_error=%d",__LINE__,newfont.c_str(),filename,error);
369 synfig::info(__FILE__":%d: \"%s\" -- ft_error=%d",__LINE__,newfont.c_str(),error);
370 // Unable to generate fs_spec
375 #ifdef WITH_FONTCONFIG
382 synfig::warning("Layer_Freetype: fontconfig: %s",_("unable to initialize"));
385 FcPattern* pat = FcNameParse((FcChar8 *) newfont.c_str());
386 FcConfigSubstitute(0, pat, FcMatchPattern);
387 FcDefaultSubstitute(pat);
389 fs = FcFontSetCreate();
390 match = FcFontMatch(0, pat, &result);
392 FcFontSetAdd(fs, match);
394 FcPatternDestroy(pat);
397 if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch )
398 error=FT_New_Face(ft_library,(const char*)file,face_index,&face);
399 FcFontSetDestroy(fs);
401 synfig::warning("Layer_Freetype: fontconfig: %s",_("empty font set"));
407 if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont).c_str(),face_index,&face);
408 if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont+".ttf").c_str(),face_index,&face);
412 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont).c_str(),face_index,&face);
413 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face);
414 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face);
416 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont).c_str(),face_index,&face);
417 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face);
418 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face);
421 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont).c_str(),face_index,&face);
422 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont+".ttf").c_str(),face_index,&face);
424 if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont).c_str(),face_index,&face);
425 if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face);
427 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont).c_str(),face_index,&face);
428 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont+".ttf").c_str(),face_index,&face);
430 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont).c_str(),face_index,&face);
431 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face);
436 //synfig::error(strprintf("Layer_Freetype:%s (err=%d)",_("Unable to open face."),error));
447 Layer_Freetype::set_param(const String & param, const ValueBase &value)
449 Mutex::Lock lock(mutex);
451 if(param=="font" && value.same_type_as(font))
453 new_font(etl::basename(value.get(font)),style,weight);
454 family=etl::basename(value.get(font));
458 IMPORT_PLUS(family,new_font(family,style,weight));
459 IMPORT_PLUS(weight,new_font(family,style,weight));
460 IMPORT_PLUS(style,new_font(family,style,weight));
461 IMPORT_PLUS(size, if(old_version){size/=2.0;} needs_sync_=true );
462 IMPORT_PLUS(text,needs_sync_=true);
463 IMPORT_PLUS(origin,needs_sync_=true);
464 IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
465 set_blend_method(Color::BLEND_ALPHA_OVER);
466 color.set_a(1); } else transparent_color_ = true; } });
468 IMPORT_PLUS(orient,needs_sync_=true);
469 IMPORT_PLUS(compress,needs_sync_=true);
470 IMPORT_PLUS(vcompress,needs_sync_=true);
471 IMPORT_PLUS(use_kerning,needs_sync_=true);
472 IMPORT_PLUS(grid_fit,needs_sync_=true);
474 IMPORT_AS(origin,"pos");
476 return Layer_Composite::set_param(param,value);
480 Layer_Freetype::get_param(const String& param)const
500 return Layer_Composite::get_param(param);
504 Layer_Freetype::get_param_vocab(void)const
506 Layer::Vocab ret(Layer_Composite::get_param_vocab());
508 ret.push_back(ParamDesc("text")
509 .set_local_name(_("Text"))
510 .set_description(_("Text to Render"))
511 .set_hint("paragraph")
514 ret.push_back(ParamDesc("color")
515 .set_local_name(_("Color"))
516 .set_description(_("Color of the text"))
519 ret.push_back(ParamDesc("family")
520 .set_local_name(_("Font Family"))
521 .set_hint("font_family")
524 ret.push_back(ParamDesc("style")
525 .set_local_name(_("Style"))
527 .add_enum_value(PANGO_STYLE_NORMAL, "normal" ,_("Normal"))
528 .add_enum_value(PANGO_STYLE_OBLIQUE, "oblique" ,_("Oblique"))
529 .add_enum_value(PANGO_STYLE_ITALIC, "italic" ,_("Italic"))
532 ret.push_back(ParamDesc("weight")
533 .set_local_name(_("Weight"))
535 .add_enum_value(200, "ultralight" ,_("Ultralight"))
536 .add_enum_value(300, "light" ,_("light"))
537 .add_enum_value(400, "normal" ,_("Normal"))
538 .add_enum_value(700, "bold" ,_("Bold"))
539 .add_enum_value(800, "ultrabold" ,_("Ultrabold"))
540 .add_enum_value(900, "heavy" ,_("Heavy"))
542 ret.push_back(ParamDesc("compress")
543 .set_local_name(_("Horizontal Spacing"))
544 .set_description(_("Describes how close glyphs are horizontally"))
547 ret.push_back(ParamDesc("vcompress")
548 .set_local_name(_("Vertical Spacing"))
549 .set_description(_("Describes how close lines of text are vertically"))
552 ret.push_back(ParamDesc("size")
553 .set_local_name(_("Size"))
554 .set_description(_("Size of the text"))
556 .set_origin("origin")
560 ret.push_back(ParamDesc("orient")
561 .set_local_name(_("Orientation"))
562 .set_description(_("Text Orientation"))
563 .set_invisible_duck()
566 ret.push_back(ParamDesc("origin")
567 .set_local_name(_("Origin"))
568 .set_description(_("Text Position"))
571 ret.push_back(ParamDesc("font")
572 .set_local_name(_("Font"))
573 .set_description(_("Filename of the font to use"))
574 .set_hint("filename")
579 ret.push_back(ParamDesc("use_kerning")
580 .set_local_name(_("Kerning"))
581 .set_description(_("Enables/Disables font kerning (If the font supports it)"))
584 ret.push_back(ParamDesc("grid_fit")
585 .set_local_name(_("Sharpen Edges"))
586 .set_description(_("Turn this off if you are going to be animating the text"))
588 ret.push_back(ParamDesc("invert")
589 .set_local_name(_("Invert"))
595 Layer_Freetype::sync()
601 Layer_Freetype::color_func(const Point &point_ __attribute__ ((unused)), int quality __attribute__ ((unused)), float supersample __attribute__ ((unused)))const
606 return Color::alpha();
610 Layer_Freetype::get_color(Context context, const synfig::Point &pos)const
613 const_cast<Layer_Freetype*>(this)->sync();
615 const Color color(color_func(pos,0));
618 return context.get_color(pos);
620 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
623 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
627 Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
629 static synfig::RecMutex freetype_mutex;
632 const_cast<Layer_Freetype*>(this)->sync();
635 Vector size(Layer_Freetype::size*2);
637 if(!context.accelerated_render(surface,quality,renddesc,cb))
640 if(is_disabled() || text.empty())
643 // If there is no font loaded, just bail
646 if(cb)cb->warning(string("Layer_Freetype:")+_("No face loaded, no text will be rendered."));
650 String text(Layer_Freetype::text);
651 if(text=="@_FILENAME_@" && get_canvas() && !get_canvas()->get_file_name().empty())
653 text=basename(get_canvas()->get_file_name());
656 // Width and Height of a pixel
657 Vector::value_type pw=renddesc.get_w()/(renddesc.get_br()[0]-renddesc.get_tl()[0]);
658 Vector::value_type ph=renddesc.get_h()/(renddesc.get_br()[1]-renddesc.get_tl()[1]);
660 // Calculate character width and height
661 int w=abs(round_to_int(size[0]*pw));
662 int h=abs(round_to_int(size[1]*ph));
664 //int bx=(int)((origin[0]-renddesc.get_tl()[0])*pw*64+0.5);
665 //int by=(int)((origin[1]-renddesc.get_tl()[1])*ph*64+0.5);
669 // If the font is the size of a pixel, don't bother rendering any text
672 if(cb)cb->warning(string("Layer_Freetype:")+_("Text too small, no text will be rendered."));
676 synfig::RecMutex::Lock lock(freetype_mutex);
678 #define CHAR_RESOLUTION (64)
679 error = FT_Set_Char_Size(
680 face, // handle to face object
681 (int)CHAR_RESOLUTION, // char_width in 1/64th of points
682 (int)CHAR_RESOLUTION, // char_height in 1/64th of points
683 round_to_int(abs(size[0]*pw*CHAR_RESOLUTION)), // horizontal device resolution
684 round_to_int(abs(size[1]*ph*CHAR_RESOLUTION)) ); // vertical device resolution
686 // Here is where we can compensate for the
687 // error in freetype's rendering engine.
688 const float xerror(abs(size[0]*pw)/(float)face->size->metrics.x_ppem/1.13f/0.996);
689 const float yerror(abs(size[1]*ph)/(float)face->size->metrics.y_ppem/1.13f/0.996);
690 //synfig::info("xerror=%f, yerror=%f",xerror,yerror);
691 const float compress(Layer_Freetype::compress*xerror);
692 const float vcompress(Layer_Freetype::vcompress*yerror);
696 if(cb)cb->warning(string("Layer_Freetype:")+_("Unable to set face size.")+strprintf(" (err=%d)",error));
699 FT_GlyphSlot slot = face->glyph; // a small shortcut
700 FT_UInt glyph_index(0);
704 std::list<TextLine> lines;
707 -- ** -- CREATE GLYPHS -------------------------------------------------------
711 memset(&ps, 0, sizeof(ps));
713 lines.push_front(TextLine());
714 string::const_iterator iter;
715 for (iter=text.begin(); iter!=text.end(); ++iter)
720 lines.push_front(TextLine());
729 glyph_index = FT_Get_Char_Index( face, ' ' );
734 size_t converted = mbrtowc(&wc, &(*iter), text.end() - iter, &ps);
736 if(converted == (size_t)(-1))
738 synfig::warning("Layer_Freetype: multibyte: %s",
739 _("Invalid multibyte sequence - is the locale set?\n"));
743 if(converted == (size_t)(-2))
745 synfig::warning("Layer_Freetype: multibyte: %s",
746 _("Can't parse multibyte character.\n"));
750 glyph_index = FT_Get_Char_Index( face, wc );
753 iter += converted - 1;
756 // retrieve kerning distance and move pen position
757 if ( FT_HAS_KERNING(face) && use_kerning && previous && glyph_index )
762 FT_Get_Kerning( face, previous, glyph_index, ft_kerning_default, &delta );
764 FT_Get_Kerning( face, previous, glyph_index, ft_kerning_unfitted, &delta );
768 bx += round_to_int(delta.x*compress);
769 by += round_to_int(delta.y*compress);
780 // store current pen position
781 curr_glyph.pos.x = bx;
782 curr_glyph.pos.y = by;
784 // load glyph image into the slot. DO NOT RENDER IT !!
786 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT);
788 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT|FT_LOAD_NO_HINTING );
789 if (error) continue; // ignore errors, jump to next glyph
791 // extract glyph image and store it in our table
792 error = FT_Get_Glyph( face->glyph, &curr_glyph.glyph );
793 if (error) continue; // ignore errors, jump to next glyph
795 // record current glyph index
796 previous = glyph_index;
798 // Update the line width
799 lines.front().width=bx+slot->advance.x;
801 // increment pen position
803 bx += round_to_int(slot->advance.x*multiplier*compress)-bx%round_to_int(slot->advance.x*multiplier*compress);
805 bx += round_to_int(slot->advance.x*compress*multiplier);
807 //bx += round_to_int(slot->advance.x*compress*multiplier);
808 //by += round_to_int(slot->advance.y*compress);
809 by += slot->advance.y*multiplier;
811 lines.front().glyph_table.push_back(curr_glyph);
815 //float string_height;
816 //string_height=(((lines.size()-1)*face->size->metrics.height+lines.back().actual_height()));
818 //int string_height=face->size->metrics.ascender;
819 //#define METRICS_SCALE_ONE (65536.0f)
820 #define METRICS_SCALE_ONE ((float)(1<<16))
823 line_height=vcompress*((float)face->height*(((float)face->size->metrics.y_scale/METRICS_SCALE_ONE)));
825 // This module sees to expect pixel height to be negative, as it
826 // usually is. But rendering to .bmp format causes ph to be
827 // positive, which was causing text to be rendered upside down.
828 if (ph>0) line_height = -line_height;
831 string_height=round_to_int(((lines.size()-1)*line_height+lines.back().actual_height()));
832 //synfig::info("string_height=%d",string_height);
833 //synfig::info("line_height=%f",line_height);
836 -- ** -- RENDER THE GLYPHS ---------------------------------------------------
840 Surface *src_surface;
847 Surface::alpha_pen pen(surface->begin(),get_amount(),get_blend_method());
849 surface->fill(color,pen,src_.get_w(),src_.get_h());
855 std::list<TextLine>::iterator iter;
857 for(curr_line=0,iter=lines.begin();iter!=lines.end();++iter,curr_line++)
859 bx=round_to_int((origin[0]-renddesc.get_tl()[0])*pw*CHAR_RESOLUTION-orient[0]*iter->width);
860 // I've no idea why 1.5, but it kind of works. Otherwise,
861 // rendering to .bmp (which renders from bottom to top, due to
862 // the .bmp format describing the image from bottom to top,
863 // renders text in the wrong place.
864 by=round_to_int((origin[1]-renddesc.get_tl()[1])*ph*CHAR_RESOLUTION +
865 (1.0-orient[1])*string_height-line_height*curr_line +
866 ((ph>0) ? line_height/1.5 : 0));
868 //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));
869 //synfig::info("curr_line=%d, bx=%d, by=%d",curr_line,bx,by);
871 std::vector<Glyph>::iterator iter2;
872 for(iter2=iter->glyph_table.begin();iter2!=iter->glyph_table.end();++iter2)
874 FT_Glyph image(iter2->glyph);
878 pen.x = bx + iter2->pos.x;
879 pen.y = by + iter2->pos.y;
881 //synfig::info("GLYPH: line %d, pen.x=%d, pen,y=%d",curr_line,(pen.x+32)>>6,(pen.y+32)>>6);
883 error = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal,0/*&pen*/, 1 );
884 if(error) { FT_Done_Glyph( image ); continue; }
886 bit = (FT_BitmapGlyph)image;
888 for(v=0;v<bit->bitmap.rows;v++)
889 for(u=0;u<bit->bitmap.width;u++)
891 int x=u+((pen.x+32)>>6)+ bit->left;
892 int y=((pen.y+32)>>6) + (bit->top - v) * ((ph<0) ? -1 : 1);
895 y<surface->get_h() &&
898 float myamount=(float)bit->bitmap.buffer[v*bit->bitmap.pitch+u]/255.0f;
900 myamount=1.0f-myamount;
901 (*surface)[y][x]=Color::blend(color,(*src_surface)[y][x],myamount*get_amount(),get_blend_method());
905 FT_Done_Glyph( image );
907 //iter->clear_and_free();
915 Layer_Freetype::get_bounding_rect()const
918 const_cast<Layer_Freetype*>(this)->sync();
919 // if(!is_disabled())
920 return synfig::Rect::full_plane();