| 366 | | |
|---|
| 367 | | p_sys->p_fontconfig = FcInitLoadConfig(); |
|---|
| 368 | | |
|---|
| 369 | | if( p_sys->p_fontconfig ) |
|---|
| 370 | | { |
|---|
| 371 | | /* Normally this doesn't take very long, but an initial build of |
|---|
| 372 | | * the fontconfig database or the addition of a lot of new fonts |
|---|
| 373 | | * can cause it to take several minutes for a large number of fonts. |
|---|
| 374 | | * Even a small number can take several seconds - much longer than |
|---|
| 375 | | * we can afford to block, so we build the list in the background |
|---|
| 376 | | * and if it succeeds we allow fontconfig to be used. |
|---|
| | 369 | p_sys->p_fontconfig = NULL; |
|---|
| | 370 | |
|---|
| | 371 | /* Check for an existing Fontbuilder thread */ |
|---|
| | 372 | lock = var_AcquireMutex( "fontbuilder" ); |
|---|
| | 373 | p_fontbuilder = vlc_object_find_name( p_filter->p_libvlc, |
|---|
| | 374 | "fontlist builder", |
|---|
| | 375 | FIND_CHILD ); |
|---|
| | 376 | |
|---|
| | 377 | if( ! p_fontbuilder ) |
|---|
| | 378 | { |
|---|
| | 379 | /* Create the FontBuilder thread as a child of a top-level |
|---|
| | 380 | * object, so that it can survive the destruction of the |
|---|
| | 381 | * freetype object - the fontlist only needs to be built once, |
|---|
| | 382 | * and calling the fontbuild a second time while the first is |
|---|
| | 383 | * still in progress can cause thread instabilities. |
|---|
| 378 | | if( vlc_thread_create( p_filter, "fontlist builder", FontBuilder, |
|---|
| 379 | | VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) ) |
|---|
| 380 | | { |
|---|
| 381 | | /* Don't destroy the fontconfig object - we won't be able to do |
|---|
| 382 | | * italics or bold or change the font face, but we will still |
|---|
| 383 | | * be able to do underline and change the font size. |
|---|
| 384 | | */ |
|---|
| 385 | | msg_Warn( p_filter, "fontconfig database builder thread can't " |
|---|
| 386 | | "be launched. Font styling support will be limited." ); |
|---|
| 387 | | }; |
|---|
| | 385 | |
|---|
| | 386 | p_fontbuilder = vlc_object_create( p_filter->p_libvlc, |
|---|
| | 387 | VLC_OBJECT_GENERIC ); |
|---|
| | 388 | if( p_fontbuilder ) |
|---|
| | 389 | { |
|---|
| | 390 | p_fontbuilder->psz_object_name = "fontlist builder"; |
|---|
| | 391 | vlc_object_attach( p_fontbuilder, p_filter->p_libvlc ); |
|---|
| | 392 | |
|---|
| | 393 | var_Create( p_fontbuilder, "build-done", VLC_VAR_BOOL ); |
|---|
| | 394 | var_SetBool( p_fontbuilder, "build-done", VLC_FALSE ); |
|---|
| | 395 | |
|---|
| | 396 | if( vlc_thread_create( p_fontbuilder, |
|---|
| | 397 | "fontlist builder", |
|---|
| | 398 | FontBuilder, |
|---|
| | 399 | VLC_THREAD_PRIORITY_LOW, |
|---|
| | 400 | VLC_FALSE ) ) |
|---|
| | 401 | { |
|---|
| | 402 | /* Don't destroy the fontconfig object - we won't be able to do |
|---|
| | 403 | * italics or bold or change the font face, but we will still |
|---|
| | 404 | * be able to do underline and change the font size. |
|---|
| | 405 | */ |
|---|
| | 406 | msg_Warn( p_filter, "fontconfig database builder thread can't " |
|---|
| | 407 | "be launched. Font styling support will be limited." ); |
|---|
| | 408 | } |
|---|
| | 409 | } |
|---|
| | 410 | else |
|---|
| | 411 | { |
|---|
| | 412 | vlc_object_destroy( p_fontbuilder ); |
|---|
| | 413 | } |
|---|
| 472 | | filter_t *p_filter = (filter_t*)p_this; |
|---|
| 473 | | filter_sys_t *p_sys = p_filter->p_sys; |
|---|
| 474 | | time_t t1, t2; |
|---|
| 475 | | |
|---|
| 476 | | /* Find the session to announce */ |
|---|
| 477 | | vlc_mutex_lock( &p_sys->fontconfig_lock ); |
|---|
| 478 | | |
|---|
| 479 | | msg_Dbg( p_filter, "Building font database..." ); |
|---|
| 480 | | time(&t1); |
|---|
| 481 | | if(! FcConfigBuildFonts( p_sys->p_fontconfig )) |
|---|
| 482 | | { |
|---|
| 483 | | /* Don't destroy the fontconfig object - we won't be able to do |
|---|
| 484 | | * italics or bold or change the font face, but we will still |
|---|
| 485 | | * be able to do underline and change the font size. |
|---|
| 486 | | */ |
|---|
| 487 | | msg_Err( p_filter, "fontconfig database can't be built. " |
|---|
| 488 | | "Font styling won't be available" ); |
|---|
| 489 | | } |
|---|
| 490 | | time(&t2); |
|---|
| 491 | | |
|---|
| 492 | | msg_Dbg( p_filter, "Finished building font database." ); |
|---|
| 493 | | if( t1 > 0 && t2 > 0 ) |
|---|
| 494 | | msg_Dbg( p_filter, "Took %ld seconds", t2 - t1 ); |
|---|
| 495 | | |
|---|
| 496 | | p_sys->b_fontconfig_ok = VLC_TRUE; |
|---|
| 497 | | |
|---|
| 498 | | vlc_mutex_unlock( &p_sys->fontconfig_lock ); |
|---|
| | 496 | FcConfig *p_fontconfig = FcInitLoadConfig(); |
|---|
| | 497 | vlc_mutex_t *lock; |
|---|
| | 498 | |
|---|
| | 499 | vlc_thread_ready( p_this ); |
|---|
| | 500 | |
|---|
| | 501 | if( p_fontconfig ) |
|---|
| | 502 | { |
|---|
| | 503 | time_t t1, t2; |
|---|
| | 504 | |
|---|
| | 505 | msg_Dbg( p_this, "Building font database..." ); |
|---|
| | 506 | time( &t1 ); |
|---|
| | 507 | if(! FcConfigBuildFonts( p_fontconfig )) |
|---|
| | 508 | { |
|---|
| | 509 | /* Don't destroy the fontconfig object - we won't be able to do |
|---|
| | 510 | * italics or bold or change the font face, but we will still |
|---|
| | 511 | * be able to do underline and change the font size. |
|---|
| | 512 | */ |
|---|
| | 513 | msg_Err( p_this, "fontconfig database can't be built. " |
|---|
| | 514 | "Font styling won't be available" ); |
|---|
| | 515 | } |
|---|
| | 516 | time( &t2 ); |
|---|
| | 517 | |
|---|
| | 518 | msg_Dbg( p_this, "Finished building font database." ); |
|---|
| | 519 | if( t1 > 0 && t2 > 0 ) |
|---|
| | 520 | msg_Dbg( p_this, "Took %ld seconds", t2 - t1 ); |
|---|
| | 521 | |
|---|
| | 522 | lock = var_AcquireMutex( "fontbuilder" ); |
|---|
| | 523 | var_SetBool( p_this, "build-done", VLC_TRUE ); |
|---|
| | 524 | |
|---|
| | 525 | FcConfigDestroy( p_fontconfig ); |
|---|
| | 526 | vlc_mutex_unlock( lock ); |
|---|
| | 527 | } |
|---|
| | 2185 | static int CheckIfFontBuildComplete( filter_t *p_filter ) |
|---|
| | 2186 | { |
|---|
| | 2187 | filter_sys_t *p_sys = p_filter->p_sys; |
|---|
| | 2188 | vlc_object_t *p_fb = vlc_object_find_name( p_filter->p_libvlc, |
|---|
| | 2189 | "fontlist builder", |
|---|
| | 2190 | FIND_CHILD ); |
|---|
| | 2191 | if( p_fb ) |
|---|
| | 2192 | { |
|---|
| | 2193 | vlc_mutex_t *lock = var_AcquireMutex( "fontbuilder" ); |
|---|
| | 2194 | vlc_value_t val; |
|---|
| | 2195 | |
|---|
| | 2196 | if( VLC_SUCCESS == var_Get( p_fb, "build-done", &val )) |
|---|
| | 2197 | { |
|---|
| | 2198 | p_sys->b_fontconfig_ok = val.b_bool; |
|---|
| | 2199 | |
|---|
| | 2200 | if( p_sys->b_fontconfig_ok ) |
|---|
| | 2201 | { |
|---|
| | 2202 | FcInit(); |
|---|
| | 2203 | p_sys->p_fontconfig = FcConfigGetCurrent(); |
|---|
| | 2204 | } |
|---|
| | 2205 | else |
|---|
| | 2206 | msg_Dbg( p_filter, "Font Build still not complete" ); |
|---|
| | 2207 | } |
|---|
| | 2208 | vlc_mutex_unlock( lock ); |
|---|
| | 2209 | vlc_object_release( p_fb ); |
|---|
| | 2210 | |
|---|
| | 2211 | return VLC_SUCCESS; |
|---|
| | 2212 | } |
|---|
| | 2213 | return VLC_EGENERIC; |
|---|
| | 2214 | } |
|---|
| | 2215 | |
|---|