1 /******************************************************************************
2 *
3 * diathekemgr.cpp - DiathekeMgr
4 *
5 * $Id: diathekemgr.cpp 3515 2017-11-01 11:38:09Z scribe $
6 *
7 * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
8 * CrossWire Bible Society
9 * P. O. Box 2528
10 * Tempe, AZ 85280-2528
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation version 2.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 */
22
23 //---------------------------------------------------------------------------
24 #include <swmodule.h>
25
26 #ifdef _ICU_
27 #include <utf8arshaping.h>
28 #include <utf8bidireorder.h>
29 #include <utf8transliterator.h>
30 #endif
31
32 #ifdef WIN32
33 #include <windows.h>
34 #endif
35
36 #include "diathekemgr.h"
37
38 //---------------------------------------------------------------------------
DiathekeMgr(SWConfig * iconfig,SWConfig * isysconfig,bool autoload,char enc,char mark,bool ibidi,bool ishape)39 DiathekeMgr::DiathekeMgr (SWConfig * iconfig, SWConfig * isysconfig, bool autoload, char enc, char mark, bool ibidi, bool ishape)
40 : SWMgr(iconfig, isysconfig, autoload, new DiathekeFilterMgr(mark, enc))
41 {
42 bidi = ibidi;
43 shape = ishape;
44
45 #ifdef _ICU_
46 arshaping = new UTF8arShaping();
47 bidireorder = new UTF8BiDiReorder();
48 transliterator = new UTF8Transliterator();
49 #endif
50 load();
51
52 #ifdef WIN32
53 OSVERSIONINFO osvi;
54 memset (&osvi, 0, sizeof(OSVERSIONINFO));
55 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
56 GetVersionEx(&osvi);
57 platformID = osvi.dwPlatformId;
58 #endif
59
60 }
61
62
~DiathekeMgr()63 DiathekeMgr::~DiathekeMgr()
64 {
65 #ifdef _ICU_
66 if (arshaping)
67 delete arshaping;
68 if (bidireorder)
69 delete bidireorder;
70 if (transliterator)
71 delete transliterator;
72 #endif
73 }
74
75
addRenderFilters(SWModule * module,ConfigEntMap & section)76 void DiathekeMgr::addRenderFilters(SWModule *module, ConfigEntMap §ion)
77 {
78 SWBuf lang;
79 ConfigEntMap::iterator entry;
80
81 lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en";
82
83 #ifdef _ICU_
84 bool rtl;
85 rtl = ((entry = section.find("Direction")) != section.end()) ? ((*entry).second == "RtoL") : false;
86
87 if (shape) {
88 module->addRenderFilter(arshaping);
89 }
90 if (bidi && rtl) {
91 module->addRenderFilter(bidireorder);
92 }
93 #endif
94 SWMgr::addRenderFilters(module, section);
95 }
96
load()97 signed char DiathekeMgr::load() {
98 signed char retval = SWMgr::load();
99 #ifdef _ICU_
100 optionFilters["UTF8Transliterator"] = transliterator;
101 options.push_back(transliterator->getOptionName());
102 #endif
103 return retval;
104 };
105
addGlobalOptionFilters(SWModule * module,ConfigEntMap & section)106 void DiathekeMgr::addGlobalOptionFilters(SWModule *module, ConfigEntMap §ion) {
107
108 SWMgr::addGlobalOptionFilters(module, section);
109 #ifdef _ICU_
110 module->addOptionFilter(transliterator);
111 #endif
112 };
113
114