Debian Codegraph @

src/lib/ReadySetGoStyleManager.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #include <cmath>
35 #include <iomanip>
36 #include <iostream>
37 #include <limits>
38 #include <sstream>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWFontConverter.hxx"
43 #include "MWAWGraphicListener.hxx"
44 #include "MWAWGraphicShape.hxx"
45 #include "MWAWGraphicStyle.hxx"
46 #include "MWAWHeader.hxx"
47 #include "MWAWParagraph.hxx"
48 #include "MWAWPictBitmap.hxx"
49 #include "MWAWPictData.hxx"
50 #include "MWAWPrinter.hxx"
51 #include "MWAWPosition.hxx"
52 #include "MWAWRSRCParser.hxx"
53 #include "MWAWSubDocument.hxx"
54
55 #include "ReadySetGoParser.hxx"
56
57 #include "ReadySetGoStyleManager.hxx"
58
59 /** Internal: the structures of a ReadySetGoStyleManager */
60 namespace ReadySetGoStyleManagerInternal
61 {
62
63 ////////////////////////////////////////
64 //! Internal: the state of a ReadySetGoStyleManager
65 struct State {
66 //! constructor
67 State()
68 : m_version(-1)
69 , m_isDesignStudio(false)
70 , m_colors()
71 , m_patterns()
72 {
73 }
74
75 //! init the color's list
76 void initColors();
77 //! init the patterns' list
78 void initPatterns();
79
80 //! the file version
81 int m_version;
82 //! a flag to know if we parse a Design Studio file
83 bool m_isDesignStudio;
84 //! the list of colors: v45
85 std::vector<MWAWColor> m_colors;
86 //! the list of patterns: v3
87 std::vector<MWAWGraphicStyle::Pattern> m_patterns;
88 };
89
90 void State::initColors()
91 {
92 if (!m_colors.empty()) return;
93 if (m_version<5) {
94 MWAW_DEBUG_MSG(("ReadSetGoStyleManagerInternal::initColors: unknown version\n"));
95 return;
96 }
97 static uint32_t const values[797]= {
98 0x000000, 0xffee00, 0xde4f16, 0xa1006a, 0xc5008e, 0x7d0089, 0x0c0087, 0x0075ad,
99 0x00a36e, 0x080d02, 0x30007b, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
100 0x000000, 0x000000, 0x000000, 0x000000, 0xe5dec5, 0xdcd9c7, 0xbaada4, 0xa6968d,
101 0x827872, 0xaf9b8f, 0xa9988d, 0x857a74, 0x786e6b, 0x605857, 0x443c3e, 0xcfc9b5,
102 0xcac6ba, 0xbeb5b2, 0xb0a6a6, 0x918e92, 0xaa9b98, 0x918d90, 0x75747e, 0x5b5a68,
103 0x4d4d5c, 0x323543, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
104 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
105 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xffffff, 0xdd0806, 0x008011,
106 0x0000d4, 0x02abea, 0xf20884, 0xfcf305, 0xff37b9, 0x9c66fe, 0xff5f0d, 0x00cb00,
107 0x4a1209, 0x848484, 0xf9e2a6, 0xfc4b44, 0xe0ad0d, 0xe06d9b, 0x79b4ff, 0x002eb2,
108 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
109 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
110 0x000000, 0x000000, 0x000000, 0xffffff, 0xfff681, 0xfffb6b, 0xfff400, 0xc5b00a,
111 0xa49300, 0x6a6000, 0xfff37a, 0xfff46b, 0xffef5e, 0xffed2f, 0xd9bd11, 0xa28b00,
112 0x8e7e00, 0xffee7a, 0xffef6a, 0xffea57, 0xffd900, 0xc2a100, 0xa1850d, 0x73690f,
113 0xffed7a, 0xffee76, 0xffe21c, 0xffd200, 0xc39800, 0x9a7f00, 0x847200, 0xffe97a,
114 0xffea78, 0xffe01a, 0xffc700, 0xc89900, 0x846d00, 0x524d05, 0xffe072, 0xffd65f,
115 0xffc51a, 0xffac00, 0xce8b00, 0x936c00, 0x5a4e09, 0xffd561, 0xffce4c, 0xf2b52b,
116 0xcb8300, 0xc57e00, 0x906f00, 0x5b5101, 0xffd788, 0xffca74, 0xffa719, 0xff9800,
117 0xcb7d00, 0x956500, 0x7f5800, 0xffe4a3, 0xffd483, 0xf59a4c, 0xed7f2e, 0xb2582a,
118 0x7a4702, 0x4d3506, 0xffcb8b, 0xffb073, 0xff9351, 0xe67500, 0xc26200, 0x9b5405,
119 0x43290d, 0xffc198, 0xff9e7c, 0xff855d, 0xff6d0d, 0xb85802, 0x723d07, 0x482904,
120 0xffbdab, 0xff8e83, 0xff7061, 0xc64230, 0x8e3825, 0x582a23, 0xffc5ba, 0xff8e9e,
121 0xec768e, 0xcc304f, 0xa3223a, 0x741019, 0x491010, 0xffb2b1, 0xff98a9, 0xdf5978,
122 0xd62654, 0x9a2447, 0x611333, 0x44182e, 0xffc3bd, 0xebaab1, 0xca356a, 0xaa1743,
123 0x8d0034, 0x711839, 0x591d1f, 0xffc0c3, 0xe97da2, 0xd55686, 0xaf0755, 0x7c1549,
124 0x530b34, 0x431030, 0xffa8b9, 0xe76d9c, 0xdb3381, 0xb81063, 0xa1185b, 0x671544,
125 0x440930, 0xffcedf, 0xda74b1, 0xbc1a88, 0x7c0056, 0x650049, 0x400031, 0xff7ac5,
126 0xe85dac, 0xd33198, 0xb80081, 0x7d005e, 0x570046, 0x3c1036, 0xffbad4, 0xe46cb2,
127 0xd0349e, 0xa6007b, 0x6c0059, 0x4a0040, 0xffa1d8, 0xef60c6, 0xc63ca5, 0xab0089,
128 0x800071, 0x68005d, 0x3f003c, 0xffd0ed, 0xde95c5, 0xd067c2, 0x8d008a, 0x7c007c,
129 0x66006e, 0x44004d, 0xf9d5ee, 0xe493ff, 0xab35be, 0x630074, 0x4e0058, 0x370047,
130 0xe6b9d3, 0xd29bc6, 0x9145a5, 0x640a7f, 0x450f56, 0x3b174e, 0x351d4a, 0xdac4de,
131 0xb18ad0, 0x6f2bb1, 0x48128a, 0x360570, 0x2f0a5e, 0x21054d, 0xc2a6cc, 0xab89c4,
132 0x8c6fba, 0x3e1d88, 0x250765, 0x220c57, 0x1c0d45, 0xc2c9dc, 0xa8abdd, 0x7c89c4,
133 0x06106a, 0x000e4f, 0x0a0c44, 0xc9d5f0, 0xa7b8df, 0x5f74e2, 0x253fb6, 0x001769,
134 0x000067, 0x000e44, 0xc4d5e5, 0x94b0dc, 0x7592c7, 0x0000b4, 0x002a7f, 0x00286c,
135 0x001c48, 0x8bb0c9, 0x6c97b8, 0x407fb3, 0x0f59a0, 0x004085, 0x002f5d, 0x00294d,
136 0xcceae4, 0x7fcde1, 0x56a9c7, 0x006795, 0x004261, 0x002f4e, 0x9ed7d2, 0x72b7c1,
137 0x2e8aa1, 0x007291, 0x006281, 0x00445f, 0x00293c, 0xdbffe4, 0xc7f5df, 0x72d6c1,
138 0x009696, 0x00787d, 0x006b71, 0x004b55, 0xb7dfc2, 0x89d0b0, 0x6bb9a1, 0x178479,
139 0x105f5e, 0x004f50, 0x16373f, 0xccf5c2, 0xc0f0be, 0x74e2a3, 0x17855c, 0x156e54,
140 0x12584b, 0xa1e8b1, 0x82ce9d, 0x59aa80, 0x2a9167, 0x1b6d52, 0x245c4a, 0x11413d,
141 0xc8eea5, 0xbcf4a2, 0x8dee88, 0x3bb253, 0x309540, 0x2a6f36, 0x2d4a1f, 0xc8f6a6,
142 0xbcffa0, 0x92f58f, 0x2bcb4c, 0x318b40, 0x2a6739, 0x274730, 0xd6f094, 0xb7e36f,
143 0x8fd44e, 0x5ea223, 0x4a7d22, 0x466c18, 0x3f5c12, 0xe5f491, 0xdaf173, 0xc0e752,
144 0x89ca03, 0x76a600, 0x628000, 0x45520a, 0xf6ff74, 0xe8ff6c, 0xcce73d, 0xb0de00,
145 0x98bd00, 0x7f9300, 0x515700, 0xf7f666, 0xe6f157, 0xd1e022, 0xc4d600, 0xacae00,
146 0x989600, 0x6e6b00, 0xf9fa7e, 0xf4fa62, 0xedfa37, 0xecff0d, 0xbbbf00, 0x9f9900,
147 0x747300, 0xfdf378, 0xf6f94f, 0xf1f220, 0xe9f200, 0xbfba00, 0xa19b00, 0x8e8603,
148 0xd3c9af, 0xb2a390, 0x968d80, 0x827a6d, 0x5e5854, 0x33312e, 0xd6cab5, 0xb5a69a,
149 0xaa9c97, 0x7c7371, 0x544a48, 0x433e44, 0x110f0a, 0xc8c0a6, 0xaca396, 0x89867d,
150 0x656764, 0x4b4d4b, 0x393b3b, 0x131317, 0xc8c3bb, 0xbcb7b8, 0x8d8b92, 0x7f7d82,
151 0x5d5b60, 0x3a3a48, 0x070b1c, 0xccc7bb, 0xb2acb0, 0x8f8f99, 0x787882, 0x515567,
152 0x282e48, 0x0f1020, 0xccb0a6, 0xc3a49d, 0x9a7b7f, 0x78606a, 0x3f2d3d, 0x261a25,
153 0x211b22, 0xd4d2c6, 0xbdbbb8, 0x8b8e91, 0x696a6d, 0x474850, 0x2e2e3b, 0x222422,
154 0x3a3116, 0x4f463a, 0x594e2d, 0xa08f72, 0xad9d86, 0xc8ba95, 0xddd8ad, 0x544b25,
155 0x7f7019, 0xa88f2f, 0xe2d360, 0xeae171, 0xf7ef83, 0xf7ee98, 0x594535, 0x6d4f2b,
156 0x835a35, 0xc2a075, 0xd6ba8a, 0xdbc58e, 0xead9a3, 0x4d3522, 0x9f612e, 0xc26d21,
157 0xe9a872, 0xe6b480, 0xf0cf99, 0xf3d59e, 0x3b292d, 0x5a3d3b, 0x683e3b, 0xa57f6f,
158 0xb19286, 0xccab97, 0xd6c4af, 0x4f3020, 0x914120, 0xc83f31, 0xdb9279, 0xefab8d,
159 0xebb298, 0xf5cfb0, 0x4e2b33, 0x602732, 0x702237, 0xc5707d, 0xe89b9e, 0xefb5b1,
160 0xf4cab6, 0x3f291b, 0x593331, 0x723c38, 0xc7807e, 0xd59890, 0xe4b1a5, 0xf0cdb9,
161 0x421f31, 0x532138, 0x602944, 0xbc6c83, 0xd28390, 0xe9a6a9, 0xecb8b8, 0x48264a,
162 0x682f6f, 0x802e83, 0xc26aa9, 0xd38bb4, 0xeba5c2, 0xf7c7cf, 0x3b1d3e, 0x552961,
163 0x62296f, 0xa6729a, 0xbc8da6, 0xd5aab9, 0xe7c7ce, 0x3c2056, 0x4e2077, 0x5b1c8b,
164 0x9462a8, 0xba86c1, 0xd2a2cd, 0xe2c5e1, 0x211e3c, 0x2d234e, 0x3e376b, 0x8b8099,
165 0xad9eb5, 0xb9afc2, 0xccc8d0, 0x18234c, 0x0f2d67, 0x0f337c, 0x657bab, 0x8c9bbc,
166 0xa9b1c6, 0xc3cddc, 0x001b39, 0x093151, 0x1f4769, 0x597a96, 0x819cac, 0x9fabb3,
167 0xc3cfcd, 0x192b00, 0x183e00, 0x214e27, 0x69866d, 0x95a690, 0xa5b19a, 0xb7c5aa,
168 0x1d3027, 0x275046, 0x396c5d, 0x74a185, 0x92b499, 0xc4ddbe, 0xe1f6d7, 0x1b382d,
169 0x164f3b, 0x2b6c55, 0x67a684, 0x93c79e, 0xb6d9b2, 0xd1e8c1, 0x394100, 0x4e6200,
170 0x567700, 0xa6be64, 0xc8d885, 0xd5de87, 0xdde49a, 0x5a5600, 0x909100, 0xa5ae00,
171 0xd0da5b, 0xdde365, 0xe7ec73, 0xe9ef8d, 0xffd170, 0xffcd64, 0xffb615, 0xff9c00,
172 0xce8500, 0x7c5a00, 0x463400, 0xffcc8f, 0xffa963, 0xf58532, 0xf77800, 0xc26300,
173 0x864e00, 0x573100, 0xffb68c, 0xffa57b, 0xff834f, 0xe66000, 0xc25600, 0x7d3b00,
174 0x4d2700, 0xffa7a5, 0xff888f, 0xff6375, 0xde2c1a, 0xc62d37, 0x781915, 0x4f1818,
175 0xca61ff, 0xbc39ff, 0x800ebe, 0x590089, 0x4c0074, 0x380058, 0x2f004e, 0xbf6bff,
176 0xae3dff, 0x8a20db, 0x470080, 0x3d0070, 0x350063, 0x280052, 0xcf99ff, 0xa84eff,
177 0x6c0fc0, 0x5100a0, 0x20005f, 0x1e124c, 0x9c79cc, 0x8e74cc, 0x6c22cf, 0x33008e,
178 0x26006f, 0x1d0057, 0x170045, 0xbcd5da, 0x7cacd1, 0x569ac9, 0x2176c1, 0x13528a,
179 0x00395d, 0x002540, 0x9ed7ca, 0x72b4b6, 0x0092a1, 0x0d768b, 0x00687c, 0x00475b,
180 0x003548, 0xaee9c3, 0x7ee3b7, 0x50c39e, 0x00947c, 0x00786c, 0x00514f, 0x003238,
181 0xacdfb7, 0x7cd0a6, 0x5eb996, 0x009176, 0x0a7160, 0x0c5b51, 0x0d3732, 0x86d6b0,
182 0x70cda6, 0x29a889, 0x008a6e, 0x006e5c, 0x005749, 0x002e26, 0xa4e9a7, 0x7ce595,
183 0x5cd481, 0x34a562, 0x308057, 0x245c44, 0x113823, 0xffff78, 0xfbfe4f, 0xf8fa20,
184 0xe9ec00, 0xaba200, 0x858100, 0x595600, 0x4f420c, 0x776900, 0x8a7c3e, 0xbbab7e,
185 0xbfb084, 0xcac49b, 0xd6d1a9, 0x452a00, 0x7e5943, 0xa17a62, 0xbe9675, 0xc9a98c,
186 0xc9ac91, 0xd3ba9c, 0x4d2b32, 0x6a3e3e, 0x926e66, 0xae8474, 0xbc9580, 0xc8ac99,
187 0xd1b79e, 0x432d3a, 0x714355, 0x92606d, 0xc6949a, 0xd5a4a7, 0xdbc2b9, 0xddccc3,
188 0x3f184a, 0x632e6f, 0x8c5691, 0xba89ad, 0xc09ab3, 0xceb1c2, 0xd9c8cd, 0x2d1b3e,
189 0x442952, 0x694870, 0x90728b, 0xac8d9f, 0xc2aab3, 0xd7c7c6, 0x1e004b, 0x3a2077,
190 0x421c8b, 0x735cac, 0x9b84c1, 0xb7a4cd, 0xccc3e1, 0x061c50, 0x1b3365, 0x4d5f85,
191 0x75809c, 0x9a9eb8, 0xb0afc5, 0xc3c8d4, 0x00253e, 0x1a475b, 0x517483, 0x899fa3,
192 0xa2b4b4, 0xbccac2, 0xd1dcd0, 0x001b31, 0x18394c, 0x375363, 0x77878c, 0x94a0a0,
193 0xadb4b0, 0xc8d0c7, 0x283840, 0x4c645c, 0x6a8377, 0x7b8f82, 0xa1ad9f, 0xafb9a8,
194 0xc1ccb7, 0x172721, 0x3a504d, 0x576963, 0x909d91, 0xacb1a2, 0xc0ccb5, 0xd6dec8,
195 0x343d29, 0x4a5735, 0x5d6c3d, 0x9ea175, 0xb1b07e, 0xc9cba2, 0xd8d9ae, 0x3f4511,
196 0x5d6600, 0x7e8746, 0xb1b273, 0xc8cc91, 0xd5d9a2, 0xdddead, 0x494a2a, 0x71743d,
197 0xa5a069, 0xc4c07d, 0xcac785, 0xd3d08f, 0xdad7a3
198 };
199
200 m_colors.resize(797);
201 for (size_t i=0; i < 797; ++i)
202 m_colors[i] = values[i];
203 }
204
205 void State::initPatterns()
206 {
207 if (!m_patterns.empty()) return;
208 if (m_version<3) {
209 MWAW_DEBUG_MSG(("ReadSetGoParserInternal::initPatterns: unknown version\n"));
210 return;
211 }
212 if (m_version==3) {
213 static uint16_t const values[] = {
214 0xffff, 0xffff, 0xffff, 0xffff, 0xddff, 0x77ff, 0xddff, 0x77ff, 0xdd77, 0xdd77, 0xdd77, 0xdd77, 0xaa55, 0xaa55, 0xaa55, 0xaa55,
215 0x55ff, 0x55ff, 0x55ff, 0x55ff, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0xeedd, 0xbb77, 0xeedd, 0xbb77, 0x8888, 0x8888, 0x8888, 0x8888,
216 0xb130, 0x031b, 0xd8c0, 0x0c8d, 0x8010, 0x0220, 0x0108, 0x4004, 0xff88, 0x8888, 0xff88, 0x8888, 0xff80, 0x8080, 0xff08, 0x0808,
217 0x0000, 0x0002, 0x0000, 0x0002, 0x8040, 0x2000, 0x0204, 0x0800, 0x8244, 0x3944, 0x8201, 0x0101, 0xf874, 0x2247, 0x8f17, 0x2271,
218 0x55a0, 0x4040, 0x550a, 0x0404, 0x2050, 0x8888, 0x8888, 0x0502, 0xbf00, 0xbfbf, 0xb0b0, 0xb0b0, 0x0000, 0x0000, 0x0000, 0x0000,
219 0x8000, 0x0800, 0x8000, 0x0800, 0x8800, 0x2200, 0x8800, 0x2200, 0x8822, 0x8822, 0x8822, 0x8822, 0xaa00, 0xaa00, 0xaa00, 0xaa00,
220 0x00ff, 0x00ff, 0x00ff, 0x00ff, 0x1122, 0x4488, 0x1122, 0x4488, 0x8040, 0x2000, 0x0204, 0x0800, 0x0102, 0x0408, 0x1020, 0x4080,
221 0xaa00, 0x8000, 0x8800, 0x8000, 0xff80, 0x8080, 0x8080, 0x8080, 0x0814, 0x2241, 0x8001, 0x0204, 0x8814, 0x2241, 0x8800, 0xaa00,
222 0x40a0, 0x0000, 0x040a, 0x0000, 0x0384, 0x4830, 0x0c02, 0x0101, 0x8080, 0x413e, 0x0808, 0x14e3, 0x1020, 0x54aa, 0xff02, 0x0408,
223 0x7789, 0x8f8f, 0x7798, 0xf8f8, 0x0008, 0x142a, 0x552a, 0x1408, 0x0000, 0x0000, 0x0000, 0x0000,
224 };
225 size_t N=MWAW_N_ELEMENTS(values)/4;
226 m_patterns.resize(N);
227 uint16_t const *ptr=values;
228 for (size_t i=0; i<N; ++i) {
229 auto &pat=m_patterns[i];
230 pat.m_dim=MWAWVec2i(8,8);
231 pat.m_data.resize(8);
232 for (size_t j=0; j<8; j+=2) {
233 pat.m_data[j]=uint8_t(~(*ptr>>8));
234 pat.m_data[j+1]=uint8_t(~(*(ptr++)&0xff));
235 }
236 }
237 return;
238 }
239 if (m_version<6 || (m_isDesignStudio && m_version==6)) {
240 static uint16_t const values[] = {
241 0xffff, 0xffff, 0xffff, 0xffff, 0x7f7f, 0x7f7f, 0x7f7f, 0x7f7f, 0xff, 0xffff, 0xffff, 0xffff, 0xefdf, 0xbf7f, 0xfefd, 0xfbf7,
242 0xbfff, 0xffff, 0xfbff, 0xffff, 0x3f3f, 0x3f3f, 0x3f3f, 0x3f3f, 0x0, 0xffff, 0xffff, 0xffff, 0xe7cf, 0x9f3f, 0x7efc, 0xf9f3,
243 0xff77, 0xffff, 0xffdd, 0xffff, 0x1f1f, 0x1f1f, 0x1f1f, 0x1f1f, 0x0, 0xff, 0xffff, 0xffff, 0xe3c7, 0x8f1f, 0x3e7c, 0xf8f1,
244 0xddff, 0x77ff, 0xddff, 0x77ff, 0xf0f, 0xf0f, 0xf0f, 0xf0f, 0x0, 0x0, 0xffff, 0xffff, 0xe1c3, 0x870f, 0x1e3c, 0x78f0,
245 0xdd77, 0xdd77, 0xdd77, 0xdd77, 0x707, 0x707, 0x707, 0x707, 0x0, 0x0, 0xff, 0xffff, 0xc183, 0x70e, 0x1c38, 0x70e0,
246 0xaa55, 0xaa55, 0xaa55, 0xaa55, 0x303, 0x303, 0x303, 0x303, 0x0, 0x0, 0x0, 0xffff, 0x306, 0xc18, 0x3060, 0xc081,
247 0x8822, 0x8822, 0x8822, 0x8822, 0x8080, 0x8080, 0x8080, 0x8080, 0x0, 0x0, 0x0, 0xff, 0x102, 0x408, 0x1020, 0x4080,
248 0x8800, 0x2200, 0x8800, 0x2200, 0x8888, 0x8888, 0x8888, 0x8888, 0xff, 0x0, 0xff, 0x0, 0x1122, 0x4488, 0x1122, 0x4488,
249 0x8000, 0x800, 0x8000, 0x800, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x0, 0xffff, 0x0, 0xffff, 0x3366, 0xcc99, 0x3366, 0xcc99,
250 0x0, 0x2000, 0x0, 0x200, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0xff, 0xffff, 0xff, 0xffff, 0x77ee, 0xddbb, 0x77ee, 0xddbb,
251 0x0, 0x0, 0x0, 0x0, 0x40a0, 0x0, 0x40a, 0x0, 0xff80, 0x8080, 0xff08, 0x808, 0xff77, 0x3311, 0xff77, 0x3311, 0xb130,
252 0x31b, 0xd8c0, 0xc8d, 0x8040, 0x2000, 0x204, 0x800, 0x8010, 0x220, 0x108, 0x4004, 0x4, 0xc3f, 0x1c2c, 0x4400,
253 0x0, 0x0, 0x0, 0x0, /* none*/ 0x7789, 0x8f8f, 0x7798, 0xf8f8, 0x8, 0x142a, 0x552a, 0x1408, 0xfffb, 0xf3c0, 0xe3d3, 0xbbff,
254 };
255 size_t N=MWAW_N_ELEMENTS(values)/4;
256 m_patterns.resize(N);
257 uint16_t const *ptr=values;
258 for (size_t i=0; i<N; ++i) {
259 auto &pat=m_patterns[i];
260 pat.m_dim=MWAWVec2i(8,8);
261 pat.m_data.resize(8);
262 for (size_t j=0; j<8; j+=2) {
263 pat.m_data[j]=uint8_t(~(*ptr>>8));
264 pat.m_data[j+1]=uint8_t(~(*(ptr++)&0xff));
265 }
266 }
267 return;
268 }
269
270 static uint16_t const values[] = {
271 0xffff, 0xffff, 0xffff, 0xffff, 0xff, 0xffff, 0xffff, 0xffff, 0xefdf, 0xbf7f, 0xfefd, 0xfbf7, 0x0, 0x0, 0x0, 0x0, /* none */
272 0x0, 0xffff, 0xffff, 0xffff, 0xe7cf, 0x9f3f, 0x7efc, 0xf9f3, 0x1f1f, 0x1f1f, 0x1f1f, 0x1f1f, 0x0, 0xff, 0xffff, 0xffff,
273 0xe3c7, 0x8f1f, 0x3e7c, 0xf8f1, 0xf0f, 0xf0f, 0xf0f, 0xf0f, 0x0, 0x0, 0xffff, 0xffff, 0xe1c3, 0x870f, 0x1e3c, 0x78f0,
274 0x707, 0x707, 0x707, 0x707, 0x0, 0x0, 0xff, 0xffff, 0xc183, 0x70e, 0x1c38, 0x70e0, 0x303, 0x303, 0x303, 0x303,
275 0x0, 0x0, 0x0, 0xffff, 0x306, 0xc18, 0x3060, 0xc081, 0x8080, 0x8080, 0x8080, 0x8080, 0x0, 0x0, 0x0, 0xff,
276 0x102, 0x408, 0x1020, 0x4080, 0x8888, 0x8888, 0x8888, 0x8888, 0xff, 0x0, 0xff, 0x0, 0x1122, 0x4488, 0x1122, 0x4488,
277 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x0, 0xffff, 0x0, 0xffff, 0x3366, 0xcc99, 0x3366, 0xcc99, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
278 0xff, 0xffff, 0xff, 0xffff, 0x77ee, 0xddbb, 0x77ee, 0xddbb, 0x40a0, 0x0, 0x40a, 0x0, 0xff80, 0x8080, 0xff08, 0x808,
279 0xff77, 0x3311, 0xff77, 0x3311, 0x8040, 0x2000, 0x204, 0x800, 0x8010, 0x220, 0x108, 0x4004, 0x4, 0xc3f, 0x1c2c, 0x4400,
280 0x7789, 0x8f8f, 0x7798, 0xf8f8, 0x8, 0x142a, 0x552a, 0x1408, 0xfffb, 0xf3c0, 0xe3d3, 0xbbff, 0xb130, 0x31b, 0xd8c0, 0xc8d,
281 0x3f3f, 0x3f3f, 0x3f3f, 0x3f3f, 0x7f7f, 0x7f7f, 0x7f7f, 0x7f7f
282 };
283 size_t N=MWAW_N_ELEMENTS(values)/4;
284 m_patterns.resize(N);
285 uint16_t const *ptr=values;
286 for (size_t i=0; i<N; ++i) {
287 auto &pat=m_patterns[i];
288 pat.m_dim=MWAWVec2i(8,8);
289 pat.m_data.resize(8);
290 for (size_t j=0; j<8; j+=2) {
291 pat.m_data[j]=uint8_t(~(*ptr>>8));
292 pat.m_data[j+1]=uint8_t(~(*(ptr++)&0xff));
293 }
294 }
295 }
296
297 }
298
299 ////////////////////////////////////////////////////////////
300 // constructor/destructor, ...
301 ////////////////////////////////////////////////////////////
302 ReadySetGoStyleManager::ReadySetGoStyleManager(ReadySetGoParser &parser)
303 : m_parser(parser)
304 , m_parserState(parser.getParserState())
305 , m_state(new ReadySetGoStyleManagerInternal::State)
306 {
307 }
308
309 ReadySetGoStyleManager::~ReadySetGoStyleManager()
310 {
311 }
312
313 int ReadySetGoStyleManager::version() const
314 {
315 if (m_state->m_version==-1) {
316 int const vers=m_parser.version();
317 m_state->m_version=vers;
318 m_state->m_isDesignStudio=m_parser.isDesignStudioFile();
319 m_state->m_colors.clear();
320 if (vers>=5)
321 m_state->initColors();
322 }
323 return m_state->m_version;
324 }
325
326 bool ReadySetGoStyleManager::getColor(int colorId, MWAWColor &color) const
327 {
328 if (colorId>0 && size_t(colorId)<m_state->m_colors.size()) {
329 color=m_state->m_colors[size_t(colorId)];
330 return true;
331 }
332 MWAW_DEBUG_MSG(("ReadySetGoParser::getColor: unknown color id=%d\n", colorId));
333 return false;
334 }
335
336 bool ReadySetGoStyleManager::getPattern(int patternId, MWAWGraphicStyle::Pattern &pattern) const
337 {
338 version();
339 if (m_state->m_patterns.empty())
340 m_state->initPatterns();
341 if (patternId < 0 || size_t(patternId) >= m_state->m_patterns.size()) {
342 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::getPattern: can not find pattern %d\n", patternId));
343 return false;
344 }
345 pattern=m_state->m_patterns[size_t(patternId)];
346 return true;
347 }
348
349 ////////////////////////////////////////////////////////////
350 //
351 // Intermediate level
352 //
353 ////////////////////////////////////////////////////////////
354 bool ReadySetGoStyleManager::readColors()
355 {
356 int const vers=version();
357 if (vers<5) {
358 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColors: unexpected version\n"));
359 return false;
360 }
361 MWAWInputStreamPtr input = m_parser.getInput();
362 if (!input)
363 return false;
364 long pos=input->tell();
365 if (!input->checkPosition(pos+120)) {
366 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColors: can not find the data\n"));
367 return false;
368 }
369 libmwaw::DebugStream f;
370 libmwaw::DebugFile &ascFile=m_parser.ascii();
371 f << "Entries(Colors):";
372 if (m_state->m_colors.size()<60+20) {
373 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColors: can not use the data\n"));
374 f << "###";
375 ascFile.addPos(pos);
376 ascFile.addNote(f.str().c_str());
377 input->seek(pos+120, librevenge::RVNG_SEEK_SET);
378 return true;
379 }
380 f << "colors=[";
381 for (size_t i=0; i<20; ++i) {
382 uint8_t colors[3];
383 for (auto &c : colors) c=uint8_t(input->readULong(2)>>8);
384 m_state->m_colors[60+i]=MWAWColor(colors[0],colors[1],colors[2]);
385 f << m_state->m_colors[60+i] << ",";
386 }
387 f << "],";
388 ascFile.addPos(pos);
389 ascFile.addNote(f.str().c_str());
390 return true;
391 }
392
393 bool ReadySetGoStyleManager::readColorNames()
394 {
395 int const vers=version();
396 if (vers<5) {
397 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColorNames: unexpected version\n"));
398 return false;
399 }
400 MWAWInputStreamPtr input = m_parser.getInput();
401 if (!input)
402 return false;
403 long pos=input->tell();
404 if (!input->checkPosition(pos+4)) {
405 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColorNames: can not find the data\n"));
406 return false;
407 }
408 libmwaw::DebugStream f;
409 libmwaw::DebugFile &ascFile=m_parser.ascii();
410 f << "Entries(ColorNames):";
411 long len=long(input->readLong(4));
412 if (len==0) {
413 ascFile.addPos(pos);
414 ascFile.addNote("_");
415 return true;
416 }
417 long endPos=pos+4+len;
418 if (len<20 || endPos<pos+4 || !input->checkPosition(endPos)) {
419 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColorNames: can not find the data\n"));
420 f << "###";
421 ascFile.addPos(pos);
422 ascFile.addNote(f.str().c_str());
423 return false;
424 }
425
426 f << "names=[";
427 for (int i=0; i<20; ++i) {
428 int cLen=int(input->readULong(1));
429 if (input->tell()+cLen>endPos) {
430 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readColorNames: can not read a name\n"));
431 f << "###";
432 break;
433 }
434 std::string name;
435 for (int c=0; c<cLen; ++c) {
436 char ch=char(input->readLong(1));
437 if (ch)
438 name+=ch;
439 }
440 f << name << ",";
441 }
442 f << "],";
443 ascFile.addPos(pos);
444 ascFile.addNote(f.str().c_str());
445 if (input->tell()!=endPos)
446 ascFile.addDelimiter(input->tell(),'|');
447 return true;
448 }
449
450 bool ReadySetGoStyleManager::readFontsBlock()
451 {
452 MWAWInputStreamPtr input = m_parser.getInput();
453 if (!input)
454 return false;
455 int const vers=version();
456 long pos=input->tell();
457 libmwaw::DebugStream f;
458 libmwaw::DebugFile &ascFile = m_parser.ascii();
459 f << "Entries(FontBlock):";
460 if (vers<5) {
461 f << "###";
462 ascFile.addPos(pos);
463 ascFile.addNote(f.str().c_str());
464 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock: unexpected version\n"));
465 return false;
466 }
467 long len=long(input->readLong(4));
468 long endPos=pos+4+len;
469 if (len<4 || endPos<pos+8 || !input->checkPosition(endPos)) {
470 f << "###";
471 ascFile.addPos(pos);
472 ascFile.addNote(f.str().c_str());
473 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock: the zone's length seems bad\n"));
474 return false;
475 }
476
477 int N=int(input->readULong(2));
478 int const dataSize=vers==5 ? 1110 : 1106;
479 f << "N=" << N << ",";
480 if (N<0 || (len-(m_parser.isDesignStudioFile() ? 2 : 4))/dataSize<N) {
481 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock: the n values seems bad\n"));
482 f << "###";
483 ascFile.addPos(pos);
484 ascFile.addNote(f.str().c_str());
485 N=0;
486 }
487 f << "unk=" << input->readLong(2) << ",";
488 ascFile.addPos(pos);
489 ascFile.addNote(f.str().c_str());
490 for (int i=0; i<N; ++i) {
491 pos=input->tell();
492 if (pos+dataSize > endPos)
493 break;
494 f.str("");
495 f << "FontBlock-A" << i << ":";
496 int cLen=int(input->readULong(1));
497 if (cLen>63) {
498 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock: the name seems too long\n"));
499 f << "###";
500 cLen=0;
501 }
502 std::string name;
503 for (int c=0; c<cLen; ++c) {
504 char ch=char(input->readLong(1));
505 if (ch==0)
506 break;
507 name+=ch;
508 }
509 f << name << ",";
510 ascFile.addDelimiter(pos+64,'|');
511 input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET);
512 ascFile.addPos(pos);
513 ascFile.addNote(f.str().c_str());
514 }
515 input->seek(endPos, librevenge::RVNG_SEEK_SET);
516
517 if (vers>5) return true;
518 for (int i=0; i<N; ++i) {
519 pos=input->tell();
520 len=long(input->readLong(4));
521 f.str("");
522 f << "FontBlock-B" << i << ":";
523 if ((long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) {
524 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock: can not find a data block\n"));
525 f << "###";
526 ascFile.addPos(pos);
527 ascFile.addNote(f.str().c_str());
528 return false;
529 }
530 if (len==0) {
531 ascFile.addPos(pos);
532 ascFile.addNote("_");
533 continue;
534 }
535 ascFile.addPos(pos);
536 ascFile.addNote(f.str().c_str());
537 input->seek(pos+4+len, librevenge::RVNG_SEEK_SET);
538 }
539
540 return true;
541 }
542
543 bool ReadySetGoStyleManager::readFontsBlock2()
544 {
545 MWAWInputStreamPtr input = m_parser.getInput();
546 if (!input)
547 return false;
548 int const vers=version();
549 long pos=input->tell();
550 libmwaw::DebugFile &ascFile = m_parser.ascii();
551 libmwaw::DebugStream f;
552 f << "Entries(FontBlck2):";
553 if (vers<6) {
554 f << "###";
555 ascFile.addPos(pos);
556 ascFile.addNote(f.str().c_str());
557 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock2: unexpected version\n"));
558 return false;
559 }
560 long len=long(input->readLong(4));
561 long endPos=pos+4+len;
562 if (endPos<pos+4 || !input->checkPosition(endPos)) {
563 f << "###";
564 ascFile.addPos(pos);
565 ascFile.addNote(f.str().c_str());
566 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock2: the zone's length seems bad\n"));
567 return false;
568 }
569 ascFile.addPos(pos);
570 ascFile.addNote(f.str().c_str());
571
572 int N=int(len/260);
573 for (int n=0; n<N; ++n) {
574 pos=input->tell();
575 f.str("");
576 f << "FontBlck2-" << n << ":";
577 f << "id=" << input->readLong(2) << ",";
578 int val=int(input->readLong(2));
579 if (val) f << "f0=" << val << ",";
580 int cLen=int(input->readULong(1));
581 if (cLen>63) {
582 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsBlock2: the name seems too long\n"));
583 f << "###";
584 cLen=0;
585 }
586 std::string name;
587 for (int c=0; c<cLen; ++c) {
588 char ch=char(input->readLong(1));
589 if (ch==0)
590 break;
591 name+=ch;
592 }
593 f << name << ",";
594 ascFile.addDelimiter(pos+4+64,'|');
595 input->seek(pos+260, librevenge::RVNG_SEEK_SET);
596 ascFile.addPos(pos);
597 ascFile.addNote(f.str().c_str());
598 }
599 input->seek(endPos, librevenge::RVNG_SEEK_SET);
600 return true;
601 }
602
603 bool ReadySetGoStyleManager::readFontsName()
604 {
605 MWAWInputStreamPtr input = m_parser.getInput();
606 if (!input)
607 return false;
608 int const vers=version();
609 long pos=input->tell();
610 libmwaw::DebugFile &ascFile = m_parser.ascii();
611 libmwaw::DebugStream f;
612 f << "Entries(FontName):";
613 if (vers<6) {
614 f << "###";
615 ascFile.addPos(pos);
616 ascFile.addNote(f.str().c_str());
617 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsName: unexpected version\n"));
618 return false;
619 }
620 long len=long(input->readLong(4));
621 long endPos=pos+4+len;
622 if (len<4 || endPos<pos+8 || !input->checkPosition(endPos)) {
623 f << "###";
624 ascFile.addPos(pos);
625 ascFile.addNote(f.str().c_str());
626 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsName: the zone's length seems bad\n"));
627 return false;
628 }
629 ascFile.addPos(pos);
630 ascFile.addNote(f.str().c_str());
631
632 int N=int(len/68);
633 for (int i=0; i<N; ++i) {
634 pos=input->tell();
635 f.str("");
636 f << "FontName-" << i << ":";
637 int cLen=int(input->readULong(1));
638 if (cLen>63) {
639 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readFontsName: can not read a name\n"));
640 f << "###";
641 ascFile.addPos(pos);
642 ascFile.addNote(f.str().c_str());
643 break;
644 }
645 std::string name;
646 for (int c=0; c<cLen; ++c) {
647 char ch=char(input->readLong(1));
648 if (ch)
649 name+=ch;
650 }
651 f << name << ",";
652 input->seek(pos+64, librevenge::RVNG_SEEK_SET);
653 int fId=int(input->readLong(2));
654 f << "id=" << fId << ",";
655 if (!name.empty())
656 m_parser.getFontConverter()->setCorrespondance(fId, name);
657 int val=int(input->readLong(2));
658 if (val)
659 f << "f0=" << val << ",";
660 ascFile.addPos(pos);
661 ascFile.addNote(f.str().c_str());
662 }
663 return true;
664 }
665
666 bool ReadySetGoStyleManager::readStyles(int numStyles)
667 {
668 MWAWInputStreamPtr input = m_parser.getInput();
669 if (!input)
670 return false;
671 int const vers=version();
672 long pos=input->tell();
673 libmwaw::DebugFile &ascFile = m_parser.ascii();
674 libmwaw::DebugStream f;
675 f << "Entries(Style):";
676 if (vers<4) {
677 f << "###";
678 ascFile.addPos(pos);
679 ascFile.addNote(f.str().c_str());
680 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyles: unexpected version\n"));
681 return false;
682 }
683 long len=long(input->readLong(4));
684 long endPos=pos+4+len;
685 if (endPos<pos+4 || !input->checkPosition(endPos)) {
686 f << "###";
687 ascFile.addPos(pos);
688 ascFile.addNote(f.str().c_str());
689 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyles: the zone's length seems bad\n"));
690 return false;
691 }
692 int const dataSize=vers==4 ? 74 : vers==5 ? 82 : vers==6 ? (m_parser.isDesignStudioFile() ? 90 : 92) : 98;
693 if (numStyles<0 || numStyles*dataSize>len) {
694 f << "###";
695 ascFile.addPos(pos);
696 ascFile.addNote(f.str().c_str());
697 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyles: the zone's length seems too short\n"));
698 return false;
699 }
700 if (len==0) {
701 ascFile.addPos(pos);
702 ascFile.addNote("_");
703 }
704 ascFile.addPos(pos);
705 ascFile.addNote(f.str().c_str());
706
707 int N=int(len/dataSize), numTabZones=0;
708 for (int i=0; i<N; ++i) {
709 pos=input->tell();
710 f.str("");
711 f << "Style-" << i << ":";
712 int cLen=int(input->readULong(1));
713 if (cLen>39) {
714 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyles: can not determine the name length\n"));
715 f << "##name[len]=" << cLen << ",";
716 cLen=0;
717 }
718 std::string name;
719 for (auto j=0; j<cLen; ++j) {
720 char c=char(input->readLong(1));
721 if (!c)
722 break;
723 name+=c;
724 }
725 f << name << ",";
726 input->seek(pos+40, librevenge::RVNG_SEEK_SET);
727 ascFile.addPos(pos);
728 ascFile.addNote(f.str().c_str());
729
730 int cPos;
731 MWAWFont font;
732 MWAWParagraph para;
733 readStyle(font, para, &cPos);
734
735 pos=input->tell();
736 input->seek(pos, librevenge::RVNG_SEEK_SET);
737 f.str("");
738 f << "Style-id" << ":";
739 if (vers>6)
740 input->seek(6, librevenge::RVNG_SEEK_CUR);
741 long tabId=long(input->readULong(4));
742 if (tabId) {
743 ++numTabZones;
744 f << "tab[id]=" << std::hex << tabId << std::dec << ",";
745 }
746 ascFile.addPos(pos);
747 ascFile.addNote(f.str().c_str());
748 }
749 if (input->tell()!=endPos) {
750 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyles: find extra data\n"));
751 ascFile.addPos(input->tell());
752 ascFile.addNote("Style:extra#");
753 }
754 input->seek(endPos, librevenge::RVNG_SEEK_SET);
755
756 for (int i=0; i<numTabZones; ++i) {
757 int cPos=0;
758 std::vector<MWAWTabStop> tabs;
759 if (!readTabulations(tabs, -1, &cPos))
760 return false;
761 }
762 return true;
763 }
764
765 bool ReadySetGoStyleManager::readStyle(MWAWFont &font, MWAWParagraph &para, int *cPos)
766 {
767 font=MWAWFont();
768 para=MWAWParagraph();
769 MWAWInputStreamPtr input = m_parser.getInput();
770 if (!input)
771 return false;
772 int const vers=version();
773 long pos=input->tell();
774 libmwaw::DebugStream f;
775 f << "Style:";
776 libmwaw::DebugFile &ascFile = m_parser.ascii();
777 if (vers<3) {
778 f << "###";
779 ascFile.addPos(pos);
780 ascFile.addNote(f.str().c_str());
781 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected version\n"));
782 return false;
783 }
784
785 long endPos=pos+(vers==3 ? 22 : vers==4 ? 26 : vers== 5 ? 34 : m_parser.isDesignStudioFile() ? 42 : 44)+(cPos ? 4 : 0);
786 if (!input->checkPosition(endPos)) {
787 f << "###";
788 ascFile.addPos(pos);
789 ascFile.addNote(f.str().c_str());
790 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: the zone is too short\n"));
791 return false;
792 }
793 if (cPos) {
794 *cPos=int(input->readLong(4));
795 f << "pos[char]=" << *cPos << ",";
796 }
797
798 font.setId(int(input->readULong(2)));
799 para.m_marginsUnit=librevenge::RVNG_INCH;
800 for (int i=0; i<3; ++i)
801 para.m_margins[i]=float(input->readLong(4))/65536;
802 para.m_margins[0]=*para.m_margins[0]-*para.m_margins[1];
803 if (vers<=4)
804 font.setSize(float(input->readULong(1)));
805 else
806 font.setSize(float(input->readULong(2))/100);
807 int val=int(input->readULong(1));
808 uint32_t flags=0;
809 if (val&0x1) flags |= MWAWFont::boldBit;
810 if (val&0x2) flags |= MWAWFont::italicBit;
811 if (val&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
812 if (val&0x8) flags |= MWAWFont::embossBit;
813 if (val&0x10) flags |= MWAWFont::shadowBit;
814 if (val&0x80) font.setStrikeOutStyle(MWAWFont::Line::Simple); // only v4
815 if (val&0x60) f << "fl=#" << std::hex << (val&0x60) << std::dec << ",";
816 font.setFlags(flags);
817 if (vers<=4) {
818 val=int(input->readULong(1));
819 if (val<100)
820 para.setInterline(val, librevenge::RVNG_POINT, MWAWParagraph::AtLeast);
821 else if (val && val!=100) {
822 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected interline\n"));
823 f << "###interline=" << val << ",";
824 }
825 val=int(input->readULong(1));
826 if (val && val<40)
827 para.m_spacings[1]=double(val)/72;
828 else {
829 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected paragraph spacing\n"));
830 f << "###para[spacing]=" << val << ",";
831 }
832 }
833 else {
834 input->seek(1, librevenge::RVNG_SEEK_CUR);
835 val=int(input->readULong(2));
836 if (val<100*100)
837 para.setInterline(float(val)/100, librevenge::RVNG_POINT, MWAWParagraph::AtLeast);
838 else if (val && val!=100*100) {
839 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected interline\n"));
840 f << "###interline=" << float(val)/100 << ",";
841 }
842 val=int(input->readULong(2));
843 if (val && val<40*100)
844 para.m_spacings[1]=double(val)/72/100;
845 else if (val && val!=65535) { // -1: means no set
846 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected paragraph spacing\n"));
847 f << "###para[spacing]=" << val << ",";
848 }
849 }
850 val=int(input->readULong(1));
851 switch (val & 7) {
852 case 1:
853 para.m_justify = MWAWParagraph::JustificationRight;
854 break;
855 case 2:
856 para.m_justify = MWAWParagraph::JustificationCenter;
857 break;
858 case 3:
859 para.m_justify = MWAWParagraph::JustificationFull;
860 break;
861 case 4:
862 para.m_justify = MWAWParagraph::JustificationFullAllLines;
863 break;
864 case 0: // left
865 break;
866 default:
867 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: unexpected justification\n"));
868 f << "###para[justify]=" << (val&7) << ",";
869 break;
870 }
871 if (val&0xf8) f << "fl1=" << std::hex << (val&0xf8) << std::dec << ",";
872 val=int(input->readLong(1));
873 if (val) f << "f0=" << val << ",";
874 if (vers<=4) {
875 val=int(input->readLong(1));
876 if (val) font.setDeltaLetterSpacing(float(val), librevenge::RVNG_POINT);
877 val=int(input->readLong(1));
878 if (val) font.set(MWAWFont::Script(-float(val), librevenge::RVNG_POINT));
879 }
880 else {
881 val=int(input->readLong(2));
882 if (val) font.set(MWAWFont::Script(-float(val)/100, librevenge::RVNG_POINT));
883 val=int(input->readLong(2));
884 if (val) font.setDeltaLetterSpacing(float(val)/100, librevenge::RVNG_POINT);
885 }
886 if (vers>=4) {
887 val=int(input->readULong(1));
888 if (val!=100)
889 f << "word[spacing]=" << val << "%,";
890 val=int(input->readULong(1));
891 if (val!=100) {
892 if (vers<=5) // checkme, there is no menu to set the horizontal scaling in 4.5
893 f << "f1=" << val << "%,";
894 else {
895 if (val<=500)
896 font.setWidthStreching(float(val)/100);
897 else {
898 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: find unexpected streching\n"));
899 f << "hor[scale]=###" << val << ",";
900 }
901 }
902 }
903 }
904 if (vers>=5) {
905 int col=int(input->readULong(2));
906 int tint=100;
907 if (vers>=6) {
908 val=int(input->readULong(2));
909 if (val!=1000)
910 f << "f1=" << val << ",";
911 tint=int(input->readULong(1));
912 if (tint!=100)
913 f << "tint=" << tint << "%,";
914 }
915 if (col>=0 && size_t(col)<m_state->m_colors.size()) {
916 if (tint>=0 && tint<=100)
917 font.setColor(MWAWColor::barycenter(1-float(tint)/100, MWAWColor::white(), float(tint)/100, m_state->m_colors[size_t(col)]));
918 else
919 font.setColor(m_state->m_colors[size_t(col)]);
920 }
921 else {
922 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readStyle: find unexpected paragraph color\n"));
923 f << "color=###" << col << ",";
924 }
925 // v6: last value is trapping *1000 but unsure is trapping
926 }
927 f << font.getDebugString(m_parser.getFontConverter()) << ",";
928 f << para << ",";
929
930 ascFile.addPos(pos);
931 ascFile.addNote(f.str().c_str());
932 if (input->tell()!=endPos)
933 ascFile.addDelimiter(input->tell(),'|');
934 input->seek(endPos, librevenge::RVNG_SEEK_SET);
935
936 return true;
937 }
938
939 bool ReadySetGoStyleManager::readTabulationsV1(std::vector<MWAWTabStop> &tabulations, std::string &extra)
940 {
941 tabulations.clear();
942 MWAWInputStreamPtr input = m_parser.getInput();
943 if (!input)
944 return false;
945 int const vers=version();
946 long pos=input->tell();
947 if (vers>=3) {
948 extra="###";
949 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulationsV1: unexpected version\n"));
950 return false;
951 }
952 long endPos=pos+(vers<=1 ? 40 : 32);
953 if (!input->checkPosition(endPos)) {
954 extra="###";
955 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulationsV1: bad length\n"));
956 return false;
957 }
958 libmwaw::DebugStream f;
959
960 MWAWTabStop tabs[5];
961 if (vers==1) {
962 for (int i=0; i<5; ++i) {
963 tabs[i].m_position=int(input->readLong(2));
964 tabs[i].m_position+=float(input->readLong(2))/10000;
965 if (tabs[i].m_position>0)
966 f << "tab" << i << "[pos]=" << tabs[i].m_position << ",";
967 }
968 }
969 else {
970 for (int i=0; i<5; ++i) tabs[i].m_position=int(input->readLong(2));
971 for (int i=0; i<5; ++i) {
972 tabs[i].m_position+=float(input->readLong(2))/10000;
973 if (tabs[i].m_position>0)
974 f << "tab" << i << "[pos]=" << tabs[i].m_position << ",";
975 }
976 }
977 bool tabOn[5];
978 for (int i=0; i<5; ++i) {
979 int val=int(input->readLong(vers<=1 ? 2 : 1));
980 tabOn[i]=val==1;
981 if (val==(vers==1 ? -1 : 0)) // off
982 continue;
983 if (val==1)
984 f << "tab" << i << "=on,";
985 else
986 f << "tab" << i << "[on]=" << val << ",";
987 }
988 if (vers==2)
989 input->seek(1, librevenge::RVNG_SEEK_CUR);
990 for (int i=0; i<5; ++i) {
991 int val=int(input->readLong(vers<=1 ? 2 : 1));
992 if (val==1) // left
993 continue;
994 if (val==(vers==1 ? -1 : 0)) {
995 tabs[i].m_alignment=MWAWTabStop::DECIMAL;
996 f << "tab" << i << "=decimal,";
997 }
998 else
999 f << "tab" << i << "[type]=" << val << ",";
1000 }
1001 if (vers==2)
1002 input->seek(1, librevenge::RVNG_SEEK_CUR);
1003
1004 for (int i=0; i<5; ++i) {
1005 if (tabOn[i])
1006 tabulations.push_back(tabs[i]);
1007 }
1008
1009 extra=f.str();
1010 return true;
1011 }
1012
1013 bool ReadySetGoStyleManager::readTabulations(std::vector<MWAWTabStop> &tabs, long len, int *cPos)
1014 {
1015 tabs.clear();
1016 MWAWInputStreamPtr input = m_parser.getInput();
1017 if (!input)
1018 return false;
1019 int const vers=version();
1020 long pos=input->tell();
1021 long endPos=pos+len;
1022 if (len<=0) {
1023 len=long(input->readLong(4));
1024 endPos=pos+4+len;
1025 }
1026 libmwaw::DebugStream f;
1027 libmwaw::DebugFile &ascFile=m_parser.ascii();
1028 f << "Tabs[list]:";
1029 if (vers<3) {
1030 f << "###";
1031 ascFile.addPos(pos);
1032 ascFile.addNote(f.str().c_str());
1033 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulations: unexpected version\n"));
1034 return false;
1035 }
1036 if (len<2+(len<=0 ? 4 : 0)+(cPos ? 4 : 0) || !input->checkPosition(endPos)) {
1037 f << "###";
1038 ascFile.addPos(pos);
1039 ascFile.addNote(f.str().c_str());
1040 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulations: bad length\n"));
1041 return false;
1042 }
1043 if (cPos) {
1044 *cPos=int(input->readLong(4));
1045 f << "pos[char]=" << *cPos << ",";
1046 }
1047 int N=int(input->readLong(2));
1048 f << "N=" << N << ",";
1049 int const dataSize=vers<=3 ? 10 : 14;
1050 if (N<0 || 2+(cPos ? 4 : 0) + dataSize*N > len) {
1051 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulations: can not read the number of tabs\n"));
1052 f << "###";
1053 N=0;
1054 }
1055 ascFile.addPos(pos);
1056 ascFile.addNote(f.str().c_str());
1057
1058 for (int i=0; i<N; ++i) {
1059 pos=input->tell();
1060 f.str("");
1061 f << "Tabs" << i << ":";
1062 MWAWTabStop tab;
1063 tab.m_position=float(input->readLong(4))/65536;
1064 f << "pos=" << tab.m_position << ",";
1065 int val=int(input->readLong(4));
1066 if (val)
1067 f << "measure=" << float(val)/65536 << ",";
1068 val=int(input->readLong(1));
1069 switch (val) {
1070 case 0: // left
1071 f << "left,";
1072 break;
1073 case 1:
1074 tab.m_alignment=MWAWTabStop::CENTER;
1075 f << "center,";
1076 break;
1077 case 2:
1078 tab.m_alignment=MWAWTabStop::RIGHT;
1079 f << "right,";
1080 break;
1081 case 3:
1082 tab.m_alignment=MWAWTabStop::DECIMAL;
1083 f << "decimal,";
1084 break;
1085 default:
1086 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulations: unknown tab's alignment\n"));
1087 f << "###align=" << val << ",";
1088 }
1089 val=int(input->readLong(1));
1090 if (val) {
1091 f << "on,";
1092 if (val!=1) {
1093 f << "leader=" << char(val) << ",";
1094 int unicode=m_parser.getFontConverter()->unicode(12,(unsigned char) val);
1095 if (unicode!=-1)
1096 tab.m_leaderCharacter=uint16_t(unicode);
1097 else if (val>0x1f && val<0x80)
1098 tab.m_leaderCharacter=uint16_t(unicode);
1099 else {
1100 f << "###";
1101 MWAW_DEBUG_MSG(("ReadySetGoStyleManager::readTabulations: unknown tab's leader character\n"));
1102 }
1103 }
1104 tabs.push_back(tab);
1105 }
1106 if (vers>3) {
1107 val=int(input->readLong(4));
1108 if (val)
1109 f << "decal[decimal]=" << float(val)/65536;
1110 }
1111 ascFile.addPos(pos);
1112 ascFile.addNote(f.str().c_str());
1113 }
1114
1115 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1116 return true;
1117 }
1118
1119
1120 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: