X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Flyr_freetype%2Flyr_freetype.cpp;h=07d25332a764bdb1b3bcd38a0dda01f58dc37953;hb=4c003ac49046e06b6d9a31b38707f921830ea41b;hp=3dc5397f76cef9dbd1c3d954655c513ae6f4ea26;hpb=28f28705612902c15cd0702cc891fba35bf2d2df;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 3dc5397..07d2533 100644 --- a/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp +++ b/synfig-core/trunk/src/modules/lyr_freetype/lyr_freetype.cpp @@ -3,16 +3,17 @@ ** Template File ** $Id: lyr_freetype.cpp,v 1.5 2005/01/24 05:00:18 darco Exp $ ** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** ** === N O T E S =========================================================== ** @@ -31,17 +32,6 @@ #include "lyr_freetype.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include #endif @@ -138,23 +128,26 @@ lyr_freetype::new_font(const synfig::String &family, int style, int weight) } bool -lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) +lyr_freetype::new_font_(const synfig::String &font_fam_, int style, int weight) { - synfig::String family(family_); + synfig::String font_fam(font_fam_); + + if(new_face(font_fam_)) + return true; //start evil hack - for(int i=0;iWEIGHT_NORMAL) @@ -166,9 +159,13 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) if(new_face(arial)) return true; +#ifdef __APPLE__ + if(new_face("Helvetica RO")) + return true; +#endif } - if(family=="comic" || family=="comic sans") + if(font_fam=="comic" || font_fam=="comic sans") { String filename("comic"); if(weight>WEIGHT_NORMAL) @@ -181,7 +178,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) return true; } - if(family=="courier" || family=="courier new") + if(font_fam=="courier" || font_fam=="courier new") { String filename("cour"); if(weight>WEIGHT_NORMAL) @@ -194,7 +191,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) return true; } - if(family=="serif" || family=="times" || family=="times new roman") + if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman") { String filename("times"); if(weight>WEIGHT_NORMAL) @@ -207,7 +204,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) return true; } - if(family=="trebuchet") + if(font_fam=="trebuchet") { String filename("trebuc"); if(weight>WEIGHT_NORMAL) @@ -224,7 +221,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) } - if(family=="sans serif" || family=="luxi sans") + if(font_fam=="sans serif" || font_fam=="luxi sans") { { String luxi("luxis"); @@ -244,7 +241,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) if(new_face("Arial")) return true; } - if(family=="serif" || family=="times" || family=="times new roman" || family=="luxi serif") + if(font_fam=="serif" || font_fam=="times" || font_fam=="times new roman" || font_fam=="luxi serif") { { String luxi("luxir"); @@ -263,7 +260,7 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) if(new_face("Times")) return true; } - if(family=="luxi") + if(font_fam=="luxi") { { String luxi("luxim"); @@ -284,16 +281,47 @@ lyr_freetype::new_font_(const synfig::String &family_, int style, int weight) return true; } - return new_face(family_) || new_face(family); + return new_face(font_fam_) || new_face(font_fam); return false; } +#ifdef USE_MAC_FT_FUNCS +void fss2path(char *path, FSSpec *fss) +{ + int l; //fss->name contains name of last item in path + for(l=0; l<(fss->name[0]); l++) path[l] = fss->name[l + 1]; + path[l] = 0; + + if(fss->parID != fsRtParID) //path is more than just a volume name + { + int i, len; + CInfoPBRec pb; + + pb.dirInfo.ioNamePtr = fss->name; + pb.dirInfo.ioVRefNum = fss->vRefNum; + pb.dirInfo.ioDrParID = fss->parID; + do + { + pb.dirInfo.ioFDirIndex = -1; //get parent directory name + pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; + if(PBGetCatInfoSync(&pb) != noErr) break; + + len = fss->name[0] + 1; + for(i=l; i>=0; i--) path[i + len] = path[i]; + for(i=1; iname[i]; //add to start of path + path[i - 1] = ':'; + l += len; +} while(pb.dirInfo.ioDrDirID != fsRtDirID); //while more directory levels + } +} +#endif + bool lyr_freetype::new_face(const String &newfont) { int error; - int face_index=0; + FT_Long face_index=0; // If we are already loaded, don't bother reloading. if(face && font==newfont) @@ -314,30 +342,57 @@ lyr_freetype::new_face(const String &newfont) if(error)error=FT_New_Face(ft_library,(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPERATOR+newfont+".ttf").c_str(),face_index,&face); } +#ifdef USE_MAC_FT_FUNCS + if(error) + { + FSSpec fs_spec; + error=FT_GetFile_From_Mac_Name(newfont.c_str(),&fs_spec,&face_index); + if(!error) + { + char filename[512]; + fss2path(filename,&fs_spec); + //FSSpecToNativePathName(fs_spec,filename,sizeof(filename)-1, 0); + + error=FT_New_Face(ft_library, filename, face_index,&face); + //error=FT_New_Face_From_FSSpec(ft_library, &fs_spec, face_index,&face); + synfig::info(__FILE__":%d: \"%s\" (%s) -- ft_error=%d",__LINE__,newfont.c_str(),filename,error); + } + else + { + synfig::info(__FILE__":%d: \"%s\" -- ft_error=%d",__LINE__,newfont.c_str(),error); + // Unable to generate fs_spec + } + + } +#endif + #ifdef WIN32 if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont).c_str(),face_index,&face); if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont+".ttf").c_str(),face_index,&face); #else - if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont).c_str(),face_index,&face); - if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face); - - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont).c_str(),face_index,&face); - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont+".ttf").c_str(),face_index,&face); - - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont).c_str(),face_index,&face); - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face); - - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont).c_str(),face_index,&face); - if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont+".ttf").c_str(),face_index,&face); #ifdef __APPLE__ if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont).c_str(),face_index,&face); if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("~/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face); if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont).c_str(),face_index,&face); if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".ttf").c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("/Library/Fonts/"+newfont+".dfont").c_str(),face_index,&face); #endif + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont).c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/type1/"+newfont+".ttf").c_str(),face_index,&face); + + if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont).c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("/usr/share/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face); + + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont).c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/TTF/"+newfont+".ttf").c_str(),face_index,&face); + + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont).c_str(),face_index,&face); + if(error)error=FT_New_Face(ft_library,("/usr/X11R6/lib/X11/fonts/truetype/"+newfont+".ttf").c_str(),face_index,&face); + #endif if(error) { @@ -355,12 +410,14 @@ bool lyr_freetype::set_param(const String & param, const ValueBase &value) { Mutex::Lock lock(mutex); +/* if(param=="font" && value.same_as(font)) { new_font(etl::basename(value.get(font)),style,weight); family=etl::basename(value.get(font)); return true; } +*/ IMPORT_PLUS(family,new_font(family,style,weight)); IMPORT_PLUS(weight,new_font(family,style,weight)); IMPORT_PLUS(style,new_font(family,style,weight)); @@ -504,7 +561,7 @@ lyr_freetype::sync() } Color -lyr_freetype::get_color(Context context, const Point &pos)const +lyr_freetype::get_color(Context context, const synfig::Point &pos)const { if(needs_sync_) const_cast(this)->sync(); @@ -777,5 +834,5 @@ lyr_freetype::get_bounding_rect()const if(needs_sync_) const_cast(this)->sync(); // if(!is_disabled()) - return Rect::full_plane(); + return synfig::Rect::full_plane(); }