gdkfont.c 3.96 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20 21 22 23 24 25 26

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

Owen Taylor's avatar
Started  
Owen Taylor committed
27
#include "gdkfont.h"
28
#include "gdkinternals.h"
Elliot Lee's avatar
Elliot Lee committed
29

30 31
GdkFont*
gdk_font_ref (GdkFont *font)
Elliot Lee's avatar
Elliot Lee committed
32 33 34
{
  GdkFontPrivate *private;

35
  g_return_val_if_fail (font != NULL, NULL);
Elliot Lee's avatar
Elliot Lee committed
36 37

  private = (GdkFontPrivate*) font;
38 39
  private->ref_count += 1;
  return font;
Elliot Lee's avatar
Elliot Lee committed
40 41 42
}

void
43
gdk_font_unref (GdkFont *font)
Elliot Lee's avatar
Elliot Lee committed
44 45
{
  GdkFontPrivate *private;
46
  private = (GdkFontPrivate*) font;
Elliot Lee's avatar
Elliot Lee committed
47 48

  g_return_if_fail (font != NULL);
49
  g_return_if_fail (private->ref_count > 0);
Elliot Lee's avatar
Elliot Lee committed
50 51 52

  private->ref_count -= 1;
  if (private->ref_count == 0)
53
    _gdk_font_destroy (font);
Elliot Lee's avatar
Elliot Lee committed
54 55 56 57 58 59 60 61 62
}

gint
gdk_string_width (GdkFont     *font,
		  const gchar *string)
{
  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (string != NULL, -1);

63
  return gdk_text_width (font, string, _gdk_font_strlen (font, string));
Elliot Lee's avatar
Elliot Lee committed
64 65 66 67 68 69 70 71
}

gint
gdk_char_width (GdkFont *font,
		gchar    character)
{
  g_return_val_if_fail (font != NULL, -1);

72
  return gdk_text_width (font, &character, 1);
Elliot Lee's avatar
Elliot Lee committed
73 74
}

75 76 77 78 79 80
gint
gdk_char_width_wc (GdkFont *font,
		   GdkWChar character)
{
  g_return_val_if_fail (font != NULL, -1);

81
  return gdk_text_width_wc (font, &character, 1);
82 83
}

Elliot Lee's avatar
Elliot Lee committed
84 85 86 87 88 89 90
gint
gdk_string_measure (GdkFont     *font,
                    const gchar *string)
{
  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (string != NULL, -1);

91
  return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
Owen Taylor's avatar
Owen Taylor committed
92 93
}

94 95 96 97 98 99 100 101 102 103 104 105
void
gdk_string_extents (GdkFont     *font,
		    const gchar *string,
		    gint        *lbearing,
		    gint        *rbearing,
		    gint        *width,
		    gint        *ascent,
		    gint        *descent)
{
  g_return_if_fail (font != NULL);
  g_return_if_fail (string != NULL);

106
  gdk_text_extents (font, string, _gdk_font_strlen (font, string),
107 108 109 110
		    lbearing, rbearing, width, ascent, descent);
}


Elliot Lee's avatar
Elliot Lee committed
111 112 113 114 115
gint
gdk_text_measure (GdkFont     *font,
                  const gchar *text,
                  gint         text_length)
{
116
  gint rbearing;
Elliot Lee's avatar
Elliot Lee committed
117 118 119 120

  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (text != NULL, -1);

121 122
  gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
  return rbearing;
Elliot Lee's avatar
Elliot Lee committed
123 124 125 126 127 128 129 130 131
}
gint
gdk_char_measure (GdkFont *font,
                  gchar    character)
{
  g_return_val_if_fail (font != NULL, -1);

  return gdk_text_measure (font, &character, 1);
}
132 133 134 135 136 137 138 139

gint
gdk_string_height (GdkFont     *font,
		   const gchar *string)
{
  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (string != NULL, -1);

140
  return gdk_text_height (font, string, _gdk_font_strlen (font, string));
141 142 143 144 145 146 147
}

gint
gdk_text_height (GdkFont     *font,
		 const gchar *text,
		 gint         text_length)
{
148
  gint ascent, descent;
149 150 151 152

  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (text != NULL, -1);

153 154
  gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
  return ascent + descent;
155 156 157 158 159 160 161 162 163 164
}

gint
gdk_char_height (GdkFont *font,
		 gchar    character)
{
  g_return_val_if_fail (font != NULL, -1);

  return gdk_text_height (font, &character, 1);
}