diff options
-rw-r--r-- | pango/pango-attributes.c | 254 | ||||
-rw-r--r-- | pango/pango-attributes.h | 19 | ||||
-rw-r--r-- | pango/pango-layout.c | 65 | ||||
-rw-r--r-- | pango/pango-layout.h | 9 |
4 files changed, 347 insertions, 0 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index cb3d917d..1a4a9443 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -2496,3 +2496,257 @@ pango_attr_iterator_get_attrs (PangoAttrIterator *iterator) return attrs; } + + +/** + * pango_attribute_as_int: + * @attr: A `PangoAttribute` such as weight + * + * Returns the attribute cast to `PangoAttrInt`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrInt`, + * or %NULL if it's not an integer attribute + * + * Since: 1.50 + */ +PangoAttrInt * +pango_attribute_as_int (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_STYLE: + case PANGO_ATTR_WEIGHT: + case PANGO_ATTR_VARIANT: + case PANGO_ATTR_STRETCH: + case PANGO_ATTR_UNDERLINE: + case PANGO_ATTR_STRIKETHROUGH: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_GRAVITY: + case PANGO_ATTR_GRAVITY_HINT: + case PANGO_ATTR_FOREGROUND_ALPHA: + case PANGO_ATTR_BACKGROUND_ALPHA: + case PANGO_ATTR_ALLOW_BREAKS: + case PANGO_ATTR_SHOW: + case PANGO_ATTR_INSERT_HYPHENS: + case PANGO_ATTR_OVERLINE: + return (PangoAttrInt *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_float: + * @attr: A `PangoAttribute` such as scale + * + * Returns the attribute cast to `PangoAttrFloat`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrFloat`, + * or %NULL if it's not a floating point attribute + * + * Since: 1.50 + */ +PangoAttrFloat * +pango_attribute_as_float (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_SCALE: + return (PangoAttrFloat *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_string: + * @attr: A `PangoAttribute` such as family + * + * Returns the attribute cast to `PangoAttrString`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrString`, + * or %NULL if it's not a string attribute + */ +PangoAttrString * +pango_attribute_as_string (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_FAMILY: + return (PangoAttrString *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_size: + * @attr: A `PangoAttribute` representing a size + * + * Returns the attribute cast to `PangoAttrSize`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrSize`, + * or NULL if it's not a size attribute + * + * Since: 1.50 + */ +PangoAttrSize * +pango_attribute_as_size (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_SIZE: + case PANGO_ATTR_ABSOLUTE_SIZE: + return (PangoAttrSize *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_color: + * @attr: A `PangoAttribute` such as foreground + * + * Returns the attribute cast to `PangoAttrColor`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrColor`, + * or %NULL if it's not a color attribute + * + * Since: 1.50 + */ +PangoAttrColor * +pango_attribute_as_color (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_FOREGROUND: + case PANGO_ATTR_BACKGROUND: + case PANGO_ATTR_UNDERLINE_COLOR: + case PANGO_ATTR_STRIKETHROUGH_COLOR: + case PANGO_ATTR_OVERLINE_COLOR: + return (PangoAttrColor *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_font_desc: + * @attr: A `PangoAttribute` representing a font description + * + * Returns the attribute cast to `PangoAttrFontDesc`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrFontDesc`, + * or %NULL if it's not a font description attribute + * + * Since: 1.50 + */ +PangoAttrFontDesc * +pango_attribute_as_font_desc (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_FONT_DESC: + return (PangoAttrFontDesc *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_font_features: + * @attr: A `PangoAttribute` representing font features + * + * Returns the attribute cast to `PangoAttrFontFeatures`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrFontFeatures`, + * or %NULL if it's not a font features attribute + * + * Since: 1.50 + */ +PangoAttrFontFeatures * +pango_attribute_as_font_features (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_FONT_FEATURES: + return (PangoAttrFontFeatures *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_language: + * @attr: A `PangoAttribute` representing a language + * + * Returns the attribute cast to `PangoAttrLanguage`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrLanguage`, + * or %NULL if it's not a language attribute + * + * Since: 1.50 + */ +PangoAttrLanguage * +pango_attribute_as_language (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_LANGUAGE: + return (PangoAttrLanguage *)attr; + + default: + return NULL; + } +} + +/** + * pango_attribute_as_shape: + * @attr: A `PangoAttribute` representing a shape + * + * Returns the attribute cast to `PangoAttrShape`. + * + * This is mainly useful for language bindings. + * + * Returns: (nullable) (transfer none): The attribute as `PangoAttrShape`, + * or %NULL if it's not a shape attribute + * + * Since: 1.50 + */ +PangoAttrShape * +pango_attribute_as_shape (PangoAttribute *attr) +{ + switch (attr->klass->type) + { + case PANGO_ATTR_SHAPE: + return (PangoAttrShape *)attr; + + default: + return NULL; + } +} diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 3336eb53..6f18718e 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -699,6 +699,25 @@ gboolean pango_markup_parser_finish (GMarkupParseContext *context gunichar *accel_char, GError **error); +PANGO_AVAILABLE_IN_1_50 +PangoAttrString *pango_attribute_as_string (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrLanguage *pango_attribute_as_language (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrInt *pango_attribute_as_int (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrSize *pango_attribute_as_size (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrFloat *pango_attribute_as_float (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrColor *pango_attribute_as_color (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrFontDesc *pango_attribute_as_font_desc (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrShape *pango_attribute_as_shape (PangoAttribute *attr); +PANGO_AVAILABLE_IN_1_50 +PangoAttrFontFeatures *pango_attribute_as_font_features (PangoAttribute *attr); + G_END_DECLS #endif /* __PANGO_ATTRIBUTES_H__ */ diff --git a/pango/pango-layout.c b/pango/pango-layout.c index f5175552..8303be2c 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -4517,6 +4517,71 @@ G_DEFINE_BOXED_TYPE (PangoLayoutLine, pango_layout_line, pango_layout_line_unref); /** + * pango_layout_line_get_start_index: + * @line: a `PangoLayoutLine` + * + * Returns the start index of the line, as byte index + * into the text of the layout. + * + * Returns: the start index of the line + * + * Since: 1.50 + */ +int +pango_layout_line_get_start_index (PangoLayoutLine *line) +{ + return line->start_index; +} + +/** + * pango_layout_line_get_length: + * @line: a `PangoLayoutLine` + * + * Returns the length of the line, in bytes. + * + * Returns: the length of the line + * + * Since: 1.50 + */ +int +pango_layout_line_get_length (PangoLayoutLine *line) +{ + return line->length; +} + +/** + * pango_layout_line_is_paragraph_start: + * @line: a `PangoLayoutLine` + * + * Returns whether this is the first line of the paragraph. + * + * Returns: %TRUE if this is the first line + * + * Since: 1.50 + */ +gboolean +pango_layout_line_is_paragraph_start (PangoLayoutLine *line) +{ + return line->is_paragraph_start; +} + +/** + * pango_layout_line_get_resolved_direction: + * @line: a `PangoLayoutLine` + * + * Returns the resolved direction of the line. + * + * Returns: the resolved direction of the line + * + * Since: 1.50 + */ +PangoDirection +pango_layout_line_get_resolved_direction (PangoLayoutLine *line) +{ + return (PangoDirection) line->resolved_dir; +} + +/** * pango_layout_line_x_to_index: * @line: a `PangoLayoutLine` * @x_pos: the X offset (in Pango units) from the left edge of the line. diff --git a/pango/pango-layout.h b/pango/pango-layout.h index 7042ec44..34758ae3 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -347,6 +347,15 @@ PangoLayoutLine *pango_layout_line_ref (PangoLayoutLine *line); PANGO_AVAILABLE_IN_ALL void pango_layout_line_unref (PangoLayoutLine *line); +PANGO_AVAILABLE_IN_1_50 +int pango_layout_line_get_start_index (PangoLayoutLine *line); +PANGO_AVAILABLE_IN_1_50 +int pango_layout_line_get_length (PangoLayoutLine *line); +PANGO_AVAILABLE_IN_1_50 +gboolean pango_layout_line_is_paragraph_start (PangoLayoutLine *line); +PANGO_AVAILABLE_IN_1_50 +PangoDirection pango_layout_line_get_resolved_direction (PangoLayoutLine *line); + PANGO_AVAILABLE_IN_ALL gboolean pango_layout_line_x_to_index (PangoLayoutLine *line, int x_pos, |