nss: upgrade to release 3.73
[LibreOffice.git] / hwpfilter / source / hstyle.cxx
blob33f143440c321bd083de02e3ebbf64ec7613dbff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include "hwplib.h"
25 #include "hwpfile.h"
26 #include "hstyle.h"
28 enum
30 MAXSTYLENAME = 20
33 #define DATA static_cast<StyleData*>(style)
35 namespace
37 struct StyleData
39 char name[MAXSTYLENAME + 1];
40 CharShape cshape;
41 ParaShape pshape;
45 static char buffer[MAXSTYLENAME + 1];
47 HWPStyle::HWPStyle()
49 nstyles = 0;
50 style = nullptr;
53 HWPStyle::~HWPStyle()
55 delete[] DATA;
56 nstyles = 0;
59 char* HWPStyle::GetName(int n) const
61 if (n < 0 || n >= nstyles)
62 return nullptr;
63 return DATA[n].name;
66 void HWPStyle::SetName(int n, char const* name)
68 if (n < 0 || n >= nstyles)
69 return;
71 if (name)
73 #if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 10) && !defined __clang__
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Wstringop-truncation"
76 #endif
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
82 #endif
84 else
85 DATA[n].name[0] = 0;
88 CharShape* HWPStyle::GetCharShape(int n) const
90 if (n < 0 || n >= nstyles)
91 return nullptr;
92 return &DATA[n].cshape;
95 void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
97 if (n >= 0 && n < nstyles)
99 if (cshapep)
100 DATA[n].cshape = *cshapep;
101 else
102 memset(&DATA[n].cshape, 0, sizeof(CharShape));
106 ParaShape* HWPStyle::GetParaShape(int n) const
108 if (n < 0 || n >= nstyles)
109 return nullptr;
110 return &DATA[n].pshape;
113 void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
115 if (n >= 0 && n < nstyles)
117 if (pshapep)
118 DATA[n].pshape = *pshapep;
119 else
120 DATA[n].pshape = ParaShape();
124 void HWPStyle::Read(HWPFile& hwpf)
126 CharShape cshape;
127 ParaShape pshape;
129 hwpf.Read2b(&nstyles, 1);
130 style = ::comphelper::newArray_null<StyleData>(nstyles);
131 if (!style)
132 return;
134 for (int ii = 0; ii < nstyles; ii++)
136 hwpf.ReadBlock(buffer, MAXSTYLENAME);
137 cshape.Read(hwpf);
138 pshape.Read(hwpf);
140 SetName(ii, buffer);
141 SetCharShape(ii, &cshape);
142 SetParaShape(ii, &pshape);
143 if (hwpf.State())
144 return;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */