LCOV - code coverage report
Current view: top level - hwpfilter/source - hfont.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 33 38 86.8 %
Date: 2014-11-03 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           2 : HWPFont::HWPFont(void)
      27             : {
      28          16 :     for (int ii = 0; ii < NLanguage; ii++)
      29             :     {
      30          14 :         nFonts[ii] = 0;
      31          14 :         fontnames[ii] = NULL;
      32             :     }
      33           2 : }
      34             : 
      35             : 
      36           2 : HWPFont::~HWPFont(void)
      37             : {
      38          16 :     for (int ii = 0; ii < NLanguage; ii++)
      39             :     {
      40          14 :         nFonts[ii] = 0;
      41          14 :         delete[]fontnames[ii];
      42             :     }
      43           2 : }
      44             : 
      45             : 
      46        1406 : int HWPFont::AddFont(int lang, const char *font)
      47             : {
      48             :     int nfonts;
      49             : 
      50        1406 :     if (!(lang >= 0 && lang < NLanguage))
      51           0 :         return 0;
      52        1406 :     nfonts = nFonts[lang];
      53        1406 :     if (MAXFONTS <= nfonts)
      54           0 :         return 0;
      55        1406 :     strncpy(fontnames[lang] + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
      56        1406 :     nFonts[lang]++;
      57        1406 :     return nfonts;
      58             : }
      59             : 
      60             : 
      61          28 : const char *HWPFont::GetFontName(int lang, int id)
      62             : {
      63          28 :     if (!(lang >= 0 && lang < NLanguage))
      64           0 :         return 0;
      65          28 :     if (id < 0 || nFonts[lang] <= id)
      66           0 :         return 0;
      67          28 :     return fontnames[lang] + id * FONTNAMELEN;
      68             : }
      69             : 
      70             : 
      71             : static char buffer[FONTNAMELEN];
      72             : 
      73           2 : bool HWPFont::Read(HWPFile & hwpf)
      74             : {
      75           2 :     int lang = 0;
      76           2 :     short nfonts = 0;
      77             : 
      78             : //printf("HWPFont::Read : lang = %d\n",NLanguage);
      79          16 :     for(lang = 0; lang < NLanguage; lang++)
      80             :     {
      81          14 :         hwpf.Read2b(&nfonts, 1);
      82          14 :         if (!(nfonts > 0 && nfonts < MAXFONTS))
      83             :         {
      84           0 :             return !hwpf.SetState(HWP_InvalidFileFormat);
      85             :         }
      86          14 :         fontnames[lang] = new char[nfonts * FONTNAMELEN];
      87             : 
      88          14 :         memset(fontnames[lang], 0, nfonts * FONTNAMELEN);
      89        1420 :         for (int jj = 0; jj < nfonts; jj++)
      90             :         {
      91        1406 :             hwpf.ReadBlock(buffer, FONTNAMELEN);
      92        1406 :             AddFont(lang, buffer);
      93             :         }
      94             :     }
      95             : 
      96           2 :     return !hwpf.State();
      97             : }
      98             : 
      99             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10