| 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) 2006 Ariya Hidayat ([email protected]) |
| 18 |
* Copyright (C) 2004 Marc Oude Kotte ([email protected]) |
| 19 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 20 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 21 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 22 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 23 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 24 |
* |
| 25 |
* |
| 26 |
* All Rights Reserved. |
| 27 |
* |
| 28 |
* For minor contributions see the git repository. |
| 29 |
* |
| 30 |
* Alternatively, the contents of this file may be used under the terms of |
| 31 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 32 |
* in which case the provisions of the LGPLv2+ are applicable |
| 33 |
* instead of those above. |
| 34 |
*/ |
| 35 |
|
| 36 |
#include <string.h> |
| 37 |
|
| 38 |
#include <librevenge/librevenge.h> |
| 39 |
#include <libmwaw/libmwaw.hxx> |
| 40 |
|
| 41 |
#include "libmwaw_internal.hxx" |
| 42 |
|
| 43 |
#include "MWAWDebug.hxx" |
| 44 |
|
| 45 |
#include "MWAWGraphicDecoder.hxx" |
| 46 |
|
| 47 |
void MWAWGraphicDecoder::insertElement(const char *psName) |
| 48 |
{ |
| 49 |
if (!m_output) return; |
| 50 |
int len=psName ? int(strlen(psName)) : 0; |
| 51 |
if (!len) { |
| 52 |
MWAW_DEBUG_MSG(("MWAWGraphicDecoder::insertElement: called without name\n")); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
bool ok=true; |
| 57 |
switch (psName[0]) { |
| 58 |
case 'C': |
| 59 |
if (len>=6 && strncmp(psName,"Close",5)==0) { |
| 60 |
psName+=5; |
| 61 |
if (strcmp(psName,"Group")==0) |
| 62 |
m_output->closeGroup(); |
| 63 |
else if (strcmp(psName,"Link")==0) |
| 64 |
m_output->closeLink(); |
| 65 |
else if (strcmp(psName,"ListElement")==0) |
| 66 |
m_output->closeListElement(); |
| 67 |
else if (strcmp(psName,"OrderedListLevel")==0) |
| 68 |
m_output->closeOrderedListLevel(); |
| 69 |
else if (strcmp(psName,"Paragraph")==0) |
| 70 |
m_output->closeParagraph(); |
| 71 |
else if (strcmp(psName,"Span")==0) |
| 72 |
m_output->closeSpan(); |
| 73 |
else if (strcmp(psName,"TableCell")==0) |
| 74 |
m_output->closeTableCell(); |
| 75 |
else if (strcmp(psName,"TableRow")==0) |
| 76 |
m_output->closeTableRow(); |
| 77 |
else if (strcmp(psName,"UnorderedListLevel")==0) |
| 78 |
m_output->closeUnorderedListLevel(); |
| 79 |
else |
| 80 |
ok=false; |
| 81 |
} |
| 82 |
else |
| 83 |
ok=false; |
| 84 |
break; |
| 85 |
case 'E': |
| 86 |
if (len>=4 && strncmp(psName,"End",3)==0) { |
| 87 |
psName+=3; |
| 88 |
if (strcmp(psName,"Document")==0) |
| 89 |
m_output->endDocument(); |
| 90 |
else if (strcmp(psName,"EmbeddedGraphics")==0) |
| 91 |
m_output->endEmbeddedGraphics(); |
| 92 |
else if (strcmp(psName,"Layer")==0) |
| 93 |
m_output->endLayer(); |
| 94 |
else if (strcmp(psName,"MasterPage")==0) |
| 95 |
m_output->endMasterPage(); |
| 96 |
else if (strcmp(psName,"Page")==0) |
| 97 |
m_output->endPage(); |
| 98 |
else if (strcmp(psName,"TableObject")==0) |
| 99 |
m_output->endTableObject(); |
| 100 |
else if (strcmp(psName,"TextObject")==0) |
| 101 |
m_output->endTextObject(); |
| 102 |
else |
| 103 |
ok=false; |
| 104 |
} |
| 105 |
else |
| 106 |
ok=false; |
| 107 |
break; |
| 108 |
case 'I': |
| 109 |
if (len>=7 && strncmp(psName,"Insert",6)==0) { |
| 110 |
psName+=6; |
| 111 |
if (strcmp(psName,"LineBreak")==0) |
| 112 |
m_output->insertLineBreak(); |
| 113 |
else if (strcmp(psName,"Space")==0) |
| 114 |
m_output->insertSpace(); |
| 115 |
else if (strcmp(psName,"Tab")==0) |
| 116 |
m_output->insertTab(); |
| 117 |
else |
| 118 |
ok=false; |
| 119 |
} |
| 120 |
else |
| 121 |
ok=false; |
| 122 |
break; |
| 123 |
default: |
| 124 |
ok=false; |
| 125 |
break; |
| 126 |
} |
| 127 |
if (!ok) { |
| 128 |
MWAW_DEBUG_MSG(("MWAWGraphicDecoder::insertElement: called with unexpected name %s\n", psName)); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
void MWAWGraphicDecoder::insertElement(const char *psName, const librevenge::RVNGPropertyList &propList) |
| 133 |
{ |
| 134 |
if (!m_output) return; |
| 135 |
int len=psName ? int(strlen(psName)) : 0; |
| 136 |
if (!len) { |
| 137 |
MWAW_DEBUG_MSG(("MWAWGraphicDecoder::insertElement: called without any name\n")); |
| 138 |
return; |
| 139 |
} |
| 140 |
|
| 141 |
bool ok=true; |
| 142 |
switch (psName[0]) { |
| 143 |
case 'D': |
| 144 |
if (len>=7 && strncmp(psName,"Define",6)==0) { |
| 145 |
psName+=6; |
| 146 |
if (strcmp(psName,"CharacterStyle")==0) |
| 147 |
m_output->defineCharacterStyle(propList); |
| 148 |
else if (strcmp(psName,"EmbeddedFont")==0) |
| 149 |
m_output->defineEmbeddedFont(propList); |
| 150 |
else if (strcmp(psName,"ParagraphStyle")==0) |
| 151 |
m_output->defineParagraphStyle(propList); |
| 152 |
else |
| 153 |
ok=false; |
| 154 |
} |
| 155 |
else if (len>=5 && strncmp(psName,"Draw",4)==0) { |
| 156 |
psName+=4; |
| 157 |
if (strcmp(psName,"Connector")==0) |
| 158 |
m_output->drawConnector(propList); |
| 159 |
else if (strcmp(psName,"Ellipse")==0) |
| 160 |
m_output->drawEllipse(propList); |
| 161 |
else if (strcmp(psName,"GraphicObject")==0) |
| 162 |
m_output->drawGraphicObject(propList); |
| 163 |
else if (strcmp(psName,"Path")==0) |
| 164 |
m_output->drawPath(propList); |
| 165 |
else if (strcmp(psName,"Polygon")==0) |
| 166 |
m_output->drawPolygon(propList); |
| 167 |
else if (strcmp(psName,"Polyline")==0) |
| 168 |
m_output->drawPolyline(propList); |
| 169 |
else if (strcmp(psName,"Rectangle")==0) |
| 170 |
m_output->drawRectangle(propList); |
| 171 |
else |
| 172 |
ok=false; |
| 173 |
} |
| 174 |
else |
| 175 |
ok=false; |
| 176 |
break; |
| 177 |
case 'I': |
| 178 |
if (len>=7 && strncmp(psName,"Insert",6)==0) { |
| 179 |
psName+=6; |
| 180 |
if (strcmp(psName,"CoveredTableCell")==0) |
| 181 |
m_output->insertCoveredTableCell(propList); |
| 182 |
else if (strcmp(psName,"Field")==0) |
| 183 |
m_output->insertField(propList); |
| 184 |
else |
| 185 |
ok=false; |
| 186 |
} |
| 187 |
else |
| 188 |
ok=false; |
| 189 |
break; |
| 190 |
case 'O': |
| 191 |
if (len>=5 && strncmp(psName,"Open",4)==0) { |
| 192 |
psName+=4; |
| 193 |
if (strcmp(psName,"Group")==0) |
| 194 |
m_output->openGroup(propList); |
| 195 |
else if (strcmp(psName,"Link")==0) |
| 196 |
m_output->openLink(propList); |
| 197 |
else if (strcmp(psName,"ListElement")==0) |
| 198 |
m_output->openListElement(propList); |
| 199 |
else if (strcmp(psName,"OrderedListLevel")==0) |
| 200 |
m_output->openOrderedListLevel(propList); |
| 201 |
else if (strcmp(psName,"Paragraph")==0) |
| 202 |
m_output->openParagraph(propList); |
| 203 |
else if (strcmp(psName,"Span")==0) |
| 204 |
m_output->openSpan(propList); |
| 205 |
else if (strcmp(psName,"TableCell")==0) |
| 206 |
m_output->openTableCell(propList); |
| 207 |
else if (strcmp(psName,"TableRow")==0) |
| 208 |
m_output->openTableRow(propList); |
| 209 |
else if (strcmp(psName,"UnorderedListLevel")==0) |
| 210 |
m_output->openUnorderedListLevel(propList); |
| 211 |
else |
| 212 |
ok=false; |
| 213 |
} |
| 214 |
else |
| 215 |
ok=false; |
| 216 |
break; |
| 217 |
case 'S': |
| 218 |
if (len>=4 && strncmp(psName,"Set",3)==0) { |
| 219 |
psName+=3; |
| 220 |
if (strcmp(psName,"DocumentMetaData")==0) |
| 221 |
m_output->setDocumentMetaData(propList); |
| 222 |
else if (strcmp(psName,"Style")==0) |
| 223 |
m_output->setStyle(propList); |
| 224 |
else |
| 225 |
ok=false; |
| 226 |
} |
| 227 |
else if (len>=6 && strncmp(psName,"Start",5)==0) { |
| 228 |
psName+=5; |
| 229 |
if (strcmp(psName,"Document")==0) |
| 230 |
m_output->startDocument(propList); |
| 231 |
else if (strcmp(psName,"EmbeddedGraphics")==0) |
| 232 |
m_output->startEmbeddedGraphics(propList); |
| 233 |
else if (strcmp(psName,"Layer")==0) |
| 234 |
m_output->startLayer(propList); |
| 235 |
else if (strcmp(psName,"MasterPage")==0) |
| 236 |
m_output->startMasterPage(propList); |
| 237 |
else if (strcmp(psName,"Page")==0) |
| 238 |
m_output->startPage(propList); |
| 239 |
else if (strcmp(psName,"TableObject")==0) |
| 240 |
m_output->startTableObject(propList); |
| 241 |
else if (strcmp(psName,"TextObject")==0) |
| 242 |
m_output->startTextObject(propList); |
| 243 |
else |
| 244 |
ok=false; |
| 245 |
} |
| 246 |
else |
| 247 |
ok=false; |
| 248 |
break; |
| 249 |
default: |
| 250 |
ok=false; |
| 251 |
break; |
| 252 |
} |
| 253 |
if (!ok) { |
| 254 |
MWAW_DEBUG_MSG(("MWAWGraphicDecoder::insertElement: called with unexpected name %s\n", psName)); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |