LibreOffice Module hwpfilter (master) 1
hstyle.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
23
24#include "hwplib.h"
25#include "hwpfile.h"
26#include "hstyle.h"
27
28enum
29{
30 MAXSTYLENAME = 20
31};
32
33namespace hwpfilter
34{
36{
37 char name[MAXSTYLENAME + 1];
40};
41}
42
43static char buffer[MAXSTYLENAME + 1];
44
46{
47 nstyles = 0;
48 style = nullptr;
49}
50
52{
53 delete[] style;
54 nstyles = 0;
55}
56
57char* HWPStyle::GetName(int n) const
58{
59 if (n < 0 || n >= nstyles)
60 return nullptr;
61 return style[n].name;
62}
63
64void HWPStyle::SetName(int n, char const* name)
65{
66 if (n < 0 || n >= nstyles)
67 return;
68
69 if (name)
70 {
71#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 13) && !defined __clang__
72#pragma GCC diagnostic push
73#pragma GCC diagnostic ignored "-Wstringop-truncation"
74#endif
75 auto const p = style[n].name;
76 strncpy(p, name, MAXSTYLENAME);
77 p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized
78#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 13) && !defined __clang__
79#pragma GCC diagnostic pop
80#endif
81 }
82 else
83 style[n].name[0] = 0;
84}
85
87{
88 if (n < 0 || n >= nstyles)
89 return nullptr;
90 return &style[n].cshape;
91}
92
93void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
94{
95 if (n >= 0 && n < nstyles)
96 {
97 if (cshapep)
98 style[n].cshape = *cshapep;
99 else
100 style[n].cshape = CharShape();
101 }
102}
103
105{
106 if (n < 0 || n >= nstyles)
107 return nullptr;
108 return &style[n].pshape;
109}
110
111void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
112{
113 if (n >= 0 && n < nstyles)
114 {
115 if (pshapep)
116 style[n].pshape = *pshapep;
117 else
118 style[n].pshape = ParaShape();
119 }
120}
121
123{
124 CharShape cshape;
125 ParaShape pshape;
126
127 hwpf.Read2b(&nstyles, 1);
128 style = ::comphelper::newArray_null<hwpfilter::StyleData>(nstyles);
129 if (!style)
130 return;
131
132 for (int ii = 0; ii < nstyles; ii++)
133 {
135 cshape.Read(hwpf);
136 pshape.Read(hwpf);
137
138 SetName(ii, buffer);
139 SetCharShape(ii, &cshape);
140 SetParaShape(ii, &pshape);
141 if (hwpf.State())
142 return;
143 }
144}
145
146/* 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 State(void) const
Say current state.
Definition: hwpfile.h:119
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
CharShape * GetCharShape(int n) const
Definition: hstyle.cxx:86
void SetCharShape(int n, CharShape const *cshapep)
Definition: hstyle.cxx:93
HWPStyle(void)
Definition: hstyle.cxx:45
ParaShape * GetParaShape(int n) const
Definition: hstyle.cxx:104
short nstyles
Definition: hstyle.h:36
char * GetName(int n) const
Definition: hstyle.cxx:57
hwpfilter::StyleData * style
Definition: hstyle.h:37
void SetName(int n, char const *name)
Definition: hstyle.cxx:64
void Read(HWPFile &hwpf)
Definition: hstyle.cxx:122
~HWPStyle(void)
Definition: hstyle.cxx:51
void SetParaShape(int n, ParaShape const *pshapep)
Definition: hstyle.cxx:111
static char buffer[MAXSTYLENAME+1]
Definition: hstyle.cxx:43
@ MAXSTYLENAME
Definition: hstyle.cxx:30
const char * name
Definition: hwpreader.cxx:365
void * p
sal_Int64 n
Style of character.
Definition: hinfo.h:213
void Read(HWPFile &)
Definition: hinfo.cxx:273
Style of paragraph.
Definition: hinfo.h:276
void Read(HWPFile &)
Definition: hinfo.cxx:210
char name[MAXSTYLENAME+1]
Definition: hstyle.cxx:37
CharShape cshape
Definition: hstyle.cxx:38
ParaShape pshape
Definition: hstyle.cxx:39