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

Generated by: LCOV version 1.10