Author: tom
Date: Tue Dec 23 08:45:03 2008
New Revision: 3624

URL: http://svn.slimdevices.com?rev=3624&root=Jive&view=rev
Log:
pango:
- Textarea smooth scrolling, line by line scrolling
- Use new FreeSans fonts.
- Integrate LayoutContext work

Modified:
    7.4/branches/pango/squeezeplay/src/Makefile.osx
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h
    7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_font.c
    7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
    7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c

Modified: 7.4/branches/pango/squeezeplay/src/Makefile.osx
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/Makefile.osx?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/Makefile.osx (original)
+++ 7.4/branches/pango/squeezeplay/src/Makefile.osx Tue Dec 23 08:45:03 2008
@@ -49,7 +49,7 @@
 export PREFIX=${BUILD_TOP}
 
 export CFLAGS=  -I${PREFIX}/include -I${PREFIX}/include/SDL 
-I${PREFIX}/include/pango-1.0 \
-  -I${PREFIX}/include -I${PREFIX}/include/glib-2.0 
-I${PREFIX}/lib/glib-2.0/include -I${PREFIX}/include/cairo -g
+  -I${PREFIX}/include -I${PREFIX}/include/glib-2.0  
-I${PREFIX}/include/freetype2 -I${PREFIX}/lib/glib-2.0/include 
-I${PREFIX}/include/cairo -g
 export LDFLAGS=-L${PREFIX}/lib -L/usr/lib
 
 export TOOLPATH = $(shell dirname `which gcc`)
@@ -189,7 +189,9 @@
 
 fontconfig: generated/${FONTCONFIG_DIR}/configure 
generated/${FONTCONFIG_DIR}/Makefile
        -mkdir -p /tmp/splocal/fonts/
-       cp freefont-20060126/Free*ttf /tmp/splocal/fonts/
+       cp freefont-20080912/Free*ttf /tmp/splocal/fonts/
+       #cp DroidFonts/*Fallback*ttf /tmp/splocal/fonts/
+       #cp DroidFonts/*ttf /tmp/splocal/fonts/
        cd generated/${FONTCONFIG_DIR}; make && make install
        
 # pixman 
@@ -352,8 +354,8 @@
 # freefont
 freefont:
        mkdir -p ${PREFIX}/share/jive/fonts
-       cp freefont-20060126/FreeSans.ttf ${PREFIX}/share/jive/fonts
-       cp freefont-20060126/FreeSansBold.ttf ${PREFIX}/share/jive/fonts
+       cp freefont-20080912/FreeSans.ttf ${PREFIX}/share/jive/fonts
+       cp freefont-20080912/FreeSansBold.ttf ${PREFIX}/share/jive/fonts
 # fonts for clock screensaver
        cp fonts-clock/Digital.ttf ${PREFIX}/share/jive/fonts
        cp fonts-clock/DigitalItalic.ttf ${PREFIX}/share/jive/fonts

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua 
Tue Dec 23 08:45:03 2008
@@ -190,7 +190,8 @@
 
        if type == EVENT_SCROLL then
 
-               self:scrollBy(event:getScroll())
+               self:scrollLines(event:getScroll())
+               self:reDraw()
                return EVENT_CONSUME 
 
        elseif type == EVENT_MOUSE_DOWN then
@@ -227,11 +228,14 @@
                local keycode = event:getKeycode()
 
                if keycode == KEY_UP then
-                       self:scrollBy( -(self.visibleLines - 1) )
+                   
+                       self:scrollLines( -1 )
+                       self:reDraw()
                        return EVENT_CONSUME
 
                elseif keycode == KEY_DOWN then
-                       self:scrollBy( self.visibleLines - 1 )
+                       self:scrollLines( 1 )
+                       self:reDraw()
                        return EVENT_CONSUME
                        
                elseif keycode == KEY_PAGE_UP then 

Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h Tue Dec 23 
08:45:03 2008
@@ -11,6 +11,7 @@
 #include "common.h"
 
 #include <pango/pango.h>
