1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "precompile.h"
22 #include <comphelper/newarray.hxx>
33 #define DATA static_cast<StyleData*>(style)
39 char name
[MAXSTYLENAME
+ 1];
45 static char buffer
[MAXSTYLENAME
+ 1];
59 char* HWPStyle::GetName(int n
) const
61 if (n
< 0 || n
>= nstyles
)
66 void HWPStyle::SetName(int n
, char const* name
)
68 if (n
< 0 || n
>= nstyles
)
73 #if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 10) && !defined __clang__
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Wstringop-truncation"
77 auto const p
= DATA
[n
].name
;
78 strncpy(p
, name
, MAXSTYLENAME
);
79 p
[MAXSTYLENAME
] = '\0'; // just in case, even though the array is zero-initialized
80 #if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 10) && !defined __clang__
81 #pragma GCC diagnostic pop
88 CharShape
* HWPStyle::GetCharShape(int n
) const
90 if (n
< 0 || n
>= nstyles
)
92 return &DATA
[n
].cshape
;
95 void HWPStyle::SetCharShape(int n
, CharShape
const* cshapep
)
97 if (n
>= 0 && n
< nstyles
)
100 DATA
[n
].cshape
= *cshapep
;
102 memset(&DATA
[n
].cshape
, 0, sizeof(CharShape
));
106 ParaShape
* HWPStyle::GetParaShape(int n
) const
108 if (n
< 0 || n
>= nstyles
)
110 return &DATA
[n
].pshape
;
113 void HWPStyle::SetParaShape(int n
, ParaShape
const* pshapep
)
115 if (n
>= 0 && n
< nstyles
)
118 DATA
[n
].pshape
= *pshapep
;
120 DATA
[n
].pshape
= ParaShape();
124 void HWPStyle::Read(HWPFile
& hwpf
)
129 hwpf
.Read2b(&nstyles
, 1);
130 style
= ::comphelper::newArray_null
<StyleData
>(nstyles
);
134 for (int ii
= 0; ii
< nstyles
; ii
++)
136 hwpf
.ReadBlock(buffer
, MAXSTYLENAME
);
141 SetCharShape(ii
, &cshape
);
142 SetParaShape(ii
, &pshape
);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */