Skip to content

Commit

Permalink
update 'enum font_style' to 'enum class font_style'
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Nov 5, 2024
1 parent d922edf commit 16a3d32
Showing 1 changed file with 53 additions and 72 deletions.
125 changes: 53 additions & 72 deletions src/FoLiA-abby.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "ticcutils/zipper.h"
#include "ticcutils/FileUtils.h"
#include "ticcutils/Unicode.h"
#include "ticcutils/enum_flags.h"
#include "ticcutils/CommandLine.h"
#include "libfolia/folia.h"
#include "foliautils/common_code.h"
Expand All @@ -61,93 +62,73 @@ bool keep_hyphens = false;
bool add_breaks = false;
bool add_metrics = false;

enum font_style { REGULAR=0,
ITALIC=1,
BOLD=2,
SMALLCAPS=4,
SUPERSCRIPT=8,
SUBSCRIPT=16,
UNDERLINE=32,
STRIKEOUT=64
enum class font_style { REGULAR=0,
ITALIC=1,
BOLD=2,
SMALLCAPS=4,
SUPERSCRIPT=8,
SUBSCRIPT=16,
UNDERLINE=32,
STRIKEOUT=64
};

inline font_style operator~( font_style f ){
return (font_style)( ~(int)f );
}

inline font_style operator&( font_style f1, font_style f2 ){
return (font_style)((int)f1&(int)f2);
}

inline font_style& operator&=( font_style& f1, font_style f2 ){
f1 = (f1 & f2);
return f1;
}

inline font_style operator|( font_style f1, font_style f2 ){
return (font_style) ((int)f1|(int)f2);
}

inline font_style& operator|=( font_style& f1, font_style f2 ){
f1 = (f1 | f2);
return f1;
}
DEFINE_ENUM_FLAG_OPERATORS(font_style);

font_style stringToMode( const string& s ){
if ( s.empty() ){
return REGULAR;
return font_style::REGULAR;
}
else if ( s == "italic" ){
return ITALIC;
return font_style::ITALIC;
}
else if ( s == "bold" ) {
return BOLD;
return font_style::BOLD;
}
else if ( s == "smallcaps" ) {
return SMALLCAPS;
return font_style::SMALLCAPS;
}
else if ( s == "superscript" ) {
return SUPERSCRIPT;
return font_style::SUPERSCRIPT;
}
else if ( s == "subscript" ) {
return SUBSCRIPT;
return font_style::SUBSCRIPT;
}
else if ( s == "underline" ) {
return UNDERLINE;
return font_style::UNDERLINE;
}
else if ( s == "strikeout" ) {
return STRIKEOUT;
return font_style::STRIKEOUT;
}
else {
cerr << "FoLiA-abby: unsupported Font-Style " << s << " (ignored)" << endl;
return REGULAR;
return font_style::REGULAR;
}
}

string toString( font_style fs ){
if ( fs == REGULAR ){
if ( fs == font_style::REGULAR ){
return "";
}
string result;
if ( fs & ITALIC ){
if ( fs % font_style::ITALIC ){
result += "italic|";
}
if ( fs & BOLD ){
if ( fs % font_style::BOLD ){
result += "bold|";
}
if ( fs & SMALLCAPS ){
if ( fs % font_style::SMALLCAPS ){
result += "smallcaps|";
}
if ( fs & SUPERSCRIPT ){
if ( fs % font_style::SUPERSCRIPT ){
result += "superscript|";
}
if ( fs & SUBSCRIPT ){
if ( fs % font_style::SUBSCRIPT ){
result += "subscript|";
}
if ( fs & UNDERLINE ){
if ( fs % font_style::UNDERLINE ){
result += "underline|";
}
if ( fs & STRIKEOUT ){
if ( fs % font_style::STRIKEOUT ){
result += "strikeout|";
}
result.pop_back();
Expand All @@ -160,7 +141,7 @@ ostream& operator<<( ostream& os, const font_style& fs ){
}
struct formatting_info {
formatting_info():
_fst(REGULAR)
_fst(font_style::REGULAR)
{};
formatting_info( const string& lang,
const string& ff,
Expand Down Expand Up @@ -294,64 +275,64 @@ void update_formatting_info( formatting_info& line_font,
string value = TiCC::getAttribute( node, "bold" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= BOLD;
line_font._fst |= font_style::BOLD;
}
else {
line_font._fst &= ~BOLD;
line_font._fst &= ~font_style::BOLD;
}
}
value = TiCC::getAttribute( node, "italic" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= ITALIC;
line_font._fst |= font_style::ITALIC;
}
else {
line_font._fst &= ~ITALIC;
line_font._fst &= ~font_style::ITALIC;
}
}
value = TiCC::getAttribute( node, "smallcaps" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= SMALLCAPS;
line_font._fst |= font_style::SMALLCAPS;
}
else {
line_font._fst &= ~SMALLCAPS;
line_font._fst &= ~font_style::SMALLCAPS;
}
}
value = TiCC::getAttribute( node, "superscript" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= SUPERSCRIPT;
line_font._fst |= font_style::SUPERSCRIPT;
}
else {
line_font._fst &= ~SUPERSCRIPT;
line_font._fst &= ~font_style::SUPERSCRIPT;
}
}
value = TiCC::getAttribute( node, "subscript" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= SUBSCRIPT;
line_font._fst |= font_style::SUBSCRIPT;
}
else {
line_font._fst &= ~SUBSCRIPT;
line_font._fst &= ~font_style::SUBSCRIPT;
}
}
value = TiCC::getAttribute( node, "strikeout" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= STRIKEOUT;
line_font._fst |= font_style::STRIKEOUT;
}
else {
line_font._fst &= ~STRIKEOUT;
line_font._fst &= ~font_style::STRIKEOUT;
}
}
value = TiCC::getAttribute( node, "underline" );
if ( !value.empty() ){
if ( value == "1" ){
line_font._fst |= UNDERLINE;
line_font._fst |= font_style::UNDERLINE;
}
else {
line_font._fst &= ~UNDERLINE;
line_font._fst &= ~font_style::UNDERLINE;
}
}
}
Expand Down Expand Up @@ -402,45 +383,45 @@ void process_line( xmlNode *block,

void append_styles( folia::TextMarkupStyle* markup,
const font_style& fs ){
if ( fs & BOLD ){
if ( fs % font_style::BOLD ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "bold";
markup->add_child<folia::Feature>( args );
}
if ( fs & ITALIC ){
if ( fs % font_style::ITALIC ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "italic";
markup->add_child<folia::Feature>( args );
}
if ( fs & SMALLCAPS ){
if ( fs % font_style::SMALLCAPS ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "smallcaps";
markup->add_child<folia::Feature>( args );
}
if ( fs & SUPERSCRIPT ){
if ( fs % font_style::SUPERSCRIPT ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "superscript";
markup->add_child<folia::Feature>( args );
markup->settag("token");
}
if ( fs & SUBSCRIPT ){
if ( fs % font_style::SUBSCRIPT ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "subscript";
markup->add_child<folia::Feature>( args );
markup->settag("token");
}
if ( fs & UNDERLINE ){
if ( fs % font_style::UNDERLINE ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "underline";
markup->add_child<folia::Feature>( args );
}
if ( fs & STRIKEOUT ){
if ( fs % font_style::STRIKEOUT ){
folia::KWargs args;
args["subset"] = "font_typeface";
args["class"] = "strikeout";
Expand All @@ -458,7 +439,7 @@ folia::TextMarkupStyle* make_style_content( const formatting_info& info,
args["class"] = info._lang;
content->add_child<folia::TextMarkupLanguage>( args );
}
if ( style != REGULAR ){
if ( style != font_style::REGULAR ){
append_styles( content, style );
}
if ( !info._ff.empty() ){
Expand Down Expand Up @@ -734,14 +715,14 @@ map<string,formatting_info> extract_formatting_info( xmlNode *root ){
string font_id = TiCC::getAttribute( fst, "id" );
string font_ff = TiCC::getAttribute( fst, "ff" );
string font_fs = TiCC::getAttribute( fst, "fs" );
font_style f_s = font_style::REGULAR;
string italic = TiCC::getAttribute( fst, "italic" );
string bold = TiCC::getAttribute( fst, "bold" );
font_style f_s = REGULAR;
if ( italic == "1" ){
f_s = ITALIC;
f_s = font_style::ITALIC;
}
else if ( bold == "1" ){
f_s = BOLD;
f_s = font_style::BOLD;
}
formatting_info fi( font_lang, font_ff, font_fs, f_s );
result.insert( make_pair(font_id,fi) );
Expand Down

0 comments on commit 16a3d32

Please sign in to comment.