+#include <pango/pangoft2.h>
 #include <SDL_image.h>
 #include <SDL_ttf.h>
 #include <SDL_gfxPrimitives.h>
@@ -252,11 +253,6 @@
        struct jive_font *next;
 
        const char *magic;
-};
-
-struct jive_pango_context {
-    PangoContext *context;
-    PangoFontMap *font_map;
 };
 
 struct jive_perfwarn {
@@ -379,7 +375,8 @@
 int jive_font_ascend(JiveFont *font);
 int jive_font_offset(JiveFont *font);
 JiveSurface *jive_font_draw_text(JiveFont *font, Uint32 color, const char 
*str);
-JiveSurface *jive_font_draw_text_wrap(JiveFont *font, Uint32 color, const char 
*str, Uint16 surface_width);
+JiveSurface *jive_font_draw_text_wrap(JiveFont *font, Uint32 color, const char 
*str, Uint16 surface_width, SDLPango_Layout_Context *layoutcontext);
+void jive_font_parse_text_wrap(JiveFont *font, Uint32 color, const char *str, 
Uint16 surface_width, SDLPango_Layout_Context *layoutcontext);
 JiveSurface *jive_font_ndraw_text(JiveFont *font, Uint32 color, const char 
*str, size_t len);
 
 
@@ -475,6 +472,7 @@
 int jiveL_textarea_layout(lua_State *L);
 int jiveL_textarea_draw(lua_State *L);
 int jiveL_textarea_scroll(lua_State *L);
+int jiveL_textarea_scroll_lines(lua_State *L);
 int jiveL_textarea_gc(lua_State *L);
 
 int jiveL_window_skin(lua_State *L);

Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_font.c
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_font.c?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_font.c (original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_font.c Tue Dec 
23 08:45:03 2008
@@ -249,27 +249,27 @@
        return srf;
 }
 JiveSurface *jive_font_draw_text(JiveFont *font, Uint32 color, const char *str 
) {
-    return jive_font_draw_text_wrap(font, color, str, -1 );
-}
-
-/**
- * if wrapping_width == 0, no wrapping will be done
- */
-JiveSurface *jive_font_draw_text_wrap(JiveFont *font, Uint32 color, const char 
*str, Uint16 wrapping_width ) {
-       JiveSurface *jive_surface;
-       PangoAttrList *attr_list;
+    return jive_font_draw_text_wrap(font, color, str, -1, NULL);
+}
+
+void jive_font_parse_text_wrap(JiveFont *font, Uint32 color, const char *str, 
Uint16 wrapping_width, SDLPango_Layout_Context *layoutcontext) {
+    PangoAttrList *attr_list;
        PangoAttribute *size, *fgcolor, *family, *weight;
        //PangoAttribute *letter_spacing;
     GError *err = NULL;
     char *text = NULL;
     PangoLayout *layout;
-    
-       assert(font && font->magic == JIVE_FONT_MAGIC);
-
-    layout = SDLPango_GetPangoLayout(pangocontext);
+       assert(font);
+
+    if (layoutcontext == NULL) {
+        //todo:this might go away, still here for labels;
+        layout = SDLPango_GetPangoLayout(pangocontext);
+    } else {
+        layout = layoutcontext->layout; 
+    }
 
     if ( !pango_parse_markup(str, -1, 0, &attr_list, &text, NULL, &err)) {
-        fprintf(stderr, "pango_parse_markup error: %s\n", err->message);
+        fprintf(stderr, "pango_parse_markup error on text (%s): %s\n", str, 
err->message);
         g_error_free(err); 
        
        //Fall back to using non-marked up set_text which is more forgiving and 
will replace illegal chars with '?' 
@@ -321,10 +321,22 @@
         pango_layout_set_width(layout, (guint) wrapping_width * PANGO_SCALE);
     }
     pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
-    //pango_layout_set_height (SDLPango_GetPangoLayout(pangocontext), 300* 
PANGO_SCALE);
+    //pango_layout_set_height (layout, 300* PANGO_SCALE);
     
-       jive_surface = jive_surface_new_SDLSurface(str ? 
SDLPango_CreateSurfaceDraw (pangocontext) : NULL);
-
+
+}
+
+/**
+ * if wrapping_width == 0, no wrapping will be done
+ */
+JiveSurface *jive_font_draw_text_wrap(JiveFont *font, Uint32 color, const char 
*str, Uint16 wrapping_width, SDLPango_Layout_Context *layoutcontext ) {
+       JiveSurface *jive_surface;
+
+    jive_font_parse_text_wrap(font, color, str, wrapping_width, layoutcontext);
+    
+       jive_surface = jive_surface_new_SDLSurface(str ? 
SDLPango_CreateSurfaceDrawWithLayout(pangocontext, layoutcontext) : NULL);
+
+    //todo: free SDLPango_Layout_Context
        return jive_surface;
 
 }

Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Tue 
Dec 23 08:45:03 2008
@@ -26,7 +26,6 @@
 struct jive_perfwarn perfwarn = { 0, 0, 0, 0, 0, 0 };
 
 SDLPango_Context *pangocontext;
