LCOV - code coverage report
Current view: top level - libreoffice/hwpfilter/source - hstyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 55 85.5 %
Date: 2012-12-27 Functions: 10 10 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 <comphelper/newarray.hxx>
      23             : 
      24             : #include    "hwplib.h"
      25             : #include    "hwpfile.h"
      26             : #include    "hstyle.h"
      27             : 
      28             : enum
      29             : { MAXSTYLENAME = 20 };
      30             : 
      31             : #define DATA ((StyleData *)style)
      32             : 
      33             : struct StyleData
      34             : {
      35             :     char name[MAXSTYLENAME + 1];
      36             :     CharShape cshape;
      37             :     ParaShape pshape;
      38             : };
      39             : 
      40             : static char buffer[MAXSTYLENAME + 1];
      41             : 
      42           1 : HWPStyle::HWPStyle(void)
      43             : {
      44           1 :     nstyles = 0;
      45           1 :     style = 0;
      46           1 : }
      47             : 
      48             : 
      49           1 : HWPStyle::~HWPStyle(void)
      50             : {
      51           1 :     delete[]DATA;
      52           1 :     nstyles = 0;
      53           1 : }
      54             : 
      55             : 
      56          13 : int HWPStyle::Num(void) const
      57             : {
      58          13 :     return nstyles;
      59             : }
      60             : 
      61             : 
      62          12 : char *HWPStyle::GetName(int n) const
      63             : {
      64          12 :     if (!(n >= 0 && n < nstyles))
      65           0 :         return 0;
      66          12 :     return DATA[n].name;
      67             : }
      68             : 
      69             : 
      70          12 : void HWPStyle::SetName(int n, char *name)
      71             : {
      72          12 :     if (n >= 0 && n < nstyles)
      73             :     {
      74          12 :         if (name)
      75          12 :             strncpy(DATA[n].name, name, MAXSTYLENAME);
      76             :         else
      77           0 :             DATA[n].name[0] = 0;
      78             :     }
      79          12 : }
      80             : 
      81             : 
      82          12 : CharShape *HWPStyle::GetCharShape(int n) const
      83             : {
      84          12 :     if (!(n >= 0 && n < nstyles))
      85           0 :         return 0;
      86          12 :     return &DATA[n].cshape;
      87             : }
      88             : 
      89             : 
      90          12 : void HWPStyle::SetCharShape(int n, CharShape * cshapep)
      91             : {
      92          12 :     if (n >= 0 && n < nstyles)
      93             :     {
      94          12 :         if (cshapep)
      95          12 :             DATA[n].cshape = *cshapep;
      96             :         else
      97           0 :             memset(&DATA[n].cshape, 0, sizeof(CharShape));
      98             :     }
      99          12 : }
     100             : 
     101             : 
     102          12 : ParaShape *HWPStyle::GetParaShape(int n) const
     103             : {
     104          12 :     if (!(n >= 0 && n < nstyles))
     105           0 :         return 0;
     106          12 :     return &DATA[n].pshape;
     107             : }
     108             : 
     109             : 
     110          12 : void HWPStyle::SetParaShape(int n, ParaShape * pshapep)
     111             : {
     112          12 :     if (n >= 0 && n < nstyles)
     113             :     {
     114          12 :         if (pshapep)
     115          12 :             DATA[n].pshape = *pshapep;
     116             :         else
     117           0 :             memset(&DATA[n].pshape, 0, sizeof(ParaShape));
     118             :     }
     119          12 : }
     120             : 
     121             : 
     122           1 : bool HWPStyle::Read(HWPFile & hwpf)
     123             : {
     124             :     CharShape cshape;
     125             :     ParaShape pshape;
     126             : 
     127           1 :     hwpf.Read2b(&nstyles, 1);
     128           1 :     style = ::comphelper::newArray_null<StyleData>(nstyles);
     129           1 :     if (!style)
     130           0 :         return false;
     131             : 
     132          13 :     for (int ii = 0; ii < nstyles; ii++)
     133             :     {
     134          12 :         hwpf.ReadBlock(buffer, MAXSTYLENAME);
     135          12 :         cshape.Read(hwpf);
     136          12 :         pshape.Read(hwpf);
     137             : 
     138          12 :         SetName(ii, buffer);
     139          12 :         SetCharShape(ii, &cshape);
     140          12 :         SetParaShape(ii, &pshape);
     141          12 :         if (hwpf.State())
     142           0 :             return false;
     143             :     }
     144           1 :     return true;
     145             : }
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10