• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ie_exp_HTML_StyleTree.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiWord
00004  * Copyright (C) 1998 AbiSource, Inc.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 #ifndef IE_EXP_HTML_STYLETREE_H
00023 #define IE_EXP_HTML_STYLETREE_H
00024 
00025 #include <string>
00026 
00027 #include "ie_exp_HTML_util.h"
00028 #include "ut_locale.h"
00029 #include "ut_debugmsg.h"
00030 #include "ut_assert.h"
00031 #include "ut_std_string.h"
00032 #include "pt_Types.h"
00033 #include "pl_Listener.h"
00034 #include "pd_Document.h"
00035 #include "pd_Style.h"
00036 #include "pp_AttrProp.h"
00037 #include "pp_Property.h"
00038 #include "pp_PropertyMap.h"
00039 #include "px_ChangeRecord.h"
00040 #include "px_CR_Object.h"
00041 #include "px_CR_Span.h"
00042 #include "px_CR_Strux.h"
00043 
00044 #define IS_TRANSPARENT_COLOR(c) (!strcmp(c, "transparent"))
00045 
00046 #define BT_NORMAL       1
00047 #define BT_HEADING1     2
00048 #define BT_HEADING2     3
00049 #define BT_HEADING3     4
00050 #define BT_BLOCKTEXT    5
00051 #define BT_PLAINTEXT    6
00052 #define BT_NUMBEREDLIST 7
00053 #define BT_BULLETLIST   8
00054 
00055 class ABI_EXPORT IE_Exp_HTML_StyleTree{
00056 private:
00057     PD_Document * m_pDocument; // root element of tree only (atm, anyway)
00058 
00059     IE_Exp_HTML_StyleTree * m_parent;
00060     IE_Exp_HTML_StyleTree ** m_list;
00061 
00062     UT_uint32 m_count;
00063     UT_uint32 m_max;
00064 
00065     bool m_bInUse;
00066 
00067     std::string m_style_name;
00068     std::string m_class_name;
00069     std::string m_class_list;
00070 
00071     typedef std::map<std::string, std::string> map_type;
00072     map_type m_map;
00073 
00074     IE_Exp_HTML_StyleTree(IE_Exp_HTML_StyleTree * parent, const gchar * name, PD_Style * style);
00075 public:
00076     IE_Exp_HTML_StyleTree(PD_Document * pDocument);
00077     ~IE_Exp_HTML_StyleTree();
00078 
00079 private:
00080     bool add(const gchar * style_name, PD_Style * style);
00081 public:
00082     bool add(const gchar * style_name, PD_Document * pDoc);
00083 
00084 private:
00085     void inUse();
00086 public:
00087     const IE_Exp_HTML_StyleTree * findAndUse(const gchar * style_name);
00088 
00089     const IE_Exp_HTML_StyleTree * find(const gchar * style_name) const;
00090     const IE_Exp_HTML_StyleTree * find(PD_Style * style) const;
00091 
00092     bool descends(const gchar * style_name) const;
00093 
00094     template<typename StyleListener>
00095     void print(StyleListener * listener) const;
00096 
00097     const IE_Exp_HTML_StyleTree * operator[] (UT_uint32 i) const {
00098         return (i < m_count) ? m_list[i] : 0;
00099     }
00100 
00101     UT_uint32 count() const {
00102         return m_count;
00103     }
00104 
00105     const std::string& style_name() const {
00106         return m_style_name;
00107     }
00108 
00109     const std::string& class_name() const {
00110         return m_class_name;
00111     }
00112 
00113     const std::string& class_list() const {
00114         return m_class_list;
00115     }
00116 
00117     PD_Document* getDocument() const{
00118         return m_pDocument;
00119     }
00120 
00121     const std::string & lookup(const std::string & prop_name) const;
00122 
00123 };
00124 
00125 class ABI_EXPORT IE_Exp_HTML_StyleListener : public PL_Listener {
00126 public:
00127     IE_Exp_HTML_StyleListener(IE_Exp_HTML_StyleTree *styleTree);
00128 
00129     bool populate(fl_ContainerLayout* sfh,
00130             const PX_ChangeRecord * pcr);
00131 
00132     bool populateStrux(pf_Frag_Strux* sdh,
00133             const PX_ChangeRecord * pcr,
00134             fl_ContainerLayout* * psfh);
00135 
00136     bool change(fl_ContainerLayout* sfh,
00137             const PX_ChangeRecord * pcr);
00138 
00139     bool insertStrux(fl_ContainerLayout* sfh,
00140             const PX_ChangeRecord * pcr,
00141             pf_Frag_Strux* sdh,
00142             PL_ListenerId lid,
00143             void (*pfnBindHandles) (pf_Frag_Strux* sdhNew,
00144             PL_ListenerId lid,
00145             fl_ContainerLayout* sfhNew));
00146 
00147     bool signal(UT_uint32 iSignal);
00148 private:
00149     void styleCheck(PT_AttrPropIndex api);
00150 
00151     IE_Exp_HTML_StyleTree *m_pStyleTree;
00152 };
00153 
00154 template<typename StyleListener>
00155 void IE_Exp_HTML_StyleTree::print(StyleListener * listener) const {
00156     if (!m_bInUse) {
00157         return;
00158     }
00159 
00160     if (strstr(m_style_name.c_str(), "List")) {
00161         return;
00162     }
00163 
00164     if (m_parent) {
00165         std::string selector("*.");
00166         if (!m_class_name.empty()) {
00167             std::string tmp = m_class_name;
00168             tmp = UT_escapeXML(tmp);
00169             selector += tmp;
00170         } else {
00171             if (m_style_name == "Normal")
00172                 selector = "p, h1, h2, h3, li";
00173             else if (m_style_name == "Heading 1")
00174                 selector = "h1";
00175             else if (m_style_name == "Heading 2")
00176                 selector = "h2";
00177             else if (m_style_name == "Heading 3")
00178                 selector = "h3";
00179         }
00180         listener->styleOpen(selector);
00181 
00182         for (map_type::const_iterator iter = m_map.begin();
00183                 iter != m_map.end(); iter++) {
00184             listener->styleNameValue((*iter).first.c_str(),
00185                     (*iter).second.c_str());
00186         }
00187         listener->styleClose();
00188     }
00189     for (UT_uint32 i = 0; i < m_count; i++) {
00190         m_list[i]->print(listener);
00191     }
00192 }
00193 
00194 struct StyleListener {
00195     UT_ByteBuf& m_sink;
00196     std::string m_utf8_0;
00197     UT_uint32 m_styleIndent;
00198 
00199     StyleListener(UT_ByteBuf & sink)
00200     : m_sink(sink), m_styleIndent(0) {
00201     }
00202 
00203     bool get_Compact() {
00204         return false;
00205     }
00206 
00207     void tagRaw(const std::string& content) {
00208         m_sink.append((const UT_Byte*) content.c_str(), content.size());
00209     }
00210 
00211     void styleIndent() {
00212         m_utf8_0 = "";
00213 
00214         for (UT_uint32 i = 0; i < m_styleIndent; i++) {
00215             m_utf8_0 += "\t";
00216         }
00217     }
00218 
00219     void styleOpen(const std::string& rule) {
00220         styleIndent();
00221 
00222         m_utf8_0 += rule + " {";
00223         if (!get_Compact())
00224             m_utf8_0 += MYEOL;
00225 
00226         tagRaw(m_utf8_0);
00227 
00228         m_styleIndent++;
00229     }
00230 
00231     void styleClose() {
00232         if (m_styleIndent == 0) {
00233             UT_DEBUGMSG(("WARNING: CSS style group over-closing!\n"));
00234             return;
00235         }
00236         m_styleIndent--;
00237 
00238         styleIndent();
00239 
00240         m_utf8_0 += "}";
00241         if (!get_Compact())
00242             m_utf8_0 += MYEOL;
00243 
00244         tagRaw(m_utf8_0);
00245     }
00246 
00247     void styleNameValue(const gchar * name, const std::string & value) {
00248         styleIndent();
00249 
00250         m_utf8_0 += name;
00251         m_utf8_0 += ":";
00252         m_utf8_0 += value;
00253         m_utf8_0 += ";";
00254         if (!get_Compact())
00255             m_utf8_0 += MYEOL;
00256 
00257         tagRaw(m_utf8_0);
00258     }
00259 
00260     void styleText(const std::string& content) {
00261         m_utf8_0 = content;
00262         tagRaw(m_utf8_0);
00263     }
00264 };
00265 
00266 #endif

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1