summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'sdext/source/pdfimport/wrapper')
-rwxr-xr-xsdext/source/pdfimport/wrapper/makefile.mk6
-rwxr-xr-xsdext/source/pdfimport/wrapper/wrapper.cxx161
2 files changed, 115 insertions, 52 deletions
diff --git a/sdext/source/pdfimport/wrapper/makefile.mk b/sdext/source/pdfimport/wrapper/makefile.mk
index ce02047986e5..743633c8b612 100755
--- a/sdext/source/pdfimport/wrapper/makefile.mk
+++ b/sdext/source/pdfimport/wrapper/makefile.mk
@@ -2,14 +2,10 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
-# Copyright 2008 by Sun Microsystems, Inc.
+# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
-# $RCSfile: makefile.mk,v $
-#
-# $Revision: 1.3 $
-#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 9e23a061b760..51817ce5eacf 100755
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -2,14 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: wrapper.cxx,v $
- *
- * $Revision: 1.2.4.1 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -74,6 +70,10 @@
#include <hash_map>
#include <string.h>
+#ifdef WNT
+#include <stdlib.h>
+#include <ctype.h>
+#endif
#include "rtl/bootstrap.h"
@@ -184,6 +184,10 @@ class Parser
void readLink();
void readMaskedImage();
void readSoftMaskedImage();
+ int parseFontCheckForString( const sal_Unicode* pCopy, const char* str, sal_Int32& nLen,
+ FontAttributes& aResult, bool bItalic, bool bBold);
+ int parseFontRemoveSuffix( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen);
+
public:
Parser( const ContentSinkSharedPtr& rSink,
@@ -201,6 +205,60 @@ public:
void parseLine( const ::rtl::OString& rLine );
};
+
+namespace
+{
+
+ /** Unescapes line-ending characters in input string. These
+ characters are encoded as pairs of characters: '\\' 'n', resp.
+ '\\' 'r'. This function converts them back to '\n', resp. '\r'.
+ */
+ rtl::OString lcl_unescapeLineFeeds(const rtl::OString& i_rStr)
+ {
+ const size_t nOrigLen(sal::static_int_cast<size_t>(i_rStr.getLength()));
+ const sal_Char* const pOrig(i_rStr.getStr());
+ sal_Char* const pBuffer(new sal_Char[nOrigLen + 1]);
+
+ const sal_Char* pRead(pOrig);
+ sal_Char* pWrite(pBuffer);
+ const sal_Char* pCur(pOrig);
+ while ((pCur = strchr(pCur, '\\')) != 0)
+ {
+ const sal_Char cNext(pCur[1]);
+ if (cNext == 'n' || cNext == 'r' || cNext == '\\')
+ {
+ const size_t nLen(pCur - pRead);
+ strncpy(pWrite, pRead, nLen);
+ pWrite += nLen;
+ *pWrite = cNext == 'n' ? '\n' : (cNext == 'r' ? '\r' : '\\');
+ ++pWrite;
+ pCur = pRead = pCur + 2;
+ }
+ else
+ {
+ // Just continue on the next character. The current
+ // block will be copied the next time it goes through the
+ // 'if' branch.
+ ++pCur;
+ }
+ }
+ // maybe there are some data to copy yet
+ if (sal::static_int_cast<size_t>(pRead - pOrig) < nOrigLen)
+ {
+ const size_t nLen(nOrigLen - (pRead - pOrig));
+ strncpy(pWrite, pRead, nLen);
+ pWrite += nLen;
+ }
+ *pWrite = '\0';
+
+ rtl::OString aResult(pBuffer);
+ delete[] pBuffer;
+ return aResult;
+ }
+
+}
+
+
::rtl::OString Parser::readNextToken()
{
OSL_PRECOND(m_nCharIndex!=-1,"insufficient input");
@@ -326,7 +384,7 @@ void Parser::readChar()
readDouble(aUnoMatrix.m10);
readDouble(aUnoMatrix.m11);
- rtl::OString aChars = m_aLine.copy( m_nCharIndex );
+ rtl::OString aChars = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
// chars gobble up rest of line
m_nCharIndex = -1;
@@ -405,6 +463,35 @@ rendering::ARGBColor Parser::readColor()
return aRes;
}
+int Parser::parseFontCheckForString( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen,
+ FontAttributes& aResult, bool bItalic, bool bBold)
+{
+ int l = strlen(s);
+ if (nLen < l)
+ return 0;
+ for (int i = 0; i < l; i++)
+ if (tolower(pCopy[i]) != s[i]
+ && toupper(pCopy[i]) != s[i])
+ return 0;
+ aResult.isItalic = bItalic;
+ aResult.isBold = bBold;
+ nLen -= l;
+ pCopy += l;
+ return l;
+}
+
+int Parser::parseFontRemoveSuffix( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen)
+{
+ int l = strlen(s);
+ if (nLen < l)
+ return 0;
+ for (int i = 0; i < l; i++)
+ if ( pCopy[nLen - l + i] != s[i] )
+ return 0;
+ nLen -= l;
+ return l;
+}
+
void Parser::parseFontFamilyName( FontAttributes& aResult )
{
rtl::OUStringBuffer aNewFamilyName( aResult.familyName.getLength() );
@@ -420,39 +507,17 @@ void Parser::parseFontFamilyName( FontAttributes& aResult )
while( nLen )
{
- if( nLen > 5 &&
- ( *pCopy == 'i' || *pCopy == 'I' ) &&
- pCopy[1] == 't' &&
- pCopy[2] == 'a' &&
- pCopy[3] == 'l' &&
- pCopy[4] == 'i' &&
- pCopy[5] == 'c' )
- {
- aResult.isItalic = true;
- nLen -=6;
- pCopy += 6;
- }
- else if( nLen > 3 &&
- ( *pCopy == 'B' || *pCopy == 'b' ) &&
- pCopy[1] == 'o' &&
- pCopy[2] == 'l' &&
- pCopy[3] == 'd' )
- {
- aResult.isBold = true;
- nLen -=4;
- pCopy += 4;
- }
- else if( nLen > 5 &&
- *pCopy == '-' &&
- ( pCopy[1] == 'R' || pCopy[1] == 'r' ) &&
- pCopy[2] == 'o' &&
- pCopy[3] == 'm' &&
- pCopy[4] == 'a' &&
- pCopy[5] == 'n' )
- {
- nLen -= 6;
- pCopy += 6;
- }
+ if (parseFontRemoveSuffix( pCopy, "PSMT", nLen)) {}
+ else if (parseFontRemoveSuffix( pCopy, "MT", nLen)) {}
+
+ if (parseFontCheckForString( pCopy, "Italic", nLen, aResult, true, false)) {}
+ else if (parseFontCheckForString( pCopy, "-Bold", nLen, aResult, false, true)) {}
+ else if (parseFontCheckForString( pCopy, "Bold", nLen, aResult, false, true)) {}
+ else if (parseFontCheckForString( pCopy, "-Roman", nLen, aResult, false, false)) {}
+ else if (parseFontCheckForString( pCopy, "-LightOblique", nLen, aResult, true, false)) {}
+ else if (parseFontCheckForString( pCopy, "-BoldOblique", nLen, aResult, true, true)) {}
+ else if (parseFontCheckForString( pCopy, "-Light", nLen, aResult, false, false)) {}
+ else if (parseFontCheckForString( pCopy, "-Reg", nLen, aResult, false, false)) {}
else
{
if( *pCopy != '-' )
@@ -480,7 +545,7 @@ void Parser::readFont()
readInt32(nFileLen);
nSize = nSize < 0.0 ? -nSize : nSize;
- aFontName = m_aLine.copy( m_nCharIndex );
+ aFontName = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
// name gobbles up rest of line
m_nCharIndex = -1;
@@ -507,7 +572,6 @@ void Parser::readFont()
// extract textual attributes (bold, italic in the name, etc.)
parseFontFamilyName(aResult);
-
// need to read font file?
if( nFileLen )
{
@@ -532,6 +596,7 @@ void Parser::readFont()
if( aRes >>= aFD )
{
aResult.familyName = aFD.Name;
+ parseFontFamilyName(aResult);
aResult.isBold = (aFD.Weight > 100.0);
aResult.isItalic = (aFD.Slant == awt::FontSlant_OBLIQUE ||
aFD.Slant == awt::FontSlant_ITALIC );
@@ -552,7 +617,6 @@ void Parser::readFont()
}
}
-
m_aFontMap[nFontID] = aResult;
aResult.size = nSize;
@@ -672,8 +736,9 @@ void Parser::readLink()
readDouble(aBounds.Y2);
m_pSink->hyperLink( aBounds,
- rtl::OStringToOUString( m_aLine.copy(m_nCharIndex),
- RTL_TEXTENCODING_UTF8 ));
+ rtl::OStringToOUString( lcl_unescapeLineFeeds(
+ m_aLine.copy(m_nCharIndex) ),
+ RTL_TEXTENCODING_UTF8 ) );
// name gobbles up rest of line
m_nCharIndex = -1;
}
@@ -824,7 +889,8 @@ oslFileError readLine( oslFileHandle pFile, ::rtl::OStringBuffer& line )
static bool checkEncryption( const rtl::OUString& i_rPath,
const uno::Reference< task::XInteractionHandler >& i_xIHdl,
rtl::OUString& io_rPwd,
- bool& o_rIsEncrypted
+ bool& o_rIsEncrypted,
+ const rtl::OUString& i_rDocName
)
{
bool bSuccess = false;
@@ -857,7 +923,7 @@ static bool checkEncryption( const rtl::OUString&
bool bEntered = false;
do
{
- bEntered = getPassword( i_xIHdl, io_rPwd, ! bEntered );
+ bEntered = getPassword( i_xIHdl, io_rPwd, ! bEntered, i_rDocName );
rtl::OString aIsoPwd = rtl::OUStringToOString( io_rPwd,
RTL_TEXTENCODING_ISO_8859_1 );
bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() );
@@ -886,11 +952,12 @@ bool xpdf_ImportFromFile( const ::rtl::OUString& rUR
::rtl::OUString aSysUPath;
if( osl_getSystemPathFromFileURL( rURL.pData, &aSysUPath.pData ) != osl_File_E_None )
return false;
+ rtl::OUString aDocName( rURL.copy( rURL.lastIndexOf( sal_Unicode('/') )+1 ) );
// check for encryption, if necessary get password
rtl::OUString aPwd( rPwd );
bool bIsEncrypted = false;
- if( checkEncryption( aSysUPath, xIHdl, aPwd, bIsEncrypted ) == false )
+ if( checkEncryption( aSysUPath, xIHdl, aPwd, bIsEncrypted, aDocName ) == false )
return false;
rtl::OUStringBuffer converterURL = rtl::OUString::createFromAscii("xpdfimport");