5 class DFXP extends CaptionFormat
\r
7 private $textStyles = array();
\r
11 * Imports a caption string into a CaptionCollection
\r
13 * @param String $theCCString the caption file as string
\r
14 * @return CaptionCollection $myCcCollection A CaptionCollection Object
\r
16 public function importCC($theCCString) {
\r
18 // include classes for XML parser
\r
19 include_once('include/classes/core_XmlTag.php');
\r
20 include_once('include/classes/core_XmlTagCollection.php');
\r
21 include_once('include/classes/core_XmlTagTrace.php');
\r
23 // create a xml parser
\r
24 $myXmlParse = new XmlTagTrace($theCCString,'P',4);
\r
26 // print xml collection
\r
27 //$myXmlParse->toString();
\r
29 // get xml collection
\r
30 $myXmlTagCollection = $myXmlParse->getCollection();
\r
32 //include_once('CaptionCollection.php');
\r
33 $myCcCollection = new CaptionCollection();
\r
35 foreach ($myXmlTagCollection as $xmlTagObj)
\r
37 //echo '<br/>Begin Time: '.$xmlTagObj->getTagAttribute('BEGIN');
\r
38 //echo '<br/>End Time: '.$xmlTagObj->getTagAttribute('END');
\r
39 //echo '<br>Caption:'.$xmlTagObj->getTagValue();
\r
41 $txtStylesArr = Array();
\r
42 $newCaption = new Caption($xmlTagObj->getTagAttribute('BEGIN').'0',$xmlTagObj->getTagAttribute('END').'0',$xmlTagObj->getTagValue(),$txtStylesArr);
\r
44 // add captions to the collection
\r
45 $myCcCollection->addCaption($newCaption);
\r
49 //$myCcCollection->toString();
\r
51 return $myCcCollection;
\r
56 * Exports a CaptionCollection object into a string
\r
58 * @param CaptionCollection $theCollection A CaptionCollection Object
\r
59 * @return String $captionString The caption as a String
\r
61 public function exportCC($theCollection)
\r
65 $myCollection = $theCollection->getCollection();
\r
68 $ttCaption .= $this->getTTHeader();
\r
73 foreach ($myCollection as $captionObj)
\r
77 // adding caption number - for debug purpuses
\r
78 //$captionObj->getCaption() = "[CAP no. $capCount]" . " ". $captionObj->getCaption();
\r
80 // adapt \n character to <br/>
\r
81 //$fixCap = "[CAP no. $capCount] : ". CcUtil::ccNewLineToBr($captionObj->getCaption(),' <br/>');
\r
82 $fixCap = "". TxtFileTools::ccNewLineToBr($captionObj->getCaption(),' <br />');
\r
84 // convert qt to TT time format
\r
85 $ttTimeIn = $this->timeQtToTT($captionObj->getInTime());
\r
86 $ttTimeOut = $this->timeQtToTT($captionObj->getOutTime());
\r
89 $ttCaption .= "".$this->getTTCaption($ttTimeIn,$ttTimeOut,$fixCap,$captionObj->getTextStyles());
\r
91 // show caption object
\r
92 //$captionObj->toString();
\r
97 $ttCaption .= $this->getTTClose();
\r
101 } // end exportCC()
\r
104 * Verify if the caption file is a QText caption file
\r
106 public function checkFormat($theCCString)
\r
109 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText
\r
110 preg_match_all($patternCheck,$theCCString,$patternFound);
\r
112 if(count($patternFound)>0)
\r
119 } // end checkFormat()
\r
122 * Here functions to re-define
\r
124 public function getName()
\r
126 return 'Timed Text (TT) Authoring Format 1.0
\96 Distribution Format Exchange Profile (DFXP)';
\r
129 public function getAbout()
\r
131 return 'This is the most comprehensive caption format ever !!
\r
133 Additional information at <a href="http://www.w3.org/TR/2006/CR-ttaf1-dfxp-20061116/">W3-dfxp</a>';
\r
136 public function getVersion()
\r
141 public function getFileExtension()
\r
146 public function getIdPattern()
\r
148 $idPattern = '/(<tt xmlns="http:\/\/www.w3.org\/2006\/04\/ttaf1)/';
\r
153 public function allowsTextStyles()
\r
158 public function template()
\r
164 /*////////////////////////////////////////////////////////
\r
165 Functions for TT - Timed Text Conversion
\r
166 //////////////////////////////////////////////////////*/
\r
170 * creates a TT Caption
\r
171 * @return String $ttCaption A TT formatted caption
\r
172 * @param string $capInTime Caption start time (e.g 0:00:00.80)
\r
173 * @param string $capOutTime Caption end time (e.g 0:00:00.80)
\r
174 * @param String $caption caption, with all styles
\r
175 * @param Array $txtStyles Array with text styles in the caption
\r
177 private function getTTCaption($capInTime,$capOutTime,$caption,$txtStyles)
\r
180 // <p begin="0:00:00.00" end="0:00:00.80">1 begining</p>
\r
184 // Find if text alignment in $txtStyles array
\r
185 if (isset($txtStyles['text-align']))
\r
187 if ($txtStyles['text-align']=='right')
\r
189 // Add right alignment style
\r
191 <p begin="'.$capInTime.'" end="'.$capOutTime.'" style="txtRight">'.$caption.'</p>';
\r
193 else if ($txtStyles['text-align']=='left')
\r
195 // Add right alignment style
\r
197 <p begin="'.$capInTime.'" end="'.$capOutTime.'" style="txtLeft">'.$caption.'</p>';
\r
199 else if ($txtStyles['text-align']=='center')
\r
202 <p begin="'.$capInTime.'" end="'.$capOutTime.'">'.$caption.'</p>';
\r
207 // no text style, creates a plain caption
\r
209 <p begin="'.$capInTime.'" end="'.$capOutTime.'">'.$caption.'</p>';
\r
217 } // end getTTCaption()
\r
220 * Converts QT time to TT Time; drops last right number on the time format
\r
221 * @return String $ttTime TT time format 00:01:10.28"
\r
222 * @param String $qtTime QT time Format; "00:01:10.280"
\r
224 private function timeQtToTT($qtTime)
\r
226 $ttTime = substr($qtTime, 0, 11); // returns "d" ;
\r
228 } // end timeQtToTT
\r
231 private function getTTHeader()
\r
234 $textFont = "Arial";
\r
235 $textFontWeight = "normal";
\r
236 $textFontStyle = "normal";
\r
238 $textJustify = "center";
\r
241 $capTitle = 'This is a sample SAMI 1.0 caption';
\r
242 $textHtmlColor = "white";
\r
243 $bgHtmlColor = "black";
\r
244 $capLangName = "English";
\r
245 $capLangCode= "EN-US-CC";
\r
247 $capTT_header = '<?xml version="1.0" encoding="UTF-8"?>
\r
248 <tt xmlns="http://www.w3.org/2006/04/ttaf1"
\r
249 xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling" xml:lang="en">
\r
252 <style id="txtRight" tts:textAlign="right" tts:color="cyan"/>
\r
253 <style id="txtLeft" tts:textAlign="left" tts:color="#FCCA03"/>
\r
254 <style id="defaultSpeaker" tts:fontSize="'.$textSize.'px" tts:fontFamily="'.$textFont.'" tts:fontWeight="'.$textFontWeight.'" tts:fontStyle="'.$textFontStyle.'" tts:textDecoration="none" tts:color="'.$textHtmlColor.'" tts:backgroundColor="'.$bgHtmlColor.'" tts:textAlign="'.$textJustify.'" />
\r
255 <style id="defaultCaption" tts:fontSize="14px" tts:fontFamily="SansSerif" tts:fontWeight="normal" tts:fontStyle="normal" tts:textDecoration="none" tts:color="white" tts:backgroundColor="black" tts:textAlign="left" />
\r
258 <body id="ccbody" style="defaultSpeaker">
\r
259 <div xml:lang="en">';
\r
261 return $capTT_header;
\r
263 } // end getTTHeader()
\r
267 private function getTTClose()
\r
269 // alternative close "<div xml:lang="en"/>"
\r
275 return $capTT_close;
\r
278 } // end classQText
\r