update dev300-m58
[ooovba.git] / hwpfilter / source / hfont.cpp
blob1a6705b4b1b96a06e2ebb081f12d76365686fe2b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hfont.cpp,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 /* $Id: hfont.cpp,v 1.4 2008-06-04 09:56:49 vg Exp $ */
33 #include "precompile.h"
34 #include "hwplib.h"
35 #include "hwpfile.h"
36 #include "hfont.h"
37 /* ÀÌ ÇÔ¼ö´Â HWP ÆÄÀÏÀ» Çؼ®ÇÏ´Â ºÎºÐÀÌ´Ù. */
39 HWPFont::HWPFont(void)
41 for (int ii = 0; ii < NLanguage; ii++)
43 nFonts[ii] = 0;
44 fontnames[ii] = NULL;
49 HWPFont::~HWPFont(void)
51 for (int ii = 0; ii < NLanguage; ii++)
53 nFonts[ii] = 0;
54 delete[]fontnames[ii];
59 int HWPFont::AddFont(int lang, const char *font)
61 int nfonts;
63 if (!(lang >= 0 && lang < NLanguage))
64 return 0;
65 nfonts = nFonts[lang];
66 if (MAXFONTS <= nfonts)
67 return 0;
68 strncpy(fontnames[lang] + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
69 nFonts[lang]++;
70 return nfonts;
74 const char *HWPFont::GetFontName(int lang, int id)
76 if (!(lang >= 0 && lang < NLanguage))
77 return 0;
78 if (id < 0 || nFonts[lang] <= id)
79 return 0;
80 return fontnames[lang] + id * FONTNAMELEN;
84 static char buffer[FONTNAMELEN];
86 bool HWPFont::Read(HWPFile & hwpf)
88 int lang = 0;
89 short nfonts = 0;
91 //printf("HWPFont::Read : lang = %d\n",NLanguage);
92 for(lang = 0; lang < NLanguage; lang++)
94 hwpf.Read2b(&nfonts, 1);
95 if (!(nfonts > 0 && nfonts < MAXFONTS))
97 return !hwpf.SetState(HWP_InvalidFileFormat);
99 fontnames[lang] = new char[nfonts * FONTNAMELEN];
101 memset(fontnames[lang], 0, nfonts * FONTNAMELEN);
102 for (int jj = 0; jj < nfonts; jj++)
104 hwpf.ReadBlock(buffer, FONTNAMELEN);
105 AddFont(lang, buffer);
109 return !hwpf.State();