/[classpath]/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c
ViewVC logotype

Diff of /classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by fitzsim, Thu Jul 14 22:07:02 2005 UTC revision 1.9 by smarothy, Thu Sep 29 13:41:50 2005 UTC
# Line 38  Line 38 
38    
39  #include <jni.h>  #include <jni.h>
40  #include <gtk/gtk.h>  #include <gtk/gtk.h>
41    #include <string.h>
42    #include <pango/pango.h>
43    #include <pango/pangoft2.h>
44    #include <pango/pangofc-font.h>
45    #include <freetype/ftglyph.h>
46    #include <freetype/ftoutln.h>
47  #include "native_state.h"  #include "native_state.h"
48  #include "gdkfont.h"  #include "gdkfont.h"
49  #include "gnu_java_awt_peer_gtk_GdkTextLayout.h"  #include "gnu_java_awt_peer_gtk_GdkTextLayout.h"
50    
51  struct state_table *cp_gtk_native_text_layout_state_table;  struct state_table *cp_gtk_native_text_layout_state_table;
52    
53    typedef struct gp
54    {
55      JNIEnv *env;
56      jobject obj;
57      double px;
58      double py;
59      double sx;
60      double sy;
61    } generalpath ;
62    
63  JNIEXPORT void JNICALL  JNIEXPORT void JNICALL
64  Java_gnu_java_awt_peer_gtk_GdkTextLayout_initStaticState  Java_gnu_java_awt_peer_gtk_GdkTextLayout_initStaticState
65    (JNIEnv *env, jclass clazz)    (JNIEnv *env, jclass clazz)
# Line 190  Java_gnu_java_awt_peer_gtk_GdkTextLayout Line 206  Java_gnu_java_awt_peer_gtk_GdkTextLayout
206    
207    gdk_threads_leave ();    gdk_threads_leave ();
208  }  }
209    
210    /* GetOutline code follows ****************************/
211    /********* Freetype callback functions *****************************/
212    
213    static int _moveTo( FT_Vector* to,
214                        generalpath *path)
215    {
216      JNIEnv *env;
217      jobject obj;
218      jclass cls;
219      jmethodID method;
220      jvalue values[2];
221    
222      env = path->env;
223      obj = path->obj;
224    
225      values[0].f = (jfloat)(to->x * path->sx + path->px);
226      values[1].f = (jfloat)(to->y * path->sy + path->py);
227    
228      cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
229      method = (*env)->GetMethodID (env, cls, "moveTo", "(FF)V");
230      (*env)->CallVoidMethodA(env, obj, method, values );
231    
232      return 0;
233    }
234    
235    static int _lineTo( FT_Vector*  to,
236                        generalpath *path)
237    {
238      JNIEnv *env;
239      jobject obj;
240      jclass cls;
241      jmethodID method;
242      jvalue values[2];
243    
244      env = path->env;
245      obj = path->obj;
246      values[0].f = (jfloat)(to->x * path->sx + path->px);
247      values[1].f = (jfloat)(to->y * path->sy + path->py);
248    
249      cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
250      method = (*env)->GetMethodID (env, cls, "lineTo", "(FF)V");
251      (*env)->CallVoidMethodA(env, obj, method, values );
252    
253      return 0;
254    }
255    
256    static int _quadTo( FT_Vector*  cp,
257                        FT_Vector*  to,
258                        generalpath *path)
259    {
260      JNIEnv *env;
261      jobject obj;
262      jclass cls;
263      jmethodID method;
264      jvalue values[4];
265    
266      env = path->env;
267      obj = path->obj;
268      values[0].f = (jfloat)(cp->x * path->sx + path->px);
269      values[1].f = (jfloat)(cp->y * path->sy + path->py);
270      values[2].f = (jfloat)(to->x * path->sx + path->px);
271      values[3].f = (jfloat)(to->y * path->sy + path->py);
272    
273      cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
274      method = (*env)->GetMethodID (env, cls, "quadTo", "(FFFF)V");
275      (*env)->CallVoidMethodA(env, obj, method, values );
276    
277      return 0;
278    }
279    
280    static int _curveTo( FT_Vector*  cp1,
281                         FT_Vector*  cp2,
282                         FT_Vector*  to,
283                         generalpath *path)
284    {
285      JNIEnv *env;
286      jobject obj;
287      jclass cls;
288      jmethodID method;
289      jvalue values[6];
290    
291      env = path->env;
292      obj = path->obj;
293      values[0].f = (jfloat)(cp1->x * path->sx + path->px);
294      values[1].f = (jfloat)(cp1->y * path->sy + path->py);
295      values[2].f = (jfloat)(cp2->x * path->sx + path->px);
296      values[3].f = (jfloat)(cp2->y * path->sy + path->py);
297      values[4].f = (jfloat)(to->x * path->sx + path->px);
298      values[5].f = (jfloat)(to->y * path->sy + path->py);
299    
300      cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
301      method = (*env)->GetMethodID (env, cls, "curveTo", "(FFFFFF)V");
302      (*env)->CallVoidMethodA(env, obj, method, values );
303    
304      return 0;
305    }
306    
307    
308    JNIEXPORT jobject JNICALL
309    Java_gnu_java_awt_peer_gtk_GdkTextLayout_getOutline
310     (JNIEnv *env, jobject obj, jobject transform)
311    {
312      struct textlayout *tl;
313      generalpath *path;
314      jobject gp;
315      GSList *current_run;
316      PangoLayoutLine *current_line;
317      FT_Outline_Funcs ftCallbacks =
318        {
319          _moveTo,
320          _lineTo,
321          _quadTo,
322          _curveTo
323        };
324      PangoLayoutIter* layoutIterator;
325    
326      gdk_threads_enter ();
327    
328      tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, obj);
329      g_assert(tl != NULL);
330      g_assert(tl->pango_layout != NULL);
331    
332      path = g_malloc0 (sizeof (generalpath));
333      g_assert(path != NULL);
334      path->env = env;
335    
336      /* Scaling factors */
337      path->sx = PANGO_SCALE/65536.0;
338      path->sy = -PANGO_SCALE/65536.0;            
339    
340      {  /* create a GeneralPath instance */
341        jclass cls;
342        jmethodID method;
343        
344        cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
345        method = (*env)->GetMethodID (env, cls, "<init>", "()V");
346        gp = path->obj = (*env)->NewObject (env, cls, method);
347      }
348    
349      layoutIterator = pango_layout_get_iter (tl->pango_layout);
350      g_assert (layoutIterator != NULL);
351    
352      if (pango_layout_iter_get_line (layoutIterator))
353        do
354          {
355            PangoRectangle line_logical_rect;
356            current_line = pango_layout_iter_get_line (layoutIterator);
357            pango_layout_iter_get_line_extents (layoutIterator,
358                                                NULL,
359                                                &line_logical_rect);
360          
361            path->px = line_logical_rect.x/(double)PANGO_SCALE;
362            path->py = line_logical_rect.y/(double)PANGO_SCALE;
363    
364            current_run = current_line->runs;
365            while (current_run)
366              {
367                FT_Face ft_face;
368                int index;
369                PangoGlyphItem *run = current_run->data;
370                PangoGlyphString *glyphs = run->glyphs;
371              
372                PangoAnalysis *analysis = &run->item->analysis;
373                g_assert (analysis != NULL);
374                g_assert (analysis->font != NULL);
375              
376                ft_face = pango_fc_font_lock_face ((PangoFcFont *)analysis->font);
377                g_assert (ft_face != NULL);
378    
379                for (index = 0; index < glyphs->num_glyphs; index++)
380                  {
381                    FT_Glyph glyph;
382                    FT_Error fterror;
383                    PangoGlyphGeometry pgg = glyphs->glyphs[index].geometry;
384                  
385                    fterror = FT_Load_Glyph(ft_face,
386                                            (FT_UInt)(glyphs->glyphs[index].glyph),
387                                            FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP);
388                    g_assert(fterror == 0);
389    
390                    FT_Get_Glyph (ft_face->glyph, &glyph);
391                    FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline),
392                                          &ftCallbacks, path);
393                    FT_Done_Glyph (glyph);
394    
395                    path->px += pgg.width/(double)PANGO_SCALE;
396                  }
397    
398                pango_fc_font_unlock_face ((PangoFcFont *)analysis->font);
399                current_run = current_run->next;
400              }
401          } while (pango_layout_iter_next_line (layoutIterator));
402    
403      g_free(path);
404      gdk_threads_leave ();
405    
406      if (transform != NULL)
407        {
408          jclass cls;
409          jmethodID method;
410    
411          cls = (*env)->FindClass (env, "java/awt/geom/GeneralPath");
412          method = (*env)->GetMethodID (env, cls, "transform",
413                                        "(Ljava/awt/geom/AffineTransform;)V");
414          (*env)->CallVoidMethod(env, gp, method, transform );
415        }
416    
417      return gp;
418    }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26