filters

ImportStyle.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Nicolas GOUTTE <goutte@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qfontinfo.h>
00021 
00022 #include <kglobalsettings.h>
00023 #include <kdebug.h>
00024 
00025 #include <KoGlobal.h>
00026 
00027 #include "ImportStyle.h"
00028 
00029 StyleData::StyleData(void): m_level(-1)
00030 {
00031 }
00032 
00033 StyleDataMap::StyleDataMap(void)
00034 {
00035 }
00036 
00037 QString StyleDataMap::getDefaultStyle(void)
00038 {
00039     // We use QFontInfo, as it return real values
00040     QFontInfo fontInfo(KoGlobal::defaultFont());
00041     QString strReturn;
00042 
00043     strReturn += "font-family:";
00044     strReturn += fontInfo.family(); // TODO: should be "Times New Roman"
00045     strReturn += "; font-size: 12pt;";
00046     // Note: the last property must have a semi-colon!
00047 
00048     return strReturn;
00049 }
00050 
00051 void StyleDataMap::defineNewStyleFromOld(const QString& strName, const QString& strOld,
00052     const int level, const QString& strProps)
00053 {
00054     if (strOld.isEmpty())
00055     {
00056         defineNewStyle(strName,level,strProps);
00057         return;
00058     }
00059 
00060     StyleDataMap::Iterator it=find(strOld);
00061     if (it==end())
00062     {
00063         defineNewStyle(strName,level,strProps);
00064     }
00065     else
00066     {
00067         QString strAllProps=it.data().m_props;
00068         strAllProps+=strProps;
00069         defineNewStyle(strName,level,strAllProps);
00070     }
00071 }
00072 
00073 
00074 void StyleDataMap::defineNewStyle(const QString& strName, const int level,
00075     const QString& strProps)
00076 {
00077     // Despite its name, this method can be called multiple times
00078     // We must take care that KWord just gets it only one time.
00079     StyleDataMap::Iterator it=find(strName);
00080     if (it==end())
00081     {
00082         // The style does not exist yet, so we must define it.
00083         it=insert(strName,StyleData());
00084     }
00085     StyleData& styleData=it.data();
00086     styleData.m_level=level;
00087     styleData.m_props+=getDefaultStyle();
00088     if (!strProps.isEmpty())
00089     {
00090         styleData.m_props+=strProps;
00091         styleData.m_props+=";"; // Security if other properties are appended later
00092     }
00093 }
00094 
00095 StyleDataMap::Iterator StyleDataMap::useOrCreateStyle(const QString& strName)
00096 {
00097     // We are using a style but we are not sure if it is defined
00098     StyleDataMap::Iterator it=find(strName);
00099     if (it==end())
00100     {
00101         // The style is not yet defined!
00102         StyleData data;
00103         data.m_level=-1;
00104         data.m_props=getDefaultStyle();
00105         it=insert(strName,data);
00106     }
00107     return it;
00108 }
00109 
00110 void StyleDataMap::defineDefaultStyles(void)
00111 {
00112     // Add a few of AbiWord predefined style sheets
00113     // AbiWord file: src/text/ptbl/xp/pt_PT_Styles.cpp
00114     defineNewStyle("Normal",-1,QString::null);
00115     // TODO: font should be "Arial"
00116     // TODO: "keep with next"
00117     QString strHeading("font-weight: bold; margin-top: 22pt; margin-bottom: 3pt; ");
00118     defineNewStyle("Heading 1",1,strHeading+"font-size: 17pt");
00119     defineNewStyle("Heading 2",2,strHeading+"font-size: 14pt");
00120     defineNewStyle("Heading 3",3,strHeading+"font-size: 12pt");
00121     defineNewStyle("Block Text",-1,"margin-left: 1in; margin-right: 1in; margin-bottom: 6pt");
00122     QFontInfo fixedInfo(KGlobalSettings::fixedFont());
00123     QString strPlainText=QString("font-family: %1")
00124         .arg(fixedInfo.family()); // TODO: should be "Courier New"
00125     kdDebug(30506) << "Plain Text: " << strPlainText << endl;
00126     defineNewStyle("Plain Text",-1,strPlainText);
00127     // TODO: all list and numbered types
00128 }
KDE Home | KDE Accessibility Home | Description of Access Keys