LCOV - code coverage report
Current view: top level - hwpfilter/source - hfont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 38 86.8 %
Date: 2015-06-13 12:38:46 Functions: 5 5 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             : #include "hwplib.h"
      22             : #include "hwpfile.h"
      23             : #include "hfont.h"
      24             : /* 이 함수는 HWP 파일을 해석하는 부분이다. */
      25             : 
      26          86 : HWPFont::HWPFont()
      27             : {
      28         688 :     for (int ii = 0; ii < NLanguage; ii++)
      29             :     {
      30         602 :         nFonts[ii] = 0;
      31         602 :         fontnames[ii] = NULL;
      32             :     }
      33          86 : }
      34             : 
      35             : 
      36          86 : HWPFont::~HWPFont()
      37             : {
      38         688 :     for (int ii = 0; ii < NLanguage; ii++)
      39             :     {
      40         602 :         nFonts[ii] = 0;
      41         602 :         delete[]fontnames[ii];
      42             :     }
      43          86 : }
      44             : 
      45             : 
      46         703 : int HWPFont::AddFont(int lang, const char *font)
      47             : {
      48             :     int nfonts;
      49             : 
      50         703 :     if (!(lang >= 0 && lang < NLanguage))
      51           0 :         return 0;
      52         703 :     nfonts = nFonts[lang];
      53         703 :     if (MAXFONTS <= nfonts)
      54           0 :         return 0;
      55         703 :     strncpy(fontnames[lang] + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
      56         703 :     nFonts[lang]++;
      57         703 :     return nfonts;
      58             : }
      59             : 
      60             : 
      61          14 : const char *HWPFont::GetFontName(int lang, int id)
      62             : {
      63          14 :     if (!(lang >= 0 && lang < NLanguage))
      64           0 :         return 0;
      65          14 :     if (id < 0 || nFonts[lang] <= id)
      66           0 :         return 0;
      67          14 :     return fontnames[lang] + id * FONTNAMELEN;
      68             : }
      69             : 
      70             : 
      71             : static char buffer[FONTNAMELEN];
      72             : 
      73           1 : bool HWPFont::Read(HWPFile & hwpf)
      74             : {
      75           1 :     int lang = 0;
      76           1 :     short nfonts = 0;
      77             : 
      78             : //printf("HWPFont::Read : lang = %d\n",NLanguage);
      79           8 :     for(lang = 0; lang < NLanguage; lang++)
      80             :     {
      81           7 :         hwpf.Read2b(&nfonts, 1);
      82           7 :         if (!(nfonts > 0 && nfonts < MAXFONTS))
      83             :         {
      84           0 :             return !hwpf.SetState(HWP_InvalidFileFormat);
      85             :         }
      86           7 :         fontnames[lang] = new char[nfonts * FONTNAMELEN];
      87             : 
      88           7 :         memset(fontnames[lang], 0, nfonts * FONTNAMELEN);
      89         710 :         for (int jj = 0; jj < nfonts; jj++)
      90             :         {
      91         703 :             hwpf.ReadBlock(buffer, FONTNAMELEN);
      92         703 :             AddFont(lang, buffer);
      93             :         }
      94             :     }
      95             : 
      96           1 :     return !hwpf.State();
      97             : }
      98             : 
      99             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11