| 1 |
/* font-manager-reject.c |
| 2 |
* |
| 3 |
* Copyright (C) 2009-2025 Jerry Casiano |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. |
| 17 |
* |
| 18 |
* If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "font-manager-reject.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* SECTION: font-manager-reject |
| 25 |
* @short_description: Fontconfig font selection configuration |
| 26 |
* @title: Disabled Fonts |
| 27 |
* @include: font-manager-reject.h |
| 28 |
* |
| 29 |
* Set of font families that should be excluded from the set of fonts used to resolve |
| 30 |
* list and match requests as if they didn't exist in the system. |
| 31 |
*/ |
| 32 |
|
| 33 |
G_DEFINE_TYPE(FontManagerReject, font_manager_reject, FONT_MANAGER_TYPE_SELECTIONS) |
| 34 |
|
| 35 |
static void |
| 36 |
font_manager_reject_class_init (FontManagerRejectClass *klass) |
| 37 |
{ |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
static void |
| 42 |
font_manager_reject_init (FontManagerReject *self) |
| 43 |
{ |
| 44 |
g_autofree gchar *config_dir = font_manager_get_user_fontconfig_directory(); |
| 45 |
g_object_set(G_OBJECT(self), |
| 46 |
"config-dir", config_dir, |
| 47 |
"target-element", "rejectfont", |
| 48 |
"target-file", "78-Reject.conf", |
| 49 |
NULL); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* font_manager_reject_get_rejected_files: |
| 55 |
* @self: #FontManagerReject |
| 56 |
* @db: #FontManagerDatabase |
| 57 |
* @error: #GError or %NULL to ignore errors |
| 58 |
* |
| 59 |
* Returns: (transfer full) (nullable): |
| 60 |
* A set of filepaths for all currently blacklisted fonts or %NULL if there was an error. |
| 61 |
* Free the returned object using #g_object_unref(). |
| 62 |
*/ |
| 63 |
FontManagerStringSet * |
| 64 |
font_manager_reject_get_rejected_files (FontManagerReject *self, |
| 65 |
FontManagerDatabase *db, |
| 66 |
GError **error) |
| 67 |
{ |
| 68 |
g_return_val_if_fail(self != NULL, NULL); |
| 69 |
g_return_val_if_fail((error == NULL || *error == NULL), NULL); |
| 70 |
g_autoptr(FontManagerStringSet) rejected_files = font_manager_string_set_new(); |
| 71 |
g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
| 72 |
guint len_rejected = font_manager_string_set_size(FONT_MANAGER_STRING_SET(self)); |
| 73 |
const gchar *_sql = "SELECT DISTINCT filepath FROM Fonts WHERE family = %s"; |
| 74 |
for (guint i = 0; i < len_rejected; i++) { |
| 75 |
const gchar *data = font_manager_string_set_get(FONT_MANAGER_STRING_SET(self), i); |
| 76 |
char *family = sqlite3_mprintf("%Q", (char *) data); |
| 77 |
g_autofree gchar *sql = g_strdup_printf(_sql, family); |
| 78 |
sqlite3_free(family); |
| 79 |
font_manager_database_execute_query(db, sql, error); |
| 80 |
g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
| 81 |
g_autoptr(FontManagerDatabaseIterator) db_iter = font_manager_database_iterator_new(db); |
| 82 |
while (font_manager_database_iterator_next(db_iter)) { |
| 83 |
sqlite3_stmt *stmt = font_manager_database_iterator_get(db_iter); |
| 84 |
const gchar *path = (const gchar *) sqlite3_column_text(stmt, 0); |
| 85 |
if (font_manager_exists(path)) |
| 86 |
font_manager_string_set_add(rejected_files, path); |
| 87 |
} |
| 88 |
font_manager_database_end_query(db); |
| 89 |
} |
| 90 |
return g_steal_pointer(&rejected_files); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* font_manager_reject_new: |
| 95 |
* |
| 96 |
* Returns: (transfer full): A newly created #FontManagerReject. |
| 97 |
* Free the returned object using #g_object_unref(). |
| 98 |
*/ |
| 99 |
FontManagerReject * |
| 100 |
font_manager_reject_new (void) |
| 101 |
{ |
| 102 |
|
| 103 |
return g_object_new(FONT_MANAGER_TYPE_REJECT, NULL); |
| 104 |
} |