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

Generated by: LCOV version 1.10