diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 266530b02c04..93575c874010 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -920,8 +920,35 @@ gfxFontConfigFont::GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams) } #endif +gfxFcPlatformFontList::gfxFcPlatformFontList() + : mLocalNames(64), mGenericMappings(32), mLastConfig(nullptr) +{ + // if the rescan interval is set, start the timer + int rescanInterval = FcConfigGetRescanInterval(nullptr); + if (rescanInterval) { + mLastConfig = FcConfigGetCurrent(); + mCheckFontUpdatesTimer = do_CreateInstance("@mozilla.org/timer;1"); + if (mCheckFontUpdatesTimer) { + mCheckFontUpdatesTimer-> + InitWithFuncCallback(CheckFontUpdates, this, + (rescanInterval + 1) * 1000, + nsITimer::TYPE_REPEATING_SLACK); + } else { + NS_WARNING("Failure to create font updates timer"); + } + } + +#ifdef MOZ_BUNDLED_FONTS + mBundledFontsInitialized = false; +#endif +} + gfxFcPlatformFontList::~gfxFcPlatformFontList() { + if (mCheckFontUpdatesTimer) { + mCheckFontUpdatesTimer->Cancel(); + mCheckFontUpdatesTimer = nullptr; + } } void @@ -1008,6 +1035,8 @@ gfxFcPlatformFontList::AddFontSetFamilies(FcFontSet* aFontSet) nsresult gfxFcPlatformFontList::InitFontList() { + mLastConfig = FcConfigGetCurrent(); + // reset font lists gfxPlatformFontList::InitFontList(); @@ -1394,6 +1423,21 @@ gfxFcPlatformFontList::FindGenericFamily(const nsAString& aGeneric, return genericFamily; } +/* static */ void +gfxFcPlatformFontList::CheckFontUpdates(nsITimer *aTimer, void *aThis) +{ + // check for font updates + FcInitBringUptoDate(); + + // update fontlist if current config changed + gfxFcPlatformFontList *pfl = static_cast(aThis); + FcConfig* current = FcConfigGetCurrent(); + if (current != pfl->GetLastConfig()) { + pfl->UpdateFontList(); + pfl->ForceGlobalReflow(); + } +} + #ifdef MOZ_BUNDLED_FONTS void gfxFcPlatformFontList::ActivateBundledFonts() diff --git a/gfx/thebes/gfxFcPlatformFontList.h b/gfx/thebes/gfxFcPlatformFontList.h index b17b61801f86..b10f76b4e6f9 100644 --- a/gfx/thebes/gfxFcPlatformFontList.h +++ b/gfx/thebes/gfxFcPlatformFontList.h @@ -28,6 +28,13 @@ public: static void Release(FcObjectSet *ptr) { FcObjectSetDestroy(ptr); } }; +template <> +class nsAutoRefTraits : public nsPointerRefTraits +{ +public: + static void Release(FcConfig *ptr) { FcConfigDestroy(ptr); } + static void AddRef(FcConfig *ptr) { FcConfigReference(ptr); } +}; // Helper classes used for clearning out user font data when cairo font // face is destroyed. Since multiple faces may use the same data, be @@ -187,13 +194,7 @@ protected: class gfxFcPlatformFontList : public gfxPlatformFontList { public: - gfxFcPlatformFontList() - : mLocalNames(64), mGenericMappings(32) - { -#ifdef MOZ_BUNDLED_FONTS - mBundledFontsInitialized = false; -#endif - } + gfxFcPlatformFontList(); // initialize font lists nsresult InitFontList() override; @@ -223,6 +224,8 @@ public: bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) override; + FcConfig* GetLastConfig() const { return mLastConfig; } + static FT_Library GetFTLibrary(); protected: @@ -236,6 +239,8 @@ protected: gfxFontFamily* FindGenericFamily(const nsAString& aGeneric, nsIAtom* aLanguage); + static void CheckFontUpdates(nsITimer *aTimer, void *aThis); + #ifdef MOZ_BUNDLED_FONTS void ActivateBundledFonts(); nsCString mBundledFontsPath; @@ -249,6 +254,9 @@ protected: // caching generic/lang ==> font family nsRefPtrHashtable mGenericMappings; + nsCOMPtr mCheckFontUpdatesTimer; + nsCountedRef mLastConfig; + static FT_Library sCairoFTLibrary; };