From 0e6409a158d9dd76a31b9eccf7c4f26c5466d082 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 21 Jun 2000 16:13:42 +0000 Subject: Remove tests for libunicode Wed Jun 21 12:11:56 2000 Owen Taylor * configure.in: Remove tests for libunicode * pango/utils.[ch]: Removed. The functions from here are now in GLib. * **.[ch]: Removed use of libunicode and utils.c in favor of Unicode functions in GLib. Requires latest GLib from CVS. --- pango/Makefile.am | 4 +- pango/break.c | 17 ++-- pango/glyphstring.c | 7 +- pango/gunicode.h | 21 ----- pango/itemize.c | 11 ++- pango/mapping.c | 7 +- pango/modules.c | 5 +- pango/pango-context.c | 21 +++-- pango/pango-layout.c | 50 ++++++----- pango/pangox.c | 15 ++-- pango/shape.c | 1 - pango/utils.c | 228 -------------------------------------------------- pango/utils.h | 42 ---------- 13 files changed, 62 insertions(+), 367 deletions(-) delete mode 100644 pango/gunicode.h delete mode 100644 pango/utils.c delete mode 100644 pango/utils.h (limited to 'pango') diff --git a/pango/Makefile.am b/pango/Makefile.am index 5cd9e019..ea86de71 100644 --- a/pango/Makefile.am +++ b/pango/Makefile.am @@ -21,9 +21,7 @@ libpango_la_SOURCES = \ pango-item.c \ pango-layout.c \ reorder-items.c \ - shape.c \ - utils.c \ - utils.h + shape.c libpangox_la_SOURCES = \ pangox.c \ diff --git a/pango/break.c b/pango/break.c index 70de69ce..93ffecf2 100644 --- a/pango/break.c +++ b/pango/break.c @@ -20,8 +20,6 @@ */ #include "pango.h" -#include -#include "utils.h" /** * pango_break: @@ -41,20 +39,14 @@ void pango_break (const gchar *text, /* Pseudo-implementation */ const gchar *cur = text; - const gchar *next; gint i = 0; - GUChar4 wc; + gunichar wc; - while (*cur) + while (*cur && cur - text < length) { - next = unicode_get_utf8 (cur, &wc); - if (!next) + wc = g_utf8_get_char (cur); + if (wc == (gunichar)-1) break; /* FIXME: ERROR */ - if (cur == next) - break; - if ((next - text) > length) - break; - cur = next; attrs[i].is_white = (wc == ' ' || wc == '\t' || wc == '\n' || wc == 0x200b) ? 1 : 0; attrs[i].is_break = i == 0 || attrs[i-1].is_white || attrs[i].is_white; @@ -62,5 +54,6 @@ void pango_break (const gchar *text, attrs[i].is_word_stop = (i == 0) || attrs[i-1].is_white; i++; + cur = g_utf8_next_char (cur); } } diff --git a/pango/glyphstring.c b/pango/glyphstring.c index d9d7c87b..b8d9eaa7 100644 --- a/pango/glyphstring.c +++ b/pango/glyphstring.c @@ -22,7 +22,6 @@ #include #include #include -#include /** * pango_glyph_string_new: @@ -188,7 +187,7 @@ pango_glyph_string_extents (PangoGlyphString *glyphs, * @text: the text corresponding to the glyphs * @length: the length of @text, in bytes * @embedding_level: the embedding level of the string - * @logical_widths: an array whose length is unicode_strlen (text, length) + * @logical_widths: an array whose length is g_utf8_strlen (text, length) * to be filled in with the resulting character widths. * * Given a #PangoGlyphString resulting from pango_shape() and the corresponding @@ -222,7 +221,7 @@ pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs, while (p < text + glyphs->log_clusters[glyph_index]) { next_cluster++; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); } } else @@ -230,7 +229,7 @@ pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs, while (p < text + length) { next_cluster++; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); } } diff --git a/pango/gunicode.h b/pango/gunicode.h deleted file mode 100644 index 6d089880..00000000 --- a/pango/gunicode.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Pango - * gunicode.h: - * - * Copyright (C) 1999 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. - */ - diff --git a/pango/itemize.c b/pango/itemize.c index ed877fc0..da8b0fbc 100644 --- a/pango/itemize.c +++ b/pango/itemize.c @@ -20,10 +20,8 @@ */ #include -#include #include "pango.h" #include "iconv.h" -#include "utils.h" #include "modules.h" static void add_engines (PangoContext *context, @@ -90,7 +88,7 @@ pango_itemize (PangoContext *context, if (!text_ucs2) return NULL; - n_chars = unicode_strlen (text, length); + n_chars = g_utf8_strlen (text, length); embedding_levels = g_new (guint8, n_chars); /* Storing these as ranges would be a lot more efficient, @@ -126,7 +124,7 @@ pango_itemize (PangoContext *context, p = text; for (i=0; i -#include /** * pango_glyph_string_index_to_x: @@ -143,7 +142,7 @@ pango_glyph_string_index_to_x (PangoGlyphString *glyphs, if (p < text + index) cluster_offset++; cluster_chars++; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); } /* Now interpolate the result. For South Asian languages @@ -265,7 +264,7 @@ pango_glyph_string_x_to_index (PangoGlyphString *glyphs, p = text + start_index; while (p < text + end_index) { - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); cluster_chars++; } @@ -287,7 +286,7 @@ pango_glyph_string_x_to_index (PangoGlyphString *glyphs, while (i + 1 <= cp) { - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); i++; } diff --git a/pango/modules.c b/pango/modules.c index 66a75c2c..fcd42813 100644 --- a/pango/modules.c +++ b/pango/modules.c @@ -29,7 +29,6 @@ #include "pango-modules.h" #include "modules.h" -#include "utils.h" typedef struct _PangoMapInfo PangoMapInfo; typedef struct _PangoEnginePair PangoEnginePair; @@ -464,8 +463,8 @@ build_map (PangoMapInfo *info) submap <= pair->info.ranges[i].end / 256; submap ++) { - GUChar4 start; - GUChar4 end; + gunichar start; + gunichar end; if (submap == pair->info.ranges[i].start / 256) start = pair->info.ranges[i].start % 256; diff --git a/pango/pango-context.c b/pango/pango-context.c index b967000b..11e1ecbc 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -21,10 +21,8 @@ #include #include -#include #include "iconv.h" -#include "utils.h" #include "pango-modules.h" struct _PangoContext @@ -511,7 +509,7 @@ pango_itemize (PangoContext *context, int length, PangoAttrList *attrs) { - GUChar4 *text_ucs4; + gunichar *text_ucs4; int n_chars, i; guint8 *embedding_levels; FriBidiCharType base_dir; @@ -543,11 +541,11 @@ pango_itemize (PangoContext *context, /* First, apply the bidirectional algorithm to break * the text into directional runs. */ - text_ucs4 = _pango_utf8_to_ucs4 (text, length); + text_ucs4 = g_utf8_to_ucs4 (text, length); if (!text_ucs4) return NULL; - n_chars = unicode_strlen (text, length); + n_chars = g_utf8_strlen (text, length); embedding_levels = g_new (guint8, n_chars); fribidi_log2vis_get_embedding_levels (text_ucs4, n_chars, &base_dir, @@ -577,7 +575,7 @@ pango_itemize (PangoContext *context, p = text; for (i=0; i #include /* For pango_shape() */ #include -#include #define LINE_IS_VALID(line) ((line)->layout != NULL) @@ -431,18 +430,17 @@ pango_layout_set_text (PangoLayout *layout, } else { - unicode_char_t junk; const char *p = text; int n_chars = 0; while (*p && (length < 0 || p < text + length)) { - p = unicode_get_utf8 (p, &junk); - if (!p) + if (g_utf8_get_char (p) == (gunichar)-1) { g_warning ("Invalid UTF8 string passed to pango_layout_set_text()"); return; } + p = g_utf8_next_char (p); n_chars++; } @@ -454,8 +452,7 @@ pango_layout_set_text (PangoLayout *layout, length = p - text; - /* NULL-terminate the text, since we currently use unicode_next_utf8() - * in quite a few places, and for convenience. + /* NULL-terminate the text for convenience. */ layout->text = g_malloc (length + 1); @@ -761,10 +758,10 @@ pango_layout_move_cursor_visually (PangoLayout *layout, next_line = NULL; if (old_trailing) - old_index = unicode_next_utf8 (layout->text + old_index) - layout->text; + old_index = g_utf8_next_char (layout->text + old_index) - layout->text; log2vis_map = pango_layout_line_get_log2vis_map (line, TRUE); - n_vis = unicode_strlen (layout->text + bytes_seen, line->length); + n_vis = g_utf8_strlen (layout->text + bytes_seen, line->length); vis_pos = log2vis_map[old_index - bytes_seen]; g_free (log2vis_map); @@ -794,7 +791,7 @@ pango_layout_move_cursor_visually (PangoLayout *layout, line = next_line; } - vis_pos = unicode_strlen (layout->text + bytes_seen, line->length); + vis_pos = g_utf8_strlen (layout->text + bytes_seen, line->length); } else if (vis_pos == n_vis && direction > 0) { @@ -830,9 +827,9 @@ pango_layout_move_cursor_visually (PangoLayout *layout, *new_index = bytes_seen + vis2log_map[vis_pos]; g_free (vis2log_map); - if (*new_index == bytes_seen + line->length) + if (*new_index == bytes_seen + line->length && line->length > 0) { - *new_index = unicode_previous_utf8 (layout->text, layout->text + *new_index) - layout->text; + *new_index = g_utf8_prev_char (layout->text + *new_index) - layout->text; *new_trailing = 1; } else @@ -1023,7 +1020,7 @@ pango_layout_line_get_vis2log_map (PangoLayoutLine *line, int n_chars; pango_layout_line_get_range (line, &start, &end); - n_chars = unicode_strlen (start, end - start); + n_chars = g_utf8_strlen (start, end - start); result = g_new (int, n_chars + 1); @@ -1057,12 +1054,12 @@ pango_layout_line_get_vis2log_map (PangoLayoutLine *line, (prev_dir == run_dir)) result[pos] = p - start; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); for (i = 1; i < run_n_chars; i++) { result[pos + i] = p - start; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); } if ((strong && base_dir == run_dir) || @@ -1075,12 +1072,12 @@ pango_layout_line_get_vis2log_map (PangoLayoutLine *line, (!strong && base_dir != run_dir)) result[pos + run_n_chars] = p - start; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); for (i = 1; i < run_n_chars; i++) { result[pos + run_n_chars - i] = p - start; - p = unicode_next_utf8 (p); + p = g_utf8_next_char (p); } if ((strong && base_dir == run_dir) || @@ -1108,7 +1105,7 @@ pango_layout_line_get_log2vis_map (PangoLayoutLine *line, int n_chars; pango_layout_line_get_range (line, &start, &end); - n_chars = unicode_strlen (start, end - start); + n_chars = g_utf8_strlen (start, end - start); result = g_new0 (int, end - start + 1); reverse_map = pango_layout_line_get_vis2log_map (line, strong); @@ -1220,7 +1217,7 @@ pango_layout_get_cursor_pos (PangoLayout *layout, } else { - gint prev_index = unicode_previous_utf8 (layout->text, layout->text + index) - layout->text; + gint prev_index = g_utf8_prev_char (layout->text + index) - layout->text; dir1 = pango_layout_line_get_char_direction (layout_line, prev_index); pango_layout_line_index_to_x (layout_line, prev_index, TRUE, &x1_trailing); } @@ -1565,7 +1562,7 @@ process_item (PangoLayoutLine *line, { PangoItem *new_item = pango_item_copy (item); - length = unicode_offset_to_index (text + item->offset, num_chars); + length = g_utf8_offset_to_pointer (text + item->offset, num_chars) - (text + item->offset); new_item->length = length; new_item->num_chars = num_chars; @@ -1679,7 +1676,7 @@ pango_layout_check_lines (PangoLayout *layout) while (end != layout->text + layout->length && *end != '\n') { - end = unicode_next_utf8 (end); + end = g_utf8_next_char (end); para_chars++; } @@ -1911,8 +1908,13 @@ pango_layout_line_x_to_index (PangoLayoutLine *line, return; } - last_index = first_index + line->length; - last_index = unicode_previous_utf8 (line->layout->text + first_index, line->layout->text + last_index) - line->layout->text; + if (line->length > 0) + { + last_index = first_index + line->length; + last_index = g_utf8_prev_char (line->layout->text + last_index) - line->layout->text; + } + else + last_index = first_index; /* FIXME - does this make sense at all? */ /* This is a HACK. If a program only keeps track if cursor (etc) * indices and not the trailing flag, then the trailing index of the @@ -2072,9 +2074,11 @@ pango_layout_line_get_x_ranges (PangoLayoutLine *line, int run_end_index = MIN (end_index, run->item->offset + run->item->length); int run_start_x, run_end_x; + g_assert (run_end_index > 0); + /* Back the end_index off one since we want to find the trailing edge of the preceding character */ - run_end_index = unicode_previous_utf8 (line->layout->text, line->layout->text + run_end_index) - line->layout->text; + run_end_index = g_utf8_prev_char (line->layout->text + run_end_index) - line->layout->text; pango_glyph_string_index_to_x (run->glyphs, line->layout->text + run->item->offset, diff --git a/pango/pangox.c b/pango/pangox.c index b2f3ca0d..c9388fef 100644 --- a/pango/pangox.c +++ b/pango/pangox.c @@ -24,12 +24,9 @@ #include #include -#include #include "pangox.h" #include "pangox-private.h" -#include "utils.h" - #include #define PANGO_TYPE_X_FONT (pango_x_font_get_type ()) @@ -487,15 +484,15 @@ get_font_metrics_from_string (PangoFont *font, PangoGlyphString *glyph_str = pango_glyph_string_new (); PangoEngineShape *shaper, *last_shaper; int last_level; - GUChar4 *text_ucs4; + gunichar *text_ucs4; int n_chars, i; guint8 *embedding_levels; FriBidiCharType base_dir = PANGO_DIRECTION_LTR; GSList *subfonts = NULL; - n_chars = unicode_strlen (str, -1); + n_chars = g_utf8_strlen (str, -1); - text_ucs4 = _pango_utf8_to_ucs4 (str, strlen (str)); + text_ucs4 = g_utf8_to_ucs4 (str, strlen (str)); if (!text_ucs4) return; @@ -511,9 +508,9 @@ get_font_metrics_from_string (PangoFont *font, p = start = str; while (*p) { - unicode_char_t wc; - p = unicode_get_utf8 (p, &wc); - + gunichar wc = g_utf8_get_char (p); + p = g_utf8_next_char (p); + shaper = pango_font_find_shaper (font, lang, wc); if (p > start && (shaper != last_shaper || last_level != embedding_levels[i])) diff --git a/pango/shape.c b/pango/shape.c index 7209d97a..c7ec405c 100644 --- a/pango/shape.c +++ b/pango/shape.c @@ -20,7 +20,6 @@ */ #include -#include "utils.h" /** * pango_shape: diff --git a/pango/utils.c b/pango/utils.c deleted file mode 100644 index 6f7ff8ca..00000000 --- a/pango/utils.c +++ /dev/null @@ -1,228 +0,0 @@ -/* Pango - * utils.c: - * - * Copyright (C) 1999 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 "utils.h" -#include -#include -#include - -gboolean -_pango_utf8_iterate (const char *cur, const char **next, GUChar4 *wc_out) -{ - const guchar *p = (guchar *)cur; - guchar c = *p; - GUChar4 wc; - gint length; - - if ((c & 0x80) == 0) - { - length = 1; - wc = c; - } - else if ((c & 0xc0) == 0x80) - { - return FALSE; - } - else if ((c & 0xe0) == 0xc0) - { - length = 2; - wc = c & 0x1f; - } - else if ((c & 0xf0) == 0xe0) - { - length = 3; - wc = c & 0x0f; - } - else - return FALSE; - - p++; - while (--length > 0) - { - if (*p == 0) /* Incomplete character */ - { - if (next) - *next = cur; - if (wc_out) - *wc_out = 0; - return TRUE; - } - - if ((*p & 0xc0) != 0x80) - return FALSE; - - wc <<= 6; - wc |= (*p) & 0x3f; - - p++; - } - - if (wc_out) - *wc_out = wc; - if (next) - *next = (const char *)p; - - return TRUE; -} - -int -_pango_utf8_len (const char *str, int limit) -{ - const char *cur = str; - const char *next; - int len = 0; - - while (*cur) - { - if (!_pango_utf8_iterate (cur, &next, NULL)) - return -1; - if (cur == next) - break; - if (limit >= 0 && (next - str) > limit) - return len; - cur = next; - len++; - } - - return len; -} - -#if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define UCS2_CHARSET "UNICODELITTLE" -#else -#define UCS2_CHARSET "UNICODE" -#endif - -GUChar2 * -_pango_utf8_to_ucs2 (const char *str, int len) -{ - iconv_t cd; - char *outbuf, *result; - const char *inbuf; - size_t inbytesleft; - size_t outbytesleft; - gint outlen; - - gint count; - - cd = iconv_open (UCS2_CHARSET, "UTF-8"); - - if (cd == (iconv_t)-1) - g_error ("No converter from UTF-8 to " UCS2_CHARSET); - - if (len < 0) - len = strlen (str); - - outlen = unicode_strlen (str, len) * sizeof(GUChar2); - result = g_malloc (outlen); - - inbuf = str; - inbytesleft = len; - outbuf = result; - outbytesleft = outlen; - - count = iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - - if (count < 0 && (errno != E2BIG)) - { - g_free (result); - result = NULL; - } - - iconv_close (cd); - - return (GUChar2 *)result; - -} - -GUChar4 * -_pango_utf8_to_ucs4 (const char *str, int len) -{ - GUChar4 *result; - int n_chars, i; - const char *p; - - n_chars = unicode_strlen (str, len); - result = g_new (GUChar4, n_chars); - - p = str; - for (i=0; i < n_chars; i++) - p = unicode_get_utf8 (p, &result[i]); - - return result; -} - -/** - * _pango_guchar4_to_utf8: - * @ch: a ISO10646 character code - * @out: output buffer, must have at least 6 bytes of space. - * - * Convert a single character to utf8 - * - * Return value: number of bytes written - **/ -int -_pango_guchar4_to_utf8 (GUChar4 c, char *outbuf) -{ - size_t len = 0; - int first; - int i; - - if (c < 0x80) - { - first = 0; - len = 1; - } - else if (c < 0x800) - { - first = 0xc0; - len = 2; - } - else if (c < 0x10000) - { - first = 0xe0; - len = 3; - } - else if (c < 0x200000) - { - first = 0xf0; - len = 4; - } - else if (c < 0x4000000) - { - first = 0xf8; - len = 5; - } - else - { - first = 0xfc; - len = 6; - } - - for (i = len - 1; i > 0; --i) - { - outbuf[i] = (c & 0x3f) | 0x80; - c >>= 6; - } - outbuf[0] = c | first; - - return len; -} diff --git a/pango/utils.h b/pango/utils.h deleted file mode 100644 index 9cf40dbb..00000000 --- a/pango/utils.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Pango - * utils.h: - * - * Copyright (C) 1999 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. - */ - -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include - -typedef guint16 GUChar2; -typedef guint32 GUChar4; - -gboolean _pango_utf8_iterate (const char *cur, - const char **next, - GUChar4 *wc_out); -GUChar2 *_pango_utf8_to_ucs2 (const char *str, - gint len); -GUChar4 *_pango_utf8_to_ucs4 (const char *str, - int len); -int _pango_guchar4_to_utf8 (GUChar4 c, - char *outbuf); -int _pango_utf8_len (const char *str, - gint limit); - -#endif /* __UTILS_H__ */ -- cgit v1.2.1