Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale



Two down, one to go!
 
3. The spec wants the image to be displayable on the left or right of the textview, with any accompanying text at the top, middle or bottom of the image.
 
I used Gtk2::TextTags with the 'justification' and 'rise' properties set. 'justification' works just fine when there is only text on the line, but it stops working the minute an image is added to the same line. 'rise' doesn't work at all.
 
I could handle left-justification by inserting the image at the first iter in the line (instead of at the end of the line, as usual). But I can't think of any workaround for the 'rise' property.
 
---
 
#!/usr/bin/perl
package scaleme;
 
use strict;
use diagnostics;
use warnings;
 
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
 
# Display this image
my $path = 'change_this_directory/cat.bmp';
 
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_title('scaleme');
$window->set_position('center');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
 
    Gtk2->main_quit();
    exit;
});
            
my $frame = Gtk2::Frame->new();
$window->add($frame);
 
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$frame->add($scrollWin);
$scrollWin->set_policy('automatic', 'automatic');     
$scrollWin->set_border_width(0);
 
my $textView = Gtk2::TextView->new;
$scrollWin->add_with_viewport($textView);
 
if (-e $path) {
 
    # Display an image
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
 
    my $buffer = $textView->get_buffer();
    $buffer->insert_pixbuf(
        $buffer->get_end_iter(),
        $pixbuf,
    );
 
    # Create some text tags for modifying how text on the same line
    #   as the image is displayed. (I have specified colours so we
    #   can be sure which tag is displayed)
    $buffer->create_tag(
        'rise_tag',
        'rise'          => '100',
        'rise-set'      => TRUE,
        'foreground'    => '#FF0000',
    );
 
    $buffer->create_tag(
        'justify_tag',
        'justification' => 'right',
        'foreground'    => '#FF00FF',
    );
 
    # Test the tags with some innocuous text
    $buffer->insert_with_tags_by_name(
        $buffer->get_end_iter(),
        'Here is some text to look at',
        'rise_tag',
    );
}
 
$window->show_all();   
Gtk2->main();
   


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]