Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <deque>
21 : #include <memory>
22 :
23 : #include <boost/shared_ptr.hpp>
24 :
25 : #include "hwpreader.hxx"
26 : #include <math.h>
27 :
28 : #include <comphelper/newarray.hxx>
29 :
30 : #include "fontmap.hxx"
31 : #include "formula.h"
32 : #include "cspline.h"
33 :
34 : #include <iostream>
35 : #include <locale.h>
36 : #include <sal/types.h>
37 : // #i42367# prevent MS compiler from using system locale for parsing
38 : #ifdef _MSC_VER
39 : #pragma setlocale("C")
40 : #endif
41 :
42 : // To be shorten source code by realking
43 : #define hconv(x) OUString(hstr2ucsstr(x).c_str())
44 : #define ascii(x) OUString::createFromAscii(x)
45 : #define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(false)
46 : #define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(false)
47 : #define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false)
48 : #define padd(x,y,z) pList->addAttribute(x,y,z)
49 : #define Double2Str(x) OUString::number((double)(x))
50 : #define WTI(x) ((double)(x) / 1800.) // unit => inch
51 : #define WTMM(x) ((double)(x) / 1800. * 25.4) // unit => mm
52 : #define WTSM(x) ((int)((x) / 1800. * 2540)) // unit ==> 1/100 mm
53 :
54 : #define PI 3.14159265358979323846
55 :
56 : // xmloff/xmlkyd.hxx
57 : #define sXML_CDATA ascii("CDATA")
58 :
59 : #define STARTP padd( ascii("text:style-name"), ascii("CDATA"), ascii(getPStyleName(((ParaShape &)para->GetParaShape()).index,buf))); \
60 : rstartEl( ascii("text:p"),rList ); \
61 : pList->clear(); \
62 : pstart = true
63 : #define STARTT \
64 : curr = para->GetCharShape(n > 0 ? n-1 : 0)->index; \
65 : padd( ascii("text:style-name"), ascii("CDATA") , ascii( getTStyleName(curr, buf) ) ); \
66 : rstartEl( ascii("text:span"),rList ); \
67 : pList->clear(); \
68 : tstart = true
69 : #define ENDP \
70 : rendEl(ascii("text:p")); \
71 : pstart = false
72 : #define ENDT \
73 : rendEl(ascii("text:span")); \
74 : tstart = false
75 :
76 : static hchar *field = 0L;
77 : static char buf[1024];
78 :
79 : namespace
80 : {
81 :
82 : template<typename T>
83 : struct Free
84 : {
85 0 : void operator()(T* const ptr)
86 : {
87 0 : free(ptr);
88 0 : }
89 : };
90 :
91 : }
92 :
93 : struct HwpReaderPrivate
94 : {
95 2 : HwpReaderPrivate()
96 : {
97 2 : bFirstPara = true;
98 2 : bInBody = false;
99 2 : bInHeader = false;
100 2 : nPnPos = 0;
101 2 : pPn = 0L;
102 :
103 2 : }
104 : bool bFirstPara;
105 : bool bInBody;
106 : bool bInHeader;
107 : ShowPageNum *pPn;
108 : int nPnPos;
109 : };
110 :
111 2 : HwpReader::HwpReader()
112 : {
113 2 : pList = new AttributeListImpl;
114 2 : rList = (XAttributeList *) pList;
115 2 : d = new HwpReaderPrivate;
116 2 : }
117 :
118 :
119 6 : HwpReader::~HwpReader()
120 : {
121 2 : rList = 0;
122 2 : delete d;
123 4 : }
124 :
125 :
126 4 : sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) throw(RuntimeException, std::exception)
127 : {
128 4 : utl::MediaDescriptor aDescriptor(rDescriptor);
129 4 : aDescriptor.addInputStream();
130 :
131 : Reference< XInputStream > xInputStream(
132 8 : aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY_THROW);
133 :
134 8 : std::unique_ptr<HStream> stream(new HStream);
135 8 : Sequence < sal_Int8 > aBuffer;
136 4 : sal_Int32 nRead, nBlock = 32768, nTotal = 0;
137 : while( true )
138 : {
139 8 : nRead = xInputStream->readBytes(aBuffer, nBlock);
140 8 : if( nRead == 0 )
141 4 : break;
142 4 : stream->addData( (const byte *)aBuffer.getConstArray(), nRead );
143 4 : nTotal += nRead;
144 : }
145 :
146 4 : if( nTotal == 0 ) return sal_False;
147 :
148 4 : if (hwpfile.ReadHwpFile(stream.release()))
149 2 : return sal_False;
150 :
151 2 : if (m_rxDocumentHandler.is())
152 0 : m_rxDocumentHandler->startDocument();
153 :
154 2 : padd(ascii("office:class"), sXML_CDATA, ascii("text"));
155 2 : padd(ascii("office:version"), sXML_CDATA, ascii("0.9"));
156 :
157 2 : padd(ascii("xmlns:office"), ascii("CDATA"), ascii("http://openoffice.org/2000/office"));
158 2 : padd(ascii("xmlns:style"), ascii("CDATA"), ascii("http://openoffice.org/2000/style"));
159 2 : padd(ascii("xmlns:text"), ascii("CDATA"), ascii("http://openoffice.org/2000/text"));
160 2 : padd(ascii("xmlns:table"), ascii("CDATA"), ascii("http://openoffice.org/2000/table"));
161 2 : padd(ascii("xmlns:draw"), ascii("CDATA"), ascii("http://openoffice.org/2000/drawing"));
162 2 : padd(ascii("xmlns:fo"), ascii("CDATA"), ascii("http://www.w3.org/1999/XSL/Format"));
163 2 : padd(ascii("xmlns:xlink"), ascii("CDATA"), ascii("http://www.w3.org/1999/xlink"));
164 2 : padd(ascii("xmlns:dc"), ascii("CDATA"), ascii("http://purl.org/dc/elements/1.1/"));
165 2 : padd(ascii("xmlns:meta"), ascii("CDATA"), ascii("http://openoffice.org/2000/meta"));
166 2 : padd(ascii("xmlns:number"), ascii("CDATA"), ascii("http://openoffice.org/2000/datastyle"));
167 2 : padd(ascii("xmlns:svg"), ascii("CDATA"), ascii("http://www.w3.org/2000/svg"));
168 2 : padd(ascii("xmlns:chart"), ascii("CDATA"), ascii("http://openoffice.org/2000/chart"));
169 2 : padd(ascii("xmlns:dr3d"), ascii("CDATA"), ascii("http://openoffice.org/2000/dr3d"));
170 2 : padd(ascii("xmlns:math"), ascii("CDATA"), ascii("http://www.w3.org/1998/Math/MathML"));
171 2 : padd(ascii("xmlns:form"), ascii("CDATA"), ascii("http://openoffice.org/2000/form"));
172 2 : padd(ascii("xmlns:script"), ascii("CDATA"), ascii("http://openoffice.org/2000/script"));
173 :
174 2 : rstartEl(ascii("office:document"), rList);
175 2 : pList->clear();
176 :
177 2 : makeMeta();
178 2 : makeStyles();
179 2 : makeAutoStyles();
180 2 : makeMasterStyles();
181 2 : makeBody();
182 :
183 2 : rendEl(ascii("office:document"));
184 :
185 2 : if (m_rxDocumentHandler.is())
186 0 : m_rxDocumentHandler->endDocument();
187 6 : return sal_True;
188 : }
189 :
190 :
191 : /**
192 : * make office:body
193 : */
194 2 : void HwpReader::makeBody()
195 : {
196 2 : rstartEl(ascii("office:body"), rList);
197 2 : makeTextDecls();
198 2 : HWPPara *hwppara = hwpfile.GetFirstPara();
199 2 : d->bInBody = true;
200 2 : parsePara(hwppara);
201 2 : rendEl(ascii("office:body"));
202 2 : d->bInBody = false;
203 2 : }
204 :
205 :
206 : /**
207 : * make text decls
208 : */
209 2 : void HwpReader::makeTextDecls()
210 : {
211 2 : rstartEl(ascii("text:sequence-decls"), rList);
212 2 : padd(ascii("text:display-outline-level"), sXML_CDATA, ascii("0"));
213 2 : padd(ascii("text:name"), sXML_CDATA, ascii("Illustration"));
214 2 : rstartEl(ascii("text:sequence-decl"), rList);
215 2 : pList->clear();
216 2 : rendEl(ascii("text:sequence-decl"));
217 2 : padd(ascii("text:display-outline-level"), sXML_CDATA, ascii("0"));
218 2 : padd(ascii("text:name"), sXML_CDATA, ascii("Table"));
219 2 : rstartEl(ascii("text:sequence-decl"), rList);
220 2 : pList->clear();
221 2 : rendEl(ascii("text:sequence-decl"));
222 2 : padd(ascii("text:display-outline-level"), sXML_CDATA, ascii("0"));
223 2 : padd(ascii("text:name"), sXML_CDATA, ascii("Text"));
224 2 : rstartEl(ascii("text:sequence-decl"), rList);
225 2 : pList->clear();
226 2 : rendEl(ascii("text:sequence-decl"));
227 2 : padd(ascii("text:display-outline-level"), sXML_CDATA, ascii("0"));
228 2 : padd(ascii("text:name"), sXML_CDATA, ascii("Drawing"));
229 2 : rstartEl(ascii("text:sequence-decl"), rList);
230 2 : pList->clear();
231 2 : rendEl(ascii("text:sequence-decl"));
232 2 : rendEl(ascii("text:sequence-decls"));
233 2 : }
234 :
235 :
236 : #define ISNUMBER(x) ( (x) <= 0x39 && (x) >= 0x30 )
237 : /**
238 : * make office:meta
239 : * Completed
240 : */
241 2 : void HwpReader::makeMeta()
242 : {
243 2 : HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
244 :
245 2 : rstartEl(ascii("office:meta"), rList);
246 :
247 2 : if (hwpinfo.summary.title[0])
248 : {
249 2 : rstartEl(ascii("dc:title"), rList);
250 2 : rchars((hconv(hwpinfo.summary.title)));
251 2 : rendEl(ascii("dc:title"));
252 : }
253 :
254 2 : if (hwpinfo.summary.subject[0])
255 : {
256 0 : rstartEl(ascii("dc:subject"), rList);
257 0 : rchars((hconv(hwpinfo.summary.subject)));
258 0 : rendEl(ascii("dc:subject"));
259 : }
260 :
261 2 : if (hwpinfo.summary.author[0])
262 : {
263 0 : rstartEl(ascii("meta:initial-creator"), rList);
264 0 : rchars((hconv(hwpinfo.summary.author)));
265 0 : rendEl(ascii("meta:initial-creator"));
266 : }
267 :
268 2 : if (hwpinfo.summary.date[0])
269 : {
270 2 : unsigned short *pDate = hwpinfo.summary.date;
271 : int year,month,day,hour,minute;
272 2 : int gab = 0;
273 4 : if( ISNUMBER( pDate[0] ) && ISNUMBER( pDate[1] ) &&
274 4 : ISNUMBER( pDate[2] ) && ISNUMBER( pDate[3] ))
275 : {
276 4 : year = (pDate[0]-0x30) * 1000 + (pDate[1]-0x30) * 100 +
277 4 : (pDate[2]-0x30) * 10 + (pDate[3]-0x30);
278 : }
279 : else {
280 0 : year = 0;
281 : }
282 2 : if( ISNUMBER( pDate[6] ))
283 : {
284 4 : if( ISNUMBER( pDate[7] ) )
285 0 : month = (pDate[6] - 0x30) * 10 + (pDate[6+ ++gab]-0x30);
286 : else
287 2 : month = (pDate[6] - 0x30);
288 : }
289 : else {
290 0 : month = 0;
291 : }
292 2 : if( ISNUMBER( pDate[9 + gab] ) )
293 : {
294 4 : if( ISNUMBER( pDate[10 + gab])) {
295 0 : day = ( pDate[9 + gab] - 0x30 ) * 10 + (pDate[9+ gab + 1]-0x30);
296 0 : ++gab;
297 : } else
298 2 : day = (pDate[9+gab]-0x30);
299 : }
300 : else {
301 0 : day = 0;
302 : }
303 2 : if( ISNUMBER( pDate[17 + gab] ) )
304 : {
305 0 : if( ISNUMBER( pDate[18 + gab])) {
306 0 : hour = ( pDate[17 + gab] - 0x30 ) * 10 + (pDate[17+ gab + 1]-0x30);
307 0 : ++gab;
308 : } else
309 0 : hour = (pDate[17+gab]-0x30);
310 : }
311 : else {
312 2 : hour = 0;
313 : }
314 2 : if( ISNUMBER( pDate[20 + gab] ) )
315 : {
316 0 : if( ISNUMBER( pDate[21 + gab])) {
317 0 : minute = ( pDate[20 + gab] - 0x30 ) * 10 + (pDate[20+ gab + 1]-0x30);
318 0 : ++gab;
319 : } else
320 0 : minute = (pDate[20+gab]-0x30);
321 : }
322 : else {
323 2 : minute = 0;
324 : }
325 2 : sprintf(buf,"%d-%02d-%02dT%02d:%02d:00",year,month,day,hour,minute);
326 :
327 2 : rstartEl( ascii("meta:creation-date"), rList );
328 2 : rchars( ascii(buf));
329 2 : rendEl( ascii("meta:creation-date") );
330 : }
331 :
332 2 : if (hwpinfo.summary.keyword[0][0] || hwpinfo.summary.etc[0][0])
333 : {
334 0 : rstartEl(ascii("meta:keywords"), rList);
335 0 : if (hwpinfo.summary.keyword[0][0])
336 : {
337 0 : rstartEl(ascii("meta:keyword"), rList);
338 0 : rchars((hconv(hwpinfo.summary.keyword[0])));
339 0 : rendEl(ascii("meta:keyword"));
340 : }
341 0 : if (hwpinfo.summary.keyword[1][0])
342 : {
343 0 : rstartEl(ascii("meta:keyword"), rList);
344 0 : rchars((hconv(hwpinfo.summary.keyword[1])));
345 0 : rendEl(ascii("meta:keyword"));
346 : }
347 0 : if (hwpinfo.summary.etc[0][0])
348 : {
349 0 : rstartEl(ascii("meta:keyword"), rList);
350 0 : rchars((hconv(hwpinfo.summary.etc[0])));
351 0 : rendEl(ascii("meta:keyword"));
352 : }
353 0 : if (hwpinfo.summary.etc[1][0])
354 : {
355 0 : rstartEl(ascii("meta:keyword"), rList);
356 0 : rchars((hconv(hwpinfo.summary.etc[1])));
357 0 : rendEl(ascii("meta:keyword"));
358 : }
359 0 : if (hwpinfo.summary.etc[2][0])
360 : {
361 0 : rstartEl(ascii("meta:keyword"), rList);
362 0 : rchars((hconv(hwpinfo.summary.etc[2])));
363 0 : rendEl(ascii("meta:keyword"));
364 : }
365 0 : rendEl(ascii("meta:keywords"));
366 : }
367 2 : rendEl(ascii("office:meta"));
368 2 : }
369 :
370 :
371 : static struct
372 : {
373 : const char *name;
374 : bool bMade;
375 : }
376 : ArrowShape[] =
377 : {
378 : { "", false },
379 : { "Arrow", false },
380 : { "Line Arrow", false },
381 : { "Square", false }
382 : };
383 :
384 : static struct
385 : {
386 : double dots1;
387 : double dots2;
388 : double distance;
389 : }
390 :
391 :
392 : LineStyle[] =
393 : {
394 : { 0.0, 0.0, 0.0 },
395 : {
396 : 0.34, 0., 0.272
397 : },
398 : { 0.17, 0., 0.136},
399 : {
400 : 0.612, 0.17, 0.136
401 : },
402 : { 0.85, 0.17, 0.136}
403 : };
404 :
405 0 : void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
406 : {
407 0 : while( hdo )
408 : {
409 0 : if( hdo->child )
410 0 : makeDrawMiscStyle( hdo->child );
411 :
412 0 : HWPDOProperty *prop = &hdo->property;
413 0 : if( hdo->type == HWPDO_CONTAINER )
414 : {
415 0 : hdo = hdo->next;
416 0 : continue;
417 : }
418 :
419 0 : if( prop->line_pstyle > 0 && prop->line_pstyle < 5 && prop->line_color <= 0xffffff)
420 : {
421 0 : padd( ascii("draw:name"), sXML_CDATA, ascii(Int2Str(hdo->index, "LineType%d", buf)));
422 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("round"));
423 0 : padd( ascii("draw:dots1"), sXML_CDATA, ascii("1"));
424 0 : padd( ascii("draw:dots1-length"), sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots1 * WTMM(prop->line_width) ) + ascii("cm"));
425 0 : if( prop->line_pstyle == 3 )
426 : {
427 0 : padd( ascii("draw:dots2"), sXML_CDATA, ascii("1"));
428 0 : padd( ascii("draw:dots2-length"), sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width) ) + ascii("cm"));
429 : }
430 0 : else if( prop->line_pstyle == 4 )
431 : {
432 0 : padd( ascii("draw:dots2"), sXML_CDATA, ascii("2"));
433 0 : padd( ascii("draw:dots2-length"), sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width)) + ascii("cm"));
434 : }
435 0 : padd( ascii("draw:distance"), sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].distance * WTMM(prop->line_width)) + ascii("cm"));
436 0 : rstartEl( ascii("draw:stroke-dash"), rList);
437 0 : pList->clear();
438 0 : rendEl( ascii("draw:stroke-dash") );
439 : }
440 :
441 0 : if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC || hdo->type == HWPDO_FREEFORM ||
442 0 : hdo->type == HWPDO_ADVANCED_ARC )
443 : {
444 0 : if( prop->line_tstyle && !ArrowShape[prop->line_tstyle].bMade )
445 : {
446 0 : ArrowShape[prop->line_tstyle].bMade = true;
447 0 : padd(ascii("draw:name"), sXML_CDATA,
448 0 : ascii(ArrowShape[prop->line_tstyle].name));
449 0 : if( prop->line_tstyle == 1 )
450 : {
451 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 20 30"));
452 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("m10 0-10 30h20z"));
453 : }
454 0 : else if( prop->line_tstyle == 2 )
455 : {
456 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 1122 2243"));
457 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("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"));
458 : }
459 0 : else if( prop->line_tstyle == 3 )
460 : {
461 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 30 30"));
462 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("m0 0h30v30h-30z"));
463 : }
464 0 : rstartEl(ascii("draw:marker"), rList);
465 0 : pList->clear();
466 0 : rendEl(ascii("draw:marker"));
467 : }
468 0 : if( prop->line_hstyle && !ArrowShape[prop->line_hstyle].bMade)
469 : {
470 0 : ArrowShape[prop->line_hstyle].bMade = true;
471 0 : padd(ascii("draw:name"), sXML_CDATA,
472 0 : ascii(ArrowShape[prop->line_hstyle].name));
473 0 : if( prop->line_hstyle == 1 )
474 : {
475 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 20 30"));
476 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("m10 0-10 30h20z"));
477 : }
478 0 : else if( prop->line_hstyle == 2 )
479 : {
480 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 1122 2243"));
481 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("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"));
482 : }
483 0 : else if( prop->line_hstyle == 3 )
484 : {
485 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii("0 0 20 20"));
486 0 : padd(ascii("svg:d"), sXML_CDATA, ascii("m0 0h20v20h-20z"));
487 : }
488 0 : rstartEl(ascii("draw:marker"), rList);
489 0 : pList->clear();
490 0 : rendEl(ascii("draw:marker"));
491 : }
492 : }
493 :
494 0 : if( hdo->type != HWPDO_LINE )
495 : {
496 0 : if( prop->flag >> 18 & 0x01 )
497 : {
498 0 : padd( ascii("draw:name"), sXML_CDATA, ascii(Int2Str(hdo->index, "fillimage%d", buf)));
499 0 : if( !prop->pictype )
500 : {
501 0 : padd( ascii("xlink:href"), sXML_CDATA,
502 0 : hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
503 : }
504 : else
505 : {
506 0 : EmPicture *emp = 0L;
507 0 : if ( strlen( prop->szPatternFile ) > 3)
508 0 : emp = hwpfile.GetEmPictureByName(prop->szPatternFile);
509 0 : if( emp )
510 : {
511 : char filename[128+17+9];
512 : char dirname[128];
513 : int fd;
514 : #ifdef _WIN32
515 : GetTempPath(sizeof(dirname), dirname);
516 : sprintf(filename, "%s%s",dirname, emp->name);
517 : if( (fd = open( filename , _O_CREAT | _O_WRONLY | _O_BINARY , 0666)) >= 0 )
518 : #else
519 0 : strcpy(dirname, "/tmp/");
520 0 : sprintf(filename, "%s%s", dirname, emp->name);
521 0 : if( (fd = open( filename , O_CREAT | O_WRONLY , 0666)) >= 0 )
522 : #endif
523 : {
524 0 : size_t nWritten = write(fd, emp->data, emp->size);
525 : OSL_VERIFY(nWritten == emp->size);
526 0 : close(fd);
527 : }
528 : #ifdef _WIN32
529 : int j;
530 : for(j = 0 ; j < (int)strlen( dirname ) ; j++)
531 : {
532 : if( dirname[j] == '\\' ) buf[j] = '/';
533 : else buf[j] = dirname[j];
534 : }
535 : buf[j] = '\0';
536 : sprintf(filename, "file:///%s%s",buf, emp->name );
537 : #else
538 0 : sprintf(filename, "file://%s%s",dirname, emp->name );
539 : #endif
540 0 : padd( ascii("xlink:href"), sXML_CDATA, ascii(filename));
541 : }
542 : else
543 : {
544 0 : padd( ascii("xlink:href"), sXML_CDATA,
545 0 : hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
546 : }
547 :
548 : }
549 0 : padd( ascii("xlink:type"), sXML_CDATA, ascii("simple"));
550 0 : padd( ascii("xlink:show"), sXML_CDATA, ascii("embed"));
551 0 : padd( ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
552 :
553 0 : rstartEl( ascii("draw:fill-image"), rList);
554 0 : pList->clear();
555 0 : rendEl( ascii("draw:fill-image"));
556 : }
557 : /* 그라데이션이 존재해도, 비트맵파일이 존재하면, 이것이 우선이다. */
558 0 : else if( prop->flag >> 16 & 0x01 ) /* 그라데이션 존재여부 */
559 : {
560 0 : padd( ascii("draw:name"), sXML_CDATA, ascii(Int2Str(hdo->index, "Grad%d", buf)));
561 0 : switch( prop->gstyle )
562 : {
563 : case 1 :
564 0 : if( prop->center_y == 50 )
565 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("axial"));
566 : else
567 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("linear"));
568 0 : break;
569 : case 2:
570 : case 3:
571 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("radial"));
572 0 : break;
573 : case 4:
574 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("square"));
575 0 : break;
576 : default:
577 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("linear"));
578 0 : break;
579 : }
580 0 : padd( ascii("draw:cx"), sXML_CDATA,ascii(Int2Str(prop->center_x, "%d%%", buf)));
581 0 : padd( ascii("draw:cy"), sXML_CDATA,ascii(Int2Str(prop->center_y, "%d%%", buf)));
582 :
583 0 : HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
584 0 : int default_color = 0xffffff;
585 0 : if( hwpinfo.back_info.isset )
586 : {
587 0 : if( hwpinfo.back_info.color[0] > 0 || hwpinfo.back_info.color[1] > 0
588 0 : || hwpinfo.back_info.color[2] > 0 )
589 0 : default_color = hwpinfo.back_info.color[0] << 16 |
590 0 : hwpinfo.back_info.color[1] << 8 | hwpinfo.back_info.color[2];
591 : }
592 :
593 0 : if( prop->fromcolor > 0xffffff )
594 0 : prop->fromcolor = default_color;
595 0 : if( prop->tocolor > 0xffffff )
596 0 : prop->tocolor = default_color;
597 :
598 0 : if( prop->gstyle == 1)
599 : {
600 0 : if( prop->center_y == 100 )
601 : {
602 : sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff,
603 0 : (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff );
604 0 : padd( ascii("draw:start-color"), sXML_CDATA, ascii( buf ));
605 : sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff,
606 0 : (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff );
607 0 : padd( ascii("draw:end-color"), sXML_CDATA, ascii( buf ));
608 : }
609 : else
610 : {
611 : sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff,
612 0 : (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff );
613 0 : padd( ascii("draw:start-color"), sXML_CDATA, ascii( buf ));
614 : sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff,
615 0 : (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff );
616 0 : padd( ascii("draw:end-color"), sXML_CDATA, ascii( buf ));
617 : }
618 : }
619 : else
620 : {
621 : sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff,
622 0 : (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff );
623 0 : padd( ascii("draw:start-color"), sXML_CDATA,ascii( buf ));
624 :
625 : sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff,
626 0 : (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff );
627 0 : padd( ascii("draw:end-color"), sXML_CDATA,ascii( buf ));
628 : }
629 0 : if( prop->angle > 0 && ( prop->gstyle == 1 || prop->gstyle == 4))
630 : {
631 0 : int angle = prop->angle >= 180 ? prop->angle - 180 : prop->angle;
632 0 : angle = 1800 - prop->angle * 10;
633 0 : padd( ascii("draw:angle"), sXML_CDATA,
634 0 : ascii(Int2Str( angle, "%d", buf)));
635 : }
636 0 : rstartEl( ascii("draw:gradient"), rList );
637 0 : pList->clear();
638 0 : rendEl( ascii("draw:gradient"));
639 : }
640 : /* 해칭 */
641 0 : else if( prop->pattern_type >> 24 & 0x01 )
642 : {
643 0 : int type = prop->pattern_type & 0xffffff;
644 0 : padd( ascii("draw:name"), sXML_CDATA,
645 0 : ascii(Int2Str(hdo->index, "Hatch%d", buf)));
646 0 : if( type < 4 )
647 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("single") );
648 : else
649 0 : padd( ascii("draw:style"), sXML_CDATA, ascii("double") );
650 : sprintf( buf, "#%02x%02x%02x",
651 : sal_uInt16(prop->pattern_color & 0xff),
652 0 : sal_uInt16((prop->pattern_color >> 8) & 0xff),
653 0 : sal_uInt16((prop->pattern_color >>16) & 0xff) );
654 0 : padd( ascii("draw:color"), sXML_CDATA, ascii( buf ));
655 0 : padd( ascii("draw:distance"), sXML_CDATA, ascii("0.12cm"));
656 0 : switch( type )
657 : {
658 : case 0 :
659 : case 4 :
660 0 : padd( ascii("draw:rotation"), sXML_CDATA, ascii("0"));
661 0 : break;
662 : case 1 :
663 0 : padd( ascii("draw:rotation"), sXML_CDATA, ascii("900"));
664 0 : break;
665 : case 2 :
666 0 : padd( ascii("draw:rotation"), sXML_CDATA, ascii("1350"));
667 0 : break;
668 : case 3 :
669 : case 5 :
670 0 : padd( ascii("draw:rotation"), sXML_CDATA, ascii("450"));
671 0 : break;
672 : }
673 0 : rstartEl( ascii("draw:hatch"), rList);
674 0 : pList->clear();
675 0 : rendEl( ascii("draw:hatch"));
676 : }
677 : }
678 0 : hdo = hdo->next;
679 : }
680 0 : }
681 :
682 :
683 2 : void HwpReader::makeStyles()
684 : {
685 2 : HWPStyle& hwpstyle = hwpfile.GetHWPStyle();
686 :
687 2 : rstartEl(ascii("office:styles"), rList);
688 :
689 : int i;
690 2 : for (i = 0; i < hwpfile.getFBoxStyleCount(); i++)
691 : {
692 0 : if( hwpfile.getFBoxStyle(i)->boxtype == 'D' )
693 : {
694 0 : makeDrawMiscStyle((HWPDrawingObject *)hwpfile.getFBoxStyle(i)->cell );
695 : }
696 : }
697 :
698 2 : padd(ascii("style:name"), sXML_CDATA, ascii("Standard"));
699 2 : padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
700 2 : padd(ascii("style:class"), sXML_CDATA, ascii("text"));
701 2 : rstartEl(ascii("style:style"), rList);
702 2 : pList->clear();
703 :
704 2 : padd(ascii("fo:line-height"), sXML_CDATA, ascii("160%"));
705 2 : padd(ascii("fo:text-align"), sXML_CDATA, ascii("justify"));
706 2 : rstartEl(ascii("style:properties"), rList);
707 2 : pList->clear();
708 2 : rstartEl(ascii("style:tab-stops"), rList);
709 :
710 80 : for( i = 1 ; i < 40 ; i++)
711 : {
712 156 : padd(ascii("style:position"), sXML_CDATA,
713 78 : Double2Str( WTI(1000 * i)) + ascii("inch"));
714 78 : rstartEl(ascii("style:tab-stop"), rList);
715 78 : pList->clear();
716 78 : rendEl(ascii("style:tab-stop"));
717 : }
718 2 : rendEl(ascii("style:tab-stops"));
719 2 : rendEl(ascii("style:properties"));
720 :
721 2 : rendEl(ascii("style:style"));
722 :
723 26 : for (int ii = 0; ii < hwpstyle.Num(); ii++)
724 : {
725 24 : unsigned char *stylename = (unsigned char *) hwpstyle.GetName(ii);
726 24 : padd(ascii("style:name"), sXML_CDATA, (hconv(kstr2hstr(stylename).c_str())));
727 24 : padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
728 24 : padd(ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
729 :
730 24 : rstartEl(ascii("style:style"), rList);
731 :
732 24 : pList->clear();
733 :
734 24 : parseCharShape(hwpstyle.GetCharShape(ii));
735 24 : parseParaShape(hwpstyle.GetParaShape(ii));
736 :
737 24 : rstartEl(ascii("style:properties"), rList);
738 24 : pList->clear();
739 24 : rendEl(ascii("style:properties"));
740 :
741 24 : rendEl(ascii("style:style"));
742 : }
743 :
744 : {
745 2 : padd( ascii("style:name"), sXML_CDATA, ascii("Header"));
746 2 : padd( ascii("style:family"), sXML_CDATA, ascii("paragraph"));
747 2 : padd( ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
748 2 : padd( ascii("style:class"), sXML_CDATA, ascii("extra"));
749 2 : rstartEl(ascii("style:style"), rList);
750 2 : pList->clear();
751 2 : rendEl(ascii("style:style"));
752 : }
753 :
754 : {
755 2 : padd( ascii("style:name"), sXML_CDATA, ascii("Footer"));
756 2 : padd( ascii("style:family"), sXML_CDATA, ascii("paragraph"));
757 2 : padd( ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
758 2 : padd( ascii("style:class"), sXML_CDATA, ascii("extra"));
759 2 : rstartEl(ascii("style:style"), rList);
760 2 : pList->clear();
761 :
762 2 : rendEl(ascii("style:style"));
763 : }
764 :
765 2 : if( hwpfile.linenumber > 0)
766 : {
767 0 : padd( ascii("style:name"), sXML_CDATA, ascii("Horizontal Line"));
768 0 : padd( ascii("style:family"), sXML_CDATA, ascii("paragraph"));
769 0 : padd( ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
770 0 : padd( ascii("style:class"), sXML_CDATA, ascii("html"));
771 0 : rstartEl( ascii("style:style"), rList);
772 0 : pList->clear();
773 0 : padd( ascii("fo:font-size"), sXML_CDATA, ascii("6pt"));
774 0 : padd( ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
775 0 : padd( ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
776 0 : padd( ascii("style:border-line-width-bottom"), sXML_CDATA, ascii("0.02cm 0.035cm 0.002cm"));
777 0 : padd( ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
778 0 : padd( ascii("fo:border-bottom"), sXML_CDATA, ascii("0.039cm double #808080"));
779 0 : padd( ascii("text:number-lines"), sXML_CDATA, ascii("false"));
780 0 : padd( ascii("text:line-number"), sXML_CDATA, ascii("0"));
781 0 : padd(ascii("fo:line-height"), sXML_CDATA, ascii("100%"));
782 0 : rstartEl( ascii("style:properties"), rList);
783 0 : pList->clear();
784 0 : rendEl( ascii("style:properties"));
785 0 : rendEl( ascii("style:style"));
786 : }
787 :
788 2 : HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
789 :
790 2 : padd(ascii("text:num-suffix"), sXML_CDATA, ascii(")"));
791 2 : padd(ascii("text:num-format"), sXML_CDATA, ascii("1"));
792 2 : if( hwpinfo.beginfnnum != 1)
793 0 : padd(ascii("text:offset"), sXML_CDATA, ascii(Int2Str(hwpinfo.beginfnnum -1, "%d", buf)));
794 2 : rstartEl(ascii("text:footnotes-configuration"), rList);
795 2 : pList->clear();
796 2 : rendEl(ascii("text:footnotes-configuration"));
797 :
798 2 : rendEl(ascii("office:styles"));
799 2 : }
800 :
801 :
802 : /**
803 : * parse automatic styles from hwpfile
804 : * 자동적으로 반영이 되는 스타일을 정의한다. 예를들어 각각의 문단이나, 테이블, 헤더 등등의 스타일을 이곳에서 정의하고, Body에서는 이곳에 정의된 스타일을 이용한다.
805 : * 1. paragraph, text, fbox, page스타일에 대해 지원한다.
806 : */
807 2 : void HwpReader::makeAutoStyles()
808 : {
809 : int i;
810 :
811 2 : rstartEl(ascii("office:automatic-styles"), rList);
812 :
813 4 : for (i = 0; i < hwpfile.getParaShapeCount(); i++)
814 2 : makePStyle(hwpfile.getParaShape(i));
815 :
816 4 : for (i = 0; i < hwpfile.getCharShapeCount(); i++)
817 2 : makeTStyle(hwpfile.getCharShape(i));
818 :
819 2 : for( i = 0 ; i < hwpfile.getTableCount(); i++)
820 0 : makeTableStyle(hwpfile.getTable(i));
821 :
822 2 : for (i = 0; i < hwpfile.getFBoxStyleCount(); i++)
823 : {
824 0 : if( hwpfile.getFBoxStyle(i)->boxtype == 'D' )
825 0 : makeDrawStyle((HWPDrawingObject *)hwpfile.getFBoxStyle(i)->cell, hwpfile.getFBoxStyle(i));
826 : else
827 0 : makeFStyle(hwpfile.getFBoxStyle(i));
828 : }
829 :
830 2 : bool bIsLeft = false, bIsMiddle = false, bIsRight = false;
831 2 : for( i = 0 ; i < hwpfile.getPageNumberCount() ; i++ )
832 : {
833 0 : ShowPageNum *pn = hwpfile.getPageNumber(i);
834 0 : if( pn->where == 7 || pn->where == 8 )
835 : {
836 0 : bIsLeft = true;
837 0 : bIsRight = true;
838 : }
839 0 : else if( pn->where == 1 || pn->where == 4 )
840 : {
841 0 : bIsLeft = true;
842 : }
843 0 : else if( pn->where == 2 || pn->where == 5 )
844 : {
845 0 : bIsMiddle = true;
846 : }
847 0 : else if( pn->where == 3 || pn->where == 6 )
848 : {
849 0 : bIsRight = true;
850 : }
851 : }
852 :
853 8 : for( i = 1; i <= 3 ; i++ )
854 : {
855 6 : if( i == 1 && bIsLeft == false )
856 2 : continue;
857 4 : if( i == 2 && bIsMiddle == false )
858 2 : continue;
859 2 : if( i == 3 && bIsRight == false )
860 2 : continue;
861 0 : padd(ascii("style:name"), sXML_CDATA,
862 0 : ascii(Int2Str(i,"PNPara%d", buf)));
863 0 : padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
864 0 : padd(ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
865 0 : rstartEl(ascii("style:style"), rList);
866 0 : pList->clear();
867 0 : if( i == 1 )
868 0 : padd(ascii("fo:text-align"), sXML_CDATA, ascii("start"));
869 0 : else if ( i == 2 )
870 0 : padd(ascii("fo:text-align"), sXML_CDATA, ascii("center"));
871 0 : else if ( i == 3 )
872 0 : padd(ascii("fo:text-align"), sXML_CDATA, ascii("end"));
873 0 : rstartEl(ascii("style:properties"), rList);
874 0 : pList->clear();
875 0 : rendEl( ascii("style:properties"));
876 0 : rendEl( ascii("style:style"));
877 :
878 0 : padd(ascii("style:name"), sXML_CDATA, ascii(Int2Str(i,"PNBox%d",buf)));
879 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
880 0 : rstartEl(ascii("style:style"), rList);
881 0 : pList->clear();
882 :
883 0 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
884 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
885 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
886 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
887 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
888 :
889 0 : if( i == 1 )
890 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("left"));
891 0 : else if ( i == 2 )
892 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
893 0 : else if ( i == 3 )
894 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("right"));
895 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
896 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
897 0 : padd(ascii("stylefamily"), sXML_CDATA, ascii("graphics"));
898 0 : rstartEl(ascii("style:properties"), rList);
899 0 : pList->clear();
900 0 : rendEl(ascii("style:properties"));
901 0 : rendEl(ascii("style:style"));
902 : }
903 :
904 2 : for (i = 0; i < hwpfile.getDateFormatCount(); i++)
905 0 : makeDateFormat(hwpfile.getDateCode(i));
906 :
907 2 : makePageStyle();
908 :
909 2 : rendEl(ascii("office:automatic-styles"));
910 2 : }
911 :
912 :
913 : struct PageSetting
914 : {
915 4 : PageSetting()
916 : {
917 4 : header = 0L;
918 4 : header_odd = 0L;
919 4 : header_even = 0L;
920 4 : footer = 0L;
921 4 : footer_odd = 0L;
922 4 : footer_even = 0L;
923 4 : pagenumber=0L;
924 4 : bIsSet = false;
925 4 : }
926 : HeaderFooter *header ;
927 : HeaderFooter *header_odd ;
928 : HeaderFooter *header_even ;
929 : HeaderFooter *footer ;
930 : HeaderFooter *footer_odd ;
931 : HeaderFooter *footer_even ;
932 : ShowPageNum *pagenumber;
933 : bool bIsSet;
934 : };
935 :
936 2 : void HwpReader::makeMasterStyles()
937 : {
938 2 : rstartEl(ascii("office:master-styles"), rList);
939 :
940 : int i;
941 2 : int nMax = hwpfile.getMaxSettedPage();
942 2 : std::deque<PageSetting> pSet(nMax + 1);
943 :
944 2 : for( i = 0 ; i < hwpfile.getPageNumberCount() ; i++ )
945 : {
946 0 : ShowPageNum *pn = hwpfile.getPageNumber(i);
947 0 : pSet[pn->m_nPageNumber].pagenumber = pn;
948 0 : pSet[pn->m_nPageNumber].bIsSet = true;
949 : }
950 2 : for( i = 0 ; i < hwpfile.getHeaderFooterCount() ; i++ )
951 : {
952 0 : HeaderFooter* hf = hwpfile.getHeaderFooter(i);
953 0 : pSet[hf->m_nPageNumber].bIsSet = true;
954 0 : if( hf->type == 0 ) // header
955 : {
956 0 : switch( hf->where )
957 : {
958 : case 0 :
959 0 : pSet[hf->m_nPageNumber].header = hf;
960 0 : pSet[hf->m_nPageNumber].header_even = 0L;
961 0 : pSet[hf->m_nPageNumber].header_odd = 0L;
962 0 : break;
963 : case 1:
964 0 : pSet[hf->m_nPageNumber].header_even = hf;
965 0 : if( pSet[hf->m_nPageNumber].header )
966 : {
967 0 : pSet[hf->m_nPageNumber].header_odd =
968 0 : pSet[hf->m_nPageNumber].header;
969 0 : pSet[hf->m_nPageNumber].header = 0L;
970 : }
971 0 : break;
972 : case 2:
973 0 : pSet[hf->m_nPageNumber].header_odd = hf;
974 0 : if( pSet[hf->m_nPageNumber].header )
975 : {
976 0 : pSet[hf->m_nPageNumber].header_even =
977 0 : pSet[hf->m_nPageNumber].header;
978 0 : pSet[hf->m_nPageNumber].header = 0L;
979 : }
980 0 : break;
981 : }
982 : }
983 : else // footer
984 : {
985 0 : switch( hf->where )
986 : {
987 : case 0 :
988 0 : pSet[hf->m_nPageNumber].footer = hf;
989 0 : pSet[hf->m_nPageNumber].footer_even = 0L;
990 0 : pSet[hf->m_nPageNumber].footer_odd = 0L;
991 0 : break;
992 : case 1:
993 0 : pSet[hf->m_nPageNumber].footer_even = hf;
994 0 : if( pSet[hf->m_nPageNumber].footer )
995 : {
996 0 : pSet[hf->m_nPageNumber].footer_odd =
997 0 : pSet[hf->m_nPageNumber].footer;
998 0 : pSet[hf->m_nPageNumber].footer = 0L;
999 : }
1000 0 : break;
1001 : case 2:
1002 0 : pSet[hf->m_nPageNumber].footer_odd = hf;
1003 0 : if( pSet[hf->m_nPageNumber].footer )
1004 : {
1005 0 : pSet[hf->m_nPageNumber].footer_even =
1006 0 : pSet[hf->m_nPageNumber].footer;
1007 0 : pSet[hf->m_nPageNumber].footer = 0L;
1008 : }
1009 0 : break;
1010 : }
1011 : }
1012 : }
1013 :
1014 2 : PageSetting *pPrevSet = 0L;
1015 2 : PageSetting *pPage = 0L;
1016 :
1017 4 : for( i = 1; i <= nMax ; i++ )
1018 : {
1019 2 : if( i == 1 )
1020 2 : padd(ascii("style:name"), sXML_CDATA, ascii("Standard"));
1021 : else
1022 0 : padd(ascii("style:name"), sXML_CDATA,
1023 0 : ascii(Int2Str(i, "p%d", buf)));
1024 4 : padd(ascii("style:page-master-name"), sXML_CDATA,
1025 2 : ascii(Int2Str(hwpfile.GetPageMasterNum(i), "pm%d", buf)));
1026 2 : if( i < nMax )
1027 0 : padd(ascii("style:next-style-name"), sXML_CDATA,
1028 0 : ascii(Int2Str(i+1, "p%d", buf)));
1029 4 : padd(ascii("draw:style-name"), sXML_CDATA,
1030 2 : ascii(Int2Str(i, "master%d", buf)));
1031 2 : rstartEl(ascii("style:master-page"), rList);
1032 2 : pList->clear();
1033 :
1034 2 : if( pSet[i].bIsSet ) /* 현재 설정이 바뀌었으면 */
1035 : {
1036 0 : if( !pSet[i].pagenumber ){
1037 0 : if( pPrevSet && pPrevSet->pagenumber )
1038 0 : pSet[i].pagenumber = pPrevSet->pagenumber;
1039 : }
1040 0 : if( pSet[i].pagenumber )
1041 : {
1042 0 : if( pSet[i].pagenumber->where == 7 && pSet[i].header )
1043 : {
1044 0 : pSet[i].header_even = pSet[i].header;
1045 0 : pSet[i].header_odd = pSet[i].header;
1046 0 : pSet[i].header = 0L;
1047 : }
1048 0 : if( pSet[i].pagenumber->where == 8 && pSet[i].footer )
1049 : {
1050 0 : pSet[i].footer_even = pSet[i].footer;
1051 0 : pSet[i].footer_odd = pSet[i].footer;
1052 0 : pSet[i].footer = 0L;
1053 : }
1054 : }
1055 :
1056 0 : if( !pSet[i].header_even && pPrevSet && pPrevSet->header_even )
1057 : {
1058 0 : pSet[i].header_even = pPrevSet->header_even;
1059 : }
1060 0 : if( !pSet[i].header_odd && pPrevSet && pPrevSet->header_odd )
1061 : {
1062 0 : pSet[i].header_odd = pPrevSet->header_odd;
1063 : }
1064 0 : if( !pSet[i].footer_even && pPrevSet && pPrevSet->footer_even )
1065 : {
1066 0 : pSet[i].footer_even = pPrevSet->footer_even;
1067 : }
1068 0 : if( !pSet[i].footer_odd && pPrevSet && pPrevSet->footer_odd )
1069 : {
1070 0 : pSet[i].footer_odd = pPrevSet->footer_odd;
1071 : }
1072 :
1073 0 : pPage = &pSet[i];
1074 0 : pPrevSet = &pSet[i];
1075 : }
1076 2 : else if( pPrevSet ) /* 이전의 설정된 것이 있으면. */
1077 : {
1078 0 : pPage = pPrevSet;
1079 : }
1080 : else /* 아직 설정이 없다면 기본설정으로 */
1081 : {
1082 2 : rstartEl(ascii("style:header"), rList);
1083 2 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1084 2 : rstartEl(ascii("text:p"), rList);
1085 2 : pList->clear();
1086 2 : rendEl(ascii("text:p"));
1087 2 : rendEl(ascii("style:header"));
1088 :
1089 2 : rstartEl(ascii("style:footer"), rList);
1090 2 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1091 2 : rstartEl(ascii("text:p"), rList);
1092 2 : pList->clear();
1093 2 : rendEl(ascii("text:p"));
1094 2 : rendEl(ascii("style:footer"));
1095 :
1096 2 : rendEl(ascii("style:master-page"));
1097 :
1098 2 : continue;
1099 : }
1100 : // ------------- header -------------
1101 0 : if( pPage->header )
1102 : {
1103 0 : rstartEl(ascii("style:header"), rList);
1104 0 : if( pPage->pagenumber && pPage->pagenumber->where < 4 )
1105 : {
1106 0 : d->bInHeader = true;
1107 0 : d->pPn = pPage->pagenumber;
1108 : }
1109 0 : parsePara(pPage->header->plist.front());
1110 0 : d->bInHeader = false;
1111 0 : d->pPn = 0L;
1112 0 : rendEl(ascii("style:header"));
1113 : }
1114 0 : if( pPage->header_even )
1115 : {
1116 0 : rstartEl(ascii("style:header"), rList);
1117 0 : if( pPage->pagenumber && ( pPage->pagenumber->where < 4
1118 0 : || pPage->pagenumber->where == 7 ) )
1119 : {
1120 0 : d->bInHeader = true;
1121 0 : d->pPn = pPage->pagenumber;
1122 0 : d->nPnPos = 3;
1123 : }
1124 0 : parsePara(pPage->header_even->plist.front());
1125 0 : d->bInHeader = false;
1126 0 : d->pPn = 0L;
1127 0 : d->nPnPos = 0;
1128 0 : rendEl(ascii("style:header"));
1129 : }
1130 : /* 기본으로 한다. */
1131 0 : else if( pPage->header_odd && !pPage->header_even )
1132 : {
1133 0 : rstartEl(ascii("style:header"), rList);
1134 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1135 0 : rstartEl(ascii("text:p"), rList);
1136 0 : pList->clear();
1137 0 : if( pPage->pagenumber && ( pPage->pagenumber->where < 4 ||
1138 0 : pPage->pagenumber->where == 7 ) )
1139 : {
1140 0 : d->pPn = pPage->pagenumber;
1141 0 : d->nPnPos = 3;
1142 0 : makeShowPageNum();
1143 0 : d->pPn = 0L;
1144 0 : d->nPnPos = 0;
1145 : }
1146 0 : rendEl(ascii("text:p"));
1147 0 : rendEl(ascii("style:header"));
1148 : }
1149 0 : if( pPage->header_odd )
1150 : {
1151 0 : rstartEl(ascii("style:header-left"), rList);
1152 0 : if( pPage->pagenumber && ( pPage->pagenumber->where < 4
1153 0 : || pPage->pagenumber->where == 7 ) )
1154 : {
1155 0 : d->bInHeader = true;
1156 0 : d->nPnPos = 1;
1157 0 : d->pPn = pPage->pagenumber;
1158 : }
1159 0 : parsePara(pPage->header_odd->plist.front());
1160 0 : d->bInHeader = false;
1161 0 : d->pPn = 0L;
1162 0 : d->nPnPos = 0;
1163 0 : rendEl(ascii("style:header-left"));
1164 : }
1165 : /* 기본으로 한다. */
1166 0 : else if( pPage->header_even && !pPage->header_odd )
1167 : {
1168 0 : rstartEl(ascii("style:header-left"), rList);
1169 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1170 0 : rstartEl(ascii("text:p"), rList);
1171 0 : pList->clear();
1172 0 : if( pPage->pagenumber && ( pPage->pagenumber->where < 4 ||
1173 0 : pPage->pagenumber->where == 7 ) )
1174 : {
1175 0 : d->pPn = pPage->pagenumber;
1176 0 : d->nPnPos = 1;
1177 0 : makeShowPageNum();
1178 0 : d->pPn = 0L;
1179 0 : d->nPnPos = 0;
1180 : }
1181 0 : rendEl(ascii("text:p"));
1182 0 : rendEl(ascii("style:header-left"));
1183 : }
1184 0 : if( !pPage->header && !pPage->header_even && !pPage->header_odd )
1185 : {
1186 0 : rstartEl(ascii("style:header"), rList);
1187 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1188 0 : rstartEl(ascii("text:p"), rList);
1189 0 : pList->clear();
1190 0 : if( pPage->pagenumber && (pPage->pagenumber->where < 4 ||
1191 0 : pPage->pagenumber->where == 7 ) )
1192 : {
1193 0 : d->pPn = pPage->pagenumber;
1194 0 : makeShowPageNum();
1195 0 : d->pPn = 0L;
1196 : }
1197 0 : rendEl(ascii("text:p"));
1198 0 : rendEl(ascii("style:header"));
1199 : }
1200 : // ------------- footer -------------
1201 0 : if( pPage->footer )
1202 : {
1203 0 : rstartEl(ascii("style:footer"), rList);
1204 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1205 0 : && pPage->pagenumber->where != 7 )
1206 : {
1207 0 : d->bInHeader = true;
1208 0 : d->pPn = pPage->pagenumber;
1209 : }
1210 0 : parsePara(pPage->footer->plist.front());
1211 0 : d->bInHeader = false;
1212 0 : d->pPn = 0L;
1213 0 : rendEl(ascii("style:footer"));
1214 : }
1215 0 : if( pPage->footer_even )
1216 : {
1217 0 : rstartEl(ascii("style:footer"), rList);
1218 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1219 0 : && pPage->pagenumber->where != 7 )
1220 : {
1221 0 : d->bInHeader = true;
1222 0 : d->pPn = pPage->pagenumber;
1223 0 : d->nPnPos = 3;
1224 : }
1225 0 : parsePara(pPage->footer_even->plist.front());
1226 0 : d->bInHeader = false;
1227 0 : d->pPn = 0L;
1228 0 : d->nPnPos = 0;
1229 0 : rendEl(ascii("style:footer"));
1230 : }
1231 : /* 기본으로 한다. */
1232 0 : else if( pPage->footer_odd && !pPage->footer_even )
1233 : {
1234 0 : rstartEl(ascii("style:footer"), rList);
1235 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1236 0 : rstartEl(ascii("text:p"), rList);
1237 0 : pList->clear();
1238 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1239 0 : && pPage->pagenumber->where != 7 )
1240 : {
1241 0 : d->pPn = pPage->pagenumber;
1242 0 : d->nPnPos = 3;
1243 0 : makeShowPageNum();
1244 0 : d->pPn = 0L;
1245 0 : d->nPnPos = 0;
1246 : }
1247 0 : rendEl(ascii("text:p"));
1248 0 : rendEl(ascii("style:footer"));
1249 : }
1250 0 : if( pPage->footer_odd )
1251 : {
1252 0 : rstartEl(ascii("style:footer-left"), rList);
1253 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1254 0 : && pPage->pagenumber->where != 7 )
1255 : {
1256 0 : d->bInHeader = true;
1257 0 : d->pPn = pPage->pagenumber;
1258 0 : d->nPnPos = 1;
1259 : }
1260 0 : parsePara(pPage->footer_odd->plist.front());
1261 0 : d->bInHeader = false;
1262 0 : d->pPn = 0L;
1263 0 : d->nPnPos = 0;
1264 0 : rendEl(ascii("style:footer-left"));
1265 : }
1266 : /* 기본으로 한다. */
1267 0 : else if( pPage->footer_even && !pPage->footer_odd )
1268 : {
1269 0 : rstartEl(ascii("style:footer-left"), rList);
1270 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1271 0 : rstartEl(ascii("text:p"), rList);
1272 0 : pList->clear();
1273 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1274 0 : && pPage->pagenumber->where != 7 )
1275 : {
1276 0 : d->pPn = pPage->pagenumber;
1277 0 : d->nPnPos = 1;
1278 0 : makeShowPageNum();
1279 0 : d->pPn = 0L;
1280 0 : d->nPnPos = 0;
1281 : }
1282 0 : rendEl(ascii("text:p"));
1283 0 : rendEl(ascii("style:footer-left"));
1284 : }
1285 0 : if( !pPage->footer && !pPage->footer_even && !pPage->footer_odd )
1286 : {
1287 0 : rstartEl(ascii("style:footer"), rList);
1288 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
1289 0 : rstartEl(ascii("text:p"), rList);
1290 0 : pList->clear();
1291 0 : if( pPage->pagenumber && pPage->pagenumber->where >= 4
1292 0 : && pPage->pagenumber->where != 7 )
1293 : {
1294 0 : d->pPn = pPage->pagenumber;
1295 0 : makeShowPageNum();
1296 0 : d->pPn = 0L;
1297 : }
1298 0 : rendEl(ascii("text:p"));
1299 0 : rendEl(ascii("style:footer"));
1300 : }
1301 :
1302 0 : rendEl(ascii("style:master-page"));
1303 : }
1304 2 : rendEl(ascii("office:master-styles"));
1305 2 : }
1306 :
1307 :
1308 : /**
1309 : * 텍스트 스타일을 위한 프로퍼티들을 만든다.
1310 : * 1. fo:font-size, fo:font-family, fo:letter-spacing, fo:color,
1311 : * style:text-background-color, fo:font-style, fo:font-weight,
1312 : * style:text-underline,style:text-outline,fo:text-shadow,style:text-position
1313 : * 을 지원한다.
1314 : */
1315 28 : void HwpReader::parseCharShape(CharShape * cshape)
1316 : {
1317 28 : HWPFont& hwpfont = hwpfile.GetHWPFont();
1318 :
1319 56 : padd(ascii("fo:font-size"), sXML_CDATA,
1320 28 : ascii(Int2Str(cshape->size / 25, "%dpt", buf)));
1321 56 : padd(ascii("style:font-size-asian"), sXML_CDATA,
1322 28 : ascii(Int2Str(cshape->size / 25, "%dpt", buf)));
1323 :
1324 : ::std::string const tmp = hstr2ksstr(kstr2hstr(
1325 28 : (unsigned char *) hwpfont.GetFontName(0, cshape->font[0])).c_str());
1326 28 : double fRatio = 1.0;
1327 28 : int size = getRepFamilyName(tmp.c_str(), buf, fRatio);
1328 :
1329 56 : padd(ascii("fo:font-family"), sXML_CDATA,
1330 28 : OUString(buf, size, RTL_TEXTENCODING_EUC_KR));
1331 56 : padd(ascii("style:font-family-asian"), sXML_CDATA,
1332 28 : OUString(buf, size, RTL_TEXTENCODING_EUC_KR));
1333 :
1334 56 : padd(ascii("style:text-scale"), sXML_CDATA,
1335 28 : ascii(Int2Str((int)(cshape->ratio[0] * fRatio), "%d%%", buf)));
1336 :
1337 28 : double sspace = (cshape->size / 25) * cshape->space[0] / 100.;
1338 :
1339 28 : if (sspace != 0.)
1340 : {
1341 8 : padd(ascii("fo:letter-spacing"), sXML_CDATA,
1342 4 : Double2Str(sspace) + ascii("pt"));
1343 : }
1344 28 : if (cshape->color[1] != 0)
1345 0 : padd(ascii("fo:color"), sXML_CDATA,
1346 0 : ascii(hcolor2str(cshape->color[1], 100, buf, true)));
1347 28 : if (cshape->shade != 0)
1348 0 : padd(ascii("style:text-background-color"), sXML_CDATA,
1349 0 : ascii(hcolor2str(cshape->color[0], cshape->shade, buf)));
1350 28 : if (cshape->attr & 0x01)
1351 : {
1352 0 : padd(ascii("fo:font-style"), sXML_CDATA, ascii("italic"));
1353 0 : padd(ascii("style:font-style-asian"), sXML_CDATA, ascii("italic"));
1354 : }
1355 : else{
1356 28 : padd(ascii("fo:font-style"), sXML_CDATA, ascii("normal"));
1357 28 : padd(ascii("style:font-style-asian"), sXML_CDATA, ascii("normal"));
1358 : }
1359 28 : if (cshape->attr >> 1 & 0x01)
1360 : {
1361 0 : padd(ascii("fo:font-weight"), sXML_CDATA, ascii("bold"));
1362 0 : padd(ascii("style:font-weight-asian"), sXML_CDATA, ascii("bold"));
1363 : }
1364 : else{
1365 28 : padd(ascii("fo:font-weight"), sXML_CDATA, ascii("normal"));
1366 28 : padd(ascii("style:font-weight-asian"), sXML_CDATA, ascii("normal"));
1367 : }
1368 28 : if (cshape->attr >> 2 & 0x01)
1369 0 : padd(ascii("style:text-underline"), sXML_CDATA, ascii("single"));
1370 28 : if (cshape->attr >> 3 & 0x01)
1371 0 : padd(ascii("style:text-outline"), sXML_CDATA, ascii("true"));
1372 28 : if (cshape->attr >> 4 & 0x01)
1373 0 : padd(ascii("fo:text-shadow"), sXML_CDATA, ascii("1pt 1pt"));
1374 28 : if (cshape->attr >> 5 & 0x01)
1375 0 : padd(ascii("style:text-position"), sXML_CDATA, ascii("super 58%"));
1376 28 : if (cshape->attr >> 6 & 0x01)
1377 0 : padd(ascii("style:text-position"), sXML_CDATA, ascii("sub 58%"));
1378 :
1379 28 : }
1380 :
1381 :
1382 : /**
1383 : * 실제 Paragraph에 해당하는 properties들을 만든다.
1384 : * 1. fo:margin-left,fo:margin-right,fo:margin-top, fo:margin-bottom,
1385 : * fo:text-indent, fo:line-height, fo:text-align, fo:border
1386 : * 가 구현됨.
1387 : * TODO : 탭설정 => 기본값이 아닌것들만 선택적으로 설정해야 한다.
1388 : */
1389 26 : void HwpReader::parseParaShape(ParaShape * pshape)
1390 : {
1391 :
1392 26 : if (pshape->left_margin != 0)
1393 8 : padd(ascii("fo:margin-left"), sXML_CDATA, Double2Str
1394 4 : (WTI(pshape->left_margin )) + ascii("inch"));
1395 26 : if (pshape->right_margin != 0)
1396 0 : padd(ascii("fo:margin-right"), sXML_CDATA, Double2Str
1397 0 : (WTI(pshape->right_margin)) + ascii("inch"));
1398 26 : if (pshape->pspacing_prev != 0)
1399 0 : padd(ascii("fo:margin-top"), sXML_CDATA, Double2Str
1400 0 : (WTI(pshape->pspacing_prev)) + ascii("inch"));
1401 26 : if (pshape->pspacing_next != 0)
1402 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, Double2Str
1403 0 : (WTI(pshape->pspacing_next)) + ascii("inch"));
1404 26 : if (pshape->indent != 0)
1405 4 : padd(ascii("fo:text-indent"), sXML_CDATA, Double2Str
1406 2 : (WTI(pshape->indent)) + ascii("inch"));
1407 26 : if (pshape->lspacing != 0)
1408 52 : padd(ascii("fo:line-height"), sXML_CDATA,
1409 26 : ascii(Int2Str (pshape->lspacing, "%d%%", buf)));
1410 :
1411 26 : unsigned char set_align = 0;
1412 :
1413 26 : switch ((int) pshape->arrange_type)
1414 : {
1415 : case 1:
1416 0 : strcpy(buf, "start");
1417 0 : set_align = 1;
1418 0 : break;
1419 : case 2:
1420 0 : strcpy(buf, "end");
1421 0 : set_align = 1;
1422 0 : break;
1423 : case 3:
1424 0 : strcpy(buf, "center");
1425 0 : set_align = 1;
1426 0 : break;
1427 : case 4:
1428 : case 5:
1429 : case 6:
1430 26 : strcpy(buf, "justify");
1431 26 : set_align = 1;
1432 26 : break;
1433 : }
1434 :
1435 26 : if (set_align)
1436 26 : padd(ascii("fo:text-align"), sXML_CDATA, ascii(buf));
1437 :
1438 26 : if (pshape->outline)
1439 0 : padd(ascii("fo:border"), sXML_CDATA, ascii("0.002cm solid #000000"));
1440 26 : if( pshape->shade > 0 )
1441 : {
1442 0 : padd(ascii("fo:background-color"), sXML_CDATA,
1443 0 : ascii(hcolor2str(0, pshape->shade, buf)));
1444 : }
1445 :
1446 26 : if( pshape->pagebreak & 0x02 || pshape->pagebreak & 0x04)
1447 0 : padd(ascii("fo:break-before"), sXML_CDATA, ascii("page"));
1448 26 : else if( pshape->pagebreak & 0x01 )
1449 0 : padd(ascii("fo:break-before"), sXML_CDATA, ascii("column"));
1450 :
1451 26 : }
1452 :
1453 :
1454 : /**
1455 : * Paragraph에 대한 스타일을 만든다.
1456 : */
1457 2 : void HwpReader::makePStyle(ParaShape * pshape)
1458 : {
1459 2 : int nscount = pshape->tabs[MAXTABS -1].type;
1460 4 : padd(ascii("style:name"), sXML_CDATA,
1461 2 : ascii(Int2Str(pshape->index, "P%d", buf)));
1462 2 : padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
1463 2 : rstartEl(ascii("style:style"), rList);
1464 2 : pList->clear();
1465 2 : parseParaShape(pshape);
1466 2 : parseCharShape(pshape->cshape);
1467 2 : rstartEl(ascii("style:properties"), rList);
1468 2 : pList->clear();
1469 :
1470 2 : if( nscount )
1471 : {
1472 0 : unsigned char tf = 0;
1473 0 : rstartEl(ascii("style:tab-stops"),rList);
1474 :
1475 0 : int tab_margin = pshape->left_margin + pshape->indent;
1476 0 : if( tab_margin < 0 )
1477 0 : tab_margin = 0;
1478 0 : for( int i = 0 ; i < MAXTABS -1 ; i++)
1479 : {
1480 0 : if( i > 0 && pshape->tabs[i].position == 0. )
1481 0 : break;
1482 0 : if( pshape->tabs[i].position <= tab_margin )
1483 0 : continue;
1484 0 : padd(ascii("style:position"), sXML_CDATA,
1485 0 : Double2Str(WTMM(pshape->tabs[i].position - tab_margin )) + ascii("mm"));
1486 0 : if( pshape->tabs[i].type )
1487 : {
1488 0 : tf = 1;
1489 0 : switch(pshape->tabs[i].type)
1490 : {
1491 : case 1 :
1492 0 : padd(ascii("style:type"), sXML_CDATA, ascii("right"));
1493 0 : break;
1494 : case 2:
1495 0 : padd(ascii("style:type"), sXML_CDATA, ascii("center"));
1496 0 : break;
1497 : case 3:
1498 0 : padd(ascii("style:type"), sXML_CDATA, ascii("char"));
1499 0 : padd(ascii("style:char"), sXML_CDATA, ascii("."));
1500 0 : break;
1501 : }
1502 : }
1503 0 : if( pshape->tabs[i].dot_continue )
1504 : {
1505 0 : tf = 1;
1506 0 : padd(ascii("style:leader-char"), sXML_CDATA, ascii("."));
1507 : }
1508 0 : rstartEl( ascii("style:tab-stop"), rList);
1509 0 : pList->clear();
1510 0 : rendEl( ascii("style:tab-stop") );
1511 :
1512 0 : if( (pshape->tabs[i].position != 1000 * i ) || tf )
1513 : {
1514 0 : if( !--nscount ) break;
1515 : }
1516 : }
1517 0 : rendEl( ascii("style:tab-stops"));
1518 : }
1519 2 : rendEl(ascii("style:properties"));
1520 2 : rendEl(ascii("style:style"));
1521 2 : }
1522 :
1523 :
1524 : /**
1525 : * 페이지의 스타일을 만든다. 여기에는 header/footer, footnote등이 포함된다.
1526 : * TODO : , fo:background-color(정보가 없다)
1527 : */
1528 2 : void HwpReader::makePageStyle()
1529 : {
1530 2 : HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
1531 2 : int pmCount = hwpfile.getColumnCount();
1532 :
1533 4 : for( int i = 0 ; i < pmCount ; i++ ){
1534 2 : padd(ascii("style:name"), sXML_CDATA, ascii(Int2Str(i + 1, "pm%d", buf)));
1535 2 : rstartEl(ascii("style:page-master"),rList);
1536 2 : pList->clear();
1537 :
1538 :
1539 2 : switch( hwpinfo.paper.paper_kind )
1540 : {
1541 : case 3: // A4
1542 2 : if( hwpinfo.paper.paper_direction )
1543 : {
1544 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("210mm"));
1545 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("297mm"));
1546 : }
1547 : else
1548 : {
1549 2 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("210mm"));
1550 2 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("297mm"));
1551 : }
1552 2 : break;
1553 : case 4: // 80 column
1554 0 : if( hwpinfo.paper.paper_direction )
1555 : {
1556 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("8.5inch"));
1557 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("11inch"));
1558 : }
1559 : else
1560 : {
1561 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("8.5inch"));
1562 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("11inch"));
1563 : }
1564 0 : break;
1565 : case 5: // B5
1566 0 : if( hwpinfo.paper.paper_direction )
1567 : {
1568 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("176mm"));
1569 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("250mm"));
1570 : }
1571 : else
1572 : {
1573 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("176mm"));
1574 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("250mm"));
1575 : }
1576 0 : break;
1577 : case 6: // B4
1578 0 : if( hwpinfo.paper.paper_direction )
1579 : {
1580 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("250mm"));
1581 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("353mm"));
1582 : }
1583 : else
1584 : {
1585 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("250mm"));
1586 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("353mm"));
1587 : }
1588 0 : break;
1589 : case 7:
1590 0 : if( hwpinfo.paper.paper_direction )
1591 : {
1592 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("8.5inch"));
1593 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("14inch"));
1594 : }
1595 : else
1596 : {
1597 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("8.5inch"));
1598 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("14inch"));
1599 : }
1600 0 : break;
1601 : case 8:
1602 0 : if( hwpinfo.paper.paper_direction )
1603 : {
1604 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("297mm"));
1605 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("420mm"));
1606 : }
1607 : else
1608 : {
1609 0 : padd(ascii("fo:page-width"),sXML_CDATA, ascii("297mm"));
1610 0 : padd(ascii("fo:page-height"),sXML_CDATA, ascii("420mm"));
1611 : }
1612 0 : break;
1613 : case 0:
1614 : case 1:
1615 : case 2:
1616 : default:
1617 0 : if( hwpinfo.paper.paper_direction )
1618 : {
1619 0 : padd(ascii("fo:page-width"),sXML_CDATA,
1620 0 : Double2Str(WTI(hwpinfo.paper.paper_height)) + ascii("inch"));
1621 0 : padd(ascii("fo:page-height"),sXML_CDATA,
1622 0 : Double2Str(WTI(hwpinfo.paper.paper_width)) + ascii("inch"));
1623 : }
1624 : else
1625 : {
1626 0 : padd(ascii("fo:page-width"),sXML_CDATA,
1627 0 : Double2Str(WTI(hwpinfo.paper.paper_width)) + ascii("inch"));
1628 0 : padd(ascii("fo:page-height"),sXML_CDATA,
1629 0 : Double2Str(WTI(hwpinfo.paper.paper_height)) + ascii("inch"));
1630 : }
1631 0 : break;
1632 :
1633 : }
1634 :
1635 4 : padd(ascii("style:print-orientation"),sXML_CDATA,
1636 2 : ascii(hwpinfo.paper.paper_direction ? "landscape" : "portrait"));
1637 2 : if( hwpinfo.beginpagenum != 1)
1638 0 : padd(ascii("style:first-page-number"),sXML_CDATA,
1639 0 : ascii(Int2Str(hwpinfo.beginpagenum, "%d", buf)));
1640 :
1641 2 : if( hwpinfo.borderline ){
1642 0 : padd(ascii("fo:margin-left"),sXML_CDATA,
1643 0 : Double2Str(WTI(hwpinfo.paper.left_margin - hwpinfo.bordermargin[0] + hwpinfo.paper.gutter_length)) + ascii("inch"));
1644 0 : padd(ascii("fo:margin-right"),sXML_CDATA,
1645 0 : Double2Str(WTI(hwpinfo.paper.right_margin - hwpinfo.bordermargin[1])) + ascii("inch"));
1646 0 : padd(ascii("fo:margin-top"),sXML_CDATA,
1647 0 : Double2Str(WTI(hwpinfo.paper.top_margin - hwpinfo.bordermargin[2])) + ascii("inch"));
1648 0 : padd(ascii("fo:margin-bottom"),sXML_CDATA,
1649 0 : Double2Str(WTI(hwpinfo.paper.bottom_margin - hwpinfo.bordermargin[3])) + ascii("inch"));
1650 : }
1651 : else{
1652 4 : padd(ascii("fo:margin-left"),sXML_CDATA,
1653 2 : Double2Str(WTI(hwpinfo.paper.left_margin + hwpinfo.paper.gutter_length)) + ascii("inch"));
1654 4 : padd(ascii("fo:margin-right"),sXML_CDATA,
1655 2 : Double2Str(WTI(hwpinfo.paper.right_margin)) + ascii("inch"));
1656 4 : padd(ascii("fo:margin-top"),sXML_CDATA,
1657 2 : Double2Str(WTI(hwpinfo.paper.top_margin)) + ascii("inch"));
1658 4 : padd(ascii("fo:margin-bottom"),sXML_CDATA,
1659 2 : Double2Str(WTI(hwpinfo.paper.bottom_margin)) + ascii("inch"));
1660 : }
1661 :
1662 2 : switch( hwpinfo.borderline )
1663 : {
1664 : case 1:
1665 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
1666 0 : break;
1667 : case 3:
1668 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm dotted #000000"));
1669 0 : break;
1670 : case 2:
1671 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
1672 0 : break;
1673 : case 4:
1674 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1675 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
1676 0 : break;
1677 : }
1678 :
1679 4 : padd(ascii("fo:padding-left"), sXML_CDATA,
1680 2 : Double2Str(WTI(hwpinfo.bordermargin[0])) + ascii("inch"));
1681 4 : padd(ascii("fo:padding-right"), sXML_CDATA,
1682 2 : Double2Str(WTI(hwpinfo.bordermargin[1])) + ascii("inch"));
1683 4 : padd(ascii("fo:padding-top"), sXML_CDATA,
1684 2 : Double2Str(WTI(hwpinfo.bordermargin[2])) + ascii("inch"));
1685 4 : padd(ascii("fo:padding-bottom"), sXML_CDATA,
1686 2 : Double2Str(WTI(hwpinfo.bordermargin[3])) + ascii("inch"));
1687 :
1688 : /* background color */
1689 2 : if( hwpinfo.back_info.isset )
1690 : {
1691 0 : if( hwpinfo.back_info.color[0] > 0 || hwpinfo.back_info.color[1] > 0
1692 0 : || hwpinfo.back_info.color[2] > 0 ){
1693 0 : sprintf(buf,"#%02x%02x%02x",hwpinfo.back_info.color[0],
1694 0 : hwpinfo.back_info.color[1],hwpinfo.back_info.color[2] );
1695 0 : padd(ascii("fo:background-color"), sXML_CDATA, ascii(buf));
1696 : }
1697 : }
1698 :
1699 2 : rstartEl(ascii("style:properties"),rList);
1700 2 : pList->clear();
1701 :
1702 : /* background image */
1703 2 : if( hwpinfo.back_info.isset && hwpinfo.back_info.type > 0 )
1704 : {
1705 0 : if( hwpinfo.back_info.type == 1 ){
1706 : #ifdef _WIN32
1707 : padd(ascii("xlink:href"), sXML_CDATA,
1708 : hconv(kstr2hstr((uchar*) urltowin(hwpinfo.back_info.filename).c_str()).c_str()));
1709 : #else
1710 0 : padd(ascii("xlink:href"), sXML_CDATA,
1711 0 : hconv(kstr2hstr( (uchar *)urltounix(hwpinfo.back_info.filename).c_str()).c_str()));
1712 : #endif
1713 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
1714 0 : padd(ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
1715 : }
1716 0 : if( hwpinfo.back_info.flag >= 2)
1717 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("stretch"));
1718 0 : else if( hwpinfo.back_info.flag == 1 ){
1719 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("no-repeat"));
1720 0 : padd(ascii("style:position"), sXML_CDATA, ascii("center"));
1721 : }
1722 0 : rstartEl(ascii("style:background-image"),rList);
1723 :
1724 0 : if( hwpinfo.back_info.type == 2 ){
1725 0 : rstartEl(ascii("office:binary-data"), rList);
1726 0 : pList->clear();
1727 0 : boost::shared_ptr<char> pStr(base64_encode_string((unsigned char *) hwpinfo.back_info.data, hwpinfo.back_info.size ), Free<char>());
1728 0 : rchars(ascii(pStr.get()));
1729 0 : rendEl(ascii("office:binary-data"));
1730 : }
1731 0 : rendEl(ascii("style:background-image"));
1732 : }
1733 :
1734 2 : makeColumns( hwpfile.GetColumnDef(i) );
1735 :
1736 2 : rendEl(ascii("style:properties"));
1737 :
1738 : /* header style */
1739 2 : rstartEl(ascii("style:header-style"), rList);
1740 4 : padd(ascii("svg:height"), sXML_CDATA,
1741 2 : Double2Str(WTI(hwpinfo.paper.header_length)) + ascii("inch"));
1742 2 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0mm"));
1743 :
1744 2 : rstartEl(ascii("style:properties"),rList);
1745 2 : pList->clear();
1746 2 : rendEl(ascii("style:properties"));
1747 2 : rendEl(ascii("style:header-style"));
1748 :
1749 : /* footer style */
1750 2 : rstartEl(ascii("style:footer-style"), rList);
1751 4 : padd(ascii("svg:height"), sXML_CDATA,
1752 2 : Double2Str(WTI(hwpinfo.paper.footer_length)) + ascii("inch"));
1753 2 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0mm"));
1754 2 : rstartEl(ascii("style:properties"),rList);
1755 2 : pList->clear();
1756 2 : rendEl(ascii("style:properties"));
1757 2 : rendEl(ascii("style:footer-style"));
1758 :
1759 : /* footnote style 이건 dtd에서는 빠졌으나, 스펙에는 정의되어 있다. REALKING */
1760 2 : rstartEl(ascii("style:footnote-layout"), rList);
1761 :
1762 4 : padd(ascii("style:distance-before-sep"), sXML_CDATA,
1763 2 : Double2Str(WTI(hwpinfo.splinetext)) + ascii("inch"));
1764 4 : padd(ascii("style:distance-after-sep"), sXML_CDATA,
1765 2 : Double2Str(WTI(hwpinfo.splinefn)) + ascii("inch"));
1766 2 : rstartEl(ascii("style:properties"),rList);
1767 2 : pList->clear();
1768 2 : rendEl(ascii("style:properties"));
1769 2 : if ( hwpinfo.fnlinetype == 2 )
1770 0 : padd(ascii("style:width"), sXML_CDATA, ascii("15cm"));
1771 2 : else if ( hwpinfo.fnlinetype == 1)
1772 0 : padd(ascii("style:width"), sXML_CDATA, ascii("2cm"));
1773 2 : else if ( hwpinfo.fnlinetype == 3)
1774 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0cm"));
1775 : else
1776 2 : padd(ascii("style:width"), sXML_CDATA, ascii("5cm"));
1777 :
1778 2 : rstartEl(ascii("style:footnote-sep"),rList);
1779 2 : pList->clear();
1780 2 : rendEl(ascii("style:footnote-sep"));
1781 :
1782 2 : rendEl(ascii("style:footnote-layout"));
1783 :
1784 2 : rendEl(ascii("style:page-master"));
1785 : }
1786 2 : }
1787 :
1788 2 : void HwpReader::makeColumns(ColumnDef *coldef)
1789 : {
1790 4 : if( !coldef ) return;
1791 0 : padd(ascii("fo:column-count"), sXML_CDATA, ascii(Int2Str(coldef->ncols, "%d", buf)));
1792 0 : rstartEl(ascii("style:columns"),rList);
1793 0 : pList->clear();
1794 0 : if( coldef->separator != 0 )
1795 : {
1796 0 : switch( coldef->separator )
1797 : {
1798 : case 1: /* 얇은선 */
1799 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0.02mm"));
1800 : //fall-through
1801 : case 3: /* 점선 */
1802 0 : padd(ascii("style:style"), sXML_CDATA, ascii("dotted"));
1803 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0.02mm"));
1804 0 : break;
1805 : case 2: /* 두꺼운선 */
1806 : case 4: /* 2중선 */
1807 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0.35mm"));
1808 0 : break;
1809 : case 0: /* 없음 */
1810 : default:
1811 0 : padd(ascii("style:style"), sXML_CDATA, ascii("none"));
1812 0 : break;
1813 : }
1814 0 : rstartEl(ascii("style:column-sep"),rList);
1815 0 : pList->clear();
1816 0 : rendEl(ascii("style:column-sep"));
1817 : }
1818 0 : double spacing = WTI(coldef->spacing)/ 2. ;
1819 0 : for(int ii = 0 ; ii < coldef->ncols ; ii++)
1820 : {
1821 0 : if( ii == 0 )
1822 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0mm"));
1823 : else
1824 0 : padd(ascii("fo:margin-left"), sXML_CDATA,
1825 0 : Double2Str( spacing) + ascii("inch"));
1826 0 : if( ii == ( coldef->ncols -1) )
1827 0 : padd(ascii("fo:margin-right"), sXML_CDATA,ascii("0mm"));
1828 : else
1829 0 : padd(ascii("fo:margin-right"), sXML_CDATA,
1830 0 : Double2Str( spacing) + ascii("inch"));
1831 0 : rstartEl(ascii("style:column"),rList);
1832 0 : pList->clear();
1833 0 : rendEl(ascii("style:column"));
1834 : }
1835 0 : rendEl(ascii("style:columns"));
1836 : }
1837 :
1838 2 : void HwpReader::makeTStyle(CharShape * cshape)
1839 : {
1840 4 : padd(ascii("style:name"), sXML_CDATA,
1841 2 : ascii(Int2Str(cshape->index, "T%d", buf)));
1842 2 : padd(ascii("style:family"), sXML_CDATA, ascii("text"));
1843 2 : rstartEl(ascii("style:style"), rList);
1844 2 : pList->clear();
1845 2 : parseCharShape(cshape);
1846 2 : rstartEl(ascii("style:properties"), rList);
1847 2 : pList->clear();
1848 2 : rendEl(ascii("style:properties"));
1849 2 : rendEl(ascii("style:style"));
1850 2 : }
1851 :
1852 :
1853 0 : void HwpReader::makeTableStyle(Table *tbl)
1854 : {
1855 : // --------------- table ----------------
1856 0 : TxtBox *hbox = tbl->box;
1857 :
1858 0 : padd(ascii("style:name"), sXML_CDATA,
1859 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
1860 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table"));
1861 0 : rstartEl(ascii("style:style"), rList);
1862 0 : pList->clear();
1863 0 : padd(ascii("style:width"), sXML_CDATA,
1864 0 : Double2Str(WTMM(hbox->box_xs)) + ascii("mm"));
1865 0 : padd(ascii("table:align"), sXML_CDATA,ascii("left"));
1866 0 : padd(ascii("fo:keep-with-next"), sXML_CDATA,ascii("false"));
1867 0 : rstartEl(ascii("style:properties"), rList);
1868 0 : pList->clear();
1869 0 : rendEl(ascii("style:properties"));
1870 0 : rendEl(ascii("style:style"));
1871 :
1872 : // --------------- column ----------------
1873 0 : for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
1874 : {
1875 0 : sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
1876 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1877 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-column"));
1878 0 : rstartEl(ascii("style:style"), rList);
1879 0 : pList->clear();
1880 0 : padd(ascii("style:column-width"), sXML_CDATA,
1881 0 : Double2Str(WTMM(tbl->columns.data[i+1] - tbl->columns.data[i])) + ascii("mm"));
1882 0 : rstartEl(ascii("style:properties"), rList);
1883 0 : pList->clear();
1884 0 : rendEl(ascii("style:properties"));
1885 0 : rendEl(ascii("style:style"));
1886 : }
1887 :
1888 : // --------------- row ----------------
1889 0 : for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++)
1890 : {
1891 0 : sprintf(buf,"Table%d.row%" SAL_PRI_SIZET "u",hbox->style.boxnum, i + 1);
1892 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1893 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-row"));
1894 0 : rstartEl(ascii("style:style"), rList);
1895 0 : pList->clear();
1896 0 : padd(ascii("style:row-height"), sXML_CDATA,
1897 0 : Double2Str(WTMM(tbl->rows.data[i+1] - tbl->rows.data[i])) + ascii("mm"));
1898 0 : rstartEl(ascii("style:properties"), rList);
1899 0 : pList->clear();
1900 0 : rendEl(ascii("style:properties"));
1901 0 : rendEl(ascii("style:style"));
1902 : }
1903 :
1904 : // --------------- cell ---------------------
1905 0 : for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it)
1906 : {
1907 0 : TCell *tcell = *it;
1908 0 : sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
1909 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1910 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-cell"));
1911 0 : rstartEl(ascii("style:style"), rList);
1912 0 : pList->clear();
1913 0 : Cell *cl = tcell->pCell;
1914 0 : if( cl->ver_align == 1 )
1915 0 : padd(ascii("fo:vertical-align"), sXML_CDATA,ascii("middle"));
1916 :
1917 0 : if(cl->linetype[2] == cl->linetype[3] && cl->linetype[2] == cl->linetype[0]
1918 0 : && cl->linetype[2] == cl->linetype[1])
1919 : {
1920 0 : switch( cl->linetype[2] )
1921 : {
1922 : case 1: /* 가는실선 */
1923 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1924 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
1925 0 : break;
1926 : case 2: /* 굵은실선 */
1927 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
1928 0 : break;
1929 : case 4: /* 2중선 */
1930 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1931 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
1932 0 : break;
1933 : }
1934 : }
1935 : else
1936 : {
1937 0 : switch( cl->linetype[0] )
1938 : {
1939 : case 1: /* 가는실선 */
1940 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1941 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
1942 0 : break;
1943 : case 2: /* 굵은실선 */
1944 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
1945 0 : break;
1946 : case 4: /* 2중선 */
1947 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1948 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
1949 0 : break;
1950 : }
1951 0 : switch( cl->linetype[1] )
1952 : {
1953 : case 1: /* 가는실선 */
1954 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1955 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
1956 0 : break;
1957 : case 2: /* 굵은실선 */
1958 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
1959 0 : break;
1960 : case 4: /* 2중선 */
1961 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1962 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
1963 0 : break;
1964 : }
1965 0 : switch( cl->linetype[2] )
1966 : {
1967 : case 1: /* 가는실선 */
1968 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1969 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
1970 0 : break;
1971 : case 2: /* 굵은실선 */
1972 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
1973 0 : break;
1974 : case 4: /* 2중선 */
1975 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1976 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
1977 0 : break;
1978 : }
1979 0 : switch( cl->linetype[3] )
1980 : {
1981 : case 1: /* 가는실선 */
1982 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1983 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
1984 0 : break;
1985 : case 2: /* 굵은실선 */
1986 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
1987 0 : break;
1988 : case 4: /* 2중선 */
1989 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1990 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
1991 0 : break;
1992 : }
1993 : }
1994 0 : if(cl->shade != 0)
1995 0 : padd(ascii("fo:background-color"), sXML_CDATA,
1996 : ascii(hcolor2str(sal::static_int_cast<uchar>(cl->color),
1997 0 : sal::static_int_cast<uchar>(cl->shade), buf)));
1998 :
1999 0 : rstartEl(ascii("style:properties"), rList);
2000 0 : pList->clear();
2001 0 : rendEl(ascii("style:properties"));
2002 :
2003 0 : rendEl(ascii("style:style"));
2004 : }
2005 0 : }
2006 :
2007 :
2008 0 : void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle)
2009 : {
2010 0 : while( hdo )
2011 : {
2012 0 : padd(ascii("style:name"), sXML_CDATA,
2013 0 : ascii(Int2Str(hdo->index, "Draw%d", buf)));
2014 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2015 :
2016 0 : rstartEl(ascii("style:style"), rList);
2017 0 : pList->clear();
2018 :
2019 0 : switch (fstyle->txtflow)
2020 : {
2021 : case 0:
2022 0 : break;
2023 : case 1:
2024 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2025 0 : break;
2026 : case 2:
2027 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2028 0 : break;
2029 : }
2030 : long color;
2031 : // invisible line
2032 0 : if( hdo->property.line_color > 0xffffff )
2033 : {
2034 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("none") );
2035 : }
2036 : else
2037 : {
2038 :
2039 0 : if( hdo->property.line_pstyle == 0 )
2040 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("solid") );
2041 0 : else if( hdo->property.line_pstyle < 5 )
2042 : {
2043 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("dash") );
2044 0 : padd(ascii("draw:stroke-dash"), sXML_CDATA,
2045 0 : ascii(Int2Str(hdo->index, "LineType%d", buf)));
2046 : }
2047 0 : padd(ascii("svg:stroke-width"), sXML_CDATA,
2048 0 : Double2Str( WTMM(hdo->property.line_width)) + ascii("mm" ));
2049 0 : color = hdo->property.line_color;
2050 : sprintf( buf, "#%02x%02x%02x",
2051 : sal_uInt16(color & 0xff),
2052 0 : sal_uInt16((color >> 8) & 0xff),
2053 0 : sal_uInt16((color >>16) & 0xff) );
2054 0 : padd(ascii("svg:stroke-color"), sXML_CDATA, ascii( buf) );
2055 : }
2056 :
2057 0 : if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC ||
2058 0 : hdo->type == HWPDO_FREEFORM || hdo->type == HWPDO_ADVANCED_ARC )
2059 : {
2060 :
2061 0 : if( hdo->property.line_tstyle > 0 )
2062 : {
2063 0 : padd(ascii("draw:marker-start"), sXML_CDATA,
2064 0 : ascii(ArrowShape[hdo->property.line_tstyle].name) );
2065 0 : if( hdo->property.line_width > 100 )
2066 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2067 0 : Double2Str( WTMM(hdo->property.line_width * 3)) + ascii("mm" ));
2068 0 : else if( hdo->property.line_width > 80 )
2069 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2070 0 : Double2Str( WTMM(hdo->property.line_width * 4)) + ascii("mm" ));
2071 0 : else if( hdo->property.line_width > 60 )
2072 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2073 0 : Double2Str( WTMM(hdo->property.line_width * 5)) + ascii("mm" ));
2074 0 : else if( hdo->property.line_width > 40 )
2075 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2076 0 : Double2Str( WTMM(hdo->property.line_width * 6)) + ascii("mm" ));
2077 : else
2078 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2079 0 : Double2Str( WTMM(hdo->property.line_width * 7)) + ascii("mm" ));
2080 : }
2081 :
2082 0 : if( hdo->property.line_hstyle > 0 )
2083 : {
2084 0 : padd(ascii("draw:marker-end"), sXML_CDATA,
2085 0 : ascii(ArrowShape[hdo->property.line_hstyle].name) );
2086 0 : if( hdo->property.line_width > 100 )
2087 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2088 0 : Double2Str( WTMM(hdo->property.line_width * 3)) + ascii("mm" ));
2089 0 : else if( hdo->property.line_width > 80 )
2090 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2091 0 : Double2Str( WTMM(hdo->property.line_width * 4)) + ascii("mm" ));
2092 0 : else if( hdo->property.line_width > 60 )
2093 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2094 0 : Double2Str( WTMM(hdo->property.line_width * 5)) + ascii("mm" ));
2095 0 : else if( hdo->property.line_width > 40 )
2096 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2097 0 : Double2Str( WTMM(hdo->property.line_width * 6)) + ascii("mm" ));
2098 : else
2099 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2100 0 : Double2Str( WTMM(hdo->property.line_width * 7)) + ascii("mm" ));
2101 : }
2102 : }
2103 :
2104 0 : if(hdo->type != HWPDO_LINE )
2105 : {
2106 0 : if( hdo->property.flag >> 19 & 0x01 )
2107 : {
2108 0 : padd( ascii("draw:textarea-horizontal-align"), sXML_CDATA, ascii("center"));
2109 : }
2110 :
2111 0 : color = hdo->property.fill_color;
2112 :
2113 0 : if( hdo->property.flag >> 18 & 0x01 ) // bitmap pattern
2114 : {
2115 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("bitmap"));
2116 0 : padd(ascii("draw:fill-image-name"), sXML_CDATA,
2117 0 : ascii(Int2Str(hdo->index, "fillimage%d", buf)));
2118 : // bitmap resizing
2119 0 : if( hdo->property.flag >> 3 & 0x01 )
2120 : {
2121 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("stretch"));
2122 : }
2123 : else
2124 : {
2125 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("repeat"));
2126 0 : padd(ascii("draw:fill-image-ref-point"), sXML_CDATA, ascii("top-left"));
2127 : }
2128 0 : if( hdo->property.flag >> 20 & 0x01 )
2129 : {
2130 0 : if( hdo->property.luminance > 0 )
2131 : {
2132 0 : padd(ascii("draw:transparency"), sXML_CDATA,
2133 0 : ascii(Int2Str(hdo->property.luminance, "%d%%", buf)));
2134 : }
2135 : }
2136 :
2137 : }
2138 : // Gradation
2139 0 : else if( hdo->property.flag >> 16 & 0x01 )
2140 : {
2141 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("gradient"));
2142 0 : padd(ascii("draw:fill-gradient-name"), sXML_CDATA,
2143 0 : ascii(Int2Str(hdo->index, "Grad%d", buf)));
2144 0 : padd(ascii("draw:gradient-step-count"), sXML_CDATA,
2145 0 : ascii(Int2Str(hdo->property.nstep, "%d", buf)));
2146 :
2147 : }
2148 : // Hatching
2149 0 : else if( hdo->property.pattern_type >> 24 & 0x01 )
2150 : {
2151 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("hatch"));
2152 0 : padd(ascii("draw:fill-hatch-name"), sXML_CDATA,
2153 0 : ascii(Int2Str(hdo->index, "Hatch%d", buf)));
2154 0 : if( color < 0xffffff )
2155 : {
2156 : sprintf( buf, "#%02x%02x%02x",
2157 : sal_uInt16(color & 0xff),
2158 0 : sal_uInt16((color >> 8) & 0xff),
2159 0 : sal_uInt16((color >>16) & 0xff) );
2160 0 : padd(ascii("draw:fill-color"), sXML_CDATA, ascii( buf) );
2161 0 : padd(ascii("draw:fill-hatch-solid"), sXML_CDATA, ascii("true"));
2162 : }
2163 : }
2164 0 : else if( color <= 0xffffff )
2165 : {
2166 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("solid"));
2167 : sprintf( buf, "#%02x%02x%02x",
2168 : sal_uInt16(color & 0xff),
2169 0 : sal_uInt16((color >> 8) & 0xff),
2170 0 : sal_uInt16((color >>16) & 0xff) );
2171 0 : padd(ascii("draw:fill-color"), sXML_CDATA, ascii( buf) );
2172 : }
2173 : else
2174 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("none"));
2175 : }
2176 :
2177 0 : if( fstyle->anchor_type == CHAR_ANCHOR )
2178 : {
2179 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2180 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2181 : }
2182 :
2183 0 : rstartEl(ascii("style:properties"), rList);
2184 0 : pList->clear();
2185 0 : rendEl(ascii("style:properties"));
2186 0 : rendEl(ascii("style:style"));
2187 :
2188 0 : if( hdo->type == 0 )
2189 : {
2190 0 : makeDrawStyle( hdo->child, fstyle );
2191 : }
2192 0 : hdo = hdo->next;
2193 : }
2194 0 : }
2195 :
2196 :
2197 0 : void HwpReader::makeCaptionStyle(FBoxStyle * fstyle)
2198 : {
2199 0 : padd(ascii("style:name"), sXML_CDATA,
2200 0 : ascii(Int2Str(fstyle->boxnum, "CapBox%d", buf)));
2201 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2202 0 : rstartEl(ascii("style:style"), rList);
2203 0 : pList->clear();
2204 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0cm"));
2205 0 : padd(ascii("fo:margin-right"), sXML_CDATA, ascii("0cm"));
2206 0 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
2207 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
2208 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2209 0 : switch (fstyle->txtflow)
2210 : {
2211 : case 0:
2212 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2213 0 : break;
2214 : case 1:
2215 0 : if( fstyle->boxtype == 'G' )
2216 0 : padd(ascii("style:run-through"), sXML_CDATA, ascii("background"));
2217 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2218 0 : break;
2219 : case 2:
2220 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2221 0 : break;
2222 : }
2223 0 : if (fstyle->anchor_type == CHAR_ANCHOR)
2224 : {
2225 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2226 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2227 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2228 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2229 : }
2230 : else
2231 : {
2232 :
2233 0 : switch (-(fstyle->xpos))
2234 : {
2235 : case 2:
2236 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("right"));
2237 0 : break;
2238 : case 3:
2239 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2240 0 : break;
2241 : case 1:
2242 : default:
2243 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2244 0 : break;
2245 : }
2246 0 : switch (-(fstyle->ypos))
2247 : {
2248 : case 2:
2249 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("bottom"));
2250 0 : break;
2251 : case 3:
2252 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("middle"));
2253 0 : break;
2254 : case 1:
2255 : default:
2256 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2257 0 : break;
2258 : }
2259 0 : if ( fstyle->anchor_type == PARA_ANCHOR )
2260 : {
2261 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2262 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2263 : }
2264 : else
2265 : {
2266 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("page-content"));
2267 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("page-content"));
2268 : }
2269 : }
2270 0 : rstartEl(ascii("style:properties"), rList);
2271 0 : pList->clear();
2272 0 : rendEl(ascii("style:properties"));
2273 0 : rendEl(ascii("style:style"));
2274 0 : if( fstyle->boxtype == 'G' )
2275 : {
2276 0 : padd(ascii("style:name"), sXML_CDATA,
2277 0 : ascii(Int2Str(fstyle->boxnum, "G%d", buf)));
2278 : }
2279 : else
2280 : {
2281 0 : padd(ascii("style:name"), sXML_CDATA,
2282 0 : ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf)));
2283 : }
2284 :
2285 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2286 0 : rstartEl(ascii("style:style"), rList);
2287 0 : pList->clear();
2288 :
2289 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0cm"));
2290 0 : padd(ascii("fo:margin-right"), sXML_CDATA, ascii("0cm"));
2291 0 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
2292 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
2293 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2294 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2295 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2296 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2297 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2298 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2299 0 : if( fstyle->boxtype == 'G' )
2300 : {
2301 0 : char *cell = (char *)fstyle->cell;
2302 0 : padd(ascii("draw:luminance"), sXML_CDATA,
2303 0 : ascii(Int2Str(cell[0], "%d%%", buf)));
2304 0 : padd(ascii("draw:contrast"), sXML_CDATA,
2305 0 : ascii(Int2Str(cell[1], "%d%%", buf)));
2306 0 : if( cell[2] == 0 )
2307 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("standard"));
2308 0 : else if( cell[2] == 1 )
2309 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("greyscale"));
2310 0 : else if( cell[2] == 2 )
2311 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("mono"));
2312 : }
2313 : else
2314 : {
2315 0 : Cell *cell = (Cell *)fstyle->cell;
2316 0 : if(cell->linetype[0] == cell->linetype[1] &&
2317 0 : cell->linetype[0] == cell->linetype[2] &&
2318 0 : cell->linetype[0] == cell->linetype[3])
2319 : {
2320 0 : switch( cell->linetype[0] )
2321 : {
2322 : case 0:
2323 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2324 0 : break;
2325 : case 1: /* 가는실선 */
2326 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2327 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
2328 0 : break;
2329 : case 2: /* 굵은실선 */
2330 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
2331 0 : break;
2332 : case 4: /* 2중선 */
2333 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2334 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
2335 0 : break;
2336 : }
2337 : }
2338 : else
2339 : {
2340 0 : switch( cell->linetype[0] )
2341 : {
2342 : case 1: /* 가는실선 */
2343 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2344 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
2345 0 : break;
2346 : case 2: /* 굵은실선 */
2347 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
2348 0 : break;
2349 : case 4: /* 2중선 */
2350 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2351 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
2352 0 : break;
2353 : }
2354 0 : switch( cell->linetype[1] )
2355 : {
2356 : case 1: /* 가는실선 */
2357 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2358 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
2359 0 : break;
2360 : case 2: /* 굵은실선 */
2361 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
2362 0 : break;
2363 : case 4: /* 2중선 */
2364 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2365 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
2366 0 : break;
2367 : }
2368 0 : switch( cell->linetype[2] )
2369 : {
2370 : case 1: /* 가는실선 */
2371 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2372 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
2373 0 : break;
2374 : case 2: /* 굵은실선 */
2375 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
2376 0 : break;
2377 : case 4: /* 2중선 */
2378 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2379 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
2380 0 : break;
2381 : }
2382 0 : switch( cell->linetype[3] )
2383 : {
2384 : case 1: /* 가는실선 */
2385 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2386 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
2387 0 : break;
2388 : case 2: /* 굵은실선 */
2389 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
2390 0 : break;
2391 : case 4: /* 2중선 */
2392 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2393 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
2394 0 : break;
2395 : }
2396 : }
2397 0 : if(cell->shade != 0)
2398 0 : padd(ascii("fo:background-color"), sXML_CDATA, ascii(hcolor2str(
2399 : sal::static_int_cast<uchar>(cell->color),
2400 0 : sal::static_int_cast<uchar>(cell->shade), buf)));
2401 : }
2402 0 : rstartEl(ascii("style:properties"), rList);
2403 0 : pList->clear();
2404 0 : rendEl(ascii("style:properties"));
2405 0 : rendEl(ascii("style:style"));
2406 0 : }
2407 :
2408 :
2409 : /**
2410 : * Floating 객체에 대한 스타일을 만든다.
2411 : */
2412 0 : void HwpReader::makeFStyle(FBoxStyle * fstyle)
2413 : {
2414 : /* 캡션 exist */
2415 0 : if( ( fstyle->boxtype == 'G' || fstyle->boxtype == 'X' ) && fstyle->cap_len > 0 )
2416 : {
2417 0 : makeCaptionStyle(fstyle);
2418 0 : return;
2419 : }
2420 0 : switch( fstyle->boxtype )
2421 : {
2422 : case 'X' : // txtbox
2423 : case 'E' : // equation
2424 : case 'B' : // button
2425 : case 'O' : // other
2426 : case 'T' : // table
2427 0 : padd(ascii("style:name"), sXML_CDATA,
2428 0 : ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf)));
2429 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2430 0 : break;
2431 : case 'G' : // graphics
2432 0 : padd(ascii("style:name"), sXML_CDATA,
2433 0 : ascii(Int2Str(fstyle->boxnum, "G%d", buf)));
2434 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2435 0 : break;
2436 : case 'L' : // line TODO : all
2437 0 : padd(ascii("style:name"), sXML_CDATA,
2438 0 : ascii(Int2Str(fstyle->boxnum, "L%d", buf)));
2439 0 : padd( ascii("style:family") , sXML_CDATA , ascii("paragraph") );
2440 0 : break;
2441 : }
2442 :
2443 0 : rstartEl(ascii("style:style"), rList);
2444 0 : pList->clear();
2445 :
2446 0 : if ( fstyle->boxtype == 'T')
2447 : {
2448 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2449 : }
2450 :
2451 0 : if( !(fstyle->boxtype == 'G' && fstyle->cap_len > 0 ))
2452 : {
2453 0 : padd(ascii("fo:margin-left"), sXML_CDATA,
2454 0 : Double2Str(WTMM(fstyle->margin[0][0]) ) + ascii("mm"));
2455 0 : padd(ascii("fo:margin-right"), sXML_CDATA,
2456 0 : Double2Str(WTMM(fstyle->margin[0][1])) + ascii("mm"));
2457 0 : padd(ascii("fo:margin-top"), sXML_CDATA,
2458 0 : Double2Str(WTMM(fstyle->margin[0][2])) + ascii("mm"));
2459 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA,
2460 0 : Double2Str(WTMM(fstyle->margin[0][3])) + ascii("mm"));
2461 : }
2462 :
2463 0 : switch (fstyle->txtflow)
2464 : {
2465 : case 0:
2466 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2467 0 : break;
2468 : case 1:
2469 0 : if( fstyle->boxtype == 'G' || fstyle->boxtype == 'B' || fstyle->boxtype == 'O')
2470 0 : padd(ascii("style:run-through"), sXML_CDATA, ascii("background"));
2471 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2472 0 : break;
2473 : case 2:
2474 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2475 0 : break;
2476 : }
2477 0 : if (fstyle->anchor_type == CHAR_ANCHOR)
2478 : {
2479 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2480 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2481 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2482 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2483 : }
2484 : else
2485 : {
2486 :
2487 0 : switch (-(fstyle->xpos))
2488 : {
2489 : case 2:
2490 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("right"));
2491 0 : break;
2492 : case 3:
2493 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2494 0 : break;
2495 : case 1:
2496 : default:
2497 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2498 0 : break;
2499 : }
2500 0 : switch (-(fstyle->ypos))
2501 : {
2502 : case 2:
2503 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("bottom"));
2504 0 : break;
2505 : case 3:
2506 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("middle"));
2507 0 : break;
2508 : case 1:
2509 : default:
2510 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2511 0 : break;
2512 : }
2513 0 : if ( fstyle->anchor_type == PARA_ANCHOR )
2514 : {
2515 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2516 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2517 : }
2518 : else
2519 : {
2520 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("page-content"));
2521 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("page-content"));
2522 : }
2523 : }
2524 0 : if( fstyle->boxtype == 'X' || fstyle->boxtype == 'B' )
2525 : {
2526 0 : Cell *cell = (Cell *)fstyle->cell;
2527 0 : if(cell->linetype[0] == cell->linetype[1] &&
2528 0 : cell->linetype[0] == cell->linetype[2] &&
2529 0 : cell->linetype[0] == cell->linetype[3])
2530 : {
2531 0 : switch( cell->linetype[0] )
2532 : {
2533 : case 0:
2534 0 : padd(ascii("fo:border"), sXML_CDATA, ascii("none"));
2535 0 : break;
2536 : case 1: /* 가는실선 */
2537 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2538 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
2539 0 : break;
2540 : case 2: /* 굵은실선 */
2541 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
2542 0 : break;
2543 : case 4: /* 2중선 */
2544 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2545 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
2546 0 : break;
2547 : }
2548 : }
2549 : else
2550 : {
2551 0 : switch( cell->linetype[0] )
2552 : {
2553 : case 1: /* 가는실선 */
2554 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2555 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
2556 0 : break;
2557 : case 2: /* 굵은실선 */
2558 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
2559 0 : break;
2560 : case 4: /* 2중선 */
2561 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2562 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
2563 0 : break;
2564 : }
2565 0 : switch( cell->linetype[1] )
2566 : {
2567 : case 1: /* 가는실선 */
2568 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2569 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
2570 0 : break;
2571 : case 2: /* 굵은실선 */
2572 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
2573 0 : break;
2574 : case 4: /* 2중선 */
2575 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2576 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
2577 0 : break;
2578 : }
2579 0 : switch( cell->linetype[2] )
2580 : {
2581 : case 1: /* 가는실선 */
2582 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2583 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
2584 0 : break;
2585 : case 2: /* 굵은실선 */
2586 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
2587 0 : break;
2588 : case 4: /* 2중선 */
2589 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2590 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
2591 0 : break;
2592 : }
2593 0 : switch( cell->linetype[3] )
2594 : {
2595 : case 1: /* 가는실선 */
2596 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2597 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
2598 0 : break;
2599 : case 2: /* 굵은실선 */
2600 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
2601 0 : break;
2602 : case 4: /* 2중선 */
2603 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2604 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
2605 0 : break;
2606 : }
2607 : }
2608 :
2609 0 : if( cell->linetype[0] == 0 && cell->linetype[1] == 0 &&
2610 0 : cell->linetype[2] == 0 && cell->linetype[3] == 0 ){
2611 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2612 : }
2613 : else{
2614 0 : padd(ascii("fo:padding-left"), sXML_CDATA,
2615 0 : Double2Str(WTMM(fstyle->margin[1][0])) + ascii("mm"));
2616 0 : padd(ascii("fo:padding-right"), sXML_CDATA,
2617 0 : Double2Str(WTMM(fstyle->margin[1][1])) + ascii("mm"));
2618 0 : padd(ascii("fo:padding-top"), sXML_CDATA,
2619 0 : Double2Str(WTMM(fstyle->margin[1][2])) + ascii("mm"));
2620 0 : padd(ascii("fo:padding-bottom"), sXML_CDATA,
2621 0 : Double2Str(WTMM(fstyle->margin[1][3])) + ascii("mm"));
2622 : }
2623 0 : if(cell->shade != 0)
2624 0 : padd(ascii("fo:background-color"), sXML_CDATA,
2625 : ascii(hcolor2str(
2626 : sal::static_int_cast<uchar>(cell->color),
2627 : sal::static_int_cast<uchar>(cell->shade),
2628 0 : buf)));
2629 : }
2630 0 : else if( fstyle->boxtype == 'E' )
2631 : {
2632 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2633 : }
2634 0 : else if( fstyle->boxtype == 'L' )
2635 : {
2636 0 : padd( ascii("style:border-line-width-bottom"), sXML_CDATA, ascii("0.02mm 0.35mm 0.02mm"));
2637 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #808080"));
2638 : }
2639 0 : else if( fstyle->boxtype == 'G' )
2640 : {
2641 0 : if( fstyle->margin[1][0] || fstyle->margin[1][1] || fstyle->margin[1][2] || fstyle->margin[1][3] ){
2642 0 : OUString clip = ascii("rect(");
2643 0 : clip += Double2Str(WTMM(-fstyle->margin[1][0]) ) + ascii("mm ");
2644 0 : clip += Double2Str(WTMM(-fstyle->margin[1][1]) ) + ascii("mm ");
2645 0 : clip += Double2Str(WTMM(-fstyle->margin[1][2]) ) + ascii("mm ");
2646 0 : clip += Double2Str(WTMM(-fstyle->margin[1][3]) ) + ascii("mm)");
2647 0 : padd(ascii("style:mirror"), sXML_CDATA, ascii("none"));
2648 0 : padd(ascii("fo:clip"), sXML_CDATA, clip);
2649 : }
2650 0 : char *cell = (char *)fstyle->cell;
2651 0 : padd(ascii("draw:luminance"), sXML_CDATA,
2652 0 : ascii(Int2Str(cell[0], "%d%%", buf)));
2653 0 : padd(ascii("draw:contrast"), sXML_CDATA,
2654 0 : ascii(Int2Str(cell[1], "%d%%", buf)));
2655 0 : if( cell[2] == 0 )
2656 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("standard"));
2657 0 : else if( cell[2] == 1 )
2658 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("greyscale"));
2659 0 : else if( cell[2] == 2 )
2660 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("mono"));
2661 :
2662 : }
2663 0 : rstartEl(ascii("style:properties"), rList);
2664 0 : pList->clear();
2665 0 : rendEl(ascii("style:properties"));
2666 0 : rendEl(ascii("style:style"));
2667 : }
2668 :
2669 :
2670 4 : char *HwpReader::getTStyleName(int index, char *_buf)
2671 : {
2672 4 : return Int2Str(index, "T%d", _buf);
2673 : }
2674 :
2675 :
2676 4 : char *HwpReader::getPStyleName(int index, char *_buf)
2677 : {
2678 4 : return Int2Str(index, "P%d", _buf);
2679 : }
2680 :
2681 :
2682 4 : void HwpReader::makeChars(hchar_string & rStr)
2683 : {
2684 4 : rchars(OUString(rStr.c_str()));
2685 4 : rStr.clear();
2686 4 : }
2687 :
2688 :
2689 : /**
2690 : * 문단내에 특수문자가 없고 모든 문자가 동일한 CharShape를 사용하는 경우
2691 : */
2692 0 : void HwpReader::make_text_p0(HWPPara * para, bool bParaStart)
2693 : {
2694 0 : hchar_string str;
2695 : int n;
2696 : int res;
2697 : hchar dest[3];
2698 0 : unsigned char firstspace = 0;
2699 0 : if( !bParaStart)
2700 : {
2701 0 : padd(ascii("text:style-name"), sXML_CDATA,
2702 0 : ascii(getPStyleName(para->GetParaShape().index, buf)));
2703 0 : rstartEl(ascii("text:p"), rList);
2704 0 : pList->clear();
2705 : }
2706 0 : if( d->bFirstPara && d->bInBody )
2707 : {
2708 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2709 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2710 0 : rstartEl(ascii("text:bookmark"), rList);
2711 0 : pList->clear();
2712 0 : rendEl(ascii("text:bookmark"));
2713 0 : d->bFirstPara = false;
2714 : }
2715 0 : if( d->bInHeader )
2716 : {
2717 0 : makeShowPageNum();
2718 0 : d->bInHeader = false;
2719 : }
2720 0 : padd(ascii("text:style-name"), sXML_CDATA,
2721 0 : ascii(getTStyleName(para->cshape.index, buf)));
2722 0 : rstartEl(ascii("text:span"), rList);
2723 0 : pList->clear();
2724 :
2725 0 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2726 0 : n += para->hhstr[n]->WSize())
2727 : {
2728 0 : if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
2729 : {
2730 0 : makeChars(str);
2731 0 : rstartEl(ascii("text:s"), rList);
2732 0 : rendEl(ascii("text:s"));
2733 : }
2734 0 : else if (para->hhstr[n]->hh == CH_END_PARA)
2735 : {
2736 0 : makeChars(str);
2737 0 : rendEl(ascii("text:span"));
2738 0 : rendEl(ascii("text:p"));
2739 0 : break;
2740 : }
2741 : else
2742 : {
2743 0 : if (para->hhstr[n]->hh == CH_SPACE)
2744 0 : firstspace = 0;
2745 : else
2746 0 : firstspace = 1;
2747 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2748 0 : for( int j = 0 ; j < res; j++ )
2749 : {
2750 0 : str.push_back(dest[j]);
2751 : }
2752 : }
2753 0 : }
2754 0 : }
2755 :
2756 :
2757 : /**
2758 : * 문단내에 특수문자가 없으나 문자들이 다른 CharShape를 사용하는 경우
2759 : */
2760 4 : void HwpReader::make_text_p1(HWPPara * para,bool bParaStart)
2761 : {
2762 4 : hchar_string str;
2763 : int n;
2764 : int res;
2765 : hchar dest[3];
2766 4 : int curr = para->cshape.index;
2767 4 : unsigned char firstspace = 0;
2768 :
2769 4 : if( !bParaStart )
2770 : {
2771 8 : padd(ascii("text:style-name"), sXML_CDATA,
2772 4 : ascii(getPStyleName(para->GetParaShape().index, buf)));
2773 4 : rstartEl(ascii("text:p"), rList);
2774 4 : pList->clear();
2775 : }
2776 4 : if( d->bFirstPara && d->bInBody )
2777 : {
2778 : /* for HWP's Bookmark */
2779 2 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2780 2 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2781 2 : rstartEl(ascii("text:bookmark"), rList);
2782 2 : pList->clear();
2783 2 : rendEl(ascii("text:bookmark"));
2784 2 : d->bFirstPara = false;
2785 : }
2786 4 : if( d->bInHeader )
2787 : {
2788 0 : makeShowPageNum();
2789 0 : d->bInHeader = false;
2790 : }
2791 8 : padd(ascii("text:style-name"), sXML_CDATA,
2792 4 : ascii(getTStyleName(curr, buf)));
2793 4 : rstartEl(ascii("text:span"), rList);
2794 4 : pList->clear();
2795 :
2796 70 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2797 66 : n += para->hhstr[n]->WSize())
2798 : {
2799 70 : if (para->GetCharShape(n)->index != curr)
2800 : {
2801 0 : makeChars(str);
2802 0 : rendEl(ascii("text:span"));
2803 0 : curr = para->GetCharShape(n)->index;
2804 0 : padd(ascii("text:style-name"), sXML_CDATA,
2805 0 : ascii(getTStyleName(curr, buf)));
2806 0 : rstartEl(ascii("text:span"), rList);
2807 0 : pList->clear();
2808 : }
2809 70 : if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
2810 : {
2811 0 : makeChars(str);
2812 0 : rstartEl(ascii("text:s"), rList);
2813 0 : rendEl(ascii("text:s"));
2814 : }
2815 70 : else if (para->hhstr[n]->hh == CH_END_PARA)
2816 : {
2817 4 : makeChars(str);
2818 4 : rendEl(ascii("text:span"));
2819 4 : rendEl(ascii("text:p"));
2820 4 : break;
2821 : }
2822 : else
2823 : {
2824 66 : if( para->hhstr[n]->hh < CH_SPACE )
2825 0 : continue;
2826 66 : if (para->hhstr[n]->hh == CH_SPACE)
2827 4 : firstspace = 0;
2828 : else
2829 62 : firstspace = 1;
2830 66 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2831 132 : for( int j = 0 ; j < res; j++ )
2832 : {
2833 66 : str.push_back(dest[j]);
2834 : }
2835 : }
2836 4 : }
2837 4 : }
2838 :
2839 :
2840 : /**
2841 : * 문단 내의 특수문자가 있으며 문자들이 다른 CharShape를 갖는 경우에 대해 처리
2842 : */
2843 0 : void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
2844 : {
2845 0 : hchar_string str;
2846 : int n, res;
2847 : hchar dest[3];
2848 0 : unsigned char firstspace = 0;
2849 0 : bool pstart = bParaStart;
2850 0 : bool tstart = false;
2851 0 : bool infield = false;
2852 0 : int curr = para->cshape.index;
2853 0 : if( d->bFirstPara && d->bInBody )
2854 : {
2855 0 : if ( !pstart ) {
2856 0 : STARTP;
2857 : }
2858 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2859 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2860 0 : rstartEl(ascii("text:bookmark"), rList);
2861 0 : pList->clear();
2862 0 : rendEl(ascii("text:bookmark"));
2863 0 : d->bFirstPara = false;
2864 : }
2865 0 : if( d->bInHeader )
2866 : {
2867 0 : if ( !pstart ) {
2868 0 : STARTP;
2869 : }
2870 0 : makeShowPageNum();
2871 0 : d->bInHeader = false;
2872 : }
2873 :
2874 0 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2875 0 : n += para->hhstr[n]->WSize())
2876 : {
2877 0 : if( para->hhstr[n]->hh == CH_END_PARA )
2878 : {
2879 0 : if (str.size() > 0)
2880 : {
2881 0 : if( !pstart ){ STARTP;}
2882 0 : if( !tstart ){ STARTT;}
2883 0 : makeChars(str);
2884 : }
2885 0 : if( tstart ){ ENDT;}
2886 0 : if( !pstart ){ STARTP;}
2887 0 : if( pstart ){ ENDP;}
2888 0 : break;
2889 : }
2890 0 : else if( para->hhstr[n]->hh == CH_SPACE && !firstspace)
2891 : {
2892 0 : if( !pstart ) {STARTP;}
2893 0 : if( !tstart ) {STARTT;}
2894 0 : makeChars(str);
2895 0 : rstartEl(ascii("text:s"), rList);
2896 0 : pList->clear();
2897 0 : rendEl(ascii("text:s"));
2898 : }
2899 0 : else if ( para->hhstr[n]->hh >= CH_SPACE )
2900 : {
2901 0 : if( n > 0 )
2902 0 : if( para->GetCharShape(n)->index != para->GetCharShape(n-1)->index && !infield )
2903 : {
2904 0 : if( !pstart ) {STARTP;}
2905 0 : if( !tstart ) {STARTT;}
2906 0 : makeChars(str);
2907 0 : ENDT;
2908 : }
2909 0 : if( para->hhstr[n]->hh == CH_SPACE )
2910 0 : firstspace = 0;
2911 : else
2912 0 : firstspace = 1;
2913 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2914 0 : for( int j = 0 ; j < res; j++ )
2915 : {
2916 0 : str.push_back(dest[j]);
2917 : }
2918 : }
2919 0 : else if (para->hhstr[n]->hh == CH_FIELD)
2920 : {
2921 0 : FieldCode *hbox = static_cast<FieldCode *>(para->hhstr[n]);
2922 0 : if( hbox->location_info == 1)
2923 : {
2924 0 : if( !pstart ) {STARTP;}
2925 0 : if( !tstart ) {STARTT;}
2926 0 : makeChars(str);
2927 0 : firstspace = 1;
2928 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
2929 : {
2930 0 : field = hbox->str3;
2931 : }
2932 : else{
2933 0 : makeFieldCode(str, hbox);
2934 : }
2935 0 : infield = true;
2936 : }
2937 : else
2938 : {
2939 0 : firstspace = 1;
2940 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
2941 : {
2942 0 : makeFieldCode(str, hbox);
2943 0 : field = 0L;
2944 : }
2945 0 : infield = false;
2946 0 : str.clear();
2947 : }
2948 : }
2949 : else
2950 : {
2951 0 : switch (para->hhstr[n]->hh)
2952 : {
2953 : case CH_BOOKMARK:
2954 0 : if( !pstart ) {STARTP;}
2955 0 : if( !tstart ) {STARTT;}
2956 0 : makeChars(str);
2957 0 : makeBookmark(static_cast<Bookmark *>(para->hhstr[n]));
2958 0 : break;
2959 : case CH_DATE_FORM: // 7
2960 0 : break;
2961 : case CH_DATE_CODE: // 8
2962 0 : if( !pstart ) {STARTP;}
2963 0 : if( !tstart ) {STARTT;}
2964 0 : makeChars(str);
2965 0 : makeDateCode(static_cast<DateCode *>(para->hhstr[n]));
2966 0 : break;
2967 : case CH_TAB: // 9
2968 0 : if( !pstart ) {STARTP;}
2969 0 : if (str.size() > 0)
2970 : {
2971 0 : if( !tstart ) {STARTT;}
2972 0 : makeChars(str);
2973 : }
2974 0 : makeTab(static_cast<Tab *>(para->hhstr[n]));
2975 0 : break;
2976 : case CH_TEXT_BOX: /* 10 - 표/텍스트박스/수식/버튼/하이퍼텍스트 순 */
2977 : {
2978 : /* 일단은 표만 처리하고, 수식은 text:p안에 들어가는 것으로 처리. */
2979 0 : TxtBox *hbox = static_cast<TxtBox *>(para->hhstr[n]);
2980 :
2981 0 : if( hbox->style.anchor_type == 0 )
2982 : {
2983 0 : if( !pstart ) {STARTP;}
2984 0 : if( !tstart ) {STARTT;}
2985 0 : makeChars(str);
2986 : }
2987 : else
2988 : {
2989 0 : if( !pstart ) {STARTP;}
2990 0 : if (str.size() > 0)
2991 : {
2992 0 : if( !tstart ) {STARTT;}
2993 0 : makeChars(str);
2994 : }
2995 0 : if( tstart ) {ENDT;}
2996 : }
2997 0 : switch (hbox->type)
2998 : {
2999 : case TBL_TYPE: // table
3000 : case TXT_TYPE: // text box
3001 : case EQU_TYPE: // formula
3002 0 : makeTextBox(hbox);
3003 0 : break;
3004 : case BUTTON_TYPE: // text button
3005 : case HYPERTEXT_TYPE: // hypertext
3006 0 : makeHyperText(hbox);
3007 0 : break;
3008 : }
3009 0 : break;
3010 : }
3011 : case CH_PICTURE: // 11
3012 : {
3013 0 : Picture *hbox = static_cast<Picture *>(para->hhstr[n]);
3014 0 : if( hbox->style.anchor_type == 0 )
3015 : {
3016 0 : if( !pstart ) {STARTP;}
3017 0 : if( !tstart ) {STARTT;}
3018 0 : makeChars(str);
3019 : }
3020 : else
3021 : {
3022 0 : if( !pstart ) {STARTP;}
3023 0 : if (str.size() > 0)
3024 : {
3025 0 : if( !tstart ) {STARTT;}
3026 0 : makeChars(str);
3027 : }
3028 0 : if( tstart ) {ENDT;}
3029 : }
3030 0 : makePicture(hbox);
3031 0 : break;
3032 : }
3033 : case CH_LINE: // 14
3034 : {
3035 0 : Line *hbox = static_cast<Line *>(para->hhstr[n]);
3036 0 : if (str.size() > 0)
3037 : {
3038 0 : if( !pstart ) {STARTP;}
3039 0 : if( !tstart ) {STARTT;}
3040 0 : makeChars(str);
3041 : }
3042 0 : if( tstart ) {ENDT;}
3043 0 : if( pstart ) {ENDP;}
3044 0 : makeLine(hbox);
3045 0 : pstart = true;
3046 0 : break;
3047 : }
3048 : case CH_HIDDEN: // 15
3049 0 : if( !pstart ) {STARTP;}
3050 0 : if( !tstart ) {STARTT;}
3051 0 : makeChars(str);
3052 0 : makeHidden(static_cast<Hidden *>(para->hhstr[n]));
3053 0 : break;
3054 : case CH_FOOTNOTE: // 17
3055 0 : if( !pstart ) {STARTP;}
3056 0 : if( !tstart ) {STARTT;}
3057 0 : makeChars(str);
3058 0 : makeFootnote(static_cast<Footnote *>(para->hhstr[n]));
3059 0 : break;
3060 : case CH_AUTO_NUM: // 18
3061 0 : if( !pstart ) {STARTP;}
3062 0 : if( !tstart ) {STARTT;}
3063 0 : makeChars(str);
3064 0 : makeAutoNum(static_cast<AutoNum *>(para->hhstr[n]));
3065 0 : break;
3066 : case CH_NEW_NUM: // 19 -skip
3067 0 : break;
3068 : case CH_PAGE_NUM_CTRL: // 21
3069 0 : break;
3070 : case CH_MAIL_MERGE: // 22
3071 0 : if( !pstart ) {STARTP;}
3072 0 : if( !tstart ) {STARTT;}
3073 0 : makeChars(str);
3074 0 : makeMailMerge(static_cast<MailMerge *>(para->hhstr[n]));
3075 0 : break;
3076 : case CH_COMPOSE: /* 23 - 글자겹침 */
3077 0 : break;
3078 : case CH_HYPHEN: // 24
3079 0 : break;
3080 : case CH_TOC_MARK: /* 25 아래의 3개는 작업해야 한다. */
3081 0 : if( !pstart ) {STARTP;}
3082 0 : if( !tstart ) {STARTT;}
3083 0 : makeChars(str);
3084 0 : makeTocMark(static_cast<TocMark *>(para->hhstr[n]));
3085 0 : break;
3086 : case CH_INDEX_MARK: // 26
3087 0 : if( !pstart ) {STARTP;}
3088 0 : if( !tstart ) {STARTT;}
3089 0 : makeChars(str);
3090 0 : makeIndexMark(static_cast<IndexMark *>(para->hhstr[n]));
3091 0 : break;
3092 : case CH_OUTLINE: // 28
3093 0 : if( !pstart ) {STARTP;}
3094 0 : if( !tstart ) {STARTT;}
3095 0 : makeChars(str);
3096 0 : makeOutline(static_cast<Outline *>(para->hhstr[n]));
3097 0 : break;
3098 : case CH_FIXED_SPACE:
3099 : case CH_KEEP_SPACE:
3100 0 : str.push_back(0x0020);
3101 0 : break;
3102 : }
3103 : }
3104 0 : }
3105 0 : }
3106 :
3107 :
3108 0 : void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
3109 : {
3110 : /* 누름틀 */
3111 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
3112 : {
3113 0 : padd(ascii("text:placeholder-type"), sXML_CDATA, ascii("text"));
3114 0 : if( field )
3115 0 : padd(ascii("text:description"), sXML_CDATA, hconv(field));
3116 0 : rstartEl( ascii("text:placeholder"), rList);
3117 0 : pList->clear();
3118 0 : rchars( OUString(rStr.c_str()));
3119 0 : rendEl( ascii("text:placeholder") );
3120 : }
3121 : /* 문서요약 */
3122 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
3123 : {
3124 0 : if (hconv(hbox->str3) == "title")
3125 : {
3126 0 : rstartEl( ascii("text:title"), rList );
3127 0 : rchars( hconv(hbox->str2) );
3128 0 : rendEl( ascii("text:title") );
3129 : }
3130 0 : else if (hconv(hbox->str3) == "subject")
3131 : {
3132 0 : rstartEl( ascii("text:subject"), rList );
3133 0 : rchars( hconv(hbox->str2) );
3134 0 : rendEl( ascii("text:subject") );
3135 : }
3136 0 : else if (hconv(hbox->str3) == "author")
3137 : {
3138 0 : rstartEl( ascii("text:author-name"), rList );
3139 0 : rchars( hconv(hbox->str2) );
3140 0 : rendEl( ascii("text:author-name") );
3141 : }
3142 0 : else if (hconv(hbox->str3) == "keywords")
3143 : {
3144 0 : rstartEl( ascii("text:keywords"), rList );
3145 0 : rchars( hconv(hbox->str2) );
3146 0 : rendEl( ascii("text:keywords") );
3147 : }
3148 : }
3149 : /* 개인정보 */
3150 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
3151 : {
3152 0 : if (hconv(hbox->str3) == "User")
3153 : {
3154 0 : rstartEl( ascii("text:sender-lastname"), rList );
3155 0 : rchars( hconv(hbox->str2) );
3156 0 : rendEl( ascii("text:sender-lastname") );
3157 : }
3158 0 : else if (hconv(hbox->str3) == "Company")
3159 : {
3160 0 : rstartEl( ascii("text:sender-company"), rList );
3161 0 : rchars( hconv(hbox->str2) );
3162 0 : rendEl( ascii("text:sender-company") );
3163 : }
3164 0 : else if (hconv(hbox->str3) == "Position")
3165 : {
3166 0 : rstartEl( ascii("text:sender-title"), rList );
3167 0 : rchars( hconv(hbox->str2) );
3168 0 : rendEl( ascii("text:sender-title") );
3169 : }
3170 0 : else if (hconv(hbox->str3) == "Division")
3171 : {
3172 0 : rstartEl( ascii("text:sender-position"), rList );
3173 0 : rchars( hconv(hbox->str2) );
3174 0 : rendEl( ascii("text:sender-position") );
3175 : }
3176 0 : else if (hconv(hbox->str3) == "Fax")
3177 : {
3178 0 : rstartEl( ascii("text:sender-fax"), rList );
3179 0 : rchars( hconv(hbox->str2) );
3180 0 : rendEl( ascii("text:sender-fax") );
3181 : }
3182 0 : else if (hconv(hbox->str3) == "Pager")
3183 : {
3184 0 : rstartEl( ascii("text:phone-private"), rList );
3185 0 : rchars( hconv(hbox->str2) );
3186 0 : rendEl( ascii("text:phone-private") );
3187 : }
3188 0 : else if (hconv(hbox->str3) == "E-mail")
3189 : {
3190 0 : rstartEl( ascii("text:sender-email"), rList );
3191 0 : rchars( hconv(hbox->str2) );
3192 0 : rendEl( ascii("text:sender-email") );
3193 : }
3194 0 : else if (hconv(hbox->str3) == "Zipcode(office)")
3195 : {
3196 0 : rstartEl( ascii("text:sender-postal-code"), rList );
3197 0 : rchars( hconv(hbox->str2) );
3198 0 : rendEl( ascii("text:sender-postal-code") );
3199 : }
3200 0 : else if (hconv(hbox->str3) == "Phone(office)")
3201 : {
3202 0 : rstartEl( ascii("text:sender-phone-work"), rList );
3203 0 : rchars( hconv(hbox->str2) );
3204 0 : rendEl( ascii("text:sender-phone-work") );
3205 : }
3206 0 : else if (hconv(hbox->str3) == "Address(office)")
3207 : {
3208 0 : rstartEl( ascii("text:sender-street"), rList );
3209 0 : rchars( hconv(hbox->str2) );
3210 0 : rendEl( ascii("text:sender-street") );
3211 : }
3212 :
3213 : }
3214 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 2 ) /* 만든날짜 */
3215 : {
3216 0 : if( hbox->m_pDate )
3217 0 : padd(ascii("style:data-style-name"), sXML_CDATA,
3218 0 : ascii(Int2Str(hbox->m_pDate->key, "N%d", buf)));
3219 0 : rstartEl( ascii("text:creation-date"), rList );
3220 0 : pList->clear();
3221 0 : rchars( hconv(hbox->str2) );
3222 0 : rendEl( ascii("text:creation-date") );
3223 : }
3224 0 : }
3225 :
3226 :
3227 : /**
3228 : * Completed
3229 : * 스타오피스에서는 북마크를 Reference로 참조하나 hwp에는 그 기능이 없다.
3230 : */
3231 0 : void HwpReader::makeBookmark(Bookmark * hbox)
3232 : {
3233 0 : if (hbox->type == 0)
3234 : {
3235 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3236 0 : rstartEl(ascii("text:bookmark"), rList);
3237 0 : pList->clear();
3238 0 : rendEl(ascii("text:bookmark"));
3239 : }
3240 0 : else if (hbox->type == 1) /* 블록 북마크일 경우 시작과 끝이 있다 */
3241 : {
3242 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3243 0 : rstartEl(ascii("text:bookmark-start"), rList);
3244 0 : pList->clear();
3245 0 : rendEl(ascii("text:bookmark-start"));
3246 : }
3247 0 : else if (hbox->type == 2)
3248 : {
3249 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3250 0 : rstartEl(ascii("text:bookmark-end"), rList);
3251 0 : pList->clear();
3252 0 : rendEl(ascii("text:bookmark-end"));
3253 : }
3254 0 : }
3255 :
3256 :
3257 : #include "datecode.h"
3258 :
3259 0 : void HwpReader::makeDateFormat(DateCode * hbox)
3260 : {
3261 0 : padd(ascii("style:name"), sXML_CDATA,
3262 0 : ascii(Int2Str(hbox->key, "N%d", buf)));
3263 0 : padd(ascii("style:family"), sXML_CDATA,ascii("data-style"));
3264 0 : padd(ascii("number:language"), sXML_CDATA,ascii("ko"));
3265 0 : padd(ascii("number:country"), sXML_CDATA,ascii("KR"));
3266 :
3267 0 : rstartEl(ascii("number:date-style"), rList);
3268 0 : pList->clear();
3269 :
3270 0 : bool add_zero = false;
3271 0 : int zero_check = 0;
3272 0 : hbox->format[DATE_SIZE -1] = 0;
3273 :
3274 0 : const hchar *fmt = hbox->format[0] ? hbox->format : defaultform;
3275 :
3276 0 : for( ; *fmt ; fmt++ )
3277 : {
3278 0 : if( zero_check == 1 )
3279 : {
3280 0 : zero_check = 0;
3281 : }
3282 : else
3283 0 : add_zero = false;
3284 :
3285 0 : switch( *fmt )
3286 : {
3287 : case '0':
3288 0 : zero_check = 1;
3289 0 : add_zero = true;
3290 0 : break;
3291 : case '1':
3292 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3293 0 : rstartEl(ascii("number:year"), rList);
3294 0 : pList->clear();
3295 0 : rendEl(ascii("number:year"));
3296 0 : break;
3297 : case '!':
3298 0 : rstartEl(ascii("number:year"), rList);
3299 0 : pList->clear();
3300 0 : rendEl(ascii("number:year"));
3301 0 : break;
3302 : case '2':
3303 0 : if( add_zero )
3304 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3305 0 : rstartEl(ascii("number:month"), rList);
3306 0 : pList->clear();
3307 0 : rendEl(ascii("number:month"));
3308 0 : break;
3309 : case '@':
3310 0 : padd(ascii("number:textual"), sXML_CDATA, ascii("true"));
3311 0 : rstartEl(ascii("number:month"), rList);
3312 0 : pList->clear();
3313 0 : rendEl(ascii("number:month"));
3314 0 : break;
3315 : case '*':
3316 0 : padd(ascii("number:textual"), sXML_CDATA, ascii("true"));
3317 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3318 0 : rstartEl(ascii("number:month"), rList);
3319 0 : pList->clear();
3320 0 : rendEl(ascii("number:month"));
3321 0 : break;
3322 : case '3':
3323 0 : if( add_zero )
3324 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3325 0 : rstartEl(ascii("number:day"), rList);
3326 0 : pList->clear();
3327 0 : rendEl(ascii("number:day"));
3328 0 : break;
3329 : case '#':
3330 0 : if( add_zero )
3331 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3332 0 : rstartEl(ascii("number:day"), rList);
3333 0 : pList->clear();
3334 0 : rendEl(ascii("number:day"));
3335 0 : switch( hbox->date[DateCode::DAY] % 10)
3336 : {
3337 : case 1:
3338 0 : rstartEl(ascii("number:text"), rList);
3339 0 : rchars(ascii("st"));
3340 0 : rendEl(ascii("number:text"));
3341 0 : break;
3342 : case 2:
3343 0 : rstartEl(ascii("number:text"), rList);
3344 0 : rchars(ascii("nd"));
3345 0 : rendEl(ascii("number:text"));
3346 0 : break;
3347 : case 3:
3348 0 : rstartEl(ascii("number:text"), rList);
3349 0 : rchars(ascii("rd"));
3350 0 : rendEl(ascii("number:text"));
3351 0 : break;
3352 : default:
3353 0 : rstartEl(ascii("number:text"), rList);
3354 0 : rchars(ascii("th"));
3355 0 : rendEl(ascii("number:text"));
3356 0 : break;
3357 : }
3358 0 : break;
3359 : case '4':
3360 : case '$':
3361 0 : if( add_zero )
3362 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3363 0 : rstartEl(ascii("number:hours"), rList);
3364 0 : pList->clear();
3365 0 : rendEl(ascii("number:hours"));
3366 0 : break;
3367 : case '5':
3368 : case '%':
3369 0 : if( add_zero )
3370 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3371 0 : rstartEl(ascii("number:minutes"), rList);
3372 0 : pList->clear();
3373 0 : rendEl(ascii("number:minutes"));
3374 0 : break;
3375 : case '_':
3376 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3377 : //fall-through
3378 : case '6':
3379 : case '^':
3380 0 : rstartEl(ascii("number:day-of-week"), rList);
3381 0 : pList->clear();
3382 0 : rendEl(ascii("number:day-of-week"));
3383 0 : break;
3384 : case '7':
3385 : case '&':
3386 : case '+':
3387 0 : rstartEl(ascii("number:am-pm"), rList);
3388 0 : pList->clear();
3389 0 : rendEl(ascii("number:am-pm"));
3390 0 : break;
3391 : case '~': // Chinese Locale
3392 0 : break;
3393 : default:
3394 : hchar sbuf[2];
3395 0 : sbuf[0] = *fmt;
3396 0 : sbuf[1] = 0;
3397 0 : rstartEl(ascii("number:text"), rList);
3398 0 : rchars((hconv(sbuf)));
3399 0 : rendEl(ascii("number:text"));
3400 0 : break;
3401 : }
3402 : }
3403 0 : pList->clear();
3404 0 : rendEl(ascii("number:date-style"));
3405 0 : }
3406 :
3407 :
3408 0 : void HwpReader::makeDateCode(DateCode * hbox)
3409 : {
3410 0 : padd(ascii("style:data-style-name"), sXML_CDATA,
3411 0 : ascii(Int2Str(hbox->key, "N%d", buf)));
3412 0 : rstartEl( ascii("text:date"), rList );
3413 0 : pList->clear();
3414 0 : hchar_string const boxstr = hbox->GetString();
3415 0 : rchars((hconv(boxstr.c_str())));
3416 0 : rendEl( ascii("text:date") );
3417 0 : }
3418 :
3419 :
3420 0 : void HwpReader::makeTab(Tab * ) /*hbox */
3421 : {
3422 0 : rstartEl(ascii("text:tab-stop"), rList);
3423 0 : rendEl(ascii("text:tab-stop"));
3424 0 : }
3425 :
3426 :
3427 0 : void HwpReader::makeTable(TxtBox * hbox)
3428 : {
3429 0 : padd(ascii("table:name"), sXML_CDATA,
3430 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
3431 0 : padd(ascii("table:style-name"), sXML_CDATA,
3432 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
3433 0 : rstartEl(ascii("table:table"), rList);
3434 0 : pList->clear();
3435 :
3436 0 : Table *tbl = hbox->m_pTable;
3437 : // ----------- column ----------------
3438 0 : for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
3439 : {
3440 0 : sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
3441 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3442 0 : rstartEl(ascii("table:table-column"), rList);
3443 0 : pList->clear();
3444 0 : rendEl(ascii("table:table-column"));
3445 : }
3446 :
3447 : // ----------- cell ----------------
3448 0 : int j = -1, k = -1;
3449 0 : for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it)
3450 : {
3451 0 : TCell *tcell = *it;
3452 0 : if( tcell->nRowIndex > j )
3453 : {
3454 0 : if( j > k )
3455 : {
3456 0 : rendEl(ascii("table:table-row"));
3457 0 : k = j;
3458 : }
3459 : // --------------- row ----------------
3460 0 : sprintf(buf,"Table%d.row%d",hbox->style.boxnum, tcell->nRowIndex + 1);
3461 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3462 0 : rstartEl(ascii("table:table-row"), rList);
3463 0 : pList->clear();
3464 0 : j = tcell->nRowIndex;
3465 : }
3466 :
3467 0 : sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
3468 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3469 0 : if( tcell->nColumnSpan > 1 )
3470 0 : padd(ascii("table:number-columns-spanned"), sXML_CDATA,
3471 0 : ascii(Int2Str(tcell->nColumnSpan, "%d", buf)));
3472 0 : if( tcell->nRowSpan > 1 )
3473 0 : padd(ascii("table:number-rows-spanned"), sXML_CDATA,
3474 0 : ascii(Int2Str(tcell->nRowSpan, "%d", buf)));
3475 0 : padd(ascii("table:value-type"), sXML_CDATA,ascii("string"));
3476 0 : if( tcell->pCell->protect )
3477 0 : padd(ascii("table:protected"), sXML_CDATA,ascii("true"));
3478 0 : rstartEl(ascii("table:table-cell"), rList);
3479 0 : pList->clear();
3480 0 : parsePara(hbox->plists[tcell->pCell->key].front());
3481 0 : rendEl(ascii("table:table-cell"));
3482 : }
3483 0 : rendEl(ascii("table:table-row"));
3484 0 : rendEl(ascii("table:table"));
3485 0 : }
3486 :
3487 :
3488 : /**
3489 : * 텍스트박스와 테이블을 파싱한다.
3490 : * 1. draw:style-name, draw:name, text:anchor-type, svg:width,
3491 : * fo:min-height, svg:x, svg:y
3492 : * TODO : fo:background-color로 셀의 칼라 설정=>스타일에 들어가는 지 아직 모르겠다.
3493 : */
3494 0 : void HwpReader::makeTextBox(TxtBox * hbox)
3495 : {
3496 0 : if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
3497 : {
3498 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3499 0 : ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf)));
3500 0 : padd(ascii("draw:name"), sXML_CDATA,
3501 0 : ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf)));
3502 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3503 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3504 0 : switch (hbox->style.anchor_type)
3505 : {
3506 : case CHAR_ANCHOR:
3507 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3508 0 : break;
3509 : case PARA_ANCHOR:
3510 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3511 0 : break;
3512 : case PAGE_ANCHOR:
3513 : case PAPER_ANCHOR:
3514 : {
3515 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3516 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3517 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3518 0 : break;
3519 : }
3520 : }
3521 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3522 : {
3523 0 : padd(ascii("svg:x"), sXML_CDATA,
3524 0 : Double2Str(WTMM( ( hbox->pgx + hbox->style.margin[0][0] ) )) + ascii("mm"));
3525 0 : padd(ascii("svg:y"), sXML_CDATA,
3526 0 : Double2Str(WTMM( ( hbox->pgy + hbox->style.margin[0][2] ) )) + ascii("mm"));
3527 : }
3528 0 : padd(ascii("svg:width"), sXML_CDATA,
3529 0 : Double2Str(WTMM(( hbox->box_xs + hbox->cap_xs) )) + ascii("mm"));
3530 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3531 0 : Double2Str(WTMM(( hbox->box_ys + hbox->cap_ys) )) + ascii("mm"));
3532 0 : rstartEl(ascii("draw:text-box"), rList);
3533 0 : pList->clear();
3534 0 : if( hbox->cap_pos % 2 ) /* 캡션이 위쪽에 위치한다 */
3535 : {
3536 0 : parsePara(hbox->caption.front());
3537 : }
3538 0 : padd( ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
3539 0 : rstartEl(ascii("text:p"), rList);
3540 0 : pList->clear();
3541 : }
3542 : else{
3543 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3544 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3545 : }
3546 :
3547 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3548 0 : ascii(Int2Str(hbox->style.boxnum, "Txtbox%d", buf)));
3549 0 : padd(ascii("draw:name"), sXML_CDATA,
3550 0 : ascii(Int2Str(hbox->style.boxnum, "Frame%d", buf)));
3551 :
3552 0 : if( hbox->style.cap_len <= 0 || hbox->type != TXT_TYPE )
3553 : {
3554 0 : int x = 0;
3555 0 : int y = 0;
3556 0 : switch (hbox->style.anchor_type)
3557 : {
3558 : case CHAR_ANCHOR:
3559 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3560 0 : break;
3561 : case PARA_ANCHOR:
3562 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3563 0 : break;
3564 : case PAGE_ANCHOR:
3565 : case PAPER_ANCHOR:
3566 : {
3567 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3568 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3569 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3570 0 : break;
3571 : }
3572 : }
3573 0 : if( hbox->style.anchor_type != CHAR_ANCHOR )
3574 : {
3575 0 : x += hbox->style.margin[0][0];
3576 0 : y += hbox->style.margin[0][2];
3577 : }
3578 0 : padd(ascii("svg:x"), sXML_CDATA,
3579 0 : Double2Str(WTMM( hbox->pgx + x )) + ascii("mm"));
3580 0 : padd(ascii("svg:y"), sXML_CDATA,
3581 0 : Double2Str(WTMM( hbox->pgy + y )) + ascii("mm"));
3582 : }
3583 : else
3584 : {
3585 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3586 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
3587 : }
3588 0 : padd(ascii("svg:width"), sXML_CDATA,
3589 0 : Double2Str(WTMM( hbox->box_xs )) + ascii("mm"));
3590 0 : if( hbox->style.cap_len > 0 && hbox->type != TXT_TYPE)
3591 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3592 0 : Double2Str(WTMM( hbox->box_ys + hbox->cap_ys)) + ascii("mm"));
3593 : else
3594 0 : padd(ascii("svg:height"), sXML_CDATA,
3595 0 : Double2Str(WTMM(hbox->box_ys )) + ascii("mm"));
3596 :
3597 0 : if( hbox->type != EQU_TYPE )
3598 : {
3599 0 : rstartEl(ascii("draw:text-box"), rList);
3600 0 : pList->clear();
3601 : /* 캡션이 존재하고, 위쪽에 있으면 */
3602 0 : if( hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE )
3603 : {
3604 0 : parsePara(hbox->caption.front());
3605 : }
3606 0 : if( hbox->type == TBL_TYPE) // Is Table
3607 : {
3608 0 : makeTable(hbox);
3609 : }
3610 : else // Is TextBox
3611 : {
3612 0 : parsePara(hbox->plists[0].front());
3613 : }
3614 : /* 캡션이 존재하고, 아래쪽에 있으면 */
3615 0 : if( hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE)
3616 : {
3617 0 : parsePara(hbox->caption.front());
3618 : }
3619 0 : rendEl(ascii("draw:text-box"));
3620 : // Caption exist and it is text-box
3621 0 : if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
3622 : {
3623 0 : rendEl( ascii("text:p"));
3624 0 : if( !(hbox->cap_pos % 2))
3625 : {
3626 0 : parsePara(hbox->caption.front());
3627 : }
3628 0 : rendEl( ascii("draw:text-box"));
3629 : }
3630 : }
3631 : else // is Formula
3632 : {
3633 0 : rstartEl(ascii("draw:object"), rList);
3634 0 : pList->clear();
3635 0 : makeFormula(hbox);
3636 0 : rendEl(ascii("draw:object"));
3637 : }
3638 0 : }
3639 :
3640 :
3641 : /**
3642 : * MathML로 변환해야 한다.
3643 : *
3644 : */
3645 0 : void HwpReader::makeFormula(TxtBox * hbox)
3646 : {
3647 : char mybuf[3000];
3648 : HWPPara* pPar;
3649 0 : CharShape *cshape = 0;
3650 :
3651 : int n, c, res;
3652 : hchar dest[3];
3653 0 : size_t l = 0;
3654 :
3655 0 : pPar = hbox->plists[0].front();
3656 0 : while( pPar )
3657 : {
3658 0 : for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh;
3659 0 : n += pPar->hhstr[n]->WSize() )
3660 : {
3661 0 : if (!cshape)
3662 0 : cshape = pPar->GetCharShape(n);
3663 0 : if (l >= sizeof(mybuf)-7)
3664 0 : break;
3665 0 : res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
3666 0 : for( int j = 0 ; j < res; j++ ){
3667 0 : c = dest[j];
3668 0 : if( c < 32 )
3669 0 : c = ' ';
3670 0 : if( c < 256 )
3671 0 : mybuf[l++] = sal::static_int_cast<char>(c);
3672 : else
3673 : {
3674 0 : mybuf[l++] = sal::static_int_cast<char>((c >> 8) & 0xff);
3675 0 : mybuf[l++] = sal::static_int_cast<char>(c & 0xff);
3676 : }
3677 : }
3678 : }
3679 0 : if (l >= sizeof(mybuf)-7)
3680 0 : break;
3681 0 : mybuf[l++] = '\n';
3682 0 : pPar = pPar->Next();
3683 : }
3684 0 : mybuf[l] = '\0';
3685 :
3686 0 : Formula *form = new Formula(mybuf);
3687 0 : form->setDocumentHandler(m_rxDocumentHandler);
3688 0 : form->setAttributeListImpl(pList);
3689 0 : form->parse();
3690 :
3691 0 : delete form;
3692 0 : }
3693 :
3694 :
3695 : /**
3696 : * platform정보를 읽어들여서 href가 C:\나 D:\로 시작할 경우 리눅스나 솔라리스이면
3697 : * C:\ => 홈으로, D:\ => 루트(/)로 바꾸어주는 작업이 필요하다. 이것은
3698 : * 한컴이 도스에뮬레이터를 쓰기 때문이다.
3699 : */
3700 0 : void HwpReader::makeHyperText(TxtBox * hbox)
3701 : {
3702 0 : HyperText *hypert = hwpfile.GetHyperText();
3703 0 : if( !hypert ) return;
3704 :
3705 0 : if( strlen((char *)hypert->filename) > 0 ){
3706 0 : ::std::string const tmp = hstr2ksstr(hypert->bookmark);
3707 : ::std::string const tmp2 = hstr2ksstr(kstr2hstr(
3708 : #ifdef _WIN32
3709 : (uchar *) urltowin((char *)hypert->filename).c_str()).c_str());
3710 : #else
3711 0 : (uchar *) urltounix((char *)hypert->filename).c_str()).c_str());
3712 : #endif
3713 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3714 0 : if (tmp.size() > 0 && strcmp(tmp.c_str(), "[HTML]")) {
3715 0 : ::std::string tmp3(tmp2);
3716 0 : tmp3.push_back('#');
3717 0 : tmp3.append(tmp);
3718 0 : padd(ascii("xlink:href"), sXML_CDATA,
3719 0 : OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR));
3720 : }
3721 : else{
3722 0 : padd(ascii("xlink:href"), sXML_CDATA,
3723 0 : OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR));
3724 :
3725 0 : }
3726 : }
3727 : else
3728 : {
3729 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3730 0 : ::std::string tmp;
3731 0 : tmp.push_back('#');
3732 0 : tmp.append(hstr2ksstr(hypert->bookmark));
3733 0 : padd(ascii("xlink:href"), sXML_CDATA,
3734 0 : OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR));
3735 : }
3736 0 : rstartEl(ascii("draw:a"), rList);
3737 0 : pList->clear();
3738 0 : makeTextBox(hbox);
3739 0 : rendEl(ascii("draw:a"));
3740 : }
3741 :
3742 :
3743 : /**
3744 : * platform정보를 읽어들여서 href가 C:\나 D:\로 시작할 경우 리눅스나 솔라리스이면
3745 : * C:\ => 홈으로, D:\ => 루트(/)로 바꾸었다. 이것은
3746 : * 한컴이 도스에뮬레이터를 쓰기 때문이다.
3747 : */
3748 0 : void HwpReader::makePicture(Picture * hbox)
3749 : {
3750 0 : switch (hbox->pictype)
3751 : {
3752 : case PICTYPE_OLE:
3753 : case PICTYPE_EMBED:
3754 : case PICTYPE_FILE:
3755 : {
3756 0 : if( hbox->style.cap_len > 0 )
3757 : {
3758 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3759 0 : ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf)));
3760 0 : padd(ascii("draw:name"), sXML_CDATA,
3761 0 : ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf)));
3762 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3763 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3764 0 : switch (hbox->style.anchor_type)
3765 : {
3766 : case CHAR_ANCHOR:
3767 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3768 0 : break;
3769 : case PARA_ANCHOR:
3770 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3771 0 : break;
3772 : case PAGE_ANCHOR:
3773 : case PAPER_ANCHOR:
3774 : {
3775 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3776 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3777 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3778 0 : break;
3779 : }
3780 : }
3781 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3782 : {
3783 0 : padd(ascii("svg:x"), sXML_CDATA,
3784 0 : Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + ascii("mm"));
3785 0 : padd(ascii("svg:y"), sXML_CDATA,
3786 0 : Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + ascii("mm"));
3787 : }
3788 0 : padd(ascii("svg:width"), sXML_CDATA,
3789 0 : Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1] )) + ascii("mm"));
3790 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3791 0 : Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3] + hbox->cap_ys )) + ascii("mm"));
3792 0 : rstartEl(ascii("draw:text-box"), rList);
3793 0 : pList->clear();
3794 0 : if( hbox->cap_pos % 2 ) /* 캡션이 위쪽에 위치한다 */
3795 : {
3796 0 : parsePara(hbox->caption.front());
3797 : }
3798 0 : padd( ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
3799 0 : rstartEl(ascii("text:p"), rList);
3800 0 : pList->clear();
3801 : }
3802 0 : if( hbox->ishyper )
3803 : {
3804 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3805 : #ifdef _WIN32
3806 : if( hbox->follow[4] != 0 )
3807 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4).c_str())));
3808 : else
3809 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5).c_str())));
3810 : #else
3811 0 : if( hbox->follow[4] != 0 )
3812 0 : padd(ascii("xlink:href"), sXML_CDATA,
3813 0 : (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4)).c_str()).c_str())));
3814 : else
3815 0 : padd(ascii("xlink:href"), sXML_CDATA,
3816 0 : (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5)).c_str()).c_str())));
3817 : #endif
3818 0 : rstartEl(ascii("draw:a"), rList);
3819 0 : pList->clear();
3820 : }
3821 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3822 0 : ascii(Int2Str(hbox->style.boxnum, "G%d", buf)));
3823 0 : padd(ascii("draw:name"), sXML_CDATA,
3824 0 : ascii(Int2Str(hbox->style.boxnum, "Image%d", buf)));
3825 :
3826 0 : if( hbox->style.cap_len <= 0 )
3827 : {
3828 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3829 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3830 0 : switch (hbox->style.anchor_type)
3831 : {
3832 : case CHAR_ANCHOR:
3833 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3834 0 : break;
3835 : case PARA_ANCHOR:
3836 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3837 0 : break;
3838 : case PAGE_ANCHOR:
3839 : case PAPER_ANCHOR:
3840 : {
3841 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3842 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3843 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3844 0 : break;
3845 : }
3846 : }
3847 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3848 : {
3849 0 : padd(ascii("svg:x"), sXML_CDATA,
3850 0 : Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + ascii("mm"));
3851 0 : padd(ascii("svg:y"), sXML_CDATA,
3852 0 : Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + ascii("mm"));
3853 : }
3854 : }
3855 : else
3856 : {
3857 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3858 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
3859 : }
3860 0 : padd(ascii("svg:width"), sXML_CDATA,
3861 0 : Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1])) + ascii("mm"));
3862 0 : padd(ascii("svg:height"), sXML_CDATA,
3863 0 : Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3])) + ascii("mm"));
3864 :
3865 0 : if ( hbox->pictype == PICTYPE_FILE ){
3866 : #ifdef _WIN32
3867 : sprintf(buf, "file:///%s", hbox->picinfo.picun.path );
3868 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf).c_str())));
3869 : #else
3870 0 : padd(ascii("xlink:href"), sXML_CDATA,
3871 0 : (hconv(kstr2hstr((uchar *) urltounix(hbox->picinfo.picun.path).c_str()).c_str())));
3872 : #endif
3873 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3874 0 : padd(ascii("xlink:show"), sXML_CDATA, ascii("embed"));
3875 0 : padd(ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
3876 : }
3877 :
3878 0 : if( hbox->pictype == PICTYPE_OLE )
3879 0 : rstartEl(ascii("draw:object-ole"), rList);
3880 : else
3881 0 : rstartEl(ascii("draw:image"), rList);
3882 0 : pList->clear();
3883 0 : if (hbox->pictype == PICTYPE_EMBED || hbox->pictype == PICTYPE_OLE)
3884 : {
3885 0 : rstartEl(ascii("office:binary-data"), rList);
3886 0 : pList->clear();
3887 0 : if( hbox->pictype == PICTYPE_EMBED ){
3888 0 : EmPicture *emp = hwpfile.GetEmPicture(hbox);
3889 0 : if( emp )
3890 : {
3891 0 : boost::shared_ptr<char> pStr(base64_encode_string( emp->data, emp->size ), Free<char>());
3892 0 : rchars(ascii(pStr.get()));
3893 : }
3894 : }
3895 : else{
3896 0 : if( hwpfile.oledata ){
3897 : #ifdef WIN32
3898 : LPSTORAGE srcsto;
3899 : LPUNKNOWN pObj;
3900 : wchar_t pathname[200];
3901 :
3902 : MultiByteToWideChar(CP_ACP, 0, hbox->picinfo.picole.embname, -1, pathname, 200);
3903 : int rc = hwpfile.oledata->pis->OpenStorage(pathname, 0,
3904 : STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, NULL, 0, &srcsto);
3905 : if (rc != S_OK) {
3906 : rchars(ascii(""));
3907 : }
3908 : else{
3909 : rc = OleLoad(srcsto, IID_IUnknown, NULL, (LPVOID*)&pObj);
3910 : if( rc != S_OK ){
3911 : srcsto->Release();
3912 : rchars(ascii(""));
3913 : }
3914 : else{
3915 : boost::shared_ptr<char> pStr(base64_encode_string( (uchar *)pObj, strlen((char *)pObj)), Free<char>());
3916 : rchars(ascii(pStr.get()));
3917 : pObj->Release();
3918 : srcsto->Release();
3919 : }
3920 : }
3921 : #else
3922 0 : rchars(ascii(""));
3923 : #endif
3924 : }
3925 : }
3926 0 : rendEl(ascii("office:binary-data"));
3927 : }
3928 0 : if( hbox->pictype == PICTYPE_OLE )
3929 0 : rendEl(ascii("draw:object-ole"));
3930 : else
3931 0 : rendEl(ascii("draw:image"));
3932 0 : if( hbox->ishyper )
3933 : {
3934 0 : rendEl(ascii("draw:a"));
3935 : }
3936 0 : if( hbox->style.cap_len > 0 )
3937 : {
3938 0 : rendEl( ascii("text:p"));
3939 0 : if( !(hbox->cap_pos % 2)) /* 캡션이 아래쪽에 위치하면, */
3940 : {
3941 0 : parsePara(hbox->caption.front());
3942 : }
3943 0 : rendEl( ascii("draw:text-box"));
3944 : }
3945 0 : break;
3946 : }
3947 : case PICTYPE_DRAW:
3948 0 : if( hbox->picinfo.picdraw.zorder > 0 )
3949 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3950 0 : ascii(Int2Str( hbox->picinfo.picdraw.zorder + 10000, "%d", buf)));
3951 0 : makePictureDRAW( (HWPDrawingObject *) hbox->picinfo.picdraw.hdo, hbox);
3952 0 : break;
3953 : case PICTYPE_UNKNOWN:
3954 0 : break;
3955 : }
3956 0 : }
3957 :
3958 :
3959 : #define DBL(x) ((x) * (x))
3960 0 : void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox)
3961 : {
3962 0 : int x = hbox->pgx;
3963 0 : int y = hbox->pgy;
3964 : int a, b;
3965 0 : bool bIsRotate = false;
3966 :
3967 0 : while (drawobj)
3968 : {
3969 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3970 0 : ascii(Int2Str(drawobj->index, "Draw%d", buf)));
3971 0 : a = 0; b = 0;
3972 :
3973 0 : switch (hbox->style.anchor_type)
3974 : {
3975 : case CHAR_ANCHOR:
3976 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3977 0 : break;
3978 : case PARA_ANCHOR:
3979 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3980 0 : break;
3981 : case PAGE_ANCHOR:
3982 : case PAPER_ANCHOR:
3983 : {
3984 0 : HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
3985 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3986 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3987 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3988 0 : a = hwpinfo.paper.left_margin;
3989 0 : b = hwpinfo.paper.top_margin + hwpinfo.paper.header_length;
3990 0 : break;
3991 : }
3992 : }
3993 :
3994 0 : if (drawobj->type == HWPDO_CONTAINER)
3995 : {
3996 0 : rstartEl(ascii("draw:g"), rList);
3997 0 : pList->clear();
3998 0 : makePictureDRAW(drawobj->child, hbox);
3999 0 : rendEl(ascii("draw:g"));
4000 : }
4001 : else
4002 : {
4003 0 : bIsRotate = false;
4004 0 : if( (drawobj->property.flag & HWPDO_FLAG_ROTATION) &&
4005 0 : (drawobj->property.parall.pt[0].y != drawobj->property.parall.pt[1].y) &&
4006 : //(drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE || drawobj->type == HWPDO_ADVANCED_ARC )
4007 0 : (drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE )
4008 : )
4009 : {
4010 :
4011 : int i;
4012 0 : ZZParall *pal = &drawobj->property.parall;
4013 :
4014 : ZZPoint pt[3], r_pt[3];
4015 0 : for(i = 0 ; i < 3 ; i++ ){
4016 0 : pt[i].x = pal->pt[i].x - drawobj->property.rot_originx;
4017 : /* 물리좌표계로 변환 */
4018 0 : pt[i].y = -(pal->pt[i].y - drawobj->property.rot_originy);
4019 : }
4020 :
4021 : double rotate, skewX ;
4022 :
4023 : /* 2 - 회전각 계산 */
4024 0 : if( pt[1].x == pt[0].x ){
4025 0 : if( pt[1].y > pt[0].y )
4026 0 : rotate = PI/2;
4027 : else
4028 0 : rotate = -(PI/2);
4029 : }
4030 : else
4031 0 : rotate = atan((double)( pt[1].y - pt[0].y )/(pt[1].x - pt[0].x ));
4032 0 : if( pt[1].x < pt[0].x )
4033 0 : rotate += PI;
4034 :
4035 0 : for( i = 0 ; i < 3 ; i++){
4036 0 : r_pt[i].x = (int)(pt[i].x * cos(-(rotate)) - pt[i].y * sin(-(rotate)));
4037 0 : r_pt[i].y = (int)(pt[i].y * cos(-(rotate)) + pt[i].x * sin(-(rotate)));
4038 : }
4039 :
4040 : /* 4 - 휜각 계산 */
4041 0 : if( r_pt[2].y == r_pt[1].y )
4042 0 : skewX = 0;
4043 : else
4044 0 : skewX = atan((double)(r_pt[2].x - r_pt[1].x )/( r_pt[2].y - r_pt[1].y ));
4045 0 : if( skewX >= PI/2 )
4046 0 : skewX -= PI;
4047 0 : if( skewX <= -PI/2 )
4048 0 : skewX += PI;
4049 :
4050 0 : OUString trans;
4051 0 : if( skewX != 0.0 && rotate != 0.0 ){
4052 0 : trans = ascii("skewX (") + Double2Str(skewX)
4053 0 : + ascii(") rotate (") + Double2Str(rotate)
4054 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4055 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4056 0 : bIsRotate = true;
4057 : }
4058 0 : else if( skewX != 0.0 ){
4059 0 : trans = ascii("skewX (") + Double2Str(skewX)
4060 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4061 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4062 0 : bIsRotate = true;
4063 : }
4064 0 : else if( rotate != 0.0 ){
4065 0 : trans = ascii("rotate (") + Double2Str(rotate)
4066 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4067 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4068 0 : bIsRotate = true;
4069 : }
4070 0 : if( bIsRotate ){
4071 0 : drawobj->extent.w = (int)sqrt(double(DBL(pt[1].x-pt[0].x)+DBL(pt[1].y-pt[0].y)));
4072 0 : drawobj->extent.h = (int)sqrt(double(DBL(pt[2].x-pt[1].x)+DBL(pt[2].y-pt[1].y)));
4073 0 : padd(ascii("draw:transform"), sXML_CDATA, trans);
4074 0 : }
4075 : }
4076 0 : switch (drawobj->type)
4077 : {
4078 : case HWPDO_LINE: /* 선 - 시작좌표, 끝좌표. */
4079 0 : if( drawobj->u.line_arc.flip & 0x01 )
4080 : {
4081 0 : padd(ascii("svg:x1"), sXML_CDATA,
4082 0 : Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + ascii("mm"));
4083 0 : padd(ascii("svg:x2"), sXML_CDATA,
4084 0 : Double2Str (WTMM( x + a + drawobj->offset2.x )) + ascii("mm"));
4085 : }
4086 : else
4087 : {
4088 0 : padd(ascii("svg:x1"), sXML_CDATA,
4089 0 : Double2Str (WTMM( x + a + drawobj->offset2.x )) + ascii("mm"));
4090 0 : padd(ascii("svg:x2"), sXML_CDATA,
4091 0 : Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + ascii("mm"));
4092 : }
4093 0 : if( drawobj->u.line_arc.flip & 0x02 )
4094 : {
4095 0 : padd(ascii("svg:y1"), sXML_CDATA,
4096 0 : Double2Str (WTMM( y + b + drawobj->offset2.y + drawobj->extent.h ) ) + ascii("mm"));
4097 0 : padd(ascii("svg:y2"), sXML_CDATA,
4098 0 : Double2Str (WTMM( y + b + drawobj->offset2.y )) + ascii("mm"));
4099 : }
4100 : else
4101 : {
4102 0 : padd(ascii("svg:y1"), sXML_CDATA,
4103 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4104 0 : padd(ascii("svg:y2"), sXML_CDATA,
4105 0 : Double2Str (WTMM(y + b + drawobj->offset2.y + drawobj->extent.h)) + ascii("mm"));
4106 : }
4107 :
4108 0 : rstartEl(ascii("draw:line"), rList);
4109 0 : pList->clear();
4110 0 : rendEl(ascii("draw:line"));
4111 0 : break;
4112 : case HWPDO_RECT: /* 사각형 - 시작위치, 가로/세로 */
4113 0 : if( !bIsRotate )
4114 : {
4115 0 : padd(ascii("svg:x"), sXML_CDATA,
4116 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4117 0 : padd(ascii("svg:y"), sXML_CDATA,
4118 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4119 : }
4120 0 : padd(ascii("svg:width"), sXML_CDATA,
4121 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4122 0 : padd(ascii("svg:height"), sXML_CDATA,
4123 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4124 0 : if( drawobj->property.flag & 0x01 )
4125 : {
4126 0 : int value = drawobj->extent.w < drawobj->extent.h ?
4127 0 : drawobj->extent.w : drawobj->extent.h ;
4128 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4129 0 : Double2Str (WTMM( value/10 )) + ascii("mm"));
4130 : }
4131 0 : else if( drawobj->property.flag & 0x04 )
4132 : {
4133 0 : int value = drawobj->extent.w < drawobj->extent.h ?
4134 0 : drawobj->extent.w : drawobj->extent.h ;
4135 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4136 0 : Double2Str (WTMM( value / 2)) + ascii("mm"));
4137 : }
4138 :
4139 0 : rstartEl(ascii("draw:rect"), rList);
4140 0 : pList->clear();
4141 0 : if( (drawobj->property.flag & HWPDO_FLAG_AS_TEXTBOX) &&
4142 : drawobj->property.pPara ) // As Textbox
4143 : {
4144 0 : HWPPara *pPara = drawobj->property.pPara;
4145 : //parsePara(pPara);
4146 0 : while(pPara)
4147 : {
4148 0 : make_text_p1( pPara );
4149 0 : pPara = pPara->Next();
4150 : }
4151 : }
4152 0 : rendEl(ascii("draw:rect"));
4153 0 : break;
4154 : case HWPDO_ELLIPSE: /* 타원 - 시작위치, 가로/세로 */
4155 : case HWPDO_ADVANCED_ELLIPSE: /* 변형된 타원 */
4156 : {
4157 0 : if( !bIsRotate )
4158 : {
4159 0 : padd(ascii("svg:x"), sXML_CDATA,
4160 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4161 0 : padd(ascii("svg:y"), sXML_CDATA,
4162 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4163 : }
4164 :
4165 0 : padd(ascii("svg:width"), sXML_CDATA,
4166 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4167 0 : padd(ascii("svg:height"), sXML_CDATA,
4168 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4169 0 : if( drawobj->type == HWPDO_ADVANCED_ELLIPSE ){
4170 0 : if( drawobj->u.arc.radial[0].x != drawobj->u.arc.radial[1].x
4171 0 : || drawobj->u.arc.radial[0].y != drawobj->u.arc.radial[1].y ){
4172 : int Cx,Cy;
4173 0 : Cx = ( drawobj->offset2.x + drawobj->extent.w ) / 2;
4174 0 : Cy = ( drawobj->offset2.y + drawobj->extent.h ) / 2;
4175 :
4176 : double start_angle, end_angle;
4177 0 : start_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[0].x, drawobj->u.arc.radial[0].y );
4178 0 : end_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[1].x, drawobj->u.arc.radial[1].y );
4179 0 : if( drawobj->property.fill_color < 0xffffff )
4180 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("section"));
4181 : else
4182 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("arc"));
4183 0 : padd(ascii("draw:start-angle"), sXML_CDATA, Double2Str(start_angle ));
4184 0 : padd(ascii("draw:end-angle"), sXML_CDATA, Double2Str(end_angle));
4185 : }
4186 : }
4187 0 : rstartEl(ascii("draw:ellipse"), rList);
4188 0 : pList->clear();
4189 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4190 : drawobj->property.pPara ) // As Textbox
4191 : {
4192 0 : HWPPara *pPara = drawobj->property.pPara;
4193 : //parsePara(pPara);
4194 0 : while(pPara)
4195 : {
4196 0 : make_text_p1( pPara );
4197 0 : pPara = pPara->Next();
4198 : }
4199 : }
4200 0 : rendEl(ascii("draw:ellipse"));
4201 0 : break;
4202 :
4203 : }
4204 : case HWPDO_ARC: /* 호 */
4205 : case HWPDO_ADVANCED_ARC:
4206 : {
4207 : /* 호일경우에, 스타오피스는 전체 타원의 크기를 사이즈로 한다. */
4208 0 : uint flip = drawobj->u.line_arc.flip;
4209 0 : if( !bIsRotate )
4210 : {
4211 0 : if( ( flip == 0 || flip == 2 ) && drawobj->type == HWPDO_ARC)
4212 0 : padd(ascii("svg:x"), sXML_CDATA,
4213 0 : Double2Str (WTMM( x + a + drawobj->offset2.x - drawobj->extent.w)) + ascii("mm"));
4214 : else
4215 0 : padd(ascii("svg:x"), sXML_CDATA,
4216 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4217 0 : if( ( flip == 0 || flip == 1 ) && drawobj->type == HWPDO_ARC)
4218 0 : padd(ascii("svg:y"), sXML_CDATA,
4219 0 : Double2Str (WTMM( y + b + drawobj->offset2.y - drawobj->extent.h)) + ascii("mm"));
4220 : else
4221 0 : padd(ascii("svg:y"), sXML_CDATA,
4222 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4223 : }
4224 :
4225 0 : padd(ascii("svg:width"), sXML_CDATA,
4226 0 : Double2Str (WTMM( drawobj->extent.w * 2)) + ascii("mm"));
4227 0 : padd(ascii("svg:height"), sXML_CDATA,
4228 0 : Double2Str (WTMM( drawobj->extent.h * 2)) + ascii("mm"));
4229 0 : if( drawobj->property.flag & HWPDO_FLAG_DRAW_PIE ||
4230 0 : drawobj->property.fill_color < 0xffffff )
4231 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("section"));
4232 : else
4233 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("arc"));
4234 :
4235 0 : if( drawobj->type == HWPDO_ADVANCED_ARC ){
4236 : double start_angle, end_angle;
4237 0 : ZZParall *pal = &drawobj->property.parall;
4238 :
4239 0 : if( pal->pt[1].x == pal->pt[0].x ){
4240 0 : if( pal->pt[0].y < pal->pt[1].y )
4241 0 : start_angle = 1.5 * PI;
4242 : else
4243 0 : start_angle = 0.5 * PI;
4244 : }
4245 : else{
4246 0 : start_angle = atan((double)( pal->pt[0].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[0].x ));
4247 0 : if( pal->pt[1].x < pal->pt[0].x )
4248 0 : start_angle += PI;
4249 : }
4250 0 : if( pal->pt[1].x == pal->pt[2].x ){
4251 0 : if( pal->pt[2].y < pal->pt[1].y )
4252 0 : end_angle = 1.5 * PI;
4253 : else
4254 0 : end_angle = 0.5 * PI;
4255 : }
4256 : else{
4257 0 : end_angle = atan((double)( pal->pt[2].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[2].x ));
4258 0 : if( pal->pt[1].x < pal->pt[2].x )
4259 0 : end_angle += PI;
4260 : }
4261 :
4262 0 : if( start_angle >= 2 * PI )
4263 0 : start_angle -= 2 * PI;
4264 0 : if( end_angle >= 2 * PI )
4265 0 : end_angle -= 2 * PI;
4266 0 : if( ( start_angle > end_angle ) && (start_angle - end_angle < PI )){
4267 0 : double tmp_angle = start_angle;
4268 0 : start_angle = end_angle;
4269 0 : end_angle = tmp_angle;
4270 : }
4271 0 : padd(ascii("draw:start-angle"), sXML_CDATA, Double2Str(start_angle * 180. / PI));
4272 0 : padd(ascii("draw:end-angle"), sXML_CDATA, Double2Str(end_angle * 180. / PI));
4273 :
4274 : }
4275 : else{
4276 0 : if( drawobj->u.line_arc.flip == 0 )
4277 : {
4278 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("270"));
4279 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("0"));
4280 : }
4281 0 : else if( drawobj->u.line_arc.flip == 1 )
4282 : {
4283 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("180"));
4284 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("270"));
4285 : }
4286 0 : else if( drawobj->u.line_arc.flip == 2 )
4287 : {
4288 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("0"));
4289 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("90"));
4290 : }
4291 : else
4292 : {
4293 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("90"));
4294 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("180"));
4295 : }
4296 : }
4297 0 : rstartEl(ascii("draw:ellipse"), rList);
4298 0 : pList->clear();
4299 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4300 : drawobj->property.pPara ) // As Textbox
4301 : {
4302 0 : HWPPara *pPara = drawobj->property.pPara;
4303 : //parsePara(pPara);
4304 0 : while(pPara)
4305 : {
4306 0 : make_text_p1( pPara );
4307 0 : pPara = pPara->Next();
4308 : }
4309 : }
4310 0 : rendEl(ascii("draw:ellipse"));
4311 0 : break;
4312 :
4313 : }
4314 : case HWPDO_CURVE: /* 곡선 : 다각형으로 변환. */
4315 : {
4316 0 : bool bIsNatural = true;
4317 0 : if( drawobj->property.flag >> 5 & 0x01){
4318 0 : bIsNatural = false;
4319 : }
4320 0 : if( !bIsRotate )
4321 : {
4322 0 : padd(ascii("svg:x"), sXML_CDATA,
4323 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4324 0 : padd(ascii("svg:y"), sXML_CDATA,
4325 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4326 : }
4327 0 : padd(ascii("svg:width"), sXML_CDATA,
4328 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4329 0 : padd(ascii("svg:height"), sXML_CDATA,
4330 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4331 0 : sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w) , WTSM(drawobj->extent.h) );
4332 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii(buf) );
4333 :
4334 0 : OUString oustr;
4335 :
4336 0 : if ((drawobj->u.freeform.npt > 2) &&
4337 0 : (static_cast<size_t>(drawobj->u.freeform.npt) <
4338 0 : ((::std::numeric_limits<int>::max)() / sizeof(double))))
4339 : {
4340 : int n, i;
4341 0 : n = drawobj->u.freeform.npt;
4342 :
4343 0 : double *xarr = new double[n+1];
4344 0 : double *yarr = new double[n+1];
4345 0 : double *tarr = new double[n+1];
4346 :
4347 0 : double *xb = 0L;
4348 0 : double *yb = 0L;
4349 :
4350 0 : double *carr = 0L;
4351 0 : double *darr = 0L;
4352 :
4353 :
4354 0 : for( i = 0 ; i < n ; i++ ){
4355 0 : xarr[i] = drawobj->u.freeform.pt[i].x;
4356 0 : yarr[i] = drawobj->u.freeform.pt[i].y;
4357 0 : tarr[i] = i;
4358 : }
4359 0 : xarr[n] = xarr[0];
4360 0 : yarr[n] = yarr[0];
4361 0 : tarr[n] = n;
4362 :
4363 0 : if( bIsNatural == false ){
4364 0 : PeriodicSpline(n, tarr, xarr, xb, carr, darr);
4365 : // prevent memory leak
4366 0 : delete[] carr;
4367 0 : carr = 0;
4368 0 : delete[] darr;
4369 0 : darr = 0;
4370 0 : PeriodicSpline(n, tarr, yarr, yb, carr, darr);
4371 : }
4372 : else{
4373 0 : NaturalSpline(n, tarr, xarr, xb, carr, darr);
4374 : // prevent memory leak
4375 0 : delete[] carr;
4376 0 : carr = 0;
4377 0 : delete[] darr;
4378 0 : darr = 0;
4379 0 : NaturalSpline(n, tarr, yarr, yb, carr, darr);
4380 : }
4381 :
4382 0 : sprintf(buf, "M%d %dC%d %d", WTSM((int)xarr[0]), WTSM((int)yarr[0]),
4383 0 : WTSM((int)(xarr[0] + xb[0]/3)), WTSM((int)(yarr[0] + yb[0]/3)) );
4384 0 : oustr += ascii(buf);
4385 :
4386 0 : for( i = 1 ; i < n ; i++ ){
4387 0 : if( i == n -1 ){
4388 : sprintf(buf, " %d %d %d %dz",
4389 0 : WTSM((int)(xarr[i] - xb[i]/3)), WTSM((int)(yarr[i] - yb[i]/3)),
4390 0 : WTSM((int)xarr[i]), WTSM((int)yarr[i]) );
4391 : }
4392 : else{
4393 : sprintf(buf, " %d %d %d %d %d %d",
4394 0 : WTSM((int)(xarr[i] - xb[i]/3)), WTSM((int)(yarr[i] - yb[i]/3)),
4395 0 : WTSM((int)xarr[i]), WTSM((int)yarr[i]),
4396 0 : WTSM((int)xarr[i] + xb[i]/3), WTSM((int)(yarr[i] + yb[i]/3)) );
4397 : }
4398 :
4399 0 : oustr += ascii(buf);
4400 : }
4401 0 : delete[] tarr;
4402 0 : delete[] xarr;
4403 0 : delete[] yarr;
4404 :
4405 0 : delete[] xb;
4406 0 : delete[] yb;
4407 :
4408 0 : delete[] carr;
4409 0 : delete[] darr;
4410 : }
4411 :
4412 0 : padd(ascii("svg:d"), sXML_CDATA, oustr);
4413 :
4414 0 : rstartEl(ascii("draw:path"), rList);
4415 0 : pList->clear();
4416 : // As Textbox
4417 0 : if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara )
4418 : {
4419 0 : HWPPara *pPara = drawobj->property.pPara;
4420 0 : while(pPara)
4421 : {
4422 0 : make_text_p1( pPara );
4423 0 : pPara = pPara->Next();
4424 : }
4425 : }
4426 0 : rendEl(ascii("draw:path"));
4427 0 : break;
4428 : }
4429 : case HWPDO_CLOSED_FREEFORM:
4430 : case HWPDO_FREEFORM: /* 다각형 */
4431 : {
4432 0 : bool bIsPolygon = false;
4433 :
4434 0 : padd(ascii("svg:x"), sXML_CDATA,
4435 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4436 0 : padd(ascii("svg:y"), sXML_CDATA,
4437 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4438 :
4439 0 : padd(ascii("svg:width"), sXML_CDATA,
4440 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4441 0 : padd(ascii("svg:height"), sXML_CDATA,
4442 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4443 :
4444 0 : sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w), WTSM(drawobj->extent.h));
4445 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii(buf) );
4446 :
4447 0 : OUString oustr;
4448 :
4449 0 : if (drawobj->u.freeform.npt > 0)
4450 : {
4451 0 : sprintf(buf, "%d,%d", WTSM(drawobj->u.freeform.pt[0].x), WTSM(drawobj->u.freeform.pt[0].y));
4452 0 : oustr += ascii(buf);
4453 : int i;
4454 0 : for (i = 1; i < drawobj->u.freeform.npt ; i++)
4455 : {
4456 : sprintf(buf, " %d,%d",
4457 0 : WTSM(drawobj->u.freeform.pt[i].x),
4458 0 : WTSM(drawobj->u.freeform.pt[i].y));
4459 0 : oustr += ascii(buf);
4460 : }
4461 0 : if( drawobj->u.freeform.pt[0].x == drawobj->u.freeform.pt[i-1].x &&
4462 0 : drawobj->u.freeform.pt[0].y == drawobj->u.freeform.pt[i-1].y )
4463 : {
4464 0 : bIsPolygon = true;
4465 : }
4466 : }
4467 0 : padd(ascii("draw:points"), sXML_CDATA, oustr);
4468 :
4469 0 : if( drawobj->property.fill_color <= 0xffffff ||
4470 0 : drawobj->property.pattern_type != 0)
4471 : {
4472 0 : bIsPolygon = true;
4473 : }
4474 :
4475 0 : if(bIsPolygon)
4476 : {
4477 0 : rstartEl(ascii("draw:polygon"), rList);
4478 0 : pList->clear();
4479 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4480 : // As Textbox
4481 : drawobj->property.pPara )
4482 : {
4483 0 : HWPPara *pPara = drawobj->property.pPara;
4484 : // parsePara(pPara);
4485 0 : while(pPara)
4486 : {
4487 0 : make_text_p1( pPara );
4488 0 : pPara = pPara->Next();
4489 : }
4490 : }
4491 0 : rendEl(ascii("draw:polygon"));
4492 : }
4493 : else
4494 : {
4495 0 : rstartEl(ascii("draw:polyline"), rList);
4496 0 : pList->clear();
4497 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4498 : // As Textbox
4499 : drawobj->property.pPara )
4500 : {
4501 0 : HWPPara *pPara = drawobj->property.pPara;
4502 : //parsePara(pPara);
4503 0 : while(pPara)
4504 : {
4505 0 : make_text_p1( pPara );
4506 0 : pPara = pPara->Next();
4507 : }
4508 : }
4509 0 : rendEl(ascii("draw:polyline"));
4510 : }
4511 0 : break;
4512 : }
4513 : case HWPDO_TEXTBOX:
4514 0 : if( !bIsRotate )
4515 : {
4516 0 : padd(ascii("svg:x"), sXML_CDATA,
4517 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4518 0 : padd(ascii("svg:y"), sXML_CDATA,
4519 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4520 : }
4521 0 : padd(ascii("svg:width"), sXML_CDATA,
4522 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4523 0 : padd(ascii("svg:height"), sXML_CDATA,
4524 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4525 0 : if( drawobj->property.flag & 0x01 )
4526 : {
4527 0 : int value = drawobj->extent.w < drawobj->extent.h ?
4528 0 : drawobj->extent.w : drawobj->extent.h ;
4529 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4530 0 : Double2Str (WTMM( value/10 )) + ascii("mm"));
4531 : }
4532 0 : else if( drawobj->property.flag & 0x04 )
4533 : {
4534 0 : int value = drawobj->extent.w < drawobj->extent.h ?
4535 0 : drawobj->extent.w : drawobj->extent.h ;
4536 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4537 0 : Double2Str (WTMM( value / 2)) + ascii("mm"));
4538 : }
4539 :
4540 0 : rstartEl(ascii("draw:text-box"), rList);
4541 0 : pList->clear();
4542 :
4543 0 : HWPPara *pPara = drawobj->u.textbox.h;
4544 : //parsePara(pPara);
4545 0 : while(pPara)
4546 : {
4547 0 : make_text_p1( pPara );
4548 0 : pPara = pPara->Next();
4549 : }
4550 :
4551 0 : rendEl(ascii("draw:text-box"));
4552 0 : break;
4553 : }
4554 : }
4555 0 : pList->clear();
4556 0 : drawobj = drawobj->next;
4557 : }
4558 0 : }
4559 :
4560 :
4561 : /**
4562 : *
4563 : */
4564 0 : void HwpReader::makeLine(Line * )
4565 : {
4566 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Horizontal Line"));
4567 0 : rstartEl( ascii("text:p"), rList);
4568 0 : pList->clear();
4569 0 : }
4570 :
4571 :
4572 : /**
4573 : * 입력-주석-숨은설명 : 사용자에게 숨은 설명을 보여준다.
4574 : * 문단이 포함될 수 있으나, 단지 문자열만 뽑아내어 파싱한다.
4575 : */
4576 0 : void HwpReader::makeHidden(Hidden * hbox)
4577 : {
4578 0 : hchar_string str;
4579 : int res;
4580 : hchar dest[3];
4581 :
4582 0 : padd(ascii("text:condition"), sXML_CDATA, ascii(""));
4583 0 : padd(ascii("text:string-value"), sXML_CDATA, ascii(""));
4584 0 : rstartEl(ascii("text:hidden-text"), rList);
4585 0 : pList->clear();
4586 0 : HWPPara *para = hbox->plist.front();
4587 :
4588 0 : while (para)
4589 : {
4590 0 : for (int n = 0; n < para->nch && para->hhstr[n]->hh;
4591 0 : n += para->hhstr[n]->WSize())
4592 : {
4593 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
4594 0 : for( int j = 0 ; j < res ; j++ )
4595 : {
4596 0 : str.push_back(dest[j]);
4597 : }
4598 : }
4599 0 : para = para->Next();
4600 : }
4601 0 : makeChars(str);
4602 0 : rendEl(ascii("text:hidden-text"));
4603 0 : }
4604 :
4605 :
4606 : /**
4607 : * 각주는 text:footnote, 미주는 text:endnote로 변환
4608 : */
4609 0 : void HwpReader::makeFootnote(Footnote * hbox)
4610 : {
4611 0 : if (hbox->type)
4612 : {
4613 0 : padd(ascii("text:id"), sXML_CDATA,
4614 0 : ascii(Int2Str(hbox->number, "edn%d", buf)));
4615 0 : rstartEl(ascii("text:endnote"), rList);
4616 0 : pList->clear();
4617 0 : padd(ascii("text:label"), sXML_CDATA,
4618 0 : ascii(Int2Str(hbox->number, "%d", buf)));
4619 0 : rstartEl(ascii("text:endnote-citation"), rList);
4620 0 : pList->clear();
4621 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4622 0 : rendEl(ascii("text:endnote-citation"));
4623 0 : rstartEl(ascii("text:endnote-body"), rList);
4624 0 : parsePara(hbox->plist.front());
4625 0 : rendEl(ascii("text:endnote-body"));
4626 0 : rendEl(ascii("text:endnote"));
4627 : }
4628 : else
4629 : {
4630 0 : padd(ascii("text:id"), sXML_CDATA,
4631 0 : ascii(Int2Str(hbox->number, "ftn%d", buf)));
4632 0 : rstartEl(ascii("text:footnote"), rList);
4633 0 : pList->clear();
4634 0 : padd(ascii("text:label"), sXML_CDATA,
4635 0 : ascii(Int2Str(hbox->number, "%d", buf)));
4636 0 : rstartEl(ascii("text:footnote-citation"), rList);
4637 0 : pList->clear();
4638 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4639 0 : rendEl(ascii("text:footnote-citation"));
4640 0 : rstartEl(ascii("text:footnote-body"), rList);
4641 0 : parsePara(hbox->plist.front());
4642 0 : rendEl(ascii("text:footnote-body"));
4643 0 : rendEl(ascii("text:footnote"));
4644 : }
4645 0 : }
4646 :
4647 :
4648 : /**
4649 : * page/footnote/endnote/picture/table/formula number
4650 : */
4651 0 : void HwpReader::makeAutoNum(AutoNum * hbox)
4652 : {
4653 0 : switch (hbox->type)
4654 : {
4655 : case PGNUM_AUTO:
4656 0 : rstartEl(ascii("text:page-number"), rList);
4657 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4658 0 : rendEl(ascii("text:page-number"));
4659 0 : break;
4660 : case FNNUM_AUTO:
4661 0 : break;
4662 : case ENNUM_AUTO:
4663 0 : break;
4664 : case EQUNUM_AUTO:
4665 : case PICNUM_AUTO:
4666 0 : padd(ascii("text:ref-name"),sXML_CDATA,
4667 0 : ascii(Int2Str(hbox->number, "refIllustration%d", buf)));
4668 0 : padd(ascii("text:name"),sXML_CDATA, ascii("Illustration"));
4669 0 : padd(ascii("style:num-format"),sXML_CDATA, ascii("1"));
4670 0 : rstartEl(ascii("text:sequence"), rList);
4671 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4672 0 : rendEl(ascii("text:sequence"));
4673 0 : break;
4674 : case TBLNUM_AUTO:
4675 0 : padd(ascii("text:ref-name"),sXML_CDATA,
4676 0 : ascii(Int2Str(hbox->number, "refTable%d", buf)));
4677 0 : padd(ascii("text:name"),sXML_CDATA, ascii("Table"));
4678 0 : padd(ascii("style:num-format"),sXML_CDATA, ascii("1"));
4679 0 : rstartEl(ascii("text:sequence"), rList);
4680 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4681 0 : rendEl(ascii("text:sequence"));
4682 0 : break;
4683 : }
4684 0 : }
4685 :
4686 :
4687 0 : void HwpReader::makeShowPageNum()
4688 : {
4689 0 : ShowPageNum *hbox = d->pPn;
4690 0 : int nPos = 0;
4691 0 : if( hbox->where == 1 || hbox->where == 4 )
4692 0 : nPos = 1;
4693 0 : else if( hbox->where == 2 || hbox->where == 5 )
4694 0 : nPos = 2;
4695 0 : else if( hbox->where == 3 || hbox->where == 6 )
4696 0 : nPos = 3;
4697 : else /* 이 경우가 존재하면 안된다. */
4698 : {
4699 0 : if( d->nPnPos == 1 )
4700 0 : nPos = 1;
4701 0 : else if( d->nPnPos == 3 )
4702 0 : nPos = 3;
4703 : }
4704 :
4705 0 : padd(ascii("draw:style-name"), sXML_CDATA,
4706 0 : ascii(Int2Str(nPos, "PNBox%d", buf)));
4707 0 : padd(ascii("draw:name"), sXML_CDATA,
4708 0 : ascii(Int2Str(nPos, "PageNumber%d", buf)));
4709 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
4710 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
4711 0 : padd(ascii("svg:width"), sXML_CDATA, ascii("2.0cm"));
4712 0 : padd(ascii("fo:min-height"), sXML_CDATA, ascii("0.5cm"));
4713 0 : rstartEl(ascii("draw:text-box"), rList);
4714 0 : pList->clear();
4715 :
4716 0 : padd(ascii("text:style-name"), sXML_CDATA,
4717 0 : ascii(Int2Str(nPos, "PNPara%d", buf)));
4718 0 : rstartEl(ascii("text:p"), rList);
4719 0 : pList->clear();
4720 0 : if( hbox->shape > 2 )
4721 0 : rchars(ascii("- "));
4722 0 : if( hbox->shape % 3 == 0 )
4723 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("1"));
4724 0 : else if( hbox->shape % 3 == 1 )
4725 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("I"));
4726 : else
4727 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("i"));
4728 0 : padd(ascii("text:select-page"), sXML_CDATA, ascii("current"));
4729 0 : rstartEl(ascii("text:page-number"), rList);
4730 0 : pList->clear();
4731 0 : rchars(ascii("2"));
4732 0 : rendEl(ascii("text:page-number"));
4733 0 : if( hbox->shape > 2 )
4734 0 : rchars(ascii(" -"));
4735 0 : rendEl(ascii("text:p"));
4736 0 : rendEl(ascii("draw:text-box"));
4737 0 : }
4738 :
4739 :
4740 : /**
4741 : * mail merge operation using hwp addressbook and hwp data form.
4742 : * not support operation in OO writer.
4743 : */
4744 0 : void HwpReader::makeMailMerge(MailMerge * hbox)
4745 : {
4746 0 : hchar_string const boxstr = hbox->GetString();
4747 0 : rchars((hconv(boxstr.c_str())));
4748 0 : }
4749 :
4750 :
4751 : /**
4752 : * Make heading contents file using toc marks
4753 : * not support operation.
4754 : */
4755 0 : void HwpReader::makeTocMark(TocMark * ) /*hbox */
4756 : {
4757 0 : }
4758 :
4759 :
4760 : /**
4761 : * Make search character table in automatic
4762 : * not support operation
4763 : */
4764 0 : void HwpReader::makeIndexMark(IndexMark * ) /*hbox */
4765 : {
4766 0 : }
4767 :
4768 :
4769 0 : void HwpReader::makeOutline(Outline * hbox)
4770 : {
4771 0 : if( hbox->kind == 1 )
4772 0 : rchars(OUString(hbox->GetUnicode().c_str()));
4773 0 : }
4774 :
4775 :
4776 2 : void HwpReader::parsePara(HWPPara * para, bool bParaStart)
4777 : {
4778 :
4779 8 : while (para)
4780 : {
4781 4 : if( para->nch == 1)
4782 : {
4783 0 : if( !bParaStart )
4784 : {
4785 0 : padd(ascii("text:style-name"), sXML_CDATA,
4786 0 : ascii(getPStyleName(para->GetParaShape().index, buf)));
4787 0 : rstartEl( ascii("text:p"),rList);
4788 0 : pList->clear();
4789 : }
4790 0 : if( d->bFirstPara && d->bInBody )
4791 : {
4792 : /* for HWP's Bookmark */
4793 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
4794 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
4795 0 : rstartEl(ascii("text:bookmark"), rList);
4796 0 : pList->clear();
4797 0 : rendEl(ascii("text:bookmark"));
4798 0 : d->bFirstPara = false;
4799 : }
4800 0 : if( d->bInHeader )
4801 : {
4802 0 : makeShowPageNum();
4803 0 : d->bInHeader = false;
4804 : }
4805 :
4806 0 : rendEl( ascii("text:p") );
4807 : }
4808 : else
4809 : {
4810 4 : if (!para->ctrlflag)
4811 : {
4812 4 : if (para->contain_cshape)
4813 4 : make_text_p1(para, bParaStart);
4814 : else
4815 0 : make_text_p0(para, bParaStart);
4816 : }
4817 : else
4818 0 : make_text_p3(para, bParaStart);
4819 : }
4820 4 : bParaStart = false;
4821 4 : para = para->Next();
4822 : }
4823 8 : }
4824 :
4825 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|