source: A2P/a2p/AFPDS/MODCA/IPS.pm @ 14

Last change on this file since 14 was 3, checked in by guillaume, 17 years ago
  • AUTHORS: Ajout des différents contributeurs
  • COPYING: Ajout de la licence GPL v3
  • a2p: Préparation des sources pour leur publication sous GPL
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1#
2# Copyright (c) 2004-2007 - Consultas, PKG.fr
3#
4# This file is part of A2P.
5#
6# A2P is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# A2P is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with A2P; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id: IPS.pm 3 2007-10-18 16:20:19Z guillaume $
21#
22# Class to export Include Page Segment members
23#
24# cf ref #1, p. 99
25#
26
27package AFPDS::MODCA::IPS ;
28
29use strict ;
30use A2P::Globals ;
31use A2P::Syslog ;
32use AFPDS::MODCA::Common ;
33
34BEGIN {
35    our $VERSION = sprintf "%s", q$Rev: 1007 $ =~ /([0-9.]+)\s+/ ;
36}
37our $VERSION ;
38our @ISA = ("AFPDS::MODCA");
39our $IDENTS ;
40
41sub _ID { 0xD3AF5F }
42
43sub new {
44    my $class = shift ;
45    &Debug("new " . __PACKAGE__ . " v$VERSION object");
46
47    my $self = {
48        FLUX     => 0,        # Associated flux
49        IDENT    => _ID,      # MO:DCA identity
50        FLAG     => 0,        # MO:DCA flags
51        RESERVED => 0,        # MO:DCA reserved
52        LONG     => 0,        # MO:DCA buffer length
53        BUFFER   => ''        # MO:DCA content buffer
54    };
55
56    return bless $self , $class ;
57}
58
59sub validate {
60    my $self = shift ;
61
62    &UPSTAT('GETSEGMENT');
63    &Debug("Found IPS as LOGO");
64
65    # Check buffer size
66    return ( 251, "Found too short IPS object (" . $self->{LONG} . "<14)" )
67        if ( $self->{LONG} < 14 );
68
69    &Warn("Found IPS Field value with triplets (" . $self->{LONG} . ">14)")
70        if ( $self->{LONG} > 14 );
71
72    # Check FLUX is a Flux object
73    return ( 251, "IPS needs to be used with Flux object" )
74        unless ( ref($self->{FLUX}) =~ /^AFPDS::Flux$/ );
75
76    return () ;
77}
78
79sub create {
80    my $self = shift ;
81
82    my $flux = $self->{FLUX} ;
83    my ( $landscape, $rotation ) = $flux->orientations ;
84
85    my $logoline = '' ;
86    if ( $landscape != $rotation ) {
87        $flux->updateFlux( { ROTSEGMENT=> $landscape } );
88        $logoline = "\\def\\ROTSEGMENT{" . $landscape . "}%\n" ;
89    }
90
91    # Set logoname
92    my $logoname = substr( $self->{BUFFER}, 0, 8 );
93    $logoname = $self->convert( $logoname );
94    return ( 252, "Invalid logoname found" ) unless $logoname ;
95    $logoname = uc( $logoname );
96
97    &UPSTAT('USESEGMENT_' . $logoname);
98
99    # Set segname for TeX/LaTeX coding
100    my $segname = $logoname ;
101    $segname =~ y/0-9/a-j/ ;
102
103    my $logox = $self->get_from_buffer(  8, 3 );
104    my $logoy = $self->get_from_buffer( 11, 3 );
105
106    my ( $xtex, $ytex ) = ( '', '' );
107    unless ( $logox == 0xFFFFFF ) {
108        # This is a signed number
109        $logox -= 0x1000000 if ( $logox > 0x7FFFFF );
110
111        # Check and set X off-set
112        return ( 222, "Found bad IPS X-value ($logox)" )
113            if ( $logox < -32768 or $logox > 32767 );
114
115        # X off-set as TeX code
116        $xtex = sprintf( "%d\\Xunit" , $logox ) ;
117    }
118
119    unless ( $logoy == 0xFFFFFF ) {
120        # This is a signed number
121        $logoy -= 0x1000000 if ( $logoy > 0x7FFFFF );
122
123        # Check and set Y off-set
124        return ( 223, "Found bad IPS Y-value ($logoy)" )
125            if ( $logoy < -32768 or $logoy > 32767 );
126
127        # Y off-set as TeX code
128        $ytex = sprintf( "%d\\Yunit" , $logoy ) ;
129    }
130
131    # If LOGOPATH is not used, then SEGMENT would be find in TeX env
132    my $segpath = $LOGOPATH ? $LOGOPATH . "/" : "" ;
133
134    # Add SEGMENT to logo list
135    $flux->addsegpath( $segpath, $logoname );
136
137    # Keep information on this valid segment after adding its path
138    $flux->updateFlux( { LOGOs => { $logoname => 1 } } );
139
140    # Finish Tex/LaTeX code and add it to logo list
141    $logoline .= "\\SEGMENT{" . $xtex . "}{" . $ytex  . "}{\\" ;
142    $logoline .= "Rotated" if $landscape ;
143    $logoline .= "Segment" . $segname . "}% Logo: $logoname @ $logox x $logoy" ;
144    $flux->newlogo( $logoline );
145
146    unless ($NO_SYSLOG_DEBUG) {
147        # Just to protect '%' from printf interpretation in syslog...
148        $logoline =~ s/%/%%/g ;
149        &Debug("new logo line '$logoline'");
150    }
151
152    return () ;
153}
154
155&Debug("Module " . __PACKAGE__ . " v$VERSION loaded");
156
157( $IDENTS->{&_ID} ) = __PACKAGE__ =~ /(\w+)$/ ;
Note: See TracBrowser for help on using the repository browser.