Blame view

tools/sctk-2.4.10/src/align2html/Token.pm 5.47 KB
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  # ALIGN2HTML
  # Author: Jerome Ajot
  #
  # This software was developed at the National Institute of Standards and Technology by 
  # employees of the Federal Government in the course of their official duties. Pursuant
  # to title 17 Section 105 of the United States Code this software is not subject to
  # copyright protection and is in the public domain. ALIGN2HTML is an experimental system.
  # NIST assumes no responsibility whatsoever for its use by other parties, and makes no
  # guarantees, expressed or implied, about its quality, reliability, or any other
  # characteristic. We would appreciate acknowledgement if the software is used.
  #
  # THIS SOFTWARE IS PROVIDED "AS IS."  With regard to this software, NIST MAKES NO EXPRESS
  # OR IMPLIED WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING MERCHANTABILITY,
  # OR FITNESS FOR A PARTICULAR PURPOSE.
  
  package Token;
  use strict;
  use Data::Dumper;
  
  sub new
  {
      my $class = shift;
      my $self = {};
  
  	$self->{ID} = shift;
  	$self->{BT} = shift;
  	$self->{DUR} = shift;
  	$self->{MID} = 0;
  	$self->{TEXT} = shift;
  	$self->{LENGTH} = 0;
  	$self->{XSTARTPOS} = 0;
  	$self->{XENDPOS} = 0;
  	$self->{YPOS} = 0;
  	$self->{XMIDPOS} = 0;
  	$self->{TEXTPOS} = "top";
  	$self->{WIDTHLINE} = 1;
  	$self->{PIXPERSEC} = 100;
  	$self->{REFORSYS} = shift;
  	$self->{PREVTKNID} = [()];
  	$self->{NEXTTKNID} = [()];
  	$self->{DISPLAY} = 0;
  	$self->{NUMPREV} = 0;
  	$self->{NUMNEXT} = 0;
  	$self->{SEGGRPID} = shift;
  	$self->{SEGID} = shift;
  	$self->{SPKRID} = shift;
  	$self->{CONF} = shift;
  	$self->{REALTIME} = 1;	
  	
  	my $tmpprev = shift;
  	my $tmpnext = shift;
  	
  	$self->{SEGBT} = shift;
  	$self->{SEGET} = shift;
  	
  	bless $self;
  	
  	$self->{REALTIME} = 0 if( ($self->{BT} eq "") || ($self->{DUR} eq "") );
  	
  	if($self->{REALTIME} == 0)
  	{
  		$self->{BT} = $self->{SEGBT};
  		$self->{DUR} = sprintf("%.3f", $self->{SEGET}-$self->{SEGBT});
  	}
  	
      $self->{MID} = sprintf("%.0f", $self->{BT} + $self->{DUR}/2);
      $self->{XSTARTPOS} = sprintf("%.0f", $self->{PIXPERSEC}*$self->{BT});
  	$self->{XMIDPOS} = sprintf("%.0f", $self->{PIXPERSEC}*($self->{BT}+$self->{DUR}/2));
  	$self->{XENDPOS} = sprintf("%.0f", $self->{PIXPERSEC}*($self->{BT}+$self->{DUR}));
  	$self->{LENGTH} = sprintf("%.0f", $self->{PIXPERSEC}*$self->{DUR});
  	$self->{TEXTPOS} = "bottom" if($self->{REFORSYS} eq "SYS");
  	
  	push(@{ $self->{PREVTKNID} }, sort {$a <=> $b} split(/\|/, $tmpprev) );
  	push(@{ $self->{NEXTTKNID} }, sort {$a <=> $b} split(/\|/, $tmpnext) );
  	
  	$self->{NUMPREV} = scalar( @{ $self->{PREVTKNID} } );
  	$self->{NUMNEXT} = scalar( @{ $self->{NEXTTKNID} } );
  	
      return $self;
  }
  
  sub MakeFakeTime
  {
  	my ($self, $beginindex, $endindex, $maxind) = @_;
  	
  	$self->{DUR} = sprintf("%.3f", ($self->{SEGET} - $self->{SEGBT})*( ($endindex - $beginindex)/$maxind ) );
  	$self->{BT} = sprintf("%.3f", $self->{SEGBT} + ($self->{SEGET} - $self->{SEGBT})*$beginindex/$maxind);
  	$self->{MID} = sprintf("%.0f", $self->{BT} + $self->{DUR}/2);
      $self->{XSTARTPOS} = sprintf("%.0f", $self->{PIXPERSEC}*$self->{BT});
  	$self->{XMIDPOS} = sprintf("%.0f", $self->{PIXPERSEC}*($self->{BT}+$self->{DUR}/2));
  	$self->{XENDPOS} = sprintf("%.0f", $self->{PIXPERSEC}*($self->{BT}+$self->{DUR}));
  	$self->{LENGTH} = sprintf("%.0f", $self->{PIXPERSEC}*$self->{DUR});
  }
  
  sub DoDisplay
  {
  	my ($self) = @_;
  	$self->{DISPLAY} = 1;
  }
  
  sub AddPrevToken
  {
  	my ($self, $prevtknid) = @_;
  	push(@{ $self->{PREVTKNID} }, $prevtknid);
  }
  
  sub AddNextToken
  {
  	my ($self, $nexttknid) = @_;
  	push(@{ $self->{NEXTTKNID} }, $nexttknid);
  }
  
  sub SetYPos
  {
  	my ($self, $ypos) = @_;
  	$self->{YPOS} += $ypos;
  }
  
  
  sub SetWidthLine
  {
  	my ($self, $lwidth) = @_;
  	$self->{WIDTHLINE} = $lwidth;
  }
  
  sub IsFakeToken
  {
      my ($self) = @_;
      return( ($self->{SEGBT} == 0) && ($self->{SEGET} == 0) && ($self->{TEXT} eq "") );
  }
  
  sub GetDraw
  {
  	my ($self, $minx) = @_;
  	my $output = "";
  
  	return $output if(! $self->{DISPLAY});
  	
  	if($self->{TEXT} ne "")
  	{
  		my $modiftexty = ($self->{TEXTPOS} eq "top" ? -17 : 6);
  		my $bullet = "images/white_dk.gif";
  		$bullet = "images/white_lt.gif" if($self->{REALTIME} == 0);
  		
  		$output .= sprintf("jg.setColor(\"DimGray\");
  ");
  		$output .= sprintf("jg.setStroke(%.0f);
  ", $self->{WIDTHLINE});
  		$output .= sprintf("jg.drawLine(%.0f*scale, %.0f, %.0f*scale, %.0f);
  ", $self->{XSTARTPOS} - $minx, $self->{YPOS}, $self->{XENDPOS} - $minx, $self->{YPOS});
  		$output .= sprintf("jg.setFont(\"arial\",\"11px\",Font.PLAIN);
  ");
  		$output .= sprintf("jg.drawStringRect(\"%s\", %.0f*scale + 1, %.0f, %.0f*scale - 1, \"center\");
  ", $self->{TEXT}, $self->{XSTARTPOS} - $minx, $self->{YPOS}+$modiftexty, $self->{LENGTH});
  		$output .= sprintf("jg.drawImage(\"%s\", %.0f*scale - 7, %.0f - 7, 14, 14);
  ", $bullet, $self->{XSTARTPOS} - $minx, $self->{YPOS});
  		$output .= sprintf("jg.drawImage(\"%s\", %.0f*scale - 7, %.0f - 7, 14, 14);
  ", $bullet, $self->{XENDPOS} - $minx, $self->{YPOS});
  	}
  	elsif(!( ($self->{SEGBT} == 0) && ($self->{SEGET} == 0) && ($self->{TEXT} eq "") ) )
  	{
  		$output .= sprintf("jg.setColor(\"brown\");
  ");
  		$output .= sprintf("jg.setStroke(%.0f);
  ", $self->{WIDTHLINE});
  		$output .= sprintf("jg.drawLine(%.0f*scale, %.0f, %.0f*scale, %.0f);
  ", $self->{XSTARTPOS} - $minx, $self->{YPOS}, $self->{XENDPOS} - $minx, $self->{YPOS});
  		$output .= sprintf("jg.drawLine(%.0f*scale, %.0f, %.0f*scale, %.0f);
  ", $self->{XSTARTPOS} - $minx, $self->{YPOS} - 4, $self->{XSTARTPOS} - $minx, $self->{YPOS} + 4);
  		$output .= sprintf("jg.drawLine(%.0f*scale, %.0f, %.0f*scale, %.0f);
  ", $self->{XENDPOS} - $minx, $self->{YPOS} - 4, $self->{XENDPOS} - $minx, $self->{YPOS} + 4);
  	}
  	
  	return $output;
  }
  
  1;