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);
114 Layer_Freetype::~Layer_Freetype()
121 Layer_Freetype::new_font(const synfig::String &family, int style, int weight)
124 !new_font_(family,style,weight) &&
125 !new_font_(family,style,WEIGHT_NORMAL) &&
126 !new_font_(family,PANGO_STYLE_NORMAL,weight) &&
127 !new_font_(family,PANGO_STYLE_NORMAL,WEIGHT_NORMAL) &&
128 !new_font_("sans serif",style,weight) &&
129 !new_font_("sans serif",style,WEIGHT_NORMAL) &&
130 !new_font_("sans serif",PANGO_STYLE_NORMAL,weight)
132 new_font_("sans serif",PANGO_STYLE_NORMAL,WEIGHT_NORMAL);
136 Layer_Freetype::new_font_(const synfig::String &font_fam_, int style, int weight)
138 synfig::String font_fam(font_fam_);
140 if(new_face(font_fam_))
144 for(unsigned int i=0;i<font_fam.size();i++)font_fam[i]=tolower(font_fam[i]);
147 if(font_fam=="arial black")
150 if(new_face("ariblk"))
154 font_fam="sans serif";
157 if(font_fam=="sans serif" || font_fam=="arial")
159 String arial("arial");
160 if(weight>WEIGHT_NORMAL)
162 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
165 if(weight>WEIGHT_NORMAL) arial+='d';
170 if(new_face("Helvetica RO"))
175 if(font_fam=="comic" || font_fam=="comic sans")
177 String filename("comic");
178 if(weight>WEIGHT_NORMAL)
180 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
182 else if(weight>WEIGHT_NORMAL) filename+='d';
184 if(new_face(filename))
188 if(font_fam=="courier" || font_fam=="courier new")
190 String filename("cour");
191 if(weight>WEIGHT_NORMAL)
193 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
195 else if(weight>WEIGHT_NORMAL) filename+='d';
197 if(new_face(filename))
201 if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman")
203 String filename("times");
204 if(weight>WEIGHT_NORMAL)
206 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
208 else if(weight>WEIGHT_NORMAL) filename+='d';
210 if(new_face(filename))
214 if(font_fam=="trebuchet")
216 String filename("trebuc");
217 if(weight>WEIGHT_NORMAL)
219 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
222 if(weight<=WEIGHT_NORMAL) filename+='t';
224 else if(weight>WEIGHT_NORMAL) filename+='d';
226 if(new_face(filename))
230 if(font_fam=="sans serif" || font_fam=="luxi sans")
233 String luxi("luxis");
234 if(weight>WEIGHT_NORMAL)
238 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
244 if(new_face("arial"))
246 if(new_face("Arial"))
249 if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman" || font_fam=="luxi serif")
252 String luxi("luxir");
253 if(weight>WEIGHT_NORMAL)
257 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
263 if(new_face("Times New Roman"))
265 if(new_face("Times"))
271 String luxi("luxim");
272 if(weight>WEIGHT_NORMAL)
276 if(style==PANGO_STYLE_ITALIC||style==PANGO_STYLE_OBLIQUE)
283 if(new_face("Times New Roman"))
285 if(new_face("Times"))
289 return new_face(font_fam_) || new_face(font_fam);
294 #ifdef USE_MAC_FT_FUNCS
295 void fss2path(char *path, FSSpec *fss)
297 int l; //fss->name contains name of last item in path
298 for(l=0; l<(fss->name[0]); l++) path[l] = fss->name[l + 1];
301 if(fss->parID != fsRtParID) //path is more than just a volume name
306 pb.dirInfo.ioNamePtr = fss->name;
307 pb.dirInfo.ioVRefNum = fss->vRefNum;
308 pb.dirInfo.ioDrParID = fss->parID;
311 pb.dirInfo.ioFDirIndex = -1; //get parent directory name
312 pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
313 if(PBGetCatInfoSync(&pb) != noErr) break;
315 len = fss->name[0] + 1;
316 for(i=l; i>=0; i--) path[i + len] = path[i];
317 for(i=1; i<len; i++) path[i - 1] = fss->name[i]; //add to start of path
320 } while(pb.dirInfo.ioDrDirID != fsRtDirID); //while more directory levels
326 Layer_Freetype::new_face(const String &newfont)
329 FT_Long face_index=0;
331 // If we are already loaded, don't bother reloading.
332 if(face && font==newfont)
341 error=FT_New_Face(ft_library,newfont.c_str(),face_index,&face);
342 if(error)error=FT_New_Face(ft_library,(newfont+".ttf").c_str(),face_index,&face);
346 if(error)error=FT_New_Face(ft_library,(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPARATOR+newfont).c_str(),face_index,&face);
347 if(error)error=FT_New_Face(ft_library,(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPARATOR+newfont+".ttf").c_str(),face_index,&face);
350 #ifdef USE_MAC_FT_FUNCS
354 error=FT_GetFile_From_Mac_Name(newfont.c_str(),&fs_spec,&face_index);
358 fss2path(filename,&fs_spec);
359 //FSSpecToNativePathName(fs_spec,filename,sizeof(filename)-1, 0);
361 error=FT_New_Face(ft_library, filename, face_index,&face);
362 //error=FT_New_Face_From_FSSpec(ft_library, &fs_spec, face_index,&face);
363 synfig::info(__FILE__":%d: \"%s\" (%s) -- ft_error=%d",__LINE__,newfont.c_str(),filename,error);
367 synfig::info(__FILE__":%d: \"%s\" -- ft_error=%d",__LINE__,newfont.c_str(),error);
368 // Unable to generate fs_spec
373 #ifdef WITH_FONTCONFIG
380 synfig::warning("Layer_Freetype: fontconfig: %s",_("unable to initialize"));
383 FcPattern* pat = FcNameParse((FcChar8 *) newfont.c_str());
384 FcConfigSubstitute(0, pat, FcMatchPattern);
385 FcDefaultSubstitute(pat);
387 fs = FcFontSetCreate();
388 match = FcFontMatch(0, pat, &result);
390 FcFontSetAdd(fs, match);
392 FcPatternDestroy(pat);
395 if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch )
396 error=FT_New_Face(ft_library,(const char*)file,face_index,&face);
397 FcFontSetDestroy(fs);
399 synfig::warning("Layer_Freetype: fontconfig: %s",_("empty font set"));
405 if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont).c_str(),face_index,&face);
406 if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont+".ttf").c_str(),face_index,&face);
410 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont).c_str(),face_index,&face);
411 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face);
412 if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face);
414 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont).c_str(),face_index,&face);
415 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face);
416 if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face);
419 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont).c_str(),face_index,&face);
420 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont+".ttf").c_str(),face_index,&face);
422 if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont).c_str(),face_index,&face);
423 if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face);
425 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont).c_str(),face_index,&face);
426 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont+".ttf").c_str(),face_index,&face);
428 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont).c_str(),face_index,&face);
429 if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face);
434 //synfig::error(strprintf("Layer_Freetype:%s (err=%d)",_("Unable to open face."),error));
445 Layer_Freetype::set_param(const String & param, const ValueBase &value)
447 Mutex::Lock lock(mutex);
449 if(param=="font" && value.same_type_as(font))
451 new_font(etl::basename(value.get(font)),style,weight);
452 family=etl::basename(value.get(font));
456 IMPORT_PLUS(family,new_font(family,style,weight));
457 IMPORT_PLUS(weight,new_font(family,style,weight));
458 IMPORT_PLUS(style,new_font(family,style,weight));
459 IMPORT_PLUS(size, if(old_version){size/=2.0;} needs_sync_=true );
460 IMPORT_PLUS(text,needs_sync_=true);
461 IMPORT_PLUS(origin,needs_sync_=true);
462 IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
463 set_blend_method(Color::BLEND_ALPHA_OVER);
464 color.set_a(1); } else transparent_color_ = true; } });
466 IMPORT_PLUS(orient,needs_sync_=true);
467 IMPORT_PLUS(compress,needs_sync_=true);
468 IMPORT_PLUS(vcompress,needs_sync_=true);
469 IMPORT_PLUS(use_kerning,needs_sync_=true);
470 IMPORT_PLUS(grid_fit,needs_sync_=true);
472 IMPORT_AS(origin,"pos");
474 return Layer_Composite::set_param(param,value);
478 Layer_Freetype::get_param(const String& param)const
498 return Layer_Composite::get_param(param);
502 Layer_Freetype::get_param_vocab(void)const
504 Layer::Vocab ret(Layer_Composite::get_param_vocab());
506 ret.push_back(ParamDesc("text")
507 .set_local_name(_("Text"))
508 .set_description(_("Text to Render"))
509 .set_hint("paragraph")
512 ret.push_back(ParamDesc("color")
513 .set_local_name(_("Color"))
514 .set_description(_("Color of the text"))
517 ret.push_back(ParamDesc("family")
518 .set_local_name(_("Font Family"))
519 .set_hint("font_family")
522 ret.push_back(ParamDesc("style")
523 .set_local_name(_("Style"))
525 .add_enum_value(PANGO_STYLE_NORMAL, "normal" ,_("Normal"))
526 .add_enum_value(PANGO_STYLE_OBLIQUE, "oblique" ,_("Oblique"))
527 .add_enum_value(PANGO_STYLE_ITALIC, "italic" ,_("Italic"))
530 ret.push_back(ParamDesc("weight")
531 .set_local_name(_("Weight"))
533 .add_enum_value(200, "ultralight" ,_("Ultralight"))
534 .add_enum_value(300, "light" ,_("light"))
535 .add_enum_value(400, "normal" ,_("Normal"))
536 .add_enum_value(700, "bold" ,_("Bold"))
537 .add_enum_value(800, "ultrabold" ,_("Ultrabold"))
538 .add_enum_value(900, "heavy" ,_("Heavy"))
540 ret.push_back(ParamDesc("compress")
541 .set_local_name(_("Horizontal Spacing"))
542 .set_description(_("Describes how close glyphs are horizontally"))
545 ret.push_back(ParamDesc("vcompress")
546 .set_local_name(_("Vertical Spacing"))
547 .set_description(_("Describes how close lines of text are vertically"))
550 ret.push_back(ParamDesc("size")
551 .set_local_name(_("Size"))
552 .set_description(_("Size of the text"))
554 .set_origin("origin")
558 ret.push_back(ParamDesc("orient")
559 .set_local_name(_("Orientation"))
560 .set_description(_("Text Orientation"))
561 .set_invisible_duck()
564 ret.push_back(ParamDesc("origin")
565 .set_local_name(_("Origin"))
566 .set_description(_("Text Position"))
569 ret.push_back(ParamDesc("font")
570 .set_local_name(_("Font"))
571 .set_description(_("Filename of the font to use"))
572 .set_hint("filename")
577 ret.push_back(ParamDesc("use_kerning")
578 .set_local_name(_("Kerning"))
579 .set_description(_("Enables/Disables font kerning (If the font supports it)"))
582 ret.push_back(ParamDesc("grid_fit")
583 .set_local_name(_("Sharpen Edges"))
584 .set_description(_("Turn this off if you are going to be animating the text"))
586 ret.push_back(ParamDesc("invert")
587 .set_local_name(_("Invert"))
593 Layer_Freetype::sync()
599 Layer_Freetype::color_func(const Point &point_ __attribute__ ((unused)), int quality __attribute__ ((unused)), float supersample __attribute__ ((unused)))const
604 return Color::alpha();
608 Layer_Freetype::get_color(Context context, const synfig::Point &pos)const
611 const_cast<Layer_Freetype*>(this)->sync();
613 const Color color(color_func(pos,0));
616 return context.get_color(pos);
618 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
621 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
625 Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
627 static synfig::RecMutex freetype_mutex;
630 const_cast<Layer_Freetype*>(this)->sync();
633 Vector size(Layer_Freetype::size*2);
635 if(!context.accelerated_render(surface,quality,renddesc,cb))
638 if(is_disabled() || text.empty())
641 // If there is no font loaded, just bail
644 if(cb)cb->warning(string("Layer_Freetype:")+_("No face loaded, no text will be rendered."));
648 String text(Layer_Freetype::text);
649 if(text=="@_FILENAME_@" && get_canvas() && !get_canvas()->get_file_name().empty())
651 text=basename(get_canvas()->get_file_name());
654 // Width and Height of a pixel
655 Vector::value_type pw=renddesc.get_w()/(renddesc.get_br()[0]-renddesc.get_tl()[0]);
656 Vector::value_type ph=renddesc.get_h()/(renddesc.get_br()[1]-renddesc.get_tl()[1]);
658 // Calculate character width and height
659 int w=abs(round_to_int(size[0]*pw));
660 int h=abs(round_to_int(size[1]*ph));
662 //int bx=(int)((origin[0]-renddesc.get_tl()[0])*pw*64+0.5);
663 //int by=(int)((origin[1]-renddesc.get_tl()[1])*ph*64+0.5);
667 // If the font is the size of a pixel, don't bother rendering any text
670 if(cb)cb->warning(string("Layer_Freetype:")+_("Text too small, no text will be rendered."));
674 synfig::RecMutex::Lock lock(freetype_mutex);
676 #define CHAR_RESOLUTION (64)
677 error = FT_Set_Char_Size(
678 face, // handle to face object
679 (int)CHAR_RESOLUTION, // char_width in 1/64th of points
680 (int)CHAR_RESOLUTION, // char_height in 1/64th of points
681 round_to_int(abs(size[0]*pw*CHAR_RESOLUTION)), // horizontal device resolution
682 round_to_int(abs(size[1]*ph*CHAR_RESOLUTION)) ); // vertical device resolution
684 // Here is where we can compensate for the
685 // error in freetype's rendering engine.
686 const float xerror(abs(size[0]*pw)/(float)face->size->metrics.x_ppem/1.13f/0.996);
687 const float yerror(abs(size[1]*ph)/(float)face->size->metrics.y_ppem/1.13f/0.996);
688 //synfig::info("xerror=%f, yerror=%f",xerror,yerror);
689 const float compress(Layer_Freetype::compress*xerror);
690 const float vcompress(Layer_Freetype::vcompress*yerror);
694 if(cb)cb->warning(string("Layer_Freetype:")+_("Unable to set face size.")+strprintf(" (err=%d)",error));
697 FT_GlyphSlot slot = face->glyph; // a small shortcut
698 FT_UInt glyph_index(0);
702 std::list<TextLine> lines;
705 -- ** -- CREATE GLYPHS -------------------------------------------------------
709 memset(&ps, 0, sizeof(ps));
711 lines.push_front(TextLine());
712 string::const_iterator iter;
713 for (iter=text.begin(); iter!=text.end(); ++iter)
718 lines.push_front(TextLine());
727 glyph_index = FT_Get_Char_Index( face, ' ' );
732 size_t converted = mbrtowc(&wc, &(*iter), text.end() - iter, &ps);
734 if(converted == (size_t)(-1))
736 synfig::warning("Layer_Freetype: multibyte: %s",
737 _("Invalid multibyte sequence - is the locale set?\n"));
741 if(converted == (size_t)(-2))
743 synfig::warning("Layer_Freetype: multibyte: %s",
744 _("Can't parse multibyte character.\n"));
748 glyph_index = FT_Get_Char_Index( face, wc );
751 iter += converted - 1;
754 // retrieve kerning distance and move pen position
755 if ( FT_HAS_KERNING(face) && use_kerning && previous && glyph_index )
760 FT_Get_Kerning( face, previous, glyph_index, ft_kerning_default, &delta );
762 FT_Get_Kerning( face, previous, glyph_index, ft_kerning_unfitted, &delta );
766 bx += round_to_int(delta.x*compress);
767 by += round_to_int(delta.y*compress);
778 // store current pen position
779 curr_glyph.pos.x = bx;
780 curr_glyph.pos.y = by;
782 // load glyph image into the slot. DO NOT RENDER IT !!
784 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT);
786 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT|FT_LOAD_NO_HINTING );
787 if (error) continue; // ignore errors, jump to next glyph
789 // extract glyph image and store it in our table
790 error = FT_Get_Glyph( face->glyph, &curr_glyph.glyph );
791 if (error) continue; // ignore errors, jump to next glyph
793 // record current glyph index
794 previous = glyph_index;
796 // Update the line width
797 lines.front().width=bx+slot->advance.x;
799 // increment pen position
801 bx += round_to_int(slot->advance.x*multiplier*compress)-bx%round_to_int(slot->advance.x*multiplier*compress);
803 bx += round_to_int(slot->advance.x*compress*multiplier);
805 //bx += round_to_int(slot->advance.x*compress*multiplier);
806 //by += round_to_int(slot->advance.y*compress);
807 by += slot->advance.y*multiplier;
809 lines.front().glyph_table.push_back(curr_glyph);
813 //float string_height;
814 //string_height=(((lines.size()-1)*face->size->metrics.height+lines.back().actual_height()));
816 //int string_height=face->size->metrics.ascender;
817 //#define METRICS_SCALE_ONE (65536.0f)
818 #define METRICS_SCALE_ONE ((float)(1<<16))
821 line_height=vcompress*((float)face->height*(((float)face->size->metrics.y_scale/METRICS_SCALE_ONE)));
823 // This module sees to expect pixel height to be negative, as it
824 // usually is. But rendering to .bmp format causes ph to be
825 // positive, which was causing text to be rendered upside down.
826 if (ph>0) line_height = -line_height;
829 string_height=round_to_int(((lines.size()-1)*line_height+lines.back().actual_height()));
830 //synfig::info("string_height=%d",string_height);
831 //synfig::info("line_height=%f",line_height);
834 -- ** -- RENDER THE GLYPHS ---------------------------------------------------
838 Surface *src_surface;
845 Surface::alpha_pen pen(surface->begin(),get_amount(),get_blend_method());
847 surface->fill(color,pen,src_.get_w(),src_.get_h());
853 std::list<TextLine>::iterator iter;
855 for(curr_line=0,iter=lines.begin();iter!=lines.end();++iter,curr_line++)
857 bx=round_to_int((origin[0]-renddesc.get_tl()[0])*pw*CHAR_RESOLUTION-orient[0]*iter->width);
858 // I've no idea why 1.5, but it kind of works. Otherwise,
859 // rendering to .bmp (which renders from bottom to top, due to
860 // the .bmp format describing the image from bottom to top,
861 // renders text in the wrong place.
862 by=round_to_int((origin[1]-renddesc.get_tl()[1])*ph*CHAR_RESOLUTION +
863 (1.0-orient[1])*string_height-line_height*curr_line +
864 ((ph>0) ? line_height/1.5 : 0));
866 //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));
867 //synfig::info("curr_line=%d, bx=%d, by=%d",curr_line,bx,by);
869 std::vector<Glyph>::iterator iter2;
870 for(iter2=iter->glyph_table.begin();iter2!=iter->glyph_table.end();++iter2)
872 FT_Glyph image(iter2->glyph);
876 pen.x = bx + iter2->pos.x;
877 pen.y = by + iter2->pos.y;
879 //synfig::info("GLYPH: line %d, pen.x=%d, pen,y=%d",curr_line,(pen.x+32)>>6,(pen.y+32)>>6);
881 error = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal,0/*&pen*/, 1 );
882 if(error) { FT_Done_Glyph( image ); continue; }
884 bit = (FT_BitmapGlyph)image;
886 for(v=0;v<bit->bitmap.rows;v++)
887 for(u=0;u<bit->bitmap.width;u++)
889 int x=u+((pen.x+32)>>6)+ bit->left;
890 int y=((pen.y+32)>>6) + (bit->top - v) * ((ph<0) ? -1 : 1);
893 y<surface->get_h() &&
896 float myamount=(float)bit->bitmap.buffer[v*bit->bitmap.pitch+u]/255.0f;
898 myamount=1.0f-myamount;
899 (*surface)[y][x]=Color::blend(color,(*src_surface)[y][x],myamount*get_amount(),get_blend_method());
903 FT_Done_Glyph( image );
905 //iter->clear_and_free();
913 Layer_Freetype::get_bounding_rect()const
916 const_cast<Layer_Freetype*>(this)->sync();
917 // if(!is_disabled())
918 return synfig::Rect::full_plane();