Hi,

we have completed the Windows API for PdfImage.
Currently there is only the function LoadFromJpeg that supports Unicode for Windows:
void LoadFromJpeg( const wchar_t* pszFilename );

In the patch we added:
void LoadFromFile( const wchar_t* pszFilename );
void LoadFromTiff( const wchar_t* pszFilename );
void LoadFromPng( const wchar_t* pszFilename );

Additionally I stumbled upon forced "#define PODOFO_JPEG_RUNTIME_COMPATIBLE".
If this is undefined the code makes no sense and will not compile.
So I removed this legacy unused code.

So please check my changes and add them to the repository.

Kind regards

Andreas
--

dots <http://www.dots.de/en/>

Andreas Brzesowsky

dots Software GmbH
Schlesische Str. 27, 10997 Berlin, Germany
Phone: +49 (0)30 695 799-34, Fax: +49 (0)30 695 799-55

andreas.brzesow...@dots.de <mailto:andreas.brzesow...@dots.de>
http://www.dots.de <http://www.dots.de/>

Amtsgericht (District Court): Berlin Charlottenburg HRB 65201
Geschäftsführer (Managing Directors): Olaf Lorenz

Follow us on: Twitter <http://www.dots.de/?id=twitter> Youtube <http://www.dots.de/?id=youtube> Xing <http://www.dots.de/?id=xing>

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (revision 1673)
+++ CMakeLists.txt      (working copy)
@@ -426,28 +426,6 @@
        SET(PODOFO_LIB_FONTCONFIG:STRING)
 ENDIF(WANT_FONTCONFIG)
 
-# libjpeg has routines that take a FILE*. This is safe if and only
-# if the C runtime podofo is built against is the same as the C runtime
-# libjpeg is built against. That is not always the case.
-#
-# If the user has explicitly told us that libjpeg's libc is binary compatible,
-# don't worry about using workarounds. Otherwise, on Windows we assume it's not
-# compatible and on other platforms we'll assume it is. This change currently
-# only affects PdfImage.cpp.
-#
-IF(DEFINED JPEG_RUNTIME_COMPATIBLE)
-       IF(JPEG_RUNTIME_COMPATIBLE)
-               # Trust the user to know what they're doing and pass a FILE*
-               SET(PODOFO_JPEG_RUNTIME_COMPATIBLE TRUE)
-       ENDIF(JPEG_RUNTIME_COMPATIBLE)
-ELSE(DEFINED JPEG_RUNTIME_COMPATIBLE)
-       IF(NOT WIN32)
-               # It's a sensible platform and the user hasn't told us
-               # otherwise - pass a FILE* .
-               SET(PODOFO_JPEG_RUNTIME_COMPATIBLE TRUE)
-       ENDIF(NOT WIN32)
-ENDIF(DEFINED JPEG_RUNTIME_COMPATIBLE)
-
 IF(NOT PODOFO_BUILD_LIB_ONLY)
 FIND_PACKAGE(LUA)
 IF(LUA_FOUND)
Index: podofo_config.h.in
===================================================================
--- podofo_config.h.in  (revision 1673)
+++ podofo_config.h.in  (working copy)
@@ -56,6 +56,3 @@
 #cmakedefine PODOFO_HAVE_CPPUNIT
 #cmakedefine PODOFO_HAVE_OPENSSL
 #cmakedefine PODOFO_HAVE_LIBIDN
-
-/* Platform quirks */
-#cmakedefine PODOFO_JPEG_RUNTIME_COMPATIBLE
Index: src/doc/PdfImage.cpp
===================================================================
--- src/doc/PdfImage.cpp        (revision 1673)
+++ src/doc/PdfImage.cpp        (working copy)
@@ -44,7 +44,6 @@
 #include <wchar.h>
 #include <sstream>
 
