Blame pango/pango-ot-ruleset.c

Packit 0ec9dd
/* Pango
Packit 0ec9dd
 * pango-ot-ruleset.c: Shaping using OpenType features
Packit 0ec9dd
 *
Packit 0ec9dd
 * Copyright (C) 2000 Red Hat Software
Packit 0ec9dd
 *
Packit 0ec9dd
 * This library is free software; you can redistribute it and/or
Packit 0ec9dd
 * modify it under the terms of the GNU Library General Public
Packit 0ec9dd
 * License as published by the Free Software Foundation; either
Packit 0ec9dd
 * version 2 of the License, or (at your option) any later version.
Packit 0ec9dd
 *
Packit 0ec9dd
 * This library is distributed in the hope that it will be useful,
Packit 0ec9dd
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0ec9dd
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit 0ec9dd
 * Library General Public License for more details.
Packit 0ec9dd
 *
Packit 0ec9dd
 * You should have received a copy of the GNU Library General Public
Packit 0ec9dd
 * License along with this library; if not, write to the
Packit 0ec9dd
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 0ec9dd
 * Boston, MA 02111-1307, USA.
Packit 0ec9dd
 */
Packit 0ec9dd
Packit 0ec9dd
#include "config.h"
Packit 0ec9dd
Packit 0ec9dd
#include "pango-ot-private.h"
Packit 0ec9dd
Packit 0ec9dd
static void pango_ot_ruleset_finalize   (GObject        *object);
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * PangoOTRuleset:
Packit 0ec9dd
 *
Packit 0ec9dd
 * The #PangoOTRuleset structure holds a
Packit 0ec9dd
 * set of features selected from the tables in an OpenType font.
Packit 0ec9dd
 * (A feature is an operation such as adjusting glyph positioning
Packit 0ec9dd
 * that should be applied to a text feature such as a certain
Packit 0ec9dd
 * type of accent.) A #PangoOTRuleset
Packit 0ec9dd
 * is created with pango_ot_ruleset_new(), features are added
Packit 0ec9dd
 * to it with pango_ot_ruleset_add_feature(), then it is
Packit 0ec9dd
 * applied to a #PangoGlyphString with pango_ot_ruleset_shape().
Packit 0ec9dd
 */
