[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: Please review attached patch
From:       Karl-Heinz Zimmer <khz () kde ! org>
Date:       2004-02-01 23:40:33
Message-ID: 200402020040.40693 () postmaster ! bugcops ! org
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sonntag, 1. Februar 2004 20:59, Nicolas Goutte wrote:
(...)
> The problem is DCOP. The DCOP calls are mostly the same as the
> functions. So if the function is not KURL aware, the DCOP call would
> be unaware too, which gives later problems for binary compatibility
> when switching to KURL-aware versions.
>
>
>
> But here you have perhaps another solution (not tested)
>
> bool KPrCanvas::exportPage( int nPage, int nWidth, int nHeight,
>                             const KURL& url,
>                             const char* format,
>                             int quality )
> {
>   bool flag=false;
>   if (url.isLocalFile())
>     flag=exportPage( nPage, nWidth, nHeight, url.path(), format,
> quality ); else
>   {
>     KTempFile temp;
>     temp.setAutoDelete(true);
>     flag=exportPage( nPage, nWidth, nHeight, temp.name(), format,
> quality ); #if KDE_IS_VERSION(3.1.90)
>     KIO::NetAccess::upload( this, temp.name(), url );
> #else
>     KIO::NetAccess::upload( temp.name(), url );
> #endif
>   }
>   return flag;
> }

Thanks for the suggestion, I changes my code accordingly - well, nearly
accordingly only.  It was not so good to use the KURL as DCOP parameter
but I am using it for the internal function now - that's the one that is 
to be called when the user has entered her width/height values in the
yet-to-be-developed size dialog.

Combining internal KURL with external QString allowes the dcop user
to choose whether to specify an url or a normal path.

Please review the attached 5th version of my patch and tell me if it
is OK to commit it.

Note: There is still a bug - but I am sure it is not in my code - since
      the positions of the texts and positions of the other objects in
      the page are correct, but the text-sizes are NOT.

I would prefer to commit my code anyway to get it done, we have to find
the font size bug independently from this - do you agree?

Karl-Heinz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQFAHY53CcaVnbvggDcRAv2dAJ9PgJoF1pHThHwUOq1TGU6/adKWBACghmb5
sfTwShZdpoUwqSclLwKtbcg=
=jmXN
-----END PGP SIGNATURE-----

["kpresenter_exportPage_v5.patch" (text/x-diff)]

Index: KPresenterViewIface.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/KPresenterViewIface.cc,v
retrieving revision 1.54
diff -u -3 -p -r1.54 KPresenterViewIface.cc
--- KPresenterViewIface.cc	3 Jan 2004 06:58:44 -0000	1.54
+++ KPresenterViewIface.cc	1 Feb 2004 23:31:53 -0000
@@ -21,6 +21,8 @@
 #include "KPresenterViewIface.h"
 
 #include "kpresenter_view.h"
+#include "kprcanvas.h"
+#include "kprpage.h"
 #include "kpresenter_doc.h"
 
 #include <kapplication.h>
@@ -587,6 +589,52 @@ void KPresenterViewIface::savePicture()
     view->savePicture();
 }
 
+// note: _nPage is the user visible 1-based page number
+// if 0 < _verbose exportPage() returns the title and notes of the page
+// if not verbose it returns an empty string
+QStringList KPresenterViewIface::exportPage( int _nPage,
+                                             int _nWidth,
+                                             int _nHeight,
+                                             const QString & _fileName,
+                                             const QString & _format,
+                                             int _quality,
+                                             int _verbose )const
+{
+    QStringList res;
+    // we translate the user visible 1-based page number
+    // to KPresenter's internal 0-based page number
+    const int nPage = _nPage-1;
+    if( 0 <= nPage &&
+        view &&
+        view->kPresenterDoc() &&
+        nPage < (int)view->kPresenterDoc()->getPageNums() ){
+        KPrCanvas* canvas = view->getCanvas();
+        if( canvas ){
+            if( canvas->exportPage( nPage,
+                                    QMAX(8, _nWidth),
+                                    QMAX(8, _nHeight),
+                                    KURL::fromPathOrURL( _fileName ),
+                                    _format.isEmpty() ? "PNG" : _format.latin1(),
+                                    QMAX(-1, QMIN(100, _quality))) ){
+                if( 0 < _verbose ){
+                    KPrPage* page = view->kPresenterDoc()->pageList().at( nPage );
+                    if( page ){
+                        // Note: Do not i18n the following strings, they are \
prepared +                        //       to be written to an IndeView page \
information file, +                        //       see http://www.indeview.org for \
details. +                        // Note: We use the 1-based page number as fallback \
page title. +                        res << QString("Name=%1")
+                                .arg( page->pageTitle( QString("Page%1").arg(_nPage) \
) ); +                        res << QString("Notes=%1")
+                                .arg( page->noteText() );
+                    }
+                }
+            }
+        }
+    }
+    return res;
+}
+
 void KPresenterViewIface::insertFile()
 {
     view->insertFile();
Index: KPresenterViewIface.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/KPresenterViewIface.h,v
retrieving revision 1.53
diff -u -3 -p -r1.53 KPresenterViewIface.h
--- KPresenterViewIface.h	27 Aug 2003 14:45:38 -0000	1.53
+++ KPresenterViewIface.h	1 Feb 2004 23:31:53 -0000
@@ -24,6 +24,7 @@
 #include <KoViewIface.h>
 
 #include <qstring.h>
+#include <qstringlist.h>
 
 class KPresenterView;
 
@@ -179,6 +180,16 @@ k_dcop:
     virtual void closeObject();
 
     void savePicture();
+    // note: _nPage is the user visible 1-based page number
+    // if 0 < _verbose exportPage() returns the title and notes of the page
+    // if not verbose it returns an empty string
+    QStringList exportPage( int _nPage,
+                            int _nWidth,
+                            int _nHeight,
+                            const QString & _fileName,
+                            const QString & _format,
+                            int _quality,
+                            int _verbose )const;
     void insertFile();
     void importStyle();
     void backgroundPicture();
Index: kprcanvas.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprcanvas.cc,v
retrieving revision 1.383
diff -u -3 -p -r1.383 kprcanvas.cc
--- kprcanvas.cc	14 Jan 2004 17:02:31 -0000	1.383
+++ kprcanvas.cc	1 Feb 2004 23:31:56 -0000
@@ -2409,6 +2409,60 @@ void KPrCanvas::chPic()
     stickyPage()->chPic(m_view);
 }
 
