Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User ecostanza's Avatar
    Join Date
    Jan 2007
    Posts
    29
    Hello.

    It seems to me that fonts are not correctly handled on images (e.g. for double buffering). In particular, if I try to render text on an image using a larger font than default, the text gets rendered very very small. This looks similar to a bug that was affecting font on canvas in an older release, about one year ago..

    To demonstrate the problem I added an extra function "font_canvas_double_buffer" to the test_font.py script that is in the \src\ext\graphics folder of the source distribution. The full source is at the bottom of this message.

    I am using version 1.4.3 (but the test_font.py is from the 1.4.2 source release) and testing on an E51.

    Is this a bug, or am I doing something stupid in the way I handle the double buffering?

    Thanks,
    Enrico

    Code:
    from appuifw import *
    from graphics import *
    import e32
    import time
    
    app.body=c=Canvas()
    
    fonts=[None,
           (None,20),
           'normal',
           ('normal',20),
           (u'fasfsafs',20),
           (u'Nokia Sans S60',10,0),
           (u'Nokia Sans S60',20),
           'dense',
           'title',
           (None,10,FONT_BOLD),
           (None,10,FONT_ITALIC),
           (None,10,FONT_ANTIALIAS),
           (None,10,FONT_NO_ANTIALIAS),
           ('normal',None,FONT_BOLD),
           ('normal',None,FONT_ITALIC),
           ('normal',None,FONT_NO_ANTIALIAS)      
           ]
    
    def font_canvas():
        app.body=c=Canvas()
        c.clear()
        tl=(0,0)
        for font in fonts:
            text_to_draw=u'font:'+str(font)
            (bbox,advance,ichars)=c.measure_text(text_to_draw, font=font)
            print bbox, advance, ichars    
            # position the next piece of text so the top-left corner of its bounding box is at tl.    
            o=(tl[0]-bbox[0],tl[1]-bbox[1])
            # Draw the bounding box of the text as returned by measure_text
            c.rectangle((o[0]+bbox[0],o[1]+bbox[1],o[0]+bbox[2],o[1]+bbox[3]),outline=0x00ff00) 
            c.text(o, text_to_draw, font=font)                
            # Compute the new top-left.
            tl=(0,o[1]+bbox[3])
    
    def font_canvas_double_buffer():
        #app.body=c=Canvas()
        canvas=Canvas()
        c = Image.new(canvas.size)
        c.clear()
        tl=(0,0)
        for font in fonts:
            text_to_draw=u'font:'+str(font)
            (bbox,advance,ichars)=c.measure_text(text_to_draw, font=font)
            print bbox, advance, ichars    
            # position the next piece of text so the top-left corner of its bounding box is at tl.    
            o=(tl[0]-bbox[0],tl[1]-bbox[1])
            # Draw the bounding box of the text as returned by measure_text
            c.rectangle((o[0]+bbox[0],o[1]+bbox[1],o[0]+bbox[2],o[1]+bbox[3]),outline=0x00ff00) 
            c.text(o, text_to_draw, font=font)                
            # Compute the new top-left.
            tl=(0,o[1]+bbox[3])
    	
        app.body=canvas
        app.body.blit(c)
    
    def measure_text():
        app.body=c=Canvas()
        c.clear()
        tl=(0,0)
        font='normal'
        for maxwidth in (50,100,150,200,250):
            text_to_draw=u'Lorem ipsum dolor sit amet'
            (bbox,advance,maxchars)=c.measure_text(text_to_draw, font=font, maxwidth=maxwidth)
            print bbox, advance, maxchars
            # Position the next piece of text so the top-left corner of its bounding box is at tl.    
            o=(tl[0]-bbox[0],tl[1]-bbox[1])
            # Draw the bounding box of the text as returned by measure_text
            c.rectangle((o[0]+bbox[0],o[1]+bbox[1],o[0]+bbox[2],o[1]+bbox[3]),outline=0x00ff00) 
            # Draw the maximum width specification line.
            c.line((tl[0],tl[1]+10,tl[0]+maxwidth,tl[1]+10), outline=0xff0000)
            # Draw the full text
            c.text(o, text_to_draw, font=font, fill=0x000080)                
            # Draw the text limited to given number of chars.
            c.text(o, text_to_draw[0:maxchars], font=font, fill=0)                
            # Compute the new top-left.
            tl=(0,o[1]+bbox[3]+3)
    
    def font_benchmark():
        app.body=c=Canvas()
        c.clear()
        tl=(0,0)
        font='normal'
        text=u'Lorem ipsum dolor sit amet'
        def bench(name, func):
            start=time.time()
            func()
            end=time.time()
            print "%s: %d s"%(name,end-start)
        def default_font_test(c,t):
            for k in range(1000):
                c.text((0,30),t)        
        bench("default font", lambda:default_font_test(c,text))    
    
    def font_attributes():
        app.body=c=Canvas()
        c.clear()
        y=20
        for font in [(None,None,0),
                     (None,None,FONT_ITALIC),
                     (None,None,FONT_BOLD),
                     (None,None,FONT_ITALIC|FONT_BOLD),
                     (None,None,FONT_ANTIALIAS),
                     (None,None,FONT_SUPERSCRIPT),
                     (None,None,FONT_SUBSCRIPT),
                     (None,None,FONT_NO_ANTIALIAS)]:
            c.text((20,y), u'abcd '+str(font), font=font)
            y+=20
    
    
    def font_text():
        app.body=t=Text()
        for font in fonts:
            t.font=None
            t.add(u'font:'+str(font))
            t.font=font
            t.add(u'abcd1234')
            
            
    
    lock=e32.Ao_lock()
    app.screen='full'
    app.exit_key_handler=lock.signal
    
    app.menu=[(u'Fonts on canvas', font_canvas),
              (u'Fonts on canvas DBL Buff', font_canvas_double_buffer),
              (u'Measure text', measure_text),
              (u'Font attributes', font_attributes),
              (u'Font benchmark', font_benchmark),
              (u'Fonts on Text', font_text)]
    font_canvas()
    lock.wait()

  2. #2
    Super Contributor jplauril's Avatar
    Join Date
    Dec 2004
    Posts
    643
    Yes, it's a bug - one that has recently been fixed in internal code.

    http://sourceforge.net/tracker/index...55&atid=790646

    The fix will be in the next release.

  3. #3
    Registered User ecostanza's Avatar
    Join Date
    Jan 2007
    Posts
    29
    Thanks!

    Any idea when the next release is expected?
    Would you suggest that I get the sources from svn and complile it myself or shall I just wait?

    Best,
    Enrico

  4. #4
    Registered User ecostanza's Avatar
    Join Date
    Jan 2007
    Posts
    29
    Actually I just looked at the sourceforge svn and the repository seems to be not at all updated.. where is the source?

    Thanks,
    Enrico

  5. #5
    Super Contributor jplauril's Avatar
    Join Date
    Dec 2004
    Posts
    643
    Unfortunately we can't keep our internal version control system open to the public. You'll just have to wait for the next release.

Similar Threads

  1. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  2. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  3. A BUG!!! Drawing to image graphics (3650)
    By palmcrust in forum Mobile Java General
    Replies: 2
    Last Post: 2004-02-23, 02:12
  4. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31
  5. A bug in Image class for S60
    By cryptoalex in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-05-30, 08:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved