gtktextlayout.c 109 KB
Newer Older
1 2
/* GTK - The GIMP Toolkit
 * gtktextlayout.c - calculate the layout of the text
3 4 5 6 7 8 9
 *
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Red Hat, Inc.
 * Tk->Gtk port by Havoc Pennington
 * Pango support by Owen Taylor
 *
10 11
 * This file can be used under your choice of two licenses, the LGPL
 * and the original Tk license.
12
 *
13
 * LGPL:
14
 *
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Original Tk license:
30 31 32 33 34
 *
 * This software is copyrighted by the Regents of the University of
 * California, Sun Microsystems, Inc., and other parties.  The
 * following terms apply to all files associated with the software
 * unless explicitly disclaimed in individual files.
35
 *
36 37 38 39 40 41 42 43 44
 * The authors hereby grant permission to use, copy, modify,
 * distribute, and license this software and its documentation for any
 * purpose, provided that existing copyright notices are retained in
 * all copies and that this notice is included verbatim in any
 * distributions. No written agreement, license, or royalty fee is
 * required for any of the authorized uses.  Modifications to this
 * software may be copyrighted by their authors and need not follow
 * the licensing terms described here, provided that the new terms are
 * clearly indicated on the first page of each file where they apply.
45
 *
46 47 48 49 50
 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * GOVERNMENT USE: If you are acquiring this software on behalf of the
 * U.S. government, the Government shall have only "Restricted Rights"
 * in the software and related documentation as defined in the Federal
 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
 * are acquiring the software on behalf of the Department of Defense,
 * the software shall be classified as "Commercial Computer Software"
 * and the Government shall have only "Restricted Rights" as defined
 * in Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 * foregoing, the authors grant the U.S. Government and others acting
 * in its behalf permission to use and distribute the software in
 * accordance with the terms specified in this license.
70 71 72 73 74 75 76
 *
 */
/*
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
77 78
 */

79
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
80
#include <config.h>
81
#include "gtkmarshalers.h"
82 83 84
#include "gtktextlayout.h"
#include "gtktextbtree.h"
#include "gtktextiterprivate.h"
85
#include "gtktextutil.h"
Matthias Clasen's avatar
Matthias Clasen committed
86
#include "gtkintl.h"
87
#include "gtkalias.h"
88 89

#include <stdlib.h>
90
#include <string.h>
91

92 93 94 95 96 97 98 99 100 101 102 103
#define GTK_TEXT_LAYOUT_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutPrivate))

typedef struct _GtkTextLayoutPrivate GtkTextLayoutPrivate;

struct _GtkTextLayoutPrivate
{
  /* Cache the line that the cursor is positioned on, as the keyboard
     direction only influences the direction of the cursor line.
  */
  GtkTextLine *cursor_line;
};

104
static GtkTextLineData *gtk_text_layout_real_wrap (GtkTextLayout *layout,
105 106 107
                                                   GtkTextLine *line,
                                                   /* may be NULL */
                                                   GtkTextLineData *line_data);
108 109 110

static void gtk_text_layout_invalidated     (GtkTextLayout     *layout);

111 112 113
static void gtk_text_layout_real_invalidate        (GtkTextLayout     *layout,
						    const GtkTextIter *start,
						    const GtkTextIter *end);
114 115 116
static void gtk_text_layout_real_invalidate_cursors(GtkTextLayout     *layout,
						    const GtkTextIter *start,
						    const GtkTextIter *end);
117
static void gtk_text_layout_invalidate_cache       (GtkTextLayout     *layout,
118 119 120 121
						    GtkTextLine       *line,
						    gboolean           cursors_only);
static void gtk_text_layout_invalidate_cursor_line (GtkTextLayout     *layout,
						    gboolean           cursors_only);
122 123 124
static void gtk_text_layout_real_free_line_data    (GtkTextLayout     *layout,
						    GtkTextLine       *line,
						    GtkTextLineData   *line_data);
Owen Taylor's avatar
Owen Taylor committed
125 126 127 128
static void gtk_text_layout_emit_changed           (GtkTextLayout     *layout,
						    gint               y,
						    gint               old_height,
						    gint               new_height);
129 130 131 132 133

static void gtk_text_layout_invalidate_all (GtkTextLayout *layout);

static PangoAttribute *gtk_text_attr_appearance_new (const GtkTextAppearance *appearance);

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
static void gtk_text_layout_mark_set_handler    (GtkTextBuffer     *buffer,
						 const GtkTextIter *location,
						 GtkTextMark       *mark,
						 gpointer           data);
static void gtk_text_layout_buffer_insert_text  (GtkTextBuffer     *textbuffer,
						 GtkTextIter       *iter,
						 gchar             *str,
						 gint               len,
						 gpointer           data);
static void gtk_text_layout_buffer_delete_range (GtkTextBuffer     *textbuffer,
						 GtkTextIter       *start,
						 GtkTextIter       *end,
						 gpointer           data);

static void gtk_text_layout_update_cursor_line (GtkTextLayout *layout);

150 151 152
enum {
  INVALIDATED,
  CHANGED,
153
  ALLOCATE_CHILD,
154 155 156 157 158 159 160 161
  LAST_SIGNAL
};

enum {
  ARG_0,
  LAST_ARG
};

162 163
#define PIXEL_BOUND(d) (((d) + PANGO_SCALE - 1) / PANGO_SCALE)

Matthias Clasen's avatar
Matthias Clasen committed
164
static void gtk_text_layout_finalize (GObject *object);
165 166 167 168 169

