poppler/poppler-0.90.0-qt4-update.p...

384 lines
14 KiB
Diff

--- poppler-0.90.0/qt4/src/poppler-annotation.cc
+++ poppler-0.90.0/qt4/src/poppler-annotation.cc
@@ -789,7 +789,7 @@ Link* AnnotationPrivate::additionalActio
case Annotation::PageInvisibleAction: actionType = Annot::actionPageInvisible; break;
}
- ::LinkAction *linkAction = nullptr;
+ std::unique_ptr<::LinkAction> linkAction = nullptr;
if ( pdfAnnot->getType() == Annot::typeScreen )
linkAction = static_cast<AnnotScreen*>( pdfAnnot )->getAdditionalAction( actionType );
else
@@ -798,7 +798,7 @@ Link* AnnotationPrivate::additionalActio
Link *link = nullptr;
if ( linkAction )
- link = PageData::convertLinkActionToLink( linkAction, parentDoc, QRectF() );
+ link = PageData::convertLinkActionToLink( linkAction.get(), parentDoc, QRectF() );
return link;
}
--- poppler-0.90.0/qt4/src/poppler-document.cc
+++ poppler-0.90.0/qt4/src/poppler-document.cc
@@ -57,8 +57,6 @@
namespace Poppler {
- int DocumentData::count = 0;
-
Document *Document::load(const QString &filePath, const QByteArray &ownerPassword,
const QByteArray &userPassword)
{
@@ -633,7 +631,16 @@ namespace Poppler {
void Document::setColorDisplayProfile(void* outputProfileA)
{
#if defined(USE_CMS)
- GfxColorSpace::setDisplayProfile((cmsHPROFILE)outputProfileA);
+ if (m_doc->m_sRGBProfile && m_doc->m_sRGBProfile.get() == outputProfileA) {
+ // Catch the special case that the user passes the sRGB profile
+ m_doc->m_displayProfile = m_doc->m_sRGBProfile;
+ return;
+ }
+ if (m_doc->m_displayProfile && m_doc->m_displayProfile.get() == outputProfileA) {
+ // Catch the special case that the user passes the display profile
+ return;
+ }
+ m_doc->m_displayProfile = make_GfxLCMSProfilePtr(outputProfileA);
#else
Q_UNUSED(outputProfileA);
#endif
@@ -642,9 +649,8 @@ namespace Poppler {
void Document::setColorDisplayProfileName(const QString &name)
{
#if defined(USE_CMS)
- GooString *profileName = QStringToGooString( name );
- GfxColorSpace::setDisplayProfileName(profileName);
- delete profileName;
+ void* rawprofile = cmsOpenProfileFromFile(name.toLocal8Bit().constData(),"r");
+ m_doc->m_displayProfile = make_GfxLCMSProfilePtr(rawprofile);
#else
Q_UNUSED(name);
#endif
@@ -653,7 +659,10 @@ namespace Poppler {
void* Document::colorRgbProfile() const
{
#if defined(USE_CMS)
- return (void*)GfxColorSpace::getRGBProfile();
+ if (!m_doc->m_sRGBProfile) {
+ m_doc->m_sRGBProfile = make_GfxLCMSProfilePtr(cmsCreate_sRGBProfile());
+ }
+ return m_doc->m_sRGBProfile.get();
#else
return NULL;
#endif
@@ -662,7 +671,7 @@ namespace Poppler {
void* Document::colorDisplayProfile() const
{
#if defined(USE_CMS)
- return (void*)GfxColorSpace::getDisplayProfile();
+ return m_doc->m_displayProfile.get();
#else
return NULL;
#endif
--- poppler-0.90.0/qt4/src/poppler-link.cc
+++ poppler-0.90.0/qt4/src/poppler-link.cc
@@ -232,7 +232,7 @@ class LinkMoviePrivate : public LinkPriv
if ( data.namedDest && !ld && !data.externalDest )
{
deleteDest = true;
- ld = data.doc->doc->findDest( data.namedDest );
+ ld = data.doc->doc->findDest( data.namedDest ).release();
}
// in case this destination was named one, and it was not resolved
if ( data.namedDest && !ld )
--- poppler-0.90.0/qt4/src/poppler-page.cc
+++ poppler-0.90.0/qt4/src/poppler-page.cc
@@ -110,30 +110,30 @@ Link* PageData::convertLinkActionToLink(
case actionNamed:
{
- const char * name = ((LinkNamed *)a)->getName()->c_str();
- if ( !strcmp( name, "NextPage" ) )
+ const std::string& name = ((LinkNamed *)a)->getName();
+ if ( name == "NextPage" )
popplerLink = new LinkAction( linkArea, LinkAction::PageNext );
- else if ( !strcmp( name, "PrevPage" ) )
+ else if ( name == "PrevPage" )
popplerLink = new LinkAction( linkArea, LinkAction::PagePrev );
- else if ( !strcmp( name, "FirstPage" ) )
+ else if ( name == "FirstPage" )
popplerLink = new LinkAction( linkArea, LinkAction::PageFirst );
- else if ( !strcmp( name, "LastPage" ) )
+ else if ( name == "LastPage" )
popplerLink = new LinkAction( linkArea, LinkAction::PageLast );
- else if ( !strcmp( name, "GoBack" ) )
+ else if ( name == "GoBack" )
popplerLink = new LinkAction( linkArea, LinkAction::HistoryBack );
- else if ( !strcmp( name, "GoForward" ) )
+ else if ( name == "GoForward" )
popplerLink = new LinkAction( linkArea, LinkAction::HistoryForward );
- else if ( !strcmp( name, "Quit" ) )
+ else if ( name == "Quit" )
popplerLink = new LinkAction( linkArea, LinkAction::Quit );
- else if ( !strcmp( name, "GoToPage" ) )
+ else if ( name == "GoToPage" )
popplerLink = new LinkAction( linkArea, LinkAction::GoToPage );
- else if ( !strcmp( name, "Find" ) )
+ else if ( name == "Find" )
popplerLink = new LinkAction( linkArea, LinkAction::Find );
- else if ( !strcmp( name, "FullScreen" ) )
+ else if ( name == "FullScreen" )
popplerLink = new LinkAction( linkArea, LinkAction::Presentation );
- else if ( !strcmp( name, "Print" ) )
+ else if ( name == "Print" )
popplerLink = new LinkAction( linkArea, LinkAction::Print );
- else if ( !strcmp( name, "Close" ) )
+ else if ( name == "Close" )
{
// acroread closes the document always, doesnt care whether
// its presentation mode or not
@@ -149,7 +149,7 @@ Link* PageData::convertLinkActionToLink(
case actionURI:
{
- popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->c_str() );
+ popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI().c_str() );
}
break;
@@ -362,6 +362,10 @@ QImage Page::renderToImage(double xres,
splash_output.setFreeTypeHinting(m_page->parentDoc->m_hints & Document::TextHinting ? true : false,
m_page->parentDoc->m_hints & Document::TextSlightHinting ? true : false);
+#ifdef USE_CMS
+ splash_output.setDisplayProfile(m_page->parentDoc->m_displayProfile);
+#endif
+
splash_output.startDoc(m_page->parentDoc->doc);
m_page->parentDoc->doc->displayPageSlice(&splash_output, m_page->index + 1, xres, yres,
@@ -442,6 +447,11 @@ bool Page::renderToPainter(QPainter* pai
painter->translate(x == -1 ? 0 : -x, y == -1 ? 0 : -y);
ArthurOutputDev arthur_output(painter);
arthur_output.startDoc(m_page->parentDoc->doc->getXRef());
+
+#ifdef USE_CMS
+ arthur_output.setDisplayProfile(m_page->parentDoc->m_displayProfile);
+#endif
+
m_page->parentDoc->doc->displayPageSlice(&arthur_output,
m_page->index + 1,
xres,
@@ -671,12 +681,11 @@ Link *Page::action( PageAction act ) con
Dict *dict = o.getDict();
const char *key = act == Page::Opening ? "O" : "C";
Object o2 = dict->lookup((char*)key);
- ::LinkAction *lact = ::LinkAction::parseAction(&o2, m_page->parentDoc->doc->getCatalog()->getBaseURI() );
+ std::unique_ptr<::LinkAction> lact = ::LinkAction::parseAction(&o2, m_page->parentDoc->doc->getCatalog()->getBaseURI() );
Link *popplerLink = NULL;
if (lact != NULL)
{
- popplerLink = m_page->convertLinkActionToLink(lact, QRectF());
- delete lact;
+ popplerLink = m_page->convertLinkActionToLink(lact.get(), QRectF());
}
return popplerLink;
}
--- poppler-0.90.0/qt4/src/poppler-private.cc
+++ poppler-0.90.0/qt4/src/poppler-private.cc
@@ -49,15 +49,13 @@ namespace Debug {
}
- static UnicodeMap *utf8Map = 0;
-
void setDebugErrorFunction(PopplerDebugFunc function, const QVariant &closure)
{
Debug::debugFunction = function ? function : Debug::qDebugDebugFunction;
Debug::debugClosure = closure;
}
- static void qt4ErrorFunction(void * /*data*/, ErrorCategory /*category*/, Goffset pos, const char *msg)
+ void qt4ErrorFunction(ErrorCategory /*category*/, Goffset pos, const char *msg)
{
QString emsg;
@@ -74,12 +72,7 @@ namespace Debug {
}
QString unicodeToQString(const Unicode* u, int len) {
- if (!utf8Map)
- {
- GooString enc("UTF-8");
- utf8Map = globalParams->getUnicodeMap(&enc);
- utf8Map->incRefCnt();
- }
+ const UnicodeMap *utf8Map = globalParams->getUtf8Map();
// ignore the last character if it is 0x0
if ((len > 0) && (u[len - 1] == 0))
@@ -99,34 +92,25 @@ namespace Debug {
}
QString UnicodeParsedString(const GooString *s1) {
- if ( !s1 || s1->getLength() == 0 )
+ return (s1) ? UnicodeParsedString(s1->toStr()) : QString();
+ }
+
+ QString UnicodeParsedString(const std::string& s1) {
+ if ( s1.empty() )
return QString();
- const char *cString;
- int stringLength;
- bool deleteCString;
- if ( ( s1->getChar(0) & 0xff ) == 0xfe && ( s1->getLength() > 1 && ( s1->getChar(1) & 0xff ) == 0xff ) )
- {
- cString = s1->c_str();
- stringLength = s1->getLength();
- deleteCString = false;
- }
- else
+ if ( GooString::hasUnicodeMarker(s1) || GooString::hasUnicodeMarkerLE(s1) )
{
- cString = pdfDocEncodingToUTF16(s1, &stringLength);
- deleteCString = true;
+ return QString::fromUtf16(reinterpret_cast<const ushort *>(s1.c_str()), s1.size() / 2);
}
-
- QString result;
- // i = 2 to skip the unicode marker
- for ( int i = 2; i < stringLength; i += 2 )
+ else
{
- const Unicode u = ( ( cString[i] & 0xff ) << 8 ) | ( cString[i+1] & 0xff );
- result += QChar( u );
- }
- if (deleteCString)
+ int stringLength;
+ const char *cString = pdfDocEncodingToUTF16(s1, &stringLength);
+ auto result = QString::fromUtf16(reinterpret_cast<const ushort *>(cString), stringLength / 2);
delete[] cString;
- return result;
+ return result;
+ }
}
GooString *QStringToUnicodeGooString(const QString &s) {
@@ -221,7 +205,7 @@ namespace Debug {
case actionURI:
{
const LinkURI * u = static_cast< const LinkURI * >( a );
- e->setAttribute( "DestinationURI", u->getURI()->c_str() );
+ e->setAttribute( "DestinationURI", u->getURI().c_str() );
}
default: ;
}
@@ -233,13 +217,6 @@ namespace Debug {
delete (OptContentModel *)m_optContentModel;
delete doc;
delete m_fontInfoIterator;
-
- count --;
- if ( count == 0 )
- {
- utf8Map = nullptr;
- globalParams.reset();
- }
}
void DocumentData::init()
@@ -249,14 +226,6 @@ namespace Debug {
paperColor = Qt::white;
m_hints = 0;
m_optContentModel = 0;
-
- if ( count == 0 )
- {
- utf8Map = nullptr;
- globalParams = std::make_unique<GlobalParams>();
- setErrorCallback(qt4ErrorFunction, nullptr);
- }
- count ++;
}
--- poppler-0.90.0/qt4/src/poppler-private.h
+++ poppler-0.90.0/qt4/src/poppler-private.h
@@ -55,6 +55,8 @@ class FormWidget;
QString unicodeToQString(const Unicode* u, int len);
QString UnicodeParsedString(const GooString *s1);
+
+ QString UnicodeParsedString(const std::string& s1);
GooString *QStringToUnicodeGooString(const QString &s);
@@ -65,7 +67,7 @@ namespace Poppler {
GooString *QDateTimeToUnicodeGooString(const QDateTime &dt);
- void qt4ErrorFunction(int pos, char *msg, va_list args);
+ void qt4ErrorFunction(ErrorCategory /*category*/, Goffset pos, const char *msg);
class LinkDestinationData
{
@@ -65,9 +67,10 @@ namespace Poppler {
bool externalDest;
};
- class DocumentData {
+ class DocumentData : private GlobalParamsIniter {
public:
- DocumentData(const QString &filePath, GooString *ownerPassword, GooString *userPassword)
+ DocumentData(const QString &filePath, GooString *ownerPassword, GooString *userPassword) :
+ GlobalParamsIniter(qt4ErrorFunction)
{
init();
m_filePath = filePath;
@@ -102,7 +105,8 @@ namespace Poppler {
delete userPassword;
}
- DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword)
+ DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword) :
+ GlobalParamsIniter(qt4ErrorFunction)
{
fileContents = data;
MemStream *str = new MemStream((char*)fileContents.data(), 0, fileContents.length(), Object(objNull));
@@ -148,7 +152,10 @@ namespace Poppler {
QPointer<OptContentModel> m_optContentModel;
QColor paperColor;
int m_hints;
- static int count;
+#ifdef USE_CMS
+ GfxLCMSProfilePtr m_sRGBProfile;
+ GfxLCMSProfilePtr m_displayProfile;
+#endif
};
class FontInfoData
--- poppler-0.90.0/qt4/src/poppler-ps-converter.cc
+++ poppler-0.90.0/qt4/src/poppler-ps-converter.cc
@@ -235,7 +235,7 @@ bool PSConverter::convert()
d->marginBottom,
d->paperWidth - d->marginRight,
d->paperHeight - d->marginTop,
- (d->opts & ForceRasterization));
+ (d->opts & ForceRasterization) ? psAlwaysRasterize : psRasterizeWhenNeeded);
if (d->opts & StrictMargins)
{
--- poppler-0.90.0/qt4/src/poppler-sound.cc
+++ poppler-0.90.0/qt4/src/poppler-sound.cc
@@ -75,8 +75,7 @@ QString SoundObject::url() const
if ( m_soundData->m_type != SoundObject::External )
return QString();
- const GooString * goo = m_soundData->m_soundObj->getFileName();
- return goo ? QString( goo->c_str() ) : QString();
+ return QString( m_soundData->m_soundObj->getFileName().c_str() );
}
QByteArray SoundObject::data() const