summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2000-07-06 23:32:42 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-07-06 23:32:42 +0000
commit420062f86db398b4df038f42e01e3db5cd656a7d (patch)
tree73369cfff3ffafa006e2909e07c8ad48e0f8bca5 /pango
parent3d95e7ed152e045e311f855a8028746fc9ab38be (diff)
downloadpango-420062f86db398b4df038f42e01e3db5cd656a7d.tar.gz
Implement this function, to get logical attributes without a
2000-07-06 Havoc Pennington <hp@redhat.com> * pango/break.c (pango_get_log_attrs): Implement this function, to get logical attributes without a PangoAnalysis. (pango_break): Fix bug in word stop location
Diffstat (limited to 'pango')
-rw-r--r--pango/break.c100
-rw-r--r--pango/pango.h6
2 files changed, 105 insertions, 1 deletions
diff --git a/pango/break.c b/pango/break.c
index 93ffecf2..0f9d3dfe 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -20,6 +20,7 @@
*/
#include "pango.h"
+#include "pango-modules.h"
/**
* pango_break:
@@ -51,9 +52,106 @@ void pango_break (const gchar *text,
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;
attrs[i].is_char_stop = 1;
- attrs[i].is_word_stop = (i == 0) || attrs[i-1].is_white;
+ attrs[i].is_word_stop = ((i == 0) || attrs[i-1].is_white) && !attrs[i].is_white;
i++;
cur = g_utf8_next_char (cur);
}
}
+
+/**
+ * pango_get_log_attrs:
+ * @text: text to process
+ * @length: length in bytes of @text
+ * @level: embedding level, or -1 if unknown
+ * @language: language code
+ * @log_attrs: array with one PangoLogAttr per character in @text, to be filled in
+ *
+ * Computes a PangoLogAttr for each character in @text
+ */
+void
+pango_get_log_attrs (const char *text,
+ int length,
+ int level,
+ const char *language,
+ PangoLogAttr *log_attrs)
+{
+ int n_chars;
+ PangoMap *lang_map;
+ int chars_broken;
+ const char *pos;
+ const char *end;
+ PangoEngineLang* range_engine;
+ const char *range_start;
+ int chars_in_range;
+ static guint engine_type_id = 0;
+ static guint render_type_id = 0;
+ PangoAnalysis analysis = { NULL, NULL, NULL, (guint8)level };
+
+ g_return_if_fail (length == 0 || text != NULL);
+ g_return_if_fail (log_attrs != NULL);
+
+ if (length == 0)
+ return;
+
+ if (engine_type_id == 0)
+ {
+ engine_type_id = g_quark_from_static_string (PANGO_ENGINE_TYPE_LANG);
+ render_type_id = g_quark_from_static_string (PANGO_RENDER_TYPE_NONE);
+ }
+
+ n_chars = g_utf8_strlen (text, length);
+
+ lang_map = pango_find_map (language, engine_type_id, render_type_id);
+
+ range_start = text;
+ range_engine = (PangoEngineLang*) pango_map_get_engine (lang_map,
+ g_utf8_get_char (text));
+ analysis.lang_engine = range_engine;
+ chars_broken = 0;
+ chars_in_range = 1;
+
+ end = text + length;
+ pos = g_utf8_next_char (text);
+
+ while (pos != end)
+ {
+ analysis.lang_engine =
+ (PangoEngineLang*) pango_map_get_engine (lang_map,
+ g_utf8_get_char (pos));
+
+ if (range_engine != analysis.lang_engine)
+ {
+ /* Engine has changed; do the breaking for the current range,
+ * then start a new range.
+ */
+ pango_break (range_start,
+ pos - range_start,
+ &analysis,
+ log_attrs + chars_broken);
+
+ chars_broken += chars_in_range;
+
+ range_start = pos;
+ range_engine = analysis.lang_engine;
+ chars_in_range = 1;
+ }
+ else
+ {
+ chars_in_range += 1;
+ }
+
+ pos = g_utf8_next_char (pos);
+ }
+
+ g_assert (chars_in_range > 0);
+ g_assert (range_start != end);
+ g_assert (pos == end);
+ g_assert (range_engine == analysis.lang_engine);
+
+ pango_break (range_start,
+ end - range_start,
+ &analysis,
+ log_attrs + chars_broken);
+}
+
diff --git a/pango/pango.h b/pango/pango.h
index 5d083b9f..e0652fd0 100644
--- a/pango/pango.h
+++ b/pango/pango.h
@@ -57,6 +57,12 @@ void pango_break (const gchar *text,
PangoAnalysis *analysis,
PangoLogAttr *attrs);
+void pango_get_log_attrs (const char *text,
+ int length,
+ int level,
+ const char *language,
+ PangoLogAttr *log_attrs);
+
/* Turn a string of characters into a string of glyphs
*/
void pango_shape (const gchar *text,