LCOV - code coverage report
Current view: top level - libreoffice/hwpfilter/source - hpara.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 93 163 57.1 %
Date: 2012-12-17 Functions: 8 8 100.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 "precompile.h"
      21             : 
      22             : #include <osl/diagnose.h>
      23             : 
      24             : #include <comphelper/newarray.hxx>
      25             : 
      26             : #include "hwplib.h"
      27             : #include "hwpfile.h"
      28             : #include "hpara.h"
      29             : #include "hbox.h"
      30             : #include "hutil.h"
      31             : #include "hutil.h"
      32             : 
      33           4 : bool LineInfo::Read(HWPFile & hwpf, HWPPara *pPara)
      34             : {
      35           4 :     pos = sal::static_int_cast<unsigned short>(hwpf.Read2b());
      36           4 :     space_width = (short) hwpf.Read2b();
      37           4 :     height = (short) hwpf.Read2b();
      38             : // internal informations
      39           4 :     pgy = (short) hwpf.Read2b();
      40           4 :     sx = (short) hwpf.Read2b();
      41           4 :     psx = (short) hwpf.Read2b();
      42           4 :     pex = (short) hwpf.Read2b();
      43           4 :     height_sp = 0;
      44             : 
      45           4 :     if( pex >> 15 & 0x01 )
      46             :     {
      47           0 :           if( pex & 0x01 )
      48           0 :                 hwpf.AddPage();
      49           0 :         pPara->pshape.reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
      50           0 :         pPara->pshape.reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
      51             :     }
      52             : 
      53           4 :     return (!hwpf.State());
      54             : }
      55             : 
      56             : 
      57           6 : HWPPara::HWPPara(void)
      58             : {
      59           6 :     _next = NULL;
      60           6 :     linfo = NULL;
      61           6 :     cshapep = NULL;
      62           6 :     hhstr = NULL;
      63           6 :     pno = 0;
      64             : 
      65           6 : }
      66             : 
      67             : 
      68           6 : HWPPara::~HWPPara(void)
      69             : {
      70           6 :     if (linfo)
      71           6 :         delete[]linfo;
      72           6 :     if (cshapep)
      73           4 :         delete[]cshapep;
      74           6 :     if (hhstr)
      75             :     {
      76             : // virtual destructor
      77             : /* C++은 null에 대해서도 동작한다. */
      78          76 :         for (int ii = 0; ii < nch; ++ii)
      79          70 :             delete hhstr[ii];
      80             : 
      81           6 :         delete[]hhstr;
      82             :     }
      83             : 
      84           6 : }
      85             : 
      86             : 
      87           6 : int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
      88             : {
      89             :     unsigned char same_cshape;
      90             :     register int ii;
      91           6 :     scflag = flag;
      92             : // Paragraph Information
      93           6 :     hwpf.Read1b(&reuse_shape, 1);
      94           6 :     hwpf.Read2b(&nch, 1);
      95           6 :     hwpf.Read2b(&nline, 1);
      96           6 :     hwpf.Read1b(&contain_cshape, 1);
      97           6 :     hwpf.Read1b(&etcflag, 1);
      98           6 :     hwpf.Read4b(&ctrlflag, 1);
      99           6 :     hwpf.Read1b(&pstyno, 1);
     100             : 
     101             : 
     102             : /* Paragraph 대표 글자 */
     103           6 :     cshape.Read(hwpf);
     104           6 :     if (nch > 0)
     105           4 :         hwpf.AddCharShape(&cshape);
     106             : 
     107             : /* Paragraph 문단 모양 */
     108           6 :     if (nch && !reuse_shape)
     109             :     {
     110           4 :         pshape.Read(hwpf);
     111           4 :         pshape.cshape = &cshape;
     112           4 :           pshape.pagebreak = etcflag;
     113             :     }
     114             : 
     115           6 :     linfo = ::comphelper::newArray_null<LineInfo>(nline);
     116           6 :     if (!linfo) { return false; }
     117          10 :     for (ii = 0; ii < nline; ii++)
     118             :     {
     119           4 :         linfo[ii].Read(hwpf, this);
     120             :     }
     121           6 :      if( etcflag & 0x04 ){
     122           0 :          hwpf.AddColumnInfo();
     123             :      }
     124             : 
     125           6 :     if (nch && !reuse_shape){
     126           4 :          if( pshape.coldef.ncols > 1 ){
     127           0 :              hwpf.SetColumnDef( &pshape.coldef );
     128             :          }
     129             :      }
     130             : 
     131             : 
     132           6 :     if( nline > 0 )
     133             :     {
     134           4 :         begin_ypos = linfo[0].pgy;
     135             :     }
     136             :     else
     137             :     {
     138           2 :         begin_ypos = 0;
     139             :     }
     140             : 
     141           6 :     if (contain_cshape)
     142             :     {
     143           4 :         cshapep = ::comphelper::newArray_null<CharShape>(nch);
     144           4 :         if (!cshapep)
     145             :         {
     146           0 :             perror("Memory Allocation: cshape\n");
     147           0 :             return false;
     148             :         }
     149             : 
     150          74 :         for (ii = 0; ii < nch; ii++)
     151             :         {
     152             : 
     153          70 :             hwpf.Read1b(&same_cshape, 1);
     154          70 :             if (!same_cshape)
     155             :             {
     156           4 :                 cshapep[ii].Read(hwpf);
     157           4 :                 if (nch > 1)
     158           4 :                     hwpf.AddCharShape(&cshapep[ii]);
     159             :             }
     160          66 :             else if (ii == 0)
     161           0 :                 cshapep[ii] = cshape;
     162             :             else
     163          66 :                 cshapep[ii] = cshapep[ii - 1];
     164             :         }
     165             :     }
     166             : // read string
     167           6 :     hhstr = ::comphelper::newArray_null<HBox *>(nch);
     168           6 :     if (!hhstr) { return false; }
     169          76 :     for (ii = 0; ii < nch; ii++)
     170          70 :         hhstr[ii] = 0;
     171           6 :     ii = 0;
     172          78 :     while (ii < nch)
     173             :     {
     174          70 :         if (0 == (hhstr[ii] = readHBox(hwpf)))
     175           0 :             return false;
     176          70 :         if (hhstr[ii]->hh == CH_END_PARA)
     177           4 :             break;
     178          66 :           if( hhstr[ii]->hh < CH_END_PARA )
     179           0 :                 pshape.reserved[0] = 0;
     180          66 :         ii += hhstr[ii]->WSize();
     181             :     }
     182           6 :     return nch && !hwpf.State();
     183             : }
     184             : 
     185             : 
     186           4 : HWPPara *HWPPara::Next(void)
     187             : {
     188           4 :     return _next;
     189             : }
     190             : 
     191             : 
     192          70 : CharShape *HWPPara::GetCharShape(int pos)
     193             : {
     194          70 :     if (contain_cshape == 0)
     195           0 :         return &cshape;
     196          70 :     return cshapep + pos;
     197             : }
     198             : 
     199             : 
     200           4 : ParaShape *HWPPara::GetParaShape(void)
     201             : {
     202           4 :     return &pshape;
     203             : }
     204             : 
     205             : 
     206          70 : HBox *HWPPara::readHBox(HWPFile & hwpf)
     207             : {
     208          70 :     hchar hh = sal::static_int_cast<hchar>(hwpf.Read2b());
     209          70 :     HBox *hbox = 0;
     210             : 
     211          70 :     if (hwpf.State() != HWP_NoError)
     212           0 :         return 0;
     213             : 
     214          70 :     if (hh > 31 || hh == CH_END_PARA)
     215          70 :         hbox = new HBox(hh);
     216           0 :     else if (IS_SP_SKIP_BLOCK(hh))
     217           0 :         hbox = new SkipData(hh);
     218             :     else
     219             :     {
     220           0 :         switch (hh)
     221             :         {
     222             :             case CH_FIELD:                        // 5
     223           0 :                 hbox = new FieldCode;
     224           0 :                 break;
     225             :             case CH_BOOKMARK:                     // 6
     226           0 :                 hbox = new Bookmark;
     227           0 :                 break;
     228             :             case CH_DATE_FORM:                    // 7
     229           0 :                 hbox = new DateFormat;
     230           0 :                 break;
     231             :             case CH_DATE_CODE:                    // 8
     232           0 :                 hbox = new DateCode;
     233           0 :                 break;
     234             :             case CH_TAB:                          // 9
     235           0 :                 hbox = new Tab;
     236           0 :                 break;
     237             :             case CH_TEXT_BOX:                     // 10
     238           0 :                 hbox = new TxtBox;
     239           0 :                 break;
     240             :             case CH_PICTURE:                      // 11
     241           0 :                 hbox = new Picture;
     242           0 :                 break;
     243             :             case CH_LINE:                         // 14
     244           0 :                 hbox = new Line;
     245           0 :                 break;
     246             :             case CH_HIDDEN:                       // 15
     247           0 :                 hbox = new Hidden;
     248           0 :                 break;
     249             :             case CH_HEADER_FOOTER:                // 16
     250           0 :                 hbox = new HeaderFooter;
     251           0 :                 break;
     252             :             case CH_FOOTNOTE:                     // 17
     253           0 :                 hbox = new Footnote;
     254           0 :                 break;
     255             :             case CH_AUTO_NUM:                     // 18
     256           0 :                 hbox = new AutoNum;
     257           0 :                 break;
     258             :             case CH_NEW_NUM:                      // 19
     259           0 :                 hbox = new NewNum;
     260           0 :                 break;
     261             :             case CH_SHOW_PAGE_NUM:                // 20
     262           0 :                 hbox = new ShowPageNum;
     263           0 :                 break;
     264             :             case CH_PAGE_NUM_CTRL:                // 21
     265           0 :                 hbox = new PageNumCtrl;
     266           0 :                 break;
     267             :             case CH_MAIL_MERGE:                   // 22
     268           0 :                 hbox = new MailMerge;
     269           0 :                 break;
     270             :             case CH_COMPOSE:                      // 23
     271           0 :                 hbox = new Compose;
     272           0 :                 break;
     273             :             case CH_HYPHEN:                       // 24
     274           0 :                 hbox = new Hyphen;
     275           0 :                 break;
     276             :             case CH_TOC_MARK:                     // 25
     277           0 :                 hbox = new TocMark;
     278           0 :                 break;
     279             :             case CH_INDEX_MARK:                   // 26
     280           0 :                 hbox = new IndexMark;
     281           0 :                 break;
     282             :             case CH_OUTLINE:                      // 28
     283           0 :                 hbox = new Outline;
     284           0 :                 break;
     285             :             case CH_KEEP_SPACE:                   // 30
     286           0 :                 hbox = new KeepSpace;
     287           0 :                 break;
     288             :             case CH_FIXED_SPACE:                  // 31
     289           0 :                 hbox = new FixedSpace;
     290           0 :                 break;
     291             :             default:
     292           0 :                 break;
     293             :         }
     294             :     }
     295          70 :     if (!hbox || !hbox->Read(hwpf))
     296             :     {
     297           0 :         delete hbox;
     298             : 
     299           0 :         return 0;
     300             :     }
     301          70 :     if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
     302             :     {
     303           0 :         FBox *fbox = static_cast<FBox *>(hbox);
     304           0 :         if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
     305             :         {
     306             :             //strange construct to compile without warning
     307           0 :             int nTemp = fbox->pgy;
     308           0 :             nTemp -= begin_ypos;
     309           0 :             fbox->pgy = sal::static_int_cast<short>(nTemp);
     310             :         }
     311             :     }
     312          70 :     return hbox;
     313             : }
     314             : 
     315             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10