5 class QTtext 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
17 //echo 'show the replaced TQtext:<form><textarea name="textarea" cols="120" rows="5">'. $theCCString. '</textarea></form>';
\r
19 // clean malformed patterns creted when files were saved on win notepad
\r
20 //$toSearch = array(chr(13).chr(10));
\r
21 //$toReplace = array(chr(10));
\r
23 $toSearch = array(chr(13).chr(10),chr(13),chr(10).chr(32).chr(10),chr(10).chr(10) ); // this default break line in Capscribe Desktop - Mac OS
\r
24 $toReplace = array(chr(10),chr(10),chr(10),chr(10));
\r
26 //$toSearch = chr(13); // this default break line in Capscribe Desktop - Mac OS
\r
27 //$toReplace = chr(10);
\r
29 $theCCString = str_replace($toSearch,$toReplace,$theCCString);
\r
31 // get all lines in array
\r
32 $allLines = split(chr(10),$theCCString);
\r
33 $controlTime = 0; // control time marks IN and OUT
\r
34 $controlCaptionLines = 0; // control the number of lines of one caption
\r
35 $addCaptionControl = 0; //Start Adding caption when = 1
\r
37 $captionCounter = 0; // Total number of captions found
\r
40 $timesOut = array();
\r
41 $captions = array();
\r
43 // Defining QText known pattenrs;
\r
44 $qtPatternRegEx = "/({(.*?)})/";
\r
45 $pattern_QT_time_format_000 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\]";
\r
46 $pattern_QT_time_format_00 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})\]";
\r
47 $pattern_QT_time_format_selected = '';
\r
49 // determine if miliseconds are in 2 of 3 digit format
\r
50 if (preg_match("/$pattern_QT_time_format_000/", $theCCString))
\r
52 $pattern_QT_time_format_selected = $pattern_QT_time_format_000;
\r
54 else if (preg_match("/$pattern_QT_time_format_00/", $theCCString))
\r
56 $pattern_QT_time_format_selected = $pattern_QT_time_format_00;
\r
59 // loop through caption lines
\r
60 for ($i=0; $i<count($allLines);$i++)
\r
63 //echo '<br/>Line ('.$i.') *** '.($allLines[$i]).'';
\r
65 // is this a time mark ?
\r
66 $isTime = preg_match("/$pattern_QT_time_format_selected/", $allLines[$i]);
\r
68 // if it is a time mark, start converting else is a caption n lines
\r
71 // clean up time mark '[]' characters
\r
72 $allLines[$i] = str_replace('[','',$allLines[$i]);
\r
73 $allLines[$i] = str_replace(']','',$allLines[$i]);
\r
75 // Is this the First time mark?
\r
76 if ($controlTime == 0)
\r
78 // ok get the first time mark and wait for the time out mark
\r
79 $timesIn[] = $allLines[$i]; // mm this is not java style... FIX ME!!
\r
81 // start caption text and wait for n lines
\r
82 $captions[$captionCounter]= '';
\r
83 $addCaptionControl = 1;
\r
84 $currentIndex = $captionCounter;
\r
86 //echo '------ This The first time TIME MARK';
\r
89 // Is this the Time IN of the caption?
\r
90 else if ($controlTime == 1)
\r
93 $timesIn[] = $allLines[$i]; // mm this is not java style... FIX ME!!
\r
95 // start caption text and wait for n lines
\r
96 $captions[$captionCounter]= '';
\r
97 $addCaptionControl = 1;
\r
98 $currentIndex = $captionCounter;
\r
100 //echo '------ This is IN TIME MARK';
\r
103 // Is this the Time Out of the caption?
\r
104 else if ($controlTime == 2)
\r
107 $timesOut[] = $allLines[$i]; // mm this is not java style... FIX ME!!
\r
109 $addCaptionControl = 0;
\r
110 //echo '------ This is OUT TIME MARK';
\r
115 // start adding captions
\r
116 if ($addCaptionControl==1)
\r
118 // add new line to the current caption
\r
119 $captions[$currentIndex] .= $allLines[$i].chr(10);
\r
120 //echo '------ The caption'.$captions[$currentIndex];
\r
126 // create a collection object
\r
127 $myQTextCollection = new CaptionCollection();
\r
130 echo '<br/><br/>Total Captions Found: '.$captionCounter;
\r
131 echo '<br/><br/>Total TIME IN: '.count($timesIn);
\r
132 echo '<br/><br/>Total TIME OUT: '.count($timesOut);
\r
133 echo '<br/><br/>Total CAPTIONS: '.count($captions);
\r
136 // test in a text area
\r
137 //echo '<form><textarea cols="100" rows="10">';
\r
139 for ($j=0;$j<$captionCounter;$j++)
\r
142 // get all QT styles found in caption text
\r
143 preg_match_all($qtPatternRegEx,$captions[$j],$captionStylesFound);
\r
145 // clean all QT styles from the caption
\r
146 $captions[$j] = str_replace($captionStylesFound[0], "", $captions[$j]);
\r
148 // show the plain text Caption
\r
149 //echo '<br/><br/>'.$captions[$j];
\r
152 // show all QT found in caption line
\r
153 foreach ($captionStylesFound[0] as $allStyleAttrib => $allStyleValue)
\r
155 echo '<br/>'.$allStyleAttrib.' = '.$allStyleValue;
\r
159 $textStyles = Array();
\r
161 // add text styles features to caption text styles array
\r
162 if (isset($captionStylesFound[0]))
\r
164 foreach ($captionStylesFound[0] as $txtStyle)
\r
166 //$textStyles[] = $txtStyle;
\r
167 //echo '<br/>'.$txtStyle;
\r
169 //adding only known text styles
\r
170 if ($txtStyle == '{justify:center}')
\r
172 $textStyles['text-align'] = 'center';
\r
173 } else if ($txtStyle == '{justify:left}')
\r
175 $textStyles['text-align'] = 'left';
\r
177 else if ($txtStyle == '{justify:right}')
\r
179 $textStyles['text-align'] = 'right';
\r
181 // adding QT formats
\r
182 //$textStyles['QT'.$txtStyle] = $txtStyle.'-- NOT used yet';
\r
187 // add a capton only if all values are set
\r
189 if (isset($timesIn[$j]) && isset($timesOut[$j]) && isset($captions[$j]))
\r
191 // Create a Caption Object
\r
192 $newCaption = new Caption($timesIn[$j],$timesOut[$j],$captions[$j],$textStyles);
\r
194 // print added caption
\r
195 //echo $newCaption->toString();
\r
197 // add caption object to the collection
\r
198 $myQTextCollection->addCaption($newCaption);
\r
202 echo chr(10).'IN: '.$timesIn[$j];
\r
203 echo chr(10).'OUT: '.$timesOut[$j];
\r
204 echo chr(10).'Caption: '.$captions[$j];
\r
206 //echo chr(10).'Caption: '.$captions[$j];
\r
211 //echo '</textarea></form>';
\r
215 //echo $myQTextCollection->toString();
\r
217 return $myQTextCollection;
\r
219 } // end importCC()
\r
222 * Exports a CaptionCollection object into a string
\r
224 * @param CaptionCollection $theCollection A CaptionCollection Object
\r
225 * @return String $captionString The caption as a String
\r
227 public function exportCC($theCollection)
\r
232 $myCollection = $theCollection->getCollection();
\r
235 $ccExport .= $this->getHeader()."\r\n";
\r
237 foreach ($myCollection as $captionObj)
\r
240 $ccExport .= '['.$captionObj->getInTime().']'."\r\n";
\r
242 // Convert <br/> into \n character
\r
243 $fixCaption = str_replace('<BR />',"\r\n",$captionObj->getCaption());
\r
244 //echo '<br/>'.$fixCaption;
\r
246 // get getTextStyles array from caption object
\r
247 $ccTxtStyles = $captionObj->getTextStyles();
\r
249 //$ccTxtStyles = $this->getDefaultStyles($captionObj->getTextAtribute('text-align'));
\r
251 // check if the caption has text styles
\r
252 if (count($ccTxtStyles)!=0)
\r
254 // loop all txt styles
\r
255 foreach ($ccTxtStyles as $txtAttrib => $txtValue)
\r
257 // HERE parse any known txt style and apply it to the caption
\r
259 // only for text alignment in QT
\r
260 if ($txtValue=='center' || $txtValue=='left' || $txtValue=='right')
\r
262 // get the txt align default values
\r
263 $thisTxtAlign = $this->getDefaultStyles($txtValue,strlen($fixCaption));
\r
264 //echo '<br/>'.$fixCaption;
\r
265 //echo '<br/> Lenght: '.strlen($fixCaption);
\r
267 // add default text styles to the caption
\r
268 $fixCaption = $thisTxtAlign.$fixCaption;
\r
273 } // end if txt styles
\r
275 // add caption(s) to export string
\r
276 //$ccExport .= $fixCaption;
\r
277 $ccExport .= $fixCaption."\r\n";
\r
280 $ccExport .= '['.$captionObj->getOutTime().']'."\r\n";
\r
285 // Remove any doble break line (already done in import string.. but just in case captions lines bring this issue;)
\r
286 //-- $ccExport = str_replace(chr(10).chr(10),chr(10),$ccExport);
\r
290 } // end exportCC()
\r
293 * Verify if the caption file is a QText caption file
\r
295 * @param String $theCCString A caption file as text = string
\r
298 public function checkFormat($theCCString)
\r
302 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText
\r
303 preg_match_all($patternCheck,$theCCString,$patternFound);
\r
305 if(count($patternFound)>0)
\r
312 } // end checkFormat()
\r
315 * Get the name of the Caption Format Class
\r
317 * @return String $captionFormatname The name of the Caption Format
\r
319 public function getName()
\r
321 $captionFormatname = 'Quick Time Text';
\r
323 return $captionFormatname;
\r
327 * Get the Description of the Caption Format
\r
329 * @return String $captionAbout Description of the Caption Format
\r
331 public function getAbout()
\r
333 $captionAbout = 'This format can be used by Quick Time Player.
\r
334 This is the native format of CAPSCRIBE !!!
\r
335 Additional information can be found at <a href="http://www.apple.com/quicktime/tutorials/texttracks.html">Apple Website</a>';
\r
337 return $captionAbout;
\r
343 * Get the version of the caption format class
\r
345 * @return String $theVersion The Version of the Caption Format as String
\r
347 public function getVersion()
\r
349 $theVersion = '1.0';
\r
351 return $theVersion;
\r
354 public function getFileExtension()
\r
356 $theExtension = 'txt';
\r
358 return $theExtension;
\r
361 public function getIdPattern()
\r
363 $idPattern = '/({QTtext})/';
\r
364 //$idPattern = "/({(.*?)})/";
\r
365 //$qtPatternRegEx = "/({(.*?)})/";
\r
370 public function allowsTextStyles()
\r
375 public function template()
\r
378 {QTtext}{font: Comic Sans MS}{italic}{size:18}{textColor: 65280,65280,65280}{backColor: 0,0,0}{justify:center}{timeScale: 1000}{timeStamps:absolute}{keyedtext:on}{language:0}{height:156}{width:383}{textEncoding:0}
\r
393 {QTtext} {font:Tahoma}
\r
396 {width:160} {height:32}
\r
397 {timeStamps:absolute} {language:0}
\r
399 caption 1 - using Bold style?
\r
412 return $ccTemplate;
\r
415 /*////////////////////////////////////////////////////////
\r
416 Functions for QText conversion
\r
417 //////////////////////////////////////////////////////*/
\r
420 * Creates the QText default header.. soon this method will receive all the needed parameters
\r
422 * @return String $myHeader The QText default header
\r
424 private function getHeader()
\r
430 {textColor: 45824,45824,45824}
\r
434 {timeStamps:absolute}
\r
443 $textFont = "Comic Sans MS";
\r
445 $textJustify = "center";
\r
447 // Unique QText header Variables
\r
448 $myHeader = '{QTtext}';
\r
449 $myHeader .= '{font: '.$textFont.'}';
\r
450 //$myHeader .= '{plain}';
\r
451 //$myHeader .= '{size: '.$textSize.'}';
\r
452 $myHeader .= '{textColor: 65280,65280,0}';
\r
453 $myHeader .= '{backColor: 0,0,0}';
\r
454 $myHeader .= '{justify:'.$textJustify.'}';
\r
455 $myHeader .= '{timeScale: 1000}';
\r
456 $myHeader .= '{timeStamps:absolute}';
\r
457 $myHeader .= '{keyedtext:on}'; /// WHAT IS THIS????? FIX ME
\r
458 $myHeader .= '{language:0}'; // working on ...
\r
459 $myHeader .= '{width:114}'; // working on ...
\r
460 $myHeader .= '{height:334}'; // working on ...
\r
461 $myHeader .= '{textEncoding:0}';
\r
462 // ... and much more can be set here acording to QT specification ...
\r
465 {anti-alias: onOrOff }
\r
466 {doNotDisplay: onOrOff }
\r
467 {doNotAutoScale: onOrOff }
\r
470 $myHeader = '{QTtext}{font: Tahoma}{plain}{size:18}{textColor: 45824,45824,45824}{backColor: 0,0,0}{justify:center}{timeScale: 1000}{timeStamps:absolute}{keyedtext:on}{language:0}{height:114}{width:334}{textEncoding:0}';
\r
476 * Sets default QT text styles at the caption level. No text style implemented yet at the word level
\r
477 * @param String $txtAlign The text alignment, (e.g. 'left', 'right') if null assumed center
\r
478 * @return String $myStyles the QText styles to be added before the caption text.
\r
480 private function getDefaultStyles($txtAlign,$txtLength )
\r
482 // {hilitecolor:3000,0,0}{hilite:0,103}{font:Tahoma}{size:18}{textcolor:45824,45824,45824}{backcolor:0,0,0}{justify:center}{plain}(
\r
484 //$myStyles .= '{hilitecolor:3000,0,0}{hilite:0,139}{font:Tahoma}';
\r
485 $myStyles .= '{hilitecolor:3000,0,0}{hilite:0,'.$txtLength.'}{font:Tahoma}{size:18}{backcolor:0,0,0}';
\r
487 if ($txtAlign == 'left')
\r
489 $myStyles .= '{textcolor:65280,55040,18432}{justify:'.$txtAlign.'}';
\r
491 else if ($txtAlign == 'right')
\r
493 $myStyles .= '{textcolor:26112,65280,65280}{justify:'.$txtAlign.'}';
\r
497 $myStyles .= '{textcolor:45824,45824,45824}{justify:center}';
\r
499 // and much more to be added here... !!
\r
502 {plain} Plain text.
\r
504 {italic} Italic text.
\r
505 {underline} Underlined text.
\r
506 {outline} Outlined text.
\r
507 {shadow} Text with a drop shadow.
\r
508 {condense} Text with spacing between characters decreased.
\r
509 {extend} Text with spacing between characters increased.
\r
511 //$myStyles .= '{plain}';
\r
516 } // end classQText
\r