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 :
22 : #include <boost/shared_ptr.hpp>
23 :
24 : #include "hwpreader.hxx"
25 : #include <math.h>
26 :
27 : #include <comphelper/newarray.hxx>
28 :
29 : #include "formula.h"
30 : #include "cspline.h"
31 :
32 : extern int getRepFamilyName(const char* , char *, double &ratio);
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(0)
46 : #define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(0)
47 : #define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(0)
48 : #define padd(x,y,z) pList->addAttribute(x,y,z)
49 : #define Double2Str(x) OUString::valueOf((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)
127 : {
128 4 : comphelper::MediaDescriptor aDescriptor(rDescriptor);
129 4 : aDescriptor.addInputStream();
130 :
131 : Reference< XInputStream > xInputStream(
132 4 : aDescriptor[comphelper::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY_THROW);
133 :
134 4 : HStream stream;
135 4 : Sequence < sal_Int8 > aBuffer;
136 4 : sal_Int32 nRead, nBlock = 32768, nTotal = 0;
137 4 : while( 1 )
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))
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 2 : 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 10 : if( ISNUMBER( pDate[0] ) && ISNUMBER( pDate[1] ) &&
274 8 : 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 : 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 0 : 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 : 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 : sal_Bool bIsLeft = sal_False, bIsMiddle = sal_False, bIsRight = sal_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 = sal_True;
837 0 : bIsRight = sal_True;
838 : }
839 0 : else if( pn->where == 1 || pn->where == 4 )
840 : {
841 0 : bIsLeft = sal_True;
842 : }
843 0 : else if( pn->where == 2 || pn->where == 5 )
844 : {
845 0 : bIsMiddle = sal_True;
846 : }
847 0 : else if( pn->where == 3 || pn->where == 6 )
848 : {
849 0 : bIsRight = sal_True;
850 : }
851 : }
852 :
853 8 : for( i = 1; i <= 3 ; i++ )
854 : {
855 6 : if( i == 1 && bIsLeft == sal_False )
856 2 : continue;
857 4 : if( i == 2 && bIsMiddle == sal_False )
858 2 : continue;
859 2 : if( i == 3 && bIsRight == sal_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 : || 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 : 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 : || 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 : 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 : && 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 : && 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 : && 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 : && 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 : && 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 : && 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 : && 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 : case 3: /* 점선 */
1801 0 : padd(ascii("style:style"), sXML_CDATA, ascii("dotted"));
1802 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0.02mm"));
1803 0 : break;
1804 : case 2: /* 두꺼운선 */
1805 : case 4: /* 2중선 */
1806 0 : padd(ascii("style:width"), sXML_CDATA, ascii("0.35mm"));
1807 0 : break;
1808 : case 0: /* 없음 */
1809 : default:
1810 0 : padd(ascii("style:style"), sXML_CDATA, ascii("none"));
1811 0 : break;
1812 : }
1813 0 : rstartEl(ascii("style:column-sep"),rList);
1814 0 : pList->clear();
1815 0 : rendEl(ascii("style:column-sep"));
1816 : }
1817 0 : double spacing = WTI(coldef->spacing)/ 2. ;
1818 0 : for(int ii = 0 ; ii < coldef->ncols ; ii++)
1819 : {
1820 0 : if( ii == 0 )
1821 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0mm"));
1822 : else
1823 0 : padd(ascii("fo:margin-left"), sXML_CDATA,
1824 0 : Double2Str( spacing) + ascii("inch"));
1825 0 : if( ii == ( coldef->ncols -1) )
1826 0 : padd(ascii("fo:margin-right"), sXML_CDATA,ascii("0mm"));
1827 : else
1828 0 : padd(ascii("fo:margin-right"), sXML_CDATA,
1829 0 : Double2Str( spacing) + ascii("inch"));
1830 0 : rstartEl(ascii("style:column"),rList);
1831 0 : pList->clear();
1832 0 : rendEl(ascii("style:column"));
1833 : }
1834 0 : rendEl(ascii("style:columns"));
1835 : }
1836 :
1837 2 : void HwpReader::makeTStyle(CharShape * cshape)
1838 : {
1839 4 : padd(ascii("style:name"), sXML_CDATA,
1840 2 : ascii(Int2Str(cshape->index, "T%d", buf)));
1841 2 : padd(ascii("style:family"), sXML_CDATA, ascii("text"));
1842 2 : rstartEl(ascii("style:style"), rList);
1843 2 : pList->clear();
1844 2 : parseCharShape(cshape);
1845 2 : rstartEl(ascii("style:properties"), rList);
1846 2 : pList->clear();
1847 2 : rendEl(ascii("style:properties"));
1848 2 : rendEl(ascii("style:style"));
1849 2 : }
1850 :
1851 :
1852 0 : void HwpReader::makeTableStyle(Table *tbl)
1853 : {
1854 : // --------------- table ---------------- //
1855 0 : TxtBox *hbox = tbl->box;
1856 :
1857 0 : padd(ascii("style:name"), sXML_CDATA,
1858 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
1859 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table"));
1860 0 : rstartEl(ascii("style:style"), rList);
1861 0 : pList->clear();
1862 0 : padd(ascii("style:width"), sXML_CDATA,
1863 0 : Double2Str(WTMM(hbox->box_xs)) + ascii("mm"));
1864 0 : padd(ascii("table:align"), sXML_CDATA,ascii("left"));
1865 0 : padd(ascii("fo:keep-with-next"), sXML_CDATA,ascii("false"));
1866 0 : rstartEl(ascii("style:properties"), rList);
1867 0 : pList->clear();
1868 0 : rendEl(ascii("style:properties"));
1869 0 : rendEl(ascii("style:style"));
1870 :
1871 : // --------------- column ---------------- //
1872 0 : for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
1873 : {
1874 0 : sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
1875 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1876 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-column"));
1877 0 : rstartEl(ascii("style:style"), rList);
1878 0 : pList->clear();
1879 0 : padd(ascii("style:column-width"), sXML_CDATA,
1880 0 : Double2Str(WTMM(tbl->columns.data[i+1] - tbl->columns.data[i])) + ascii("mm"));
1881 0 : rstartEl(ascii("style:properties"), rList);
1882 0 : pList->clear();
1883 0 : rendEl(ascii("style:properties"));
1884 0 : rendEl(ascii("style:style"));
1885 : }
1886 :
1887 : // --------------- row ---------------- //
1888 0 : for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++)
1889 : {
1890 0 : sprintf(buf,"Table%d.row%" SAL_PRI_SIZET "u",hbox->style.boxnum, i + 1);
1891 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1892 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-row"));
1893 0 : rstartEl(ascii("style:style"), rList);
1894 0 : pList->clear();
1895 0 : padd(ascii("style:row-height"), sXML_CDATA,
1896 0 : Double2Str(WTMM(tbl->rows.data[i+1] - tbl->rows.data[i])) + ascii("mm"));
1897 0 : rstartEl(ascii("style:properties"), rList);
1898 0 : pList->clear();
1899 0 : rendEl(ascii("style:properties"));
1900 0 : rendEl(ascii("style:style"));
1901 : }
1902 :
1903 : // --------------- cell --------------------- //
1904 0 : for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
1905 : {
1906 0 : std::list<TCell*>::iterator it = tbl->cells.begin();
1907 :
1908 0 : for( int ii = 0; it != tbl->cells.end(); ++it, ii++ ){
1909 0 : if( ii == i )
1910 0 : break;
1911 : }
1912 :
1913 0 : TCell *tcell = *it;
1914 0 : sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
1915 0 : padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
1916 0 : padd(ascii("style:family"), sXML_CDATA,ascii("table-cell"));
1917 0 : rstartEl(ascii("style:style"), rList);
1918 0 : pList->clear();
1919 0 : Cell *cl = tcell->pCell;
1920 0 : if( cl->ver_align == 1 )
1921 0 : padd(ascii("fo:vertical-align"), sXML_CDATA,ascii("middle"));
1922 :
1923 0 : if(cl->linetype[2] == cl->linetype[3] && cl->linetype[2] == cl->linetype[0]
1924 0 : && cl->linetype[2] == cl->linetype[1])
1925 : {
1926 0 : switch( cl->linetype[2] )
1927 : {
1928 : case 1: /* 가는실선 */
1929 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1930 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
1931 0 : break;
1932 : case 2: /* 굵은실선 */
1933 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
1934 0 : break;
1935 : case 4: /* 2중선 */
1936 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1937 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
1938 0 : break;
1939 : }
1940 : }
1941 : else
1942 : {
1943 0 : switch( cl->linetype[0] )
1944 : {
1945 : case 1: /* 가는실선 */
1946 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1947 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
1948 0 : break;
1949 : case 2: /* 굵은실선 */
1950 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
1951 0 : break;
1952 : case 4: /* 2중선 */
1953 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1954 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
1955 0 : break;
1956 : }
1957 0 : switch( cl->linetype[1] )
1958 : {
1959 : case 1: /* 가는실선 */
1960 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1961 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
1962 0 : break;
1963 : case 2: /* 굵은실선 */
1964 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
1965 0 : break;
1966 : case 4: /* 2중선 */
1967 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1968 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
1969 0 : break;
1970 : }
1971 0 : switch( cl->linetype[2] )
1972 : {
1973 : case 1: /* 가는실선 */
1974 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1975 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
1976 0 : break;
1977 : case 2: /* 굵은실선 */
1978 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
1979 0 : break;
1980 : case 4: /* 2중선 */
1981 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1982 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
1983 0 : break;
1984 : }
1985 0 : switch( cl->linetype[3] )
1986 : {
1987 : case 1: /* 가는실선 */
1988 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
1989 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
1990 0 : break;
1991 : case 2: /* 굵은실선 */
1992 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
1993 0 : break;
1994 : case 4: /* 2중선 */
1995 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
1996 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
1997 0 : break;
1998 : }
1999 : }
2000 0 : if(cl->shade != 0)
2001 0 : padd(ascii("fo:background-color"), sXML_CDATA,
2002 : ascii(hcolor2str(sal::static_int_cast<uchar>(cl->color),
2003 0 : sal::static_int_cast<uchar>(cl->shade), buf)));
2004 :
2005 0 : rstartEl(ascii("style:properties"), rList);
2006 0 : pList->clear();
2007 0 : rendEl(ascii("style:properties"));
2008 :
2009 0 : rendEl(ascii("style:style"));
2010 : }
2011 0 : }
2012 :
2013 :
2014 0 : void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle)
2015 : {
2016 0 : while( hdo )
2017 : {
2018 0 : padd(ascii("style:name"), sXML_CDATA,
2019 0 : ascii(Int2Str(hdo->index, "Draw%d", buf)));
2020 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2021 :
2022 0 : rstartEl(ascii("style:style"), rList);
2023 0 : pList->clear();
2024 :
2025 0 : switch (fstyle->txtflow)
2026 : {
2027 : case 0:
2028 0 : break;
2029 : case 1:
2030 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2031 0 : break;
2032 : case 2:
2033 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2034 0 : break;
2035 : }
2036 : long color;
2037 : // invisible line
2038 0 : if( hdo->property.line_color > 0xffffff )
2039 : {
2040 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("none") );
2041 : }
2042 : else
2043 : {
2044 :
2045 0 : if( hdo->property.line_pstyle == 0 )
2046 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("solid") );
2047 0 : else if( hdo->property.line_pstyle < 5 )
2048 : {
2049 0 : padd(ascii("draw:stroke"), sXML_CDATA, ascii("dash") );
2050 0 : padd(ascii("draw:stroke-dash"), sXML_CDATA,
2051 0 : ascii(Int2Str(hdo->index, "LineType%d", buf)));
2052 : }
2053 0 : padd(ascii("svg:stroke-width"), sXML_CDATA,
2054 0 : Double2Str( WTMM(hdo->property.line_width)) + ascii("mm" ));
2055 0 : color = hdo->property.line_color;
2056 : sprintf( buf, "#%02x%02x%02x",
2057 : sal_uInt16(color & 0xff),
2058 : sal_uInt16((color >> 8) & 0xff),
2059 0 : sal_uInt16((color >>16) & 0xff) );
2060 0 : padd(ascii("svg:stroke-color"), sXML_CDATA, ascii( buf) );
2061 : }
2062 :
2063 0 : if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC ||
2064 : hdo->type == HWPDO_FREEFORM || hdo->type == HWPDO_ADVANCED_ARC )
2065 : {
2066 :
2067 0 : if( hdo->property.line_tstyle > 0 )
2068 : {
2069 0 : padd(ascii("draw:marker-start"), sXML_CDATA,
2070 0 : ascii(ArrowShape[hdo->property.line_tstyle].name) );
2071 0 : if( hdo->property.line_width > 100 )
2072 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2073 0 : Double2Str( WTMM(hdo->property.line_width * 3)) + ascii("mm" ));
2074 0 : else if( hdo->property.line_width > 80 )
2075 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2076 0 : Double2Str( WTMM(hdo->property.line_width * 4)) + ascii("mm" ));
2077 0 : else if( hdo->property.line_width > 60 )
2078 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2079 0 : Double2Str( WTMM(hdo->property.line_width * 5)) + ascii("mm" ));
2080 0 : else if( hdo->property.line_width > 40 )
2081 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2082 0 : Double2Str( WTMM(hdo->property.line_width * 6)) + ascii("mm" ));
2083 : else
2084 0 : padd(ascii("draw:marker-start-width"), sXML_CDATA,
2085 0 : Double2Str( WTMM(hdo->property.line_width * 7)) + ascii("mm" ));
2086 : }
2087 :
2088 0 : if( hdo->property.line_hstyle > 0 )
2089 : {
2090 0 : padd(ascii("draw:marker-end"), sXML_CDATA,
2091 0 : ascii(ArrowShape[hdo->property.line_hstyle].name) );
2092 0 : if( hdo->property.line_width > 100 )
2093 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2094 0 : Double2Str( WTMM(hdo->property.line_width * 3)) + ascii("mm" ));
2095 0 : else if( hdo->property.line_width > 80 )
2096 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2097 0 : Double2Str( WTMM(hdo->property.line_width * 4)) + ascii("mm" ));
2098 0 : else if( hdo->property.line_width > 60 )
2099 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2100 0 : Double2Str( WTMM(hdo->property.line_width * 5)) + ascii("mm" ));
2101 0 : else if( hdo->property.line_width > 40 )
2102 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2103 0 : Double2Str( WTMM(hdo->property.line_width * 6)) + ascii("mm" ));
2104 : else
2105 0 : padd(ascii("draw:marker-end-width"), sXML_CDATA,
2106 0 : Double2Str( WTMM(hdo->property.line_width * 7)) + ascii("mm" ));
2107 : }
2108 : }
2109 :
2110 0 : if(hdo->type != HWPDO_LINE )
2111 : {
2112 0 : if( hdo->property.flag >> 19 & 0x01 )
2113 : {
2114 0 : padd( ascii("draw:textarea-horizontal-align"), sXML_CDATA, ascii("center"));
2115 : }
2116 :
2117 0 : color = hdo->property.fill_color;
2118 :
2119 0 : if( hdo->property.flag >> 18 & 0x01 ) // bitmap pattern
2120 : {
2121 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("bitmap"));
2122 0 : padd(ascii("draw:fill-image-name"), sXML_CDATA,
2123 0 : ascii(Int2Str(hdo->index, "fillimage%d", buf)));
2124 : // bitmap resizing
2125 0 : if( hdo->property.flag >> 3 & 0x01 )
2126 : {
2127 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("stretch"));
2128 : }
2129 : else
2130 : {
2131 0 : padd(ascii("style:repeat"), sXML_CDATA, ascii("repeat"));
2132 0 : padd(ascii("draw:fill-image-ref-point"), sXML_CDATA, ascii("top-left"));
2133 : }
2134 0 : if( hdo->property.flag >> 20 & 0x01 )
2135 : {
2136 0 : if( hdo->property.luminance > 0 )
2137 : {
2138 0 : padd(ascii("draw:transparency"), sXML_CDATA,
2139 0 : ascii(Int2Str(hdo->property.luminance, "%d%%", buf)));
2140 : }
2141 : }
2142 :
2143 : }
2144 : // Gradation
2145 0 : else if( hdo->property.flag >> 16 & 0x01 )
2146 : {
2147 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("gradient"));
2148 0 : padd(ascii("draw:fill-gradient-name"), sXML_CDATA,
2149 0 : ascii(Int2Str(hdo->index, "Grad%d", buf)));
2150 0 : padd(ascii("draw:gradient-step-count"), sXML_CDATA,
2151 0 : ascii(Int2Str(hdo->property.nstep, "%d", buf)));
2152 :
2153 : }
2154 : // Hatching
2155 0 : else if( hdo->property.pattern_type >> 24 & 0x01 )
2156 : {
2157 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("hatch"));
2158 0 : padd(ascii("draw:fill-hatch-name"), sXML_CDATA,
2159 0 : ascii(Int2Str(hdo->index, "Hatch%d", buf)));
2160 0 : if( color < 0xffffff )
2161 : {
2162 : sprintf( buf, "#%02x%02x%02x",
2163 : sal_uInt16(color & 0xff),
2164 : sal_uInt16((color >> 8) & 0xff),
2165 0 : sal_uInt16((color >>16) & 0xff) );
2166 0 : padd(ascii("draw:fill-color"), sXML_CDATA, ascii( buf) );
2167 0 : padd(ascii("draw:fill-hatch-solid"), sXML_CDATA, ascii("true"));
2168 : }
2169 : }
2170 0 : else if( color <= 0xffffff )
2171 : {
2172 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("solid"));
2173 : sprintf( buf, "#%02x%02x%02x",
2174 : sal_uInt16(color & 0xff),
2175 : sal_uInt16((color >> 8) & 0xff),
2176 0 : sal_uInt16((color >>16) & 0xff) );
2177 0 : padd(ascii("draw:fill-color"), sXML_CDATA, ascii( buf) );
2178 : }
2179 : else
2180 0 : padd(ascii("draw:fill"), sXML_CDATA, ascii("none"));
2181 : }
2182 :
2183 0 : if( fstyle->anchor_type == CHAR_ANCHOR )
2184 : {
2185 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2186 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2187 : }
2188 :
2189 0 : rstartEl(ascii("style:properties"), rList);
2190 0 : pList->clear();
2191 0 : rendEl(ascii("style:properties"));
2192 0 : rendEl(ascii("style:style"));
2193 :
2194 0 : if( hdo->type == 0 )
2195 : {
2196 0 : makeDrawStyle( hdo->child, fstyle );
2197 : }
2198 0 : hdo = hdo->next;
2199 : }
2200 0 : }
2201 :
2202 :
2203 0 : void HwpReader::makeCaptionStyle(FBoxStyle * fstyle)
2204 : {
2205 0 : padd(ascii("style:name"), sXML_CDATA,
2206 0 : ascii(Int2Str(fstyle->boxnum, "CapBox%d", buf)));
2207 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2208 0 : rstartEl(ascii("style:style"), rList);
2209 0 : pList->clear();
2210 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0cm"));
2211 0 : padd(ascii("fo:margin-right"), sXML_CDATA, ascii("0cm"));
2212 0 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
2213 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
2214 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2215 0 : switch (fstyle->txtflow)
2216 : {
2217 : case 0:
2218 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2219 0 : break;
2220 : case 1:
2221 0 : if( fstyle->boxtype == 'G' )
2222 0 : padd(ascii("style:run-through"), sXML_CDATA, ascii("background"));
2223 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2224 0 : break;
2225 : case 2:
2226 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2227 0 : break;
2228 : }
2229 0 : if (fstyle->anchor_type == CHAR_ANCHOR)
2230 : {
2231 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2232 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2233 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2234 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2235 : }
2236 : else
2237 : {
2238 :
2239 0 : switch (-(fstyle->xpos))
2240 : {
2241 : case 2:
2242 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("right"));
2243 0 : break;
2244 : case 3:
2245 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2246 0 : break;
2247 : case 1:
2248 : default:
2249 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2250 0 : break;
2251 : }
2252 0 : switch (-(fstyle->ypos))
2253 : {
2254 : case 2:
2255 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("bottom"));
2256 0 : break;
2257 : case 3:
2258 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("middle"));
2259 0 : break;
2260 : case 1:
2261 : default:
2262 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2263 0 : break;
2264 : }
2265 0 : if ( fstyle->anchor_type == PARA_ANCHOR )
2266 : {
2267 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2268 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2269 : }
2270 : else
2271 : {
2272 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("page-content"));
2273 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("page-content"));
2274 : }
2275 : }
2276 0 : rstartEl(ascii("style:properties"), rList);
2277 0 : pList->clear();
2278 0 : rendEl(ascii("style:properties"));
2279 0 : rendEl(ascii("style:style"));
2280 0 : if( fstyle->boxtype == 'G' )
2281 : {
2282 0 : padd(ascii("style:name"), sXML_CDATA,
2283 0 : ascii(Int2Str(fstyle->boxnum, "G%d", buf)));
2284 : }
2285 : else
2286 : {
2287 0 : padd(ascii("style:name"), sXML_CDATA,
2288 0 : ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf)));
2289 : }
2290 :
2291 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2292 0 : rstartEl(ascii("style:style"), rList);
2293 0 : pList->clear();
2294 :
2295 0 : padd(ascii("fo:margin-left"), sXML_CDATA, ascii("0cm"));
2296 0 : padd(ascii("fo:margin-right"), sXML_CDATA, ascii("0cm"));
2297 0 : padd(ascii("fo:margin-top"), sXML_CDATA, ascii("0cm"));
2298 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA, ascii("0cm"));
2299 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2300 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2301 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2302 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2303 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2304 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2305 0 : if( fstyle->boxtype == 'G' )
2306 : {
2307 0 : char *cell = (char *)fstyle->cell;
2308 0 : padd(ascii("draw:luminance"), sXML_CDATA,
2309 0 : ascii(Int2Str(cell[0], "%d%%", buf)));
2310 0 : padd(ascii("draw:contrast"), sXML_CDATA,
2311 0 : ascii(Int2Str(cell[1], "%d%%", buf)));
2312 0 : if( cell[2] == 0 )
2313 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("standard"));
2314 0 : else if( cell[2] == 1 )
2315 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("greyscale"));
2316 0 : else if( cell[2] == 2 )
2317 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("mono"));
2318 : }
2319 : else
2320 : {
2321 0 : Cell *cell = (Cell *)fstyle->cell;
2322 0 : if(cell->linetype[0] == cell->linetype[1] &&
2323 0 : cell->linetype[0] == cell->linetype[2] &&
2324 0 : cell->linetype[0] == cell->linetype[3])
2325 : {
2326 0 : switch( cell->linetype[0] )
2327 : {
2328 : case 0:
2329 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2330 0 : break;
2331 : case 1: /* 가는실선 */
2332 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2333 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
2334 0 : break;
2335 : case 2: /* 굵은실선 */
2336 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
2337 0 : break;
2338 : case 4: /* 2중선 */
2339 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2340 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
2341 0 : break;
2342 : }
2343 : }
2344 : else
2345 : {
2346 0 : switch( cell->linetype[0] )
2347 : {
2348 : case 1: /* 가는실선 */
2349 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2350 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
2351 0 : break;
2352 : case 2: /* 굵은실선 */
2353 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
2354 0 : break;
2355 : case 4: /* 2중선 */
2356 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2357 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
2358 0 : break;
2359 : }
2360 0 : switch( cell->linetype[1] )
2361 : {
2362 : case 1: /* 가는실선 */
2363 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2364 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
2365 0 : break;
2366 : case 2: /* 굵은실선 */
2367 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
2368 0 : break;
2369 : case 4: /* 2중선 */
2370 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2371 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
2372 0 : break;
2373 : }
2374 0 : switch( cell->linetype[2] )
2375 : {
2376 : case 1: /* 가는실선 */
2377 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2378 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
2379 0 : break;
2380 : case 2: /* 굵은실선 */
2381 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
2382 0 : break;
2383 : case 4: /* 2중선 */
2384 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2385 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
2386 0 : break;
2387 : }
2388 0 : switch( cell->linetype[3] )
2389 : {
2390 : case 1: /* 가는실선 */
2391 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2392 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
2393 0 : break;
2394 : case 2: /* 굵은실선 */
2395 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
2396 0 : break;
2397 : case 4: /* 2중선 */
2398 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2399 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
2400 0 : break;
2401 : }
2402 : }
2403 0 : if(cell->shade != 0)
2404 0 : padd(ascii("fo:background-color"), sXML_CDATA, ascii(hcolor2str(
2405 : sal::static_int_cast<uchar>(cell->color),
2406 0 : sal::static_int_cast<uchar>(cell->shade), buf)));
2407 : }
2408 0 : rstartEl(ascii("style:properties"), rList);
2409 0 : pList->clear();
2410 0 : rendEl(ascii("style:properties"));
2411 0 : rendEl(ascii("style:style"));
2412 0 : }
2413 :
2414 :
2415 : /**
2416 : * Floating 객체에 대한 스타일을 만든다.
2417 : */
2418 0 : void HwpReader::makeFStyle(FBoxStyle * fstyle)
2419 : {
2420 : /* 캡션 exist */
2421 0 : if( ( fstyle->boxtype == 'G' || fstyle->boxtype == 'X' ) && fstyle->cap_len > 0 )
2422 : {
2423 0 : makeCaptionStyle(fstyle);
2424 0 : return;
2425 : }
2426 0 : switch( fstyle->boxtype )
2427 : {
2428 : case 'X' : // txtbox
2429 : case 'E' : // equation
2430 : case 'B' : // button
2431 : case 'O' : // other
2432 : case 'T' : // table
2433 0 : padd(ascii("style:name"), sXML_CDATA,
2434 0 : ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf)));
2435 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2436 0 : break;
2437 : case 'G' : // graphics
2438 0 : padd(ascii("style:name"), sXML_CDATA,
2439 0 : ascii(Int2Str(fstyle->boxnum, "G%d", buf)));
2440 0 : padd(ascii("style:family"), sXML_CDATA, ascii("graphics"));
2441 0 : break;
2442 : case 'L' : // line TODO : all
2443 0 : padd(ascii("style:name"), sXML_CDATA,
2444 0 : ascii(Int2Str(fstyle->boxnum, "L%d", buf)));
2445 0 : padd( ascii("style:family") , sXML_CDATA , ascii("paragraph") );
2446 0 : break;
2447 : }
2448 :
2449 0 : rstartEl(ascii("style:style"), rList);
2450 0 : pList->clear();
2451 :
2452 0 : if ( fstyle->boxtype == 'T')
2453 : {
2454 0 : padd(ascii("fo:padding"), sXML_CDATA, ascii("0cm"));
2455 : }
2456 :
2457 0 : if( !(fstyle->boxtype == 'G' && fstyle->cap_len > 0 ))
2458 : {
2459 0 : padd(ascii("fo:margin-left"), sXML_CDATA,
2460 0 : Double2Str(WTMM(fstyle->margin[0][0]) ) + ascii("mm"));
2461 0 : padd(ascii("fo:margin-right"), sXML_CDATA,
2462 0 : Double2Str(WTMM(fstyle->margin[0][1])) + ascii("mm"));
2463 0 : padd(ascii("fo:margin-top"), sXML_CDATA,
2464 0 : Double2Str(WTMM(fstyle->margin[0][2])) + ascii("mm"));
2465 0 : padd(ascii("fo:margin-bottom"), sXML_CDATA,
2466 0 : Double2Str(WTMM(fstyle->margin[0][3])) + ascii("mm"));
2467 : }
2468 :
2469 0 : switch (fstyle->txtflow)
2470 : {
2471 : case 0:
2472 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("none"));
2473 0 : break;
2474 : case 1:
2475 0 : if( fstyle->boxtype == 'G' || fstyle->boxtype == 'B' || fstyle->boxtype == 'O')
2476 0 : padd(ascii("style:run-through"), sXML_CDATA, ascii("background"));
2477 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("run-through"));
2478 0 : break;
2479 : case 2:
2480 0 : padd(ascii("style:wrap"), sXML_CDATA, ascii("dynamic"));
2481 0 : break;
2482 : }
2483 0 : if (fstyle->anchor_type == CHAR_ANCHOR)
2484 : {
2485 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("top"));
2486 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("baseline"));
2487 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2488 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2489 : }
2490 : else
2491 : {
2492 :
2493 0 : switch (-(fstyle->xpos))
2494 : {
2495 : case 2:
2496 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("right"));
2497 0 : break;
2498 : case 3:
2499 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("center"));
2500 0 : break;
2501 : case 1:
2502 : default:
2503 0 : padd(ascii("style:horizontal-pos"), sXML_CDATA, ascii("from-left"));
2504 0 : break;
2505 : }
2506 0 : switch (-(fstyle->ypos))
2507 : {
2508 : case 2:
2509 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("bottom"));
2510 0 : break;
2511 : case 3:
2512 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("middle"));
2513 0 : break;
2514 : case 1:
2515 : default:
2516 0 : padd(ascii("style:vertical-pos"), sXML_CDATA, ascii("from-top"));
2517 0 : break;
2518 : }
2519 0 : if ( fstyle->anchor_type == PARA_ANCHOR )
2520 : {
2521 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("paragraph"));
2522 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("paragraph"));
2523 : }
2524 : else
2525 : {
2526 0 : padd(ascii("style:vertical-rel"), sXML_CDATA, ascii("page-content"));
2527 0 : padd(ascii("style:horizontal-rel"), sXML_CDATA, ascii("page-content"));
2528 : }
2529 : }
2530 0 : if( fstyle->boxtype == 'X' || fstyle->boxtype == 'B' )
2531 : {
2532 0 : Cell *cell = (Cell *)fstyle->cell;
2533 0 : if(cell->linetype[0] == cell->linetype[1] &&
2534 0 : cell->linetype[0] == cell->linetype[2] &&
2535 0 : cell->linetype[0] == cell->linetype[3])
2536 : {
2537 0 : switch( cell->linetype[0] )
2538 : {
2539 : case 0:
2540 0 : padd(ascii("fo:border"), sXML_CDATA, ascii("none"));
2541 0 : break;
2542 : case 1: /* 가는실선 */
2543 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2544 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.002cm solid #000000"));
2545 0 : break;
2546 : case 2: /* 굵은실선 */
2547 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.035cm solid #000000"));
2548 0 : break;
2549 : case 4: /* 2중선 */
2550 0 : padd(ascii("style:border-line-width"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2551 0 : padd(ascii("fo:border"), sXML_CDATA,ascii("0.039cm double #000000"));
2552 0 : break;
2553 : }
2554 : }
2555 : else
2556 : {
2557 0 : switch( cell->linetype[0] )
2558 : {
2559 : case 1: /* 가는실선 */
2560 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2561 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.002cm solid #000000"));
2562 0 : break;
2563 : case 2: /* 굵은실선 */
2564 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.035cm solid #000000"));
2565 0 : break;
2566 : case 4: /* 2중선 */
2567 0 : padd(ascii("style:border-line-width-left"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2568 0 : padd(ascii("fo:border-left"), sXML_CDATA,ascii("0.039cm double #000000"));
2569 0 : break;
2570 : }
2571 0 : switch( cell->linetype[1] )
2572 : {
2573 : case 1: /* 가는실선 */
2574 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2575 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.002cm solid #000000"));
2576 0 : break;
2577 : case 2: /* 굵은실선 */
2578 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.035cm solid #000000"));
2579 0 : break;
2580 : case 4: /* 2중선 */
2581 0 : padd(ascii("style:border-line-width-right"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2582 0 : padd(ascii("fo:border-right"), sXML_CDATA,ascii("0.039cm double #000000"));
2583 0 : break;
2584 : }
2585 0 : switch( cell->linetype[2] )
2586 : {
2587 : case 1: /* 가는실선 */
2588 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2589 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.002cm solid #000000"));
2590 0 : break;
2591 : case 2: /* 굵은실선 */
2592 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.035cm solid #000000"));
2593 0 : break;
2594 : case 4: /* 2중선 */
2595 0 : padd(ascii("style:border-line-width-top"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2596 0 : padd(ascii("fo:border-top"), sXML_CDATA,ascii("0.039cm double #000000"));
2597 0 : break;
2598 : }
2599 0 : switch( cell->linetype[3] )
2600 : {
2601 : case 1: /* 가는실선 */
2602 : case 3: /* 점선 -> 스타오피스에는 점선이 없다. */
2603 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.002cm solid #000000"));
2604 0 : break;
2605 : case 2: /* 굵은실선 */
2606 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.035cm solid #000000"));
2607 0 : break;
2608 : case 4: /* 2중선 */
2609 0 : padd(ascii("style:border-line-width-bottom"), sXML_CDATA,ascii("0.002cm 0.035cm 0.002cm"));
2610 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #000000"));
2611 0 : break;
2612 : }
2613 : }
2614 :
2615 0 : if( cell->linetype[0] == 0 && cell->linetype[1] == 0 &&
2616 0 : cell->linetype[2] == 0 && cell->linetype[3] == 0 ){
2617 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2618 : }
2619 : else{
2620 0 : padd(ascii("fo:padding-left"), sXML_CDATA,
2621 0 : Double2Str(WTMM(fstyle->margin[1][0])) + ascii("mm"));
2622 0 : padd(ascii("fo:padding-right"), sXML_CDATA,
2623 0 : Double2Str(WTMM(fstyle->margin[1][1])) + ascii("mm"));
2624 0 : padd(ascii("fo:padding-top"), sXML_CDATA,
2625 0 : Double2Str(WTMM(fstyle->margin[1][2])) + ascii("mm"));
2626 0 : padd(ascii("fo:padding-bottom"), sXML_CDATA,
2627 0 : Double2Str(WTMM(fstyle->margin[1][3])) + ascii("mm"));
2628 : }
2629 0 : if(cell->shade != 0)
2630 0 : padd(ascii("fo:background-color"), sXML_CDATA,
2631 : ascii(hcolor2str(
2632 : sal::static_int_cast<uchar>(cell->color),
2633 : sal::static_int_cast<uchar>(cell->shade),
2634 0 : buf)));
2635 : }
2636 0 : else if( fstyle->boxtype == 'E' )
2637 : {
2638 0 : padd(ascii("fo:padding"), sXML_CDATA,ascii("0mm"));
2639 : }
2640 0 : else if( fstyle->boxtype == 'L' )
2641 : {
2642 0 : padd( ascii("style:border-line-width-bottom"), sXML_CDATA, ascii("0.02mm 0.35mm 0.02mm"));
2643 0 : padd(ascii("fo:border-bottom"), sXML_CDATA,ascii("0.039cm double #808080"));
2644 : }
2645 0 : else if( fstyle->boxtype == 'G' )
2646 : {
2647 0 : if( fstyle->margin[1][0] || fstyle->margin[1][1] || fstyle->margin[1][2] || fstyle->margin[1][3] ){
2648 0 : OUString clip = ascii("rect(");
2649 0 : clip += Double2Str(WTMM(-fstyle->margin[1][0]) ) + ascii("mm ");
2650 0 : clip += Double2Str(WTMM(-fstyle->margin[1][1]) ) + ascii("mm ");
2651 0 : clip += Double2Str(WTMM(-fstyle->margin[1][2]) ) + ascii("mm ");
2652 0 : clip += Double2Str(WTMM(-fstyle->margin[1][3]) ) + ascii("mm)");
2653 0 : padd(ascii("style:mirror"), sXML_CDATA, ascii("none"));
2654 0 : padd(ascii("fo:clip"), sXML_CDATA, clip);
2655 : }
2656 0 : char *cell = (char *)fstyle->cell;
2657 0 : padd(ascii("draw:luminance"), sXML_CDATA,
2658 0 : ascii(Int2Str(cell[0], "%d%%", buf)));
2659 0 : padd(ascii("draw:contrast"), sXML_CDATA,
2660 0 : ascii(Int2Str(cell[1], "%d%%", buf)));
2661 0 : if( cell[2] == 0 )
2662 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("standard"));
2663 0 : else if( cell[2] == 1 )
2664 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("greyscale"));
2665 0 : else if( cell[2] == 2 )
2666 0 : padd(ascii("draw:color-mode"), sXML_CDATA, ascii("mono"));
2667 :
2668 : }
2669 0 : rstartEl(ascii("style:properties"), rList);
2670 0 : pList->clear();
2671 0 : rendEl(ascii("style:properties"));
2672 0 : rendEl(ascii("style:style"));
2673 : }
2674 :
2675 :
2676 4 : char *HwpReader::getTStyleName(int index, char *_buf)
2677 : {
2678 4 : return Int2Str(index, "T%d", _buf);
2679 : }
2680 :
2681 :
2682 4 : char *HwpReader::getPStyleName(int index, char *_buf)
2683 : {
2684 4 : return Int2Str(index, "P%d", _buf);
2685 : }
2686 :
2687 :
2688 4 : void HwpReader::makeChars(hchar_string & rStr)
2689 : {
2690 4 : rchars(OUString(rStr.c_str()));
2691 4 : rStr.clear();
2692 4 : }
2693 :
2694 :
2695 : /**
2696 : * 문단내에 특수문자가 없고 모든 문자가 동일한 CharShape를 사용하는 경우
2697 : */
2698 0 : void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
2699 : {
2700 0 : hchar_string str;
2701 : int n;
2702 : int res;
2703 : hchar dest[3];
2704 0 : unsigned char firstspace = 0;
2705 0 : if( !bParaStart)
2706 : {
2707 0 : padd(ascii("text:style-name"), sXML_CDATA,
2708 0 : ascii(getPStyleName(para->GetParaShape()->index, buf)));
2709 0 : rstartEl(ascii("text:p"), rList);
2710 0 : pList->clear();
2711 : }
2712 0 : if( d->bFirstPara && d->bInBody )
2713 : {
2714 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2715 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2716 0 : rstartEl(ascii("text:bookmark"), rList);
2717 0 : pList->clear();
2718 0 : rendEl(ascii("text:bookmark"));
2719 0 : d->bFirstPara = false;
2720 : }
2721 0 : if( d->bInHeader )
2722 : {
2723 0 : makeShowPageNum();
2724 0 : d->bInHeader = false;
2725 : }
2726 0 : padd(ascii("text:style-name"), sXML_CDATA,
2727 0 : ascii(getTStyleName(para->cshape.index, buf)));
2728 0 : rstartEl(ascii("text:span"), rList);
2729 0 : pList->clear();
2730 :
2731 0 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2732 0 : n += para->hhstr[n]->WSize())
2733 : {
2734 0 : if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
2735 : {
2736 0 : makeChars(str);
2737 0 : rstartEl(ascii("text:s"), rList);
2738 0 : rendEl(ascii("text:s"));
2739 : }
2740 0 : else if (para->hhstr[n]->hh == CH_END_PARA)
2741 : {
2742 0 : makeChars(str);
2743 0 : rendEl(ascii("text:span"));
2744 0 : rendEl(ascii("text:p"));
2745 0 : break;
2746 : }
2747 : else
2748 : {
2749 0 : if (para->hhstr[n]->hh == CH_SPACE)
2750 0 : firstspace = 0;
2751 : else
2752 0 : firstspace = 1;
2753 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2754 0 : for( int j = 0 ; j < res; j++ )
2755 : {
2756 0 : str.push_back(dest[j]);
2757 : }
2758 : }
2759 0 : }
2760 0 : }
2761 :
2762 :
2763 : /**
2764 : * 문단내에 특수문자가 없으나 문자들이 다른 CharShape를 사용하는 경우
2765 : */
2766 4 : void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
2767 : {
2768 4 : hchar_string str;
2769 : int n;
2770 : int res;
2771 : hchar dest[3];
2772 4 : int curr = para->cshape.index;
2773 4 : unsigned char firstspace = 0;
2774 :
2775 4 : if( !bParaStart )
2776 : {
2777 8 : padd(ascii("text:style-name"), sXML_CDATA,
2778 4 : ascii(getPStyleName(para->GetParaShape()->index, buf)));
2779 4 : rstartEl(ascii("text:p"), rList);
2780 4 : pList->clear();
2781 : }
2782 4 : if( d->bFirstPara && d->bInBody )
2783 : {
2784 : /* for HWP's Bookmark */
2785 2 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2786 2 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2787 2 : rstartEl(ascii("text:bookmark"), rList);
2788 2 : pList->clear();
2789 2 : rendEl(ascii("text:bookmark"));
2790 2 : d->bFirstPara = false;
2791 : }
2792 4 : if( d->bInHeader )
2793 : {
2794 0 : makeShowPageNum();
2795 0 : d->bInHeader = false;
2796 : }
2797 8 : padd(ascii("text:style-name"), sXML_CDATA,
2798 4 : ascii(getTStyleName(curr, buf)));
2799 4 : rstartEl(ascii("text:span"), rList);
2800 4 : pList->clear();
2801 :
2802 70 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2803 66 : n += para->hhstr[n]->WSize())
2804 : {
2805 70 : if (para->GetCharShape(n)->index != curr)
2806 : {
2807 0 : makeChars(str);
2808 0 : rendEl(ascii("text:span"));
2809 0 : curr = para->GetCharShape(n)->index;
2810 0 : padd(ascii("text:style-name"), sXML_CDATA,
2811 0 : ascii(getTStyleName(curr, buf)));
2812 0 : rstartEl(ascii("text:span"), rList);
2813 0 : pList->clear();
2814 : }
2815 70 : if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
2816 : {
2817 0 : makeChars(str);
2818 0 : rstartEl(ascii("text:s"), rList);
2819 0 : rendEl(ascii("text:s"));
2820 : }
2821 70 : else if (para->hhstr[n]->hh == CH_END_PARA)
2822 : {
2823 4 : makeChars(str);
2824 4 : rendEl(ascii("text:span"));
2825 4 : rendEl(ascii("text:p"));
2826 4 : break;
2827 : }
2828 : else
2829 : {
2830 66 : if( para->hhstr[n]->hh < CH_SPACE )
2831 0 : continue;
2832 66 : if (para->hhstr[n]->hh == CH_SPACE)
2833 4 : firstspace = 0;
2834 : else
2835 62 : firstspace = 1;
2836 66 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2837 132 : for( int j = 0 ; j < res; j++ )
2838 : {
2839 66 : str.push_back(dest[j]);
2840 : }
2841 : }
2842 4 : }
2843 4 : }
2844 :
2845 :
2846 : /**
2847 : * 문단 내의 특수문자가 있으며 문자들이 다른 CharShape를 갖는 경우에 대해 처리
2848 : */
2849 0 : void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
2850 : {
2851 0 : hchar_string str;
2852 : int n, res;
2853 : hchar dest[3];
2854 0 : unsigned char firstspace = 0;
2855 0 : bool pstart = bParaStart;
2856 0 : bool tstart = false;
2857 0 : bool infield = false;
2858 0 : int curr = para->cshape.index;
2859 0 : if( d->bFirstPara && d->bInBody )
2860 : {
2861 0 : if( !pstart )
2862 0 : STARTP;
2863 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
2864 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
2865 0 : rstartEl(ascii("text:bookmark"), rList);
2866 0 : pList->clear();
2867 0 : rendEl(ascii("text:bookmark"));
2868 0 : d->bFirstPara = false;
2869 : }
2870 0 : if( d->bInHeader )
2871 : {
2872 0 : if( !pstart )
2873 0 : STARTP;
2874 0 : makeShowPageNum();
2875 0 : d->bInHeader = false;
2876 : }
2877 :
2878 0 : for (n = 0; n < para->nch && para->hhstr[n]->hh;
2879 0 : n += para->hhstr[n]->WSize())
2880 : {
2881 0 : if( para->hhstr[n]->hh == CH_END_PARA )
2882 : {
2883 0 : if (str.size() > 0)
2884 : {
2885 0 : if( !pstart ){ STARTP;}
2886 0 : if( !tstart ){ STARTT;}
2887 0 : makeChars(str);
2888 : }
2889 0 : if( tstart ){ ENDT;}
2890 0 : if( !pstart ){ STARTP;}
2891 0 : if( pstart ){ ENDP;}
2892 0 : break;
2893 : }
2894 0 : else if( para->hhstr[n]->hh == CH_SPACE && !firstspace)
2895 : {
2896 0 : if( !pstart ) {STARTP;}
2897 0 : if( !tstart ) {STARTT;}
2898 0 : makeChars(str);
2899 0 : rstartEl(ascii("text:s"), rList);
2900 0 : pList->clear();
2901 0 : rendEl(ascii("text:s"));
2902 : }
2903 0 : else if ( para->hhstr[n]->hh >= CH_SPACE )
2904 : {
2905 0 : if( n > 0 )
2906 0 : if( para->GetCharShape(n)->index != para->GetCharShape(n-1)->index && !infield )
2907 : {
2908 0 : if( !pstart ) {STARTP;}
2909 0 : if( !tstart ) {STARTT;}
2910 0 : makeChars(str);
2911 0 : ENDT;
2912 : }
2913 0 : if( para->hhstr[n]->hh == CH_SPACE )
2914 0 : firstspace = 0;
2915 : else
2916 0 : firstspace = 1;
2917 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
2918 0 : for( int j = 0 ; j < res; j++ )
2919 : {
2920 0 : str.push_back(dest[j]);
2921 : }
2922 : }
2923 0 : else if (para->hhstr[n]->hh == CH_FIELD)
2924 : {
2925 0 : FieldCode *hbox = (FieldCode *) para->hhstr[n];
2926 0 : if( hbox->location_info == 1)
2927 : {
2928 0 : if( !pstart ) {STARTP;}
2929 0 : if( !tstart ) {STARTT;}
2930 0 : makeChars(str);
2931 0 : firstspace = 1;
2932 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
2933 : {
2934 0 : field = hbox->str3;
2935 : }
2936 : else{
2937 0 : makeFieldCode(str, hbox);
2938 : }
2939 0 : infield = true;
2940 : }
2941 : else
2942 : {
2943 0 : firstspace = 1;
2944 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
2945 : {
2946 0 : makeFieldCode(str, hbox);
2947 0 : field = 0L;
2948 : }
2949 0 : infield = false;
2950 0 : str.clear();
2951 : }
2952 : }
2953 : else
2954 : {
2955 0 : switch (para->hhstr[n]->hh)
2956 : {
2957 : case CH_BOOKMARK:
2958 0 : if( !pstart ) {STARTP;}
2959 0 : if( !tstart ) {STARTT;}
2960 0 : makeChars(str);
2961 0 : makeBookmark((Bookmark *) para->hhstr[n]);
2962 0 : break;
2963 : case CH_DATE_FORM: // 7
2964 0 : break;
2965 : case CH_DATE_CODE: // 8
2966 0 : if( !pstart ) {STARTP;}
2967 0 : if( !tstart ) {STARTT;}
2968 0 : makeChars(str);
2969 0 : makeDateCode((DateCode *) para->hhstr[n]);
2970 0 : break;
2971 : case CH_TAB: // 9
2972 0 : if( !pstart ) {STARTP;}
2973 0 : if (str.size() > 0)
2974 : {
2975 0 : if( !tstart ) {STARTT;}
2976 0 : makeChars(str);
2977 : }
2978 0 : makeTab((Tab *) para->hhstr[n]);
2979 0 : break;
2980 : case CH_TEXT_BOX: /* 10 - 표/텍스트박스/수식/버튼/하이퍼텍스트 순 */
2981 : {
2982 : /* 일단은 표만 처리하고, 수식은 text:p안에 들어가는 것으로 처리. */
2983 0 : TxtBox *hbox = (TxtBox *) para->hhstr[n];
2984 :
2985 0 : if( hbox->style.anchor_type == 0 )
2986 : {
2987 0 : if( !pstart ) {STARTP;}
2988 0 : if( !tstart ) {STARTT;}
2989 0 : makeChars(str);
2990 : }
2991 : else
2992 : {
2993 0 : if( !pstart ) {STARTP;}
2994 0 : if (str.size() > 0)
2995 : {
2996 0 : if( !tstart ) {STARTT;}
2997 0 : makeChars(str);
2998 : }
2999 0 : if( tstart ) {ENDT;}
3000 : }
3001 0 : switch (hbox->type)
3002 : {
3003 : case TBL_TYPE: // table
3004 : case TXT_TYPE: // text box
3005 : case EQU_TYPE: // formula
3006 0 : makeTextBox(hbox);
3007 0 : break;
3008 : case BUTTON_TYPE: // text button
3009 : case HYPERTEXT_TYPE: // hypertext
3010 0 : makeHyperText(hbox);
3011 0 : break;
3012 : }
3013 0 : break;
3014 : }
3015 : case CH_PICTURE: // 11
3016 : {
3017 0 : Picture *hbox = (Picture *) para->hhstr[n];
3018 0 : if( hbox->style.anchor_type == 0 )
3019 : {
3020 0 : if( !pstart ) {STARTP;}
3021 0 : if( !tstart ) {STARTT;}
3022 0 : makeChars(str);
3023 : }
3024 : else
3025 : {
3026 0 : if( !pstart ) {STARTP;}
3027 0 : if (str.size() > 0)
3028 : {
3029 0 : if( !tstart ) {STARTT;}
3030 0 : makeChars(str);
3031 : }
3032 0 : if( tstart ) {ENDT;}
3033 : }
3034 0 : makePicture(hbox);
3035 0 : break;
3036 : }
3037 : case CH_LINE: // 14
3038 : {
3039 0 : Line *hbox = (Line *) para->hhstr[n];
3040 0 : if (str.size() > 0)
3041 : {
3042 0 : if( !pstart ) {STARTP;}
3043 0 : if( !tstart ) {STARTT;}
3044 0 : makeChars(str);
3045 : }
3046 0 : if( tstart ) {ENDT;}
3047 0 : if( pstart ) {ENDP;}
3048 0 : makeLine(hbox);
3049 0 : pstart = true;
3050 0 : break;
3051 : }
3052 : case CH_HIDDEN: // 15
3053 0 : if( !pstart ) {STARTP;}
3054 0 : if( !tstart ) {STARTT;}
3055 0 : makeChars(str);
3056 0 : makeHidden((Hidden *) para->hhstr[n]);
3057 0 : break;
3058 : case CH_FOOTNOTE: // 17
3059 0 : if( !pstart ) {STARTP;}
3060 0 : if( !tstart ) {STARTT;}
3061 0 : makeChars(str);
3062 0 : makeFootnote((Footnote *) para->hhstr[n]);
3063 0 : break;
3064 : case CH_AUTO_NUM: // 18
3065 0 : if( !pstart ) {STARTP;}
3066 0 : if( !tstart ) {STARTT;}
3067 0 : makeChars(str);
3068 0 : makeAutoNum((AutoNum *) para->hhstr[n]);
3069 0 : break;
3070 : case CH_NEW_NUM: // 19 -skip
3071 0 : break;
3072 : case CH_PAGE_NUM_CTRL: // 21
3073 0 : break;
3074 : case CH_MAIL_MERGE: // 22
3075 0 : if( !pstart ) {STARTP;}
3076 0 : if( !tstart ) {STARTT;}
3077 0 : makeChars(str);
3078 0 : makeMailMerge((MailMerge *) para->hhstr[n]);
3079 0 : break;
3080 : case CH_COMPOSE: /* 23 - 글자겹침 */
3081 0 : break;
3082 : case CH_HYPHEN: // 24
3083 0 : break;
3084 : case CH_TOC_MARK: /* 25 아래의 3개는 작업해야 한다. */
3085 0 : if( !pstart ) {STARTP;}
3086 0 : if( !tstart ) {STARTT;}
3087 0 : makeChars(str);
3088 0 : makeTocMark((TocMark *) para->hhstr[n]);
3089 0 : break;
3090 : case CH_INDEX_MARK: // 26
3091 0 : if( !pstart ) {STARTP;}
3092 0 : if( !tstart ) {STARTT;}
3093 0 : makeChars(str);
3094 0 : makeIndexMark((IndexMark *) para->hhstr[n]);
3095 0 : break;
3096 : case CH_OUTLINE: // 28
3097 0 : if( !pstart ) {STARTP;}
3098 0 : if( !tstart ) {STARTT;}
3099 0 : makeChars(str);
3100 0 : makeOutline((Outline *) para->hhstr[n]);
3101 0 : break;
3102 : case CH_FIXED_SPACE:
3103 : case CH_KEEP_SPACE:
3104 0 : str.push_back(0x0020);
3105 0 : break;
3106 : }
3107 : }
3108 0 : }
3109 0 : }
3110 :
3111 :
3112 0 : void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
3113 : {
3114 : /* 누름틀 */
3115 0 : if( hbox->type[0] == 4 && hbox->type[1] == 0 )
3116 : {
3117 0 : padd(ascii("text:placeholder-type"), sXML_CDATA, ascii("text"));
3118 0 : if( field )
3119 0 : padd(ascii("text:description"), sXML_CDATA, hconv(field));
3120 0 : rstartEl( ascii("text:placeholder"), rList);
3121 0 : pList->clear();
3122 0 : rchars( OUString(rStr.c_str()));
3123 0 : rendEl( ascii("text:placeholder") );
3124 : }
3125 : /* 문서요약 */
3126 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
3127 : {
3128 0 : if (hconv(hbox->str3) == "title")
3129 : {
3130 0 : rstartEl( ascii("text:title"), rList );
3131 0 : rchars( hconv(hbox->str2) );
3132 0 : rendEl( ascii("text:title") );
3133 : }
3134 0 : else if (hconv(hbox->str3) == "subject")
3135 : {
3136 0 : rstartEl( ascii("text:subject"), rList );
3137 0 : rchars( hconv(hbox->str2) );
3138 0 : rendEl( ascii("text:subject") );
3139 : }
3140 0 : else if (hconv(hbox->str3) == "author")
3141 : {
3142 0 : rstartEl( ascii("text:author-name"), rList );
3143 0 : rchars( hconv(hbox->str2) );
3144 0 : rendEl( ascii("text:author-name") );
3145 : }
3146 0 : else if (hconv(hbox->str3) == "keywords")
3147 : {
3148 0 : rstartEl( ascii("text:keywords"), rList );
3149 0 : rchars( hconv(hbox->str2) );
3150 0 : rendEl( ascii("text:keywords") );
3151 : }
3152 : }
3153 : /* 개인정보 */
3154 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
3155 : {
3156 0 : if (hconv(hbox->str3) == "User")
3157 : {
3158 0 : rstartEl( ascii("text:sender-lastname"), rList );
3159 0 : rchars( hconv(hbox->str2) );
3160 0 : rendEl( ascii("text:sender-lastname") );
3161 : }
3162 0 : else if (hconv(hbox->str3) == "Company")
3163 : {
3164 0 : rstartEl( ascii("text:sender-company"), rList );
3165 0 : rchars( hconv(hbox->str2) );
3166 0 : rendEl( ascii("text:sender-company") );
3167 : }
3168 0 : else if (hconv(hbox->str3) == "Position")
3169 : {
3170 0 : rstartEl( ascii("text:sender-title"), rList );
3171 0 : rchars( hconv(hbox->str2) );
3172 0 : rendEl( ascii("text:sender-title") );
3173 : }
3174 0 : else if (hconv(hbox->str3) == "Division")
3175 : {
3176 0 : rstartEl( ascii("text:sender-position"), rList );
3177 0 : rchars( hconv(hbox->str2) );
3178 0 : rendEl( ascii("text:sender-position") );
3179 : }
3180 0 : else if (hconv(hbox->str3) == "Fax")
3181 : {
3182 0 : rstartEl( ascii("text:sender-fax"), rList );
3183 0 : rchars( hconv(hbox->str2) );
3184 0 : rendEl( ascii("text:sender-fax") );
3185 : }
3186 0 : else if (hconv(hbox->str3) == "Pager")
3187 : {
3188 0 : rstartEl( ascii("text:phone-private"), rList );
3189 0 : rchars( hconv(hbox->str2) );
3190 0 : rendEl( ascii("text:phone-private") );
3191 : }
3192 0 : else if (hconv(hbox->str3) == "E-mail")
3193 : {
3194 0 : rstartEl( ascii("text:sender-email"), rList );
3195 0 : rchars( hconv(hbox->str2) );
3196 0 : rendEl( ascii("text:sender-email") );
3197 : }
3198 0 : else if (hconv(hbox->str3) == "Zipcode(office)")
3199 : {
3200 0 : rstartEl( ascii("text:sender-postal-code"), rList );
3201 0 : rchars( hconv(hbox->str2) );
3202 0 : rendEl( ascii("text:sender-postal-code") );
3203 : }
3204 0 : else if (hconv(hbox->str3) == "Phone(office)")
3205 : {
3206 0 : rstartEl( ascii("text:sender-phone-work"), rList );
3207 0 : rchars( hconv(hbox->str2) );
3208 0 : rendEl( ascii("text:sender-phone-work") );
3209 : }
3210 0 : else if (hconv(hbox->str3) == "Address(office)")
3211 : {
3212 0 : rstartEl( ascii("text:sender-street"), rList );
3213 0 : rchars( hconv(hbox->str2) );
3214 0 : rendEl( ascii("text:sender-street") );
3215 : }
3216 :
3217 : }
3218 0 : else if( hbox->type[0] == 3 && hbox->type[1] == 2 ) /* 만든날짜 */
3219 : {
3220 0 : if( hbox->m_pDate )
3221 0 : padd(ascii("style:data-style-name"), sXML_CDATA,
3222 0 : ascii(Int2Str(hbox->m_pDate->key, "N%d", buf)));
3223 0 : rstartEl( ascii("text:creation-date"), rList );
3224 0 : pList->clear();
3225 0 : rchars( hconv(hbox->str2) );
3226 0 : rendEl( ascii("text:creation-date") );
3227 : }
3228 0 : }
3229 :
3230 :
3231 : /**
3232 : * Completed
3233 : * 스타오피스에서는 북마크를 Reference로 참조하나 hwp에는 그 기능이 없다.
3234 : */
3235 0 : void HwpReader::makeBookmark(Bookmark * hbox)
3236 : {
3237 0 : if (hbox->type == 0)
3238 : {
3239 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3240 0 : rstartEl(ascii("text:bookmark"), rList);
3241 0 : pList->clear();
3242 0 : rendEl(ascii("text:bookmark"));
3243 : }
3244 0 : else if (hbox->type == 1) /* 블록 북마크일 경우 시작과 끝이 있다 */
3245 : {
3246 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3247 0 : rstartEl(ascii("text:bookmark-start"), rList);
3248 0 : pList->clear();
3249 0 : rendEl(ascii("text:bookmark-start"));
3250 : }
3251 0 : else if (hbox->type == 2)
3252 : {
3253 0 : padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
3254 0 : rstartEl(ascii("text:bookmark-end"), rList);
3255 0 : pList->clear();
3256 0 : rendEl(ascii("text:bookmark-end"));
3257 : }
3258 0 : }
3259 :
3260 :
3261 : #include "datecode.h"
3262 :
3263 0 : void HwpReader::makeDateFormat(DateCode * hbox)
3264 : {
3265 0 : padd(ascii("style:name"), sXML_CDATA,
3266 0 : ascii(Int2Str(hbox->key, "N%d", buf)));
3267 0 : padd(ascii("style:family"), sXML_CDATA,ascii("data-style"));
3268 0 : padd(ascii("number:language"), sXML_CDATA,ascii("ko"));
3269 0 : padd(ascii("number:country"), sXML_CDATA,ascii("KR"));
3270 :
3271 0 : rstartEl(ascii("number:date-style"), rList);
3272 0 : pList->clear();
3273 :
3274 0 : bool add_zero = false;
3275 0 : int zero_check = 0;
3276 0 : hbox->format[DATE_SIZE -1] = 0;
3277 :
3278 0 : const hchar *fmt = hbox->format[0] ? hbox->format : defaultform;
3279 :
3280 0 : for( ; *fmt ; fmt++ )
3281 : {
3282 0 : if( zero_check == 1 )
3283 : {
3284 0 : zero_check = 0;
3285 : }
3286 : else
3287 0 : add_zero = false;
3288 :
3289 0 : switch( *fmt )
3290 : {
3291 : case '0':
3292 0 : zero_check = 1;
3293 0 : add_zero = true;
3294 : break;
3295 : case '1':
3296 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3297 0 : rstartEl(ascii("number:year"), rList);
3298 0 : pList->clear();
3299 0 : rendEl(ascii("number:year"));
3300 : break;
3301 : case '!':
3302 0 : rstartEl(ascii("number:year"), rList);
3303 0 : pList->clear();
3304 0 : rendEl(ascii("number:year"));
3305 : break;
3306 : case '2':
3307 0 : if( add_zero )
3308 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3309 0 : rstartEl(ascii("number:month"), rList);
3310 0 : pList->clear();
3311 0 : rendEl(ascii("number:month"));
3312 : break;
3313 : case '@':
3314 0 : padd(ascii("number:textual"), sXML_CDATA, ascii("true"));
3315 0 : rstartEl(ascii("number:month"), rList);
3316 0 : pList->clear();
3317 0 : rendEl(ascii("number:month"));
3318 : break;
3319 : case '*':
3320 0 : padd(ascii("number:textual"), sXML_CDATA, ascii("true"));
3321 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3322 0 : rstartEl(ascii("number:month"), rList);
3323 0 : pList->clear();
3324 0 : rendEl(ascii("number:month"));
3325 : break;
3326 : case '3':
3327 0 : if( add_zero )
3328 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3329 0 : rstartEl(ascii("number:day"), rList);
3330 0 : pList->clear();
3331 0 : rendEl(ascii("number:day"));
3332 : break;
3333 : case '#':
3334 0 : if( add_zero )
3335 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3336 0 : rstartEl(ascii("number:day"), rList);
3337 0 : pList->clear();
3338 0 : rendEl(ascii("number:day"));
3339 0 : switch( hbox->date[DateCode::DAY] % 10)
3340 : {
3341 : case 1:
3342 0 : rstartEl(ascii("number:text"), rList);
3343 0 : rchars(ascii("st"));
3344 0 : rendEl(ascii("number:text"));
3345 0 : break;
3346 : case 2:
3347 0 : rstartEl(ascii("number:text"), rList);
3348 0 : rchars(ascii("nd"));
3349 0 : rendEl(ascii("number:text"));
3350 0 : break;
3351 : case 3:
3352 0 : rstartEl(ascii("number:text"), rList);
3353 0 : rchars(ascii("rd"));
3354 0 : rendEl(ascii("number:text"));
3355 0 : break;
3356 : default:
3357 0 : rstartEl(ascii("number:text"), rList);
3358 0 : rchars(ascii("th"));
3359 0 : rendEl(ascii("number:text"));
3360 0 : break;
3361 : }
3362 : break;
3363 : case '4':
3364 : case '$':
3365 0 : if( add_zero )
3366 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3367 0 : rstartEl(ascii("number:hours"), rList);
3368 0 : pList->clear();
3369 0 : rendEl(ascii("number:hours"));
3370 : break;
3371 : case '5':
3372 : case '%':
3373 0 : if( add_zero )
3374 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3375 0 : rstartEl(ascii("number:minutes"), rList);
3376 0 : pList->clear();
3377 0 : rendEl(ascii("number:minutes"));
3378 : break;
3379 : case '_':
3380 0 : padd(ascii("number:style"), sXML_CDATA, ascii("long"));
3381 : case '6':
3382 : case '^':
3383 0 : rstartEl(ascii("number:day-of-week"), rList);
3384 0 : pList->clear();
3385 0 : rendEl(ascii("number:day-of-week"));
3386 : break;
3387 : case '7':
3388 : case '&':
3389 : case '+':
3390 0 : rstartEl(ascii("number:am-pm"), rList);
3391 0 : pList->clear();
3392 0 : rendEl(ascii("number:am-pm"));
3393 : break;
3394 : case '~': // Chinese Locale
3395 : break;
3396 : default:
3397 : hchar sbuf[2];
3398 0 : sbuf[0] = *fmt;
3399 0 : sbuf[1] = 0;
3400 0 : rstartEl(ascii("number:text"), rList);
3401 0 : rchars((hconv(sbuf)));
3402 0 : rendEl(ascii("number:text"));
3403 : break;
3404 : }
3405 : }
3406 0 : pList->clear();
3407 0 : rendEl(ascii("number:date-style"));
3408 0 : }
3409 :
3410 :
3411 0 : void HwpReader::makeDateCode(DateCode * hbox)
3412 : {
3413 0 : padd(ascii("style:data-style-name"), sXML_CDATA,
3414 0 : ascii(Int2Str(hbox->key, "N%d", buf)));
3415 0 : rstartEl( ascii("text:date"), rList );
3416 0 : pList->clear();
3417 0 : hchar_string const boxstr = hbox->GetString();
3418 0 : rchars((hconv(boxstr.c_str())));
3419 0 : rendEl( ascii("text:date") );
3420 0 : }
3421 :
3422 :
3423 0 : void HwpReader::makeTab(Tab * ) /*hbox */
3424 : {
3425 0 : rstartEl(ascii("text:tab-stop"), rList);
3426 0 : rendEl(ascii("text:tab-stop"));
3427 0 : }
3428 :
3429 :
3430 0 : void HwpReader::makeTable(TxtBox * hbox)
3431 : {
3432 0 : padd(ascii("table:name"), sXML_CDATA,
3433 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
3434 0 : padd(ascii("table:style-name"), sXML_CDATA,
3435 0 : ascii(Int2Str(hbox->style.boxnum, "Table%d", buf)));
3436 0 : rstartEl(ascii("table:table"), rList);
3437 0 : pList->clear();
3438 :
3439 0 : Table *tbl = hbox->m_pTable;
3440 : // ----------- column ---------------- //
3441 0 : for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
3442 : {
3443 0 : sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
3444 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3445 0 : rstartEl(ascii("table:table-column"), rList);
3446 0 : pList->clear();
3447 0 : rendEl(ascii("table:table-column"));
3448 : }
3449 :
3450 : // ----------- cell ---------------- //
3451 0 : int j = -1, k = -1;
3452 0 : for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
3453 : {
3454 0 : std::list<TCell*>::iterator it = tbl->cells.begin();
3455 :
3456 0 : for( int ii = 0; it != tbl->cells.end(); ++it, ii++ ){
3457 0 : if( ii == i )
3458 0 : break;
3459 : }
3460 :
3461 0 : TCell *tcell = *it;
3462 0 : if( tcell->nRowIndex > j )
3463 : {
3464 0 : if( j > k )
3465 : {
3466 0 : rendEl(ascii("table:table-row"));
3467 0 : k = j;
3468 : }
3469 : // --------------- row ---------------- //
3470 0 : sprintf(buf,"Table%d.row%d",hbox->style.boxnum, tcell->nRowIndex + 1);
3471 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3472 0 : rstartEl(ascii("table:table-row"), rList);
3473 0 : pList->clear();
3474 0 : j = tcell->nRowIndex;
3475 : }
3476 :
3477 0 : sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
3478 0 : padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
3479 0 : if( tcell->nColumnSpan > 1 )
3480 0 : padd(ascii("table:number-columns-spanned"), sXML_CDATA,
3481 0 : ascii(Int2Str(tcell->nColumnSpan, "%d", buf)));
3482 0 : if( tcell->nRowSpan > 1 )
3483 0 : padd(ascii("table:number-rows-spanned"), sXML_CDATA,
3484 0 : ascii(Int2Str(tcell->nRowSpan, "%d", buf)));
3485 0 : padd(ascii("table:value-type"), sXML_CDATA,ascii("string"));
3486 0 : if( tcell->pCell->protect )
3487 0 : padd(ascii("table:protected"), sXML_CDATA,ascii("true"));
3488 0 : rstartEl(ascii("table:table-cell"), rList);
3489 0 : pList->clear();
3490 0 : parsePara(hbox->plists[tcell->pCell->key].front());
3491 0 : rendEl(ascii("table:table-cell"));
3492 : }
3493 0 : rendEl(ascii("table:table-row"));
3494 0 : rendEl(ascii("table:table"));
3495 0 : }
3496 :
3497 :
3498 : /**
3499 : * 텍스트박스와 테이블을 파싱한다.
3500 : * 1. draw:style-name, draw:name, text:anchor-type, svg:width,
3501 : * fo:min-height, svg:x, svg:y
3502 : * TODO : fo:background-color로 셀의 칼라 설정=>스타일에 들어가는 지 아직 모르겠다.
3503 : */
3504 0 : void HwpReader::makeTextBox(TxtBox * hbox)
3505 : {
3506 0 : if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
3507 : {
3508 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3509 0 : ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf)));
3510 0 : padd(ascii("draw:name"), sXML_CDATA,
3511 0 : ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf)));
3512 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3513 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3514 0 : switch (hbox->style.anchor_type)
3515 : {
3516 : case CHAR_ANCHOR:
3517 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3518 0 : break;
3519 : case PARA_ANCHOR:
3520 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3521 0 : break;
3522 : case PAGE_ANCHOR:
3523 : case PAPER_ANCHOR:
3524 : {
3525 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3526 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3527 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3528 0 : break;
3529 : }
3530 : }
3531 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3532 : {
3533 0 : padd(ascii("svg:x"), sXML_CDATA,
3534 0 : Double2Str(WTMM( ( hbox->pgx + hbox->style.margin[0][0] ) )) + ascii("mm"));
3535 0 : padd(ascii("svg:y"), sXML_CDATA,
3536 0 : Double2Str(WTMM( ( hbox->pgy + hbox->style.margin[0][2] ) )) + ascii("mm"));
3537 : }
3538 0 : padd(ascii("svg:width"), sXML_CDATA,
3539 0 : Double2Str(WTMM(( hbox->box_xs + hbox->cap_xs) )) + ascii("mm"));
3540 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3541 0 : Double2Str(WTMM(( hbox->box_ys + hbox->cap_ys) )) + ascii("mm"));
3542 0 : rstartEl(ascii("draw:text-box"), rList);
3543 0 : pList->clear();
3544 0 : if( hbox->cap_pos % 2 ) /* 캡션이 위쪽에 위치한다 */
3545 : {
3546 0 : parsePara(hbox->caption.front());
3547 : }
3548 0 : padd( ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
3549 0 : rstartEl(ascii("text:p"), rList);
3550 0 : pList->clear();
3551 : }
3552 : else{
3553 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3554 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3555 : }
3556 :
3557 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3558 0 : ascii(Int2Str(hbox->style.boxnum, "Txtbox%d", buf)));
3559 0 : padd(ascii("draw:name"), sXML_CDATA,
3560 0 : ascii(Int2Str(hbox->style.boxnum, "Frame%d", buf)));
3561 :
3562 0 : if( hbox->style.cap_len <= 0 || hbox->type != TXT_TYPE )
3563 : {
3564 0 : int x = 0;
3565 0 : int y = 0;
3566 0 : switch (hbox->style.anchor_type)
3567 : {
3568 : case CHAR_ANCHOR:
3569 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3570 0 : break;
3571 : case PARA_ANCHOR:
3572 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3573 0 : break;
3574 : case PAGE_ANCHOR:
3575 : case PAPER_ANCHOR:
3576 : {
3577 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3578 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3579 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3580 0 : break;
3581 : }
3582 : }
3583 0 : if( hbox->style.anchor_type != CHAR_ANCHOR )
3584 : {
3585 0 : x += hbox->style.margin[0][0];
3586 0 : y += hbox->style.margin[0][2];
3587 : }
3588 0 : padd(ascii("svg:x"), sXML_CDATA,
3589 0 : Double2Str(WTMM( hbox->pgx + x )) + ascii("mm"));
3590 0 : padd(ascii("svg:y"), sXML_CDATA,
3591 0 : Double2Str(WTMM( hbox->pgy + y )) + ascii("mm"));
3592 : }
3593 : else
3594 : {
3595 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3596 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
3597 : }
3598 0 : padd(ascii("svg:width"), sXML_CDATA,
3599 0 : Double2Str(WTMM( hbox->box_xs )) + ascii("mm"));
3600 0 : if( hbox->style.cap_len > 0 && hbox->type != TXT_TYPE)
3601 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3602 0 : Double2Str(WTMM( hbox->box_ys + hbox->cap_ys)) + ascii("mm"));
3603 : else
3604 0 : padd(ascii("svg:height"), sXML_CDATA,
3605 0 : Double2Str(WTMM(hbox->box_ys )) + ascii("mm"));
3606 :
3607 0 : if( hbox->type != EQU_TYPE )
3608 : {
3609 0 : rstartEl(ascii("draw:text-box"), rList);
3610 0 : pList->clear();
3611 : /* 캡션이 존재하고, 위쪽에 있으면 */
3612 0 : if( hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE )
3613 : {
3614 0 : parsePara(hbox->caption.front());
3615 : }
3616 0 : if( hbox->type == TBL_TYPE) // Is Table
3617 : {
3618 0 : makeTable(hbox);
3619 : }
3620 : else // Is TextBox
3621 : {
3622 0 : parsePara(hbox->plists[0].front());
3623 : }
3624 : /* 캡션이 존재하고, 아래쪽에 있으면 */
3625 0 : if( hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE)
3626 : {
3627 0 : parsePara(hbox->caption.front());
3628 : }
3629 0 : rendEl(ascii("draw:text-box"));
3630 : // Caption exist and it is text-box
3631 0 : if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
3632 : {
3633 0 : rendEl( ascii("text:p"));
3634 0 : if( !(hbox->cap_pos % 2))
3635 : {
3636 0 : parsePara(hbox->caption.front());
3637 : }
3638 0 : rendEl( ascii("draw:text-box"));
3639 : }
3640 : }
3641 : else // is Formula
3642 : {
3643 0 : rstartEl(ascii("draw:object"), rList);
3644 0 : pList->clear();
3645 0 : makeFormula(hbox);
3646 0 : rendEl(ascii("draw:object"));
3647 : }
3648 0 : }
3649 :
3650 :
3651 : /**
3652 : * MathML로 변환해야 한다.
3653 : *
3654 : */
3655 0 : void HwpReader::makeFormula(TxtBox * hbox)
3656 : {
3657 : char mybuf[3000];
3658 : HWPPara* pPar;
3659 0 : CharShape *cshape = 0;
3660 :
3661 : int n, c, res;
3662 : hchar dest[3];
3663 0 : size_t l = 0;
3664 :
3665 0 : pPar = hbox->plists[0].front();
3666 0 : while( pPar )
3667 : {
3668 0 : for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh;
3669 0 : n += pPar->hhstr[n]->WSize() )
3670 : {
3671 0 : if (!cshape)
3672 0 : cshape = pPar->GetCharShape(n);
3673 0 : if (l >= sizeof(mybuf)-7)
3674 0 : break;
3675 0 : res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
3676 0 : for( int j = 0 ; j < res; j++ ){
3677 0 : c = dest[j];
3678 0 : if( c < 32 )
3679 0 : c = ' ';
3680 0 : if( c < 256 )
3681 0 : mybuf[l++] = sal::static_int_cast<char>(c);
3682 : else
3683 : {
3684 0 : mybuf[l++] = sal::static_int_cast<char>((c >> 8) & 0xff);
3685 0 : mybuf[l++] = sal::static_int_cast<char>(c & 0xff);
3686 : }
3687 : }
3688 : }
3689 0 : if (l >= sizeof(mybuf)-7)
3690 0 : break;
3691 0 : mybuf[l++] = '\n';
3692 0 : pPar = pPar->Next();
3693 : }
3694 0 : mybuf[l] = '\0';
3695 :
3696 0 : Formula *form = new Formula(mybuf);
3697 0 : form->setDocumentHandler(m_rxDocumentHandler);
3698 0 : form->setAttributeListImpl(pList);
3699 0 : form->parse();
3700 :
3701 0 : delete form;
3702 0 : }
3703 :
3704 :
3705 : /**
3706 : * platform정보를 읽어들여서 href가 C:\나 D:\로 시작할 경우 리눅스나 솔라리스이면
3707 : * C:\ => 홈으로, D:\ => 루트(/)로 바꾸어주는 작업이 필요하다. 이것은
3708 : * 한컴이 도스에뮬레이터를 쓰기 때문이다.
3709 : */
3710 0 : void HwpReader::makeHyperText(TxtBox * hbox)
3711 : {
3712 0 : HyperText *hypert = hwpfile.GetHyperText();
3713 0 : if( !hypert ) return;
3714 :
3715 0 : if( strlen((char *)hypert->filename) > 0 ){
3716 0 : ::std::string const tmp = hstr2ksstr(hypert->bookmark);
3717 : ::std::string const tmp2 = hstr2ksstr(kstr2hstr(
3718 : #ifdef _WIN32
3719 : (uchar *) urltowin((char *)hypert->filename).c_str()).c_str());
3720 : #else
3721 0 : (uchar *) urltounix((char *)hypert->filename).c_str()).c_str());
3722 : #endif
3723 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3724 0 : if (tmp.size() > 0 && strcmp(tmp.c_str(), "[HTML]")) {
3725 0 : ::std::string tmp3(tmp2);
3726 0 : tmp3.push_back('#');
3727 0 : tmp3.append(tmp);
3728 0 : padd(ascii("xlink:href"), sXML_CDATA,
3729 0 : OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR));
3730 : }
3731 : else{
3732 0 : padd(ascii("xlink:href"), sXML_CDATA,
3733 0 : OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR));
3734 :
3735 0 : }
3736 : }
3737 : else
3738 : {
3739 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3740 0 : ::std::string tmp;
3741 0 : tmp.push_back('#');
3742 0 : tmp.append(hstr2ksstr(hypert->bookmark));
3743 0 : padd(ascii("xlink:href"), sXML_CDATA,
3744 0 : OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR));
3745 : }
3746 0 : rstartEl(ascii("draw:a"), rList);
3747 0 : pList->clear();
3748 0 : makeTextBox(hbox);
3749 0 : rendEl(ascii("draw:a"));
3750 : }
3751 :
3752 :
3753 : /**
3754 : * platform정보를 읽어들여서 href가 C:\나 D:\로 시작할 경우 리눅스나 솔라리스이면
3755 : * C:\ => 홈으로, D:\ => 루트(/)로 바꾸었다. 이것은
3756 : * 한컴이 도스에뮬레이터를 쓰기 때문이다.
3757 : */
3758 0 : void HwpReader::makePicture(Picture * hbox)
3759 : {
3760 0 : switch (hbox->pictype)
3761 : {
3762 : case PICTYPE_OLE:
3763 : case PICTYPE_EMBED:
3764 : case PICTYPE_FILE:
3765 : {
3766 0 : if( hbox->style.cap_len > 0 )
3767 : {
3768 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3769 0 : ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf)));
3770 0 : padd(ascii("draw:name"), sXML_CDATA,
3771 0 : ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf)));
3772 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3773 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3774 0 : switch (hbox->style.anchor_type)
3775 : {
3776 : case CHAR_ANCHOR:
3777 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3778 0 : break;
3779 : case PARA_ANCHOR:
3780 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3781 0 : break;
3782 : case PAGE_ANCHOR:
3783 : case PAPER_ANCHOR:
3784 : {
3785 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3786 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3787 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3788 0 : break;
3789 : }
3790 : }
3791 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3792 : {
3793 0 : padd(ascii("svg:x"), sXML_CDATA,
3794 0 : Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + ascii("mm"));
3795 0 : padd(ascii("svg:y"), sXML_CDATA,
3796 0 : Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + ascii("mm"));
3797 : }
3798 0 : padd(ascii("svg:width"), sXML_CDATA,
3799 0 : Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1] )) + ascii("mm"));
3800 0 : padd(ascii("fo:min-height"), sXML_CDATA,
3801 0 : Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3] + hbox->cap_ys )) + ascii("mm"));
3802 0 : rstartEl(ascii("draw:text-box"), rList);
3803 0 : pList->clear();
3804 0 : if( hbox->cap_pos % 2 ) /* 캡션이 위쪽에 위치한다 */
3805 : {
3806 0 : parsePara(hbox->caption.front());
3807 : }
3808 0 : padd( ascii("text:style-name"), sXML_CDATA, ascii("Standard"));
3809 0 : rstartEl(ascii("text:p"), rList);
3810 0 : pList->clear();
3811 : }
3812 0 : if( hbox->ishyper )
3813 : {
3814 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3815 : #ifdef _WIN32
3816 : if( hbox->follow[4] != 0 )
3817 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4).c_str())));
3818 : else
3819 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5).c_str())));
3820 : #else
3821 0 : if( hbox->follow[4] != 0 )
3822 0 : padd(ascii("xlink:href"), sXML_CDATA,
3823 0 : (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4)).c_str()).c_str())));
3824 : else
3825 0 : padd(ascii("xlink:href"), sXML_CDATA,
3826 0 : (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5)).c_str()).c_str())));
3827 : #endif
3828 0 : rstartEl(ascii("draw:a"), rList);
3829 0 : pList->clear();
3830 : }
3831 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3832 0 : ascii(Int2Str(hbox->style.boxnum, "G%d", buf)));
3833 0 : padd(ascii("draw:name"), sXML_CDATA,
3834 0 : ascii(Int2Str(hbox->style.boxnum, "Image%d", buf)));
3835 :
3836 0 : if( hbox->style.cap_len <= 0 )
3837 : {
3838 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3839 0 : ascii(Int2Str(hbox->zorder, "%d", buf)));
3840 0 : switch (hbox->style.anchor_type)
3841 : {
3842 : case CHAR_ANCHOR:
3843 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3844 0 : break;
3845 : case PARA_ANCHOR:
3846 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3847 0 : break;
3848 : case PAGE_ANCHOR:
3849 : case PAPER_ANCHOR:
3850 : {
3851 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3852 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3853 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3854 0 : break;
3855 : }
3856 : }
3857 0 : if (hbox->style.anchor_type != CHAR_ANCHOR)
3858 : {
3859 0 : padd(ascii("svg:x"), sXML_CDATA,
3860 0 : Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + ascii("mm"));
3861 0 : padd(ascii("svg:y"), sXML_CDATA,
3862 0 : Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + ascii("mm"));
3863 : }
3864 : }
3865 : else
3866 : {
3867 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3868 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
3869 : }
3870 0 : padd(ascii("svg:width"), sXML_CDATA,
3871 0 : Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1])) + ascii("mm"));
3872 0 : padd(ascii("svg:height"), sXML_CDATA,
3873 0 : Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3])) + ascii("mm"));
3874 :
3875 0 : if ( hbox->pictype == PICTYPE_FILE ){
3876 : #ifdef _WIN32
3877 : sprintf(buf, "file:///%s", hbox->picinfo.picun.path );
3878 : padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf).c_str())));
3879 : #else
3880 0 : padd(ascii("xlink:href"), sXML_CDATA,
3881 0 : (hconv(kstr2hstr((uchar *) urltounix(hbox->picinfo.picun.path).c_str()).c_str())));
3882 : #endif
3883 0 : padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
3884 0 : padd(ascii("xlink:show"), sXML_CDATA, ascii("embed"));
3885 0 : padd(ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
3886 : }
3887 :
3888 0 : if( hbox->pictype == PICTYPE_OLE )
3889 0 : rstartEl(ascii("draw:object-ole"), rList);
3890 : else
3891 0 : rstartEl(ascii("draw:image"), rList);
3892 0 : pList->clear();
3893 0 : if (hbox->pictype == PICTYPE_EMBED || hbox->pictype == PICTYPE_OLE)
3894 : {
3895 0 : rstartEl(ascii("office:binary-data"), rList);
3896 0 : pList->clear();
3897 0 : if( hbox->pictype == PICTYPE_EMBED ){
3898 0 : EmPicture *emp = hwpfile.GetEmPicture(hbox);
3899 0 : if( emp )
3900 : {
3901 0 : boost::shared_ptr<char> pStr(base64_encode_string( emp->data, emp->size ), Free<char>());
3902 0 : rchars(ascii(pStr.get()));
3903 : }
3904 : }
3905 : else{
3906 0 : if( hwpfile.oledata ){
3907 : #ifdef WIN32
3908 : LPSTORAGE srcsto;
3909 : LPUNKNOWN pObj;
3910 : wchar_t pathname[200];
3911 :
3912 : MultiByteToWideChar(CP_ACP, 0, hbox->picinfo.picole.embname, -1, pathname, 200);
3913 : int rc = hwpfile.oledata->pis->OpenStorage(pathname, 0,
3914 : STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, NULL, 0, &srcsto);
3915 : if (rc != S_OK) {
3916 : rchars(ascii(""));
3917 : }
3918 : else{
3919 : rc = OleLoad(srcsto, IID_IUnknown, NULL, (LPVOID*)&pObj);
3920 : if( rc != S_OK ){
3921 : srcsto->Release();
3922 : rchars(ascii(""));
3923 : }
3924 : else{
3925 : boost::shared_ptr<char> pStr(base64_encode_string( (uchar *)pObj, strlen((char *)pObj)), Free<char>());
3926 : rchars(ascii(pStr.get()));
3927 : pObj->Release();
3928 : srcsto->Release();
3929 : }
3930 : }
3931 : #else
3932 0 : rchars(ascii(""));
3933 : #endif
3934 : }
3935 : }
3936 0 : rendEl(ascii("office:binary-data"));
3937 : }
3938 0 : if( hbox->pictype == PICTYPE_OLE )
3939 0 : rendEl(ascii("draw:object-ole"));
3940 : else
3941 0 : rendEl(ascii("draw:image"));
3942 0 : if( hbox->ishyper )
3943 : {
3944 0 : rendEl(ascii("draw:a"));
3945 : }
3946 0 : if( hbox->style.cap_len > 0 )
3947 : {
3948 0 : rendEl( ascii("text:p"));
3949 0 : if( !(hbox->cap_pos % 2)) /* 캡션이 아래쪽에 위치하면, */
3950 : {
3951 0 : parsePara(hbox->caption.front());
3952 : }
3953 0 : rendEl( ascii("draw:text-box"));
3954 : }
3955 0 : break;
3956 : }
3957 : case PICTYPE_DRAW:
3958 0 : if( hbox->picinfo.picdraw.zorder > 0 )
3959 0 : padd(ascii("draw:z-index"), sXML_CDATA,
3960 0 : ascii(Int2Str( hbox->picinfo.picdraw.zorder + 10000, "%d", buf)));
3961 0 : makePictureDRAW( (HWPDrawingObject *) hbox->picinfo.picdraw.hdo, hbox);
3962 0 : break;
3963 : case PICTYPE_UNKNOWN:
3964 0 : break;
3965 : }
3966 0 : }
3967 :
3968 :
3969 : #define DBL(x) ((x) * (x))
3970 0 : void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox)
3971 : {
3972 0 : int x = hbox->pgx;
3973 0 : int y = hbox->pgy;
3974 : int a, b;
3975 0 : sal_Bool bIsRotate = sal_False;
3976 :
3977 0 : while (drawobj)
3978 : {
3979 0 : padd(ascii("draw:style-name"), sXML_CDATA,
3980 0 : ascii(Int2Str(drawobj->index, "Draw%d", buf)));
3981 0 : a = 0; b = 0;
3982 :
3983 0 : switch (hbox->style.anchor_type)
3984 : {
3985 : case CHAR_ANCHOR:
3986 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("as-char"));
3987 0 : break;
3988 : case PARA_ANCHOR:
3989 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
3990 0 : break;
3991 : case PAGE_ANCHOR:
3992 : case PAPER_ANCHOR:
3993 : {
3994 0 : HWPInfo *hwpinfo = hwpfile.GetHWPInfo();
3995 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("page"));
3996 0 : padd(ascii("text:anchor-page-number"), sXML_CDATA,
3997 0 : ascii(Int2Str(hbox->pgno +1, "%d", buf)));
3998 0 : a = hwpinfo->paper.left_margin;
3999 0 : b = hwpinfo->paper.top_margin + hwpinfo->paper.header_length;
4000 0 : break;
4001 : }
4002 : }
4003 :
4004 0 : if (drawobj->type == HWPDO_CONTAINER)
4005 : {
4006 0 : rstartEl(ascii("draw:g"), rList);
4007 0 : pList->clear();
4008 0 : makePictureDRAW(drawobj->child, hbox);
4009 0 : rendEl(ascii("draw:g"));
4010 : }
4011 : else
4012 : {
4013 0 : bIsRotate = sal_False;
4014 0 : if( (drawobj->property.flag & HWPDO_FLAG_ROTATION) &&
4015 : (drawobj->property.parall.pt[0].y != drawobj->property.parall.pt[1].y) &&
4016 : //(drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE || drawobj->type == HWPDO_ADVANCED_ARC )
4017 : (drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE )
4018 : )
4019 : {
4020 :
4021 : int i;
4022 0 : ZZParall *pal = &drawobj->property.parall;
4023 :
4024 : ZZPoint pt[3], r_pt[3];
4025 0 : for(i = 0 ; i < 3 ; i++ ){
4026 0 : pt[i].x = pal->pt[i].x - drawobj->property.rot_originx;
4027 : /* 물리좌표계로 변환 */
4028 0 : pt[i].y = -(pal->pt[i].y - drawobj->property.rot_originy);
4029 : }
4030 :
4031 : double rotate, skewX ;
4032 :
4033 : /* 2 - 회전각 계산 */
4034 0 : if( pt[1].x == pt[0].x ){
4035 0 : if( pt[1].y > pt[0].y )
4036 0 : rotate = PI/2;
4037 : else
4038 0 : rotate = -(PI/2);
4039 : }
4040 : else
4041 0 : rotate = atan((double)( pt[1].y - pt[0].y )/(pt[1].x - pt[0].x ));
4042 0 : if( pt[1].x < pt[0].x )
4043 0 : rotate += PI;
4044 :
4045 0 : for( i = 0 ; i < 3 ; i++){
4046 0 : r_pt[i].x = (int)(pt[i].x * cos(-(rotate)) - pt[i].y * sin(-(rotate)));
4047 0 : r_pt[i].y = (int)(pt[i].y * cos(-(rotate)) + pt[i].x * sin(-(rotate)));
4048 : }
4049 :
4050 : /* 4 - 휜각 계산 */
4051 0 : if( r_pt[2].y == r_pt[1].y )
4052 0 : skewX = 0;
4053 : else
4054 0 : skewX = atan((double)(r_pt[2].x - r_pt[1].x )/( r_pt[2].y - r_pt[1].y ));
4055 0 : if( skewX >= PI/2 )
4056 0 : skewX -= PI;
4057 0 : if( skewX <= -PI/2 )
4058 0 : skewX += PI;
4059 :
4060 0 : OUString trans;
4061 0 : if( skewX != 0.0 && rotate != 0.0 ){
4062 0 : trans = ascii("skewX (") + Double2Str(skewX)
4063 0 : + ascii(") rotate (") + Double2Str(rotate)
4064 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4065 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4066 0 : bIsRotate = sal_True;
4067 : }
4068 0 : else if( skewX != 0.0 ){
4069 0 : trans = ascii("skewX (") + Double2Str(skewX)
4070 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4071 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4072 0 : bIsRotate = sal_True;
4073 : }
4074 0 : else if( rotate != 0.0 ){
4075 0 : trans = ascii("rotate (") + Double2Str(rotate)
4076 0 : + ascii(") translate (") + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + ascii("mm ")
4077 0 : + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + ascii("mm)");
4078 0 : bIsRotate = sal_True;
4079 : }
4080 0 : if( bIsRotate == sal_True ){
4081 0 : drawobj->extent.w = (int)sqrt(double(DBL(pt[1].x-pt[0].x)+DBL(pt[1].y-pt[0].y)));
4082 0 : drawobj->extent.h = (int)sqrt(double(DBL(pt[2].x-pt[1].x)+DBL(pt[2].y-pt[1].y)));
4083 0 : padd(ascii("draw:transform"), sXML_CDATA, trans);
4084 0 : }
4085 : }
4086 0 : switch (drawobj->type)
4087 : {
4088 : case HWPDO_LINE: /* 선 - 시작좌표, 끝좌표. */
4089 0 : if( drawobj->u.line_arc.flip & 0x01 )
4090 : {
4091 0 : padd(ascii("svg:x1"), sXML_CDATA,
4092 0 : Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + ascii("mm"));
4093 0 : padd(ascii("svg:x2"), sXML_CDATA,
4094 0 : Double2Str (WTMM( x + a + drawobj->offset2.x )) + ascii("mm"));
4095 : }
4096 : else
4097 : {
4098 0 : padd(ascii("svg:x1"), sXML_CDATA,
4099 0 : Double2Str (WTMM( x + a + drawobj->offset2.x )) + ascii("mm"));
4100 0 : padd(ascii("svg:x2"), sXML_CDATA,
4101 0 : Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + ascii("mm"));
4102 : }
4103 0 : if( drawobj->u.line_arc.flip & 0x02 )
4104 : {
4105 0 : padd(ascii("svg:y1"), sXML_CDATA,
4106 0 : Double2Str (WTMM( y + b + drawobj->offset2.y + drawobj->extent.h ) ) + ascii("mm"));
4107 0 : padd(ascii("svg:y2"), sXML_CDATA,
4108 0 : Double2Str (WTMM( y + b + drawobj->offset2.y )) + ascii("mm"));
4109 : }
4110 : else
4111 : {
4112 0 : padd(ascii("svg:y1"), sXML_CDATA,
4113 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4114 0 : padd(ascii("svg:y2"), sXML_CDATA,
4115 0 : Double2Str (WTMM(y + b + drawobj->offset2.y + drawobj->extent.h)) + ascii("mm"));
4116 : }
4117 :
4118 0 : rstartEl(ascii("draw:line"), rList);
4119 0 : pList->clear();
4120 0 : rendEl(ascii("draw:line"));
4121 0 : break;
4122 : case HWPDO_RECT: /* 사각형 - 시작위치, 가로/세로 */
4123 0 : if( !bIsRotate )
4124 : {
4125 0 : padd(ascii("svg:x"), sXML_CDATA,
4126 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4127 0 : padd(ascii("svg:y"), sXML_CDATA,
4128 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4129 : }
4130 0 : padd(ascii("svg:width"), sXML_CDATA,
4131 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4132 0 : padd(ascii("svg:height"), sXML_CDATA,
4133 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4134 0 : if( drawobj->property.flag & 0x01 )
4135 : {
4136 : int value = drawobj->extent.w < drawobj->extent.h ?
4137 0 : drawobj->extent.w : drawobj->extent.h ;
4138 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4139 0 : Double2Str (WTMM( value/10 )) + ascii("mm"));
4140 : }
4141 0 : else if( drawobj->property.flag & 0x04 )
4142 : {
4143 : int value = drawobj->extent.w < drawobj->extent.h ?
4144 0 : drawobj->extent.w : drawobj->extent.h ;
4145 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4146 0 : Double2Str (WTMM( value / 2)) + ascii("mm"));
4147 : }
4148 :
4149 0 : rstartEl(ascii("draw:rect"), rList);
4150 0 : pList->clear();
4151 0 : if( (drawobj->property.flag & HWPDO_FLAG_AS_TEXTBOX) &&
4152 : drawobj->property.pPara ) // As Textbox
4153 : {
4154 0 : HWPPara *pPara = drawobj->property.pPara;
4155 : //parsePara(pPara);
4156 0 : while(pPara)
4157 : {
4158 0 : make_text_p1( pPara );
4159 0 : pPara = pPara->Next();
4160 : }
4161 : }
4162 0 : rendEl(ascii("draw:rect"));
4163 0 : break;
4164 : case HWPDO_ELLIPSE: /* 타원 - 시작위치, 가로/세로 */
4165 : case HWPDO_ADVANCED_ELLIPSE: /* 변형된 타원 */
4166 : {
4167 0 : if( !bIsRotate )
4168 : {
4169 0 : padd(ascii("svg:x"), sXML_CDATA,
4170 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4171 0 : padd(ascii("svg:y"), sXML_CDATA,
4172 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4173 : }
4174 :
4175 0 : padd(ascii("svg:width"), sXML_CDATA,
4176 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4177 0 : padd(ascii("svg:height"), sXML_CDATA,
4178 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4179 0 : if( drawobj->type == HWPDO_ADVANCED_ELLIPSE ){
4180 0 : if( drawobj->u.arc.radial[0].x != drawobj->u.arc.radial[1].x
4181 : || drawobj->u.arc.radial[0].y != drawobj->u.arc.radial[1].y ){
4182 : int Cx,Cy;
4183 0 : Cx = ( drawobj->offset2.x + drawobj->extent.w ) / 2;
4184 0 : Cy = ( drawobj->offset2.y + drawobj->extent.h ) / 2;
4185 :
4186 : double start_angle, end_angle;
4187 0 : start_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[0].x, drawobj->u.arc.radial[0].y );
4188 0 : end_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[1].x, drawobj->u.arc.radial[1].y );
4189 0 : if( drawobj->property.fill_color < 0xffffff )
4190 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("section"));
4191 : else
4192 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("arc"));
4193 0 : padd(ascii("draw:start-angle"), sXML_CDATA, Double2Str(start_angle ));
4194 0 : padd(ascii("draw:end-angle"), sXML_CDATA, Double2Str(end_angle));
4195 : }
4196 : }
4197 0 : rstartEl(ascii("draw:ellipse"), rList);
4198 0 : pList->clear();
4199 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4200 : drawobj->property.pPara ) // As Textbox
4201 : {
4202 0 : HWPPara *pPara = drawobj->property.pPara;
4203 : //parsePara(pPara);
4204 0 : while(pPara)
4205 : {
4206 0 : make_text_p1( pPara );
4207 0 : pPara = pPara->Next();
4208 : }
4209 : }
4210 0 : rendEl(ascii("draw:ellipse"));
4211 0 : break;
4212 :
4213 : }
4214 : case HWPDO_ARC: /* 호 */
4215 : case HWPDO_ADVANCED_ARC:
4216 : {
4217 : /* 호일경우에, 스타오피스는 전체 타원의 크기를 사이즈로 한다. */
4218 0 : uint flip = drawobj->u.line_arc.flip;
4219 0 : if( !bIsRotate )
4220 : {
4221 0 : if( ( flip == 0 || flip == 2 ) && drawobj->type == HWPDO_ARC)
4222 0 : padd(ascii("svg:x"), sXML_CDATA,
4223 0 : Double2Str (WTMM( x + a + drawobj->offset2.x - drawobj->extent.w)) + ascii("mm"));
4224 : else
4225 0 : padd(ascii("svg:x"), sXML_CDATA,
4226 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4227 0 : if( ( flip == 0 || flip == 1 ) && drawobj->type == HWPDO_ARC)
4228 0 : padd(ascii("svg:y"), sXML_CDATA,
4229 0 : Double2Str (WTMM( y + b + drawobj->offset2.y - drawobj->extent.h)) + ascii("mm"));
4230 : else
4231 0 : padd(ascii("svg:y"), sXML_CDATA,
4232 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4233 : }
4234 :
4235 0 : padd(ascii("svg:width"), sXML_CDATA,
4236 0 : Double2Str (WTMM( drawobj->extent.w * 2)) + ascii("mm"));
4237 0 : padd(ascii("svg:height"), sXML_CDATA,
4238 0 : Double2Str (WTMM( drawobj->extent.h * 2)) + ascii("mm"));
4239 0 : if( drawobj->property.flag & HWPDO_FLAG_DRAW_PIE ||
4240 : drawobj->property.fill_color < 0xffffff )
4241 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("section"));
4242 : else
4243 0 : padd(ascii("draw:kind"), sXML_CDATA, ascii("arc"));
4244 :
4245 0 : if( drawobj->type == HWPDO_ADVANCED_ARC ){
4246 : double start_angle, end_angle;
4247 0 : ZZParall *pal = &drawobj->property.parall;
4248 :
4249 0 : if( pal->pt[1].x == pal->pt[0].x ){
4250 0 : if( pal->pt[0].y < pal->pt[1].y )
4251 0 : start_angle = 1.5 * PI;
4252 : else
4253 0 : start_angle = 0.5 * PI;
4254 : }
4255 : else{
4256 0 : start_angle = atan((double)( pal->pt[0].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[0].x ));
4257 0 : if( pal->pt[1].x < pal->pt[0].x )
4258 0 : start_angle += PI;
4259 : }
4260 0 : if( pal->pt[1].x == pal->pt[2].x ){
4261 0 : if( pal->pt[2].y < pal->pt[1].y )
4262 0 : end_angle = 1.5 * PI;
4263 : else
4264 0 : end_angle = 0.5 * PI;
4265 : }
4266 : else{
4267 0 : end_angle = atan((double)( pal->pt[2].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[2].x ));
4268 0 : if( pal->pt[1].x < pal->pt[2].x )
4269 0 : end_angle += PI;
4270 : }
4271 :
4272 0 : if( start_angle >= 2 * PI )
4273 0 : start_angle -= 2 * PI;
4274 0 : if( end_angle >= 2 * PI )
4275 0 : end_angle -= 2 * PI;
4276 0 : if( ( start_angle > end_angle ) && (start_angle - end_angle < PI )){
4277 0 : double tmp_angle = start_angle;
4278 0 : start_angle = end_angle;
4279 0 : end_angle = tmp_angle;
4280 : }
4281 0 : padd(ascii("draw:start-angle"), sXML_CDATA, Double2Str(start_angle * 180. / PI));
4282 0 : padd(ascii("draw:end-angle"), sXML_CDATA, Double2Str(end_angle * 180. / PI));
4283 :
4284 : }
4285 : else{
4286 0 : if( drawobj->u.line_arc.flip == 0 )
4287 : {
4288 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("270"));
4289 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("0"));
4290 : }
4291 0 : else if( drawobj->u.line_arc.flip == 1 )
4292 : {
4293 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("180"));
4294 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("270"));
4295 : }
4296 0 : else if( drawobj->u.line_arc.flip == 2 )
4297 : {
4298 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("0"));
4299 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("90"));
4300 : }
4301 : else
4302 : {
4303 0 : padd(ascii("draw:start-angle"), sXML_CDATA, ascii("90"));
4304 0 : padd(ascii("draw:end-angle"), sXML_CDATA, ascii("180"));
4305 : }
4306 : }
4307 0 : rstartEl(ascii("draw:ellipse"), rList);
4308 0 : pList->clear();
4309 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4310 : drawobj->property.pPara ) // As Textbox
4311 : {
4312 0 : HWPPara *pPara = drawobj->property.pPara;
4313 : //parsePara(pPara);
4314 0 : while(pPara)
4315 : {
4316 0 : make_text_p1( pPara );
4317 0 : pPara = pPara->Next();
4318 : }
4319 : }
4320 0 : rendEl(ascii("draw:ellipse"));
4321 0 : break;
4322 :
4323 : }
4324 : case HWPDO_CURVE: /* 곡선 : 다각형으로 변환. */
4325 : {
4326 0 : sal_Bool bIsNatural = sal_True;
4327 0 : if( drawobj->property.flag >> 5 & 0x01){
4328 0 : bIsNatural = sal_False;
4329 : }
4330 0 : if( !bIsRotate )
4331 : {
4332 0 : padd(ascii("svg:x"), sXML_CDATA,
4333 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4334 0 : padd(ascii("svg:y"), sXML_CDATA,
4335 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4336 : }
4337 0 : padd(ascii("svg:width"), sXML_CDATA,
4338 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4339 0 : padd(ascii("svg:height"), sXML_CDATA,
4340 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4341 0 : sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w) , WTSM(drawobj->extent.h) );
4342 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii(buf) );
4343 :
4344 0 : OUString oustr;
4345 :
4346 0 : if ((drawobj->u.freeform.npt > 2) &&
4347 : (static_cast<size_t>(drawobj->u.freeform.npt) <
4348 0 : ((::std::numeric_limits<int>::max)() / sizeof(double))))
4349 : {
4350 : int n, i;
4351 0 : n = drawobj->u.freeform.npt;
4352 :
4353 0 : double *xarr = new double[n+1];
4354 0 : double *yarr = new double[n+1];
4355 0 : double *tarr = new double[n+1];
4356 :
4357 0 : double *xb = 0L;
4358 0 : double *yb = 0L;
4359 :
4360 0 : double *carr = 0L;
4361 0 : double *darr = 0L;
4362 :
4363 :
4364 0 : for( i = 0 ; i < n ; i++ ){
4365 0 : xarr[i] = drawobj->u.freeform.pt[i].x;
4366 0 : yarr[i] = drawobj->u.freeform.pt[i].y;
4367 0 : tarr[i] = i;
4368 : }
4369 0 : xarr[n] = xarr[0];
4370 0 : yarr[n] = yarr[0];
4371 0 : tarr[n] = n;
4372 :
4373 0 : if( bIsNatural == sal_False ){
4374 0 : PeriodicSpline(n, tarr, xarr, xb, carr, darr);
4375 : // prevent memory leak
4376 0 : delete[] carr;
4377 0 : carr = 0;
4378 0 : delete[] darr;
4379 0 : darr = 0;
4380 0 : PeriodicSpline(n, tarr, yarr, yb, carr, darr);
4381 : }
4382 : else{
4383 0 : NaturalSpline(n, tarr, xarr, xb, carr, darr);
4384 : // prevent memory leak
4385 0 : delete[] carr;
4386 0 : carr = 0;
4387 0 : delete[] darr;
4388 0 : darr = 0;
4389 0 : NaturalSpline(n, tarr, yarr, yb, carr, darr);
4390 : }
4391 :
4392 0 : sprintf(buf, "M%d %dC%d %d", WTSM((int)xarr[0]), WTSM((int)yarr[0]),
4393 0 : WTSM((int)(xarr[0] + xb[0]/3)), WTSM((int)(yarr[0] + yb[0]/3)) );
4394 0 : oustr += ascii(buf);
4395 :
4396 0 : for( i = 1 ; i < n ; i++ ){
4397 0 : if( i == n -1 ){
4398 : sprintf(buf, " %d %d %d %dz",
4399 0 : WTSM((int)(xarr[i] - xb[i]/3)), WTSM((int)(yarr[i] - yb[i]/3)),
4400 0 : WTSM((int)xarr[i]), WTSM((int)yarr[i]) );
4401 : }
4402 : else{
4403 : sprintf(buf, " %d %d %d %d %d %d",
4404 0 : WTSM((int)(xarr[i] - xb[i]/3)), WTSM((int)(yarr[i] - yb[i]/3)),
4405 0 : WTSM((int)xarr[i]), WTSM((int)yarr[i]),
4406 0 : WTSM((int)xarr[i] + xb[i]/3), WTSM((int)(yarr[i] + yb[i]/3)) );
4407 : }
4408 :
4409 0 : oustr += ascii(buf);
4410 : }
4411 0 : delete[] tarr;
4412 0 : delete[] xarr;
4413 0 : delete[] yarr;
4414 :
4415 0 : delete[] xb;
4416 0 : delete[] yb;
4417 :
4418 0 : delete[] carr;
4419 0 : delete[] darr;
4420 : }
4421 :
4422 0 : padd(ascii("svg:d"), sXML_CDATA, oustr);
4423 :
4424 0 : rstartEl(ascii("draw:path"), rList);
4425 0 : pList->clear();
4426 : // As Textbox
4427 0 : if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara )
4428 : {
4429 0 : HWPPara *pPara = drawobj->property.pPara;
4430 0 : while(pPara)
4431 : {
4432 0 : make_text_p1( pPara );
4433 0 : pPara = pPara->Next();
4434 : }
4435 : }
4436 0 : rendEl(ascii("draw:path"));
4437 0 : break;
4438 : }
4439 : case HWPDO_CLOSED_FREEFORM:
4440 : case HWPDO_FREEFORM: /* 다각형 */
4441 : {
4442 0 : bool bIsPolygon = false;
4443 :
4444 0 : padd(ascii("svg:x"), sXML_CDATA,
4445 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4446 0 : padd(ascii("svg:y"), sXML_CDATA,
4447 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4448 :
4449 0 : padd(ascii("svg:width"), sXML_CDATA,
4450 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4451 0 : padd(ascii("svg:height"), sXML_CDATA,
4452 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4453 :
4454 0 : sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w), WTSM(drawobj->extent.h));
4455 0 : padd(ascii("svg:viewBox"), sXML_CDATA, ascii(buf) );
4456 :
4457 0 : OUString oustr;
4458 :
4459 0 : if (drawobj->u.freeform.npt > 0)
4460 : {
4461 0 : sprintf(buf, "%d,%d", WTSM(drawobj->u.freeform.pt[0].x), WTSM(drawobj->u.freeform.pt[0].y));
4462 0 : oustr += ascii(buf);
4463 : int i;
4464 0 : for (i = 1; i < drawobj->u.freeform.npt ; i++)
4465 : {
4466 : sprintf(buf, " %d,%d",
4467 0 : WTSM(drawobj->u.freeform.pt[i].x),
4468 0 : WTSM(drawobj->u.freeform.pt[i].y));
4469 0 : oustr += ascii(buf);
4470 : }
4471 0 : if( drawobj->u.freeform.pt[0].x == drawobj->u.freeform.pt[i-1].x &&
4472 0 : drawobj->u.freeform.pt[0].y == drawobj->u.freeform.pt[i-1].y )
4473 : {
4474 0 : bIsPolygon = true;
4475 : }
4476 : }
4477 0 : padd(ascii("draw:points"), sXML_CDATA, oustr);
4478 :
4479 0 : if( drawobj->property.fill_color <= 0xffffff ||
4480 : drawobj->property.pattern_type != 0)
4481 : {
4482 0 : bIsPolygon = true;
4483 : }
4484 :
4485 0 : if(bIsPolygon)
4486 : {
4487 0 : rstartEl(ascii("draw:polygon"), rList);
4488 0 : pList->clear();
4489 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4490 : // As Textbox
4491 : drawobj->property.pPara )
4492 : {
4493 0 : HWPPara *pPara = drawobj->property.pPara;
4494 : // parsePara(pPara);
4495 0 : while(pPara)
4496 : {
4497 0 : make_text_p1( pPara );
4498 0 : pPara = pPara->Next();
4499 : }
4500 : }
4501 0 : rendEl(ascii("draw:polygon"));
4502 : }
4503 : else
4504 : {
4505 0 : rstartEl(ascii("draw:polyline"), rList);
4506 0 : pList->clear();
4507 0 : if( drawobj->property.flag >> 19 & 0x01 &&
4508 : // As Textbox
4509 : drawobj->property.pPara )
4510 : {
4511 0 : HWPPara *pPara = drawobj->property.pPara;
4512 : //parsePara(pPara);
4513 0 : while(pPara)
4514 : {
4515 0 : make_text_p1( pPara );
4516 0 : pPara = pPara->Next();
4517 : }
4518 : }
4519 0 : rendEl(ascii("draw:polyline"));
4520 : }
4521 0 : break;
4522 : }
4523 : case HWPDO_TEXTBOX:
4524 0 : if( !bIsRotate )
4525 : {
4526 0 : padd(ascii("svg:x"), sXML_CDATA,
4527 0 : Double2Str (WTMM( x + a + drawobj->offset2.x)) + ascii("mm"));
4528 0 : padd(ascii("svg:y"), sXML_CDATA,
4529 0 : Double2Str (WTMM( y + b + drawobj->offset2.y)) + ascii("mm"));
4530 : }
4531 0 : padd(ascii("svg:width"), sXML_CDATA,
4532 0 : Double2Str (WTMM( drawobj->extent.w )) + ascii("mm"));
4533 0 : padd(ascii("svg:height"), sXML_CDATA,
4534 0 : Double2Str (WTMM( drawobj->extent.h )) + ascii("mm"));
4535 0 : if( drawobj->property.flag & 0x01 )
4536 : {
4537 : int value = drawobj->extent.w < drawobj->extent.h ?
4538 0 : drawobj->extent.w : drawobj->extent.h ;
4539 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4540 0 : Double2Str (WTMM( value/10 )) + ascii("mm"));
4541 : }
4542 0 : else if( drawobj->property.flag & 0x04 )
4543 : {
4544 : int value = drawobj->extent.w < drawobj->extent.h ?
4545 0 : drawobj->extent.w : drawobj->extent.h ;
4546 0 : padd(ascii("draw:corner-radius"), sXML_CDATA,
4547 0 : Double2Str (WTMM( value / 2)) + ascii("mm"));
4548 : }
4549 :
4550 0 : rstartEl(ascii("draw:text-box"), rList);
4551 0 : pList->clear();
4552 :
4553 0 : HWPPara *pPara = drawobj->u.textbox.h;
4554 : //parsePara(pPara);
4555 0 : while(pPara)
4556 : {
4557 0 : make_text_p1( pPara );
4558 0 : pPara = pPara->Next();
4559 : }
4560 :
4561 0 : rendEl(ascii("draw:text-box"));
4562 0 : break;
4563 : }
4564 : }
4565 0 : pList->clear();
4566 0 : drawobj = drawobj->next;
4567 : }
4568 0 : }
4569 :
4570 :
4571 : /**
4572 : *
4573 : */
4574 0 : void HwpReader::makeLine(Line * )
4575 : {
4576 0 : padd(ascii("text:style-name"), sXML_CDATA, ascii("Horizontal Line"));
4577 0 : rstartEl( ascii("text:p"), rList);
4578 0 : pList->clear();
4579 0 : }
4580 :
4581 :
4582 : /**
4583 : * 입력-주석-숨은설명 : 사용자에게 숨은 설명을 보여준다.
4584 : * 문단이 포함될 수 있으나, 단지 문자열만 뽑아내어 파싱한다.
4585 : */
4586 0 : void HwpReader::makeHidden(Hidden * hbox)
4587 : {
4588 0 : hchar_string str;
4589 : int res;
4590 : hchar dest[3];
4591 :
4592 0 : padd(ascii("text:condition"), sXML_CDATA, ascii(""));
4593 0 : padd(ascii("text:string-value"), sXML_CDATA, ascii(""));
4594 0 : rstartEl(ascii("text:hidden-text"), rList);
4595 0 : pList->clear();
4596 0 : HWPPara *para = hbox->plist.front();
4597 :
4598 0 : while (para)
4599 : {
4600 0 : for (int n = 0; n < para->nch && para->hhstr[n]->hh;
4601 0 : n += para->hhstr[n]->WSize())
4602 : {
4603 0 : res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
4604 0 : for( int j = 0 ; j < res ; j++ )
4605 : {
4606 0 : str.push_back(dest[j]);
4607 : }
4608 : }
4609 0 : para = para->Next();
4610 : }
4611 0 : makeChars(str);
4612 0 : rendEl(ascii("text:hidden-text"));
4613 0 : }
4614 :
4615 :
4616 : /**
4617 : * 각주는 text:footnote, 미주는 text:endnote로 변환
4618 : */
4619 0 : void HwpReader::makeFootnote(Footnote * hbox)
4620 : {
4621 0 : if (hbox->type)
4622 : {
4623 0 : padd(ascii("text:id"), sXML_CDATA,
4624 0 : ascii(Int2Str(hbox->number, "edn%d", buf)));
4625 0 : rstartEl(ascii("text:endnote"), rList);
4626 0 : pList->clear();
4627 0 : padd(ascii("text:label"), sXML_CDATA,
4628 0 : ascii(Int2Str(hbox->number, "%d", buf)));
4629 0 : rstartEl(ascii("text:endnote-citation"), rList);
4630 0 : pList->clear();
4631 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4632 0 : rendEl(ascii("text:endnote-citation"));
4633 0 : rstartEl(ascii("text:endnote-body"), rList);
4634 0 : parsePara(hbox->plist.front());
4635 0 : rendEl(ascii("text:endnote-body"));
4636 0 : rendEl(ascii("text:endnote"));
4637 : }
4638 : else
4639 : {
4640 0 : padd(ascii("text:id"), sXML_CDATA,
4641 0 : ascii(Int2Str(hbox->number, "ftn%d", buf)));
4642 0 : rstartEl(ascii("text:footnote"), rList);
4643 0 : pList->clear();
4644 0 : padd(ascii("text:label"), sXML_CDATA,
4645 0 : ascii(Int2Str(hbox->number, "%d", buf)));
4646 0 : rstartEl(ascii("text:footnote-citation"), rList);
4647 0 : pList->clear();
4648 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4649 0 : rendEl(ascii("text:footnote-citation"));
4650 0 : rstartEl(ascii("text:footnote-body"), rList);
4651 0 : parsePara(hbox->plist.front());
4652 0 : rendEl(ascii("text:footnote-body"));
4653 0 : rendEl(ascii("text:footnote"));
4654 : }
4655 0 : }
4656 :
4657 :
4658 : /**
4659 : * page/footnote/endnote/picture/table/formula number
4660 : */
4661 0 : void HwpReader::makeAutoNum(AutoNum * hbox)
4662 : {
4663 0 : switch (hbox->type)
4664 : {
4665 : case PGNUM_AUTO:
4666 0 : rstartEl(ascii("text:page-number"), rList);
4667 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4668 0 : rendEl(ascii("text:page-number"));
4669 0 : break;
4670 : case FNNUM_AUTO:
4671 0 : break;
4672 : case ENNUM_AUTO:
4673 0 : break;
4674 : case EQUNUM_AUTO:
4675 : case PICNUM_AUTO:
4676 0 : padd(ascii("text:ref-name"),sXML_CDATA,
4677 0 : ascii(Int2Str(hbox->number, "refIllustration%d", buf)));
4678 0 : padd(ascii("text:name"),sXML_CDATA, ascii("Illustration"));
4679 0 : padd(ascii("style:num-format"),sXML_CDATA, ascii("1"));
4680 0 : rstartEl(ascii("text:sequence"), rList);
4681 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4682 0 : rendEl(ascii("text:sequence"));
4683 0 : break;
4684 : case TBLNUM_AUTO:
4685 0 : padd(ascii("text:ref-name"),sXML_CDATA,
4686 0 : ascii(Int2Str(hbox->number, "refTable%d", buf)));
4687 0 : padd(ascii("text:name"),sXML_CDATA, ascii("Table"));
4688 0 : padd(ascii("style:num-format"),sXML_CDATA, ascii("1"));
4689 0 : rstartEl(ascii("text:sequence"), rList);
4690 0 : rchars(ascii(Int2Str(hbox->number, "%d", buf)));
4691 0 : rendEl(ascii("text:sequence"));
4692 0 : break;
4693 : }
4694 0 : }
4695 :
4696 :
4697 0 : void HwpReader::makeShowPageNum()
4698 : {
4699 0 : ShowPageNum *hbox = d->pPn;
4700 0 : int nPos = 0;
4701 0 : if( hbox->where == 1 || hbox->where == 4 )
4702 0 : nPos = 1;
4703 0 : else if( hbox->where == 2 || hbox->where == 5 )
4704 0 : nPos = 2;
4705 0 : else if( hbox->where == 3 || hbox->where == 6 )
4706 0 : nPos = 3;
4707 : else /* 이 경우가 존재하면 안된다. */
4708 : {
4709 0 : if( d->nPnPos == 1 )
4710 0 : nPos = 1;
4711 0 : else if( d->nPnPos == 3 )
4712 0 : nPos = 3;
4713 : }
4714 :
4715 0 : padd(ascii("draw:style-name"), sXML_CDATA,
4716 0 : ascii(Int2Str(nPos, "PNBox%d", buf)));
4717 0 : padd(ascii("draw:name"), sXML_CDATA,
4718 0 : ascii(Int2Str(nPos, "PageNumber%d", buf)));
4719 0 : padd(ascii("text:anchor-type"), sXML_CDATA, ascii("paragraph"));
4720 0 : padd(ascii("svg:y"), sXML_CDATA, ascii("0cm"));
4721 0 : padd(ascii("svg:width"), sXML_CDATA, ascii("2.0cm"));
4722 0 : padd(ascii("fo:min-height"), sXML_CDATA, ascii("0.5cm"));
4723 0 : rstartEl(ascii("draw:text-box"), rList);
4724 0 : pList->clear();
4725 :
4726 0 : padd(ascii("text:style-name"), sXML_CDATA,
4727 0 : ascii(Int2Str(nPos, "PNPara%d", buf)));
4728 0 : rstartEl(ascii("text:p"), rList);
4729 0 : pList->clear();
4730 0 : if( hbox->shape > 2 )
4731 0 : rchars(ascii("- "));
4732 0 : if( hbox->shape % 3 == 0 )
4733 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("1"));
4734 0 : else if( hbox->shape % 3 == 1 )
4735 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("I"));
4736 : else
4737 0 : padd(ascii("style:num-format"), sXML_CDATA, ascii("i"));
4738 0 : padd(ascii("text:select-page"), sXML_CDATA, ascii("current"));
4739 0 : rstartEl(ascii("text:page-number"), rList);
4740 0 : pList->clear();
4741 0 : rchars(ascii("2"));
4742 0 : rendEl(ascii("text:page-number"));
4743 0 : if( hbox->shape > 2 )
4744 0 : rchars(ascii(" -"));
4745 0 : rendEl(ascii("text:p"));
4746 0 : rendEl(ascii("draw:text-box"));
4747 0 : }
4748 :
4749 :
4750 : /**
4751 : * mail merge operation using hwp addressbook and hwp data form.
4752 : * not support operation in OO writer.
4753 : */
4754 0 : void HwpReader::makeMailMerge(MailMerge * hbox)
4755 : {
4756 0 : hchar_string const boxstr = hbox->GetString();
4757 0 : rchars((hconv(boxstr.c_str())));
4758 0 : }
4759 :
4760 :
4761 : /**
4762 : * Make heading contents file using toc marks
4763 : * not support operation.
4764 : */
4765 0 : void HwpReader::makeTocMark(TocMark * ) /*hbox */
4766 : {
4767 0 : }
4768 :
4769 :
4770 : /**
4771 : * Make search character table in automatic
4772 : * not support operation
4773 : */
4774 0 : void HwpReader::makeIndexMark(IndexMark * ) /*hbox */
4775 : {
4776 0 : }
4777 :
4778 :
4779 0 : void HwpReader::makeOutline(Outline * hbox)
4780 : {
4781 0 : if( hbox->kind == 1 )
4782 0 : rchars(OUString(hbox->GetUnicode().c_str()));
4783 0 : }
4784 :
4785 :
4786 2 : void HwpReader::parsePara(HWPPara * para, sal_Bool bParaStart)
4787 : {
4788 :
4789 8 : while (para)
4790 : {
4791 4 : if( para->nch == 1)
4792 : {
4793 0 : if( !bParaStart )
4794 : {
4795 0 : padd(ascii("text:style-name"), sXML_CDATA,
4796 0 : ascii(getPStyleName(para->GetParaShape()->index, buf)));
4797 0 : rstartEl( ascii("text:p"),rList);
4798 0 : pList->clear();
4799 : }
4800 0 : if( d->bFirstPara && d->bInBody )
4801 : {
4802 : /* for HWP's Bookmark */
4803 0 : strcpy(buf,"[문서의 처음]"); /* "Begin of Document" */
4804 0 : padd(ascii("text:name"), sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8));
4805 0 : rstartEl(ascii("text:bookmark"), rList);
4806 0 : pList->clear();
4807 0 : rendEl(ascii("text:bookmark"));
4808 0 : d->bFirstPara = false;
4809 : }
4810 0 : if( d->bInHeader )
4811 : {
4812 0 : makeShowPageNum();
4813 0 : d->bInHeader = false;
4814 : }
4815 :
4816 0 : rendEl( ascii("text:p") );
4817 : }
4818 : else
4819 : {
4820 4 : if (!para->ctrlflag)
4821 : {
4822 4 : if (para->contain_cshape)
4823 4 : make_text_p1(para, bParaStart);
4824 : else
4825 0 : make_text_p0(para, bParaStart);
4826 : }
4827 : else
4828 0 : make_text_p3(para, bParaStart);
4829 : }
4830 4 : bParaStart = false;
4831 4 : para = para->Next();
4832 : }
4833 8 : }
4834 :
4835 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|