summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-03-13 15:59:09 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-03-13 15:59:09 +0000
commita6128c9efba496a2193894ec9ebe7a14404df72e (patch)
treeae1e9c9be775c9b2fe75e51c33b2a9ebd69a272a /examples
parentdf19b2f5a156b717186f8cbc6b1ad39d2401ab90 (diff)
downloadpango-a6128c9efba496a2193894ec9ebe7a14404df72e.tar.gz
Memory management functions for PangoItem.
Mon Mar 13 10:54:48 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-item.[ch]: Memory management functions for PangoItem. * pango/*.[ch]: Random constification. * pango/pangox.c pango/pango-layout.c pango/pango-context.c: Add an extra_attrs field to PangoItem. Use this to handle underlining for PangoLayout. * examples/viewer.c (reload_font): Make paragraphs global to save the complexity of passing it around all over the place. * pango/pango-layout.[ch] (pango_layout_context_changed): Add a function to reset the layout on changes to the layout's context. * pango/pangox.c (pango_x_make_matching_xlfd): Prefer bitmap to scaleable if the discrepancy is < 1 pixel. (Probably not the ideal criterion.) * pango/pangox.c (pango_x_font_map_for_display): Fix resolution computation error. * pango/pango-layout.c (pango_layout_check_lines): Handle text with embedded newlines. * pango/pangox.c (pango_x_render_layout): Fix y to refer to the top of the layout, not the baseline of the first line. * pango/pango-layout.c (process_item): Don't wrap if width is set to -1. * Makefile.am configure.in **/*.[ch]: move libpango/ directory and fix all headers to install under include/pango/
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am6
-rw-r--r--examples/viewer.c53
2 files changed, 33 insertions, 26 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index b794125f..784afb85 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -2,21 +2,21 @@
aliasdir = $(sysconfdir)/pango
-INCLUDES = -I$(top_srcdir)/libpango/
+INCLUDES = -I$(top_srcdir)
if BUILD_TESTS
bin_PROGRAMS = pango-viewer
pango_viewer_SOURCES = \
viewer.c
-pango_viewer_LDADD = ../libpango/libpango.la ../libpango/libpangox.la $(GTK_LIBS) -lfribidi $(UNICODE_LIBS)
+pango_viewer_LDADD = ../pango/libpango.la ../pango/libpangox.la $(GTK_LIBS) -lfribidi $(UNICODE_LIBS)
endif
all-local: pango.modules
pango.modules:
( cd ../modules && \
- ../libpango/pango-querymodules `find . -name '*.so'` > ../examples/pango.modules )
+ ../pango/pango-querymodules `find . -name '*.so'` > ../examples/pango.modules )
EXTRA_DIST=HELLO.utf8 muru.utf pangox_aliases
diff --git a/examples/viewer.c b/examples/viewer.c
index b4c971d1..ccff0b77 100644
--- a/examples/viewer.c
+++ b/examples/viewer.c
@@ -23,8 +23,8 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
-#include "pango.h"
-#include "pangox.h"
+#include <pango/pango.h>
+#include <pango/pangox.h>
#include <unicode.h>
#include <unistd.h>
@@ -34,8 +34,6 @@
#include <stdio.h>
#include <string.h>
-#include "utils.h"
-
#define BUFSIZE 1024
typedef struct _Paragraph Paragraph;
@@ -60,6 +58,8 @@ struct _Paragraph {
int offset; /* Offset from left margin line, in pixels */
};
+GList *paragraphs;
+
static PangoFontDescription font_description;
static Paragraph *highlight_para;
static int highlight_offset;
@@ -124,7 +124,7 @@ static GList *
split_paragraphs (char *text)
{
char *p = text;
- GUChar4 wc;
+ unicode_char_t wc;
GList *result = NULL;
char *last_para = text;
@@ -162,8 +162,7 @@ split_paragraphs (char *text)
* within the paragraph of the click.
*/
gboolean
-xy_to_cp (GList *paragraphs, int width, int x, int y,
- Paragraph **para_return, int *index)
+xy_to_cp (int width, int x, int y, Paragraph **para_return, int *index)
{
GList *para_list;
int height = 0;
@@ -196,8 +195,7 @@ xy_to_cp (GList *paragraphs, int width, int x, int y,
* bounding rectangle for the character at the offset.
*/
void
-char_bounds (GList *paragraphs, Paragraph *para, int index,
- int width, PangoRectangle *rect)
+char_bounds (Paragraph *para, int index, int width, PangoRectangle *rect)
{
GList *para_list;
@@ -229,7 +227,7 @@ char_bounds (GList *paragraphs, Paragraph *para, int index,
*/
void
xor_char (GtkWidget *layout, GdkRectangle *clip_rect,
- GList *paragraphs, Paragraph *para, int offset)
+ Paragraph *para, int offset)
{
static GdkGC *gc;
PangoRectangle rect; /* GdkRectangle in 1.2 is too limited
@@ -247,8 +245,7 @@ xor_char (GtkWidget *layout, GdkRectangle *clip_rect,
gdk_gc_set_clip_rectangle (gc, clip_rect);
- char_bounds (paragraphs, para, offset, layout->allocation.width,
- &rect);
+ char_bounds (para, offset, layout->allocation.width, &rect);
rect.y -= GTK_LAYOUT (layout)->yoffset;
@@ -262,7 +259,7 @@ xor_char (GtkWidget *layout, GdkRectangle *clip_rect,
* then queing a redraw
*/
void
-size_allocate (GtkWidget *layout, GtkAllocation *allocation, GList *paragraphs)
+size_allocate (GtkWidget *layout, GtkAllocation *allocation)
{
GList *tmp_list;
int height = 0;
@@ -296,7 +293,7 @@ size_allocate (GtkWidget *layout, GtkAllocation *allocation, GList *paragraphs)
* the region and reexposing them.
*/
void
-draw (GtkWidget *layout, GdkRectangle *area, GList *paragraphs)
+draw (GtkWidget *layout, GdkRectangle *area)
{
GList *tmp_list;
int height = 0;
@@ -327,43 +324,43 @@ draw (GtkWidget *layout, GdkRectangle *area, GList *paragraphs)
gdk_gc_set_clip_rectangle (layout->style->text_gc[layout->state], NULL);
if (highlight_para)
- xor_char (layout, area, paragraphs, highlight_para, highlight_offset);
+ xor_char (layout, area, highlight_para, highlight_offset);
}
gboolean
-expose (GtkWidget *layout, GdkEventExpose *event, GList *paragraphs)
+expose (GtkWidget *layout, GdkEventExpose *event)
{
if (event->window == GTK_LAYOUT (layout)->bin_window)
- draw (layout, &event->area, paragraphs);
+ draw (layout, &event->area);
return TRUE;
}
void
-button_press (GtkWidget *layout, GdkEventButton *event, GList *paragraphs)
+button_press (GtkWidget *layout, GdkEventButton *event)
{
Paragraph *para = NULL;
int offset;
gchar *message;
- xy_to_cp (paragraphs, layout->allocation.width,
+ xy_to_cp (layout->allocation.width,
event->x, event->y + GTK_LAYOUT (layout)->yoffset,
&para, &offset);
if (highlight_para)
- xor_char (layout, NULL, paragraphs, highlight_para, highlight_offset);
+ xor_char (layout, NULL, highlight_para, highlight_offset);
highlight_para = para;
highlight_offset = offset;
if (para)
{
- GUChar4 wc;
+ unicode_char_t wc;
unicode_get_utf8 (para->text + offset, &wc);
message = g_strdup_printf ("Current char: U%04x", wc);
- xor_char (layout, NULL, paragraphs, highlight_para, highlight_offset);
+ xor_char (layout, NULL, highlight_para, highlight_offset);
}
else
message = g_strdup_printf ("Current char:");
@@ -382,8 +379,19 @@ checkbutton_toggled (GtkWidget *widget, gpointer data)
static void
reload_font ()
{
+ GList *para_list;
+
pango_context_set_font_description (context, &font_description);
+ para_list = paragraphs;
+ while (para_list)
+ {
+ Paragraph *para = para_list->data;
+
+ pango_layout_context_changed (para->layout);
+ para_list = para_list->next;
+ }
+
if (layout)
gtk_widget_queue_resize (layout);
}
@@ -611,7 +619,6 @@ main (int argc, char **argv)
GtkWidget *vbox, *hbox;
GtkWidget *frame;
GtkWidget *checkbutton;
- GList *paragraphs;
gtk_init (&argc, &argv);