Skip to content

Commit

Permalink
Move markers h h1 h2 h3 to styles v2
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Feb 16, 2025
1 parent 6fa5288 commit 1f0c0c9
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 48 deletions.
50 changes: 28 additions & 22 deletions filter/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,12 @@ 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, ""))) {
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {"h","h1","h2","h3"}))) {
database::styles1::Item style = styles [marker];
note_citations.evaluate_style(style);
switch (style.type) {
case StyleTypeIdentifier:
switch (style.subtype) {
case IdentifierSubtypeRunningHeader: // Todo move to v2
{
const std::string runningHeader = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
runningHeaders.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, runningHeader));
break;
}
case IdentifierSubtypeLongTOC:
{
const std::string longTOC = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
Expand Down Expand Up @@ -314,6 +308,9 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
}
else if (const stylesv2::Style* style {database::styles2::get_marker_data (stylesheet, marker)}; style) {
switch (style->type) {
case stylesv2::Type::starting_boundary:
case stylesv2::Type::none:
break;
case stylesv2::Type::book_id:
{
// Get book number.
Expand All @@ -329,8 +326,15 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
// Done.
break;
}
case stylesv2::Type::starting_boundary:
case stylesv2::Type::none:
case stylesv2::Type::file_encoding:
case stylesv2::Type::remark:
break;
case stylesv2::Type::running_header:
{
const std::string running_header = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
runningHeaders.push_back (filter::text::passage_marker_value (m_current_book_identifier, m_current_chapter_number, m_current_verse_number, marker, running_header));
break;
}
case stylesv2::Type::stopping_boundary:
default:
break;
Expand Down Expand Up @@ -364,7 +368,7 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
const std::string marker = filter::usfm::get_marker (current_item);
// Strip word-level attributes.
if (is_opening_marker) filter::usfm::remove_word_level_attributes (marker, chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, ""))) // Todo
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {}))) // Todo
{
// Deal with a known style.
const database::styles1::Item& style = styles.at(marker);
Expand All @@ -374,16 +378,6 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
{
switch (style.subtype)
{
case IdentifierSubtypeRunningHeader: // Todo move to v2.
{
close_text_style_all();
// This information was processed during the preprocessing stage.
std::string runningHeader = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
// Ideally this information should be inserted in the headers of the standard text document.
// UserBool2RunningHeaderLeft:
// UserBool3RunningHeaderRight:
break;
}
case IdentifierSubtypeLongTOC:
{
close_text_style_all();
Expand Down Expand Up @@ -992,6 +986,9 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
}
else if (const stylesv2::Style* style {database::styles2::get_marker_data (stylesheet, marker)}; style) { // Todo v2
switch (style->type) {
case stylesv2::Type::starting_boundary:
case stylesv2::Type::none:
break;
case stylesv2::Type::book_id:
{
close_text_style_all();
Expand Down Expand Up @@ -1050,8 +1047,17 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
add_to_info (R"(Comment: \)" + marker, true);
break;
}
case stylesv2::Type::starting_boundary:
case stylesv2::Type::none:
case stylesv2::Type::running_header:
{
close_text_style_all();
// This information was processed during the preprocessing stage.
std::string runningHeader = filter::usfm::get_text_following_marker (chapter_usfm_markers_and_text, chapter_usfm_markers_and_text_pointer);
// The running header has properties about wheter to output the running header,
// on the left page, on the right page, or on both.
// This has not been implemented here.
// It were better if this had been implemented.
break;
}
case stylesv2::Type::stopping_boundary:
default:
break;
Expand Down
3 changes: 2 additions & 1 deletion pkgdata/files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
/fonts/Montserrat-SemiBold.ttf
/fonts/SILEOT.ttf
/fonts/SIL-Licenses.txt
/generate
/git
/git/gitflag
/gumbo
Expand Down Expand Up @@ -568,7 +569,6 @@
/read
/read/index.html
/read/index.js
/redirect
/related
/related/ot-quotations-in-nt.xml
/related/parallel-passages-nt.xml
Expand Down Expand Up @@ -624,6 +624,7 @@
/sendreceive
/sendreceive/index.html
/sendreceive/index.js
/server
/session
/session/login.html
/session/login.js
Expand Down
11 changes: 0 additions & 11 deletions styles/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ std::string styles_logic_type_text (int type)
std::string styles_logic_subtype_text (int type, int subtype)
{
if (type == StyleTypeIdentifier) {
if (subtype == IdentifierSubtypeRunningHeader ) return translate ("is a running header"); // Todo out.
if (subtype == IdentifierSubtypeLongTOC ) return translate ("is long table of contents text");
if (subtype == IdentifierSubtypeShortTOC ) return translate ("is short table of contents text");
if (subtype == IdentifierSubtypeBookAbbrev ) return translate ("is the book abbreviation");
Expand Down Expand Up @@ -447,10 +446,6 @@ std::string styles_logic_get_userbool1_text (int function)
// Returns the function of userbool2 for type and subtype
int styles_logic_get_userbool2_function (int type, int subtype)
{
if (type == StyleTypeIdentifier) {
if (subtype == IdentifierSubtypeRunningHeader) // Todo out.
return UserBool2RunningHeaderLeft;
}
if (type == StyleTypeChapterNumber) {
return UserBool2ChapterInLeftRunningHeader;
}
Expand All @@ -464,7 +459,6 @@ std::string styles_logic_get_userbool2_text (int function)
switch (function) {
case UserBool2IdStartsOddPage: return translate ("New page starts with an odd number (not implemented due to limitations in OpenDocument)");
case UserBool2ChapterInLeftRunningHeader: return translate ("Print chapter number in the running header of the left page");
case UserBool2RunningHeaderLeft: return translate ("Print this in the running header of the left page"); // Todo out.
default: return std::string();
}
return std::string();
Expand All @@ -474,10 +468,6 @@ std::string styles_logic_get_userbool2_text (int function)
// Returns the function of userbool3 for type and subtype
int styles_logic_get_userbool3_function (int type, int subtype)
{
if (type == StyleTypeIdentifier) {
if (subtype == IdentifierSubtypeRunningHeader) // Todo out.
return UserBool3RunningHeaderRight;
}
if (type == StyleTypeChapterNumber) {
return UserBool3ChapterInRightRunningHeader;
}
Expand All @@ -490,7 +480,6 @@ std::string styles_logic_get_userbool3_text (int function)
{
switch (function) {
case UserBool3ChapterInRightRunningHeader: return translate ("Print chapter number in the running header of the right page");
case UserBool3RunningHeaderRight: return translate ("Print this in the running header of the right page"); // Todo out.
default: return std::string();
}
return std::string();
Expand Down
3 changes: 0 additions & 3 deletions styles/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#define StyleTypeWordlistElement 13


#define IdentifierSubtypeRunningHeader 3 // Todo out.
#define IdentifierSubtypeLongTOC 4
#define IdentifierSubtypeShortTOC 5
#define IdentifierSubtypeBookAbbrev 6
Expand Down Expand Up @@ -115,12 +114,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#define UserBool2None 0
#define UserBool2IdStartsOddPage 1 // \id: whether to start an odd page number. Not implemented due to limitations in OpenDocument.
#define UserBool2ChapterInLeftRunningHeader 2 // Chapter number (\c): Whether to include it in the left running header.
#define UserBool2RunningHeaderLeft 3 // Running header (\h(#): Whether to include it in the left running header. // Todo out


#define UserBool3None 0
#define UserBool3ChapterInRightRunningHeader 1 // Chapter number (\c): Whether to include it in the right running header.
#define UserBool3RunningHeaderRight 2 // Running header (\h(#): Whether to include it in the right running header. Todo out.


#define UserInt1None 0
Expand Down
29 changes: 29 additions & 0 deletions styles/view2.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ <h1>translate("Style")</h1>
</tr>
<!-- #ENDZONE starts_new_page -->

<!-- #BEGINZONE on_left_page -->
<tr>
<td>translate("Capability")</td>
<td>
<input type="checkbox" name="on_left_page" onchange="checkbox_v2(this, '##sheet##', '##style##')" ##on_left_page## />
translate("Put this on the left page")
</td>
</tr>
<!-- #ENDZONE on_left_page -->

<!-- #BEGINZONE on_right_page -->
<tr>
<td>translate("Capability")</td>
<td>
<input type="checkbox" name="on_right_page" onchange="checkbox_v2(this, '##sheet##', '##style##')" ##on_right_page## />
translate("Put this on the right page")
</td>
</tr>
<!-- #ENDZONE on_right_page -->

<!-- #BEGINZONE deprecated -->
<tr>
<td>translate("Notice")</td>
<td>
translate("This style is deprecated in the current USFM standard")
</td>
</tr>
<!-- #ENDZONE deprecated -->

</table>

<link rel="stylesheet" type="text/css" href="../coloris/coloris.min.css">
Expand Down
75 changes: 69 additions & 6 deletions stylesv2/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ std::string type_enum_to_value (const Type type, const bool describe)
return "file_encoding";
case Type::remark:
return "remark";
case Type::running_header:
if (describe)
return "running header";
return "running_header";
case Type::stopping_boundary:
return "stopping_boundary";
default:
Expand Down Expand Up @@ -70,6 +74,12 @@ std::string property_enum_to_value (const Property property)
return "none";
case Property::starts_new_page:
return "starts_new_page";
case Property::deprecated:
return "deprecated";
case Property::on_left_page:
return "on_left_page";
case Property::on_right_page:
return "on_right_page";
case Property::stopping_boundary:
return "stopping_boundary";
default:
Expand Down Expand Up @@ -98,6 +108,11 @@ Variant property_to_variant (const Property property)
return Variant::none;
case Property::starts_new_page:
return Variant::boolean;
case Property::deprecated:
return Variant::none;
case Property::on_left_page:
case Property::on_right_page:
return Variant::boolean;
case Property::stopping_boundary:
default:
return Variant::none;
Expand Down Expand Up @@ -176,19 +191,65 @@ const std::list<Style> styles {
.properties = {},
.implemented = true,
},
{
.marker = "h",
.type = Type::running_header,
.name = "Running header",
.info = "Running header text for a book.",
.properties = {{Property::on_left_page,true},{Property::on_right_page,true}},
.implemented = true,
},
{
.marker = "h1",
.type = Type::running_header,
.name = "Running header",
.info = "Running header text for a book.",
.properties = {
{Property::on_left_page,true},
{Property::on_right_page,true},
{Property::deprecated,std::monostate()}
},
.implemented = true,
},
{
.marker = "h2",
.type = Type::running_header,
.name = "Left running header",
.info = "Running header text for a book, left page.",
.properties = {
{Property::on_left_page,true},
{Property::on_right_page,false},
{Property::deprecated,std::monostate()}
},
.implemented = true,
},
{
.marker = "h3",
.type = Type::running_header,
.name = "Right running header",
.info = "Running header text for a book, right page.",
.properties = {
{Property::on_left_page,false},
{Property::on_right_page,true},
{Property::deprecated,std::monostate()}
},
.implemented = true,
},
};


// Temporal function that indicates whether a marker has moved to version 2.
// The $marker is the one being considered.
// The $extra is an extra marker in addition to the already implemented ones.
bool marker_moved_to_v2 (const std::string& marker, const char* extra)
bool marker_moved_to_v2 (const std::string& marker, const std::vector<const char*> extra)
{
static std::map<std::string,bool> cache{};
const auto get_key = [&]() {
std::string key {marker};
key.append(" ");
key.append(extra);
if (!extra.empty()) {
key.append(" ");
key.append(std::accumulate(extra.begin(), extra.end(), std::string{}));
}
return key;
};
const std::string key {get_key()};
Expand All @@ -202,9 +263,11 @@ bool marker_moved_to_v2 (const std::string& marker, const char* extra)
return true;
}
}
if (marker == extra) {
cache[key] = true;
return true;
for (const auto bit : extra) {
if (marker == bit) {
cache[key] = true;
return true;
}
}
cache[key] = false;
return false;
Expand Down
Loading

0 comments on commit 1f0c0c9

Please sign in to comment.