mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
feature: new command halign, valign, condition in 02_RSS.pm (Betateilchen & Boris)
git-svn-id: https://svn.fhem.de/fhem/trunk@4219 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7fb6f1281f
commit
1e06ddda99
@ -1,6 +1,8 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
- SVN
|
- SVN
|
||||||
|
- feature: new command halign, valign, condition in 02_RSS.pm
|
||||||
|
(Betateilchen & Boris)
|
||||||
- bugfix: PRESENCE: Fix nonworking initialization in mode "lan-bluetooth"
|
- bugfix: PRESENCE: Fix nonworking initialization in mode "lan-bluetooth"
|
||||||
- bugfix: fhem.pl: write-select to avoid blocking in inform/Event Monitor
|
- bugfix: fhem.pl: write-select to avoid blocking in inform/Event Monitor
|
||||||
- bugfix: fix issue with DST changes in 57_Calendar.pm
|
- bugfix: fix issue with DST changes in 57_Calendar.pm
|
||||||
|
@ -11,8 +11,13 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use GD;
|
use GD;
|
||||||
|
use feature qw/switch/;
|
||||||
use vars qw(%data);
|
use vars qw(%data);
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
|
require "98_SVG.pm"; # enable use of plotAsPng()
|
||||||
|
|
||||||
|
my @valid_valign = qw(top center base bottom);
|
||||||
|
my @valid_halign = qw(left center right);
|
||||||
|
|
||||||
# we can
|
# we can
|
||||||
# use vars qw(%FW_types); # device types,
|
# use vars qw(%FW_types); # device types,
|
||||||
@ -42,7 +47,6 @@ RSS_Initialize($) {
|
|||||||
$hash->{AttrList}= "size bg tmin";
|
$hash->{AttrList}= "size bg tmin";
|
||||||
$hash->{SetFn} = "RSS_Set";
|
$hash->{SetFn} = "RSS_Set";
|
||||||
|
|
||||||
|
|
||||||
RSS_addExtension("RSS_CGI","rss","RSS");
|
RSS_addExtension("RSS_CGI","rss","RSS");
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -84,6 +88,12 @@ RSS_Define($$) {
|
|||||||
$hash->{fhem}{hostname}= $hostname;
|
$hash->{fhem}{hostname}= $hostname;
|
||||||
$hash->{fhem}{filename}= $filename;
|
$hash->{fhem}{filename}= $filename;
|
||||||
|
|
||||||
|
eval "use GD::Text::Align";
|
||||||
|
$hash->{fhem}{useTextAlign} = ($@ ? 0 : 1 );
|
||||||
|
if(!($hash->{fhem}{useTextAlign})) {
|
||||||
|
Log3 $hash, 1, "Cannot use text alignment: $@";
|
||||||
|
}
|
||||||
|
|
||||||
RSS_readLayout($hash);
|
RSS_readLayout($hash);
|
||||||
|
|
||||||
$hash->{STATE} = $name;
|
$hash->{STATE} = $name;
|
||||||
@ -217,8 +227,21 @@ sub
|
|||||||
RSS_itemText {
|
RSS_itemText {
|
||||||
my ($S,$x,$y,$text,%params)= @_;
|
my ($S,$x,$y,$text,%params)= @_;
|
||||||
return unless(defined($text));
|
return unless(defined($text));
|
||||||
($x,$y)= RSS_xy($S,$x,$y);
|
|
||||||
$S->stringFT(RSS_color($S,$params{rgb}),$params{font},$params{pt},0,$x,$y,$text);
|
if($params{useTextAlign}) {
|
||||||
|
($x,$y)= RSS_xy($S,$x,$y);
|
||||||
|
my $align = GD::Text::Align->new($S,
|
||||||
|
color => RSS_color($S, $params{rgb}),
|
||||||
|
valign => $params{tvalign},
|
||||||
|
halign => $params{thalign},
|
||||||
|
);
|
||||||
|
$align->set_font($params{font}, $params{pt});
|
||||||
|
$align->set_text($text);
|
||||||
|
$align->draw($x, $y, 0);
|
||||||
|
} else {
|
||||||
|
($x,$y)= RSS_xy($S,$x,$y);
|
||||||
|
$S->stringFT(RSS_color($S,$params{rgb}),$params{font},$params{pt},0,$x,$y,$text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -227,6 +250,7 @@ RSS_itemTime {
|
|||||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
||||||
RSS_itemText($S,$x,$y,sprintf("%02d:%02d", $hour, $min),%params);
|
RSS_itemText($S,$x,$y,sprintf("%02d:%02d", $hour, $min),%params);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
RSS_itemSeconds {
|
RSS_itemSeconds {
|
||||||
my ($S,$x,$y,$format,%params)= @_;
|
my ($S,$x,$y,$format,%params)= @_;
|
||||||
@ -237,7 +261,7 @@ RSS_itemSeconds {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RSS_itemText($S,$x,$y,sprintf("%02d", $sec),%params);
|
RSS_itemText($S,$x,$y,sprintf("%02d", $sec),%params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sub
|
sub
|
||||||
@ -276,7 +300,6 @@ RSS_itemImg {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elsif($srctype eq "data") {
|
} elsif($srctype eq "data") {
|
||||||
require "98_SVG.pm"; # enable use of plotAsPng()
|
|
||||||
if($imgtype eq "gif") {
|
if($imgtype eq "gif") {
|
||||||
$I= GD::Image->newFromGifData($arg);
|
$I= GD::Image->newFromGifData($arg);
|
||||||
} elsif($imgtype eq "png") {
|
} elsif($imgtype eq "png") {
|
||||||
@ -290,18 +313,37 @@ RSS_itemImg {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
($x,$y)= RSS_xy($S,$x,$y);
|
($x,$y)= RSS_xy($S,$x,$y);
|
||||||
my ($width,$height)= $I->getBounds();
|
|
||||||
if ($scale =~ s/([wh])([\d]*)/$2/) { # get the digit from width/hight to pixel entry
|
eval {
|
||||||
#Debug "RSS scale $scale (1: $1 / 2: $2)contais px after Digit - width: $width / height: $height";
|
my ($width,$height)= $I->getBounds();
|
||||||
if ($1 eq "w") {
|
if ($scale =~ s/([wh])([\d]*)/$2/) { # get the digit from width/hight to pixel entry
|
||||||
$scale=$scale/$width;
|
#Debug "RSS scale $scale (1: $1 / 2: $2)contais px after Digit - width: $width / height: $height";
|
||||||
} else {
|
if ($1 eq "w") {
|
||||||
$scale=$scale/$height;
|
$scale=$scale/$width;
|
||||||
|
} else {
|
||||||
|
$scale=$scale/$height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
my ($swidth,$sheight)= (int($scale*$width), int($scale*$height));
|
||||||
|
|
||||||
|
given ($params{ihalign}) {
|
||||||
|
when('center') { $x -= $swidth/2; }
|
||||||
|
when('right') { $x -= $swidth; }
|
||||||
|
default { } # nothing to do
|
||||||
|
}
|
||||||
|
given ($params{ivalign}) {
|
||||||
|
when('center') { $y -= $sheight/2; }
|
||||||
|
when('base') { $y -= $sheight; }
|
||||||
|
when('bottom') { $y -= $sheight; }
|
||||||
|
default { } # nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
#Debug "RSS placing $arg ($swidth x $sheight) at ($x,$y)";
|
||||||
|
$S->copyResampled($I,$x,$y,0,0,$swidth,$sheight,$width,$height);
|
||||||
|
};
|
||||||
|
if($@) {
|
||||||
|
Log3 undef, 2, "RSS: cannot create image $srctype $imgtype '$arg': $@";
|
||||||
}
|
}
|
||||||
my ($swidth,$sheight)= (int($scale*$width), int($scale*$height));
|
|
||||||
#Debug "RSS placing $arg ($swidth x $sheight) at ($x,$y)";
|
|
||||||
$S->copyResampled($I,$x,$y,0,0,$swidth,$sheight,$width,$height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -324,6 +366,16 @@ RSS_evalLayout($$@) {
|
|||||||
$params{font}= "Arial";
|
$params{font}= "Arial";
|
||||||
$params{pt}= 12;
|
$params{pt}= 12;
|
||||||
$params{rgb}= "ffffff";
|
$params{rgb}= "ffffff";
|
||||||
|
$params{halign} = 'left';
|
||||||
|
$params{valign} = 'base';
|
||||||
|
$params{condition} = '1';
|
||||||
|
# we need two pairs of align parameters
|
||||||
|
# due to different default values for text and img
|
||||||
|
$params{useTextAlign}= $defs{$name}{fhem}{useTextAlign};
|
||||||
|
$params{ihalign} = 'left';
|
||||||
|
$params{ivalign} = 'top';
|
||||||
|
$params{thalign} = 'left';
|
||||||
|
$params{tvalign} = 'base';
|
||||||
|
|
||||||
my ($x,$y,$x1,$y1,$x2,$y2,$scale,$text,$imgtype,$srctype,$arg,$format);
|
my ($x,$y,$x1,$y1,$x2,$y2,$scale,$text,$imgtype,$srctype,$arg,$format);
|
||||||
|
|
||||||
@ -342,6 +394,8 @@ RSS_evalLayout($$@) {
|
|||||||
# split line into command and definition
|
# split line into command and definition
|
||||||
my ($cmd, $def)= split("[ \t]+", $line, 2);
|
my ($cmd, $def)= split("[ \t]+", $line, 2);
|
||||||
##Debug, "CMD= \"$cmd\", DEF= \"$def\"";
|
##Debug, "CMD= \"$cmd\", DEF= \"$def\"";
|
||||||
|
$params{condition} = AnalyzePerlCommand(undef, $def) if($cmd eq 'condition');
|
||||||
|
next unless($params{condition});
|
||||||
if($cmd eq "rgb") {
|
if($cmd eq "rgb") {
|
||||||
$def= "\"$def\"" if(length($def) == 6 && $def =~ /[[:xdigit:]]{6}/);
|
$def= "\"$def\"" if(length($def) == 6 && $def =~ /[[:xdigit:]]{6}/);
|
||||||
$params{rgb}= AnalyzePerlCommand(undef, $def);
|
$params{rgb}= AnalyzePerlCommand(undef, $def);
|
||||||
@ -349,6 +403,24 @@ RSS_evalLayout($$@) {
|
|||||||
$params{font}= $def;
|
$params{font}= $def;
|
||||||
} elsif($cmd eq "pt") {
|
} elsif($cmd eq "pt") {
|
||||||
$params{pt}= $def;
|
$params{pt}= $def;
|
||||||
|
} elsif($cmd eq "halign"){
|
||||||
|
my $d = AnalyzePerlCommand(undef, $def);
|
||||||
|
if($d ~~ @valid_halign) {
|
||||||
|
#Debug "$name: halign $d found valid in halign_array";
|
||||||
|
$params{ihalign}= $d;
|
||||||
|
$params{thalign}= $d;
|
||||||
|
} else {
|
||||||
|
Log3 $name, 2, "$name: Illegal horizontal alignment $d";
|
||||||
|
}
|
||||||
|
} elsif($cmd eq "valign") {
|
||||||
|
my $d = AnalyzePerlCommand(undef, $def);
|
||||||
|
if( $d ~~ @valid_valign) {
|
||||||
|
# Debug "$name: valign $d found valid in valign_array";
|
||||||
|
$params{ivalign}= $d;
|
||||||
|
$params{tvalign}= $d;
|
||||||
|
} else {
|
||||||
|
Log3 $name, 2, "$name: Illegal vertical alignment $d";
|
||||||
|
}
|
||||||
} elsif($cmd eq "text") {
|
} elsif($cmd eq "text") {
|
||||||
($x,$y,$text)= split("[ \t]+", $def, 3);
|
($x,$y,$text)= split("[ \t]+", $def, 3);
|
||||||
my $txt= AnalyzePerlCommand(undef, $text);
|
my $txt= AnalyzePerlCommand(undef, $text);
|
||||||
@ -374,7 +446,6 @@ RSS_evalLayout($$@) {
|
|||||||
} else {
|
} else {
|
||||||
Log3 $name, 1, "$name: Illegal command $cmd in layout definition.";
|
Log3 $name, 1, "$name: Illegal command $cmd in layout definition.";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,18 +698,33 @@ RSS_CGI(){
|
|||||||
putting a \ at the end.<p>
|
putting a \ at the end.<p>
|
||||||
|
|
||||||
<i>Layout control commands</i><p>
|
<i>Layout control commands</i><p>
|
||||||
|
Notes:
|
||||||
|
(1) Use double quotes to quote literal text if perl specials are allowed.
|
||||||
|
(2) Text alignment requires the Perl module GD::Text::Align to be installed. Debian-based systems can install it with <code>apt-get install libgd-text-perl</code>.
|
||||||
|
<p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>font <font><br>Sets the font. <font> is the name of a TrueType font (e.g.
|
<li>font "<font>"<br>Sets the font. <font> is the name of a TrueType font (e.g.
|
||||||
<code>Arial</code>) or the full path to a TrueType font
|
<code>Arial</code>) or the full path to a TrueType font
|
||||||
(e.g. <code>/usr/share/fonts/truetype/arial.ttf</code>),
|
(e.g. <code>/usr/share/fonts/truetype/arial.ttf</code>),
|
||||||
whatever works on your system.</li><br>
|
whatever works on your system.</li><br>
|
||||||
|
|
||||||
<li>rgb <color><br>Sets the color. <color> is a 6-digit hex number, every 2 digits
|
<li>rgb "<color>"<br>Sets the color. <color> is a 6-digit hex number, every 2 digits
|
||||||
determining the red, green and blue color components as in HTML color codes (e.g.
|
determining the red, green and blue color components as in HTML color codes (e.g.
|
||||||
<code>FF0000</code> for red, <code>C0C0C0</code> for light gray). You can use
|
<code>FF0000</code> for red, <code>C0C0C0</code> for light gray). You can use
|
||||||
<code>{ <a href="#perl"><perl special></a> }</code> for <color>.</li><br>
|
<code>{ <a href="#perl"><perl special></a> }</code> for <color>.</li><br>
|
||||||
|
|
||||||
<li>pt <pt><br>Sets the font size in points.</li><br>
|
<li>pt <pt><br>Sets the font size in points.</li><br>
|
||||||
|
|
||||||
|
<li>halign "left"|"center"|"right"<br>Sets the horizontal text and image alignment. Defaults to left-aligned. You can use
|
||||||
|
<code>{ <a href="#perl"><perl special></a> }</code> instead of the literal alignment control word.</li><br>
|
||||||
|
|
||||||
|
<li>valign "top"|"center"|"base"|"bottom"<br>Sets the vertical text and image alignment. Defaults to top-aligned. You can use
|
||||||
|
<code>{ <a href="#perl"><perl special></a> }</code> instead of the literal alignment control word.</li><br>
|
||||||
|
|
||||||
|
<li>condition <condition><br>Subsequent layout control and item placement commands except for another condition command
|
||||||
|
are ignored if and only if <condition>
|
||||||
|
evaluates to false.</li><br>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<i>Item placement commands</i><p>
|
<i>Item placement commands</i><p>
|
||||||
@ -669,7 +755,7 @@ RSS_CGI(){
|
|||||||
This is how a layout definition might look like:<p>
|
This is how a layout definition might look like:<p>
|
||||||
<code>
|
<code>
|
||||||
font /usr/share/fonts/truetype/arial.ttf # must be a TrueType font<br>
|
font /usr/share/fonts/truetype/arial.ttf # must be a TrueType font<br>
|
||||||
rgb c0c0c0 # HTML color notation, RGB<br>
|
rgb "c0c0c0" # HTML color notation, RGB<br>
|
||||||
pt 48 # font size in points<br>
|
pt 48 # font size in points<br>
|
||||||
time 0.10 0.90<br>
|
time 0.10 0.90<br>
|
||||||
pt 24<br>
|
pt 24<br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user