+bool KPrCanvas::exportPage( int nPage,
+                            int nWidth,
+                            int nHeight,
+                            const KURL& _fileURL,
+                            const char* format,
+                            int quality )
+{
+    bool res = false;
+    const QCursor oldCursor( cursor() );
+    setCursor( waitCursor );
+    QPixmap pix( nWidth, nHeight );
+    drawPageInPix( pix, nPage, 0, true, nWidth, nHeight );
+    if( !pix.isNull() ){
+        // Depending on the desired target size due to rounding
+        // errors during zoom the resulting pixmap *might* be
+        // 1 pixel or 2 pixels wider/higher than desired: we just
+        // remove the additional columns/rows.  This can be done
+        // since KPresenter is leaving a minimal border below/at
+        // the right of the image anyway.
+        const QSize desiredSize(nWidth, nHeight);
+        if( desiredSize != pix.size() )
+            pix.resize( desiredSize );
+        // save the pixmap to the desired file
+        KURL fileURL(_fileURL);
+        if( fileURL.protocol().isEmpty() )
+            fileURL.setProtocol( "file" );
+        const bool bLocalFile = fileURL.isLocalFile();
+        KTempFile* tmpFile = bLocalFile ? NULL : new KTempFile();
+        if( !bLocalFile )
+            tmpFile->setAutoDelete( true );
+        if( bLocalFile || 0 == tmpFile->status() ){
+            QFile file( bLocalFile ? fileURL.path(0) : tmpFile->name() );
+            if ( file.open( IO_ReadWrite ) ) {
+                res = pix.save( &file, format, quality );
+                file.close();
+            }
+            if( !bLocalFile ){
+                if( res ){
+#if KDE_IS_VERSION(3,1,90)
+                    res = KIO::NetAccess::upload( this, tmpFile->name(), fileURL );
+#else
+                    res = KIO::NetAccess::upload( tmpFile->name(), fileURL, this );
+#endif
+                }
+            }
+        }
+        if( !bLocalFile ){
+            delete tmpFile;
+        }
+    }
+    setCursor( oldCursor );
+    return res;
+}
+
 void KPrCanvas::savePicture()
 {
     bool state=m_activePage->savePicture( m_view);
@@ -3263,14 +3317,46 @@ bool KPrCanvas::isOneObjectSelected() co
 
 // This one is used to generate the pixmaps for the HTML presentation,
 // for the pres-structure-dialog, for the sidebar previews, for template icons.
-void KPrCanvas::drawPageInPix( QPixmap &_pix, int pgnum, int zoom, bool \
forceRealVariableValue ) +// Set forceWidth and/or forceHeight to override the zoom \
factor +// and obtain a pixmap of the specified width and/or height.
+// By omitting one of them you make sure that the aspect ratio
+// of your page is used for the resulting image.
+void KPrCanvas::drawPageInPix( QPixmap &_pix, int pgnum, int zoom,
+                               bool forceRealVariableValue,
+                               int forceWidth,
+                               int forceHeight )
 {
     //kdDebug(33001) << "Page::drawPageInPix" << endl;
     currPresPage = pgnum + 1;
 
-    int oldZoom = m_view->kPresenterDoc()->zoomHandler()->zoom();
+    KPresenterDoc *doc = m_view->kPresenterDoc();
+    int oldZoom = doc->zoomHandler()->zoom();
     bool oldDisplayFieldValue = false;
-    m_view->zoomDocument(zoom);
+    
+    if( 0 < forceWidth || 0 < forceHeight )
+    {
+        const QRect rect( doc->getPageRect( true ) );
+        const double dRectHeight = static_cast<double>(rect.height());
+        const double dRectWidth  = static_cast<double>(rect.width());
+        double dForceHeight      = static_cast<double>(forceHeight);
+        double dForceWidth       = static_cast<double>(forceWidth);
+        
+        // adjust width or height, in case one of them is missing
+        if( 0 >= forceWidth )
+            dForceWidth = dForceHeight * dRectWidth / dRectHeight;
+        else if( 0 >= forceHeight )
+            dForceHeight = dForceWidth * dRectHeight / dRectWidth;
+        
+        // set the stretching values
+        doc->zoomHandler()->setResolution( dForceWidth / dRectWidth,
+                                           dForceHeight / dRectHeight );
+        // As of yet (Feb. 2004) the following call results
+        // in a NOP but be prepared for the future...
+        doc->newZoomAndResolution( false, false );
+    }else{
+        m_view->zoomDocument(zoom);
+    }
+    
     if ( forceRealVariableValue )
     {
         oldDisplayFieldValue = \
m_view->kPresenterDoc()->getVariableCollection()->variableSetting()->displayFieldCode();
 @@ -3311,7 +3397,6 @@ void KPrCanvas::drawPageInPix( QPixmap &
     //draw sticky object
     //the numbers for the sticky page have to be recalculated
     KPrPage* saveActivePage = m_activePage;
-    KPresenterDoc *doc = m_view->kPresenterDoc();
     doc->displayActivePage( doc->pageList().at( currPresPage-1 ) );
     setActivePage(doc->pageList().at( currPresPage - 1 ) );
     //setActivePage(m_view->kPresenterDoc()->pageList().at(currPresPage-1));
Index: kprcanvas.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprcanvas.h,v
retrieving revision 1.147
diff -u -3 -p -r1.147 kprcanvas.h
--- kprcanvas.h	14 Jan 2004 17:02:31 -0000	1.147
+++ kprcanvas.h	1 Feb 2004 23:31:56 -0000
@@ -148,12 +148,29 @@ public:
     void setAutoForm( const QString &_autoform )
         { autoform = _autoform; }
 
-    void drawPageInPix( QPixmap&, int pgnum, int zoom, bool forceRealVariableValue = \
                false );
-
+    // Set forceWidth and/or forceHeight to override the zoom factor
+    // and obtain a pixmap of the specified width and/or height.
+    // By omitting one of them you make sure that the aspect ratio
+    // of your page is used for the resulting image.
+    void drawPageInPix( QPixmap&, int pgnum, int zoom,
+                        bool forceRealVariableValue = false,
+                        int forceWidth  = 0,
+                        int forceHeight = 0 );
+
+    // Try to export a page by using a QPixmap::save() call.
+    // note: _nPage is the internal 0-based page number
+    // returns: true is the page was saved successfully.
+    // example:
+    //   exportPage( 0, s, 800, 600, "/home/khz/page0.png", "PNG", 100 );
+    bool exportPage( int nPage, int nWidth, int nHeight,
+                     const KURL& fileURL,
+                     const char* format,
+                     int quality = -1 );
+    
     void gotoPage( int pg );
 
     KPrPage* activePage() const;
-
+    
     bool oneObjectTextExist() const;
     bool oneObjectTextSelected() const;
     bool isOneObjectSelected() const;



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic