1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module pango.PgLayout; 26 27 private import glib.ConstructionException; 28 private import glib.ListSG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gtkc.pango; 32 public import gtkc.pangotypes; 33 private import pango.PgAttributeList; 34 private import pango.PgContext; 35 private import pango.PgFontDescription; 36 private import pango.PgLayoutIter; 37 private import pango.PgLayoutLine; 38 private import pango.PgTabArray; 39 40 41 /** 42 * The #PangoLayout structure represents an entire paragraph 43 * of text. It is initialized with a #PangoContext, UTF-8 string 44 * and set of attributes for that string. Once that is done, the 45 * set of formatted lines can be extracted from the object, 46 * the layout can be rendered, and conversion between logical 47 * character positions within the layout's text, and the physical 48 * position of the resulting glyphs can be made. 49 * 50 * There are also a number of parameters to adjust the formatting 51 * of a #PangoLayout, which are illustrated in <xref linkend="parameters"/>. 52 * It is possible, as well, to ignore the 2-D setup, and simply 53 * treat the results of a #PangoLayout as a list of lines. 54 * 55 * <figure id="parameters"> 56 * <title>Adjustable parameters for a PangoLayout</title> 57 * <graphic fileref="layout.gif" format="GIF"></graphic> 58 * </figure> 59 * 60 * The #PangoLayout structure is opaque, and has no user-visible 61 * fields. 62 */ 63 public class PgLayout : ObjectG 64 { 65 /** the main Gtk struct */ 66 protected PangoLayout* pangoLayout; 67 68 /** Get the main Gtk struct */ 69 public PangoLayout* getPgLayoutStruct() 70 { 71 return pangoLayout; 72 } 73 74 /** the main Gtk struct as a void* */ 75 protected override void* getStruct() 76 { 77 return cast(void*)pangoLayout; 78 } 79 80 protected override void setStruct(GObject* obj) 81 { 82 pangoLayout = cast(PangoLayout*)obj; 83 super.setStruct(obj); 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (PangoLayout* pangoLayout, bool ownedRef = false) 90 { 91 this.pangoLayout = pangoLayout; 92 super(cast(GObject*)pangoLayout, ownedRef); 93 } 94 95 /** 96 */ 97 98 public static GType getType() 99 { 100 return pango_layout_get_type(); 101 } 102 103 /** 104 * Create a new #PangoLayout object with attributes initialized to 105 * default values for a particular #PangoContext. 106 * 107 * Params: 108 * context = a #PangoContext 109 * 110 * Return: the newly allocated #PangoLayout, with a reference 111 * count of one, which should be freed with 112 * g_object_unref(). 113 * 114 * Throws: ConstructionException GTK+ fails to create the object. 115 */ 116 public this(PgContext context) 117 { 118 auto p = pango_layout_new((context is null) ? null : context.getPgContextStruct()); 119 120 if(p is null) 121 { 122 throw new ConstructionException("null returned by new"); 123 } 124 125 this(cast(PangoLayout*) p, true); 126 } 127 128 /** 129 * Forces recomputation of any state in the #PangoLayout that 130 * might depend on the layout's context. This function should 131 * be called if you make changes to the context subsequent 132 * to creating the layout. 133 */ 134 public void contextChanged() 135 { 136 pango_layout_context_changed(pangoLayout); 137 } 138 139 /** 140 * Does a deep copy-by-value of the @src layout. The attribute list, 141 * tab array, and text from the original layout are all copied by 142 * value. 143 * 144 * Return: the newly allocated #PangoLayout, 145 * with a reference count of one, which should be freed 146 * with g_object_unref(). 147 */ 148 public PgLayout copy() 149 { 150 auto p = pango_layout_copy(pangoLayout); 151 152 if(p is null) 153 { 154 return null; 155 } 156 157 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p, true); 158 } 159 160 /** 161 * Gets the alignment for the layout: how partial lines are 162 * positioned within the horizontal space available. 163 * 164 * Return: the alignment. 165 */ 166 public PangoAlignment getAlignment() 167 { 168 return pango_layout_get_alignment(pangoLayout); 169 } 170 171 /** 172 * Gets the attribute list for the layout, if any. 173 * 174 * Return: a #PangoAttrList. 175 */ 176 public PgAttributeList getAttributes() 177 { 178 auto p = pango_layout_get_attributes(pangoLayout); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) p); 186 } 187 188 /** 189 * Gets whether to calculate the bidirectional base direction 190 * for the layout according to the contents of the layout. 191 * See pango_layout_set_auto_dir(). 192 * 193 * Return: %TRUE if the bidirectional base direction 194 * is computed from the layout's contents, %FALSE otherwise. 195 * 196 * Since: 1.4 197 */ 198 public bool getAutoDir() 199 { 200 return pango_layout_get_auto_dir(pangoLayout) != 0; 201 } 202 203 /** 204 * Gets the Y position of baseline of the first line in @layout. 205 * 206 * Return: baseline of first line, from top of @layout. 207 * 208 * Since: 1.22 209 */ 210 public int getBaseline() 211 { 212 return pango_layout_get_baseline(pangoLayout); 213 } 214 215 /** 216 * Returns the number of Unicode characters in the 217 * the text of @layout. 218 * 219 * Return: the number of Unicode characters 220 * in the text of @layout 221 * 222 * Since: 1.30 223 */ 224 public int getCharacterCount() 225 { 226 return pango_layout_get_character_count(pangoLayout); 227 } 228 229 /** 230 * Retrieves the #PangoContext used for this layout. 231 * 232 * Return: the #PangoContext for the layout. 233 * This does not have an additional refcount added, so if you want to 234 * keep a copy of this around, you must reference it yourself. 235 */ 236 public PgContext getContext() 237 { 238 auto p = pango_layout_get_context(pangoLayout); 239 240 if(p is null) 241 { 242 return null; 243 } 244 245 return ObjectG.getDObject!(PgContext)(cast(PangoContext*) p); 246 } 247 248 /** 249 * Given an index within a layout, determines the positions that of the 250 * strong and weak cursors if the insertion point is at that 251 * index. The position of each cursor is stored as a zero-width 252 * rectangle. The strong cursor location is the location where 253 * characters of the directionality equal to the base direction of the 254 * layout are inserted. The weak cursor location is the location 255 * where characters of the directionality opposite to the base 256 * direction of the layout are inserted. 257 * 258 * Params: 259 * index = the byte index of the cursor 260 * strongPos = location to store the strong cursor position 261 * (may be %NULL) 262 * weakPos = location to store the weak cursor position (may be %NULL) 263 */ 264 public void getCursorPos(int index, out PangoRectangle strongPos, out PangoRectangle weakPos) 265 { 266 pango_layout_get_cursor_pos(pangoLayout, index, &strongPos, &weakPos); 267 } 268 269 /** 270 * Gets the type of ellipsization being performed for @layout. 271 * See pango_layout_set_ellipsize() 272 * 273 * Return: the current ellipsization mode for @layout. 274 * 275 * Use pango_layout_is_ellipsized() to query whether any paragraphs 276 * were actually ellipsized. 277 * 278 * Since: 1.6 279 */ 280 public PangoEllipsizeMode getEllipsize() 281 { 282 return pango_layout_get_ellipsize(pangoLayout); 283 } 284 285 /** 286 * Computes the logical and ink extents of @layout. Logical extents 287 * are usually what you want for positioning things. Note that both extents 288 * may have non-zero x and y. You may want to use those to offset where you 289 * render the layout. Not doing that is a very typical bug that shows up as 290 * right-to-left layouts not being correctly positioned in a layout with 291 * a set width. 292 * 293 * The extents are given in layout coordinates and in Pango units; layout 294 * coordinates begin at the top left corner of the layout. 295 * 296 * Params: 297 * inkRect = rectangle used to store the extents of the 298 * layout as drawn or %NULL to indicate that the result is 299 * not needed. 300 * logicalRect = rectangle used to store the logical 301 * extents of the layout or %NULL to indicate that the 302 * result is not needed. 303 */ 304 public void getExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect) 305 { 306 pango_layout_get_extents(pangoLayout, &inkRect, &logicalRect); 307 } 308 309 /** 310 * Gets the font description for the layout, if any. 311 * 312 * Return: a pointer to the layout's font description, 313 * or %NULL if the font description from the layout's 314 * context is inherited. This value is owned by the layout 315 * and must not be modified or freed. 316 * 317 * Since: 1.8 318 */ 319 public PgFontDescription getFontDescription() 320 { 321 auto p = pango_layout_get_font_description(pangoLayout); 322 323 if(p is null) 324 { 325 return null; 326 } 327 328 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p); 329 } 330 331 /** 332 * Gets the height of layout used for ellipsization. See 333 * pango_layout_set_height() for details. 334 * 335 * Return: the height, in Pango units if positive, or 336 * number of lines if negative. 337 * 338 * Since: 1.20 339 */ 340 public int getHeight() 341 { 342 return pango_layout_get_height(pangoLayout); 343 } 344 345 /** 346 * Gets the paragraph indent width in Pango units. A negative value 347 * indicates a hanging indentation. 348 * 349 * Return: the indent in Pango units. 350 */ 351 public int getIndent() 352 { 353 return pango_layout_get_indent(pangoLayout); 354 } 355 356 /** 357 * Returns an iterator to iterate over the visual extents of the layout. 358 * 359 * Return: the new #PangoLayoutIter that should be freed using 360 * pango_layout_iter_free(). 361 */ 362 public PgLayoutIter getIter() 363 { 364 auto p = pango_layout_get_iter(pangoLayout); 365 366 if(p is null) 367 { 368 return null; 369 } 370 371 return ObjectG.getDObject!(PgLayoutIter)(cast(PangoLayoutIter*) p); 372 } 373 374 /** 375 * Gets whether each complete line should be stretched to fill the entire 376 * width of the layout. 377 * 378 * Return: the justify. 379 */ 380 public bool getJustify() 381 { 382 return pango_layout_get_justify(pangoLayout) != 0; 383 } 384 385 /** 386 * Retrieves a particular line from a #PangoLayout. 387 * 388 * Use the faster pango_layout_get_line_readonly() if you do not plan 389 * to modify the contents of the line (glyphs, glyph widths, etc.). 390 * 391 * Params: 392 * line = the index of a line, which must be between 0 and 393 * <literal>pango_layout_get_line_count(layout) - 1</literal>, inclusive. 394 * 395 * Return: the requested #PangoLayoutLine, or %NULL if the 396 * index is out of range. This layout line can 397 * be ref'ed and retained, but will become invalid 398 * if changes are made to the #PangoLayout. 399 */ 400 public PgLayoutLine getLine(int line) 401 { 402 auto p = pango_layout_get_line(pangoLayout, line); 403 404 if(p is null) 405 { 406 return null; 407 } 408 409 return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p); 410 } 411 412 /** 413 * Retrieves the count of lines for the @layout. 414 * 415 * Return: the line count. 416 */ 417 public int getLineCount() 418 { 419 return pango_layout_get_line_count(pangoLayout); 420 } 421 422 /** 423 * Retrieves a particular line from a #PangoLayout. 424 * 425 * This is a faster alternative to pango_layout_get_line(), 426 * but the user is not expected 427 * to modify the contents of the line (glyphs, glyph widths, etc.). 428 * 429 * Params: 430 * line = the index of a line, which must be between 0 and 431 * <literal>pango_layout_get_line_count(layout) - 1</literal>, inclusive. 432 * 433 * Return: the requested #PangoLayoutLine, or %NULL if the 434 * index is out of range. This layout line can 435 * be ref'ed and retained, but will become invalid 436 * if changes are made to the #PangoLayout. 437 * No changes should be made to the line. 438 * 439 * Since: 1.16 440 */ 441 public PgLayoutLine getLineReadonly(int line) 442 { 443 auto p = pango_layout_get_line_readonly(pangoLayout, line); 444 445 if(p is null) 446 { 447 return null; 448 } 449 450 return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p); 451 } 452 453 /** 454 * Returns the lines of the @layout as a list. 455 * 456 * Use the faster pango_layout_get_lines_readonly() if you do not plan 457 * to modify the contents of the lines (glyphs, glyph widths, etc.). 458 * 459 * Return: a #GSList containing 460 * the lines in the layout. This points to internal data of the #PangoLayout 461 * and must be used with care. It will become invalid on any change to the layout's 462 * text or properties. 463 */ 464 public ListSG getLines() 465 { 466 auto p = pango_layout_get_lines(pangoLayout); 467 468 if(p is null) 469 { 470 return null; 471 } 472 473 return new ListSG(cast(GSList*) p); 474 } 475 476 /** 477 * Returns the lines of the @layout as a list. 478 * 479 * This is a faster alternative to pango_layout_get_lines(), 480 * but the user is not expected 481 * to modify the contents of the lines (glyphs, glyph widths, etc.). 482 * 483 * Return: a #GSList containing 484 * the lines in the layout. This points to internal data of the #PangoLayout and 485 * must be used with care. It will become invalid on any change to the layout's 486 * text or properties. No changes should be made to the lines. 487 * 488 * Since: 1.16 489 */ 490 public ListSG getLinesReadonly() 491 { 492 auto p = pango_layout_get_lines_readonly(pangoLayout); 493 494 if(p is null) 495 { 496 return null; 497 } 498 499 return new ListSG(cast(GSList*) p); 500 } 501 502 /** 503 * Retrieves an array of logical attributes for each character in 504 * the @layout. 505 * 506 * Params: 507 * attrs = location to store a pointer to an array of logical attributes 508 * This value must be freed with g_free(). 509 * nAttrs = location to store the number of the attributes in the 510 * array. (The stored value will be one more than the total number 511 * of characters in the layout, since there need to be attributes 512 * corresponding to both the position before the first character 513 * and the position after the last character.) 514 */ 515 public void getLogAttrs(out PangoLogAttr[] attrs) 516 { 517 PangoLogAttr* outattrs = null; 518 int nAttrs; 519 520 pango_layout_get_log_attrs(pangoLayout, &outattrs, &nAttrs); 521 522 attrs = outattrs[0 .. nAttrs]; 523 } 524 525 /** 526 * Retrieves an array of logical attributes for each character in 527 * the @layout. 528 * 529 * This is a faster alternative to pango_layout_get_log_attrs(). 530 * The returned array is part of @layout and must not be modified. 531 * Modifying the layout will invalidate the returned array. 532 * 533 * The number of attributes returned in @n_attrs will be one more 534 * than the total number of characters in the layout, since there 535 * need to be attributes corresponding to both the position before 536 * the first character and the position after the last character. 537 * 538 * Return: an array of logical attributes 539 * 540 * Since: 1.30 541 */ 542 public PangoLogAttr[] getLogAttrsReadonly() 543 { 544 int nAttrs; 545 546 auto p = pango_layout_get_log_attrs_readonly(pangoLayout, &nAttrs); 547 548 return p[0 .. nAttrs]; 549 } 550 551 /** 552 * Computes the logical and ink extents of @layout in device units. 553 * This function just calls pango_layout_get_extents() followed by 554 * two pango_extents_to_pixels() calls, rounding @ink_rect and @logical_rect 555 * such that the rounded rectangles fully contain the unrounded one (that is, 556 * passes them as first argument to pango_extents_to_pixels()). 557 * 558 * Params: 559 * inkRect = rectangle used to store the extents of the 560 * layout as drawn or %NULL to indicate that the result is 561 * not needed. 562 * logicalRect = rectangle used to store the logical 563 * extents of the layout or %NULL to indicate that the 564 * result is not needed. 565 */ 566 public void getPixelExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect) 567 { 568 pango_layout_get_pixel_extents(pangoLayout, &inkRect, &logicalRect); 569 } 570 571 /** 572 * Determines the logical width and height of a #PangoLayout 573 * in device units. (pango_layout_get_size() returns the width 574 * and height scaled by %PANGO_SCALE.) This 575 * is simply a convenience function around 576 * pango_layout_get_pixel_extents(). 577 * 578 * Params: 579 * width = location to store the logical width, or %NULL 580 * height = location to store the logical height, or %NULL 581 */ 582 public void getPixelSize(out int width, out int height) 583 { 584 pango_layout_get_pixel_size(pangoLayout, &width, &height); 585 } 586 587 /** 588 * Returns the current serial number of @layout. The serial number is 589 * initialized to an small number larger than zero when a new layout 590 * is created and is increased whenever the layout is changed using any 591 * of the setter functions, or the #PangoContext it uses has changed. 592 * The serial may wrap, but will never have the value 0. Since it 593 * can wrap, never compare it with "less than", always use "not equals". 594 * 595 * This can be used to automatically detect changes to a #PangoLayout, and 596 * is useful for example to decide whether a layout needs redrawing. 597 * To force the serial to be increased, use pango_layout_context_changed(). 598 * 599 * Return: The current serial number of @layout. 600 * 601 * Since: 1.32.4 602 */ 603 public uint getSerial() 604 { 605 return pango_layout_get_serial(pangoLayout); 606 } 607 608 /** 609 * Obtains the value set by pango_layout_set_single_paragraph_mode(). 610 * 611 * Return: %TRUE if the layout does not break paragraphs at 612 * paragraph separator characters, %FALSE otherwise. 613 */ 614 public bool getSingleParagraphMode() 615 { 616 return pango_layout_get_single_paragraph_mode(pangoLayout) != 0; 617 } 618 619 /** 620 * Determines the logical width and height of a #PangoLayout 621 * in Pango units (device units scaled by %PANGO_SCALE). This 622 * is simply a convenience function around pango_layout_get_extents(). 623 * 624 * Params: 625 * width = location to store the logical width, or %NULL 626 * height = location to store the logical height, or %NULL 627 */ 628 public void getSize(out int width, out int height) 629 { 630 pango_layout_get_size(pangoLayout, &width, &height); 631 } 632 633 /** 634 * Gets the amount of spacing between the lines of the layout. 635 * 636 * Return: the spacing in Pango units. 637 */ 638 public int getSpacing() 639 { 640 return pango_layout_get_spacing(pangoLayout); 641 } 642 643 /** 644 * Gets the current #PangoTabArray used by this layout. If no 645 * #PangoTabArray has been set, then the default tabs are in use 646 * and %NULL is returned. Default tabs are every 8 spaces. 647 * The return value should be freed with pango_tab_array_free(). 648 * 649 * Return: a copy of the tabs for this layout, or %NULL. 650 */ 651 public PgTabArray getTabs() 652 { 653 auto p = pango_layout_get_tabs(pangoLayout); 654 655 if(p is null) 656 { 657 return null; 658 } 659 660 return ObjectG.getDObject!(PgTabArray)(cast(PangoTabArray*) p); 661 } 662 663 /** 664 * Gets the text in the layout. The returned text should not 665 * be freed or modified. 666 * 667 * Return: the text in the @layout. 668 */ 669 public string getText() 670 { 671 return Str.toString(pango_layout_get_text(pangoLayout)); 672 } 673 674 /** 675 * Counts the number unknown glyphs in @layout. That is, zero if 676 * glyphs for all characters in the layout text were found, or more 677 * than zero otherwise. 678 * 679 * This function can be used to determine if there are any fonts 680 * available to render all characters in a certain string, or when 681 * used in combination with %PANGO_ATTR_FALLBACK, to check if a 682 * certain font supports all the characters in the string. 683 * 684 * Return: The number of unknown glyphs in @layout. 685 * 686 * Since: 1.16 687 */ 688 public int getUnknownGlyphsCount() 689 { 690 return pango_layout_get_unknown_glyphs_count(pangoLayout); 691 } 692 693 /** 694 * Gets the width to which the lines of the #PangoLayout should wrap. 695 * 696 * Return: the width in Pango units, or -1 if no width set. 697 */ 698 public int getWidth() 699 { 700 return pango_layout_get_width(pangoLayout); 701 } 702 703 /** 704 * Gets the wrap mode for the layout. 705 * 706 * Use pango_layout_is_wrapped() to query whether any paragraphs 707 * were actually wrapped. 708 * 709 * Return: active wrap mode. 710 */ 711 public PangoWrapMode getWrap() 712 { 713 return pango_layout_get_wrap(pangoLayout); 714 } 715 716 /** 717 * Converts from byte @index_ within the @layout to line and X position. 718 * (X position is measured from the left edge of the line) 719 * 720 * Params: 721 * index = the byte index of a grapheme within the layout. 722 * trailing = an integer indicating the edge of the grapheme to retrieve the 723 * position of. If 0, the trailing edge of the grapheme, if > 0, 724 * the leading of the grapheme. 725 * line = location to store resulting line index. (which will 726 * between 0 and pango_layout_get_line_count(layout) - 1), or %NULL 727 * xPos = location to store resulting position within line 728 * (%PANGO_SCALE units per device unit), or %NULL 729 */ 730 public void indexToLineX(int index, bool trailing, out int line, out int xPos) 731 { 732 pango_layout_index_to_line_x(pangoLayout, index, trailing, &line, &xPos); 733 } 734 735 /** 736 * Converts from an index within a #PangoLayout to the onscreen position 737 * corresponding to the grapheme at that index, which is represented 738 * as rectangle. Note that <literal>pos->x</literal> is always the leading 739 * edge of the grapheme and <literal>pos->x + pos->width</literal> the trailing 740 * edge of the grapheme. If the directionality of the grapheme is right-to-left, 741 * then <literal>pos->width</literal> will be negative. 742 * 743 * Params: 744 * index = byte index within @layout 745 * pos = rectangle in which to store the position of the grapheme 746 */ 747 public void indexToPos(int index, out PangoRectangle pos) 748 { 749 pango_layout_index_to_pos(pangoLayout, index, &pos); 750 } 751 752 /** 753 * Queries whether the layout had to ellipsize any paragraphs. 754 * 755 * This returns %TRUE if the ellipsization mode for @layout 756 * is not %PANGO_ELLIPSIZE_NONE, a positive width is set on @layout, 757 * and there are paragraphs exceeding that width that have to be 758 * ellipsized. 759 * 760 * Return: %TRUE if any paragraphs had to be ellipsized, %FALSE 761 * otherwise. 762 * 763 * Since: 1.16 764 */ 765 public bool isEllipsized() 766 { 767 return pango_layout_is_ellipsized(pangoLayout) != 0; 768 } 769 770 /** 771 * Queries whether the layout had to wrap any paragraphs. 772 * 773 * This returns %TRUE if a positive width is set on @layout, 774 * ellipsization mode of @layout is set to %PANGO_ELLIPSIZE_NONE, 775 * and there are paragraphs exceeding the layout width that have 776 * to be wrapped. 777 * 778 * Return: %TRUE if any paragraphs had to be wrapped, %FALSE 779 * otherwise. 780 * 781 * Since: 1.16 782 */ 783 public bool isWrapped() 784 { 785 return pango_layout_is_wrapped(pangoLayout) != 0; 786 } 787 788 /** 789 * Computes a new cursor position from an old position and 790 * a count of positions to move visually. If @direction is positive, 791 * then the new strong cursor position will be one position 792 * to the right of the old cursor position. If @direction is negative, 793 * then the new strong cursor position will be one position 794 * to the left of the old cursor position. 795 * 796 * In the presence of bidirectional text, the correspondence 797 * between logical and visual order will depend on the direction 798 * of the current run, and there may be jumps when the cursor 799 * is moved off of the end of a run. 800 * 801 * Motion here is in cursor positions, not in characters, so a 802 * single call to pango_layout_move_cursor_visually() may move the 803 * cursor over multiple characters when multiple characters combine 804 * to form a single grapheme. 805 * 806 * Params: 807 * strong = whether the moving cursor is the strong cursor or the 808 * weak cursor. The strong cursor is the cursor corresponding 809 * to text insertion in the base direction for the layout. 810 * oldIndex = the byte index of the grapheme for the old index 811 * oldTrailing = if 0, the cursor was at the trailing edge of the 812 * grapheme indicated by @old_index, if > 0, the cursor 813 * was at the leading edge. 814 * direction = direction to move cursor. A negative 815 * value indicates motion to the left. 816 * newIndex = location to store the new cursor byte index. A value of -1 817 * indicates that the cursor has been moved off the beginning 818 * of the layout. A value of %G_MAXINT indicates that 819 * the cursor has been moved off the end of the layout. 820 * newTrailing = number of characters to move forward from the 821 * location returned for @new_index to get the position 822 * where the cursor should be displayed. This allows 823 * distinguishing the position at the beginning of one 824 * line from the position at the end of the preceding 825 * line. @new_index is always on the line where the 826 * cursor should be displayed. 827 */ 828 public void moveCursorVisually(bool strong, int oldIndex, int oldTrailing, int direction, out int newIndex, out int newTrailing) 829 { 830 pango_layout_move_cursor_visually(pangoLayout, strong, oldIndex, oldTrailing, direction, &newIndex, &newTrailing); 831 } 832 833 /** 834 * Sets the alignment for the layout: how partial lines are 835 * positioned within the horizontal space available. 836 * 837 * Params: 838 * alignment = the alignment 839 */ 840 public void setAlignment(PangoAlignment alignment) 841 { 842 pango_layout_set_alignment(pangoLayout, alignment); 843 } 844 845 /** 846 * Sets the text attributes for a layout object. 847 * References @attrs, so the caller can unref its reference. 848 * 849 * Params: 850 * attrs = a #PangoAttrList, can be %NULL 851 */ 852 public void setAttributes(PgAttributeList attrs) 853 { 854 pango_layout_set_attributes(pangoLayout, (attrs is null) ? null : attrs.getPgAttributeListStruct()); 855 } 856 857 /** 858 * Sets whether to calculate the bidirectional base direction 859 * for the layout according to the contents of the layout; 860 * when this flag is on (the default), then paragraphs in 861 * @layout that begin with strong right-to-left characters 862 * (Arabic and Hebrew principally), will have right-to-left 863 * layout, paragraphs with letters from other scripts will 864 * have left-to-right layout. Paragraphs with only neutral 865 * characters get their direction from the surrounding paragraphs. 866 * 867 * When %FALSE, the choice between left-to-right and 868 * right-to-left layout is done according to the base direction 869 * of the layout's #PangoContext. (See pango_context_set_base_dir()). 870 * 871 * When the auto-computed direction of a paragraph differs from the 872 * base direction of the context, the interpretation of 873 * %PANGO_ALIGN_LEFT and %PANGO_ALIGN_RIGHT are swapped. 874 * 875 * Params: 876 * autoDir = if %TRUE, compute the bidirectional base direction 877 * from the layout's contents. 878 * 879 * Since: 1.4 880 */ 881 public void setAutoDir(bool autoDir) 882 { 883 pango_layout_set_auto_dir(pangoLayout, autoDir); 884 } 885 886 /** 887 * Sets the type of ellipsization being performed for @layout. 888 * Depending on the ellipsization mode @ellipsize text is 889 * removed from the start, middle, or end of text so they 890 * fit within the width and height of layout set with 891 * pango_layout_set_width() and pango_layout_set_height(). 892 * 893 * If the layout contains characters such as newlines that 894 * force it to be layed out in multiple paragraphs, then whether 895 * each paragraph is ellipsized separately or the entire layout 896 * is ellipsized as a whole depends on the set height of the layout. 897 * See pango_layout_set_height() for details. 898 * 899 * Params: 900 * ellipsize = the new ellipsization mode for @layout 901 * 902 * Since: 1.6 903 */ 904 public void setEllipsize(PangoEllipsizeMode ellipsize) 905 { 906 pango_layout_set_ellipsize(pangoLayout, ellipsize); 907 } 908 909 /** 910 * Sets the default font description for the layout. If no font 911 * description is set on the layout, the font description from 912 * the layout's context is used. 913 * 914 * Params: 915 * desc = the new #PangoFontDescription, or %NULL to unset the 916 * current font description 917 */ 918 public void setFontDescription(PgFontDescription desc) 919 { 920 pango_layout_set_font_description(pangoLayout, (desc is null) ? null : desc.getPgFontDescriptionStruct()); 921 } 922 923 /** 924 * Sets the height to which the #PangoLayout should be ellipsized at. There 925 * are two different behaviors, based on whether @height is positive or 926 * negative. 927 * 928 * If @height is positive, it will be the maximum height of the layout. Only 929 * lines would be shown that would fit, and if there is any text omitted, 930 * an ellipsis added. At least one line is included in each paragraph regardless 931 * of how small the height value is. A value of zero will render exactly one 932 * line for the entire layout. 933 * 934 * If @height is negative, it will be the (negative of) maximum number of lines per 935 * paragraph. That is, the total number of lines shown may well be more than 936 * this value if the layout contains multiple paragraphs of text. 937 * The default value of -1 means that first line of each paragraph is ellipsized. 938 * This behvaior may be changed in the future to act per layout instead of per 939 * paragraph. File a bug against pango at <ulink 940 * url="http://bugzilla.gnome.org/">http://bugzilla.gnome.org/</ulink> if your 941 * code relies on this behavior. 942 * 943 * Height setting only has effect if a positive width is set on 944 * @layout and ellipsization mode of @layout is not %PANGO_ELLIPSIZE_NONE. 945 * The behavior is undefined if a height other than -1 is set and 946 * ellipsization mode is set to %PANGO_ELLIPSIZE_NONE, and may change in the 947 * future. 948 * 949 * Params: 950 * height = the desired height of the layout in Pango units if positive, 951 * or desired number of lines if negative. 952 * 953 * Since: 1.20 954 */ 955 public void setHeight(int height) 956 { 957 pango_layout_set_height(pangoLayout, height); 958 } 959 960 /** 961 * Sets the width in Pango units to indent each paragraph. A negative value 962 * of @indent will produce a hanging indentation. That is, the first line will 963 * have the full width, and subsequent lines will be indented by the 964 * absolute value of @indent. 965 * 966 * The indent setting is ignored if layout alignment is set to 967 * %PANGO_ALIGN_CENTER. 968 * 969 * Params: 970 * indent = the amount by which to indent. 971 */ 972 public void setIndent(int indent) 973 { 974 pango_layout_set_indent(pangoLayout, indent); 975 } 976 977 /** 978 * Sets whether each complete line should be stretched to 979 * fill the entire width of the layout. This stretching is typically 980 * done by adding whitespace, but for some scripts (such as Arabic), 981 * the justification may be done in more complex ways, like extending 982 * the characters. 983 * 984 * Note that this setting is not implemented and so is ignored in Pango 985 * older than 1.18. 986 * 987 * Params: 988 * justify = whether the lines in the layout should be justified. 989 */ 990 public void setJustify(bool justify) 991 { 992 pango_layout_set_justify(pangoLayout, justify); 993 } 994 995 /** 996 * Same as pango_layout_set_markup_with_accel(), but 997 * the markup text isn't scanned for accelerators. 998 * 999 * Params: 1000 * markup = marked-up text 1001 * length = length of marked-up text in bytes, or -1 if @markup is 1002 * null-terminated 1003 */ 1004 public void setMarkup(string markup, int length) 1005 { 1006 pango_layout_set_markup(pangoLayout, Str.toStringz(markup), length); 1007 } 1008 1009 /** 1010 * Sets the layout text and attribute list from marked-up text (see 1011 * <link linkend="PangoMarkupFormat">markup format</link>). Replaces 1012 * the current text and attribute list. 1013 * 1014 * If @accel_marker is nonzero, the given character will mark the 1015 * character following it as an accelerator. For example, @accel_marker 1016 * might be an ampersand or underscore. All characters marked 1017 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, 1018 * and the first character so marked will be returned in @accel_char. 1019 * Two @accel_marker characters following each other produce a single 1020 * literal @accel_marker character. 1021 * 1022 * Params: 1023 * markup = marked-up text 1024 * (see <link linkend="PangoMarkupFormat">markup format</link>) 1025 * length = length of marked-up text in bytes, or -1 if @markup is 1026 * null-terminated 1027 * accelMarker = marker for accelerators in the text 1028 * accelChar = return location 1029 * for first located accelerator, or %NULL 1030 */ 1031 public void setMarkupWithAccel(string markup, int length, dchar accelMarker, out dchar accelChar) 1032 { 1033 pango_layout_set_markup_with_accel(pangoLayout, Str.toStringz(markup), length, accelMarker, &accelChar); 1034 } 1035 1036 /** 1037 * If @setting is %TRUE, do not treat newlines and similar characters 1038 * as paragraph separators; instead, keep all text in a single paragraph, 1039 * and display a glyph for paragraph separator characters. Used when 1040 * you want to allow editing of newlines on a single text line. 1041 * 1042 * Params: 1043 * setting = new setting 1044 */ 1045 public void setSingleParagraphMode(bool setting) 1046 { 1047 pango_layout_set_single_paragraph_mode(pangoLayout, setting); 1048 } 1049 1050 /** 1051 * Sets the amount of spacing in Pango unit between the lines of the 1052 * layout. 1053 * 1054 * Params: 1055 * spacing = the amount of spacing 1056 */ 1057 public void setSpacing(int spacing) 1058 { 1059 pango_layout_set_spacing(pangoLayout, spacing); 1060 } 1061 1062 /** 1063 * Sets the tabs to use for @layout, overriding the default tabs 1064 * (by default, tabs are every 8 spaces). If @tabs is %NULL, the default 1065 * tabs are reinstated. @tabs is copied into the layout; you must 1066 * free your copy of @tabs yourself. 1067 * 1068 * Params: 1069 * tabs = a #PangoTabArray, or %NULL 1070 */ 1071 public void setTabs(PgTabArray tabs) 1072 { 1073 pango_layout_set_tabs(pangoLayout, (tabs is null) ? null : tabs.getPgTabArrayStruct()); 1074 } 1075 1076 /** 1077 * Sets the text of the layout. 1078 * 1079 * Note that if you have used 1080 * pango_layout_set_markup() or pango_layout_set_markup_with_accel() on 1081 * @layout before, you may want to call pango_layout_set_attributes() to clear 1082 * the attributes set on the layout from the markup as this function does not 1083 * clear attributes. 1084 * 1085 * Params: 1086 * text = a valid UTF-8 string 1087 * length = maximum length of @text, in bytes. -1 indicates that 1088 * the string is nul-terminated and the length should be 1089 * calculated. The text will also be truncated on 1090 * encountering a nul-termination even when @length is 1091 * positive. 1092 */ 1093 public void setText(string text) 1094 { 1095 pango_layout_set_text(pangoLayout, Str.toStringz(text), cast(int)text.length); 1096 } 1097 1098 /** 1099 * Sets the width to which the lines of the #PangoLayout should wrap or 1100 * ellipsized. The default value is -1: no width set. 1101 * 1102 * Params: 1103 * width = the desired width in Pango units, or -1 to indicate that no 1104 * wrapping or ellipsization should be performed. 1105 */ 1106 public void setWidth(int width) 1107 { 1108 pango_layout_set_width(pangoLayout, width); 1109 } 1110 1111 /** 1112 * Sets the wrap mode; the wrap mode only has effect if a width 1113 * is set on the layout with pango_layout_set_width(). 1114 * To turn off wrapping, set the width to -1. 1115 * 1116 * Params: 1117 * wrap = the wrap mode 1118 */ 1119 public void setWrap(PangoWrapMode wrap) 1120 { 1121 pango_layout_set_wrap(pangoLayout, wrap); 1122 } 1123 1124 /** 1125 * Converts from X and Y position within a layout to the byte 1126 * index to the character at that logical position. If the 1127 * Y position is not inside the layout, the closest position is chosen 1128 * (the position will be clamped inside the layout). If the 1129 * X position is not within the layout, then the start or the 1130 * end of the line is chosen as described for pango_layout_xy_to_index(). 1131 * If either the X or Y positions were not inside the layout, then the 1132 * function returns %FALSE; on an exact hit, it returns %TRUE. 1133 * 1134 * Params: 1135 * x = the X offset (in Pango units) 1136 * from the left edge of the layout. 1137 * y = the Y offset (in Pango units) 1138 * from the top edge of the layout 1139 * index = location to store calculated byte index 1140 * trailing = location to store a integer indicating where 1141 * in the grapheme the user clicked. It will either 1142 * be zero, or the number of characters in the 1143 * grapheme. 0 represents the trailing edge of the grapheme. 1144 * 1145 * Return: %TRUE if the coordinates were inside text, %FALSE otherwise. 1146 */ 1147 public bool xyToIndex(int x, int y, out int index, out int trailing) 1148 { 1149 return pango_layout_xy_to_index(pangoLayout, x, y, &index, &trailing) != 0; 1150 } 1151 }