-#define PODOFO_JPEG_RUNTIME_COMPATIBLE
 #ifdef PODOFO_HAVE_TIFF_LIB
 extern "C" {
 #  include "tiffio.h"
@@ -253,6 +252,45 @@
        PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedImageFormat, pszFilename 
);
 }
     
+#ifdef _WIN32
+void PdfImage::LoadFromFile( const wchar_t* pszFilename )
+{
+    if( pszFilename && wcslen( pszFilename ) > 3 )
+    {
+        const wchar_t* pszExtension = pszFilename + wcslen( pszFilename ) - 3;
+
+#ifdef PODOFO_HAVE_TIFF_LIB
+               if( _wcsnicmp( pszExtension, L"tif", 3 ) == 0 ||
+            _wcsnicmp( pszExtension, L"iff", 3 ) == 0 ) // "tiff"
+        {
+            LoadFromTiff( pszFilename );
+            return;
+        }
+#endif
+
+#ifdef PODOFO_HAVE_JPEG_LIB
+        if( _wcsnicmp( pszExtension, L"jpg", 3 ) == 0 )
+        {
+            LoadFromJpeg( pszFilename );
+            return;
+        }
+#endif
+
+#ifdef PODOFO_HAVE_PNG_LIB
+        if( _wcsnicmp( pszExtension, L"png", 3 ) == 0 )
+        {
+            LoadFromPng( pszFilename );
+            return;
+        }
+#endif
+       }
+
+       PdfError e( ePdfError_UnsupportedImageFormat, __FILE__, __LINE__ );
+    e.SetErrorInformation( pszFilename );
+    throw e;
+}
+#endif // _WIN32
+
 void PdfImage::LoadFromData(const unsigned char* pData, pdf_long dwLen)
 {
     if (dwLen > 4) {
@@ -345,21 +383,7 @@
 
     jpeg_create_decompress(&cinfo);
 
-#if !defined(PODOFO_JPEG_RUNTIME_COMPATIBLE)
-    const long lSize = 1024;
-    PdfRefCountedBuffer buffer( lSize );
-    fread( buffer.GetBuffer(), sizeof(char), lSize, hInfile );
-    
-    // On WIN32, you can only pass a FILE Handle to DLLs which where compiled 
using the same
-    // C library. This is usually not the case with LibJpeg on WIN32. 
-    // As a reason we use a memory buffer to determine the header information.
-    //
-    // If you are sure that libJpeg is compiled against the same C library as 
your application
-    // you can removed this ifdef.
-    jpeg_memory_src ( &cinfo, reinterpret_cast<JOCTET*>(buffer.GetBuffer()), 
buffer.GetSize() );
-#else
     jpeg_stdio_src(&cinfo, pInStream->GetHandle());
-#endif // PODOFO_JPEG_RUNTIME_COMPATIBLE
 
     if( jpeg_read_header(&cinfo, TRUE) <= 0 )
     {
@@ -697,6 +721,30 @@
     LoadFromTiffHandle(hInfile);
 }
 
+#ifdef _WIN32
+void PdfImage::LoadFromTiff( const wchar_t* pszFilename )
+{
+    TIFFSetErrorHandler(TIFFErrorWarningHandler);
+    TIFFSetWarningHandler(TIFFErrorWarningHandler);
+    
+    if( !pszFilename )
+    {
+        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
+    }
+
+    TIFF* hInfile = TIFFOpenW(pszFilename, "rb");
+
+    if( !hInfile )
+    {
+               PdfError e( ePdfError_FileNotFound, __FILE__, __LINE__ );
+        e.SetErrorInformation( pszFilename );
+        throw e;
+    }
+
+       LoadFromTiffHandle(hInfile);
+}
+#endif // _WIN32
+
 struct tiffData
 {
     tiffData(const unsigned char* data, tsize_t size):_data(data), _pos(0), 
_size(size) {}
@@ -825,17 +873,21 @@
 #ifdef PODOFO_HAVE_PNG_LIB
 void PdfImage::LoadFromPng( const char* pszFilename )
 {
-    if( !pszFilename )
-    {
-        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
-    }
+    PdfFileInputStream stream( pszFilename );
+    LoadFromPngHandle( &stream );
+}
 
-    FILE* hFile = fopen(pszFilename, "rb");
-    if( !hFile )
-    {
-        PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
-    }
+#ifdef _WIN32
+void PdfImage::LoadFromPng( const wchar_t* pszFilename )
+{
+    PdfFileInputStream stream( pszFilename );
+    LoadFromPngHandle( &stream );
+}
+#endif // _WIN32
 
+void PdfImage::LoadFromPngHandle( PdfFileInputStream* pInStream ) 
+{
+    FILE* hFile = pInStream->GetHandle();
     png_byte header[8];
     fread(header, 1, 8, hFile);
     if( png_sig_cmp(header, 0, 8) )
Index: src/doc/PdfImage.h
===================================================================
--- src/doc/PdfImage.h  (revision 1673)
+++ src/doc/PdfImage.h  (working copy)
@@ -185,6 +185,17 @@
      */
     void LoadFromData(const unsigned char* pData, pdf_long dwLen);
 
+#ifdef _WIN32
+    /** Load the image data from a file
+     *  \param pszFilename
+     *
+     *  This is an overloaded member function to allow working
+     *  with unicode characters. On Unix systems you can also pass
+     *  UTF-8 to the const char* overload.
+     */
+    void LoadFromFile( const wchar_t* pszFilename );
+#endif // _WIN32
+
 #ifdef PODOFO_HAVE_JPEG_LIB
     /** Load the image data from a JPEG file
      *  \param pszFilename
@@ -202,7 +213,7 @@
      *  \param pszFilename
      *
      *  This is an overloaded member function to allow working
-     *  with unicode characters. On Unix systes you can also path
+     *  with unicode characters. On Unix systems you can also pass
      *  UTF-8 to the const char* overload.
      */
     void LoadFromJpeg( const wchar_t* pszFilename );
@@ -219,6 +230,17 @@
      *  \param dwLen number of bytes
      */
     void LoadFromTiffData(const unsigned char* pData, pdf_long dwLen);
+
+#ifdef _WIN32
+    /** Load the image data from a TIFF file
+     *  \param pszFilename
+     *
+     *  This is an overloaded member function to allow working
+     *  with unicode characters. On Unix systems you can also pass
+     *  UTF-8 to the const char* overload.
+     */
+    void LoadFromTiff( const wchar_t* pszFilename );
+#endif // _WIN32
 #endif // PODOFO_HAVE_TIFF_LIB
 #ifdef PODOFO_HAVE_PNG_LIB
     /** Load the image data from a PNG file
@@ -231,6 +253,17 @@
      *  \param dwLen number of bytes
      */
     void LoadFromPngData(const unsigned char* pData, pdf_long dwLen);
+
+#ifdef _WIN32
+    /** Load the image data from a PNG file
+     *  \param pszFilename
+     *
+     *  This is an overloaded member function to allow working
+     *  with unicode characters. On Unix systems you can also pass
+     *  UTF-8 to the const char* overload.
+     */
+    void LoadFromPng( const wchar_t* pszFilename );
+#endif // _WIN32
 #endif // PODOFO_HAVE_PNG_LIB
 
     /** Set an color/chroma-key mask on an image.
@@ -266,6 +299,9 @@
 #ifdef PODOFO_HAVE_TIFF_LIB
     void LoadFromTiffHandle( void* pInStream );
 #endif // PODOFO_HAVE_TIFF_LIB
+#ifdef PODOFO_HAVE_PNG_LIB
+       void LoadFromPngHandle( PdfFileInputStream* pInStream );
+#endif // PODOFO_HAVE_PNG_LIB
 };
 
 // -----------------------------------------------------
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to