5 class Sami extends CaptionFormat
\r
7 private $textStyles = array();
\r
10 * Imports a caption string into a CaptionCollection
\r
12 * @param String $theCCString the caption file as string
\r
13 * @return CaptionCollection $myCcCollection A CaptionCollection Object
\r
15 public function importCC($theCCString)
\r
23 * Exports a CaptionCollection object into a string
\r
25 * @param CaptionCollection $theCollection A CaptionCollection Object
\r
26 * @return String $captionString The caption as a String
\r
28 public function exportCC($theCollection)
\r
33 $myCollection = $theCollection->getCollection();
\r
35 // start SAMI Caption
\r
39 $samiCaption .= $this->getSamiHeader();
\r
44 // Building Sami caption
\r
46 foreach ($myCollection as $captionObj)
\r
51 // convert to qt to Sami time format
\r
52 $samiTimeIn = TimeUtil::timeQtToSami($captionObj->getInTime());
\r
53 $samiTimeOut = TimeUtil::timeQtToSami($captionObj->getOutTime());
\r
55 $captionStyles = $captionObj->getTextStyles();
\r
57 $fixCap = TxtFileTools::ccNewLineToBr($captionObj->getCaption(),' <br/>');
\r
59 // ading caption to String
\r
60 //$samiCaption .= "". $this->getSamiCaption($samiTime,$fixCap,"QT");
\r
62 // new adding empty caption when time out
\r
63 $samiCaption .= "". $this->getSamiCaption($samiTimeIn,$samiTimeOut,$fixCap,$captionObj->getTextStyles());
\r
65 } // end for each caption
\r
68 $samiCaption .= $this->getSamiClose();
\r
72 $ccExport = $samiCaption;
\r
79 * Verify if the caption file is a SAMI caption file
\r
81 public function checkFormat($theCCString)
\r
84 } // end checkFormat()
\r
87 * Here functions to re-define
\r
89 public function getName()
\r
94 public function getAbout()
\r
96 return 'This caption format can be played by Windows Media Player on Windows OS. ';
\r
99 public function getVersion()
\r
104 public function getFileExtension()
\r
109 public function getIdPattern()
\r
111 $idPattern = '/(<SAMI>)/';
\r
116 public function allowsTextStyles()
\r
121 public function template()
\r
125 return $ccTemplate;
\r
129 /*////////////////////////////////////////////////////////
\r
130 Functions for SAMI conversion
\r
131 //////////////////////////////////////////////////////*/
\r
134 * creates a SAMI Caption
\r
135 * @return String $samiCaption A SAMI formatted caption
\r
136 * @param int $capInTime Caption start time in miliseconds 1 sec = 1000
\r
137 * @param int $capOutTime Caption end time in miliseconds 1 sec = 1000
\r
138 * @param String $caption caption, with all styles
\r
139 * @param Array $txtStyles Array with text styles in the caption
\r
141 private function getSamiCaption($capInTime,$capOutTime,$caption,$txtStyles)
\r
144 $captionReFormated = "";
\r
146 // Find if text alignment in $txtStyles array
\r
147 if (isset($txtStyles['text-align']))
\r
149 if ($txtStyles['text-align']=='right')
\r
151 $caption = '<table align=right><span style="color:#00FFFF">'.$caption.'</span></table>';
\r
153 else if ($txtStyles['text-align']=='left')
\r
155 $caption = '<table align=left><span style="color:#FCCA03">'.$caption.'</span></table>';
\r
157 else if ($txtStyles['text-align']=='center')
\r
159 $caption = '<table align=center>'.$caption.'</table>';
\r
164 // Create SAMI Caption
\r
166 <SYNC start='.$capInTime.'><P>'.$caption.'</P></SYNC>';
\r
168 // add an empty caption when caption finishes if caption's lenght is more than x sec
\r
169 // prevents caption for displaying it if next caption is to ahead //// still working
\r
170 $captionLenght = $capOutTime-$capInTime;
\r
171 if ($captionLenght>2000)
\r
174 <SYNC start='.$capOutTime.'><P> </P></SYNC>';
\r
177 return $samiCaption;
\r
179 } // end getSamiCaption
\r
183 private function getSamiHeader()
\r
186 $textFont = "Arial";
\r
187 $textFontWeight = "normal";
\r
189 $textJustify = "center";
\r
191 // unique vars for SAMI
\r
192 $capTitle = 'This is a sample SAMI 1.0 caption';
\r
193 $textHtmlColor = "#FFFFFF";
\r
194 $bgHtmlColor = "#000000";
\r
195 $capLangName = "English";
\r
196 $capLangCode= "EN-US-CC";
\r
198 $capSAMI_header = '<SAMI>
\r
200 <TITLE>'.$capTitle.'</TITLE>
\r
201 <STYLE TYPE="text/css">
\r
203 P { margin: 2px 20% 0px 20%; font-size:'.$textSize.'; font-family: '.$textFont.'; font-weight: '.$textFontWeight.'; color: '.$textHtmlColor.'; background-color: '.$bgHtmlColor.'; text-align: '.$textJustify.'; }
\r
204 .ENUSCC { name: '.$capLangName.'; lang: '.$capLangCode.'; }
\r
205 .txtRight { font-size:'.$textSize.'; font-family: '.$textFont.'; font-weight: '.$textFontWeight.'; color: #00FFFF; background-color: '.$bgHtmlColor.'; text-align: right; }
\r
206 .txtLeft { font-size:'.$textSize.'; font-family: '.$textFont.'; font-weight: '.$textFontWeight.'; color: #FCCA03; background-color: '.$bgHtmlColor.'; text-align: left; }
\r
211 return $capSAMI_header;
\r
212 } // end getSamiHeader()
\r
216 private function getSamiClose()
\r
221 return $capSAMI_close;
\r
226 } // end CCsami Class
\r