From: Fridrich S. <str...@us...> - 2010-06-11 15:25:00
|
Update of /cvsroot/libwpd/libwpd2/src/lib In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv9769/src/lib Modified Files: WP1ContentListener.cpp WP3ContentListener.cpp WP42ContentListener.cpp WP5ContentListener.cpp WP6CharacterGroup.cpp WP6CharacterGroup.h WP6ContentListener.cpp WP6VariableLengthGroup.cpp WP6VariableLengthGroup.h WPXContentListener.cpp WPXContentListener.h Log Message: Try to map Dingbats too and fix a regression in FontFace change function Index: WP6VariableLengthGroup.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP6VariableLengthGroup.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- WP6VariableLengthGroup.cpp 10 Jun 2010 11:54:24 -0000 1.40 +++ WP6VariableLengthGroup.cpp 11 Jun 2010 15:24:51 -0000 1.41 @@ -47,7 +47,8 @@ m_flags(0), m_numPrefixIDs(0), m_prefixIDs(0), - m_sizeNonDeletable(0) + m_sizeNonDeletable(0), + m_sizeDeletable(0) { } @@ -153,13 +154,18 @@ } m_sizeNonDeletable = readU16(input, encryption); - if (m_sizeNonDeletable > m_size) + if (m_sizeNonDeletable > m_size || (m_sizeNonDeletable & 0x8000)) { WPD_DEBUG_MSG(("WordPerfect: Possible corruption detected, bailing out!\n")); throw FileException(); - } + } + + uint32_t tmpPosition = input->tell(); + input->seek(m_sizeNonDeletable, WPX_SEEK_CUR); + m_sizeDeletable = (uint16_t)(startPosition + m_size - 4 - input->tell()); + input->seek(tmpPosition, WPX_SEEK_SET); - WPD_DEBUG_MSG(("WordPerfect: Read variable group header (start_position: %i, sub_group: %i, size: %i, flags: %i, num_prefix_ids: %i, size_non_deletable: %i)\n", startPosition, m_subGroup, m_size, m_flags, m_numPrefixIDs, m_sizeNonDeletable)); + WPD_DEBUG_MSG(("WordPerfect: Read variable group header (start_position: %i, sub_group: %i, size: %i, flags: %i, num_prefix_ids: %i, size_non_deletable: %i, size_deletable: %i)\n", startPosition, m_subGroup, m_size, m_flags, m_numPrefixIDs, m_sizeNonDeletable, m_sizeDeletable)); _readContents(input, encryption); Index: WP5ContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP5ContentListener.cpp,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- WP5ContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.41 +++ WP5ContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.42 @@ -65,7 +65,7 @@ void WP5ContentListener::insertCharacter(uint16_t character) { - uint16_t tmpCharacter = _mapSymbolFont(character); + uint16_t tmpCharacter = _mapNonUnicodeCharacter(character); if (!m_ps->m_isSpanOpened) _openSpan(); appendUCS4(m_parseState->m_textBuffer, (uint32_t)tmpCharacter); Index: WP42ContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP42ContentListener.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- WP42ContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.25 +++ WP42ContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.26 @@ -61,7 +61,7 @@ { if (!isUndoOn()) { - uint16_t tmpCharacter = _mapSymbolFont(character); + uint16_t tmpCharacter = _mapNonUnicodeCharacter(character); if (!m_ps->m_isSpanOpened) _openSpan(); appendUCS4(m_parseState->m_textBuffer, (uint32_t)tmpCharacter); Index: WP6ContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP6ContentListener.cpp,v retrieving revision 1.75 retrieving revision 1.76 diff -u -d -r1.75 -r1.76 --- WP6ContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.75 +++ WP6ContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.76 @@ -412,7 +412,7 @@ { if (!isUndoOn()) { - uint16_t tmpCharacter = _mapSymbolFont(character); + uint16_t tmpCharacter = _mapNonUnicodeCharacter(character); if (m_parseState->m_styleStateSequence.getCurrentState() == STYLE_BODY || m_parseState->m_styleStateSequence.getCurrentState() == NORMAL) Index: WPXContentListener.h =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WPXContentListener.h,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- WPXContentListener.h 11 Jun 2010 09:58:26 -0000 1.27 +++ WPXContentListener.h 11 Jun 2010 15:24:51 -0000 1.28 @@ -203,13 +203,15 @@ void _insertBreakIfNecessary(WPXPropertyList &propList); - uint16_t _mapSymbolFont(uint16_t character); + uint16_t _mapNonUnicodeCharacter(uint16_t character); private: WPXContentListener(const WPXContentListener&); WPXContentListener& operator=(const WPXContentListener&); WPXString _colorToString(const RGBSColor * color); WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor); + uint16_t _mapSymbolFontCharacter(uint16_t character); + uint16_t _mapDingbatsFontCharacter(uint16_t character); }; #endif /* WPXCONTENTLISTENER_H */ Index: WP6CharacterGroup.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP6CharacterGroup.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- WP6CharacterGroup.cpp 10 Jun 2010 11:52:46 -0000 1.38 +++ WP6CharacterGroup.cpp 11 Jun 2010 15:24:51 -0000 1.39 @@ -92,7 +92,7 @@ * WP6CharacterGroup_FontFaceChangeSubGroups *************************************************************************/ -WP6CharacterGroup_FontFaceChangeSubGroup::WP6CharacterGroup_FontFaceChangeSubGroup(WPXInputStream *input, WPXEncryption *encryption) : +WP6CharacterGroup_FontFaceChangeSubGroup::WP6CharacterGroup_FontFaceChangeSubGroup(WPXInputStream *input, WPXEncryption *encryption, uint16_t sizeDeletable) : m_oldMatchedPointSize(0), m_hash(0), m_matchedFontIndex(0), m_matchedFontPointSize(0), m_fontName() { m_oldMatchedPointSize = readU16(input, encryption); @@ -101,11 +101,14 @@ m_matchedFontPointSize = readU16(input, encryption); WPD_DEBUG_MSG(("WordPerfect: Character Group Font Face Change subgroup info (old matched point size: %i, hash: %i, matched font index: %i, matched font point size: %i)\n", m_oldMatchedPointSize, m_hash, m_matchedFontIndex, m_matchedFontPointSize)); - input->seek(22, WPX_SEEK_CUR); - uint16_t tmpSizeDeletable = readU16(input, encryption); - WP6FontDescriptorPacket::_readFontName(input, encryption, m_fontName, tmpSizeDeletable); + if (sizeDeletable > 24) + { + input->seek(22, WPX_SEEK_CUR); + uint16_t tmpSizeDeletable = readU16(input, encryption); + WP6FontDescriptorPacket::_readFontName(input, encryption, m_fontName, tmpSizeDeletable); - WPD_DEBUG_MSG(("WordPerfect: Character Group Font Face Change subgroup info (font name length: %i, font name: %s)\n", tmpSizeDeletable, m_fontName.cstr())); + WPD_DEBUG_MSG(("WordPerfect: Character Group Font Face Change subgroup info (font name length: %i, font name: %s)\n", tmpSizeDeletable, m_fontName.cstr())); + } } void WP6CharacterGroup_FontFaceChangeSubGroup::parse(WP6Listener *listener, const uint8_t /* numPrefixIDs */, uint16_t const *prefixIDs) const @@ -285,7 +288,7 @@ switch (getSubGroup()) { case WP6_CHARACTER_GROUP_FONT_FACE_CHANGE: - m_subGroupData = new WP6CharacterGroup_FontFaceChangeSubGroup(input, encryption); + m_subGroupData = new WP6CharacterGroup_FontFaceChangeSubGroup(input, encryption, getSizeDeletable()); break; case WP6_CHARACTER_GROUP_FONT_SIZE_CHANGE: m_subGroupData = new WP6CharacterGroup_FontSizeChangeSubGroup(input, encryption); Index: WP6VariableLengthGroup.h =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP6VariableLengthGroup.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- WP6VariableLengthGroup.h 22 Nov 2007 12:20:47 -0000 1.28 +++ WP6VariableLengthGroup.h 11 Jun 2010 15:24:51 -0000 1.29 @@ -56,6 +56,7 @@ uint8_t getNumPrefixIDs() const { return m_numPrefixIDs; } const uint16_t * getPrefixIDs() const { return m_prefixIDs; } uint16_t getSizeNonDeletable() const { return m_sizeNonDeletable; } + uint16_t getSizeDeletable() const { return m_sizeDeletable; } private: WP6VariableLengthGroup(const WP6VariableLengthGroup&); @@ -66,6 +67,7 @@ uint8_t m_numPrefixIDs; uint16_t *m_prefixIDs; uint16_t m_sizeNonDeletable; + uint16_t m_sizeDeletable; }; #endif /* WP6VARIABLELENGTHGROUP_H */ Index: WP6CharacterGroup.h =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP6CharacterGroup.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- WP6CharacterGroup.h 10 Jun 2010 11:52:46 -0000 1.25 +++ WP6CharacterGroup.h 11 Jun 2010 15:24:51 -0000 1.26 @@ -64,7 +64,7 @@ class WP6CharacterGroup_FontFaceChangeSubGroup : public WP6VariableLengthGroup_SubGroup { public: - WP6CharacterGroup_FontFaceChangeSubGroup(WPXInputStream *input, WPXEncryption *encryption); + WP6CharacterGroup_FontFaceChangeSubGroup(WPXInputStream *input, WPXEncryption *encryption, uint16_t sizeDeletable); void parse(WP6Listener *listener, const uint8_t numPrefixIDs, uint16_t const *prefixIDs) const; private: Index: WP3ContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP3ContentListener.cpp,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- WP3ContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.45 +++ WP3ContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.46 @@ -69,7 +69,7 @@ { if (!isUndoOn()) { - uint16_t tmpCharacter = _mapSymbolFont(character); + uint16_t tmpCharacter = _mapNonUnicodeCharacter(character); if (!m_ps->m_isSpanOpened) _openSpan(); appendUCS4(m_parseState->m_textBuffer, (uint32_t)tmpCharacter); Index: WP1ContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WP1ContentListener.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- WP1ContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.29 +++ WP1ContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.30 @@ -64,7 +64,7 @@ { if (!isUndoOn()) { - uint16_t tmpCharacter = _mapSymbolFont(character); + uint16_t tmpCharacter = _mapNonUnicodeCharacter(character); if (!m_ps->m_isSpanOpened) _openSpan(); @@ -89,7 +89,7 @@ if (extendedCharacter <= 0x20) appendUCS4(m_parseState->m_textBuffer, (uint32_t)0x20); else - appendUCS4(m_parseState->m_textBuffer, (uint32_t)macintoshCharacterMap[extendedCharacter - 0x20]); + appendUCS4(m_parseState->m_textBuffer, (uint32_t)(_mapNonUnicodeCharacter(macintoshCharacterMap[extendedCharacter - 0x20]))); } } Index: WPXContentListener.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/lib/WPXContentListener.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- WPXContentListener.cpp 11 Jun 2010 09:58:26 -0000 1.43 +++ WPXContentListener.cpp 11 Jun 2010 15:24:51 -0000 1.44 @@ -712,12 +712,8 @@ propList.insert("fo:text-shadow", "1pt 1pt"); if (m_ps->m_fontName) - { - if (*(m_ps->m_fontName) == "Symbol") - propList.insert("style:font-name", "WGL4"); - else - propList.insert("style:font-name", m_ps->m_fontName->cstr()); - } + propList.insert("style:font-name", m_ps->m_fontName->cstr()); + propList.insert("fo:font-size", fontSizeChange*m_ps->m_fontSize, WPX_POINT); // Here we give the priority to the redline bit over the font color. This is how WordPerfect behaves: @@ -1283,11 +1279,22 @@ return position; } -uint16_t WPXContentListener::_mapSymbolFont(uint16_t character) +uint16_t WPXContentListener::_mapNonUnicodeCharacter(uint16_t character) { - static uint16_t _symbolFontMap1 [] = + if (*(m_ps->m_fontName) == "Symbol") + return _mapSymbolFontCharacter(character); + + if (*(m_ps->m_fontName) == "Dingbats") + return _mapDingbatsFontCharacter(character); + + return character; +} + +uint16_t WPXContentListener::_mapSymbolFontCharacter(uint16_t character) +{ + static const uint16_t _symbolFontMap1 [] = { - 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220D, // 0x21 .. + 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220D, // 0x20 .. 0x0028, 0x0029, 0x2217, 0x002B, 0x002C, 0x2212, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, @@ -1301,7 +1308,7 @@ 0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D, 0x223C // .. 0x7E }; - static uint16_t _symbolFontMap2 [] = + static const uint16_t _symbolFontMap2 [] = { 0x20AC, 0x03D2, 0x2032, 0x2264, 0x2044, 0x221E, 0x0192, 0x2663, // 0xA0 .. 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193, @@ -1317,12 +1324,64 @@ 0x23A0, 0x23A4, 0x23A5, 0x23A6, 0x23AB, 0x23AC, 0x23AD // .. 0xFE }; - if (*(m_ps->m_fontName) != "Symbol") - return character; - - if (character >= 0x0020 && character < 0x7F) + if (character >= 0x0020 && character <= 0x7E) return _symbolFontMap1[character - 0x20]; - if (character >= 0x00A0 && character < 0xFF) + if (character >= 0x00A0 && character <= 0xFE) return _symbolFontMap2[character - 0xA0]; return character; } + +uint16_t WPXContentListener::_mapDingbatsFontCharacter(uint16_t character) +{ + static const uint16_t _dingbatsFontMap1 [] = + { + 0x0020, 0x2701, 0x2702, 0x2703, 0x2704, 0x260E, 0x2706, 0x2707, // 0x20 .. + 0x2708, 0x2709, 0x261B, 0x261E, 0x270C, 0x270D, 0x270E, 0x270F, + 0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715, 0x2716, 0x2717, + 0x2718, 0x2719, 0x271A, 0x271B, 0x271C, 0x271D, 0x271E, 0x271F, + 0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727, + 0x2605, 0x2729, 0x272A, 0x272B, 0x272C, 0x272D, 0x272E, 0x272F, + 0x2730, 0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737, + 0x2738, 0x2739, 0x273A, 0x273B, 0x273C, 0x273D, 0x273E, 0x273F, + 0x2740, 0x2741, 0x2742, 0x2743, 0x2744, 0x2745, 0x2746, 0x2747, + 0x2748, 0x2749, 0x274A, 0x274B, 0x25CF, 0x274D, 0x25A0, 0x274F, + 0x2750, 0x2751, 0x2752, 0x25B2, 0x25BC, 0x25C6, 0x2756, 0x25D7, + 0x2758, 0x2759, 0x275A, 0x275B, 0x275C, 0x275D, 0x275E // .. 0x7E + }; + + static const uint16_t _dingbatsFontMap2 [] = + { + 0x2768, 0x2769, 0x276A, 0x276B, 0x276C, 0x276D, 0x276E, 0x276F, // 0x80 .. + 0x2770, 0x2771, 0x2772, 0x2773, 0x2774, 0x2775 // .. 0x8D + }; + + static const uint16_t _dingbatsFontMap3 [] = + { + 0x2761, 0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767, 0x2663, // 0xA1 .. + 0x2666, 0x2665, 0x2660, 0x2460, 0x2461, 0x2462, 0x2463, 0x2464, + 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x2776, 0x2777, 0x2778, + 0x2779, 0x277A, 0x277B, 0x277C, 0x277D, 0x277E, 0x277F, 0x2780, + 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786, 0x2787, 0x2788, + 0x2789, 0x278A, 0x278B, 0x278C, 0x278D, 0x278E, 0x278F, 0x2790, + 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195, 0x2798, + 0x2799, 0x279A, 0x279B, 0x279C, 0x279D, 0x279E, 0x279F, 0x27A0, + 0x27A1, 0x27A2, 0x27A3, 0x27A4, 0x27A5, 0x27A6, 0x27A7, 0x27A8, + 0x27A9, 0x27AA, 0x27AB, 0x27AC, 0x27AD, 0x27AE, 0x27AF // .. 0xEF + }; + + static const uint16_t _dingbatsFontMap4 [] = + { + 0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7, 0x27B8, // 0xF1 .. + 0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE // .. OxFE + }; + + if (character >= 0x20 && character <= 0x7E) + return _dingbatsFontMap1[character - 0x20]; + if (character >= 0x80 && character <= 0x8D) + return _dingbatsFontMap2[character - 0x80]; + if (character >= 0xA1 && character <= 0xEF) + return _dingbatsFontMap3[character - 0xA1]; + if (character >= 0xF1 && character <=0xFE) + return _dingbatsFontMap4[character - 0xF1]; + return character; +} |