Kaydet (Commit) a4196e56 authored tarafından Caolán McNamara's avatar Caolán McNamara

adjust auto font installation

to happen on a 5 second timer and collect up as much missing
stuff in one go as we can

Change-Id: I79f5e70634684a2ef83e3090790531149baf529b
üst feddd3d8
......@@ -846,64 +846,71 @@ namespace
return LanguageTag(OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8));
}
int autoInstallFontLangSupport(const std::vector<OString> &rNewReqs, guint xid)
guint get_xid_for_dbus()
{
GError *error = NULL;
/* get the DBUS session connection */
DBusGConnection *session_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL)
{
g_warning ("DBUS cannot connect : %s", error->message);
g_error_free (error);
return -1;
}
const Window *pTopWindow = Application::IsHeadlessModeEnabled() ? NULL : Application::GetActiveTopWindow();
const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL;
return pEnvData ? pEnvData->aWindow : 0;
}
#endif
}
/* get the proxy with gnome-session-manager */
DBusGProxy *proxy = dbus_g_proxy_new_for_name(session_connection,
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify");
if (proxy == NULL)
{
g_warning("Could not get DBUS proxy: org.freedesktop.PackageKit");
return -1;
}
IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport)
{
guint xid = get_xid_for_dbus();
gchar **fonts = (gchar**)g_malloc((rNewReqs.size() + 1) * sizeof(gchar*));
gchar **font = fonts;
for (std::vector<OString>::const_iterator aI = rNewReqs.begin(); aI != rNewReqs.end(); ++aI)
*font++ = (gchar*)aI->getStr();
*font = NULL;
gboolean res = dbus_g_proxy_call(proxy, "InstallFontconfigResources", &error,
G_TYPE_UINT, xid, /* xid */
G_TYPE_STRV, fonts, /* data */
G_TYPE_STRING, "hide-finished", /* interaction */
G_TYPE_INVALID,
G_TYPE_INVALID);
/* check the return value */
if (!res)
g_warning("InstallFontconfigResources method failed");
/* check the error value */
if (error != NULL)
{
g_warning("InstallFontconfigResources problem : %s", error->message);
g_error_free(error);
}
if (!xid)
return -1;
g_free(fonts);
g_object_unref(G_OBJECT (proxy));
#ifdef ENABLE_DBUS
GError *error = NULL;
/* get the DBUS session connection */
DBusGConnection *session_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL)
{
g_warning ("DBUS cannot connect : %s", error->message);
g_error_free (error);
return -1;
}
return 0;
/* get the proxy with gnome-session-manager */
DBusGProxy *proxy = dbus_g_proxy_new_for_name(session_connection,
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify");
if (proxy == NULL)
{
g_warning("Could not get DBUS proxy: org.freedesktop.PackageKit");
return -1;
}
guint get_xid_for_dbus()
gchar **fonts = (gchar**)g_malloc((m_aCurrentRequests.size() + 1) * sizeof(gchar*));
gchar **font = fonts;
for (std::vector<OString>::const_iterator aI = m_aCurrentRequests.begin(); aI != m_aCurrentRequests.end(); ++aI)
*font++ = (gchar*)aI->getStr();
*font = NULL;
gboolean res = dbus_g_proxy_call(proxy, "InstallFontconfigResources", &error,
G_TYPE_UINT, xid, /* xid */
G_TYPE_STRV, fonts, /* data */
G_TYPE_STRING, "hide-finished", /* interaction */
G_TYPE_INVALID,
G_TYPE_INVALID);
/* check the return value */
if (!res)
g_warning("InstallFontconfigResources method failed");
/* check the error value */
if (error != NULL)
{
const Window *pTopWindow = Application::IsHeadlessModeEnabled() ? NULL : Application::GetActiveTopWindow();
const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL;
return pEnvData ? pEnvData->aWindow : 0;
g_warning("InstallFontconfigResources problem : %s", error->message);
g_error_free(error);
}
g_free(fonts);
g_object_unref(G_OBJECT (proxy));
m_aCurrentRequests.clear();
#endif
return 0;
}
bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes )
......@@ -1050,10 +1057,8 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
}
OUString sStillMissing(pRemainingCodes, nRemainingLen);
#ifdef ENABLE_DBUS
guint xid = get_xid_for_dbus();
if (xid)
if (get_xid_for_dbus())
{
std::vector<OString> aNewRequests;
if (sStillMissing == rMissingCodes) //replaced nothing
{
//It'd be better if we could ask packagekit using the
......@@ -1071,13 +1076,16 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
if (!sTag.isEmpty() && m_aPreviousLangSupportRequests.find(sTag) == m_aPreviousLangSupportRequests.end())
{
OString sReq = OString(":lang=") + sTag;
aNewRequests.push_back(sReq);
m_aCurrentRequests.push_back(sReq);
m_aPreviousLangSupportRequests.insert(sTag);
}
}
}
if (!aNewRequests.empty())
autoInstallFontLangSupport(aNewRequests, xid);
if (!m_aCurrentRequests.empty())
{
m_aFontInstallerTimer.Stop();
m_aFontInstallerTimer.Start();
}
}
#endif
rMissingCodes = sStillMissing;
......
......@@ -1018,12 +1018,16 @@ PrintFontManager::PrintFontManager()
m_aAdobecodeToUnicode.insert( ::boost::unordered_multimap< sal_uInt8, sal_Unicode >::value_type( aAdobeCodes[i].aAdobeStandardCode, aAdobeCodes[i].aUnicode ) );
}
}
m_aFontInstallerTimer.SetTimeoutHdl(LINK(this, PrintFontManager, autoInstallFontLangSupport));
m_aFontInstallerTimer.SetTimeout(5000);
}
// -------------------------------------------------------------------------
PrintFontManager::~PrintFontManager()
{
m_aFontInstallerTimer.Stop();
deinitFontconfig();
for( ::boost::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
delete (*it).second;
......
......@@ -36,6 +36,7 @@
#include "vcl/dllapi.h"
#include "vcl/helper.hxx"
#include "vcl/timer.hxx"
#include "vcl/vclenum.hxx"
#include "com/sun/star/lang/Locale.hpp"
......@@ -354,6 +355,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
bool readOverrideMetrics();
std::set<OString> m_aPreviousLangSupportRequests;
std::vector<OString> m_aCurrentRequests;
Timer m_aFontInstallerTimer;
DECL_LINK( autoInstallFontLangSupport, void* );
PrintFontManager();
~PrintFontManager();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment