font-selector.cpp revision 4860787346cf1965a9a1069f8a37326e0fbeb683
#define __SP_FONT_SELECTOR_C__
/*
* Font selection widgets
*
* Authors:
* Chris Lahey <clahey@ximian.com>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Tavmjong Bah <tavmjong@free.fr>
*
* Copyright (C) 1999-2001 Ximian, Inc.
* Copyright (C) 2002 Lauris Kaplinski
* Copyright (C) -2013 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libnrtype/font-lister.h>
#include <libnrtype/font-instance.h>
#include "desktop.h"
#include "widgets/font-selector.h"
#include "preferences.h"
/* SPFontSelector */
struct SPFontSelector
{
unsigned int block_emit : 1;
bool fontsize_dirty;
};
struct SPFontSelectorClass
{
};
enum {
};
static void sp_font_selector_class_init (SPFontSelectorClass *c);
{
if (!type) {
sizeof(SPFontSelectorClass),
0, // base_init
0, // base_finalize
0, // class_finalize
0, // class_data
sizeof(SPFontSelector),
0, // n_preallocs
0 // value_table
};
}
return type;
}
static void sp_font_selector_class_init(SPFontSelectorClass *c)
{
1, G_TYPE_POINTER);
}
{
Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(unit), ")");
}
/*
* Create a widget with children for selecting font-family, font-style, and font-size.
*/
{
/* Family frame */
gtk_widget_show (f);
/* Muck with style, see text-toolbar.cpp */
"widget \"*font_selector_family\" style \"fontfamily-separator-style\"");
gtk_tree_view_set_model (GTK_TREE_VIEW(fsel->family_treeview), GTK_TREE_MODEL (Glib::unwrap (store)));
//gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->family_treeview),2);
g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK (sp_font_selector_family_select_row), fsel);
/* Style frame */
gtk_widget_show(f);
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
// CSS Style name
//gtk_tree_view_column_pack_start (column, cell, FALSE);
// Display Style name
//gtk_tree_view_column_pack_start (column, cell, FALSE);
//gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->style_treeview), 1);
g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK (sp_font_selector_style_select_row), fsel);
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
// Font-size
g_signal_connect (G_OBJECT(fsel->size), "changed", G_CALLBACK (sp_font_selector_size_changed), fsel);
gtk_widget_show_all (l);
// Set default size... next two lines must match
fsel->fontsize_dirty = false;
}
{
}
}
}
}
}
// Callback when family changed, updates style list for new family.
{
// We need our own copy of the style list store since the font-family
// may not be the same in the font-selector as stored in the font-lister
// TODO: use font-lister class for this by modifying new_font_family to accept an optional style list
// TODO: add store to SPFontSelector struct and reuse.
// Start by getting iterator to selected font
// Next get family name with its style list
// Find best style match for selected family with current style (e.g. of selected text).
// Create our own store of styles for selected font-family and find index of best style match
int path_index = 0;
int index = 0;
GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); // Where is this deleted?
{
-1);
path_index = index;
}
++index;
}
// Attach store to tree view. Can trigger style changed signal (but not FONT_SET):
//gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->style_treeview),1);
// Get path to best style
// Highlight best style. Triggers style changed signal:
gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->style_treeview)), path);
}
// Callback when row changed
{
if (!fsel->block_emit)
{
}
}
/*
* Set the default list of font sizes, scaled to the users preferred unit
* TODO: This routine occurs both here and in text-toolbar. Move to font-lister?
*/
{
int sizes[] = {
4, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28,
32, 36, 40, 48, 56, 64, 72, 144
};
// Array must be same length as SPCSSUnit in style.h
for (unsigned int n = 0; n < G_N_ELEMENTS(sizes); ++n)
{
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fsel->size), Glib::ustring::format(size).c_str());
}
}
// Callback when size changed
{
if (text) {
value = -1;
}
int max_size = prefs->getInt("/dialogs/textandfont/maxFontSize", 10000); // somewhat arbitrary, but text&font preview freezes with too huge fontsizes
if (value <= 0) {
return; // could not parse value
}
{
fsel->fontsize_dirty = true;
}
}
// Called from sp_font_selector_style_select_row
// Called from sp_font_selector_size_changed
// Called indirectly for sp_font_selector_family_select_row (since style changes).
// Emits FONT_SET signal (handled by TextEdit::onFontChange, GlyphsPanel::fontChangeCB).
{
//We need to check this here since most GtkTreeModel operations are not atomic
//See GtkListStore documenation, Chapter "Atomic Operations" --mderezynski
if (!model_family) return;
if (!model_style ) return;
fontspec += ", ";
}
{
return GTK_WIDGET(fsel);
}
/*
* Sets the values displayed in the font-selector from a fontspec.
* It is only called from TextEdit with a new selection and from GlyphsPanel
*/
{
{
try {
} catch (...) {
return;
}
// High light selected family and scroll so it is in view.
gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->family_treeview)), path.gobj());
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->family_treeview), path.gobj(), NULL, TRUE, 0.5, 0.5);
// We don't need to get best style since this is only called on a new
// selection where we already know the "best" style.
// Glib::ustring bestStyle = font_lister->get_best_style_match (family, style);
// std::cout << "Best: " << bestStyle << std::endl;
// The "trial" style list and the regular list are the same in this case.
try {
} catch (...) {
return;
}
gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->style_treeview)), path_c.gobj());
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fsel->style_treeview), path_c.gobj(), NULL, TRUE, 0.5, 0.5);
{
gchar s[8];
}
}
}
{
}
/*
* Return the font size in pixels
*/
{
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :