LCOV - code coverage report
Current view: top level - hwpfilter/source - hpara.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 163 0.0 %
Date: 2014-04-14 Functions: 0 8 0.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           0 : bool LineInfo::Read(HWPFile & hwpf, HWPPara *pPara)
      33             : {
      34           0 :     pos = sal::static_int_cast<unsigned short>(hwpf.Read2b());
      35           0 :     space_width = (short) hwpf.Read2b();
      36           0 :     height = (short) hwpf.Read2b();
      37             : // internal information
      38           0 :     pgy = (short) hwpf.Read2b();
      39           0 :     sx = (short) hwpf.Read2b();
      40           0 :     psx = (short) hwpf.Read2b();
      41           0 :     pex = (short) hwpf.Read2b();
      42           0 :     height_sp = 0;
      43             : 
      44           0 :     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           0 :     return (!hwpf.State());
      53             : }
      54             : 
      55             : 
      56           0 : HWPPara::HWPPara(void)
      57             : {
      58           0 :     _next = NULL;
      59           0 :     linfo = NULL;
      60           0 :     cshapep = NULL;
      61           0 :     hhstr = NULL;
      62           0 :     pno = 0;
      63             : 
      64           0 : }
      65             : 
      66             : 
      67           0 : HWPPara::~HWPPara(void)
      68             : {
      69           0 :     if (linfo)
      70           0 :         delete[]linfo;
      71           0 :     if (cshapep)
      72           0 :         delete[]cshapep;
      73           0 :     if (hhstr)
      74             :     {
      75             : // virtual destructor
      76             : /* C++은 null에 대해서도 동작한다. */
      77           0 :         for (int ii = 0; ii < nch; ++ii)
      78           0 :             delete hhstr[ii];
      79             : 
      80           0 :         delete[]hhstr;
      81             :     }
      82             : 
      83           0 : }
      84             : 
      85             : 
      86           0 : bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
      87             : {
      88             :     unsigned char same_cshape;
      89             :     int ii;
      90           0 :     scflag = flag;
      91             : // Paragraph Information
      92           0 :     hwpf.Read1b(&reuse_shape, 1);
      93           0 :     hwpf.Read2b(&nch, 1);
      94           0 :     hwpf.Read2b(&nline, 1);
      95           0 :     hwpf.Read1b(&contain_cshape, 1);
      96           0 :     hwpf.Read1b(&etcflag, 1);
      97           0 :     hwpf.Read4b(&ctrlflag, 1);
      98           0 :     hwpf.Read1b(&pstyno, 1);
      99             : 
     100             : 
     101             : /* Paragraph 대표 글자 */
     102           0 :     cshape.Read(hwpf);
     103           0 :     if (nch > 0)
     104           0 :         hwpf.AddCharShape(&cshape);
     105             : 
     106             : /* Paragraph 문단 모양 */
     107           0 :     if (nch && !reuse_shape)
     108             :     {
     109           0 :         pshape.Read(hwpf);
     110           0 :         pshape.cshape = &cshape;
     111           0 :           pshape.pagebreak = etcflag;
     112             :     }
     113             : 
     114           0 :     linfo = ::comphelper::newArray_null<LineInfo>(nline);
     115           0 :     if (!linfo) { return false; }
     116           0 :     for (ii = 0; ii < nline; ii++)
     117             :     {
     118           0 :         linfo[ii].Read(hwpf, this);
     119             :     }
     120           0 :      if( etcflag & 0x04 ){
     121           0 :          hwpf.AddColumnInfo();
     122             :      }
     123             : 
     124           0 :     if (nch && !reuse_shape){
     125           0 :          if( pshape.coldef.ncols > 1 ){
     126           0 :              hwpf.SetColumnDef( &pshape.coldef );
     127             :          }
     128             :      }
     129             : 
     130             : 
     131           0 :     if( nline > 0 )
     132             :     {
     133           0 :         begin_ypos = linfo[0].pgy;
     134             :     }
     135             :     else
     136             :     {
     137           0 :         begin_ypos = 0;
     138             :     }
     139             : 
     140           0 :     if (contain_cshape)
     141             :     {
     142           0 :         cshapep = ::comphelper::newArray_null<CharShape>(nch);
     143           0 :         if (!cshapep)
     144             :         {
     145           0 :             perror("Memory Allocation: cshape\n");
     146           0 :             return false;
     147             :         }
     148             : 
     149           0 :         for (ii = 0; ii < nch; ii++)
     150             :         {
     151             : 
     152           0 :             hwpf.Read1b(&same_cshape, 1);
     153           0 :             if (!same_cshape)
     154             :             {
     155           0 :                 cshapep[ii].Read(hwpf);
     156           0 :                 if (nch > 1)
     157           0 :                     hwpf.AddCharShape(&cshapep[ii]);
     158             :             }
     159           0 :             else if (ii == 0)
     160           0 :                 cshapep[ii] = cshape;
     161             :             else
     162           0 :                 cshapep[ii] = cshapep[ii - 1];
     163             :         }
     164             :     }
     165             : // read string
     166           0 :     hhstr = ::comphelper::newArray_null<HBox *>(nch);
     167           0 :     if (!hhstr) { return false; }
     168           0 :     for (ii = 0; ii < nch; ii++)
     169           0 :         hhstr[ii] = 0;
     170           0 :     ii = 0;
     171           0 :     while (ii < nch)
     172             :     {
     173           0 :         if (0 == (hhstr[ii] = readHBox(hwpf)))
     174           0 :             return false;
     175           0 :         if (hhstr[ii]->hh == CH_END_PARA)
     176           0 :             break;
     177           0 :           if( hhstr[ii]->hh < CH_END_PARA )
     178           0 :                 pshape.reserved[0] = 0;
     179           0 :         ii += hhstr[ii]->WSize();
     180             :     }
     181           0 :     return nch && !hwpf.State();
     182             : }
     183             : 
     184             : 
     185           0 : HWPPara *HWPPara::Next(void)
     186             : {
     187           0 :     return _next;
     188             : }
     189             : 
     190             : 
     191           0 : CharShape *HWPPara::GetCharShape(int pos)
     192             : {
     193           0 :     if (contain_cshape == 0)
     194           0 :         return &cshape;
     195           0 :     return cshapep + pos;
     196             : }
     197             : 
     198             : 
     199           0 : ParaShape *HWPPara::GetParaShape(void)
     200             : {
     201           0 :     return &pshape;
     202             : }
     203             : 
     204             : 
     205           0 : HBox *HWPPara::readHBox(HWPFile & hwpf)
     206             : {
     207           0 :     hchar hh = sal::static_int_cast<hchar>(hwpf.Read2b());
     208           0 :     HBox *hbox = 0;
     209             : 
     210           0 :     if (hwpf.State() != HWP_NoError)
     211           0 :         return 0;
     212             : 
     213           0 :     if (hh > 31 || hh == CH_END_PARA)
     214           0 :         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           0 :     if (!hbox || !hbox->Read(hwpf))
     295             :     {
     296           0 :         delete hbox;
     297             : 
     298           0 :         return 0;
     299             :     }
     300           0 :     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           0 :     return hbox;
     312             : }
     313             : 
     314             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10