Skip to content

Commit

Permalink
Modernized converters, support for export \ca markup
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Feb 21, 2025
1 parent 012e2ae commit 8d9cae9
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 188 deletions.
84 changes: 57 additions & 27 deletions filter/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
std::string marker = filter::strings::trim (currentItem); // Change, e.g. '\id ' to '\id'.
marker = marker.substr (1); // Remove the initial backslash, e.g. '\id' becomes 'id'.
if (filter::usfm::is_opening_marker (marker)) {
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {"vp"}))) // Todo
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {"ca"}))) // Todo
{
database::styles1::Item style = styles [marker];
note_citations.evaluate_style(style);
Expand Down Expand Up @@ -315,7 +315,7 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
{
// Store the chapter label for this book and chapter.
const std::string chapter_label = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
chapterLabels.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, chapter_label));
chapter_labels.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, chapter_label));
// If a chapter label is in the book, there's no drop caps output of the chapter number.
book_has_chapter_label [m_current_book_identifier] = true;
// Done.
Expand All @@ -324,7 +324,13 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
case stylesv2::Type::published_chapter_marker:
{
const std::string published_chapter_marker = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
publishedChapterMarkers.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, published_chapter_marker));
published_chapter_markers.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, published_chapter_marker));
break;
}
case stylesv2::Type::alternate_chapter_number:
{
const std::string alternate_chapter_number = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
alternate_chapter_numbers.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, alternate_chapter_number));
break;
}
case stylesv2::Type::published_verse_marker:
Expand All @@ -333,7 +339,7 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
// The marker looks like: ... \vp ၁။\vp* ...
// It stores this markup in the object for later reference.
const std::string published_verse_marker = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
publishedVerseMarkers.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, published_verse_marker));
published_verse_markers.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, published_verse_marker));
break;
}
case stylesv2::Type::stopping_boundary: // Todo
Expand Down Expand Up @@ -461,33 +467,48 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
}
case StyleTypeChapterNumber:
{
if (odf_text_standard) odf_text_standard->close_text_style (false, false);
if (odf_text_text_only) odf_text_text_only->close_text_style (false, false);
if (odf_text_text_and_note_citations) odf_text_text_and_note_citations->close_text_style (false, false);
if (odf_text_notes) odf_text_notes->close_text_style (false, false);
if (html_text_standard) html_text_standard->close_text_style (false, false);
if (html_text_linked) html_text_linked->close_text_style (false, false);

if (onlinebible_text) onlinebible_text->storeData ();
if (odf_text_standard)
odf_text_standard->close_text_style (false, false);
if (odf_text_text_only)
odf_text_text_only->close_text_style (false, false);
if (odf_text_text_and_note_citations)
odf_text_text_and_note_citations->close_text_style (false, false);
if (odf_text_notes)
odf_text_notes->close_text_style (false, false);
if (html_text_standard)
html_text_standard->close_text_style (false, false);
if (html_text_linked)
html_text_linked->close_text_style (false, false);
if (onlinebible_text)
onlinebible_text->storeData ();

// Get the chapter number.
std::string usfm_c_fragment = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
int chapter_number = filter::strings::convert_to_int (usfm_c_fragment);

// Update this object.
m_current_chapter_number = chapter_number;
m_current_chapter_number = filter::strings::convert_to_int (usfm_c_fragment);
set_to_zero(m_current_verse_number);

// If there is a published chapter character, the chapter number takes that value.
for (const auto& published_chapter_marker : publishedChapterMarkers) {
for (const auto& published_chapter_marker : published_chapter_markers) {
if (published_chapter_marker.m_book == m_current_book_identifier) {
if (published_chapter_marker.m_chapter == m_current_chapter_number) {
usfm_c_fragment = published_chapter_marker.m_value;
chapter_number = filter::strings::convert_to_int (usfm_c_fragment);
}
}
}

// If there's an alternate chapter number, append this to the chapter number fragment.
for (const auto& alternate_chapter_number : alternate_chapter_numbers) {
if (alternate_chapter_number.m_book == m_current_book_identifier) {
if (alternate_chapter_number.m_chapter == m_current_chapter_number) {
usfm_c_fragment.append(" (");
usfm_c_fragment.append (alternate_chapter_number.m_value);
usfm_c_fragment.append(")");
}
}
}

// Enter text for the running headers.
std::string running_header = database::books::get_english_from_id (static_cast<book_id>(m_current_book_identifier));
for (const auto& item : runningHeaders) {
Expand Down Expand Up @@ -527,13 +548,13 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
// (usually done if numbers are being presented as words, not numerals).
std::string labelEntireBook {};
std::string labelCurrentChapter {};
for (const auto& pchapterLabel : chapterLabels) {
if (pchapterLabel.m_book == m_current_book_identifier) {
if (pchapterLabel.m_chapter == 0) {
labelEntireBook = pchapterLabel.m_value;
for (const auto& chapter_label : chapter_labels) {
if (chapter_label.m_book == m_current_book_identifier) {
if (chapter_label.m_chapter == 0) {
labelEntireBook = chapter_label.m_value;
}
if (pchapterLabel.m_chapter == m_current_chapter_number) {
labelCurrentChapter = pchapterLabel.m_value;
if (chapter_label.m_chapter == m_current_chapter_number) {
labelCurrentChapter = chapter_label.m_value;
}
}
}
Expand Down Expand Up @@ -638,7 +659,7 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
m_current_verse_number = v_number;
// In case there was a published verse marker, use that markup for publishing.
std::string v_vp_number = v_number;
for (const auto& publishedVerseMarker : publishedVerseMarkers) {
for (const auto& publishedVerseMarker : published_verse_markers) {
if (publishedVerseMarker.m_book == m_current_book_identifier) {
if (publishedVerseMarker.m_chapter == m_current_chapter_number) {
if (publishedVerseMarker.m_verse == m_current_verse_number) {
Expand Down Expand Up @@ -996,10 +1017,19 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
case stylesv2::Type::published_chapter_marker:
{
close_text_style_all();
// This information already went into the Info document. Remove it from the USFM stream.
// This information already is preprocessed. Remove it from the USFM stream.
filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
break;
}
case stylesv2::Type::alternate_chapter_number:
{
close_text_style_all();
if (is_opening_marker) {
// This information is already in the object.
// Remove it from the USFM stream at the opening marker.
filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
}
}
case stylesv2::Type::published_verse_marker:
{
close_text_style_all();
Expand Down Expand Up @@ -1407,13 +1437,13 @@ void Filter_Text::produceInfoDocument (std::string path)

// Chapter specials.
information.new_heading1 (translate("Publishing chapter labels"));
for (const auto& item : chapterLabels) {
for (const auto& item : chapter_labels) {
const std::string line = database::books::get_english_from_id (static_cast<book_id>(item.m_book)) + " (USFM " + item.m_marker + ") => " + item.m_value;
information.new_paragraph ();
information.add_text (line);
}
information.new_heading1 (translate("Publishing alternate chapter numbers"));
for (const auto& item : publishedChapterMarkers) {
information.new_heading1 (translate("Publishing chapter markers"));
for (const auto& item : published_chapter_markers) {
const std::string line = database::books::get_english_from_id (static_cast<book_id>(item.m_book)) + " (USFM " + item.m_marker + ") => " + item.m_value;
information.new_paragraph ();
information.add_text (line);
Expand Down
14 changes: 6 additions & 8 deletions filter/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

namespace filter::text {

class passage_marker_value
struct passage_marker_value
{
public:
passage_marker_value (int book, int chapter, std::string verse, std::string marker, std::string value);
int m_book {0};
int m_chapter {0};
Expand Down Expand Up @@ -116,12 +115,11 @@ class Filter_Text
std::vector <filter::text::passage_marker_value> bookAbbreviations {};

public:
// Vector with objects (book, chapter, verse, marker, label value).
std::vector <filter::text::passage_marker_value> chapterLabels {};
// Vector with object (book, chapter, verse, marker, marker value).
std::vector <filter::text::passage_marker_value> publishedChapterMarkers {};
// Vector with object (book, chapter, verse, marker, marker value).
std::vector <filter::text::passage_marker_value> publishedVerseMarkers {};
// The following four containers are vectors of object (book, chapter, verse, marker, label value).
std::vector <filter::text::passage_marker_value> chapter_labels {};
std::vector <filter::text::passage_marker_value> published_chapter_markers {};
std::vector <filter::text::passage_marker_value> alternate_chapter_numbers {};
std::vector <filter::text::passage_marker_value> published_verse_markers {};
private:
// std::string holding the chapter number or text to output at the first verse.
std::string m_output_chapter_text_at_first_verse {};
Expand Down
51 changes: 9 additions & 42 deletions stylesv2/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ const std::list<Style> styles {
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#cp",
},
{
.marker = "ca",
.type = Type::alternate_chapter_number,
.name = "Alternate chapter number",
.info = "Second or alternate chapter number. For coding dual versification. Useful for places where different traditions of chapter breaks need to be supported in the same translation.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#ca-ca",
},
{
.marker = "vp",
.type = Type::published_verse_marker,
Expand All @@ -320,48 +329,6 @@ const std::list<Style> styles {
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#vp-vp",
},
{
.marker = "ca",
.type = Type::alternate_chapter_number,
.name = "Alternate chapter number",
.info = "Second or alternate chapter number. For coding dual versification. Useful for places where different traditions of chapter breaks need to be supported in the same translation.",
.properties = {},
.implemented = false,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#ca-ca",
},

// /* name */ "",
// /* info */ "",
// /* category */ "cv",
// /* type */ 0,
// /* subtype */ 4,
// /* fontsize */ 16,
// /* italic */ 0,
// /* bold */ 1,
// /* underline */ 0,
// /* smallcaps */ 0,
// /* superscript */ 0,
// /* justification */ 0,
// /* spacebefore */ 0,
// /* spaceafter */ 0,
// /* leftmargin */ 0,
// /* rightmargin */ 0,
// /* firstlineindent */ 0,
// /* spancolumns */ 0,
// /* color */ "#000000",
// /* print */ 1,
// /* userbool1 */ 0,
// /* userbool2 */ 0,
// /* userbool3 */ 0,
// /* userint1 */ 20,
// /* userint2 */ 0,
// /* userint3 */ 0,
// /* userstring1 */ "",
// /* userstring2 */ "",
// /* userstring3 */ "",
// /* backgroundcolor */ "#FFFFFF",
// },

};


Expand Down
Loading

0 comments on commit 8d9cae9

Please sign in to comment.