コード例 #1
0
ファイル: text.php プロジェクト: alerque/bibledit
 /**
  * This function does the processing of the USFM code for one note,
  * formatting the document and extracting information.
  */
 private function processNote()
 {
     for (; $this->chapterUsfmMarkersAndTextPointer < count($this->chapterUsfmMarkersAndText); $this->chapterUsfmMarkersAndTextPointer++) {
         $currentItem = $this->chapterUsfmMarkersAndText[$this->chapterUsfmMarkersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($currentItem)) {
             // Flags about the nature of the marker.
             $isOpeningMarker = Filter_Usfm::isOpeningMarker($currentItem);
             $isEmbeddedMarker = Filter_Usfm::isEmbeddedMarker($currentItem);
             // Clean up the marker, so we remain with the basic version, e.g. 'f'.
             $marker = Filter_Usfm::getMarker($currentItem);
             if (array_key_exists($marker, $this->styles)) {
                 $style = $this->styles[$marker];
                 switch ($style['type']) {
                     case StyleTypeVerseNumber:
                         // Verse found. The note should have stopped here. Incorrect note markup.
                         $this->addToFallout("The note did not close at the end of the verse. The text is not correct.", false);
                         break 2;
                     case StyleTypeFootEndNote:
                         switch ($style['subtype']) {
                             case FootEndNoteSubtypeFootnote:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Add space if the paragraph has text already.
                                     if ($this->odf_text_notes) {
                                         if ($this->odf_text_notes->currentParagraphContent != "") {
                                             $this->odf_text_notes->addText(" ");
                                         }
                                     }
                                     // Add the note citation. And a no-break space after it.
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace());
                                     }
                                     // Open note in the web pages.
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote);
                                     }
                                     // Online Bible. Footnotes do not seem to behave as they ought in the Online Bible compiler.
                                     // Just take them out, then.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case FootEndNoteSubtypeEndnote:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker, true);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Open note in the web page.
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote, true);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote, true);
                                     }
                                     // Online Bible.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case FootEndNoteSubtypeStandardContent:
                                 // The style of the standard content is already used in the note's body.
                                 // If means that the text style should be cleared
                                 // in order to return to the correct style for the paragraph.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             case FootEndNoteSubtypeContent:
                             case FootEndNoteSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                 } else {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                 }
                                 break;
                             case FootEndNoteSubtypeParagraph:
                                 // The style of this is not yet implemented.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             default:
                                 break;
                         }
                         // UserBool1NoteAppliesToApocrypha: For xref too?
                         break;
                     case StyleTypeCrossreference:
                         switch ($style['subtype']) {
                             case CrossreferenceSubtypeCrossreference:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerCrossReference]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Add a space if the paragraph has text already.
                                     if ($this->odf_text_notes) {
                                         if ($this->odf_text_notes->currentParagraphContent != "") {
                                             $this->odf_text_notes->addText(" ");
                                         }
                                     }
                                     // Add the note citation. And a no-break space (NBSP) after it.
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace());
                                     }
                                     // Open note in the web page.
                                     $this->ensureNoteParagraphStyle($this->standardContentMarkerCrossReference, $this->styles[$this->standardContentMarkerCrossReference]);
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerCrossReference);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerCrossReference);
                                     }
                                     // Online Bible.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case CrossreferenceSubtypeStandardContent:
                                 // The style of the standard content is already used in the note's body.
                                 // If means that the text style should be cleared
                                 // in order to return to the correct style for the paragraph.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             case CrossreferenceSubtypeContent:
                             case CrossreferenceSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                 } else {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                 }
                                 break;
                             default:
                                 break;
                         }
                         break;
                     default:
                         $this->addToFallout("Marker not suitable in note context \\{$marker}", false);
                         break;
                 }
             } else {
                 // Here is an unknown marker. Add the marker to fallout, plus any text that follows.
                 $this->addToFallout("Unknown marker \\{$marker}", true);
             }
         } else {
             // Here is no marker. Treat it as text.
             if ($this->odf_text_standard) {
                 $this->odf_text_standard->addNoteText($currentItem);
             }
             if ($this->odf_text_notes) {
                 $this->odf_text_notes->addText($currentItem);
             }
             if ($this->html_text_standard) {
                 $this->html_text_standard->addNoteText($currentItem);
             }
             if ($this->html_text_linked) {
                 $this->html_text_linked->addNoteText($currentItem);
             }
         }
     }
     // "Close" the current note, so that any following note text, if malformed,
     // will be added to a new note, not to the last one created.
     if ($this->odf_text_standard) {
         $this->odf_text_standard->closeCurrentNote();
     }
     if ($this->odf_text_notes) {
         $this->odf_text_notes->closeTextStyle(false, false);
     }
     if ($this->html_text_standard) {
         $this->html_text_standard->closeCurrentNote();
     }
     if ($this->html_text_linked) {
         $this->html_text_linked->closeCurrentNote();
     }
     //if ($this->onlinebible_text) $this->onlinebible_text->closeCurrentNote ();
 }