diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-06-20 10:12:17 -0700 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-07-04 11:17:21 -0400 |
commit | 50f6a771709dee2686893d4c358156fd81aec043 (patch) | |
tree | 8dd8e509d89e30f92e75e0a0dd2ff486b4e8e9be /pango | |
parent | df85140892978a1c363916544dfd82eea13f06e9 (diff) | |
download | pango-50f6a771709dee2686893d4c358156fd81aec043.tar.gz |
Drop more PangoItem api
There is no way to do anything useful outside
of Pango with these functions, so keep them
private.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/meson.build | 1 | ||||
-rw-r--r-- | pango/pango-glyph-item.c | 383 | ||||
-rw-r--r-- | pango/pango-item-private.h | 12 | ||||
-rw-r--r-- | pango/pango-item.h | 16 | ||||
-rw-r--r-- | pango/pango-line-breaker.c | 4 | ||||
-rw-r--r-- | pango/reorder-items.c | 118 |
6 files changed, 199 insertions, 335 deletions
diff --git a/pango/meson.build b/pango/meson.build index 9677beed..7e89d46d 100644 --- a/pango/meson.build +++ b/pango/meson.build @@ -33,7 +33,6 @@ pango_sources = [ 'pango-tabs.c', 'pango-trace.c', 'pango-utils.c', - 'reorder-items.c', 'shape.c', 'serializer.c', 'json/gtkjsonparser.c', diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c index fec4a8c5..9e4bdb09 100644 --- a/pango/pango-glyph-item.c +++ b/pango/pango-glyph-item.c @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -47,16 +47,13 @@ * to the length of @orig (that is, there must be at least one byte * assigned to each item, you can't create a zero-length item). * - * This function is similar in function to [method@PangoItem.split] - * (and uses it internally). - * * Return value: the newly allocated item representing text before * @split_index, which should be freed with [method@Pango.GlyphItem.free] */ PangoGlyphItem * pango_glyph_item_split (PangoGlyphItem *orig, - const char *text, - int split_index) + const char *text, + int split_index) { PangoGlyphItem *new; int i; @@ -72,13 +69,13 @@ pango_glyph_item_split (PangoGlyphItem *orig, if (LTR (orig)) { for (i = 0; i < orig->glyphs->num_glyphs; i++) - { - if (orig->glyphs->log_clusters[i] >= split_index) - break; - } + { + if (orig->glyphs->log_clusters[i] >= split_index) + break; + } if (i == orig->glyphs->num_glyphs) /* No splitting necessary */ - return NULL; + return NULL; split_index = orig->glyphs->log_clusters[i]; num_glyphs = i; @@ -86,13 +83,13 @@ pango_glyph_item_split (PangoGlyphItem *orig, else { for (i = orig->glyphs->num_glyphs - 1; i >= 0; i--) - { - if (orig->glyphs->log_clusters[i] >= split_index) - break; - } + { + if (orig->glyphs->log_clusters[i] >= split_index) + break; + } if (i < 0) /* No splitting necessary */ - return NULL; + return NULL; split_index = orig->glyphs->log_clusters[i]; num_glyphs = orig->glyphs->num_glyphs - 1 - i; @@ -102,7 +99,7 @@ pango_glyph_item_split (PangoGlyphItem *orig, new = g_slice_new (PangoGlyphItem); split_offset = g_utf8_pointer_to_offset (text + orig->item->offset, - text + orig->item->offset + split_index); + text + orig->item->offset + split_index); new->item = pango_item_split (orig->item, split_index, split_offset); new->glyphs = pango_glyph_string_new (); @@ -114,9 +111,9 @@ pango_glyph_item_split (PangoGlyphItem *orig, memcpy (new->glyphs->log_clusters, orig->glyphs->log_clusters, num_glyphs * sizeof (int)); memmove (orig->glyphs->glyphs, orig->glyphs->glyphs + num_glyphs, - num_remaining * sizeof (PangoGlyphInfo)); + num_remaining * sizeof (PangoGlyphInfo)); for (i = num_glyphs; i < orig->glyphs->num_glyphs; i++) - orig->glyphs->log_clusters[i - num_glyphs] = orig->glyphs->log_clusters[i] - split_index; + orig->glyphs->log_clusters[i - num_glyphs] = orig->glyphs->log_clusters[i] - split_index; } else { @@ -124,7 +121,7 @@ pango_glyph_item_split (PangoGlyphItem *orig, memcpy (new->glyphs->log_clusters, orig->glyphs->log_clusters + num_remaining, num_glyphs * sizeof (int)); for (i = 0; i < num_remaining; i++) - orig->glyphs->log_clusters[i] = orig->glyphs->log_clusters[i] - split_index; + orig->glyphs->log_clusters[i] = orig->glyphs->log_clusters[i] - split_index; } pango_glyph_string_set_size (orig->glyphs, orig->glyphs->num_glyphs - num_glyphs); @@ -252,12 +249,12 @@ pango_glyph_item_iter_next_cluster (PangoGlyphItemIter *iter) if (LTR (iter->glyph_item)) { if (glyph_index == glyphs->num_glyphs) - return FALSE; + return FALSE; } else { if (glyph_index < 0) - return FALSE; + return FALSE; } iter->start_glyph = iter->end_glyph; @@ -268,47 +265,47 @@ pango_glyph_item_iter_next_cluster (PangoGlyphItemIter *iter) { cluster = glyphs->log_clusters[glyph_index]; while (TRUE) - { - glyph_index++; - - if (glyph_index == glyphs->num_glyphs) - { - iter->end_index = item->offset + item->length; - iter->end_char = item->num_chars; - break; - } - - if (glyphs->log_clusters[glyph_index] > cluster) - { - iter->end_index = item->offset + glyphs->log_clusters[glyph_index]; - iter->end_char += pango_utf8_strlen (iter->text + iter->start_index, - iter->end_index - iter->start_index); - break; - } - } + { + glyph_index++; + + if (glyph_index == glyphs->num_glyphs) + { + iter->end_index = item->offset + item->length; + iter->end_char = item->num_chars; + break; + } + + if (glyphs->log_clusters[glyph_index] > cluster) + { + iter->end_index = item->offset + glyphs->log_clusters[glyph_index]; + iter->end_char += pango_utf8_strlen (iter->text + iter->start_index, + iter->end_index - iter->start_index); + break; + } + } } - else /* RTL */ + else /* RTL */ { cluster = glyphs->log_clusters[glyph_index]; while (TRUE) - { - glyph_index--; - - if (glyph_index < 0) - { - iter->end_index = item->offset + item->length; - iter->end_char = item->num_chars; - break; - } - - if (glyphs->log_clusters[glyph_index] > cluster) - { - iter->end_index = item->offset + glyphs->log_clusters[glyph_index]; - iter->end_char += pango_utf8_strlen (iter->text + iter->start_index, - iter->end_index - iter->start_index); - break; - } - } + { + glyph_index--; + + if (glyph_index < 0) + { + iter->end_index = item->offset + item->length; + iter->end_char = item->num_chars; + break; + } + + if (glyphs->log_clusters[glyph_index] > cluster) + { + iter->end_index = item->offset + glyphs->log_clusters[glyph_index]; + iter->end_char += pango_utf8_strlen (iter->text + iter->start_index, + iter->end_index - iter->start_index); + break; + } + } } iter->end_glyph = glyph_index; @@ -340,12 +337,12 @@ pango_glyph_item_iter_prev_cluster (PangoGlyphItemIter *iter) if (LTR (iter->glyph_item)) { if (glyph_index == 0) - return FALSE; + return FALSE; } else { if (glyph_index == glyphs->num_glyphs - 1) - return FALSE; + return FALSE; } @@ -357,49 +354,49 @@ pango_glyph_item_iter_prev_cluster (PangoGlyphItemIter *iter) { cluster = glyphs->log_clusters[glyph_index - 1]; while (TRUE) - { - if (glyph_index == 0) - { - iter->start_index = item->offset; - iter->start_char = 0; - break; - } - - glyph_index--; - - if (glyphs->log_clusters[glyph_index] < cluster) - { - glyph_index++; - iter->start_index = item->offset + glyphs->log_clusters[glyph_index]; - iter->start_char -= pango_utf8_strlen (iter->text + iter->start_index, - iter->end_index - iter->start_index); - break; - } - } + { + if (glyph_index == 0) + { + iter->start_index = item->offset; + iter->start_char = 0; + break; + } + + glyph_index--; + + if (glyphs->log_clusters[glyph_index] < cluster) + { + glyph_index++; + iter->start_index = item->offset + glyphs->log_clusters[glyph_index]; + iter->start_char -= pango_utf8_strlen (iter->text + iter->start_index, + iter->end_index - iter->start_index); + break; + } + } } - else /* RTL */ + else /* RTL */ { cluster = glyphs->log_clusters[glyph_index + 1]; while (TRUE) - { - if (glyph_index == glyphs->num_glyphs - 1) - { - iter->start_index = item->offset; - iter->start_char = 0; - break; - } - - glyph_index++; - - if (glyphs->log_clusters[glyph_index] < cluster) - { - glyph_index--; - iter->start_index = item->offset + glyphs->log_clusters[glyph_index]; - iter->start_char -= pango_utf8_strlen (iter->text + iter->start_index, - iter->end_index - iter->start_index); - break; - } - } + { + if (glyph_index == glyphs->num_glyphs - 1) + { + iter->start_index = item->offset; + iter->start_char = 0; + break; + } + + glyph_index++; + + if (glyphs->log_clusters[glyph_index] < cluster) + { + glyph_index--; + iter->start_index = item->offset + glyphs->log_clusters[glyph_index]; + iter->start_char -= pango_utf8_strlen (iter->text + iter->start_index, + iter->end_index - iter->start_index); + break; + } + } } iter->start_glyph = glyph_index; @@ -425,8 +422,8 @@ pango_glyph_item_iter_prev_cluster (PangoGlyphItemIter *iter) */ gboolean pango_glyph_item_iter_init_start (PangoGlyphItemIter *iter, - PangoGlyphItem *glyph_item, - const char *text) + PangoGlyphItem *glyph_item, + const char *text) { iter->glyph_item = glyph_item; iter->text = text; @@ -462,8 +459,8 @@ pango_glyph_item_iter_init_start (PangoGlyphItemIter *iter, */ gboolean pango_glyph_item_iter_init_end (PangoGlyphItemIter *iter, - PangoGlyphItem *glyph_item, - const char *text) + PangoGlyphItem *glyph_item, + const char *text) { iter->glyph_item = glyph_item; iter->text = text; @@ -495,7 +492,7 @@ typedef struct */ static void append_attrs (PangoGlyphItem *glyph_item, - GSList *attrs) + GSList *attrs) { glyph_item->item->analysis.extra_attrs = g_slist_concat (glyph_item->item->analysis.extra_attrs, attrs); @@ -573,8 +570,8 @@ split_before_cluster_start (ApplyAttrsState *state) */ GSList * pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item, - const char *text, - PangoAttrList *list) + const char *text, + PangoAttrList *list) { PangoAttrIterator iter; GSList *result = NULL; @@ -604,7 +601,7 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item, { pango_attr_iterator_range (&iter, &range_start, &range_end); if (range_end > glyph_item->item->offset) - break; + break; } while (pango_attr_iterator_next (&iter)); @@ -634,11 +631,11 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item, * of the last cluster */ if (start_new_segment) - { - result = g_slist_prepend (result, - split_before_cluster_start (&state)); - state.segment_attrs = pango_attr_iterator_get_attrs (&iter); - } + { + result = g_slist_prepend (result, + split_before_cluster_start (&state)); + state.segment_attrs = pango_attr_iterator_get_attrs (&iter); + } start_new_segment = FALSE; @@ -647,42 +644,42 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item, * intersects the next cluster. */ do - { - if (range_end > state.iter.end_index) /* Range intersects next cluster */ - break; - - /* Since ranges end in this cluster, the next cluster goes into a - * separate segment - */ - start_new_segment = TRUE; - - have_next = pango_attr_iterator_next (&iter); - pango_attr_iterator_range (&iter, &range_start, &range_end); - - if (range_start >= state.iter.end_index) /* New range doesn't intersect this cluster */ - { - /* No gap between ranges, so previous range must of ended - * at cluster boundary. - */ - g_assert (range_start == state.iter.end_index && start_new_segment); - break; - } - - /* If any ranges start *inside* this cluster, then we need - * to split the previous cluster into a separate segment - */ - if (range_start > state.iter.start_index && - state.iter.start_index != glyph_item->item->offset) - { - GSList *new_attrs = attr_slist_copy (state.segment_attrs); - result = g_slist_prepend (result, - split_before_cluster_start (&state)); - state.segment_attrs = new_attrs; - } - - state.segment_attrs = g_slist_concat (state.segment_attrs, - pango_attr_iterator_get_attrs (&iter)); - } + { + if (range_end > state.iter.end_index) /* Range intersects next cluster */ + break; + + /* Since ranges end in this cluster, the next cluster goes into a + * separate segment + */ + start_new_segment = TRUE; + + have_next = pango_attr_iterator_next (&iter); + pango_attr_iterator_range (&iter, &range_start, &range_end); + + if (range_start >= state.iter.end_index) /* New range doesn't intersect this cluster */ + { + /* No gap between ranges, so previous range must of ended + * at cluster boundary. + */ + g_assert (range_start == state.iter.end_index && start_new_segment); + break; + } + + /* If any ranges start *inside* this cluster, then we need + * to split the previous cluster into a separate segment + */ + if (range_start > state.iter.start_index && + state.iter.start_index != glyph_item->item->offset) + { + GSList *new_attrs = attr_slist_copy (state.segment_attrs); + result = g_slist_prepend (result, + split_before_cluster_start (&state)); + state.segment_attrs = new_attrs; + } + + state.segment_attrs = g_slist_concat (state.segment_attrs, + pango_attr_iterator_get_attrs (&iter)); + } while (have_next); } @@ -718,9 +715,9 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item, */ void pango_glyph_item_letter_space (PangoGlyphItem *glyph_item, - const char *text, - PangoLogAttr *log_attrs, - int letter_spacing) + const char *text, + PangoLogAttr *log_attrs, + int letter_spacing) { PangoGlyphItemIter iter; PangoGlyphInfo *glyphs = glyph_item->glyphs->glyphs; @@ -754,29 +751,29 @@ pango_glyph_item_letter_space (PangoGlyphItem *glyph_item, } if (iter.start_glyph < iter.end_glyph) /* LTR */ - { - if (iter.start_char > 0) - { - glyphs[iter.start_glyph].geometry.width += space_left ; - glyphs[iter.start_glyph].geometry.x_offset += space_left ; - } - if (iter.end_char < glyph_item->item->num_chars) - { - glyphs[iter.end_glyph-1].geometry.width += space_right; - } - } - else /* RTL */ - { - if (iter.start_char > 0) - { - glyphs[iter.start_glyph].geometry.width += space_right; - } - if (iter.end_char < glyph_item->item->num_chars) - { - glyphs[iter.end_glyph+1].geometry.x_offset += space_left ; - glyphs[iter.end_glyph+1].geometry.width += space_left ; - } - } + { + if (iter.start_char > 0) + { + glyphs[iter.start_glyph].geometry.width += space_left ; + glyphs[iter.start_glyph].geometry.x_offset += space_left ; + } + if (iter.end_char < glyph_item->item->num_chars) + { + glyphs[iter.end_glyph-1].geometry.width += space_right; + } + } + else /* RTL */ + { + if (iter.start_char > 0) + { + glyphs[iter.start_glyph].geometry.width += space_right; + } + if (iter.end_char < glyph_item->item->num_chars) + { + glyphs[iter.end_glyph+1].geometry.x_offset += space_left ; + glyphs[iter.end_glyph+1].geometry.width += space_left ; + } + } } } @@ -800,8 +797,8 @@ pango_glyph_item_letter_space (PangoGlyphItem *glyph_item, */ void pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item, - const char *text, - int *logical_widths) + const char *text, + int *logical_widths) { PangoGlyphItemIter iter; gboolean has_cluster; @@ -815,26 +812,26 @@ pango_glyph_item_get_logical_widths (PangoGlyphItem *glyph_item, int glyph_index, char_index, num_chars, cluster_width = 0, char_width; for (glyph_index = iter.start_glyph; - glyph_index != iter.end_glyph; - glyph_index += dir) + glyph_index != iter.end_glyph; + glyph_index += dir) { - cluster_width += glyph_item->glyphs->glyphs[glyph_index].geometry.width; - } + cluster_width += glyph_item->glyphs->glyphs[glyph_index].geometry.width; + } num_chars = iter.end_char - iter.start_char; if (num_chars) /* pedantic */ { - char_width = cluster_width / num_chars; - - for (char_index = iter.start_char; - char_index < iter.end_char; - char_index++) - { - logical_widths[char_index] = char_width; - } - - /* add any residues to the first char */ - logical_widths[iter.start_char] += cluster_width - (char_width * num_chars); - } + char_width = cluster_width / num_chars; + + for (char_index = iter.start_char; + char_index < iter.end_char; + char_index++) + { + logical_widths[char_index] = char_width; + } + + /* add any residues to the first char */ + logical_widths[iter.start_char] += cluster_width - (char_width * num_chars); + } } } diff --git a/pango/pango-item-private.h b/pango/pango-item-private.h index 3c8b18d7..e46948c6 100644 --- a/pango/pango-item-private.h +++ b/pango/pango-item-private.h @@ -97,9 +97,15 @@ GList * pango_itemize_post_process_items (PangoContext PangoLogAttr *log_attrs, GList *items); -void pango_item_unsplit (PangoItem *orig, - int split_index, - int split_offset); +PangoItem * pango_item_new (void); +PangoItem * pango_item_split (PangoItem *orig, + int split_index, + int split_offset); +void pango_item_unsplit (PangoItem *orig, + int split_index, + int split_offset); +void pango_item_apply_attrs (PangoItem *item, + PangoAttrIterator *iter); typedef struct _ItemProperties ItemProperties; diff --git a/pango/pango-item.h b/pango/pango-item.h index 5b6c9e97..fe6f0a1b 100644 --- a/pango/pango-item.h +++ b/pango/pango-item.h @@ -57,27 +57,11 @@ PANGO_AVAILABLE_IN_ALL GType pango_item_get_type (void) G_GNUC_CONST; PANGO_AVAILABLE_IN_ALL -PangoItem * pango_item_new (void); -PANGO_AVAILABLE_IN_ALL PangoItem * pango_item_copy (PangoItem *item); PANGO_AVAILABLE_IN_ALL void pango_item_free (PangoItem *item); PANGO_AVAILABLE_IN_ALL -PangoItem * pango_item_split (PangoItem *orig, - int split_index, - int split_offset); - -PANGO_AVAILABLE_IN_ALL -void pango_item_apply_attrs (PangoItem *item, - PangoAttrIterator *iter); - -PANGO_AVAILABLE_IN_ALL -GList * pango_reorder_items (GList *items); - -/* Itemization */ - -PANGO_AVAILABLE_IN_ALL GList * pango_itemize (PangoContext *context, PangoDirection base_dir, const char *text, diff --git a/pango/pango-line-breaker.c b/pango/pango-line-breaker.c index 0c170d5b..442870d0 100644 --- a/pango/pango-line-breaker.c +++ b/pango/pango-line-breaker.c @@ -547,10 +547,6 @@ is_tab_run (PangoLine *line, return line->data->text[run->item->offset] == '\t'; } -/* - * NB: This implement the exact same algorithm as - * reorder-items.c:pango_reorder_items(). - */ static GSList * reorder_runs_recurse (GSList *items, int n_items) diff --git a/pango/reorder-items.c b/pango/reorder-items.c deleted file mode 100644 index 27ce905c..00000000 --- a/pango/reorder-items.c +++ /dev/null @@ -1,118 +0,0 @@ -/* Pango - * reorder-items.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 "config.h" -#include "pango-item-private.h" - -/* - * NB: The contents of the file implement the exact same algorithm - * pango-layout.c:pango_layout_line_reorder(). - */ - -static GList *reorder_items_recurse (GList *items, int n_items); - -/** - * pango_reorder_items: - * @items: (element-type Pango.Item): a `GList` of `PangoItem` - * in logical order. - * - * Reorder items from logical order to visual order. - * - * The visual order is determined from the associated directional - * levels of the items. The original list is unmodified. - * - * (Please open a bug if you use this function. - * It is not a particularly convenient interface, and the code - * is duplicated elsewhere in Pango for that reason.) - * - * Returns: (transfer full) (element-type Pango.Item): a `GList` - * of `PangoItem` structures in visual order. - */ -GList * -pango_reorder_items (GList *items) -{ - return reorder_items_recurse (items, g_list_length (items)); -} - -static GList * -reorder_items_recurse (GList *items, - int n_items) -{ - GList *tmp_list, *level_start_node; - int i, level_start_i; - int min_level = G_MAXINT; - GList *result = NULL; - - if (n_items == 0) - return NULL; - - tmp_list = items; - for (i=0; i<n_items; i++) - { - PangoItem *item = tmp_list->data; - - min_level = MIN (min_level, item->analysis.level); - - tmp_list = tmp_list->next; - } - - level_start_i = 0; - level_start_node = items; - tmp_list = items; - for (i=0; i<n_items; i++) - { - PangoItem *item = tmp_list->data; - - if (item->analysis.level == min_level) - { - if (min_level % 2) - { - if (i > level_start_i) - result = g_list_concat (reorder_items_recurse (level_start_node, i - level_start_i), result); - result = g_list_prepend (result, item); - } - else - { - if (i > level_start_i) - result = g_list_concat (result, reorder_items_recurse (level_start_node, i - level_start_i)); - result = g_list_append (result, item); - } - - level_start_i = i + 1; - level_start_node = tmp_list->next; - } - - tmp_list = tmp_list->next; - } - - if (min_level % 2) - { - if (i > level_start_i) - result = g_list_concat (reorder_items_recurse (level_start_node, i - level_start_i), result); - } - else - { - if (i > level_start_i) - result = g_list_concat (result, reorder_items_recurse (level_start_node, i - level_start_i)); - } - - return result; -} |