static guint signals[LAST_SIGNAL] = { 0 };

PangoAttrType gtk_text_attr_appearance_type = 0;

Matthias Clasen's avatar
Matthias Clasen committed
170
G_DEFINE_TYPE (GtkTextLayout, gtk_text_layout, G_TYPE_OBJECT)
171 172 173 174

static void
gtk_text_layout_class_init (GtkTextLayoutClass *klass)
{
175
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
176

177
  object_class->finalize = gtk_text_layout_finalize;
178 179 180

  klass->wrap = gtk_text_layout_real_wrap;
  klass->invalidate = gtk_text_layout_real_invalidate;
181
  klass->invalidate_cursors = gtk_text_layout_real_invalidate_cursors;
182 183
  klass->free_line_data = gtk_text_layout_real_free_line_data;

184
  signals[INVALIDATED] =
Matthias Clasen's avatar
Matthias Clasen committed
185
    g_signal_new (I_("invalidated"),
186 187 188 189
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTextLayoutClass, invalidated),
                  NULL, NULL,
190
                  _gtk_marshal_VOID__VOID,
Manish Singh's avatar
Manish Singh committed
191
                  G_TYPE_NONE,
192
                  0);
193 194

  signals[CHANGED] =
Matthias Clasen's avatar
Matthias Clasen committed
195
    g_signal_new (I_("changed"),
196 197 198 199
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTextLayoutClass, changed),
                  NULL, NULL,
200
                  _gtk_marshal_VOID__INT_INT_INT,
Manish Singh's avatar
Manish Singh committed
201
                  G_TYPE_NONE,
202
                  3,
Manish Singh's avatar
Manish Singh committed
203 204 205
                  G_TYPE_INT,
                  G_TYPE_INT,
                  G_TYPE_INT);
206

207
  signals[ALLOCATE_CHILD] =
Matthias Clasen's avatar
Matthias Clasen committed
208
    g_signal_new (I_("allocate_child"),
209 210 211 212
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTextLayoutClass, allocate_child),
                  NULL, NULL,
213
                  _gtk_marshal_VOID__OBJECT_INT_INT,
Manish Singh's avatar
Manish Singh committed
214
                  G_TYPE_NONE,
215 216
                  3,
                  GTK_TYPE_OBJECT,
Manish Singh's avatar
Manish Singh committed
217 218
                  G_TYPE_INT,
                  G_TYPE_INT);
219 220
  
  g_type_class_add_private (object_class, sizeof (GtkTextLayoutPrivate));
221 222
}

223
static void
224 225
gtk_text_layout_init (GtkTextLayout *text_layout)
{
226
  text_layout->cursor_visible = TRUE;
227 228 229 230 231
}

GtkTextLayout*
gtk_text_layout_new (void)
{
Manish Singh's avatar
Manish Singh committed
232
  return g_object_new (GTK_TYPE_TEXT_LAYOUT, NULL);
233 234 235 236 237 238 239
}

static void
free_style_cache (GtkTextLayout *text_layout)
{
  if (text_layout->one_style_cache)
    {
240
      gtk_text_attributes_unref (text_layout->one_style_cache);
241 242 243 244 245
      text_layout->one_style_cache = NULL;
    }
}

static void
246
gtk_text_layout_finalize (GObject *object)
247 248 249 250 251
{
  GtkTextLayout *layout;

  layout = GTK_TEXT_LAYOUT (object);

252
  gtk_text_layout_set_buffer (layout, NULL);
253 254

  if (layout->default_style)
255
    gtk_text_attributes_unref (layout->default_style);
256 257 258 259
  layout->default_style = NULL;

  if (layout->ltr_context)
    {
Manish Singh's avatar
Manish Singh committed
260
      g_object_unref (layout->ltr_context);
261 262 263 264
      layout->ltr_context = NULL;
    }
  if (layout->rtl_context)
    {
Manish Singh's avatar
Manish Singh committed
265
      g_object_unref (layout->rtl_context);
266 267
      layout->rtl_context = NULL;
    }
268
  
269 270 271 272 273 274 275
  if (layout->one_display_cache) 
    {
      GtkTextLineDisplay *tmp_display = layout->one_display_cache;
      layout->one_display_cache = NULL;
      gtk_text_layout_free_line_display (layout, tmp_display);
    }

276 277 278 279 280 281 282 283 284 285 286 287 288
  if (layout->preedit_string)
    {
      g_free (layout->preedit_string);
      layout->preedit_string = NULL;
    }

  if (layout->preedit_attrs)
    {
      pango_attr_list_unref (layout->preedit_attrs);
      layout->preedit_attrs = NULL;
    }


Matthias Clasen's avatar
Matthias Clasen committed
289
  (* G_OBJECT_CLASS (gtk_text_layout_parent_class)->finalize) (object);
290 291 292 293 294 295 296 297
}

void
gtk_text_layout_set_buffer (GtkTextLayout *layout,
                            GtkTextBuffer *buffer)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (buffer == NULL || GTK_IS_TEXT_BUFFER (buffer));
298

299 300 301 302
  if (layout->buffer == buffer)
    return;

  free_style_cache (layout);
303

304 305
  if (layout->buffer)
    {
306
      _gtk_text_btree_remove_view (_gtk_text_buffer_get_btree (layout->buffer),
307
                                  layout);
308

309 310 311 312 313 314 315 316 317 318
      g_signal_handlers_disconnect_by_func (layout->buffer, 
                                            G_CALLBACK (gtk_text_layout_mark_set_handler), 
                                            layout);
      g_signal_handlers_disconnect_by_func (layout->buffer, 
                                            G_CALLBACK (gtk_text_layout_buffer_insert_text), 
                                            layout);
      g_signal_handlers_disconnect_by_func (layout->buffer, 
                                            G_CALLBACK (gtk_text_layout_buffer_delete_range), 
                                            layout);

Manish Singh's avatar
Manish Singh committed
319
      g_object_unref (layout->buffer);
320 321 322 323 324 325 326
      layout->buffer = NULL;
    }

  if (buffer)
    {
      layout->buffer = buffer;

Manish Singh's avatar
Manish Singh committed
327
      g_object_ref (buffer);
328

329
      _gtk_text_btree_add_view (_gtk_text_buffer_get_btree (buffer), layout);
330 331 332 333 334 335 336 337

      /* Bind to all signals that move the insert mark. */
      g_signal_connect_after (layout->buffer, "mark_set",
                              G_CALLBACK (gtk_text_layout_mark_set_handler), layout);
      g_signal_connect_after (layout->buffer, "insert_text",
                              G_CALLBACK (gtk_text_layout_buffer_insert_text), layout);
      g_signal_connect_after (layout->buffer, "delete_range",
                              G_CALLBACK (gtk_text_layout_buffer_delete_range), layout);
338 339

      gtk_text_layout_update_cursor_line (layout);
340 341 342 343 344 345 346
    }
}

void
gtk_text_layout_default_style_changed (GtkTextLayout *layout)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
347

348
  DV (g_print ("invalidating all due to default style change (%s)\n", G_STRLOC));
349 350 351 352 353
  gtk_text_layout_invalidate_all (layout);
}

void
gtk_text_layout_set_default_style (GtkTextLayout *layout,
354
                                   GtkTextAttributes *values)
355 356 357 358 359 360 361
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (values != NULL);

  if (values == layout->default_style)
    return;

362
  gtk_text_attributes_ref (values);
363

364
  if (layout->default_style)
365
    gtk_text_attributes_unref (layout->default_style);
366 367 368 369 370 371 372 373

  layout->default_style = values;

  gtk_text_layout_default_style_changed (layout);
}

void
gtk_text_layout_set_contexts (GtkTextLayout *layout,
374 375
                              PangoContext  *ltr_context,
                              PangoContext  *rtl_context)
376 377 378
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));

379 380 381 382
  if (layout->ltr_context != ltr_context)
    {
      if (layout->ltr_context)
	g_object_unref (layout->ltr_context);
383

384 385 386
      layout->ltr_context = ltr_context;
      g_object_ref (layout->ltr_context);
    }
387

388 389 390 391
  if (layout->rtl_context != rtl_context)
    {
      if (layout->rtl_context)
	g_object_unref (layout->rtl_context);
392

393 394 395
      layout->rtl_context = rtl_context;
      g_object_ref (layout->rtl_context);
    }
396

397
  DV (g_print ("invalidating all due to new pango contexts (%s)\n", G_STRLOC));
398 399 400
  gtk_text_layout_invalidate_all (layout);
}

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
/**
 * gtk_text_layout_set_overwrite_mode:
 * @layout: a #GtkTextLayout
 * @overwrite: overwrite mode
 *
 * Sets overwrite mode
 **/
void
gtk_text_layout_set_overwrite_mode (GtkTextLayout *layout,
				    gboolean       overwrite)
{
  overwrite = overwrite != 0;
  if (overwrite != layout->overwrite_mode)
    {
      layout->overwrite_mode = overwrite;
      gtk_text_layout_invalidate_cursor_line (layout, TRUE);
    }
}

420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
/**
 * gtk_text_layout_set_cursor_direction:
 * @direction: the new direction(s) for which to draw cursors.
 *             %GTK_TEXT_DIR_NONE means draw cursors for both
 *             left-to-right insertion and right-to-left insertion.
 *             (The two cursors will be visually distinguished.)
 * 
 * Sets which text directions (left-to-right and/or right-to-left) for
 * which cursors will be drawn for the insertion point. The visual
 * point at which new text is inserted depends on whether the new
 * text is right-to-left or left-to-right, so it may be desired to
 * make the drawn position of the cursor depend on the keyboard state.
 **/
void
gtk_text_layout_set_cursor_direction (GtkTextLayout   *layout,
				      GtkTextDirection direction)
{
  if (direction != layout->cursor_direction)
    {
      layout->cursor_direction = direction;
440
      gtk_text_layout_invalidate_cursor_line (layout, TRUE);
441 442 443
    }
}

444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
/**
 * gtk_text_layout_set_keyboard_direction:
 * @keyboard_dir: the current direction of the keyboard.
 *
 * Sets the keyboard direction; this is used as for the bidirectional
 * base direction for the line with the cursor if the line contains
 * only neutral characters.
 **/
void
gtk_text_layout_set_keyboard_direction (GtkTextLayout   *layout,
					GtkTextDirection keyboard_dir)
{
  if (keyboard_dir != layout->keyboard_direction)
    {
      layout->keyboard_direction = keyboard_dir;
459
      gtk_text_layout_invalidate_cursor_line (layout, TRUE);
460 461 462
    }
}

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
/**
 * gtk_text_layout_get_buffer:
 * @layout: a #GtkTextLayout
 *
 * Gets the text buffer used by the layout. See
 * gtk_text_layout_set_buffer().
 *
 * Return value: the text buffer used by the layout.
 **/
GtkTextBuffer *
gtk_text_layout_get_buffer (GtkTextLayout *layout)
{
  g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), NULL);

  return layout->buffer;
}

480 481 482 483 484 485
void
gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (width >= 0);
  g_return_if_fail (layout->wrap_loop_count == 0);
486

487 488
  if (layout->screen_width == width)
    return;
489

490
  layout->screen_width = width;
491

492
  DV (g_print ("invalidating all due to new screen width (%s)\n", G_STRLOC));
493 494 495
  gtk_text_layout_invalidate_all (layout);
}

496 497 498 499
/**
 * gtk_text_layout_set_cursor_visible:
 * @layout: a #GtkTextLayout
 * @cursor_visible: If %FALSE, then the insertion cursor will not
500 501
 *   be shown, even if the text is editable.
 *
502 503 504 505 506 507
 * Sets whether the insertion cursor should be shown. Generally,
 * widgets using #GtkTextLayout will hide the cursor when the
 * widget does not have the input focus.
 **/
void
gtk_text_layout_set_cursor_visible (GtkTextLayout *layout,
508
                                    gboolean       cursor_visible)
509 510 511 512 513 514 515
{
  cursor_visible = (cursor_visible != FALSE);

  if (layout->cursor_visible != cursor_visible)
    {
      GtkTextIter iter;
      gint y, height;
516

517 518 519 520 521
      layout->cursor_visible = cursor_visible;

      /* Now queue a redraw on the paragraph containing the cursor
       */
      gtk_text_buffer_get_iter_at_mark (layout->buffer, &iter,
522
                                        gtk_text_buffer_get_insert (layout->buffer));
523 524

      gtk_text_layout_get_line_yrange (layout, &iter, &y, &height);
Owen Taylor's avatar
Owen Taylor committed
525
      gtk_text_layout_emit_changed (layout, y, height, height);
526

527
      gtk_text_layout_invalidate_cache (layout, _gtk_text_iter_get_text_line (&iter), TRUE);
528 529 530 531 532 533
    }
}

/**
 * gtk_text_layout_get_cursor_visible:
 * @layout: a #GtkTextLayout
534
 *
535
 * Returns whether the insertion cursor will be shown.
536
 *
537 538 539 540 541 542 543 544 545
 * Return value: if %FALSE, the insertion cursor will not be
    shown, even if the text is editable.
 **/
gboolean
gtk_text_layout_get_cursor_visible (GtkTextLayout *layout)
{
  return layout->cursor_visible;
}

Owen Taylor's avatar
Owen Taylor committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/**
 * gtk_text_layout_set_preedit_string:
 * @layout: a #PangoLayout
 * @preedit_string: a string to display at the insertion point
 * @preedit_attrs: a #PangoAttrList of attributes that apply to @preedit_string
 * @cursor_pos: position of cursor within preedit string in chars
 * 
 * Set the preedit string and attributes. The preedit string is a
 * string showing text that is currently being edited and not
 * yet committed into the buffer.
 **/
void
gtk_text_layout_set_preedit_string (GtkTextLayout *layout,
				    const gchar   *preedit_string,
				    PangoAttrList *preedit_attrs,
				    gint           cursor_pos)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (preedit_attrs != NULL || preedit_string == NULL);

566
  g_free (layout->preedit_string);
Owen Taylor's avatar
Owen Taylor committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

  if (layout->preedit_attrs)
    pango_attr_list_unref (layout->preedit_attrs);

  if (preedit_string)
    {
      layout->preedit_string = g_strdup (preedit_string);
      layout->preedit_len = strlen (layout->preedit_string);
      pango_attr_list_ref (preedit_attrs);
      layout->preedit_attrs = preedit_attrs;

      cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (layout->preedit_string, -1));
      layout->preedit_cursor = g_utf8_offset_to_pointer (layout->preedit_string, cursor_pos) - layout->preedit_string;
    }
  else
    {
      layout->preedit_string = NULL;
      layout->preedit_len = 0;
      layout->preedit_attrs = NULL;
      layout->preedit_cursor = 0;
    }

589
  gtk_text_layout_invalidate_cursor_line (layout, FALSE);
Owen Taylor's avatar
Owen Taylor committed
590 591
}

592 593 594 595 596 597
void
gtk_text_layout_get_size (GtkTextLayout *layout,
                          gint *width,
                          gint *height)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
598

599 600 601 602 603 604 605 606 607 608
  if (width)
    *width = layout->width;

  if (height)
    *height = layout->height;
}

static void
gtk_text_layout_invalidated (GtkTextLayout *layout)
{
Manish Singh's avatar
Manish Singh committed
609
  g_signal_emit (layout, signals[INVALIDATED], 0);
610 611
}

Owen Taylor's avatar
Owen Taylor committed
612 613 614 615 616 617 618 619 620
static void
gtk_text_layout_emit_changed (GtkTextLayout *layout,
			      gint           y,
			      gint           old_height,
			      gint           new_height)
{
  g_signal_emit (layout, signals[CHANGED], 0, y, old_height, new_height);
}

621 622 623 624 625 626
static void
text_layout_changed (GtkTextLayout *layout,
                     gint           y,
                     gint           old_height,
                     gint           new_height,
                     gboolean       cursors_only)
627
{
Owen Taylor's avatar
Owen Taylor committed
628 629 630 631 632 633 634 635 636 637 638
  /* Check if the range intersects our cached line display,
   * and invalidate the cached line if so.
   */
  if (layout->one_display_cache)
    {
      GtkTextLine *line = layout->one_display_cache->line;
      gint cache_y = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
						    line, layout);
      gint cache_height = layout->one_display_cache->height;

      if (cache_y + cache_height > y && cache_y < y + old_height)
639
	gtk_text_layout_invalidate_cache (layout, line, cursors_only);
Owen Taylor's avatar
Owen Taylor committed
640
    }
641

Owen Taylor's avatar
Owen Taylor committed
642
  gtk_text_layout_emit_changed (layout, y, old_height, new_height);
643 644
}

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
void
gtk_text_layout_changed (GtkTextLayout *layout,
                         gint           y,
                         gint           old_height,
                         gint           new_height)
{
  text_layout_changed (layout, y, old_height, new_height, FALSE);
}

void
gtk_text_layout_cursors_changed (GtkTextLayout *layout,
                                 gint           y,
				 gint           old_height,
				 gint           new_height)
{
  text_layout_changed (layout, y, old_height, new_height, TRUE);
}

663 664
void
gtk_text_layout_free_line_data (GtkTextLayout     *layout,
665 666
                                GtkTextLine       *line,
                                GtkTextLineData   *line_data)
667 668 669 670 671 672 673 674 675 676 677 678 679 680
{
  (* GTK_TEXT_LAYOUT_GET_CLASS (layout)->free_line_data)
    (layout, line, line_data);
}

void
gtk_text_layout_invalidate (GtkTextLayout *layout,
                            const GtkTextIter *start_index,
                            const GtkTextIter *end_index)
{
  (* GTK_TEXT_LAYOUT_GET_CLASS (layout)->invalidate)
    (layout, start_index, end_index);
}

681 682 683 684 685 686 687 688 689
void
gtk_text_layout_invalidate_cursors (GtkTextLayout *layout,
				    const GtkTextIter *start_index,
				    const GtkTextIter *end_index)
{
  (* GTK_TEXT_LAYOUT_GET_CLASS (layout)->invalidate_cursors)
    (layout, start_index, end_index);
}

690 691
GtkTextLineData*
gtk_text_layout_wrap (GtkTextLayout *layout,
692 693 694
                      GtkTextLine  *line,
                      /* may be NULL */
                      GtkTextLineData *line_data)
695 696 697 698 699 700 701
{
  return (* GTK_TEXT_LAYOUT_GET_CLASS (layout)->wrap) (layout, line, line_data);
}

GSList*
gtk_text_layout_get_lines (GtkTextLayout *layout,
                           /* [top_y, bottom_y) */
702
                           gint top_y,
703 704 705 706 707 708 709
                           gint bottom_y,
                           gint *first_line_y)
{
  GtkTextLine *first_btree_line;
  GtkTextLine *last_btree_line;
  GtkTextLine *line;
  GSList *retval;
710

711 712 713 714
  g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), NULL);
  g_return_val_if_fail (bottom_y > top_y, NULL);

  retval = NULL;
715

716
  first_btree_line =
717
    _gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
718
                                   layout, top_y, first_line_y);
719 720 721 722 723
  if (first_btree_line == NULL)
    {
      /* off the bottom */
      return NULL;
    }
724

725
  /* -1 since bottom_y is one past */
726
  last_btree_line =
727
    _gtk_text_btree_find_line_by_y (_gtk_text_buffer_get_btree (layout->buffer),
728
                                    layout, bottom_y - 1, NULL);
729 730

  if (!last_btree_line)
731
    last_btree_line =
732
      _gtk_text_btree_get_end_iter_line (_gtk_text_buffer_get_btree (layout->buffer));
733 734 735 736 737 738 739 740 741 742

  g_assert (last_btree_line != NULL);

  line = first_btree_line;
  while (TRUE)
    {
      retval = g_slist_prepend (retval, line);

      if (line == last_btree_line)
        break;
743

744
      line = _gtk_text_line_next_excluding_last (line);
745
    }
746

747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
  retval = g_slist_reverse (retval);

  return retval;
}

static void
invalidate_cached_style (GtkTextLayout *layout)
{
  free_style_cache (layout);
}

/* These should be called around a loop which wraps a CONTIGUOUS bunch
 * of display lines. If the lines aren't contiguous you can't call
 * these.
 */
void
gtk_text_layout_wrap_loop_start (GtkTextLayout *layout)
{
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (layout->one_style_cache == NULL);
767

768 769 770 771 772 773 774
  layout->wrap_loop_count += 1;
}

void
gtk_text_layout_wrap_loop_end (GtkTextLayout *layout)
{
  g_return_if_fail (layout->wrap_loop_count > 0);
775

776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
  layout->wrap_loop_count -= 1;

  if (layout->wrap_loop_count == 0)
    {
      /* We cache a some stuff if we're iterating over some lines wrapping
       * them. This cleans it up.
       */
      /* Nuke our cached style */
      invalidate_cached_style (layout);
      g_assert (layout->one_style_cache == NULL);
    }
}

static void
gtk_text_layout_invalidate_all (GtkTextLayout *layout)
{
  GtkTextIter start;
  GtkTextIter end;
794

795 796 797 798 799 800 801 802
  if (layout->buffer == NULL)
    return;

  gtk_text_buffer_get_bounds (layout->buffer, &start, &end);

  gtk_text_layout_invalidate (layout, &start, &end);
}

803 804
static void
gtk_text_layout_invalidate_cache (GtkTextLayout *layout,
805 806
                                  GtkTextLine   *line,
				  gboolean       cursors_only)
807 808 809
{
  if (layout->one_display_cache && line == layout->one_display_cache->line)
    {
810 811 812 813 814 815 816 817
      GtkTextLineDisplay *display = layout->one_display_cache;

      if (cursors_only)
	{
	  g_slist_foreach (display->cursors, (GFunc)g_free, NULL);
	  g_slist_free (display->cursors);
	  display->cursors = NULL;
	  display->cursors_invalid = TRUE;
818
	  display->has_block_cursor = FALSE;
819 820 821 822 823 824
	}
      else
	{
	  layout->one_display_cache = NULL;
	  gtk_text_layout_free_line_display (layout, display);
	}
825 826 827
    }
}

828 829 830
/* Now invalidate the paragraph containing the cursor
 */
static void
831 832
gtk_text_layout_invalidate_cursor_line (GtkTextLayout *layout,
					gboolean cursors_only)
833
{
834
  GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
835 836
  GtkTextLineData *line_data;

837 838
  if (priv->cursor_line == NULL)
    return;
839

840
  line_data = _gtk_text_line_get_data (priv->cursor_line, layout);
841 842
  if (line_data)
    {
843 844 845 846 847 848 849 850
      if (cursors_only)
	  gtk_text_layout_invalidate_cache (layout, priv->cursor_line, TRUE);
      else
	{
	  gtk_text_layout_invalidate_cache (layout, priv->cursor_line, FALSE);
	  _gtk_text_line_invalidate_wrap (priv->cursor_line, line_data);
	}

851 852 853 854
      gtk_text_layout_invalidated (layout);
    }
}

855 856 857 858 859 860 861
static void
gtk_text_layout_update_cursor_line(GtkTextLayout *layout)
{
  GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout);
  GtkTextIter iter;

  gtk_text_buffer_get_iter_at_mark (layout->buffer, &iter,
862 863
                                    gtk_text_buffer_get_insert (layout->buffer));

864 865 866
  priv->cursor_line = _gtk_text_iter_get_text_line (&iter);
}

867 868 869 870 871 872 873
static void
gtk_text_layout_real_invalidate (GtkTextLayout *layout,
                                 const GtkTextIter *start,
                                 const GtkTextIter *end)
{
  GtkTextLine *line;
  GtkTextLine *last_line;
874

875 876 877
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
  g_return_if_fail (layout->wrap_loop_count == 0);

878 879 880 881 882 883 884
  /* Because we may be invalidating a mark, it's entirely possible
   * that gtk_text_iter_equal (start, end) in which case we
   * should still invalidate the line they are both on. i.e.
   * we always invalidate the line with "start" even
   * if there's an empty range.
   */
  
885 886 887 888
#if 0
  gtk_text_view_index_spew (start_index, "invalidate start");
  gtk_text_view_index_spew (end_index, "invalidate end");
#endif
889

890 891
  last_line = _gtk_text_iter_get_text_line (end);
  line = _gtk_text_iter_get_text_line (start);
892 893 894

  while (TRUE)
    {
895
      GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout);
896

897
      gtk_text_layout_invalidate_cache (layout, line, FALSE);
898
      
899
      if (line_data)
900
        _gtk_text_line_invalidate_wrap (line, line_data);
901

902 903
      if (line == last_line)
        break;
904

905
      line = _gtk_text_line_next_excluding_last (line);
906
    }
907

908 909 910
  gtk_text_layout_invalidated (layout);
}

911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946
static void
gtk_text_layout_real_invalidate_cursors (GtkTextLayout     *layout,
					 const GtkTextIter *start,
					 const GtkTextIter *end)
{
  /* Check if the range intersects our cached line display,
   * and invalidate the cached line if so.
   */
  if (layout->one_display_cache)
    {
      GtkTextIter line_start, line_end;
      GtkTextLine *line = layout->one_display_cache->line;

      _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
                                        &line_start, line, 0);
      line_end = line_start;
      if (!gtk_text_iter_ends_line (&line_end))
	gtk_text_iter_forward_to_line_end (&line_end);

      if (gtk_text_iter_compare (start, end) > 0)
	{
	  const GtkTextIter *tmp = start;
	  start = end;
	  end = tmp;
	}

      if (gtk_text_iter_compare (&line_start, end) <= 0 &&
	  gtk_text_iter_compare (start, &line_end) <= 0)
	{
	  gtk_text_layout_invalidate_cache (layout, line, TRUE);
	}
    }

  gtk_text_layout_invalidated (layout);
}

947 948
static void
gtk_text_layout_real_free_line_data (GtkTextLayout     *layout,
949 950
                                     GtkTextLine       *line,
                                     GtkTextLineData   *line_data)
951
{
952
  gtk_text_layout_invalidate_cache (layout, line, FALSE);
953

954 955 956 957 958 959
  g_free (line_data);
}

/**
 * gtk_text_layout_is_valid:
 * @layout: a #GtkTextLayout
960
 *
961
 * Check if there are any invalid regions in a #GtkTextLayout's buffer
962
 *
963
 * Return value: %TRUE if any invalid regions were found
964 965 966 967 968
 **/
gboolean
gtk_text_layout_is_valid (GtkTextLayout *layout)
{
  g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), FALSE);
969

970
  return _gtk_text_btree_is_valid (_gtk_text_buffer_get_btree (layout->buffer),
971
                                  layout);
972 973
}

974 975 976
static void
update_layout_size (GtkTextLayout *layout)
{
977
  _gtk_text_btree_get_view_size (_gtk_text_buffer_get_btree (layout->buffer),
978 979 980 981
				layout,
				&layout->width, &layout->height);
}

