App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/Song.pm  view on Meta::CPAN

	}
	elsif ( $k =~ /^(chord)$/i && $v ne "" ) {
	    $chord = $v;
	}
	elsif ( $k =~ /^(type)$/i && $v ne "" ) {
	    $opts{type} = $v;
	}
	elsif ( $k =~ /^(label|href)$/i && $v ne "" ) {
	    $opts{lc($k)} = $v;
	}
	elsif ( $k =~ /^(anchor)$/i
		&& $v =~ /^(paper|page|allpages|column|float|line)$/ ) {
	    $opts{lc($k)} = lc($v);
	}
	elsif ( $k =~ /^(align)$/i
		&& $v =~ /^(center|left|right)$/ ) {
	    $opts{lc($k)} = lc($v);
	}
	elsif ( $k =~ /^(bordertrbl)$/i
		&& $v =~ /^[trbl]*$/ ) {
	    $opts{lc($k)} = lc($v);
	}
	elsif ( $uri ) {
	    do_warn( "Unknown image attribute: $k\n" );
	    next;
	}
	# Assume just an image file uri.
	else {
	    $uri = $k;
	}
    }

    return if is_true($opts{omit});

    unless ( $uri || $id || $chord ) {
	do_warn( "Missing image source\n" );
	return;
    }
    if ( $opts{align} && $opts{x} && $opts{x} =~ /\%$/ ) {
	do_warn( "Useless combination of x percentage with align (align ignored)" );
	delete $opts{align};
    }

    # If the image uri does not have a directory, look it up
    # next to the song, and then in the images folder of the
    # resources.
    if ( $uri ) {
	if ( CP->is_here($uri) ) {
	    my $found = CP->siblingres( $diag->{file}, $uri, class => "images" )
	      || CP->siblingres( $diag->{file}, $uri, class => "icons" );
	    if ( $found ) {
		$uri = $found;
	    }
	    else {
		do_warn("Missing image for \"$uri\"");
		return;
	    }
	}
	# Do not affect URIs and base64 data strings.
	elsif ( $uri !~ /^(data:|\w+:\/\/)/ ) {
	    $uri = expand_tilde($uri);
	}
    }

    if ( $chord ) {
	if ( $chord =~ /^\[(.*)\]$/ ) { # transposable
	    my $info = $self->parse_chord($1);
	    $chord = $info->{name} if $info;
	}
	$uri = "chord:$chord";
    }

    my $aid = $id || "_Image".$assetid++;

    if ( defined $opts{spread} ) {
	if ( exists $self->{spreadimage} ) {
	    do_warn("Skipping superfluous spread image");
	}
	else {
	    $self->{spreadimage} =
	      { id => $aid, space => $opts{spread} };
	    warn("Got spread image $aid with $opts{spread} space\n")
	      if $config->{debug}->{images};
	}
    }

    # Store as asset.
    if ( $uri ) {
	my $opts;
	for ( qw( type persist href ) ) {
	    $opts->{$_} = $opts{$_} if defined $opts{$_};
	    delete $opts{$_};
	}
	for ( qw( spread ) ) {
	    $opts->{$_} = $opts{$_} if defined $opts{$_};
	}

	if ( $id && %opts ) {
	    do_warn("Asset definition \"$id\" does not take attributes",
		   " (" . join(" ",sort keys %opts) . ")");
	    return;
	}

	$self->{assets} //= {};
	my $a;
	if ( $uri =~ /\.(\w+)$/ && exists $config->{delegates}->{$1} ) {
	    my $d = $config->{delegates}->{$1};
	    $a = { type      => "image",
		   subtype   => "delegate",
		   delegate  => beo( $d, 'module' ),
		   handler   => beo( $d, 'handler' ),
		   uri       => $uri,
		 };
	}
	else {
	    $a = { type      => "image",
		   uri       => $uri,
		 };
	}
	$a->{opts} = $opts if $opts;
	$self->{assets}->{$aid} = $a;



( run in 0.793 second using v1.01-cache-2.11-cpan-5b529ec07f3 )