diff --git a/src/FoLiA-abby.cxx b/src/FoLiA-abby.cxx index 9239392..0403971 100644 --- a/src/FoLiA-abby.cxx +++ b/src/FoLiA-abby.cxx @@ -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" @@ -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(); @@ -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, @@ -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; } } } @@ -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( args ); } - if ( fs & ITALIC ){ + if ( fs % font_style::ITALIC ){ folia::KWargs args; args["subset"] = "font_typeface"; args["class"] = "italic"; markup->add_child( args ); } - if ( fs & SMALLCAPS ){ + if ( fs % font_style::SMALLCAPS ){ folia::KWargs args; args["subset"] = "font_typeface"; args["class"] = "smallcaps"; markup->add_child( args ); } - if ( fs & SUPERSCRIPT ){ + if ( fs % font_style::SUPERSCRIPT ){ folia::KWargs args; args["subset"] = "font_typeface"; args["class"] = "superscript"; markup->add_child( 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( 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( args ); } - if ( fs & STRIKEOUT ){ + if ( fs % font_style::STRIKEOUT ){ folia::KWargs args; args["subset"] = "font_typeface"; args["class"] = "strikeout"; @@ -458,7 +439,7 @@ folia::TextMarkupStyle* make_style_content( const formatting_info& info, args["class"] = info._lang; content->add_child( args ); } - if ( style != REGULAR ){ + if ( style != font_style::REGULAR ){ append_styles( content, style ); } if ( !info._ff.empty() ){ @@ -734,14 +715,14 @@ map 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) );