diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-12-15 01:10:13 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-12-15 01:10:13 +0000 |
commit | f2bb9b92d5cebe5594e73e2eeea8a1a606da9005 (patch) | |
tree | 0eb5ddbd7f3c77b799603fcc21e444f6d9941d6c | |
parent | 016c4d7047fd3ac2f76667f4ffe3b3a22ad0b902 (diff) | |
download | pango-f2bb9b92d5cebe5594e73e2eeea8a1a606da9005.tar.gz |
Fix macro breakage.
Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com>
* modules/indic/pango-indic-script.h: Fix macro breakage.
* modules/basic/tables-big.i: Remove extra copy of basic_ranges.
* modules/thai/thai.c: Fix various warnings.
* configure.in Makefile.am pangoxft.pc.in pango-config.in
modules/basic/Makefile.am modules/basic/basic-xft.c
pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c
pango/pangoxft.h pango/pangoxft-private.h: Initial support
for rendering via Xft and the Xrender extension.
-rw-r--r-- | .cvsignore | 1 | ||||
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-0 | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-2 | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 14 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 14 | ||||
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | configure.in | 29 | ||||
-rw-r--r-- | modules/basic/Makefile.am | 23 | ||||
-rw-r--r-- | modules/basic/basic-fc.c | 284 | ||||
-rw-r--r-- | modules/basic/basic-x.c | 17 | ||||
-rw-r--r-- | modules/basic/basic-xft.c | 284 | ||||
-rw-r--r-- | modules/basic/basic.c | 17 | ||||
-rw-r--r-- | modules/basic/tables-big.i | 17 | ||||
-rw-r--r-- | modules/indic/pango-indic-script.h | 2 | ||||
-rw-r--r-- | modules/thai/thai-x.c | 96 | ||||
-rw-r--r-- | modules/thai/thai.c | 96 | ||||
-rw-r--r-- | pango-config.in | 6 | ||||
-rw-r--r-- | pango/Makefile.am | 41 | ||||
-rw-r--r-- | pango/pangoxft-font.c | 474 | ||||
-rw-r--r-- | pango/pangoxft-fontmap.c | 499 | ||||
-rw-r--r-- | pango/pangoxft-private.h | 63 | ||||
-rw-r--r-- | pango/pangoxft.h | 61 | ||||
-rw-r--r-- | pangoxft.pc.in | 12 |
26 files changed, 1984 insertions, 143 deletions
@@ -6,6 +6,7 @@ config.log config.status pango.pc pangox.pc +pangoxft.pc pango.spec pango-config stamp-h @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-0 b/ChangeLog.pre-1-0 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-0 +++ b/ChangeLog.pre-1-0 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-2 +++ b/ChangeLog.pre-1-2 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index f38b72af..167c9a80 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,17 @@ +Thu Dec 14 19:00:46 2000 Owen Taylor <otaylor@redhat.com> + + * modules/indic/pango-indic-script.h: Fix macro breakage. + + * modules/basic/tables-big.i: Remove extra copy of basic_ranges. + + * modules/thai/thai.c: Fix various warnings. + + * configure.in Makefile.am pangoxft.pc.in pango-config.in + modules/basic/Makefile.am modules/basic/basic-xft.c + pango/Makefile.am pango/pangoxft-font.[ch] pango/pangoxft-fontmap.c + pango/pangoxft.h pango/pangoxft-private.h: Initial support + for rendering via Xft and the Xrender extension. + 2000-12-14 Havoc Pennington <hp@redhat.com> * pango/fonts.c (pango_font_find_shaper): add assertion that diff --git a/Makefile.am b/Makefile.am index 8d5c10f9..b3b42e8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,11 +9,16 @@ EXTRA_DIST = \ pango-config.in \ pango.pc.in \ pangox.pc.in \ + pangoxft.pc.in \ TODO.xml \ README.win32 +if HAVE_XFT +XFT_PC=pangoxft.pc +endif + pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = pango.pc pangox.pc +pkgconfig_DATA = pango.pc pangox.pc $(XFT_PC) dist-hook: pango.spec cp pango.spec $(distdir) diff --git a/configure.in b/configure.in index 09678255..a4cffeeb 100644 --- a/configure.in +++ b/configure.in @@ -23,13 +23,33 @@ if test "x$GCC" = "xyes"; then fi changequote([,])dnl -AC_PATH_X +AC_PATH_XTRA + if test x$no_x = xyes ; then AC_MSG_ERROR([X development libraries not found]) -fi -X_LIBS="-L$x_libraries -lX11" -AC_SUBST(X_LIBS) +fi + +X_LIBS="$X_LIBS -lX11" + +# +# Checks for Xft/XRender +# +have_xft=false +XFT_LIBS="" +AC_CHECK_LIB(Xrender, XRenderFindFormat, + AC_CHECK_LIB(Xft, XftFontOpen, have_xft=true, :, -lXrender $X_LIBS) +,:,-lXext $X_LIBS) + +if $have_xft = 'true' ; then + XFT_LIBS="-lXft -lXrender -lXext $X_LIBS" +fi + +AC_SUBST(XFT_LIBS) +AM_CONDITIONAL(HAVE_XFT, $have_xft) +# +# Checks for GLib +# AM_PATH_GLIB_2_0(1.3.1,, AC_MSG_ERROR([GLib 1.3.1 is required for building Pango]), gmodule gobject) @@ -292,6 +312,7 @@ pango.spec pango-config pango.pc pangox.pc +pangoxft.pc ],[case "$CONFIG_FILES" in *pango-config*)chmod +x pango-config;; esac]) diff --git a/modules/basic/Makefile.am b/modules/basic/Makefile.am index b2cc5f33..f0daa7ae 100644 --- a/modules/basic/Makefile.am +++ b/modules/basic/Makefile.am @@ -1,6 +1,12 @@ ## Process this file with automake to create Makefile.in. -sources = basic.c +basic_sources = basic.c + +if HAVE_XFT +XFT_MODULES=pango-basic-xft.la +else +XFT_MODULES= +endif if INCLUDE_BASIC noinst_LTLIBRARIES = libpango-basic.la @@ -8,17 +14,21 @@ moddefine = -DMODULE_PREFIX else moduledir = $(libdir)/pango/modules -module_LTLIBRARIES = pango-basic.la +module_LTLIBRARIES = $(XFT_MODULES) pango-basic.la moduleflags=-rpath $(libdir) endif -INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(moddefine) +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(X_CFLAGS) $(moddefine) pango_basic_la_LDFLAGS = $(moduleflags) -export-dynamic -avoid-version -module pango_basic_la_LIBADD = -pango_basic_la_SOURCES = $(sources) +pango_basic_la_SOURCES = $(basic_sources) -libpango_basic_la_SOURCES = $(sources) +libpango_basic_la_SOURCES = $(basic_sources) + +pango_basic_xft_la_LDFLAGS = -rpath $(libdir) -export-dynamic -avoid-version -module +pango_basic_xft_la_LIBADD = +pango_basic_xft_la_SOURCES = basic-xft.c EXTRA_DIST = \ tables-big.i \ @@ -27,6 +37,3 @@ EXTRA_DIST = \ basic-ft2.c \ makefile.mingw \ makefile.mingw.in - -makefile.mingw: $(top_builddir)/config.status $(top_srcdir)/modules/basic/makefile.mingw.in - cd $(top_builddir) && CONFIG_FILES=modules/basic/$@ CONFIG_HEADERS= $(SHELL) ./config.status diff --git a/modules/basic/basic-fc.c b/modules/basic/basic-fc.c new file mode 100644 index 00000000..979a3772 --- /dev/null +++ b/modules/basic/basic-fc.c @@ -0,0 +1,284 @@ +/* Pango + * basic-xft.h: + * + * Copyright (C) 2000 Red Hat Software + * Author: Owen Taylor <otaylor@redhat.com> + * + * 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 "pangoxft.h" +#include "pango-utils.h" + +static PangoEngineRange basic_ranges[] = { + /* Language characters */ + { 0x0380, 0x058f, "*" }, + { 0x0591, 0x05f4, "*" }, /* Hebrew */ + { 0x060c, 0x06f9, "" }, /* Arabic */ + { 0x0e01, 0x0e5b, "" }, /* Thai */ + { 0x10a0, 0x10ff, "*" }, /* Georgian */ + { 0x1200, 0x16ff, "*" }, /* Ethiopic,Cherokee,Canadian,Ogham,Runic */ + { 0x1e00, 0x1fff, "*" }, + { 0x2000, 0x9fff, "*" }, + { 0xac00, 0xd7a3, "kr" }, + { 0xf900, 0xfa0b, "kr" }, + { 0xff00, 0xffe3, "*" }, + { 0x0000, 0xffff, "" }, +}; + +static PangoEngineInfo script_engines[] = { + { + "BasicScriptEngineXft", + PANGO_ENGINE_TYPE_SHAPE, + PANGO_RENDER_TYPE_XFT, + basic_ranges, G_N_ELEMENTS(basic_ranges) + } +}; + +static void +swap_range (PangoGlyphString *glyphs, int start, int end) +{ + int i, j; + + for (i = start, j = end - 1; i < j; i++, j--) + { + PangoGlyphInfo glyph_info; + gint log_cluster; + + glyph_info = glyphs->glyphs[i]; + glyphs->glyphs[i] = glyphs->glyphs[j]; + glyphs->glyphs[j] = glyph_info; + + log_cluster = glyphs->log_clusters[i]; + glyphs->log_clusters[i] = glyphs->log_clusters[j]; + glyphs->log_clusters[j] = log_cluster; + } +} + +static void +set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph) +{ + PangoRectangle logical_rect; + + glyphs->glyphs[i].glyph = glyph; + + glyphs->glyphs[i].geometry.x_offset = 0; + glyphs->glyphs[i].geometry.y_offset = 0; + + glyphs->log_clusters[i] = offset; + + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect); + glyphs->glyphs[i].geometry.width = logical_rect.width; +} + +static guint +find_char (Display *display, PangoFont *font, gunichar wc) +{ + XftFont *xft_font = pango_xft_font_get_font (font); + + if (XftGlyphExists (display, xft_font, wc)) + return wc; + else + return 0; +} + +static void +basic_engine_shape (PangoFont *font, + const char *text, + gint length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + int n_chars; + int i; + const char *p; + Display *display; + + g_return_if_fail (font != NULL); + g_return_if_fail (text != NULL); + g_return_if_fail (length >= 0); + g_return_if_fail (analysis != NULL); + + display = pango_xft_font_get_display (font); + + n_chars = g_utf8_strlen (text, length); + pango_glyph_string_set_size (glyphs, n_chars); + + p = text; + for (i=0; i < n_chars; i++) + { + gunichar wc; + gunichar mirrored_ch; + PangoGlyph index; + char buf[6]; + const char *input; + + wc = g_utf8_get_char (p); + + input = p; + if (analysis->level % 2) + if (pango_get_mirror_char (wc, &mirrored_ch)) + { + wc = mirrored_ch; + + g_unichar_to_utf8 (wc, buf); + input = buf; + } + + if (wc == 0x200B || wc == 0x200E || wc == 0x200F) /* Zero-width characters */ + { + set_glyph (font, glyphs, i, p - text, 0); + } + else + { + index = find_char (display, font, wc); + + if (!index) + { + set_glyph (font, glyphs, i, p - text, + pango_xft_font_get_unknown_glyph (font, wc)); + +#if 0 + gint j; + char buf[9]; + int len = (wc < 65536) ? 6 : 8; + + sprintf(buf, "[%0*X]", len - 2, wc); + + n_chars += len - 1; + pango_glyph_string_set_size (glyphs, n_chars); + for (j=0; j < len; j++) + { + set_glyph (font, glyphs, i + j, + p - text, find_char (display, font, buf[j])); + } + i += len - 1; +#endif + } + else + { + set_glyph (font, glyphs, i, p - text, index); + + if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK) + { + if (i > 0) + { + PangoRectangle logical_rect, ink_rect; + + glyphs->glyphs[i].geometry.width = MAX (glyphs->glyphs[i-1].geometry.width, + glyphs->glyphs[i].geometry.width); + glyphs->glyphs[i-1].geometry.width = 0; + glyphs->log_clusters[i] = glyphs->log_clusters[i-1]; + + /* Some heuristics to try to guess how overstrike glyphs are + * done and compensate + */ + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, &ink_rect, &logical_rect); + if (logical_rect.width == 0 && ink_rect.x == 0) + glyphs->glyphs[i].geometry.x_offset = (glyphs->glyphs[i].geometry.width - ink_rect.width) / 2; + } + } + } + } + + p = g_utf8_next_char (p); + } + + /* Simple bidi support... may have separate modules later */ + + if (analysis->level % 2) + { + int start, end; + + /* Swap all glyphs */ + swap_range (glyphs, 0, n_chars); + + /* Now reorder glyphs within each cluster back to LTR */ + for (start=0; start<n_chars;) + { + end = start; + while (end < n_chars && + glyphs->log_clusters[end] == glyphs->log_clusters[start]) + end++; + + swap_range (glyphs, start, end); + start = end; + } + } +} + +static PangoCoverage * +basic_engine_get_coverage (PangoFont *font, + const char *lang) +{ + return pango_font_get_coverage (font, lang); +} + +static PangoEngine * +basic_engine_xft_new () +{ + PangoEngineShape *result; + + result = g_new (PangoEngineShape, 1); + + result->engine.id = PANGO_RENDER_TYPE_XFT; + result->engine.type = PANGO_ENGINE_TYPE_SHAPE; + result->engine.length = sizeof (result); + result->script_shape = basic_engine_shape; + result->get_coverage = basic_engine_get_coverage; + + return (PangoEngine *)result; +} + +/* The following three functions provide the public module API for + * Pango. If we are compiling it is a module, then we name the + * entry points script_engine_list, etc. But if we are compiling + * it for inclusion directly in Pango, then we need them to + * to have distinct names for this module, so we prepend + * _pango_basic_ + */ +#ifdef MODULE_PREFIX +#define MODULE_ENTRY(func) _pango_basic_##func +#else +#define MODULE_ENTRY(func) func +#endif + +/* List the engines contained within this module + */ +void +MODULE_ENTRY(script_engine_list) (PangoEngineInfo **engines, gint *n_engines) +{ + *engines = script_engines; + *n_engines = G_N_ELEMENTS (script_engines); +} + +/* Load a particular engine given the ID for the engine + */ +PangoEngine * +MODULE_ENTRY(script_engine_load) (const char *id) +{ + if (!strcmp (id, "BasicScriptEngineXft")) + return basic_engine_xft_new (); + else + return NULL; +} + +void +MODULE_ENTRY(script_engine_unload) (PangoEngine *engine) +{ +} diff --git a/modules/basic/basic-x.c b/modules/basic/basic-x.c index ab54aa9b..4169fe6c 100644 --- a/modules/basic/basic-x.c +++ b/modules/basic/basic-x.c @@ -77,6 +77,23 @@ static PangoGlyph conv_ucs4 (CharCache *cache, #include "tables-big.i" +static PangoEngineRange basic_ranges[] = { + /* Language characters */ + { 0x0000, 0x02af, "*" }, + { 0x02b0, 0x02ff, "" }, + { 0x0380, 0x058f, "*" }, + { 0x0591, 0x05f4, "*" }, /* Hebrew */ + { 0x060c, 0x06f9, "" }, /* Arabic */ + { 0x0e01, 0x0e5b, "" }, /* Thai */ + { 0x10a0, 0x10ff, "*" }, /* Georgian */ + { 0x1200, 0x16ff, "*" }, /* Ethiopic,Cherokee,Canadian,Ogham,Runic */ + { 0x1e00, 0x1fff, "*" }, + { 0x2000, 0x9fff, "*" }, + { 0xac00, 0xd7a3, "kr" }, + { 0xf900, 0xfa0b, "kr" }, + { 0xff00, 0xffe3, "*" } +}; + static PangoEngineInfo script_engines[] = { { "BasicScriptEngineX", diff --git a/modules/basic/basic-xft.c b/modules/basic/basic-xft.c new file mode 100644 index 00000000..979a3772 --- /dev/null +++ b/modules/basic/basic-xft.c @@ -0,0 +1,284 @@ +/* Pango + * basic-xft.h: + * + * Copyright (C) 2000 Red Hat Software + * Author: Owen Taylor <otaylor@redhat.com> + * + * 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 "pangoxft.h" +#include "pango-utils.h" + +static PangoEngineRange basic_ranges[] = { + /* Language characters */ + { 0x0380, 0x058f, "*" }, + { 0x0591, 0x05f4, "*" }, /* Hebrew */ + { 0x060c, 0x06f9, "" }, /* Arabic */ + { 0x0e01, 0x0e5b, "" }, /* Thai */ + { 0x10a0, 0x10ff, "*" }, /* Georgian */ + { 0x1200, 0x16ff, "*" }, /* Ethiopic,Cherokee,Canadian,Ogham,Runic */ + { 0x1e00, 0x1fff, "*" }, + { 0x2000, 0x9fff, "*" }, + { 0xac00, 0xd7a3, "kr" }, + { 0xf900, 0xfa0b, "kr" }, + { 0xff00, 0xffe3, "*" }, + { 0x0000, 0xffff, "" }, +}; + +static PangoEngineInfo script_engines[] = { + { + "BasicScriptEngineXft", + PANGO_ENGINE_TYPE_SHAPE, + PANGO_RENDER_TYPE_XFT, + basic_ranges, G_N_ELEMENTS(basic_ranges) + } +}; + +static void +swap_range (PangoGlyphString *glyphs, int start, int end) +{ + int i, j; + + for (i = start, j = end - 1; i < j; i++, j--) + { + PangoGlyphInfo glyph_info; + gint log_cluster; + + glyph_info = glyphs->glyphs[i]; + glyphs->glyphs[i] = glyphs->glyphs[j]; + glyphs->glyphs[j] = glyph_info; + + log_cluster = glyphs->log_clusters[i]; + glyphs->log_clusters[i] = glyphs->log_clusters[j]; + glyphs->log_clusters[j] = log_cluster; + } +} + +static void +set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph) +{ + PangoRectangle logical_rect; + + glyphs->glyphs[i].glyph = glyph; + + glyphs->glyphs[i].geometry.x_offset = 0; + glyphs->glyphs[i].geometry.y_offset = 0; + + glyphs->log_clusters[i] = offset; + + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect); + glyphs->glyphs[i].geometry.width = logical_rect.width; +} + +static guint +find_char (Display *display, PangoFont *font, gunichar wc) +{ + XftFont *xft_font = pango_xft_font_get_font (font); + + if (XftGlyphExists (display, xft_font, wc)) + return wc; + else + return 0; +} + +static void +basic_engine_shape (PangoFont *font, + const char *text, + gint length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + int n_chars; + int i; + const char *p; + Display *display; + + g_return_if_fail (font != NULL); + g_return_if_fail (text != NULL); + g_return_if_fail (length >= 0); + g_return_if_fail (analysis != NULL); + + display = pango_xft_font_get_display (font); + + n_chars = g_utf8_strlen (text, length); + pango_glyph_string_set_size (glyphs, n_chars); + + p = text; + for (i=0; i < n_chars; i++) + { + gunichar wc; + gunichar mirrored_ch; + PangoGlyph index; + char buf[6]; + const char *input; + + wc = g_utf8_get_char (p); + + input = p; + if (analysis->level % 2) + if (pango_get_mirror_char (wc, &mirrored_ch)) + { + wc = mirrored_ch; + + g_unichar_to_utf8 (wc, buf); + input = buf; + } + + if (wc == 0x200B || wc == 0x200E || wc == 0x200F) /* Zero-width characters */ + { + set_glyph (font, glyphs, i, p - text, 0); + } + else + { + index = find_char (display, font, wc); + + if (!index) + { + set_glyph (font, glyphs, i, p - text, + pango_xft_font_get_unknown_glyph (font, wc)); + +#if 0 + gint j; + char buf[9]; + int len = (wc < 65536) ? 6 : 8; + + sprintf(buf, "[%0*X]", len - 2, wc); + + n_chars += len - 1; + pango_glyph_string_set_size (glyphs, n_chars); + for (j=0; j < len; j++) + { + set_glyph (font, glyphs, i + j, + p - text, find_char (display, font, buf[j])); + } + i += len - 1; +#endif + } + else + { + set_glyph (font, glyphs, i, p - text, index); + + if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK) + { + if (i > 0) + { + PangoRectangle logical_rect, ink_rect; + + glyphs->glyphs[i].geometry.width = MAX (glyphs->glyphs[i-1].geometry.width, + glyphs->glyphs[i].geometry.width); + glyphs->glyphs[i-1].geometry.width = 0; + glyphs->log_clusters[i] = glyphs->log_clusters[i-1]; + + /* Some heuristics to try to guess how overstrike glyphs are + * done and compensate + */ + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, &ink_rect, &logical_rect); + if (logical_rect.width == 0 && ink_rect.x == 0) + glyphs->glyphs[i].geometry.x_offset = (glyphs->glyphs[i].geometry.width - ink_rect.width) / 2; + } + } + } + } + + p = g_utf8_next_char (p); + } + + /* Simple bidi support... may have separate modules later */ + + if (analysis->level % 2) + { + int start, end; + + /* Swap all glyphs */ + swap_range (glyphs, 0, n_chars); + + /* Now reorder glyphs within each cluster back to LTR */ + for (start=0; start<n_chars;) + { + end = start; + while (end < n_chars && + glyphs->log_clusters[end] == glyphs->log_clusters[start]) + end++; + + swap_range (glyphs, start, end); + start = end; + } + } +} + +static PangoCoverage * +basic_engine_get_coverage (PangoFont *font, + const char *lang) +{ + return pango_font_get_coverage (font, lang); +} + +static PangoEngine * +basic_engine_xft_new () +{ + PangoEngineShape *result; + + result = g_new (PangoEngineShape, 1); + + result->engine.id = PANGO_RENDER_TYPE_XFT; + result->engine.type = PANGO_ENGINE_TYPE_SHAPE; + result->engine.length = sizeof (result); + result->script_shape = basic_engine_shape; + result->get_coverage = basic_engine_get_coverage; + + return (PangoEngine *)result; +} + +/* The following three functions provide the public module API for + * Pango. If we are compiling it is a module, then we name the + * entry points script_engine_list, etc. But if we are compiling + * it for inclusion directly in Pango, then we need them to + * to have distinct names for this module, so we prepend + * _pango_basic_ + */ +#ifdef MODULE_PREFIX +#define MODULE_ENTRY(func) _pango_basic_##func +#else +#define MODULE_ENTRY(func) func +#endif + +/* List the engines contained within this module + */ +void +MODULE_ENTRY(script_engine_list) (PangoEngineInfo **engines, gint *n_engines) +{ + *engines = script_engines; + *n_engines = G_N_ELEMENTS (script_engines); +} + +/* Load a particular engine given the ID for the engine + */ +PangoEngine * +MODULE_ENTRY(script_engine_load) (const char *id) +{ + if (!strcmp (id, "BasicScriptEngineXft")) + return basic_engine_xft_new (); + else + return NULL; +} + +void +MODULE_ENTRY(script_engine_unload) (PangoEngine *engine) +{ +} diff --git a/modules/basic/basic.c b/modules/basic/basic.c index ab54aa9b..4169fe6c 100644 --- a/modules/basic/basic.c +++ b/modules/basic/basic.c @@ -77,6 +77,23 @@ static PangoGlyph conv_ucs4 (CharCache *cache, #include "tables-big.i" +static PangoEngineRange basic_ranges[] = { + /* Language characters */ + { 0x0000, 0x02af, "*" }, + { 0x02b0, 0x02ff, "" }, + { 0x0380, 0x058f, "*" }, + { 0x0591, 0x05f4, "*" }, /* Hebrew */ + { 0x060c, 0x06f9, "" }, /* Arabic */ + { 0x0e01, 0x0e5b, "" }, /* Thai */ + { 0x10a0, 0x10ff, "*" }, /* Georgian */ + { 0x1200, 0x16ff, "*" }, /* Ethiopic,Cherokee,Canadian,Ogham,Runic */ + { 0x1e00, 0x1fff, "*" }, + { 0x2000, 0x9fff, "*" }, + { 0xac00, 0xd7a3, "kr" }, + { 0xf900, 0xfa0b, "kr" }, + { 0xff00, 0xffe3, "*" } +}; + static PangoEngineInfo script_engines[] = { { "BasicScriptEngineX", diff --git a/modules/basic/tables-big.i b/modules/basic/tables-big.i index 0e7bf27f..2de955b9 100644 --- a/modules/basic/tables-big.i +++ b/modules/basic/tables-big.i @@ -42,23 +42,6 @@ Charset charsets[] = { { 18, "ISO-10646", "iso10646-1", conv_ucs4 } }; -static PangoEngineRange basic_ranges[] = { - /* Language characters */ - { 0x0000, 0x02af, "*" }, - { 0x02b0, 0x02ff, "" }, - { 0x0380, 0x058f, "*" }, - { 0x0591, 0x05f4, "*" }, /* Hebrew */ - { 0x060c, 0x06f9, "" }, /* Arabic */ - { 0x0e01, 0x0e5b, "" }, /* Thai */ - { 0x10a0, 0x10ff, "*" }, /* Georgian */ - { 0x1200, 0x16ff, "*" }, /* Ethiopic,Cherokee,Canadian,Ogham,Runic */ - { 0x1e00, 0x1fff, "*" }, - { 0x2000, 0x9fff, "*" }, - { 0xac00, 0xd7a3, "kr" }, - { 0xf900, 0xfa0b, "kr" }, - { 0xff00, 0xffe3, "*" } -}; - const guint32 char_mask_map[] = { 0, ENC_ISO_8859_10|ENC_ISO_8859_1|ENC_ISO_8859_13|ENC_ISO_8859_14|ENC_ISO_8859_15|ENC_ISO_8859_2|ENC_ISO_8859_3|ENC_ISO_8859_4|ENC_ISO_8859_5|ENC_ISO_8859_6|ENC_ISO_8859_7|ENC_ISO_8859_8|ENC_ISO_8859_9|ENC_KOI8_R, diff --git a/modules/indic/pango-indic-script.h b/modules/indic/pango-indic-script.h index 8a4c40a3..c041c845 100644 --- a/modules/indic/pango-indic-script.h +++ b/modules/indic/pango-indic-script.h @@ -22,6 +22,6 @@ }; \ static gint n_script_engines = G_N_ELEMENTS (script_engines); -#define pango_indic_get_char ( (chars) >= (end) ? 0 : *(chars) ) +#define pango_indic_get_char(chars,end) ( (chars) >= (end) ? 0 : *(chars) ) #endif diff --git a/modules/thai/thai-x.c b/modules/thai/thai-x.c index c6c2a6cc..b32721b4 100644 --- a/modules/thai/thai-x.c +++ b/modules/thai/thai-x.c @@ -1,4 +1,4 @@ -/* pANGO +/* Pango * thai.c: * * Copyright (C) 1999 Red Hat Software @@ -27,6 +27,8 @@ */ +#include <string.h> + #include <glib.h> #include <string.h> #include "pango.h" @@ -238,40 +240,40 @@ static const gint TAC_char_class[256] = { static const gchar TAC_compose_and_input_check_type_table[17][17] = { /* Cn */ /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */ - /* Cn-1 00 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 10 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 20 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', - 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', - /* 30 */ 'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 40 */ 'X', 'S', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 50 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 60 */ 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 70 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R', - /* 80 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R', - /* 90 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* A0 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* B0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* C0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* D0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* E0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R', - /* F0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R', - 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' + /* Cn-1 00 */ { 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 10 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 20 */ { 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', + 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C' }, + /* 30 */ {'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 40 */ { 'X', 'S', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 50 */ { 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 60 */ { 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 70 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' }, + /* 80 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 90 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* A0 */ { 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* B0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* C0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* D0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* E0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' }, + /* F0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' }, + { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' } }; typedef struct { @@ -439,10 +441,10 @@ add_glyph (ThaiFontInfo *font_info, static gint get_adjusted_glyphs_list (ThaiFontInfo *font_info, - gunichar *cluster, - gint num_chrs, - PangoGlyph **glyph_lists, - const ThaiShapeTable *shaping_table) + gunichar *cluster, + gint num_chrs, + PangoGlyph *glyph_lists, + const ThaiShapeTable *shaping_table) { switch (num_chrs) { @@ -665,7 +667,7 @@ static gint get_glyphs_list (ThaiFontInfo *font_info, gunichar *cluster, gint num_chrs, - PangoGlyph **glyph_lists) + PangoGlyph *glyph_lists) { PangoGlyph glyph; gint xtis_index; @@ -737,7 +739,7 @@ add_cluster (ThaiFontInfo *font_info, gint num_glyphs; gint i; - num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, &glyphs_list); + num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, glyphs_list); for (i=0; i<num_glyphs; i++) add_glyph (font_info, glyphs, cluster_start, glyphs_list[i], i == 0 ? FALSE : TRUE); @@ -758,12 +760,15 @@ is_wtt_composible (gunichar cur_wc, gunichar nxt_wc) case 'C': return TRUE; } + + g_assert_not_reached (); + return FALSE; } static const char * get_next_cluster(const char *text, gint length, - gunichar **cluster, + gunichar *cluster, gint *num_chrs) { const char *p; @@ -808,11 +813,6 @@ thai_engine_shape (PangoFont *font, gunichar cluster[MAX_CLUSTER_CHRS]; gint num_chrs; - gunichar base = 0; - gunichar group1 = 0; - gunichar group2 = 0; - int cluster_start = 0; - pango_glyph_string_set_size (glyphs, 0); font_info = get_font_info (font); @@ -821,7 +821,7 @@ thai_engine_shape (PangoFont *font, while (p < text + length) { log_cluster = p; - p = get_next_cluster (p, text + length - p, &cluster, &num_chrs); + p = get_next_cluster (p, text + length - p, cluster, &num_chrs); add_cluster (font_info, glyphs, log_cluster - text, cluster, num_chrs); } } diff --git a/modules/thai/thai.c b/modules/thai/thai.c index c6c2a6cc..b32721b4 100644 --- a/modules/thai/thai.c +++ b/modules/thai/thai.c @@ -1,4 +1,4 @@ -/* pANGO +/* Pango * thai.c: * * Copyright (C) 1999 Red Hat Software @@ -27,6 +27,8 @@ */ +#include <string.h> + #include <glib.h> #include <string.h> #include "pango.h" @@ -238,40 +240,40 @@ static const gint TAC_char_class[256] = { static const gchar TAC_compose_and_input_check_type_table[17][17] = { /* Cn */ /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */ - /* Cn-1 00 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 10 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 20 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', - 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', - /* 30 */ 'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 40 */ 'X', 'S', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 50 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 60 */ 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* 70 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R', - /* 80 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R', - /* 90 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* A0 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* B0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* C0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* D0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', - /* E0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R', - /* F0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R', - 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', - 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' + /* Cn-1 00 */ { 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 10 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 20 */ { 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', + 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C' }, + /* 30 */ {'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 40 */ { 'X', 'S', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 50 */ { 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 60 */ { 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 70 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' }, + /* 80 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* 90 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* A0 */ { 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* B0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* C0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* D0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' }, + /* E0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' }, + /* F0 */ { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' }, + { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', + 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' } }; typedef struct { @@ -439,10 +441,10 @@ add_glyph (ThaiFontInfo *font_info, static gint get_adjusted_glyphs_list (ThaiFontInfo *font_info, - gunichar *cluster, - gint num_chrs, - PangoGlyph **glyph_lists, - const ThaiShapeTable *shaping_table) + gunichar *cluster, + gint num_chrs, + PangoGlyph *glyph_lists, + const ThaiShapeTable *shaping_table) { switch (num_chrs) { @@ -665,7 +667,7 @@ static gint get_glyphs_list (ThaiFontInfo *font_info, gunichar *cluster, gint num_chrs, - PangoGlyph **glyph_lists) + PangoGlyph *glyph_lists) { PangoGlyph glyph; gint xtis_index; @@ -737,7 +739,7 @@ add_cluster (ThaiFontInfo *font_info, gint num_glyphs; gint i; - num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, &glyphs_list); + num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, glyphs_list); for (i=0; i<num_glyphs; i++) add_glyph (font_info, glyphs, cluster_start, glyphs_list[i], i == 0 ? FALSE : TRUE); @@ -758,12 +760,15 @@ is_wtt_composible (gunichar cur_wc, gunichar nxt_wc) case 'C': return TRUE; } + + g_assert_not_reached (); + return FALSE; } static const char * get_next_cluster(const char *text, gint length, - gunichar **cluster, + gunichar *cluster, gint *num_chrs) { const char *p; @@ -808,11 +813,6 @@ thai_engine_shape (PangoFont *font, gunichar cluster[MAX_CLUSTER_CHRS]; gint num_chrs; - gunichar base = 0; - gunichar group1 = 0; - gunichar group2 = 0; - int cluster_start = 0; - pango_glyph_string_set_size (glyphs, 0); font_info = get_font_info (font); @@ -821,7 +821,7 @@ thai_engine_shape (PangoFont *font, while (p < text + length) { log_cluster = p; - p = get_next_cluster (p, text + length - p, &cluster, &num_chrs); + p = get_next_cluster (p, text + length - p, cluster, &num_chrs); add_cluster (font_info, glyphs, log_cluster - text, cluster, num_chrs); } } diff --git a/pango-config.in b/pango-config.in index df116b31..725d43cb 100644 --- a/pango-config.in +++ b/pango-config.in @@ -66,6 +66,9 @@ while test $# -gt 0; do pangox) lib_pangox=yes ;; + pangoxft) + lib_pangoxft=yes + ;; *) usage 1 1>&2 ;; @@ -90,5 +93,8 @@ if test "$echo_libs" = "yes"; then if test "$lib_pangox" = "yes"; then libs="@X_LIBS@ -lpangox $libs" fi + if test "$lib_pangoxft" = "yes"; then + libs="@XFT_LIBS@ -lpangoxft $libs" + fi echo -L@libdir@ $libs fi diff --git a/pango/Makefile.am b/pango/Makefile.am index 4df0d880..7ffb4114 100644 --- a/pango/Makefile.am +++ b/pango/Makefile.am @@ -8,9 +8,19 @@ endif INCLUDES = \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DLIBDIR=\"$(libdir)\" \ + $(X_CFLAGS) \ -I$(top_srcdir) -lib_LTLIBRARIES = libpango.la libpangox.la +if HAVE_XFT +XFT_HFILES=pangoxft.h +XFT_BUILD_LIBS=libpangoxft.la +else +XFT_HFILES= +XFT_BUILD_LIBS= +endif + +lib_LTLIBRARIES = libpango.la libpangox.la $(XFT_BUILD_LIBS) + bin_PROGRAMS = pango-querymodules libpango_la_SOURCES = \ @@ -53,7 +63,14 @@ libpango_la_LIBADD = mini-fribidi/libmini-fribidi.la endif libpangox_la_LDFLAGS = -release $(VERSION) -libpangox_la_LIBADD = $(INCLUDED_MODULES) +libpangox_la_LIBADD = $(INCLUDED_MODULES) $(X_LIBS) + +libpangoxft_la_SOURCES = \ + pangoxft-font.c \ + pangoxft-fontmap.c + +libpangoxft_la_LIBADD = $(INCLUDED_MODULES) $(XFT_LIBS) +libpangoxft_la_LDFLAGS = -release $(VERSION) pangoincludedir=$(includedir)/pango-1.0/pango @@ -73,14 +90,19 @@ pangoinclude_HEADERS = \ pango-tabs.h \ pango-types.h \ pango-utils.h \ - pangox.h + pangox.h \ + $(XFT_HFILES) # # As a temporary hack, we pull in libpangox here so that we can link # pango_querymodules_SOURCES = \ querymodules.c +if HAVE_XFT +pango_querymodules_LDADD = libpangox.la libpangoxft.la libpango.la $(GLIB_LIBS) $(FRIBIDI_LIBS) $(XFT_LIBS) +else pango_querymodules_LDADD = libpangox.la libpango.la $(GLIB_LIBS) $(FRIBIDI_LIBS) $(X_LIBS) +endif EXTRA_DIST = \ module-defs.c.win32 \ @@ -105,16 +127,3 @@ EXTRA_DIST = \ pangoft2.rc.in \ pangowin32.rc \ pangowin32.rc.in - - -makefile.mingw: $(top_builddir)/config.status $(top_srcdir)/pango/makefile.mingw.in - cd $(top_builddir) && CONFIG_FILES=pango/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -pango2.rc: $(top_builddir)/config.status $(top_srcdir)/pango/pango.rc.in - cd $(top_builddir) && CONFIG_FILES=pango/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -pangoft2.rc: $(top_builddir)/config.status $(top_srcdir)/pango/pangoft2.rc.in - cd $(top_builddir) && CONFIG_FILES=pango/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -pangowin32.rc: $(top_builddir)/config.status $(top_srcdir)/pango/pangowin32.rc.in - cd $(top_builddir) && CONFIG_FILES=pango/$@ CONFIG_HEADERS= $(SHELL) ./config.status diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c new file mode 100644 index 00000000..66a3d356 --- /dev/null +++ b/pango/pangoxft-font.c @@ -0,0 +1,474 @@ +/* Pango + * pangoxft-font.c: Routines for handling X fonts + * + * Copyright (C) 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 "pangoxft-private.h" +#include "X11/Xft/XftFreetype.h" +#include "modules.h" + +#define PANGO_TYPE_XFT_FONT (pango_xft_font_get_type ()) +#define PANGO_XFT_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_XFT_FONT, PangoXftFont)) +#define PANGO_XFT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_XFT_FONT, PangoXftFontClass)) +#define PANGO_XFT_IS_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_XFT_FONT)) +#define PANGO_XFT_IS_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_XFT_FONT)) +#define PANGO_XFT_FONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_XFT_FONT, PangoXftFontClass)) + +#define PANGO_XFT_UNKNOWN_FLAG 0x10000000 + +typedef struct _PangoXftFontClass PangoXftFontClass; + +struct _PangoXftFontClass +{ + PangoFontClass parent_class; +}; + +static PangoFontClass *parent_class; /* Parent class structure for PangoXftFont */ + +static void pango_xft_font_class_init (PangoXftFontClass *class); +static void pango_xft_font_init (PangoXftFont *xfont); +static void pango_xft_font_shutdown (GObject *object); +static void pango_xft_font_finalize (GObject *object); + +static PangoFontDescription *pango_xft_font_describe (PangoFont *font); +static PangoCoverage * pango_xft_font_get_coverage (PangoFont *font, + const char *lang); +static PangoEngineShape * pango_xft_font_find_shaper (PangoFont *font, + const char *lang, + guint32 ch); +static void pango_xft_font_get_glyph_extents (PangoFont *font, + PangoGlyph glyph, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect); +static void pango_xft_font_get_metrics (PangoFont *font, + const gchar *lang, + PangoFontMetrics *metrics); + + +static GType +pango_xft_font_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoXftFontClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_xft_font_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoXftFont), + 0, /* n_preallocs */ + (GInstanceInitFunc) pango_xft_font_init, + }; + + object_type = g_type_register_static (PANGO_TYPE_FONT, + "PangoXftFont", + &object_info, 0); + } + + return object_type; +} + +static void +pango_xft_font_init (PangoXftFont *xfont) +{ + xfont->in_cache = FALSE; +} + +static void +pango_xft_font_class_init (PangoXftFontClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontClass *font_class = PANGO_FONT_CLASS (class); + + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = pango_xft_font_finalize; + object_class->shutdown = pango_xft_font_shutdown; + + font_class->describe = pango_xft_font_describe; + font_class->get_coverage = pango_xft_font_get_coverage; + font_class->find_shaper = pango_xft_font_find_shaper; + font_class->get_glyph_extents = pango_xft_font_get_glyph_extents; + font_class->get_metrics = pango_xft_font_get_metrics; +} + +PangoXftFont * +_pango_xft_font_new (PangoFontMap *fontmap, + const PangoFontDescription *description, + XftFont *xft_font) +{ + PangoXftFont *xfont; + + g_return_val_if_fail (fontmap != NULL, NULL); + g_return_val_if_fail (description != NULL, NULL); + g_return_val_if_fail (xft_font != NULL, NULL); + + xfont = (PangoXftFont *)g_object_new (PANGO_TYPE_XFT_FONT, NULL); + + xfont->fontmap = fontmap; + + g_object_ref (G_OBJECT (fontmap)); + xfont->description = pango_font_description_copy (description); + xfont->xft_font = xft_font; + + _pango_xft_font_map_add (xfont->fontmap, xfont); + + return xfont; +} + +static PangoFont * +get_mini_font (PangoFont *font) +{ + PangoXftFont *xfont = (PangoXftFont *)font; + + if (!xfont->mini_font) + { + Display *display; + PangoFontDescription desc; + int i; + int width = 0, height = 0; + XGlyphInfo extents; + XftFont *mini_xft; + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + + desc.family_name = "monospace"; + desc.style = PANGO_STYLE_NORMAL; + desc.variant = PANGO_VARIANT_NORMAL; + desc.weight = PANGO_WEIGHT_NORMAL; + + desc.size = 0.5 * xfont->description->size; + + xfont->mini_font = pango_font_map_load_font (xfont->fontmap, &desc); + mini_xft = ((PangoXftFont *)xfont->mini_font)->xft_font; + + for (i = 0 ; i < 16 ; i++) + { + char c = i < 10 ? '0' + i : 'A' + i - 10; + + XftTextExtents8 (display, mini_xft, &c, 1, &extents); + + width = MAX (width, extents.width); + height = MAX (height, extents.height); + } + + xfont->mini_width = width; + xfont->mini_height = height; + xfont->mini_pad = MAX (height / 10, 1); + } + + return xfont->mini_font; +} + +static void +draw_box (XftDraw *draw, + XftColor *color, + PangoXftFont *xfont, + gint x, + gint y, + gint width, + gint height) +{ + XftDrawRect (draw, color, + x, y, width, xfont->mini_pad); + XftDrawRect (draw, color, + x, y + xfont->mini_pad, xfont->mini_pad, height - xfont->mini_pad * 2); + XftDrawRect (draw, color, + x + width - xfont->mini_pad, y + xfont->mini_pad, xfont->mini_pad, height - xfont->mini_pad * 2); + XftDrawRect (draw, color, + x, y + height - xfont->mini_pad, width, xfont->mini_pad); +} + +void +pango_xft_render (XftDraw *draw, + XftColor *color, + PangoFont *font, + PangoGlyphString *glyphs, + gint x, + gint y) +{ + PangoXftFont *xfont = PANGO_XFT_FONT (font); + Display *display; + int i; + int x_off = 0; + + g_return_if_fail (draw != NULL); + g_return_if_fail (color != NULL); + g_return_if_fail (font != NULL); + g_return_if_fail (glyphs != NULL); + + /* Slow initial implementation. For speed, it should really + * collect the characters into runs, and draw multiple + * characters with each XftDrawString32 call. + */ + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + + for (i=0; i<glyphs->num_glyphs; i++) + { + PangoGlyph glyph = glyphs->glyphs[i].glyph; + + if (glyph) + { + if (glyph & PANGO_XFT_UNKNOWN_FLAG) + { + char buf[5]; + int ys[3]; + int xs[3]; + int j, k; + + PangoFont *mini_font = get_mini_font (font); + XftFont *mini_xft = ((PangoXftFont *)mini_font)->xft_font; + + glyph &= ~PANGO_XFT_UNKNOWN_FLAG; + + ys[0] = y + PANGO_PIXELS (glyphs->glyphs[i].geometry.y_offset) - xfont->xft_font->ascent + (xfont->xft_font->ascent + xfont->xft_font->descent - xfont->mini_height * 2 - xfont->mini_pad * 5) / 2; + ys[1] = ys[0] + 2 * xfont->mini_pad + xfont->mini_height; + ys[2] = ys[1] + xfont->mini_height + xfont->mini_pad; + + xs[0] = x + PANGO_PIXELS (x_off + glyphs->glyphs[i].geometry.x_offset); + xs[1] = xs[0] + 2 * xfont->mini_pad; + xs[2] = xs[1] + xfont->mini_width + xfont->mini_pad; + + draw_box (draw, color, xfont, + xs[0], ys[0], + xfont->mini_width * 2 + xfont->mini_pad * 5, + xfont->mini_height * 2 + xfont->mini_pad * 5); + + g_snprintf (buf, sizeof(buf), "%04X", glyph); + + for (j = 0; j < 2; j++) + for (k = 0; k < 2; k++) + XftDrawString8 (draw, color, mini_xft, + xs[k+1], ys[j+1], + &buf[2*j + k], 1); + } + else + XftDrawString32 (draw, color, xfont->xft_font, + x + PANGO_PIXELS (x_off + glyphs->glyphs[i].geometry.x_offset), + y + PANGO_PIXELS (glyphs->glyphs[i].geometry.y_offset), + &glyph, 1); + } + + x_off += glyphs->glyphs[i].geometry.width; + } +} + +static void +pango_xft_font_get_metrics (PangoFont *font, + const gchar *lang, + PangoFontMetrics *metrics) +{ + PangoXftFont *xfont = (PangoXftFont *)font; + + metrics->ascent = PANGO_SCALE * xfont->xft_font->ascent; + metrics->descent = PANGO_SCALE * xfont->xft_font->descent; + + return; +} + +static void +pango_xft_font_shutdown (GObject *object) +{ + PangoXftFont *xfont = PANGO_XFT_FONT (object); + + /* If the font is not already in the freed-fonts cache, add it, + * if it is already there, do nothing and the font will be + * freed. + */ + if (!xfont->in_cache && xfont->fontmap) + _pango_xft_font_map_cache_add (xfont->fontmap, xfont); + + G_OBJECT_CLASS (parent_class)->shutdown (object); +} + +static void +pango_xft_font_finalize (GObject *object) +{ + PangoXftFont *xfont = (PangoXftFont *)object; + + _pango_xft_font_map_remove (xfont->fontmap, xfont); + + if (xfont->mini_font) + g_object_unref (xfont->mini_font); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static PangoFontDescription * +pango_xft_font_describe (PangoFont *font) +{ + PangoXftFont *xfont = (PangoXftFont *)font; + + return pango_font_description_copy (xfont->description); +} + +static PangoCoverage * +pango_xft_font_get_coverage (PangoFont *font, + const char *lang) +{ + PangoXftFont *xfont = (PangoXftFont *)font; + PangoCoverage *coverage; + Display *display; + int i; + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + + coverage = _pango_xft_font_map_get_coverage (xfont->fontmap, + xfont->description->family_name); + + if (coverage) + return pango_coverage_ref (coverage); + + /* Ugh, this is going to be SLOW */ + + coverage = pango_coverage_new (); + for (i = 0; i < G_MAXUSHORT; i++) + { + if (XftGlyphExists (display, xfont->xft_font, i)) + pango_coverage_set (coverage, i, PANGO_COVERAGE_EXACT); + } + + _pango_xft_font_map_set_coverage (xfont->fontmap, xfont->description->family_name, coverage); + + return coverage; +} + +static void +pango_xft_font_get_glyph_extents (PangoFont *font, + PangoGlyph glyph, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + PangoXftFont *xfont = (PangoXftFont *)font; + XGlyphInfo extents; + Display *display; + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + + if (glyph == (PangoGlyph)-1) + glyph = 0; + + if (glyph & PANGO_XFT_UNKNOWN_FLAG) + { + get_mini_font (font); + + if (ink_rect) + { + ink_rect->x = 0; + ink_rect->y = PANGO_SCALE * (- xfont->xft_font->ascent + (xfont->xft_font->ascent + xfont->xft_font->descent - xfont->mini_height * 2 - xfont->mini_pad * 5) / 2); + ink_rect->width = PANGO_SCALE * (xfont->mini_width * 2 + xfont->mini_pad * 5); + ink_rect->height = PANGO_SCALE * (xfont->mini_height * 2 + xfont->mini_pad * 5); + } + + if (logical_rect) + { + logical_rect->x = 0; + logical_rect->y = - PANGO_SCALE * xfont->xft_font->ascent; + logical_rect->width = PANGO_SCALE * (xfont->mini_width * 2 + xfont->mini_pad * 6); + logical_rect->height = (xfont->xft_font->ascent + xfont->xft_font->descent) * PANGO_SCALE; + } + } + else + { + XftTextExtents32 (display, xfont->xft_font, &glyph, 1, &extents); + + if (ink_rect) + { + ink_rect->x = extents.x * PANGO_SCALE; + ink_rect->y = extents.y * PANGO_SCALE; + ink_rect->width = extents.width * PANGO_SCALE; + ink_rect->height = extents.height * PANGO_SCALE; + } + + if (logical_rect) + { + logical_rect->x = 0; + logical_rect->y = - xfont->xft_font->ascent * PANGO_SCALE; + logical_rect->width = extents.xOff * PANGO_SCALE; + logical_rect->height = (xfont->xft_font->ascent + xfont->xft_font->descent) * PANGO_SCALE; + } + } +} + +static PangoMap * +pango_xft_get_shaper_map (const char *lang) +{ + static guint engine_type_id = 0; + static guint render_type_id = 0; + + if (engine_type_id == 0) + { + engine_type_id = g_quark_from_static_string (PANGO_ENGINE_TYPE_SHAPE); + render_type_id = g_quark_from_static_string (PANGO_RENDER_TYPE_XFT); + } + + return pango_find_map (lang, engine_type_id, render_type_id); +} + +static PangoEngineShape * +pango_xft_font_find_shaper (PangoFont *font, + const gchar *lang, + guint32 ch) +{ + PangoMap *shape_map = NULL; + + shape_map = pango_xft_get_shaper_map (lang); + return (PangoEngineShape *)pango_map_get_engine (shape_map, ch); +} + +XftFont * +pango_xft_font_get_font (PangoFont *font) +{ + PangoXftFont *xfont; + + g_return_val_if_fail (PANGO_XFT_IS_FONT (font), NULL); + + xfont = PANGO_XFT_FONT (font); + + return xfont->xft_font; +} + +Display * +pango_xft_font_get_display (PangoFont *font) +{ + PangoXftFont *xfont; + Display *display; + + g_return_val_if_fail (PANGO_XFT_IS_FONT (font), NULL); + + xfont = PANGO_XFT_FONT (font); + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + + return display; +} + +PangoGlyph +pango_xft_font_get_unknown_glyph (PangoFont *font, + gunichar wc) +{ + g_return_val_if_fail (PANGO_XFT_IS_FONT (font), -1); + + return wc | PANGO_XFT_UNKNOWN_FLAG; +} diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c new file mode 100644 index 00000000..03695f1b --- /dev/null +++ b/pango/pangoxft-fontmap.c @@ -0,0 +1,499 @@ +/* Pango + * pangoxft-fontmap.h: Font handling + * + * Copyright (C) 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 "pango-fontmap.h" +#include "pangoxft.h" +#include "pangoxft-private.h" + +#define PANGO_TYPE_XFT_FONT_MAP (pango_xft_font_map_get_type ()) +#define PANGO_XFT_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_XFT_FONT_MAP, PangoXftFontMap)) +#define PANGO_XFT_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_XFT_FONT_MAP, PangoXftFontMapClass)) +#define PANGO_XFT_IS_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_XFT_FONT_MAP)) +#define PANGO_XFT_IS_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_XFT_FONT_MAP)) +#define PANGO_XFT_FONT_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_XFT_FONT_MAP, PangoXftFontMapClass)) + +/* Number of freed fonts */ +#define MAX_FREED_FONTS 16 + +typedef struct _PangoXftFontMap PangoXftFontMap; +typedef struct _PangoXftFontMapClass PangoXftFontMapClass; + +struct _PangoXftFontMap +{ + PangoFontMap parent_instance; + + GHashTable *font_hash; + GHashTable *coverage_hash; + GQueue *freed_fonts; + + Display *display; + int screen; +}; + +struct _PangoXftFontMapClass +{ + PangoFontMapClass parent_class; +}; + +static GType pango_xft_font_map_get_type (void); +static void pango_xft_font_map_init (PangoXftFontMap *fontmap); +static void pango_xft_font_map_class_init (PangoXftFontMapClass *class); + +static void pango_xft_font_map_finalize (GObject *object); +static PangoFont *pango_xft_font_map_load_font (PangoFontMap *fontmap, + const PangoFontDescription *description); +static void pango_xft_font_map_list_fonts (PangoFontMap *fontmap, + const gchar *family, + PangoFontDescription ***descs, + int *n_descs); +static void pango_xft_font_map_list_families (PangoFontMap *fontmap, + gchar ***families, + int *n_families); + +static void pango_xft_font_map_cache_clear (PangoXftFontMap *xfontmap); +static void pango_xft_font_map_cache_remove (PangoFontMap *fontmap, + PangoXftFont *xfont); + +static PangoFontClass *parent_class; /* Parent class structure for PangoXftFontMap */ + +static GType +pango_xft_font_map_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (PangoXftFontMapClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pango_xft_font_map_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (PangoXftFontMap), + 0, /* n_preallocs */ + (GInstanceInitFunc) pango_xft_font_map_init, + }; + + object_type = g_type_register_static (PANGO_TYPE_FONT_MAP, + "PangoXftFontMap", + &object_info, 0); + } + + return object_type; +} + +static void +pango_xft_font_map_init (PangoXftFontMap *xfontmap) +{ +} + +static void +pango_xft_font_map_class_init (PangoXftFontMapClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontMapClass *font_map_class = PANGO_FONT_MAP_CLASS (class); + + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = pango_xft_font_map_finalize; + font_map_class->load_font = pango_xft_font_map_load_font; + font_map_class->list_fonts = pango_xft_font_map_list_fonts; + font_map_class->list_families = pango_xft_font_map_list_families; +} + +static GSList *fontmaps = NULL; + +static guint +font_description_hash (const PangoFontDescription *desc) +{ + guint hash = 0; + + if (desc->family_name) + hash = g_str_hash (desc->family_name); + + hash ^= desc->size; + hash ^= desc->style << 16; + hash ^= desc->variant << 18; + hash ^= desc->weight << 16; + hash ^= desc->stretch << 26; + + return hash; +} + +static PangoFontMap * +pango_xft_get_font_map (Display *display, + int screen) +{ + PangoXftFontMap *xfontmap; + GSList *tmp_list = fontmaps; + + g_return_val_if_fail (display != NULL, NULL); + + /* Make sure that the type system is initialized */ + g_type_init(); + + while (tmp_list) + { + xfontmap = tmp_list->data; + + if (xfontmap->display == display && + xfontmap->screen == screen) + return PANGO_FONT_MAP (xfontmap); + } + + xfontmap = (PangoXftFontMap *)g_object_new (PANGO_TYPE_XFT_FONT_MAP, NULL); + + xfontmap->display = display; + xfontmap->screen = screen; + + xfontmap->font_hash = g_hash_table_new ((GHashFunc)font_description_hash, + (GEqualFunc)pango_font_description_equal); + xfontmap->coverage_hash = g_hash_table_new (g_str_hash, g_str_equal); + xfontmap->freed_fonts = g_queue_new (); + + fontmaps = g_slist_prepend (fontmaps, xfontmap); + + return PANGO_FONT_MAP (xfontmap); +} + +PangoContext * +pango_xft_get_context (Display *display, + int screen) +{ + PangoContext *result; + + g_return_val_if_fail (display != NULL, NULL); + + result = pango_context_new (); + pango_context_add_font_map (result, pango_xft_get_font_map (display, screen)); + + return result; +} + +static void +coverage_foreach (gpointer key, gpointer value, gpointer data) +{ + PangoCoverage *coverage = value; + + g_free (key); + pango_coverage_unref (coverage); +} + +static void +pango_xft_font_map_finalize (GObject *object) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (object); + + fontmaps = g_slist_remove (fontmaps, object); + + g_queue_free (xfontmap->freed_fonts); + g_hash_table_destroy (xfontmap->font_hash); + + g_hash_table_foreach (xfontmap->coverage_hash, coverage_foreach, NULL); + g_hash_table_destroy (xfontmap->coverage_hash); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +void +_pango_xft_font_map_add (PangoFontMap *fontmap, + PangoXftFont *xfont) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + g_hash_table_insert (xfontmap->font_hash, xfont->description, xfont); +} + +void +_pango_xft_font_map_remove (PangoFontMap *fontmap, + PangoXftFont *xfont) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + g_hash_table_remove (xfontmap->font_hash, xfont->description); +} + +static PangoFontDescription * +font_desc_from_pattern (XftPattern *pattern) +{ + PangoFontDescription *desc; + char *s; + int i; + + desc = g_new (PangoFontDescription, 1); + + g_assert (XftPatternGetString (pattern, XFT_FAMILY, 0, &s) == XftResultMatch); + + desc->family_name = g_strdup (s); + + if (XftPatternGetInteger (pattern, XFT_SLANT, 0, &i) == XftResultMatch) + { + if (i == XFT_SLANT_ROMAN) + desc->style = PANGO_STYLE_NORMAL; + else if (i == XFT_SLANT_OBLIQUE) + desc->style = PANGO_STYLE_OBLIQUE; + else + desc->style = PANGO_STYLE_ITALIC; + } + else + desc->style = PANGO_STYLE_NORMAL; + + if (XftPatternGetInteger (pattern, XFT_WEIGHT, 0, &i) == XftResultMatch) + { + if (i < XFT_WEIGHT_LIGHT) + desc->weight = PANGO_WEIGHT_ULTRALIGHT; + else if (i < (XFT_WEIGHT_LIGHT + XFT_WEIGHT_MEDIUM) / 2) + desc->weight = PANGO_WEIGHT_LIGHT; + else if (i < (XFT_WEIGHT_MEDIUM + XFT_WEIGHT_DEMIBOLD) / 2) + desc->weight = PANGO_WEIGHT_NORMAL; + else if (i < (XFT_WEIGHT_DEMIBOLD + XFT_WEIGHT_BOLD) / 2) + desc->weight = 600; + else if (i < (XFT_WEIGHT_BOLD + XFT_WEIGHT_BLACK) / 2) + desc->weight = PANGO_WEIGHT_BOLD; + else + desc->weight = PANGO_WEIGHT_ULTRABOLD; + } + + desc->variant = PANGO_VARIANT_NORMAL; + desc->stretch = PANGO_STRETCH_NORMAL; + desc->size = -1; + + return desc; +} + + +static void +pango_xft_font_map_list_fonts (PangoFontMap *fontmap, + const gchar *family, + PangoFontDescription ***descs, + int *n_descs) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + XftFontSet *fontset; + + if (family) + fontset = XftListFonts (xfontmap->display, xfontmap->screen, + XFT_ENCODING, XftTypeString, "iso10646-1", + XFT_FAMILY, XftTypeString, family, + NULL, + XFT_FAMILY, + XFT_STYLE, + XFT_WEIGHT, + XFT_SLANT, + NULL); + else + fontset = XftListFonts (xfontmap->display, xfontmap->screen, + XFT_ENCODING, XftTypeString, "iso10646-1", + NULL, + XFT_FAMILY, + XFT_STYLE, + XFT_WEIGHT, + XFT_SLANT, + NULL); + + if (n_descs) + *n_descs = fontset->nfont; + + if (descs) + { + gint i; + + *descs = g_new (PangoFontDescription *, fontset->nfont); + + for (i = 0; i < fontset->nfont; i++) + (*descs)[i] = font_desc_from_pattern (fontset->fonts[i]); + } + + XftFontSetDestroy (fontset); +} + +static void +pango_xft_font_map_list_families (PangoFontMap *fontmap, + gchar ***families, + int *n_families) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + XftFontSet *fontset; + int i; + + fontset = XftListFonts (xfontmap->display, xfontmap->screen, + XFT_ENCODING, XftTypeString, "iso10646-1", + NULL, + XFT_FAMILY, + NULL); + + if (n_families) + *n_families = fontset->nfont; + + if (families) + { + *families = g_new (gchar *, fontset->nfont); + + for (i = 0; i < fontset->nfont; i++) + { + char *s; + XftResult res; + + res = XftPatternGetString (fontset->fonts[i], XFT_FAMILY, 0, &s); + g_assert (res == XftResultMatch); + + (*families)[i] = g_strdup (s); + } + } + + XftFontSetDestroy (fontset); +} + +static PangoFont * +pango_xft_font_map_load_font (PangoFontMap *fontmap, + const PangoFontDescription *description) +{ + PangoXftFontMap *xfontmap = (PangoXftFontMap *)fontmap; + PangoXftFont *font; + int slant; + int weight; + XftFont *xft_font; + + font = g_hash_table_lookup (xfontmap->font_hash, description); + + if (font) + { + if (font->in_cache) + pango_xft_font_map_cache_remove (fontmap, font); + + return (PangoFont *)g_object_ref (G_OBJECT (font)); + } + + if (description->style == PANGO_STYLE_ITALIC) + slant = XFT_SLANT_ITALIC; + else if (description->style == PANGO_STYLE_OBLIQUE) + slant = XFT_SLANT_OBLIQUE; + else + slant = XFT_SLANT_ROMAN; + + if (description->weight < (PANGO_WEIGHT_NORMAL + PANGO_WEIGHT_LIGHT) / 2) + weight = XFT_WEIGHT_LIGHT; + else if (description->weight < (PANGO_WEIGHT_NORMAL + 600) / 2) + weight = XFT_WEIGHT_MEDIUM; + else if (description->weight < (600 + PANGO_WEIGHT_BOLD) / 2) + weight = XFT_WEIGHT_DEMIBOLD; + else if (description->weight < (PANGO_WEIGHT_BOLD + PANGO_WEIGHT_ULTRABOLD) / 2) + weight = XFT_WEIGHT_BOLD; + else + weight = XFT_WEIGHT_BLACK; + + xft_font = XftFontOpen (xfontmap->display, xfontmap->screen, + XFT_FAMILY, XftTypeString, description->family_name, + XFT_WEIGHT, XftTypeInteger, weight, + XFT_SLANT, XftTypeInteger, slant, + XFT_SIZE, XftTypeDouble, (double)description->size/PANGO_SCALE, + NULL); + + if (xft_font) + font = _pango_xft_font_new (fontmap, description, xft_font); + else + return NULL; + + return (PangoFont *)font; +} + +void +_pango_xft_font_map_cache_add (PangoFontMap *fontmap, + PangoXftFont *xfont) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + if (xfontmap->freed_fonts->length == MAX_FREED_FONTS) + { + GObject *old_font = g_queue_pop_tail (xfontmap->freed_fonts); + g_object_unref (old_font); + } + + g_object_ref (G_OBJECT (xfont)); + g_queue_push_head (xfontmap->freed_fonts, xfont); + xfont->in_cache = TRUE; +} + +static void +pango_xft_font_map_cache_remove (PangoFontMap *fontmap, + PangoXftFont *xfont) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + GList *link = g_list_find (xfontmap->freed_fonts->head, xfont); + if (link == xfontmap->freed_fonts->tail) + { + xfontmap->freed_fonts->tail = xfontmap->freed_fonts->tail->prev; + if (xfontmap->freed_fonts->tail) + xfontmap->freed_fonts->tail->next = NULL; + } + + xfontmap->freed_fonts->head = g_list_delete_link (xfontmap->freed_fonts->head, link); + xfontmap->freed_fonts->length--; + xfont->in_cache = FALSE; + + g_object_unref (G_OBJECT (xfont)); +} + +static void +pango_xft_font_map_cache_clear (PangoXftFontMap *xfontmap) +{ + g_list_foreach (xfontmap->freed_fonts->head, (GFunc)g_object_unref, NULL); + g_list_free (xfontmap->freed_fonts->head); + xfontmap->freed_fonts->head = NULL; + xfontmap->freed_fonts->tail = NULL; + xfontmap->freed_fonts->length = 0; +} + +void +_pango_xft_font_map_set_coverage (PangoFontMap *fontmap, + const char *name, + PangoCoverage *coverage) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + g_hash_table_insert (xfontmap->coverage_hash, g_strdup (name), + pango_coverage_ref (coverage)); +} + +PangoCoverage * +_pango_xft_font_map_get_coverage (PangoFontMap *fontmap, + const char *name) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + return g_hash_table_lookup (xfontmap->coverage_hash, name); +} + +void +_pango_xft_font_map_get_info (PangoFontMap *fontmap, + Display **display, + int *screen) +{ + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + + if (display) + *display = xfontmap->display; + if (screen) + *screen = xfontmap->screen; +} diff --git a/pango/pangoxft-private.h b/pango/pangoxft-private.h new file mode 100644 index 00000000..7cf7dc2e --- /dev/null +++ b/pango/pangoxft-private.h @@ -0,0 +1,63 @@ +/* Pango + * pangox-private.h: + * + * Copyright (C) 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 <pangoxft.h> + +#ifndef __PANGOXFT_PRIVATE_H__ +#define __PANGOXFT_PRIVATE_H__ + +typedef struct _PangoXftFont PangoXftFont; + +struct _PangoXftFont +{ + PangoFont parent_instance; + + XftFont *xft_font; + PangoFont *mini_font; + PangoFontMap *fontmap; + PangoFontDescription *description; + + guint16 mini_width; + guint16 mini_height; + guint16 mini_pad; + + gboolean in_cache; +}; + +PangoXftFont * _pango_xft_font_new (PangoFontMap *font, + const PangoFontDescription *description, + XftFont *xft_font); +void _pango_xft_font_map_cache_add (PangoFontMap *fontmap, + PangoXftFont *xfont); +void _pango_xft_font_map_add (PangoFontMap *fontmap, + PangoXftFont *xfont); +void _pango_xft_font_map_remove (PangoFontMap *fontmap, + PangoXftFont *xfont); +void _pango_xft_font_map_set_coverage (PangoFontMap *fontmap, + const char *name, + PangoCoverage *coverage); +PangoCoverage *_pango_xft_font_map_get_coverage (PangoFontMap *fontmap, + const char *name); +void _pango_xft_font_map_get_info (PangoFontMap *fontmap, + Display **display, + int *screen); + +#endif /* __PANGOXFT_PRIVATE_H__ */ diff --git a/pango/pangoxft.h b/pango/pangoxft.h new file mode 100644 index 00000000..b7636ee4 --- /dev/null +++ b/pango/pangoxft.h @@ -0,0 +1,61 @@ +/* Pango + * pangox.h: + * + * Copyright (C) 1999 Red Hat Software + * Copyright (C) 2000 SuSE Linux Ltd + * + * 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. + */ + +#ifndef __PANGOXFT_H__ +#define __PANGOXFT_H__ + +#include <pango/pango.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include <X11/Xlib.h> +#include <X11/Xft/Xft.h> + +#define PANGO_RENDER_TYPE_XFT "PangoRenderXft" + +/* Calls for applications + */ +PangoContext * pango_xft_get_context (Display *display, + int screen); +void pango_xft_render (XftDraw *draw, + XftColor *color, + PangoFont *font, + PangoGlyphString *glyphs, + gint x, + gint y); + +/* For shape engines + */ + +XftFont * pango_xft_font_get_font (PangoFont *font); +Display * pango_xft_font_get_display (PangoFont *font); +PangoGlyph pango_xft_font_get_unknown_glyph (PangoFont *font, + gunichar wc); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __PANGOXFT_H__ */ diff --git a/pangoxft.pc.in b/pangoxft.pc.in new file mode 100644 index 00000000..fdf7c890 --- /dev/null +++ b/pangoxft.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Pango X +Description: X Window System font support for Pango +Version: @VERSION@ +Requires: pango +Libs: -L${libdir} -lpangoxft @XFT_LIBS@ +Cflags: -I${includedir}/pango-1.0 + |