diff -Nur -X X abiword-2.9.1.orig/plugins/mswrite/xp/ie_impexp_MSWrite.cpp abiword-2.9.1/plugins/mswrite/xp/ie_impexp_MSWrite.cpp --- abiword-2.9.1.orig/plugins/mswrite/xp/ie_impexp_MSWrite.cpp 2011-03-03 07:30:19.000000000 +0100 +++ abiword-2.9.1/plugins/mswrite/xp/ie_impexp_MSWrite.cpp 2011-07-13 21:23:35.000000000 +0200 @@ -1,5 +1,6 @@ /* AbiWord * Copyright (C) 2001 Sean Young + * Copyright (C) 2010-2011 Ingo Brueckl * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -129,4 +130,3 @@ exit (1); return 0; } - diff -Nur -X X abiword-2.9.1.orig/plugins/mswrite/xp/ie_impexp_MSWrite.h abiword-2.9.1/plugins/mswrite/xp/ie_impexp_MSWrite.h --- abiword-2.9.1.orig/plugins/mswrite/xp/ie_impexp_MSWrite.h 2011-03-03 07:30:19.000000000 +0100 +++ abiword-2.9.1/plugins/mswrite/xp/ie_impexp_MSWrite.h 2011-07-12 21:37:16.000000000 +0200 @@ -2,7 +2,7 @@ * Copyright (C) 2001 Sean Young * Copyright (C) 2001 Hubert Figuiere * Copyright (C) 2001 Dom Lachowicz - * 2010 Ingo Brueckl + * Copyright (C) 2010-2011 Ingo Brueckl * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -69,11 +69,3 @@ p[3] = ((s) & 0xff000000) >> 24; } #endif /* IE_IMPEXP_MSWRITE_H */ - - - - - - - - diff -Nur -X X abiword-2.9.1.orig/plugins/mswrite/xp/ie_imp_MSWrite.cpp abiword-2.9.1/plugins/mswrite/xp/ie_imp_MSWrite.cpp --- abiword-2.9.1.orig/plugins/mswrite/xp/ie_imp_MSWrite.cpp 2011-03-15 16:17:59.000000000 +0100 +++ abiword-2.9.1/plugins/mswrite/xp/ie_imp_MSWrite.cpp 2011-07-15 19:44:49.000000000 +0200 @@ -4,7 +4,7 @@ * Copyright (C) 2001 Sean Young * Copyright (C) 2001 Hubert Figuiere * Copyright (C) 2001 Dom Lachowicz - * 2010 Ingo Brueckl + * Copyright (C) 2010-2011 Ingo Brueckl * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,11 +23,6 @@ * * Documentation at http://www.msxnet.org/word2rtf/formats/write * - * TODO: - * - pictures: clean up / polish off code, add wmf - * - OLE: no support yet - * - headers/footers need proper positioning implemented - * - speed it up! */ #ifdef HAVE_CONFIG_H @@ -35,9 +30,8 @@ #endif #include -//#include +#include #include -#include #include "ut_locale.h" #include "ut_types.h" @@ -96,7 +90,7 @@ mi->name = "MSWrite Importer"; mi->desc = "Import MSWrite Documents"; mi->version = ABI_VERSION_STRING; - mi->author = "Abi the Ant"; + mi->author = "Sean Young, Ingo Brückl"; mi->usage = "No Usage"; IE_Imp::registerImporter (m_sniffer); @@ -199,7 +193,8 @@ void IE_Imp_MSWrite::free_ffntb () { for (UT_uint32 i=0; i < wri_fonts_count; i++) { - wri_fonts[i].name.~basic_string(); + free((void*)wri_fonts[i].name); + wri_fonts[i].name = NULL; } free(wri_fonts); wri_fonts = NULL; @@ -210,6 +205,7 @@ int page, pnMac, font_count, cbFfn; unsigned char byt[2], ffid; char *ffn; + int flen; struct wri_font *wri_fonts_tmp; /* if the page is the same as pnMac, there are no fonts */ @@ -233,8 +229,6 @@ font_count = 0; wri_fonts = NULL; - - std::set raw_fonts; while (true) { if (!gsf_input_read (mFile, 2, byt)) { @@ -276,26 +270,11 @@ perror ("wri_file"); return 1; } - char *trname; - wri_fonts[font_count].codepage=get_codepage(ffn,&trname); - if (wri_fonts[font_count].codepage) { - strcpy(ffn,trname); - raw_fonts.insert(trname); - } - memset(&(wri_fonts[font_count].name),0,sizeof(std::string)); + wri_fonts[font_count].codepage = get_codepage(ffn, &flen); + ffn[flen] = 0; wri_fonts[font_count].name = ffn; font_count++; - - free(ffn); } - for (int i=0; i::iterator pos; - if (!wri_fonts[i].codepage) { - pos = raw_fonts.find(wri_fonts[i].name); - if (pos != raw_fonts.end()) - wri_fonts[i].codepage="CP1252"; - } - } if (static_cast(font_count) != wri_fonts_count) { wri_fonts_count = font_count; UT_DEBUGMSG(("write file lied about number of fonts\n")); @@ -307,12 +286,17 @@ const char *suffix; const char *cpid; } const cp_suf_tbl[]={ - {"\x04 cyr","CP1251"}, - {"\x03 ce","CP1250"}, - {NULL,NULL} + {"\x03 CE", "CP1250"}, + {"\x04 Cyr", "CP1251"}, + {"\x06 Greek", "CP1253"}, + {"\x04 Tur", "CP1254"}, + {"\x09 (Hebrew)", "CP1255"}, + {"\x09 (Arabic)", "CP1256"}, + {"\x07 Baltic", "CP1257"}, + {NULL, "CP1252"} // default codepage }; -void inline IE_Imp_MSWrite::translate_char (char ch, UT_UCS4String &buf) +inline void IE_Imp_MSWrite::translate_char (char ch, UT_UCS4String &buf) { UT_UCS4Char uch=ch; @@ -333,36 +317,31 @@ case 13: /* carriage return */ case 31: /* soft hyphen */ break; + default: - if (ch & 0x80) { - charconv.mbtowc(uch, ch); - } + if (ch & 0x80) charconv.mbtowc(uch, ch); buf += uch; } } -const char *IE_Imp_MSWrite::get_codepage(char *facename, char **newname) const +const char *IE_Imp_MSWrite::get_codepage (const char *facename, int *facelen) { - static char facebuf[40]; const cst_data *p=cp_suf_tbl; int l=strlen(facename); while (p->suffix) { if (*p->suffix < l) { if (!g_ascii_strcasecmp(&p->suffix[1],&facename[l-*p->suffix])) { - if (newname) { - strncpy(facebuf,facename,l-*p->suffix); - facebuf[l-*p->suffix]=0; - *newname=facebuf; - } + *facelen = l-*p->suffix; return p->cpid; } } p++; } - return 0; + *facelen = l; + return p->cpid; } -void IE_Imp_MSWrite::set_codepage(const char *charset) +inline void IE_Imp_MSWrite::set_codepage (const char *charset) { charconv.setInCharset(charset); } @@ -371,7 +350,8 @@ int IE_Imp_MSWrite::read_sep () { int page, pnSetb, cch; - int yaMac, yaTop, dyaText, yaBot, xaMac, xaLeft, dxaText, xaRight; + int yaMac, yaTop, dyaText, yaBot, xaMac, dxaText; + int rStartPage, yaHeader, yaFooter; unsigned char sep_page[0x80]; UT_String propBuffer; @@ -387,7 +367,9 @@ xaLeft = 1800; dxaText = 8640; - int firstpage = -1; + rStartPage = 0xFFFF; + yaHeader = 1080; + yaFooter = 15760; if (page != pnSetb) { @@ -397,37 +379,52 @@ if (cch >= 4) yaMac = READ_WORD(sep_page + 3); if (cch >= 6) xaMac = READ_WORD(sep_page + 5); - if (cch >= 8) firstpage = READ_WORD(sep_page + 7); + if (cch >= 8) rStartPage = READ_WORD(sep_page + 7); if (cch >= 10) yaTop = READ_WORD(sep_page + 9); if (cch >= 12) dyaText = READ_WORD(sep_page + 11); if (cch >= 14) xaLeft = READ_WORD(sep_page + 13); if (cch >= 16) dxaText = READ_WORD(sep_page + 15); + if (cch >= 20) yaHeader = READ_WORD(sep_page + 19); + if (cch >= 22) yaFooter = READ_WORD(sep_page + 21); } yaBot = yaMac - yaTop - dyaText; xaRight = xaMac - xaLeft - dxaText; UT_LocaleTransactor lt(LC_NUMERIC, "C"); - UT_String_sprintf(propBuffer, "page-margin-right:%.4fin; " + UT_String_sprintf(propBuffer, "page-margin-header:%.4fin; " + "page-margin-right:%.4fin; " "page-margin-left:%.4fin; " "page-margin-top:%.4fin; " - "page-margin-bottom:%.4fin", + "page-margin-bottom:%.4fin; " + "page-margin-footer:%.4fin", + static_cast(yaHeader) / 1440.0, static_cast(xaRight) / 1440.0, static_cast(xaLeft) / 1440.0, static_cast(yaTop) / 1440.0, - static_cast(yaBot) / 1440.0); + static_cast(yaBot) / 1440.0, + static_cast(yaMac - yaFooter) / 1440.0); - // We assume each document has header and footer for - // the sake of simplicity + if (rStartPage & 0x8000) rStartPage = -0x10000 + rStartPage; - const gchar *propsArray[7]; + if (rStartPage >= 0) { + UT_String tmp; + UT_String_sprintf(tmp, "; section-restart:1; section-restart-value:%d", rStartPage); + propBuffer += tmp; + } + + const gchar *propsArray[11]; propsArray[0] = PT_PROPS_ATTRIBUTE_NAME; propsArray[1] = propBuffer.c_str(); - propsArray[2] = PT_HEADER_ATTRIBUTE_NAME; + propsArray[2] = PT_HEADERFIRST_ATTRIBUTE_NAME; propsArray[3] = "0"; - propsArray[4] = PT_FOOTER_ATTRIBUTE_NAME; + propsArray[4] = PT_HEADER_ATTRIBUTE_NAME; propsArray[5] = "1"; - propsArray[6] = NULL; + propsArray[6] = PT_FOOTERFIRST_ATTRIBUTE_NAME; + propsArray[7] = "2"; + propsArray[8] = PT_FOOTER_ATTRIBUTE_NAME; + propsArray[9] = "3"; + propsArray[10] = NULL; appendStrux(PTX_Section, propsArray); @@ -435,7 +432,7 @@ } /* the paragraph information */ -int IE_Imp_MSWrite::read_pap (int cStart, int cLimit) +int IE_Imp_MSWrite::read_pap (pap_t process) { int page, cfod, fod; int fcFirst, fcLim, fcMac, n; @@ -460,129 +457,141 @@ UT_DEBUGMSG(("fcFirst wrong, trying to continue...\n")); } for (fod=0;fod= 2) { - jc = pap_page[bfProp + 6] & 3; - } - if (cch >= 12) { - dyaLine = pap_page[bfProp + 15] + - pap_page[bfProp + 16] * 256; - } - if (dyaLine < 240) dyaLine = 240; - if (cch >= 17) { - fGraphics = pap_page[bfProp + 21] & 0x10; - header = pap_page[bfProp + 21] & 6; - rhcPage = pap_page[bfProp + 21] & 1; - } - if (cch >= 6) { - dxaRight = pap_page[bfProp + 9] + - pap_page[bfProp + 10] * 256; - if (dxaRight & 0x8000) - dxaRight = -0x10000 + dxaRight; - } - if (cch >= 8) { - dxaLeft = pap_page[bfProp + 11] + - pap_page[bfProp + 12] * 256; - if (dxaLeft & 0x8000) - dxaLeft = -0x10000 + dxaLeft; - } - if (cch >= 10) { - dxaLeft1 = pap_page[bfProp + 13] + - pap_page[bfProp + 14] * 256; - if (dxaLeft1 & 0x8000) - dxaLeft1 = -0x10000 + dxaLeft1; - } - - // TODO: dyaBefore, dyaAfter are used for header/footer - - for (n=0;n<14;n++) { - if (cch >= (4 * (n + 1) + 26) ) { - tabs[tab_count] = pap_page[bfProp + n * 4 + 27] + - 256 * pap_page[bfProp + n * 4 + 28]; - jcTab[tab_count] = (pap_page[bfProp + n * 4 + 29] & 3); - tab_count++; + /* default values */ + jc = 0; + dyaLine = 240; + fGraphics = 0; + rhcPage = rHeaderFooter = rhcFirst = 0; + tab_count = 0; + dxaLeft = dxaRight = dxaLeft1 = 0; + + if ((bfProp != 0xffff) && (bfProp + (cch = pap_page[bfProp + 4]) < 0x80)) { + if (cch >= 2) { + jc = pap_page[bfProp + 6] & 3; + } + if (cch >= 12) { + dyaLine = pap_page[bfProp + 15] + + pap_page[bfProp + 16] * 256; + } + if (dyaLine < 240) dyaLine = 240; + if (cch >= 17) { + rhcPage = pap_page[bfProp + 21] & 1; + rHeaderFooter = pap_page[bfProp + 21] & 6; + rhcFirst = pap_page[bfProp + 21] & 8; + fGraphics = pap_page[bfProp + 21] & 0x10; + } + if (process == All) { + if (rHeaderFooter) { + if (rhcPage) { + if (!hasFooter) { + hasFooter = true; + page1Footer = rhcFirst; + } } + else { + if (!hasHeader) { + hasHeader = true; + page1Header = rhcFirst; + } + } + } + } + if (cch >= 6) { + dxaRight = pap_page[bfProp + 9] + + pap_page[bfProp + 10] * 256; + if (dxaRight & 0x8000) + dxaRight = -0x10000 + dxaRight; + } + if (cch >= 8) { + dxaLeft = pap_page[bfProp + 11] + + pap_page[bfProp + 12] * 256; + if (dxaLeft & 0x8000) + dxaLeft = -0x10000 + dxaLeft; + } + if (cch >= 10) { + dxaLeft1 = pap_page[bfProp + 13] + + pap_page[bfProp + 14] * 256; + if (dxaLeft1 & 0x8000) + dxaLeft1 = -0x10000 + dxaLeft1; + } + + for (n=0;n<14;n++) { + if (cch >= (4 * (n + 1) + 26) ) { + tabs[tab_count] = pap_page[bfProp + n * 4 + 27] + + 256 * pap_page[bfProp + n * 4 + 28]; + jcTab[tab_count] = (pap_page[bfProp + n * 4 + 29] & 3); + tab_count++; } } } - - if (fcFirst >= cLimit) return 0; - if (fcFirst >= cStart) { - if (!m_insubdoc && header) { - add_subdoc((rhcPage)? 1 : 0, - fcFirst,fcLim); - } else { - UT_LocaleTransactor lt (LC_NUMERIC, "C"); - UT_String_sprintf (propBuffer, "text-align:%s; line-height:%.1f", - text_align[jc], static_cast(dyaLine) / 240.0); - - /* tabs */ - if (tab_count) { - propBuffer += "; tabstops:"; - for (n=0; n < tab_count; n++) { - UT_String_sprintf (tempBuffer, "%.4fin/%c0", static_cast(tabs[n]) / 1440.0, - jcTab[n] ? 'D' : 'L'); - propBuffer += tempBuffer; - if (n != (tab_count - 1)) { - propBuffer += ","; - } - } - } - - /* indentation */ - if (dxaLeft1) { - UT_String_sprintf (tempBuffer, "; text-indent:%.4fin", - static_cast(dxaLeft1) / 1440.0); - propBuffer += tempBuffer; - } - if (dxaLeft) { - UT_String_sprintf (tempBuffer, "; margin-left:%.4fin", - static_cast(dxaLeft) / 1440.0); - propBuffer += tempBuffer; - } - if (dxaRight) { - UT_String_sprintf (tempBuffer, "; margin-right:%.4fin", - static_cast(dxaRight) / 1440.0); + if ((process == All && !rHeaderFooter) || (rHeaderFooter && ((process == Header && !rhcPage) || (process == Footer && rhcPage)))) { + UT_LocaleTransactor lt (LC_NUMERIC, "C"); + UT_String_sprintf (propBuffer, "text-align:%s; line-height:%.1f", + text_align[jc], static_cast(dyaLine) / 240.0); + + /* tabs */ + if (tab_count) { + propBuffer += "; tabstops:"; + for (n=0; n < tab_count; n++) { + UT_String_sprintf (tempBuffer, "%.4fin/%c0", static_cast(tabs[n]) / 1440.0, + jcTab[n] ? 'D' : 'L'); propBuffer += tempBuffer; + if (n != (tab_count - 1)) { + propBuffer += ","; + } } + } + + /* indentation */ + if (process == Header || process == Footer) { + // for reasons unknown, the left and right margins from the paper + // are included in the indents of the headers and footers + dxaLeft -= xaLeft; + dxaRight -= xaRight; + } + if (dxaLeft1) { + UT_String_sprintf (tempBuffer, "; text-indent:%.4fin", + static_cast(dxaLeft1) / 1440.0); + propBuffer += tempBuffer; + } + if (dxaLeft) { + UT_String_sprintf (tempBuffer, "; margin-left:%.4fin", + static_cast(dxaLeft) / 1440.0); + propBuffer += tempBuffer; + } + if (dxaRight) { + UT_String_sprintf (tempBuffer, "; margin-right:%.4fin", + static_cast(dxaRight) / 1440.0); + propBuffer += tempBuffer; + } - // end of formatting - - if (lf || (strcmp(propBuffer.c_str(), lastProp.c_str()) != 0)) { - // only if fod has changed or last char was line feed - const gchar* propsArray[3]; - propsArray[0] = PT_PROPS_ATTRIBUTE_NAME; - propsArray[1] = propBuffer.c_str(); - propsArray[2] = NULL; - - appendStrux (PTX_Block, propsArray); - lastProp = propBuffer; - } - - if (fGraphics) { - read_pic(fcFirst, fcLim - fcFirst); - } else { - read_char (fcFirst, fcLim - 1); - } + // end of formatting + if (lf || (strcmp(propBuffer.c_str(), lastProp.c_str()) != 0)) { + // only if fod has changed or last char was line feed + const gchar* propsArray[3]; + propsArray[0] = PT_PROPS_ATTRIBUTE_NAME; + propsArray[1] = propBuffer.c_str(); + propsArray[2] = NULL; + + appendStrux (PTX_Block, propsArray); + lastProp = propBuffer; + } + + if (fGraphics) { + read_pic(fcFirst, fcLim - fcFirst); + } else { + read_char (fcFirst, fcLim - 1); } + } fcFirst = fcLim; @@ -601,7 +610,7 @@ UT_String propBuffer; UT_String tempBuffer; - const char *oldcp = ""; + static const char *oldcp; fcMac = wri_struct_value (write_file_header, "fcMac"); page = (fcMac + 127) / 128; @@ -669,52 +678,57 @@ propBuffer += tempBuffer; } if (wri_fonts_count) { - UT_String_sprintf (tempBuffer, "; font-family:%s", wri_fonts[ftc].name.c_str()); + UT_String_sprintf (tempBuffer, "; font-family:%s", wri_fonts[ftc].name); propBuffer += tempBuffer; } - const char *needcp = wri_fonts[ftc].codepage ? - wri_fonts[ftc].codepage : default_cp.c_str(); - if (needcp != oldcp /*sic!*/) { - set_codepage((char*)needcp); - oldcp = needcp; + + if (wri_fonts[ftc].codepage != oldcp /*sic!*/) { + set_codepage(wri_fonts[ftc].codepage); + oldcp = wri_fonts[ftc].codepage; } - - const gchar* propsArray[3]; - - const char *pText = (const char*) mTextBuf.getPointer(0) - 0x80; - //const char *pLimit = pText + mTextBuf.getLength(); - UT_uint32 nLimit = 0x80 + mTextBuf.getLength(); - + while (fcFirst2 >= fcFirst) { if ((fcFirst2 >= fcLim) || (fcFirst2 > fcLim2) || - (fcFirst2 >= nLimit)) { + (fcFirst2 - 0x80 >= static_cast(mTextBuf.getLength()))) { break; } - if (pText[fcFirst2] == 0x1) { - propsArray[0] = PT_PROPS_ATTRIBUTE_NAME; - propsArray[1] = propBuffer.c_str(); - propsArray[2] = NULL; - appendFmt (propsArray); - if (mCharBuf.size() > 0) { - appendSpan (reinterpret_cast(mCharBuf.ucs4_str()), mCharBuf.size()); - } - const gchar *atts[3] = {"type","page_number",NULL}; - appendObject(PTO_Field,atts,propsArray); - mCharBuf.clear(); - } else - translate_char (pText[fcFirst2], mCharBuf); + translate_char (*(mTextBuf.getPointer(fcFirst2 - 0x80)), mCharBuf); fcFirst2++; } if (mCharBuf.size() > 0) { + const gchar* propsArray[5]; + const UT_UCS4Char *p, *charBuf = mCharBuf.ucs4_str(); + size_t bufLen; + propsArray[0] = PT_PROPS_ATTRIBUTE_NAME; propsArray[1] = propBuffer.c_str(); propsArray[2] = NULL; - + appendFmt (propsArray); - appendSpan (reinterpret_cast(mCharBuf.ucs4_str()), mCharBuf.size()); + + // check for page number (should only be in header or footer) + p = charBuf; + while (*p && *p != (UT_UCS4Char)0x01) p++; + if (*p) { + if (p - charBuf) appendSpan(reinterpret_cast(charBuf), p - charBuf); + + propsArray[2] = PT_TYPE_ATTRIBUTE_NAME; + propsArray[3] = "page_number"; + propsArray[4] = NULL; + appendObject(PTO_Field, propsArray); + + bufLen = mCharBuf.size() - (p - charBuf) - 1; + p++; + } + else { + bufLen = mCharBuf.size(); + p = charBuf; + } + + if (bufLen) appendSpan(reinterpret_cast(p), bufLen); } - /*else { // can occur on empty paragraphs + /*else { UT_DEBUGMSG (("Hub: Ignoring 0 length span\n")); }*/ } @@ -781,7 +795,6 @@ #define WRITE_PICTURE_HEADER 40 // common size of both header types static const struct wri_struct WRITE_PICTURE[] = { - /* value, data, size, type, name */ /* word no. */ /* METAFILEPICT structure */ { 0, NULL, 2, CT_VALUE, "mm" }, /* 0 */ @@ -856,25 +869,21 @@ #define BM16_BitsPixel 9 #define BM16_Bits 10 - IE_Imp_MSWrite::~IE_Imp_MSWrite() { - free_wri_struct (write_file_header); + free_wri_struct(write_file_header); free(write_file_header); free(write_ole_picture); free(write_picture); } + IE_Imp_MSWrite::IE_Imp_MSWrite(PD_Document * pDocument) : IE_Imp(pDocument), mFile(0), wri_fonts_count(0), - wri_fonts(0), pic_nr(0), default_cp("CP1252"), - lf(false) + wri_fonts(0), pic_nr(0), + lf(false), xaLeft(0), xaRight(0), + hasHeader(false), hasFooter(false), page1Header(false), page1Footer(false) { - set_codepage((char*)default_cp.c_str()); - - static const doc_range s_docrange_0 = {0,0}; - m_header = m_footer = s_docrange_0; - write_file_header = static_cast(malloc (sizeof (WRITE_FILE_HEADER))); memcpy (write_file_header, WRITE_FILE_HEADER, sizeof (WRITE_FILE_HEADER)); @@ -924,29 +933,30 @@ mTextBuf.append(thetext, size); free(thetext); read_sep(); - m_insubdoc = false; - read_pap (0x80, 0x80 + size); // ugly... - - UT_ASSERT(getDoc()); + read_pap(All); - m_insubdoc = true; - _append_hdrftr(0); - if (m_header.start > 0) { - read_pap (m_header.start, m_header.end); - } - _append_hdrftr(1); - if (m_footer.start > 0) { - read_pap (m_footer.start, m_footer.end); - } + if (hasHeader) { + _append_hdrftr(header); + read_pap(Header); + + if (!page1Header) _append_hdrftr(headerfirst); // an empty one + } + + if (hasFooter) { + _append_hdrftr(footer); + read_pap(Footer); + + if (!page1Footer) _append_hdrftr(footerfirst); // an empty one + } free_ffntb (); return UT_OK; } - /*****************************************************************/ - /*****************************************************************/ - +/*****************************************************************/ +/*****************************************************************/ + int IE_Imp_MSWrite::read_pic (int from, int size) { unsigned char page[0x80]; @@ -1249,8 +1259,9 @@ {0xff, 0xff, 0xff, 0x00}, {0xc0, 0xc0, 0xc0, 0x00} // a color only in the 4 bit colormap }; + // indices for the 4 bit colormap - int const c16idx[16] = { 0, 128, 16, 144, 2, 130, 18, 256, + const int c16idx[16] = { 0, 128, 16, 144, 2, 130, 18, 256, 146, 224, 28, 252, 3, 227, 31, 255 }; @@ -1258,7 +1269,7 @@ { UT_DEBUGMSG(("Size error 1\n")); return 1; - } + } // prepare bmp file header memset(&bmpheader, 0, sizeof(bmpheader)); @@ -1286,7 +1297,7 @@ { msg = "Size error 2\n"; break; - } + } if (mm == 0xe3) // bitmap needs header { @@ -1297,7 +1308,7 @@ { msg = "Color palette error\n"; break; - } + } // make a bitmap file header @@ -1321,14 +1332,13 @@ chunk = wri_struct_value(write_pic, "bmWidthBytes"); filler = (4 - (chunk & 3)) & 3; - } + } else { iegft = IEGFT_WMF; chunk = cbSize; filler = 0; - } - + } written = 0; @@ -1338,11 +1348,12 @@ pBB.append(mTextBuf.getPointer(from - 0x80 + cbHeader + written), chunk); for (int i = 0; i < filler; i++) pBB.append(reinterpret_cast("\x00"), 1); written += chunk; - } + } break; - case 0xe4: /* ole object */ + case 0xe4: /* ole object */ + write_pic = write_ole_picture; read_wri_struct_mem(write_pic, page); @@ -1362,14 +1373,16 @@ } ole_offset += READ_DWORD(page + cbHeader + OLE_TopicNameLength + ole_offset); + if (size < cbHeader + OLE_ItemNameString + ole_offset) { msg = "Size error 4\n"; break; - } + } ole_offset += READ_DWORD(page + cbHeader + OLE_ItemNameLength + ole_offset); - } + } + objLen = READ_DWORD(page + cbHeader + OLE_ObjDataSize + ole_offset); if (strcmp(className, "METAFILEPICT") == 0) @@ -1379,6 +1392,7 @@ objLen -= OLE_MF_Object - OLE_Object; objectType = 2; // we can go embedded now } + if (size <= cbHeader + OLE_Object + ole_offset || cbHeader + OLE_Object + ole_offset > 0x80 || size < cbHeader + OLE_Object + ole_offset + objLen) @@ -1403,8 +1417,10 @@ pBB.append(reinterpret_cast(&bmpheader), sizeof(bmpheader)); objectType = 2; // we can go embedded now + } - } else if (strcmp(className, "BITMAP") == 0) { + if (strcmp(className, "BITMAP") == 0) + { if ((bitsppixel = *(page + cbHeader + OLE_Object + ole_offset + BM16_BitsPixel)) < 16) colorPaletteLen = (1 << bitsppixel) << 2; @@ -1532,31 +1548,36 @@ return (msg ? 1 : 0); } -void IE_Imp_MSWrite::add_subdoc(int type, unsigned int from, unsigned int to) +void IE_Imp_MSWrite::_append_hdrftr (hdrftr_t which) { - doc_range *r; - if (type == 0) r=&m_header; - else if (type == 1) r=&m_footer; - else return; - - if (r->end == r->start) { - r->start = from; - r->end = to; - } else if (r->end == from) { - r->end = to; - } else - UT_DEBUGMSG(("Not contigious range [%d;%d), was [%d;%d)\n",from,to,r->start,r->end)); -} - -void IE_Imp_MSWrite::_append_hdrftr(int type) -{ - const gchar *attribs[8]; - - attribs[0]= PT_ID_ATTRIBUTE_NAME; - attribs[1]= type ? "1" : "0"; - attribs[2]= PT_TYPE_ATTRIBUTE_NAME; - attribs[3]= type ? "footer" : "header"; - attribs[4]=NULL; + const gchar *attribs[5]; + + attribs[0] = PT_ID_ATTRIBUTE_NAME; + attribs[2] = PT_TYPE_ATTRIBUTE_NAME; + attribs[4] = NULL; + + switch (which) + { + case headerfirst: + attribs[1] = "0"; + attribs[3] = "header-first"; + break; + + case header: + attribs[1] = "1"; + attribs[3] = "header"; + break; + + case footerfirst: + attribs[1] = "2"; + attribs[3] = "footer-first"; + break; + + case footer: + attribs[1] = "3"; + attribs[3] = "footer"; + break; + } appendStrux(PTX_Section,attribs); } diff -Nur -X X abiword-2.9.1.orig/plugins/mswrite/xp/ie_imp_MSWrite.h abiword-2.9.1/plugins/mswrite/xp/ie_imp_MSWrite.h --- abiword-2.9.1.orig/plugins/mswrite/xp/ie_imp_MSWrite.h 2011-03-07 16:30:45.000000000 +0100 +++ abiword-2.9.1/plugins/mswrite/xp/ie_imp_MSWrite.h 2011-07-15 19:44:56.000000000 +0200 @@ -3,7 +3,7 @@ /* AbiWord * Copyright (C) 1998 AbiSource, Inc. * Copyright (C) 2000 Hubert Figuière - * 2010 Ingo Brueckl + * Copyright (C) 2010-2011 Ingo Brueckl * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,8 +25,6 @@ #define IE_IMP_MSWRITE_H #include -#include -#include #include "ut_bytebuf.h" #include "ut_string_class.h" @@ -40,7 +38,7 @@ /* the fonts */ typedef struct wri_font { short ffid; - std::string name; + const char *name; const char *codepage; } wri_font; @@ -72,23 +70,20 @@ public: IE_Imp_MSWrite(PD_Document * pDocument); ~IE_Imp_MSWrite(); - - struct doc_range - { - unsigned int start; - unsigned int end; - }; protected: virtual UT_Error _loadFile(GsfInput * input); UT_Error _parseFile(); private: + enum pap_t {All, Header, Footer}; + enum hdrftr_t {headerfirst, header, footerfirst, footer}; + void free_ffntb (); int read_ffntb (); void translate_char (char ch, UT_UCS4String & buf); int read_sep(); - int read_pap (int cStart, int cLimit); + int read_pap(pap_t process); int read_char (int fcFirst2, int fcLim2); int read_pic(int, int); @@ -101,21 +96,18 @@ struct wri_struct *write_file_header; struct wri_struct *write_picture; struct wri_struct *write_ole_picture; - - doc_range m_header, m_footer; - - std::string default_cp; - const char *get_codepage(char *facename, char **newname=NULL) const; // gets cp by font name; - void set_codepage(const char *cp); // sets the translation table to corresponding codeset - void add_subdoc(int type, unsigned int from, unsigned int to); - void _append_hdrftr(int type); - - bool m_insubdoc; + + const char *get_codepage(const char *facename, int *facelen); // gets codepage from font name + void set_codepage(const char *charset); // sets the input character set for conversion + + void _append_hdrftr(hdrftr_t which); UT_UCS4String mCharBuf; // buffer for char runs. UT_ByteBuf mTextBuf; // complete text buffer as extracted out of the file. - UT_UCS4_mbtowc charconv; // unicode conversion. + UT_UCS4_mbtowc charconv; // Windows codepage to unicode conversion bool lf; + int xaLeft, xaRight; + bool hasHeader, hasFooter, page1Header, page1Footer; }; #endif /* IE_IMP_MSWRITE_H */