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
HWPFont()26 HWPFont::HWPFont()
27 {
28 for (int ii = 0; ii < NLanguage; ii++)
29 {
30 nFonts[ii] = 0;
31 fontnames[ii] = nullptr;
32 }
33 }
34
35
~HWPFont()36 HWPFont::~HWPFont()
37 {
38 }
39
40
AddFont(int lang,const char * font)41 void HWPFont::AddFont(int lang, const char *font)
42 {
43 int nfonts;
44
45 if (!(lang >= 0 && lang < NLanguage))
46 return;
47 nfonts = nFonts[lang];
48 if (MAXFONTS <= nfonts)
49 return;
50 auto const p = fontnames[lang].get() + FONTNAMELEN * nfonts;
51 strncpy(p, font, FONTNAMELEN - 1);
52 p[FONTNAMELEN - 1] = '\0'; // just in case, even though the array is zero-initialized
53 nFonts[lang]++;
54 }
55
56
GetFontName(int lang,int id)57 const char *HWPFont::GetFontName(int lang, int id)
58 {
59 if (!(lang >= 0 && lang < NLanguage))
60 return nullptr;
61 if (id < 0 || nFonts[lang] <= id)
62 return nullptr;
63 return fontnames[lang].get() + id * FONTNAMELEN;
64 }
65
66
67 static char buffer[FONTNAMELEN];
68
Read(HWPFile & hwpf)69 void HWPFont::Read(HWPFile & hwpf)
70 {
71 int lang = 0;
72 short nfonts = 0;
73
74 //printf("HWPFont::Read : lang = %d\n",NLanguage);
75 for(lang = 0; lang < NLanguage; lang++)
76 {
77 hwpf.Read2b(&nfonts, 1);
78 if (!(nfonts > 0 && nfonts < MAXFONTS))
79 {
80 (void)hwpf.SetState(HWP_InvalidFileFormat);
81 return;
82 }
83 fontnames[lang].reset(new char[nfonts * FONTNAMELEN]);
84
85 memset(fontnames[lang].get(), 0, nfonts * FONTNAMELEN);
86 for (int jj = 0; jj < nfonts; jj++)
87 {
88 hwpf.ReadBlock(buffer, FONTNAMELEN);
89 AddFont(lang, buffer);
90 }
91 }
92 }
93
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
95