2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c
blobafb705bf6e1835c85aac5a02b182d322504cd262
1 /* gnu_java_awt_GdkFont.c
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 #include "gdkfont.h"
39 #include "gnu_java_awt_peer_gtk_GdkClasspathFontPeer.h"
41 struct state_table *native_font_state_table;
44 rough sketch of the mapping between java and
45 pango text objects:
47 Font <-> - PangoFont
48 - PangoFontDescription
49 - PangoContext
51 GlyphVector <-> - GList of PangoGlyphItem
52 - PangoFontDescription
53 - PangoContext
55 FontRenderContext <-> stays in plain java
59 enum java_awt_font_style {
60 java_awt_font_PLAIN = 0,
61 java_awt_font_BOLD = 1,
62 java_awt_font_ITALIC = 2
65 enum java_awt_font_baseline {
66 java_awt_font_ROMAN_BASELINE = 0,
67 java_awt_font_CENTER_BASELINE = 1,
68 java_awt_font_HANGING_BASELINE = 2
71 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_initStaticState
72 (JNIEnv *env, jclass clazz)
74 NSA_FONT_INIT (env, clazz);
77 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_initState
78 (JNIEnv *env, jobject self)
80 struct peerfont *pfont = NULL;
82 gdk_threads_enter ();
83 g_assert (self != NULL);
84 pfont = (struct peerfont *) g_malloc0 (sizeof (struct peerfont));
85 g_assert (pfont != NULL);
86 NSA_SET_FONT_PTR (env, self, pfont);
87 gdk_threads_leave ();
91 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_dispose
92 (JNIEnv *env, jobject self)
94 struct peerfont *pfont = NULL;
96 gdk_threads_enter ();
97 pfont = (struct peerfont *)NSA_DEL_FONT_PTR (env, self);
98 g_assert (pfont != NULL);
99 if (pfont->ctx != NULL)
100 g_object_unref (pfont->ctx);
101 if (pfont->font != NULL)
102 g_object_unref (pfont->font);
103 if (pfont->desc != NULL)
104 pango_font_description_free (pfont->desc);
105 g_free (pfont);
106 gdk_threads_leave ();
109 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont
110 (JNIEnv *env, jobject self, jstring family_name_str, jint style_int, jint size)
112 struct peerfont *pfont = NULL;
113 PangoFontMap *map = NULL;
114 char const *family_name = NULL;
116 gdk_threads_enter ();
117 enum java_awt_font_style style = (enum java_awt_font_style) style_int;
119 g_assert (self != NULL);
120 pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self);
121 g_assert (pfont != NULL);
123 if (pfont->ctx != NULL)
124 g_object_unref (pfont->ctx);
125 if (pfont->font != NULL)
126 g_object_unref (pfont->font);
127 if (pfont->desc != NULL)
128 pango_font_description_free (pfont->desc);
130 pfont->desc = pango_font_description_new ();
131 g_assert (pfont->desc != NULL);
133 family_name = (*env)->GetStringUTFChars(env, family_name_str, 0);
134 g_assert (family_name != NULL);
135 pango_font_description_set_family (pfont->desc, family_name);
136 (*env)->ReleaseStringUTFChars(env, family_name_str, family_name);
138 pango_font_description_set_size (pfont->desc, size * PANGO_SCALE);
140 if (style & java_awt_font_BOLD)
141 pango_font_description_set_weight (pfont->desc, PANGO_WEIGHT_BOLD);
143 if (style & java_awt_font_ITALIC)
144 pango_font_description_set_style (pfont->desc, PANGO_STYLE_ITALIC);
147 FIXME: these are possibly wrong, and should in any case
148 probably be cached between calls.
151 map = pango_ft2_font_map_for_display ();
152 g_assert (map != NULL);
154 if (pfont->ctx == NULL)
155 pfont->ctx = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP (map));
156 g_assert (pfont->ctx != NULL);
158 if (pfont->font != NULL)
159 g_object_unref (pfont->font);
161 pfont->font = pango_font_map_load_font (map, pfont->ctx, pfont->desc);
162 g_assert (pfont->font != NULL);
164 gdk_threads_leave ();