982 983 984 985 986
/**
 * gtk_text_layout_validate_yrange:
 * @layout: a #GtkTextLayout
 * @anchor: iter pointing into a line that will be used as the
 *          coordinate origin
987 988 989 990 991 992
 * @y0_: offset from the top of the line pointed to by @anchor at
 *       which to begin validation. (The offset here is in pixels
 *       after validation.)
 * @y1_: offset from the top of the line pointed to by @anchor at
 *       which to end validation. (The offset here is in pixels
 *       after validation.)
993 994
 *
 * Ensure that a region of a #GtkTextLayout is valid. The ::changed
995 996 997 998
 * signal will be emitted if any lines are validated.
 **/
void
gtk_text_layout_validate_yrange (GtkTextLayout *layout,
999 1000 1001
                                 GtkTextIter   *anchor,
                                 gint           y0,
                                 gint           y1)
1002 1003 1004 1005 1006 1007
{
  GtkTextLine *line;
  GtkTextLine *first_line = NULL;
  GtkTextLine *last_line = NULL;
  gint seen;
  gint delta_height = 0;
1008 1009 1010
  gint first_line_y = 0;        /* Quiet GCC */
  gint last_line_y = 0;         /* Quiet GCC */

1011
  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
1012

1013 1014 1015 1016
  if (y0 > 0)
    y0 = 0;
  if (y1 < 0)
    y1 = 0;
1017
  
1018 1019
  /* Validate backwards from the anchor line to y0
   */
1020
  line = _gtk_text_iter_get_text_line (anchor);
1021
  line = _gtk_text_line_previous (line);
1022 1023 1024
  seen = 0;
  while (line && seen < -y0)
    {
1025
      GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout);
1026
      if (!line_data || !line_data->valid)
1027
        {
1028 1029 1030
          gint old_height, new_height;
	  
	  old_height = line_data ? line_data->height : 0;
1031

1032
          _gtk_text_btree_validate_line (_gtk_text_buffer_get_btree (layout->buffer),
1033
                                         line, layout);
1034
          line_data = _gtk_text_line_get_data (line, layout);
1035

1036 1037 1038
	  new_height = line_data ? line_data->height : 0;

          delta_height += new_height - old_height;
1039
          
1040
          first_line = line;
1041
          first_line_y = -seen - new_height;
1042 1043 1044
          if (!last_line)
            {
              last_line = line;
1045
              last_line_y = -seen;
1046 1047 1048
            }
        }

1049
      seen += line_data ? line_data->height : 0;
1050
      line = _gtk_text_line_previous (line);
1051 1052 1053
    }

  /* Validate forwards to y1 */
1054
  line = _gtk_text_iter_get_text_line (anchor);
1055 1056 1057
  seen = 0;
  while (line && seen < y1)
    {
1058
      GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout);
1059
      if (!line_data || !line_data->valid)
1060
        {
1061 1062 1063
          gint old_height, new_height;
	  
	  old_height = line_data ? line_data->height : 0;
1064

1065
          _gtk_text_btree_validate_line (_gtk_text_buffer_get_btree (layout->buffer),
1066
                                         line, layout);
1067
          line_data = _gtk_text_line_get_data (line, layout);
1068
	  new_height = line_data ? line_data->height : 0;
1069

1070
          delta_height += new_height - old_height;
1071
          
1072 1073 1074 1075 1076 1077
          if (!first_line)
            {
              first_line = line;
              first_line_y = seen;
            }
          last_line = line;
1078
          last_line_y = seen + new_height;
1079 1080
        }

1081
      seen += line_data ? line_data->height : 0;
1082
      line = _gtk_text_line_next_excluding_last (line);
1083 1084
    }

1085 1086
  /* If we found and validated any invalid lines, update size and
   * emit the changed signal
1087 1088 1089
   */
  if (first_line)
    {
1090 1091 1092 1093
      gint line_top;

      update_layout_size (layout);

1094
      line_top = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer),
1095
                                                first_line, layout);
1096

Owen Taylor's avatar
Owen Taylor committed
1097 1098 1099 1100
      gtk_text_layout_emit_changed (layout,
				    line_top,
				    last_line_y - first_line_y - delta_height,
				    last_line_y - first_line_y);
1101 1102 1103 1104 1105 1106 1107 1108
    }
}

/**
 * gtk_text_layout_validate:
 * @tree: a #GtkTextLayout
 * @max_pixels: the maximum number of pixels to validate. (No more
 *              than one paragraph beyond this limit will be validated)
1109
 *
1110 1111 1112 1113 1114
 * Validate regions of a #GtkTextLayout. The ::changed signal will
 * be emitted for each region validated.
 **/
void
gtk_text_layout_validate (GtkTextLayout *layout,
1115
                          gint           max_pixels)
1116 1117 1118 1119
{
  gint y, old_height, new_height;

  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
1120

1121
  while (max_pixels > 0 &&
1122
         _gtk_text_btree_validate (_gtk_text_buffer_get_btree (layout->buffer),
1123 1124
                                   layout,  max_pixels,
                                   &y, &old_height, &new_height))
1125 1126
    {
      max_pixels -= new_height;
1127 1128

      update_layout_size (layout);
Owen Taylor's avatar
Owen Taylor committed
1129
      gtk_text_layout_emit_changed (layout, y, old_height, new_height);
1130 1131 1132 1133 1134
    }
}

static GtkTextLineData*
gtk_text_layout_real_wrap (GtkTextLayout   *layout,
1135 1136 1137
                           GtkTextLine     *line,
                           /* may be NULL */
                           GtkTextLineData *line_data)
