Index: podofo/trunk/src/doc/PdfFontMetrics.h
===================================================================
--- podofo/trunk/src/doc/PdfFontMetrics.h	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetrics.h	(working copy)
@@ -37,6 +37,7 @@
 #include "podofo/base/PdfDefines.h"
 #include "podofo/base/Pdf3rdPtyForwardDecl.h"
 #include "podofo/base/PdfString.h"
+#include "podofo/base/PdfEncoding.h"
 
 namespace PoDoFo {
 
@@ -60,8 +61,9 @@
      *  \param var the final width array is written to this PdfVariant
      *  \param nFirst first character to be in the array
      *  \param nLast last character code to be in the array
+     *  \param pEncoding encoding for correct character widths. If not passed default (latin1) encoding is used
      */
-    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const = 0;
+    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding = NULL ) const = 0;
 
     /** Get the width of a single glyph id
      *
Index: podofo/trunk/src/doc/PdfFontMetricsBase14.cpp
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsBase14.cpp	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsBase14.cpp	(working copy)
@@ -248,7 +248,7 @@
     return;
 }
 
-void PdfFontMetricsBase14::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const
+void PdfFontMetricsBase14::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding ) const
 {
     unsigned int i;
     PdfArray     list;
@@ -255,7 +255,18 @@
     
     for( i=nFirst;i<=nLast;i++ )
     {
-		list.push_back( PdfVariant(  double(widths_table[i].width)  ) );
+        if (pEncoding != NULL)
+        {
+            unsigned short shCode = pEncoding->GetCharCode(i);
+#ifdef PODOFO_IS_LITTLE_ENDIAN
+            shCode = ((shCode & 0x00FF) << 8) | ((shCode & 0xFF00) >> 8);
+#endif
+            list.push_back(PdfObject( (pdf_int64)this->GetGlyphWidth(this->GetGlyphIdUnicode(shCode) )));
+        }
+        else
+        {
+            list.push_back( PdfVariant(  double(widths_table[i].width)  ) );
+        }
     }
     
     var = PdfVariant( list );
Index: podofo/trunk/src/doc/PdfFontMetricsBase14.h
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsBase14.h	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsBase14.h	(working copy)
@@ -89,8 +89,9 @@
      *  \param var the final width array is written to this PdfVariant
      *  \param nFirst first character to be in the array
      *  \param nLast last character code to be in the array
+     *  \param pEncoding encoding for correct character widths. If not passed default (latin1) encoding is used
      */
