| 1 | /* -*- Mode: C; c-basic-offset: 4 -*- |
|---|
| 2 | * pygtk- Python bindings for the GTK toolkit. |
|---|
| 3 | * Copyright (C) 1998-2003 James Henstridge |
|---|
| 4 | * |
|---|
| 5 | * pangomodule.c: module wrapping the Pango library |
|---|
| 6 | * |
|---|
| 7 | * This library is free software; you can redistribute it and/or |
|---|
| 8 | * modify it under the terms of the GNU Lesser General Public |
|---|
| 9 | * License as published by the Free Software Foundation; either |
|---|
| 10 | * version 2.1 of the License, or (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This library is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 | * Lesser General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU Lesser General Public |
|---|
| 18 | * License along with this library; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 20 | * USA |
|---|
| 21 | */ |
|---|
| 22 | #ifdef HAVE_CONFIG_H |
|---|
| 23 | # include "config.h" |
|---|
| 24 | #endif |
|---|
| 25 | #include <Python.h> |
|---|
| 26 | #include <pygobject.h> |
|---|
| 27 | |
|---|
| 28 | #include <pango/pango-font.h> |
|---|
| 29 | |
|---|
| 30 | /* include any extra headers needed here */ |
|---|
| 31 | |
|---|
| 32 | void pypango_register_classes(PyObject *d); |
|---|
| 33 | void pypango_add_constants(PyObject *module, const gchar *strip_prefix); |
|---|
| 34 | extern PyMethodDef pypango_functions[]; |
|---|
| 35 | |
|---|
| 36 | #ifndef pyg_add_warning_redirection |
|---|
| 37 | |
|---|
| 38 | static void |
|---|
| 39 | _log_func(const gchar *log_domain, |
|---|
| 40 | GLogLevelFlags log_level, |
|---|
| 41 | const gchar *message, |
|---|
| 42 | gpointer user_data) |
|---|
| 43 | { |
|---|
| 44 | PyGILState_STATE state; |
|---|
| 45 | PyObject* warning = user_data; |
|---|
| 46 | |
|---|
| 47 | state = pyg_gil_state_ensure(); |
|---|
| 48 | PyErr_Warn(warning, (char *) message); |
|---|
| 49 | pyg_gil_state_release(state); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | DL_EXPORT(void) |
|---|
| 56 | initpango(void) |
|---|
| 57 | { |
|---|
| 58 | PyObject *m, *d; |
|---|
| 59 | PyObject *warning; |
|---|
| 60 | |
|---|
| 61 | /* perform any initialisation required by the library here */ |
|---|
| 62 | |
|---|
| 63 | m = Py_InitModule("pango", pypango_functions); |
|---|
| 64 | d = PyModule_GetDict(m); |
|---|
| 65 | |
|---|
| 66 | init_pygobject_check(2, 11, 1); |
|---|
| 67 | |
|---|
| 68 | /* set the default python encoding to utf-8 */ |
|---|
| 69 | PyUnicode_SetDefaultEncoding("utf-8"); |
|---|
| 70 | |
|---|
| 71 | pypango_register_classes(d); |
|---|
| 72 | pypango_add_constants(m, "PANGO_"); |
|---|
| 73 | |
|---|
| 74 | PyModule_AddObject(m, "SCALE_XX_SMALL", |
|---|
| 75 | PyFloat_FromDouble(PANGO_SCALE_XX_SMALL)); |
|---|
| 76 | PyModule_AddObject(m, "SCALE_X_SMALL", |
|---|
| 77 | PyFloat_FromDouble(PANGO_SCALE_X_SMALL)); |
|---|
| 78 | PyModule_AddObject(m, "SCALE_SMALL", |
|---|
| 79 | PyFloat_FromDouble(PANGO_SCALE_SMALL)); |
|---|
| 80 | PyModule_AddObject(m, "SCALE_MEDIUM", |
|---|
| 81 | PyFloat_FromDouble(PANGO_SCALE_MEDIUM)); |
|---|
| 82 | PyModule_AddObject(m, "SCALE_LARGE", |
|---|
| 83 | PyFloat_FromDouble(PANGO_SCALE_LARGE)); |
|---|
| 84 | PyModule_AddObject(m, "SCALE_X_LARGE", |
|---|
| 85 | PyFloat_FromDouble(PANGO_SCALE_X_LARGE)); |
|---|
| 86 | PyModule_AddObject(m, "SCALE_XX_LARGE", |
|---|
| 87 | PyFloat_FromDouble(PANGO_SCALE_XX_LARGE)); |
|---|
| 88 | PyModule_AddObject(m, "SCALE", |
|---|
| 89 | PyInt_FromLong(PANGO_SCALE)); |
|---|
| 90 | |
|---|
| 91 | /* add anything else to the module dictionary (such as constants) */ |
|---|
| 92 | warning = PyErr_NewException("pango.PangoWarning", PyExc_Warning, NULL); |
|---|
| 93 | PyDict_SetItemString(d, "Warning", warning); |
|---|
| 94 | #ifdef pyg_add_warning_redirection |
|---|
| 95 | pyg_add_warning_redirection("Pango", warning); |
|---|
| 96 | #else |
|---|
| 97 | g_log_set_handler("Pango", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING, |
|---|
| 98 | _log_func, warning); |
|---|
| 99 | #endif |
|---|
| 100 | } |
|---|