filters

KWEFUtil.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2001 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qstring.h>
00022 #include <qtextcodec.h>
00023 
00024 #include <KoPageLayout.h>
00025 
00026 #include "KWEFUtil.h"
00027 
00028 QString KWEFUtil::EscapeSgmlText(const QTextCodec* codec,
00029                       const QString& strIn,
00030                       const bool quot /* = false */ ,
00031                       const bool apos /* = false */ )
00032 {
00033     QString strReturn;
00034     QChar ch;
00035 
00036     for (uint i=0; i<strIn.length(); i++)
00037     {
00038         ch=strIn[i];
00039         switch (ch.unicode())
00040         {
00041         case 38: // &
00042             {
00043                 strReturn+="&amp;";
00044                 break;
00045             }
00046         case 60: // <
00047             {
00048                 strReturn+="&lt;";
00049                 break;
00050             }
00051         case 62: // >
00052             {
00053                 strReturn+="&gt;";
00054                 break;
00055             }
00056         case 34: // "
00057             {
00058                 if (quot)
00059                     strReturn+="&quot;";
00060                 else
00061                     strReturn+=ch;
00062                 break;
00063             }
00064         case 39: // '
00065             {
00066                 // NOTE:  HTML does not define &apos; by default (only XML/XHTML does)
00067                 if (apos)
00068                     strReturn+="&apos;";
00069                 else
00070                     strReturn+=ch;
00071                 break;
00072             }
00073         default:
00074             {
00075                 // verify that the character ch can be expressed in the
00076                 //   encoding in which we will write the HTML file.
00077                 if (codec)
00078                 {
00079                     if (!codec->canEncode(ch))
00080                     {
00081                         strReturn+=QString("&#%1;").arg(ch.unicode());
00082                         break;
00083                     }
00084                 }
00085                 strReturn+=ch;
00086                 break;
00087             }
00088         }
00089     }
00090 
00091     return strReturn;
00092 }
00093 
00094 void KWEFUtil::GetNativePaperFormat(const int format,
00095     QString& width, QString& height, QString& units)
00096 // Find data for paper format, as needed for AbiWord and CSS
00097 {
00098     switch (format)
00099     {
00100         // ISO A formats
00101         case PG_DIN_A0: // ISO A0
00102         {
00103             width="84.1"; height="118.0"; units="cm";
00104             break;
00105         }
00106         case PG_DIN_A1: // ISO A1
00107         {
00108             width="59.4"; height="84.1"; units="cm";
00109             break;
00110         }
00111         case PG_DIN_A2: // ISO A2
00112         {
00113             width="42.0"; height="59.4"; units="cm";
00114             break;
00115         }
00116         case PG_DIN_A3: // ISO A3
00117         {
00118             width="29.7"; height="42.0"; units="cm";
00119             break;
00120         }
00121         case PG_DIN_A4: // ISO A4
00122         {
00123             width="21.0"; height="29.7"; units="cm";
00124             break;
00125         }
00126         case PG_DIN_A5: // ISO A5
00127         {
00128             width="14.8"; height="21.0"; units="cm";
00129             break;
00130         }
00131         case PG_DIN_A6: // ISO A6
00132         {
00133             width="10.5"; height="14.8"; units="cm";
00134             break;
00135         }
00136         // ISO B formats
00137         case PG_DIN_B0: // ISO B0
00138         {
00139             width="100.0"; height="141.0"; units="cm";
00140             break;
00141         }
00142         case PG_DIN_B1: // ISO B1
00143         {
00144             width="70.7"; height="100.0"; units="cm";
00145             break;
00146         }
00147         case PG_DIN_B2: // ISO B2
00148         {
00149             width="50.0"; height="70.7"; units="cm";
00150             break;
00151         }
00152         case PG_DIN_B3: // ISO B3
00153         {
00154             width="35.3"; height="50.0"; units="cm";
00155             break;
00156         }
00157         case PG_DIN_B4: // ISO B4
00158         {
00159             width="25.8"; height="35.3"; units="cm";
00160             break;
00161         }
00162         case PG_DIN_B5: // ISO B5
00163         {
00164             width="17.6"; height="25.0"; units="cm";
00165             break;
00166         }
00167         case PG_DIN_B6: // ISO B6
00168         {
00169             width="12.5"; height="17.6"; units="cm";
00170             break;
00171         }
00172         // American formats
00173         case PG_US_LETTER: // US Letter
00174         {
00175             width="8.5"; height="11.0"; units="inch";
00176             break;
00177         }
00178         case PG_US_LEGAL: // US Legal
00179         {
00180             width="8.5"; height="14.0"; units="inch";
00181             break;
00182         }
00183         case PG_US_EXECUTIVE: // US Executive
00184         {
00185             width="7.5"; height="10.0"; units="inch";
00186             break;
00187         }
00188         // Other format not supported yet by AbiWord CVS 2001-04-25)
00189         case PG_DIN_A7: // ISO A7
00190         case PG_DIN_A8: // ISO A8
00191         case PG_DIN_A9: // ISO A9
00192         case PG_DIN_B10: // ISO B10
00193         // Other formats
00194         case PG_SCREEN: // Screen
00195         case PG_CUSTOM: // Custom
00196         default:
00197         {
00198             // TODO
00199             width=QString::null;
00200             height=QString::null;
00201             units=QString::null;
00202             break;
00203         }
00204     }
00205 }
KDE Home | KDE Accessibility Home | Description of Access Keys