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

Generated by: LCOV version 1.11