Changeset 156 for trunk/Lucide


Ignore:
Timestamp:
Nov 17, 2006, 10:42:35 PM (15 years ago)
Author:
Eugene Romanenko
Message:

optimized unicode conversion, fixes crash in uconv.dll (closes #97)

Location:
trunk/Lucide/SOURCE
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Lucide/SOURCE/gui/clipbrd.cpp

    r37 r156  
    2222 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2323 * in which case the provisions of the LGPL are applicable instead of those
    24  * above. If you wish to allow use of your version of this file only under the 
     24 * above. If you wish to allow use of your version of this file only under the
    2525 * terms of the LGPL, and not to allow others to use your version of this file
    2626 * under the terms of the CDDL, indicate your decision by deleting the
    2727 * provisions above and replace them with the notice and other provisions
    2828 * required by the LGPL. If you do not delete the provisions above, a recipient
    29  * may use your version of this file under the terms of any one of the CDDL 
     29 * may use your version of this file under the terms of any one of the CDDL
    3030 * or the LGPL.
    3131 *
     
    3636#define INCL_DOS
    3737#include <os2.h>
     38
     39#include <uconv.h>
     40#include <unidef.h>
    3841
    3942#include <string.h>
     
    5962}
    6063
     64
    6165void textToClipbrd( HAB hab, const char *text )
    6266{
     67    void *objtouni, *objtosys;
     68    int rc = ULS_SUCCESS;
     69    rc = UniCreateUconvObject( (UniChar *)L"UTF-8", &objtouni );
     70    if ( rc != ULS_SUCCESS ) {
     71        return;
     72    }
     73    rc = UniCreateUconvObject( (UniChar *)L"", &objtosys );
     74    if ( rc != ULS_SUCCESS ) {
     75        UniFreeUconvObject( objtouni );
     76        return;
     77    }
     78
     79    uconv_attribute_t attr;
     80    UniQueryUconvObject( objtouni, &attr, sizeof(attr), NULL, NULL, NULL );
     81    attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
     82    UniSetUconvObject( objtouni, &attr );
     83    UniQueryUconvObject( objtosys, &attr, sizeof(attr), NULL, NULL, NULL );
     84    attr.options = UCONV_OPTION_SUBSTITUTE_BOTH;
     85    UniSetUconvObject( objtosys, &attr );
     86
    6387    size_t len = 0;
    6488    size_t olen = 0;
    65     const char *tsav = text;
    6689
    6790    if ( WinOpenClipbrd( hab ) )
     
    6992        WinEmptyClipbrd( hab );
    7093
     94        size_t cSubs = 0;
    7195        len = strlen( text );
    72         olen = (len + 2)*2;
    73 
    74         void *memuni = NULL;
     96        olen = ( len + 2 ) * 2;
     97        void *shmemuni = NULL;
     98        void *shmemsys = NULL;
    7599
    76100        // place to clipboard as unicode
    77         if ( DosAllocSharedMem( &memuni, NULL, olen, fALLOCSHR ) == 0 )
     101        if ( DosAllocSharedMem( &shmemuni, NULL, olen, fALLOCSHR ) == 0 )
    78102        {
    79             memset( memuni, 0, olen );
    80             void *tmem = memuni;
    81 
    82             tsav = text;
    83             cnvUTF8ToUni( &text, &len, (char **)&memuni, &olen );
    84             text = tsav;
     103            memset( shmemuni, 0, olen );
     104            size_t unilen = olen / sizeof( UniChar );
     105            UniChar *tmpuni = (UniChar *)shmemuni;
     106            UniUconvToUcs( objtouni, (void **)&text, &len, &tmpuni, &unilen, &cSubs );
     107            unilen = UniStrlen( (UniChar *)shmemuni );
     108            void *memuni = (void *)new char[ olen ];
     109            memcpy( memuni, shmemuni, olen );
    85110
    86111            ULONG ulFormatID = RegisterClipboardFormat( kUnicodeMime );
    87             WinSetClipbrdData( hab, (ULONG)tmem, ulFormatID, CFI_POINTER );
     112            WinSetClipbrdData( hab, (ULONG)shmemuni, ulFormatID, CFI_POINTER );
     113
     114            int liglen = uniLigaturesLength( (UniChar *)memuni );
     115            if ( liglen > 0 )  // string contain ligature(s)
     116            {
     117                unsigned ulen_tmp = ( unilen + liglen + 1 ) * sizeof( UniChar );
     118                char *uni_tmp = new char[ ulen_tmp ];
     119                uniReplaceLigatures( (UniChar *)memuni, (UniChar *)uni_tmp );
     120                delete memuni;
     121                memuni = uni_tmp;
     122                unilen = UniStrlen( (UniChar *)memuni );
     123            }
     124            uniConvertSpChars( (UniChar *)memuni );
     125
     126            // place to clipboard as current codepage
     127            if ( DosAllocSharedMem( &shmemsys, NULL, olen, fALLOCSHR ) == 0 )
     128            {
     129                memset( shmemsys, 0, olen );
     130
     131                cSubs = 0;
     132                tmpuni = (UniChar *)memuni;
     133                void *tmpsys = shmemsys;
     134                UniUconvFromUcs( objtosys, &tmpuni, &unilen, &tmpsys, &olen, &cSubs );
     135
     136                WinSetClipbrdData( hab, (ULONG)shmemsys, CF_TEXT, CFI_POINTER );
     137            }
     138            delete memuni;
    88139        }
    89 
    90         len = strlen( text );
    91         olen = (len + 2)*2;
    92         void *memcp = NULL;
    93 
    94         // place to clipboard as current codepage
    95         if ( DosAllocSharedMem( &memcp, NULL, olen, fALLOCSHR ) == 0 )
    96         {
    97             memset( memcp, 0, olen );
    98             void *tmem = memcp;
    99 
    100             tsav = text;
    101             cnvUTF8ToSys( &text, &len, (char **)&memcp, &olen );
    102                         text = tsav;
    103 
    104             WinSetClipbrdData( hab, (ULONG)tmem, CF_TEXT, CFI_POINTER );
    105         }
    106 
    107140
    108141        WinCloseClipbrd( hab );
    109142    }
     143
     144    UniFreeUconvObject( objtouni );
     145    UniFreeUconvObject( objtosys );
    110146}
    111147
  • trunk/Lucide/SOURCE/gui/makefile

    r154 r156  
    7474lib ..\plugins\ludoc\ludoc
    7575lib somtk
     76lib libconv
     77lib libuls
    7678export LucideMain
    7779| tmpmake.lnk >NUL
  • trunk/Lucide/SOURCE/plugins/ludoc/cpconv.cpp

    r113 r156  
    3333
    3434
    35 #define INCL_DOS
    36 #include <os2.h>
    37 
    38 #include <string.h>
    39 #include <malloc.h>
    40 #include <stdio.h>
    41 
    4235#include <uconv.h>
    4336
    4437
    45 class cpconv
    46 {
    47     protected:
    48         int  err;
    49         void *objtoucs;
    50         void *objfromucs;
    51     public:
    52         cpconv( int cpfrom, int cpto = 0 );
    53         cpconv( UniChar *cpfrom, UniChar *cpto );
    54         ~cpconv();
    55         int conv( int chfrom );
    56         int conv( const char **in, size_t *in_left, char **out, size_t *out_left );
    57 };
    58 
    59 cpconv::cpconv( UniChar *cpfrom, UniChar *cpto )
    60 {
    61     err = 0;
    62     int         rc = ULS_SUCCESS;
    63 
    64     rc = UniCreateUconvObject( cpfrom, &objtoucs );
    65     if (rc != ULS_SUCCESS)
    66     {
    67         err = 1;
    68         return;
    69     }
    70 
    71     uconv_attribute_t attr;
    72     UniQueryUconvObject(objtoucs, &attr, sizeof(attr), NULL, NULL, NULL);
    73     attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
    74     UniSetUconvObject(objtoucs, &attr);
    75 
    76     rc = UniCreateUconvObject( cpto, &objfromucs );
    77     if (rc != ULS_SUCCESS)
    78     {
    79         UniFreeUconvObject( objtoucs );
    80         err = 1;
    81         return;
    82     }
    83     UniQueryUconvObject(objfromucs, &attr, sizeof(uconv_attribute_t), NULL, NULL, NULL);
    84     attr.options = UCONV_OPTION_SUBSTITUTE_BOTH;
    85     UniSetUconvObject(objfromucs, &attr);
    86 }
    87 
    88 cpconv::cpconv( int cpfrom, int cpto )
    89 {
    90     err = 0;
    91 
    92     UniChar     ucs_code_page[12];
    93     size_t      num_elems = 12;
    94     int         rc = ULS_SUCCESS;
    95 
    96     rc = UniMapCpToUcsCp(cpfrom, ucs_code_page, num_elems);
    97     if (rc != ULS_SUCCESS)
    98     {
    99         err = 1;
    100         return;
    101     }
    102 
    103     rc = UniCreateUconvObject(ucs_code_page, &objtoucs);
    104     if (rc != ULS_SUCCESS)
    105     {
    106         err = 1;
    107         return;
    108     }
    109 
    110     uconv_attribute_t attr;
    111     UniQueryUconvObject(objtoucs, &attr, sizeof(attr), NULL, NULL, NULL);
    112     attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
    113     UniSetUconvObject(objtoucs, &attr);
    114 
    115     rc = UniMapCpToUcsCp(cpto, ucs_code_page, num_elems);
    116     if (rc != ULS_SUCCESS)
    117     {
    118         UniFreeUconvObject( objtoucs );
    119         err = 1;
    120         return;
    121     }
    122 
    123     rc = UniCreateUconvObject(ucs_code_page, &objfromucs);
    124     if (rc != ULS_SUCCESS)
    125     {
    126         UniFreeUconvObject( objtoucs );
    127         err = 1;
    128         return;
    129     }
    130     UniQueryUconvObject(objfromucs, &attr, sizeof(uconv_attribute_t), NULL, NULL, NULL);
    131     attr.options = UCONV_OPTION_SUBSTITUTE_BOTH;
    132     UniSetUconvObject(objfromucs, &attr);
    133 }
    134 
    135 cpconv::~cpconv()
    136 {
    137     if ( !err )
    138     {
    139         UniFreeUconvObject( objtoucs );
    140         UniFreeUconvObject( objfromucs );
    141     }
    142 }
    143 
    144 // convert one char
    145 int cpconv::conv( int chfrom )
    146 {
    147     int rc = ULS_SUCCESS;
    148     size_t ns = 0;
    149     int chto = 0;
    150 
    151     if ( err )  return chfrom;
    152 
    153     size_t len = 1;
    154     UniChar unichar;
    155     UniChar *punichar = &unichar;
    156     void *pchfrom = &chfrom;
    157     void *pchto = &chto;
    158 
    159     rc = UniUconvToUcs( objtoucs, &pchfrom, &len, &punichar, &len, &ns);
    160     if ( rc != ULS_SUCCESS )  return chfrom;
    161 
    162     len = 1;
    163     punichar = &unichar;
    164     ns = 0;
    165     rc = UniUconvFromUcs( objfromucs, &punichar, &len, &pchto, &len, &ns);
    166     if ( rc != ULS_SUCCESS )  return chfrom;
    167 
    168     return chto;
    169 }
    170 
    171 int cpconv::conv( const char **in, size_t *in_left, char **out, size_t *out_left )
    172 {
    173     int       rc;
    174     size_t    sl;
    175     size_t    nonid;
    176     UniChar  *ucs;
    177     UniChar  *orig_ucs;
    178     size_t    retval = 0;
    179 
    180     if (!in || !*in) {
    181         return 0;
    182     }
    183 
    184     sl =  *in_left;
    185     //ucs = new UniChar[ sl ];
    186     // have crashes in libc memmanager due to frequent alloc/free
    187     // use system malloc routines as workaround
    188     DosAllocMem( (PPVOID)&ucs, sl * sizeof( UniChar ), fALLOC );
    189     orig_ucs = ucs;
    190 
    191     rc = UniUconvToUcs( objtoucs, (void **)in, in_left, &ucs, &sl, &retval );
    192     if ( rc != 0 ) {
    193         //delete ucs;
    194         DosFreeMem( ucs );
    195         err = 1;
    196         return -1;
    197     }
    198 
    199     sl = ucs - orig_ucs;
    200     ucs = orig_ucs;
    201     rc = UniUconvFromUcs( objfromucs, &ucs, &sl, (void **)out, out_left, &nonid );
    202     //delete ucs;
    203     DosFreeMem( ucs );
    204 
    205     if ( rc != 0 ) {
    206         err = 1;
    207         return -1;
    208     }
    209 
    210     retval += nonid;
    211     return 0;
    212 }
    213 
    214 extern "C" LONG APIENTRY cnvUniToUTF8( const char **in, unsigned *in_left,
    215                                        char **out, unsigned *out_left )
    216 {
    217     cpconv c( 1200, 1208 );
    218     return c.conv( in, in_left, out, out_left );
    219 }
    220 
    221 extern "C" LONG APIENTRY cnvUniBEToUTF8( const char **in, unsigned *in_left,
    222                                          char **out, unsigned *out_left )
    223 {
    224     cpconv c( (UniChar *)(L"UCS-2@endian=big"), (UniChar *)(L"UTF-8") );
    225     return c.conv( in, in_left, out, out_left );
    226 }
    227 
    228 extern "C" LONG APIENTRY cnvUTF8ToUni( const char **in, unsigned *in_left,
    229                                        char **out, unsigned *out_left )
    230 {
    231     cpconv c( 1208, 1200 );
    232     return c.conv( in, in_left, out, out_left );
    233 }
    234 
    235 
    23638// Converts special non-ascii chars to suitable ascii chars
    237 static void convSpchars( UniChar *uni )
     39extern "C" VOID APIENTRY uniConvertSpChars( UniChar *uni )
    23840{
    23941    while ( *uni )
     
    25254                *uni = 0x0022; // "
    25355                break;
     56            case 0x2013:
    25457            case 0x2014:
    25558                *uni = 0x002D; // -
     
    309112// length to fit the string with converted ligatures.
    310113// If no ligatures in string - returns zero.
    311 static int ligaturesLength( UniChar *str )
     114extern "C" LONG APIENTRY uniLigaturesLength( UniChar *str )
    312115{
    313     int llen = 0;
     116    LONG llen = 0;
    314117    while ( *str != 0 ) {
    315118        llen += isLigature( *str++ );
     
    320123// replaces ligatures in src into dst
    321124// src remains unchanged
    322 static void replLigatures( UniChar *src, UniChar *dst )
     125extern "C" VOID APIENTRY uniReplaceLigatures( UniChar *src, UniChar *dst )
    323126{
    324127    while ( *src != 0 )
     
    337140}
    338141
    339 extern "C" LONG APIENTRY cnvUTF8ToSys( const char **in, unsigned *in_left,
    340                                        char **out, unsigned *out_left )
    341 {
    342     unsigned ulen = ( (*in_left) * 2 ) + 2;
    343     char *uni = new char[ ulen ];
    344     memset( uni, 0, ulen );
    345     char *savuni = uni;
    346     unsigned savulen = ulen;
    347     cnvUTF8ToUni( in, in_left, &uni, &ulen );
    348     uni = savuni;
    349     ulen = savulen;
    350     int liglen = ligaturesLength( (UniChar *)uni );
    351     if ( liglen > 0 )  // string contain ligature(s)
    352     {
    353         unsigned ulen_tmp = ulen + ( liglen * 2 );
    354         char *uni_tmp = new char[ ulen_tmp ];
    355         replLigatures( (UniChar *)uni, (UniChar *)uni_tmp );
    356         delete uni;
    357         uni = uni_tmp;
    358         ulen = ulen_tmp;
    359     }
    360     convSpchars( (UniChar *)uni );
    361     cpconv c( 1200 );
    362     LONG rc = c.conv( (const char **)&uni, &ulen, out, out_left );
    363     uni = savuni;
    364     delete uni;
    365     return rc;
    366 }
    367 
    368 extern "C" LONG APIENTRY cnvUniBEToSys( const char **in, unsigned *in_left,
    369                                          char **out, unsigned *out_left )
    370 {
    371     unsigned ulen = ( (*in_left) * 2 ) + 2;
    372     char *uni = new char[ ulen ];
    373     memset( uni, 0, ulen );
    374     char *savuni = uni;
    375     unsigned savulen = ulen;
    376     cpconv c1( (UniChar *)(L"UCS-2@endian=big"), (UniChar *)(L"UCS-2") );
    377     c1.conv( in, in_left, &uni, &ulen );
    378     uni = savuni;
    379     ulen = savulen;
    380     convSpchars( (UniChar *)uni );
    381     cpconv c2( 1200 );
    382     LONG rc = c2.conv( (const char **)&uni, &ulen, out, out_left );
    383     uni = savuni;
    384     delete uni;
    385     return rc;
    386 }
    387 
    388 extern "C" LONG APIENTRY cnvUniToSys( const char **in, unsigned *in_left,
    389                                       char **out, unsigned *out_left )
    390 {
    391     convSpchars( (UniChar *)in );
    392     cpconv c( 1200 );
    393     return c.conv( (const char **)&in, in_left, out, out_left );
    394 }
    395 
    396 extern "C" LONG APIENTRY cnvSysToUCS2( const char **in, unsigned *in_left,
    397                                        char **out, unsigned *out_left )
    398 {
    399     cpconv c( (UniChar *)(L""), (UniChar *)(L"UCS-2") );
    400     return c.conv( in, in_left, out, out_left );
    401 }
    402 
    403 
    404 // test
    405 /*void main()
    406 {
    407     const char *testutf8 = "test UTF-8  ’¥áâ! à®¢¥àª !";
    408     char buf[ 100 ];
    409     memset( buf, 0, sizeof( buf ) );
    410     char *bufsav = buf;
    411     char *buf1 = buf;
    412     unsigned in_len = strlen( testutf8 );
    413     unsigned out_len = sizeof( buf );
    414 
    415     cnvUTF8ToUCS4( &testutf8, &in_len, &buf1, &out_len );
    416 
    417     for ( int i = 0; i<100; i++ )
    418     {
    419         printf( ":%d:", (int)bufsav[i] );
    420     }
    421     printf( "\n" );
    422 }
    423 */
  • trunk/Lucide/SOURCE/plugins/ludoc/cpconv.h

    r35 r156  
    3636#define __cpconv_h
    3737
    38 #ifndef APIENTRY
    39 #define APIENTRY _System
    40 #endif
     38#include <unidef.h>
    4139
    4240#ifdef __cplusplus
     
    4442#endif
    4543
    46 long APIENTRY cnvUniToUTF8( const char **in, unsigned *in_left,
    47                             char **out, unsigned *out_left );
    48 long APIENTRY cnvUniBEToUTF8( const char **in, unsigned *in_left,
    49                               char **out, unsigned *out_left );
    50 long APIENTRY cnvUTF8ToUni( const char **in, unsigned *in_left,
    51                             char **out, unsigned *out_left );
    52 long APIENTRY cnvUTF8ToSys( const char **in, unsigned *in_left,
    53                             char **out, unsigned *out_left );
    54 long APIENTRY cnvUniBEToSys( const char **in, unsigned *in_left,
    55                              char **out, unsigned *out_left );
    56 long APIENTRY cnvUniToSys( const char **in, unsigned *in_left,
    57                            char **out, unsigned *out_left );
    58 long APIENTRY cnvSysToUCS2( const char **in, unsigned *in_left,
    59                             char **out, unsigned *out_left );
     44// Converts special non-ascii chars to suitable ascii chars
     45VOID APIENTRY uniConvertSpChars( UniChar *uni );
     46
     47// Return number of chars which should be added to string
     48// length to fit the string with converted ligatures.
     49// If no ligatures in string - returns zero.
     50LONG APIENTRY uniLigaturesLength( UniChar *str );
     51
     52// replaces ligatures in src into dst
     53// src remains unchanged
     54VOID APIENTRY uniReplaceLigatures( UniChar *src, UniChar *dst );
    6055                           
    6156#ifdef __cplusplus
  • trunk/Lucide/SOURCE/plugins/ludoc/ludoc.def

    r145 r156  
    1717    _LuIndexNodeClassData
    1818    _LuIndexNodeCClassData
    19     cnvUniToUTF8
    20     cnvUniBEToUTF8
    21     cnvUTF8ToUni
    22     cnvUTF8ToSys
    23     cnvUniBEToSys
    24     cnvUniToSys
    25     cnvSysToUCS2
     19    uniConvertSpChars
     20    uniLigaturesLength
     21    uniReplaceLigatures
  • trunk/Lucide/SOURCE/plugins/ludoc/makefile

    r145 r156  
    5252export getSupportedExtensions
    5353export getDescription
    54 export cnvUniToUTF8
    55 export cnvUniBEToUTF8
    56 export cnvUTF8ToUni
    57 export cnvUTF8ToSys
    58 export cnvUniBEToSys
    59 export cnvUniToSys
    60 export cnvSysToUCS2
     54export uniConvertSpChars
     55export uniLigaturesLength
     56export uniReplaceLigatures
    6157| tmpmake.lnk >NUL
    6258    wlink @tmpmake.lnk
  • trunk/Lucide/SOURCE/plugins/lupoppler/lupoppler.cpp

    r155 r156  
    6060using namespace std;
    6161#include <time.h>
     62#include <uconv.h>
    6263#include "cpconv.h"
    6364
     
    127128        char *text;
    128129        HMTX mutex;
     130
     131        void *objUtf8;
     132        void *objUniBe;
     133        void *objSys;
    129134
    130135        PopplerDocument();
     
    140145    mutex      = NULLHANDLE;
    141146    DosCreateMutexSem( NULL, &mutex, 0, FALSE );
     147
     148    uconv_attribute_t attr;
     149    UniCreateUconvObject( (UniChar *)L"UTF-8", &objUtf8 );
     150    UniQueryUconvObject( objUtf8, &attr, sizeof(attr), NULL, NULL, NULL );
     151    attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
     152    UniSetUconvObject( objUtf8, &attr );
     153
     154    UniCreateUconvObject( (UniChar *)L"UCS-2@endian=big", &objUniBe );
     155    UniQueryUconvObject( objUniBe, &attr, sizeof(attr), NULL, NULL, NULL );
     156    attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
     157    UniSetUconvObject( objUniBe, &attr );
     158
     159    UniCreateUconvObject( (UniChar *)L"", &objSys );
     160    UniQueryUconvObject( objSys, &attr, sizeof(attr), NULL, NULL, NULL );
     161    attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
     162    attr.options = UCONV_OPTION_SUBSTITUTE_BOTH;
     163    UniSetUconvObject( objSys, &attr );
    142164}
    143165
     
    149171    delete text;
    150172    DosCloseMutexSem( mutex );
     173
     174    UniFreeUconvObject( objUtf8 );
     175    UniFreeUconvObject( objUniBe );
     176    UniFreeUconvObject( objSys );
    151177}
    152178
     
    877903}
    878904
    879 static char *newstrFromUTF8( const char *s )
    880 {
    881     unsigned blen = strlen( s ) + 1;
     905static char *newstrFromUTF8( const char *s, void *objUtf8, void *objSys )
     906{
     907    size_t cSubs = 0;
     908    size_t len = strlen( s ) + 1;
     909    size_t unilen = len + 2;
     910    UniChar *unibuf = new UniChar[ unilen ];
     911    UniChar *tmpuni = unibuf;
     912    UniUconvToUcs( objUtf8, (void **)&s, &len, &tmpuni, &unilen, &cSubs );
     913    unilen = UniStrlen( unibuf );
     914
     915    int liglen = uniLigaturesLength( unibuf );
     916    if ( liglen > 0 )  // string contain ligature(s)
     917    {
     918        unsigned ulen_tmp = ( unilen + liglen + 1 ) * sizeof( UniChar );
     919        char *uni_tmp = new char[ ulen_tmp ];
     920        uniReplaceLigatures( unibuf, (UniChar *)uni_tmp );
     921        delete unibuf;
     922        unibuf = (UniChar *)uni_tmp;
     923        unilen = UniStrlen( unibuf );
     924    }
     925    uniConvertSpChars( unibuf );
     926
     927    size_t blen = ( unilen + 1 ) * 2;
    882928    char *b = new char[ blen ];
    883929    memset( b, 0, blen );
    884930    char *bsav = b;
    885     const char *from = s;
    886     unsigned flen = strlen( s );
    887     cnvUTF8ToSys( &from, &flen, &b, &blen );
     931    tmpuni = unibuf;
     932    cSubs = 0;
     933    UniUconvFromUcs( objSys, &tmpuni, &unilen, (void **)&b, &blen, &cSubs );
     934    delete unibuf;
    888935    return bsav;
    889936}
    890937
    891 static void add_item( Environment *ev, PDFDoc *doc, LuIndexNode *n, GooList *items )
     938static void add_item( Environment *ev, PDFDoc *doc, LuIndexNode *n, GooList *items,
     939                      void *objUtf8, void *objSys )
    892940{
    893941    if ( items == NULL ) {
     
    903951        LuLink evlink;
    904952        char *t1 = unicode_to_char( item->getTitle(), item->getTitleLength() );
    905         char *t2 = newstrFromUTF8( t1 );
     953        char *t2 = newstrFromUTF8( t1, objUtf8, objSys );
    906954        build_link( doc, &evlink, t2, link_action );
    907955        delete t2;
     
    914962        {
    915963            GooList *citems = item->getKids();
    916             add_item( ev, doc, cn, citems );
     964            add_item( ev, doc, cn, citems, objUtf8, objSys );
    917965        }
    918966    }
     
    923971{
    924972    LuPopplerDocumentData *somThis = LuPopplerDocumentGetData(somSelf);
    925     PDFDoc *doc = ((PopplerDocument *)somThis->data)->doc;
     973    PopplerDocument *document = (PopplerDocument *)somThis->data;
     974    PDFDoc *doc = document->doc;
    926975
    927976    Outline *outline = doc->getOutline();
     
    936985
    937986    LuIndexNode *root = new LuIndexNode( ev, NULL );
    938     add_item( ev, doc, root, items );
     987    add_item( ev, doc, root, items, document->objUtf8, document->objSys );
    939988
    940989    return root;
     
    949998
    950999// return SOMMalloc'ed string
    951 static char *propcnv( GooString *s )
     1000static char *propcnv( GooString *s, void *objUniBe, void *objSys )
    9521001{
    9531002    if ( has_unicode_marker( s ) )
    9541003    {
    955         unsigned blen = s->getLength() * 2;
     1004        size_t cSubs = 0;
     1005        size_t unilen = s->getLength() + 1;
     1006        UniChar *unibuf = new UniChar[ unilen ];
     1007        UniChar *tmpuni = unibuf;
     1008        const char *from = s->getCString() + 2;
     1009        size_t fromlen = s->getLength() * 2;
     1010        UniUconvToUcs( objUniBe, (void **)&from, &fromlen, &tmpuni, &unilen, &cSubs );
     1011        unilen = UniStrlen( unibuf );
     1012
     1013        int liglen = uniLigaturesLength( unibuf );
     1014        if ( liglen > 0 )  // string contain ligature(s)
     1015        {
     1016            unsigned ulen_tmp = ( unilen + liglen + 1 ) * sizeof( UniChar );
     1017            char *uni_tmp = new char[ ulen_tmp ];
     1018            uniReplaceLigatures( unibuf, (UniChar *)uni_tmp );
     1019            delete unibuf;
     1020            unibuf = (UniChar *)uni_tmp;
     1021            unilen = UniStrlen( unibuf );
     1022        }
     1023        uniConvertSpChars( unibuf );
     1024
     1025        size_t blen = ( unilen + 1 ) * 2;
    9561026        char *b = (char *)SOMMalloc( blen );
    9571027        memset( b, 0, blen );
    9581028        char *bsav = b;
    959         const char *from = s->getCString() + 2;
    960         unsigned flen = s->getLength() - 2;
    961         cnvUniBEToSys( &from, &flen, &b, &blen );
     1029        tmpuni = unibuf;
     1030        cSubs = 0;
     1031        UniUconvFromUcs( objSys, &tmpuni, &unilen, (void **)&b, &blen, &cSubs );
     1032        delete unibuf;
    9621033        return bsav;
    9631034    }
     
    10561127{
    10571128    LuPopplerDocumentData *somThis = LuPopplerDocumentGetData(somSelf);
    1058     PDFDoc *doc = ((PopplerDocument *)somThis->data)->doc;
     1129    PopplerDocument *document = (PopplerDocument *)somThis->data;
     1130    PDFDoc *doc = document->doc;
    10591131
    10601132    LuDocumentInfo *info = (LuDocumentInfo *)SOMMalloc( sizeof( LuDocumentInfo ) );
     
    10691141
    10701142        if ( d->lookup( "Title", &obj )->isString() ) {
    1071             info->title = propcnv( obj.getString() );
     1143            info->title = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10721144            info->fields_mask |= LU_DOCUMENT_INFO_TITLE;
    10731145        }
    10741146        obj.free();
    10751147        if ( d->lookup( "Author", &obj )->isString() ) {
    1076             info->author = propcnv( obj.getString() );
     1148            info->author = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10771149            info->fields_mask |= LU_DOCUMENT_INFO_AUTHOR;
    10781150        }
    10791151        obj.free();
    10801152        if ( d->lookup( "Subject", &obj )->isString() ) {
    1081             info->subject = propcnv( obj.getString() );
     1153            info->subject = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10821154            info->fields_mask |= LU_DOCUMENT_INFO_SUBJECT;
    10831155        }
    10841156        obj.free();
    10851157        if ( d->lookup( "Keywords", &obj )->isString() ) {
    1086             info->keywords = propcnv( obj.getString() );
     1158            info->keywords = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10871159            info->fields_mask |= LU_DOCUMENT_INFO_KEYWORDS;
    10881160        }
    10891161        obj.free();
    10901162        if ( d->lookup( "Creator", &obj )->isString() ) {
    1091             info->creator = propcnv( obj.getString() );
     1163            info->creator = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10921164            info->fields_mask |= LU_DOCUMENT_INFO_CREATOR;
    10931165        }
    10941166        obj.free();
    10951167        if ( d->lookup( "Producer", &obj )->isString() ) {
    1096             info->producer = propcnv( obj.getString() );
     1168            info->producer = propcnv( obj.getString(), document->objUniBe, document->objSys );
    10971169            info->fields_mask |= LU_DOCUMENT_INFO_PRODUCER;
    10981170        }
    10991171        obj.free();
    11001172        if ( d->lookup( "CreationDate", &obj )->isString() ) {
    1101             char *d = propcnv( obj.getString() );
     1173            char *d = propcnv( obj.getString(), document->objUniBe, document->objSys );
    11021174            info->creation_date = propToDate( d );
    11031175            if ( (long)info->creation_date != -1 ) {
     
    11081180        obj.free();
    11091181        if ( d->lookup( "ModDate", &obj )->isString() ) {
    1110             char *d = propcnv( obj.getString() );
     1182            char *d = propcnv( obj.getString(), document->objUniBe, document->objSys );
    11111183            info->modified_date = propToDate( d );
    11121184            if ( (long)info->modified_date != -1 ) {
     
    12601332    // Convert string from system encoding to UCS-4
    12611333    // first, convert to UCS-2
    1262     unsigned text_len = strlen( text );
    1263     unsigned text_len_sav = text_len;
    1264     unsigned ucs2_len = ( text_len + 1 ) * 2;
     1334    size_t cSubs = 0;
     1335    size_t text_len = strlen( text );
     1336    size_t text_len_sav = text_len;
     1337    size_t ucs2_len = ( text_len + 1 ) * 2;
    12651338    char *ucs2 = new char[ ucs2_len ];
    12661339    memset( ucs2, 0, ucs2_len );
    12671340    char *ucs2sav = ucs2;
    1268     cnvSysToUCS2( (const char **)&text, &text_len, &ucs2, &ucs2_len );
     1341    UniUconvToUcs( document->objSys, (void **)&text, &text_len,
     1342                   (UniChar **)&ucs2, &ucs2_len, &cSubs );
    12691343    // second, convert UCS-2 to UCS-4
    12701344    short *uucs2 = (short *)ucs2sav;
  • trunk/Lucide/SOURCE/plugins/lupoppler/makefile

    r143 r156  
    3333lib ..\ludoc\ludoc
    3434lib somtk
     35lib libconv
     36lib libuls
    3537export LuPopplerDocumentNewClass
    3638export LuPopplerDocumentClassData
Note: See TracChangeset for help on using the changeset viewer.