~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/scimgdataloader_pdf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2007-08-11 17:41:51 UTC
  • mfrom: (0.1.1 upstream) (4.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20070811174151-tmkgjvjuc0mtk8ul
Tags: 1.3.4.dfsg+svn20071115-1
* Upstream svn update (Closes: #447480, #448949).
* debian/NEWS: Added a note for users wanting stable Scribus to switch to
  the "scribus" package (Closes: #427638).
* debian/watch: Updated the watch regex to properly track sourceforge
  releases for this branch (Closes: #449700).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
 
3
to the COPYING file provided with the program. Following this notice may exist
 
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
 
5
for which a new license (GPL+exception) is in place.
 
6
*/
 
7
#include <qfile.h>
 
8
#include <qfileinfo.h>
 
9
#include "gsutil.h"
 
10
#include "scpaths.h"
 
11
#include "scribuscore.h"
 
12
#include "scimgdataloader_pdf.h"
 
13
 
 
14
ScImgDataLoader_PDF::ScImgDataLoader_PDF(void) : ScImgDataLoader()
 
15
{
 
16
        initSupportedFormatList();
 
17
}
 
18
 
 
19
void ScImgDataLoader_PDF::initSupportedFormatList(void)
 
20
{
 
21
        m_supportedFormats.clear();
 
22
        m_supportedFormats.append( "pdf" );
 
23
}
 
24
 
 
25
void ScImgDataLoader_PDF::loadEmbeddedProfile(const QString& fn)
 
26
{
 
27
        m_embeddedProfile.resize(0);
 
28
        m_profileComponents = 0;
 
29
}
 
30
 
 
31
bool ScImgDataLoader_PDF::loadPicture(const QString& fn, int gsRes, bool /*thumbnail*/)
 
32
{
 
33
        QStringList args;
 
34
        if (!QFile::exists(fn))
 
35
                return false;
 
36
        QString tmpFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "sc.png");
 
37
        QString picFile = QDir::convertSeparators(fn);
 
38
        float xres = gsRes;
 
39
        float yres = gsRes;
 
40
 
 
41
        initialize();
 
42
        m_imageInfoRecord.type = 4;
 
43
        m_imageInfoRecord.exifDataValid = false;
 
44
        args.append("-r"+QString::number(gsRes));
 
45
        args.append("-sOutputFile="+tmpFile);
 
46
        args.append("-dFirstPage=1");
 
47
        args.append("-dLastPage=1");
 
48
        args.append(picFile);
 
49
        int retg = callGS(args);
 
50
        if (retg == 0)
 
51
        {
 
52
                m_image.load(tmpFile);
 
53
                unlink(tmpFile);
 
54
                m_image.setAlphaBuffer(true);
 
55
                if (ScCore->havePNGAlpha() != 0)
 
56
                {
 
57
                        for( int yi=0; yi < m_image.height(); ++yi )
 
58
                        {
 
59
                                QRgb *s = (QRgb*)(m_image.scanLine( yi ));
 
60
                                for(int xi=0; xi < m_image.width(); ++xi )
 
61
                                {
 
62
                                        if((*s) == 0xffffffff)
 
63
                                                (*s) &= 0x00ffffff;
 
64
                                        s++;
 
65
                                }
 
66
                        }
 
67
                }
 
68
                m_imageInfoRecord.BBoxX = 0;
 
69
                m_imageInfoRecord.BBoxH = m_image.height();
 
70
                m_imageInfoRecord.xres = qRound(gsRes);
 
71
                m_imageInfoRecord.yres = qRound(gsRes);
 
72
                m_imageInfoRecord.colorspace = 0;
 
73
                m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 
74
                m_image.setDotsPerMeterY ((int) (yres / 0.0254));
 
75
                return true;
 
76
        }
 
77
        return false;
 
78
}
 
79
 
 
80
void ScImgDataLoader_PDF::preloadAlphaChannel(const QString& fn, int gsRes)
 
81
{
 
82
        float xres, yres;
 
83
//      short resolutionunit = 0;
 
84
        initialize();
 
85
        QFileInfo fi = QFileInfo(fn);
 
86
        if (!fi.exists())
 
87
                return;
 
88
        QString tmp, BBox;
 
89
        QString ext = fi.extension(false).lower();
 
90
        QString tmpFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "sc.png");
 
91
        QString picFile = QDir::convertSeparators(fn);
 
92
        QStringList args;
 
93
        xres = gsRes;
 
94
        yres = gsRes;
 
95
        args.append("-r"+QString::number(gsRes));
 
96
//      args.append("-sOutputFile=\""+tmpFile + "\"");
 
97
        args.append("-sOutputFile="+tmpFile);
 
98
        args.append("-dFirstPage=1");
 
99
        args.append("-dLastPage=1");
 
100
//      args.append("\""+picFile+"\"");
 
101
        args.append(picFile);
 
102
        int retg = callGS(args);
 
103
        if (retg == 0)
 
104
        {
 
105
                m_image.load(tmpFile);
 
106
                unlink(tmpFile);
 
107
                m_image.setAlphaBuffer(true);
 
108
                if (ScCore->havePNGAlpha() != 0)
 
109
                {
 
110
                        QRgb *s;
 
111
                        for( int yi=0; yi < m_image.height(); ++yi )
 
112
                        {
 
113
                                s = (QRgb*)(m_image.scanLine( yi ));
 
114
                                for(int xi=0; xi < m_image.width(); ++xi )
 
115
                                {
 
116
                                        if((*s) == 0xffffffff)
 
117
                                                (*s) &= 0x00ffffff;
 
118
                                        s++;
 
119
                                }
 
120
                        }
 
121
                }
 
122
        }
 
123
}