4 * Copyright (C) 1999 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include "pango-glyph.h"
26 * NB: The contents of the file implement the exact same algorithm
27 * pango-layout.c:pango_layout_line_reorder().
30 static GList *reorder_items_recurse (GList *items, int n_items);
33 * pango_reorder_items:
34 * @logical_items: a #GList of #PangoItem in logical order.
36 * From a list of items in logical order and the associated
37 * directional levels, produce a list in visual order.
38 * The original list is unmodified.
40 * Returns: a #GList of #PangoItem structures in visual order.
42 * (Please open a bug if you use this function.
43 * It is not a particularly convenient interface, and the code
44 * is duplicated elsewhere in Pango for that reason.)
47 pango_reorder_items (GList *logical_items)
49 return reorder_items_recurse (logical_items, g_list_length (logical_items));
53 reorder_items_recurse (GList *items, int n_items)
55 GList *tmp_list, *level_start_node;
57 int min_level = G_MAXINT;
64 for (i=0; i<n_items; i++)
66 PangoItem *item = tmp_list->data;
68 min_level = MIN (min_level, item->analysis.level);
70 tmp_list = tmp_list->next;
74 level_start_node = items;
76 for (i=0; i<n_items; i++)
78 PangoItem *item = tmp_list->data;
80 if (item->analysis.level == min_level)
84 if (i > level_start_i)
85 result = g_list_concat (reorder_items_recurse (level_start_node, i - level_start_i), result);
86 result = g_list_prepend (result, item);
90 if (i > level_start_i)
91 result = g_list_concat (result, reorder_items_recurse (level_start_node, i - level_start_i));
92 result = g_list_append (result, item);
95 level_start_i = i + 1;
96 level_start_node = tmp_list->next;
99 tmp_list = tmp_list->next;
104 if (i > level_start_i)
105 result = g_list_concat (reorder_items_recurse (level_start_node, i - level_start_i), result);
109 if (i > level_start_i)
110 result = g_list_concat (result, reorder_items_recurse (level_start_node, i - level_start_i));