bool ImportWordDocument( LVStreamRef stream, ldomDocument * m_doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback ) { AntiwordStreamGuard file(stream); setOptions(); inside_p = false; inside_table = false; table_col_count = 0; inside_list = 0; // 0=none, 1=ul, 2=ol alignment = 0; inside_li = false; last_space_char = false; sLeftIndent = 0; /* Left indentation in twips */ sLeftIndent1 = 0; /* First line left indentation in twips */ sRightIndent = 0; /* Right indentation in twips */ usBeforeIndent = 0; /* Vertical indent before paragraph in twips */ usAfterIndent = 0; /* Vertical indent after paragraph in twips */ BOOL bResult = 0; diagram_type *pDiag; int iWordVersion; lUInt32 lFilesize = (lUInt32)stream->GetSize(); iWordVersion = iGuessVersionNumber(file, lFilesize); if (iWordVersion < 0 || iWordVersion == 3) { if (bIsRtfFile(file)) { CRLog::error("not a Word Document." " It is probably a Rich Text Format file"); } if (bIsWordPerfectFile(file)) { CRLog::error("not a Word Document." " It is probably a Word Perfect file"); } else { CRLog::error("not a Word Document"); } return FALSE; } /* Reset any reading done during file testing */ stream->SetPos(0); ldomDocumentWriter w(m_doc); writer = &w; doc = m_doc; image_index = 0; pDiag = pCreateDiagram("cr3", "filename.doc"); if (pDiag == NULL) { return false; } bResult = bWordDecryptor(file, lFilesize, pDiag); vDestroyDiagram(pDiag); doc = NULL; writer = NULL; #ifdef _DEBUG #define SAVE_COPY_OF_LOADED_DOCUMENT 1//def _DEBUG #endif if ( bResult!=0 ) { #ifdef SAVE_COPY_OF_LOADED_DOCUMENT //def _DEBUG LVStreamRef ostream = LVOpenFileStream( "/tmp/test_save_source.xml", LVOM_WRITE ); if ( !ostream.isNull() ) m_doc->saveToStream( ostream, "utf-16" ); #endif } return bResult!=0; }
bool TexHyph::load( LVStreamRef stream ) { int w = isCorrectHyphFile(stream.get()); int patternCount = 0; if (w) { _hash = stream->crc32(); int i; lvsize_t dw; lvByteOrderConv cnv; int hyph_count = w; thyph hyph; lvpos_t p = 78 + (hyph_count * 8 + 2); stream->SetPos(p); if ( stream->SetPos(p)!=p ) return false; lChar16 charMap[256]; unsigned char buf[0x10000]; memset( charMap, 0, sizeof( charMap ) ); // make char map table for (i=0; i<hyph_count; i++) { if ( stream->Read( &hyph, 522, &dw )!=LVERR_OK || dw!=522 ) return false; cnv.msf( &hyph.len ); //rword(_main_hyph[i].len); lvpos_t newPos; if ( stream->Seek( hyph.len, LVSEEK_CUR, &newPos )!=LVERR_OK ) return false; cnv.msf( hyph.wl ); cnv.msf( hyph.wu ); charMap[ (unsigned char)hyph.al ] = hyph.wl; charMap[ (unsigned char)hyph.au ] = hyph.wu; // lChar16 ch = hyph.wl; // CRLog::debug("wl=%s mask=%c%c", LCSTR(lString16(&ch, 1)), hyph.mask0[0], hyph.mask0[1]); if (hyph.mask0[0]!='0'||hyph.mask0[1]!='0') { unsigned char pat[4]; pat[0] = hyph.al; pat[1] = hyph.mask0[0]; pat[2] = hyph.mask0[1]; pat[3] = 0; TexPattern * pattern = new TexPattern(pat, 1, charMap); #if DUMP_PATTERNS==1 CRLog::debug("Pattern: '%s' - %s", LCSTR(lString16(pattern->word)), pattern->attr ); #endif addPattern( pattern ); patternCount++; } } if ( stream->SetPos(p)!=p ) return false; for (i=0; i<hyph_count; i++) { stream->Read( &hyph, 522, &dw ); if (dw!=522) return false; cnv.msf( &hyph.len ); stream->Read(buf, hyph.len, &dw); if (dw!=hyph.len) return false; unsigned char * p = buf; unsigned char * end_p = p + hyph.len; while ( p < end_p ) { lUInt8 sz = *p++; if ( p + sz > end_p ) break; TexPattern * pattern = new TexPattern( p, sz, charMap ); #if DUMP_PATTERNS==1 CRLog::debug("Pattern: '%s' - %s", LCSTR(lString16(pattern->word)), pattern->attr); #endif addPattern( pattern ); patternCount++; p += sz + sz + 1; } } return patternCount>0; } else { // tex xml format as for FBReader lString16Collection data; HyphPatternReader reader( data ); LVXMLParser parser( stream, &reader ); if ( !parser.CheckFormat() ) return false; if ( !parser.Parse() ) return false; if ( !data.length() ) return false; for ( int i=0; i<(int)data.length(); i++ ) { data[i].lowercase(); TexPattern * pattern = new TexPattern( data[i] ); #if DUMP_PATTERNS==1 CRLog::debug("Pattern: (%s) '%s' - %s", LCSTR(data[i]), LCSTR(lString16(pattern->word)), pattern->attr); #endif addPattern( pattern ); patternCount++; } return patternCount>0; } }