| 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 <array> |
| 35 |
#include <cmath> |
| 36 |
#include <iomanip> |
| 37 |
#include <iostream> |
| 38 |
#include <limits> |
| 39 |
#include <map> |
| 40 |
#include <set> |
| 41 |
#include <sstream> |
| 42 |
|
| 43 |
#include <librevenge/librevenge.h> |
| 44 |
|
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWFontConverter.hxx" |
| 47 |
#include "MWAWGraphicListener.hxx" |
| 48 |
#include "MWAWGraphicShape.hxx" |
| 49 |
#include "MWAWParagraph.hxx" |
| 50 |
#include "MWAWPictData.hxx" |
| 51 |
#include "MWAWPosition.hxx" |
| 52 |
#include "MWAWSubDocument.hxx" |
| 53 |
|
| 54 |
#include "ReadySetGoParser.hxx" |
| 55 |
#include "ReadySetGoStyleManager.hxx" |
| 56 |
|
| 57 |
#include "ReadySetGoGraph.hxx" |
| 58 |
|
| 59 |
/** Internal: the structures of a ReadySetGoGraph */ |
| 60 |
namespace ReadySetGoGraphInternal |
| 61 |
{ |
| 62 |
//////////////////////////////////////// |
| 63 |
//! Internal: a shape in a ReadySetGoGraph document |
| 64 |
struct Shape { |
| 65 |
//! the shape type |
| 66 |
enum Type { T_Empty, T_Line, T_Oval, T_Picture, T_Polygon, T_Rectangle, T_RectOval, T_Text, T_Unknown }; |
| 67 |
//! constructor |
| 68 |
explicit Shape(Type type) |
| 69 |
: m_type(type) |
| 70 |
, m_box() |
| 71 |
, m_rotate(0) |
| 72 |
, m_style(MWAWGraphicStyle::emptyStyle()) |
| 73 |
, m_groupId(0) |
| 74 |
, m_wrapRoundAround(false) |
| 75 |
, m_cornerSize(-1,-1) |
| 76 |
, m_vertices() |
| 77 |
, m_textId(-1) |
| 78 |
, m_paragraph() |
| 79 |
, m_hasPicture(false) |
| 80 |
{ |
| 81 |
for (auto &link : m_linkIds) link=-1; |
| 82 |
for (auto &cPos : m_textPositions) cPos=-1; |
| 83 |
} |
| 84 |
|
| 85 |
//! the shape type |
| 86 |
Type m_type; |
| 87 |
//! the bounding box |
| 88 |
MWAWBox2f m_box; |
| 89 |
//! the shape rotation: v6 |
| 90 |
int m_rotate; |
| 91 |
//! the graphic style |
| 92 |
MWAWGraphicStyle m_style; |
| 93 |
//! the group id: v6 |
| 94 |
int m_groupId; // FIXME: useme |
| 95 |
//! the round around wraping flag |
| 96 |
bool m_wrapRoundAround; |
| 97 |
//! the line points |
| 98 |
MWAWVec2f m_points[2]; |
| 99 |
//! the corner size: rectangle oval |
| 100 |
MWAWVec2i m_cornerSize; |
| 101 |
//! the list of vertices : polygon |
| 102 |
std::vector<MWAWVec2f> m_vertices; |
| 103 |
|
| 104 |
//! the text limits: v4 |
| 105 |
int m_textPositions[2]; |
| 106 |
//! the text link id |
| 107 |
int m_textId; |
| 108 |
//! the text links: prev/next |
| 109 |
int m_linkIds[2]; |
| 110 |
//! the paragraph style |
| 111 |
MWAWParagraph m_paragraph; |
| 112 |
|
| 113 |
//! a flag to know if a picture is empty or not |
| 114 |
bool m_hasPicture; |
| 115 |
|
| 116 |
//! the zone entries: picture or text zones |
| 117 |
MWAWEntry m_entries[3]; |
| 118 |
}; |
| 119 |
|
| 120 |
//////////////////////////////////////// |
| 121 |
//! Internal: a layout in a ReadySetGoGraph document |
| 122 |
struct Layout { |
| 123 |
//! constructor |
| 124 |
Layout() |
| 125 |
: m_useMasterPage(true) |
| 126 |
, m_masterId(0) |
| 127 |
, m_shapes() |
| 128 |
{ |
| 129 |
} |
| 130 |
|
| 131 |
//! a flag to know if we use or not the master page |
| 132 |
bool m_useMasterPage; |
| 133 |
//! the master id: v6 |
| 134 |
int m_masterId; |
| 135 |
//! a map id to shape |
| 136 |
std::vector<Shape> m_shapes; |
| 137 |
}; |
| 138 |
|
| 139 |
//////////////////////////////////////// |
| 140 |
//! Internal: the state of a ReadySetGoGraph |
| 141 |
struct State { |
| 142 |
//! constructor |
| 143 |
State() |
| 144 |
: m_version(-1) |
| 145 |
, m_layouts() |
| 146 |
, m_masterLayouts() |
| 147 |
{ |
| 148 |
} |
| 149 |
|
| 150 |
//! the file version |
| 151 |
int m_version; |
| 152 |
//! the list of layout (one by potential master + page) |
| 153 |
std::vector<Layout> m_layouts; |
| 154 |
//! the list of master layouts: v6 |
| 155 |
std::vector<Layout> m_masterLayouts; |
| 156 |
}; |
| 157 |
|
| 158 |
//////////////////////////////////////// |
| 159 |
//! Internal: the subdocument of a ReadySetGoGraph |
| 160 |
class SubDocument final : public MWAWSubDocument |
| 161 |
{ |
| 162 |
public: |
| 163 |
SubDocument(ReadySetGoGraph &pars, MWAWInputStreamPtr const &input, Shape const &shape) |
| 164 |
: MWAWSubDocument(&pars.m_parser, input, MWAWEntry()) |
| 165 |
, m_graphParser(&pars) |
| 166 |
, m_shape(&shape) |
| 167 |
{ |
| 168 |
} |
| 169 |
|
| 170 |
//! destructor |
| 171 |
~SubDocument() final {} |
| 172 |
|
| 173 |
//! operator!= |
| 174 |
bool operator!=(MWAWSubDocument const &doc) const final |
| 175 |
{ |
| 176 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 177 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 178 |
if (!sDoc) return true; |
| 179 |
if (m_graphParser != sDoc->m_graphParser) return true; |
| 180 |
if (m_shape != sDoc->m_shape) return true; |
| 181 |
return false; |
| 182 |
} |
| 183 |
|
| 184 |
//! the parser function |
| 185 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 186 |
|
| 187 |
protected: |
| 188 |
/** the graph parser */ |
| 189 |
ReadySetGoGraph *m_graphParser; |
| 190 |
//! the text shape |
| 191 |
Shape const *m_shape; |
| 192 |
private: |
| 193 |
SubDocument(SubDocument const &orig) = delete; |
| 194 |
SubDocument &operator=(SubDocument const &orig) = delete; |
| 195 |
}; |
| 196 |
|
| 197 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
| 198 |
{ |
| 199 |
if (!listener || !listener->canWriteText()) { |
| 200 |
MWAW_DEBUG_MSG(("ReadySetGoParserInternal::SubDocument::parse: no listener\n")); |
| 201 |
return; |
| 202 |
} |
| 203 |
if (!m_graphParser || !m_shape) { |
| 204 |
MWAW_DEBUG_MSG(("ReadySetGoParserInternal::SubDocument::parse: no parser\n")); |
| 205 |
return; |
| 206 |
} |
| 207 |
long pos = m_input->tell(); |
| 208 |
m_graphParser->sendText(*m_shape); |
| 209 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 210 |
} |
| 211 |
|
| 212 |
} |
| 213 |
|
| 214 |
//////////////////////////////////////////////////////////// |
| 215 |
// constructor/destructor, ... |
| 216 |
//////////////////////////////////////////////////////////// |
| 217 |
ReadySetGoGraph::ReadySetGoGraph(ReadySetGoParser &parser) |
| 218 |
: m_state(new ReadySetGoGraphInternal::State) |
| 219 |
, m_parser(parser) |
| 220 |
, m_styleManager(parser.m_styleManager) |
| 221 |
{ |
| 222 |
} |
| 223 |
|
| 224 |
ReadySetGoGraph::~ReadySetGoGraph() |
| 225 |
{ |
| 226 |
} |
| 227 |
|
| 228 |
int ReadySetGoGraph::version() const |
| 229 |
{ |
| 230 |
if (m_state->m_version==-1) |
| 231 |
m_state->m_version=m_parser.version(); |
| 232 |
return m_state->m_version; |
| 233 |
} |
| 234 |
|
| 235 |
void ReadySetGoGraph::updatePageSpanList(std::vector<MWAWPageSpan> &spanList) const |
| 236 |
{ |
| 237 |
// create the page list |
| 238 |
int const vers=version(); |
| 239 |
int num=int(m_state->m_layouts.size()); |
| 240 |
if (vers>=3) |
| 241 |
num=std::max<int>(0,num-2); |
| 242 |
if (vers<3) { |
| 243 |
MWAWPageSpan ps(m_parser.getPageSpan()); |
| 244 |
ps.setPageSpan(std::max<int>(1,num)); |
| 245 |
spanList.push_back(ps); |
| 246 |
} |
| 247 |
else { |
| 248 |
bool const sharedList=vers<6 || (vers==6 && m_parser.isDesignStudioFile()); |
| 249 |
std::vector<std::array<bool,2> > hasMasters; |
| 250 |
size_t numMasters=!sharedList ? (m_state->m_masterLayouts.size()+1)/2 : 1; |
| 251 |
hasMasters.resize(numMasters); |
| 252 |
for (auto &hasMaster : hasMasters) hasMaster= {{false, false}}; |
| 253 |
if (sharedList) { |
| 254 |
for (size_t i=0; i<2; ++i) |
| 255 |
hasMasters[0][i]=!m_state->m_layouts[i].m_shapes.empty(); |
| 256 |
} |
| 257 |
else { |
| 258 |
for (size_t i=0; i<m_state->m_masterLayouts.size(); ++i) |
| 259 |
hasMasters[i/2][i%2] =!m_state->m_masterLayouts[i].m_shapes.empty(); |
| 260 |
} |
| 261 |
for (size_t i=(sharedList ? 2 : 0); i<m_state->m_layouts.size(); ++i) { |
| 262 |
auto const &layout=m_state->m_layouts[i]; |
| 263 |
MWAWPageSpan ps(m_parser.getPageSpan()); |
| 264 |
ps.setPageSpan(1); |
| 265 |
int whichMaster= !sharedList ? layout.m_masterId : 0; |
| 266 |
if (layout.m_useMasterPage && whichMaster>=0 && whichMaster<int(hasMasters.size()) && hasMasters[size_t(whichMaster)][(i+1)%2]) { |
| 267 |
librevenge::RVNGString name; |
| 268 |
name.sprintf("MasterPage%d", 2*whichMaster+int((i+1)%2)); |
| 269 |
ps.setMasterPageName(name); |
| 270 |
} |
| 271 |
spanList.push_back(ps); |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
bool ReadySetGoGraph::updateTextBoxLinks() |
| 277 |
{ |
| 278 |
int const vers=version(); |
| 279 |
if (vers<=2) |
| 280 |
return true; |
| 281 |
std::map<int, ReadySetGoGraphInternal::Shape *> idToShapeMap; |
| 282 |
std::map<int, int> idToLinkIdsMap[2]; |
| 283 |
for (int st=0; st<2; ++st) { |
| 284 |
auto &layouts = st==0 ? m_state->m_layouts : m_state->m_masterLayouts; |
| 285 |
for (auto &layout : layouts) { |
| 286 |
for (auto &shape : layout.m_shapes) { |
| 287 |
if (shape.m_linkIds[0]<0 && shape.m_linkIds[1]<0) |
| 288 |
continue; |
| 289 |
if (idToShapeMap.find(shape.m_textId)!=idToShapeMap.end()) { |
| 290 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks: find dupplicated text id=%d\n", shape.m_textId)); |
| 291 |
return false; |
| 292 |
} |
| 293 |
idToShapeMap[shape.m_textId]=&shape; |
| 294 |
for (int i=0; i<2; ++i) { |
| 295 |
if (shape.m_linkIds[i]<0) continue; |
| 296 |
if (idToLinkIdsMap[i].find(shape.m_linkIds[i])!=idToLinkIdsMap[i].end()) { |
| 297 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks[%d]: find dupplicated text id=%d\n", i, shape.m_linkIds[i])); |
| 298 |
return false; |
| 299 |
} |
| 300 |
idToLinkIdsMap[i][shape.m_linkIds[i]]=shape.m_textId; |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
// check that the link are coherent, ie. for each link, there exists a reciprocal link |
| 307 |
for (auto st=0; st<2; ++st) { |
| 308 |
std::set<int> badIds; |
| 309 |
for (auto const &it : idToLinkIdsMap[st]) { |
| 310 |
auto rIt=idToLinkIdsMap[1-st].find(it.second); |
| 311 |
if (rIt==idToLinkIdsMap[1-st].end() || rIt->second!=it.first) { |
| 312 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks: find no reciprocal link for link=%d-%d\n", it.first, it.second)); |
| 313 |
badIds.insert(it.first); |
| 314 |
} |
| 315 |
} |
| 316 |
for (auto bad : badIds) |
| 317 |
idToLinkIdsMap[st].erase(bad); |
| 318 |
} |
| 319 |
|
| 320 |
// check that there is no loop: following next path |
| 321 |
for (auto const &iIt : idToShapeMap) { |
| 322 |
std::set<int> ids; |
| 323 |
int id=iIt.first, firstId=id; |
| 324 |
bool ok=true; |
| 325 |
while (true) { |
| 326 |
if (ids.find(id)!=ids.end()) { |
| 327 |
ok=false; |
| 328 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks: find a loop for link id=%d\n", id)); |
| 329 |
break; |
| 330 |
} |
| 331 |
ids.insert(id); |
| 332 |
auto const &nextIt=idToLinkIdsMap[1].find(id); |
| 333 |
if (nextIt==idToLinkIdsMap[1].end()) |
| 334 |
break; |
| 335 |
id=nextIt->second; |
| 336 |
} |
| 337 |
if (ok) continue; |
| 338 |
// ok: remove this loop |
| 339 |
id=firstId; |
| 340 |
while (true) { |
| 341 |
auto const &nextIt=idToLinkIdsMap[1].find(id); |
| 342 |
if (nextIt==idToLinkIdsMap[1].end()) |
| 343 |
break; |
| 344 |
int nextId=nextIt->second; |
| 345 |
idToLinkIdsMap[1].erase(id); |
| 346 |
idToLinkIdsMap[0].erase(nextId); |
| 347 |
id=nextId; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
if (vers<4) { |
| 352 |
// update the shape's style name |
| 353 |
for (auto const &iIt : idToShapeMap) { |
| 354 |
auto &shape=*iIt.second; |
| 355 |
int prevId=shape.m_linkIds[0]; |
| 356 |
if (prevId>=0 && idToLinkIdsMap[0].find(prevId)!=idToLinkIdsMap[0].end()) { |
| 357 |
std::stringstream s; |
| 358 |
s << "Frame" << iIt.first; |
| 359 |
shape.m_style.m_frameName=s.str(); |
| 360 |
} |
| 361 |
int nextId=shape.m_linkIds[1]; |
| 362 |
if (nextId>=0 && idToLinkIdsMap[1].find(nextId)!=idToLinkIdsMap[1].end()) { |
| 363 |
std::stringstream s; |
| 364 |
s << "Frame" << nextId; |
| 365 |
shape.m_style.m_frameNextName=s.str(); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
else { |
| 370 |
for (auto const &iIt : idToShapeMap) { |
| 371 |
auto &shape=*iIt.second; |
| 372 |
if (shape.m_linkIds[0]>=0 || shape.m_linkIds[1]<0) continue; |
| 373 |
// shape is the first node of a loop |
| 374 |
int nextId=shape.m_linkIds[1]; |
| 375 |
auto *currentShape=&shape; |
| 376 |
while (nextId>=0) { |
| 377 |
if (idToLinkIdsMap[1].find(nextId)==idToLinkIdsMap[1].end()) // the link has been cutted |
| 378 |
break; |
| 379 |
auto nextShapeIt=idToShapeMap.find(nextId); |
| 380 |
if (nextShapeIt==idToShapeMap.end()) { |
| 381 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks: can not find shape corresponding to id=%d\n", nextId)); |
| 382 |
break; |
| 383 |
} |
| 384 |
auto *nextShape=nextShapeIt->second; |
| 385 |
for (int l=0; l<3; ++l) // update the shape entries |
| 386 |
nextShape->m_entries[l]=shape.m_entries[l]; |
| 387 |
nextId=nextShape->m_linkIds[1]; |
| 388 |
if (currentShape->m_textPositions[1]>=nextShape->m_textPositions[0]-1) |
| 389 |
currentShape->m_textPositions[1]=std::max(0,nextShape->m_textPositions[0]-1); |
| 390 |
else if (currentShape->m_textPositions[1]<nextShape->m_textPositions[0]-10) { // a difference of 2 characters seems ok |
| 391 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::updateTextBoxLinks: can not update the text limits\n")); |
| 392 |
} |
| 393 |
currentShape=nextShape; |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
return true; |
| 398 |
} |
| 399 |
|
| 400 |
//////////////////////////////////////////////////////////// |
| 401 |
// |
| 402 |
// Intermediate level |
| 403 |
// |
| 404 |
//////////////////////////////////////////////////////////// |
| 405 |
bool ReadySetGoGraph::readLayoutsList(int numLayouts, bool master) |
| 406 |
{ |
| 407 |
int const vers=version(); |
| 408 |
if (vers<3) { |
| 409 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readLayoutsList: unexpected version\n")); |
| 410 |
return false; |
| 411 |
} |
| 412 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 413 |
if (!input) |
| 414 |
return false; |
| 415 |
long pos=input->tell(); |
| 416 |
if (!input->checkPosition(pos+4)) { |
| 417 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readLayoutsList: can not read the zone length\n")); |
| 418 |
return false; |
| 419 |
} |
| 420 |
libmwaw::DebugFile &ascFile = m_parser.ascii(); |
| 421 |
libmwaw::DebugStream f; |
| 422 |
bool const designStudio=m_parser.isDesignStudioFile(); |
| 423 |
f << "Entries(Layout):"; |
| 424 |
long len=long(input->readLong(4)); |
| 425 |
long endPos=pos+4+len; |
| 426 |
int const dataSize=vers==3 ? 10 : vers==4 ? 14 : vers==5 ? 136 : (designStudio ? 210 : 212); |
| 427 |
if (len<0 || len/dataSize<numLayouts || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 428 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readLayoutsList: can not read the zone length\n")); |
| 429 |
f << "###"; |
| 430 |
ascFile.addPos(pos); |
| 431 |
ascFile.addNote(f.str().c_str()); |
| 432 |
return false; |
| 433 |
} |
| 434 |
f << "N=" << numLayouts << ","; |
| 435 |
ascFile.addPos(pos); |
| 436 |
ascFile.addNote(f.str().c_str()); |
| 437 |
std::vector<ReadySetGoGraphInternal::Layout> &layouts= master ? m_state->m_masterLayouts : m_state->m_layouts; |
| 438 |
for (int l=0; l<numLayouts; ++l) { // LR,1:R,2:L,... |
| 439 |
pos=input->tell(); |
| 440 |
f.str(""); |
| 441 |
f << "Layout-" << (master ? "M" : "L") << l << ":"; |
| 442 |
layouts.push_back(ReadySetGoGraphInternal::Layout()); |
| 443 |
auto &layout=layouts.back(); |
| 444 |
if (vers==3) { |
| 445 |
for (int i=0; i<2; ++i) { // f0=0 or 8(rare) |
| 446 |
int val=int(input->readLong(2)); |
| 447 |
if (val) |
| 448 |
f << "f" << i << "=" << val << ","; |
| 449 |
} |
| 450 |
} |
| 451 |
else { |
| 452 |
int dim[4]; |
| 453 |
for (auto &d : dim) d=int(input->readLong(2)); |
| 454 |
if (dim[2]!=dim[0] || dim[3]!=dim[1]) |
| 455 |
f << "box?=" << MWAWBox2i(MWAWVec2i(dim[0],dim[1]), MWAWVec2i(dim[2],dim[3])) << ","; |
| 456 |
} |
| 457 |
int val=int(input->readULong(4)); |
| 458 |
if (val) |
| 459 |
f << "ID=" << std::hex << val << std::dec << ","; // last shape id in layout? |
| 460 |
val=int(input->readULong(2)); // 1|3 |
| 461 |
if ((val&1)==0) { |
| 462 |
f << "use[master]=false,"; |
| 463 |
layout.m_useMasterPage=false; |
| 464 |
} |
| 465 |
val &= 0xfffe; |
| 466 |
if (val) |
| 467 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 468 |
if (vers>=6 && !designStudio) { |
| 469 |
ascFile.addDelimiter(input->tell(),'|'); |
| 470 |
input->seek(pos+210, librevenge::RVNG_SEEK_SET); |
| 471 |
ascFile.addDelimiter(input->tell(),'|'); |
| 472 |
layout.m_masterId=int(input->readULong(2)); |
| 473 |
if (layout.m_masterId) |
| 474 |
f << "master=" << layout.m_masterId << ","; |
| 475 |
} |
| 476 |
if (input->tell()!=pos+dataSize) |
| 477 |
ascFile.addDelimiter(input->tell(),'|'); |
| 478 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 479 |
ascFile.addPos(pos); |
| 480 |
ascFile.addNote(f.str().c_str()); |
| 481 |
} |
| 482 |
|
| 483 |
if (input->tell()!=endPos) { |
| 484 |
if (!master) { |
| 485 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readLayoutsList: find extra data\n")); |
| 486 |
ascFile.addPos(input->tell()); |
| 487 |
ascFile.addNote("Layout-extra:###"); |
| 488 |
} |
| 489 |
else { |
| 490 |
ascFile.addPos(input->tell()); |
| 491 |
ascFile.addNote("_"); |
| 492 |
} |
| 493 |
} |
| 494 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 495 |
return true; |
| 496 |
} |
| 497 |
|
| 498 |
bool ReadySetGoGraph::readShapes() |
| 499 |
{ |
| 500 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 501 |
if (!input) |
| 502 |
return false; |
| 503 |
long pos=input->tell(); |
| 504 |
|
| 505 |
int const vers=version(); |
| 506 |
libmwaw::DebugFile &ascFile = m_parser.ascii(); |
| 507 |
libmwaw::DebugStream f; |
| 508 |
if (vers<=2) { |
| 509 |
f << "Entries(Pages):"; |
| 510 |
if (!input->checkPosition(pos+2)) { |
| 511 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapes: the zone seems too short\n")); |
| 512 |
f << "###"; |
| 513 |
ascFile.addPos(pos); |
| 514 |
ascFile.addNote(f.str().c_str()); |
| 515 |
return false; |
| 516 |
} |
| 517 |
int numPages=1; |
| 518 |
if (vers==2) { |
| 519 |
numPages=int(input->readULong(2)); |
| 520 |
if (!input->checkPosition(pos+2+2*numPages)) { |
| 521 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapes: the zone seems too short\n")); |
| 522 |
f << "###N=" << numPages << ","; |
| 523 |
ascFile.addPos(pos); |
| 524 |
ascFile.addNote(f.str().c_str()); |
| 525 |
return false; |
| 526 |
} |
| 527 |
ascFile.addPos(pos); |
| 528 |
ascFile.addNote(f.str().c_str()); |
| 529 |
} |
| 530 |
std::vector<int> numShapesByPage; |
| 531 |
f << "N=["; |
| 532 |
for (int i=0; i<numPages; ++i) { |
| 533 |
numShapesByPage.push_back(int(input->readULong(2))); |
| 534 |
f << numShapesByPage.back(); |
| 535 |
} |
| 536 |
f << "],"; |
| 537 |
ascFile.addPos(pos); |
| 538 |
ascFile.addNote(f.str().c_str()); |
| 539 |
|
| 540 |
for (size_t p=0; p<size_t(numPages); ++p) { |
| 541 |
m_state->m_layouts.push_back(ReadySetGoGraphInternal::Layout()); |
| 542 |
auto &layout=m_state->m_layouts.back(); |
| 543 |
for (int sh=0; sh<numShapesByPage[p]; ++sh) { |
| 544 |
pos=input->tell(); |
| 545 |
if (vers==1) { |
| 546 |
if (readShapeV1() && !layout.m_shapes.empty() && |
| 547 |
(layout.m_shapes.back().m_type!=ReadySetGoGraphInternal::Shape::T_Empty || sh+1==numShapesByPage[p])) |
| 548 |
continue; |
| 549 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapes: can not read a shape\n")); |
| 550 |
ascFile.addPos(pos); |
| 551 |
ascFile.addNote("Entries(BadShape):###"); |
| 552 |
return false; |
| 553 |
} |
| 554 |
else if (!readShapeV2(layout)) |
| 555 |
return false; |
| 556 |
} |
| 557 |
} |
| 558 |
return true; |
| 559 |
} |
| 560 |
|
| 561 |
// Design Studio v2 |
| 562 |
if (m_parser.isDesignStudioFile()) { |
| 563 |
for (auto &layout : m_state->m_layouts) { |
| 564 |
while (!input->isEnd()) { |
| 565 |
bool last; |
| 566 |
if (!readShapeDSV2(layout, last)) |
| 567 |
return false; |
| 568 |
if (last) |
| 569 |
break; |
| 570 |
} |
| 571 |
} |
| 572 |
updateTextBoxLinks(); |
| 573 |
return true; |
| 574 |
} |
| 575 |
// v3, v4, v4.5 |
| 576 |
if (vers<=5) { |
| 577 |
for (auto &layout : m_state->m_layouts) { |
| 578 |
while (!input->isEnd()) { |
| 579 |
bool last; |
| 580 |
if (!readShapeV3(layout, last)) |
| 581 |
return false; |
| 582 |
if (last) |
| 583 |
break; |
| 584 |
} |
| 585 |
} |
| 586 |
updateTextBoxLinks(); |
| 587 |
return true; |
| 588 |
} |
| 589 |
// v6 |
| 590 |
// normally two layouts by master labelled from 'A'-'Z' |
| 591 |
for (size_t i=0; i<m_state->m_masterLayouts.size(); ++i) { |
| 592 |
while (!input->isEnd()) { |
| 593 |
bool last; |
| 594 |
if (!readShapeV6(m_state->m_masterLayouts[i], last)) |
| 595 |
return false; |
| 596 |
if (last) |
| 597 |
break; |
| 598 |
} |
| 599 |
} |
| 600 |
// followed by num layouts-2, |
| 601 |
// I supposed that layouts 0 and 1 remain only to be "coherent" with v4.5 format |
| 602 |
for (size_t i=2; i<m_state->m_layouts.size(); ++i) { |
| 603 |
while (!input->isEnd()) { |
| 604 |
bool last; |
| 605 |
if (!readShapeV6(m_state->m_layouts[i], last)) |
| 606 |
return false; |
| 607 |
if (last) |
| 608 |
break; |
| 609 |
} |
| 610 |
} |
| 611 |
updateTextBoxLinks(); |
| 612 |
return true; |
| 613 |
} |
| 614 |
|
| 615 |
bool ReadySetGoGraph::readShapesInObject() |
| 616 |
{ |
| 617 |
if (version()<6) { |
| 618 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapesInObject: unexpected version\n")); |
| 619 |
return false; |
| 620 |
} |
| 621 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 622 |
if (!input) |
| 623 |
return false; |
| 624 |
ReadySetGoGraphInternal::Layout dummy; |
| 625 |
if (m_parser.isDesignStudioFile()) { |
| 626 |
while (!input->isEnd()) { |
| 627 |
bool last; |
| 628 |
if (!readShapeDSV2(dummy, last)) |
| 629 |
return false; |
| 630 |
if (last) |
| 631 |
break; |
| 632 |
} |
| 633 |
} |
| 634 |
else { |
| 635 |
while (!input->isEnd()) { |
| 636 |
bool last; |
| 637 |
if (!readShapeV6(dummy, last)) |
| 638 |
return false; |
| 639 |
if (last) |
| 640 |
break; |
| 641 |
} |
| 642 |
} |
| 643 |
return true; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
//////////////////////////////////////////////////////////// |
| 648 |
// low level |
| 649 |
//////////////////////////////////////////////////////////// |
| 650 |
bool ReadySetGoGraph::readShapeV1() |
| 651 |
{ |
| 652 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 653 |
if (!input) |
| 654 |
return false; |
| 655 |
long pos=input->tell(); |
| 656 |
if (!input->checkPosition(pos+26)) { |
| 657 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: can not read a shape\n")); |
| 658 |
return false; |
| 659 |
} |
| 660 |
if (m_state->m_layouts.empty()) { |
| 661 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: oops, must create a new layout\n")); |
| 662 |
m_state->m_layouts.resize(1); |
| 663 |
} |
| 664 |
int type=int(input->readULong(2)); |
| 665 |
|
| 666 |
static char const *wh[]= {"EndZone", "Text", nullptr, "Frame", "Solid", "Picture"}; |
| 667 |
if (type<0 || type==2 || type>5) { |
| 668 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: unknown type\n")); |
| 669 |
return false; |
| 670 |
} |
| 671 |
libmwaw::DebugFile &ascFile = m_parser.ascii(); |
| 672 |
libmwaw::DebugStream f; |
| 673 |
if (wh[type]) |
| 674 |
f << "Entries(" << wh[type] << "):"; |
| 675 |
else |
| 676 |
f << "Entries(Zone" << type << "):"; |
| 677 |
int const expectedSize[]= {26, 74, 0, 30, 28, 28}; |
| 678 |
if (expectedSize[type]<=0 || !input->checkPosition(pos+expectedSize[type])) { |
| 679 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: the zone seems too short for a shape\n")); |
| 680 |
f << "###"; |
| 681 |
ascFile.addPos(pos); |
| 682 |
ascFile.addNote(f.str().c_str()); |
| 683 |
return false; |
| 684 |
} |
| 685 |
static ReadySetGoGraphInternal::Shape::Type const shapeTypes[]= { |
| 686 |
ReadySetGoGraphInternal::Shape::T_Empty, |
| 687 |
ReadySetGoGraphInternal::Shape::T_Text, |
| 688 |
ReadySetGoGraphInternal::Shape::T_Unknown, |
| 689 |
ReadySetGoGraphInternal::Shape::T_Rectangle, // frame |
| 690 |
ReadySetGoGraphInternal::Shape::T_Rectangle, // solid |
| 691 |
ReadySetGoGraphInternal::Shape::T_Picture |
| 692 |
}; |
| 693 |
ReadySetGoGraphInternal::Shape shape(shapeTypes[type]); |
| 694 |
float dim[4]; |
| 695 |
for (auto &d : dim) d=float(input->readLong(2)); |
| 696 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])); |
| 697 |
f << "box=" << shape.m_box << ","; |
| 698 |
if (type!=0) { |
| 699 |
for (auto &d : dim) { |
| 700 |
d=float(input->readLong(2)); |
| 701 |
d+=float(input->readLong(2))/10000; |
| 702 |
} |
| 703 |
f << "box[inch]=" << MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])) << ","; |
| 704 |
int val; |
| 705 |
if (type==3) { |
| 706 |
val=int(input->readLong(2)); |
| 707 |
if (val<0 || val>100) { |
| 708 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: the frame size seems bad\n")); |
| 709 |
f << "###"; |
| 710 |
} |
| 711 |
else |
| 712 |
shape.m_style.m_lineWidth=float(val); |
| 713 |
if (val!=1) |
| 714 |
f << "frame[size]=" << val << ","; |
| 715 |
} |
| 716 |
if (type==5) { |
| 717 |
val=int(input->readLong(2)); |
| 718 |
shape.m_hasPicture=val!=0; |
| 719 |
if (val==0) |
| 720 |
f <<"noPict,"; |
| 721 |
else if (val!=1) |
| 722 |
f << "###pict=" << val << ","; |
| 723 |
} |
| 724 |
else if (type!=1) { |
| 725 |
val=int(input->readLong(2)); |
| 726 |
if (val<0 || val>4) { |
| 727 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: the color id seems bad\n")); |
| 728 |
f << "###col=" << val << ","; |
| 729 |
} |
| 730 |
else { |
| 731 |
uint8_t grey=uint8_t(val==0 ? 255 : 32*val); |
| 732 |
if (type==3) |
| 733 |
shape.m_style.m_lineColor=MWAWColor(grey,grey,grey); |
| 734 |
else |
| 735 |
shape.m_style.setSurfaceColor(MWAWColor(grey,grey,grey)); |
| 736 |
f << "color=" << val << ","; // 0: none, 1: black, 2: grey1, .., 4: light grey |
| 737 |
} |
| 738 |
} |
| 739 |
else { |
| 740 |
shape.m_paragraph.m_marginsUnit=librevenge::RVNG_INCH; |
| 741 |
for (int i=0; i<2; ++i) { // 0 |
| 742 |
val=int(input->readLong(2)); |
| 743 |
shape.m_paragraph.m_margins[1-i]=float(val)+float(input->readULong(2))/10000; |
| 744 |
if (*shape.m_paragraph.m_margins[1-i]>0) f << (i==0 ? "para" : "left") << "[indent]=" << *shape.m_paragraph.m_margins[1-i] << ","; |
| 745 |
} |
| 746 |
shape.m_paragraph.m_margins[0]=*shape.m_paragraph.m_margins[0]-*shape.m_paragraph.m_margins[1]; |
| 747 |
std::string extra; |
| 748 |
m_styleManager->readTabulationsV1(*shape.m_paragraph.m_tabs, extra); |
| 749 |
f << extra; |
| 750 |
} |
| 751 |
} |
| 752 |
if (input->tell()!=pos+expectedSize[type]) { |
| 753 |
ascFile.addDelimiter(input->tell(),'|'); |
| 754 |
input->seek(pos+expectedSize[type], librevenge::RVNG_SEEK_SET); |
| 755 |
} |
| 756 |
ascFile.addPos(pos); |
| 757 |
ascFile.addNote(f.str().c_str()); |
| 758 |
if (type!=1 && (type!=5 || !shape.m_hasPicture)) { |
| 759 |
m_state->m_layouts[0].m_shapes.push_back(shape); |
| 760 |
return true; |
| 761 |
} |
| 762 |
// before size zone0+zone1 |
| 763 |
for (int st=0; st<2; ++st) { // zone1=[text, style], zone2=[para] |
| 764 |
pos=input->tell(); |
| 765 |
f.str(""); |
| 766 |
if (type==1) |
| 767 |
f << "Text-" << (st==0 ? "char" : "para") << ":"; |
| 768 |
else |
| 769 |
f << "Picture:"; |
| 770 |
int len=int(input->readULong(2)); |
| 771 |
if (!input->checkPosition(pos+2+len)) { |
| 772 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV1: the zone seems too short for a text sub zone\n")); |
| 773 |
f << "###"; |
| 774 |
ascFile.addPos(pos); |
| 775 |
ascFile.addNote(f.str().c_str()); |
| 776 |
return false; |
| 777 |
} |
| 778 |
shape.m_entries[st].setBegin(pos+2); |
| 779 |
shape.m_entries[st].setLength(len); |
| 780 |
ascFile.addPos(pos); |
| 781 |
ascFile.addNote(f.str().c_str()); |
| 782 |
input->seek(pos+2+len+(len%2), librevenge::RVNG_SEEK_SET); |
| 783 |
if (type==5) |
| 784 |
break; |
| 785 |
} |
| 786 |
|
| 787 |
m_state->m_layouts[0].m_shapes.push_back(shape); |
| 788 |
return true; |
| 789 |
} |
| 790 |
|
| 791 |
bool ReadySetGoGraph::readShapeV2(ReadySetGoGraphInternal::Layout &layout) |
| 792 |
{ |
| 793 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 794 |
if (!input) |
| 795 |
return false; |
| 796 |
|
| 797 |
long pos=input->tell(); |
| 798 |
if (!input->checkPosition(pos+8)) { |
| 799 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: can not read a shape\n")); |
| 800 |
return false; |
| 801 |
} |
| 802 |
int type=int(input->readULong(2)); |
| 803 |
int id=int(input->readULong(2)); |
| 804 |
libmwaw::DebugFile &ascFile = m_parser.ascii(); |
| 805 |
libmwaw::DebugStream f; |
| 806 |
if (type<0 || type>6) { |
| 807 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: find bad type=%d\n", type)); |
| 808 |
f << "Entries(Zone" << type << ")[S" << id << "]:###"; |
| 809 |
ascFile.addPos(pos); |
| 810 |
ascFile.addNote(f.str().c_str()); |
| 811 |
return false; |
| 812 |
} |
| 813 |
char const *wh[]= { nullptr, "Solid", "Frame", "Picture", "Text", nullptr, nullptr }; |
| 814 |
std::string what; |
| 815 |
if (wh[type]) |
| 816 |
what=wh[type]; |
| 817 |
else { |
| 818 |
std::stringstream s; |
| 819 |
s << "Zone" << type; |
| 820 |
what=s.str(); |
| 821 |
} |
| 822 |
f << "Entries(" << what << ")[S" << id << "]:"; |
| 823 |
static ReadySetGoGraphInternal::Shape::Type const shapeTypes[]= { |
| 824 |
ReadySetGoGraphInternal::Shape::T_Unknown, |
| 825 |
ReadySetGoGraphInternal::Shape::T_Rectangle, // solid |
| 826 |
ReadySetGoGraphInternal::Shape::T_Rectangle, // frame |
| 827 |
ReadySetGoGraphInternal::Shape::T_Picture, |
| 828 |
ReadySetGoGraphInternal::Shape::T_Text, |
| 829 |
ReadySetGoGraphInternal::Shape::T_Unknown, |
| 830 |
ReadySetGoGraphInternal::Shape::T_Unknown |
| 831 |
}; |
| 832 |
ReadySetGoGraphInternal::Shape shape(shapeTypes[type]); |
| 833 |
int len=int(input->readULong(2)); |
| 834 |
if (len<0x1c || !input->checkPosition(pos+6+len)) { |
| 835 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: find unexpected size for generic data block\n")); |
| 836 |
f << "###"; |
| 837 |
ascFile.addPos(pos); |
| 838 |
ascFile.addNote(f.str().c_str()); |
| 839 |
return false; |
| 840 |
} |
| 841 |
int val=int(input->readLong(2)); |
| 842 |
if (val!=type) f << "##type2=" << val << ","; |
| 843 |
for (int i=0; i<2; ++i) { |
| 844 |
val=int(input->readLong(2)); |
| 845 |
if (val!=id) f << "id" << i+1 << "=" << val << ","; |
| 846 |
} |
| 847 |
val=int(input->readLong(2)); |
| 848 |
if (val!=1) f << "f0=" << val << ","; |
| 849 |
float dim[4]; |
| 850 |
for (auto &d : dim) { |
| 851 |
d=72*float(input->readLong(2)); |
| 852 |
d+=72*float(input->readLong(2))/10000; |
| 853 |
} |
| 854 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])); |
| 855 |
f << "box=" << shape.m_box << ","; |
| 856 |
f << "ID=" << std::hex << input->readULong(4) << std::dec << ","; |
| 857 |
if (input->tell()!=pos+6+len) { |
| 858 |
ascFile.addDelimiter(input->tell(),'|'); |
| 859 |
input->seek(pos+6+len, librevenge::RVNG_SEEK_SET); |
| 860 |
} |
| 861 |
ascFile.addPos(pos); |
| 862 |
ascFile.addNote(f.str().c_str()); |
| 863 |
|
| 864 |
pos=input->tell(); |
| 865 |
f.str(""); |
| 866 |
f << what << "-data:S" << id << ","; |
| 867 |
len=int(input->readULong(2)); |
| 868 |
long endPos=pos+2+len; |
| 869 |
if (len<0 || !input->checkPosition(endPos)) { |
| 870 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: find unexpected size for shape data block\n")); |
| 871 |
f << "###"; |
| 872 |
ascFile.addPos(pos); |
| 873 |
ascFile.addNote(f.str().c_str()); |
| 874 |
return false; |
| 875 |
} |
| 876 |
switch (type) { |
| 877 |
case 1: // solid |
| 878 |
case 2: { // frame |
| 879 |
if (len!=2+2*type) { |
| 880 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2[%d]: find unexpected size for shape data block\n", type)); |
| 881 |
f << "###"; |
| 882 |
break; |
| 883 |
} |
| 884 |
val=int(input->readLong(2)); |
| 885 |
if (val<0 || val>4) { |
| 886 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: the color id seems bad\n")); |
| 887 |
f << "###col=" << val << ","; |
| 888 |
} |
| 889 |
else { |
| 890 |
uint8_t grey=uint8_t(val==0 ? 255 : 32*val); |
| 891 |
if (type==2) |
| 892 |
shape.m_style.m_lineColor=MWAWColor(grey,grey,grey); |
| 893 |
else |
| 894 |
shape.m_style.setSurfaceColor(MWAWColor(grey,grey,grey)); |
| 895 |
f << "color=" << val << ","; // 0: none, 1: black, 2: grey1, .., 4: light grey |
| 896 |
} |
| 897 |
if (type==2) { |
| 898 |
val=int(input->readLong(2)); |
| 899 |
if (val<0 || val>100) { |
| 900 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: the frame size seems bad\n")); |
| 901 |
f << "###"; |
| 902 |
} |
| 903 |
else |
| 904 |
shape.m_style.m_lineWidth=float(val); |
| 905 |
if (val!=1) |
| 906 |
f << "frame[size]=" << val << ","; |
| 907 |
} |
| 908 |
int subType=int(input->readLong(2)); |
| 909 |
switch (subType) { |
| 910 |
case 1: // rectangle |
| 911 |
break; |
| 912 |
case 2: |
| 913 |
shape.m_type=ReadySetGoGraphInternal::Shape::T_RectOval; |
| 914 |
f << "rectOval,"; |
| 915 |
break; |
| 916 |
case 3: |
| 917 |
shape.m_type=ReadySetGoGraphInternal::Shape::T_Oval; |
| 918 |
f << "oval,"; |
| 919 |
break; |
| 920 |
default: |
| 921 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: unknown rectangle type\n")); |
| 922 |
f << "###type=" << subType << ","; |
| 923 |
break; |
| 924 |
} |
| 925 |
break; |
| 926 |
} |
| 927 |
case 3: { |
| 928 |
if (len!=16) { |
| 929 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2[pict]: find unexpected size for shape data block\n")); |
| 930 |
f << "###"; |
| 931 |
break; |
| 932 |
} |
| 933 |
for (int i=0; i<2; ++i) { |
| 934 |
val=int(input->readULong(2)); |
| 935 |
if (val!=100) |
| 936 |
f << "scale" << (i==0 ? "X" : "Y") << "=" << val << "%,"; |
| 937 |
} |
| 938 |
int iDim[2]; // some multiples of 6, link to decal? |
| 939 |
for (auto &d : iDim) d=int(input->readLong(2)); |
| 940 |
if (iDim[0] || iDim[1]) |
| 941 |
f << "crop=" << MWAWVec2i(iDim[1],iDim[0]) << ","; // checkme |
| 942 |
val=int(input->readULong(4)); |
| 943 |
if (val) { |
| 944 |
shape.m_hasPicture=true; |
| 945 |
f << "ID=" << std::hex << val << std::dec << ","; |
| 946 |
} |
| 947 |
for (int i=0; i<2; ++i) { // 0 |
| 948 |
val=int(input->readULong(2)); |
| 949 |
if (val) f << "f" << i << "=" << val << ","; |
| 950 |
} |
| 951 |
break; |
| 952 |
} |
| 953 |
case 4: { |
| 954 |
if (len!=0x9a) { |
| 955 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2[text]: find unexpected size for shape data block\n")); |
| 956 |
f << "###"; |
| 957 |
break; |
| 958 |
} |
| 959 |
shape.m_paragraph.m_marginsUnit=librevenge::RVNG_INCH; |
| 960 |
for (int i=0; i<2; ++i) { // 0 |
| 961 |
val=int(input->readLong(2)); |
| 962 |
shape.m_paragraph.m_margins[1-i]=float(val)+float(input->readULong(2))/10000; |
| 963 |
if (*shape.m_paragraph.m_margins[1-i]>0) f << (i==0 ? "para" : "left") << "[indent]=" << *shape.m_paragraph.m_margins[i] << ","; |
| 964 |
} |
| 965 |
shape.m_paragraph.m_margins[0]=*shape.m_paragraph.m_margins[0]-*shape.m_paragraph.m_margins[1]; |
| 966 |
std::string extra; |
| 967 |
m_styleManager->readTabulationsV1(*shape.m_paragraph.m_tabs, extra); |
| 968 |
f << extra; |
| 969 |
ascFile.addPos(pos); |
| 970 |
ascFile.addNote(f.str().c_str()); |
| 971 |
|
| 972 |
pos=input->tell(); |
| 973 |
f.str(""); |
| 974 |
f << what << "-data1:"; |
| 975 |
input->seek(pos+66, librevenge::RVNG_SEEK_SET); |
| 976 |
ascFile.addPos(pos); |
| 977 |
ascFile.addNote(f.str().c_str()); |
| 978 |
|
| 979 |
pos=input->tell(); |
| 980 |
f.str(""); |
| 981 |
f << what << "-data2:"; |
| 982 |
// pos+16: maybe alignement |
| 983 |
break; |
| 984 |
} |
| 985 |
default: |
| 986 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: reading data of type=%d is not implemented\n", type)); |
| 987 |
f << "###"; |
| 988 |
break; |
| 989 |
} |
| 990 |
if (input->tell()!=pos && input->tell()!=endPos) |
| 991 |
ascFile.addDelimiter(input->tell(),'|'); |
| 992 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 993 |
ascFile.addPos(pos); |
| 994 |
ascFile.addNote(f.str().c_str()); |
| 995 |
|
| 996 |
if (type==3 && shape.m_hasPicture) { |
| 997 |
pos=input->tell(); |
| 998 |
len=int(input->readULong(2)); |
| 999 |
f.str(""); |
| 1000 |
f << "Picture:"; |
| 1001 |
if (!input->checkPosition(pos+2+len)) { |
| 1002 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: find unexpected size for picture\n")); |
| 1003 |
f << "###"; |
| 1004 |
ascFile.addPos(pos); |
| 1005 |
ascFile.addNote(f.str().c_str()); |
| 1006 |
return false; |
| 1007 |
} |
| 1008 |
shape.m_entries[0].setBegin(pos+2); |
| 1009 |
shape.m_entries[0].setLength(len); |
| 1010 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 1011 |
ascFile.addPos(pos); |
| 1012 |
ascFile.addNote(f.str().c_str()); |
| 1013 |
} |
| 1014 |
if (type!=4) { |
| 1015 |
layout.m_shapes.push_back(shape); |
| 1016 |
return true; |
| 1017 |
} |
| 1018 |
for (int st=0; st<2; ++st) { // zone1=[text, style], zone2=[para] |
| 1019 |
pos=input->tell(); |
| 1020 |
f.str(""); |
| 1021 |
f << "Text-" << (st==0 ? "char" : "para") << ":"; |
| 1022 |
len=int(input->readULong(2)); |
| 1023 |
if (!input->checkPosition(pos+2+len)) { |
| 1024 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV2: find unexpected size for text sub zone=%d\n", st)); |
| 1025 |
f << "###"; |
| 1026 |
ascFile.addPos(pos); |
| 1027 |
ascFile.addNote(f.str().c_str()); |
| 1028 |
return false; |
| 1029 |
} |
| 1030 |
shape.m_entries[st].setBegin(pos+2); |
| 1031 |
shape.m_entries[st].setLength(len); |
| 1032 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 1033 |
ascFile.addPos(pos); |
| 1034 |
ascFile.addNote(f.str().c_str()); |
| 1035 |
} |
| 1036 |
layout.m_shapes.push_back(shape); |
| 1037 |
return true; |
| 1038 |
} |
| 1039 |
|
| 1040 |
bool ReadySetGoGraph::readShapeV3(ReadySetGoGraphInternal::Layout &layout, bool &last) |
| 1041 |
{ |
| 1042 |
last=false; |
| 1043 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 1044 |
if (!input) |
| 1045 |
return false; |
| 1046 |
|
| 1047 |
int const vers=version(); |
| 1048 |
long pos=input->tell(); |
| 1049 |
if (!input->checkPosition(pos+2)) { |
| 1050 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3: can not read a shape\n")); |
| 1051 |
return false; |
| 1052 |
} |
| 1053 |
|
| 1054 |
auto &ascFile = m_parser.ascii(); |
| 1055 |
int type=int(input->readLong(2)); |
| 1056 |
if (type==-1) { |
| 1057 |
ascFile.addPos(pos); |
| 1058 |
ascFile.addNote("Layout-end:"); |
| 1059 |
last=true; |
| 1060 |
return true; |
| 1061 |
} |
| 1062 |
if (type<0 || type>6) { |
| 1063 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3: the type seems bad\n")); |
| 1064 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1065 |
return false; |
| 1066 |
} |
| 1067 |
libmwaw::DebugStream f; |
| 1068 |
|
| 1069 |
long len=long(input->readLong(4)); |
| 1070 |
int const decal=vers<=3 ? 0 : 4; |
| 1071 |
if (len<32+decal || (long)((unsigned long)pos+6+(unsigned long)len)<pos+6 || !input->checkPosition(pos+6+len)) { |
| 1072 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3: can not find a shape length\n")); |
| 1073 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1074 |
f << "Entries(Shape" << type << "):"; |
| 1075 |
f << "###"; |
| 1076 |
ascFile.addPos(pos); |
| 1077 |
ascFile.addNote(f.str().c_str()); |
| 1078 |
return false; |
| 1079 |
} |
| 1080 |
static ReadySetGoGraphInternal::Shape::Type const shapeTypes[]= { |
| 1081 |
ReadySetGoGraphInternal::Shape::T_Rectangle, |
| 1082 |
ReadySetGoGraphInternal::Shape::T_RectOval, // + oval size |
| 1083 |
ReadySetGoGraphInternal::Shape::T_Oval, |
| 1084 |
ReadySetGoGraphInternal::Shape::T_Picture, |
| 1085 |
ReadySetGoGraphInternal::Shape::T_Text, |
| 1086 |
ReadySetGoGraphInternal::Shape::T_Line, |
| 1087 |
ReadySetGoGraphInternal::Shape::T_Line |
| 1088 |
}; |
| 1089 |
static char const *what[]= { "Rectangle", "RectOval", "Oval", "Picture", "Text", "Line" /* hv*/, "Line" /* not axis aligned*/}; |
| 1090 |
f << "Entries(" << what[type] << "):"; |
| 1091 |
ReadySetGoGraphInternal::Shape shape(shapeTypes[type]); |
| 1092 |
f << "IDS=["; // next, prev |
| 1093 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 1094 |
f << "],"; |
| 1095 |
float dim[4]; |
| 1096 |
for (auto &d : dim) d=72*float(input->readLong(4))/65536; |
| 1097 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])); |
| 1098 |
f << "box=" << shape.m_box << ","; |
| 1099 |
int val; |
| 1100 |
if (vers>3) { |
| 1101 |
val=int(input->readULong(4)); |
| 1102 |
if (val!=0x1555) |
| 1103 |
f << "dist[text,repel]=" << float(val)/65536 << ",";; |
| 1104 |
} |
| 1105 |
val=int(input->readLong(1)); |
| 1106 |
if (val!=type) |
| 1107 |
f << "##type1=" << val << ","; |
| 1108 |
val=int(input->readLong(1)); |
| 1109 |
if (val==-1) |
| 1110 |
f << "selected,"; |
| 1111 |
else if (val) |
| 1112 |
f << "#selected=" << val << ","; |
| 1113 |
bool hasPicture=false, hasTabs=false; |
| 1114 |
val=int(input->readLong(1)); |
| 1115 |
if (val==-1) { |
| 1116 |
if (vers<4) |
| 1117 |
shape.m_wrapRoundAround=true; |
| 1118 |
f << "run[around],"; |
| 1119 |
} |
| 1120 |
else if (val) |
| 1121 |
f << "run[around]=" << val << ","; |
| 1122 |
val=int(input->readULong(1)); // only v4? |
| 1123 |
if (val&1) |
| 1124 |
f << "locked,"; |
| 1125 |
if (val&2) |
| 1126 |
f << "print[no],"; |
| 1127 |
if (val&4) { |
| 1128 |
f << "run[around],"; |
| 1129 |
if (vers>=4) |
| 1130 |
shape.m_wrapRoundAround=true; |
| 1131 |
} |
| 1132 |
val &=0xf8; |
| 1133 |
if (val) |
| 1134 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 1135 |
switch (type) { |
| 1136 |
case 0: |
| 1137 |
case 1: |
| 1138 |
case 2: |
| 1139 |
case 5: |
| 1140 |
case 6: { |
| 1141 |
if (len!=(type==1 ? 36 : type==6 ? 40 : 32)+decal+(vers>=5 ? 4 : 0)) { |
| 1142 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[%d]: unexpected data length\n", type)); |
| 1143 |
f << "###"; |
| 1144 |
break; |
| 1145 |
} |
| 1146 |
auto &style=shape.m_style; |
| 1147 |
val=int(input->readLong(1)); |
| 1148 |
int const extraVal=vers<5 ? 0 : 3; |
| 1149 |
if (val>=0 && val<=5+extraVal) { |
| 1150 |
float const w[]= {0.125f, 0.25f, 0.5f, 0.75f, 1, 2, 4, 6, 8}; |
| 1151 |
style.m_lineWidth=w[val+(3-extraVal)]; |
| 1152 |
} |
| 1153 |
else if (val>=6+extraVal && val<=10+extraVal) { |
| 1154 |
float const w[]= {1, 2, 4, 6, 8}; |
| 1155 |
style.m_lineWidth=w[val-6-extraVal]; |
| 1156 |
f << "dash,"; |
| 1157 |
style.m_lineDashWidth= {10,10}; |
| 1158 |
} |
| 1159 |
else if (val>=11+extraVal && val<=13+extraVal) { |
| 1160 |
// changeme: double line 2-1-1, 1-1-2, 1-1-1 |
| 1161 |
style.m_lineWidth=val==13+extraVal ? 3 : 4; |
| 1162 |
f << "double[line],"; |
| 1163 |
} |
| 1164 |
else { |
| 1165 |
style.m_lineWidth=1; |
| 1166 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[%d]: find unknown line style\n", type)); |
| 1167 |
f << "###line[style]=" << val << ","; |
| 1168 |
} |
| 1169 |
if (style.m_lineWidth<1 || style.m_lineWidth>1) |
| 1170 |
f << "line[width]=" << style.m_lineWidth << ","; |
| 1171 |
|
| 1172 |
int patIds[2]; |
| 1173 |
int const nonePatId=vers==3 ? 39 : 48; |
| 1174 |
for (auto &p : patIds) p=int(input->readULong(1)); |
| 1175 |
input->seek(1, librevenge::RVNG_SEEK_CUR); // junk? |
| 1176 |
|
| 1177 |
int colIds[2]= {-1,-1}; |
| 1178 |
MWAWColor colors[2]= {MWAWColor::white(), MWAWColor::black()}; |
| 1179 |
if (vers>=5) { |
| 1180 |
for (int i=0; i<2; ++i) { |
| 1181 |
colIds[i]=int(input->readULong(2)); |
| 1182 |
int const expected[]= {7, 60}; |
| 1183 |
if (colIds[i]==expected[i]) continue; |
| 1184 |
f << "col[" << (i==0 ? "surf" : "line") << "]="; |
| 1185 |
if (colIds[i]>0 && m_styleManager->getColor(colIds[i], colors[i])) |
| 1186 |
f << colors[i] << ","; |
| 1187 |
else { |
| 1188 |
f << "###" << colIds[i] << ","; |
| 1189 |
colIds[i]=-1; |
| 1190 |
} |
| 1191 |
} |
| 1192 |
} |
| 1193 |
if (type==1) { |
| 1194 |
int corner[2]; |
| 1195 |
for (auto &d : corner) d=int(input->readLong(2)); |
| 1196 |
shape.m_cornerSize=MWAWVec2i(corner[0], corner[1]); |
| 1197 |
f << "corner=" << shape.m_cornerSize << ","; |
| 1198 |
} |
| 1199 |
if (type==5) { // we must retrieve the line points |
| 1200 |
auto const &box=shape.m_box; |
| 1201 |
if (box.size()[0]>box.size()[1]) { |
| 1202 |
auto y=(box[0][1]+box[1][1])/2; |
| 1203 |
shape.m_points[0]=MWAWVec2f(box[0][0],y); |
| 1204 |
shape.m_points[1]=MWAWVec2f(box[1][0],y); |
| 1205 |
} |
| 1206 |
else { |
| 1207 |
auto x=(box[0][0]+box[1][0])/2; |
| 1208 |
shape.m_points[0]=MWAWVec2f(x,box[0][1]); |
| 1209 |
shape.m_points[1]=MWAWVec2f(x,box[1][1]); |
| 1210 |
} |
| 1211 |
} |
| 1212 |
if (type==6) { |
| 1213 |
float iDim[4]; |
| 1214 |
for (auto &d: iDim) d=float(input->readLong(2)); |
| 1215 |
shape.m_points[0]=MWAWVec2f(iDim[1],iDim[0]); |
| 1216 |
shape.m_points[1]=MWAWVec2f(iDim[3],iDim[2]); |
| 1217 |
f << "pos=" << shape.m_points[0] << "<->" << shape.m_points[1] << ","; |
| 1218 |
} |
| 1219 |
|
| 1220 |
// time to set the patterns/colors |
| 1221 |
if (patIds[0]!=nonePatId && (type!=5 && type!=6)) { |
| 1222 |
MWAWGraphicStyle::Pattern pat; |
| 1223 |
MWAWColor color; |
| 1224 |
if (!m_styleManager->getPattern(patIds[0]-1, pat)) |
| 1225 |
f << "##surface[color]=" << patIds[0] << ","; |
| 1226 |
else { |
| 1227 |
if (colIds[0]>=0) |
| 1228 |
pat.m_colors[0]=colors[0]; |
| 1229 |
if (pat.getUniqueColor(color)) { |
| 1230 |
style.setSurfaceColor(color); |
| 1231 |
f << "surface[color]=" << color << ","; |
| 1232 |
} |
| 1233 |
else { |
| 1234 |
style.setPattern(pat); |
| 1235 |
f << "surface[pat]=" << pat << ","; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
} |
| 1239 |
if (patIds[1]==nonePatId) // transparent |
| 1240 |
style.m_lineWidth=0; |
| 1241 |
else { |
| 1242 |
MWAWGraphicStyle::Pattern pat; |
| 1243 |
MWAWColor color; |
| 1244 |
if (!m_styleManager->getPattern(patIds[1]-1, pat)) |
| 1245 |
f << "##line[color]=" << patIds[1] << ","; |
| 1246 |
else { |
| 1247 |
if (colIds[1]>=0) |
| 1248 |
pat.m_colors[0]=colors[1]; |
| 1249 |
if (pat.getAverageColor(style.m_lineColor)) |
| 1250 |
f << "line[color]=" << style.m_lineColor << ","; |
| 1251 |
else { |
| 1252 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[%d]: can not determine a shape color\n", type)); |
| 1253 |
f << "###line[color]=" << patIds[1] << ","; |
| 1254 |
} |
| 1255 |
} |
| 1256 |
} |
| 1257 |
break; |
| 1258 |
} |
| 1259 |
case 3: { |
| 1260 |
if (len!=(vers==3 ? 40 : vers==4 ? 84 : 0x16c)) { |
| 1261 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[picture]: unexpected data length\n")); |
| 1262 |
f << "###"; |
| 1263 |
break; |
| 1264 |
} |
| 1265 |
val=int(input->readLong(4)); |
| 1266 |
if (val) { |
| 1267 |
f << "ID1=" << std::hex << val << std::dec << ","; |
| 1268 |
hasPicture=true; |
| 1269 |
} |
| 1270 |
if (vers>4) { |
| 1271 |
val=int(input->readLong(2)); |
| 1272 |
if (val) f << "f2=" << val << ","; |
| 1273 |
} |
| 1274 |
int iDim[2]; // some multiples of 6, link to decal? |
| 1275 |
for (auto &d : iDim) d=int(input->readLong(2)); |
| 1276 |
if (iDim[0] || iDim[1]) |
| 1277 |
f << "crop=" << MWAWVec2i(iDim[1],iDim[0]) << ","; |
| 1278 |
for (int i=0; i<2; ++i) { |
| 1279 |
val=int(input->readULong(2)); |
| 1280 |
if (val!=100) |
| 1281 |
f << "scale" << (i==0 ? "X" : "Y") << "=" << val << "%,"; |
| 1282 |
} |
| 1283 |
if (vers==3) |
| 1284 |
break; |
| 1285 |
for (int i=0; i<(vers==4 ? 20 : 3); ++i) { |
| 1286 |
val=int(input->readLong(2)); |
| 1287 |
if (!val) continue; |
| 1288 |
if (i==2) // g2&2 run around graphic/frame?, g2&200 print as gray |
| 1289 |
f << "g" << i << "=" << std::hex << val << std::dec << ","; |
| 1290 |
else |
| 1291 |
f << "g" << i << "=" << val << ","; |
| 1292 |
} |
| 1293 |
break; |
| 1294 |
} |
| 1295 |
case 4: { |
| 1296 |
if (len!=(vers==3 ? 80 : vers==4 ? 100 : 104)) { |
| 1297 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[text]: unexpected data length\n")); |
| 1298 |
f << "###"; |
| 1299 |
break; |
| 1300 |
} |
| 1301 |
f << "IDS1=["; // next, prev |
| 1302 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 1303 |
f << "],"; |
| 1304 |
if (vers==3) { |
| 1305 |
f << "id=" << input->readLong(2) << ","; // 1-f |
| 1306 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1307 |
val=int(input->readULong(4)); |
| 1308 |
if (val) { |
| 1309 |
f << "tab[ID]=" << std::hex << val << std::dec << ","; |
| 1310 |
hasTabs=true; |
| 1311 |
} |
| 1312 |
} |
| 1313 |
else { |
| 1314 |
val=int(input->readULong(4)); |
| 1315 |
if (val) { |
| 1316 |
f << "tab[ID]=" << std::hex << val << std::dec << ","; |
| 1317 |
hasTabs=true; |
| 1318 |
} |
| 1319 |
f << "id=" << input->readLong(2) << ","; // 1-f |
| 1320 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1321 |
} |
| 1322 |
int tDim[4]; |
| 1323 |
for (auto &d : tDim) d=int(input->readLong(2)); |
| 1324 |
f << "unkn=" << MWAWBox2i(MWAWVec2i(tDim[0],tDim[1]),MWAWVec2i(tDim[2],tDim[3])) << ","; |
| 1325 |
for (int i=0; i<5; ++i) { |
| 1326 |
val=int(input->readLong(2)); |
| 1327 |
if (val) |
| 1328 |
f << "f" << i+2 << "=" << val << ","; |
| 1329 |
} |
| 1330 |
val=int(input->readULong(2)); |
| 1331 |
if (val&0x4) |
| 1332 |
f << "postscript,"; |
| 1333 |
if (val&0x10) // useme: basically the text is hidden |
| 1334 |
f << "white[type],"; |
| 1335 |
if (val&0x20) |
| 1336 |
f << "ignore[run,around],"; |
| 1337 |
val&=0xffdb; |
| 1338 |
if (val) |
| 1339 |
f << "fl1=" << std::hex << val << std::dec << ","; |
| 1340 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1341 |
input->seek(pos+76+(vers==3 ? 0 : 4), librevenge::RVNG_SEEK_SET); |
| 1342 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1343 |
shape.m_textId=int(input->readLong(2)); |
| 1344 |
f << "text[id]=" << shape.m_textId << ","; |
| 1345 |
for (int i=0; i<2; ++i) { |
| 1346 |
shape.m_linkIds[i]=int(input->readLong(2)); |
| 1347 |
if (shape.m_linkIds[i]==-1) |
| 1348 |
continue; |
| 1349 |
f << (i==0 ? "prev" : "next") << "[link]=" << shape.m_linkIds[i] << ","; |
| 1350 |
} |
| 1351 |
for (int i=0; i<2; ++i) { |
| 1352 |
val=int(input->readLong(2)); |
| 1353 |
if (val!=-1) |
| 1354 |
f << "g" << i << "=" << val << ","; |
| 1355 |
} |
| 1356 |
if (vers==3) |
| 1357 |
break; |
| 1358 |
for (int i=0; i<(vers==4 ? 8 : 9); ++i) { // g4=3100 |
| 1359 |
val=int(input->readLong(2)); |
| 1360 |
if (val) |
| 1361 |
f << "g" << i+2 << "=" << val << ","; |
| 1362 |
} |
| 1363 |
if (vers==4) |
| 1364 |
break; |
| 1365 |
val=int(input->readLong(1)); |
| 1366 |
switch (val) { |
| 1367 |
case 0: // top |
| 1368 |
break; |
| 1369 |
case 1: |
| 1370 |
shape.m_style.m_verticalAlignment=MWAWGraphicStyle::V_AlignBottom; |
| 1371 |
f << "vAlign=bottom,"; |
| 1372 |
break; |
| 1373 |
case 2: |
| 1374 |
shape.m_style.m_verticalAlignment=MWAWGraphicStyle::V_AlignCenter; |
| 1375 |
f << "vAlign=center,"; |
| 1376 |
break; |
| 1377 |
case 3: |
| 1378 |
shape.m_style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 1379 |
f << "vAlign=justify[feathering],"; |
| 1380 |
break; |
| 1381 |
case 4: |
| 1382 |
shape.m_style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 1383 |
f << "vAlign=justify[paragraph],"; |
| 1384 |
break; |
| 1385 |
default: |
| 1386 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[text]: unknown vertical alignment\n")); |
| 1387 |
f << "##vAlign=" << val << ","; |
| 1388 |
break; |
| 1389 |
} |
| 1390 |
val=int(input->readLong(1)); |
| 1391 |
if (val) f << "h0=" << val << ","; |
| 1392 |
break; |
| 1393 |
} |
| 1394 |
default: |
| 1395 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[%d]: unexpected data\n", type)); |
| 1396 |
f << "###"; |
| 1397 |
break; |
| 1398 |
} |
| 1399 |
if (input->tell()!=pos+6+len) |
| 1400 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1401 |
ascFile.addPos(pos); |
| 1402 |
ascFile.addNote(f.str().c_str()); |
| 1403 |
input->seek(pos+6+len, librevenge::RVNG_SEEK_SET); |
| 1404 |
|
| 1405 |
if (hasPicture) { |
| 1406 |
pos=input->tell(); |
| 1407 |
len=long(input->readLong(4)); |
| 1408 |
if ((len&0xffff)<7 || !input->checkPosition(pos+4+len)) |
| 1409 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1410 |
else { |
| 1411 |
shape.m_entries[0].setBegin(pos+4); |
| 1412 |
shape.m_entries[0].setLength(len); |
| 1413 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 1414 |
ascFile.addPos(pos); |
| 1415 |
ascFile.addNote("Picture-data:"); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
if (type==4 && vers>3) { |
| 1419 |
pos=input->tell(); |
| 1420 |
f.str(""); |
| 1421 |
f << "Text-limits:"; |
| 1422 |
if (!input->checkPosition(pos+8)) { |
| 1423 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3: can not find the text limits positions\n")); |
| 1424 |
f << "###"; |
| 1425 |
ascFile.addPos(pos); |
| 1426 |
ascFile.addNote(f.str().c_str()); |
| 1427 |
return false; |
| 1428 |
} |
| 1429 |
for (int i=0; i<2; ++i) { |
| 1430 |
shape.m_textPositions[i]=int(input->readLong(4)); |
| 1431 |
if (shape.m_textPositions[i]==0) continue; |
| 1432 |
f << (i==0 ? "min[pos]" : "max[pos]") << "=" << shape.m_textPositions[i] << ","; |
| 1433 |
} |
| 1434 |
ascFile.addPos(pos); |
| 1435 |
ascFile.addNote(f.str().c_str()); |
| 1436 |
} |
| 1437 |
if (type==4 && shape.m_linkIds[0]<0) { |
| 1438 |
for (int st=0; st<(!hasTabs ? 2 : 3); ++st) { |
| 1439 |
pos=input->tell(); |
| 1440 |
len=long(input->readLong(4)); |
| 1441 |
if (len<10 || (long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) { |
| 1442 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV3[text]: can not find a shape length\n")); |
| 1443 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1444 |
f << "###"; |
| 1445 |
ascFile.addPos(pos); |
| 1446 |
ascFile.addNote("Text-####"); |
| 1447 |
return false; |
| 1448 |
} |
| 1449 |
shape.m_entries[st].setBegin(pos+4); |
| 1450 |
shape.m_entries[st].setLength(len); |
| 1451 |
ascFile.addPos(pos); |
| 1452 |
ascFile.addNote(st==0 ? "Text-text" : st==1 ? "Entries(Style):" : "Entries(Tabs):"); |
| 1453 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 1454 |
} |
| 1455 |
} |
| 1456 |
layout.m_shapes.push_back(shape); |
| 1457 |
return true; |
| 1458 |
} |
| 1459 |
|
| 1460 |
bool ReadySetGoGraph::readShapeV6(ReadySetGoGraphInternal::Layout &layout, bool &last) |
| 1461 |
{ |
| 1462 |
last=false; |
| 1463 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 1464 |
if (!input) |
| 1465 |
return false; |
| 1466 |
|
| 1467 |
int const vers=version(); |
| 1468 |
if (vers<6 || m_parser.isDesignStudioFile()) { |
| 1469 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: unexpected version\n")); |
| 1470 |
return false; |
| 1471 |
} |
| 1472 |
long pos=input->tell(); |
| 1473 |
if (!input->checkPosition(pos+2)) { |
| 1474 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: can not read a shape\n")); |
| 1475 |
return false; |
| 1476 |
} |
| 1477 |
|
| 1478 |
auto &ascFile = m_parser.ascii(); |
| 1479 |
int type=int(input->readLong(2)); |
| 1480 |
if (type==-1) { |
| 1481 |
ascFile.addPos(pos); |
| 1482 |
ascFile.addNote("Layout-end:"); |
| 1483 |
last=true; |
| 1484 |
return true; |
| 1485 |
} |
| 1486 |
libmwaw::DebugStream f; |
| 1487 |
if (type<0 || type>7) { |
| 1488 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: the type seems bad\n")); |
| 1489 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1490 |
f << "Entries(Shape" << type << "):"; |
| 1491 |
f << "###"; |
| 1492 |
ascFile.addPos(pos); |
| 1493 |
ascFile.addNote(f.str().c_str()); |
| 1494 |
return false; |
| 1495 |
} |
| 1496 |
|
| 1497 |
long len=long(input->readLong(4)); |
| 1498 |
int const minSize[]= {0x98, 0x9c, 0x98, 0x1e6, 0xe0, 0x98, 0xa0, 0xa0}; |
| 1499 |
if (len<minSize[type] || (long)((unsigned long)pos+6+(unsigned long)len)<pos+6 || !input->checkPosition(pos+6+len)) { |
| 1500 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: can not find a shape length\n")); |
| 1501 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1502 |
f << "Entries(Shape" << type << "):"; |
| 1503 |
f << "###"; |
| 1504 |
ascFile.addPos(pos); |
| 1505 |
ascFile.addNote(f.str().c_str()); |
| 1506 |
return false; |
| 1507 |
} |
| 1508 |
static ReadySetGoGraphInternal::Shape::Type const shapeTypes[]= { |
| 1509 |
ReadySetGoGraphInternal::Shape::T_Rectangle, |
| 1510 |
ReadySetGoGraphInternal::Shape::T_RectOval, // + oval size |
| 1511 |
ReadySetGoGraphInternal::Shape::T_Oval, |
| 1512 |
ReadySetGoGraphInternal::Shape::T_Picture, |
| 1513 |
ReadySetGoGraphInternal::Shape::T_Text, |
| 1514 |
ReadySetGoGraphInternal::Shape::T_Line, |
| 1515 |
ReadySetGoGraphInternal::Shape::T_Line, |
| 1516 |
ReadySetGoGraphInternal::Shape::T_Polygon, |
| 1517 |
}; |
| 1518 |
static char const *what[]= { "Rectangle", "RectOval", "Oval", "Picture", "Text", "Line" /* hv*/, "Line" /* not axis aligned*/, "Polygon" }; |
| 1519 |
f << "Entries(" << what[type] << "):"; |
| 1520 |
ReadySetGoGraphInternal::Shape shape(shapeTypes[type]); |
| 1521 |
f << "IDS=["; // next, prev |
| 1522 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 1523 |
f << "],"; |
| 1524 |
float dim[4]; |
| 1525 |
for (auto &d : dim) d=72*float(input->readLong(4))/65536; |
| 1526 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])); |
| 1527 |
f << "box=" << shape.m_box << ","; |
| 1528 |
int val; |
| 1529 |
val=int(input->readULong(4)); |
| 1530 |
if (val!=0x1555) |
| 1531 |
f << "dist[text,repel]=" << float(val)/65536 << ",";; |
| 1532 |
val=int(input->readLong(1)); |
| 1533 |
if (val!=type) |
| 1534 |
f << "##type1=" << val << ","; |
| 1535 |
val=int(input->readLong(1)); |
| 1536 |
if (val==-1) |
| 1537 |
f << "selected,"; |
| 1538 |
else if (val) |
| 1539 |
f << "#selected=" << val << ","; |
| 1540 |
bool hasTabs=false; |
| 1541 |
int numPictures=0; |
| 1542 |
int numPoints=0; |
| 1543 |
val=int(input->readLong(1)); |
| 1544 |
if (val==-1) |
| 1545 |
f << "run[around],"; |
| 1546 |
else if (val) |
| 1547 |
f << "run[around]=" << val << ","; |
| 1548 |
val=int(input->readULong(1)); // only v4? |
| 1549 |
if (val&1) |
| 1550 |
f << "locked,"; |
| 1551 |
if (val&2) |
| 1552 |
f << "print[no],"; |
| 1553 |
if (val&4) { |
| 1554 |
f << "run[around],"; |
| 1555 |
shape.m_wrapRoundAround=true; |
| 1556 |
} |
| 1557 |
val &=0xf8; |
| 1558 |
if (val) |
| 1559 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 1560 |
auto &style=shape.m_style; |
| 1561 |
shape.m_rotate=int(input->readLong(2)); |
| 1562 |
if (shape.m_rotate) { |
| 1563 |
f << "rot=" << double(shape.m_rotate)/10 << ","; |
| 1564 |
style.m_rotate=float(shape.m_rotate)/10; |
| 1565 |
} |
| 1566 |
val=int(input->readULong(2)); |
| 1567 |
if (val&0x100) { |
| 1568 |
f << "flipY,"; |
| 1569 |
style.m_flip[1]=true; |
| 1570 |
} |
| 1571 |
if (val&0x200) { |
| 1572 |
f << "flipX,"; |
| 1573 |
style.m_flip[0]=true; |
| 1574 |
} |
| 1575 |
val&=0xfcff; |
| 1576 |
if (val) f << "f7" << "=" << std::hex << val << std::dec << ","; |
| 1577 |
for (auto &d : dim) d=float(input->readLong(2)); |
| 1578 |
if (dim[0]<dim[2] || dim[1]<dim[3]) |
| 1579 |
f << "box1=" << MWAWBox2f(MWAWVec2f(dim[1],dim[0]), MWAWVec2f(dim[3],dim[2])) << ","; |
| 1580 |
for (int i=0; i<2; ++i) { |
| 1581 |
val=int(input->readLong(2)); |
| 1582 |
if (val) f << "f" << 8+i << "=" << val << ","; |
| 1583 |
} |
| 1584 |
for (int i=0; i<2; ++i) { |
| 1585 |
for (auto &d : dim) d=float(input->readLong(2)); |
| 1586 |
if (dim[0]<dim[2] || dim[1]<dim[3]) |
| 1587 |
f << "box" << 2+i << "=" << MWAWBox2f(MWAWVec2f(dim[1],dim[0]), MWAWVec2f(dim[3],dim[2])) << ","; |
| 1588 |
} |
| 1589 |
for (int i=0; i<14; ++i) { |
| 1590 |
val=int(input->readLong(2)); |
| 1591 |
if (val) f << "f" << 10+i << "=" << val << ","; |
| 1592 |
} |
| 1593 |
shape.m_groupId=int(input->readLong(2)); |
| 1594 |
if (shape.m_groupId) f << "group=" << shape.m_groupId << ","; |
| 1595 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1596 |
input->seek(32, librevenge::RVNG_SEEK_CUR); |
| 1597 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1598 |
val=int(input->readULong(4)); |
| 1599 |
if (val) |
| 1600 |
f << "ID[unk]=" << std::hex << val << std::dec << ","; |
| 1601 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1602 |
input->seek(8, librevenge::RVNG_SEEK_CUR); |
| 1603 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1604 |
|
| 1605 |
int const nonePatId=4; |
| 1606 |
int backColId=60; |
| 1607 |
int backPatId=nonePatId; |
| 1608 |
if (type==4) { |
| 1609 |
f << "IDS1=["; // next, prev |
| 1610 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 1611 |
f << "],"; |
| 1612 |
val=int(input->readULong(4)); |
| 1613 |
if (val) { |
| 1614 |
f << "tab[ID]=" << std::hex << val << std::dec << ","; |
| 1615 |
hasTabs=true; |
| 1616 |
} |
| 1617 |
f << "id=" << input->readLong(2) << ","; // 1-f |
| 1618 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1619 |
int tDim[4]; |
| 1620 |
for (auto &d : tDim) d=int(input->readLong(2)); |
| 1621 |
f << "unkn=" << MWAWBox2i(MWAWVec2i(tDim[0],tDim[1]),MWAWVec2i(tDim[2],tDim[3])) << ","; |
| 1622 |
for (int i=0; i<5; ++i) { |
| 1623 |
val=int(input->readLong(2)); |
| 1624 |
if (!val) continue; |
| 1625 |
f << "f" << i+2 << "=" << val << ","; |
| 1626 |
} |
| 1627 |
val=int(input->readULong(2)); |
| 1628 |
if (val&0x4) |
| 1629 |
f << "postscript,"; |
| 1630 |
if (val&0x10) // useme: basically the text is hidden |
| 1631 |
f << "white[type],"; |
| 1632 |
if (val&0x20) |
| 1633 |
f << "ignore[run,around],"; |
| 1634 |
val&=0xffdb; |
| 1635 |
if (val) |
| 1636 |
f << "fl1=" << std::hex << val << std::dec << ","; |
| 1637 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1638 |
input->seek(pos+76+110, librevenge::RVNG_SEEK_SET); |
| 1639 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1640 |
shape.m_textId=int(input->readLong(2)); |
| 1641 |
f << "text[id]=" << shape.m_textId << ","; |
| 1642 |
for (int i=0; i<2; ++i) { |
| 1643 |
shape.m_linkIds[i]=int(input->readLong(2)); |
| 1644 |
if (shape.m_linkIds[i]==-1) |
| 1645 |
continue; |
| 1646 |
f << (i==0 ? "prev" : "next") << "[link]=" << shape.m_linkIds[i] << ","; |
| 1647 |
} |
| 1648 |
for (int i=0; i<2; ++i) { |
| 1649 |
val=int(input->readLong(2)); |
| 1650 |
if (val!=-1) |
| 1651 |
f << "g" << i << "=" << val << ","; |
| 1652 |
} |
| 1653 |
bool hasBackPattern=false; |
| 1654 |
uint8_t backPattern[8]; |
| 1655 |
for (auto &p : backPattern) { |
| 1656 |
p=uint8_t(input->readULong(1)); |
| 1657 |
if (p) hasBackPattern=true; |
| 1658 |
} |
| 1659 |
if (hasBackPattern) { |
| 1660 |
f << "back[pat]=["; |
| 1661 |
for (auto const &p : backPattern) f << std::hex << int(p) << std::dec << ","; |
| 1662 |
f << "],"; |
| 1663 |
} |
| 1664 |
backColId=int(input->readLong(2)); |
| 1665 |
if (backColId!=60) |
| 1666 |
f << "back[col,id]=" << backColId << ","; |
| 1667 |
backPatId=int(input->readULong(1)); |
| 1668 |
if (backPatId!=nonePatId) |
| 1669 |
f << "back[pat,id]=" << backPatId << ","; |
| 1670 |
input->seek(1, librevenge::RVNG_SEEK_CUR); |
| 1671 |
for (int i=0; i<3; ++i) { |
| 1672 |
val=int(input->readLong(2)); |
| 1673 |
if (!val) |
| 1674 |
continue; |
| 1675 |
f << "g" << i+2 << "=" << val << ","; |
| 1676 |
} |
| 1677 |
val=int(input->readLong(1)); |
| 1678 |
switch (val) { |
| 1679 |
case 0: // top |
| 1680 |
break; |
| 1681 |
case 1: |
| 1682 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignBottom; |
| 1683 |
f << "vAlign=bottom,"; |
| 1684 |
break; |
| 1685 |
case 2: |
| 1686 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignCenter; |
| 1687 |
f << "vAlign=center,"; |
| 1688 |
break; |
| 1689 |
case 3: |
| 1690 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 1691 |
f << "vAlign=justify[feathering],"; |
| 1692 |
break; |
| 1693 |
case 4: |
| 1694 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 1695 |
f << "vAlign=justify[paragraph],"; |
| 1696 |
break; |
| 1697 |
default: |
| 1698 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[text]: unknown vertical alignment\n")); |
| 1699 |
f << "##vAlign=" << val << ","; |
| 1700 |
break; |
| 1701 |
} |
| 1702 |
val=int(input->readLong(1)); |
| 1703 |
if (val) f << "h0=" << val << ","; |
| 1704 |
} |
| 1705 |
val=int(input->readLong(1)); |
| 1706 |
if (val>=0 && val<=8) { |
| 1707 |
float const w[]= {0.125f, 0.25f, 0.5f, 0.75f, 1, 2, 4, 6, 8}; |
| 1708 |
style.m_lineWidth=w[val]; |
| 1709 |
} |
| 1710 |
else if (val>=9 && val<=13) { |
| 1711 |
float const w[]= {1, 2, 4, 6, 8}; |
| 1712 |
style.m_lineWidth=w[val-9]; |
| 1713 |
f << "dash,"; |
| 1714 |
style.m_lineDashWidth= {10,10}; |
| 1715 |
} |
| 1716 |
else if (val>=14 && val<=16) { |
| 1717 |
// changeme: double line 2-1-1, 1-1-2, 1-1-1 |
| 1718 |
style.m_lineWidth=val==16 ? 3 : 4; |
| 1719 |
f << "double[line],"; |
| 1720 |
} |
| 1721 |
else { |
| 1722 |
style.m_lineWidth=1; |
| 1723 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[%d]: find unknown line style\n", type)); |
| 1724 |
f << "###line[style]=" << val << ","; |
| 1725 |
} |
| 1726 |
if (style.m_lineWidth<1 || style.m_lineWidth>1) |
| 1727 |
f << "line[width]=" << style.m_lineWidth << ","; |
| 1728 |
val=int(input->readLong(1)); |
| 1729 |
if (val!=1) |
| 1730 |
f << "g0=" << val << ","; |
| 1731 |
|
| 1732 |
if (type==3) // fixme |
| 1733 |
style.m_lineWidth=0; |
| 1734 |
int numColors=(type<=2 || (type>=5 && type<=7)) ? 2 : 1; |
| 1735 |
int patIds[2]; |
| 1736 |
for (auto &p : patIds) p=int(input->readULong(1)); |
| 1737 |
int colIds[2]= {-1,-1}; |
| 1738 |
MWAWColor colors[2]= {MWAWColor::white(), MWAWColor::black()}; |
| 1739 |
for (int i=0; i<numColors; ++i) { |
| 1740 |
colIds[i]=int(input->readULong(2)); |
| 1741 |
int const expected[]= {7, 60}; |
| 1742 |
if (colIds[i]==(type==3 ? 60 : expected[i])) continue; |
| 1743 |
if (numColors==1) |
| 1744 |
f << "col="; |
| 1745 |
else |
| 1746 |
f << "col[" << (i==0 ? "surf" : "line") << "]="; |
| 1747 |
if (colIds[i]>0 && m_styleManager->getColor(colIds[i], colors[i])) |
| 1748 |
f << colors[i] << ","; |
| 1749 |
else { |
| 1750 |
f << "###" << colIds[i] << ","; |
| 1751 |
colIds[i]=-1; |
| 1752 |
} |
| 1753 |
} |
| 1754 |
for (int i=0; i<numColors; ++i) { |
| 1755 |
int tint=int(input->readLong(2)); |
| 1756 |
if (tint==10000) continue; |
| 1757 |
f << "tints[" << (i==0 ? "surf" : "line") << "]=" << float(tint)/100 << "%,"; |
| 1758 |
if (tint<0 || tint>10000) { |
| 1759 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: find bad tint\n")); |
| 1760 |
f << "###"; |
| 1761 |
continue; |
| 1762 |
} |
| 1763 |
colors[i]=MWAWColor::barycenter(float(10000-tint)/10000, MWAWColor::white(), float(tint)/10000, colors[i]); |
| 1764 |
} |
| 1765 |
val=int(input->readLong(2)); |
| 1766 |
if (val!=100) f << "g3=" << val << ","; |
| 1767 |
|
| 1768 |
switch (type) { |
| 1769 |
case 0: |
| 1770 |
case 1: |
| 1771 |
case 2: |
| 1772 |
case 5: |
| 1773 |
case 6: |
| 1774 |
case 7: { |
| 1775 |
if (type==1) { |
| 1776 |
int corner[2]; |
| 1777 |
for (auto &d : corner) d=int(input->readLong(2)); |
| 1778 |
shape.m_cornerSize=MWAWVec2i(corner[0], corner[1]); |
| 1779 |
f << "corner=" << shape.m_cornerSize << ","; |
| 1780 |
} |
| 1781 |
if (type==5) { // we must retrieve the line points |
| 1782 |
auto const &box=shape.m_box; |
| 1783 |
if (box.size()[0]>box.size()[1]) { |
| 1784 |
auto y=(box[0][1]+box[1][1])/2; |
| 1785 |
shape.m_points[0]=MWAWVec2f(box[0][0],y); |
| 1786 |
shape.m_points[1]=MWAWVec2f(box[1][0],y); |
| 1787 |
} |
| 1788 |
else { |
| 1789 |
auto x=(box[0][0]+box[1][0])/2; |
| 1790 |
shape.m_points[0]=MWAWVec2f(x,box[0][1]); |
| 1791 |
shape.m_points[1]=MWAWVec2f(x,box[1][1]); |
| 1792 |
} |
| 1793 |
} |
| 1794 |
if (type==6) { |
| 1795 |
float iDim[4]; |
| 1796 |
for (auto &d: iDim) d=float(input->readLong(2)); |
| 1797 |
shape.m_points[0]=MWAWVec2f(iDim[1],iDim[0]); |
| 1798 |
shape.m_points[1]=MWAWVec2f(iDim[3],iDim[2]); |
| 1799 |
f << "pos=" << shape.m_points[0] << "<->" << shape.m_points[1] << ","; |
| 1800 |
} |
| 1801 |
if (type==7) { |
| 1802 |
numPoints=int(input->readULong(2)); |
| 1803 |
f << "N=" << numPoints << ","; |
| 1804 |
val=int(input->readULong(2)); |
| 1805 |
if (val!=0x100) |
| 1806 |
f << "g4=" << val << ","; |
| 1807 |
auto ID=input->readULong(4); |
| 1808 |
if (ID) |
| 1809 |
f << "ID=" << std::hex << ID << std::dec << ","; |
| 1810 |
// checkme |
| 1811 |
} |
| 1812 |
// time to set the patterns/colors |
| 1813 |
if (patIds[0]!=nonePatId && (type!=5 && type!=6)) { |
| 1814 |
MWAWGraphicStyle::Pattern pat; |
| 1815 |
MWAWColor color; |
| 1816 |
if (!m_styleManager->getPattern(patIds[0]-1, pat)) |
| 1817 |
f << "##surface[color]=" << patIds[0] << ","; |
| 1818 |
else { |
| 1819 |
if (colIds[0]>=0) |
| 1820 |
pat.m_colors[0]=colors[0]; |
| 1821 |
if (pat.getUniqueColor(color)) { |
| 1822 |
style.setSurfaceColor(color); |
| 1823 |
f << "surface[color]=" << color << ","; |
| 1824 |
} |
| 1825 |
else { |
| 1826 |
style.setPattern(pat); |
| 1827 |
f << "surface[pat]=" << pat << ","; |
| 1828 |
} |
| 1829 |
} |
| 1830 |
} |
| 1831 |
if (patIds[1]==nonePatId) // transparent |
| 1832 |
style.m_lineWidth=0; |
| 1833 |
else { |
| 1834 |
MWAWGraphicStyle::Pattern pat; |
| 1835 |
MWAWColor color; |
| 1836 |
if (!m_styleManager->getPattern(patIds[1]-1, pat)) |
| 1837 |
f << "##line[color]=" << patIds[1] << ","; |
| 1838 |
else { |
| 1839 |
if (colIds[1]>=0) |
| 1840 |
pat.m_colors[0]=colors[1]; |
| 1841 |
if (pat.getAverageColor(style.m_lineColor)) |
| 1842 |
f << "line[color]=" << style.m_lineColor << ","; |
| 1843 |
else { |
| 1844 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[%d]: can not determine a shape color\n", type)); |
| 1845 |
f << "###line[color]=" << patIds[1] << ","; |
| 1846 |
} |
| 1847 |
} |
| 1848 |
} |
| 1849 |
break; |
| 1850 |
} |
| 1851 |
case 3: { |
| 1852 |
if (patIds[0]!=4) |
| 1853 |
f << "pattern[line]=" << patIds[0] << ","; |
| 1854 |
if (vers==6) { |
| 1855 |
val=int(input->readLong(2)); |
| 1856 |
if (val) f << "g4=" << val << ","; |
| 1857 |
} |
| 1858 |
val=int(input->readULong(4)); |
| 1859 |
if (val) { |
| 1860 |
f << "ID[pict]=" << std::hex << val << std::dec << ","; |
| 1861 |
++numPictures; |
| 1862 |
} |
| 1863 |
for (int i=0; i<(vers==6 ? 1 : 2); ++i) { |
| 1864 |
val=int(input->readLong(2)); |
| 1865 |
if (val) f << "g" << i+3 << "=" << val << ","; |
| 1866 |
} |
| 1867 |
int iDim[2]; // some multiples of 6, link to decal? |
| 1868 |
for (auto &d : iDim) d=int(input->readLong(2)); |
| 1869 |
if (iDim[0] || iDim[1]) |
| 1870 |
f << "crop=" << MWAWVec2i(iDim[1],iDim[0]) << ","; |
| 1871 |
for (int i=0; i<2; ++i) { |
| 1872 |
val=int(input->readULong(2)); |
| 1873 |
if (val!=100) |
| 1874 |
f << "scale" << (i==0 ? "X" : "Y") << "=" << val << "%,"; |
| 1875 |
} |
| 1876 |
long aPos=input->tell(); // checkme probably identical in v4.5 |
| 1877 |
std::string pictType; |
| 1878 |
for (int i=0; i<4; ++i) { |
| 1879 |
char c=char(input->readULong(1)); |
| 1880 |
if (!c) break; |
| 1881 |
pictType+=c; |
| 1882 |
} |
| 1883 |
if (!pictType.empty()) { |
| 1884 |
f << "type=" << pictType << ","; |
| 1885 |
++numPictures; |
| 1886 |
} |
| 1887 |
input->seek(aPos+4, librevenge::RVNG_SEEK_SET); |
| 1888 |
val=int(input->readLong(2)); |
| 1889 |
if (val) // run around graphic/frame?, g2&200 print as gray |
| 1890 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 1891 |
|
| 1892 |
long actPos=input->tell(); |
| 1893 |
libmwaw::DebugStream f2; |
| 1894 |
f2 << "Picture-A:"; |
| 1895 |
input->seek(actPos+314, librevenge::RVNG_SEEK_SET); |
| 1896 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1897 |
val=int(input->readULong(1)); |
| 1898 |
if (val) |
| 1899 |
f << "shape=" << val << ","; |
| 1900 |
ascFile.addPos(actPos); |
| 1901 |
ascFile.addNote(f2.str().c_str()); |
| 1902 |
break; |
| 1903 |
} |
| 1904 |
case 4: { |
| 1905 |
if (patIds[0]==nonePatId) // transparent |
| 1906 |
style.m_lineWidth=0; |
| 1907 |
else { |
| 1908 |
MWAWGraphicStyle::Pattern pat; |
| 1909 |
MWAWColor color; |
| 1910 |
if (!m_styleManager->getPattern(patIds[0]-1, pat)) |
| 1911 |
f << "##line[color]=" << patIds[0] << ","; |
| 1912 |
else { |
| 1913 |
if (colIds[0]>=0) |
| 1914 |
pat.m_colors[0]=colors[0]; |
| 1915 |
if (pat.getAverageColor(style.m_lineColor)) |
| 1916 |
f << "line[color]=" << style.m_lineColor << ","; |
| 1917 |
else { |
| 1918 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[%d]: can not determine a shape color\n", type)); |
| 1919 |
f << "###line[color]=" << patIds[0] << ","; |
| 1920 |
} |
| 1921 |
} |
| 1922 |
} |
| 1923 |
|
| 1924 |
val=int(input->readLong(2)); |
| 1925 |
if (val) |
| 1926 |
f << "h0=" << val << ","; |
| 1927 |
int backTint=int(input->readLong(2)); |
| 1928 |
if (backTint) f << "tint=" << float(backTint)/100 << "%,"; |
| 1929 |
if (backPatId==nonePatId) |
| 1930 |
break; |
| 1931 |
|
| 1932 |
MWAWColor color = MWAWColor::black(); |
| 1933 |
if (backColId!=60) |
| 1934 |
m_styleManager->getColor(backColId, color); |
| 1935 |
color=MWAWColor::barycenter(float(10000-backTint)/10000, MWAWColor::white(), float(backTint)/10000, color); |
| 1936 |
MWAWGraphicStyle::Pattern pat; |
| 1937 |
if (backPatId<1 || !m_styleManager->getPattern(backPatId-1, pat)) |
| 1938 |
style.setSurfaceColor(color); |
| 1939 |
else { |
| 1940 |
pat.m_colors[0]=color; |
| 1941 |
if (pat.getUniqueColor(color)) |
| 1942 |
style.setSurfaceColor(color); |
| 1943 |
else |
| 1944 |
style.setPattern(pat); |
| 1945 |
} |
| 1946 |
break; |
| 1947 |
} |
| 1948 |
default: |
| 1949 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[%d]: unexpected data\n", type)); |
| 1950 |
f << "###"; |
| 1951 |
break; |
| 1952 |
} |
| 1953 |
if (input->tell()!=pos+6+len) |
| 1954 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1955 |
ascFile.addPos(pos); |
| 1956 |
ascFile.addNote(f.str().c_str()); |
| 1957 |
input->seek(pos+6+len, librevenge::RVNG_SEEK_SET); |
| 1958 |
|
| 1959 |
for (int p=0; p<numPictures; ++p) { |
| 1960 |
pos=input->tell(); |
| 1961 |
len=long(input->readLong(4)); |
| 1962 |
if (len==0 && p==1) { // can happen in v7 files |
| 1963 |
ascFile.addPos(pos); |
| 1964 |
ascFile.addNote("_"); |
| 1965 |
continue; |
| 1966 |
} |
| 1967 |
if ((len&0xffff)<7 || !input->checkPosition(pos+4+len)) { |
| 1968 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1969 |
break; |
| 1970 |
} |
| 1971 |
shape.m_entries[p].setBegin(pos+4); |
| 1972 |
shape.m_entries[p].setLength(len); |
| 1973 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 1974 |
ascFile.addPos(pos); |
| 1975 |
ascFile.addNote("Picture-data:"); |
| 1976 |
} |
| 1977 |
if (numPoints) { // FIXME |
| 1978 |
pos=input->tell(); |
| 1979 |
len=long(input->readLong(4)); |
| 1980 |
if ((len&0xffff)<2 || !input->checkPosition(pos+4+len)) |
| 1981 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1982 |
else { |
| 1983 |
f.str(""); |
| 1984 |
f << "Polygon-point:"; |
| 1985 |
int len2=int(input->readLong(2)); |
| 1986 |
if (len2>len || 2+4*(2+numPoints)>len2) { |
| 1987 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: the number of points seems bad\n")); |
| 1988 |
f << "###"; |
| 1989 |
numPoints=0; |
| 1990 |
} |
| 1991 |
f << "box=["; |
| 1992 |
for (int i=0; i<2; ++i) { |
| 1993 |
int pts[2]; |
| 1994 |
for (auto &pt : pts) pt=int(input->readLong(2)); |
| 1995 |
f << MWAWVec2i(pts[1], pts[0]) << ","; |
| 1996 |
} |
| 1997 |
f << "],"; |
| 1998 |
f << "pts=["; |
| 1999 |
for (int i=0; i<numPoints; ++i) { |
| 2000 |
float pts[2]; |
| 2001 |
for (auto &pt : pts) pt=float(input->readLong(2)); |
| 2002 |
shape.m_vertices.push_back(MWAWVec2f(pts[1], pts[0])); |
| 2003 |
f << shape.m_vertices.back() << ","; |
| 2004 |
} |
| 2005 |
f << "],"; |
| 2006 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 2007 |
ascFile.addPos(pos); |
| 2008 |
ascFile.addNote(f.str().c_str()); |
| 2009 |
} |
| 2010 |
} |
| 2011 |
if (type==4) { |
| 2012 |
pos=input->tell(); |
| 2013 |
f.str(""); |
| 2014 |
f << "Text-limits:"; |
| 2015 |
if (!input->checkPosition(pos+8)) { |
| 2016 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6: can not find the text limits positions\n")); |
| 2017 |
f << "###"; |
| 2018 |
ascFile.addPos(pos); |
| 2019 |
ascFile.addNote(f.str().c_str()); |
| 2020 |
return false; |
| 2021 |
} |
| 2022 |
for (int i=0; i<2; ++i) { |
| 2023 |
shape.m_textPositions[i]=int(input->readLong(4)); |
| 2024 |
if (shape.m_textPositions[i]==0) continue; |
| 2025 |
f << (i==0 ? "min[pos]" : "max[pos]") << "=" << shape.m_textPositions[i] << ","; |
| 2026 |
} |
| 2027 |
ascFile.addPos(pos); |
| 2028 |
ascFile.addNote(f.str().c_str()); |
| 2029 |
} |
| 2030 |
if (type==4 && shape.m_linkIds[0]<0) { |
| 2031 |
for (int st=0; st<(!hasTabs ? 2 : 3); ++st) { |
| 2032 |
pos=input->tell(); |
| 2033 |
len=long(input->readLong(4)); |
| 2034 |
if (len<10 || (long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) { |
| 2035 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeV6[text]: can not find a shape length\n")); |
| 2036 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2037 |
f << "###"; |
| 2038 |
ascFile.addPos(pos); |
| 2039 |
ascFile.addNote("Text-####"); |
| 2040 |
return false; |
| 2041 |
} |
| 2042 |
shape.m_entries[st].setBegin(pos+4); |
| 2043 |
shape.m_entries[st].setLength(len); |
| 2044 |
ascFile.addPos(pos); |
| 2045 |
ascFile.addNote(st==0 ? "Text-text" : st==1 ? "Entries(Style):" : "Entries(Tabs):"); |
| 2046 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 2047 |
} |
| 2048 |
} |
| 2049 |
layout.m_shapes.push_back(shape); |
| 2050 |
return true; |
| 2051 |
} |
| 2052 |
|
| 2053 |
bool ReadySetGoGraph::readShapeDSV2(ReadySetGoGraphInternal::Layout &layout, bool &last) |
| 2054 |
{ |
| 2055 |
last=false; |
| 2056 |
MWAWInputStreamPtr input = m_parser.getInput(); |
| 2057 |
if (!input) |
| 2058 |
return false; |
| 2059 |
|
| 2060 |
int const vers=version(); |
| 2061 |
if (vers<6 || !m_parser.isDesignStudioFile()) { |
| 2062 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: unexpected version\n")); |
| 2063 |
return false; |
| 2064 |
} |
| 2065 |
long pos=input->tell(); |
| 2066 |
if (!input->checkPosition(pos+2)) { |
| 2067 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: can not read a shape\n")); |
| 2068 |
return false; |
| 2069 |
} |
| 2070 |
|
| 2071 |
auto &ascFile = m_parser.ascii(); |
| 2072 |
int type=int(input->readLong(2)); |
| 2073 |
if (type==-1) { |
| 2074 |
ascFile.addPos(pos); |
| 2075 |
ascFile.addNote("Layout-end:"); |
| 2076 |
last=true; |
| 2077 |
return true; |
| 2078 |
} |
| 2079 |
libmwaw::DebugStream f; |
| 2080 |
if (type<0 || type>7) { |
| 2081 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: the type seems bad\n")); |
| 2082 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2083 |
f << "Entries(Shape" << type << "):"; |
| 2084 |
f << "###"; |
| 2085 |
ascFile.addPos(pos); |
| 2086 |
ascFile.addNote(f.str().c_str()); |
| 2087 |
return false; |
| 2088 |
} |
| 2089 |
|
| 2090 |
long len=long(input->readLong(4)); |
| 2091 |
int const minSize[]= {0x7c, 0x80, 0x7c, 0x1ca, 0xc4, 0x84, 0x84, 0x84}; |
| 2092 |
if (len<minSize[type]-28 || (long)((unsigned long)pos+6+(unsigned long)len)<pos+6 || !input->checkPosition(pos+6+len)) { |
| 2093 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: can not find a shape length\n")); |
| 2094 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2095 |
f << "Entries(Shape" << type << "):"; |
| 2096 |
f << "###"; |
| 2097 |
ascFile.addPos(pos); |
| 2098 |
ascFile.addNote(f.str().c_str()); |
| 2099 |
return false; |
| 2100 |
} |
| 2101 |
static ReadySetGoGraphInternal::Shape::Type const shapeTypes[]= { |
| 2102 |
ReadySetGoGraphInternal::Shape::T_Rectangle, |
| 2103 |
ReadySetGoGraphInternal::Shape::T_RectOval, // + oval size |
| 2104 |
ReadySetGoGraphInternal::Shape::T_Oval, |
| 2105 |
ReadySetGoGraphInternal::Shape::T_Picture, |
| 2106 |
ReadySetGoGraphInternal::Shape::T_Text, |
| 2107 |
ReadySetGoGraphInternal::Shape::T_Line, |
| 2108 |
ReadySetGoGraphInternal::Shape::T_Line, |
| 2109 |
ReadySetGoGraphInternal::Shape::T_Polygon, |
| 2110 |
}; |
| 2111 |
// checkme can type=1 and type=6 exists |
| 2112 |
static char const *what[]= { "Rectangle", "RectOval", "Oval", "Picture", "Text", "Line" /* hv*/, "Line" /* not axis aligned*/, "Polygon" }; |
| 2113 |
f << "Entries(" << what[type] << "):"; |
| 2114 |
ReadySetGoGraphInternal::Shape shape(shapeTypes[type]); |
| 2115 |
f << "IDS=["; // next, prev |
| 2116 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 2117 |
f << "],"; |
| 2118 |
float dim[4]; |
| 2119 |
for (auto &d : dim) d=72*float(input->readLong(4))/65536; |
| 2120 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[0]+dim[2],dim[1]+dim[3])); |
| 2121 |
f << "box=" << shape.m_box << ","; |
| 2122 |
int val; |
| 2123 |
val=int(input->readULong(4)); |
| 2124 |
if (val!=0x1555) |
| 2125 |
f << "dist[text,repel]=" << float(val)/65536 << ",";; |
| 2126 |
val=int(input->readLong(1)); |
| 2127 |
if (val!=type) |
| 2128 |
f << "##type1=" << val << ","; |
| 2129 |
val=int(input->readLong(1)); |
| 2130 |
if (val==-1) |
| 2131 |
f << "selected,"; |
| 2132 |
else if (val) |
| 2133 |
f << "#selected=" << val << ","; |
| 2134 |
bool hasTabs=false; |
| 2135 |
int numPictures=0; |
| 2136 |
int numPoints=0; |
| 2137 |
val=int(input->readLong(1)); |
| 2138 |
if (val==-1) |
| 2139 |
f << "run[around],"; |
| 2140 |
else if (val) |
| 2141 |
f << "run[around]=" << val << ","; |
| 2142 |
val=int(input->readULong(1)); // only v4? |
| 2143 |
if (val&1) |
| 2144 |
f << "locked,"; |
| 2145 |
if (val&2) |
| 2146 |
f << "print[no],"; |
| 2147 |
if (val&4) { |
| 2148 |
f << "run[around],"; |
| 2149 |
shape.m_wrapRoundAround=true; |
| 2150 |
} |
| 2151 |
val &=0xf8; |
| 2152 |
if (val) |
| 2153 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 2154 |
auto &style=shape.m_style; |
| 2155 |
shape.m_rotate=int(input->readLong(2)); |
| 2156 |
if (shape.m_rotate) { |
| 2157 |
f << "rot=" << double(shape.m_rotate)/10 << ","; |
| 2158 |
style.m_rotate=float(shape.m_rotate)/10; |
| 2159 |
} |
| 2160 |
val=int(input->readULong(2)); |
| 2161 |
if (val&0x100) { |
| 2162 |
f << "flipY,"; |
| 2163 |
style.m_flip[1]=true; |
| 2164 |
} |
| 2165 |
if (val&0x200) { |
| 2166 |
f << "flipX,"; |
| 2167 |
style.m_flip[0]=true; |
| 2168 |
} |
| 2169 |
val&=0xfcff; |
| 2170 |
if (val) f << "f7" << "=" << std::hex << val << std::dec << ","; |
| 2171 |
for (auto &d : dim) d=float(input->readLong(2)); |
| 2172 |
if (dim[0]<dim[2] || dim[1]<dim[3]) |
| 2173 |
f << "box1=" << MWAWBox2f(MWAWVec2f(dim[1],dim[0]), MWAWVec2f(dim[3],dim[2])) << ","; |
| 2174 |
for (int i=0; i<2; ++i) { |
| 2175 |
val=int(input->readLong(2)); |
| 2176 |
if (val) f << "f" << 8+i << "=" << val << ","; |
| 2177 |
} |
| 2178 |
for (int i=0; i<2; ++i) { |
| 2179 |
for (auto &d : dim) d=float(input->readLong(2)); |
| 2180 |
if (dim[0]<dim[2] || dim[1]<dim[3]) |
| 2181 |
f << "box" << 2+i << "=" << MWAWBox2f(MWAWVec2f(dim[1],dim[0]), MWAWVec2f(dim[3],dim[2])) << ","; |
| 2182 |
} |
| 2183 |
for (int i=0; i<14; ++i) { |
| 2184 |
val=int(input->readLong(2)); |
| 2185 |
if (val) f << "f" << 10+i << "=" << val << ","; |
| 2186 |
} |
| 2187 |
shape.m_groupId=int(input->readLong(2)); |
| 2188 |
if (shape.m_groupId) f << "group=" << shape.m_groupId << ","; |
| 2189 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2190 |
input->seek(14, librevenge::RVNG_SEEK_CUR); // 0000002d003c0000002d003c0[12]00 12: maybe left/right page |
| 2191 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2192 |
val=int(input->readULong(4)); |
| 2193 |
if (val) |
| 2194 |
f << "ID[unk]=" << std::hex << val << std::dec << ","; |
| 2195 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2196 |
val=int(input->readLong(2)); |
| 2197 |
if (val!=60) // a color index |
| 2198 |
f << "g0=" << val << ","; |
| 2199 |
for (int i=0; i<2; ++i) { // g1=2-4, g2=0-3 |
| 2200 |
val=int(input->readULong(1)); |
| 2201 |
if (val!=(i==0 ? 4 : 0)) |
| 2202 |
f << "g" << i+1 << "=" << val << ","; |
| 2203 |
} |
| 2204 |
|
| 2205 |
int const nonePatId=48; |
| 2206 |
int backColId=60; |
| 2207 |
int backPatId=nonePatId; |
| 2208 |
if (type==4) { |
| 2209 |
f << "IDS1=["; // next, prev |
| 2210 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ","; |
| 2211 |
f << "],"; |
| 2212 |
val=int(input->readULong(4)); |
| 2213 |
if (val) { |
| 2214 |
f << "tab[ID]=" << std::hex << val << std::dec << ","; |
| 2215 |
hasTabs=true; |
| 2216 |
} |
| 2217 |
f << "id=" << input->readLong(2) << ","; // 1-f |
| 2218 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; |
| 2219 |
int tDim[4]; |
| 2220 |
for (auto &d : tDim) d=int(input->readLong(2)); |
| 2221 |
f << "unkn=" << MWAWBox2i(MWAWVec2i(tDim[0],tDim[1]),MWAWVec2i(tDim[2],tDim[3])) << ","; |
| 2222 |
for (int i=0; i<5; ++i) { |
| 2223 |
val=int(input->readLong(2)); |
| 2224 |
if (!val) continue; |
| 2225 |
f << "f" << i+2 << "=" << val << ","; |
| 2226 |
} |
| 2227 |
val=int(input->readULong(2)); |
| 2228 |
if (val&0x4) |
| 2229 |
f << "postscript,"; |
| 2230 |
if (val&0x10) // useme: basically the text is hidden |
| 2231 |
f << "white[type],"; |
| 2232 |
if (val&0x20) |
| 2233 |
f << "ignore[run,around],"; |
| 2234 |
val&=0xffdb; |
| 2235 |
if (val) |
| 2236 |
f << "fl1=" << std::hex << val << std::dec << ","; |
| 2237 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2238 |
input->seek(pos+76+88, librevenge::RVNG_SEEK_SET); |
| 2239 |
ascFile.addDelimiter(input->tell(),'@'); |
| 2240 |
shape.m_textId=int(input->readLong(2)); |
| 2241 |
f << "text[id]=" << shape.m_textId << ","; |
| 2242 |
for (int i=0; i<2; ++i) { |
| 2243 |
shape.m_linkIds[i]=int(input->readLong(2)); |
| 2244 |
if (shape.m_linkIds[i]==-1) |
| 2245 |
continue; |
| 2246 |
f << (i==0 ? "prev" : "next") << "[link]=" << shape.m_linkIds[i] << ","; |
| 2247 |
} |
| 2248 |
for (int i=0; i<2; ++i) { |
| 2249 |
val=int(input->readLong(2)); |
| 2250 |
if (val!=-1) |
| 2251 |
f << "g" << i << "=" << val << ","; |
| 2252 |
} |
| 2253 |
ascFile.addDelimiter(input->tell(),'@'); |
| 2254 |
bool hasBackPattern=false; |
| 2255 |
uint8_t backPattern[8]; |
| 2256 |
for (auto &p : backPattern) { |
| 2257 |
p=uint8_t(input->readULong(1)); |
| 2258 |
if (p) hasBackPattern=true; |
| 2259 |
} |
| 2260 |
if (hasBackPattern) { |
| 2261 |
f << "back[pat]=["; |
| 2262 |
for (auto const &p : backPattern) f << std::hex << int(p) << std::dec << ","; |
| 2263 |
f << "],"; |
| 2264 |
} |
| 2265 |
backColId=int(input->readLong(2)); |
| 2266 |
if (backColId!=60) |
| 2267 |
f << "back[col,id]=" << backColId << ","; |
| 2268 |
backPatId=int(input->readULong(1)); |
| 2269 |
if (backPatId!=nonePatId) |
| 2270 |
f << "back[pat,id]=" << backPatId << ","; |
| 2271 |
input->seek(1, librevenge::RVNG_SEEK_CUR); |
| 2272 |
for (int i=0; i<3; ++i) { |
| 2273 |
val=int(input->readLong(2)); |
| 2274 |
if (!val) |
| 2275 |
continue; |
| 2276 |
f << "g" << i+2 << "=" << val << ","; |
| 2277 |
} |
| 2278 |
val=int(input->readLong(1)); |
| 2279 |
switch (val) { |
| 2280 |
case 0: // top |
| 2281 |
break; |
| 2282 |
case 1: |
| 2283 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignBottom; |
| 2284 |
f << "vAlign=bottom,"; |
| 2285 |
break; |
| 2286 |
case 2: |
| 2287 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignCenter; |
| 2288 |
f << "vAlign=center,"; |
| 2289 |
break; |
| 2290 |
case 3: |
| 2291 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 2292 |
f << "vAlign=justify[feathering],"; |
| 2293 |
break; |
| 2294 |
case 4: |
| 2295 |
style.m_verticalAlignment=MWAWGraphicStyle::V_AlignJustify; |
| 2296 |
f << "vAlign=justify[paragraph],"; |
| 2297 |
break; |
| 2298 |
default: |
| 2299 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[text]: unknown vertical alignment\n")); |
| 2300 |
f << "##vAlign=" << val << ","; |
| 2301 |
break; |
| 2302 |
} |
| 2303 |
val=int(input->readLong(1)); |
| 2304 |
if (val) f << "h0=" << val << ","; |
| 2305 |
} |
| 2306 |
val=int(input->readLong(1)); |
| 2307 |
int width=int(input->readULong(1)); |
| 2308 |
if (val>=0 && val<=8) { |
| 2309 |
float const w[]= {0.125f, 0.25f, 0.5f, 0.75f, 1, 2, 4, 6, 8}; |
| 2310 |
style.m_lineWidth=w[val]; |
| 2311 |
} |
| 2312 |
else if (val==9) |
| 2313 |
style.m_lineWidth=float(width); |
| 2314 |
else if (val>=11 && val<=14) { |
| 2315 |
float const w[]= {1, 2, 4, 6, 8}; |
| 2316 |
style.m_lineWidth=w[val-11]; |
| 2317 |
f << "dash,"; |
| 2318 |
style.m_lineDashWidth= {10,10}; |
| 2319 |
} |
| 2320 |
else if (val>=16 && val<=18) { |
| 2321 |
// changeme: double line 2-1-1, 1-1-2, 1-1-1 |
| 2322 |
style.m_lineWidth=val==18 ? 3 : 4; |
| 2323 |
f << "double[line],"; |
| 2324 |
} |
| 2325 |
else { |
| 2326 |
style.m_lineWidth=1; |
| 2327 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[%d]: find unknown line style\n", type)); |
| 2328 |
f << "###line[style]=" << val << "[" << width << "],"; |
| 2329 |
} |
| 2330 |
if (style.m_lineWidth<1 || style.m_lineWidth>1) |
| 2331 |
f << "line[width]=" << style.m_lineWidth << ","; |
| 2332 |
|
| 2333 |
if (type==3) // fixme |
| 2334 |
style.m_lineWidth=0; |
| 2335 |
int numColors=(type<=2 || (type>=5 && type<=7)) ? 2 : 1; |
| 2336 |
int patIds[2]; // 31 1 |
| 2337 |
for (auto &p : patIds) p=int(input->readULong(1)); |
| 2338 |
int colIds[2]= {-1,-1}; |
| 2339 |
MWAWColor colors[2]= {MWAWColor::white(), MWAWColor::black()}; |
| 2340 |
for (int i=0; i<numColors; ++i) { |
| 2341 |
colIds[i]=int(input->readULong(2)); |
| 2342 |
int const expected[]= {7, 60}; |
| 2343 |
if (colIds[i]==(type==3 ? 60 : expected[i])) continue; |
| 2344 |
if (numColors==1) |
| 2345 |
f << "col="; |
| 2346 |
else |
| 2347 |
f << "col[" << (i==0 ? "surf" : "line") << "]="; |
| 2348 |
if (colIds[i]>0 && m_styleManager->getColor(colIds[i], colors[i])) |
| 2349 |
f << colors[i] << ","; |
| 2350 |
else { |
| 2351 |
f << "###" << colIds[i] << ","; |
| 2352 |
colIds[i]=-1; |
| 2353 |
} |
| 2354 |
} |
| 2355 |
|
| 2356 |
switch (type) { |
| 2357 |
case 0: |
| 2358 |
case 1: |
| 2359 |
case 2: |
| 2360 |
case 5: |
| 2361 |
case 6: |
| 2362 |
case 7: { |
| 2363 |
if (type==1) { |
| 2364 |
int corner[2]; |
| 2365 |
for (auto &d : corner) d=int(input->readLong(2)); |
| 2366 |
shape.m_cornerSize=MWAWVec2i(corner[0], corner[1]); |
| 2367 |
f << "corner=" << shape.m_cornerSize << ","; |
| 2368 |
} |
| 2369 |
if (type==5) { // we must retrieve the line points |
| 2370 |
auto const &box=shape.m_box; |
| 2371 |
if (box.size()[0]>box.size()[1]) { |
| 2372 |
auto y=(box[0][1]+box[1][1])/2; |
| 2373 |
shape.m_points[0]=MWAWVec2f(box[0][0],y); |
| 2374 |
shape.m_points[1]=MWAWVec2f(box[1][0],y); |
| 2375 |
} |
| 2376 |
else { |
| 2377 |
auto x=(box[0][0]+box[1][0])/2; |
| 2378 |
shape.m_points[0]=MWAWVec2f(x,box[0][1]); |
| 2379 |
shape.m_points[1]=MWAWVec2f(x,box[1][1]); |
| 2380 |
} |
| 2381 |
int arrowDim[3]; |
| 2382 |
for (auto &d: arrowDim) d=int(input->readLong(2)); |
| 2383 |
if (arrowDim[1]!=20 || arrowDim[2]!=10) |
| 2384 |
f << "arrow[pt0]=" << MWAWVec2i(arrowDim[1], arrowDim[2]) << ","; |
| 2385 |
if (arrowDim[0]!=20) |
| 2386 |
f << "arrow[pt1]=" << MWAWVec2i(arrowDim[0], 0) << ","; |
| 2387 |
float w=float(std::max<int>(5,arrowDim[2])); |
| 2388 |
val=int(input->readULong(2)); |
| 2389 |
MWAWGraphicStyle::Arrow arrow; |
| 2390 |
if (val&4) { |
| 2391 |
// changeme normally the polygon is defined by O, pt0, pt1, arrowDim[1]x-arrowDim[2] |
| 2392 |
f << "bound[arrow,only],"; |
| 2393 |
arrow=MWAWGraphicStyle::Arrow(w, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(1122,2243)), "M0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z", false); |
| 2394 |
} |
| 2395 |
else { |
| 2396 |
bool ok=true; |
| 2397 |
for (auto const &d : arrowDim) { |
| 2398 |
if (d<=0) ok=false; |
| 2399 |
} |
| 2400 |
if (ok) { |
| 2401 |
std::stringstream s; |
| 2402 |
s << "M " << arrowDim[2] << " 0 " |
| 2403 |
<< 2*arrowDim[2] << " " << arrowDim[1] << " " |
| 2404 |
<< arrowDim[2] << " " << arrowDim[0] << " " |
| 2405 |
<< "0 " << arrowDim[1] << "z"; |
| 2406 |
arrow=MWAWGraphicStyle::Arrow(float(arrowDim[2]), MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(2*arrowDim[2],std::max(arrowDim[0],arrowDim[1]))), s.str(), false); |
| 2407 |
} |
| 2408 |
else |
| 2409 |
arrow=MWAWGraphicStyle::Arrow(w, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(20,30)), "m10 0l-10 30h20z", false); |
| 2410 |
} |
| 2411 |
if (val&1) { |
| 2412 |
style.m_arrows[0]=arrow; |
| 2413 |
f << "arrow[beg],"; |
| 2414 |
} |
| 2415 |
if (val&2) { |
| 2416 |
style.m_arrows[1]=arrow; |
| 2417 |
f << "arrow[end],"; |
| 2418 |
} |
| 2419 |
val&=0xfff8; |
| 2420 |
if (val) |
| 2421 |
f << "arrow[fl]=" << std::hex << val << std::dec << ","; |
| 2422 |
} |
| 2423 |
if (type==6) { |
| 2424 |
float iDim[4]; |
| 2425 |
for (auto &d: iDim) d=float(input->readLong(2)); |
| 2426 |
shape.m_points[0]=MWAWVec2f(iDim[1],iDim[0]); |
| 2427 |
shape.m_points[1]=MWAWVec2f(iDim[3],iDim[2]); |
| 2428 |
f << "pos=" << shape.m_points[0] << "<->" << shape.m_points[1] << ","; |
| 2429 |
} |
| 2430 |
if (type==7) { |
| 2431 |
numPoints=int(input->readULong(2)); |
| 2432 |
f << "N=" << numPoints << ","; |
| 2433 |
val=int(input->readULong(2)); |
| 2434 |
if (val!=0x100) |
| 2435 |
f << "g4=" << val << ","; |
| 2436 |
auto ID=input->readULong(4); |
| 2437 |
if (ID) |
| 2438 |
f << "ID=" << std::hex << ID << std::dec << ","; |
| 2439 |
// checkme |
| 2440 |
} |
| 2441 |
// time to set the patterns/colors |
| 2442 |
if (patIds[0]!=nonePatId && (type!=5 && type!=6)) { |
| 2443 |
MWAWGraphicStyle::Pattern pat; |
| 2444 |
MWAWColor color; |
| 2445 |
if (!m_styleManager->getPattern(patIds[0]-1, pat)) |
| 2446 |
f << "##surface[color]=" << patIds[0] << ","; |
| 2447 |
else { |
| 2448 |
if (colIds[0]>=0) |
| 2449 |
pat.m_colors[0]=colors[0]; |
| 2450 |
if (pat.getUniqueColor(color)) { |
| 2451 |
style.setSurfaceColor(color); |
| 2452 |
f << "surface[color]=" << color << ","; |
| 2453 |
} |
| 2454 |
else { |
| 2455 |
style.setPattern(pat); |
| 2456 |
f << "surface[pat]=" << pat << ","; |
| 2457 |
} |
| 2458 |
} |
| 2459 |
} |
| 2460 |
if (patIds[1]==nonePatId) // transparent |
| 2461 |
style.m_lineWidth=0; |
| 2462 |
else { |
| 2463 |
MWAWGraphicStyle::Pattern pat; |
| 2464 |
MWAWColor color; |
| 2465 |
if (!m_styleManager->getPattern(patIds[1]-1, pat)) |
| 2466 |
f << "##line[color]=" << patIds[1] << ","; |
| 2467 |
else { |
| 2468 |
if (colIds[1]>=0) |
| 2469 |
pat.m_colors[0]=colors[1]; |
| 2470 |
if (pat.getAverageColor(style.m_lineColor)) |
| 2471 |
f << "line[color]=" << style.m_lineColor << ","; |
| 2472 |
else { |
| 2473 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[%d]: can not determine a shape color\n", type)); |
| 2474 |
f << "###line[color]=" << patIds[1] << ","; |
| 2475 |
} |
| 2476 |
} |
| 2477 |
} |
| 2478 |
break; |
| 2479 |
} |
| 2480 |
case 3: { |
| 2481 |
if (patIds[0]!=4) |
| 2482 |
f << "pattern[line]=" << patIds[0] << ","; |
| 2483 |
if (vers==6) { |
| 2484 |
val=int(input->readLong(2)); |
| 2485 |
if (val) f << "g4=" << val << ","; |
| 2486 |
} |
| 2487 |
val=int(input->readULong(2)); |
| 2488 |
if (val) { |
| 2489 |
f << "num[pict]=" << val << ","; |
| 2490 |
++numPictures; |
| 2491 |
} |
| 2492 |
auto ID=int(input->readULong(4)); |
| 2493 |
if (ID) |
| 2494 |
f << "ID[pict]=" << std::hex << ID << std::dec << ","; |
| 2495 |
int iDim[2]; // some multiples of 6, link to decal? |
| 2496 |
for (auto &d : iDim) d=int(input->readLong(2)); |
| 2497 |
if (iDim[0] || iDim[1]) |
| 2498 |
f << "crop=" << MWAWVec2i(iDim[1],iDim[0]) << ","; |
| 2499 |
for (int i=0; i<2; ++i) { |
| 2500 |
val=int(input->readULong(2)); |
| 2501 |
if (val!=100) |
| 2502 |
f << "scale" << (i==0 ? "X" : "Y") << "=" << val << "%,"; |
| 2503 |
} |
| 2504 |
long aPos=input->tell(); // checkme probably identical in v4.5 |
| 2505 |
std::string pictType; |
| 2506 |
for (int i=0; i<4; ++i) { |
| 2507 |
char c=char(input->readULong(1)); |
| 2508 |
if (!c) break; |
| 2509 |
pictType+=c; |
| 2510 |
} |
| 2511 |
if (!pictType.empty()) |
| 2512 |
f << "type=" << pictType << ","; |
| 2513 |
input->seek(aPos+4, librevenge::RVNG_SEEK_SET); |
| 2514 |
val=int(input->readULong(2)); |
| 2515 |
if (val) // run around graphic/frame?, g2&200 print as gray |
| 2516 |
f << "fl=" << std::hex << val << std::dec << ","; |
| 2517 |
|
| 2518 |
long actPos=input->tell(); |
| 2519 |
libmwaw::DebugStream f2; |
| 2520 |
f2 << "Picture-A:"; |
| 2521 |
int cPos=int(input->readULong(1)); |
| 2522 |
std::string name; |
| 2523 |
if (cPos>=32) { |
| 2524 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[pict]: can not read the filename\n")); |
| 2525 |
f2 << "###filename"; |
| 2526 |
cPos=0; |
| 2527 |
} |
| 2528 |
for (int i=0; i<cPos; ++i) { |
| 2529 |
char c=char(input->readULong(1)); |
| 2530 |
if (!c) break; |
| 2531 |
name+=c; |
| 2532 |
} |
| 2533 |
if (!name.empty()) |
| 2534 |
f2 << "file=" << name << ","; |
| 2535 |
input->seek(actPos+314, librevenge::RVNG_SEEK_SET); |
| 2536 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2537 |
val=int(input->readULong(1)); |
| 2538 |
if (val) |
| 2539 |
f << "shape=" << val << ","; |
| 2540 |
ascFile.addPos(actPos); |
| 2541 |
ascFile.addNote(f2.str().c_str()); |
| 2542 |
break; |
| 2543 |
} |
| 2544 |
case 4: { |
| 2545 |
if (patIds[0]==nonePatId) // transparent |
| 2546 |
style.m_lineWidth=0; |
| 2547 |
else { |
| 2548 |
MWAWGraphicStyle::Pattern pat; |
| 2549 |
MWAWColor color; |
| 2550 |
if (!m_styleManager->getPattern(patIds[0]-1, pat)) |
| 2551 |
f << "##line[color]=" << patIds[0] << ","; |
| 2552 |
else { |
| 2553 |
if (colIds[0]>=0) |
| 2554 |
pat.m_colors[0]=colors[0]; |
| 2555 |
if (pat.getAverageColor(style.m_lineColor)) |
| 2556 |
f << "line[color]=" << style.m_lineColor << ","; |
| 2557 |
else { |
| 2558 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[%d]: can not determine a shape color\n", type)); |
| 2559 |
f << "###line[color]=" << patIds[0] << ","; |
| 2560 |
} |
| 2561 |
} |
| 2562 |
} |
| 2563 |
|
| 2564 |
if (backPatId==nonePatId) |
| 2565 |
break; |
| 2566 |
|
| 2567 |
MWAWColor color = MWAWColor::black(); |
| 2568 |
if (backColId!=60) |
| 2569 |
m_styleManager->getColor(backColId, color); |
| 2570 |
MWAWGraphicStyle::Pattern pat; |
| 2571 |
if (backPatId<1 || !m_styleManager->getPattern(backPatId-1, pat)) |
| 2572 |
style.setSurfaceColor(color); |
| 2573 |
else { |
| 2574 |
pat.m_colors[0]=color; |
| 2575 |
if (pat.getUniqueColor(color)) |
| 2576 |
style.setSurfaceColor(color); |
| 2577 |
else |
| 2578 |
style.setPattern(pat); |
| 2579 |
} |
| 2580 |
break; |
| 2581 |
} |
| 2582 |
default: |
| 2583 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[%d]: unexpected data\n", type)); |
| 2584 |
f << "###"; |
| 2585 |
break; |
| 2586 |
} |
| 2587 |
if (input->tell()!=pos+6+len) |
| 2588 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2589 |
ascFile.addPos(pos); |
| 2590 |
ascFile.addNote(f.str().c_str()); |
| 2591 |
input->seek(pos+6+len, librevenge::RVNG_SEEK_SET); |
| 2592 |
|
| 2593 |
for (int p=0; p<numPictures; ++p) { |
| 2594 |
pos=input->tell(); |
| 2595 |
len=long(input->readLong(4)); |
| 2596 |
if ((len&0xffff)<7 || !input->checkPosition(pos+4+len)) { |
| 2597 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2598 |
break; |
| 2599 |
} |
| 2600 |
shape.m_entries[p].setBegin(pos+4); |
| 2601 |
shape.m_entries[p].setLength(len); |
| 2602 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 2603 |
ascFile.addPos(pos); |
| 2604 |
ascFile.addNote("Picture-data:"); |
| 2605 |
} |
| 2606 |
if (numPoints) { // FIXME |
| 2607 |
pos=input->tell(); |
| 2608 |
len=long(input->readLong(4)); |
| 2609 |
if ((len&0xffff)<2 || !input->checkPosition(pos+4+len)) |
| 2610 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2611 |
else { |
| 2612 |
f.str(""); |
| 2613 |
f << "Polygon-point:"; |
| 2614 |
int len2=int(input->readLong(2)); |
| 2615 |
if (len2>len || 2+4*(2+numPoints)>len2) { |
| 2616 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: the number of points seems bad\n")); |
| 2617 |
f << "###"; |
| 2618 |
numPoints=0; |
| 2619 |
} |
| 2620 |
f << "box=["; |
| 2621 |
for (int i=0; i<2; ++i) { |
| 2622 |
int pts[2]; |
| 2623 |
for (auto &pt : pts) pt=int(input->readLong(2)); |
| 2624 |
f << MWAWVec2i(pts[1], pts[0]) << ","; |
| 2625 |
} |
| 2626 |
f << "],"; |
| 2627 |
f << "pts=["; |
| 2628 |
for (int i=0; i<numPoints; ++i) { |
| 2629 |
float pts[2]; |
| 2630 |
for (auto &pt : pts) pt=float(input->readLong(2)); |
| 2631 |
shape.m_vertices.push_back(MWAWVec2f(pts[1], pts[0])); |
| 2632 |
f << shape.m_vertices.back() << ","; |
| 2633 |
} |
| 2634 |
f << "],"; |
| 2635 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 2636 |
ascFile.addPos(pos); |
| 2637 |
ascFile.addNote(f.str().c_str()); |
| 2638 |
} |
| 2639 |
} |
| 2640 |
if (type==4) { |
| 2641 |
pos=input->tell(); |
| 2642 |
f.str(""); |
| 2643 |
f << "Text-limits:"; |
| 2644 |
if (!input->checkPosition(pos+8)) { |
| 2645 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2: can not find the text limits positions\n")); |
| 2646 |
f << "###"; |
| 2647 |
ascFile.addPos(pos); |
| 2648 |
ascFile.addNote(f.str().c_str()); |
| 2649 |
return false; |
| 2650 |
} |
| 2651 |
for (int i=0; i<2; ++i) { |
| 2652 |
shape.m_textPositions[i]=int(input->readLong(4)); |
| 2653 |
if (shape.m_textPositions[i]==0) continue; |
| 2654 |
f << (i==0 ? "min[pos]" : "max[pos]") << "=" << shape.m_textPositions[i] << ","; |
| 2655 |
} |
| 2656 |
ascFile.addPos(pos); |
| 2657 |
ascFile.addNote(f.str().c_str()); |
| 2658 |
} |
| 2659 |
if (type==4 && shape.m_linkIds[0]<0) { |
| 2660 |
for (int st=0; st<(!hasTabs ? 2 : 3); ++st) { |
| 2661 |
pos=input->tell(); |
| 2662 |
len=long(input->readLong(4)); |
| 2663 |
if (len<10 || (long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) { |
| 2664 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::readShapeDSV2[text]: can not find a shape length\n")); |
| 2665 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2666 |
f << "###"; |
| 2667 |
ascFile.addPos(pos); |
| 2668 |
ascFile.addNote("Text-####"); |
| 2669 |
return false; |
| 2670 |
} |
| 2671 |
shape.m_entries[st].setBegin(pos+4); |
| 2672 |
shape.m_entries[st].setLength(len); |
| 2673 |
ascFile.addPos(pos); |
| 2674 |
ascFile.addNote(st==0 ? "Text-text" : st==1 ? "Entries(Style):" : "Entries(Tabs):"); |
| 2675 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 2676 |
} |
| 2677 |
} |
| 2678 |
layout.m_shapes.push_back(shape); |
| 2679 |
return true; |
| 2680 |
} |
| 2681 |
|
| 2682 |
//////////////////////////////////////////////////////////// |
| 2683 |
// send data |
| 2684 |
//////////////////////////////////////////////////////////// |
| 2685 |
bool ReadySetGoGraph::sendMasterPages() |
| 2686 |
{ |
| 2687 |
auto listener=m_parser.getGraphicListener(); |
| 2688 |
if (!listener) { |
| 2689 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendMasterPages: can not find the listener\n")); |
| 2690 |
return false; |
| 2691 |
} |
| 2692 |
int const vers=version(); |
| 2693 |
if (vers<3) |
| 2694 |
return true; |
| 2695 |
bool const sharedList=vers<6 || (vers==6 && m_parser.isDesignStudioFile()); |
| 2696 |
auto const &layouts = sharedList ? m_state->m_layouts : m_state->m_masterLayouts; |
| 2697 |
size_t const numMaster=sharedList ? std::min<size_t>(2,layouts.size()) : layouts.size(); |
| 2698 |
for (size_t layout=0; layout<numMaster; ++layout) { |
| 2699 |
if (layouts[layout].m_shapes.empty()) |
| 2700 |
continue; |
| 2701 |
MWAWPageSpan ps(m_parser.getPageSpan()); |
| 2702 |
librevenge::RVNGString name; |
| 2703 |
name.sprintf("MasterPage%d", int(layout)); |
| 2704 |
ps.setMasterPageName(name); |
| 2705 |
if (!listener->openMasterPage(ps)) { |
| 2706 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendMasterPages: can not create the master page\n")); |
| 2707 |
} |
| 2708 |
else { |
| 2709 |
send(layouts[layout]); |
| 2710 |
listener->closeMasterPage(); |
| 2711 |
} |
| 2712 |
} |
| 2713 |
return true; |
| 2714 |
} |
| 2715 |
|
| 2716 |
bool ReadySetGoGraph::sendPages() |
| 2717 |
{ |
| 2718 |
auto listener=m_parser.getGraphicListener(); |
| 2719 |
if (!listener) { |
| 2720 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendPages: can not find the listener\n")); |
| 2721 |
return false; |
| 2722 |
} |
| 2723 |
bool firstPage=true; |
| 2724 |
int const vers=version(); |
| 2725 |
for (size_t layout=(vers<3 ? 0 : 2); layout<m_state->m_layouts.size(); ++layout) { |
| 2726 |
if (!firstPage) |
| 2727 |
listener->insertBreak(MWAWListener::PageBreak); |
| 2728 |
send(m_state->m_layouts[layout]); |
| 2729 |
firstPage=false; |
| 2730 |
} |
| 2731 |
return true; |
| 2732 |
} |
| 2733 |
|
| 2734 |
bool ReadySetGoGraph::send(ReadySetGoGraphInternal::Layout const &layout) |
| 2735 |
{ |
| 2736 |
auto listener=m_parser.getGraphicListener(); |
| 2737 |
if (!listener) { |
| 2738 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::send[layout]: can not find the listener\n")); |
| 2739 |
return false; |
| 2740 |
} |
| 2741 |
for (size_t i=0; i<layout.m_shapes.size();) { |
| 2742 |
auto const &shape=layout.m_shapes[i]; |
| 2743 |
if (shape.m_groupId>0) { |
| 2744 |
int group=shape.m_groupId; |
| 2745 |
if (i+1<layout.m_shapes.size() && layout.m_shapes[i+1].m_groupId==group) { |
| 2746 |
MWAWPosition pos(shape.m_box[0], shape.m_box.size(), librevenge::RVNG_POINT); |
| 2747 |
pos.setRelativePosition(MWAWPosition::Page); |
| 2748 |
if (listener->openGroup(pos)) { |
| 2749 |
while (i<layout.m_shapes.size() && layout.m_shapes[i].m_groupId==group) |
| 2750 |
send(layout.m_shapes[i++]); |
| 2751 |
listener->closeGroup(); |
| 2752 |
continue; |
| 2753 |
} |
| 2754 |
} |
| 2755 |
} |
| 2756 |
++i; |
| 2757 |
send(shape); |
| 2758 |
} |
| 2759 |
return true; |
| 2760 |
} |
| 2761 |
|
| 2762 |
bool ReadySetGoGraph::send(ReadySetGoGraphInternal::Shape const &shape) |
| 2763 |
{ |
| 2764 |
auto input=m_parser.getInput(); |
| 2765 |
auto listener=m_parser.getGraphicListener(); |
| 2766 |
if (!input || !listener) { |
| 2767 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::send: can not find the listener\n")); |
| 2768 |
return false; |
| 2769 |
} |
| 2770 |
MWAWPosition pos(shape.m_box[0], shape.m_box.size(), librevenge::RVNG_POINT); |
| 2771 |
pos.setRelativePosition(MWAWPosition::Page); |
| 2772 |
if (shape.m_wrapRoundAround) |
| 2773 |
pos.m_wrapping=MWAWPosition::WDynamic; |
| 2774 |
MWAWGraphicShape gShape; |
| 2775 |
switch (shape.m_type) { |
| 2776 |
case ReadySetGoGraphInternal::Shape::T_Empty: |
| 2777 |
return true; |
| 2778 |
case ReadySetGoGraphInternal::Shape::T_Text: { |
| 2779 |
auto subdoc=std::make_shared<ReadySetGoGraphInternal::SubDocument>(*this, input, shape); |
| 2780 |
listener->insertTextBox(pos, subdoc, shape.m_style); |
| 2781 |
return true; |
| 2782 |
} |
| 2783 |
case ReadySetGoGraphInternal::Shape::T_Line: |
| 2784 |
gShape=MWAWGraphicShape::line(shape.m_box[0]+shape.m_points[0], shape.m_box[0]+shape.m_points[1]); |
| 2785 |
break; |
| 2786 |
case ReadySetGoGraphInternal::Shape::T_Oval: |
| 2787 |
gShape=MWAWGraphicShape::circle(shape.m_box); |
| 2788 |
break; |
| 2789 |
case ReadySetGoGraphInternal::Shape::T_Rectangle: |
| 2790 |
gShape=MWAWGraphicShape::rectangle(shape.m_box); |
| 2791 |
break; |
| 2792 |
case ReadySetGoGraphInternal::Shape::T_RectOval: |
| 2793 |
gShape=MWAWGraphicShape::rectangle(shape.m_box, shape.m_cornerSize[0]>=0 ? 0.5f*MWAWVec2f(float(shape.m_cornerSize[0]), float(shape.m_cornerSize[1])) |
| 2794 |
: 0.25f*shape.m_box.size()); |
| 2795 |
break; |
| 2796 |
case ReadySetGoGraphInternal::Shape::T_Polygon: |
| 2797 |
if (shape.m_vertices.size()<2) { |
| 2798 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::send[polygon]: sorry, the number of points seem bad\n")); |
| 2799 |
return false; |
| 2800 |
} |
| 2801 |
if (shape.m_style.hasSurface()) |
| 2802 |
gShape=MWAWGraphicShape::polygon(shape.m_box); |
| 2803 |
else |
| 2804 |
gShape=MWAWGraphicShape::polyline(shape.m_box); |
| 2805 |
gShape.m_vertices=shape.m_vertices; |
| 2806 |
break; |
| 2807 |
case ReadySetGoGraphInternal::Shape::T_Picture: { |
| 2808 |
if (!shape.m_entries[0].valid() || !input->checkPosition(shape.m_entries[0].end())) { |
| 2809 |
MWAWGraphicStyle style; |
| 2810 |
listener->openGroup(pos); |
| 2811 |
for (int w=0; w<3; ++w) { |
| 2812 |
if (w==0) |
| 2813 |
gShape=MWAWGraphicShape::rectangle(shape.m_box); |
| 2814 |
else if (w==1) |
| 2815 |
gShape=MWAWGraphicShape::line(shape.m_box[0],shape.m_box[1]); |
| 2816 |
else |
| 2817 |
gShape=MWAWGraphicShape::line(MWAWVec2f(shape.m_box[0][0],shape.m_box[1][1]), MWAWVec2f(shape.m_box[1][0],shape.m_box[0][1])); |
| 2818 |
if (shape.m_rotate) { |
| 2819 |
gShape=gShape.rotate(float(shape.m_rotate)/10, shape.m_box.center()); |
| 2820 |
auto box=gShape.getBdBox(shape.m_style); |
| 2821 |
pos.setOrigin(box[0]); |
| 2822 |
pos.setSize(box.size()); |
| 2823 |
} |
| 2824 |
if (shape.m_style.m_flip[0]) { |
| 2825 |
gShape.scale(MWAWVec2f(-1,1)); |
| 2826 |
pos.setOrigin(pos.origin()+MWAWVec2f(pos.size()[0],0)); |
| 2827 |
} |
| 2828 |
if (shape.m_style.m_flip[1]) { |
| 2829 |
gShape.scale(MWAWVec2f(1,-1)); |
| 2830 |
pos.setOrigin(pos.origin()+MWAWVec2f(0,pos.size()[1])); |
| 2831 |
} |
| 2832 |
|
| 2833 |
listener->insertShape(pos, gShape, style); |
| 2834 |
} |
| 2835 |
listener->closeGroup(); |
| 2836 |
return true; |
| 2837 |
} |
| 2838 |
MWAWEmbeddedObject object; |
| 2839 |
for (int w=0; w<2; w++) { |
| 2840 |
if (!shape.m_entries[w].valid()) |
| 2841 |
continue; |
| 2842 |
input->seek(shape.m_entries[w].begin(), librevenge::RVNG_SEEK_SET); |
| 2843 |
std::shared_ptr<MWAWPict> pict(MWAWPictData::get(input, int(shape.m_entries[w].length()))); |
| 2844 |
MWAWEmbeddedObject image; |
| 2845 |
if (pict && pict->getBinary(image) && !image.m_dataList.empty()) { |
| 2846 |
object.add(image.m_dataList[0], !image.m_typeList.empty() ? image.m_typeList[0] : "image/pict"); |
| 2847 |
#ifdef DEBUG_WITH_FILES |
| 2848 |
static int volatile pictName = 0; |
| 2849 |
libmwaw::DebugStream f2; |
| 2850 |
f2 << "PICT-" << ++pictName << ".pct"; |
| 2851 |
libmwaw::Debug::dumpFile(object.m_dataList[0], f2.str().c_str()); |
| 2852 |
m_parser.ascii().skipZone(shape.m_entries[w].begin(), shape.m_entries[w].end()-1); |
| 2853 |
#endif |
| 2854 |
} |
| 2855 |
else { |
| 2856 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::send: sorry, can not retrieve a picture\n")); |
| 2857 |
} |
| 2858 |
} |
| 2859 |
if (!object.isEmpty()) |
| 2860 |
listener->insertPicture(pos, object); |
| 2861 |
return true; |
| 2862 |
} |
| 2863 |
case ReadySetGoGraphInternal::Shape::T_Unknown: |
| 2864 |
default: |
| 2865 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::send: sorry sending a shape with type=%d is not implemented\n", int(shape.m_type))); |
| 2866 |
return false; |
| 2867 |
} |
| 2868 |
if (shape.m_rotate) { |
| 2869 |
gShape=gShape.rotate(float(shape.m_rotate)/10, shape.m_box.center()); |
| 2870 |
auto box=gShape.getBdBox(shape.m_style); |
| 2871 |
pos.setOrigin(box[0]); |
| 2872 |
pos.setSize(box.size()); |
| 2873 |
} |
| 2874 |
if (shape.m_style.m_flip[0]) { |
| 2875 |
gShape.scale(MWAWVec2f(-1,1)); |
| 2876 |
pos.setOrigin(pos.origin()+MWAWVec2f(pos.size()[0],0)); |
| 2877 |
} |
| 2878 |
if (shape.m_style.m_flip[1]) { |
| 2879 |
gShape.scale(MWAWVec2f(1,-1)); |
| 2880 |
pos.setOrigin(pos.origin()+MWAWVec2f(0,pos.size()[1])); |
| 2881 |
} |
| 2882 |
listener->insertShape(pos, gShape, shape.m_style); |
| 2883 |
return true; |
| 2884 |
} |
| 2885 |
|
| 2886 |
bool ReadySetGoGraph::sendText(ReadySetGoGraphInternal::Shape const &shape) |
| 2887 |
{ |
| 2888 |
auto input=m_parser.getInput(); |
| 2889 |
auto listener=m_parser.getGraphicListener(); |
| 2890 |
int const vers=version(); |
| 2891 |
bool const isDesign=m_parser.isDesignStudioFile(); |
| 2892 |
if (!input || !listener) { |
| 2893 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the listener\n")); |
| 2894 |
return false; |
| 2895 |
} |
| 2896 |
if (shape.m_type!=shape.T_Text) { |
| 2897 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: unexpected type\n")); |
| 2898 |
return false; |
| 2899 |
} |
| 2900 |
if (!shape.m_entries[0].valid() || shape.m_entries[0].length()<4 || !input->checkPosition(shape.m_entries[0].end())) { |
| 2901 |
if (shape.m_linkIds[0]<0) { |
| 2902 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the character zone\n")); |
| 2903 |
return false; |
| 2904 |
} |
| 2905 |
return true; |
| 2906 |
} |
| 2907 |
input->seek(shape.m_entries[0].begin(), librevenge::RVNG_SEEK_SET); |
| 2908 |
libmwaw::DebugFile &ascFile = m_parser.ascii(); |
| 2909 |
libmwaw::DebugStream f; |
| 2910 |
int const lengthSize=vers<3 ? 2 : 4; |
| 2911 |
int len=int(input->readULong(lengthSize)); |
| 2912 |
long begTextPos=shape.m_entries[0].begin()+(vers<3 ? 2 : vers<6 ? 20 : 58); |
| 2913 |
if (len+(vers<3 ? 2*lengthSize : vers<6 ? 20 : 58)>shape.m_entries[0].length()) { |
| 2914 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the character zone\n")); |
| 2915 |
f << "###"; |
| 2916 |
ascFile.addPos(shape.m_entries[0].begin()); |
| 2917 |
ascFile.addNote("Text-text:###"); |
| 2918 |
return false; |
| 2919 |
} |
| 2920 |
|
| 2921 |
int minCPos=0, maxCPos=len; |
| 2922 |
|
| 2923 |
// first try to read the pararagraph style: v1-v2 or the list of style v3 |
| 2924 |
auto fontConverter=m_parser.getFontConverter(); |
| 2925 |
std::map<int,MWAWFont> posToFont; |
| 2926 |
std::map<int,MWAWParagraph> posToPara; |
| 2927 |
std::map<int, std::vector<MWAWTabStop> > posToTabs; |
| 2928 |
if (vers<3) { |
| 2929 |
MWAWParagraph para=shape.m_paragraph; |
| 2930 |
if (!shape.m_entries[1].valid() || shape.m_entries[1].length()!=0x1e || !input->checkPosition(shape.m_entries[1].end())) { |
| 2931 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the paragraph zone\n")); |
| 2932 |
} |
| 2933 |
else { |
| 2934 |
input->seek(shape.m_entries[1].begin(), librevenge::RVNG_SEEK_SET); |
| 2935 |
long pos=input->tell(); |
| 2936 |
f.str(""); |
| 2937 |
// unsure the first line's style is sometimes different than the |
| 2938 |
// other lines', but the interface is so weird that it is |
| 2939 |
// difficult to understand what happens |
| 2940 |
for (int i=0; i<2; ++i) { // left and right margins from left, |
| 2941 |
int val=int(input->readLong(2)); |
| 2942 |
if (val) f << "margins[" << (i==0 ? "left" : "right") << "]=" << val << ","; |
| 2943 |
} |
| 2944 |
int val=int(input->readLong(1)); |
| 2945 |
switch (val & 3) { |
| 2946 |
case 1: |
| 2947 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 2948 |
break; |
| 2949 |
case 2: |
| 2950 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 2951 |
break; |
| 2952 |
case 3: |
| 2953 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 2954 |
break; |
| 2955 |
case 0: // left |
| 2956 |
default: |
| 2957 |
break; |
| 2958 |
} |
| 2959 |
if (val&0xfc) f << "fl=" << std::hex << (val&0xfc) << std::dec << ","; |
| 2960 |
int interline=0; |
| 2961 |
for (int i=0; i<3; ++i) { // small number maybe another justification |
| 2962 |
val=int(input->readLong(1)); |
| 2963 |
if (!val) continue; |
| 2964 |
if ((i==0 && vers==1) || (i==2 && vers==2)) |
| 2965 |
interline=val; |
| 2966 |
else |
| 2967 |
f << "f" << i << "=" << val << ","; |
| 2968 |
} |
| 2969 |
switch (interline) { |
| 2970 |
case 0: // normal |
| 2971 |
case 1: |
| 2972 |
case 2: |
| 2973 |
para.setInterline(1+double(interline)/2, librevenge::RVNG_PERCENT); |
| 2974 |
break; |
| 2975 |
default: |
| 2976 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: unknown interline\n")); |
| 2977 |
f << "interline=###" << interline << ","; |
| 2978 |
break; |
| 2979 |
} |
| 2980 |
int dim[4]; |
| 2981 |
for (auto &d : dim) d=int(input->readLong(2)); |
| 2982 |
f << "box?=" << MWAWBox2i(MWAWVec2i(dim[0],dim[1]),MWAWVec2i(dim[2],dim[3])) << ","; |
| 2983 |
f << para; |
| 2984 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2985 |
ascFile.addPos(pos-lengthSize); |
| 2986 |
ascFile.addNote(f.str().c_str()); |
| 2987 |
} |
| 2988 |
listener->setParagraph(para); |
| 2989 |
|
| 2990 |
// now read the list of char style |
| 2991 |
input->seek(shape.m_entries[0].begin()+lengthSize+len+(len%2), librevenge::RVNG_SEEK_SET); |
| 2992 |
long pos=input->tell(); |
| 2993 |
int cLen=int(input->readULong(lengthSize)); |
| 2994 |
f.str(""); |
| 2995 |
f << "Text-font:"; |
| 2996 |
if (pos+2+cLen>shape.m_entries[0].end() || (cLen%6)) { |
| 2997 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the find the number of fonts\n")); |
| 2998 |
f << "###"; |
| 2999 |
cLen=0; |
| 3000 |
} |
| 3001 |
ascFile.addPos(pos); |
| 3002 |
ascFile.addNote(f.str().c_str()); |
| 3003 |
for (int s=0; s<(cLen/6); ++s) { |
| 3004 |
pos=input->tell(); |
| 3005 |
f.str(""); |
| 3006 |
f << "Text-font" << s << ":"; |
| 3007 |
int cPos=int(input->readULong(2)); |
| 3008 |
if (cPos) f << "pos=" << cPos << ","; |
| 3009 |
MWAWFont font; |
| 3010 |
font.setSize(float(input->readULong(1))); |
| 3011 |
uint32_t flags=0; |
| 3012 |
int val=int(input->readULong(1)); |
| 3013 |
if (val&0x1) flags |= MWAWFont::boldBit; |
| 3014 |
if (val&0x2) flags |= MWAWFont::italicBit; |
| 3015 |
if (val&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 3016 |
if (val&0x8) flags |= MWAWFont::embossBit; |
| 3017 |
if (val&0x10) flags |= MWAWFont::shadowBit; |
| 3018 |
if (val&0xe0) f << "fl=#" << std::hex << (val&0xe0) << std::dec << ","; |
| 3019 |
font.setFlags(flags); |
| 3020 |
font.setId(int(input->readULong(2))); |
| 3021 |
f << font.getDebugString(fontConverter) << ","; |
| 3022 |
if (posToFont.find(cPos)==posToFont.end()) |
| 3023 |
posToFont[cPos]=font; |
| 3024 |
else { |
| 3025 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: find duplicated position for font's style\n")); |
| 3026 |
f << "###"; |
| 3027 |
} |
| 3028 |
ascFile.addPos(pos); |
| 3029 |
ascFile.addNote(f.str().c_str()); |
| 3030 |
input->seek(pos+6, librevenge::RVNG_SEEK_SET); |
| 3031 |
} |
| 3032 |
|
| 3033 |
|
| 3034 |
} |
| 3035 |
else { |
| 3036 |
if (shape.m_entries[2].valid() && shape.m_entries[2].length()>2) { |
| 3037 |
input->seek(shape.m_entries[2].begin(), librevenge::RVNG_SEEK_SET); |
| 3038 |
|
| 3039 |
int numPara=1; |
| 3040 |
if (vers>3) { |
| 3041 |
f.str(""); |
| 3042 |
numPara=int(input->readLong(2)); |
| 3043 |
f << "N=" << numPara << ","; |
| 3044 |
if (2+(isDesign ? 218 : 148)*numPara>shape.m_entries[2].length()) { |
| 3045 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not determine the number of differents tabulation\n")); |
| 3046 |
f << "###"; |
| 3047 |
numPara=0; |
| 3048 |
} |
| 3049 |
ascFile.addPos(shape.m_entries[2].begin()-4); |
| 3050 |
ascFile.addNote(f.str().c_str()); |
| 3051 |
} |
| 3052 |
|
| 3053 |
for (int p=0; p<numPara; ++p) { |
| 3054 |
int cPos=0; |
| 3055 |
std::vector<MWAWTabStop> tabs; |
| 3056 |
if (!m_styleManager->readTabulations(tabs, vers==3 ? shape.m_entries[2].length() : (isDesign ? 218 : 148), vers==3 ? nullptr : &cPos)) |
| 3057 |
break; |
| 3058 |
posToTabs[cPos]=tabs; |
| 3059 |
} |
| 3060 |
} |
| 3061 |
|
| 3062 |
if (!shape.m_entries[1].valid() || shape.m_entries[1].length()<4 || !input->checkPosition(shape.m_entries[1].end())) { |
| 3063 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the style zone\n")); |
| 3064 |
} |
| 3065 |
else { |
| 3066 |
input->seek(shape.m_entries[1].begin(), librevenge::RVNG_SEEK_SET); |
| 3067 |
f.str(""); |
| 3068 |
int N=int(input->readLong(4)); |
| 3069 |
f << "N=" << N << ","; |
| 3070 |
int const dataSize=vers==3 ? 26 : vers==4 ? 26 : vers==5 ? 34 : vers==6 ? 44 : 50; |
| 3071 |
if (N<0 || (shape.m_entries[1].length()-4)/dataSize<N || 4+N*dataSize>shape.m_entries[1].length()) { |
| 3072 |
f << "###"; |
| 3073 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: can not find the number of styles\n")); |
| 3074 |
N=0; |
| 3075 |
} |
| 3076 |
ascFile.addPos(shape.m_entries[1].begin()-4); |
| 3077 |
ascFile.addNote(f.str().c_str()); |
| 3078 |
for (int s=0; s<N; ++s) { |
| 3079 |
int cPos; |
| 3080 |
MWAWFont font; |
| 3081 |
MWAWParagraph para; |
| 3082 |
if (!m_styleManager->readStyle(font,para,&cPos)) |
| 3083 |
break; |
| 3084 |
if (vers>6) |
| 3085 |
input->seek(6, librevenge::RVNG_SEEK_CUR); |
| 3086 |
// the position can be sometimes dupplicated, so use the latter |
| 3087 |
posToFont[cPos]=font; |
| 3088 |
posToPara[cPos]=para; |
| 3089 |
} |
| 3090 |
} |
| 3091 |
if (shape.m_entries[0].valid() && shape.m_entries[0].length()>=20) { |
| 3092 |
input->seek(shape.m_entries[0].begin()+4, librevenge::RVNG_SEEK_SET); |
| 3093 |
f.str(""); |
| 3094 |
f << "N=" << len << ","; |
| 3095 |
for (int i=0; i<2; ++i) { // probably the selection |
| 3096 |
int val=int(input->readLong(4)); |
| 3097 |
if (val!=len) |
| 3098 |
f << "N" << i+1 << "=" << val << ","; |
| 3099 |
} |
| 3100 |
f << "IDS=["; |
| 3101 |
for (int i=0; i<2; ++i) { |
| 3102 |
auto val=input->readULong(4); |
| 3103 |
if (val) |
| 3104 |
f << std::hex << val << std::dec << ","; |
| 3105 |
else |
| 3106 |
f << "_,"; |
| 3107 |
} |
| 3108 |
f << "],"; |
| 3109 |
ascFile.addPos(shape.m_entries[0].begin()); |
| 3110 |
ascFile.addNote(f.str().c_str()); |
| 3111 |
} |
| 3112 |
if (vers>3) { |
| 3113 |
// time to use the text limit |
| 3114 |
if (shape.m_textPositions[0]<0 || shape.m_textPositions[0]>len) { |
| 3115 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: the minimum position seems bad\n")); |
| 3116 |
} |
| 3117 |
else |
| 3118 |
minCPos=shape.m_textPositions[0]; |
| 3119 |
if (shape.m_textPositions[1]<minCPos || shape.m_textPositions[1]>len) { |
| 3120 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: the maximum position seems bad\n")); |
| 3121 |
} |
| 3122 |
// min=max=0 means all data |
| 3123 |
// if there is not a next frame, we do not want to cut the text |
| 3124 |
else if (shape.m_textPositions[1]>0 && shape.m_textPositions[1]+1<len && shape.m_linkIds[1]>=0) |
| 3125 |
maxCPos=shape.m_textPositions[1]+1; |
| 3126 |
} |
| 3127 |
} |
| 3128 |
|
| 3129 |
f.str(""); |
| 3130 |
f << "Text-text:"; |
| 3131 |
input->seek(begTextPos+minCPos, librevenge::RVNG_SEEK_SET); |
| 3132 |
std::vector<MWAWTabStop> tabs; |
| 3133 |
MWAWParagraph para; |
| 3134 |
if (minCPos!=0) { |
| 3135 |
// we need to retrieve the current style |
| 3136 |
auto tIt=posToTabs.lower_bound(minCPos); |
| 3137 |
if (tIt!=posToTabs.begin()) { |
| 3138 |
--tIt; |
| 3139 |
tabs=tIt->second; |
| 3140 |
para.m_tabs=tabs; |
| 3141 |
listener->setParagraph(para); |
| 3142 |
} |
| 3143 |
auto pIt=posToPara.lower_bound(minCPos); |
| 3144 |
if (pIt!=posToPara.begin()) { |
| 3145 |
--pIt; |
| 3146 |
para=pIt->second; |
| 3147 |
para.m_tabs=tabs; |
| 3148 |
listener->setParagraph(para); |
| 3149 |
} |
| 3150 |
auto fIt=posToFont.lower_bound(minCPos); |
| 3151 |
if (fIt!=posToFont.begin()) { |
| 3152 |
--fIt; |
| 3153 |
listener->setFont(fIt->second); |
| 3154 |
} |
| 3155 |
} |
| 3156 |
for (int c=minCPos; c<maxCPos; ++c) { |
| 3157 |
auto tIt=posToTabs.find(c); |
| 3158 |
if (tIt!=posToTabs.end()) { |
| 3159 |
tabs=tIt->second; |
| 3160 |
para.m_tabs=tabs; |
| 3161 |
listener->setParagraph(para); |
| 3162 |
} |
| 3163 |
auto pIt=posToPara.find(c); |
| 3164 |
if (pIt!=posToPara.end()) { |
| 3165 |
para=pIt->second; |
| 3166 |
para.m_tabs=tabs; |
| 3167 |
listener->setParagraph(para); |
| 3168 |
} |
| 3169 |
auto fIt=posToFont.find(c); |
| 3170 |
if (fIt!=posToFont.end()) |
| 3171 |
listener->setFont(fIt->second); |
| 3172 |
if (input->isEnd()) { |
| 3173 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: find end of input at pos=%d\n", c)); |
| 3174 |
f << "###"; |
| 3175 |
break; |
| 3176 |
} |
| 3177 |
unsigned char ch=(unsigned char)(input->readULong(1)); |
| 3178 |
if (ch) |
| 3179 |
f << ch; |
| 3180 |
else |
| 3181 |
f << "[#page]"; |
| 3182 |
switch (ch) { |
| 3183 |
case 0: |
| 3184 |
listener->insertField(MWAWField(MWAWField::PageNumber)); |
| 3185 |
break; |
| 3186 |
case 5: |
| 3187 |
listener->insertField(MWAWField(MWAWField::PageCount)); |
| 3188 |
break; |
| 3189 |
case 0x9: |
| 3190 |
listener->insertTab(); |
| 3191 |
break; |
| 3192 |
// case 0xb: column break, useme |
| 3193 |
case 0xd: |
| 3194 |
listener->insertEOL(); |
| 3195 |
break; |
| 3196 |
case 0x1f: // soft hyphen |
| 3197 |
break; |
| 3198 |
default: |
| 3199 |
if (ch<=0x1f) { |
| 3200 |
MWAW_DEBUG_MSG(("ReadySetGoGraph::sendText: find unknown char=%d at pos=%d\n", int(ch), c)); |
| 3201 |
f << "###"; |
| 3202 |
break; |
| 3203 |
} |
| 3204 |
listener->insertCharacter(ch); |
| 3205 |
} |
| 3206 |
} |
| 3207 |
ascFile.addPos(shape.m_entries[0].begin()); |
| 3208 |
ascFile.addNote(f.str().c_str()); |
| 3209 |
return true; |
| 3210 |
} |
| 3211 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |