diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-05-28 15:52:25 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-05-28 15:52:25 +0000 |
commit | 45a1d90a3a453950f74bada5c5337554cb596062 (patch) | |
tree | e48eacb949402aab82269bed5fec6de06dac0e5b | |
parent | 1c7a5a30d5896a79a4a0c806b43a2db7e4bcc4f8 (diff) | |
download | pango-45a1d90a3a453950f74bada5c5337554cb596062.tar.gz |
Since we require GLib-1.3, and thus can no longer build the examples
Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com>
* examples/Makefile.am examples/viewer-qt.cc
examples/viewer-qt.h: Since we require GLib-1.3,
and thus can no longer build the examples against
GTK+-1.2, and since there is a nasty circular dependency
if we build examples against GTK+-1.3, rewrite
(optional) example program in Qt. (I wasn't going
to do it in Xaw or straight Xlib...)
* configure.in: Added checks for Qt.
* pango/pango-layout.h: Fix constness.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-0 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-2 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 15 | ||||
-rw-r--r-- | configure.in | 52 | ||||
-rw-r--r-- | examples/.cvsignore | 1 | ||||
-rw-r--r-- | examples/Makefile.am | 26 | ||||
-rw-r--r-- | examples/viewer-qt.cc | 515 | ||||
-rw-r--r-- | examples/viewer-qt.h | 113 | ||||
-rw-r--r-- | examples/viewer.c | 17 | ||||
-rw-r--r-- | pango/pango-layout.c | 4 | ||||
-rw-r--r-- | pango/pango-layout.h | 2 |
15 files changed, 804 insertions, 31 deletions
@@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-0 b/ChangeLog.pre-1-0 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-0 +++ b/ChangeLog.pre-1-0 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-2 +++ b/ChangeLog.pre-1-2 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 2a3eb02d..d7217354 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,17 @@ +Sun May 28 16:24:43 2000 Owen Taylor <otaylor@redhat.com> + + * examples/Makefile.am examples/viewer-qt.cc + examples/viewer-qt.h: Since we require GLib-1.3, + and thus can no longer build the examples against + GTK+-1.2, and since there is a nasty circular dependency + if we build examples against GTK+-1.3, rewrite + (optional) example program in Qt. (I wasn't going + to do it in Xaw or straight Xlib...) + + * configure.in: Added checks for Qt. + + * pango/pango-layout.h: Fix constness. + Sat May 27 22:05:53 2000 Owen Taylor <otaylor@redhat.com> * pango/Makefile.am (pangoinclude_HEADERS): Install @@ -53,6 +67,7 @@ Thu May 18 17:30:00 2000 Robert Brady <rwb197@zepler.org> * fonts/devnag18.bdf: Fix advance widths of some glyphs. +>>>>>>> 1.65 Tue May 9 22:09:42 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-types.h (PANGO_SCALE): Change PANGO_SCALE diff --git a/configure.in b/configure.in index 57a7c934..4fb3eb18 100644 --- a/configure.in +++ b/configure.in @@ -24,12 +24,9 @@ fi X_LIBS="-L$x_libraries -lX11" AC_SUBST(X_LIBS) -gtk_works=no -AM_PATH_GTK(1.2.0, - [CFLAGS="$GTK_CFLAGS $CFLAGS"; gtk_works=yes], - AC_MSG_WARN("Disabling GTK+-based tests")) - -AM_CONDITIONAL(BUILD_TESTS, test x$gtk_works = xyes) +AM_PATH_GLIB(1.3.1,, + AC_MSG_ERROR([GLib 1.3.1 is required for building Pango]), + gmodule gobject) AC_PATH_PROG(FRIBIDI_CONFIG, fribidi-config, no) if test x$FRIBIDI_CONFIG = xno ; then @@ -136,9 +133,52 @@ AM_CONDITIONAL(INCLUDE_THAI,echo $included_modules | grep '\(^\|,\)thai\($\|,\)' # AC_CHECK_FUNCS(flockfile) +# +# Check for Qt - which we use for building the viewer example, if +# present +# + +AC_ARG_WITH(qt, [ --with-qt=DIR Location where Qt is installed],,with_qt=yes) + +QTDIR= +AC_MSG_CHECKING(For Qt location) + +if test "x$with_qt" = xyes ; then +# Search for Qt in various possibly standard ocations + for dir in /usr/lib/qt-2.1.0 /usr/lib/qt-2.0.1 /usr/lib/qt-2.0.0 ; do + if test -x $dir/bin/moc ; then + QTDIR=$dir + break + fi + done + +else + if ! test "x$with_qt" = xno ; then + if test -x $with_qt/bin/moc ; then + QTDIR=$with_qt + fi + fi +fi + +if test "x$QTDIR" = x ; then + AC_MSG_RESULT(none) +else + AC_MSG_RESULT($QTDIR) + + AC_PROG_CXX +fi + +AM_CONDITIONAL(BUILD_QT_TEST, ! test "x$QTDIR" = x) +AC_SUBST(QTDIR) + +# +# Check for gtkdoc +# AC_CHECK_PROG(gtkdoc, gtkdoc-scan, yes, no) AM_CONDITIONAL(HAVE_GTK_DOC, test x$gtkdoc = xyes) + + AC_OUTPUT_COMMANDS([ cat > pango/module-defs.c <<EOTEXT /* Autogenerated by configure. Do not edit */ diff --git a/examples/.cvsignore b/examples/.cvsignore index cb3030ba..aa19118b 100644 --- a/examples/.cvsignore +++ b/examples/.cvsignore @@ -2,6 +2,7 @@ Makefile.in Makefile pango.modules pango-viewer +moc_viewer-qt.cc .deps .libs *.lo diff --git a/examples/Makefile.am b/examples/Makefile.am index a9300511..4c3ae795 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -2,15 +2,31 @@ aliasdir = $(sysconfdir)/pango -INCLUDES = -I$(top_srcdir) +################################################### +if BUILD_QT_TEST + +QT_INCLUDES=-I $(QTDIR)/include +QT_LIBS=-L $(QTDIR)/lib -lqt +MOC=$(QTDIR)/bin/moc + +INCLUDES = -I$(top_srcdir) $(QT_INCLUDES) $(GLIB_CFLAGS) -if BUILD_TESTS bin_PROGRAMS = pango-viewer -pango_viewer_SOURCES = \ - viewer.c -pango_viewer_LDADD = ../pango/libpango.la ../pango/libpangox.la $(GTK_LIBS) $(FRIBIDI_LIBS) $(UNICODE_LIBS) +pango_viewer_SOURCES = \ + viewer-qt.cc \ + viewer-qt.h \ + moc_viewer-qt.cc + +moc_viewer-qt.cc: viewer-qt.h + $(MOC) $< -o $@ + +BUILT_SOURCES=moc_viewer-qt.cc + +pango_viewer_LDADD = ../pango/libpango.la ../pango/libpangox.la $(FRIBIDI_LIBS) $(UNICODE_LIBS) $(QT_LIBS) + endif +################################################### all-local: pango.modules diff --git a/examples/viewer-qt.cc b/examples/viewer-qt.cc new file mode 100644 index 00000000..c3d07040 --- /dev/null +++ b/examples/viewer-qt.cc @@ -0,0 +1,515 @@ +/* Pango + * viewer-qt.cc: Example program to view a UTF-8 encoding file + * using Pango to render result. + * + * Copyright (C) 1999-2000 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <stdlib.h> + +#include <qapplication.h> +#include <qcdestyle.h> +#include <qcombobox.h> +#include <qfile.h> +#include <qmenubar.h> +#include <qpopupmenu.h> +#include <qspinbox.h> +#include <qscrollview.h> +#include <qstatusbar.h> +#include <qtextcodec.h> +#include <qtextstream.h> +#include <qtoolbar.h> + +#include <pango/pango.h> +#include <pango/pangox.h> + +#include "viewer-qt.h" + +ViewerPara::ViewerPara (PangoContext *context, const QString &text) +{ + text_ = text.utf8(); + + layout_ = pango_layout_new (context); + pango_layout_set_text (layout_, (char *)(const char *)text_, text_.length()); + height_ = -1; +} + +ViewerPara::~ViewerPara () +{ + pango_layout_unref (layout_); +} + +void +ViewerPara::setWidth (int width) +{ + pango_layout_set_width (layout_, width * PANGO_SCALE); + height_ = -1; +} + +void +ViewerPara::contextChanged () +{ + pango_layout_context_changed (layout_); + height_ = -1; + + PangoContext *context; + PangoAlignment align; + + context = pango_layout_get_context (layout_); + if (pango_context_get_base_dir (context) == PANGO_DIRECTION_LTR) + align = PANGO_ALIGN_LEFT; + else + align = PANGO_ALIGN_RIGHT; + + pango_layout_set_alignment (layout_, align); +} + +int +ViewerPara::height () +{ + if (height_ < 0) + { + PangoRectangle logical_rect; + + pango_layout_get_extents (layout_, NULL, &logical_rect); + height_ = logical_rect.height / PANGO_SCALE; + } + + return height_; +} + +void +ViewerPara::draw (QPainter *painter, GC gc, int y) +{ + QPoint devicePt = painter->xForm (QPoint (0, y)); + + pango_x_render_layout (painter->device()->x11Display(), + painter->device()->handle(), + gc, layout_, 0, devicePt.y()); +} + +unicode_char_t +ViewerPara::getChar (int index) +{ + unicode_char_t result; + + if (unicode_get_utf8 (((const char *)text_) + index, &result)) + return result; + else + return 0; +} + +QRect +ViewerPara::charBounds (int index) +{ + PangoRectangle pos; + + pango_layout_index_to_pos (layout_, index, &pos); + + return QRect (MIN (pos.x, pos.x + pos.width) / PANGO_SCALE, + pos.y / PANGO_SCALE, + ABS (pos.width) / PANGO_SCALE, + pos.height / PANGO_SCALE); +} + +int +ViewerPara::findPoint (int x, int y) +{ + int index; + + bool result = pango_layout_xy_to_index (layout_, + x * PANGO_SCALE, y * PANGO_SCALE, + &index, NULL); + if (result) + return index; + else + return -1; +} + +ViewerView::ViewerView (QWidget *parent, QStatusBar *status) : QScrollView (parent) +{ + status_ = status; + + viewport()->setBackgroundMode( QWidget::PaletteBase ); + + setHScrollBarMode (QScrollView::AlwaysOff); + + context_ = pango_x_get_context (x11Display()); + pango_context_set_lang (context_, "en_US"); + + highlight_para_ = NULL; + highlight_index_ = 0; +} + +ViewerView::~ViewerView () +{ + pango_context_unref (context_); +} + +void +ViewerView::readFile (const QString &name) +{ + QFile file (name); + + file.open (IO_ReadOnly); + QTextStream ts (&file);; + + ts.setCodec (QTextCodec::codecForName ("utf8")); + + while (!ts.atEnd()) + paragraphs_.append (new ViewerPara (context (), ts.readLine())); +} + +void +ViewerView::contextChanged () +{ + QListIterator<ViewerPara> it(paragraphs_); + for (; it.current(); ++it) + it.current()->contextChanged(); + + computeHeight(); + updateContents (0, 0, contentsWidth(), contentsHeight()); +} + +void +ViewerView::setFontDesc (PangoFontDescription *font_desc) +{ + pango_context_set_font_description (context_, font_desc); + contextChanged(); +} + +void +ViewerView::setDirection (PangoDirection base_dir) +{ + QListIterator<ViewerPara> it(paragraphs_); + for (; it.current(); ++it) + it.current()->contextChanged(); + + pango_context_set_base_dir (context_, base_dir); + contextChanged(); +} + +void +ViewerView::drawContents (QPainter *p, int clipx, int clipy, int clipw, int cliph) +{ + XGCValues values; + QRect clip = p->xForm (QRect (clipx, clipy, clipw, cliph)); + + GC gc = XCreateGC (x11Display(), handle(), 0, &values); + + XSetForeground (x11Display(), gc, colorGroup().text().pixel()); + + XRectangle xclip = { clip.x(), clip.y(), clip.width(), clip.height() }; + XSetClipRectangles (x11Display(), gc, 0, 0, &xclip, 1, YXBanded); + + int y = 0; + QListIterator<ViewerPara> it(paragraphs_); + for (; it.current(); ++it) + { + ViewerPara *para = it.current(); + int y_end = y + para->height (); + + if (y_end > clipy && y < clipy + cliph) + para->draw (p, gc, y); + + if (para == highlight_para_) + { + QRect bounds = highlight_para_->charBounds (highlight_index_); + bounds.moveBy (0, y); + bounds = p->xForm (bounds); + + XRectangle xbounds = { bounds.x(), bounds.y(), bounds.width(), bounds.height() }; + + XFillRectangle (x11Display(), p->device()->handle(), gc, + xbounds.x, xbounds.y, xbounds.width, xbounds.height); + + XSetClipRectangles (x11Display(), gc, 0, 0, &xbounds, 1, YXBanded); + XSetForeground (x11Display(), gc, colorGroup().base().pixel()); + + para->draw (p, gc, y); + + XSetForeground (x11Display(), gc, colorGroup().text().pixel()); + XSetClipRectangles (x11Display(), gc, 0, 0, &xclip, 1, YXBanded); + } + + y = y_end; + } + + XFreeGC (x11Display(), gc); +} + +void +ViewerView::computeHeight () +{ + int width = visibleWidth(); + int height = 0; + + QListIterator<ViewerPara> it(paragraphs_); + for (; it.current(); ++it) + { + ViewerPara *para = it.current(); + para->setWidth (width); + height += para->height (); + } + + resizeContents (width, height); + repaintContents (0, 0, contentsWidth(), contentsHeight()); +} + +void +ViewerView::viewportResizeEvent (QResizeEvent *event) +{ + computeHeight (); +} + +void +ViewerView::updateHighlightChar () +{ + if (highlight_para_) + { + int y = 0; + QListIterator<ViewerPara> it(paragraphs_); + + for (; it.current(); ++it) + { + ViewerPara *para = it.current(); + if (para == highlight_para_) + { + QRect bounds = para->charBounds (highlight_index_); + bounds.moveBy (0, y); + updateContents (bounds); + + break; + } + + y += para->height (); + } + } +} + +void +ViewerView::contentsMousePressEvent (QMouseEvent *event) +{ + updateHighlightChar (); + highlight_para_ = NULL; + + int y = 0; + QListIterator<ViewerPara> it(paragraphs_); + for (; it.current(); ++it) + { + ViewerPara *para = it.current(); + int y_end = y + para->height (); + + if (y <= event->y() && event->y() < y_end) + { + int index = para->findPoint (event->x(), event->y() - y); + unicode_char_t wc = para->getChar (index); + + if (index >= 0 && wc) + { + highlight_para_ = para; + highlight_index_ = index; + + if (status_) + { + QString num = QString::number (wc, 16).rightJustify (4, '0'); + + status_->message (QString ("Current char: U+") + num); + } + } + + break; + } + y = y_end; + } + + if (status_ && !highlight_para_) + status_->clear (); + + updateHighlightChar(); +} + +static int +cmp_strings (const void *a, const void *b) +{ + return strcmp (*(const char **)a, *(const char **)b); +} + +ViewerWindow::ViewerWindow () +{ + // Create menu + + file_menu_ = new QPopupMenu (this); + file_menu_->setCheckable (true); + + menuBar()->insertItem ("&File", file_menu_); + + file_menu_->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); + + right_to_left_item_ = file_menu_->insertItem( "&Right-to-Left", this, SLOT( setRightToLeft() ), 0 ); + + view_ = new ViewerView (this, new QStatusBar (this)); + + setCentralWidget (view_); + + // Create families combo box + + QToolBar *toolbar = new QToolBar ("Font", this); + + 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); + + for (i=0; i<n_families; i++) + { + family_combo_->insertItem (families[i]); + if (!strcmp (families[i], "sans")) + family_combo_->setCurrentItem (i); + } + + pango_font_map_free_families (families, n_families); + + QObject::connect (family_combo_, SIGNAL(activated(int)), this, SLOT(fillStyleCombo(int))); + + style_combo_ = new QComboBox (toolbar); + fillStyleCombo (0); + + size_box_ = new QSpinBox (1, 1000, 1, toolbar); + size_box_->setValue (16); + + QObject::connect (family_combo_, SIGNAL(activated(int)), this, SLOT(fontChanged())); + QObject::connect (style_combo_, SIGNAL(activated(int)), this, SLOT(fontChanged())); + QObject::connect (size_box_, SIGNAL(valueChanged(int)), this, SLOT(fontChanged())); + + fontChanged (); + + view_->readFile ("/home/otaylor/devel/pango/examples/HELLO.utf8"); + + resize (500, 500); +} + +static int +compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b) +{ + int val = strcmp (a->family_name, b->family_name); + if (val != 0) + return val; + + if (a->weight != b->weight) + return a->weight - b->weight; + + if (a->style != b->style) + return a->style - b->style; + + if (a->stretch != b->stretch) + return a->stretch - b->stretch; + + if (a->variant != b->variant) + return a->variant - b->variant; + + return 0; +} + +static int +font_description_sort_func (const void *a, const void *b) +{ + return compare_font_descriptions (*(PangoFontDescription **)a, *(PangoFontDescription **)b); +} + +void +ViewerWindow::fillStyleCombo (int index) +{ + QString family = family_combo_->currentText(); + + PangoFontDescription **descs; + int n_descs; + + pango_context_list_fonts (view_->context(), family, &descs, &n_descs); + qsort (descs, n_descs, sizeof(PangoFontDescription *), font_description_sort_func); + + style_combo_->clear(); + for (int i = 0; i < n_descs; 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); + style_combo_->insertItem (str); + } + + pango_font_descriptions_free (descs, n_descs); +} + +void +ViewerWindow::fontChanged () +{ + QString style = style_combo_->currentText(); + + if (style == "Normal") + style = ""; + else + style += " "; + + QString font_name = (family_combo_->currentText() + " " + + style + + QString::number (size_box_->value())); + + PangoFontDescription *font_desc = pango_font_description_from_string (font_name); + + view_->setFontDesc (font_desc); + + pango_font_description_free (font_desc); +} + +void +ViewerWindow::setRightToLeft () +{ + bool new_value = !file_menu_->isItemChecked (right_to_left_item_); + + file_menu_->setItemChecked (right_to_left_item_, new_value); + view_->setDirection (new_value ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR); +} + +ViewerWindow::~ViewerWindow () +{ + delete view_; +} + +int +main (int argc, char **argv) +{ + QApplication a (argc, argv); + + QApplication::setStyle (new QCDEStyle()); + + ViewerWindow *vw = new ViewerWindow (); + + vw->show(); + + a.connect (&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); + return a.exec (); +} + diff --git a/examples/viewer-qt.h b/examples/viewer-qt.h new file mode 100644 index 00000000..75261ebb --- /dev/null +++ b/examples/viewer-qt.h @@ -0,0 +1,113 @@ +/* Pango + * viewer-qt.cc: Example program to view a UTF-8 encoding file + * using Pango to render result. + * + * Copyright (C) 1999-2000 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <qscrollview.h> +#include <qlist.h> +#include <qmainwindow.h> +#include <pango/pango.h> +#include <unicode.h> + +class QComboBox; +class QSpinBox; + +class ViewerPara +{ + public: + ViewerPara (PangoContext *context, const QString &text); + ~ViewerPara (); + + void setWidth (int width); + void contextChanged (); + int height (); + void draw (QPainter *painter, GC gc, int y); + QRect charBounds (int index); + unicode_char_t getChar (int index); + int findPoint (int x, int y); + + private: + QCString text_; + int height_; + PangoLayout *layout_; +}; + +class ViewerView : public QScrollView +{ + Q_OBJECT + + public: + + ViewerView::ViewerView (QWidget *parent, QStatusBar *status = NULL); + ~ViewerView (); + + void readFile (const QString &name); + void setFontDesc (PangoFontDescription *font_desc); + void setDirection (PangoDirection base_dir); + + void computeHeight (); + + PangoContext *context() { return context_; } + + protected: + virtual void drawContents (QPainter *p, int clipx, int clipy, int clipw, int cliph); + virtual void viewportResizeEvent ( QResizeEvent *event ); + virtual void contentsMousePressEvent (QMouseEvent *event); + + private: + void contextChanged (); + void updateHighlightChar (); + + QStatusBar *status_; + + PangoContext *context_; + QList<ViewerPara> paragraphs_; + + ViewerPara *highlight_para_; + int highlight_index_; +}; + +class ViewerWindow : public QMainWindow +{ + Q_OBJECT + + public: + + ViewerWindow (); + ~ViewerWindow (); + + private: + ViewerView *view_; + + PangoContext *context_; + + QComboBox *family_combo_; + QComboBox *style_combo_; + QSpinBox *size_box_; + + QPopupMenu *file_menu_; + + int right_to_left_item_; + + private slots: + void fillStyleCombo (int index); + void fontChanged (); + void setRightToLeft (); +}; diff --git a/examples/viewer.c b/examples/viewer.c index cbc060a6..1fb93ef8 100644 --- a/examples/viewer.c +++ b/examples/viewer.c @@ -37,7 +37,6 @@ #define BUFSIZE 1024 typedef struct _Paragraph Paragraph; -typedef struct _Line Line; /* Structure representing a paragraph */ @@ -48,16 +47,6 @@ struct _Paragraph { PangoLayout *layout; }; -/* Structure representing a line - */ - struct _Line { - /* List of PangoItems for this paragraph in visual order */ - GList *runs; - int ascent; /* Ascent of line, in pixels */ - int descent; /* Descent of lines, in pixels */ - int offset; /* Offset from left margin line, in pixels */ -}; - GList *paragraphs; static PangoFontDescription font_description; @@ -531,12 +520,6 @@ make_styles_combo () return combo; } -int -cmp_strings (const void *a, const void *b) -{ - return strcmp (*(const char **)a, *(const char **)b); -} - GtkWidget * make_families_menu () { diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 80a9d824..c0bcb43a 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -385,7 +385,7 @@ pango_layout_get_alignment (PangoLayout *layout) **/ void pango_layout_set_text (PangoLayout *layout, - char *text, + const char *text, int length) { g_return_if_fail (layout != NULL); @@ -402,7 +402,7 @@ pango_layout_set_text (PangoLayout *layout, else { unicode_char_t junk; - char *p = text; + const char *p = text; int n_chars = 0; while (*p && (length < 0 || p < text + length)) diff --git a/pango/pango-layout.h b/pango/pango-layout.h index 2a01055d..51c354ff 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -63,7 +63,7 @@ PangoContext *pango_layout_get_context (PangoLayout *layout); void pango_layout_set_attributes (PangoLayout *layout, PangoAttrList *attrs); void pango_layout_set_text (PangoLayout *layout, - char *text, + const char *text, int length); void pango_layout_set_width (PangoLayout *layout, |