~ubuntu-branches/ubuntu/saucy/libwpd/saucy

« back to all changes in this revision

Viewing changes to src/lib/WP5FontGroup.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20111129233113-xdtwca9h0y6wdxst
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
3
 
 *  
 
4
 *
4
5
 * This library is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU Lesser General Public
6
7
 * License as published by the Free Software Foundation; either
18
19
 * For further information visit http://libwpd.sourceforge.net
19
20
 */
20
21
 
21
 
/* "This product is not manufactured, approved, or supported by 
 
22
/* "This product is not manufactured, approved, or supported by
22
23
 * Corel Corporation or Corel Corporation Limited."
23
24
 */
24
25
 
31
32
#include "WP5FontNameStringPoolPacket.h"
32
33
#include "WP5Listener.h"
33
34
 
34
 
WP5FontGroup::WP5FontGroup(WPXInputStream *input, WPXEncryption *encryption) :  
 
35
WP5FontGroup::WP5FontGroup(WPXInputStream *input, WPXEncryption *encryption) :
35
36
        WP5VariableLengthGroup(),
36
37
        m_red(0),
37
38
        m_green(0),
46
47
{
47
48
        switch(getSubGroup())
48
49
        {
49
 
                case WP5_TOP_FONT_GROUP_COLOR:
50
 
                        input->seek(3, WPX_SEEK_CUR);
51
 
                        m_red = readU8(input, encryption);
52
 
                        m_green = readU8(input, encryption);
53
 
                        m_blue = readU8(input, encryption);
54
 
                        break;
55
 
                case WP5_TOP_FONT_GROUP_FONT_CHANGE:
56
 
                        input->seek(25, WPX_SEEK_CUR);
57
 
                        m_fontNumber = readU8(input, encryption);
58
 
                        if (getSize() >= 36)
59
 
                        {
60
 
                                input->seek(2, WPX_SEEK_CUR);
61
 
                                m_fontSize = (double)(readU16(input, encryption) / 50);
62
 
                        }
63
 
                        break;
64
 
                default:
65
 
                        break;
66
 
        }       
 
50
        case WP5_TOP_FONT_GROUP_COLOR:
 
51
                input->seek(3, WPX_SEEK_CUR);
 
52
                m_red = readU8(input, encryption);
 
53
                m_green = readU8(input, encryption);
 
54
                m_blue = readU8(input, encryption);
 
55
                break;
 
56
        case WP5_TOP_FONT_GROUP_FONT_CHANGE:
 
57
                input->seek(25, WPX_SEEK_CUR);
 
58
                m_fontNumber = readU8(input, encryption);
 
59
                if (getSize() >= 36)
 
60
                {
 
61
                        input->seek(2, WPX_SEEK_CUR);
 
62
                        m_fontSize = (double)(readU16(input, encryption) / 50);
 
63
                }
 
64
                break;
 
65
        default:
 
66
                break;
 
67
        }
67
68
}
68
69
 
69
70
void WP5FontGroup::parse(WP5Listener *listener)
70
71
{
71
72
        WPD_DEBUG_MSG(("WordPerfect: handling a Font group\n"));
72
 
        
 
73
 
73
74
        int tmpFontNameOffset;
74
75
        double tmpFontSize = 12.0;
75
76
        WPXString tmpFontName("Times New Roman");
76
77
 
77
78
        switch(getSubGroup())
78
79
        {
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
 
                        if (listener->getGeneralPacketData(7))
101
 
                                tmpFontName = static_cast<const WP5FontNameStringPoolPacket*>(listener->getGeneralPacketData(7))->getFontName(tmpFontNameOffset);
102
 
                        if (m_fontSize >= 0)
103
 
                                tmpFontSize = m_fontSize;
104
 
 
105
 
                        WPD_DEBUG_MSG(("WP5 Parsing Font Change, fontNumber %i, fontName: %s, fontSize: %.4f\n", m_fontNumber, tmpFontName.cstr(), tmpFontSize));
 
80
        case WP5_TOP_FONT_GROUP_COLOR:
 
81
                listener->characterColorChange(m_red, m_green, m_blue);
 
82
                break;
 
83
        case WP5_TOP_FONT_GROUP_FONT_CHANGE:
 
84
                if (listener->getGeneralPacketData(15))
 
85
                {
 
86
                        tmpFontSize = static_cast<const WP5ListFontsUsedPacket *>(listener->getGeneralPacketData(15))->getFontSize(m_fontNumber);
 
87
                        tmpFontNameOffset = static_cast<const WP5ListFontsUsedPacket *>(listener->getGeneralPacketData(15))->getFontNameOffset(m_fontNumber);
 
88
 
 
89
                }
 
90
                else if (listener->getGeneralPacketData(2))
 
91
                {
 
92
                        tmpFontSize = static_cast<const WP5ListFontsUsedPacket *>(listener->getGeneralPacketData(2))->getFontSize(m_fontNumber);
 
93
                        tmpFontNameOffset = static_cast<const WP5ListFontsUsedPacket *>(listener->getGeneralPacketData(2))->getFontNameOffset(m_fontNumber);
 
94
                }
 
95
                else
 
96
                {
106
97
                        listener->setFont(tmpFontName, tmpFontSize);
107
 
                        break;
108
 
                default:
109
 
                        break;          
 
98
                        return;
 
99
                }
 
100
 
 
101
                if (listener->getGeneralPacketData(7))
 
102
                        tmpFontName = static_cast<const WP5FontNameStringPoolPacket *>(listener->getGeneralPacketData(7))->getFontName(tmpFontNameOffset);
 
103
                if (m_fontSize >= 0)
 
104
                        tmpFontSize = m_fontSize;
 
105
 
 
106
                WPD_DEBUG_MSG(("WP5 Parsing Font Change, fontNumber %i, fontName: %s, fontSize: %.4f\n", m_fontNumber, tmpFontName.cstr(), tmpFontSize));
 
107
                listener->setFont(tmpFontName, tmpFontSize);
 
108
                break;
 
109
        default:
 
110
                break;
110
111
        }
111
112
}
 
113
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */