// Thanks to http://stackoverflow.com/a/14634033/1447751 const std::string get_font_path(const std::string &name) { std::string path; const FcChar8 *fcname = reinterpret_cast<const FcChar8 *>(name.c_str()); FcConfig *config = FcInitLoadConfigAndFonts(); // configure the search pattern, // assume "name" is a std::string with the desired font name in it FcPattern *pat = FcNameParse(fcname); FcConfigSubstitute(config, pat, FcMatchPattern); FcDefaultSubstitute(pat); FcResult result; // find the font FcPattern *font = FcFontMatch(config, pat, &result); if (font) { FcChar8 *fcpath = NULL; FcChar8 *fcfamily = NULL; if (FcPatternGetString(font, FC_FAMILY, 0, &fcfamily) == FcResultMatch && (name.empty() || !FcStrCmpIgnoreCase(fcname, fcfamily)) // Empty name means searching for default font, otherwise make // sure the returned font is exactly what we searched for && FcPatternGetString(font, FC_FILE, 0, &fcpath) == FcResultMatch) path = std::string(reinterpret_cast<char *>(fcpath)); FcPatternDestroy(font); } FcPatternDestroy(pat); return path; }
static void load_font_from_fontconfig(void) { FcConfig* config = FcInitLoadConfigAndFonts(); FcFontSet* fontset = NULL; // get application fonts fontset = FcConfigGetFonts(config, FcSetApplication); if (fontset) { FcValue fvalue, dvalue; for (int i = 0; i < fontset->nfont; i++) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FAMILY, 0, &fvalue)) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FILE, 0, &dvalue)) { font_item* font = get_font_item((const char*)fvalue.u.s, (const char*)dvalue.u.s); g_font_map.add(font); } } } } // get system fonts fontset = FcConfigGetFonts(config, FcSetSystem); if (fontset) { FcValue fvalue, dvalue; for (int i = 0; i < fontset->nfont; i++) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FAMILY, 0, &fvalue)) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FILE, 0, &dvalue)) { font_item* font = get_font_item((const char*)fvalue.u.s, (const char*)dvalue.u.s); g_font_map.add(font); } } } } FcConfigDestroy(config); }
/* * Reread the configuration and available font lists */ FcBool FcInitReinitialize (void) { FcConfig *config; config = FcInitLoadConfigAndFonts (); if (!config) return FcFalse; return FcConfigSetCurrent (config); }
static void evas_font_init(void) { static Eina_Bool fc_init = EINA_FALSE; if (fc_init) return; fc_init = EINA_TRUE; #ifdef HAVE_FONTCONFIG fc_config = FcInitLoadConfigAndFonts(); #endif }
std::string PdfFontCache::GetFontPath( const char* pszFontName, bool bBold, bool bItalic ) { #if defined(HAVE_FONTCONFIG) FcConfig* pConfig = FcInitLoadConfigAndFonts(); std::string sPath = this->GetFontConfigFontPath( pConfig, pszFontName, bBold, bItalic ); FcConfigDestroy( pConfig ); #else std::string sPath = ""; #endif return sPath; }
FontConfig::FontConfig() { if (!fc_config) { fc_config = FcInitLoadConfigAndFonts(); } if (!fc_config) { throw Exception("CL_FontConfig: Initializing FontConfig library failed."); } }
FontconfigFontProvider::FontconfigFontProvider() : _config(0) { if (!FcInit()) { warning("Failed to initialize fontconfig"); return; } _config = FcInitLoadConfigAndFonts(); if (!_config) { warning("Failed to create fontconfig config"); FcFini(); } }
PdfFontCache::PdfFontCache( PdfVecObjects* pParent ) : m_pParent( pParent ) { // Initialize all the fonts stuff #if defined(HAVE_FONTCONFIG) m_pFcConfig = static_cast<void*>(FcInitLoadConfigAndFonts()); #endif if( FT_Init_FreeType( &m_ftLibrary ) ) { PODOFO_RAISE_ERROR( ePdfError_FreeType ); } }
/* * Initialize the default library configuration */ FcBool FcInit (void) { FcConfig *config; if (_fcConfig) return FcTrue; config = FcInitLoadConfigAndFonts (); if (!config) return FcTrue; FcConfigSetCurrent (config); if (FcDebug() & FC_DBG_MEMORY) FcMemReport (); return FcTrue; }
const std::string find_font(const char* name) { std::string font_file; FcConfig* config = FcInitLoadConfigAndFonts(); FcPattern* pattern = FcNameParse((const FcChar8*) (name)); FcConfigSubstitute(config, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); FcPattern* font = FcFontMatch(config, pattern, NULL); if (font) { FcChar8* file = NULL; if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) font_file = std::string((char*) file); FcPatternDestroy(font); } FcPatternDestroy(pattern); return font_file; }
static FcConfig * FcConfigEnsure (void) { FcConfig *config; retry: config = fc_atomic_ptr_get (&_fcConfig); if (!config) { config = FcInitLoadConfigAndFonts (); if (!fc_atomic_ptr_cmpexch (&_fcConfig, NULL, config)) { FcConfigDestroy (config); goto retry; } } return config; }
void *gp_enumerate_fonts_init(gs_memory_t *mem) { #ifdef HAVE_FONTCONFIG unix_fontenum_t *state; FcPattern *pat; FcObjectSet *os; state = (unix_fontenum_t *)malloc(sizeof(unix_fontenum_t)); if (state == NULL) return NULL; /* Failed to allocate state */ state->index = 0; state->fc = NULL; state->font_list = NULL; /* Load the fontconfig library */ state->fc = FcInitLoadConfigAndFonts(); if (state->fc == NULL) { free(state); state = NULL; dlprintf("destroyed state - fontconfig init failed"); return NULL; /* Failed to open fontconfig library */ } /* load the font set that we'll iterate over */ pat = FcPatternBuild(NULL, FC_OUTLINE, FcTypeBool, 1, FC_SCALABLE, FcTypeBool, 1, NULL); os = FcObjectSetBuild(FC_FILE, FC_OUTLINE, FC_FAMILY, FC_WEIGHT, FC_SLANT, NULL); state->font_list = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); if (state->font_list == NULL) { free(state); state = NULL; return NULL; /* Failed to generate font list */ } return (void *)state; #else return NULL; #endif }
static int allocate_info(p_info_rec* p_info) { info_rec* info; *p_info = malloc(sizeof(info_rec)); if (*p_info == NULL) return YUV_no_memory; info = *p_info; info->face = NULL; strcpy(info->current_family, ""); // initialise FontConfig info->config = FcInitLoadConfigAndFonts(); if (info->config == NULL) return YUV_fontconfig; // initialise FreeType if (FT_Init_FreeType(&info->library)) return YUV_freetype; return YUV_OK; }
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size) { assert(buffer != NULL); assert(font != NULL); log_verbose("Looking for font %s with FontConfig.", font->font_name); FcConfig* config = FcInitLoadConfigAndFonts(); if (!config) { log_error("Failed to initialize FontConfig library"); FcFini(); return false; } FcPattern* pat = FcNameParse((const FcChar8*) font->font_name); FcConfigSubstitute(config, pat, FcMatchPattern); FcDefaultSubstitute(pat); bool found = false; FcResult result = FcResultNoMatch; FcPattern* match = FcFontMatch(config, pat, &result); if (match) { FcChar8* filename = NULL; if (FcPatternGetString(match, FC_FILE, 0, &filename) == FcResultMatch) { found = true; safe_strcpy(buffer, (utf8*) filename, size); log_verbose("FontConfig provided font %s", filename); } FcPatternDestroy(match); } else { log_warning("Failed to find required font."); } FcPatternDestroy(pat); FcConfigDestroy(config); FcFini(); return found; }
static fz_error *initfontlibs(void) { int fterr; int maj, min, pat; if (ftlib) return nil; fterr = FT_Init_FreeType(&ftlib); if (fterr) return fz_throw("freetype cannot initialize: %s", pdf_fterrorstring(fterr)); FT_Library_Version(ftlib, &maj, &min, &pat); if (maj == 2 && min == 1 && pat < 7) return fz_throw("freetype version too old: %d.%d.%d", maj, min, pat); fclib = FcInitLoadConfigAndFonts(); if (!fclib) return fz_throw("fontconfig cannot initialize"); return nil; }
TTF_Font *load_font(const char *font_spec) { int font_size; char *font_name; /* figure out font size from name, or default to 24 */ char *sep = strchr(font_spec, ':'); if(sep) { font_name = strndup(font_spec, sep - font_spec); font_size = strtol(sep+1, NULL, 10); } else { font_name = strdup(font_spec); font_size = 24; } FcConfig *cfg = FcInitLoadConfigAndFonts(); FcPattern *pattern = FcNameParse((const FcChar8*)font_name); FcConfigSubstitute(cfg, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); TTF_Font *ret = NULL; FcResult result = FcResultNoMatch; FcPattern* font = FcFontMatch(cfg, pattern, &result); if (font) { FcChar8 *path = NULL; if (FcPatternGetString(font, FC_FILE, 0, &path) == FcResultMatch) { ret = TTF_OpenFont((char*)path, font_size); } FcPatternDestroy(font); } FcPatternDestroy(pattern); FcConfigDestroy(cfg); free(font_name); return ret; }
/* Ask the fontgod for a generic, standard issue "Arial" font */ const char *graph_init_fontconfig(void) { /* Offer fontgod sacrificial pointers to hold his highness */ FcConfig *fc_config = FcInitLoadConfigAndFonts(); FcPattern *fc_pattern = FcPatternCreate(); /* Ask the deity for a user-specified gift of typography */ FcPatternAddString(fc_pattern, FC_FAMILY, (const FcChar8 *)option->fontname); /* Ask fontgod not to blind our eyes for our insolence */ FcPatternAddBool(fc_pattern, FC_ANTIALIAS, 1); /* Summon a fontdemon which shall transmit the gifts of our god */ FcResult fc_result; /* Incantation for our omnipotence to recognize our request: */ FcDefaultSubstitute(fc_pattern); FcConfigSubstitute(fc_config, fc_pattern, FcMatchPattern); /* "We ask you, oh you in the sky, for your attention..." */ FcPattern *fc_font_chosen = FcFontMatch(fc_config, fc_pattern, &fc_result); FcValue fc_value; /* SHOW US YOUR POWER, INVOKE ANCIENT KNOWLEDGE, GIVE US THE LOCATION! */ FcPatternGet(fc_font_chosen, "file", 0, &fc_value); /* Fontgod has given us a sacred filename, hail FONTCONFIG! */ pprintf(PRI_SPAM, "[FC] Font path received = %s\n", (char *)fc_value.u.s); return (const char *)fc_value.u.s; }
/** * @brief Tries to find a system font. */ static char *gl_fontFind( const char *fname ) { FcConfig* config; FcPattern *pat, *font; FcResult result; FcChar8* file; char *fontFile; config = FcInitLoadConfigAndFonts(); pat = FcNameParse( (const FcChar8*)fname ); FcConfigSubstitute( config, pat, FcMatchPattern ); FcDefaultSubstitute(pat); font = FcFontMatch(config, pat, &result); if (font) { file = NULL; if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { fontFile = strdup( (char*)file ); FcPatternDestroy(pat); return fontFile; } } FcPatternDestroy(pat); return NULL; }
RpiPlatform::RpiPlatform() : m_urlClient(UrlClient::Options{}) { m_fcConfig = FcInitLoadConfigAndFonts(); }
MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, ExceptionInfo *exception) { #if !defined(FC_FULLNAME) #define FC_FULLNAME "fullname" #endif char extension[MaxTextExtent], name[MaxTextExtent]; FcChar8 *family, *file, *fullname, *style; FcConfig *font_config; FcFontSet *font_set; FcObjectSet *object_set; FcPattern *pattern; FcResult status; int slant, width, weight; register ssize_t i; TypeInfo *type_info; /* Load system fonts. */ (void) exception; font_config=FcInitLoadConfigAndFonts(); if (font_config == (FcConfig *) NULL) return(MagickFalse); font_set=(FcFontSet *) NULL; object_set=FcObjectSetBuild(FC_FULLNAME,FC_FAMILY,FC_STYLE,FC_SLANT, FC_WIDTH,FC_WEIGHT,FC_FILE,(char *) NULL); if (object_set != (FcObjectSet *) NULL) { pattern=FcPatternCreate(); if (pattern != (FcPattern *) NULL) { font_set=FcFontList(0,pattern,object_set); FcPatternDestroy(pattern); } FcObjectSetDestroy(object_set); } if (font_set == (FcFontSet *) NULL) { FcConfigDestroy(font_config); return(MagickFalse); } for (i=0; i < (ssize_t) font_set->nfont; i++) { status=FcPatternGetString(font_set->fonts[i],FC_FAMILY,0,&family); if (status != FcResultMatch) continue; status=FcPatternGetString(font_set->fonts[i],FC_FILE,0,&file); if (status != FcResultMatch) continue; *extension='\0'; GetPathComponent((const char *) file,ExtensionPath,extension); if ((*extension != '\0') && (LocaleCompare(extension,"gz") == 0)) continue; type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) continue; (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString("System Fonts"); type_info->signature=MagickSignature; (void) CopyMagickString(name,"Unknown",MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_FULLNAME,0,&fullname); if ((status == FcResultMatch) && (fullname != (FcChar8 *) NULL)) (void) CopyMagickString(name,(const char *) fullname,MaxTextExtent); else { if (family != (FcChar8 *) NULL) (void) CopyMagickString(name,(const char *) family,MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_STYLE,0,&style); if ((status == FcResultMatch) && (style != (FcChar8 *) NULL) && (LocaleCompare((const char *) style,"Regular") != 0)) { (void) ConcatenateMagickString(name," ",MaxTextExtent); (void) ConcatenateMagickString(name,(const char *) style, MaxTextExtent); } } type_info->name=ConstantString(name); (void) SubstituteString(&type_info->name," ","-"); type_info->family=ConstantString((const char *) family); status=FcPatternGetInteger(font_set->fonts[i],FC_SLANT,0,&slant); type_info->style=NormalStyle; if (slant == FC_SLANT_ITALIC) type_info->style=ItalicStyle; if (slant == FC_SLANT_OBLIQUE) type_info->style=ObliqueStyle; status=FcPatternGetInteger(font_set->fonts[i],FC_WIDTH,0,&width); type_info->stretch=NormalStretch; if (width >= FC_WIDTH_ULTRACONDENSED) type_info->stretch=UltraCondensedStretch; if (width >= FC_WIDTH_EXTRACONDENSED) type_info->stretch=ExtraCondensedStretch; if (width >= FC_WIDTH_CONDENSED) type_info->stretch=CondensedStretch; if (width >= FC_WIDTH_SEMICONDENSED) type_info->stretch=SemiCondensedStretch; if (width >= FC_WIDTH_NORMAL) type_info->stretch=NormalStretch; if (width >= FC_WIDTH_SEMIEXPANDED) type_info->stretch=SemiExpandedStretch; if (width >= FC_WIDTH_EXPANDED) type_info->stretch=ExpandedStretch; if (width >= FC_WIDTH_EXTRAEXPANDED) type_info->stretch=ExtraExpandedStretch; if (width >= FC_WIDTH_ULTRAEXPANDED) type_info->stretch=UltraExpandedStretch; type_info->weight=400; status=FcPatternGetInteger(font_set->fonts[i],FC_WEIGHT,0,&weight); if (weight >= FC_WEIGHT_THIN) type_info->weight=100; if (weight >= FC_WEIGHT_EXTRALIGHT) type_info->weight=200; if (weight >= FC_WEIGHT_LIGHT) type_info->weight=300; if (weight >= FC_WEIGHT_NORMAL) type_info->weight=400; if (weight >= FC_WEIGHT_MEDIUM) type_info->weight=500; if (weight >= FC_WEIGHT_DEMIBOLD) type_info->weight=600; if (weight >= FC_WEIGHT_BOLD) type_info->weight=700; if (weight >= FC_WEIGHT_EXTRABOLD) type_info->weight=800; if (weight >= FC_WEIGHT_BLACK) type_info->weight=900; type_info->glyphs=ConstantString((const char *) file); (void) AddValueToSplayTree(type_list,type_info->name,type_info); } FcFontSetDestroy(font_set); FcConfigDestroy(font_config); return(MagickTrue); }
void font_impl::loadSystemFont(const char* const pName, int pFontSize) { //TODO do error checking once it is working std::string ttf_file_path; #ifndef OS_WIN // use fontconfig to get the file FcConfig* config = FcInitLoadConfigAndFonts(); if (!config) { FT_THROW_ERROR("fontconfig initilization failed", fg::FG_ERR_FREETYPE_ERROR); } // configure the search pattern, FcPattern* pat = FcNameParse((const FcChar8*)(pName)); if (!pat) { FT_THROW_ERROR("fontconfig pattern creation failed", fg::FG_ERR_FREETYPE_ERROR); } FcConfigSubstitute(config, pat, FcMatchPattern); FcDefaultSubstitute(pat); // find the font FcResult res; FcPattern* font = FcFontMatch(config, pat, &res); FcConfigSubstitute(config, pat, FcMatchPattern); if (font) { FcChar8* file = NULL; if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { // save the file to another std::string ttf_file_path = (char*)file; } FcPatternDestroy(font); } // destroy fontconfig pattern object FcPatternDestroy(pat); #else char buf[512]; GetWindowsDirectory(buf, 512); std::regex fontRegex(std::string(pName), std::regex_constants::egrep | std::regex_constants::icase); std::vector<std::string> fontFiles; std::vector<std::string> matchedFontFiles; getFontFilePaths(fontFiles, std::string(buf)+"\\Fonts\\", std::string("ttf")); for (const auto &fontName : fontFiles) { if (std::regex_search(fontName, fontRegex)) { matchedFontFiles.push_back(fontName); } } /* out of all the possible matches, we choose the first possible match for given input font name parameter */ if (matchedFontFiles.size()==0) FT_THROW_ERROR("loadSystemFont failed to find the given font name", fg::FG_ERR_FREETYPE_ERROR); ttf_file_path = buf; ttf_file_path += "\\Fonts\\"; ttf_file_path += matchedFontFiles[0]; #endif loadFont(ttf_file_path.c_str(), pFontSize); }
int main(int argc, char* argv[]) { msgbuf = malloc(256); msgbuf[0] = 0; currentLayer = 0; cache = true; int longIndex; int opt; do { opt = getopt_long(argc, argv, optString, longOpts, &longIndex); if (opt != -1) { switch( opt ) { case 'l': currentLayer = strtol(optarg, NULL, 10); break; case 'w': extrusionWidth = strtof(optarg, NULL); break; case 'n': printf("DISABLING CACHE\n"); cache = false; break; case 'h': /* fall-through is intentional */ case '?': display_usage(); break; case 0: /* long option without a short arg */ //if( strcmp( "randomize", longOpts[longIndex].name ) == 0 ) { // globalArgs.randomized = 1; //} break; default: /* You won't actually get here. */ break; } } } while (opt != -1); if (optind >= argc) display_usage(); int fd = open(argv[optind], 0); if (fd == -1) die("Open ", argv[optind]); struct stat filestats; if (fstat(fd, &filestats) == -1) die("fstat ", argv[optind]); filesz = filestats.st_size; printf("File is %d long\n", filesz); #ifdef __linux__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); #elif defined __APPLE__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE, fd, 0); #else #error "don't know how to mmap on this system!" #endif if (gcodefile == MAP_FAILED) die("mmap ", argv[optind]); gcodefile_end = &gcodefile[filesz]; busy = BUSY_SCANFILE; scanLines(); if (currentLayer >= layerCount) currentLayer = layerCount - 1; //for (int i = 0; i < layerCount; i++) // printf("Layer %3d starts at %7d and is %7d bytes long\n", i, layer[i].index - gcodefile, layer[i].size); Running = true; Surf_Display = NULL; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) die("SDL_init", ""); if (FcInitLoadConfigAndFonts() == ((void *) FcTrue)) die("FontConfig Init",""); // from http://www.spinics.net/lists/font-config/msg03050.html FcPattern *pat, *match; FcResult result; char *file; int index; pat = FcPatternCreate(); FcPatternAddString(pat, FC_FAMILY, (FcChar8 *) "Mono"); FcConfigSubstitute(NULL, pat, FcMatchPattern); FcDefaultSubstitute(pat); match = FcFontMatch(NULL, pat, &result); FcPatternGetString(match, FC_FILE, 0, (FcChar8 **) &file); FcPatternGetInteger(match, FC_INDEX, 0, &index); font = ftglCreateExtrudeFont(file); if (!font) die("FTGL createFont", ""); FcPatternDestroy (match); FcPatternDestroy (pat); #ifdef OPENGL transX = transY = 0.0; zoomFactor = 1.0; resize(600, 600); #else viewPortL = viewPortT = 0.0; viewPortR = viewPortB = 200.0; zoomFactor = 3.0; resize(viewPortR * zoomFactor, viewPortB * zoomFactor); #endif SDL_WM_SetCaption("gcodeview", 0); drawLayer(currentLayer); layerVelocity = 0; timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); SDL_Event Event; while(Running != false) { if (busy) { Event.type = SDL_NOEVENT; SDL_PollEvent(&Event); } else { if (SDL_WaitEvent(&Event) == 0) die("SDL_WaitEvent", ""); } //SDL_RemoveTimer(timerIdle); switch (Event.type) { case SDL_NOEVENT: if (busy & BUSY_SCANFILE) { // TODO: scan next layer scanLine(); if ((busy & BUSY_SCANFILE) == 0) { if (cache) { printf("File scanned, rendering...\n"); busy = BUSY_RENDER; } else { printf("File scanned.\n"); busy = 0; } } } else if ((busy & BUSY_RENDER) && cache) { bool allRendered = true; int i; // TODO: render next layer in background for (i = 0; i < layerCount; i++) { if (layer[i].glList == 0) { layer[i].glList = glGenLists(1); glNewList(layer[i].glList, GL_COMPILE); glBegin(GL_QUADS); for (int j = SHADOW_LAYERS; j >= 1; j--) { if (i - j > 0) render_layer(i - j, SHADOW_ALPHA - (j - 1) * (SHADOW_ALPHA / SHADOW_LAYERS)); } render_layer(i, 1.0); glEnd(); glEndList(); layer[i].flags |= LD_LISTGENERATED; allRendered = false; break; } } if (allRendered) { printf("All %d layers rendered\n", i); busy &= ~BUSY_RENDER; } } break; case SDL_QUIT: Running = false; break; case SDL_VIDEORESIZE: resize(Event.resize.w, Event.resize.h); break; case SDL_VIDEOEXPOSE: render(); break; case SDL_MOUSEBUTTONDOWN: handle_mousedown(Event.button); break; case SDL_MOUSEBUTTONUP: handle_mouseup(Event.button); break; case SDL_MOUSEMOTION: handle_mousemove(Event.motion); break; case SDL_ACTIVEEVENT: // lose or gain focus break; case SDL_KEYDOWN: handle_keydown(Event.key); break; case SDL_KEYUP: handle_keyup(Event.key); break; case SDL_USEREVENT: handle_userevent(Event.user); break; default: printf("SDL Event %d\n", Event.type); break; } //idle code //if (busy) // timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); } if (timerKeyRepeat) SDL_RemoveTimer(timerKeyRepeat); if (timerDragRender) SDL_RemoveTimer(timerDragRender); free(layer); SDL_FreeSurface(Surf_Display); SDL_Quit(); return 0; }
static int load_font_fontconfig(AVFilterContext *ctx) { DrawTextContext *s = ctx->priv; FcConfig *fontconfig; FcPattern *pat, *best; FcResult result = FcResultMatch; FcChar8 *filename; int index; double size; int err = AVERROR(ENOENT); fontconfig = FcInitLoadConfigAndFonts(); if (!fontconfig) { av_log(ctx, AV_LOG_ERROR, "impossible to init fontconfig\n"); return AVERROR_UNKNOWN; } pat = FcNameParse(s->fontfile ? s->fontfile : (uint8_t *)(intptr_t)"default"); if (!pat) { av_log(ctx, AV_LOG_ERROR, "could not parse fontconfig pat"); return AVERROR(EINVAL); } FcPatternAddString(pat, FC_FAMILY, s->font); if (s->fontsize) FcPatternAddDouble(pat, FC_SIZE, (double)s->fontsize); FcDefaultSubstitute(pat); if (!FcConfigSubstitute(fontconfig, pat, FcMatchPattern)) { av_log(ctx, AV_LOG_ERROR, "could not substitue fontconfig options"); /* very unlikely */ FcPatternDestroy(pat); return AVERROR(ENOMEM); } best = FcFontMatch(fontconfig, pat, &result); FcPatternDestroy(pat); if (!best || result != FcResultMatch) { av_log(ctx, AV_LOG_ERROR, "Cannot find a valid font for the family %s\n", s->font); goto fail; } if ( FcPatternGetInteger(best, FC_INDEX, 0, &index ) != FcResultMatch || FcPatternGetDouble (best, FC_SIZE, 0, &size ) != FcResultMatch) { av_log(ctx, AV_LOG_ERROR, "impossible to find font information"); return AVERROR(EINVAL); } if (FcPatternGetString(best, FC_FILE, 0, &filename) != FcResultMatch) { av_log(ctx, AV_LOG_ERROR, "No file path for %s\n", s->font); goto fail; } av_log(ctx, AV_LOG_INFO, "Using \"%s\"\n", filename); if (!s->fontsize) s->fontsize = size + 0.5; err = load_font_file(ctx, filename, index); if (err) return err; FcConfigDestroy(fontconfig); fail: FcPatternDestroy(best); return err; }
TextAsset::TextAsset(const std::string& textContent, TextboxStylePtr style) : _error(false), _loading(false), _loaded(false), _textContent(textContent), _style(style), _fontName(style->getFont().getFullName()), _minFontSize(style->getMinFontSize() * CLIENT_PIXEL_CONVERSION), _maxFontSize(style->getMaxFontSize() * CLIENT_PIXEL_CONVERSION), _fontSize(style->getFontSize() * CLIENT_PIXEL_CONVERSION), _maxSize(style->getWidth() * SERVER_PIXEL_CONVERSION, style->getHeight() * SERVER_PIXEL_CONVERSION), _resizeFont(style->getResizeFont()), _fitWidthToText(style->getFitWidthToText()), _fitHeightToText(style->getFitHeightToText()), _leadingMultiplier(style->getLeadingMultiplier()), _kern(style->getKern() * CLIENT_TO_SERVER_SCALE), _textColor(style->getTextColor()), _bgColor(style->getBackgroundColor()), _alignment(convertAlignment(style->getAlignment())), _dropShadow(style->getDropShadow()), _dropShadowOffset(style->getDropShadowOffset()), _dropShadowColor(style->getDropShadowColor()), _shape(style->getBackgroundShape()), _strokeThickness(style->getStrokeThickness() * CLIENT_TO_SERVER_SCALE), // CoreText's outline thickness is expressed as a percentage of client font size, so it depends on the final font size. _outlineThickness(style->getTextOutlineWidth()), _outlineColor(style->getTextOutlineColor()) { // TODO: Create server font manager if (!sFontsLoaded) { // TODO: Fix this to use a config settings FcConfig* config = FcInitLoadConfigAndFonts(); FcConfigParseAndLoad(config, reinterpret_cast<const FcChar8*>("~/Documents/MediaFramework/Styles/fonts/font_table.fonts"), FcFalse); sFontsLoaded = true; } if (!_fontTable[_fontName].isNull()) { _fontName = _fontTable[_fontName].asString(); } else { printf("No font mapping for \"%s\"\n", _fontName.c_str()); } const float border = style->getBorder(); style->getSideMargins(_marginLeft, _marginRight, _marginTop, _marginBottom); _marginLeft += border; _marginRight += border; _marginTop += border; _marginBottom += border; _marginLeft *= SERVER_PIXEL_CONVERSION; _marginRight *= SERVER_PIXEL_CONVERSION; _marginTop *= SERVER_PIXEL_CONVERSION; _marginBottom *= SERVER_PIXEL_CONVERSION; const mf::Vec2 cornerRadius = style->getCornerRadius(); _cornerWidth = cornerRadius.x() * SERVER_PIXEL_CONVERSION; _cornerHeight = cornerRadius.y() * SERVER_PIXEL_CONVERSION; // Trim off unwanted whitespace. // NOTE: We could remove all whitespace at beginning and end of string, // but for now just taking off the last character if it is a newline. if (!_textContent.empty()) { if (_textContent[_textContent.size()-1] == '\n') { _textContent = _textContent.substr(0, _textContent.size()-1); } } }
/** * Init and load font **/ OpenGLFont::OpenGLFont(RenderOpenGL* render, string name, Mod* mod, float size) { int error; // Basics this->pmpl = new OpenGLFont_Implementation(); this->render = render; this->size = size; // Init freetype // TODO: Should we share the tf ptr between OpenGLFont instances error = FT_Init_FreeType(&this->pmpl->ft); if (error) { reportFatalError("Freetype: Unable to init library."); } // On Linux, the system font is found using fontconfig #if defined(__linux__) FcConfig* config = FcInitLoadConfigAndFonts(); FcPattern* pat = FcPatternBuild( NULL, FC_FAMILY, FcTypeString, reinterpret_cast<const char*>(name.c_str()), NULL ); FcConfigSubstitute(config, pat, FcMatchPattern); FcDefaultSubstitute(pat); FcResult result; FcPattern* font = FcFontMatch(config, pat, &result); if (font == NULL) { reportFatalError("Fontconfig: Unable to find font " + name); } FcChar8* filename = NULL; if (FcPatternGetString(font, FC_FILE, 0, &filename) != FcResultMatch) { reportFatalError("Fontconfig: No filename in fontconfig match"); } error = FT_New_Face(this->pmpl->ft, reinterpret_cast<const char*>(filename), 0, &this->pmpl->face); FcPatternDestroy(font); FcPatternDestroy(pat); #else // All other systems use a file in the cr/ mod Sint64 len; name.append(".ttf"); this->pmpl->buf = mod->loadBinary(name, &len); if (this->pmpl->buf == NULL) { reportFatalError("Freetype: Unable to load data"); } error = FT_New_Memory_Face(this->pmpl->ft, (const FT_Byte *) this->pmpl->buf, (FT_Long)len, 0, &this->pmpl->face); #endif // Handle errors if (error == FT_Err_Unknown_File_Format) { reportFatalError("Freetype: Unsupported font format"); } else if (error) { reportFatalError("Freetype: Unable to load font"); } // Set character size error = FT_Set_Char_Size(this->pmpl->face, 0, size * 64, 72, 72); if (error) { reportFatalError("Freetype: Unable to load font size"); } }