-    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const;
+    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding = NULL ) const;
 
     /** Get the width of a single glyph id
      *
Index: podofo/trunk/src/doc/PdfFontMetricsFreetype.cpp
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsFreetype.cpp	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsFreetype.cpp	(working copy)
@@ -59,47 +59,47 @@
 #endif
 
 struct Scoped_FT_Face {
-	Scoped_FT_Face() : ftFace(0) {
-	}
-	~Scoped_FT_Face() {
-		if (ftFace) {
-			FT_Done_Face(ftFace);
-		}
-	}
-	FT_Face ftFace;
+    Scoped_FT_Face() : ftFace(0) {
+    }
+    ~Scoped_FT_Face() {
+        if (ftFace) {
+            FT_Done_Face(ftFace);
+        }
+    }
+    FT_Face ftFace;
 };
 
 PdfFontMetricsFreetype* PdfFontMetricsFreetype::CreateForSubsetting(FT_Library* pLibrary, const char* pszFilename, bool pIsSymbol, const char* pszSubsetPrefix ) 
 {
-	Scoped_FT_Face scoped_face;
+    Scoped_FT_Face scoped_face;
 
-	FT_Error err = FT_New_Face( *pLibrary, pszFilename, 0, &scoped_face.ftFace );
-	if (!err) {
-		FT_ULong  length = 0;
-		err = FT_Load_Sfnt_Table( scoped_face.ftFace, 0, 0, NULL, &length );
-		if (!err) {
-			PdfRefCountedBuffer buffer(length);
-			err = FT_Load_Sfnt_Table( scoped_face.ftFace, 0, 0, reinterpret_cast<FT_Byte*>(buffer.GetBuffer()), &length );
-			if (!err) {
-				return new PdfFontMetricsFreetype( pLibrary, buffer, pIsSymbol, pszSubsetPrefix );
-			}
-		}
+    FT_Error err = FT_New_Face( *pLibrary, pszFilename, 0, &scoped_face.ftFace );
+    if (!err) {
+        FT_ULong  length = 0;
+        err = FT_Load_Sfnt_Table( scoped_face.ftFace, 0, 0, NULL, &length );
+        if (!err) {
+            PdfRefCountedBuffer buffer(length);
+            err = FT_Load_Sfnt_Table( scoped_face.ftFace, 0, 0, reinterpret_cast<FT_Byte*>(buffer.GetBuffer()), &length );
+            if (!err) {
+                return new PdfFontMetricsFreetype( pLibrary, buffer, pIsSymbol, pszSubsetPrefix );
+            }
+        }
         // throw an exception
         PdfError::LogMessage( eLogSeverity_Critical, "FreeType returned the error %i when calling FT_Load_Sfnt_Table for font %s.", 
                               err, pszFilename );
         PODOFO_RAISE_ERROR( ePdfError_FreeType );
-	}
-	else {
+    }
+    else {
         // throw an exception
         PdfError::LogMessage( eLogSeverity_Critical, "FreeType returned the error %i when calling FT_New_Face for font %s.", 
                               err, pszFilename );
         PODOFO_RAISE_ERROR( ePdfError_FreeType );
-	}
-	return 0;
+    }
+    return 0;
 }
 
 PdfFontMetricsFreetype::PdfFontMetricsFreetype( FT_Library* pLibrary, const char* pszFilename, 
-															   bool pIsSymbol, const char* pszSubsetPrefix )
+                                                               bool pIsSymbol, const char* pszSubsetPrefix )
     : PdfFontMetrics( PdfFontMetrics::FontTypeFromFilename( pszFilename ),
                       pszFilename, pszSubsetPrefix ),
       m_pLibrary( pLibrary ),
@@ -120,7 +120,7 @@
 
 PdfFontMetricsFreetype::PdfFontMetricsFreetype( FT_Library* pLibrary, 
                                                 const char* pBuffer, unsigned int nBufLen,
-																bool pIsSymbol,
+                                                                bool pIsSymbol,
                                                 const char* pszSubsetPrefix )
     : PdfFontMetrics( ePdfFontType_Unknown, "", pszSubsetPrefix ),
       m_pLibrary( pLibrary ),
@@ -135,7 +135,7 @@
 
 PdfFontMetricsFreetype::PdfFontMetricsFreetype( FT_Library* pLibrary, 
                                                 const PdfRefCountedBuffer & rBuffer,
-																bool pIsSymbol,
+                                                                bool pIsSymbol,
                                                 const char* pszSubsetPrefix ) 
     : PdfFontMetrics( ePdfFontType_Unknown, "", pszSubsetPrefix ),
       m_pLibrary( pLibrary ),
@@ -148,7 +148,7 @@
 
 PdfFontMetricsFreetype::PdfFontMetricsFreetype( FT_Library* pLibrary, 
                                                 FT_Face face, 
-																bool pIsSymbol,
+                                                                bool pIsSymbol,
                                                 const char* pszSubsetPrefix  )
     : PdfFontMetrics( ePdfFontType_TrueType, 
                       // Try to initialize the pathname from m_face
@@ -178,10 +178,10 @@
 {
     FT_Open_Args openArgs;
     memset(&openArgs, 0, sizeof(openArgs));
-	openArgs.flags = FT_OPEN_MEMORY;
-	openArgs.memory_base = reinterpret_cast<FT_Byte*>(m_bufFontData.GetBuffer()), 
-	openArgs.memory_size = static_cast<FT_Long>(m_bufFontData.GetSize());
-	FT_Error error = FT_Open_Face( *m_pLibrary, &openArgs, 0, &m_pFace ); 
+    openArgs.flags = FT_OPEN_MEMORY;
+    openArgs.memory_base = reinterpret_cast<FT_Byte*>(m_bufFontData.GetBuffer()), 
+    openArgs.memory_size = static_cast<FT_Long>(m_bufFontData.GetSize());
+    FT_Error error = FT_Open_Face( *m_pLibrary, &openArgs, 0, &m_pFace ); 
     if( error ) 
     {
         PdfError::LogMessage( eLogSeverity_Critical, "FreeType returned the error %i when calling FT_New_Face for a buffered font.", error );
@@ -212,7 +212,7 @@
     m_dStrikeOutPosition  = 0.0;
     m_dStrikeOutThickness = 0.0;
     m_fFontSize           = 0.0f;
-	 m_bSymbol = pIsSymbol;
+     m_bSymbol = pIsSymbol;
     m_bIsBold = false;
     m_bIsItalic = false;
 
@@ -305,7 +305,7 @@
     return s ? s : "";
 }
 
-void PdfFontMetricsFreetype::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const
+void PdfFontMetricsFreetype::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding ) const
 {
     unsigned int  i;
     PdfArray  list;
@@ -317,20 +317,29 @@
 
     for( i=nFirst;i<=nLast;i++ )
     {
-        if( i < PODOFO_WIDTH_CACHE_SIZE )
+        if( i < PODOFO_WIDTH_CACHE_SIZE && pEncoding == NULL )
             list.push_back( PdfVariant( m_vecWidth[i] ) );
         else
         {
-            if( FT_Load_Char( m_pFace, i, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ) == 0 )  // | FT_LOAD_NO_RENDER
+            if (pEncoding != NULL)
             {
+                unsigned short shCode = pEncoding->GetCharCode(i);
+#ifdef PODOFO_IS_LITTLE_ENDIAN
+                shCode = ((shCode & 0x00FF) << 8) | ((shCode & 0xFF00) >> 8);
+#endif
+                list.push_back( PdfVariant( (pdf_int64)this->GetGlyphWidth(this->GetGlyphId(shCode)) ) );
+                continue;
+            }
+            else if( FT_Load_Char( m_pFace, i, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ) == 0 )  // | FT_LOAD_NO_RENDER
+            {
                 // zero return code is success!
                 list.push_back( PdfVariant( m_pFace->glyph->metrics.horiAdvance * 1000.0 / m_pFace->units_per_EM ) );
                 continue;
             }
-                //PODOFO_RAISE_ERROR( ePdfError_FreeType );
-                list.push_back( PdfVariant( 0.0 ) );
-            }
+            //PODOFO_RAISE_ERROR( ePdfError_FreeType );
+            list.push_back( PdfVariant( 0.0 ) );
         }
+    }
 
     var = PdfVariant( list );
 }
@@ -353,7 +362,7 @@
 
 double PdfFontMetricsFreetype::GetGlyphWidth( const char* pszGlyphname ) const
 {
-	return GetGlyphWidth( FT_Get_Name_Index( m_pFace, const_cast<char *>(pszGlyphname) ) );
+    return GetGlyphWidth( FT_Get_Name_Index( m_pFace, const_cast<char *>(pszGlyphname) ) );
 }
 
 void PdfFontMetricsFreetype::GetBoundingBox( PdfArray & array ) const
@@ -445,7 +454,7 @@
 // -----------------------------------------------------
 double PdfFontMetricsFreetype::GetStrikeOutPosition() const
 {
-	return m_dStrikeOutPosition * this->GetFontSize();
+    return m_dStrikeOutPosition * this->GetFontSize();
 }
 
 // -----------------------------------------------------
Index: podofo/trunk/src/doc/PdfFontMetricsFreetype.h
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsFreetype.h	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsFreetype.h	(working copy)
@@ -106,8 +106,9 @@
      *  \param var the final width array is written to this PdfVariant
      *  \param nFirst first character to be in the array
      *  \param nLast last character code to be in the array
+     *  \param pEncoding encoding for correct character widths. If not passed default (latin1) encoding is used
      */
-    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const;
+    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding = NULL ) const;
 
     /** Get the width of a single glyph id
      *
Index: podofo/trunk/src/doc/PdfFontMetricsObject.cpp
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsObject.cpp	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsObject.cpp	(working copy)
@@ -223,7 +223,7 @@
         return m_dDefWidth;
 }
 
-void PdfFontMetricsObject::GetWidthArray( PdfVariant & var, unsigned int, unsigned int ) const
+void PdfFontMetricsObject::GetWidthArray( PdfVariant & var, unsigned int, unsigned int, const PdfEncoding* ) const
 {
     var = m_width;
 }
Index: podofo/trunk/src/doc/PdfFontMetricsObject.h
===================================================================
--- podofo/trunk/src/doc/PdfFontMetricsObject.h	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontMetricsObject.h	(working copy)
@@ -63,8 +63,9 @@
      *  \param var the final width array is written to this PdfVariant
      *  \param nFirst first character to be in the array
      *  \param nLast last character code to be in the array
+     *  \param pEncoding encoding for correct character widths. If not passed default (latin1) encoding is used
      */
-    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const;
+    virtual void GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast, const PdfEncoding* pEncoding = NULL ) const;
 
     /** Get the width of a single glyph id
      *
Index: podofo/trunk/src/doc/PdfFontSimple.cpp
===================================================================
--- podofo/trunk/src/doc/PdfFontSimple.cpp	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontSimple.cpp	(working copy)
@@ -67,7 +67,7 @@
         PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
     }
 
-    m_pMetrics->GetWidthArray( *pWidth, m_pEncoding->GetFirstChar(), m_pEncoding->GetLastChar() );
+    m_pMetrics->GetWidthArray( *pWidth, m_pEncoding->GetFirstChar(), m_pEncoding->GetLastChar(), m_pEncoding );
 
     pDescriptor = this->GetObject()->GetOwner()->CreateObject( "FontDescriptor" );
     if( !pDescriptor )
Index: podofo/trunk/src/doc/PdfFontType1Base14.cpp
===================================================================
--- podofo/trunk/src/doc/PdfFontType1Base14.cpp	(revision 1722)
+++ podofo/trunk/src/doc/PdfFontType1Base14.cpp	(working copy)
@@ -74,32 +74,16 @@
     this->GetObject()->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("Type1"));
     this->GetObject()->GetDictionary().AddKey("BaseFont", PdfName( pMetrics->GetFontname() ) );
 
-    PdfFontMetricsBase14 *pBase14Metrics = dynamic_cast<PdfFontMetricsBase14*>(pMetrics);
-
-    if (pBase14Metrics == NULL)
+    PdfObject *pWidth = this->GetObject()->GetOwner()->CreateObject();
+    if( !pWidth )
     {
         PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
     }
 
-    // Width array for correct character spacing
-    PdfArray arWidths;
-    for ( int i = m_pEncoding->GetFirstChar(); i <= m_pEncoding->GetLastChar(); i++ )
-    {
-        // Chars below 32 are invisible- don't solve it
-        if (i < 32)
-        {
-            continue;
-        }
+    m_pMetrics->GetWidthArray( *pWidth, m_pEncoding->GetFirstChar(), m_pEncoding->GetLastChar(), m_pEncoding );
 
-        unsigned short shCode = m_pEncoding->GetCharCode(i);
-#ifdef PODOFO_IS_LITTLE_ENDIAN
-        shCode = ((shCode & 0x00FF) << 8) | ((shCode & 0xFF00) >> 8);
-#endif
-
-        arWidths.push_back(PdfObject( (pdf_int64)pBase14Metrics->GetGlyphWidth(pBase14Metrics->GetGlyphIdUnicode(shCode) )));
-    }
-    this->GetObject()->GetDictionary().AddKey("Widths", arWidths );
-    this->GetObject()->GetDictionary().AddKey("FirstChar", PdfVariant( static_cast<pdf_int64>(32) ) );
+    this->GetObject()->GetDictionary().AddKey("Widths", pWidth->Reference() );
+    this->GetObject()->GetDictionary().AddKey("FirstChar", PdfVariant( static_cast<pdf_int64>(m_pEncoding->GetFirstChar()) ) );
     this->GetObject()->GetDictionary().AddKey("LastChar", PdfVariant( static_cast<pdf_int64>(m_pEncoding->GetLastChar()) ) );
 
     m_pEncoding->AddToDictionary( this->GetObject()->GetDictionary() ); // Add encoding key
