58
58
and performs CSS adaptions to the current GTK theme. */
60
60
static renderParamPtr langParams = NULL; /* the current locale settings (for localization stylesheet) */
61
static gchar *defaultParams = NULL; /* some default parameters (for rendering stylesheets) */
63
62
static GHashTable *stylesheets = NULL; /* XSLT stylesheet cache */
68
gchar **shortlang = NULL; /* e.g. "de" */
69
gchar **lang = NULL; /* e.g. "de_AT" */
67
gchar **shortlang = NULL; /* e.g. "de" */
68
gchar **lang = NULL; /* e.g. "de_AT" */
72
72
render_parameter_free (langParams);
74
g_free (defaultParams);
76
/* prepare localization parameters */
74
/* Install default stylesheet if it does not yet exist */
75
filename = common_create_cache_filename ("", "liferea", "css");
76
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
77
common_copy_file (PACKAGE_DATA_DIR "/" PACKAGE "/css/user.css", filename);
80
/* Prepare localization parameters */
77
81
debug1 (DEBUG_HTML, "XSLT localisation: setlocale(LC_MESSAGES, NULL) reports '%s'", setlocale(LC_MESSAGES, NULL));
78
82
lang = g_strsplit (setlocale (LC_MESSAGES, NULL), "@", 0);
79
83
shortlang = g_strsplit (setlocale (LC_MESSAGES, NULL), "_", 0);
229
render_remove_css_comments (void)
231
gssize i, len = css->len;
232
gchar *str = css->str;
235
newcss = g_string_new(NULL);
238
if (i+1 < len && str[i] == '/' && str[i+1] == '*') {
240
while (i-1 < len && (str[i-2] != '*' || str[i-1] != '/'))
244
if (i+1 < len && str[i] == '/' && str[i+1] == '/') {
246
while (i < len && str[i] != '\n')
250
newcss = g_string_append_c(newcss, str[i]);
253
g_string_free(css, TRUE);
258
229
render_get_css (gboolean externalCss)
260
gchar *styleSheetFile;
261
time_t newLastModification;
263
styleSheetFile = g_build_filename (common_get_cache_path (), "liferea.css", NULL);
264
newLastModification = common_get_mod_time ((char *)styleSheetFile);
266
if (!css || lastCssModification != newLastModification) {
267
gchar *defaultStyleSheetFile, *adblockStyleSheetFile;
269
gchar *fontsize = NULL;
232
gchar *defaultStyleSheetFile;
233
gchar *userStyleSheetFile;
234
gchar *adblockStyleSheetFile;
272
// Update last modification timestamp
273
lastCssModification = newLastModification;
275
if (themeColors == NULL) {
276
238
render_get_theme_colors();
279
240
css = g_string_new(NULL);
281
/* font configuration support */
282
font = conf_get_str_value (USER_FONT);
283
if(0 == strlen(font)) {
285
font = conf_get_str_value (DEFAULT_FONT);
290
/* the GTK2/GNOME font name format is <font name>,<font size in point>
291
Or it can also be "Font Name size*/
292
strsep(&fontsize, ",");
293
if(fontsize == NULL) {
294
if(NULL != (fontsize = strrchr(font, ' '))) {
299
g_string_append(css, "body, table, div {");
300
g_string_append_printf(css, "font-family: %s;\n", font);
303
g_string_append_printf(css, "font-size: %spt;\n", fontsize);
306
g_string_append(css, "}\n");
309
242
defaultStyleSheetFile = g_build_filename (PACKAGE_DATA_DIR, PACKAGE, "css", "liferea.css", NULL);
311
244
if (g_file_get_contents(defaultStyleSheetFile, &tmp, NULL, NULL)) {
312
245
tmp = render_set_theme_colors(tmp);
313
246
g_string_append(css, tmp);
317
if (g_file_get_contents(styleSheetFile, &tmp, NULL, NULL)) {
318
tmp = render_set_theme_colors(tmp);
319
g_string_append(css, tmp);
249
g_error ("Loading %s failed.", defaultStyleSheetFile);
323
252
g_free(defaultStyleSheetFile);
254
userStyleSheetFile = g_build_filename (common_get_cache_path (), "liferea.css", NULL);
256
if (g_file_get_contents(userStyleSheetFile, &tmp, NULL, NULL)) {
257
tmp = render_set_theme_colors(tmp);
258
g_string_append(css, tmp);
262
g_free(userStyleSheetFile);
325
264
adblockStyleSheetFile = g_build_filename(PACKAGE_DATA_DIR, PACKAGE, "css", "adblock.css", NULL);
327
266
if (g_file_get_contents(adblockStyleSheetFile, &tmp, NULL, NULL)) {
375
309
paramSet = render_parameter_new ();
376
render_parameter_add (paramSet, "%s", defaultParams);
310
render_parameter_add (paramSet, "pixmapsDir='file://" PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "'");
378
resDoc = xsltApplyStylesheet(xslt, doc, (const gchar **)paramSet->params);
312
resDoc = xsltApplyStylesheet (xslt, doc, (const gchar **)paramSet->params);
380
314
g_warning ("fatal: applying rendering stylesheet (%s) failed!", xsltName);