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

Generated by: LCOV version 1.10