summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-09-18 20:05:20 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-09-18 20:05:20 +0000
commita49e070d24242c0297e6325587c4bc135e13e26c (patch)
tree0510d066cc185e9d0b1b736736da5266d259878e /examples
parent39f3626e34e0522e0bdec591f6c0334307d39625 (diff)
downloadpango-a49e070d24242c0297e6325587c4bc135e13e26c.tar.gz
Up to 0.19.
Tue Sep 18 15:47:08 2001 Owen Taylor <otaylor@redhat.com> * configure.in (PANGO_MINOR_VERSION): Up to 0.19. * pango/pango-font.h pango/pango-fontmap.[ch] pango/fonts.c pango/pangoxft-fontmap.c pango/pangoft-fontmap.c pango/pango-context.[ch] pango/pangox-fontmap.c: Add new PangoFontFace and PangoFontFamily object types, and change the font listing API to list faces and families, instead of face names and font descriptions. * pango/pango-font.h pango/fonts.c: Make PangoFontDescription an opaque heap-allocated structure, add accessors and convenience functions. * pango/pango-font.h pango/pango-private.h: Make PangoFontMetrics heap allocated, protect the structure definition with #ifdef PANGO_ENABLE_BACKEND, and add getters for the fields. * pango/pango-attributes.[ch] ( pango_attr_iterator_get_font): instead of providing a base font description and one to fill in, provide a single font description to modify based on the attributes. * pango/pango-attributes.[ch]: Fix PangoAttrFontDesc to have a PangoFontDescription by reference, not by value. * pango/pango-utils.[ch]: make pango_parse_style() and friends take pointers to individual enumerations instead of to a PangoFontDescription structure. * pango/*.c: Fix for the PangoFontDescription and PangoFontMetrics changes. * pango/pango-{break,engine,indic,ot,xft}.h pango/Makefile.am pango/opentype/Makefile.am: Protect portions with PANGO_ENABLE_ENGINE to shrink the public API. * modules/*/Makefile.am: -DPANGO_ENABLE_ENGINE. * pango/{pangox.h,pangox-private.h} modules/basic/basic-x.c: Move pango_x_font_get_unknown_glyph() into public header since it is used from modules. * pango/pango-{context,font,fontmap,modules.utils}.h pango/Makefile.am: Protect portions with PANGO_ENABLE_BACKEND to shrink the public API. * pango/*.h: Use G_BEGIN/END_DECLS * examples/viewer-qt.[cc,h]: Fix for changes to font listing API, PangoFontDescription. * pango/pango-indic.h modules/indic/*: Since we install this header fix it up to Pango conventions, namespece ZERO_WIDTH_JOINER, ZERO_WIDTH_NON_JOINER. * docs/pango-sections.txt: Updated.
Diffstat (limited to 'examples')
-rw-r--r--examples/viewer-qt.cc92
-rw-r--r--examples/viewer-qt.h4
2 files changed, 50 insertions, 46 deletions
diff --git a/examples/viewer-qt.cc b/examples/viewer-qt.cc
index fe2986be..02959690 100644
--- a/examples/viewer-qt.cc
+++ b/examples/viewer-qt.cc
@@ -350,9 +350,12 @@ ViewerView::contentsMousePressEvent (QMouseEvent *event)
}
static int
-cmp_strings (const void *a, const void *b)
+cmp_families (const void *a, const void *b)
{
- return strcmp (*(const char **)a, *(const char **)b);
+ const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
+ const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
+
+ return strcmp (a_name, b_name);
}
ViewerWindow::ViewerWindow (const QString &filename)
@@ -378,25 +381,26 @@ ViewerWindow::ViewerWindow (const QString &filename)
family_combo_ = new QComboBox (toolbar);
- gchar **families;
int n_families, i;
- pango_context_list_families (view_->context(), &families, &n_families);
- qsort (families, n_families, sizeof(char *), cmp_strings);
+ pango_context_list_families (view_->context(), &families_, &n_families);
+ qsort (families_, n_families, sizeof(PangoFontFamily *), cmp_families);
for (i=0; i<n_families; i++)
{
- family_combo_->insertItem (families[i]);
- if (!strcmp (families[i], "sans"))
+ const char *name = pango_font_family_get_name (families_[i]);
+
+ family_combo_->insertItem (name);
+ if (!strcmp (name, "sans"))
family_combo_->setCurrentItem (i);
}
- pango_font_map_free_families (families, n_families);
-
QObject::connect (family_combo_, SIGNAL(activated(int)), this, SLOT(fillStyleCombo(int)));
+ faces_ = NULL;
+
style_combo_ = new QComboBox (toolbar);
- fillStyleCombo (0);
+ fillStyleCombo (family_combo_->currentItem ());
size_box_ = new QSpinBox (1, 1000, 1, toolbar);
size_box_->setValue (16);
@@ -415,73 +419,69 @@ ViewerWindow::ViewerWindow (const QString &filename)
static int
compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b)
{
- int val = strcmp (a->family_name, b->family_name);
+ int val = strcmp (pango_font_description_get_family (a), pango_font_description_get_family (b));
if (val != 0)
return val;
- if (a->weight != b->weight)
- return a->weight - b->weight;
+ if (pango_font_description_get_weight (a) != pango_font_description_get_weight (b))
+ return pango_font_description_get_weight (a) - pango_font_description_get_weight (b);
- if (a->style != b->style)
- return a->style - b->style;
+ if (pango_font_description_get_style (a) != pango_font_description_get_style (b))
+ return pango_font_description_get_style (a) - pango_font_description_get_style (b);
- if (a->stretch != b->stretch)
- return a->stretch - b->stretch;
+ if (pango_font_description_get_stretch (a) != pango_font_description_get_stretch (b))
+ return pango_font_description_get_stretch (a) - pango_font_description_get_stretch (b);
- if (a->variant != b->variant)
- return a->variant - b->variant;
+ if (pango_font_description_get_variant (a) != pango_font_description_get_variant (b))
+ return pango_font_description_get_variant (a) - pango_font_description_get_variant (b);
return 0;
}
static int
-font_description_sort_func (const void *a, const void *b)
+faces_sort_func (const void *a, const void *b)
{
- return compare_font_descriptions (*(PangoFontDescription **)a, *(PangoFontDescription **)b);
+ PangoFontDescription *desc_a = pango_font_face_describe (*(PangoFontFace **)a);
+ PangoFontDescription *desc_b = pango_font_face_describe (*(PangoFontFace **)b);
+
+ int ord = compare_font_descriptions (desc_a, desc_b);
+
+ pango_font_description_free (desc_a);
+ pango_font_description_free (desc_b);
+
+ return ord;
}
void
ViewerWindow::fillStyleCombo (int index)
{
- QString family = family_combo_->currentText();
+ PangoFontFamily *family = families_[index];
+ int n_faces;
+
+ if (faces_)
+ g_free (faces_);
- PangoFontDescription **descs;
- int n_descs;
+ pango_font_family_list_faces (family, &faces_, &n_faces);
- pango_context_list_fonts (view_->context(), family, &descs, &n_descs);
- qsort (descs, n_descs, sizeof(PangoFontDescription *), font_description_sort_func);
+ qsort (faces_, n_faces, sizeof(PangoFontFace *), faces_sort_func);
style_combo_->clear();
- for (int i = 0; i < n_descs; i++)
+ for (int i = 0; i < n_faces; i++)
{
- PangoFontDescription tmp_desc;
-
- tmp_desc = *descs[i];
- tmp_desc.family_name = NULL;
- tmp_desc.size = 0;
-
- char *str = pango_font_description_to_string (&tmp_desc);
+ const char *str = pango_font_face_get_face_name (faces_[i]);
style_combo_->insertItem (str);
}
-
- pango_font_descriptions_free (descs, n_descs);
}
void
ViewerWindow::fontChanged ()
{
- QString style = style_combo_->currentText();
+ PangoFontFace *face = faces_[style_combo_->currentItem()];
- if (style == "Normal")
- style = "";
- else
- style += " ";
-
- QString font_name = (family_combo_->currentText() + " " +
- style +
- QString::number (size_box_->value()));
+ QString style = style_combo_->currentText();
- PangoFontDescription *font_desc = pango_font_description_from_string (font_name);
+ PangoFontDescription *font_desc = pango_font_face_describe (face);
+ pango_font_description_set_size (font_desc, size_box_->value () * PANGO_SCALE);
view_->setFontDesc (font_desc);
diff --git a/examples/viewer-qt.h b/examples/viewer-qt.h
index c8d8001b..21307111 100644
--- a/examples/viewer-qt.h
+++ b/examples/viewer-qt.h
@@ -98,7 +98,11 @@ class ViewerWindow : public QMainWindow
PangoContext *context_;
QComboBox *family_combo_;
+ PangoFontFamily **families_;
+
QComboBox *style_combo_;
+ PangoFontFace **faces_;
+
QSpinBox *size_box_;
QPopupMenu *file_menu_;