1138 1139
{
  GtkTextLineDisplay *display;
1140

1141
  g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), NULL);
1142 1143
  g_return_val_if_fail (line != NULL, NULL);
  
1144 1145
  if (line_data == NULL)
    {
1146
      line_data = _gtk_text_line_data_new (layout, line);
1147
      _gtk_text_line_add_data (line, line_data);
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
    }

  display = gtk_text_layout_get_line_display (layout, line, TRUE);
  line_data->width = display->width;
  line_data->height = display->height;
  line_data->valid = TRUE;
  gtk_text_layout_free_line_display (layout, display);

  return line_data;
}

/*
 * Layout utility functions
 */

/* If you get the style with get_style () you need to call
   release_style () to free it. */
1165
static GtkTextAttributes*
1166
get_style (GtkTextLayout *layout,
1167
	   GPtrArray     *tags)
1168
{
1169
  GtkTextAttributes *style;
1170

1171 1172 1173 1174 1175 1176
  /* If we have the one-style cache, then it means
     that we haven't seen a toggle since we filled in the
     one-style cache.
  */
  if (layout->one_style_cache != NULL)
    {
1177
      gtk_text_attributes_ref (layout->one_style_cache);
1178 1179 1180 1181
      return layout->one_style_cache;
    }

  g_assert (layout->one_style_cache == NULL);
1182

1183
  /* No tags, use default style */
1184
  if (tags == NULL || tags->len == 0)
1185 1186 1187
    {
      /* One ref for the return value, one ref for the
         layout->one_style_cache reference */
1188 1189
      gtk_text_attributes_ref (layout->default_style);
      gtk_text_attributes_ref (layout->default_style);
1190 1191 1192 1193
      layout->one_style_cache = layout->default_style;

      return layout->default_style;
    }
1194

1195
  style = gtk_text_attributes_new ();
1196

1197 1198
  gtk_text_attributes_copy_values (layout->default_style,
                                   style);
1199

1200
  _gtk_text_attributes_fill_from_tags (style,
1201 1202
                                       (GtkTextTag**) tags->pdata,
                                       tags->len);
1203 1204 1205 1206 1207

  g_assert (style->refcount == 1);

  /* Leave this style as the last one seen */
  g_assert (layout->one_style_cache == NULL);
1208
  gtk_text_attributes_ref (style); /* ref held by layout->one_style_cache */
1209
  layout->one_style_cache = style;
1210

1211 1212 1213 1214 1215 1216
  /* Returning yet another refcount */
  return style;
}

static void
release_style (GtkTextLayout *layout,
1217
               GtkTextAttributes *style)
1218 1219 1220 1221
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->refcount > 0);

1222
  gtk_text_attributes_unref (style);
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
}

/*
 * Lines
 */

/* This function tries to optimize the case where a line
   is completely invisible */
static gboolean
totally_invisible_line (GtkTextLayout *layout,
1233 1234
                        GtkTextLine   *line,
                        GtkTextIter   *iter)
1235 1236 1237
{
  GtkTextLineSegment *seg;
  int bytes = 0;
1238

1239 1240 1241 1242
  /* Check if the first char is visible, if so we are partially visible.  
   * Note that we have to check this since we don't know the current 
   * invisible/noninvisible toggle state; this function can use the whole btree 
   * to get it right.
1243
   */
1244 1245 1246 1247
  _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
				    iter, line, 0);
  
  if (!_gtk_text_btree_char_is_invisible (iter))
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    return FALSE;

  bytes = 0;
  seg = line->segments;

  while (seg != NULL)
    {
      if (seg->byte_count > 0)
        bytes += seg->byte_count;

      /* Note that these two tests can cause us to bail out
1259 1260 1261 1262 1263
       * when we shouldn't, because a higher-priority tag
       * may override these settings. However the important
       * thing is to only invisible really-invisible lines, rather
       * than to invisible all really-invisible lines.
       */
1264

1265 1266 1267
      else if (seg->type == &gtk_text_toggle_on_type)
        {
          invalidate_cached_style (layout);
1268

1269
          /* Bail out if an elision-unsetting tag begins */
1270 1271
          if (seg->body.toggle.info->tag->invisible_set &&
              !seg->body.toggle.info->tag->values->invisible)
1272 1273 1274 1275 1276
            break;
        }
      else if (seg->type == &gtk_text_toggle_off_type)
        {
          invalidate_cached_style (layout);
1277

1278
          /* Bail out if an elision-setting tag ends */
1279 1280
          if (seg->body.toggle.info->tag->invisible_set &&
              seg->body.toggle.info->tag->values->invisible)
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
            break;
        }

      seg = seg->next;
    }

  if (seg != NULL)       /* didn't reach line end */
    return FALSE;

  return TRUE;
}

static void
set_para_values (GtkTextLayout      *layout,
1295 1296
                 PangoDirection      base_dir,
                 GtkTextAttributes  *style,
1297
                 GtkTextLineDisplay *display)
1298 1299
{
  PangoAlignment pango_align = PANGO_ALIGN_LEFT;
1300
  PangoWrapMode pango_wrap = PANGO_WRAP_WORD;
1301

1302 1303 1304 1305 1306
  switch (base_dir)
    {
    /* If no base direction was found, then use the style direction */
    case PANGO_DIRECTION_NEUTRAL :
      display->direction = style->direction;
1307

1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
      /* Override the base direction */
      if (display->direction == GTK_TEXT_DIR_RTL)
        base_dir = PANGO_DIRECTION_RTL;