LibreOffice Module hwpfilter (master) 1
hfont.cxx
Go to the documentation of this file.
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
27{
28 for (int ii = 0; ii < NLanguage; ii++)
29 {
30 nFonts[ii] = 0;
31 fontnames[ii] = nullptr;
32 }
33}
34
36
37void HWPFont::AddFont(int lang, const char* font)
38{
39 int nfonts;
40
41 if (lang < 0 || lang >= NLanguage)
42 return;
43 nfonts = nFonts[lang];
44 if (MAXFONTS <= nfonts)
45 return;
46 auto const p = fontnames[lang].get() + FONTNAMELEN * nfonts;
47 strncpy(p, font, FONTNAMELEN - 1);
48 p[FONTNAMELEN - 1] = '\0'; // just in case, even though the array is zero-initialized
49 nFonts[lang]++;
50}
51
52const char* HWPFont::GetFontName(int lang, int id)
53{
54 if (lang < 0 || lang >= NLanguage)
55 return nullptr;
56 if (id < 0 || nFonts[lang] <= id)
57 return nullptr;
58 return fontnames[lang].get() + id * FONTNAMELEN;
59}
60
61static char buffer[FONTNAMELEN];
62
64{
65 int lang = 0;
66 short nfonts = 0;
67
68 //printf("HWPFont::Read : lang = %d\n",NLanguage);
69 for (lang = 0; lang < NLanguage; lang++)
70 {
71 hwpf.Read2b(&nfonts, 1);
72 if (nfonts <= 0 || nfonts >= MAXFONTS)
73 {
75 return;
76 }
77 fontnames[lang].reset(new char[nfonts * FONTNAMELEN]);
78
79 memset(fontnames[lang].get(), 0, nfonts * FONTNAMELEN);
80 for (int jj = 0; jj < nfonts; jj++)
81 {
83 AddFont(lang, buffer);
84 }
85 }
86}
87
88/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
int SetState(int errcode)
Sets the current state.
Definition: hwpfile.cxx:117
bool Read2b(unsigned short &out)
Reads two byte from HIODev.
Definition: hwpfile.cxx:137
size_t ReadBlock(void *ptr, size_t size)
Reads some bytes from HIODev not regarding endian's way.
Definition: hwpfile.cxx:171
const char * GetFontName(int lang, int id)
Definition: hfont.cxx:52
~HWPFont(void)
Definition: hfont.cxx:35
HWPFont(void)
Definition: hfont.cxx:26
void AddFont(int lang, const char *font)
Adds a font into font list of a language.
Definition: hfont.cxx:37
int nFonts[NLanguage]
System font count for each language NLanguage is 7 in common case.
Definition: hfont.h:42
std::unique_ptr< char[]> fontnames[NLanguage]
list of the font family name
Definition: hfont.h:46
void Read(HWPFile &hwpf)
Definition: hfont.cxx:63
static char buffer[FONTNAMELEN]
Definition: hfont.cxx:61
#define FONTNAMELEN
Definition: hfont.h:28
#define MAXFONTS
Definition: hfont.h:27
@ HWP_InvalidFileFormat
Definition: hwplib.h:179
#define NLanguage
Definition: hwplib.h:115
void * p
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)