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>
29 { MAXSTYLENAME
= 20 };
31 #define DATA static_cast<StyleData *>(style)
35 char name
[MAXSTYLENAME
+ 1];
40 static char buffer
[MAXSTYLENAME
+ 1];
56 char *HWPStyle::GetName(int n
) const
58 if (!(n
>= 0 && n
< nstyles
))
64 void HWPStyle::SetName(int n
, char const *name
)
66 if (n
>= 0 && n
< nstyles
)
70 #if defined __GNUC__ && (__GNUC__ == 8 || __GNUC__ == 9) && !defined __clang__
71 #pragma GCC diagnostic push
72 #pragma GCC diagnostic ignored "-Wstringop-truncation"
74 auto const p
= DATA
[n
].name
;
75 strncpy(p
, name
, MAXSTYLENAME
);
76 p
[MAXSTYLENAME
] = '\0'; // just in case, even though the array is zero-initialized
77 #if defined __GNUC__ && (__GNUC__ == 8 || __GNUC__ == 9) && !defined __clang__
78 #pragma GCC diagnostic pop
87 CharShape
*HWPStyle::GetCharShape(int n
) const
89 if (!(n
>= 0 && n
< nstyles
))
91 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
));
107 ParaShape
*HWPStyle::GetParaShape(int n
) const
109 if (!(n
>= 0 && n
< nstyles
))
111 return &DATA
[n
].pshape
;
115 void HWPStyle::SetParaShape(int n
, ParaShape
const * pshapep
)
117 if (n
>= 0 && n
< nstyles
)
120 DATA
[n
].pshape
= *pshapep
;
122 DATA
[n
].pshape
= ParaShape();
127 void HWPStyle::Read(HWPFile
& hwpf
)
132 hwpf
.Read2b(&nstyles
, 1);
133 style
= ::comphelper::newArray_null
<StyleData
>(nstyles
);
137 for (int ii
= 0; ii
< nstyles
; ii
++)
139 hwpf
.ReadBlock(buffer
, MAXSTYLENAME
);
144 SetCharShape(ii
, &cshape
);
145 SetParaShape(ii
, &pshape
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */