~ubuntu-branches/ubuntu/trusty/libwpd/trusty

« back to all changes in this revision

Viewing changes to src/lib/WP5FontGroup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2006-06-11 23:56:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060611235617-ce504k38fuqe8twa
Tags: 0.8.5-2
* dpatch'ize 
* add patch from upstream fixing WP5 font handling regression

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libwpd
 
2
 * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
 
3
 *  
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
17
 *
 
18
 * For further information visit http://libwpd.sourceforge.net
 
19
 */
 
20
 
 
21
/* "This product is not manufactured, approved, or supported by 
 
22
 * Corel Corporation or Corel Corporation Limited."
 
23
 */
 
24
 
 
25
#include "WP5FontGroup.h"
 
26
#include "WPXListener.h"
 
27
#include "libwpd_internal.h"
 
28
#include "WP5FileStructure.h"
 
29
#include "WP5PrefixData.h"
 
30
#include "WP5ListFontsUsedPacket.h"
 
31
#include "WP5FontNameStringPoolPacket.h"
 
32
#include "WP5Listener.h"
 
33
 
 
34
WP5FontGroup::WP5FontGroup(WPXInputStream *input) :     
 
35
        WP5VariableLengthGroup(),
 
36
        m_red(0),
 
37
        m_green(0),
 
38
        m_blue(0),
 
39
        m_fontNumber(0),
 
40
        m_fontSize(-1)
 
41
{
 
42
        _read(input);
 
43
}
 
44
 
 
45
void WP5FontGroup::_readContents(WPXInputStream *input)
 
46
{
 
47
        switch(getSubGroup())
 
48
        {
 
49
                case WP5_TOP_FONT_GROUP_COLOR:
 
50
                        input->seek(3, WPX_SEEK_CUR);
 
51
                        m_red = readU8(input);
 
52
                        m_green = readU8(input);
 
53
                        m_blue = readU8(input);
 
54
                        break;
 
55
                case WP5_TOP_FONT_GROUP_FONT_CHANGE:
 
56
                        input->seek(25, WPX_SEEK_CUR);
 
57
                        m_fontNumber = readU8(input);
 
58
                        if (getSize() >= 36)
 
59
                        {
 
60
                                input->seek(2, WPX_SEEK_CUR);
 
61
                                m_fontSize = (float)(readU16(input) / 50);
 
62
                        }
 
63
                        break;
 
64
                default:
 
65
                        break;
 
66
        }       
 
67
}
 
68
 
 
69
void WP5FontGroup::parse(WP5Listener *listener)
 
70
{
 
71
        WPD_DEBUG_MSG(("WordPerfect: handling a Font group\n"));
 
72
        
 
73
        uint16_t tmpFontNameOffset;
 
74
        float tmpFontSize = 12.0f;
 
75
        WPXString tmpFontName("Times New Roman");
 
76
 
 
77
        switch(getSubGroup())
 
78
        {
 
79
                case WP5_TOP_FONT_GROUP_COLOR:
 
80
                        listener->characterColorChange(m_red, m_green, m_blue);
 
81
                        break;
 
82
                case WP5_TOP_FONT_GROUP_FONT_CHANGE:
 
83
                        if (listener->getGeneralPacketData(15))
 
84
                        {
 
85
                                tmpFontSize = static_cast<const WP5ListFontsUsedPacket*>(listener->getGeneralPacketData(15))->getFontSize(m_fontNumber);
 
86
                                tmpFontNameOffset = static_cast<const WP5ListFontsUsedPacket*>(listener->getGeneralPacketData(15))->getFontNameOffset(m_fontNumber);
 
87
 
 
88
                        }
 
89
                        else if (listener->getGeneralPacketData(2))
 
90
                        {
 
91
                                tmpFontSize = static_cast<const WP5ListFontsUsedPacket*>(listener->getGeneralPacketData(2))->getFontSize(m_fontNumber);
 
92
                                tmpFontNameOffset = static_cast<const WP5ListFontsUsedPacket*>(listener->getGeneralPacketData(2))->getFontNameOffset(m_fontNumber);
 
93
                        }
 
94
                        else
 
95
                        {
 
96
                                listener->setFont(tmpFontName, tmpFontSize);
 
97
                                return;
 
98
                        }
 
99
 
 
100
                        tmpFontName = static_cast<const WP5FontNameStringPoolPacket*>(listener->getGeneralPacketData(7))->getFontName(tmpFontNameOffset);
 
101
                        if (m_fontSize >= 0)
 
102
                                tmpFontSize = m_fontSize;
 
103
 
 
104
                        WPD_DEBUG_MSG(("WP5 Parsing Font Change, fontNumber %i, fontName: %s, fontSize: %.4f\n", m_fontNumber, tmpFontName.cstr(), tmpFontSize));
 
105
                        listener->setFont(tmpFontName, tmpFontSize);
 
106
                        break;
 
107
                default:
 
108
                        break;          
 
109
        }
 
110
}