Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

encfiltmgr.cpp

00001 /******************************************************************************
00002  *  swencodingmgr.cpp   - implementaion of class EncodingFilterMgr, subclass of
00003  *                        used to transcode all module text to a requested
00004  *                        encoding.
00005  *
00006  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00007  *      CrossWire Bible Society
00008  *      P. O. Box 2528
00009  *      Tempe, AZ  85280-2528
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by the
00013  * Free Software Foundation version 2.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  */
00021 
00022 #include <encfiltmgr.h>
00023 
00024 #include <scsuutf8.h>
00025 #include <latin1utf8.h>
00026 
00027 #include <unicodertf.h>
00028 #include <utf8latin1.h>
00029 #include <utf8utf16.h>
00030 #include <utf8html.h>
00031 
00032 #include <swmgr.h>
00033 
00034 /******************************************************************************
00035  * EncodingFilterMgr Constructor - initializes instance of EncodingFilterMgr
00036  *
00037  * ENT:
00038  *      enc - Encoding format to emit
00039  */
00040 
00041 EncodingFilterMgr::EncodingFilterMgr (char enc)
00042                    : SWFilterMgr() {
00043 
00044         scsuutf8 = new SCSUUTF8();
00045         latin1utf8 = new Latin1UTF8();
00046 
00047         encoding = enc;
00048 
00049         switch (encoding) {
00050         case ENC_LATIN1:
00051                 targetenc = new UTF8Latin1();
00052                 break;
00053         case ENC_UTF16:
00054                 targetenc = new UTF8UTF16();
00055                 break;
00056         case ENC_RTF:
00057                 targetenc = new UnicodeRTF();
00058                 break;
00059         case ENC_HTML:
00060                 targetenc = new UTF8HTML();
00061                 break;
00062         default: // i.e. case ENC_UTF8
00063                 targetenc = NULL;
00064         }
00065 }
00066 
00067 /******************************************************************************
00068  * EncodingFilterMgr Destructor - Cleans up instance of EncodingFilterMgr
00069  */
00070 EncodingFilterMgr::~EncodingFilterMgr() {
00071         if (scsuutf8)
00072                 delete scsuutf8;
00073         if (latin1utf8)
00074                 delete latin1utf8;
00075         if (targetenc)
00076                 delete targetenc;
00077 }
00078 
00079 void EncodingFilterMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
00080 
00081         ConfigEntMap::iterator entry;
00082 
00083         string encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (string)"";
00084         if (encoding.empty() || !stricmp(encoding.c_str(), "Latin-1")) {
00085                 module->AddRawFilter(latin1utf8);
00086         }
00087         else if (!stricmp(encoding.c_str(), "SCSU")) {
00088                 module->AddRawFilter(scsuutf8);
00089         }
00090 }
00091 
00092 void EncodingFilterMgr::AddEncodingFilters(SWModule *module, ConfigEntMap &section) {
00093         if (targetenc)
00094                 module->AddEncodingFilter(targetenc);
00095 }
00096 
00097 /******************************************************************************
00098  * EncodingFilterMgr::Encoding  - sets/gets encoding
00099  *
00100  * ENT: enc     - new encoding or 0 to simply get the current encoding
00101  *
00102  * RET: encoding
00103  */
00104 char EncodingFilterMgr::Encoding(char enc) {
00105         if (enc && enc != encoding) {
00106                 encoding = enc;
00107                 SWFilter * oldfilter = targetenc;
00108                 
00109                 switch (encoding) {
00110                 case ENC_LATIN1:
00111                         targetenc = new UTF8Latin1();
00112                         break;
00113                 case ENC_UTF16:
00114                         targetenc = new UTF8UTF16();
00115                         break;
00116                 case ENC_RTF:
00117                         targetenc = new UnicodeRTF();
00118                         break;
00119                 case ENC_HTML:
00120                         targetenc = new UTF8HTML();
00121                         break;
00122                 default: // i.e. case ENC_UTF8
00123                         targetenc = NULL;
00124                 }
00125 
00126                 ModMap::const_iterator module;
00127 
00128                 if (oldfilter != targetenc) {
00129                         if (oldfilter) {
00130                                 if (!targetenc) {
00131                                         for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
00132                                                 module->second->RemoveRenderFilter(oldfilter);
00133                                 }
00134                                 else {
00135                                         for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
00136                                                 module->second->ReplaceRenderFilter(oldfilter, targetenc);
00137                                 }
00138                                 delete oldfilter;
00139                         }
00140                         else if (targetenc) {
00141                                 for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
00142                                         module->second->AddRenderFilter(targetenc);
00143                         }
00144                 }
00145 
00146         }
00147         return encoding;
00148 }

Generated on Thu Jun 20 22:12:58 2002 for The Sword Project by doxygen1.2.15