summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-08-20 23:00:21 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-08-20 23:00:21 +0000
commiteb1c701a10dc70680326c1bf47d6ae5aea472c46 (patch)
tree09bcf3a10fc65cc8a274e138515b7106b5cda5eb /pango
parentd166f21c486ecda8c67d94ec0392f837c5f3eea9 (diff)
downloadpango-eb1c701a10dc70680326c1bf47d6ae5aea472c46.tar.gz
Add gravity in PangoFontDescription.
2006-08-20 Behdad Esfahbod <behdad@gnome.org> * docs/pango-sections.txt: * docs/tmpl/fonts.sgml: * pango/fonts.c (pango_font_description_set_gravity), (pango_font_description_get_gravity), (pango_font_description_merge_static), (pango_font_description_better_match), (pango_font_description_equal), (pango_font_description_hash), (find_field_any), (pango_font_description_from_string), (pango_font_description_to_string): * pango/pango-font.h: * pango/pango.def: Add gravity in PangoFontDescription.
Diffstat (limited to 'pango')
-rw-r--r--pango/fonts.c126
-rw-r--r--pango/pango-font.h6
-rw-r--r--pango/pango.def2
3 files changed, 108 insertions, 26 deletions
diff --git a/pango/fonts.c b/pango/fonts.c
index 88632feb..209509aa 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -39,6 +39,7 @@ struct _PangoFontDescription
PangoVariant variant;
PangoWeight weight;
PangoStretch stretch;
+ PangoGravity gravity;
guint16 mask;
guint static_family : 1;
@@ -68,6 +69,7 @@ static const PangoFontDescription pfd_defaults = {
PANGO_VARIANT_NORMAL, /* variant */
PANGO_WEIGHT_NORMAL, /* weight */
PANGO_STRETCH_NORMAL, /* stretch */
+ PANGO_GRAVITY_SOUTH, /* gravity */
0, /* mask */
0, /* static_family */
@@ -423,6 +425,58 @@ pango_font_description_get_size_is_absolute (const PangoFontDescription *desc)
}
/**
+ * pango_font_description_set_gravity:
+ * @desc: a #PangoFontDescription
+ * @gravity: the gravity for the font description.
+ *
+ * Sets the gravity field of a font description. The gravity field
+ * specifies how the glyphs should be rotated. If @gravity is
+ * %PANGO_GRAVITY_AUTO, this actually unsets the gravity mask on
+ * the font description.
+ *
+ * This function is seldom useful to the user. Gravity should normally
+ * be set on a #PangoContext.
+ *
+ * Since: 1.16
+ **/
+void
+pango_font_description_set_gravity (PangoFontDescription *desc,
+ PangoGravity gravity)
+{
+ g_return_if_fail (desc != NULL);
+
+ if (gravity == PANGO_GRAVITY_AUTO)
+ {
+ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY);
+ return;
+ }
+
+ desc->gravity = gravity;
+ desc->mask |= PANGO_FONT_MASK_GRAVITY;
+}
+
+/**
+ * pango_font_description_get_gravity:
+ * @desc: a #PangoFontDescription
+ *
+ * Gets the gravity field of a font description. See
+ * pango_font_description_set_gravity().
+ *
+ * Return value: the gravity field for the font description. Use
+ * pango_font_description_get_set_fields() to find out if
+ * the field was explicitely set or not.
+ *
+ * Since: 1.16
+ **/
+PangoGravity
+pango_font_description_get_gravity (const PangoFontDescription *desc)
+{
+ g_return_val_if_fail (desc != NULL, pfd_defaults.gravity);
+
+ return desc->gravity;
+}
+
+/**
* pango_font_description_get_set_fields:
* @desc: a #PangoFontDescription
*
@@ -534,6 +588,8 @@ pango_font_description_merge_static (PangoFontDescription *desc,
desc->size = desc_to_merge->size;
desc->size_is_absolute = desc_to_merge->size_is_absolute;
}
+ if (new_mask & PANGO_FONT_MASK_GRAVITY)
+ desc->gravity = desc_to_merge->gravity;
desc->mask |= new_mask;
}
@@ -579,7 +635,8 @@ pango_font_description_better_match (const PangoFontDescription *desc,
g_return_val_if_fail (new_match != NULL, G_MAXINT);
if (new_match->variant == desc->variant &&
- new_match->stretch == desc->stretch)
+ new_match->stretch == desc->stretch &&
+ new_match->gravity == desc->gravity)
{
int old_distance = old_match ? compute_distance (desc, old_match) : G_MAXINT;
int new_distance = compute_distance (desc, new_match);
@@ -667,6 +724,7 @@ pango_font_description_equal (const PangoFontDescription *desc1,
desc1->stretch == desc2->stretch &&
desc1->size == desc2->size &&
desc1->size_is_absolute == desc2->size_is_absolute &&
+ desc1->gravity == desc2->gravity &&
(desc1->family_name == desc2->family_name ||
(desc1->family_name && desc2->family_name && g_ascii_strcasecmp (desc1->family_name, desc2->family_name) == 0));
}
@@ -712,6 +770,7 @@ pango_font_description_hash (const PangoFontDescription *desc)
hash ^= desc->variant << 18;
hash ^= desc->weight << 16;
hash ^= desc->stretch << 26;
+ hash ^= desc->gravity << 28;
return hash;
}
@@ -795,6 +854,17 @@ static const FieldMap stretch_map[] = {
{ PANGO_STRETCH_ULTRA_EXPANDED, "Ultra-Expanded" }
};
+static const FieldMap gravity_map[] = {
+ { PANGO_GRAVITY_SOUTH, "South" },
+ { PANGO_GRAVITY_SOUTH, "Upright" },
+ { PANGO_GRAVITY_NORTH, "North" },
+ { PANGO_GRAVITY_SOUTH, "Upside-Down" },
+ { PANGO_GRAVITY_EAST, "East" },
+ { PANGO_GRAVITY_EAST, "Rotated-Left" },
+ { PANGO_GRAVITY_WEST, "West" },
+ { PANGO_GRAVITY_WEST, "Rotated-Right" }
+};
+
static gboolean
find_field (const FieldMap *map, int n_elements, const char *str, int len, int *val)
{
@@ -817,15 +887,30 @@ find_field (const FieldMap *map, int n_elements, const char *str, int len, int *
static gboolean
find_field_any (const char *str, int len, PangoFontDescription *desc)
{
- return (g_ascii_strcasecmp (str, "Normal") == 0 ||
- find_field (style_map, G_N_ELEMENTS (style_map), str, len,
- desc ? (int *)&desc->style : NULL) ||
- find_field (variant_map, G_N_ELEMENTS (variant_map), str, len,
- desc ? (int *)&desc->variant : NULL) ||
- find_field (weight_map, G_N_ELEMENTS (weight_map), str, len,
- desc ? (int *)&desc->weight : NULL) ||
- find_field (stretch_map, G_N_ELEMENTS (stretch_map), str, len,
- desc ? (int *)&desc->stretch : NULL));
+ gboolean found = FALSE;
+
+ if (g_ascii_strcasecmp (str, "Normal") == 0)
+ return TRUE;
+
+#define FIELD(NAME, MASK) \
+ G_STMT_START { \
+ if (find_field (NAME##_map, G_N_ELEMENTS (NAME##_map), str, len, \
+ desc ? (int *)&desc->NAME : NULL)) \
+ { \
+ found = TRUE; \
+ if (desc) \
+ desc->mask |= MASK; \
+ } \
+ } G_STMT_END
+
+ FIELD (variant, PANGO_FONT_MASK_VARIANT);
+ FIELD (weight, PANGO_FONT_MASK_WEIGHT);
+ FIELD (stretch, PANGO_FONT_MASK_STRETCH);
+ FIELD (gravity, PANGO_FONT_MASK_GRAVITY);
+
+#undef FIELD
+
+ return found;
}
static const char *
@@ -878,8 +963,8 @@ parse_size (const char *word,
* Creates a new font description from a string representation in the
* form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a
* comma separated list of families optionally terminated by a comma,
- * STYLE_OPTIONS is a whitespace separated list of words where each
- * WORD describes one of style, variant, weight, or stretch, and SIZE
+ * STYLE_OPTIONS is a whitespace separated list of words where each WORD
+ * describes one of style, variant, weight, stretch, or gravity, and SIZE
* is a decimal number (size in points) or optionally followed by the
* unit modifier "px" for absolute size. Any one of the options may
* be absent. If FAMILY-LIST is absent, then the family_name field of
@@ -899,24 +984,13 @@ pango_font_description_from_string (const char *str)
g_return_val_if_fail (str != NULL, NULL);
- desc = g_slice_new (PangoFontDescription);
+ desc = pango_font_description_new ();
desc->mask = PANGO_FONT_MASK_STYLE |
PANGO_FONT_MASK_WEIGHT |
PANGO_FONT_MASK_VARIANT |
PANGO_FONT_MASK_STRETCH;
- desc->family_name = NULL;
- desc->static_family = FALSE;
-
- desc->style = PANGO_STYLE_NORMAL;
- desc->weight = PANGO_WEIGHT_NORMAL;
- desc->variant = PANGO_VARIANT_NORMAL;
- desc->stretch = PANGO_STRETCH_NORMAL;
-
- desc->size = 0;
- desc->size_is_absolute = FALSE;
-
len = strlen (str);
last = str + len;
p = getword (str, last, &wordlen);
@@ -1031,7 +1105,7 @@ pango_font_description_to_string (const PangoFontDescription *desc)
desc->style == PANGO_STYLE_NORMAL &&
desc->stretch == PANGO_STRETCH_NORMAL &&
desc->variant == PANGO_VARIANT_NORMAL &&
- (desc->mask & PANGO_FONT_MASK_SIZE) == 0)))
+ (desc->mask & (PANGO_FONT_MASK_GRAVITY | PANGO_FONT_MASK_SIZE)) == 0)))
g_string_append_c (result, ',');
}
@@ -1039,6 +1113,8 @@ pango_font_description_to_string (const PangoFontDescription *desc)
append_field (result, style_map, G_N_ELEMENTS (style_map), desc->style);
append_field (result, stretch_map, G_N_ELEMENTS (stretch_map), desc->stretch);
append_field (result, variant_map, G_N_ELEMENTS (variant_map), desc->variant);
+ if (desc->mask & PANGO_FONT_MASK_GRAVITY)
+ append_field (result, gravity_map, G_N_ELEMENTS (gravity_map), desc->gravity);
if (result->len == 0)
g_string_append (result, "Normal");
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 5b30c4ca..c03f553b 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -79,7 +79,8 @@ typedef enum {
PANGO_FONT_MASK_VARIANT = 1 << 2,
PANGO_FONT_MASK_WEIGHT = 1 << 3,
PANGO_FONT_MASK_STRETCH = 1 << 4,
- PANGO_FONT_MASK_SIZE = 1 << 5
+ PANGO_FONT_MASK_SIZE = 1 << 5,
+ PANGO_FONT_MASK_GRAVITY = 1 << 6
} PangoFontMask;
/* CSS scale factors (1.2 factor between each size) */
@@ -131,6 +132,9 @@ gint pango_font_description_get_size (const PangoFontDe
void pango_font_description_set_absolute_size (PangoFontDescription *desc,
double size);
gboolean pango_font_description_get_size_is_absolute (const PangoFontDescription *desc);
+void pango_font_description_set_gravity (PangoFontDescription *desc,
+ PangoGravity gravity);
+PangoGravity pango_font_description_get_gravity (const PangoFontDescription *desc);
PangoFontMask pango_font_description_get_set_fields (const PangoFontDescription *desc);
void pango_font_description_unset_fields (PangoFontDescription *desc,
diff --git a/pango/pango.def b/pango/pango.def
index fed46d8b..0f3ebe65 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -97,6 +97,7 @@ EXPORTS
pango_font_description_free
pango_font_description_from_string
pango_font_description_get_family
+ pango_font_description_get_gravity
pango_font_description_get_set_fields
pango_font_description_get_size
pango_font_description_get_size_is_absolute
@@ -112,6 +113,7 @@ EXPORTS
pango_font_description_set_absolute_size
pango_font_description_set_family
pango_font_description_set_family_static
+ pango_font_description_set_gravity
pango_font_description_set_size
pango_font_description_set_stretch
pango_font_description_set_style