Packit 0ec9dd
G_DEFINE_TYPE (PangoOTRuleset, pango_ot_ruleset, G_TYPE_OBJECT);
Packit 0ec9dd
Packit 0ec9dd
static void
Packit 0ec9dd
pango_ot_ruleset_class_init (PangoOTRulesetClass *klass)
Packit 0ec9dd
{
Packit 0ec9dd
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Packit 0ec9dd
Packit 0ec9dd
  object_class->finalize = pango_ot_ruleset_finalize;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
static void
Packit 0ec9dd
pango_ot_ruleset_init (PangoOTRuleset *ruleset)
Packit 0ec9dd
{
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
static void
Packit 0ec9dd
pango_ot_ruleset_finalize (GObject *object)
Packit 0ec9dd
{
Packit 0ec9dd
  G_OBJECT_CLASS (pango_ot_ruleset_parent_class)->finalize (object);
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_get_for_description:
Packit 0ec9dd
 * @info: a #PangoOTInfo.
Packit 0ec9dd
 * @desc: a #PangoOTRulesetDescription.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Returns a ruleset for the given OpenType info and ruleset
Packit 0ec9dd
 * description.  Rulesets are created on demand using
Packit 0ec9dd
 * pango_ot_ruleset_new_from_description().
Packit 0ec9dd
 * The returned ruleset should not be modified or destroyed.
Packit 0ec9dd
 *
Packit 0ec9dd
 * The static feature map members of @desc should be alive as
Packit 0ec9dd
 * long as @info is.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the #PangoOTRuleset for @desc. This object will have
Packit 0ec9dd
 * the same lifetime as @info.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
const PangoOTRuleset *
Packit 0ec9dd
pango_ot_ruleset_get_for_description (PangoOTInfo                     *info,
Packit 0ec9dd
				      const PangoOTRulesetDescription *desc)
Packit 0ec9dd
{
Packit 0ec9dd
  static PangoOTRuleset *ruleset; /* MT-safe */
Packit 0ec9dd
Packit 0ec9dd
  if (g_once_init_enter (&ruleset))
Packit 0ec9dd
    g_once_init_leave (&ruleset, g_object_new (PANGO_TYPE_OT_RULESET, NULL));
Packit 0ec9dd
Packit 0ec9dd
  return ruleset;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_new:
Packit 0ec9dd
 * @info: a #PangoOTInfo.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Creates a new #PangoOTRuleset for the given OpenType info.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the newly allocated #PangoOTRuleset, which
Packit 0ec9dd
 *               should be freed with g_object_unref().
Packit 0ec9dd
 **/
Packit 0ec9dd
PangoOTRuleset *
Packit 0ec9dd
pango_ot_ruleset_new (PangoOTInfo *info)
Packit 0ec9dd
{
Packit 0ec9dd
  return g_object_new (PANGO_TYPE_OT_RULESET, NULL);
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_new_for:
Packit 0ec9dd
 * @info: a #PangoOTInfo.
Packit 0ec9dd
 * @script: a #PangoScript.
Packit 0ec9dd
 * @language: a #PangoLanguage.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Creates a new #PangoOTRuleset for the given OpenType info, script, and
Packit 0ec9dd
 * language.
Packit 0ec9dd
 *
Packit 0ec9dd
 * This function is part of a convenience scheme that highly simplifies
Packit 0ec9dd
 * using a #PangoOTRuleset to represent features for a specific pair of script
Packit 0ec9dd
 * and language.  So one can use this function passing in the script and
Packit 0ec9dd
 * language of interest, and later try to add features to the ruleset by just
Packit 0ec9dd
 * specifying the feature name or tag, without having to deal with finding
Packit 0ec9dd
 * script, language, or feature indices manually.
Packit 0ec9dd
 *
Packit 0ec9dd
 * In excess to what pango_ot_ruleset_new() does, this function will:
Packit 0ec9dd
 * <itemizedlist>
Packit 0ec9dd
 *   <listitem>
Packit 0ec9dd
 *   Find the #PangoOTTag script and language tags associated with
Packit 0ec9dd
 *   @script and @language using pango_ot_tag_from_script() and
Packit 0ec9dd
 *   pango_ot_tag_from_language(),
Packit 0ec9dd
 *   </listitem>
Packit 0ec9dd
 *   <listitem>
Packit 0ec9dd
 *   For each of table types %PANGO_OT_TABLE_GSUB and %PANGO_OT_TABLE_GPOS,
Packit 0ec9dd
 *   find the script index of the script tag found and the language
Packit 0ec9dd
 *   system index of the language tag found in that script system, using
Packit 0ec9dd
 *   pango_ot_info_find_script() and pango_ot_info_find_language(),
Packit 0ec9dd
 *   </listitem>
Packit 0ec9dd
 *   <listitem>
Packit 0ec9dd
 *   For found language-systems, if they have required feature
Packit 0ec9dd
 *   index, add that feature to the ruleset using
Packit 0ec9dd
 *   pango_ot_ruleset_add_feature(),
Packit 0ec9dd
 *   </listitem>
Packit 0ec9dd
 *   <listitem>
Packit 0ec9dd
 *   Remember found script and language indices for both table types,
Packit 0ec9dd
 *   and use them in future pango_ot_ruleset_maybe_add_feature() and
Packit 0ec9dd
 *   pango_ot_ruleset_maybe_add_features().
Packit 0ec9dd
 *   </listitem>
Packit 0ec9dd
 * </itemizedlist>
Packit 0ec9dd
 *
Packit 0ec9dd
 * Because of the way return values of pango_ot_info_find_script() and
Packit 0ec9dd
 * pango_ot_info_find_language() are ignored, this function automatically
Packit 0ec9dd
 * finds and uses the 'DFLT' script and the default language-system.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the newly allocated #PangoOTRuleset, which
Packit 0ec9dd
 *               should be freed with g_object_unref().
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
PangoOTRuleset *
Packit 0ec9dd
pango_ot_ruleset_new_for (PangoOTInfo       *info,
Packit 0ec9dd
			  PangoScript        script,
Packit 0ec9dd
			  PangoLanguage     *language)
Packit 0ec9dd
{
Packit 0ec9dd
  return g_object_new (PANGO_TYPE_OT_RULESET, NULL);
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_new_from_description:
Packit 0ec9dd
 * @info: a #PangoOTInfo.
Packit 0ec9dd
 * @desc: a #PangoOTRulesetDescription.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Creates a new #PangoOTRuleset for the given OpenType infor and
Packit 0ec9dd
 * matching the given ruleset description.
Packit 0ec9dd
 *
Packit 0ec9dd
 * This is a convenience function that calls pango_ot_ruleset_new_for() and
Packit 0ec9dd
 * adds the static GSUB/GPOS features to the resulting ruleset, followed by
Packit 0ec9dd
 * adding other features to both GSUB and GPOS.
Packit 0ec9dd
 *
Packit 0ec9dd
 * The static feature map members of @desc should be alive as
Packit 0ec9dd
 * long as @info is.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the newly allocated #PangoOTRuleset, which
Packit 0ec9dd
 *               should be freed with g_object_unref().
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
PangoOTRuleset *
Packit 0ec9dd
pango_ot_ruleset_new_from_description (PangoOTInfo                     *info,
Packit 0ec9dd
				       const PangoOTRulesetDescription *desc)
Packit 0ec9dd
{
Packit 0ec9dd
  return g_object_new (PANGO_TYPE_OT_RULESET, NULL);
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_add_feature:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @table_type: the table type to add a feature to.
Packit 0ec9dd
 * @feature_index: the index of the feature to add.
Packit 0ec9dd
 * @property_bit: the property bit to use for this feature. Used to identify
Packit 0ec9dd
 *                the glyphs that this feature should be applied to, or
Packit 0ec9dd
 *                %PANGO_OT_ALL_GLYPHS if it should be applied to all glyphs.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Adds a feature to the ruleset.
Packit 0ec9dd
 **/
Packit 0ec9dd
void
Packit 0ec9dd
pango_ot_ruleset_add_feature (PangoOTRuleset   *ruleset,
Packit 0ec9dd
			      PangoOTTableType  table_type,
Packit 0ec9dd
			      guint             feature_index,
Packit 0ec9dd
			      gulong            property_bit)
Packit 0ec9dd
{
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_maybe_add_feature:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @table_type: the table type to add a feature to.
Packit 0ec9dd
 * @feature_tag: the tag of the feature to add.
Packit 0ec9dd
 * @property_bit: the property bit to use for this feature. Used to identify
Packit 0ec9dd
 *                the glyphs that this feature should be applied to, or
Packit 0ec9dd
 *                %PANGO_OT_ALL_GLYPHS if it should be applied to all glyphs.
Packit 0ec9dd
 *
Packit 0ec9dd
 * This is a convenience function that first tries to find the feature
Packit 0ec9dd
 * using pango_ot_info_find_feature() and the ruleset script and language
Packit 0ec9dd
 * passed to pango_ot_ruleset_new_for(),
Packit 0ec9dd
 * and if the feature is found, adds it to the ruleset.
Packit 0ec9dd
 *
Packit 0ec9dd
 * If @ruleset was not created using pango_ot_ruleset_new_for(), this function
Packit 0ec9dd
 * does nothing.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: %TRUE if the feature was found and added to ruleset,
Packit 0ec9dd
 *               %FALSE otherwise.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
gboolean
Packit 0ec9dd
pango_ot_ruleset_maybe_add_feature (PangoOTRuleset          *ruleset,
Packit 0ec9dd
				    PangoOTTableType         table_type,
Packit 0ec9dd
				    PangoOTTag               feature_tag,
Packit 0ec9dd
				    gulong                   property_bit)
Packit 0ec9dd
{
Packit 0ec9dd
  return FALSE;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_maybe_add_features:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @table_type: the table type to add features to.
Packit 0ec9dd
 * @features: array of feature name and property bits to add.
Packit 0ec9dd
 * @n_features: number of feature records in @features array.
Packit 0ec9dd
 *
Packit 0ec9dd
 * This is a convenience function that 
Packit 0ec9dd
 * for each feature in the feature map array @features
Packit 0ec9dd
 * converts the feature name to a #PangoOTTag feature tag using PANGO_OT_TAG_MAKE()
Packit 0ec9dd
 * and calls pango_ot_ruleset_maybe_add_feature() on it.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: The number of features in @features that were found
Packit 0ec9dd
 *               and added to @ruleset.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
guint
Packit 0ec9dd
pango_ot_ruleset_maybe_add_features (PangoOTRuleset          *ruleset,
Packit 0ec9dd
				     PangoOTTableType         table_type,
Packit 0ec9dd
				     const PangoOTFeatureMap *features,
Packit 0ec9dd
				     guint                    n_features)
Packit 0ec9dd
{
Packit 0ec9dd
  return 0;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_get_feature_count:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @n_gsub_features: (out) (optional): location to store number of
Packit 0ec9dd
 *   GSUB features, or %NULL.
Packit 0ec9dd
 * @n_gpos_features: (out) (optional): location to store number of
Packit 0ec9dd
 *   GPOS features, or %NULL.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Gets the number of GSUB and GPOS features in the ruleset.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: Total number of features in the @ruleset.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
guint
Packit 0ec9dd
pango_ot_ruleset_get_feature_count (const PangoOTRuleset   *ruleset,
Packit 0ec9dd
				    guint                  *n_gsub_features,
Packit 0ec9dd
				    guint                  *n_gpos_features)
Packit 0ec9dd
{
Packit 0ec9dd
  return 0;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_substitute:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @buffer: a #PangoOTBuffer.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Performs the OpenType GSUB substitution on @buffer using the features
Packit 0ec9dd
 * in @ruleset
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.4
Packit 0ec9dd
 **/
Packit 0ec9dd
void
Packit 0ec9dd
pango_ot_ruleset_substitute  (const PangoOTRuleset *ruleset,
Packit 0ec9dd
			      PangoOTBuffer        *buffer)
Packit 0ec9dd
{
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_position:
Packit 0ec9dd
 * @ruleset: a #PangoOTRuleset.
Packit 0ec9dd
 * @buffer: a #PangoOTBuffer.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Performs the OpenType GPOS positioning on @buffer using the features
Packit 0ec9dd
 * in @ruleset
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.4
Packit 0ec9dd
 **/
Packit 0ec9dd
void
Packit 0ec9dd
pango_ot_ruleset_position (const PangoOTRuleset *ruleset,
Packit 0ec9dd
			   PangoOTBuffer        *buffer)
Packit 0ec9dd
{
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
Packit 0ec9dd
/* ruleset descriptions */
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_description_hash:
Packit 0ec9dd
 * @desc: a ruleset description
Packit 0ec9dd
 *
Packit 0ec9dd
 * Computes a hash of a #PangoOTRulesetDescription structure suitable
Packit 0ec9dd
 * to be used, for example, as an argument to g_hash_table_new().
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the hash value.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
guint
Packit 0ec9dd
pango_ot_ruleset_description_hash  (const PangoOTRulesetDescription *desc)
Packit 0ec9dd
{
Packit 0ec9dd
  return 0;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_description_equal:
Packit 0ec9dd
 * @desc1: a ruleset description
Packit 0ec9dd
 * @desc2: a ruleset description
Packit 0ec9dd
 *
Packit 0ec9dd
 * Compares two ruleset descriptions for equality.
Packit 0ec9dd
 * Two ruleset descriptions are considered equal if the rulesets
Packit 0ec9dd
 * they describe are provably identical.  This means that their
Packit 0ec9dd
 * script, language, and all feature sets should be equal.  For static feature
Packit 0ec9dd
 * sets, the array addresses are compared directly, while for other
Packit 0ec9dd
 * features, the list of features is compared one by one.
Packit 0ec9dd
 * (Two ruleset descriptions may result in identical rulesets
Packit 0ec9dd
 * being created, but still compare %FALSE.)
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: %TRUE if two ruleset descriptions are identical,
Packit 0ec9dd
 *               %FALSE otherwise.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
gboolean
Packit 0ec9dd
pango_ot_ruleset_description_equal (const PangoOTRulesetDescription *desc1,
Packit 0ec9dd
				    const PangoOTRulesetDescription *desc2)
Packit 0ec9dd
{
Packit 0ec9dd
  return TRUE;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_description_copy:
Packit 0ec9dd
 * @desc: ruleset description to copy
Packit 0ec9dd
 *
Packit 0ec9dd
 * Creates a copy of @desc, which should be freed with
Packit 0ec9dd
 * pango_ot_ruleset_description_free(). Primarily used internally
Packit 0ec9dd
 * by pango_ot_ruleset_get_for_description() to cache rulesets for
Packit 0ec9dd
 * ruleset descriptions.
Packit 0ec9dd
 *
Packit 0ec9dd
 * Return value: the newly allocated #PangoOTRulesetDescription, which
Packit 0ec9dd
 *               should be freed with pango_ot_ruleset_description_free().
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
PangoOTRulesetDescription *
Packit 0ec9dd
pango_ot_ruleset_description_copy  (const PangoOTRulesetDescription *desc)
Packit 0ec9dd
{
Packit 0ec9dd
  PangoOTRulesetDescription *copy;
Packit 0ec9dd
Packit 0ec9dd
  g_return_val_if_fail (desc != NULL, NULL);
Packit 0ec9dd
Packit 0ec9dd
  copy = g_slice_new (PangoOTRulesetDescription);
Packit 0ec9dd
Packit 0ec9dd
  *copy = *desc;
Packit 0ec9dd
Packit 0ec9dd
  return copy;
Packit 0ec9dd
}
Packit 0ec9dd
Packit 0ec9dd
/**
Packit 0ec9dd
 * pango_ot_ruleset_description_free:
Packit 0ec9dd
 * @desc: an allocated #PangoOTRulesetDescription
Packit 0ec9dd
 *
Packit 0ec9dd
 * Frees a ruleset description allocated by 
Packit 0ec9dd
 * pango_ot_ruleset_description_copy().
Packit 0ec9dd
 *
Packit 0ec9dd
 * Since: 1.18
Packit 0ec9dd
 **/
Packit 0ec9dd
void
Packit 0ec9dd
pango_ot_ruleset_description_free  (PangoOTRulesetDescription *desc)
Packit 0ec9dd
{
Packit 0ec9dd
  g_slice_free (PangoOTRulesetDescription, desc);
Packit 0ec9dd
}