Ejemplo n.º 1
0
 private function process()
 {
     $this->markersAndTextPointer = 0;
     $markersAndTextCount = count($this->markersAndText);
     for ($this->markersAndTextPointer = 0; $this->markersAndTextPointer < $markersAndTextCount; $this->markersAndTextPointer++) {
         $currentItem = $this->markersAndText[$this->markersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($currentItem)) {
             // Store indicator whether the marker is an opening marker.
             $isOpeningMarker = Filter_Usfm::isOpeningMarker($currentItem);
             $isEmbeddedMarker = Filter_Usfm::isEmbeddedMarker($currentItem);
             // Clean up the marker, so we remain with the basic version, e.g. 'id'.
             $marker = Filter_Usfm::getMarker($currentItem);
             if (array_key_exists($marker, $this->styles)) {
                 $style = $this->styles[$marker];
                 switch ($style['type']) {
                     case StyleTypeIdentifier:
                     case StyleTypeNotUsedComment:
                     case StyleTypeNotUsedRunningHeader:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypeStartsParagraph:
                         $this->closeTextStyle(false, false);
                         $this->newParagraph($marker);
                         break;
                     case StyleTypeInlineText:
                         if ($isOpeningMarker) {
                             $this->openTextStyle($style, false, $isEmbeddedMarker);
                         } else {
                             $this->closeTextStyle(false, $isEmbeddedMarker);
                         }
                         break;
                     case StyleTypeChapterNumber:
                         $this->closeTextStyle(false, false);
                         $this->newParagraph($marker);
                         break;
                     case StyleTypeVerseNumber:
                         // Close any existing text style.
                         $this->closeTextStyle(false, false);
                         // Output the space before the verse number in case the paragraph already has some text.
                         if ($this->currentParagraphContent != "") {
                             $this->addText(" ");
                         }
                         // Open verse style, record verse/length, add verse number, close style again, and add a space.
                         $this->openTextStyle($style, false, false);
                         $textFollowingMarker = Filter_Usfm::getTextFollowingMarker($this->markersAndText, $this->markersAndTextPointer);
                         $number = Filter_Usfm::peekVerseNumber($textFollowingMarker);
                         $this->verseStartOffsets[intval($number)] = $this->textLength;
                         $this->addText($number);
                         $this->closeTextStyle(false, false);
                         $this->addText(" ");
                         // If there was any text following the \v marker, remove the verse number,
                         // put the remainder back into the object, and update the pointer.
                         if ($textFollowingMarker != "") {
                             $pos = strpos($textFollowingMarker, $number);
                             if ($pos !== false) {
                                 $textFollowingMarker = substr($textFollowingMarker, $pos + strlen($number));
                             }
                             $textFollowingMarker = ltrim($textFollowingMarker);
                             $this->markersAndText[$this->markersAndTextPointer] = $textFollowingMarker;
                             $this->markersAndTextPointer--;
                         }
                         break;
                     case StyleTypeFootEndNote:
                         switch ($style['subtype']) {
                             case FootEndNoteSubtypeFootnote:
                             case FootEndNoteSubtypeEndnote:
                                 $this->closeTextStyle(false, false);
                                 if ($isOpeningMarker) {
                                     $this->noteOpened = true;
                                     $caller = $this->noteCount % 9 + 1;
                                     $this->addNote($caller, $marker, false);
                                 } else {
                                     $this->closeCurrentNote();
                                     $this->noteOpened = false;
                                 }
                                 break;
                             case FootEndNoteSubtypeStandardContent:
                             case FootEndNoteSubtypeContent:
                             case FootEndNoteSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     $this->openTextStyle($style, true, $isEmbeddedMarker);
                                 } else {
                                     $this->closeTextStyle(true, $isEmbeddedMarker);
                                 }
                                 break;
                             case FootEndNoteSubtypeParagraph:
                             default:
                                 $this->closeTextStyle(false, false);
                                 break;
                         }
                         break;
                     case StyleTypeCrossreference:
                         switch ($style['subtype']) {
                             case CrossreferenceSubtypeCrossreference:
                                 $this->closeTextStyle(false, false);
                                 if ($isOpeningMarker) {
                                     $this->noteOpened = true;
                                     $caller = $this->noteCount % 9 + 1;
                                     $this->addNote($caller, $marker, false);
                                 } else {
                                     $this->closeCurrentNote();
                                     $this->noteOpened = false;
                                 }
                                 break;
                             case CrossreferenceSubtypeContent:
                             case CrossreferenceSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     $this->openTextStyle($style, true, $isEmbeddedMarker);
                                 } else {
                                     $this->closeTextStyle(true, $isEmbeddedMarker);
                                 }
                                 break;
                             case CrossreferenceSubtypeStandardContent:
                             default:
                                 // The style of the standard content is already used in the note's body.
                                 // Clear the text style to get the correct style for the note paragraph.
                                 $this->closeTextStyle(false, false);
                                 break;
                         }
                         break;
                     case StyleTypePeripheral:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypePicture:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypePageBreak:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypeTableElement:
                         $this->closeTextStyle(false, false);
                         switch ($style['subtype']) {
                             case TableElementSubtypeRow:
                                 $this->outputAsIs($marker, $isOpeningMarker);
                                 break;
                             case TableElementSubtypeHeading:
                             case TableElementSubtypeCell:
                                 $this->openTextStyle($style, false, false);
                                 break;
                             default:
                                 $this->openTextStyle($style, false, false);
                                 break;
                         }
                         break;
                     case StyleTypeWordlistElement:
                         if ($isOpeningMarker) {
                             $this->openTextStyle($style, false, false);
                         } else {
                             $this->closeTextStyle(false, false);
                         }
                         break;
                     default:
                         // This marker is known in the stylesheet, but not yet implemented here.
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                 }
             } else {
                 // This is a marker unknown in the stylesheet.
                 $this->closeTextStyle(false, false);
                 $this->outputAsIs($marker, $isOpeningMarker);
             }
         } else {
             // Here is no marker. Treat it as text.
             if ($this->noteOpened) {
                 $this->addNoteText($currentItem);
             } else {
                 $this->addText($currentItem);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * This function adds a string to the Fallout array, prefixed by the current passage.
  * $text: String to add to the Fallout array.
  * $next: If true, it also adds the text following the marker to the fallout,
  * and removes this text from the USFM input stream.
  */
 private function addToFallout($text, $next = false)
 {
     $text = $this->getCurrentPassageText() . " " . $text;
     if ($next) {
         $text .= " " . Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
     }
     $this->fallout[] = $text;
 }
Ejemplo n.º 3
0
 public static function peekTextFollowingMarker($usfm, $pointer)
 {
     return Filter_Usfm::getTextFollowingMarker($usfm, $pointer);
 }