LCOV - code coverage report
Current view: top level - hwpfilter/source - hwpreader.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 469 2883 16.3 %
Date: 2015-06-13 12:38:46 Functions: 25 51 49.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11