diff options
Diffstat (limited to 'app/wlib/gtklib/font.c')
-rw-r--r-- | app/wlib/gtklib/font.c | 362 |
1 files changed, 181 insertions, 181 deletions
diff --git a/app/wlib/gtklib/font.c b/app/wlib/gtklib/font.c index 29df04d..e89307c 100644 --- a/app/wlib/gtklib/font.c +++ b/app/wlib/gtklib/font.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -67,7 +67,7 @@ static GtkWidget *fontSelectionDialog; int absoluteFontSize = 18; struct wFont_t { - PangoFontDescription *fontDescription; + PangoFontDescription *fontDescription; }; static wFont_p standardFonts[F_HELV-F_TIMES+1][2][2]; @@ -85,76 +85,76 @@ static wFont_p curFont = NULL; static void fontSelectionDialogCallback(GtkFontSelectionDialog *fontSelectionDialog, gint response, gpointer data) { - if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { - gchar *fontName; - - fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog); - wPrefSetString("font", "name", fontName); - pango_font_description_free(curFont->fontDescription); - curFont->fontDescription = pango_font_description_from_string(fontName); - absoluteFontSize = (pango_font_description_get_size( - curFont->fontDescription))/PANGO_SCALE; + if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { + gchar *fontName; + + fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog); + wPrefSetString("font", "name", fontName); + pango_font_description_free(curFont->fontDescription); + curFont->fontDescription = pango_font_description_from_string(fontName); + absoluteFontSize = (pango_font_description_get_size( + curFont->fontDescription))/PANGO_SCALE; #if WLIB_FONT_DEBUG >= 2 - fprintf(stderr, "new font selection:\n"); - fprintf(stderr, " font name \"%s\"\n", fontName); - fprintf(stderr, " font size is %d\n", - pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); - fprintf(stderr, " font size is absolute %d\n", - pango_font_description_get_size_is_absolute(curFont->fontDescription)); + fprintf(stderr, "new font selection:\n"); + fprintf(stderr, " font name \"%s\"\n", fontName); + fprintf(stderr, " font size is %d\n", + pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); + fprintf(stderr, " font size is absolute %d\n", + pango_font_description_get_size_is_absolute(curFont->fontDescription)); #endif - g_free(fontName); - } + g_free(fontName); + } - if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) { - gtk_widget_hide(GTK_WIDGET(fontSelectionDialog)); - } + if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) { + gtk_widget_hide(GTK_WIDGET(fontSelectionDialog)); + } } static wBool_t fontInitted = FALSE; static wBool_t fontInit() { - const char *fontNames[] = { - "times 18", - "times italic 18", - "times bold 18", - "times bold italic 18", - "helvetica 18", - "helvetica oblique 18", - "helvetica bold 18", - "helvetica bold oblique 18", - }; - int s = 0; - int i, j, k; - - for (i = F_TIMES; i <= F_HELV; ++i) { - for (j = FW_MEDIUM; j <= FW_BOLD; ++j) { - for (k = FS_REGULAR; k <= FS_ITALIC; ++k) { - PangoFontDescription *fontDescription = pango_font_description_from_string( - fontNames[s++]); - wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t)); - standardFont->fontDescription = fontDescription; - standardFonts[i-F_TIMES][j][k] = standardFont; - } - } - } - - if (curFont == NULL) { - curFont = (wFont_p) malloc(sizeof(struct wFont_t)); - - if (curFont == NULL) { - return FALSE; - } - - const char *fontName = wPrefGetString("font", "name"); - curFont->fontDescription = pango_font_description_from_string( - fontName ? fontName : "helvetica 18"); - absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size( - curFont->fontDescription)); - } - - fontInitted = TRUE; - return TRUE; + const char *fontNames[] = { + "times 18", + "times italic 18", + "times bold 18", + "times bold italic 18", + "helvetica 18", + "helvetica oblique 18", + "helvetica bold 18", + "helvetica bold oblique 18", + }; + int s = 0; + int i, j, k; + + for (i = F_TIMES; i <= F_HELV; ++i) { + for (j = FW_MEDIUM; j <= FW_BOLD; ++j) { + for (k = FS_REGULAR; k <= FS_ITALIC; ++k) { + PangoFontDescription *fontDescription = pango_font_description_from_string( + fontNames[s++]); + wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t)); + standardFont->fontDescription = fontDescription; + standardFonts[i-F_TIMES][j][k] = standardFont; + } + } + } + + if (curFont == NULL) { + curFont = (wFont_p) malloc(sizeof(struct wFont_t)); + + if (curFont == NULL) { + return FALSE; + } + + const char *fontName = wPrefGetString("font", "name"); + curFont->fontDescription = pango_font_description_from_string( + fontName ? fontName : "helvetica 18"); + absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size( + curFont->fontDescription)); + } + + fontInitted = TRUE; + return TRUE; } @@ -186,59 +186,59 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p, - wDrawPix_t *baseline_p) + wDrawPix_t *baseline_p) { - if (!fontInitted) { - fontInit(); - } - - PangoLayout *layout = NULL; - gchar *utf8 = wlibConvertInput(s); - /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8. - CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have - libpangocairo at all. - pango_cairo_create_layout() was introduced with Pango 1.10. */ + if (!fontInitted) { + fontInit(); + } + + PangoLayout *layout = NULL; + gchar *utf8 = wlibConvertInput(s); + /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8. + CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have + libpangocairo at all. + pango_cairo_create_layout() was introduced with Pango 1.10. */ #if PANGO_VERSION_MAJOR >= 1 && PANGO_VERSION_MINOR >= 10 - if (cairo != NULL) { - layout = pango_cairo_create_layout((cairo_t *) cairo); - pango_layout_set_text(layout, utf8, -1); - } else + if (cairo != NULL) { + layout = pango_cairo_create_layout((cairo_t *) cairo); + pango_layout_set_text(layout, utf8, -1); + } else #endif - layout = gtk_widget_create_pango_layout(widget, utf8); - - PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription; - PangoContext *context; - PangoFontMetrics *metrics; - /* set attributes */ - pango_font_description_set_size(fontDescription, - FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE); - pango_layout_set_font_description(layout, fontDescription); - /* get layout measures */ - gint width_i, height_i; - pango_layout_get_size(layout, &width_i, &height_i); - *width_p = width_i / PANGO_SCALE; - *height_p = height_i / PANGO_SCALE; - context = gtk_widget_create_pango_context(widget); - metrics = pango_context_get_metrics(context, fontDescription, - pango_context_get_language(context)); - *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE; - *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; - *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; - pango_font_metrics_unref(metrics); - g_object_unref(context); + layout = gtk_widget_create_pango_layout(widget, utf8); + + PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription; + PangoContext *context; + PangoFontMetrics *metrics; + /* set attributes */ + pango_font_description_set_size(fontDescription, + FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE); + pango_layout_set_font_description(layout, fontDescription); + /* get layout measures */ + gint width_i, height_i; + pango_layout_get_size(layout, &width_i, &height_i); + *width_p = width_i / PANGO_SCALE; + *height_p = height_i / PANGO_SCALE; + context = gtk_widget_create_pango_context(widget); + metrics = pango_context_get_metrics(context, fontDescription, + pango_context_get_language(context)); + *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE; + *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; + *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; + pango_font_metrics_unref(metrics); + g_object_unref(context); #if WLIB_FONT_DEBUG >= 3 - fprintf(stderr, "font layout created:\n"); - fprintf(stderr, " widget: %p\n", widget); - //fprintf(stderr, " font description:%p\n", fp); - fprintf(stderr, " font size: %f\n", fs); - fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8); - fprintf(stderr, " layout width: %d\n", *width_p); - fprintf(stderr, " layout height: %d\n", *height_p); - fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p); - fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p); + fprintf(stderr, "font layout created:\n"); + fprintf(stderr, " widget: %p\n", widget); + //fprintf(stderr, " font description:%p\n", fp); + fprintf(stderr, " font size: %f\n", fs); + fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8); + fprintf(stderr, " layout width: %d\n", *width_p); + fprintf(stderr, " layout height: %d\n", *height_p); + fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p); + fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p); #endif - return layout; + return layout; } /** @@ -248,7 +248,7 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void wlibFontDestroyPangoLayout(PangoLayout *layout) { - g_object_ref_sink(layout); + g_object_ref_sink(layout); g_object_unref(layout); } @@ -259,9 +259,9 @@ void wlibFontDestroyPangoLayout(PangoLayout *layout) void wInitializeFonts() { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } } /** @@ -272,41 +272,41 @@ void wInitializeFonts() */ void wSelectFont( - const char * title) + const char * title) { - if (!fontInitted) { - fontInit(); - } - - if (fontSelectionDialog == NULL) { - fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select")); - gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE); - gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE); - gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG( - fontSelectionDialog), sampleText); - g_signal_connect(G_OBJECT(fontSelectionDialog), "response", - G_CALLBACK(fontSelectionDialogCallback), NULL); - g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy", - G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog); - } - - gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title); - - if (curFont != NULL) { - gchar *fontName; - - /* the curFont description contains the latest font info - * which is depended on the current scale - * overwrite it with the absoluteFontSize */ - pango_font_description_set_size(curFont->fontDescription, - FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE); - fontName = pango_font_description_to_string(curFont->fontDescription); - gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG( - fontSelectionDialog), fontName); - g_free(fontName); - } - - gtk_widget_show(fontSelectionDialog); + if (!fontInitted) { + fontInit(); + } + + if (fontSelectionDialog == NULL) { + fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select")); + gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE); + gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE); + gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG( + fontSelectionDialog), sampleText); + g_signal_connect(G_OBJECT(fontSelectionDialog), "response", + G_CALLBACK(fontSelectionDialogCallback), NULL); + g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy", + G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog); + } + + gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title); + + if (curFont != NULL) { + gchar *fontName; + + /* the curFont description contains the latest font info + * which is depended on the current scale + * overwrite it with the absoluteFontSize */ + pango_font_description_set_size(curFont->fontDescription, + FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE); + fontName = pango_font_description_to_string(curFont->fontDescription); + gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG( + fontSelectionDialog), fontName); + g_free(fontName); + } + + gtk_widget_show(fontSelectionDialog); } /** @@ -317,11 +317,11 @@ void wSelectFont( static wFont_p wlibSelectedFont(void) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - return curFont; + return curFont; } /** @@ -332,16 +332,16 @@ static wFont_p wlibSelectedFont(void) wFontSize_t wSelectedFontSize(void) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } #if WLIB_FONT_DEBUG >= 3 - fprintf(stderr, "the font size of current font description is: %d\n", - pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); - fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize); + fprintf(stderr, "the font size of current font description is: %d\n", + pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); + fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize); #endif - return absoluteFontSize; + return absoluteFontSize; } /** @@ -353,7 +353,7 @@ wFontSize_t wSelectedFontSize(void) void wSetSelectedFontSize(wFontSize_t size) { - absoluteFontSize = size; + absoluteFontSize = size; } /** @@ -368,30 +368,30 @@ void wSetSelectedFontSize(wFontSize_t size) const char *wlibFontTranslate(wFont_p fp) { - static gchar *fontName = NULL; + static gchar *fontName = NULL; - if (fontName != NULL) { - g_free(fontName); - } + if (fontName != NULL) { + g_free(fontName); + } - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - if (fp == NULL) { - fp = wlibSelectedFont(); - } + if (fp == NULL) { + fp = wlibSelectedFont(); + } - if (fp == NULL) { - fp = standardFonts[0][FW_MEDIUM][FS_REGULAR]; - } + if (fp == NULL) { + fp = standardFonts[0][FW_MEDIUM][FS_REGULAR]; + } - fontName = pango_font_description_to_string(fp->fontDescription); + fontName = pango_font_description_to_string(fp->fontDescription); #if WLIB_FONT_DEBUG >= 2 - fprintf(stderr, "font translation: "); - fprintf(stderr, " \"%s\"\n", fontName); + fprintf(stderr, "font translation: "); + fprintf(stderr, " \"%s\"\n", fontName); #endif - return (const char *) fontName; + return (const char *) fontName; } /** @@ -402,9 +402,9 @@ const char *wlibFontTranslate(wFont_p fp) wFont_p wStandardFont(int face, wBool_t bold, wBool_t italic) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - return standardFonts[face-F_TIMES][bold][italic]; + return standardFonts[face-F_TIMES][bold][italic]; } |