• 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., 59 Temple Place - Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #ifndef IE_EXP_HTML_STYLETREE_H
00023 #define IE_EXP_HTML_STYLETREE_H
00024 
00025 #include "ie_exp_HTML_util.h"
00026 #include "ut_locale.h"
00027 #include "ut_debugmsg.h"
00028 #include "ut_assert.h"
00029 #include "ut_string_class.h"
00030 #include "pt_Types.h"
00031 #include "pl_Listener.h"
00032 #include "pd_Document.h"
00033 #include "pd_Style.h"
00034 #include "pp_AttrProp.h"
00035 #include "pp_Property.h"
00036 #include "pp_PropertyMap.h"
00037 #include "px_ChangeRecord.h"
00038 #include "px_CR_Object.h"
00039 #include "px_CR_Span.h"
00040 #include "px_CR_Strux.h"
00041 
00042 #define IS_TRANSPARENT_COLOR(c) (!strcmp(c, "transparent"))
00043 
00044 #define BT_NORMAL       1
00045 #define BT_HEADING1     2
00046 #define BT_HEADING2     3
00047 #define BT_HEADING3     4
00048 #define BT_BLOCKTEXT    5
00049 #define BT_PLAINTEXT    6
00050 #define BT_NUMBEREDLIST 7
00051 #define BT_BULLETLIST   8
00052 
00053 class ABI_EXPORT IE_Exp_HTML_StyleTree{
00054 private:
00055     PD_Document * m_pDocument; // root element of tree only (atm, anyway)
00056 
00057     IE_Exp_HTML_StyleTree * m_parent;
00058     IE_Exp_HTML_StyleTree ** m_list;
00059 
00060     UT_uint32 m_count;
00061     UT_uint32 m_max;
00062 
00063     bool m_bInUse;
00064 
00065     UT_UTF8String m_style_name;
00066     UT_UTF8String m_class_name;
00067     UT_UTF8String m_class_list;
00068 
00069     PD_Style * m_style;
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 UT_UTF8String & style_name() const {
00106         return m_style_name;
00107     }
00108 
00109     const UT_UTF8String & class_name() const {
00110         return m_class_name;
00111     }
00112 
00113     const UT_UTF8String & 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) return;
00157 
00158     if (strstr(m_style_name.utf8_str(), "List")) return;
00159 
00160     if (m_parent) {
00161         UT_UTF8String selector("*.");
00162         if (m_class_name.byteLength()) {
00163             UT_UTF8String tmp = m_class_name;
00164             tmp.escapeXML();
00165             selector += tmp.utf8_str();
00166         } else {
00167             if (m_style_name == "Normal")
00168                 selector = "p, h1, h2, h3, li";
00169             else if (m_style_name == "Heading 1")
00170                 selector = "h1";
00171             else if (m_style_name == "Heading 2")
00172                 selector = "h2";
00173             else if (m_style_name == "Heading 3")
00174                 selector = "h3";
00175         }
00176         listener->styleOpen(selector);
00177 
00178         for (map_type::const_iterator iter = m_map.begin();
00179                 iter != m_map.end(); iter++) {
00180             listener->styleNameValue((*iter).first.c_str(),
00181                     (*iter).second.c_str());
00182         }
00183         listener->styleClose();
00184     }
00185     for (UT_uint32 i = 0; i < m_count; i++) {
00186         m_list[i]->print(listener);
00187     }
00188 }
00189 
00190 struct StyleListener {
00191     UT_ByteBuf& m_sink;
00192     UT_UTF8String m_utf8_0;
00193     UT_uint32 m_styleIndent;
00194 
00195     StyleListener(UT_ByteBuf & sink)
00196     : m_sink(sink), m_styleIndent(0) {
00197     }
00198 
00199     bool get_Compact() {
00200         return false;
00201     }
00202 
00203     void tagRaw(UT_UTF8String & content) {
00204         m_sink.append((const UT_Byte*) content.utf8_str(), content.byteLength());
00205     }
00206 
00207     void styleIndent() {
00208         m_utf8_0 = "";
00209 
00210         for (UT_uint32 i = 0; i < m_styleIndent; i++) m_utf8_0 += "\t";
00211     }
00212 
00213     void styleOpen(const UT_UTF8String & rule) {
00214         styleIndent();
00215 
00216         m_utf8_0 += rule;
00217         m_utf8_0 += " {";
00218         if (!get_Compact())
00219             m_utf8_0 += MYEOL;
00220 
00221         tagRaw(m_utf8_0);
00222 
00223         m_styleIndent++;
00224     }
00225 
00226     void styleClose() {
00227         if (m_styleIndent == 0) {
00228             UT_DEBUGMSG(("WARNING: CSS style group over-closing!\n"));
00229             return;
00230         }
00231         m_styleIndent--;
00232 
00233         styleIndent();
00234 
00235         m_utf8_0 += "}";
00236         if (!get_Compact())
00237             m_utf8_0 += MYEOL;
00238 
00239         tagRaw(m_utf8_0);
00240     }
00241 
00242     void styleNameValue(const gchar * name, const UT_UTF8String & value) {
00243         styleIndent();
00244 
00245         m_utf8_0 += name;
00246         m_utf8_0 += ":";
00247         m_utf8_0 += value;
00248         m_utf8_0 += ";";
00249         if (!get_Compact())
00250             m_utf8_0 += MYEOL;
00251 
00252         tagRaw(m_utf8_0);
00253     }
00254 
00255     void styleText(const UT_UTF8String & content) {
00256         m_utf8_0 = content;
00257         tagRaw(m_utf8_0);
00258     }
00259 };
00260 
00261 #endif

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1