Blame gdk/gdkfont.c

Packit 98cdb6
/* GDK - The GIMP Drawing Kit
Packit 98cdb6
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#undef GDK_DISABLE_DEPRECATED
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include "gdkdisplay.h"
Packit 98cdb6
#include "gdkfont.h"
Packit 98cdb6
#include "gdkinternals.h"
Packit 98cdb6
#include "gdkalias.h"
Packit 98cdb6
Packit 98cdb6
GType
Packit 98cdb6
gdk_font_get_type (void)
Packit 98cdb6
{
Packit 98cdb6
  static GType our_type = 0;
Packit 98cdb6
  
Packit 98cdb6
  if (our_type == 0)
Packit 98cdb6
    our_type = g_boxed_type_register_static (g_intern_static_string ("GdkFont"),
Packit 98cdb6
					     (GBoxedCopyFunc)gdk_font_ref,
Packit 98cdb6
					     (GBoxedFreeFunc)gdk_font_unref);
Packit 98cdb6
  return our_type;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_font_ref:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * 
Packit 98cdb6
 * Increases the reference count of a font by one.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: @font
Packit 98cdb6
 **/
Packit 98cdb6
GdkFont*
Packit 98cdb6
gdk_font_ref (GdkFont *font)
Packit 98cdb6
{
Packit 98cdb6
  GdkFontPrivate *private;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (font != NULL, NULL);
Packit 98cdb6
Packit 98cdb6
  private = (GdkFontPrivate*) font;
Packit 98cdb6
  private->ref_count += 1;
Packit 98cdb6
  return font;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_font_unref:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * 
Packit 98cdb6
 * Decreases the reference count of a font by one.
Packit 98cdb6
 * If the result is zero, destroys the font.
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gdk_font_unref (GdkFont *font)
Packit 98cdb6
{
Packit 98cdb6
  GdkFontPrivate *private;
Packit 98cdb6
  private = (GdkFontPrivate*) font;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (font != NULL);
Packit 98cdb6
  g_return_if_fail (private->ref_count > 0);
Packit 98cdb6
Packit 98cdb6
  private->ref_count -= 1;
Packit 98cdb6
  if (private->ref_count == 0)
Packit 98cdb6
    _gdk_font_destroy (font);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_string_width:
Packit 98cdb6
 * @font:  a #GdkFont
Packit 98cdb6
 * @string: the nul-terminated string to measure
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the width of a nul-terminated string.
Packit 98cdb6
 * (The distance from the origin of the string to the 
Packit 98cdb6
 * point where the next string in a sequence of strings
Packit 98cdb6
 * should be drawn)
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the width of the string in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_string_width (GdkFont     *font,
Packit 98cdb6
		  const gchar *string)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
  g_return_val_if_fail (string != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_width (font, string, _gdk_font_strlen (font, string));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_char_width:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @character: the character to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the width of a given character.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the width of the character in pixels.
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated: 2.2: Use gdk_text_extents() instead.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_char_width (GdkFont *font,
Packit 98cdb6
		gchar    character)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_width (font, &character, 1);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_char_width_wc:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @character: the character to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the width of a given wide character. (Encoded
Packit 98cdb6
 * in the wide-character encoding of the current locale).
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the width of the character in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_char_width_wc (GdkFont *font,
Packit 98cdb6
		   GdkWChar character)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_width_wc (font, &character, 1);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_string_measure:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @string: the nul-terminated string to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the distance from the origin to the rightmost
Packit 98cdb6
 * portion of a nul-terminated string when drawn. This is not the
Packit 98cdb6
 * correct value for determining the origin of the next
Packit 98cdb6
 * portion when drawing text in multiple pieces.
Packit 98cdb6
 * See gdk_string_width().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the right bearing of the string in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_string_measure (GdkFont     *font,
Packit 98cdb6
                    const gchar *string)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
  g_return_val_if_fail (string != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_string_extents:
Packit 98cdb6
 * @font: a #GdkFont.
Packit 98cdb6
 * @string: the nul-terminated string to measure.
Packit 98cdb6
 * @lbearing: the left bearing of the string.
Packit 98cdb6
 * @rbearing: the right bearing of the string.
Packit 98cdb6
 * @width: the width of the string.
Packit 98cdb6
 * @ascent: the ascent of the string.
Packit 98cdb6
 * @descent: the descent of the string.
Packit 98cdb6
 * 
Packit 98cdb6
 * Gets the metrics of a nul-terminated string.
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gdk_string_extents (GdkFont     *font,
Packit 98cdb6
		    const gchar *string,
Packit 98cdb6
		    gint        *lbearing,
Packit 98cdb6
		    gint        *rbearing,
Packit 98cdb6
		    gint        *width,
Packit 98cdb6
		    gint        *ascent,
Packit 98cdb6
		    gint        *descent)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (font != NULL);
Packit 98cdb6
  g_return_if_fail (string != NULL);
Packit 98cdb6
Packit 98cdb6
  gdk_text_extents (font, string, _gdk_font_strlen (font, string),
Packit 98cdb6
		    lbearing, rbearing, width, ascent, descent);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_text_measure:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @text: the text to measure.
Packit 98cdb6
 * @text_length: the length of the text in bytes.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the distance from the origin to the rightmost
Packit 98cdb6
 * portion of a string when drawn. This is not the
Packit 98cdb6
 * correct value for determining the origin of the next
Packit 98cdb6
 * portion when drawing text in multiple pieces. 
Packit 98cdb6
 * See gdk_text_width().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the right bearing of the string in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_text_measure (GdkFont     *font,
Packit 98cdb6
                  const gchar *text,
Packit 98cdb6
                  gint         text_length)
Packit 98cdb6
{
Packit 98cdb6
  gint rbearing;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
  g_return_val_if_fail (text != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
Packit 98cdb6
  return rbearing;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_char_measure:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @character: the character to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the distance from the origin to the rightmost
Packit 98cdb6
 * portion of a character when drawn. This is not the
Packit 98cdb6
 * correct value for determining the origin of the next
Packit 98cdb6
 * portion when drawing text in multiple pieces. 
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the right bearing of the character in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_char_measure (GdkFont *font,
Packit 98cdb6
                  gchar    character)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_measure (font, &character, 1);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_string_height:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @string: the nul-terminated string to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the total height of a given nul-terminated
Packit 98cdb6
 * string. This value is not generally useful, because you
Packit 98cdb6
 * cannot determine how this total height will be drawn in
Packit 98cdb6
 * relation to the baseline. See gdk_string_extents().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the height of the string in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_string_height (GdkFont     *font,
Packit 98cdb6
		   const gchar *string)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
  g_return_val_if_fail (string != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_height (font, string, _gdk_font_strlen (font, string));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_text_height:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @text: the text to measure.
Packit 98cdb6
 * @text_length: the length of the text in bytes.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the total height of a given string.
Packit 98cdb6
 * This value is not generally useful, because you cannot
Packit 98cdb6
 * determine how this total height will be drawn in
Packit 98cdb6
 * relation to the baseline. See gdk_text_extents().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the height of the string in pixels.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_text_height (GdkFont     *font,
Packit 98cdb6
		 const gchar *text,
Packit 98cdb6
		 gint         text_length)
Packit 98cdb6
{
Packit 98cdb6
  gint ascent, descent;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
  g_return_val_if_fail (text != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
Packit 98cdb6
  return ascent + descent;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_char_height:
Packit 98cdb6
 * @font: a #GdkFont
Packit 98cdb6
 * @character: the character to measure.
Packit 98cdb6
 * 
Packit 98cdb6
 * Determines the total height of a given character.
Packit 98cdb6
 * This value is not generally useful, because you cannot
Packit 98cdb6
 * determine how this total height will be drawn in
Packit 98cdb6
 * relation to the baseline. See gdk_text_extents().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the height of the character in pixels.
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated: 2.2: Use gdk_text_extents() instead.
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gdk_char_height (GdkFont *font,
Packit 98cdb6
		 gchar    character)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (font != NULL, -1);
Packit 98cdb6
Packit 98cdb6
  return gdk_text_height (font, &character, 1);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_font_from_description:
Packit 98cdb6
 * @font_desc: a #PangoFontDescription.
Packit 98cdb6
 * 
Packit 98cdb6
 * Load a #GdkFont based on a Pango font description. This font will
Packit 98cdb6
 * only be an approximation of the Pango font, and
Packit 98cdb6
 * internationalization will not be handled correctly. This function
Packit 98cdb6
 * should only be used for legacy code that cannot be easily converted
Packit 98cdb6
 * to use Pango. Using Pango directly will produce better results.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: the newly loaded font, or %NULL if the font
Packit 98cdb6
 * cannot be loaded.
Packit 98cdb6
 **/
Packit 98cdb6
GdkFont*
Packit 98cdb6
gdk_font_from_description (PangoFontDescription *font_desc)
Packit 98cdb6
{
Packit 98cdb6
  return gdk_font_from_description_for_display (gdk_display_get_default (),font_desc);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_font_load:
Packit 98cdb6
 * @font_name: a XLFD describing the font to load.
Packit 98cdb6
 * 
Packit 98cdb6
 * Loads a font.
Packit 98cdb6
 * 
Packit 98cdb6
 * The font may be newly loaded or looked up the font in a cache. 
Packit 98cdb6
 * You should make no assumptions about the initial reference count.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: a #GdkFont, or %NULL if the font could not be loaded.
Packit 98cdb6
 **/
Packit 98cdb6
GdkFont*
Packit 98cdb6
gdk_font_load (const gchar *font_name)
Packit 98cdb6
{  
Packit 98cdb6
   return gdk_font_load_for_display (gdk_display_get_default(), font_name);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GDK_FONT_C__
Packit 98cdb6
#include "gdkaliasdef.c"