⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pango-layout.c

📁 linux
💻 C
📖 第 1 页 / 共 5 页
字号:
 * @markup: marked-up text * @length: length of marked-up text in bytes, or -1 if @markup is * nul-terminated * * Same as pango_layout_set_markup_with_accel(), but * the markup text isn't scanned for accelerators. * **/voidpango_layout_set_markup (PangoLayout *layout,			 const char  *markup,			 int          length){  pango_layout_set_markup_with_accel (layout, markup, length, 0, NULL);}/** * pango_layout_set_markup_with_accel: * @layout: a #PangoLayout * @markup: marked-up text * (see <link linkend="PangoMarkupFormat">markup format</link>) * @length: length of marked-up text in bytes, or -1 if @markup is * nul-terminated * @accel_marker: marker for accelerators in the text * @accel_char: return location for first located accelerator, or %NULL * * Sets the layout text and attribute list from marked-up text (see * <link linkend="PangoMarkupFormat">markup format</link>). Replaces * the current text and attribute list. * * If @accel_marker is nonzero, the given character will mark the * character following it as an accelerator. For example, @accel_marker * might be an ampersand or underscore. All characters marked * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, * and the first character so marked will be returned in @accel_char. * Two @accel_marker characters following each other produce a single * literal @accel_marker character. **/voidpango_layout_set_markup_with_accel (PangoLayout    *layout,				    const char     *markup,				    int             length,				    gunichar        accel_marker,				    gunichar       *accel_char){  PangoAttrList *list = NULL;  char *text = NULL;  GError *error;  g_return_if_fail (PANGO_IS_LAYOUT (layout));  g_return_if_fail (markup != NULL);  error = NULL;  if (!pango_parse_markup (markup, length,			   accel_marker,			   &list, &text,			   accel_char,			   &error))    {      g_warning ("pango_layout_set_markup_with_accel: %s", error->message);      g_error_free (error);      return;    }  pango_layout_set_text (layout, text, -1);  pango_layout_set_attributes (layout, list);  pango_attr_list_unref (list);  g_free (text);}/** * pango_layout_get_unknown_glyphs_count: * @layout: a #PangoLayout * * Counts the number unknown glyphs in @layout.  That is, zero if * glyphs for all characters in the layout text were found, or more * than zero otherwise. * * Return value: The number of unknown glyphs in @layout. * * Since: 1.16 */intpango_layout_get_unknown_glyphs_count (PangoLayout *layout){    PangoLayoutLine *line;    PangoLayoutRun *run;    GSList *lines_list;    GSList *runs_list;    int i, count = 0;    g_return_val_if_fail (PANGO_IS_LAYOUT (layout), 0);    pango_layout_check_lines (layout);    if (layout->unknown_glyphs_count >= 0)      return layout->unknown_glyphs_count;    lines_list = layout->lines;    while (lines_list)      {	line = lines_list->data;	runs_list = line->runs;	while (runs_list)	  {	    run = runs_list->data;	    for (i = 0; i < run->glyphs->num_glyphs; i++)	      {		if (run->glyphs->glyphs[i].glyph & PANGO_GLYPH_UNKNOWN_FLAG)		    count++;	      }	    runs_list = runs_list->next;	  }	lines_list = lines_list->next;      }    layout->unknown_glyphs_count = count;    return count;}/** * pango_layout_context_changed: * @layout: a #PangoLayout * * Forces recomputation of any state in the #PangoLayout that * might depend on the layout's context. This function should * be called if you make changes to the context subsequent * to creating the layout. **/voidpango_layout_context_changed (PangoLayout *layout){  pango_layout_clear_lines (layout);  layout->tab_width = -1;}/** * pango_layout_get_log_attrs: * @layout: a #PangoLayout * @attrs: location to store a pointer to an array of logical attributes *         This value must be freed with g_free(). * @n_attrs: location to store the number of the attributes in the *           array. (The stored value will be one more than the total number *           of characters in the layout, since there need to be attributes *           corresponding to both the position before the first character *           and the position after the last character.) * * Retrieves an array of logical attributes for each character in * the @layout. **/voidpango_layout_get_log_attrs (PangoLayout    *layout,			    PangoLogAttr  **attrs,			    gint           *n_attrs){  g_return_if_fail (layout != NULL);  pango_layout_check_lines (layout);  if (attrs)    {      *attrs = g_new (PangoLogAttr, layout->n_chars + 1);      memcpy (*attrs, layout->log_attrs, sizeof(PangoLogAttr) * (layout->n_chars + 1));    }  if (n_attrs)    *n_attrs = layout->n_chars + 1;}/** * pango_layout_get_line_count: * @layout: #PangoLayout * * Retrieves the count of lines for the @layout. * * Return value: the line count. **/intpango_layout_get_line_count (PangoLayout   *layout){  g_return_val_if_fail (layout != NULL, 0);  pango_layout_check_lines (layout);  return g_slist_length (layout->lines);}/** * pango_layout_get_lines: * @layout: a #PangoLayout * * Returns the lines of the @layout as a list. * * Use the faster pango_layout_get_lines_readonly() if you do not plan * to modify the contents of the lines (glyphs, glyph widths, etc.). * * Return value: a #GSList containing the lines in the layout. This * points to internal data of the #PangoLayout and must be used with * care. It will become invalid on any change to the layout's * text or properties. **/GSList *pango_layout_get_lines (PangoLayout *layout){  pango_layout_check_lines (layout);  if (layout->lines)    {      GSList *tmp_list = layout->lines;      while (tmp_list)	{	  PangoLayoutLine *line = tmp_list->data;	  tmp_list = tmp_list->next;	  pango_layout_line_leaked (line);	}    }  return layout->lines;}/** * pango_layout_get_lines_readonly: * @layout: a #PangoLayout * * Returns the lines of the @layout as a list. * * This is a faster alternative to pango_layout_get_lines(), * but the user is not expected * to modify the contents of the lines (glyphs, glyph widths, etc.). * * Return value: a #GSList containing the lines in the layout. This * points to internal data of the #PangoLayout and must be used with * care. It will become invalid on any change to the layout's * text or properties.  No changes should be made to the lines. * * Since: 1.16 **/GSList *pango_layout_get_lines_readonly (PangoLayout *layout){  pango_layout_check_lines (layout);  return layout->lines;}/** * pango_layout_get_line: * @layout: a #PangoLayout * @line: the index of a line, which must be between 0 and *        <literal>pango_layout_get_line_count(layout) - 1</literal>, inclusive. * * Retrieves a particular line from a #PangoLayout. * * Use the faster pango_layout_get_line_readonly() if you do not plan * to modify the contents of the line (glyphs, glyph widths, etc.). * * Return value: the requested #PangoLayoutLine, or %NULL if the *               index is out of range. This layout line can *               be ref'ed and retained, but will become invalid *               if changes are made to the #PangoLayout. **/PangoLayoutLine *pango_layout_get_line (PangoLayout *layout,		       int          line){  GSList *list_item;  g_return_val_if_fail (layout != NULL, NULL);  g_return_val_if_fail (line >= 0, NULL);  if (line < 0)    return NULL;  pango_layout_check_lines (layout);  list_item = g_slist_nth (layout->lines, line);  if (list_item)    {      PangoLayoutLine *line = list_item->data;      pango_layout_line_leaked (line);      return line;    }  return NULL;}/** * pango_layout_get_line_readonly: * @layout: a #PangoLayout * @line: the index of a line, which must be between 0 and *        <literal>pango_layout_get_line_count(layout) - 1</literal>, inclusive. * * Retrieves a particular line from a #PangoLayout. * * This is a faster alternative to pango_layout_get_line(), * but the user is not expected * to modify the contents of the line (glyphs, glyph widths, etc.). * * Return value: the requested #PangoLayoutLine, or %NULL if the *               index is out of range. This layout line can *               be ref'ed and retained, but will become invalid *               if changes are made to the #PangoLayout. *               No changes should be made to the line. * * Since: 1.16 **/PangoLayoutLine *pango_layout_get_line_readonly (PangoLayout *layout,				int          line){  GSList *list_item;  g_return_val_if_fail (layout != NULL, NULL);  g_return_val_if_fail (line >= 0, NULL);  if (line < 0)    return NULL;  pango_layout_check_lines (layout);  list_item = g_slist_nth (layout->lines, line);  if (list_item)    {      PangoLayoutLine *line = list_item->data;      return line;    }  return NULL;}/** * pango_layout_line_index_to_x: * @line:     a #PangoLayoutLine * @index_:   byte offset of a grapheme within the layout * @trailing: an integer indicating the edge of the grapheme to retrieve *            the position of. If > 0, the trailing edge of the grapheme, *            if 0, the leading of the grapheme. * @x_pos: location to store the x_offset (in #PangoGlyphUnit) * * Converts an index within a line to a X position. * **/voidpango_layout_line_index_to_x (PangoLayoutLine  *line,			      int               index,			      int               trailing,			      int              *x_pos){  PangoLayout *layout = line->layout;  GSList *run_list = line->runs;  int width = 0;  while (run_list)    {      PangoLayoutRun *run = run_list->data;      ItemProperties properties;      pango_layout_get_item_properties (run->item, &properties);      if (run->item->offset <= index && run->item->offset + run->item->length > index)	{	  int offset = g_utf8_pointer_to_offset (layout->text, layout->text + index);	  if (trailing)	    {	      while (index < line->start_index + line->length &&		     offset + 1 < layout->n_chars &&		     !layout->log_attrs[offset + 1].is_cursor_position)		{		  offset++;		  index = g_utf8_next_char (layout->text + index) - layout->text;		}	    }	  else	    {	      while (index > line->start_index &&		     !layout->log_attrs[offset].is_cursor_position)		{		  offset--;		  index = g_utf8_prev_char (layout->text + index) - layout->text;		}	    }	  pango_glyph_string_index_to_x (run->glyphs,					 layout->text + run->item->offset,					 run->item->length,					 &run->item->analysis,					 index - run->item->offset, trailing, x_pos);	  if (x_pos)	    *x_pos += width;	  return;	}      width += pango_glyph_string_get_width (run->glyphs);      run_list = run_list->next;    }  if (x_pos)    *x_pos = width;}static PangoLayoutLine *pango_layout_index_to_line (PangoLayout      *layout,			    int               index,			    int              *line_nr,			    PangoLayoutLine **line_before,			    PangoLayoutLine **line_after){  GSList *tmp_list;  GSList *line_list;  PangoLayoutLine *line = NULL;  PangoLayoutLine *prev_line = NULL;  int i = -1;  line_list = tmp_list = layout->lines;  while (tmp_list)    {      PangoLayoutLine *tmp_line = tmp_list->data;      if (tmp_line->start_index > index)	break; /* index was in paragraph delimiters */      prev_line = line;      line = tmp_line;      line_list = tmp_list;      i++;      if (line->start_index + line->length > index)	break;      tmp_list = tmp_list->next;    }  if (line_nr)    *line_nr = i;  if (line_before)    *line_before = prev_line;  if (line_after)    *line_after = (line_list && line_list->next) ? line_list->next->data : NULL;  return line;}static PangoLayoutLine *pango_layout_index_to_line_and_extents (PangoLayout     *layout,					int              index,					PangoRectangle  *line_rect){  PangoLayoutIter *iter;  PangoLayoutLine *line = NULL;  iter = pango_layout_get_iter (layout);  if (!ITER_IS_INVALID (iter))    while (TRUE)      {	PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (iter);	if (tmp_line->start_index > index)	    break; /* index was in paragraph delimiters */	line = tmp_line;	pango_layout_iter_get_line_extents (iter, NULL, line_rect);	if (line->start_index + line->length > index)	  break;	if (!pango_layout_iter_next_line (iter))	  break; /* Use end of last line */      }  pango_layout_iter_free (iter);  return line;}/** * pango_layout_index_to_line_x: * @layout:    a #PangoLayout * @index_:    the byte index of a grapheme within the layout. * @trailing:  an integer indicating the edge of the grapheme to retrieve the *             position of. If 0, the trailing edge of the grapheme, if > 0, *             the leading of the grapheme. * @line:      location to store resulting line index. (which will *             between 0 and pango_layout_get_line_count(layout) - 1) * @x_pos:     location to store resulting position within line *             (%PANGO_SCALE units per device unit) * * Converts from byte @index_ within the @layout to line and X position. * (X position is measured from the left edge of the line)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -