pango_layout_set_text
89 static PangoLayout * 90 make_layout(PangoContext *context, 91 const char *text, 92 double size) 93 { 94 static PangoFontDescription *font_description; 95 PangoAlignment align; 96 PangoLayout *layout; 97 98 layout = pango_layout_new (context); 99 if (opt_markup) 100 pango_layout_set_markup (layout, text, -1); 101 else 102 pango_layout_set_text (layout, text, -1); <== 103 104 pango_layout_set_auto_dir (layout, opt_auto_dir); 105 pango_layout_set_ellipsize (layout, opt_ellipsize); 106 pango_layout_set_justify (layout, opt_justify); 107 pango_layout_set_single_paragraph_mode (layout, opt_single_par); 108 pango_layout_set_wrap (layout, opt_wrap); 109 110 font_description = pango_font_description_from_string (opt_font); 111 if (size > 0) 112 pango_font_description_set_size (font_description, size * PANGO_SCALE); 113 114 if (opt_width > 0) 115 pango_layout_set_width (layout, (opt_width * opt_dpi * PANGO_SCALE + 36) / 72); 116 117 if (opt_height > 0) 118 pango_layout_set_height (layout, (opt_height * opt_dpi * PANGO_SCALE + 36) / 72); 119 else 120 pango_layout_set_height (layout, opt_height); 121 122 if (opt_indent != 0) 123 pango_layout_set_indent (layout, (opt_indent * opt_dpi * PANGO_SCALE + 36) / 72); 124 125 align = opt_align; 126 if (align != PANGO_ALIGN_CENTER && 127 pango_context_get_base_dir (context) != PANGO_DIRECTION_LTR) { 128 /* pango reverses left and right if base dir ir rtl. so we should 129 * reverse to cancel that. unfortunately it also does that for 130 * rtl paragraphs, so we cannot really get left/right. all we get 131 * is default/other-side. */ 132 align = PANGO_ALIGN_LEFT + PANGO_ALIGN_RIGHT - align; 133 } 134 pango_layout_set_alignment (layout, align); 135 136 pango_layout_set_font_description (layout, font_description); 137 138 pango_font_description_free (font_description); 139 140 return layout; 141 }
length
maximum length of text , in bytes. -1 indicates that the string is nul-terminated and the length should be calculated. The text will also be truncated on encountering a nul-termination even when length is positive.
1082 pango_layout_set_text (PangoLayout *layout, 1083 const char *text, 1084 int length) 1085 { 1086 char *old_text, *start, *end; 1087 1088 g_return_if_fail (layout != NULL); 1089 g_return_if_fail (length == 0 || text != NULL); 1090 1091 old_text = layout->text; 1092 1093 if (length < 0) 1094 layout->text = g_strdup (text); 1095 else if (length > 0) 1096 /* This is not exactly what we want. We don't need the padding... 1097 */ 1098 layout->text = g_strndup (text, length); 1099 else 1100 layout->text = g_malloc0 (1); 1101 1102 layout->length = strlen (layout->text); 1103 1104 /* validate it, and replace invalid bytes with '?' 1105 */ 1106 start = layout->text; 1107 for (;;) { 1108 gboolean valid; 1109 1110 valid = g_utf8_validate (start, -1, (const char **)&end); 1111 1112 if (!*end) 1113 break; 1114 1115 /* Replace invalid bytes with -1. The -1 will be converted to 1116 * ((gunichar) -1) by glib, and that in turn yields a glyph value of 1117 * ((PangoGlyph) -1) by PANGO_GET_UNKNOWN_GLYPH(-1), 1118 * and that's PANGO_GLYPH_INVALID_INPUT. 1119 */ 1120 if (!valid) 1121 *end++ = -1; 1122 1123 start = end; 1124 } 1125 1126 if (start != layout->text) 1127 /* TODO: Write out the beginning excerpt of text? */ 1128 g_warning ("Invalid UTF-8 string passed to pango_layout_set_text()"); 1129 1130 layout->n_chars = pango_utf8_strlen (layout->text, -1); 1131 1132 layout_changed (layout); 1133 1134 g_free (old_text); 1135 }