-JivePangoContext *jive_pango_context;
 
 /* Frame rate calculations */
 //static Uint32 framedue = 0;
@@ -152,15 +151,7 @@
                exit(-1);
        }
 
-//future
-//    jive_pango_context = malloc(sizeof(JivePangoContext));
-//    jive_pango_context->font_map = pango_ft2_font_map_new ();
-//    pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP 
(context->font_map), 75.0, 75.0);
-//
-//    context->context = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP 
(context->font_map));
     
-    
-    //will likely be replaced
        pangocontext = jive_create_sdl_pango_context();
     
     
@@ -1293,6 +1284,7 @@
        { "_layout", jiveL_textarea_layout },
        { "draw", jiveL_textarea_draw },
        { "scroll", jiveL_textarea_scroll },
+       { "scrollLines", jiveL_textarea_scroll_lines },
        { NULL, NULL }
 };
 

Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c?rev=3624&root=Jive&r1=3623&r2=3624&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c Tue 
Dec 23 08:45:03 2008
@@ -29,7 +29,7 @@
 
     JiveSurface *text_surface; //todo:free me
     int text_surface_y;
-       
+    SDLPango_Layout_Context *layoutcontext; //todo:free me     
 } TextareaWidget;
 
 
@@ -111,7 +111,6 @@
        }
 
        w = peer->w.bounds.w + peer->w.padding.left + peer->w.padding.right;
-    fprintf(stderr, "peer->w.bounds.h: %d\n", peer->w.bounds.h);
     //how to get the h value - want full space but bounds not yet set
 //     h = peer->w.bounds.h;
        h = (peer->num_lines * peer->line_height) + peer->w.padding.top + 
peer->w.padding.bottom;
@@ -154,11 +153,16 @@
     peer->is_prepared = true;
        
        
+       
        /* free existing text surfaces - this seems odd, shoudl regular gc 
associated with the window 
        be the place to deal with this rather than here in prepare*/
        //jive_textarea_gc_lines(peer); - remember to free sdlpango context, 
etc, but why here in prepare
 
     
+    peer->layoutcontext = malloc(sizeof(SDLPango_Layout_Context));
+    peer->layoutcontext->tmp_ftbitmap = NULL;
+    peer->layoutcontext->layout = SDLPango_CreatePangoLayout(pangocontext);
+    
     lua_getglobal(L, "tostring");
        lua_getfield(L, 1, "text");
        lua_call(L, 1, 1);
@@ -166,7 +170,7 @@
        str = (char *) lua_tostring(L, -1);
 
     width = peer->w.bounds.w - peer->w.padding.left - peer->w.padding.right;
-    peer->text_surface = jive_font_draw_text_wrap(peer->font, peer->fg, str, 
width);
+    peer->text_surface = jive_font_draw_text_wrap(peer->font, peer->fg, str, 
width, peer->layoutcontext);
        peer->text_surface_y = 0;
        
        //todo: apply shadow surface - blit to text_surface?
@@ -333,6 +337,25 @@
        return 0;
 }
 
+static void jive_textarea_scroll(TextareaWidget *peer, int scroll_amount) {
+    Uint16 bottom;
+    Uint16 srf_w, srf_h;
+       
+    peer->text_surface_y += scroll_amount;
+    
+    if (peer->text_surface_y < 0) {
+        peer->text_surface_y = 0;
+    }
+    
+    //todo: factor in padding?
+    jive_surface_get_size(peer->text_surface, &srf_w, &srf_h);
+    bottom = srf_h - peer->w.bounds.h;
+    if (peer->text_surface_y > bottom) {
+        peer->text_surface_y = bottom;
+    }
+}
+
+
 int jiveL_textarea_scroll(lua_State *L) {
        /* stack is:
         * 1: widget
@@ -340,27 +363,68 @@
         */
        TextareaWidget *peer;
     int scroll_amount;
-    Uint16 bottom;
-    Uint16 srf_w, srf_h;
     
     peer = jive_getpeer(L, 1, &textareaPeerMeta);
        scroll_amount = tolua_tointeger(L, 2, 0);
-       
-    peer->text_surface_y += scroll_amount;
-    
-    if (peer->text_surface_y < 0) {
-        peer->text_surface_y = 0;
+
+    jive_textarea_scroll(peer,  scroll_amount);
+    
+    return 0;
+}
+
+int jiveL_textarea_scroll_lines(lua_State *L) {
+       /* stack is:
+        * 1: widget
+        * 2: scroll_lines
+        */
+       TextareaWidget *peer;
+    int scroll_lines;
+    int byte_index, trailing, line, x_pos;
+    int new_line_index, scroll_amount;
+    
+    peer = jive_getpeer(L, 1, &textareaPeerMeta);
+       scroll_lines = tolua_tointeger(L, 2, 0);
+       
+       //todo: currently calculates scroll amount based on top lines' height, 
should be based on bottom lines' height when scrolling down
+       
+       pango_layout_xy_to_index(peer->layoutcontext->layout,
+                                                         0,
+                                                         peer->text_surface_y 
* PANGO_SCALE,
+                                                         &byte_index,
+                                                         &trailing);
+       pango_layout_index_to_line_x(peer->layoutcontext->layout,
+                                                         byte_index,
+                                                         trailing,
+                                                         &line,
+                                                         &x_pos);
+       
+       new_line_index = line + scroll_lines;
+       if (new_line_index <= 0) {
+           scroll_amount = -1 * peer->text_surface_y;
+    } else {
+        PangoLayoutLine*    line;
+        PangoRectangle pos;
+        int new_byte_index;
+        
+        int line_count = 
pango_layout_get_line_count(peer->layoutcontext->layout);
+        if (new_line_index > line_count - 1) {
+            new_line_index = line_count;        
+        }
+        line = pango_layout_get_line(peer->layoutcontext->layout, 
new_line_index);
+        
+        pango_layout_line_x_to_index(line, 0, &new_byte_index, &trailing);
+                                                         
+        
pango_layout_index_to_pos(peer->layoutcontext->layout,new_byte_index,&pos); 
+        
+        
+        scroll_amount = PANGO_PIXELS(pos.y) - peer->text_surface_y;
     }
-    
-    //todo: factor in padding?
-    jive_surface_get_size(peer->text_surface, &srf_w, &srf_h);
-    bottom = srf_h - peer->w.bounds.h;
-    if (peer->text_surface_y > bottom) {
-        peer->text_surface_y = bottom;
-    }
+       
+       jive_textarea_scroll(peer, scroll_amount);
 
     return 0;
 }
+
 
 
 int jiveL_textarea_draw(lua_State *L) {

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to