[pangomm] Attribute: Add Overline and ShowFlags enums and some create*() methods



commit be3d949a796135daf7da1a95cb1233451201cfd0
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Jul 20 13:03:22 2020 +0200

    Attribute: Add Overline and ShowFlags enums and some create*() methods
    
    Fixes #9

 pango/src/attributes.ccg  | 30 +++++++++++++++++
 pango/src/attributes.hg   | 83 +++++++++++++++++++++++++++++++++++++++++++----
 tools/m4/convert_pango.m4 |  2 ++
 3 files changed, 109 insertions(+), 6 deletions(-)
---
diff --git a/pango/src/attributes.ccg b/pango/src/attributes.ccg
index ded3762..47c64c2 100644
--- a/pango/src/attributes.ccg
+++ b/pango/src/attributes.ccg
@@ -76,6 +76,11 @@ AttrType Attribute::register_type(const Glib::ustring& name)
   return (AttrType)pango_attr_type_register(name.c_str());
 }
 
+Glib::ustring Attribute::get_type_name(AttrType type)
+{
+  return Glib::convert_const_gchar_ptr_to_ustring(pango_attr_type_get_name((PangoAttrType)type));
+}
+
 AttrString Attribute::create_attr_family(const Glib::ustring& family)
 {
   return Glib::wrap((PangoAttrString*)pango_attr_family_new(family.c_str()));
@@ -151,6 +156,16 @@ AttrColor Attribute::create_attr_underline_color(guint16 red, guint16 green, gui
   return Glib::wrap((PangoAttrColor*)pango_attr_underline_color_new(red, green, blue));
 }
 
+AttrInt Attribute::create_attr_overline(Overline overline)
+{
+  return Glib::wrap((PangoAttrInt*)pango_attr_overline_new((PangoOverline)overline));
+}
+
+AttrColor Attribute::create_attr_overline_color(guint16 red, guint16 green, guint16 blue)
+{
+  return Glib::wrap((PangoAttrColor*)pango_attr_overline_color_new(red, green, blue));
+}
+
 AttrInt Attribute::create_attr_strikethrough(bool strikethrough)
 {
   return Glib::wrap((PangoAttrInt*)pango_attr_strikethrough_new(strikethrough));
@@ -201,6 +216,21 @@ AttrString Attribute::create_attr_font_features(const Glib::ustring& features)
   return Glib::wrap((PangoAttrString*)pango_attr_font_features_new(features.c_str()));
 }
 
+AttrInt Attribute::create_attr_allow_breaks(bool allow_breaks)
+{
+  return Glib::wrap((PangoAttrInt*)pango_attr_allow_breaks_new(allow_breaks));
+}
+
+AttrInt Attribute::create_attr_insert_hyphens(bool insert_hyphens)
+{
+  return Glib::wrap((PangoAttrInt*)pango_attr_insert_hyphens_new(insert_hyphens));
+}
+
+AttrInt Attribute::create_attr_show(ShowFlags show)
+{
+  return Glib::wrap((PangoAttrInt*)pango_attr_show_new((PangoShowFlags)show));
+}
+
 
 AttrString::AttrString()
 {}
diff --git a/pango/src/attributes.hg b/pango/src/attributes.hg
index c6769b3..4176a62 100644
--- a/pango/src/attributes.hg
+++ b/pango/src/attributes.hg
@@ -33,16 +33,15 @@ _CC_INCLUDE(pango/pango-enum-types.h)
 /** Pango::AttrType distinguishes between different types of attributes.
  * Along with the predefined values, it is possible to allocate additional values for
  * custom attributes using Pango::Attribute::register_type(). The predefined values
- * are given below.
+ * are given below. The type of structure used to store the
+ * attribute is listed in parentheses after the description.
  */
 _WRAP_ENUM(AttrType, PangoAttrType, s#^SCALE$#SCALE_FACTOR#, decl_prefix PANGOMM_API)
 // gcc complains that SCALE shadows the global constant SCALE from font.h.
 
-
-/** A Pango::Underline is used to specify whether text should be underlined, and if so, the type of 
underlining.
- */
 _WRAP_ENUM(Underline, PangoUnderline, decl_prefix PANGOMM_API)
-
+_WRAP_ENUM(Overline, PangoOverline, decl_prefix PANGOMM_API)
+_WRAP_ENUM(ShowFlags, PangoShowFlags, decl_prefix PANGOMM_API)
 
 /** A Pango::LogAttr stores information about the attributes of a single character.
  */
@@ -88,11 +87,27 @@ public:
   AttrType get_type() const;
 
   /** Allocate a new attribute type ID.
-   * @param name An identifier for the type (currently unused).
+   *
+   * The attribute type name can be accessed later by using get_type_name().
+   *
+   * @param name An identifier for the type.
    * @return The new type ID.
    */
   static AttrType register_type(const Glib::ustring& name);
 
+  /** Fetches the attribute type name passed in when registering the type using
+   * register_type().
+   *
+   * @newin{2,46}
+   *
+   * @param type An attribute type ID to fetch the name for.
+   * @return The type ID name (which may be an empty string), or an empty string
+   *         if @a type is a built-in Pango attribute type or invalid.
+   */
+  static Glib::ustring get_type_name(AttrType type);
+  // _WRAP_METHOD() can't be used here, because glibmm/tools/defs_gen/h2def.py
+  // assumes that pango_attr_type_get_name() is a method of a class named PangoAttrType.
+
   /** Gets the start index of the range.
    * @return The start index of the range.
    */
@@ -223,6 +238,29 @@ public:
    */
   static AttrColor create_attr_underline_color(guint16 red, guint16 green, guint16 blue);
 
+  /** Create a new overline-style object.
+   *
+   * @newin{2,46}
+   *
+   * @param overline The overline style.
+   * @return An attribute of type AttrInt.
+   */
+  static AttrInt create_attr_overline(Overline overline);
+
+  /** Create a new overline color attribute.
+   *
+   * This attribute modifies the color of overlines. If not set,
+   * overlines will use the foreground color.
+   *
+   * @newin{2,46}
+   *
+   * @param red The red value (ranging from 0 to 65535).
+   * @param green The green value (ranging from 0 to 65535).
+   * @param blue The blue value (ranging from 0 to 65535).
+   * @return An attribute of type AttrColor.
+   */
+  static AttrColor create_attr_overline_color(guint16 red, guint16 green, guint16 blue);
+
   /** Create a new font strike-through attribute.
    * @param strikethrough True indicates the text should be struck-through.
    * @return An attribute of type AttrInt.
@@ -314,6 +352,39 @@ public:
    */
   static AttrString create_attr_font_features(const Glib::ustring& features);
 
+  /** Create a new allow-breaks attribute.
+   *
+   * If breaks are disabled, the range will be kept in a
+   * single run, as far as possible.
+   *
+   * @newin{2,46}
+   *
+   * @param allow_breaks <tt>true</tt> if line breaks are allowed.
+   * @return An attribute of type AttrInt.
+   */
+  static AttrInt create_attr_allow_breaks(bool allow_breaks);
+
+  /** Create a new insert-hyphens attribute.
+   *
+   * Pangomm will insert hyphens when breaking lines in the middle
+   * of a word. This attribute can be used to suppress the hyphen.
+   *
+   * @newin{2,46}
+   *
+   * @param insert_hyphens <tt>true</tt> if hyphens should be inserted.
+   * @return An attribute of type AttrInt.
+   */
+  static AttrInt create_attr_insert_hyphens(bool insert_hyphens);
+
+  /** Create a new attribute that influences how invisible characters are rendered.
+   *
+   * @newin{2,46}
+   *
+   * @param flags Pango::ShowFlags to apply.
+   * @return An attribute of type AttrInt.
+   */
+  static AttrInt create_attr_show(ShowFlags show);
+
 protected:
   PangoAttribute* gobject_;
 };
diff --git a/tools/m4/convert_pango.m4 b/tools/m4/convert_pango.m4
index 8047b74..ddefc2f 100644
--- a/tools/m4/convert_pango.m4
+++ b/tools/m4/convert_pango.m4
@@ -2,6 +2,8 @@
 # Enums:
 _CONV_ENUM(Pango,AttrType)
 _CONV_ENUM(Pango,Underline)
+_CONV_ENUM(Pango,Overline)
+_CONV_ENUM(Pango,ShowFlags)
 _CONV_ENUM(Pango,Direction)
 _CONV_INCLASS_ENUM(Pango,Coverage,Level)
 _CONV_ENUM(Pango,Style)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]