filters

pptxml.cc

00001 /*
00002     Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
00003     This file is part of the KDE project
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., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 
00020 DESCRIPTION
00021 */
00022 
00023 #include <pptdoc.h>
00024 #include <pptxml.h>
00025 #include <qobject.h>
00026 #include <KoGlobal.h>
00027 
00028 const int PptXml::s_area = 30512;
00029 
00030 PptXml::PptXml(
00031     const myFile &mainStream,
00032     const myFile &currentUser,
00033     const myFile &pictures):
00034         PptDoc(
00035             mainStream,
00036             currentUser,
00037             pictures)
00038 {
00039     m_isConverted = false;
00040     m_success = false;
00041     m_half = false;
00042     m_y = 0;
00043 }
00044 
00045 PptXml::~PptXml()
00046 {
00047 }
00048 
00049 bool PptXml::convert()
00050 {
00051     if (!m_isConverted)
00052     {
00053        // m_y = 30;
00054         m_success = parse();
00055         m_isConverted = true;
00056     }
00057     return m_success;
00058 }
00059 
00060 void PptXml::encode(QString &text)
00061 {
00062   // When encoding the stored form of text to its run-time form,
00063   // be sure to do the conversion for "&amp;" to "&" first to avoid
00064   // accidentally converting user text into one of the other escape
00065   // sequences.
00066 
00067   text.replace('&', "&amp;");
00068   text.replace('<', "&lt;");
00069   text.replace('>', "&gt;"); // Needed to avoid ]]>
00070 
00071   // Strictly, there is no need to encode " or ', but we do so to allow
00072   // them to co-exist!
00073 
00074   text.replace('"', "&quot;");
00075   text.replace('\'', "&apos;");
00076 }
00077 
00078 const QString PptXml::getXml() const
00079 {
00080     QString body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE DOC>\n"
00081         "<DOC mime=\"application/x-kpresenter\" email=\"reggie@kde.org\" syntaxVersion=\"2\" author=\"Reginald Stadlbauer\" editor=\"Powerpoint import filter\">\n"
00082         " <PAPER ptWidth=\"680\" unit=\"0\" format=\"5\" orientation=\"0\" ptHeight=\"510\">\n"
00083         "  <PAPERBORDERS ptRight=\"0\" ptBottom=\"0\" ptLeft=\"0\" ptTop=\"0\"/>\n"
00084         " </PAPER>\n"
00085         " <BACKGROUND rastX=\"10\" rastY=\"10\" color=\"#ffffff\">\n";
00086     body += m_pages;
00087     body += " </BACKGROUND>\n"
00088         " <HEADER show=\"0\">\n"
00089         "  <ORIG x=\"0\" y=\"0\"/>\n"
00090         "  <SIZE width=\"680\" height=\"20\"/>\n"
00091         "  <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
00092         "  <TEXTOBJ>\n"
00093         "   <P/>\n"
00094         "  </TEXTOBJ>\n"
00095         " </HEADER>\n"
00096         " <FOOTER show=\"0\">\n"
00097         "  <ORIG x=\"0\" y=\"430\"/>\n"
00098         "  <SIZE width=\"680\" height=\"20\"/>\n"
00099         "  <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
00100         "  <TEXTOBJ>\n"
00101         "   <P/>\n"
00102         "  </TEXTOBJ>\n"
00103         " </FOOTER>\n"
00104         " <PAGETITLES>\n";
00105     body += m_titles;
00106     body += " </PAGETITLES>\n"
00107         " <PAGENOTES>\n";
00108     body += m_notes;
00109     body += " </PAGENOTES>\n"
00110         " <OBJECTS>\n";
00111     body += m_text;
00112     body += " </OBJECTS>\n"
00113         " <INFINITLOOP value=\"0\"/>\n"
00114         " <MANUALSWITCH value=\"1\"/>\n"
00115         " <PRESSPEED value=\"1\"/>\n"
00116         " <PRESSLIDES value=\"0\"/>\n"
00117         " <SELSLIDES>\n"
00118         " <SLIDE nr=\"0\" show=\"1\"/>\n"
00119         " </SELSLIDES>\n"
00120         " <PIXMAPS>\n"
00121         " </PIXMAPS>\n"
00122         " <CLIPARTS>\n"
00123         " </CLIPARTS>\n";
00124     body += m_embedded;
00125     body += "</DOC>\n";
00126     //kdDebug(s_area) << body << endl;
00127     return body;
00128 }
00129 
00130 void PptXml::gotDrawing(
00131     unsigned id,
00132     QString type,
00133     unsigned length,
00134     const char *data)
00135 {
00136     QString ourKey;
00137     QString uid;
00138     QString mimeType;
00139     QString filterArgs;
00140 
00141     // Send the picture to the outside world and get back the UID.
00142 
00143     ourKey = "vectorGraphic" + QString::number(id) + "." + type;
00144     if (type == "msod")
00145     {
00146         filterArgs = "shape-id=";
00147         filterArgs += QString::number(id);
00148         filterArgs += ";delay-stream=";
00149         filterArgs += QString::number(0);
00150     }
00151     emit signalSavePart(
00152             ourKey,
00153             uid,
00154             mimeType,
00155             type,
00156             length,
00157             data);
00158 
00159     // Add an entry to the list of embedded objects too. TBD: fix
00160     // RECT and FRAME settings.
00161 if (mimeType != "application/x-kontour")
00162 {
00163     m_embedded += "  <EMBEDDED>\n"
00164                 "<OBJECT url=\"" +
00165                 uid +
00166                 "\" mime=\"" +
00167                 mimeType +
00168                 "\">\n<RECT x=\"30\" y=\"190\" w=\"120\" h=\"80\"/>\n"
00169                 "</OBJECT>\n"
00170                 "<SETTINGS>\n"
00171                 "<EFFECTS effect=\"0\" effect2=\"0\"/>\n"
00172                 "<PEN red=\"0\" green=\"0\" blue=\"0\" width=\"1\" style=\"0\"/>\n"
00173                 "<BRUSH red=\"0\" green=\"0\" blue=\"0\" style=\"0\"/>\n"
00174                 "<PRESNUM value=\"0\"/>\n"
00175                 "<ANGLE value=\"0\"/>\n"
00176                 "<FILLTYPE value=\"0\"/>\n"
00177                 "<GRADIENT red1=\"255\" green1=\"0\" blue1=\"0\" red2=\"0\" green2=\"255\" blue2=\"0\" type=\"1\" unbalanced=\"0\" xfactor=\"100\" yfactor=\"100\"/>\n"
00178                 "<DISAPPEAR effect=\"0\" doit=\"0\" num=\"1\"/>\n"
00179                 "</SETTINGS>\n"
00180                 "  </EMBEDDED>\n";
00181 }
00182 }
00183 
00184 void PptXml::gotSlide(PptSlide &slide)
00185 {
00186     static const unsigned pageHeight = 510;
00187     Q_UINT16 numbOfPholders = 0;
00188         m_pages += "  <PAGE/>\n";
00189     numbOfPholders = slide.getNumberOfPholders();
00190     for(Q_UINT16 i = 0; i < numbOfPholders; i++)
00191     {
00192         slide.gotoPlaceholder(i);
00193         setPlaceholder(slide);
00194     }
00195     m_y += pageHeight;
00196 }
00197 
00198 void PptXml::setPlaceholder(PptSlide &slide)
00199 {
00200     QString xml_friendly;
00201     unsigned i = 0;
00202     bool        bulletedList = false;   //is this a bulleted list?
00203     Q_UINT16    type;               //type of text
00204     QString     x;              //x of placeholder
00205     QString     align;              //align of text
00206     QString     height ;            //height of placeholder
00207     QString     width ;         //width of placeholder
00208     QString     pointSize;          //font size
00209 
00210     xml_friendly = *slide.getPlaceholderText().at(i);
00211     encode(xml_friendly);
00212 
00213     type = slide.getPlaceholderType();
00214     Q_UINT16 y = 0;
00215 
00216     switch (type)
00217     {
00218     case TITLE_TEXT:
00219         y = 30;
00220         height = QString::number(55);
00221         x = QString::number(30);
00222         width = QString::number(610);
00223         align = QString::number(ALIGN_CENTER);
00224         pointSize = QString::number(44);
00225         bulletedList = false;
00226         m_titles += "  <Title title=\"" + xml_friendly + "\" />\n";
00227         break;
00228     case CENTER_TITLE_TEXT:
00229         y = 130;
00230         x = QString::number(45);
00231         height = QString::number(55);
00232         width = QString::number(610);
00233         align = QString::number(ALIGN_CENTER);
00234         pointSize = QString::number(44);
00235         bulletedList = false;
00236         m_titles += "  <Title title=\"" + xml_friendly + "\" />\n";
00237         break;
00238     case CENTER_BODY_TEXT:
00239         y = 200;
00240         x = QString::number(35);
00241         height = QString::number(37);
00242         width = QString::number(610);
00243         align = QString::number(ALIGN_CENTER);
00244         pointSize = QString::number(32);
00245         bulletedList = false;
00246         break;
00247     case NOTES_TEXT:
00248         m_notes += "  <Note note=\"\" />\n";
00249         break;
00250     case BODY_TEXT:
00251         y = 130;
00252         x = QString::number(35);
00253         height = QString::number(268);
00254         width = QString::number(610);
00255         align = QString::number(ALIGN_LEFT);
00256         pointSize = QString::number(28);
00257         bulletedList = true;
00258         break;
00259     case OTHER_TEXT:
00260     case HALF_BODY_TEXT:
00261     case QUARTER_BODY_TEXT:
00262         y = 130;
00263         if(m_half)
00264         {
00265             x = QString::number(335);
00266             width = QString::number(300);
00267             m_half = false;
00268         }
00269         else
00270         {
00271             x = QString::number(30);
00272             width = QString::number(300);
00273             m_half = true;
00274         }
00275         height = QString::number(268);
00276         align = QString::number(ALIGN_LEFT);
00277         pointSize = QString::number(28);
00278         bulletedList = true;
00279         break;
00280     default:
00281         return;
00282         break;
00283     }
00284 
00285         m_text += "<OBJECT type=\"4\">\n"
00286                 " <ORIG x=\""+x+"\" y=\""+QString::number(y + m_y)+"\"/>\n"
00287                 " <SIZE width=\""+width+"\" height=\""+ height +"\"/>\n"
00288                 " <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
00289                 " <TEXTOBJ>\n"
00290                 "  <P align=\""+align+"\">\n";
00291     if(bulletedList)
00292         m_text += "   <COUNTER numberingtype=\"0\" type=\"10\" depth=\"0\" />\n";
00293     m_text += "   <TEXT family=\"utopia\" pointSize=\""+pointSize+"\" color=\"#000000\">";
00294 
00295         for (i = 0; i < slide.getPlaceholderText().count(); i++)
00296         {
00297             xml_friendly = *slide.getPlaceholderText().at(i);
00298             encode(xml_friendly);
00299             m_text += xml_friendly;
00300             if (i < slide.getPlaceholderText().count() - 1)
00301         {
00302                 m_text += "</TEXT>\n"
00303                     "  </P>\n"
00304                         "  <P align=\"1\">\n";
00305             if(bulletedList)
00306                         m_text += "   <COUNTER numberingtype=\"0\" type=\"10\" depth=\"0\" />\n";
00307                 m_text += "   <TEXT family=\"utopia\" pointSize=\""+pointSize+"\" color=\"#000000\">";
00308         }
00309     }
00310         m_text += "</TEXT>\n"
00311             "  </P>\n"
00312                 " </TEXTOBJ>\n"
00313                 "</OBJECT>";
00314 
00315 }
00316 
00317 #include "pptxml.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys