summaryrefslogtreecommitdiffstats
path: root/hwpfilter/source
diff options
context:
space:
mode:
Diffstat (limited to 'hwpfilter/source')
-rw-r--r--hwpfilter/source/attributes.cxx151
-rw-r--r--hwpfilter/source/attributes.hxx61
-rw-r--r--hwpfilter/source/cspline.cxx160
-rw-r--r--hwpfilter/source/cspline.h30
-rw-r--r--hwpfilter/source/datecode.h27
-rw-r--r--hwpfilter/source/drawdef.h243
-rw-r--r--hwpfilter/source/drawing.h708
-rw-r--r--hwpfilter/source/fontmap.cxx166
-rw-r--r--hwpfilter/source/fontmap.hxx29
-rw-r--r--hwpfilter/source/formula.cxx651
-rw-r--r--hwpfilter/source/formula.h76
-rw-r--r--hwpfilter/source/grammar.cxx918
-rw-r--r--hwpfilter/source/grammar.h57
-rw-r--r--hwpfilter/source/grammar.hxx31
-rw-r--r--hwpfilter/source/hbox.cxx715
-rw-r--r--hwpfilter/source/hbox.h1007
-rw-r--r--hwpfilter/source/hcode.cxx1416
-rw-r--r--hwpfilter/source/hcode.h74
-rw-r--r--hwpfilter/source/hfont.cxx88
-rw-r--r--hwpfilter/source/hfont.h69
-rw-r--r--hwpfilter/source/hgzip.cxx298
-rw-r--r--hwpfilter/source/hgzip.h93
-rw-r--r--hwpfilter/source/hinfo.cxx288
-rw-r--r--hwpfilter/source/hinfo.h304
-rw-r--r--hwpfilter/source/hiodev.cxx355
-rw-r--r--hwpfilter/source/hiodev.h162
-rw-r--r--hwpfilter/source/hpara.cxx306
-rw-r--r--hwpfilter/source/hpara.h147
-rw-r--r--hwpfilter/source/hstream.cxx52
-rw-r--r--hwpfilter/source/hstream.hxx50
-rw-r--r--hwpfilter/source/hstyle.cxx146
-rw-r--r--hwpfilter/source/hstyle.h56
-rw-r--r--hwpfilter/source/htags.cxx133
-rw-r--r--hwpfilter/source/htags.h74
-rw-r--r--hwpfilter/source/hutil.cxx84
-rw-r--r--hwpfilter/source/hutil.h35
-rw-r--r--hwpfilter/source/hwp.component27
-rw-r--r--hwpfilter/source/hwpeq.cxx800
-rw-r--r--hwpfilter/source/hwpeq.h29
-rw-r--r--hwpfilter/source/hwpfile.cxx671
-rw-r--r--hwpfilter/source/hwpfile.h332
-rw-r--r--hwpfilter/source/hwplib.h226
-rw-r--r--hwpfilter/source/hwpread.cxx930
-rw-r--r--hwpfilter/source/hwpreader.cxx4816
-rw-r--r--hwpfilter/source/hwpreader.hxx164
-rw-r--r--hwpfilter/source/ksc5601.h863
-rw-r--r--hwpfilter/source/lexer.cxx2129
-rw-r--r--hwpfilter/source/lexer.hxx27
-rw-r--r--hwpfilter/source/mapping.h395
-rw-r--r--hwpfilter/source/mzstring.cxx268
-rw-r--r--hwpfilter/source/mzstring.h167
-rw-r--r--hwpfilter/source/nodes.h99
-rw-r--r--hwpfilter/source/precompile.h26
-rw-r--r--hwpfilter/source/solver.cxx147
-rw-r--r--hwpfilter/source/solver.h41
55 files changed, 21417 insertions, 0 deletions
diff --git a/hwpfilter/source/attributes.cxx b/hwpfilter/source/attributes.cxx
new file mode 100644
index 000000000..602165ba0
--- /dev/null
+++ b/hwpfilter/source/attributes.cxx
@@ -0,0 +1,151 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <assert.h>
+#include <vector>
+#include "attributes.hxx"
+
+namespace {
+
+struct TagAttribute
+{
+ TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
+ : sName(rName), sType(rType), sValue(rValue)
+ {
+ }
+
+ OUString sName;
+ OUString sType;
+ OUString sValue;
+};
+
+}
+
+struct AttributeListImpl_impl
+{
+ AttributeListImpl_impl()
+ {
+// performance improvement during adding
+ vecAttribute.reserve(20);
+ }
+ std::vector<struct TagAttribute> vecAttribute;
+};
+
+sal_Int16 SAL_CALL AttributeListImpl::getLength()
+{
+ return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
+}
+
+
+AttributeListImpl::AttributeListImpl( const AttributeListImpl &r )
+ : cppu::WeakImplHelper<css::xml::sax::XAttributeList>( r ),
+ m_pImpl( new AttributeListImpl_impl )
+{
+ *m_pImpl = *(r.m_pImpl);
+}
+
+
+OUString AttributeListImpl::getNameByIndex(sal_Int16 i)
+{
+ sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
+ if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
+ {
+ return m_pImpl->vecAttribute[i].sName;
+ }
+ return OUString();
+}
+
+
+OUString AttributeListImpl::getTypeByIndex(sal_Int16 i)
+{
+ sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
+ if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
+ {
+ return m_pImpl->vecAttribute[i].sType;
+ }
+ return OUString();
+}
+
+
+OUString AttributeListImpl::getValueByIndex(sal_Int16 i)
+{
+ sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
+ if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
+ {
+ return m_pImpl->vecAttribute[i].sValue;
+ }
+ return OUString();
+
+}
+
+
+OUString AttributeListImpl::getTypeByName( const OUString& sName )
+{
+ for (auto const& elem : m_pImpl->vecAttribute)
+ {
+ if( elem.sName == sName )
+ {
+ return elem.sType;
+ }
+ }
+ return OUString();
+}
+
+
+OUString AttributeListImpl::getValueByName(const OUString& sName)
+{
+ for (auto const& elem : m_pImpl->vecAttribute)
+ {
+ if( elem.sName == sName )
+ {
+ return elem.sValue;
+ }
+ }
+ return OUString();
+}
+
+
+AttributeListImpl::AttributeListImpl()
+ : m_pImpl( new AttributeListImpl_impl )
+{
+}
+
+
+AttributeListImpl::~AttributeListImpl()
+{
+}
+
+
+void AttributeListImpl::addAttribute( const OUString &sName ,
+const OUString &sType ,
+const OUString &sValue )
+{
+ m_pImpl->vecAttribute.emplace_back( sName , sType , sValue );
+}
+
+
+void AttributeListImpl::clear()
+{
+ std::vector<struct TagAttribute>().swap(m_pImpl->vecAttribute);
+
+ assert( ! getLength() );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/attributes.hxx b/hwpfilter/source/attributes.hxx
new file mode 100644
index 000000000..09dc26a03
--- /dev/null
+++ b/hwpfilter/source/attributes.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_ATTRIBUTES_HXX
+#define INCLUDED_HWPFILTER_SOURCE_ATTRIBUTES_HXX
+
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <memory>
+
+using namespace ::cppu;
+using namespace ::com::sun::star::xml::sax;
+using namespace ::com::sun::star::uno;
+
+struct AttributeListImpl_impl;
+class AttributeListImpl : public WeakImplHelper< XAttributeList >
+{
+protected:
+ virtual ~AttributeListImpl() override;
+
+public:
+ AttributeListImpl();
+ AttributeListImpl( const AttributeListImpl & );
+
+public:
+ virtual sal_Int16 SAL_CALL getLength() override;
+ virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override;
+ virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override;
+ virtual OUString SAL_CALL getTypeByName(const OUString& aName) override;
+ virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override;
+ virtual OUString SAL_CALL getValueByName(const OUString& aName) override;
+
+public:
+ void addAttribute( const OUString &sName , const OUString &sType , const OUString &sValue );
+ void clear();
+
+private:
+ std::unique_ptr<AttributeListImpl_impl> m_pImpl;
+};
+
+#endif // INCLUDED_HWPFILTER_SOURCE_ATTRIBUTES_HXX
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/cspline.cxx b/hwpfilter/source/cspline.cxx
new file mode 100644
index 000000000..0fdbd26a7
--- /dev/null
+++ b/hwpfilter/source/cspline.cxx
@@ -0,0 +1,160 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+// Natural, Clamped, or Periodic Cubic Splines
+//
+// Input: A list of N+1 points (x_i,a_i), 0 <= i <= N, which are sampled
+// from a function, a_i = f(x_i). The function f is unknown. Boundary
+// conditions are
+// (1) Natural splines: f"(x_0) = f"(x_N) = 0
+// (2) Clamped splines: f'(x_0) and f'(x_N) are user-specified.
+// (3) Periodic splines: f(x_0) = f(x_N) [in which case a_N = a_0 is
+// required in the input], f'(x_0) = f'(x_N), and f"(x_0) = f"(x_N).
+//
+// Output: b_i, c_i, d_i, 0 <= i <= N-1, which are coefficients for the cubic
+// spline S_i(x) = a_i + b_i(x-x_i) + c_i(x-x_i)^2 + d_i(x-x_i)^3 for
+// x_i <= x < x_{i+1}.
+//
+// The natural and clamped algorithms were implemented from
+//
+// Numerical Analysis, 3rd edition
+// Richard L. Burden and J. Douglas Faires
+// Prindle, Weber & Schmidt
+// Boston, 1985, pp. 122-124.
+//
+// The algorithm sets up a tridiagonal linear system of equations in the
+// c_i values. This can be solved in O(N) time.
+//
+// The periodic spline algorithm was implemented from my own derivation. The
+// linear system of equations is not tridiagonal. For now I use a standard
+// linear solver that does not take advantage of the sparseness of the
+// matrix. Therefore for very large N, you may have to worry about memory
+// usage.
+
+#include <sal/config.h>
+#include <memory>
+
+#include "cspline.h"
+#include "solver.h"
+
+void NaturalSpline (int N, const double* x, const double* a, std::unique_ptr<double[]>& b, std::unique_ptr<double[]>& c,
+ std::unique_ptr<double[]>& d)
+{
+ const double oneThird = 1.0/3.0;
+
+ int i;
+ std::unique_ptr<double[]> h(new double[N]);
+ std::unique_ptr<double[]> hdiff(new double[N]);
+ std::unique_ptr<double[]> alpha(new double[N]);
+
+ for (i = 0; i < N; i++){
+ h[i] = x[i+1]-x[i];
+ }
+
+ for (i = 1; i < N; i++)
+ hdiff[i] = x[i+1]-x[i-1];
+
+ for (i = 1; i < N; i++)
+ {
+ double numer = 3.0*(a[i+1]*h[i-1]-a[i]*hdiff[i]+a[i-1]*h[i]);
+ double denom = h[i-1]*h[i];
+ alpha[i] = numer/denom;
+ }
+
+ std::unique_ptr<double[]> ell(new double[N+1]);
+ std::unique_ptr<double[]> mu(new double[N]);
+ std::unique_ptr<double[]> z(new double[N+1]);
+ double recip;
+
+ ell[0] = 1.0;
+ mu[0] = 0.0;
+ z[0] = 0.0;
+
+ for (i = 1; i < N; i++)
+ {
+ ell[i] = 2.0*hdiff[i]-h[i-1]*mu[i-1];
+ recip = 1.0/ell[i];
+ mu[i] = recip*h[i];
+ z[i] = recip*(alpha[i]-h[i-1]*z[i-1]);
+ }
+ ell[N] = 1.0;
+ z[N] = 0.0;
+
+ b.reset(new double[N]);
+ c.reset(new double[N+1]);
+ d.reset(new double[N]);
+
+ c[N] = 0.0;
+
+ for (i = N-1; i >= 0; i--)
+ {
+ c[i] = z[i]-mu[i]*c[i+1];
+ recip = 1.0/h[i];
+ b[i] = recip*(a[i+1]-a[i])-h[i]*(c[i+1]+2.0*c[i])*oneThird;
+ d[i] = oneThird*recip*(c[i+1]-c[i]);
+ }
+}
+
+void PeriodicSpline (int N, const double* x, const double* a, std::unique_ptr<double[]>& b, std::unique_ptr<double[]>& c,
+ std::unique_ptr<double[]>& d)
+{
+ std::unique_ptr<double[]> h(new double[N]);
+ int i;
+ for (i = 0; i < N; i++)
+ h[i] = x[i+1]-x[i];
+
+ std::unique_ptr<std::unique_ptr<double[]>[]> mat = mgcLinearSystemD::NewMatrix(N+1); // guaranteed to be zeroed memory
+ c = mgcLinearSystemD::NewVector(N+1); // guaranteed to be zeroed memory
+
+ // c[0] - c[N] = 0
+ mat[0][0] = +1.0f;
+ mat[0][N] = -1.0f;
+
+ // h[i-1]*c[i-1]+2*(h[i-1]+h[i])*c[i]+h[i]*c[i+1] =
+ // 3*{(a[i+1]-a[i])/h[i] - (a[i]-a[i-1])/h[i-1]}
+ for (i = 1; i <= N-1; i++)
+ {
+ mat[i][i-1] = h[i-1];
+ mat[i][i ] = 2.0f*(h[i-1]+h[i]);
+ mat[i][i+1] = h[i];
+ c[i] = 3.0f*((a[i+1]-a[i])/h[i] - (a[i]-a[i-1])/h[i-1]);
+ }
+
+ // "wrap around equation" for periodicity
+ // h[N-1]*c[N-1]+2*(h[N-1]+h[0])*c[0]+h[0]*c[1] =
+ // 3*{(a[1]-a[0])/h[0] - (a[0]-a[N-1])/h[N-1]}
+ mat[N][N-1] = h[N-1];
+ mat[N][0 ] = 2.0f*(h[N-1]+h[0]);
+ mat[N][1 ] = h[0];
+ c[N] = 3.0f*((a[1]-a[0])/h[0] - (a[0]-a[N-1])/h[N-1]);
+
+ // solve for c[0] through c[N]
+ mgcLinearSystemD::Solve(N+1,mat,c.get());
+
+ const double oneThird = 1.0/3.0;
+ b.reset(new double[N]);
+ d.reset(new double[N]);
+ for (i = 0; i < N; i++)
+ {
+ b[i] = (a[i+1]-a[i])/h[i] - oneThird*(c[i+1]+2.0f*c[i])*h[i];
+ d[i] = oneThird*(c[i+1]-c[i])/h[i];
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/cspline.h b/hwpfilter/source/cspline.h
new file mode 100644
index 000000000..b6ddcceb8
--- /dev/null
+++ b/hwpfilter/source/cspline.h
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_CSPLINE_H
+#define INCLUDED_HWPFILTER_SOURCE_CSPLINE_H
+
+void NaturalSpline (int N, const double* x, const double* a, std::unique_ptr<double[]>& b, std::unique_ptr<double[]>& c,
+ std::unique_ptr<double[]>& d);
+void PeriodicSpline (int N, const double* x, const double* a, std::unique_ptr<double[]>& b, std::unique_ptr<double[]>& c,
+ std::unique_ptr<double[]>& d);
+
+#endif // INCLUDED_HWPFILTER_SOURCE_CSPLINE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/datecode.h b/hwpfilter/source/datecode.h
new file mode 100644
index 000000000..900d1e6c9
--- /dev/null
+++ b/hwpfilter/source/datecode.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_DATECODE_H
+#define INCLUDED_HWPFILTER_SOURCE_DATECODE_H
+
+const hchar defaultform[] = { '1', 0x9165, 32, '2', 0xB6A9, 32, '3', 0xB7A9, 0 };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/drawdef.h b/hwpfilter/source/drawdef.h
new file mode 100644
index 000000000..00296d8d1
--- /dev/null
+++ b/hwpfilter/source/drawdef.h
@@ -0,0 +1,243 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_DRAWDEF_H
+#define INCLUDED_HWPFILTER_SOURCE_DRAWDEF_H
+
+#include "hwplib.h"
+#include <memory>
+
+class HWPPara;
+
+/**
+ * Constant for drawing objects
+ */
+enum objtype
+{
+ HWPDO_CONTAINER,
+ HWPDO_LINE,
+ HWPDO_RECT,
+ HWPDO_ELLIPSE,
+ HWPDO_ARC,
+ HWPDO_FREEFORM,
+ HWPDO_TEXTBOX,
+ HWPDO_CURVE,
+ HWPDO_ADVANCED_ELLIPSE,
+ HWPDO_ADVANCED_ARC,
+ HWPDO_CLOSED_FREEFORM,
+ HWPDO_NITEMS
+};
+
+#define HWPDO_PAT_TYPE_BITS 0xFF000000
+
+#define HWPDO_PAT_SOLID 0x00000000
+
+#define HWPDO_COLOR_NONE 0x10000000
+
+#define HWPDO_FLAG_DRAW_PIE 0x00000002
+
+
+#define HWPDO_FLAG_GRADATION 0x00010000
+#define HWPDO_FLAG_ROTATION 0x00020000
+#define HWPDO_FLAG_BITMAP 0x00040000
+#define HWPDO_FLAG_AS_TEXTBOX 0x00080000
+#define HWPDO_FLAG_WATERMARK 0x00100000
+
+/**
+ * @short Basic properties for drawing objects
+ *
+ * The order of pstyle, hstyle and tstyle is important.
+ * @see LineObject
+ */
+struct BAREHWPDOProperty
+{
+ int line_pstyle;
+ int line_hstyle;
+ int line_tstyle;
+ unsigned int line_color;
+ hunit line_width;
+ unsigned int fill_color;
+ uint pattern_type;
+ unsigned int pattern_color;
+ hunit hmargin;
+ hunit vmargin;
+ uint flag;
+};
+
+/**
+ * @short Gradation properties for drawing object
+ */
+struct GradationProperty
+{
+ int fromcolor;
+ int tocolor;
+ int gstyle;
+ int angle;
+ int center_x;
+ int center_y;
+ int nstep;
+};
+
+/**
+ * @short Bitmap properties for drawing object
+ */
+struct BitmapProperty
+{
+ ZZPoint offset1;
+ ZZPoint offset2;
+ char szPatternFile[260 + 1];
+ char pictype;
+};
+
+/**
+ * @short Rotation properties for drawing object
+ */
+struct RotationProperty
+{
+ int rot_originx;
+ int rot_originy;
+ ZZParall parall;
+};
+
+/**
+ * @short All properties for drawing object
+ */
+struct HWPDOProperty
+{
+ int line_pstyle; /* Style of the middle of line */
+ int line_hstyle; /* Style of the end of line */
+ int line_tstyle; /* Style of the start of line */
+ unsigned int line_color;
+ hunit line_width;
+ unsigned int fill_color;
+ uint pattern_type;
+ unsigned int pattern_color;
+ hunit hmargin;
+ hunit vmargin;
+ uint flag;
+
+ /* Rotation properties */
+ int rot_originx;
+ int rot_originy;
+ ZZParall parall;
+
+ /* Gradation properties */
+
+ int fromcolor;
+ int tocolor;
+ int gstyle;
+ int angle;
+ int center_x;
+ int center_y;
+ int nstep;
+
+ /* Watermark */
+ int luminance;
+ int contrast;
+ int greyscale;
+
+ /* As TextBox */
+ HWPPara *pPara;
+
+
+ ZZPoint offset1;
+ ZZPoint offset2;
+ char szPatternFile[260 + 1];
+ char pictype;
+};
+
+/**
+ * @short Line Object
+ */
+struct HWPDOLine
+{
+ uint flip;
+};
+
+/**
+ * @short Polygon or Polyline Object
+ */
+struct HWPDOFreeForm
+{
+ int npt;
+ ZZPoint *pt;
+};
+
+/**
+ * @short Textbox Object
+ */
+struct HWPDOTextBox
+{
+ HWPPara *h;
+};
+
+/**
+ * @short Arc Object
+ */
+struct HWPDOArc
+{
+ ZZPoint radial[2];
+};
+
+/**
+ * @short Common header for drawing object
+ */
+struct HWPDrawingObject
+{
+/**
+ * type of drawing object
+ */
+ int type;
+/**
+ * offset from origin of current group
+ */
+ ZZPoint offset;
+/**
+ * offset from origin of drawing object
+ */
+ ZZPoint offset2;
+ ZZSize extent;
+/**
+ * rectangle with consideration of line width
+ */
+ ZZRect vrect;
+ HWPDOProperty property;
+ union
+ {
+ HWPDOLine line_arc;
+ HWPDOFreeForm freeform;
+ HWPDOTextBox textbox;
+/**
+ * extended from hwpw96
+ */
+ HWPDOArc arc;
+ }
+ u;
+ std::unique_ptr<struct HWPDrawingObject> next;
+/**
+ * This exists for container object
+ */
+ std::unique_ptr<struct HWPDrawingObject> child;
+ int index;
+ HWPDrawingObject();
+ ~HWPDrawingObject();
+};
+#endif // INCLUDED_HWPFILTER_SOURCE_DRAWDEF_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h
new file mode 100644
index 000000000..e3f2a512e
--- /dev/null
+++ b/hwpfilter/source/drawing.h
@@ -0,0 +1,708 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_DRAWING_H
+#define INCLUDED_HWPFILTER_SOURCE_DRAWING_H
+
+#include "precompile.h"
+
+#include <math.h>
+
+#include <osl/diagnose.h>
+
+#include <comphelper/newarray.hxx>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hiodev.h"
+#include "hbox.h"
+#include "drawdef.h"
+
+enum
+{
+ OBJFUNC_LOAD,
+ OBJFUNC_FREE,
+ OBJFUNC_DISPLAY,
+ OBJFUNC_NITEM
+};
+
+enum
+{
+ BEGIN_GRADATION = 0, LINEAR, RADIAL, CONICAL, SQUARE,
+ END_GRADATION, BITMAP_PATTERN
+};
+
+#define OBJRET_FILE_OK 0
+#define OBJRET_FILE_ERROR (-1)
+#define OBJRET_FILE_NO_PRIVATE_BLOCK (-2)
+#define OBJRET_FILE_NO_PRIVATE_BLOCK_2 (-3)
+
+typedef int (*HWPDOFuncType) (int, HWPDrawingObject *, int, void *, int);
+
+#define HWPDOFunc(hdo, cmd, argp, argv) \
+ (HWPDOFuncTbl[(hdo)->type]((hdo)->type, (hdo), (cmd), (argp), (argv)))
+
+static int HWPDOLineFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDORectFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOEllipseFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOArcFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOFreeFormFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOTextBoxFunc(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOEllipse2Func(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOArc2Func(int, HWPDrawingObject *, int, void *, int);
+static int HWPDOContainerFunc(int, HWPDrawingObject *, int, void *, int);
+static HWPPara *LoadParaList();
+
+HWPDOFuncType HWPDOFuncTbl[] =
+{
+ HWPDOContainerFunc,
+ HWPDOLineFunc,
+ HWPDORectFunc,
+ HWPDOEllipseFunc,
+ HWPDOArcFunc,
+ HWPDOFreeFormFunc,
+ HWPDOTextBoxFunc,
+ HWPDOFreeFormFunc,
+ HWPDOEllipse2Func,
+ HWPDOArc2Func,
+ HWPDOFreeFormFunc,
+};
+
+static HIODev *hmem = nullptr;
+
+static int count = 0;
+
+static void SetHdoParallRgn(HWPDrawingObject * hdo, int width, int height)
+{
+ hdo->property.parall.pt[0].x = 0;
+ hdo->property.parall.pt[0].y = 0;
+ hdo->property.parall.pt[1].x = width;
+ hdo->property.parall.pt[1].y = 0;
+ hdo->property.parall.pt[2].x = width;
+ hdo->property.parall.pt[2].y = height;
+}
+
+static bool SkipPrivateBlock(int type)
+{
+ int n;
+
+ if (type == OBJRET_FILE_NO_PRIVATE_BLOCK)
+ {
+ if (!hmem->read4b(n))
+ return false;
+ if (hmem->state() || hmem->skipBlock(n) != static_cast<size_t>(n))
+ return false;
+ }
+ if (!hmem->read4b(n))
+ return false;
+ if (hmem->state())
+ return false;
+ return hmem->skipBlock(n) == static_cast<size_t>(n);
+}
+
+static int SizeExpected;
+static int SizeRead;
+
+static int ReadSizeField(int size)
+{
+ SizeExpected = size;
+ if (!hmem->read4b(SizeRead))
+ return -1;
+ if (hmem->state())
+ return -1;
+ return SizeRead;
+}
+
+static bool SkipUnusedField(void)
+{
+ return (SizeExpected >= SizeRead) &&
+ hmem->skipBlock(SizeRead - SizeExpected) != 0;
+}
+
+
+#define HDOFILE_HEADER_SIZE (2*4+16) // 16=sizeof(ZZRect)
+#define HDOFILE_COMMON_SIZE (7*4+16+44)
+
+#define HDOFILE_HAS_NEXT 0x01
+#define HDOFILE_HAS_CHILD 0x02
+
+static bool LoadCommonHeader(HWPDrawingObject * hdo, unsigned short * link_info)
+{
+ uint size, common_size;
+
+ if (!hmem)
+ return false;
+ if (!hmem->read4b(size))
+ return false;
+ if (hmem->state())
+ return false;
+ if (size < HDOFILE_COMMON_SIZE)
+ return false;
+
+ common_size = HDOFILE_COMMON_SIZE;
+ unsigned short tmp16;
+ if (!hmem->read2b(tmp16))
+ return false;
+ hdo->type = tmp16;
+ if (!hmem->read2b(tmp16))
+ return false;
+ *link_info = tmp16;
+ if (!hmem->read4b(hdo->offset.x))
+ return false;
+ if (!hmem->read4b(hdo->offset.y))
+ return false;
+ if (!hmem->read4b(hdo->extent.w))
+ return false;
+ if (!hmem->read4b(hdo->extent.h))
+ return false;
+ if (!hmem->read4b(hdo->offset2.x))
+ return false;
+ if (!hmem->read4b(hdo->offset2.y))
+ return false;
+
+ if (hmem->state())
+ return false;
+
+ if (!hmem->read4b(hdo->vrect.x))
+ return false;
+ if (!hmem->read4b(hdo->vrect.y))
+ return false;
+ if (!hmem->read4b(hdo->vrect.w))
+ return false;
+ if (!hmem->read4b(hdo->vrect.h))
+ return false;
+
+// read bare property 44 bytes
+ if (!hmem->read4b(hdo->property.line_pstyle))
+ return false;
+ if (!hmem->read4b(hdo->property.line_hstyle))
+ return false;
+ if (!hmem->read4b(hdo->property.line_tstyle))
+ return false;
+ if (!hmem->read4b(hdo->property.line_color))
+ return false;
+ unsigned int tmp32;
+ if (!hmem->read4b(tmp32))
+ return false;
+ hdo->property.line_width = static_cast<hunit>(tmp32);
+ if (!hmem->read4b(hdo->property.fill_color))
+ return false;
+ if (!hmem->read4b(hdo->property.pattern_type))
+ return false;
+ if (!hmem->read4b(hdo->property.pattern_color))
+ return false;
+ if (!hmem->read4b(tmp32))
+ return false;
+ hdo->property.hmargin = static_cast<hunit>(tmp32);
+ if (!hmem->read4b(tmp32))
+ return false;
+ hdo->property.vmargin = static_cast<hunit>(tmp32);
+ if (!hmem->read4b(hdo->property.flag))
+ return false;
+// read rotation property 32 bytes
+ if ((size >= common_size + 32)
+ && (hdo->property.flag & HWPDO_FLAG_ROTATION))
+ {
+ if (!hmem->read4b(hdo->property.rot_originx))
+ return false;
+ if (!hmem->read4b(hdo->property.rot_originy))
+ return false;
+ for (int ii = 0; ii < 3; ++ii)
+ {
+ if (!hmem->read4b(hdo->property.parall.pt[ii].x))
+ return false;
+ if (!hmem->read4b(hdo->property.parall.pt[ii].y))
+ return false;
+ }
+ common_size += 32;
+ }
+ else
+ SetHdoParallRgn(hdo, hdo->extent.w, hdo->extent.h);
+
+// read gradient property 28 bytes
+ if ((size >= common_size + 28) &&
+ (hdo->property.flag & HWPDO_FLAG_GRADATION))
+ {
+ if (!hmem->read4b(hdo->property.fromcolor))
+ return false;
+ if (!hmem->read4b(hdo->property.tocolor))
+ return false;
+ if (!hmem->read4b(hdo->property.gstyle))
+ return false;
+ if (!hmem->read4b(hdo->property.angle))
+ return false;
+ if (!hmem->read4b(hdo->property.center_x))
+ return false;
+ if (!hmem->read4b(hdo->property.center_y))
+ return false;
+ if (!hmem->read4b(hdo->property.nstep))
+ return false;
+ common_size += 28;
+ }
+
+// read bitmap property 278 bytes
+ if ((size >= common_size + 278) && \
+ (hdo->property.flag & HWPDO_FLAG_BITMAP))
+ {
+ if (!hmem->read4b(hdo->property.offset1.x))
+ return false;
+ if (!hmem->read4b(hdo->property.offset1.y))
+ return false;
+ if (!hmem->read4b(hdo->property.offset2.x))
+ return false;
+ if (!hmem->read4b(hdo->property.offset2.y))
+ return false;
+ if (!hmem->readBlock(hdo->property.szPatternFile, 261))
+ return false;
+ if (!hmem->read1b(hdo->property.pictype))
+ return false;
+ common_size += 278;
+ }
+ if( ( size >= common_size + 3 ) && ( hdo->property.flag & HWPDO_FLAG_WATERMARK ) )
+ //if( ( size >= common_size ) && ( hdo->property.flag >> 20 & 0x01 ) )
+ {
+ if (size - common_size >= 5)
+ hmem->skipBlock(2);
+ unsigned char tmp8;
+ if (!hmem->read1b(tmp8))
+ return false;
+ hdo->property.luminance = tmp8;
+ if (!hmem->read1b(tmp8))
+ return false;
+ hdo->property.contrast = tmp8;
+ if (!hmem->read1b(tmp8))
+ return false;
+ hdo->property.greyscale = tmp8;
+
+ common_size += 5;
+ }
+ else
+ {
+ hdo->property.luminance = 0;
+ hdo->property.contrast = 0;
+ hdo->property.greyscale = 0;
+ }
+ hdo->property.pPara = nullptr;
+
+ if( ( size > common_size ) && (hdo->property.flag & HWPDO_FLAG_AS_TEXTBOX) )
+ {
+ hmem->skipBlock(8);
+ hdo->property.pPara = LoadParaList();
+ if( hdo->property.pPara )
+ return true;
+ else
+ return false;
+ }
+
+ if (size <= common_size)
+ return true;
+ return hmem->skipBlock(size - common_size ) != 0;
+}
+
+static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(HWPFile& hwpf)
+{
+ HWPDrawingObject *prev = nullptr;
+ std::unique_ptr<HWPDrawingObject> hdo, head;
+
+ unsigned short link_info;
+
+ do
+ {
+ hdo.reset(new HWPDrawingObject);
+ if (!LoadCommonHeader(hdo.get(), &link_info))
+ {
+ goto error;
+ }
+ if (hdo->type < 0 || hdo->type >= HWPDO_NITEMS)
+ {
+ hdo->type = HWPDO_RECT;
+ if (!SkipPrivateBlock(OBJRET_FILE_NO_PRIVATE_BLOCK))
+ {
+ goto error;
+ }
+ }
+ else
+ {
+ switch (int res = HWPDOFunc(hdo.get(), OBJFUNC_LOAD, nullptr, 0))
+ {
+ case OBJRET_FILE_ERROR:
+ goto error;
+ case OBJRET_FILE_OK:
+ break;
+ case OBJRET_FILE_NO_PRIVATE_BLOCK:
+ case OBJRET_FILE_NO_PRIVATE_BLOCK_2:
+ if (!SkipPrivateBlock(res))
+ goto error;
+ break;
+ }
+ }
+ if (link_info & HDOFILE_HAS_CHILD)
+ {
+ hdo->child = LoadDrawingObject(hwpf);
+ if (hdo->child == nullptr)
+ {
+ goto error;
+ }
+ }
+ if (prev == nullptr)
+ {
+ head = std::move(hdo);
+ prev = head.get();
+ }
+ else
+ {
+ prev->next = std::move(hdo);
+ prev = prev->next.get();
+ }
+ }
+ while (link_info & HDOFILE_HAS_NEXT);
+
+ return head;
+
+error:
+// drawing object can be list.
+// hdo = current item, head = list;
+
+ if (hdo->type < 0 || hdo->type >= HWPDO_NITEMS)
+ {
+ hdo->type = HWPDO_RECT;
+ }
+ if (hdo->property.pPara)
+ {
+ HWPPara* pPara = hdo->property.pPara;
+ while (pPara)
+ {
+ HWPPara* pNextPara = pPara->Next();
+ hwpf.move_to_failed(std::unique_ptr<HWPPara>(pPara));
+ pPara = pNextPara;
+ }
+ hdo->property.pPara = nullptr;
+ }
+ HWPDOFunc(hdo.get(), OBJFUNC_FREE, nullptr, 0);
+ hdo.reset();
+
+ if( prev )
+ {
+ prev->next = nullptr;
+ return head;
+ }
+ else
+ return nullptr;
+}
+
+
+static bool LoadDrawingObjectBlock(Picture * pic, HWPFile& hwpf)
+{
+ int size;
+ if (!hmem->read4b(size))
+ return false;
+
+ if (hmem->state() || size < HDOFILE_HEADER_SIZE)
+ return false;
+
+ if (!hmem->read4b(pic->picinfo.picdraw.zorder))
+ return false;
+ if (!hmem->read4b(pic->picinfo.picdraw.mbrcnt))
+ return false;
+ if (!hmem->read4b(pic->picinfo.picdraw.vrect.x))
+ return false;
+ if (!hmem->read4b(pic->picinfo.picdraw.vrect.y))
+ return false;
+ if (!hmem->read4b(pic->picinfo.picdraw.vrect.w))
+ return false;
+ if (!hmem->read4b(pic->picinfo.picdraw.vrect.h))
+ return false;
+
+ if (size > HDOFILE_HEADER_SIZE &&
+ !hmem->skipBlock(size - HDOFILE_HEADER_SIZE))
+ return false;
+
+ pic->picinfo.picdraw.hdo = LoadDrawingObject(hwpf).release();
+ if (pic->picinfo.picdraw.hdo == nullptr)
+ return false;
+ return true;
+}
+
+// object manipulation function
+static int
+HWPDODefaultFunc(int cmd)
+{
+ if (cmd == OBJFUNC_LOAD)
+ return OBJRET_FILE_NO_PRIVATE_BLOCK;
+ return OBJRET_FILE_OK;
+}
+
+static int
+HWPDOLineFunc(int /*type*/, HWPDrawingObject * hdo, int cmd, void * /*argp*/, int /*argv*/)
+{
+ int ret = OBJRET_FILE_OK;
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ if (ReadSizeField(4) < 4)
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.line_arc.flip))
+ return OBJRET_FILE_ERROR;
+ if (hmem->state())
+ return OBJRET_FILE_ERROR;
+ if (!SkipUnusedField())
+ return OBJRET_FILE_ERROR;
+ ret = OBJRET_FILE_NO_PRIVATE_BLOCK_2;
+ break;
+ default:
+ ret = HWPDODefaultFunc(cmd);
+ break;
+ }
+ return ret;
+}
+
+
+// rectangle
+
+static int
+HWPDORectFunc(int /*type*/, HWPDrawingObject * /*hdo*/, int cmd, void * /*argp*/, int /*argv*/)
+{
+ return HWPDODefaultFunc(cmd);
+}
+
+
+// ellipse
+
+static int
+HWPDOEllipseFunc(int /*type*/, HWPDrawingObject * /*hdo*/,
+int cmd, void * /*argp*/, int /*argv*/)
+{
+ return HWPDODefaultFunc(cmd);
+}
+
+#define WTMM(x) ((double)(x) / 1800. * 25.4)
+static int
+HWPDOEllipse2Func(int /*type*/, HWPDrawingObject * hdo,
+int cmd, void * /*argp*/, int /*argv*/)
+{
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ if (ReadSizeField(16) < 16)
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.arc.radial[0].x))
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.arc.radial[0].y))
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.arc.radial[1].x))
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.arc.radial[1].y))
+ return OBJRET_FILE_ERROR;
+ if (ReadSizeField(0) < 0)
+ return OBJRET_FILE_ERROR;
+ break;
+ default:
+ return HWPDODefaultFunc(cmd);
+ }
+ return OBJRET_FILE_OK;
+}
+
+
+// arc
+
+static int
+HWPDOArcFunc(int /*type*/, HWPDrawingObject * hdo, int cmd, void * /*argp*/, int /*argv*/)
+{
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ if (ReadSizeField(4) < 4)
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.line_arc.flip))
+ return OBJRET_FILE_ERROR;
+ if (hmem->state())
+ return OBJRET_FILE_ERROR;
+ if (!SkipUnusedField())
+ return OBJRET_FILE_ERROR;
+ break;
+ default:
+ return HWPDODefaultFunc(cmd);
+ }
+ return OBJRET_FILE_OK;
+}
+
+
+static int
+HWPDOArc2Func(int /*type*/, HWPDrawingObject * /*hdo*/, int cmd, void * /*argp*/, int /*argv*/)
+{
+ int ret = OBJRET_FILE_OK;
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ ret = OBJRET_FILE_NO_PRIVATE_BLOCK;
+ break;
+ default:
+ ret = HWPDODefaultFunc(cmd);
+ break;
+ }
+ return ret;
+}
+
+
+static int
+HWPDOFreeFormFunc(int /*type*/, HWPDrawingObject * hdo,
+int cmd, void * /*argp*/, int /*argv*/)
+{
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ {
+ hdo->u.freeform.pt = nullptr;
+ if (ReadSizeField(4) < 4)
+ return OBJRET_FILE_ERROR;
+ if (!hmem->read4b(hdo->u.freeform.npt))
+ return OBJRET_FILE_ERROR;
+ if (hmem->state())
+ return OBJRET_FILE_ERROR;
+ if (!SkipUnusedField())
+ return OBJRET_FILE_ERROR;
+
+ int size = hdo->u.freeform.npt * sizeof(ZZPoint);
+
+ if (ReadSizeField(size) < size)
+ return OBJRET_FILE_ERROR;
+ if (hdo->u.freeform.npt)
+ {
+ hdo->u.freeform.pt =
+ ::comphelper::newArray_null<ZZPoint>(hdo->u.freeform.npt);
+ if (hdo->u.freeform.pt == nullptr)
+ {
+ hdo->u.freeform.npt = 0;
+ return OBJRET_FILE_ERROR;
+ }
+ for (int ii = 0; ii < hdo->u.freeform.npt; ++ii)
+ {
+ bool bFailure = false;
+ if (!hmem->read4b(hdo->u.freeform.pt[ii].x))
+ bFailure = true;
+ if (!hmem->read4b(hdo->u.freeform.pt[ii].y))
+ bFailure = true;
+ if (hmem->state())
+ bFailure = true;
+ if (bFailure)
+ {
+ delete[]hdo->u.freeform.pt;
+ hdo->u.freeform.npt = 0;
+ return OBJRET_FILE_ERROR;
+ }
+ }
+ }
+ if (!SkipUnusedField())
+ return OBJRET_FILE_ERROR;
+ return OBJRET_FILE_OK;
+ }
+ case OBJFUNC_FREE:
+ if (hdo->u.freeform.pt)
+ delete[]hdo->u.freeform.pt;
+ break;
+ default:
+ return HWPDODefaultFunc(cmd);
+ }
+ return OBJRET_FILE_OK;
+}
+
+
+// text box
+
+static void FreeParaList(HWPPara * para)
+{
+ if (para->Next())
+ FreeParaList(para->Next());
+ delete para;
+}
+
+
+static HWPPara *LoadParaList()
+{
+ if (!hmem)
+ return nullptr;
+
+ HWPFile *hwpf = GetCurrentDoc();
+ std::unique_ptr<HIODev> hio = hwpf->SetIODevice(std::unique_ptr<HIODev>(hmem));
+
+ std::vector< HWPPara* > plist;
+
+ hwpf->ReadParaList(plist);
+ std::unique_ptr<HIODev> orighmem = hwpf->SetIODevice(std::move(hio));
+ hmem = orighmem.release();
+
+ return plist.size()? plist.front() : nullptr;
+}
+
+
+static int
+HWPDOTextBoxFunc(int /*type*/, HWPDrawingObject * hdo,
+int cmd, void * /*argp*/, int /*argv*/)
+{
+ switch (cmd)
+ {
+ case OBJFUNC_LOAD:
+ if (ReadSizeField(0) < 0 || !SkipUnusedField())
+ return OBJRET_FILE_ERROR;
+ if (ReadSizeField(0) < 0)
+ return OBJRET_FILE_ERROR;
+ hdo->u.textbox.h = LoadParaList();
+ return hdo->u.textbox.h ? OBJRET_FILE_OK : OBJRET_FILE_ERROR;
+ case OBJFUNC_FREE:
+ if (hdo->u.textbox.h)
+ {
+ FreeParaList(hdo->u.textbox.h);
+ hdo->u.textbox.h = nullptr;
+ }
+ break;
+ default:
+ return HWPDODefaultFunc(cmd);
+ }
+ return OBJRET_FILE_OK;
+}
+
+
+
+static int
+HWPDOContainerFunc(int /*type*/, HWPDrawingObject * /*hdo*/,
+int cmd, void * /*argp*/, int /*argv*/)
+{
+ return HWPDODefaultFunc(cmd);
+}
+
+
+HWPDrawingObject::HWPDrawingObject():
+ type(0), offset{0, 0}, offset2{0, 0}, extent{0, 0}, vrect{0, 0, 0, 0}
+{
+ memset(&property, 0, sizeof property);
+ memset(&u, 0, sizeof u);
+ index = ++count;
+}
+
+
+HWPDrawingObject::~HWPDrawingObject()
+{
+ if (property.pPara)
+ FreeParaList(property.pPara);
+
+ HWPDOFunc(this, OBJFUNC_FREE, nullptr, 0);
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/fontmap.cxx b/hwpfilter/source/fontmap.cxx
new file mode 100644
index 000000000..7eba07c03
--- /dev/null
+++ b/hwpfilter/source/fontmap.cxx
@@ -0,0 +1,166 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cstddef>
+#include <stdio.h>
+#ifdef __sun
+#include <strings.h>
+#else
+#include <string.h>
+#endif
+
+#include <sal/types.h>
+#include "fontmap.hxx"
+
+namespace {
+
+struct FontEntry
+{
+ const char *familyname;
+ int key;
+ double ratio;
+};
+
+}
+
+/**
+ * ratio\xb4\xc2 \xc7\xd1\xb1\xdb 70%, \xbc\xfd\xc0\xda 10% \xbf\xb5\xb9\xae 20%\xc0\xc7 \xba\xf1\xc0\xb2\xb7\xce \xb1\xb8\xbc\xba\xb5\xc7\xbe\xfa\xb4\xd9\xb4\xc2 \xb0\xa1\xc1\xa4\xc7\xcf\xbf\xa1 \xc1\xa4\xc7\xd8\xc1\xf8\xb4\xd9.
+ */
+const struct FontEntry FontMapTab[] =
+{
+ {"\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xbb\xf9\xb9\xb0",1, 0.97},
+ {"\xc7\xca\xb1\xe2",0, 0.97},
+ {"\xbd\xc3\xbd\xba\xc5\xdb",1, 0.84},
+ {"\xbd\xc3\xbd\xba\xc5\xdb \xbe\xe0\xc0\xda",1, 0.84},
+ {"\xbd\xc3\xbd\xba\xc5\xdb \xb0\xa3\xc0\xda",1, 0.84},
+ {"HY\xb5\xd5\xb1\xd9 \xb0\xed\xb5\xf1",2, 0.97},
+ {"\xbf\xbe\xc7\xd1\xb1\xdb",0, 0.97},
+ {"\xb0\xa1\xb4\xc2\xb0\xf8\xc7\xd1",0, 0.72},
+ {"\xc1\xdf\xb0\xa3\xb0\xf8\xc7\xd1",0, 0.72},
+ {"\xb1\xbd\xc0\xba\xb0\xf8\xc7\xd1",0, 0.72},
+ {"\xb0\xa1\xb4\xc2\xc7\xd1",0, 0.72},
+ {"\xc1\xdf\xb0\xa3\xc7\xd1",0, 0.72},
+ {"\xb1\xbd\xc0\xba\xc7\xd1",0, 0.72},
+ {"\xc8\xde\xb8\xd5\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xc8\xde\xb8\xd5\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xb0\xa1\xb4\xc2\xbe\xc8\xbb\xf3\xbc\xf6\xc3\xbc",0, 0.55},
+ {"\xc1\xdf\xb0\xa3\xbe\xc8\xbb\xf3\xbc\xf6\xc3\xbc",0, 0.637},
+ {"\xb1\xbd\xc0\xba\xbe\xc8\xbb\xf3\xbc\xf6\xc3\xbc",0, 0.63},
+ {"\xc8\xde\xb8\xd5\xb0\xa1\xb4\xc2\xbb\xf9\xc3\xbc",0, 0.666},
+ {"\xc8\xde\xb8\xd5\xc1\xdf\xb0\xa3\xbb\xf9\xc3\xbc",0, 0.685},
+ {"\xc8\xde\xb8\xd5\xb1\xbd\xc0\xba\xbb\xf9\xc3\xbc",0, 0.727},
+ {"\xc8\xde\xb8\xd5\xb0\xa1\xb4\xc2\xc6\xd4\xc3\xbc",0, 0.666},
+ {"\xc8\xde\xb8\xd5\xc1\xdf\xb0\xa3\xc6\xd4\xc3\xbc",0, 0.685},
+ {"\xc8\xde\xb8\xd5\xb1\xbd\xc0\xba\xc6\xd4\xc3\xbc",0, 0.727},
+ {"\xc8\xde\xb8\xd5\xbf\xbe\xc3\xbc",3, 0.97},
+ {"\xc7\xd1\xbe\xe7\xbd\xc5\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xc7\xd1\xbe\xe7\xb0\xdf\xb8\xed\xc1\xb6",1, 0.97},
+ {"\xc7\xd1\xbe\xe7\xc1\xdf\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xc7\xd1\xbe\xe7\xb0\xdf\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xc7\xd1\xbe\xe7\xb1\xd7\xb7\xa1\xc7\xc8",0, 0.97},
+ {"\xc7\xd1\xbe\xe7\xb1\xc3\xbc\xad",3, 0.97},
+ {"\xb9\xae\xc8\xad\xb9\xd9\xc5\xc1",0, 0.97},
+ {"\xb9\xae\xc8\xad\xb9\xd9\xc5\xc1\xc1\xa6\xb8\xf1",1, 0.97},
+ {"\xb9\xae\xc8\xad\xb5\xb8\xbf\xf2",1, 0.97},
+ {"\xb9\xae\xc8\xad\xb5\xb8\xbf\xf2\xc1\xa6\xb8\xf1",0, 0.97},
+ {"\xb9\xae\xc8\xad\xbe\xb2\xb1\xe2",0, 0.97},
+ {"\xb9\xae\xc8\xad\xbe\xb2\xb1\xe2\xc8\xea\xb8\xb2",0, 0.97},
+ {"\xc6\xe6\xc8\xea\xb8\xb2",0, 0.97},
+ {"\xba\xb9\xbc\xfe\xbe\xc6",0, 0.827},
+ {"\xbf\xc1\xbc\xf6\xbc\xf6",0, 0.97},
+ {"\xbf\xc0\xc0\xcc",0, 0.97},
+ {"\xb0\xa1\xc1\xf6",0, 0.97},
+ {"\xb0\xad\xb3\xb6\xc4\xe1",2, 0.97},
+ {"\xb5\xfe\xb1\xe2",3, 0.97},
+ {"\xc5\xb8\xc0\xcc\xc7\xc1",0, 0.987},
+ {"\xc5\xc2 \xb3\xaa\xb9\xab",1, 0.97},
+ {"\xc5\xc2 \xc7\xec\xb5\xe5\xb6\xf3\xc0\xce",0, 0.97},
+ {"\xc5\xc2 \xb0\xa1\xb4\xc2 \xc7\xec\xb5\xe5\xb6\xf3\xc0\xce",0, 0.97},
+ {"\xc5\xc2 \xc7\xec\xb5\xe5\xb6\xf3\xc0\xceT",0, 0.97},
+ {"\xc5\xc2 \xb0\xa1\xb4\xc2 \xc7\xec\xb5\xe5\xb6\xf3\xc0\xceT",0, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xb4\xd9\xbf\xee\xb8\xed\xc1\xb6M",0, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xba\xbb\xb8\xf1\xb0\xa2M",0, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xbc\xd2\xbd\xbd",1, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xb8\xc5\xc8\xad",1, 0.987},
+ {"\xbe\xe7\xc0\xe7 \xc6\xb0\xc6\xb0",0, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xc2\xfc\xbd\xa1",1, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xb5\xd1\xb1\xe2",0, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xbb\xfe\xb3\xda",1, 0.97},
+ {"\xbe\xe7\xc0\xe7 \xbf\xcd\xb4\xe7",1, 0.97},
+ {"\xbd\xc5\xb8\xed \xbc\xbc\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xbd\xc5\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xbd\xc5\xbd\xc5\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xc1\xdf\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xc5\xc2\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xb0\xdf\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xbd\xc5\xb9\xae\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xbc\xf8\xb8\xed\xc1\xb6",0, 0.97},
+ {"\xbd\xc5\xb8\xed \xbc\xbc\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xbd\xc5\xb8\xed \xc1\xdf\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xbd\xc5\xb8\xed \xc5\xc2\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xbd\xc5\xb8\xed \xb0\xdf\xb0\xed\xb5\xf1",1, 0.97},
+ {"\xbd\xc5\xb8\xed \xbc\xbc\xb3\xaa\xb7\xe7",2, 0.97},
+ {"\xbd\xc5\xb8\xed \xb5\xf0\xb3\xaa\xb7\xe7",2, 0.97},
+ {"\xbd\xc5\xb8\xed \xbd\xc5\xb1\xd7\xb7\xa1\xc7\xc8",2, 0.97},
+ {"\xbd\xc5\xb8\xed \xc5\xc2\xb1\xd7\xb7\xa1\xc7\xc8",2, 0.97},
+ {"\xbd\xc5\xb8\xed \xb1\xc3\xbc\xad",3, 0.97}
+};
+
+#if defined(_WIN32)
+const char* const RepFontTab[] =
+{
+ "\xb9\xd9\xc5\xc1", /* 0 */
+ "\xb5\xb8\xbf\xf2", /* 1 */
+ "\xb1\xbc\xb8\xb2", /* 2 */
+ "\xb1\xc3\xbc\xad" /* 3 */
+};
+#elif defined(LINUX)
+const char* const RepFontTab[] =
+{
+ "\xb9\xe9\xb9\xac \xb9\xd9\xc5\xc1", /* 0 */
+ "\xb9\xe9\xb9\xac \xb5\xb8\xbf\xf2", /* 1 */
+ "\xb9\xe9\xb9\xac \xb1\xbc\xb8\xb2", /* 2 */
+ "\xb9\xe9\xb9\xac \xc7\xec\xb5\xe5\xb6\xf3\xc0\xce" /* 3 */
+};
+#else
+const char* const RepFontTab[] =
+{
+ "Batang", /* 0 */
+ "Dotum", /* 1 */
+ "Gulim", /* 2 */
+ "Gungso" /* 3 */
+};
+#endif
+
+int getRepFamilyName(const char* orig, char *buf, double &ratio)
+{
+ for( std::size_t i = 0 ; i < SAL_N_ELEMENTS(FontMapTab); i++)
+ {
+ if( !strcmp(orig, FontMapTab[i].familyname) ){
+ ratio = FontMapTab[i].ratio;
+ return strlen( strcpy(buf,RepFontTab[FontMapTab[i].key]) );
+ }
+ }
+ ratio = FontMapTab[0].ratio;
+ return strlen( strcpy(buf, RepFontTab[0] ) );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/fontmap.hxx b/hwpfilter/source/fontmap.hxx
new file mode 100644
index 000000000..3ab2e0849
--- /dev/null
+++ b/hwpfilter/source/fontmap.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_FONTMAP_HXX
+#define INCLUDED_HWPFILTER_SOURCE_FONTMAP_HXX
+
+#include <sal/config.h>
+
+int getRepFamilyName(char const*, char*, double&);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/formula.cxx b/hwpfilter/source/formula.cxx
new file mode 100644
index 000000000..6093681b2
--- /dev/null
+++ b/hwpfilter/source/formula.cxx
@@ -0,0 +1,651 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "formula.h"
+#include "grammar.hxx"
+
+#include "mzstring.h"
+#include "nodes.h"
+#include "mapping.h"
+#include "hwpeq.h"
+#include <iostream>
+
+#ifndef DEBUG
+
+#include "hcode.h"
+
+#define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(false)
+#define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(false)
+#define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false)
+#define runistr(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false)
+#define reucstr(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(OUString(x,y, RTL_TEXTENCODING_EUC_KR)); } while(false)
+#define padd(x,y,z) mxList->addAttribute(x,y,z)
+#else
+static int indent = 0;
+#define inds indent++; for(int i = 0 ; i < indent ; i++) fprintf(stderr," ")
+#define inde for(int i = 0 ; i < indent ; i++) fprintf(stderr," "); indent--
+#define indo indent--;
+#endif
+
+void Formula::makeMathML(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:math xmlns:math=\"http://www.w3.org/1998/Math/MathML\">\n");
+#else
+ padd("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML");
+ rstartEl("math:math", mxList);
+ mxList->clear();
+ rstartEl("math:semantics", mxList);
+#endif
+ if( tmp->child )
+ makeLines( tmp->child );
+
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:semantics/>\n");
+ indo;
+ inde;
+ fprintf(stderr,"</math:math>\n");
+#else
+ rendEl("math:semantics");
+ rendEl("math:math");
+#endif
+}
+
+void Formula::makeLines(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+
+ if( tmp->child ){
+ if( tmp->child->id == ID_LINES )
+ makeLines( tmp->child );
+ else
+ makeLine( tmp->child );
+ }
+ if( tmp->next )
+ makeLine( tmp->next );
+}
+
+void Formula::makeLine(Node *res)
+{
+ if( !res ) return;
+#ifdef DEBUG
+ inds; fprintf(stderr,"<math:mrow>\n");
+#else
+ rstartEl("math:mrow", mxList);
+#endif
+ if( res->child )
+ makeExprList( res->child );
+#ifdef DEBUG
+ inde; fprintf(stderr,"</math:mrow>\n");
+#else
+ rendEl("math:mrow");
+#endif
+}
+
+void Formula::makeExprList(Node *res)
+{
+ if( !res ) return;
+ Node *tmp = res->child;
+ if( !tmp ) return ;
+
+ if( tmp->id == ID_EXPRLIST ){
+ Node *next = tmp->next;
+ makeExprList( tmp ) ;
+ if( next )
+ makeExpr( next );
+ }
+ else
+ makeExpr( tmp );
+}
+
+void Formula::makeExpr(Node *res)
+{
+ if( !res ) return;
+ Node *tmp = res->child;
+ if( !tmp ) return;
+ switch( tmp->id ) {
+ case ID_PRIMARYEXPR:
+ if( tmp->next ){
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mrow>\n");
+#else
+ rstartEl("math:mrow", mxList);
+#endif
+ }
+
+ makePrimary(tmp);
+
+ if( tmp->next ){
+#ifdef DEBUG
+ inde; fprintf(stderr,"</math:mrow>\n");
+#else
+ rendEl("math:mrow");
+#endif
+ }
+ break;
+ case ID_SUBEXPR:
+ case ID_SUPEXPR:
+ case ID_SUBSUPEXPR:
+ makeSubSup(tmp);
+ break;
+ case ID_FRACTIONEXPR:
+ case ID_OVER:
+ makeFraction(tmp);
+ break;
+ case ID_DECORATIONEXPR:
+ makeDecoration(tmp);
+ break;
+ case ID_SQRTEXPR:
+ case ID_ROOTEXPR:
+ makeRoot(tmp);
+ break;
+ case ID_ARROWEXPR:
+ break;
+ case ID_ACCENTEXPR:
+ makeAccent(tmp);
+ break;
+ case ID_PARENTH:
+ case ID_ABS:
+ makeParenth(tmp);
+ break;
+ case ID_FENCE:
+ makeFence(tmp);
+ break;
+ case ID_BLOCK:
+ makeBlock(tmp);
+ break;
+ case ID_BEGIN:
+ case ID_END:
+ break;
+ }
+}
+
+void Formula::makeIdentifier(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+ if( !tmp->value ) return;
+ switch( tmp->id ){
+ case ID_CHARACTER :
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value.get());
+ indo;
+#else
+ rstartEl("math:mi", mxList);
+ rchars(OUString::createFromAscii(tmp->value.get()));
+ rendEl("math:mi");
+#endif
+ break;
+ case ID_STRING :
+ {
+#ifdef DEBUG
+#else
+ rstartEl("math:mi", mxList);
+ reucstr(tmp->value.get(), strlen(tmp->value.get()));
+ rendEl("math:mi");
+#endif
+ }
+ break;
+ case ID_IDENTIFIER :
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mi>%s</math:mi>\n",
+ getMathMLEntity(tmp->value.get()).c_str());
+ indo;
+#else
+ rstartEl("math:mi", mxList);
+ runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get())));
+ rendEl("math:mi");
+#endif
+ break;
+ case ID_NUMBER :
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value.get());
+ indo;
+#else
+ rstartEl("math:mn", mxList);
+ rchars(OUString::createFromAscii(tmp->value.get()));
+ rendEl("math:mn");
+#endif
+ break;
+ case ID_OPERATOR :
+ case ID_DELIMITER :
+ {
+#ifdef DEBUG
+ inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value.get()); indo;
+#else
+ rstartEl("math:mo", mxList);
+ runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get())));
+ rendEl("math:mo");
+#endif
+ break;
+ }
+ }
+}
+void Formula::makePrimary(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return ;
+ if( tmp->child ){
+ if( tmp->child->id == ID_PRIMARYEXPR ){
+ makePrimary(tmp->child);
+ }
+ else{
+ makeIdentifier(tmp->child);
+ }
+ }
+ if( tmp->next ){
+ makeIdentifier(tmp->next);
+ }
+}
+
+void Formula::makeSubSup(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+
+#ifdef DEBUG
+ inds;
+ if( res->id == ID_SUBEXPR )
+ fprintf(stderr,"<math:msub>\n");
+ else if( res->id == ID_SUPEXPR )
+ fprintf(stderr,"<math:msup>\n");
+ else
+ fprintf(stderr,"<math:msubsup>\n");
+#else
+ if( res->id == ID_SUBEXPR )
+ rstartEl("math:msub", mxList);
+ else if( res->id == ID_SUPEXPR )
+ rstartEl("math:msup", mxList);
+ else
+ rstartEl("math:msubsup", mxList);
+#endif
+
+ tmp = tmp->child;
+ if( res->id == ID_SUBSUPEXPR ) {
+ makeExpr(tmp);
+ makeBlock(tmp->next);
+ makeBlock(tmp->next->next);
+ }
+ else{
+ makeExpr(tmp);
+ makeExpr(tmp->next);
+ }
+
+#ifdef DEBUG
+ inde;
+ if( res->id == ID_SUBEXPR )
+ fprintf(stderr,"</math:msub>\n");
+ else if( res->id == ID_SUPEXPR )
+ fprintf(stderr,"</math:msup>\n");
+ else
+ fprintf(stderr,"</math:msubsup>\n");
+#else
+ if( res->id == ID_SUBEXPR )
+ rendEl("math:msub");
+ else if( res->id == ID_SUPEXPR )
+ rendEl("math:msup");
+ else
+ rendEl("math:msubsup");
+#endif
+}
+
+void Formula::makeFraction(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mfrac>\n");
+#else
+ rstartEl("math:mfrac", mxList);
+#endif
+
+ tmp = tmp->child;
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mrow>\n");
+#else
+ rstartEl("math:mrow", mxList);
+#endif
+
+ if( res->id == ID_FRACTIONEXPR )
+ makeBlock(tmp);
+ else
+ makeExprList(tmp);
+
+#ifdef DEBUG
+ inde;
+ fprintf(stderr,"</math:mrow>\n");
+ inds;
+ fprintf(stderr,"<math:mrow>\n");
+#else
+ rendEl("math:mrow");
+ rstartEl("math:mrow", mxList);
+#endif
+
+ if( res->id == ID_FRACTIONEXPR )
+ makeBlock(tmp->next);
+ else
+ makeExprList(tmp->next);
+
+#ifdef DEBUG
+ inde;
+ fprintf(stderr,"</math:mrow>\n");
+ inde;
+ fprintf(stderr,"</math:mfrac>\n");
+#else
+ rendEl("math:mrow");
+ rendEl("math:mfrac");
+#endif
+}
+
+void Formula::makeDecoration(Node *res)
+{
+ int isover = 1;
+ Node *tmp = res->child;
+ if( !tmp ) return;
+ if( !strncmp(tmp->value.get(),"under", 5) )
+ isover = 0;
+#ifdef DEBUG
+ inds;
+ if( isover )
+ fprintf(stderr,"<math:mover>\n");
+ else
+ fprintf(stderr,"<math:munder>\n");
+#else
+ /* FIXME: no idea when 'accent' is true or false. */
+ if( isover ){
+ padd("accent","CDATA","true");
+ rstartEl("math:mover", mxList);
+ }
+ else{
+ padd("accentunder","CDATA","true");
+ rstartEl("math:munder", mxList);
+ }
+ mxList->clear();
+#endif
+
+ makeBlock(tmp->next);
+
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mo>%s</math:mo>\n",
+ getMathMLEntity(tmp->value.get()).c_str());
+ indo;
+#else
+ rstartEl("math:mo", mxList);
+ runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get())));
+ rendEl("math:mo");
+#endif
+
+#ifdef DEBUG
+ inde;
+ if( isover )
+ fprintf(stderr,"</math:mover>\n");
+ else
+ fprintf(stderr,"</math:munder>\n");
+#else
+ if( isover )
+ rendEl("math:mover");
+ else
+ rendEl("math:munder");
+#endif
+}
+
+void Formula::makeRoot(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+#ifdef DEBUG
+ inds;
+ if( tmp->id == ID_SQRTEXPR )
+ fprintf(stderr,"<math:msqrt>\n");
+ else
+ fprintf(stderr,"<math:mroot>\n");
+#else
+ if( tmp->id == ID_SQRTEXPR )
+ rstartEl("math:msqrt", mxList);
+ else
+ rstartEl("math:mroot", mxList);
+#endif
+
+ if( tmp->id == ID_SQRTEXPR ){
+ makeBlock(tmp->child);
+ }
+ else{
+ makeBracket(tmp->child);
+ makeBlock(tmp->child->next);
+ }
+
+#ifdef DEBUG
+ inde;
+ if( tmp->id == ID_SQRTEXPR )
+ fprintf(stderr,"</math:msqrt>\n");
+ else
+ fprintf(stderr,"</math:mroot>\n");
+#else
+ if( tmp->id == ID_SQRTEXPR )
+ rendEl("math:msqrt");
+ else
+ rendEl("math:mroot");
+#endif
+}
+void Formula::makeAccent(Node *res)
+{
+ makeDecoration( res );
+}
+void Formula::makeParenth(Node *res)
+{
+ Node *tmp = res;
+ if( !tmp ) return;
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mrow>\n");
+ inds;
+ if( tmp->id == ID_PARENTH ){
+ fprintf(stderr,"<math:mo>(</math:mo>\n");
+ }
+ else
+ fprintf(stderr,"<math:mo>|</math:mo>\n");
+ indo; inds;
+ fprintf(stderr,"<math:mrow>\n");
+#else
+ rstartEl("math:mrow", mxList);
+ rstartEl("math:mo", mxList);
+ if( tmp->id == ID_PARENTH )
+ rchars("(");
+ else
+ rchars("|");
+ rendEl("math:mo");
+ rstartEl("math:mrow", mxList);
+#endif
+
+ if( tmp->child )
+ makeExprList(tmp->child);
+
+#ifdef DEBUG
+ inde;
+ fprintf(stderr,"</math:mrow>\n");
+ inds;
+ if( tmp->id == ID_PARENTH )
+ fprintf(stderr,"<math:mo>)</math:mo>\n");
+ else
+ fprintf(stderr,"<math:mo>|</math:mo>\n");
+ indo;
+ inde;
+ fprintf(stderr,"</math:mrow>\n");
+#else
+ rendEl("math:mrow");
+ rstartEl("math:mo", mxList);
+ if( tmp->id == ID_PARENTH )
+ rchars(")");
+ else
+ rchars("|");
+ rendEl("math:mo");
+ rendEl("math:mrow");
+#endif
+}
+
+void Formula::makeFence(Node *res)
+{
+ Node *tmp = res->child;
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n",
+ getMathMLEntity(tmp->value.get()).c_str(),
+ getMathMLEntity(tmp->next->next->value.get()).c_str());
+#else
+ padd("open", "CDATA",
+ OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value.get()).c_str())));
+ padd("close", "CDATA",
+ OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value.get()).c_str())));
+ rstartEl("math:mfenced", mxList);
+ mxList->clear();
+#endif
+
+ makeExprList(tmp->next);
+
+#ifdef DEBUG
+ inde;
+ fprintf(stderr,"</math:mfenced>\n");
+#else
+ rendEl("math:mfenced");
+#endif
+}
+
+void Formula::makeBracket(Node *res)
+{
+ makeBlock(res);
+}
+
+void Formula::makeBlock(Node *res)
+{
+#ifdef DEBUG
+ inds;
+ fprintf(stderr,"<math:mrow>\n");
+#else
+ rstartEl("math:mrow", mxList);
+#endif
+
+ if( res->child )
+ makeExprList(res->child);
+
+#ifdef DEBUG
+ inde;
+ fprintf(stderr,"</math:mrow>\n");
+#else
+ rendEl("math:mrow");
+#endif
+}
+
+void Formula::parse()
+{
+ Node *res = nullptr;
+ if( !eq ) return;
+
+ MzString a;
+ // fprintf(stderr,"\n\n[BEFORE]\n[%s]\n",eq);
+ eq2latex(a,eq);
+
+ int idx=a.find(sal::static_int_cast<char>(0xff));
+ while(idx){
+ //printf("idx = [%d]\n",idx);
+ a.replace(idx,0x20);
+ if((idx = a.find(sal::static_int_cast<char>(0xff),idx+1)) < 0)
+ break;
+ }
+
+ char *buf = static_cast<char *>(malloc(a.length()+1));
+ bool bStart = false;
+ int i, j;
+ for( i = 0, j=0 ; i < a.length() ; i++){ // rtrim and ltrim 32 10 13
+ if( bStart ){
+ buf[j++] = a[i];
+ }
+ else{
+ if( a[i] != 32 && a[i] != 10 && a[i] != 13){
+ bStart = true;
+ buf[j++] = a[i];
+ }
+ }
+ }
+ buf[j] = 0;
+ for( i = j-1 ; i >= 0 ; i++ ){
+ if( buf[i] == 32 || buf[i] == 10 || buf[i] == 13 ){
+ buf[i] = 0;
+ }
+ else
+ break;
+ }
+ // fprintf(stderr,"\n\n[RESULT]\n[%s]\n",a.c_str());
+ if( buf[0] != '\0' )
+ res = mainParse( a.c_str() );
+ else
+ res = nullptr;
+ free(buf);
+
+ if( res ){
+ makeMathML( res );
+ }
+ nodelist.clear();
+}
+
+void Formula::trim()
+{
+ int len = strlen(eq);
+ char *buf = static_cast<char *>(malloc(len+1));
+ bool bStart = false;
+ int i, j;
+ for( i = 0, j=0 ; i < len ; i++){ // rtrim and ltrim 32 10 13
+ if( bStart ){
+ buf[j++] = eq[i];
+ }
+ else{
+ if( eq[i] != 32 && eq[i] != 10 && eq[i] != 13){
+ bStart = true;
+ buf[j++] = eq[i];
+ }
+ }
+ }
+ buf[j] = 0;
+ for( i = j-1 ; i >= 0 ; i++ ){
+ if( buf[i] == 32 || buf[i] == 10 || buf[i] == 13 ){
+ buf[i] = 0;
+ }
+ else
+ break;
+ }
+ if( buf[0] != '\0' )
+ strcpy(eq, buf);
+ else
+ eq = nullptr;
+ free(buf);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/formula.h b/hwpfilter/source/formula.h
new file mode 100644
index 000000000..d46e36b24
--- /dev/null
+++ b/hwpfilter/source/formula.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_FORMULA_H
+#define INCLUDED_HWPFILTER_SOURCE_FORMULA_H
+
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include "attributes.hxx"
+#include <rtl/ref.hxx>
+
+class Node;
+
+using namespace ::com::sun::star::xml::sax;
+
+class Formula final
+{
+public:
+ explicit Formula(char *_eq)
+ {
+ eq = _eq;
+ trim();
+ }
+
+ void setDocumentHandler(Reference < XDocumentHandler > const & xHandler )
+ {
+ m_rxDocumentHandler = xHandler;
+ }
+ void setAttributeListImpl( AttributeListImpl *p )
+ {
+ mxList = p;
+ }
+ void parse();
+private:
+ void trim();
+ void makeMathML(Node *res);
+ void makeLines(Node *res);
+ void makeLine(Node *res);
+ void makeExprList(Node *res);
+ void makeExpr(Node *res);
+ void makePrimary(Node *res);
+ void makeIdentifier(Node *res);
+ void makeSubSup(Node *res);
+ void makeFraction(Node *res);
+ void makeDecoration(Node *res);
+ void makeRoot(Node *res);
+ void makeAccent(Node *res);
+ void makeParenth(Node *res);
+ void makeFence(Node *res);
+ void makeBracket(Node *res);
+ void makeBlock(Node *res);
+
+private:
+ Reference< XDocumentHandler > m_rxDocumentHandler;
+ rtl::Reference<AttributeListImpl> mxList;
+ char *eq;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/grammar.cxx b/hwpfilter/source/grammar.cxx
new file mode 100644
index 000000000..199aab343
--- /dev/null
+++ b/hwpfilter/source/grammar.cxx
@@ -0,0 +1,918 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+/* A Bison parser, made from grammar.y
+ by GNU Bison version 1.28 */
+
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH 0
+#endif
+
+#include <vector>
+#include <stdlib.h>
+#include <string.h>
+
+#include "grammar.hxx"
+#include "lexer.hxx"
+#include "nodes.h"
+
+extern "C" {
+#include "grammar.h"
+}
+
+std::vector<std::unique_ptr<Node>> nodelist;
+
+static void yyerror(const char *);
+
+static Node *top=nullptr;
+
+int Node::count = 0;
+
+#ifdef PARSE_DEBUG
+#define debug printf
+#else
+static int debug(const char *format, ...);
+#endif
+
+#include <stdio.h>
+
+#define YYFINAL 102
+#define YYFLAG -32768
+#define YYNTBASE 43
+
+#define YYTRANSLATE(x) (static_cast<unsigned>(x) <= 285 ? yytranslate[x] : 66)
+
+const char yytranslate[] = { 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 33,
+ 37, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 36,
+ 2, 40, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 34, 2, 38, 42, 41, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 35, 32, 39, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 31
+};
+
+
+const short yyr1[] = { 0,
+ 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
+ 43, 43, 43, 43, 43, 43, 43, 44, 44, 45,
+ 45, 45, 45, 45, 45, 45, 46, 46, 46, 46,
+ 46, 46, 46, 47, 48, 48, 49, 49, 50, 50,
+ 51, 51, 51, 52, 53, 54, 55, 56, 57, 58,
+ 58, 59, 59, 60, 61, 62, 62, 63, 64, 64,
+ 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
+ 65, 65
+};
+
+const short yyr2[] = { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
+ 2, 2, 2, 2, 3, 1, 2, 2, 2, 2,
+ 2, 3, 1, 3, 3, 2, 3, 2, 3, 2,
+ 3, 3, 5, 3, 5, 1, 2, 1, 2, 2,
+ 3, 2, 3, 2, 1, 1, 3, 1, 1, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1
+};
+
+const short yydefact[] = { 0,
+ 46, 1, 4, 10, 9, 14, 2, 3, 5, 6,
+ 0, 0, 12, 13, 48, 7, 8, 17, 11, 0,
+ 0, 0, 26, 16, 15, 0, 0, 18, 70, 0,
+ 63, 62, 61, 64, 65, 66, 0, 69, 0, 67,
+ 68, 71, 72, 55, 56, 58, 59, 0, 0, 50,
+ 0, 0, 52, 54, 24, 20, 21, 22, 23, 36,
+ 0, 38, 0, 19, 0, 47, 49, 0, 60, 0,
+ 0, 40, 0, 0, 51, 44, 53, 25, 35, 0,
+ 37, 0, 33, 34, 57, 61, 41, 42, 39, 0,
+ 31, 27, 28, 29, 30, 0, 45, 32, 43, 0,
+ 0, 0
+};
+
+const short yydefgoto[] = { 28,
+ 29, 30, 84, 31, 32, 33, 51, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 100, 44, 45,
+ 46, 47
+};
+
+const short yypact[] = { 393,
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
+ -30, -19,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -19,
+ -19, -3,-32768,-32768,-32768, 290, 107,-32768, 425, 393,
+-32768,-32768,-32768,-32768,-32768,-32768, -19,-32768, -19,-32768,
+-32768,-32768,-32768, -20,-32768, 393, -21, 218, 107,-32768,
+ -19, -19, -19,-32768, -15,-32768,-32768,-32768,-32768,-32768,
+ 325,-32768, 70,-32768, 360,-32768,-32768, 393, -21, 393,
+ 393,-32768, 254, 144,-32768,-32768,-32768,-32768,-32768, 393,
+-32768, -25,-32768,-32768,-32768, -31, -21, -21,-32768, 181,
+ -14,-32768,-32768,-32768,-32768, -19,-32768,-32768,-32768, 22,
+ 23,-32768
+};
+
+const short yypgoto[] = { -2,
+-32768,-32768,-32768,-32768,-32768, -11,-32768,-32768,-32768,-32768,
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -33,
+ -24, -27
+};
+
+
+#define YYLAST 457
+
+
+const short yytable[] = { 50,
+ 52, 61, 63, 48, 49, 65, 91, 68, 53, 54,
+ 96, 92, 93, 94, 95, 49, 78, 98, 69, 70,
+ 71, 101, 102, 73, 74, 66, 64, 67, 55, 56,
+ 57, 58, 59, 69, 85, 69, 0, 69, 0, 75,
+ 76, 77, 87, 88, 0, 69, 69, 0, 0, 0,
+ 0, 0, 0, 0, 0, 90, 0, 0, 86, 0,
+ 0, 0, 69, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 99, 80, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 0, 0, 23, 0,
+ 24, 25, 26, 0, 27, 0, 0, 0, 81, 1,
+ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 0, 0, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 0, 0, 23, 0, 24, 25, 26,
+ 0, 27, 0, 0, 0, 62, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 0, 0,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 0, 0, 23, 0, 24, 25, 26, 0, 27, 0,
+ 0, 0, 81, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 0, 0, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 0, 0, 23,
+ 0, 24, 25, 26, 0, 27, 0, 0, 0, 97,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 0, 0, 13, 14, 15, 16, 17, 18,
+ 19, 20, 21, 22, 0, 0, 23, 0, 24, 25,
+ 26, 0, 27, 0, 0, 72, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 0, 0,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 0, 0, 23, 0, 24, 25, 26, 0, 27, 0,
+ 0, 89, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 0, 0, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 0, 0, 23, 0,
+ 24, 25, 26, 0, 27, 0, 60, 1, 2, 3,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 0,
+ 0, 13, 14, 15, 16, 17, 18, 19, 20, 21,
+ 22, 0, 0, 23, 0, 24, 25, 26, 0, 27,
+ 0, 79, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 0, 0, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 82, 0, 23, 83,
+ 24, 25, 26, 0, 27, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12, 0, 0, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 0,
+ 0, 23, 0, 24, 25, 26, 0, 27, 2, 3,
+ 4, 5, 6, 7, 8, 9, 10, 0, 0, 0,
+ 0, 13, 14, 0, 16, 17, 18, 19, 0, 0,
+ 0, 0, 0, 0, 0, 24, 25
+};
+
+const short yycheck[] = { 11,
+ 12, 26, 27, 34, 35, 30, 32, 28, 20, 21,
+ 42, 37, 38, 39, 40, 35, 32, 32, 46, 41,
+ 42, 0, 0, 48, 49, 37, 29, 39, 32, 33,
+ 34, 35, 36, 61, 68, 63, -1, 65, -1, 51,
+ 52, 53, 70, 71, -1, 73, 74, -1, -1, -1,
+ -1, -1, -1, -1, -1, 80, -1, -1, 70, -1,
+ -1, -1, 90, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 96, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, -1, -1, 29, -1,
+ 31, 32, 33, -1, 35, -1, -1, -1, 39, 3,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, -1, -1, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, -1, -1, 29, -1, 31, 32, 33,
+ -1, 35, -1, -1, -1, 39, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, -1, -1,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ -1, -1, 29, -1, 31, 32, 33, -1, 35, -1,
+ -1, -1, 39, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, -1, -1, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, -1, -1, 29,
+ -1, 31, 32, 33, -1, 35, -1, -1, -1, 39,
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, -1, -1, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, -1, -1, 29, -1, 31, 32,
+ 33, -1, 35, -1, -1, 38, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, -1, -1,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ -1, -1, 29, -1, 31, 32, 33, -1, 35, -1,
+ -1, 38, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, -1, -1, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, -1, -1, 29, -1,
+ 31, 32, 33, -1, 35, -1, 37, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12, 13, 14, -1,
+ -1, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+ 26, -1, -1, 29, -1, 31, 32, 33, -1, 35,
+ -1, 37, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, -1, -1, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, -1, 29, 30,
+ 31, 32, 33, -1, 35, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, -1, -1, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, -1,
+ -1, 29, -1, 31, 32, 33, -1, 35, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12, -1, -1, -1,
+ -1, 17, 18, -1, 20, 21, 22, 23, -1, -1,
+ -1, -1, -1, -1, -1, 31, 32
+};
+/* This file comes from bison-1.28. */
+
+/* Skeleton output parser for bison,
+ Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* This is the parser code that is written into each bison parser
+ when the %semantic_parser declaration is not specified in the grammar.
+ It was written by Richard Stallman by simplifying the hairy parser
+ used when %semantic_parser is specified. */
+
+/* Note: there must be only one dollar sign in this file.
+ It is replaced by the list of actions, each action
+ as one case of the switch. */
+
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+
+#define YYTERROR 1
+
+#define YYLEX yylex()
+
+/* If nonreentrant, generate the variables here */
+
+static int yychar; /* the lookahead symbol */
+YYSTYPE yylval; /* the semantic value of the */
+ /* lookahead symbol */
+
+static int yynerrs; /* number of parse errors so far */
+
+/* YYINITDEPTH indicates the initial size of the parser's stacks */
+
+#ifndef YYINITDEPTH
+#define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH is the maximum size the stacks can grow to
+ (effective only if the built-in stack extension method is used). */
+
+#if YYMAXDEPTH == 0
+#undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH 10000
+#endif
+
+#define YYPARSE_PARAM_ARG
+#define YYPARSE_PARAM_DECL
+
+/* Prevent warning if -Wstrict-prototypes. */
+#ifdef __GNUC__
+static int yyparse();
+#endif
+
+static int
+yyparse(YYPARSE_PARAM_ARG)
+ YYPARSE_PARAM_DECL
+{
+ int yystate;
+ int yyn;
+ short *yyssp;
+ YYSTYPE *yyvsp;
+ int yyerrstatus; /* number of tokens to shift before error messages enabled */
+ int yychar1 = 0; /* lookahead token as an internal (translated) token number */
+
+ short yyssa[YYINITDEPTH]; /* the state stack */
+ YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
+
+ short *yyss = yyssa; /* refer to the stacks through separate pointers */
+ YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
+
+ int yystacksize = YYINITDEPTH;
+ int yyfree_stacks = 0;
+
+ YYSTYPE yyval; /* the variable used to return */
+ yyval.dval = nullptr;
+ /* semantic values from the action */
+ /* routines */
+
+ int yylen;
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss - 1;
+ yyvsp = yyvs;
+
+/* Push a new state, which is found in yystate . */
+/* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here events the stacks. */
+yynewstate:
+
+ *++yyssp = sal::static_int_cast<short>(yystate);
+
+ if (yyssp >= yyss + yystacksize - 1)
+ {
+ /* Give user a chance to reallocate the stack */
+ /* Use copies of these so that the &'s don't force the real ones into memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ short *yyss1 = yyss;
+
+ /* Get the current used size of the three stacks, in elements. */
+ int size = yyssp - yyss + 1;
+
+ /* Extend the stack our own way. */
+ if (yystacksize >= YYMAXDEPTH)
+ {
+ yyerror("parser stack overflow");
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+ }
+ return 2;
+ }
+ yystacksize *= 2;
+ if (yystacksize > YYMAXDEPTH)
+ yystacksize = YYMAXDEPTH;
+ yyfree_stacks = 1;
+ yyss = static_cast<short *>(malloc (yystacksize * sizeof (*yyssp)));
+ memcpy (yyss, yyss1, size * sizeof (*yyssp));
+ yyvs = static_cast<YYSTYPE *>(malloc (yystacksize * sizeof (*yyvsp)));
+ memcpy (yyvs, yyvs1, size * sizeof (*yyvsp));
+
+ // https://lists.gnu.org/archive/html/bug-bison/2001-11/msg00021.html
+ if (yyss1 != yyssa)
+ free (yyss1);
+ if (yyvs1 != yyvsa)
+ free (yyvs1);
+
+ yyssp = yyss + size - 1;
+ yyvsp = yyvs + size - 1;
+
+ if (yyssp >= yyss + yystacksize - 1)
+ YYABORT;
+ }
+
+ goto yybackup;
+ yybackup:
+
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
+/* yyresume: */
+
+ /* First try to decide what to do without reference to lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* yychar is either YYEMPTY or YYEOF
+ or a valid token in external form. */
+
+ if (yychar == YYEMPTY)
+ {
+ yychar = YYLEX;
+ }
+
+ /* Convert token to internal form (in yychar1) for indexing tables with */
+
+ if (yychar <= 0) /* This means end of input. */
+ {
+ yychar1 = 0;
+ yychar = YYEOF; /* Don't call YYLEX any more */
+
+ }
+ else
+ {
+ yychar1 = YYTRANSLATE(yychar);
+
+ }
+
+ yyn += yychar1;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
+ goto yydefault;
+
+ yyn = yytable[yyn];
+
+ /* yyn is what to do for this token type in this state.
+ Negative => reduce, -yyn is rule number.
+ Positive => shift, yyn is new state.
+ New state is final state => don't bother to shift,
+ just return success.
+ 0, or most negative number => error. */
+
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrlab;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+
+ /* Discard the token being shifted unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ *++yyvsp = yylval;
+
+ /* count tokens shifted since error; after three, turn off error status. */
+ if (yyerrstatus) yyerrstatus--;
+
+ yystate = yyn;
+ goto yynewstate;
+
+/* Do the default action for the current state. */
+yydefault:
+
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+
+/* Do a reduction. yyn is the number of a rule to reduce with. */
+yyreduce:
+ yylen = yyr2[yyn];
+ if (yylen > 0)
+ yyval = yyvsp[1-yylen]; /* implement default value of the action */
+
+ switch (yyn) {
+
+case 1:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 2:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 3:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 4:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 5:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 6:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 7:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 8:
+{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 9:
+{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 10:
+{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 11:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 12:
+{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 13:
+{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 14:
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 15:
+{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value.reset(strdup("|")); debug("Identifier : '|'\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 16:
+{ yyval.ptr = new Node(ID_NUMBER); yyval.ptr->value.reset(strdup(yyvsp[0].dval)); debug("Number : %s\n",yyvsp[0].dval); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 17:
+{ yyval.ptr = new Node(ID_STRING); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("String : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 18:
+{ yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[0].ptr; debug("PrimaryExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 19:
+{ yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyval.ptr->next = yyvsp[0].ptr; debug("PrimaryExpr : PrimaryExpr Identifier\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 20:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("(")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 21:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("[")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 22:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("{")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 23:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("<")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 24:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("|")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 25:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("||")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 26:
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 27:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(")")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 28:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("]")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 29:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("}")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 30:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(">")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 31:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("|")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 32:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("||")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 33:
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 34:
+{ yyval.ptr = new Node(ID_FENCE); yyval.ptr->child=yyvsp[-2].ptr; yyvsp[-2].ptr->next=yyvsp[-1].ptr; yyvsp[-1].ptr->next=yyvsp[0].ptr; debug("Fence \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 35:
+{ yyval.ptr = new Node(ID_PARENTH); yyval.ptr->child = yyvsp[-1].ptr; debug("Parenth: '(' ExprList ')' \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 36:
+{ yyval.ptr = new Node(ID_PARENTH); debug("Parenth: '(' ')' \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 37:
+{ yyval.ptr = new Node(ID_BLOCK); yyval.ptr->child = yyvsp[-1].ptr; debug("Block: '{' ExprList '}' \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 38:
+{ yyval.ptr = new Node(ID_BLOCK); debug("Block: '{' '}' \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 39:
+{ yyval.ptr = new Node(ID_BRACKET); yyval.ptr->child = yyvsp[-1].ptr; debug("Bracket \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 40:
+{ yyval.ptr = new Node(ID_BRACKET); debug("Bracket \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 41:
+{ yyval.ptr = new Node(ID_SUBEXPR); yyval.ptr->child = yyvsp[-2].ptr; yyvsp[-2].ptr->next = yyvsp[0].ptr; debug("SubSupExpr : ID_SUBEXPR\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 42:
+{ yyval.ptr = new Node(ID_SUPEXPR); yyval.ptr->child = yyvsp[-2].ptr; yyvsp[-2].ptr->next = yyvsp[0].ptr; debug("SubSupExpr : ID_SUPEXPR\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 43:
+{ yyval.ptr = new Node(ID_SUBSUPEXPR); yyval.ptr->child=yyvsp[-4].ptr; yyvsp[-4].ptr->next=yyvsp[-2].ptr; yyvsp[-2].ptr->next=yyvsp[0].ptr; debug("SubSupExpr : ID_SUBSUPEXPR\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 44:
+{ yyval.ptr = new Node(ID_FRACTIONEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("FractionExpr : %s\n",yyvsp[-2].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 45:
+{ yyval.ptr = new Node(ID_OVER); yyval.ptr->child = yyvsp[-3].ptr; yyvsp[-3].ptr->next = yyvsp[-1].ptr; debug("OverExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 46:
+{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Accent : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 47:
+{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->child=yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("AccentExpr \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 48:
+{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Decoration : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 49:
+{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("DecorationExpr \n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 50:
+{ yyval.ptr = new Node(ID_SQRTEXPR); yyval.ptr->child = yyvsp[0].ptr; debug("RootExpr : %s\n", yyvsp[-1].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 51:
+{ yyval.ptr = new Node(ID_ROOTEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next= yyvsp[0].ptr; debug("RootExpr : %s\n", yyvsp[-2].str); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 52:
+{ yyval.ptr = new Node(ID_BEGIN); yyval.ptr->child = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("BeginExpr\n");
+ break;}
+case 53:
+{ yyval.ptr = new Node(ID_BEGIN); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next= yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("BeginExpr\n");
+ break;}
+case 54:
+{ yyval.ptr = new Node(ID_END); yyval.ptr->child = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("EndExpr\n");
+ break;}
+case 55:
+{ yyval.ptr = new Node(ID_MATHML); yyval.ptr->child = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); top = yyval.ptr; debug("MathML\n");
+ break;}
+case 56:
+{ yyval.ptr = new Node(ID_LINES); yyval.ptr->child = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("Lines\n");
+ break;}
+case 57:
+{ yyval.ptr = new Node(ID_LINES); yyval.ptr->child = yyvsp[-2].ptr; yyvsp[-2].ptr->next = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("Lines\n");
+ break;}
+case 58:
+{ yyval.ptr = new Node(ID_LINE); yyval.ptr->child = yyvsp[0].ptr; nodelist.emplace_back(yyval.ptr); debug("Line\n");
+ break;}
+case 59:
+{ yyval.ptr = new Node(ID_EXPRLIST); yyval.ptr->child = yyvsp[0].ptr; debug("ExprList : Expr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 60:
+{ yyval.ptr = new Node(ID_EXPRLIST); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("ExprList : ExprList Expr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 61:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : Block\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 62:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : Parenth\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 63:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : Fence\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 64:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : SubSupExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 65:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : FractionExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 66:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : OverExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 67:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : DecorationExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 68:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : RootExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 69:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : AccentExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 70:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : PrimaryExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 71:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : BeginExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+case 72:
+{ yyval.ptr = new Node(ID_EXPR); yyval.ptr->child = yyvsp[0].ptr; debug("Expr : EndExpr\n"); nodelist.emplace_back(yyval.ptr);
+ break;}
+}
+ /* the action file gets copied in place of this dollarsign */
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+
+ *++yyvsp = yyval;
+
+ /* Now "shift" the result of the reduction.
+ Determine what state that goes to,
+ based on the state we popped back to
+ and the rule number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
+ if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTBASE];
+
+ goto yynewstate;
+
+yyerrlab: /* here on detecting error */
+
+ if (! yyerrstatus)
+ /* If not already recovering from an error, report this error. */
+ {
+ ++yynerrs;
+
+#ifdef YYERROR_VERBOSE
+ yyn = yypact[yystate];
+
+ if (yyn > YYFLAG && yyn < YYLAST)
+ {
+ int size = 0;
+ char *msg;
+ int x, count;
+
+ count = 0;
+ /* Start X at -yyn if negative to avoid negative indexes in yycheck. */
+ for (x = ((yyn < 0) ? -yyn : 0);
+ x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ size += strlen(yytname[x]) + 15, count++;
+ msg = (char *) malloc(size + 15);
+ if (msg != 0)
+ {
+ strcpy(msg, "parse error");
+
+ if (count < 5)
+ {
+ count = 0;
+ for (x = ((yyn < 0) ? -yyn : 0);
+ x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ {
+ strcat(msg, count == 0 ? ", expecting `" : " or `");
+ strcat(msg, yytname[x]);
+ strcat(msg, "'");
+ count++;
+ }
+ }
+ yyerror(msg);
+ free(msg);
+ }
+ else
+ yyerror ("parse error; also virtual memory exceeded");
+ }
+ else
+#endif /* YYERROR_VERBOSE */
+ yyerror("parse error");
+ }
+
+ goto yyerrlab1;
+yyerrlab1: /* here on error raised explicitly by an action */
+
+ if (yyerrstatus == 3)
+ {
+ /* if just tried and failed to reuse lookahead token after an error, discard it. */
+
+ /* return failure if at end of input */
+ if (yychar == YYEOF)
+ YYABORT;
+
+ yychar = YYEMPTY;
+ }
+
+ /* Else will try to reuse lookahead token
+ after shifting the error token. */
+
+ yyerrstatus = 3; /* Each real token shifted decrements this */
+
+ goto yyerrhandle;
+
+yyerrdefault: /* current state does not do anything special for the error token. */
+
+#if 0
+ /* This is wrong; only states that explicitly want error tokens
+ should shift them. */
+ yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
+ if (yyn) goto yydefault;
+#endif
+
+yyerrpop: /* pop the current state because it cannot handle the error token */
+
+ if (yyssp == yyss) YYABORT;
+ yyvsp--;
+ yystate = *--yyssp;
+
+yyerrhandle:
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yyerrdefault;
+
+ yyn += YYTERROR;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
+ goto yyerrdefault;
+
+ yyn = yytable[yyn];
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrpop;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrpop;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+ yystate = yyn;
+ goto yynewstate;
+
+ yyacceptlab:
+ /* YYACCEPT comes here. */
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+ }
+ return 0;
+
+ yyabortlab:
+ /* YYABORT comes here. */
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+ }
+ return 1;
+}
+
+Node *mainParse(const char *_code)
+{
+ initFlex( _code );
+ top = nullptr;
+ yyparse();
+ deinitFlex();
+
+ if( top )
+ return top;
+ else
+ return nullptr;
+}
+
+void yyerror(const char * /*err*/)
+{
+// printf("REALKING ERR[%s]\n",err);
+ // if error, delete all nodes.
+ nodelist.clear();
+ top = nullptr;
+}
+
+#ifndef PARSE_DEBUG
+int debug(const char * /*format*/, ...)
+{
+ return 0;
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/grammar.h b/hwpfilter/source/grammar.h
new file mode 100644
index 000000000..4d69482cd
--- /dev/null
+++ b/hwpfilter/source/grammar.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+typedef union {
+ const char *dval;
+ const char *str;
+ Node *ptr;
+} YYSTYPE;
+#define ACCENT 257
+#define SMALL_GREEK 258
+#define CAPITAL_GREEK 259
+#define BINARY_OPERATOR 260
+#define RELATION_OPERATOR 261
+#define ARROW 262
+#define GENERAL_IDEN 263
+#define GENERAL_OPER 264
+#define BIG_SYMBOL 265
+#define FUNCTION 266
+#define ROOT 267
+#define FRACTION 268
+#define SUBSUP 269
+#define EQOVER 270
+#define DELIMETER 271
+#define LARGE_DELIM 272
+#define DECORATION 273
+#define SPACE_SYMBOL 274
+#define CHARACTER 275
+#define STRING 276
+#define OPERATOR 277
+#define EQBEGIN 278
+#define EQEND 279
+#define EQLEFT 280
+#define EQRIGHT 281
+#define NEWLINE 282
+#define LEFT_DELIM 283
+#define RIGHT_DELIM 284
+#define DIGIT 285
+
+extern YYSTYPE yylval;
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/grammar.hxx b/hwpfilter/source/grammar.hxx
new file mode 100644
index 000000000..a4a2e39cb
--- /dev/null
+++ b/hwpfilter/source/grammar.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_GRAMMAR_HXX
+#define INCLUDED_HWPFILTER_SOURCE_GRAMMAR_HXX
+
+#include <sal/config.h>
+
+class Node;
+
+Node* mainParse(char const* _code);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx
new file mode 100644
index 000000000..52e5ab653
--- /dev/null
+++ b/hwpfilter/source/hbox.cxx
@@ -0,0 +1,715 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+
+#include "hwpfile.h"
+#include "hbox.h"
+#include "hpara.h"
+#include "hutil.h"
+#include "htags.h"
+#include "drawdef.h"
+#include "hcode.h"
+#include "datecode.h"
+
+#include <rtl/character.hxx>
+
+int HBox::boxCount = 0;
+
+HBox::HBox(hchar hch)
+{
+ hh = hch;
+ boxCount++;
+}
+
+
+HBox::~HBox()
+{
+ boxCount--;
+}
+
+
+int HBox::WSize()
+{
+ static const int wsize[32] =
+ {
+ 1, 4, 4, 4, 4, 4, 4, 42, /* dateform */
+ 48, 4, 4, 4, 4, 1, 4, 4, /* hidden */
+ 4, 4, 4, 4, 4, 4, 12, 5, /* chcompose */
+ 3, 3, 123, 4, 32, 4, 2, 2
+ };
+
+ if (hh < 32)
+ return wsize[hh];
+ else
+ return 1;
+}
+
+
+// skip block
+SkipData::SkipData(hchar hch)
+ : HBox(hch)
+{
+}
+
+SkipData::~SkipData()
+{
+}
+
+
+// FieldCode [5]
+FieldCode::FieldCode()
+ : HBox(CH_FIELD)
+ , location_info(0)
+{
+}
+
+FieldCode::~FieldCode()
+{
+}
+
+// book mark(6)
+Bookmark::Bookmark()
+ : HBox(CH_BOOKMARK)
+ , dummy(0)
+ , type(0)
+{
+}
+
+Bookmark::~Bookmark()
+{
+}
+
+// date format(7)
+DateFormat::DateFormat()
+ : HBox(CH_DATE_FORM)
+ , dummy(0)
+{
+}
+
+// date code(8)
+DateCode::DateCode()
+ : HBox(CH_DATE_CODE)
+ , format{0}
+ , date{0}
+ , dummy(0)
+ , key(0)
+{
+}
+
+const hchar kor_week[] =
+{
+ 0xB7A9, 0xB6A9, 0xD1C1, 0xAE81, 0xA1A2, 0x8B71, 0xC9A1
+};
+const hchar china_week[] =
+{
+ 0x4CC8, 0x4BE4, 0x525A, 0x48D8, 0x45AB, 0x4270, 0x50B4
+};
+const char eng_week[] = { "SunMonTueWedThuFriSat" };
+const char eng_mon[] = { "JanFebMarAprMayJunJulAugSepOctNovDec" };
+const char * const en_mon[] =
+{
+ "January", "February", "March", "April", "May", "June", "July",
+ "August", "September", "October", "November", "December"
+};
+const char * const en_week[] =
+{
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"
+};
+
+hchar_string DateCode::GetString()
+{
+ hchar_string ret;
+ const hchar *fmt;
+ int i, num;
+ const char *form;
+ char cbuf[256];
+ bool is_pm, add_zero;
+
+ add_zero = false;
+ format[DATE_SIZE - 1] = 0;
+ fmt = format[0] ? format : defaultform;
+
+ for (; *fmt && (ret.size() < DATE_SIZE); fmt++)
+ {
+ form = add_zero ? "%02d" : "%d";
+
+ add_zero = false;
+ is_pm = (date[HOUR] >= 12);
+ *cbuf = 0;
+ num = -1;
+
+ switch (*fmt)
+ {
+ case '0':
+ add_zero = true;
+ break;
+ case '1':
+ num = date[YEAR];
+ form = "%04d";
+ break;
+ case '!':
+ num = date[YEAR] % 100;
+ break;
+ case '2':
+ num = date[MONTH];
+ break;
+ case '@':
+ {
+ static_assert((std::size(eng_mon) - 1) / 3 == 12);
+ size_t nIndex = o3tl::make_unsigned(date[MONTH] - 1) % 12;
+ memcpy(cbuf, eng_mon + nIndex * 3, 3);
+ cbuf[3] = '.';
+ cbuf[4] = 0;
+ break;
+ }
+ case '*':
+ {
+ size_t nIndex = o3tl::make_unsigned(date[MONTH] - 1) % std::size(en_mon);
+ strncat(cbuf, en_mon[nIndex], sizeof(cbuf) - strlen(cbuf) - 1);
+ break;
+ }
+ case '3': /* 'D' is day of korean */
+ num = date[DAY];
+ break;
+ case '#':
+ num = date[DAY];
+ switch (date[DAY] % 10)
+ {
+ case 1:
+ form = "%dst";
+ break;
+ case 2:
+ form = "%dnd";
+ break;
+ case 3:
+ form = "%drd";
+ break;
+ default:
+ form = "%dth";
+ break;
+ }
+ break;
+ case '4':
+ num = date[HOUR] - ((date[HOUR] > 12) ? 12 : 0);
+ break;
+ case '$':
+ num = date[HOUR];
+ break;
+ case '5':
+ case '%':
+ num = date[MIN];
+ break;
+ case '6':
+ {
+ size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(kor_week);
+ ret.push_back(kor_week[nIndex]);
+ break;
+ }
+ case '^':
+ {
+ static_assert((std::size(eng_week) - 1) / 3 == 7);
+ size_t nIndex = o3tl::make_unsigned(date[WEEK]) % 7;
+ memcpy(cbuf, eng_week + nIndex * 3, 3);
+ cbuf[3] = '.';
+ cbuf[4] = 0;
+ break;
+ }
+ case '_':
+ {
+ size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(en_week);
+ strncat(cbuf, en_week[nIndex], sizeof(cbuf) - strlen(cbuf) - 1);
+ break;
+ }
+ case '7':
+ ret.push_back(0xB5A1);
+ ret.push_back(is_pm ? 0xD281 : 0xB8E5);
+ break;
+ case '&':
+ strncat(cbuf, is_pm ? "p.m." : "a.m.", sizeof(cbuf) - strlen(cbuf) - 1);
+ break;
+ case '+':
+ strncat(cbuf, is_pm ? "P.M." : "A.M.", sizeof(cbuf) - strlen(cbuf) - 1);
+ break;
+ case '8': // 2.5 feature
+ case '9':
+#if 0
+// LATER
+ mkcurfilename(cbuf, *fmt);
+ for (i = 0; cbuf[i] != 0 && slen > 1; i++)
+ { //for hangle filename
+ if (cbuf[i] & 0x80 && cbuf[i + 1] != 0)
+ {
+ *d++ = (cbuf[i] << 8) | cbuf[i + 1];
+ i++;
+ }
+ else
+ *d++ = cbuf[i];
+ slen--;
+ }
+#endif
+ cbuf[0] = 0;
+ break;
+ case '~': // 3.0b feature
+ if (fmt[1] == 0)
+ break;
+ fmt++;
+ if (*fmt == '6')
+ {
+ size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(china_week);
+ ret.push_back(china_week[nIndex]);
+ break;
+ }
+ break;
+ default:
+ if (*fmt == '\\' && *++fmt == 0)
+ goto done;
+ ret.push_back(*fmt);
+ }
+ if (num != -1)
+ sprintf(cbuf, form, num);
+ for (i = 0; 0 != cbuf[i]; i++)
+ {
+ ret.push_back(*(cbuf + i));
+ }
+ }
+ done:
+ return ret;
+}
+
+// tab(9)
+Tab::Tab()
+ : HBox(CH_TAB)
+ , width(0)
+ , leader(0)
+ , dummy(0)
+{
+}
+
+// floating box
+FBox::FBox(hchar hch)
+ : HBox(hch)
+ , zorder(0)
+ , option(0)
+ , ctrl_ch(0)
+ , box_xs(0)
+ , box_ys(0)
+ , cap_xs(0)
+ , cap_ys(0)
+ , xs(0)
+ , ys(0)
+ , cap_margin(0)
+ , xpos_type(0)
+ , ypos_type(0)
+ , smart_linesp(0)
+ , boundsy(0)
+ , boundey(0)
+ , boundx(0)
+ , draw(0)
+ , pgx(0)
+ , pgy(0)
+ , pgno(0)
+ , showpg(0)
+{
+}
+
+FBox::~FBox()
+{
+}
+
+// tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
+TxtBox::TxtBox()
+ : FBox(CH_TEXT_BOX)
+ , dummy(0)
+ , dummy1(0)
+ , cap_len(0)
+ , next_box(0)
+ , dummy2(0)
+ , reserved1(0)
+ , cap_pos(0)
+ , num(0)
+ , dummy3(0)
+ , baseline(0)
+ , type(0)
+ , nCell(0)
+ , protect(0)
+ , m_pTable(nullptr)
+{
+ reserved[0] = reserved[1] = 0;
+}
+
+TxtBox::~TxtBox()
+{
+}
+
+// picture(11)
+
+Picture::Picture()
+ : FBox(CH_PICTURE)
+ , reserved{0}
+ , dummy(0)
+ , follow_block_size(0)
+ , dummy1(0)
+ , dummy2(0)
+ , reserved1(0)
+ , cap_pos(0)
+ , num(0)
+ , pictype(0)
+ , skip{0}
+ , scale{0}
+ , picinfo{}
+ , reserved3{0}
+ , ishyper(false)
+{
+}
+
+Picture::~Picture()
+{
+ if (pictype == PICTYPE_DRAW)
+ delete picinfo.picdraw.hdo;
+}
+
+
+// line(14)
+// hidden(15)
+Hidden::~Hidden()
+{
+}
+
+
+// header/footer(16)
+HeaderFooter::~HeaderFooter()
+{
+}
+
+
+// footnote(17)
+Footnote::~Footnote()
+{
+}
+
+
+// auto number(18)
+// new number(19)
+// show page number (20)
+// Start/Hide odd-numbered side (21)
+
+// mail merge(22)
+hchar_string MailMerge::GetString()
+{
+ return hchar_string();
+}
+
+
+// character composition(23)
+// hyphen(24)
+// toc mark(25)
+// index mark(26)
+// outline(28)
+
+#define OL_HANGL_JASO 0
+#define OL_HANGL_KANATA 1
+
+static hchar olHanglJaso(int num, int type)
+{
+ static const unsigned char han_init[] =
+ { 0x88, 0x90, 0x94, 0x9c, 0xa0, 0xa4, 0xac, 0xb4, 0xb8, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0 };
+ static const unsigned char jung[] = { 3, 5, 7, 11, 13, 19, 20, 26, 27, 29, 30 };
+ static const unsigned char jung2[] = { 3, 7, 13, 20, 27, 29, 30 };
+
+ hchar hh = 0;
+
+ if (type == OL_HANGL_JASO)
+ {
+ num = num % (14 + SAL_N_ELEMENTS(jung));
+
+ if (num < 14)
+ hh = (han_init[num] << 8) | 'A';
+ else
+ hh = (jung[num - 14] << 5) | 0x8401;
+ }
+ else
+ {
+ if (num < 14)
+ hh = (han_init[num] << 8) | 'a';
+ else
+ {
+ int j = (num / 14) % SAL_N_ELEMENTS(jung2);
+
+ num = num % 14;
+ hh = (han_init[num] << 8) | (jung2[j] << 5) | 1;
+ }
+ }
+ return hh;
+}
+
+
+static const hchar *GetOutlineStyleChars(int style)
+{
+ static const hchar out_bul_style_entry[5][MAX_OUTLINE_LEVEL+1] = // extern
+ {
+ { // 0 OLSTY_BULLET1
+ 0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000
+ },
+ { // 1
+ 0x2f18, 0x2f12, 0x2f06, 0x2f00, 0x2f36, 0x2f30, 0x2043, 0x0000
+ },
+ { // 2
+ 0x2f26, 0x2f20, 0x2f06, 0x2f00, 0x2f16, 0x2f10, 0x2043, 0x0000
+ },
+ { // 3
+ 0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000
+ },
+ {
+ 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000, 0x0000, 0x0000
+ },
+ };
+ if (style >= OLSTY_BULLET1 && style <= OLSTY_BULLET5)
+ return out_bul_style_entry[style - OLSTY_BULLET1];
+ return nullptr;
+}
+
+
+static void getOutlineNumStr(int style, int level, int num, hchar * hstr)
+{
+ enum
+ {
+ U_ROM = 0x01, L_ROM = 0x02, U_ENG = 0x04, L_ENG = 0x08,
+ HAN = 0x10, NUM = 0x20, L_BR = 0x40, R_BR = 0x80
+ };
+ static const unsigned char type_tbl[][MAX_OUTLINE_LEVEL] =
+ {
+ {
+ U_ROM, HAN, NUM, HAN | R_BR, L_BR | NUM | R_BR,
+ L_BR | HAN | R_BR, L_ROM | R_BR
+ },
+ {
+ U_ROM, U_ENG, NUM, L_ENG | R_BR, L_BR | NUM | R_BR,
+ L_BR | L_ENG | R_BR, L_ROM | R_BR
+ },
+ {
+ NUM, HAN, L_BR | NUM | R_BR, L_BR | HAN | R_BR, NUM |
+ R_BR, HAN | R_BR, L_ENG
+ }
+ };
+ char fmt = type_tbl[style - OLSTY_NUMSIG1][level];
+ char buf[80], *ptr;
+
+ if (num < 1)
+ num = 1;
+ if (fmt & L_BR)
+ *hstr++ = '(';
+ if (fmt & NUM)
+ {
+ sprintf(buf, "%d", num);
+ str2hstr(buf, hstr);
+ hstr += strlen(buf);
+ }
+ else if (fmt & (U_ROM | L_ROM))
+ {
+ num2roman(num, buf);
+ if (fmt & U_ROM)
+ {
+ ptr = buf;
+ while (*ptr)
+ {
+ *ptr = sal::static_int_cast<char>(
+ rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr)));
+ ptr++;
+ }
+ }
+ str2hstr(buf, hstr);
+ hstr += strlen(buf);
+ }
+ else
+ {
+ num = (num - 1) % 26;
+ if (fmt & U_ENG)
+ *hstr++ = sal::static_int_cast<hchar>('A' + num);
+ else if (fmt & L_ENG)
+ *hstr++ = sal::static_int_cast<hchar>('a' + num);
+ else if (fmt & HAN)
+ *hstr++ = olHanglJaso(num, OL_HANGL_KANATA);
+ }
+ *hstr++ = (fmt & R_BR) ? ')' : '.';
+ *hstr = 0;
+}
+
+
+enum
+{ OUTLINE_ON, OUTLINE_NUM };
+
+/* level starts from zero. ex) '1.1.1.' is the level 2.
+ number has the value. ex) '1.2.1' has '1,2,1'
+ style has the value which starts from 1 according to the definition in hbox.h
+ */
+OUString Outline::GetUnicode() const
+{
+ const hchar *p;
+ hchar buffer[255];
+
+ buffer[0] = 0;
+ if (kind == OUTLINE_NUM)
+ {
+ int levelnum;
+ switch (shape)
+ {
+ case OLSTY_NUMS1:
+ case OLSTY_NUMS2:
+ {
+ char cur_num_str[10], buf[80];
+ int i;
+
+ buf[0] = 0;
+ for (i = 0; i <= level; i++)
+ {
+ levelnum = ((number[i] < 1) ? 1 : number[i]);
+ if (shape == OLSTY_NUMS2 && i && i == level)
+ sprintf(cur_num_str, "%d%c", levelnum, 0);
+ else
+ sprintf(cur_num_str, "%d%c", levelnum, '.');
+ strcat(buf, cur_num_str);
+ }
+ str2hstr(buf, buffer);
+ return hstr2OUString(buffer);
+ }
+ case OLSTY_NUMSIG1:
+ case OLSTY_NUMSIG2:
+ case OLSTY_NUMSIG3:
+ {
+ if (level < std::size(number))
+ getOutlineNumStr(shape, level, number[level], buffer);
+ return hstr2OUString(buffer);
+ }
+ case OLSTY_BULLET1:
+ case OLSTY_BULLET2:
+ case OLSTY_BULLET3:
+ case OLSTY_BULLET4:
+ case OLSTY_BULLET5:
+ {
+ if (level < MAX_OUTLINE_LEVEL)
+ {
+ p = GetOutlineStyleChars(shape);
+ buffer[0] = p[level];
+ buffer[1] = 0;
+ }
+ return hstr2OUString(buffer);
+ }
+ case OLSTY_USER:
+ case OLSTY_BULUSER:
+ {
+ char dest[80];
+ int l = 0;
+ unsigned int i = level;
+ if (i < std::size(deco) && deco[i][0]) {
+ buffer[l++] = deco[i][0];
+ }
+/* level starts from zero. ex) '1.1.1.' is the level 2.
+ number has the value. ex) '1.2.1' has '1,2,1'
+ style has the value which starts from 1 according to the definition in hbox.h
+ */
+ if (i < std::size(user_shape))
+ {
+ switch( user_shape[i] )
+ {
+ case 0:
+ buffer[l++] = '1' + number[i] - 1;
+ break;
+ case 1: /* Uppercase Roman */
+ case 2: /* Lowercase Roman */
+ num2roman(number[i], dest);
+ if( user_shape[i] == 1 ){
+ char *ptr = dest;
+ while( *ptr )
+ {
+ *ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr)));
+ ptr++;
+ }
+ }
+ str2hstr(dest, buffer + l);
+ l += strlen(dest);
+ break;
+ case 3:
+ buffer[l++] = 'A' + number[i] -1;
+ break;
+ case 4:
+ buffer[l++] = 'a' + number[i] -1;
+ break;
+ case 5:
+ buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_KANATA);
+ break;
+ case 6:
+ buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_JASO);
+ break;
+ case 7: /* Chinese numbers: the number represented by the general */
+ buffer[l++] = '1' + number[i] -1;
+ break;
+ case 8: /* Circled numbers */
+ buffer[l++] = 0x2e00 + number[i];
+ break;
+ case 9: /* Circled lowercase alphabet */
+ buffer[l++] = 0x2c20 + number[i];
+ break;
+ case 10: /* Circled Korean Alphabet */
+ buffer[l++] = 0x2c50 + number[i] -1;
+ break;
+ case 11: /* Circled Korean Characters */
+ buffer[l++] = 0x2c40 + number[i] -1;
+ break;
+ case 12: /* Sequenced numbers. */
+ {
+ char cur_num_str[10],buf[80];
+ int j;
+ buf[0] = 0;
+ for (j = 0; j <= level; j++)
+ {
+ levelnum = ((number[j] < 1) ? 1 : number[j]);
+ if ((j && j == level) || (j == level && deco[i][1]))
+ sprintf(cur_num_str, "%d%c", levelnum, 0);
+ else
+ sprintf(cur_num_str, "%d%c", levelnum, '.');
+ strcat(buf, cur_num_str);
+ }
+ str2hstr(buf, buffer + l);
+ l += strlen(buf);
+ break;
+ }
+ default:
+ buffer[l++] = user_shape[i];
+ break;
+ }
+ }
+ if (i < std::size(deco) && deco[i][1]) {
+ buffer[l++] = deco[i][1];
+ }
+ buffer[l] = 0;
+ return hstr2OUString(buffer);
+ }
+ }
+ }
+ return hstr2OUString(buffer);
+}
+
+
+/* Bundle of spaces (30) */
+/* Fixed-width spaces (31) */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
new file mode 100644
index 000000000..f7813b225
--- /dev/null
+++ b/hwpfilter/source/hbox.h
@@ -0,0 +1,1007 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HBOX_H
+#define INCLUDED_HWPFILTER_SOURCE_HBOX_H
+
+#include <sal/config.h>
+
+#include <array>
+#include <memory>
+
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hinfo.h"
+#include "hpara.h"
+
+/**
+ * The HBox class is the base class for all date classes in hwp document.
+ * For example, there are special character, table, image, etc.
+ * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
+ *
+ * @short Base class for characters
+ */
+struct HBox
+{
+ public:
+ hchar hh;
+
+/**
+ * Construct a HBox object with parameter hch.
+ * @param hch 16bit character being able to have Korean character.
+ */
+ explicit HBox( hchar hch );
+ virtual ~HBox();
+/**
+ * @returns The Size of HBox object
+ */
+ int WSize();
+/**
+ * Read properties from HIODevice object like stream, file, memory.
+ *
+ * @param hwpf HWPFile Object having all information for a hwp file.
+ * @returns True if reading from stream is successful.
+ */
+ virtual bool Read(HWPFile &hwpf);
+
+ private:
+ static int boxCount;
+};
+
+/**
+ * @short Class for skipping data.
+ */
+struct SkipData: public HBox
+{
+ explicit SkipData(hchar);
+ virtual ~SkipData() override;
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+struct DateCode;
+struct FieldCode : public HBox
+{
+ uchar type[2]; /* 2/0 - Formula, 3/0-document summary, 3/1 Personal Information, 3/2-creation date, 4/0-pressing mold */
+ std::array<char, 4> reserved1;
+ unsigned short location_info; /* 0 - End code, 1 - start code */
+ std::array<char, 22> reserved2;
+ std::unique_ptr<hchar[]> str1;
+ std::unique_ptr<hchar[]> str2;
+ std::unique_ptr<hchar[]> str3;
+
+ std::unique_ptr<DateCode> m_pDate;
+
+ FieldCode();
+ virtual ~FieldCode() override;
+ virtual bool Read(HWPFile &hwpf) override;
+};
+/**
+ * Kind of BOOKMARK
+ */
+enum
+{
+ BM_MARK,
+ BM_BEGIN,
+ BM_END
+};
+
+#define BMK_COMMENT_LEN 15
+
+/**
+ * @short Class for BOOKMARK
+ */
+struct Bookmark: public HBox
+{
+ hchar dummy;
+ hchar id[BMK_COMMENT_LEN + 1];
+ unsigned short type;
+
+ Bookmark();
+ virtual ~Bookmark() override;
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// date format(7)
+const int DATE_SIZE = 40;
+
+/**
+ * @short Class for saving date format made by user
+ */
+struct DateFormat: public HBox
+{
+ hchar format[DATE_SIZE];
+ hchar dummy;
+
+ DateFormat();
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/**
+ * @short Class for current date and time with specified format.
+ */
+struct DateCode: public HBox
+{
+ enum
+ {
+ YEAR, MONTH, WEEK, DAY, HOUR, MIN
+ };
+
+ hchar format[DATE_SIZE];
+/**
+ * year/month/week/day/hour/minute
+ */
+ short date[6];
+ hchar dummy;
+ unsigned char key;
+
+ DateCode();
+ virtual bool Read(HWPFile &hwpf) override;
+
+ hchar_string GetString();
+};
+
+/**
+ * @short Tab object
+ */
+struct Tab: public HBox
+{
+ hunit width;
+ unsigned short leader;
+ hchar dummy;
+
+ Tab();
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
+
+enum ttype { TBL_TYPE, TXT_TYPE, EQU_TYPE, BUTTON_TYPE, HYPERTEXT_TYPE };
+enum /* TxtBox->margin[n][?] */
+{
+ OUT_M, IN_M, CELL_M
+};
+enum /* TxtBox->margin[?][n] */
+{
+ L_M, R_M, T_M, B_M
+};
+enum anchor { CHAR_ANCHOR, PARA_ANCHOR, PAGE_ANCHOR, PAPER_ANCHOR };
+enum { TF_OCCUPY_SPACE, TF_TRANSPARENT,TF_AROUND_TEXT };
+enum
+{
+ CAP_OUT_BOT, CAP_OUT_TOP, CAP_IN_BOT, CAP_IN_TOP,
+ CAP_LEFT_BOT, CAP_LEFT_TOP, CAP_RIGHT_BOT, CAP_RIGHT_TOP,
+ EQU_CAP_POS
+};
+
+struct CellLine
+{
+ unsigned char key;
+ unsigned char top; // 0-No line, 1-single, 2-thick, 3-double
+ unsigned char bottom;
+ unsigned char left;
+ unsigned char right;
+ short color; // cell color
+ unsigned char shade; // <100%
+};
+/**
+ * A cell has four properties to specify the position for itself in hwp.
+ * @li xpos - distance between left border of cell and left border of table
+ * @li ypos - distance between top border of cell and top border of table
+ * @li width - distance between left border of cell and right border of cell
+ * @li height - distance between top border of cell and bottom border of table
+ * This is differ from the format of other office in fact cell has two properties
+ * - rowindex and column index.
+ *
+ * @short Cell object
+ */
+struct Cell // Cell
+{
+ unsigned char key; // Index value of border style
+ short p;
+ short color; // cell color
+ short x, y; // [x,y] cell pos
+ short w, h; // [x,y] cell size
+ short txthigh, cellhigh; // used maximum
+ unsigned char flag, changed, used; // unused(file)
+ unsigned char ver_align; // vertical align {1=center}
+ unsigned char linetype[4]; // [left,right,top,bottom]
+ unsigned char shade; // <100%
+ unsigned char diagonal; // { 0=none,\=1,/=2,X=3}
+ unsigned char protect;
+
+ bool Read(HWPFile &hwpf);
+};
+
+/**
+ * @short Style for floating object
+ */
+struct FBoxStyle
+{
+/**
+ * Anchor type : paragraph , page, char
+ */
+ unsigned char anchor_type;
+/**
+ * Kind of wrap
+ */
+ unsigned char txtflow; /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
+/**
+ * Horizontal alignment
+ */
+ short xpos; // left, right, center, xx
+/**
+ * Vertical alignment
+ */
+ short ypos; // page top, bottom, yy
+/**
+ * Every margin of border
+ * [0-2][] : out/in/cell margin
+ * [][0-3] : left/right/top/bottom
+ */
+ short margin[3][4] = {}; // out : left, right, top, bottom
+/**
+ * Index of floating object
+ */
+ short boxnum; /* Numbers used as style-name in Libre Office */
+/**
+ * Type of floating object : line, txtbox, image, table, equalizer and button
+ */
+ unsigned char boxtype; // (L)ine, t(X)tbox, Picture - (G)
+ short cap_len; /* The length of the caption */
+
+ void *cell;
+
+ FBoxStyle()
+ : anchor_type(0)
+ , txtflow(0)
+ , xpos(0)
+ , ypos(0)
+ , boxnum(0)
+ , boxtype(0)
+ , cap_len(0)
+ , cell(nullptr)
+ {
+ }
+};
+
+/**
+ * This object is for floating object like table, image, line and so on.
+ *
+ * @short floating object
+ */
+struct FBox: public HBox
+{
+ int zorder;
+ short option; // draw frame
+ hchar ctrl_ch;
+ FBoxStyle style;
+
+ short box_xs, box_ys;
+ short cap_xs, cap_ys ;
+ short xs, ys; // ys = fig_ys + cap_ys + margin
+// xs = fig_xs + cap_xs + margin
+ short cap_margin;
+ char xpos_type, ypos_type;
+ unsigned char smart_linesp;
+
+/* In tbox or pic, this data exists in memory when running, isn't written to a file.
+ But in line, it will be written to a file.
+ */
+ short boundsy, boundey;
+ unsigned char boundx, draw;
+
+/**
+ * Physical x,y position.
+ */
+ short pgx, pgy; // physical xpos, ypos
+ short pgno, showpg; // pageno where code is
+
+ explicit FBox( hchar hch );
+ virtual ~FBox() override;
+};
+
+struct Table;
+/**
+ * The TxtBox class saves object properties about table, textbox, equalizer or button
+ */
+struct TxtBox: public FBox
+{
+ hchar reserved[2];
+ hchar dummy;
+
+ short dummy1; // to not change structure size */
+ short cap_len;
+ short next_box;
+ short dummy2; // to not change structure size */
+ unsigned char reserved1;
+/**
+ * caption position
+ */
+ short cap_pos; // caption pos
+ short num; // numbering
+
+ short dummy3;
+ short baseline; //(for equ)
+
+/**
+ * The value of type indicates as the below: zero is table, one is
+ * textbox, two is equalizer and three is button.
+ */
+ short type; // 0-table, 1-textbox, 2-수식, 3-button
+/**
+ * nCell is greater than one only for table, otherwise it is 1.
+ */
+ short nCell; //:=1 offset 80
+/**
+ * If value of protect is 1, size of cell can't change.
+ */
+ short protect; //1=size lock
+
+ std::unique_ptr<Cell[]> cell;
+ Table *m_pTable;
+/**
+ * Paragraph list
+ */
+ typedef std::vector<std::unique_ptr<HWPPara>> plist_t;
+ typedef std::vector<plist_t> plists_t;
+ plists_t plists;
+
+/**
+ * Caption
+ */
+ std::vector<std::unique_ptr<HWPPara>> caption;
+
+ TxtBox();
+ virtual ~TxtBox() override;
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+#define ALLOWED_GAP 5
+#define INIT_SIZE 20
+#define ADD_AMOUNT 10
+
+struct Columns
+{
+ std::unique_ptr<int[]> data;
+ size_t nCount;
+ size_t nTotal;
+ Columns(){
+ nCount = 0;
+ nTotal = INIT_SIZE;
+ data.reset(new int[nTotal]);
+ }
+
+ void AddColumnsSize(){
+ if (nTotal + ADD_AMOUNT < nTotal) // overflow
+ {
+ throw ::std::bad_alloc();
+ }
+ int* tmp = new int[nTotal + ADD_AMOUNT];
+ for (size_t i = 0 ; i < nTotal ; i++)
+ tmp[i] = data[i];
+ nTotal += ADD_AMOUNT;
+ data.reset(tmp);
+ }
+
+ void insert(int pos){
+ if( nCount == 0 ){
+ data[nCount++] = pos;
+ return;
+ }
+ for (size_t i = 0 ; i < nCount; i++ ) {
+ if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
+ return; // Already exist;
+ if( pos < data[i] ){
+ if( nCount == nTotal )
+ AddColumnsSize();
+ for (size_t j = nCount ; j > i ; j--)
+ data[j] = data[j-1];
+ data[i] = pos;
+ nCount++;
+ return;
+ }
+ }
+ // last position.
+ if( nCount == nTotal )
+ AddColumnsSize();
+ data[nCount++] = pos;
+ }
+
+ int getIndex(int pos)
+ {
+ if( pos == 0 )
+ return 0;
+ for (size_t i = 0 ; i < nCount; i++) {
+ if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
+ return i;
+ }
+ return -1;
+ }
+};
+
+struct Rows
+{
+ std::unique_ptr<int[]> data;
+ size_t nCount;
+ size_t nTotal;
+ Rows(){
+ nCount = 0;
+ nTotal = INIT_SIZE;
+ data.reset( new int[nTotal] );
+ }
+
+ void AddRowsSize(){
+ if (nTotal + ADD_AMOUNT < nTotal) // overflow
+ {
+ throw ::std::bad_alloc();
+ }
+ int* tmp = new int[nTotal + ADD_AMOUNT];
+ for (size_t i = 0 ; i < nTotal ; i++)
+ tmp[i] = data[i];
+ nTotal += ADD_AMOUNT;
+ data.reset(tmp);
+ }
+
+ void insert(int pos){
+ if( nCount == 0 ){
+ data[nCount++] = pos;
+ return;
+ }
+ for (size_t i = 0 ; i < nCount; i++) {
+ if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
+ return; // Already exist;
+ if( pos < data[i] ){
+ if( nCount == nTotal )
+ AddRowsSize();
+ for (size_t j = nCount ; j > i ; j--)
+ data[j] = data[j-1];
+ data[i] = pos;
+ nCount++;
+ return;
+ }
+ }
+ // last position.
+ if( nCount == nTotal )
+ AddRowsSize();
+ data[nCount++] = pos;
+ }
+
+ int getIndex(int pos)
+ {
+ if( pos == 0 )
+ return 0;
+ for (size_t i = 0 ; i < nCount; i++) {
+ if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
+ return i;
+ }
+ return -1;
+ }
+};
+
+struct TCell
+{
+ int nColumnIndex;
+ int nRowIndex;
+ int nColumnSpan;
+ int nRowSpan;
+ Cell *pCell;
+};
+
+struct Table
+{
+ Table() : box(nullptr) {};
+
+ Columns columns;
+ Rows rows;
+ std::vector<std::unique_ptr<TCell>> cells;
+ TxtBox *box;
+};
+
+/* picture (11) graphics, OLE graphics, inserted graphics, drawing */
+enum pictype
+{
+ PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
+ PICTYPE_DRAW, PICTYPE_UNKNOWN
+};
+/**
+ * @short External image file
+ */
+struct PicDefFile
+{
+ char path[256];
+ void *img;
+ bool skipfind;
+};
+
+/**
+ * @short Embedded image file
+ */
+struct PicDefEmbed
+{
+ char embname[16];
+};
+
+/**
+ * @short Win32 ole object
+ */
+struct PicDefOle
+{
+ char embname[16];
+ void *hwpole;
+};
+
+struct HWPDrawingObject;
+
+/**
+ * @short Drawing object of hwp
+ */
+struct PicDefDraw
+{
+ HWPDrawingObject *hdo;
+ uint zorder;
+ ZZRect vrect;
+ int mbrcnt;
+};
+
+/**
+ * @short For using common case
+ */
+struct PicDefUnknown
+{
+ char path[256];
+};
+
+typedef union
+{
+ PicDefFile picfile;
+ PicDefEmbed picembed;
+ PicDefOle picole;
+ PicDefDraw picdraw;
+ PicDefUnknown picun;
+} PicDef;
+
+/**
+ * There are four kinds of image.
+ * @li External image
+ * @li Embedded image
+ * @li Win32 ole object
+ * @li Drawing object of hwp
+ *
+ * @short Image object
+ */
+struct Picture: public FBox
+{
+ hchar reserved[2];
+ hchar dummy;
+/**
+ * follow_block_size is the size information of the Drawing object of hwp.
+ * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
+ */
+ uint follow_block_size; /* Additional information length. */
+ short dummy1; // to not change structure size */
+ short dummy2; // to not change structure size */
+ uchar reserved1;
+/**
+ * Position of caption
+ */
+ short cap_pos; // caption pos
+/**
+ * Index of current Picture object
+ */
+ short num; // numbering
+
+/**
+ * Type of this object
+ * It is one of external/ole/embedded/drawing picture
+ */
+ uchar pictype;
+ hunit skip[2];
+/**
+ * Ratio of magnification or reduction.
+ */
+ hunit scale[2];
+ PicDef picinfo;
+ char reserved3[9];
+
+ std::vector<std::unique_ptr<HWPPara>> caption;
+/**
+ * It's for the Drawing object
+ */
+ std::vector<unsigned char> follow; /* When the type of image is drawing, gives additional information. */
+
+ bool ishyper;
+
+ Picture();
+ virtual ~Picture() override;
+
+ virtual bool Read (HWPFile &hwpf) override;
+};
+
+// line (14)
+/**
+ * @short Line
+ */
+struct Line: public FBox
+{
+ hchar reserved[2];
+ hchar dummy;
+
+ char reserved2[8];
+
+ short sx, sy, ex, ey;
+ short width, shade, color;
+
+ Line();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// hidden(15)
+/**
+ * @short Hidden section
+ */
+struct Hidden: public HBox
+{
+ hchar reserved[2];
+ hchar dummy;
+
+ unsigned char info[8]; // h, next, dummy
+ std::vector<std::unique_ptr<HWPPara>> plist;
+
+ Hidden();
+ virtual ~Hidden() override;
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/**
+ * @short Header or footer
+ */
+struct HeaderFooter: public HBox
+{
+ hchar reserved[2];
+ hchar dummy;
+
+ unsigned char info[8];
+/**
+ * Header or footer
+ */
+ unsigned char type;
+ unsigned char where;
+ unsigned char linenumber;
+
+ unsigned int m_nPageNumber;
+
+/**
+ * Paragraph list of header or footer
+ */
+ std::vector<std::unique_ptr<HWPPara>> plist;
+
+ HeaderFooter();
+ virtual ~HeaderFooter() override;
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/**
+ * Both footnote and endnote are comment. Footnote is located at the end of paragraph; endnote is located at the end of page. The Footnote class represents footnote and endnote.
+ * @short Footnote or endnote
+ */
+struct Footnote: public HBox
+{
+ hchar reserved[2];
+ hchar dummy;
+
+ unsigned char info[8];
+/**
+ * The number of current footnote/endnote
+ */
+ unsigned short number;
+/**
+ * Set the type of Footnote either footnote or endnote.
+ */
+ unsigned short type;
+/**
+ * The width of the Footnote object.
+ */
+ hunit width;
+/**
+ * Paragraph list of Footnote objects
+ */
+ std::vector<std::unique_ptr<HWPPara>> plist;
+
+ Footnote();
+ virtual ~Footnote() override;
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// auto number(18)
+/**
+ * Kind of auto input number
+ */
+enum
+{
+ PGNUM_AUTO,
+ FNNUM_AUTO,
+ ENNUM_AUTO,
+ PICNUM_AUTO,
+ TBLNUM_AUTO,
+ EQUNUM_AUTO
+};
+
+/**
+ * @short Input current index of page,comment,table and picture.
+ */
+struct AutoNum: public HBox
+{
+ unsigned short type;
+ unsigned short number;
+ hchar dummy;
+
+ AutoNum();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/**
+ * @short Input new number as current index of page,comment,table and picture.
+ */
+struct NewNum: public HBox
+{
+ unsigned short type;
+ unsigned short number;
+ hchar dummy;
+
+ NewNum();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// page number(20)
+/**
+ * @short Input page index in footer or header
+ */
+struct ShowPageNum: public HBox
+{
+/**
+ * Location of page number to be inserted.
+ */
+ unsigned short where;
+ unsigned int m_nPageNumber;
+/**
+ * Shape of page number to be inserted.
+ */
+ unsigned short shape;
+ hchar dummy;
+
+ ShowPageNum();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/* Start odd side (21) */
+/**
+ * Controls the display of page number, header, footer and border.
+ */
+struct PageNumCtrl: public HBox
+{
+/**
+ * object type
+ */
+ unsigned short kind;
+/**
+ * control command.
+ */
+ unsigned short what;
+ hchar dummy;
+
+ PageNumCtrl();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// mail merge(22)
+/**
+ * Generates the mailing list automatically using address book and mail body format.
+ * @short Generates mailing list
+ */
+struct MailMerge: public HBox
+{
+ unsigned char field_name[20] = {};
+ hchar dummy;
+
+ MailMerge();
+
+ virtual bool Read(HWPFile &hwpf) override;
+ static hchar_string GetString();
+};
+
+// char composition(23)
+/**
+ * The compose struct displays characters at position. The maximum character count for composition is three.
+ * @short Composition several characters
+ */
+struct Compose: public HBox
+{
+ hchar compose[3];
+ hchar dummy;
+
+ Compose();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// hyphen(24)
+/**
+ * @short Hyphen
+ */
+struct Hyphen: public HBox
+{
+/**
+ * Width of hyphen
+ */
+ hchar width;
+ hchar dummy;
+
+ Hyphen();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// toc mark(25)
+/**
+ * The TocMark class is for making the content of a table.
+ * When you set TocMark on current position, hwp makes it as toc automatically.
+ * @short Table of contents
+ */
+struct TocMark: public HBox
+{
+ hchar kind;
+ hchar dummy;
+
+ TocMark();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// index mark(26)
+/**
+ * IndexMark marks the table of search.
+ * If you set IndexMark at current position, hwp make it as search index.
+ * @short Table of search
+ */
+struct IndexMark: public HBox
+{
+ hchar keyword1[60] = {};
+ hchar keyword2[60] = {};
+ unsigned short pgno;
+ hchar dummy;
+
+ IndexMark();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+// outline(28)
+#define MAX_OUTLINE_LEVEL 7
+
+enum
+{
+ OLSTY_USER = 0,
+ OLSTY_NUMS1 = 1,
+ OLSTY_NUMS2 = 2,
+ OLSTY_NUMSIG1 = 3,
+ OLSTY_NUMSIG2 = 4,
+ OLSTY_NUMSIG3 = 5,
+ OLSTY_BULUSER = 128,
+ OLSTY_BULLET1 = 129,
+ OLSTY_BULLET2 = 130,
+ OLSTY_BULLET3 = 131,
+ OLSTY_BULLET4 = 132,
+ OLSTY_BULLET5 = 133
+};
+
+// value is in style->userchar[level];
+enum
+{
+ UDO_NUM,
+ UDO_UROM,
+ UDO_LROM,
+ UDO_UENG,
+ UDO_LENG,
+ UDO_SYLL,
+ UDO_JAMO,
+ UDO_HANJA,
+ UDO_SP_CNUM,
+ UDO_SP_CLENG,
+ UDO_SP_CSYLL,
+ UDO_SP_CJAMO,
+ N_UDO
+};
+/**
+ * Number and format of title.
+ * @short Number and format of title
+ */
+class Outline: public HBox
+{
+ public:
+/**
+ * kind of numbering format
+ */
+ unsigned short kind;
+ unsigned char shape;
+/**
+ * level of number, Ex) The level of 1.3.2.4 is four
+ */
+ unsigned char level;
+/**
+ * value of level
+ */
+ unsigned short number[MAX_OUTLINE_LEVEL];
+/**
+ * shape of level
+ */
+ hchar user_shape[MAX_OUTLINE_LEVEL];
+/**
+ * decoration character for the level type
+ */
+ hchar deco[MAX_OUTLINE_LEVEL][2]; /* Prefix/postfix for Customize */
+ hchar dummy;
+
+ Outline();
+
+ virtual bool Read(HWPFile &hwpf) override;
+ OUString GetUnicode() const;
+};
+
+/* Bundle of spaces (30) */
+/**
+ * The Special space to be treated non-space when a string is
+ * cut at the end of line
+ * @short Special space
+ */
+struct KeepSpace: public HBox
+{
+ hchar dummy;
+
+ KeepSpace();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+
+/* Fixed-width spaces (31) */
+/**
+ * @short Space with always same width not relation with fonts.
+ */
+struct FixedSpace: public HBox
+{
+ hchar dummy;
+
+ FixedSpace();
+
+ virtual bool Read(HWPFile &hwpf) override;
+};
+#endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx
new file mode 100644
index 000000000..cc9d051ca
--- /dev/null
+++ b/hwpfilter/source/hcode.cxx
@@ -0,0 +1,1416 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/**
+ * Rule :
+ * Hangule johap code => unicode
+ * Hanja johap code => ks code => unicode
+ * Special johap code => ks code => unicode
+ */
+
+#include <sal/config.h>
+
+#include "precompile.h"
+#include <comphelper/base64.hxx>
+#include <comphelper/sequence.hxx>
+#include <basegfx/numeric/ftools.hxx>
+#include <o3tl/safeint.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <sal/types.h>
+#include <sal/macros.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <cmath>
+#include "hcode.h"
+#include "ksc5601.h"
+
+static hchar jaso2ks(hchar hh);
+
+// ccvHH2ASC code convert HWP20 to ASC(KSSM)
+
+#define HCA_KSS 0x3400
+#define HCA_TG 0x37C0
+#define noneks 0xA1A1
+
+#define UNI_HANGUL_FIRST 0xac00
+
+#define NUM_JOONGSEONG 21
+#define NUM_JONGSEONG 28
+
+/**
+ * kssm code table matching with ks index
+ */
+const hchar ksTbl[2350] =
+{
+ 0x8861, 0x8862, 0x8865, 0x8868, 0x8869, 0x886A, 0x886B, 0x8871,
+ 0x8873, 0x8874, 0x8875, 0x8876, 0x8877, 0x8878, 0x8879, 0x887B,
+ 0x887C, 0x887D, 0x8881, 0x8882, 0x8885, 0x8889, 0x8891, 0x8893,
+ 0x8895, 0x8896, 0x8897, 0x88A1, 0x88A2, 0x88A5, 0x88A9, 0x88B5,
+ 0x88B7, 0x88C1, 0x88C5, 0x88C9, 0x88E1, 0x88E2, 0x88E5, 0x88E8,
+ 0x88E9, 0x88EB, 0x88F1, 0x88F3, 0x88F5, 0x88F6, 0x88F7, 0x88F8,
+ 0x88FB, 0x88FC, 0x88FD, 0x8941, 0x8945, 0x8949, 0x8951, 0x8953,
+ 0x8955, 0x8956, 0x8957, 0x8961, 0x8962, 0x8963, 0x8965, 0x8968,
+ 0x8969, 0x8971, 0x8973, 0x8975, 0x8976, 0x8977, 0x897B, 0x8981,
+ 0x8985, 0x8989, 0x8993, 0x8995, 0x89A1, 0x89A2, 0x89A5, 0x89A8,
+ 0x89A9, 0x89AB, 0x89AD, 0x89B0, 0x89B1, 0x89B3, 0x89B5, 0x89B7,
+ 0x89B8, 0x89C1, 0x89C2, 0x89C5, 0x89C9, 0x89CB, 0x89D1, 0x89D3,
+ 0x89D5, 0x89D7, 0x89E1, 0x89E5, 0x89E9, 0x89F3, 0x89F6, 0x89F7,
+ 0x8A41, 0x8A42, 0x8A45, 0x8A49, 0x8A51, 0x8A53, 0x8A55, 0x8A57,
+ 0x8A61, 0x8A65, 0x8A69, 0x8A73, 0x8A75, 0x8A81, 0x8A82, 0x8A85,
+ 0x8A88, 0x8A89, 0x8A8A, 0x8A8B, 0x8A90, 0x8A91, 0x8A93, 0x8A95,
+ 0x8A97, 0x8A98, 0x8AA1, 0x8AA2, 0x8AA5, 0x8AA9, 0x8AB6, 0x8AB7,
+ 0x8AC1, 0x8AD5, 0x8AE1, 0x8AE2, 0x8AE5, 0x8AE9, 0x8AF1, 0x8AF3,
+ 0x8AF5, 0x8B41, 0x8B45, 0x8B49, 0x8B61, 0x8B62, 0x8B65, 0x8B68,
+ 0x8B69, 0x8B6A, 0x8B71, 0x8B73, 0x8B75, 0x8B77, 0x8B81, 0x8BA1,
+ 0x8BA2, 0x8BA5, 0x8BA8, 0x8BA9, 0x8BAB, 0x8BB1, 0x8BB3, 0x8BB5,
+ 0x8BB7, 0x8BB8, 0x8BBC, 0x8C61, 0x8C62, 0x8C63, 0x8C65, 0x8C69,
+ 0x8C6B, 0x8C71, 0x8C73, 0x8C75, 0x8C76, 0x8C77, 0x8C7B, 0x8C81,
+ 0x8C82, 0x8C85, 0x8C89, 0x8C91, 0x8C93, 0x8C95, 0x8C96, 0x8C97,
+ 0x8CA1, 0x8CA2, 0x8CA9, 0x8CE1, 0x8CE2, 0x8CE3, 0x8CE5, 0x8CE9,
+ 0x8CF1, 0x8CF3, 0x8CF5, 0x8CF6, 0x8CF7, 0x8D41, 0x8D42, 0x8D45,
+ 0x8D51, 0x8D55, 0x8D57, 0x8D61, 0x8D65, 0x8D69, 0x8D75, 0x8D76,
+ 0x8D7B, 0x8D81, 0x8DA1, 0x8DA2, 0x8DA5, 0x8DA7, 0x8DA9, 0x8DB1,
+ 0x8DB3, 0x8DB5, 0x8DB7, 0x8DB8, 0x8DB9, 0x8DC1, 0x8DC2, 0x8DC9,
+ 0x8DD6, 0x8DD7, 0x8DE1, 0x8DE2, 0x8DF7, 0x8E41, 0x8E45, 0x8E49,
+ 0x8E51, 0x8E53, 0x8E57, 0x8E61, 0x8E81, 0x8E82, 0x8E85, 0x8E89,
+ 0x8E90, 0x8E91, 0x8E93, 0x8E95, 0x8E97, 0x8E98, 0x8EA1, 0x8EA9,
+ 0x8EB6, 0x8EB7, 0x8EC1, 0x8EC2, 0x8EC5, 0x8EC9, 0x8ED1, 0x8ED3,
+ 0x8ED6, 0x8EE1, 0x8EE5, 0x8EE9, 0x8EF1, 0x8EF3, 0x8F41, 0x8F61,
+ 0x8F62, 0x8F65, 0x8F67, 0x8F69, 0x8F6B, 0x8F70, 0x8F71, 0x8F73,
+ 0x8F75, 0x8F77, 0x8F7B, 0x8FA1, 0x8FA2, 0x8FA5, 0x8FA9, 0x8FB1,
+ 0x8FB3, 0x8FB5, 0x8FB7, 0x9061, 0x9062, 0x9063, 0x9065, 0x9068,
+ 0x9069, 0x906A, 0x906B, 0x9071, 0x9073, 0x9075, 0x9076, 0x9077,
+ 0x9078, 0x9079, 0x907B, 0x907D, 0x9081, 0x9082, 0x9085, 0x9089,
+ 0x9091, 0x9093, 0x9095, 0x9096, 0x9097, 0x90A1, 0x90A2, 0x90A5,
+ 0x90A9, 0x90B1, 0x90B7, 0x90E1, 0x90E2, 0x90E4, 0x90E5, 0x90E9,
+ 0x90EB, 0x90EC, 0x90F1, 0x90F3, 0x90F5, 0x90F6, 0x90F7, 0x90FD,
+ 0x9141, 0x9142, 0x9145, 0x9149, 0x9151, 0x9153, 0x9155, 0x9156,
+ 0x9157, 0x9161, 0x9162, 0x9165, 0x9169, 0x9171, 0x9173, 0x9176,
+ 0x9177, 0x917A, 0x9181, 0x9185, 0x91A1, 0x91A2, 0x91A5, 0x91A9,
+ 0x91AB, 0x91B1, 0x91B3, 0x91B5, 0x91B7, 0x91BC, 0x91BD, 0x91C1,
+ 0x91C5, 0x91C9, 0x91D6, 0x9241, 0x9245, 0x9249, 0x9251, 0x9253,
+ 0x9255, 0x9261, 0x9262, 0x9265, 0x9269, 0x9273, 0x9275, 0x9277,
+ 0x9281, 0x9282, 0x9285, 0x9288, 0x9289, 0x9291, 0x9293, 0x9295,
+ 0x9297, 0x92A1, 0x92B6, 0x92C1, 0x92E1, 0x92E5, 0x92E9, 0x92F1,
+ 0x92F3, 0x9341, 0x9342, 0x9349, 0x9351, 0x9353, 0x9357, 0x9361,
+ 0x9362, 0x9365, 0x9369, 0x936A, 0x936B, 0x9371, 0x9373, 0x9375,
+ 0x9377, 0x9378, 0x937C, 0x9381, 0x9385, 0x9389, 0x93A1, 0x93A2,
+ 0x93A5, 0x93A9, 0x93AF, 0x93B1, 0x93B3, 0x93B5, 0x93B7, 0x93BC,
+ 0x9461, 0x9462, 0x9463, 0x9465, 0x9468, 0x9469, 0x946A, 0x946B,
+ 0x946C, 0x9470, 0x9471, 0x9473, 0x9475, 0x9476, 0x9477, 0x9478,
+ 0x9479, 0x947D, 0x9481, 0x9482, 0x9485, 0x9489, 0x9491, 0x9493,
+ 0x9495, 0x9496, 0x9497, 0x94A1, 0x94E1, 0x94E2, 0x94E3, 0x94E5,
+ 0x94E8, 0x94E9, 0x94EB, 0x94EC, 0x94F1, 0x94F3, 0x94F5, 0x94F7,
+ 0x94F9, 0x94FC, 0x9541, 0x9542, 0x9545, 0x9549, 0x9551, 0x9553,
+ 0x9555, 0x9556, 0x9557, 0x9561, 0x9565, 0x9569, 0x9576, 0x9577,
+ 0x9581, 0x9585, 0x95A1, 0x95A2, 0x95A5, 0x95A8, 0x95A9, 0x95AB,
+ 0x95AD, 0x95B1, 0x95B3, 0x95B5, 0x95B7, 0x95B9, 0x95BB, 0x95C1,
+ 0x95C5, 0x95C9, 0x95E1, 0x95F6, 0x9641, 0x9645, 0x9649, 0x9651,
+ 0x9653, 0x9655, 0x9661, 0x9681, 0x9682, 0x9685, 0x9689, 0x9691,
+ 0x9693, 0x9695, 0x9697, 0x96A1, 0x96B6, 0x96C1, 0x96D7, 0x96E1,
+ 0x96E5, 0x96E9, 0x96F3, 0x96F5, 0x96F7, 0x9741, 0x9745, 0x9749,
+ 0x9751, 0x9757, 0x9761, 0x9762, 0x9765, 0x9768, 0x9769, 0x976B,
+ 0x9771, 0x9773, 0x9775, 0x9777, 0x9781, 0x97A1, 0x97A2, 0x97A5,
+ 0x97A8, 0x97A9, 0x97B1, 0x97B3, 0x97B5, 0x97B6, 0x97B7, 0x97B8,
+ 0x9861, 0x9862, 0x9865, 0x9869, 0x9871, 0x9873, 0x9875, 0x9876,
+ 0x9877, 0x987D, 0x9881, 0x9882, 0x9885, 0x9889, 0x9891, 0x9893,
+ 0x9895, 0x9896, 0x9897, 0x98E1, 0x98E2, 0x98E5, 0x98E9, 0x98EB,
+ 0x98EC, 0x98F1, 0x98F3, 0x98F5, 0x98F6, 0x98F7, 0x98FD, 0x9941,
+ 0x9942, 0x9945, 0x9949, 0x9951, 0x9953, 0x9955, 0x9956, 0x9957,
+ 0x9961, 0x9976, 0x99A1, 0x99A2, 0x99A5, 0x99A9, 0x99B7, 0x99C1,
+ 0x99C9, 0x99E1, 0x9A41, 0x9A45, 0x9A81, 0x9A82, 0x9A85, 0x9A89,
+ 0x9A90, 0x9A91, 0x9A97, 0x9AC1, 0x9AE1, 0x9AE5, 0x9AE9, 0x9AF1,
+ 0x9AF3, 0x9AF7, 0x9B61, 0x9B62, 0x9B65, 0x9B68, 0x9B69, 0x9B71,
+ 0x9B73, 0x9B75, 0x9B81, 0x9B85, 0x9B89, 0x9B91, 0x9B93, 0x9BA1,
+ 0x9BA5, 0x9BA9, 0x9BB1, 0x9BB3, 0x9BB5, 0x9BB7, 0x9C61, 0x9C62,
+ 0x9C65, 0x9C69, 0x9C71, 0x9C73, 0x9C75, 0x9C76, 0x9C77, 0x9C78,
+ 0x9C7C, 0x9C7D, 0x9C81, 0x9C82, 0x9C85, 0x9C89, 0x9C91, 0x9C93,
+ 0x9C95, 0x9C96, 0x9C97, 0x9CA1, 0x9CA2, 0x9CA5, 0x9CB5, 0x9CB7,
+ 0x9CE1, 0x9CE2, 0x9CE5, 0x9CE9, 0x9CF1, 0x9CF3, 0x9CF5, 0x9CF6,
+ 0x9CF7, 0x9CFD, 0x9D41, 0x9D42, 0x9D45, 0x9D49, 0x9D51, 0x9D53,
+ 0x9D55, 0x9D57, 0x9D61, 0x9D62, 0x9D65, 0x9D69, 0x9D71, 0x9D73,
+ 0x9D75, 0x9D76, 0x9D77, 0x9D81, 0x9D85, 0x9D93, 0x9D95, 0x9DA1,
+ 0x9DA2, 0x9DA5, 0x9DA9, 0x9DB1, 0x9DB3, 0x9DB5, 0x9DB7, 0x9DC1,
+ 0x9DC5, 0x9DD7, 0x9DF6, 0x9E41, 0x9E45, 0x9E49, 0x9E51, 0x9E53,
+ 0x9E55, 0x9E57, 0x9E61, 0x9E65, 0x9E69, 0x9E73, 0x9E75, 0x9E77,
+ 0x9E81, 0x9E82, 0x9E85, 0x9E89, 0x9E91, 0x9E93, 0x9E95, 0x9E97,
+ 0x9EA1, 0x9EB6, 0x9EC1, 0x9EE1, 0x9EE2, 0x9EE5, 0x9EE9, 0x9EF1,
+ 0x9EF5, 0x9EF7, 0x9F41, 0x9F42, 0x9F45, 0x9F49, 0x9F51, 0x9F53,
+ 0x9F55, 0x9F57, 0x9F61, 0x9F62, 0x9F65, 0x9F69, 0x9F71, 0x9F73,
+ 0x9F75, 0x9F77, 0x9F78, 0x9F7B, 0x9F7C, 0x9FA1, 0x9FA2, 0x9FA5,
+ 0x9FA9, 0x9FB1, 0x9FB3, 0x9FB5, 0x9FB7, 0xA061, 0xA062, 0xA065,
+ 0xA067, 0xA068, 0xA069, 0xA06A, 0xA06B, 0xA071, 0xA073, 0xA075,
+ 0xA077, 0xA078, 0xA07B, 0xA07D, 0xA081, 0xA082, 0xA085, 0xA089,
+ 0xA091, 0xA093, 0xA095, 0xA096, 0xA097, 0xA098, 0xA0A1, 0xA0A2,
+ 0xA0A9, 0xA0B7, 0xA0E1, 0xA0E2, 0xA0E5, 0xA0E9, 0xA0EB, 0xA0F1,
+ 0xA0F3, 0xA0F5, 0xA0F7, 0xA0F8, 0xA0FD, 0xA141, 0xA142, 0xA145,
+ 0xA149, 0xA151, 0xA153, 0xA155, 0xA156, 0xA157, 0xA161, 0xA162,
+ 0xA165, 0xA169, 0xA175, 0xA176, 0xA177, 0xA179, 0xA181, 0xA1A1,
+ 0xA1A2, 0xA1A4, 0xA1A5, 0xA1A9, 0xA1AB, 0xA1B1, 0xA1B3, 0xA1B5,
+ 0xA1B7, 0xA1C1, 0xA1C5, 0xA1D6, 0xA1D7, 0xA241, 0xA245, 0xA249,
+ 0xA253, 0xA255, 0xA257, 0xA261, 0xA265, 0xA269, 0xA273, 0xA275,
+ 0xA281, 0xA282, 0xA283, 0xA285, 0xA288, 0xA289, 0xA28A, 0xA28B,
+ 0xA291, 0xA293, 0xA295, 0xA297, 0xA29B, 0xA29D, 0xA2A1, 0xA2A5,
+ 0xA2A9, 0xA2B3, 0xA2B5, 0xA2C1, 0xA2E1, 0xA2E5, 0xA2E9, 0xA341,
+ 0xA345, 0xA349, 0xA351, 0xA355, 0xA361, 0xA365, 0xA369, 0xA371,
+ 0xA375, 0xA3A1, 0xA3A2, 0xA3A5, 0xA3A8, 0xA3A9, 0xA3AB, 0xA3B1,
+ 0xA3B3, 0xA3B5, 0xA3B6, 0xA3B7, 0xA3B9, 0xA3BB, 0xA461, 0xA462,
+ 0xA463, 0xA464, 0xA465, 0xA468, 0xA469, 0xA46A, 0xA46B, 0xA46C,
+ 0xA471, 0xA473, 0xA475, 0xA477, 0xA47B, 0xA481, 0xA482, 0xA485,
+ 0xA489, 0xA491, 0xA493, 0xA495, 0xA496, 0xA497, 0xA49B, 0xA4A1,
+ 0xA4A2, 0xA4A5, 0xA4B3, 0xA4E1, 0xA4E2, 0xA4E5, 0xA4E8, 0xA4E9,
+ 0xA4EB, 0xA4F1, 0xA4F3, 0xA4F5, 0xA4F7, 0xA4F8, 0xA541, 0xA542,
+ 0xA545, 0xA548, 0xA549, 0xA551, 0xA553, 0xA555, 0xA556, 0xA557,
+ 0xA561, 0xA562, 0xA565, 0xA569, 0xA573, 0xA575, 0xA576, 0xA577,
+ 0xA57B, 0xA581, 0xA585, 0xA5A1, 0xA5A2, 0xA5A3, 0xA5A5, 0xA5A9,
+ 0xA5B1, 0xA5B3, 0xA5B5, 0xA5B7, 0xA5C1, 0xA5C5, 0xA5D6, 0xA5E1,
+ 0xA5F6, 0xA641, 0xA642, 0xA645, 0xA649, 0xA651, 0xA653, 0xA661,
+ 0xA665, 0xA681, 0xA682, 0xA685, 0xA688, 0xA689, 0xA68A, 0xA68B,
+ 0xA691, 0xA693, 0xA695, 0xA697, 0xA69B, 0xA69C, 0xA6A1, 0xA6A9,
+ 0xA6B6, 0xA6C1, 0xA6E1, 0xA6E2, 0xA6E5, 0xA6E9, 0xA6F7, 0xA741,
+ 0xA745, 0xA749, 0xA751, 0xA755, 0xA757, 0xA761, 0xA762, 0xA765,
+ 0xA769, 0xA771, 0xA773, 0xA775, 0xA7A1, 0xA7A2, 0xA7A5, 0xA7A9,
+ 0xA7AB, 0xA7B1, 0xA7B3, 0xA7B5, 0xA7B7, 0xA7B8, 0xA7B9, 0xA861,
+ 0xA862, 0xA865, 0xA869, 0xA86B, 0xA871, 0xA873, 0xA875, 0xA876,
+ 0xA877, 0xA87D, 0xA881, 0xA882, 0xA885, 0xA889, 0xA891, 0xA893,
+ 0xA895, 0xA896, 0xA897, 0xA8A1, 0xA8A2, 0xA8B1, 0xA8E1, 0xA8E2,
+ 0xA8E5, 0xA8E8, 0xA8E9, 0xA8F1, 0xA8F5, 0xA8F6, 0xA8F7, 0xA941,
+ 0xA957, 0xA961, 0xA962, 0xA971, 0xA973, 0xA975, 0xA976, 0xA977,
+ 0xA9A1, 0xA9A2, 0xA9A5, 0xA9A9, 0xA9B1, 0xA9B3, 0xA9B7, 0xAA41,
+ 0xAA61, 0xAA77, 0xAA81, 0xAA82, 0xAA85, 0xAA89, 0xAA91, 0xAA95,
+ 0xAA97, 0xAB41, 0xAB57, 0xAB61, 0xAB65, 0xAB69, 0xAB71, 0xAB73,
+ 0xABA1, 0xABA2, 0xABA5, 0xABA9, 0xABB1, 0xABB3, 0xABB5, 0xABB7,
+ 0xAC61, 0xAC62, 0xAC64, 0xAC65, 0xAC68, 0xAC69, 0xAC6A, 0xAC6B,
+ 0xAC71, 0xAC73, 0xAC75, 0xAC76, 0xAC77, 0xAC7B, 0xAC81, 0xAC82,
+ 0xAC85, 0xAC89, 0xAC91, 0xAC93, 0xAC95, 0xAC96, 0xAC97, 0xACA1,
+ 0xACA2, 0xACA5, 0xACA9, 0xACB1, 0xACB3, 0xACB5, 0xACB7, 0xACC1,
+ 0xACC5, 0xACC9, 0xACD1, 0xACD7, 0xACE1, 0xACE2, 0xACE3, 0xACE4,
+ 0xACE5, 0xACE8, 0xACE9, 0xACEB, 0xACEC, 0xACF1, 0xACF3, 0xACF5,
+ 0xACF6, 0xACF7, 0xACFC, 0xAD41, 0xAD42, 0xAD45, 0xAD49, 0xAD51,
+ 0xAD53, 0xAD55, 0xAD56, 0xAD57, 0xAD61, 0xAD62, 0xAD65, 0xAD69,
+ 0xAD71, 0xAD73, 0xAD75, 0xAD76, 0xAD77, 0xAD81, 0xAD85, 0xAD89,
+ 0xAD97, 0xADA1, 0xADA2, 0xADA3, 0xADA5, 0xADA9, 0xADAB, 0xADB1,
+ 0xADB3, 0xADB5, 0xADB7, 0xADBB, 0xADC1, 0xADC2, 0xADC5, 0xADC9,
+ 0xADD7, 0xADE1, 0xADE5, 0xADE9, 0xADF1, 0xADF5, 0xADF6, 0xAE41,
+ 0xAE45, 0xAE49, 0xAE51, 0xAE53, 0xAE55, 0xAE61, 0xAE62, 0xAE65,
+ 0xAE69, 0xAE71, 0xAE73, 0xAE75, 0xAE77, 0xAE81, 0xAE82, 0xAE85,
+ 0xAE88, 0xAE89, 0xAE91, 0xAE93, 0xAE95, 0xAE97, 0xAE99, 0xAE9B,
+ 0xAE9C, 0xAEA1, 0xAEB6, 0xAEC1, 0xAEC2, 0xAEC5, 0xAEC9, 0xAED1,
+ 0xAED7, 0xAEE1, 0xAEE2, 0xAEE5, 0xAEE9, 0xAEF1, 0xAEF3, 0xAEF5,
+ 0xAEF7, 0xAF41, 0xAF42, 0xAF49, 0xAF51, 0xAF55, 0xAF57, 0xAF61,
+ 0xAF62, 0xAF65, 0xAF69, 0xAF6A, 0xAF71, 0xAF73, 0xAF75, 0xAF77,
+ 0xAFA1, 0xAFA2, 0xAFA5, 0xAFA8, 0xAFA9, 0xAFB0, 0xAFB1, 0xAFB3,
+ 0xAFB5, 0xAFB7, 0xAFBC, 0xB061, 0xB062, 0xB064, 0xB065, 0xB069,
+ 0xB071, 0xB073, 0xB076, 0xB077, 0xB07D, 0xB081, 0xB082, 0xB085,
+ 0xB089, 0xB091, 0xB093, 0xB096, 0xB097, 0xB0B7, 0xB0E1, 0xB0E2,
+ 0xB0E5, 0xB0E9, 0xB0EB, 0xB0F1, 0xB0F3, 0xB0F6, 0xB0F7, 0xB141,
+ 0xB145, 0xB149, 0xB185, 0xB1A1, 0xB1A2, 0xB1A5, 0xB1A8, 0xB1A9,
+ 0xB1AB, 0xB1B1, 0xB1B3, 0xB1B7, 0xB1C1, 0xB1C2, 0xB1C5, 0xB1D6,
+ 0xB1E1, 0xB1F6, 0xB241, 0xB245, 0xB249, 0xB251, 0xB253, 0xB261,
+ 0xB281, 0xB282, 0xB285, 0xB289, 0xB291, 0xB293, 0xB297, 0xB2A1,
+ 0xB2B6, 0xB2C1, 0xB2E1, 0xB2E5, 0xB357, 0xB361, 0xB362, 0xB365,
+ 0xB369, 0xB36B, 0xB370, 0xB371, 0xB373, 0xB381, 0xB385, 0xB389,
+ 0xB391, 0xB3A1, 0xB3A2, 0xB3A5, 0xB3A9, 0xB3B1, 0xB3B3, 0xB3B5,
+ 0xB3B7, 0xB461, 0xB462, 0xB465, 0xB466, 0xB467, 0xB469, 0xB46A,
+ 0xB46B, 0xB470, 0xB471, 0xB473, 0xB475, 0xB476, 0xB477, 0xB47B,
+ 0xB47C, 0xB481, 0xB482, 0xB485, 0xB489, 0xB491, 0xB493, 0xB495,
+ 0xB496, 0xB497, 0xB4A1, 0xB4A2, 0xB4A5, 0xB4A9, 0xB4AC, 0xB4B1,
+ 0xB4B3, 0xB4B5, 0xB4B7, 0xB4BB, 0xB4BD, 0xB4C1, 0xB4C5, 0xB4C9,
+ 0xB4D3, 0xB4E1, 0xB4E2, 0xB4E5, 0xB4E6, 0xB4E8, 0xB4E9, 0xB4EA,
+ 0xB4EB, 0xB4F1, 0xB4F3, 0xB4F4, 0xB4F5, 0xB4F6, 0xB4F7, 0xB4F8,
+ 0xB4FA, 0xB4FC, 0xB541, 0xB542, 0xB545, 0xB549, 0xB551, 0xB553,
+ 0xB555, 0xB557, 0xB561, 0xB562, 0xB563, 0xB565, 0xB569, 0xB56B,
+ 0xB56C, 0xB571, 0xB573, 0xB574, 0xB575, 0xB576, 0xB577, 0xB57B,
+ 0xB57C, 0xB57D, 0xB581, 0xB585, 0xB589, 0xB591, 0xB593, 0xB595,
+ 0xB596, 0xB5A1, 0xB5A2, 0xB5A5, 0xB5A9, 0xB5AA, 0xB5AB, 0xB5AD,
+ 0xB5B0, 0xB5B1, 0xB5B3, 0xB5B5, 0xB5B7, 0xB5B9, 0xB5C1, 0xB5C2,
+ 0xB5C5, 0xB5C9, 0xB5D1, 0xB5D3, 0xB5D5, 0xB5D6, 0xB5D7, 0xB5E1,
+ 0xB5E2, 0xB5E5, 0xB5F1, 0xB5F5, 0xB5F7, 0xB641, 0xB642, 0xB645,
+ 0xB649, 0xB651, 0xB653, 0xB655, 0xB657, 0xB661, 0xB662, 0xB665,
+ 0xB669, 0xB671, 0xB673, 0xB675, 0xB677, 0xB681, 0xB682, 0xB685,
+ 0xB689, 0xB68A, 0xB68B, 0xB691, 0xB693, 0xB695, 0xB697, 0xB6A1,
+ 0xB6A2, 0xB6A5, 0xB6A9, 0xB6B1, 0xB6B3, 0xB6B6, 0xB6B7, 0xB6C1,
+ 0xB6C2, 0xB6C5, 0xB6C9, 0xB6D1, 0xB6D3, 0xB6D7, 0xB6E1, 0xB6E2,
+ 0xB6E5, 0xB6E9, 0xB6F1, 0xB6F3, 0xB6F5, 0xB6F7, 0xB741, 0xB742,
+ 0xB745, 0xB749, 0xB751, 0xB753, 0xB755, 0xB757, 0xB759, 0xB761,
+ 0xB762, 0xB765, 0xB769, 0xB76F, 0xB771, 0xB773, 0xB775, 0xB777,
+ 0xB778, 0xB779, 0xB77A, 0xB77B, 0xB77C, 0xB77D, 0xB781, 0xB785,
+ 0xB789, 0xB791, 0xB795, 0xB7A1, 0xB7A2, 0xB7A5, 0xB7A9, 0xB7AA,
+ 0xB7AB, 0xB7B0, 0xB7B1, 0xB7B3, 0xB7B5, 0xB7B6, 0xB7B7, 0xB7B8,
+ 0xB7BC, 0xB861, 0xB862, 0xB865, 0xB867, 0xB868, 0xB869, 0xB86B,
+ 0xB871, 0xB873, 0xB875, 0xB876, 0xB877, 0xB878, 0xB881, 0xB882,
+ 0xB885, 0xB889, 0xB891, 0xB893, 0xB895, 0xB896, 0xB897, 0xB8A1,
+ 0xB8A2, 0xB8A5, 0xB8A7, 0xB8A9, 0xB8B1, 0xB8B7, 0xB8C1, 0xB8C5,
+ 0xB8C9, 0xB8E1, 0xB8E2, 0xB8E5, 0xB8E9, 0xB8EB, 0xB8F1, 0xB8F3,
+ 0xB8F5, 0xB8F7, 0xB8F8, 0xB941, 0xB942, 0xB945, 0xB949, 0xB951,
+ 0xB953, 0xB955, 0xB957, 0xB961, 0xB965, 0xB969, 0xB971, 0xB973,
+ 0xB976, 0xB977, 0xB981, 0xB9A1, 0xB9A2, 0xB9A5, 0xB9A9, 0xB9AB,
+ 0xB9B1, 0xB9B3, 0xB9B5, 0xB9B7, 0xB9B8, 0xB9B9, 0xB9BD, 0xB9C1,
+ 0xB9C2, 0xB9C9, 0xB9D3, 0xB9D5, 0xB9D7, 0xB9E1, 0xB9F6, 0xB9F7,
+ 0xBA41, 0xBA45, 0xBA49, 0xBA51, 0xBA53, 0xBA55, 0xBA57, 0xBA61,
+ 0xBA62, 0xBA65, 0xBA77, 0xBA81, 0xBA82, 0xBA85, 0xBA89, 0xBA8A,
+ 0xBA8B, 0xBA91, 0xBA93, 0xBA95, 0xBA97, 0xBAA1, 0xBAB6, 0xBAC1,
+ 0xBAE1, 0xBAE2, 0xBAE5, 0xBAE9, 0xBAF1, 0xBAF3, 0xBAF5, 0xBB41,
+ 0xBB45, 0xBB49, 0xBB51, 0xBB61, 0xBB62, 0xBB65, 0xBB69, 0xBB71,
+ 0xBB73, 0xBB75, 0xBB77, 0xBBA1, 0xBBA2, 0xBBA5, 0xBBA8, 0xBBA9,
+ 0xBBAB, 0xBBB1, 0xBBB3, 0xBBB5, 0xBBB7, 0xBBB8, 0xBBBB, 0xBBBC,
+ 0xBC61, 0xBC62, 0xBC65, 0xBC67, 0xBC69, 0xBC6C, 0xBC71, 0xBC73,
+ 0xBC75, 0xBC76, 0xBC77, 0xBC81, 0xBC82, 0xBC85, 0xBC89, 0xBC91,
+ 0xBC93, 0xBC95, 0xBC96, 0xBC97, 0xBCA1, 0xBCA5, 0xBCB7, 0xBCE1,
+ 0xBCE2, 0xBCE5, 0xBCE9, 0xBCF1, 0xBCF3, 0xBCF5, 0xBCF6, 0xBCF7,
+ 0xBD41, 0xBD57, 0xBD61, 0xBD76, 0xBDA1, 0xBDA2, 0xBDA5, 0xBDA9,
+ 0xBDB1, 0xBDB3, 0xBDB5, 0xBDB7, 0xBDB9, 0xBDC1, 0xBDC2, 0xBDC9,
+ 0xBDD6, 0xBDE1, 0xBDF6, 0xBE41, 0xBE45, 0xBE49, 0xBE51, 0xBE53,
+ 0xBE77, 0xBE81, 0xBE82, 0xBE85, 0xBE89, 0xBE91, 0xBE93, 0xBE97,
+ 0xBEA1, 0xBEB6, 0xBEB7, 0xBEE1, 0xBF41, 0xBF61, 0xBF71, 0xBF75,
+ 0xBF77, 0xBFA1, 0xBFA2, 0xBFA5, 0xBFA9, 0xBFB1, 0xBFB3, 0xBFB7,
+ 0xBFB8, 0xBFBD, 0xC061, 0xC062, 0xC065, 0xC067, 0xC069, 0xC071,
+ 0xC073, 0xC075, 0xC076, 0xC077, 0xC078, 0xC081, 0xC082, 0xC085,
+ 0xC089, 0xC091, 0xC093, 0xC095, 0xC096, 0xC097, 0xC0A1, 0xC0A5,
+ 0xC0A7, 0xC0A9, 0xC0B1, 0xC0B7, 0xC0E1, 0xC0E2, 0xC0E5, 0xC0E9,
+ 0xC0F1, 0xC0F3, 0xC0F5, 0xC0F6, 0xC0F7, 0xC141, 0xC142, 0xC145,
+ 0xC149, 0xC151, 0xC153, 0xC155, 0xC157, 0xC161, 0xC165, 0xC176,
+ 0xC181, 0xC185, 0xC197, 0xC1A1, 0xC1A2, 0xC1A5, 0xC1A9, 0xC1B1,
+ 0xC1B3, 0xC1B5, 0xC1B7, 0xC1C1, 0xC1C5, 0xC1C9, 0xC1D7, 0xC241,
+ 0xC245, 0xC249, 0xC251, 0xC253, 0xC255, 0xC257, 0xC261, 0xC271,
+ 0xC281, 0xC282, 0xC285, 0xC289, 0xC291, 0xC293, 0xC295, 0xC297,
+ 0xC2A1, 0xC2B6, 0xC2C1, 0xC2C5, 0xC2E1, 0xC2E5, 0xC2E9, 0xC2F1,
+ 0xC2F3, 0xC2F5, 0xC2F7, 0xC341, 0xC345, 0xC349, 0xC351, 0xC357,
+ 0xC361, 0xC362, 0xC365, 0xC369, 0xC371, 0xC373, 0xC375, 0xC377,
+ 0xC3A1, 0xC3A2, 0xC3A5, 0xC3A8, 0xC3A9, 0xC3AA, 0xC3B1, 0xC3B3,
+ 0xC3B5, 0xC3B7, 0xC461, 0xC462, 0xC465, 0xC469, 0xC471, 0xC473,
+ 0xC475, 0xC477, 0xC481, 0xC482, 0xC485, 0xC489, 0xC491, 0xC493,
+ 0xC495, 0xC496, 0xC497, 0xC4A1, 0xC4A2, 0xC4B7, 0xC4E1, 0xC4E2,
+ 0xC4E5, 0xC4E8, 0xC4E9, 0xC4F1, 0xC4F3, 0xC4F5, 0xC4F6, 0xC4F7,
+ 0xC541, 0xC542, 0xC545, 0xC549, 0xC551, 0xC553, 0xC555, 0xC557,
+ 0xC561, 0xC565, 0xC569, 0xC571, 0xC573, 0xC575, 0xC576, 0xC577,
+ 0xC581, 0xC5A1, 0xC5A2, 0xC5A5, 0xC5A9, 0xC5B1, 0xC5B3, 0xC5B5,
+ 0xC5B7, 0xC5C1, 0xC5C2, 0xC5C5, 0xC5C9, 0xC5D1, 0xC5D7, 0xC5E1,
+ 0xC5F7, 0xC641, 0xC649, 0xC661, 0xC681, 0xC682, 0xC685, 0xC689,
+ 0xC691, 0xC693, 0xC695, 0xC697, 0xC6A1, 0xC6A5, 0xC6A9, 0xC6B7,
+ 0xC6C1, 0xC6D7, 0xC6E1, 0xC6E2, 0xC6E5, 0xC6E9, 0xC6F1, 0xC6F3,
+ 0xC6F5, 0xC6F7, 0xC741, 0xC745, 0xC749, 0xC751, 0xC761, 0xC762,
+ 0xC765, 0xC769, 0xC771, 0xC773, 0xC777, 0xC7A1, 0xC7A2, 0xC7A5,
+ 0xC7A9, 0xC7B1, 0xC7B3, 0xC7B5, 0xC7B7, 0xC861, 0xC862, 0xC865,
+ 0xC869, 0xC86A, 0xC871, 0xC873, 0xC875, 0xC876, 0xC877, 0xC881,
+ 0xC882, 0xC885, 0xC889, 0xC891, 0xC893, 0xC895, 0xC896, 0xC897,
+ 0xC8A1, 0xC8B7, 0xC8E1, 0xC8E2, 0xC8E5, 0xC8E9, 0xC8EB, 0xC8F1,
+ 0xC8F3, 0xC8F5, 0xC8F6, 0xC8F7, 0xC941, 0xC942, 0xC945, 0xC949,
+ 0xC951, 0xC953, 0xC955, 0xC957, 0xC961, 0xC965, 0xC976, 0xC981,
+ 0xC985, 0xC9A1, 0xC9A2, 0xC9A5, 0xC9A9, 0xC9B1, 0xC9B3, 0xC9B5,
+ 0xC9B7, 0xC9BC, 0xC9C1, 0xC9C5, 0xC9E1, 0xCA41, 0xCA45, 0xCA55,
+ 0xCA57, 0xCA61, 0xCA81, 0xCA82, 0xCA85, 0xCA89, 0xCA91, 0xCA93,
+ 0xCA95, 0xCA97, 0xCAA1, 0xCAB6, 0xCAC1, 0xCAE1, 0xCAE2, 0xCAE5,
+ 0xCAE9, 0xCAF1, 0xCAF3, 0xCAF7, 0xCB41, 0xCB45, 0xCB49, 0xCB51,
+ 0xCB57, 0xCB61, 0xCB62, 0xCB65, 0xCB68, 0xCB69, 0xCB6B, 0xCB71,
+ 0xCB73, 0xCB75, 0xCB81, 0xCB85, 0xCB89, 0xCB91, 0xCB93, 0xCBA1,
+ 0xCBA2, 0xCBA5, 0xCBA9, 0xCBB1, 0xCBB3, 0xCBB5, 0xCBB7, 0xCC61,
+ 0xCC62, 0xCC63, 0xCC65, 0xCC69, 0xCC6B, 0xCC71, 0xCC73, 0xCC75,
+ 0xCC76, 0xCC77, 0xCC7B, 0xCC81, 0xCC82, 0xCC85, 0xCC89, 0xCC91,
+ 0xCC93, 0xCC95, 0xCC96, 0xCC97, 0xCCA1, 0xCCA2, 0xCCE1, 0xCCE2,
+ 0xCCE5, 0xCCE9, 0xCCF1, 0xCCF3, 0xCCF5, 0xCCF6, 0xCCF7, 0xCD41,
+ 0xCD42, 0xCD45, 0xCD49, 0xCD51, 0xCD53, 0xCD55, 0xCD57, 0xCD61,
+ 0xCD65, 0xCD69, 0xCD71, 0xCD73, 0xCD76, 0xCD77, 0xCD81, 0xCD89,
+ 0xCD93, 0xCD95, 0xCDA1, 0xCDA2, 0xCDA5, 0xCDA9, 0xCDB1, 0xCDB3,
+ 0xCDB5, 0xCDB7, 0xCDC1, 0xCDD7, 0xCE41, 0xCE45, 0xCE61, 0xCE65,
+ 0xCE69, 0xCE73, 0xCE75, 0xCE81, 0xCE82, 0xCE85, 0xCE88, 0xCE89,
+ 0xCE8B, 0xCE91, 0xCE93, 0xCE95, 0xCE97, 0xCEA1, 0xCEB7, 0xCEE1,
+ 0xCEE5, 0xCEE9, 0xCEF1, 0xCEF5, 0xCF41, 0xCF45, 0xCF49, 0xCF51,
+ 0xCF55, 0xCF57, 0xCF61, 0xCF65, 0xCF69, 0xCF71, 0xCF73, 0xCF75,
+ 0xCFA1, 0xCFA2, 0xCFA5, 0xCFA9, 0xCFB1, 0xCFB3, 0xCFB5, 0xCFB7,
+ 0xD061, 0xD062, 0xD065, 0xD069, 0xD06E, 0xD071, 0xD073, 0xD075,
+ 0xD077, 0xD081, 0xD082, 0xD085, 0xD089, 0xD091, 0xD093, 0xD095,
+ 0xD096, 0xD097, 0xD0A1, 0xD0B7, 0xD0E1, 0xD0E2, 0xD0E5, 0xD0E9,
+ 0xD0EB, 0xD0F1, 0xD0F3, 0xD0F5, 0xD0F7, 0xD141, 0xD142, 0xD145,
+ 0xD149, 0xD151, 0xD153, 0xD155, 0xD157, 0xD161, 0xD162, 0xD165,
+ 0xD169, 0xD171, 0xD173, 0xD175, 0xD176, 0xD177, 0xD181, 0xD185,
+ 0xD189, 0xD193, 0xD1A1, 0xD1A2, 0xD1A5, 0xD1A9, 0xD1AE, 0xD1B1,
+ 0xD1B3, 0xD1B5, 0xD1B7, 0xD1BB, 0xD1C1, 0xD1C2, 0xD1C5, 0xD1C9,
+ 0xD1D5, 0xD1D7, 0xD1E1, 0xD1E2, 0xD1E5, 0xD1F5, 0xD1F7, 0xD241,
+ 0xD242, 0xD245, 0xD249, 0xD253, 0xD255, 0xD257, 0xD261, 0xD265,
+ 0xD269, 0xD273, 0xD275, 0xD281, 0xD282, 0xD285, 0xD289, 0xD28E,
+ 0xD291, 0xD295, 0xD297, 0xD2A1, 0xD2A5, 0xD2A9, 0xD2B1, 0xD2B7,
+ 0xD2C1, 0xD2C2, 0xD2C5, 0xD2C9, 0xD2D7, 0xD2E1, 0xD2E2, 0xD2E5,
+ 0xD2E9, 0xD2F1, 0xD2F3, 0xD2F5, 0xD2F7, 0xD341, 0xD342, 0xD345,
+ 0xD349, 0xD351, 0xD355, 0xD357, 0xD361, 0xD362, 0xD365, 0xD367,
+ 0xD368, 0xD369, 0xD36A, 0xD371, 0xD373, 0xD375, 0xD377, 0xD37B,
+ 0xD381, 0xD385, 0xD389, 0xD391, 0xD393, 0xD397, 0xD3A1, 0xD3A2,
+ 0xD3A5, 0xD3A9, 0xD3B1, 0xD3B3, 0xD3B5, 0xD3B7
+};
+
+/**
+ * ks symbols
+ */
+const unsigned tblhhtg_ks[] =
+{
+ 0xC7D1, 0xB1DB, 0xB0FA, 0xC4C4, 0xC7BB, 0xC5CD, noneks, noneks,
+ 0xA2B1, 0xA3DF, 0xA2D5, 0xA6B1, 0xA1B8, 0xA1B9, 0xA3DF, 0xA1DA,
+ 0xA2C6, 0xA2CC, 0xA2CB, noneks, noneks, 0xA6BE, 0xA6B9, 0xA6C1,
+ 0xA6C2, 0xA6B4, 0xA6AD, 0xA6AF, 0xA6B0, 0xA6C3, 0xA6C4, noneks,
+ 0xA6AE, 0xA6B0, 0xA2D7, 0xA1E1, 0xA1D6, noneks, 0xA6BC, 0xA6B7,
+ 0xA6B1, 0xA6AE, 0xA6B5, 0xA6B3, 0xA6B2, 0xA6AC, 0xA6B6, 0xA6BA,
+ 0xA6BF, 0xA6B8, 0xA6BD, 0xA6C5, 0xA6C6, 0xA6C8, 0xA6C7, 0xA6C0,
+ 0xA6BB, noneks, noneks, noneks, 0xA1E1, 0xA1E1, 0xA1E1, 0xA1E1
+};
+
+/**
+ * kssm symbols
+ */
+const unsigned hhtg_tg[] =
+{
+ 0xD065, 0x8B69, 0x89C1, 0xC4F1, 0xCF41, 0xC8E1, 0xD3C5, 0xD931,
+ 0xD931, 0xD481, 0xD482, 0xD488, 0xD48A, 0xD48F, 0xD493, 0xD494,
+ 0xD4B0, 0xD4B1, 0xD4B2, 0xD931, 0xD931, 0xD4B5, 0xD4B6, 0xD4B7,
+ 0xD4B8, 0xD4B9, 0xD4BA, 0xD4BB, 0xD4BC, 0xD4BD, 0xD4BE, 0xD496,
+ 0xD497, 0xD49C, 0xD4A9, 0xD4AF, 0xD4F4, 0xD4F5, 0xD4C6, 0xD4C7,
+ 0xD4C8, 0xD4C9, 0xD4CA, 0xD4CB, 0xD4CC, 0xD4CD, 0xD4CE, 0xD4CF,
+ 0xD4D0, 0xD4D1, 0xD4D2, 0xD4D3, 0xD4D4, 0xD4D5, 0xD4D6, 0xD4D7,
+ 0xD4D8, 0xD4F7, 0xD4FA, 0xD4FE, 0xD4DC, 0xD4DD, 0xD4DE, 0xD4DF
+};
+
+#define LINEBASE 0x3013
+
+// ?
+static char LineCharDir(hchar ch)
+{
+ static const char index2dir[] = { 10, 11, 9, 14, 15, 13, 6, 7, 5, 3, 12 };
+
+ return (LINEBASE <= ch && ch < LINEBASE + 11 * 7) ?
+ index2dir[(ch - LINEBASE) % 11] : 0;
+}
+
+
+/**
+ * Convert hwp's special character to ks
+ */
+static hchar s_hh2ks(hchar hh)
+{
+ hchar i, idx = hh >> 8;
+
+ if (hh == 0x81 || hh == 0x82)
+ return '\"';
+ else if (hh == 0x83 || hh == 0x84)
+ return '\'';
+ if (idx == 0x1F)
+ {
+ idx = 170;
+ i = hh & 0xff;
+ if (i >= 0x60)
+ {
+ idx++;
+ i -= 0x60;
+ }
+ return (idx << 8) | (i + 160);
+ }
+ if (((hh & 0xff) >= 0xC0) || (hh == 0x1F00))
+ return 0;
+ if (idx < 0x34 || idx >= 0x38)
+ return 0x2020;
+ if (hh >= HCA_TG)
+ {
+ return sal::static_int_cast<hchar>(tblhhtg_ks[hh - HCA_TG]);
+ }
+ hh -= HCA_KSS;
+ idx = hh / 0x60 + 161;
+ i = hh % 0x60 + 160;
+ if (idx == 170)
+ idx += 2;
+ return (idx << 8) | i;
+}
+
+
+/**
+ * Convert hwp's special character to kssm
+ */
+static hchar s_hh2kssm(hchar hh)
+{
+ hchar i, idx = hh >> 8;
+
+ if ((idx < 0x34 || idx >= 0x38) && idx != 0x1F)
+ return 0;
+ if (hh >= HCA_TG)
+ return sal::static_int_cast<hchar>(hhtg_tg[hh - HCA_TG]);
+ if (idx == 0x1F)
+ hh = hh - 0x1F00 + 0x360;
+ else
+ {
+ hh -= HCA_KSS;
+ if (hh >= 0x360)
+ hh += 0xC0;
+ }
+ idx = hh / 0xC0 + 217;
+ i = hh % 0xC0;
+ if (i >= 95)
+ i -= 2;
+ i += 48;
+ if (i >= 127)
+ i += 18;
+ return (idx << 8) | i;
+}
+
+
+static hchar lineCharConv(hchar ch)
+{
+ int flag;
+
+ switch (ch)
+ {
+ case 0x3060 + '\'' - 31:
+ case 0x3060 + '\"' - 31:
+ ch--;
+ [[fallthrough]];
+ case 0x3060 + '\'' - 32:
+ case 0x3060 + '\"' - 32:
+ case 0x3060 + '{' - 32:
+ case 0x3060 + '[' - 32:
+ case 0x3060 + ']' - 32:
+ case 0x3060 + '}' - 32:
+ return ch - (0x3060 - 32);
+ }
+ flag = LineCharDir(ch);
+ switch (flag)
+ {
+ case 3:
+ return '-';
+ case 12:
+ return '|';
+ default:
+ return '+';
+ }
+}
+
+
+static int KsSearch(hchar c)
+{
+ int lo, hi, mid;
+
+ lo = mid = 0;
+ hi = 2350 - 1;
+
+ while (lo <= hi)
+ {
+ mid = (lo + hi) >> 1;
+ hchar c2 = ksTbl[mid];
+ if (c == c2)
+ break;
+ if (c < c2)
+ hi = mid - 1;
+ else
+ lo = mid + 1;
+ }
+ return mid;
+}
+
+
+static hchar cdkssm2ks_han(hchar kssm)
+{
+ unsigned int index;
+ unsigned char lo, hi;
+
+/* "One" */
+ if (kssm == 0xd3c5)
+ return 0xc7d1;
+
+ index = KsSearch(kssm);
+ if (kssm != ksTbl[index])
+ return jaso2ks(kssm);
+ hi = sal::static_int_cast<char>(index / (0xFE - 0xA1 + 1) + 0xB0);
+ lo = sal::static_int_cast<unsigned char>(index % (0xFE - 0xA1 + 1) + 0xA1);
+ return lo | (hi << 8);
+}
+
+
+#define IsHangul(c) ((c) & 0x8000)
+#define IsHanja(c) (((c) & 0x4000)==0x4000)
+
+const hchar jaso_hh_code[] =
+{
+ 34881, 35905, 33860, 36929, 33862, 33863, 37953, 38977, 40001, 33866,
+ 33867,
+ 33868, 33869, 33870, 33871, 33872, 41025, 42049, 43073, 33876, 44097,
+ 45121,
+ 46145, 47169, 48193, 49217, 50241, 51265, 52289, 53313, 33889, 33921,
+ 33953,
+ 33985, 34017, 34113, 34145, 34177, 34209, 34241, 34273, 34369, 34401,
+ 34433,
+ 34465, 34497, 34529, 34625, 34657, 34689, 34721
+};
+
+/* os: unused
+static int is_jaso(hchar hh)
+{
+ unsigned int i;
+
+ for (i = 0; i < SAL_N_ELEMENTS(jaso_hh_code); i++)
+ if (hh == jaso_hh_code[i])
+ return 1;
+ return 0;
+}*/
+
+
+static hchar jaso2ks(hchar hh)
+{
+ for (size_t i = 0; i < SAL_N_ELEMENTS(jaso_hh_code); i++)
+ if (hh == jaso_hh_code[i])
+ {
+ return sal::static_int_cast<hchar>(0xa4a1 + i);
+ }
+ return 0;
+}
+
+
+//1 00011 00 001 00011
+const hchar choseong_to_unicode[] =
+{
+ 0x111e, 0, 0x1100, 0x1101, 0x1102, 0x1103, 0x1104, 0x1105,
+ 0x1106, 0x1107, 0x1108, 0x1109, 0x110a, 0x110b, 0x110c, 0x110d,
+ 0x110e, 0x110f, 0x1110, 0x1111, 0x1112, 0x1120, 0x1121, 0x1127,
+ 0x112b, 0x112d, 0x112f, 0x1132, 0x1136, 0x1140, 0x114c, 0x1158
+};
+/* There are some other codes where the medial sound is 0 or 1. It needs to extract the rules in those area */
+const hchar joongseong_to_unicode[] =
+{
+ 0, 0, 0, 0x1161, 0x1162, 0x1163, 0x1164, 0x1165,
+ 0, 0, 0x1166, 0x1167, 0x1168, 0x1169, 0x116a, 0x116b,
+ 0, 0x1188, 0x116c, 0x116d, 0x116e, 0x116f, 0x1170, 0x1171,
+ 0x1191, 0x1194, 0x1172, 0x1173, 0x1174, 0x1175, 0x119e, 0x11a1
+};
+
+const hchar jongseong_to_unicode[] =
+{
+ 0x11d9, 0 , 0x11a8, 0x11a9, 0x11aa, 0x11ab, 0x11ac, 0x11ad,
+ 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, 0x11b4, 0x11b5,
+ 0x11b6, 0x11b7, 0x11e6, 0x11b8, 0x11b9, 0x11ba, 0x11bb, 0x11bc,
+ 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x11eb, 0x11f0
+};
+
+/* The medial sound is 0 or 1
+ * first 32 are consonants and vowels and the other 32 is combinations of alphabets
+ * (0x8000 ~ 0xa413) are the first 32. the other 32 start from 0x8400
+ * consonants and vowels area is made as a general table and the rest are made of a structure mapping table
+ *
+ * 844, except for the remaining 1152-308 is a combination of consonants and vowels. */
+const hchar jamo_to_unicode[] =
+{
+ 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, 0x3138,
+ 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f, 0x3140,
+ 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147, 0x3148,
+ 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x3172, 0x3173,
+
+ 0x3176, 0x317a, 0x317c, 0x317d, 0x317e, 0x3185, 0x3178, 0x317f,
+ 0x3181, 0x316d, 0x11c3, 0x11c4, 0x1113, 0x1114, 0x1115, 0x1116,
+ 0x11c7, 0x11c8, 0x11c9, 0x11ca, 0x11cb, 0x11cc, 0x11cd, 0x11ce,
+ 0x11cf, 0x11d0, 0x11d1, 0x11d2, 0x11d3, 0x11d4, 0x11d5, 0x11d6,
+
+ 0x11d7, 0x11d8, 0x111b, 0x11da, 0x11db, 0x11dc, 0x11dd, 0x11de,
+ 0x11df, 0x11e0, 0x11e1, 0x11e2, 0x111f, 0x11e3, 0x1122, 0x1123,
+ 0x1124, 0x1125, 0x1126, 0x1128, 0x1129, 0x112a, 0x11e5, 0x112c,
+ 0x112e, 0x1130, 0x1131, 0x1133, 0x1134, 0x1135, 0x1137, 0x1138,
+
+ 0x1139, 0x113a, 0x113b, 0x113c, 0x113d, 0x113e, 0x113f, 0x1141,
+ 0x11ed, 0x1142, 0x1143, 0x1144, 0x1145, 0x1146, 0x1147, 0x1148,
+ 0x1149, 0x11ef, 0x114a, 0x114b, 0x11f1, 0x11f2, 0x114d, 0x114e,
+ 0x114f, 0x1150, 0x1151, 0x1152, 0x1153, 0x1154, 0x1155, 0x1156,
+
+ 0x1157, 0x11f5, 0x11f6, 0x11f7, 0x11f8, 0x11f9, 0x1176, 0x1177,
+ 0x1178, 0x1179, 0x117a, 0x117b, 0x117c, 0x117d, 0x117e, 0x117f,
+ 0x1180, 0x1181, 0x1182, 0x1183, 0x1184, 0x1185, 0x1186, 0x1187,
+ 0x1189, 0x118a, 0x118b, 0x118c, 0x118d, 0x118e, 0x118f, 0x1190,
+
+ 0x1192, 0x1193, 0x1195, 0x1196, 0x1197, 0x1198, 0x1199, 0x119a,
+ 0x119b, 0x119c, 0x119d, 0x119f, 0x11a0, 0x11a2, 0x11a8, 0x11a9,
+ 0x11aa, 0x11ab, 0x11ac, 0x11ad, 0x11ae, 0x1104, 0x11af, 0x11b0,
+ 0x11b1, 0x11b2, 0x11b3, 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8,
+
+ 0x1108, 0x11b9, 0x11ba, 0x11bb, 0x11bc, 0x11bd, 0x3149, 0x11be,
+ 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x111e, 0x1120, 0x1127, 0x11e7,
+ 0x11e8, 0x11ea, 0x1136, 0x1158, 0x11e6, 0x11eb, 0x11f0, 0x11d9,
+ 0x11c3, 0x11c4, 0x11c5, 0x1114, 0x11c6, 0x1116, 0x11c7, 0x11c8,
+
+ 0x11c9, 0x11ca, 0x11cb, 0x3169, 0x11cd, 0x11ce, 0x11cf, 0x1119,
+ 0x11d1, 0x11d2, 0x11d3, 0x11d4, 0x11d5, 0x11d6, 0x11d7, 0x11d8,
+ 0x111b, 0x11da, 0x11db, 0x11dc, 0x11dd, 0x11de, 0x11df, 0x11e0,
+ 0x11e1, 0x11e2, 0x111f, 0x11e3, 0x1122, 0x1123, 0x1124, 0x1125,
+
+ 0x1126, 0x1128, 0x1129, 0x11e4, 0x11e5, 0x112c, 0x112e, 0x1130,
+ 0x1131, 0x1133, 0x1134, 0x1135, 0x1137, 0x1138, 0x1139, 0x113a,
+ 0x113b, 0x113c, 0x113d, 0x113e, 0x113f, 0x11ec, 0x11ed, 0x1142,
+ 0x1143, 0x1144, 0x1145, 0x1146, 0x1147, 0x1148, 0x1149, 0x11ef,
+
+ 0x114a, 0x114b, 0x11f1, 0x11f2, 0x114d, 0x114e, 0x114f, 0x1150,
+ 0x1151, 0x1152, 0x1153, 0x1154, 0x1155, 0x1156, 0x1157, 0x11f5,
+ 0x11f6, 0x11f7, 0x11f8, 0x11f9
+};
+
+namespace {
+
+struct JamoComp{
+ int size;
+ hchar v1;
+ hchar v2;
+ hchar v3;
+};
+
+}
+
+/* 704 + 12 = 706 */
+const JamoComp jamocomp1_to_unicode[] =
+{
+ {3, 0x1100, 0x1161, 0x11e7}, {3, 0x1100, 0x1161, 0x3167},
+ {3, 0x1100, 0x1161, 0x11dd}, {3, 0x1100, 0x1161, 0x11e2},
+ {3, 0x1100, 0x1161, 0x11e5}, {3, 0x1100, 0x1161, 0x11f1},
+ {3, 0x1100, 0x1163, 0x11e2}, {3, 0x1100, 0x1163, 0x11f9},
+ {3, 0x1100, 0x1165, 0x11e7}, {3, 0x1100, 0x1165, 0x11c7},
+ {3, 0x1100, 0x1165, 0x11dd}, {3, 0x1100, 0x1165, 0x11e2},
+
+ {3, 0x1100, 0x1165, 0x11e3}, {3, 0x1100, 0x1167, 0x11e7},
+ {3, 0x1100, 0x1167, 0x11f1}, {3, 0x1100, 0x1167, 0x11f9},
+ {3, 0x1100, 0x1169, 0x11d6}, {3, 0x1100, 0x1169, 0x11dd},
+ {3, 0x1100, 0x1169, 0x11e2}, {3, 0x1100, 0x1169, 0x11f1},
+ {3, 0x1100, 0x1169, 0x11f7}, {3, 0x1100, 0x1169, 0x11f8},
+ {3, 0x1100, 0x116a, 0x11f9}, {3, 0x1100, 0x116d, 0x11e2},
+ {3, 0x1100, 0x116e, 0x11c7}, {3, 0x1100, 0x116e, 0x11cd},
+ {3, 0x1100, 0x116e, 0x11da}, {3, 0x1100, 0x116e, 0x11dd},
+
+ {3, 0x1100, 0x116e, 0x11e2}, {3, 0x1100, 0x116e, 0x11f6},
+ {3, 0x1100, 0x116e, 0x11f9}, {3, 0x1100, 0x116f, 0x11c7},
+ {3, 0x1100, 0x116f, 0x11f9}, {3, 0x1100, 0x1172, 0x11e2},
+ {3, 0x1100, 0x1172, 0x11f9}, {3, 0x1100, 0x1173, 0x11c7},
+ {3, 0x1100, 0x1173, 0x11dd}, {3, 0x1100, 0x1173, 0x11df},
+ {3, 0x1100, 0x1173, 0x11e2}, {3, 0x1100, 0x1173, 0x11f9},
+ {3, 0x1100, 0x1174, 0x11f9}, {3, 0x1100, 0x1175, 0x11e7},
+ {3, 0x1100, 0x1175, 0x11cd}, {3, 0x1100, 0x1175, 0x11e2},
+
+ {3, 0x1100, 0x1175, 0x11f9}, {3, 0x1100, 0x1191, 0x11f9},
+ {3, 0x1100, 0x119e, 0x11e7}, {3, 0x1100, 0x119e, 0x11d3},
+ {3, 0x1100, 0x119e, 0x11d5}, {3, 0x1100, 0x119e, 0x11e3},
+ {3, 0x1100, 0x11a1, 0x11f1}, {2, 0x1100, 0x1176, 0x0000},
+ {2, 0x1100, 0x1178, 0x0000}, {2, 0x1100, 0x117c, 0x0000},
+ {3, 0x1100, 0x117c, 0x11ab}, {3, 0x1100, 0x117c, 0x11af},
+ {3, 0x1100, 0x117c, 0x11b7}, {2, 0x1100, 0x1189, 0x0000},
+ {3, 0x1100, 0x1189, 0x11ab}, {3, 0x1100, 0x1189, 0x11bc},
+
+ {2, 0x1100, 0x118b, 0x0000}, {3, 0x1100, 0x118b, 0x11ab},
+ {2, 0x1100, 0x118c, 0x0000}, {2, 0x1100, 0x118d, 0x0000},
+ {2, 0x1100, 0x1192, 0x0000}, {3, 0x1100, 0x1192, 0x11bc},
+ {2, 0x1100, 0x1195, 0x0000}, {2, 0x1100, 0x1196, 0x0000},
+ {2, 0x1100, 0x1198, 0x0000}, {2, 0x1100, 0x119b, 0x0000},
+ {2, 0x1100, 0x119c, 0x0000}, {2, 0x1100, 0x119d, 0x0000},
+ {2, 0x1100, 0x119f, 0x0000}, {3, 0x1100, 0x119f, 0x11bc},
+ {3, 0x1101, 0x1163, 0x11e2}, {3, 0x1101, 0x1165, 0x11ec},
+
+ {3, 0x1101, 0x1165, 0x11ed}, {3, 0x1101, 0x116e, 0x11e2},
+ {3, 0x1101, 0x1172, 0x11e2}, {3, 0x1101, 0x1175, 0x11e2},
+ {3, 0x1101, 0x1175, 0x11f9}, {3, 0x1101, 0x1191, 0x11bc},
+ {2, 0x1101, 0x1176, 0x0000}, {2, 0x1101, 0x117b, 0x0000},
+ {2, 0x1101, 0x1189, 0x0000}, {2, 0x1101, 0x118c, 0x0000},
+ {2, 0x1101, 0x1198, 0x0000}, {3, 0x1102, 0x1161, 0x11e7},
+ {3, 0x1102, 0x1161, 0x11c4}, {3, 0x1102, 0x1161, 0x11da},
+ {3, 0x1102, 0x1161, 0x11dd}, {3, 0x1102, 0x1161, 0x11e2},
+
+ {3, 0x1102, 0x1161, 0x11f9}, {3, 0x1102, 0x1165, 0x11db},
+ {3, 0x1102, 0x1165, 0x11dd}, {3, 0x1102, 0x1165, 0x11e3},
+ {3, 0x1102, 0x1167, 0x11c5}, {3, 0x1102, 0x1167, 0x11c7},
+ {3, 0x1102, 0x1167, 0x11f9}, {3, 0x1102, 0x1169, 0x11e2},
+ {3, 0x1102, 0x1169, 0x11e4}, {3, 0x1102, 0x1169, 0x11f3},
+ {3, 0x1102, 0x116e, 0x11c6}, {3, 0x1102, 0x116e, 0x11c7},
+ {3, 0x1102, 0x116e, 0x11c8}, {3, 0x1102, 0x116e, 0x11dd},
+ {3, 0x1102, 0x116e, 0x11e2}, {3, 0x1102, 0x116e, 0x11f5},
+
+ {3, 0x1102, 0x1172, 0x11e2}, {3, 0x1102, 0x1173, 0x11c3},
+ {3, 0x1102, 0x1175, 0x11c3}, {3, 0x1102, 0x1175, 0x11dd},
+ {3, 0x1102, 0x1175, 0x11e2}, {3, 0x1102, 0x119e, 0x11d7},
+ {2, 0x1102, 0x1176, 0x0000}, {2, 0x1102, 0x117c, 0x0000},
+ {3, 0x1102, 0x117c, 0x11a8}, {2, 0x1102, 0x118c, 0x0000},
+ {2, 0x1102, 0x1196, 0x0000}, {2, 0x1102, 0x1197, 0x0000},
+ {2, 0x1102, 0x1198, 0x0000}, {2, 0x1102, 0x119b, 0x0000},
+ {3, 0x1103, 0x1161, 0x11e7}, {3, 0x1103, 0x1161, 0x11c7},
+
+ {3, 0x1103, 0x1161, 0x1119}, {3, 0x1103, 0x1161, 0x11db},
+ {3, 0x1103, 0x1161, 0x11dd}, {3, 0x1103, 0x1161, 0x11e2},
+ {3, 0x1103, 0x1161, 0x11f1}, {3, 0x1103, 0x1161, 0x11f9},
+ {3, 0x1103, 0x1163, 0x11e2}, {3, 0x1103, 0x1163, 0x11f1},
+ {3, 0x1103, 0x1165, 0x11dd}, {3, 0x1103, 0x1167, 0x11f9},
+ {3, 0x1103, 0x1169, 0x11e7}, {3, 0x1103, 0x1169, 0x11d6},
+ {3, 0x1103, 0x1169, 0x11e2}, {3, 0x1103, 0x1169, 0x11f1},
+ {3, 0x1103, 0x116d, 0x11e2}, {3, 0x1103, 0x116e, 0x11ce},
+
+ {3, 0x1103, 0x116e, 0x1119}, {3, 0x1103, 0x116e, 0x11da},
+ {3, 0x1103, 0x116e, 0x11e2}, {3, 0x1103, 0x1172, 0x11e2},
+ {3, 0x1103, 0x1173, 0x11cd}, {3, 0x1103, 0x1173, 0x11ce},
+ {3, 0x1103, 0x1173, 0x11e2}, {3, 0x1103, 0x1173, 0x11e3},
+ {3, 0x1103, 0x1173, 0x11f1}, {3, 0x1103, 0x1174, 0x11f9},
+ {3, 0x1103, 0x1175, 0x11f9}, {3, 0x1103, 0x119e, 0x11e7},
+ {3, 0x1103, 0x119e, 0x11e8}, {3, 0x1103, 0x119e, 0x11ea},
+ {3, 0x1103, 0x119e, 0x11c3}, {3, 0x1103, 0x119e, 0x11cc},
+
+ {3, 0x1103, 0x119e, 0x11e3}, {3, 0x1103, 0x119e, 0x11e9},
+ {2, 0x1103, 0x1176, 0x0000}, {2, 0x1103, 0x1178, 0x0000},
+ {2, 0x1103, 0x117c, 0x0000}, {3, 0x1103, 0x117c, 0x11b7},
+ {2, 0x1103, 0x1189, 0x0000}, {3, 0x1103, 0x1189, 0x11ab},
+ {2, 0x1103, 0x118c, 0x0000}, {2, 0x1103, 0x1195, 0x0000},
+ {2, 0x1103, 0x1196, 0x0000}, {2, 0x1103, 0x1198, 0x0000},
+ {2, 0x1103, 0x1199, 0x0000}, {3, 0x1103, 0x1199, 0x11ab},
+ {3, 0x1103, 0x1199, 0x11bc}, {3, 0x1104, 0x1161, 0x11d8},
+
+ {3, 0x1104, 0x1161, 0x11e2}, {3, 0x1104, 0x1161, 0x11f9},
+ {3, 0x1104, 0x1163, 0x11e2}, {3, 0x1104, 0x1169, 0x11e2},
+ {3, 0x1104, 0x1169, 0x11f9}, {3, 0x1104, 0x116d, 0x11e2},
+ {3, 0x1104, 0x116e, 0x11e2}, {3, 0x1104, 0x116e, 0x11f9},
+ {3, 0x1104, 0x1172, 0x11e2}, {3, 0x1104, 0x1173, 0x11e2},
+ {3, 0x1104, 0x1175, 0x11f9}, {2, 0x1104, 0x117b, 0x0000},
+ {2, 0x1104, 0x118c, 0x0000}, {2, 0x1104, 0x1198, 0x0000},
+ {3, 0x1105, 0x1161, 0x11e7}, {3, 0x1105, 0x1161, 0x11dd},
+
+ {3, 0x1105, 0x1161, 0x11e2}, {3, 0x1105, 0x1161, 0x11f5},
+ {3, 0x1105, 0x1161, 0x11f9}, {3, 0x1105, 0x1163, 0x11e2},
+ {3, 0x1105, 0x1167, 0x11c7}, {3, 0x1105, 0x1167, 0x11e2},
+ {3, 0x1105, 0x1167, 0x11f9}, {3, 0x1105, 0x1169, 0x11dd},
+ {3, 0x1105, 0x1169, 0x11e2}, {3, 0x1105, 0x1169, 0x11f1},
+ {3, 0x1105, 0x116d, 0x11dd}, {3, 0x1105, 0x116d, 0x11e2},
+ {3, 0x1105, 0x116e, 0x11dd}, {3, 0x1105, 0x116e, 0x11e2},
+ {3, 0x1105, 0x1172, 0x11e2}, {3, 0x1105, 0x1173, 0x11dd},
+
+ {3, 0x1105, 0x1173, 0x11e2}, {3, 0x1105, 0x1175, 0x11dd},
+ {3, 0x1105, 0x1175, 0x11e2}, {3, 0x1105, 0x1175, 0x11f9},
+ {3, 0x1105, 0x119e, 0x11d7}, {3, 0x1105, 0x119e, 0x11dc},
+ {3, 0x1105, 0x119e, 0x11dd}, {2, 0x1105, 0x1176, 0x0000},
+
+/* From here, numbers are not changed. So must change 3 to 2 manually. */
+ {2, 0x1105, 0x1178, 0x0000}, {2, 0x1105, 0x117a, 0x0000},
+ {2, 0x1105, 0x117b, 0x0000}, {2, 0x1105, 0x1186, 0x0000},
+ {2, 0x1105, 0x1187, 0x0000}, {2, 0x1105, 0x118c, 0x0000},
+ {2, 0x1105, 0x1195, 0x0000}, {2, 0x1105, 0x1196, 0x0000},
+
+ {2, 0x1105, 0x1198, 0x0000}, {2, 0x1105, 0x1199, 0x0000},
+ {3, 0x1105, 0x1199, 0x11bc}, {2, 0x1105, 0x119b, 0x0000},
+ {2, 0x111a, 0x1163, 0x0000}, {3, 0x111a, 0x1163, 0x11bc},
+ {3, 0x1106, 0x1161, 0x11e8}, {3, 0x1106, 0x1161, 0x11c7},
+ {3, 0x1106, 0x1161, 0x11cd}, {3, 0x1106, 0x1161, 0x1119},
+ {3, 0x1106, 0x1161, 0x11d8}, {3, 0x1106, 0x1161, 0x11e2},
+ {3, 0x1106, 0x1163, 0x11e2}, {3, 0x1106, 0x1165, 0x11c6},
+ {3, 0x1106, 0x1165, 0x11f9}, {3, 0x1106, 0x1169, 0x11c6},
+
+ {3, 0x1106, 0x1169, 0x11dd}, {3, 0x1106, 0x1169, 0x11e2},
+ {3, 0x1106, 0x116d, 0x11e2}, {3, 0x1106, 0x116e, 0x11e7},
+ {3, 0x1106, 0x116e, 0x11c7}, {3, 0x1106, 0x116e, 0x11e2},
+ {3, 0x1106, 0x116e, 0x11ec}, {3, 0x1106, 0x116e, 0x11ed},
+ {3, 0x1106, 0x116e, 0x11f9}, {3, 0x1106, 0x116f, 0x11f9},
+ {3, 0x1106, 0x1173, 0x11e7}, {3, 0x1106, 0x1174, 0x11f9},
+ {3, 0x1106, 0x1175, 0x11e7}, {3, 0x1106, 0x1175, 0x11f6},
+ {3, 0x1106, 0x1175, 0x11f9}, {3, 0x1106, 0x119e, 0x11c3},
+
+ {2, 0x1106, 0x1176, 0x0000}, {2, 0x1106, 0x1178, 0x0000},
+ {2, 0x1106, 0x117c, 0x0000}, {3, 0x1106, 0x117c, 0x11af},
+ {2, 0x1106, 0x1182, 0x0000}, {2, 0x1106, 0x1183, 0x0000},
+ {2, 0x1106, 0x118c, 0x0000}, {2, 0x1106, 0x1196, 0x0000},
+ {3, 0x1106, 0x1196, 0x11b7}, {2, 0x1106, 0x1198, 0x0000},
+ {2, 0x1106, 0x119f, 0x0000}, {3, 0x1106, 0x119f, 0x11ab},
+ {3, 0x1106, 0x119f, 0x11bc}, {3, 0x1107, 0x1161, 0x11e7},
+ {3, 0x1107, 0x1161, 0x11c9}, {3, 0x1107, 0x1161, 0x11dd},
+
+ {3, 0x1107, 0x1161, 0x11e2}, {3, 0x1107, 0x1161, 0x11e3},
+ {3, 0x1107, 0x1161, 0x11f1}, {3, 0x1107, 0x1161, 0x11f6},
+ {3, 0x1107, 0x1161, 0x11f9}, {3, 0x1107, 0x1165, 0x11c7},
+ {3, 0x1107, 0x1167, 0x11f1}, {3, 0x1107, 0x1169, 0x11e7},
+ {3, 0x1107, 0x1169, 0x11dd}, {3, 0x1107, 0x1169, 0x11e2},
+ {3, 0x1107, 0x116d, 0x11e2}, {3, 0x1107, 0x116e, 0x11e7},
+ {3, 0x1107, 0x116e, 0x11c7}, {3, 0x1107, 0x116e, 0x1119},
+ {3, 0x1107, 0x116e, 0x11d1}, {3, 0x1107, 0x116e, 0x11d2},
+
+ {3, 0x1107, 0x116e, 0x11e2}, {3, 0x1107, 0x116e, 0x11ef},
+ {3, 0x1107, 0x116e, 0x11f9}, {3, 0x1107, 0x116f, 0x11f9},
+ {3, 0x1107, 0x1173, 0x11e7}, {3, 0x1107, 0x1173, 0x11c3},
+ {3, 0x1107, 0x1175, 0x11e7}, {3, 0x1107, 0x1175, 0x11e2},
+ {3, 0x1107, 0x1175, 0x11f1}, {3, 0x1107, 0x1175, 0x11f9},
+ {3, 0x1107, 0x119e, 0x11c3}, {3, 0x1107, 0x119e, 0x11d5},
+ {3, 0x1107, 0x119e, 0x11e3}, {3, 0x1107, 0x11a1, 0x11f1},
+ {2, 0x1107, 0x1176, 0x0000}, {2, 0x1107, 0x1177, 0x0000},
+
+ {2, 0x1107, 0x1178, 0x0000}, {2, 0x1107, 0x117c, 0x0000},
+ {3, 0x1107, 0x117c, 0x11a8}, {3, 0x1107, 0x117c, 0x11af},
+ {3, 0x1107, 0x117c, 0x11b7}, {3, 0x1107, 0x117c, 0x11bc},
+ {2, 0x1107, 0x1182, 0x0000}, {2, 0x1107, 0x118c, 0x0000},
+ {2, 0x1107, 0x1196, 0x0000}, {2, 0x1107, 0x1198, 0x0000},
+ {2, 0x1107, 0x119a, 0x0000}, {2, 0x1107, 0x119f, 0x0000},
+ {3, 0x1107, 0x119f, 0x11ab}, {3, 0x1107, 0x119f, 0x11bc},
+ {3, 0x1108, 0x1161, 0x11e2}, {3, 0x1108, 0x1167, 0x11f9},
+
+ {3, 0x1108, 0x1169, 0x11e2}, {3, 0x1108, 0x116e, 0x11e2},
+ {3, 0x1108, 0x1174, 0x11f9}, {3, 0x1108, 0x1175, 0x11f9},
+ {3, 0x1121, 0x116a, 0x11f9}, {3, 0x1121, 0x119e, 0x114d},
+ {2, 0x1121, 0x118c, 0x0000}, {2, 0x1121, 0x1198, 0x0000},
+ {3, 0x1109, 0x1161, 0x11ca}, {3, 0x1109, 0x1161, 0x11dd},
+ {3, 0x1109, 0x1161, 0x11e2}, {3, 0x1109, 0x1161, 0x11f1},
+ {3, 0x1109, 0x1161, 0x11f9}, {3, 0x1109, 0x1163, 0x11e2},
+ {3, 0x1109, 0x1163, 0x11f1}, {3, 0x1109, 0x1165, 0x11e7},
+
+ {3, 0x1109, 0x1165, 0x11c3}, {3, 0x1109, 0x1165, 0x11ec},
+ {3, 0x1109, 0x1165, 0x11ed}, {3, 0x1109, 0x1167, 0x11e7},
+ {3, 0x1109, 0x1167, 0x11d5}, {3, 0x1109, 0x1167, 0x11dd},
+ {3, 0x1109, 0x1167, 0x11e3}, {3, 0x1109, 0x1167, 0x11f1},
+ {3, 0x1109, 0x1167, 0x11f9}, {3, 0x1109, 0x1169, 0x11c7},
+ {3, 0x1109, 0x1169, 0x11e2}, {3, 0x1109, 0x116a, 0x11f9},
+ {3, 0x1109, 0x116b, 0x11f9}, {3, 0x1109, 0x116d, 0x11e2},
+ {3, 0x1109, 0x116d, 0x11f1}, {3, 0x1109, 0x116e, 0x11e7},
+
+ {3, 0x1109, 0x116e, 0x11e2}, {3, 0x1109, 0x116e, 0x11f9},
+ {3, 0x1109, 0x1172, 0x11e2}, {3, 0x1109, 0x1173, 0x11e2},
+ {3, 0x1109, 0x1173, 0x11e3}, {3, 0x1109, 0x1173, 0x11f1},
+ {3, 0x1109, 0x1174, 0x11f9}, {3, 0x1109, 0x1175, 0x11c7},
+ {3, 0x1109, 0x1175, 0x11ce}, {3, 0x1109, 0x1175, 0x11da},
+ {3, 0x1109, 0x1175, 0x11e2}, {3, 0x1109, 0x1175, 0x11f9},
+ {3, 0x1109, 0x1191, 0x11f9}, {3, 0x1109, 0x119e, 0x11ca},
+ {3, 0x1109, 0x119e, 0x11d6}, {3, 0x1109, 0x119e, 0x11f1},
+
+ {3, 0x1109, 0x119e, 0x11e3}, {3, 0x1109, 0x11a1, 0x11dd},
+ {3, 0x1109, 0x11a1, 0x11f1}, {2, 0x1109, 0x1176, 0x0000},
+ {2, 0x1109, 0x1177, 0x0000}, {2, 0x1109, 0x1178, 0x0000},
+ {2, 0x1109, 0x117c, 0x0000}, {3, 0x1109, 0x117c, 0x11a8},
+ {3, 0x1109, 0x117c, 0x11af}, {3, 0x1109, 0x117c, 0x11b7},
+ {3, 0x1109, 0x117c, 0x11bc}, {2, 0x1109, 0x117e, 0x0000},
+ {2, 0x1109, 0x1189, 0x0000}, {3, 0x1109, 0x1189, 0x11ab},
+ {2, 0x1109, 0x118c, 0x0000}, {2, 0x1109, 0x1190, 0x0000},
+
+ {2, 0x1109, 0x1192, 0x0000}, {3, 0x1109, 0x1192, 0x11bc}
+};
+
+//#define IS_OLD_HAN(x) (((x) >= 0x8020 && (x) <= 0x83ff ) || ( (x) >= 0x8420 && (x) <= 0x843f )) // beside these, there are very much characters in the hangul.
+int hcharconv(hchar ch, hchar *dest, int codeType)
+{
+ unsigned char lo;
+ //printf("hcharconv[%04x]\n",ch);
+ if (ch < 128){
+ dest[0] = ch;
+ return 1;
+ }
+ if (IsHangul(ch))
+ {
+ hchar ch2 = ch;
+ if (codeType == KS)
+ ch = cdkssm2ks_han(ch);
+ else if( codeType == UNICODE ){
+ if( ch2 == 0xd3c5 ){
+ dest[0] = 0xd55c;
+ return 1 ;
+ }
+ int res = kssm_hangul_to_ucs2(ch, dest);
+ //printf("hcharconv Hangul[%04x]\n",dest[0]);
+ return res;
+ }
+ dest[0] = ch;
+ return 1;
+ }
+ /* Chinese characters have a value of 4888 kinds from 0x4000. */
+ else if (IsHanja(ch))
+ {
+ unsigned int index;
+ unsigned char hi;
+ /*Out of 4888 kinds are Chinese characters which are defined by Hangul Word Processor. For this
+ there is no mapping table to convert to Unicode or completion code(KSC5601-87, EUC-KR)
+ */
+ if ((index = ch - 0x4000) >= 4888)
+ {
+ if( codeType == UNICODE )
+ dest[0]= 0x25A1;
+ else
+ dest[0]= 0xA1E0;
+ return 1;
+ }
+ if (codeType == KS)
+ {
+ /* Chinese code is divided into the upper cord and lower cord. Lower code has the value from 0xA1 up to 0xFE.
+ In other words, the number of lower code is the number of (0xFE - 0xA1) +1
+ */
+ hi = sal::static_int_cast<unsigned char>(index / (0xFE - 0xA1 + 1) + 0xCA);
+ lo = sal::static_int_cast<unsigned char>(index % (0xFE - 0xA1 + 1) + 0xA1);
+ ch = (hi << 8) | lo;
+ }
+ else if(codeType == UNICODE){
+ hi = sal::static_int_cast<unsigned char>(index / (0xFE - 0xA1 + 1) + 0xCA);
+ lo = sal::static_int_cast<unsigned char>(index % (0xFE - 0xA1 + 1) + 0xA1);
+ ch = (hi << 8) | lo;
+ ch = ksc5601_han_to_ucs2(ch);
+ }
+ else
+ {
+ hi = sal::static_int_cast<unsigned char>(index / (0x100 - 0x31 - 0x11 - 2) + 0xE0);
+ lo = sal::static_int_cast<unsigned char>(index % (0x100 - 0x31 - 0x11 - 2) + 0x31);
+ if (lo >= 0x7F)
+ lo += 0x12;
+ ch = (hi << 8) | lo;
+ }
+ //printf("hcharconv Hanja[%04x]\n",ch);
+ dest[0] = ch;
+ return 1;
+ }
+ if (LineCharDir(ch))
+ {
+ dest[0] = lineCharConv(ch);
+ return 1;
+ }
+ else if (0x2f00 <= ch && ch <= 0x2f6f && (ch & 0x0f) < 9)
+ {
+// bullet
+ lo = sal::static_int_cast<unsigned char>(ch & 0x0f);
+
+ if( codeType != KSSM )
+ {
+ if (ch < 0x2f10) ch = 0xa1e0;
+ else if (ch < 0x2f20) ch = 0xa1db;
+ else if (ch < 0x2f30) ch = 0xa1de;
+ else if (ch < 0x2f40) ch = 0xa1e2;
+ else if (ch < 0x2f50) ch = 0xa1e4;
+ else if (ch < 0x2f60) ch = 0xa2b7;
+ else ch = 0xa2b9;
+
+ ch = (lo < 6) ? ch : ch + 1;
+ if( codeType == UNICODE)
+ ch = ksc5601_sym_to_ucs2(ch);
+ }
+ else
+ {
+ if (ch < 0x2f10) ch = 0xd970;
+ else if (ch < 0x2f20) ch = 0xd96b;
+ else if (ch < 0x2f30) ch = 0xd96e;
+ else if (ch < 0x2f40) ch = 0xd972;
+ else if (ch < 0x2f50) ch = 0xd974;
+ else if (ch < 0x2f60) ch = 0xd9b7;
+ else ch = 0xd9b9;
+ ch = (lo < 6) ? ch : ch + 1;
+ }
+ //printf("hcharconv Bullet[%04x]\n",ch);
+ dest[0] = ch;
+ return 1 ;
+ }
+/*
+ * Special characters code
+ * In Hangul Word Processor, special characters begins from 0x3400. Combinations are from 0xA1A0
+ */
+ else
+ {
+ if( codeType != KSSM )
+ {
+ //printf("code[0x%04x]\n",ch);
+ hchar ch2 = ch;
+ ch = s_hh2ks(ch);
+ //printf("code ks[0x%04x]\n",ch);
+ if( codeType == UNICODE ){
+ if (ch < 128){
+ dest[0] = ch;
+ return 1;
+ }
+ /* Hangul and Computer: 0x37c0 ~ 0x37c5 */
+ if( ch2 >= 0x37c0 && ch2 <= 0x37c5 ){
+ if( ch2 == 0x37c0 ) dest[0] = 0xd55c;
+ else if( ch2 == 0x37c1 ) dest[0] = 0xae00;
+ else if( ch2 == 0x37c2 ) dest[0] = 0xacfc;
+ else if( ch2 == 0x37c3 ) dest[0] = 0xcef4;
+ else if( ch2 == 0x37c4 ) dest[0] = 0xd4e8;
+ else if( ch2 == 0x37c5 ) dest[0] = 0xd130;
+ return 1;
+ }
+ if( ch == 0x2020 ){
+ switch( ch2 ){
+ case 0x309b :
+ ch = 0xff62;
+ break;
+ case 0x309d :
+ ch = 0xff63;
+ break;
+ default:
+ ch = 0x25a1;
+ break;
+ }
+ }
+ else{
+ ch = ksc5601_sym_to_ucs2(ch);
+ }
+ //printf("code ucs2[0x%04x]\n",ch);
+ }
+ }
+ else{
+ ch = s_hh2kssm(ch);
+ }
+
+ if (ch == 0){ // not '?', but square mark
+ if( codeType == UNICODE )
+ dest[0] = 0x25A1;
+ else
+ dest[0] = 0xA1E0;
+ return 1;
+ }
+ //printf("hcharconv Special[%04x]\n",ch);
+ dest[0] = ch;
+ return 1;
+ }
+}
+
+/* If it's Korean(Hangul). */
+int kssm_hangul_to_ucs2(hchar ch, hchar *dest)
+{
+ hchar choseong, joongseong, jongseong;
+
+ choseong = ((ch >> 10) & 0x1f);
+ joongseong = ((ch >> 5) & 0x1f);
+ jongseong = (ch & 0x1f) ;
+
+ //printf("kssm_hangul_to_ucs2 : [%d,%d,%d]\n", choseong,joongseong,jongseong);
+
+ if( joongseong < 2 ){ /* Not combined area, medial sound = 0,1 */
+ if( joongseong == 0 && ch < 0xa414 ){ /* consonants and vowels includes old characters */
+ int index = choseong * 32 + jongseong;
+ dest[0] = jamo_to_unicode[index];
+ return 1;
+ }
+ else{ /* combination of consonants and vowels includes old characters: an unfinished table */
+ unsigned int index = choseong * 32 + jongseong - 308;
+ if( index < SAL_N_ELEMENTS(jamocomp1_to_unicode) ){
+ dest[0] = jamocomp1_to_unicode[index].v1;
+ dest[1] = jamocomp1_to_unicode[index].v2;
+ dest[2] = jamocomp1_to_unicode[index].v3;
+ return jamocomp1_to_unicode[index].size;
+ }
+ dest[0] = 0x25a1; // empty square.
+ return 1;
+ }
+ }
+ else if ( choseong == 1 && jongseong == 1 ){ /* Vowel */
+ dest[0] = joongseong_to_unicode[joongseong];
+ return 1;
+ }
+ else if ( joongseong == 2 && jongseong == 1 ){ /* Consonant */
+ dest[0] = choseong_to_unicode[choseong];
+ return 1;
+ }
+ else if( choseong > 20 || choseong == 0 ||
+ joongseong == 17 || joongseong == 24 ||
+ joongseong == 25 || joongseong > 29 ||
+ jongseong == 0 || jongseong == 18 ||
+ jongseong > 29 ||
+ choseong == 1 || joongseong == 2 /* Incomplete Hangul */
+ ) { /* Gore */
+ int count = 0;
+ if( choseong != 1 ){
+ dest[count] = choseong_to_unicode[choseong];
+ count++;
+ }
+ if( joongseong > 2 ){
+ dest[count] = joongseong_to_unicode[joongseong];
+ count++;
+ }
+ if( jongseong != 1 ){
+ dest[count] = jongseong_to_unicode[jongseong];
+ count++;
+ }
+ return count;
+ }
+
+ choseong -= 2;
+ if( joongseong < 0x8 )
+ joongseong -= 3;
+ else if( joongseong < 0x10 )
+ joongseong -= 5;
+ else if( joongseong < 0x18 )
+ joongseong -= 7;
+ else
+ joongseong -= 9;
+
+ choseong *= (NUM_JOONGSEONG * NUM_JONGSEONG);
+ joongseong *= NUM_JONGSEONG;
+ jongseong -= jongseong > 0x12 ? 2 : 1;
+
+ dest[0] = UNI_HANGUL_FIRST + choseong + joongseong + jongseong;
+ return 1;
+}
+
+hchar ksc5601_sym_to_ucs2 (hchar input)
+{
+ unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8);
+ unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
+ int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
+ if (idx >= 0 && o3tl::make_unsigned(idx) < SAL_N_ELEMENTS(ksc5601_2uni_page21)) {
+ hchar value = ksc5601_2uni_page21[idx];
+ return value ? value : 0x25a1;
+ }
+ return 0x25a1;
+}
+
+hchar ksc5601_han_to_ucs2 (hchar input)
+{
+ unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8);
+ unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff);
+ int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1);
+ if (idx >= 3854 && o3tl::make_unsigned(idx) < 3854 + SAL_N_ELEMENTS(ksc5601_2uni_page21)) {
+ // Hanja : row 42 - row 93 : 3854 = 94 * (42-1)
+ hchar value = ksc5601_2uni_page21[idx - 3854];
+ return value ? value : '?';
+ }
+ return '?';
+}
+
+OUString hstr2OUString(hchar const* hstr)
+{
+ OUStringBuffer ret;
+ static_assert(sizeof(hchar) == sizeof(sal_Unicode));
+ hchar dest[3];
+ for( ; *hstr ; ){
+ int const res = hcharconv(*hstr++, dest, UNICODE);
+ ret.append(reinterpret_cast<sal_Unicode*>(dest), res);
+ }
+ return ret.makeStringAndClear();
+}
+
+/**
+ * Convert 'Hangul and Computer' strings to the completion code(KSC5601-87)
+ */
+::std::string hstr2ksstr(hchar const* hstr)
+{
+ ::std::string ret;
+ int j;
+ hchar dest[3];
+ for( ; *hstr ; )
+ {
+ int res = hcharconv(*hstr++, dest, KS);
+ for( j = 0 ; j < res ; j++ ){
+ int c = dest[j];
+ if( c < 32 )
+ c = ' ';
+ if( c < 256 )
+ {
+ ret.push_back(sal::static_int_cast<char>(c));
+ }
+ else
+ {
+ ret.push_back(sal::static_int_cast<char>((c >> 8 ) & 0xff));
+ ret.push_back(sal::static_int_cast<char>(c & 0xff));
+ }
+ }
+ }
+ return ret;
+}
+
+
+/*
+ * Convert strings of kchar type, which can contain Korean, English and others
+ * to strings of hchar type of Hangul Word Processor
+ */
+hchar_string kstr2hstr(uchar const* src)
+{
+ hchar_string ret;
+ if (!src)
+ return ret;
+ for (unsigned int i = 0; src[i] != '\0' ; i++)
+ {
+ if ( src[i] < 127 )
+ {
+ ret.push_back(src[i]);
+ }
+ else
+ {
+ ret.push_back(src[i] << 8 | src[i+1]);
+ i++;
+ if (src[i] == '\0')
+ break;
+ }
+ }
+ return ret;
+}
+
+
+/* Convert a combination of a color index value and a shade value to the color value of LibreOffice */
+OUString hcolor2str(uchar color, uchar shade, bool bIsChar)
+{
+ unsigned short red,green,blue;
+
+ switch( static_cast<int>(color) )
+ {
+ case 0 : // black
+ red = 0xff * (100 - shade ) /100;
+ green = 0xff * (100 - shade ) /100;
+ blue = 0xff * (100 - shade ) /100;
+ break;
+ case 1: // blue
+ red = 0xff * (100 - shade ) /100;
+ green = 0xff * (100 - shade ) /100;
+ blue = 0xff;
+ break;
+ case 2: // green
+ red = 0xff * (100 - shade ) /100;
+ if( bIsChar )
+ green = 0x80;
+ else
+ green = 0xff;
+ blue = 0xff * (100 - shade ) /100;
+ break;
+ case 3: // cyan
+ red = 0xff * (100 - shade ) /100;
+ green = 0xff;
+ blue = 0xff;
+ break;
+ case 4: // red
+ red = 0xff;
+ green = 0xff * (100 - shade ) /100;
+ blue = 0xff * (100 - shade ) /100;
+ break;
+ case 5: // magenta
+ red = 0xff;
+ green = 0xff * (100 - shade ) /100;
+ blue = 0xff;
+ break;
+ case 6: //yellow
+ red = 0xff;
+ green = 0xff;
+ blue = 0xff * (100 - shade ) /100;
+ break;
+ case 7: //white
+ default:
+ red = 0xff;
+ green = 0xff;
+ blue = 0xff;
+ break;
+ }
+ return rgb2str(red, green, blue);
+}
+
+
+OUString rgb2str(unsigned char red, unsigned char green, unsigned char blue)
+{
+ char buf[8];
+ int n = std::max(sprintf(buf, "#%02x%02x%02x", red, green, blue), 0);
+ return OUString::createFromAscii(std::string_view(buf, n));
+}
+
+
+OUString rgb2str(int32_t rgb) { return rgb2str(rgb & 0xff, (rgb >> 8) & 0xff, (rgb >> 16) & 0xff); }
+
+
+::std::string urltounix(const char *src)
+{
+ ::std::string ret;
+ std::size_t i = 0;
+ if( src[0] == 'C' && src[1] == ':' && src[2] == '\\' ) // Home Dir
+ {
+ ret.append("file://");
+ const char *pHome = getenv("HOME");
+ if (pHome)
+ {
+ ret.append(pHome);
+ ret.push_back('/');
+ }
+ i = 3; // skip first 3
+ }
+ else if( src[0] == 'D' && src[1] == ':' && src[2] == '\\' ) // Root Dir
+ {
+ ret.append("file:///");
+ i = 3; // skip first 3
+ }
+ else if( !strncmp(src,"http",4) ) // Start from "http"
+ {
+ // nothing special here, just copy
+ }
+ else
+ {
+ unsigned int srclen = strlen(src);
+ if (3 < srclen)
+ {
+ char const*const ext = src + (srclen-3);
+#ifdef _WIN32
+ if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+#else
+ if (strcasecmp(ext,"HWP") && strcasecmp(ext,"HWT"))
+#endif
+ {
+ ret.append("http://");
+ }
+ }
+ }
+ for (; i < strlen(src); i++)
+ {
+ if (src[i] == '\\') {
+ ret.push_back('/');
+ } else {
+ ret.push_back(src[i]);
+ }
+ }
+ return ret;
+}
+
+#ifdef _WIN32
+::std::string urltowin(const char *src)
+{
+ std::string ret;
+ if( !_strnicmp(src, "http", 4))
+ {
+ // nothing special here, just copy
+ }
+ else
+ {
+ unsigned int srclen = strlen(src);
+ if (3 < srclen)
+ {
+ char const*const ext = src + (srclen-3);
+ if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+ {
+ ret.append("http://");
+ }
+ else
+ {
+ ret.append(src); // no backslash conversion
+ return ret;
+ }
+ }
+ }
+ for (size_t i = 0; i < strlen(src); i++)
+ {
+ if (src[i] == '\\') {
+ ret.push_back('/');
+ } else {
+ ret.push_back(src[i]);
+ }
+ }
+ return ret;
+}
+#endif
+
+OUString base64_encode_string( const uchar *buf, unsigned int len )
+{
+ OStringBuffer aBuf;
+ comphelper::Base64::encode(aBuf, comphelper::arrayToSequence<sal_Int8>(buf, len));
+ return OUString::createFromAscii(aBuf);
+}
+
+double calcAngle(double x1, double y1, double x2, double y2)
+{
+ y1 = -y1;
+ y2 = -y2;
+ if( x2 == x1 ){
+ if( y2 >= y1 )
+ return 0.;
+ else
+ return 270.;
+ }
+ // atan2 handles all 4 quadrants
+ return basegfx::rad2deg(atan2(y2 - y1 , x2 - x1));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h
new file mode 100644
index 000000000..53c1513e2
--- /dev/null
+++ b/hwpfilter/source/hcode.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <rtl/ustring.hxx>
+
+#include "hwplib.h"
+
+/**
+ * Codetype of Korean
+ * KSSM - Johap, KS - Wansung
+ */
+enum { KSSM, KS, UNICODE };
+/**
+ * Transfer combination-code for internal using of hwp to ascii
+ */
+DLLEXPORT int hcharconv(hchar ch, hchar *dest, int codeType) ;
+
+DLLEXPORT int kssm_hangul_to_ucs2(hchar ch, hchar *dest) ;
+DLLEXPORT hchar ksc5601_han_to_ucs2 (hchar);
+DLLEXPORT hchar ksc5601_sym_to_ucs2 (hchar);
+DLLEXPORT OUString hstr2OUString(hchar const* hstr);
+/**
+ * 한컴스트링을 완성형스트링으로 변환한다.
+ */
+DLLEXPORT ::std::string hstr2ksstr(hchar const* hstr);
+
+/**
+ * 한글을 포함할 수 있는 char형스트링을 한컴스트링으로 변환한다.
+ */
+DLLEXPORT hchar_string kstr2hstr(uchar const* src);
+
+/**
+ * hwp의 경로를 unix형태로 바꾼다.
+ */
+DLLEXPORT ::std::string urltounix(const char *src);
+
+/**
+ * hwp의 경로를 windows형태로 바꾼다.
+ */
+#ifdef _WIN32
+DLLEXPORT ::std::string urltowin(const char *src);
+#endif
+
+/**
+ * color인덱스 값과 음영값을 조합하여 스타오피스의 color로 변환
+ */
+DLLEXPORT OUString hcolor2str(uchar color, uchar shade, bool bIsChar = false);
+DLLEXPORT OUString rgb2str(unsigned char red, unsigned char green, unsigned char blue);
+DLLEXPORT OUString rgb2str(int32_t rgb);
+
+DLLEXPORT OUString base64_encode_string( const uchar *buf, unsigned int len );
+DLLEXPORT double calcAngle(double x1, double y1, double x2, double y2);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hfont.cxx b/hwpfilter/source/hfont.cxx
new file mode 100644
index 000000000..cdb77ec77
--- /dev/null
+++ b/hwpfilter/source/hfont.cxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hfont.h"
+/* 이 함수는 HWP 파일을 해석하는 부분이다. */
+
+HWPFont::HWPFont()
+{
+ for (int ii = 0; ii < NLanguage; ii++)
+ {
+ nFonts[ii] = 0;
+ fontnames[ii] = nullptr;
+ }
+}
+
+HWPFont::~HWPFont() {}
+
+void HWPFont::AddFont(int lang, const char* font)
+{
+ int nfonts;
+
+ if (lang < 0 || lang >= NLanguage)
+ return;
+ nfonts = nFonts[lang];
+ if (MAXFONTS <= nfonts)
+ return;
+ auto const p = fontnames[lang].get() + FONTNAMELEN * nfonts;
+ strncpy(p, font, FONTNAMELEN - 1);
+ p[FONTNAMELEN - 1] = '\0'; // just in case, even though the array is zero-initialized
+ nFonts[lang]++;
+}
+
+const char* HWPFont::GetFontName(int lang, int id)
+{
+ if (lang < 0 || lang >= NLanguage)
+ return nullptr;
+ if (id < 0 || nFonts[lang] <= id)
+ return nullptr;
+ return fontnames[lang].get() + id * FONTNAMELEN;
+}
+
+static char buffer[FONTNAMELEN];
+
+void HWPFont::Read(HWPFile& hwpf)
+{
+ int lang = 0;
+ short nfonts = 0;
+
+ //printf("HWPFont::Read : lang = %d\n",NLanguage);
+ for (lang = 0; lang < NLanguage; lang++)
+ {
+ hwpf.Read2b(&nfonts, 1);
+ if (nfonts <= 0 || nfonts >= MAXFONTS)
+ {
+ (void)hwpf.SetState(HWP_InvalidFileFormat);
+ return;
+ }
+ fontnames[lang].reset(new char[nfonts * FONTNAMELEN]);
+
+ memset(fontnames[lang].get(), 0, nfonts * FONTNAMELEN);
+ for (int jj = 0; jj < nfonts; jj++)
+ {
+ hwpf.ReadBlock(buffer, FONTNAMELEN);
+ AddFont(lang, buffer);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hfont.h b/hwpfilter/source/hfont.h
new file mode 100644
index 000000000..c9d2e9930
--- /dev/null
+++ b/hwpfilter/source/hfont.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HFONT_H
+#define INCLUDED_HWPFILTER_SOURCE_HFONT_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <memory>
+
+#define MAXFONTS 256
+#define FONTNAMELEN 40
+
+class HWPFile;
+
+/**
+ * The HWPFont class has the font list for the document when it's saved.
+ * @short Font information
+ */
+class DLLEXPORT HWPFont final
+{
+/**
+ * System font count for each language
+ * NLanguage is 7 in common case.
+ */
+ int nFonts[NLanguage];
+/**
+ * list of the font family name
+ */
+ std::unique_ptr<char[]> fontnames[NLanguage];
+
+ public:
+ HWPFont(void);
+ ~HWPFont(void);
+
+/**
+ * Adds a font into font list of a language
+ * @param lang Language index
+ * @param font Name of font family
+ */
+ void AddFont( int lang, const char *font );
+/**
+ * @param lang Language index
+ * @param id Index of font
+ * @returns Font name
+ */
+ const char *GetFontName( int lang, int id );
+
+ void Read( HWPFile &hwpf );
+};
+#endif /* _HWPFONTS+H_ */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hgzip.cxx b/hwpfilter/source/hgzip.cxx
new file mode 100644
index 000000000..ed8ef8a75
--- /dev/null
+++ b/hwpfilter/source/hgzip.cxx
@@ -0,0 +1,298 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "hgzip.h"
+#include "hstream.hxx"
+
+#define Z_BUFSIZE (1024 * 4)
+
+#define ALLOC(size) malloc(size)
+#define TRYFREE(p) {if (p) free(p);}
+
+static int get_byte(gz_stream * s);
+static int destroy(gz_stream * s);
+static uLong getLong(gz_stream * s);
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb"). The file is given either by file descriptor
+ or path name (if fd == -1).
+ gz_open return NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR).
+*/
+gz_stream *gz_open(HStream & _stream)
+{
+ int err;
+ //int level = Z_DEFAULT_COMPRESSION; /* compression level */
+
+// char *p = (char*)mode;
+ //char fmode[80]; /* copy of mode, without the compression level */
+ //char *m = fmode;
+ gz_stream *s;
+
+ s = static_cast<gz_stream *>(ALLOC(sizeof(gz_stream)));
+ if (!s)
+ return Z_NULL;
+ s->stream.zalloc = nullptr;
+ s->stream.zfree = nullptr;
+ s->stream.opaque = nullptr;
+ s->stream.next_in = s->inbuf = Z_NULL;
+ s->stream.next_out = Z_NULL;
+ s->stream.avail_in = s->stream.avail_out = 0;
+//s->_inputstream = NULL;
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->crc = crc32(0, Z_NULL, 0);
+ s->msg = nullptr;
+
+ s->mode = 'r';
+
+//realking
+ err = inflateInit2(&(s->stream), -MAX_WBITS);
+ s->stream.next_in = s->inbuf = static_cast<Byte *>(ALLOC(Z_BUFSIZE));
+
+ if (err != Z_OK || s->inbuf == Z_NULL)
+ {
+ destroy(s);
+ return Z_NULL;
+ }
+
+ s->stream.avail_out = Z_BUFSIZE;
+
+ errno = 0;
+ s->_inputstream = &_stream;
+
+ return s;
+}
+
+
+/* ===========================================================================
+ Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+ for end of file.
+ IN assertion: the stream s has been successfully opened for reading.
+*/
+static int get_byte(gz_stream * s)
+{
+ if (s->z_eof)
+ return EOF;
+ if (s->stream.avail_in == 0)
+ {
+ errno = 0;
+
+ s->stream.avail_in = s->_inputstream->readBytes(s->inbuf, Z_BUFSIZE);
+ if (s->stream.avail_in == 0)
+ {
+ s->z_eof = 1;
+ return EOF;
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->stream.avail_in--;
+ return *(s->stream.next_in)++;
+}
+
+
+/* ===========================================================================
+ * Cleanup then free the given gz_stream. Return a zlib error code.
+ * Try freeing in the reverse order of allocations.
+ */
+static int destroy(gz_stream * s)
+{
+ int err = Z_OK;
+
+ if (!s)
+ return Z_STREAM_ERROR;
+
+ TRYFREE(s->msg);
+
+ if (s->stream.state != nullptr)
+ {
+ err = inflateEnd(&(s->stream));
+ }
+ if (s->z_err < 0)
+ err = s->z_err;
+
+ TRYFREE(s->inbuf);
+ TRYFREE(s);
+ return err;
+}
+
+
+// typedef unsigned char Byte
+// typedef Byte Bytef;
+/* ===========================================================================
+ Reads the given number of uncompressed bytes from the compressed file.
+ gz_read returns the number of bytes actually read (0 for end of file).
+*/
+size_t gz_read(gz_stream * file, voidp buf, unsigned len)
+{
+//printf("@@ gz_read : len : %d\t",len);
+ gz_stream *s = file;
+ Bytef *start = static_cast<Bytef *>(buf); /* starting point for crc computation */
+ if (s == nullptr)
+ return 0;
+
+ if (s->z_eof)
+ return 0;
+
+ if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)
+ return 0;
+ if (s->z_err == Z_STREAM_END)
+ return 0; /* EOF */
+
+ s->stream.next_out = static_cast<Bytef *>(buf);
+ s->stream.avail_out = len;
+
+ while (s->stream.avail_out != 0)
+ {
+ if (s->stream.avail_in == 0 && !s->z_eof)
+ {
+
+ errno = 0;
+ s->stream.avail_in = s->_inputstream->readBytes(s->inbuf, Z_BUFSIZE);
+ if (s->stream.avail_in == 0)
+ {
+ s->z_eof = 1;
+ break;
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
+
+ if (s->z_err == Z_STREAM_END)
+ {
+/* Check CRC and original size */
+ s->crc = crc32(s->crc, start, static_cast<uInt>(s->stream.next_out - start));
+ start = s->stream.next_out;
+
+ if (getLong(s) != s->crc || getLong(s) != s->stream.total_out)
+ {
+ s->z_err = Z_DATA_ERROR;
+ }
+ else if (s->z_err == Z_OK)
+ {
+ inflateReset(&(s->stream));
+ s->crc = crc32(0, Z_NULL, 0);
+ }
+ }
+ if (s->z_err != Z_OK || s->z_eof)
+ break;
+ }
+ s->crc = crc32(s->crc, start, static_cast<uInt>(s->stream.next_out - start));
+ return len - s->stream.avail_out;
+}
+
+/* ===========================================================================
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function.
+ gz_flush should be called only when strictly necessary because it can
+ degrade compression.
+*/
+int gz_flush(gz_stream * file, int flush)
+{
+ uInt len;
+ bool done = false;
+ gz_stream *s = file;
+
+ if (s == nullptr || s->mode != 'w')
+ return Z_STREAM_ERROR;
+
+ s->stream.avail_in = 0; /* should be zero already anyway */
+
+ for (;;)
+ {
+ len = Z_BUFSIZE - s->stream.avail_out;
+ if (len != 0)
+ {
+/*
+ if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
+ s->z_err = Z_ERRNO;
+ return Z_ERRNO;
+ }
+ */
+ s->stream.next_out = nullptr;
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ if (done)
+ break;
+ s->z_err = deflate(&(s->stream), flush);
+
+/* deflate has finished flushing only when it hasn't used up
+ * all the available space in the output buffer:
+ */
+ done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
+
+ if (s->z_err != Z_OK && s->z_err != Z_STREAM_END)
+ break;
+ }
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+
+
+/* ===========================================================================
+ Reads a long in LSB order from the given gz_stream. Sets
+*/
+static uLong getLong(gz_stream * s)
+{
+ uLong x = static_cast<unsigned char>(get_byte(s));
+
+ x += static_cast<unsigned char>(get_byte(s)) << 8;
+ x += static_cast<unsigned char>(get_byte(s)) << 16;
+ x += static_cast<unsigned char>(get_byte(s)) << 24;
+ if (s->z_eof)
+ {
+ s->z_err = Z_DATA_ERROR;
+ }
+ return x;
+}
+
+
+/* ===========================================================================
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state.
+*/
+int gz_close(gz_stream * file)
+{
+// int err;
+ gz_stream *s = file;
+
+ if (s == nullptr)
+ return Z_STREAM_ERROR;
+#if 0
+ if (s->mode == 'w')
+ {
+ err = gz_flush(file, Z_FINISH);
+ if (err != Z_OK)
+ return destroy(s);
+ putLong(s->file, s->crc);
+ putLong(s->file, s->stream.total_in);
+ }
+#endif
+ return destroy(s);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hgzip.h b/hwpfilter/source/hgzip.h
new file mode 100644
index 000000000..40260a99d
--- /dev/null
+++ b/hwpfilter/source/hgzip.h
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HGZIP_H
+#define INCLUDED_HWPFILTER_SOURCE_HGZIP_H
+
+#include <zlib.h>
+
+class HStream;
+/**
+ * @short Structure for using z_stream
+ */
+struct gz_stream
+{
+ z_stream stream;
+/**
+ * The error code of z_stream operation
+ */
+ int z_err;
+/**
+ * EOF of the input file
+ */
+ int z_eof;
+/**
+ * Stream
+ */
+ HStream* _inputstream;
+/**
+ * Input buffer
+ */
+ Byte *inbuf;
+/**
+ * Crc32 of uncompressed data
+ */
+ uLong crc;
+/**
+ * Stream
+ */
+ char *msg;
+/**
+ * 'w' or 'r'
+ */
+ char mode;
+};
+
+/**
+ * Opens a gzipped stream for reading.
+ * gz_open returns NULL if the stream could not be opened or if there was
+ * insufficient memory to allocate the (de)compression state; errno
+ * can be checked to distinguish the two cases (if errno is zero, the
+ * zlib error is Z_MEM_ERROR).
+ * @param _stream Reference of stream object having binary data.
+ */
+gz_stream *gz_open ( HStream& _stream );
+/**
+ * Flushes all pending output if necessary, closes the compressed stream
+ * and deallocates all the (de)compression state
+ */
+int gz_close ( gz_stream *file );
+/**
+ * Reads the given number of uncompressed bytes from the compressed stream
+ * @param file Gzipped stream
+ * @param buf Buffer to have the data to be read
+ * @param len Length of data to be read
+ * @returns The number of bytes actually read
+ */
+size_t gz_read ( gz_stream *file, voidp buf, unsigned len );
+/**
+ * Flushes all pending output into the compressed file
+ * gz_flush should be called only when strictly necessary because it can
+ * degrade compression
+ * @param flush Is as in the deflate() function
+ */
+int gz_flush ( gz_stream *file, int flush );
+#endif // INCLUDED_HWPFILTER_SOURCE_HGZIP_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hinfo.cxx b/hwpfilter/source/hinfo.cxx
new file mode 100644
index 000000000..505936b92
--- /dev/null
+++ b/hwpfilter/source/hinfo.cxx
@@ -0,0 +1,288 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include "hwplib.h"
+#include "hinfo.h"
+#include "hwpfile.h"
+
+// Info Block
+
+
+static bool HWPReadInfoBlock(void *ptr, int len, HWPFile & hwpf)
+{
+ hwpf.info_block_len = len;
+ if (0 == len)
+ return true;
+ else
+ return hwpf.ReadBlock(ptr, len) != 0;
+}
+
+
+// Document Information
+HWPInfo::HWPInfo()
+ : cur_col(0)
+ , cur_row(0)
+ , readonly(0)
+ , encrypted(0)
+ , beginpagenum(0)
+ , beginfnnum(0)
+ , countfn(0)
+ , splinetext(0)
+ , splinefn(0)
+ , spfnfn(0)
+ , fnchar(0)
+ , fnlinetype(0)
+ , borderline(0)
+ , empty_line_hide(0)
+ , table_move(0)
+ , compressed(0)
+ , reserved3(0)
+ , info_block_len(0)
+{
+ back_info.isset = false;
+}
+
+HWPInfo::~HWPInfo()
+{
+}
+
+
+/**
+ * Function for reading document information (128 bytes)
+ * Document information is the information after the file identification information (30 bytes).
+ */
+void HWPInfo::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&cur_col, 1); /* When a document is saving, the paragraph number where the coursor is */
+ hwpf.Read2b(&cur_row, 1); /* Paragraphs rows */
+
+ hwpf.Read1b(paper.paper_kind); /* Paper Type */
+ hwpf.Read1b(paper.paper_direction); /* Paper orientation */
+
+// paper geometry information
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.paper_height = tmp16; /* Paper length */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.paper_width = tmp16; /* Sheet width */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.top_margin = tmp16; /* Top margin */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.bottom_margin = tmp16; /* The bottom margin */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.left_margin = tmp16; /* Left Margin */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.right_margin = tmp16; /* Right margins */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.header_length = tmp16; /* Header length */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.footer_length = tmp16; /* Footer length */
+ if (!hwpf.Read2b(tmp16))
+ return;
+ paper.gutter_length = tmp16; /* The binding margin */
+ hwpf.Read2b(&readonly, 1); /* Reserve */
+ hwpf.ReadBlock(reserved1, 4); /* Reserve */
+ hwpf.Read1b(chain_info.chain_page_no); /* Connect page number: 1-Connect, 0-newly started (used in connection printing) */
+ hwpf.Read1b(chain_info.chain_footnote_no); /* Connect footnote number: 1-connect, 0-newly started*/
+ /* the file name to be printed with connection */
+ hwpf.ReadBlock(chain_info.chain_filename, CHAIN_MAX_PATH);
+
+ hwpf.ReadBlock(annotation, ANNOTATION_LEN); /* Annotation (additional information when a file is saving.) */
+ hwpf.Read2b(&encrypted, 1); /* encrypt: 0-normal file(without password), 1-protected by password */
+ hwpf.Read2b(&beginpagenum,1); /* Page starting number */
+
+// footnote
+ hwpf.Read2b(&beginfnnum,1); /* Footnote start number */
+ hwpf.Read2b(&countfn,1); /* Number of footnote */
+
+ if (!hwpf.Read2b(tmp16))
+ return;
+ splinetext = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ splinefn = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ spfnfn = tmp16;
+ hwpf.Read1b(fnchar);
+ hwpf.Read1b(fnlinetype);
+// border layout
+ for (int & ii : bordermargin)
+ {
+ if (!hwpf.Read2b(tmp16))
+ return;
+ ii = tmp16;
+ }
+ hwpf.Read2b(&borderline, 1);
+
+ hwpf.Read1b(empty_line_hide);
+ hwpf.Read1b(table_move);
+ hwpf.Read1b(compressed);
+
+ hwpf.Read1b(reserved3);
+
+ hwpf.Read2b(&info_block_len, 1);
+ if (hwpf.State())
+ return;
+
+/* Read the article summary. */
+ if (!summary.Read(hwpf))
+ return;
+ if (info_block_len > 0)
+ {
+ info_block.reset( new unsigned char[info_block_len + 1] );
+
+ if (!HWPReadInfoBlock(info_block.get(), info_block_len, hwpf))
+ return;
+ }
+
+/* reset the value of hwpf. */
+ hwpf.compressed = compressed != 0;
+ hwpf.encrypted = encrypted != 0;
+ hwpf.info_block_len = info_block_len;
+ hwpf.SetCompressed(hwpf.compressed);
+}
+
+
+// Document Summary
+
+bool HWPSummary::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(title, 56);
+ hwpf.Read2b(subject, 56);
+ hwpf.Read2b(author, 56);
+ hwpf.Read2b(date, 56);
+ hwpf.Read2b(keyword[0], 56);
+ hwpf.Read2b(keyword[1], 56);
+ hwpf.Read2b(etc[0], 56);
+ hwpf.Read2b(etc[1], 56);
+ hwpf.Read2b(etc[2], 56);
+
+ return (!hwpf.State());
+}
+
+ParaShape::ParaShape()
+ : index(0)
+ , left_margin(0)
+ , right_margin(0)
+ , indent(0)
+ , lspacing(0)
+ , pspacing_prev(0)
+ , pspacing_next(0)
+ , condense(0)
+ , arrange_type(0)
+ , xColdef(std::make_shared<ColumnDef>())
+ , shade(0)
+ , outline(0)
+ , outline_continue(0)
+ , pagebreak(0)
+{
+ reserved[0] = 0;
+ reserved[1] = 0;
+}
+
+void ParaShape::Read(HWPFile & hwpf)
+{
+ pagebreak = 0;
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ left_margin = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ right_margin = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ indent = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ lspacing = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ pspacing_next = tmp16;
+
+ hwpf.Read1b(condense);
+ hwpf.Read1b(arrange_type);
+ for (TabSet & tab : tabs)
+ {
+ hwpf.Read1b(tab.type);
+ hwpf.Read1b(tab.dot_continue);
+ if (!hwpf.Read2b(tmp16))
+ return;
+ tab.position = tmp16;
+ }
+ hwpf.Read1b(xColdef->ncols);
+ hwpf.Read1b(xColdef->separator);
+ if (!hwpf.Read2b(tmp16))
+ return;
+ xColdef->spacing = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ xColdef->columnlen = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ xColdef->columnlen0 = tmp16;
+ hwpf.Read1b(shade);
+ hwpf.Read1b(outline);
+ hwpf.Read1b(outline_continue);
+ if (!hwpf.Read2b(tmp16))
+ return;
+ pspacing_prev = tmp16;
+
+ hwpf.ReadBlock(reserved, 2);
+}
+
+CharShape::CharShape()
+ : index(0)
+ , size(0)
+ , font{0}
+ , ratio{0}
+ , space{0}
+ , color{0}
+ , shade(0)
+ , attr(0)
+{
+}
+
+void CharShape::Read(HWPFile & hwpf)
+{
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ size = tmp16;
+ hwpf.ReadBlock(font, NLanguage);
+ hwpf.ReadBlock(ratio, NLanguage);
+ hwpf.ReadBlock(space, NLanguage);
+ hwpf.ReadBlock(color, 2);
+ hwpf.Read1b(shade);
+ hwpf.Read1b(attr);
+ hwpf.SkipBlock(4);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hinfo.h b/hwpfilter/source/hinfo.h
new file mode 100644
index 000000000..003dafc0d
--- /dev/null
+++ b/hwpfilter/source/hinfo.h
@@ -0,0 +1,304 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HINFO_H
+#define INCLUDED_HWPFILTER_SOURCE_HINFO_H
+
+#include "hwplib.h"
+#include <string.h>
+
+#include <vector>
+#include <memory>
+
+#define CHAIN_MAX_PATH 40
+#define ANNOTATION_LEN 24
+
+class HWPFile;
+class CTextOut;
+class CHTMLOut;
+
+/**
+ * Information of page (physical)
+ */
+struct PaperInfo
+{
+ unsigned char paper_kind;
+ unsigned char paper_direction;
+ hunit paper_height;
+ hunit paper_width;
+ hunit top_margin;
+ hunit bottom_margin;
+ hunit left_margin;
+ hunit right_margin;
+ hunit header_length;
+ hunit footer_length;
+ hunit gutter_length;
+ PaperInfo()
+ : paper_kind(0)
+ , paper_direction(0)
+ , paper_height(0)
+ , paper_width(0)
+ , top_margin(0)
+ , bottom_margin(0)
+ , left_margin(0)
+ , right_margin(0)
+ , header_length(0)
+ , footer_length(0)
+ , gutter_length(0)
+ {
+ }
+};
+
+/* 페이지 배경색, 배경그림 정보 */
+struct PaperBackInfo
+{
+ char type; // 0- background color, 1 - external image, 2- embedded image
+ char reserved1[8] = {};
+ int luminance; /* 밝기 ( -100 ~ 100 ) */
+ int contrast; /* 명암 ( -100 ~ 100 ) */
+ char effect; /* 0-원래그림, 1-그레이스케일, 2-흑백 */
+ char reserved2[8] = {};
+ char filename[260 + 1] = {}; // filename
+ unsigned char color[3] = {}; //0 - red, 1 - green, 2 - blue
+ unsigned short flag; /* 0 - 바둑판식, 1 - 가운데로, 2 - 쪽크기, 3 - 용지크기 */
+ int range; /* 0-전체, 1-첫페이지, 3-짝수쪽, 4-홀수쪽 */
+ char reserved3[27] = {};
+ int size;
+ std::vector<char> data; // image data
+ bool isset;
+ PaperBackInfo()
+ : type(0)
+ , luminance(0)
+ , contrast(0)
+ , effect(0)
+ , flag(0)
+ , range(0)
+ , size(0)
+ , isset(false)
+ {
+ }
+};
+
+/* 연결인쇄 정보 */
+/**
+ * Information of printing for chained page
+ */
+struct DocChainInfo
+{
+ unsigned char chain_page_no;
+ unsigned char chain_footnote_no;
+ unsigned char chain_filename[CHAIN_MAX_PATH] = {};
+ DocChainInfo()
+ : chain_page_no(0)
+ , chain_footnote_no(0)
+ {
+ }
+};
+
+/* 문서 요약 */
+/**
+ * Summary of document
+ */
+struct HWPSummary
+{
+ unsigned short title[56];
+ unsigned short subject[56];
+ unsigned short author[56];
+ unsigned short date[56];
+ unsigned short keyword[2][56];
+ unsigned short etc[3][56];
+
+ bool Read(HWPFile &);
+};
+
+/**
+ HWPInfo class는 HWPFile에 대한 정보를 담고 있는 클래스이다.
+ 종이나 여백 등의 레이아웃(layout) 정보는 쪽매기기에서
+ 사용하며, 기타 내부 정보를 포함하고 있다. \\
+
+ HWPInfo 클래스는 HWPFile의 #GetHWPInfo()# 함수를 통해 얻을 수 있다.
+
+ @memo Hwp 문서 정보
+*/
+/**
+ * Contains the basic information of the hwp document:
+ * margin, layout, paper and internal data.
+ */
+class DLLEXPORT HWPInfo
+{
+ public:
+/**
+ * The column index of a document that is saved at last
+ */
+ short cur_col;
+/**
+ * The row index of a document that is saved at last
+ */
+ short cur_row;
+/**
+ * Paper Information
+ */
+ PaperInfo paper;
+
+ PaperBackInfo back_info;
+/**
+ * Sets the attribute of read-only or read/write.
+ */
+ short readonly;
+ unsigned char reserved1[4] = {};
+/**
+ * Information about document chain
+ */
+ DocChainInfo chain_info;
+ unsigned char annotation[ANNOTATION_LEN] = {};
+ short encrypted;
+// unsigned char reserved2[6];
+ short beginpagenum; /* 시작페이지 번호 */
+/**
+ * Information about footnote
+ */
+ short beginfnnum; /* 각주시작번호 */
+ short countfn; /* 각주 갯수 */
+ hunit splinetext, splinefn;
+ hunit spfnfn;
+ unsigned char fnchar;
+ unsigned char fnlinetype;
+// layout info
+/**
+ * Information about page layout
+ */
+ hunit bordermargin[4] = {};
+ short borderline;
+
+ unsigned char empty_line_hide;
+ unsigned char table_move;
+ unsigned char compressed;
+ unsigned char reserved3;
+ short info_block_len;
+/* 여기까지가 128 바이트이다 */
+/**
+ * Summary of document
+ */
+ HWPSummary summary;
+ std::unique_ptr<unsigned char[]> info_block;
+
+ HWPInfo(void);
+ ~HWPInfo(void);
+
+ void Read(HWPFile &hwpf);
+
+};
+
+/* 글자 모양 구조체 */
+/**
+ * @short Style of character
+ */
+struct CharShape
+{
+/**
+ * Index of character style
+ */
+ int index; /* 스타일의 인덱스를 저장. */
+/**
+ * Font size
+ */
+ hunit size;
+ unsigned char font[NLanguage];
+ unsigned char ratio[NLanguage];
+ signed char space[NLanguage]; /* 자간 */
+ unsigned char color[2];
+ unsigned char shade;
+ unsigned char attr;
+
+ void Read(HWPFile &);
+
+ CharShape();
+};
+
+/* 탭 설정에 대한 구조체 */
+
+#define MAXTABS 40
+/**
+ * @short Tab properties
+ */
+struct TabSet
+{
+ unsigned char type;
+ unsigned char dot_continue;
+ hunit position;
+ TabSet()
+ : type(0)
+ , dot_continue(0)
+ , position(0)
+ {
+ }
+};
+
+/**
+ * @short Column properties
+ */
+struct ColumnDef
+{
+ unsigned char ncols;
+ unsigned char separator;
+ hunit spacing;
+ hunit columnlen, columnlen0;
+ ColumnDef()
+ : ncols(0)
+ , separator(0)
+ , spacing(0)
+ , columnlen(0)
+ , columnlen0(0)
+ {
+ }
+};
+
+/**
+ * @short Style of paragraph
+ */
+struct ParaShape
+{
+/**
+ * Index of paragraph style
+ */
+ int index; /* 스타일의 인덱스를 저장 */
+ hunit left_margin;
+ hunit right_margin;
+ hunit indent;
+ hunit lspacing;
+ hunit pspacing_prev;
+ hunit pspacing_next;
+ unsigned char condense;
+ unsigned char arrange_type;
+ TabSet tabs[MAXTABS];
+ std::shared_ptr<ColumnDef> xColdef;
+ unsigned char shade;
+ unsigned char outline;
+ unsigned char outline_continue;
+ unsigned char reserved[2];
+ std::shared_ptr<CharShape> cshape;
+ unsigned char pagebreak;
+
+ void Read(HWPFile &);
+
+ ParaShape();
+};
+#endif // INCLUDED_HWPFILTER_SOURCE_HINFO_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx
new file mode 100644
index 000000000..643700414
--- /dev/null
+++ b/hwpfilter/source/hiodev.cxx
@@ -0,0 +1,355 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef _WIN32
+# include <io.h>
+#else
+# include <unistd.h>
+#endif
+
+
+#include "hwplib.h"
+#include "hgzip.h"
+#include "hiodev.h"
+#include "hwpfile.h"
+#include "hstream.hxx"
+
+const size_t BUFSIZE = 1024;
+static uchar rBuf[BUFSIZE];
+
+// HIODev abstract class
+HIODev::HIODev()
+{
+ init();
+}
+
+
+HIODev::~HIODev()
+{
+}
+
+
+void HIODev::init()
+{
+ compressed = false;
+}
+
+size_t HIODev::read2b(void *ptr, size_t nmemb)
+{
+ ushort *p = static_cast<ushort *>(ptr);
+
+ if (state())
+ return 0;
+ size_t ii;
+ for (ii = 0; ii < nmemb; ++ii)
+ {
+ if (!read2b(p[ii]))
+ break;
+ if (state())
+ break;
+ }
+ return ii;
+}
+
+size_t HIODev::read4b(void *ptr, size_t nmemb)
+{
+ uint *p = static_cast<uint *>(ptr);
+
+ if (state())
+ return 0;
+ size_t ii;
+ for (ii = 0; ii < nmemb; ++ii)
+ {
+ if (!read4b(p[ii]))
+ break;
+ if (state())
+ break;
+ }
+ return ii;
+}
+
+
+// hfileiodev class
+HStreamIODev::HStreamIODev(std::unique_ptr<HStream> stream):_stream(std::move(stream))
+{
+ init();
+}
+
+
+HStreamIODev::~HStreamIODev()
+{
+/* 플러시한 후 닫는다. */
+ flush();
+ if (_gzfp)
+ gz_close(_gzfp);
+ _gzfp = nullptr;
+}
+
+
+void HStreamIODev::init()
+{
+ _gzfp = nullptr;
+ compressed = false;
+}
+
+
+bool HStreamIODev::open()
+{
+ return _stream->available() != 0;
+}
+
+
+void HStreamIODev::flush()
+{
+ if (_gzfp)
+ gz_flush(_gzfp, Z_FINISH);
+}
+
+bool HStreamIODev::state() const
+{
+ return false;
+}
+
+/* zlib 관련 부분 */
+bool HStreamIODev::setCompressed(bool flag)
+{
+ compressed = flag;
+ if (flag)
+ {
+ _gzfp = gz_open(*_stream);
+ return nullptr != _gzfp;
+ }
+ else if (_gzfp)
+ {
+ gz_flush(_gzfp, Z_FINISH);
+ gz_close(_gzfp);
+ _gzfp = nullptr;
+ }
+ return true;
+}
+
+
+// IO routines
+
+#define GZREAD(ptr,len) (_gzfp?gz_read(_gzfp,ptr,len):0)
+
+bool HStreamIODev::read1b(unsigned char &out)
+{
+ size_t res = compressed ? GZREAD(rBuf, 1) : _stream->readBytes(rBuf, 1);
+
+ if (res < 1)
+ return false;
+
+ out = static_cast<unsigned char>(rBuf[0]);
+ return true;
+}
+
+bool HStreamIODev::read1b(char &out)
+{
+ unsigned char tmp8;
+ if (!read1b(tmp8))
+ return false;
+ out = tmp8;
+ return true;
+}
+
+bool HStreamIODev::read2b(unsigned short &out)
+{
+ size_t res = compressed ? GZREAD(rBuf, 2) : _stream->readBytes(rBuf, 2);
+
+ if (res < 2)
+ return false;
+
+ out = (static_cast<unsigned char>(rBuf[1]) << 8 | static_cast<unsigned char>(rBuf[0]));
+ return true;
+}
+
+bool HStreamIODev::read4b(unsigned int &out)
+{
+ size_t res = compressed ? GZREAD(rBuf, 4) : _stream->readBytes(rBuf, 4);
+
+ if (res < 4)
+ return false;
+
+ out = (static_cast<unsigned char>(rBuf[3]) << 24 | static_cast<unsigned char>(rBuf[2]) << 16 |
+ static_cast<unsigned char>(rBuf[1]) << 8 | static_cast<unsigned char>(rBuf[0]));
+ return true;
+}
+
+bool HStreamIODev::read4b(int &out)
+{
+ unsigned int tmp32;
+ if (!read4b(tmp32))
+ return false;
+ out = tmp32;
+ return true;
+}
+
+size_t HStreamIODev::readBlock(void *ptr, size_t size)
+{
+ size_t count =
+ compressed
+ ? GZREAD(ptr, size)
+ : _stream->readBytes(static_cast<byte *>(ptr), size);
+
+ return count;
+}
+
+size_t HStreamIODev::skipBlock(size_t size)
+{
+ if (compressed){
+ if( size <= BUFSIZE )
+ return GZREAD(rBuf, size);
+ else{
+ size_t remain = size;
+ while(remain){
+ if( remain > BUFSIZE ) {
+ size_t read = GZREAD(rBuf, BUFSIZE);
+ remain -= read;
+ if (read != BUFSIZE)
+ break;
+ }
+ else{
+ remain -= GZREAD(rBuf, remain);
+ break;
+ }
+ }
+ return size - remain;
+ }
+ }
+ return _stream->skipBytes(size);
+}
+
+
+HMemIODev::HMemIODev(char *s, size_t len)
+{
+ init();
+ ptr = reinterpret_cast<uchar *>(s);
+ length = len;
+}
+
+
+HMemIODev::~HMemIODev()
+{
+}
+
+
+void HMemIODev::init()
+{
+ ptr = nullptr;
+ length = 0;
+ pos = 0;
+}
+
+
+bool HMemIODev::open()
+{
+ return true;
+}
+
+
+void HMemIODev::flush()
+{
+}
+
+bool HMemIODev::state() const
+{
+ return pos > length;
+}
+
+bool HMemIODev::setCompressed(bool )
+{
+ return false;
+}
+
+bool HMemIODev::read1b(unsigned char &out)
+{
+ ++pos;
+ if (!state())
+ {
+ out = ptr[pos - 1];
+ return true;
+ }
+ return false;
+}
+
+bool HMemIODev::read1b(char &out)
+{
+ unsigned char tmp8;
+ if (!read1b(tmp8))
+ return false;
+ out = tmp8;
+ return true;
+}
+
+bool HMemIODev::read2b(unsigned short &out)
+{
+ pos += 2;
+ if (!state())
+ {
+ out = ptr[pos - 1] << 8 | ptr[pos - 2];
+ return true;
+ }
+ return false;
+}
+
+bool HMemIODev::read4b(unsigned int &out)
+{
+ pos += 4;
+ if (!state())
+ {
+ out = static_cast<unsigned int>(ptr[pos - 1] << 24 | ptr[pos - 2] << 16 |
+ ptr[pos - 3] << 8 | ptr[pos - 4]);
+ return true;
+ }
+ return false;
+}
+
+bool HMemIODev::read4b(int &out)
+{
+ unsigned int tmp32;
+ if (!read4b(tmp32))
+ return false;
+ out = tmp32;
+ return true;
+}
+
+size_t HMemIODev::readBlock(void *p, size_t size)
+{
+ if (state())
+ return 0;
+ if (size > length - pos)
+ size = length - pos;
+ memcpy(p, ptr + pos, size);
+ pos += size;
+ return size;
+}
+
+size_t HMemIODev::skipBlock(size_t size)
+{
+ if (state() || size > length - pos)
+ return 0;
+ pos += size;
+ return size;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hiodev.h b/hwpfilter/source/hiodev.h
new file mode 100644
index 000000000..b6f2c7aa2
--- /dev/null
+++ b/hwpfilter/source/hiodev.h
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/**
+ * hwpio.h
+ * (C) 1999 Mizi Research, All rights are reserved
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HIODEV_H
+#define INCLUDED_HWPFILTER_SOURCE_HIODEV_H
+
+#include <sal/config.h>
+
+#include <stdio.h>
+
+#include <memory>
+#include <sal/types.h>
+
+#include "hwplib.h"
+/**
+ * @short Abstract IO class
+ */
+class DLLEXPORT HIODev
+{
+ protected:
+ bool compressed;
+ virtual void init();
+ public:
+ HIODev();
+ virtual ~HIODev();
+
+ virtual bool open() = 0;
+ virtual void flush() = 0;
+ virtual bool state() const = 0;
+/* gzip routine wrapper */
+ virtual bool setCompressed( bool ) = 0;
+
+ virtual bool read1b(unsigned char &out) = 0;
+ virtual bool read1b(char &out) = 0;
+ virtual bool read2b(unsigned short &out) = 0;
+ virtual bool read4b(unsigned int &out) = 0;
+ virtual bool read4b(int &out) = 0;
+ virtual size_t readBlock( void *ptr, size_t size ) = 0;
+ virtual size_t skipBlock( size_t size ) = 0;
+
+ size_t read2b( void *ptr, size_t nmemb );
+ size_t read4b( void *ptr, size_t nmemb );
+};
+
+struct gz_stream;
+
+/* File input and output devices */
+
+/**
+ * This controls the HStream given by constructor
+ * @short Stream IO device
+ */
+class HStreamIODev final: public HIODev
+{
+ private:
+/* zlib으로 압축을 풀기 위한 자료 구조 */
+ std::unique_ptr<HStream> _stream;
+ gz_stream *_gzfp;
+ public:
+ explicit HStreamIODev(std::unique_ptr<HStream> stream);
+ virtual ~HStreamIODev() override;
+/**
+ * Check whether the stream is available
+ */
+ virtual bool open() override;
+/**
+ * If the stream is gzipped, flush the stream.
+ */
+ virtual void flush() override;
+/**
+ * Not implemented.
+ */
+ virtual bool state() const override;
+/**
+ * Set whether the stream is compressed or not
+ */
+ virtual bool setCompressed( bool ) override;
+/**
+ * Read one byte from stream
+ */
+ virtual bool read1b(unsigned char &out) override;
+ virtual bool read1b(char &out) override;
+/**
+ * Read 2 bytes from stream
+ */
+ using HIODev::read2b;
+ virtual bool read2b(unsigned short &out) override;
+/**
+ * Read 4 bytes from stream
+ */
+ using HIODev::read4b;
+ virtual bool read4b(unsigned int &out) override;
+ virtual bool read4b(int &out) override;
+/**
+ * Read some bytes from stream to given pointer as amount of size
+ */
+ virtual size_t readBlock( void *ptr, size_t size ) override;
+/**
+ * Move current pointer of stream as amount of size
+ */
+ virtual size_t skipBlock( size_t size ) override;
+ private:
+/**
+ * Initialize this object
+ */
+ virtual void init() override;
+};
+
+/* Memory, input and output devices */
+/**
+ * The HMemIODev class controls the Input/Output device.
+ * @short Memory IO device
+ */
+class HMemIODev final: public HIODev
+{
+ uchar *ptr;
+ size_t pos, length;
+ public:
+ HMemIODev(char *s, size_t len);
+ virtual ~HMemIODev() override;
+
+ virtual bool open() override;
+ virtual void flush() override;
+ virtual bool state() const override;
+/* gzip routine wrapper */
+ virtual bool setCompressed( bool ) override;
+ virtual bool read1b(unsigned char &out) override;
+ virtual bool read1b(char &out) override;
+ using HIODev::read2b;
+ virtual bool read2b(unsigned short &out) override;
+ using HIODev::read4b;
+ virtual bool read4b(unsigned int &out) override;
+ virtual bool read4b(int &out) override;
+ virtual size_t readBlock( void *ptr, size_t size ) override;
+ virtual size_t skipBlock( size_t size ) override;
+ private:
+ virtual void init() override;
+};
+#endif // INCLUDED_HWPFILTER_SOURCE_HIODEV_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
new file mode 100644
index 000000000..9ac169ab4
--- /dev/null
+++ b/hwpfilter/source/hpara.cxx
@@ -0,0 +1,306 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <memory>
+#include "precompile.h"
+
+
+#include <comphelper/newarray.hxx>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hpara.h"
+#include "hbox.h"
+#include "hutil.h"
+
+void LineInfo::Read(HWPFile & hwpf, HWPPara const *pPara)
+{
+ if (!hwpf.Read2b(pos))
+ return;
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ space_width = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ height = tmp16;
+// internal information
+ if (!hwpf.Read2b(tmp16))
+ return;
+ pgy = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ sx = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ psx = tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return;
+ pex = tmp16;
+ height_sp = 0;
+
+ if( pex >> 15 & 0x01 )
+ {
+ if (pex & 0x01)
+ hwpf.AddPage();
+ pPara->pshape->reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
+ pPara->pshape->reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
+ }
+}
+
+HWPPara::HWPPara()
+ : _next(nullptr)
+ , reuse_shape(0)
+ , nch(0)
+ , nline(0)
+ , begin_ypos(0)
+ , scflag(0)
+ , contain_cshape(0)
+ , etcflag(0)
+ , ctrlflag(0)
+ , pstyno(0)
+ , cshape(std::make_shared<CharShape>())
+ , pshape(std::make_shared<ParaShape>())
+{
+}
+
+HWPPara::~HWPPara()
+{
+}
+
+bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
+{
+ DepthGuard aGuard(hwpf);
+ if (aGuard.toodeep())
+ return false;
+ int ii;
+ scflag = flag;
+// Paragraph Information
+ hwpf.Read1b(reuse_shape);
+ hwpf.Read2b(&nch, 1);
+ hwpf.Read2b(&nline, 1);
+ hwpf.Read1b(contain_cshape);
+ hwpf.Read1b(etcflag);
+ hwpf.Read4b(ctrlflag);
+ hwpf.Read1b(pstyno);
+
+/* Paragraph representative character */
+ cshape->Read(hwpf);
+ if (nch > 0)
+ hwpf.AddCharShape(cshape);
+
+/* Paragraph paragraphs shape */
+ if (nch && !reuse_shape)
+ {
+ pshape->Read(hwpf);
+ pshape->cshape = cshape;
+ pshape->pagebreak = etcflag;
+ }
+
+ linfo.reset(::comphelper::newArray_null<LineInfo>(nline));
+ for (ii = 0; ii < nline; ii++)
+ {
+ linfo[ii].Read(hwpf, this);
+ }
+ if( etcflag & 0x04 ){
+ hwpf.AddColumnInfo();
+ }
+
+ if (nch && !reuse_shape){
+ if( pshape->xColdef->ncols > 1 ) {
+ hwpf.SetColumnDef(pshape->xColdef);
+ }
+ }
+
+ if( nline > 0 )
+ {
+ begin_ypos = linfo[0].pgy;
+ }
+ else
+ {
+ begin_ypos = 0;
+ }
+
+ if (contain_cshape)
+ {
+ cshapep.resize(nch);
+
+ for (ii = 0; ii < nch; ii++)
+ {
+ cshapep[ii] = std::make_shared<CharShape>();
+
+ unsigned char same_cshape(0);
+ hwpf.Read1b(same_cshape);
+ if (!same_cshape)
+ {
+ cshapep[ii]->Read(hwpf);
+ if (nch > 1)
+ hwpf.AddCharShape(cshapep[ii]);
+ }
+ else if (ii == 0)
+ cshapep[ii] = cshape;
+ else
+ cshapep[ii] = cshapep[ii - 1];
+ }
+ }
+// read string
+ ii = 0;
+ while (ii < nch)
+ {
+ auto hBox = readHBox(hwpf);
+ if (!hBox)
+ return false;
+ hhstr[ii] = std::move(hBox);
+ if (hhstr[ii]->hh == CH_END_PARA)
+ break;
+ if( hhstr[ii]->hh < CH_END_PARA )
+ pshape->reserved[0] = 0;
+ ii += hhstr[ii]->WSize();
+ }
+ return nch && !hwpf.State();
+}
+
+CharShape *HWPPara::GetCharShape(int pos)
+{
+ if (contain_cshape == 0)
+ return cshape.get();
+ return cshapep[pos].get();
+}
+
+std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
+{
+ std::unique_ptr<HBox> hbox;
+
+ hchar hh;
+ if (!hwpf.Read2b(hh))
+ return hbox;
+
+ if (hwpf.State() != HWP_NoError)
+ return hbox;
+
+ if (hh > 31 || hh == CH_END_PARA)
+ hbox.reset(new HBox(hh));
+ else if (IS_SP_SKIP_BLOCK(hh))
+ hbox.reset(new SkipData(hh));
+ else
+ {
+ switch (hh)
+ {
+ case CH_FIELD: // 5
+ hbox.reset(new FieldCode);
+ break;
+ case CH_BOOKMARK: // 6
+ hbox.reset(new Bookmark);
+ break;
+ case CH_DATE_FORM: // 7
+ hbox.reset(new DateFormat);
+ break;
+ case CH_DATE_CODE: // 8
+ hbox.reset(new DateCode);
+ break;
+ case CH_TAB: // 9
+ hbox.reset(new Tab);
+ break;
+ case CH_TEXT_BOX: // 10
+ hbox.reset(new TxtBox);
+ break;
+ case CH_PICTURE: // 11
+ hbox.reset(new Picture);
+ break;
+ case CH_LINE: // 14
+ hbox.reset(new Line);
+ break;
+ case CH_HIDDEN: // 15
+ hbox.reset(new Hidden);
+ break;
+ case CH_HEADER_FOOTER: // 16
+ if (!hwpf.already_importing_type(CH_HEADER_FOOTER))
+ hbox.reset(new HeaderFooter);
+ break;
+ case CH_FOOTNOTE: // 17
+ hbox.reset(new Footnote);
+ break;
+ case CH_AUTO_NUM: // 18
+ hbox.reset(new AutoNum);
+ break;
+ case CH_NEW_NUM: // 19
+ hbox.reset(new NewNum);
+ break;
+ case CH_SHOW_PAGE_NUM: // 20
+ hbox.reset(new ShowPageNum);
+ break;
+ case CH_PAGE_NUM_CTRL: // 21
+ hbox.reset(new PageNumCtrl);
+ break;
+ case CH_MAIL_MERGE: // 22
+ hbox.reset(new MailMerge);
+ break;
+ case CH_COMPOSE: // 23
+ hbox.reset(new Compose);
+ break;
+ case CH_HYPHEN: // 24
+ hbox.reset(new Hyphen);
+ break;
+ case CH_TOC_MARK: // 25
+ hbox.reset(new TocMark);
+ break;
+ case CH_INDEX_MARK: // 26
+ hbox.reset(new IndexMark);
+ break;
+ case CH_OUTLINE: // 28
+ hbox.reset(new Outline);
+ break;
+ case CH_KEEP_SPACE: // 30
+ hbox.reset(new KeepSpace);
+ break;
+ case CH_FIXED_SPACE: // 31
+ hbox.reset(new FixedSpace);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!hbox)
+ return nullptr;
+
+ hwpf.push_hpara_type(scflag);
+ bool bRead = hbox->Read(hwpf);
+ hwpf.pop_hpara_type();
+ if (!bRead)
+ {
+ hbox.reset();
+ return nullptr;
+ }
+
+ if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
+ {
+ FBox *fbox = static_cast<FBox *>(hbox.get());
+ if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
+ {
+ //strange construct to compile without warning
+ int nTemp = fbox->pgy;
+ nTemp -= begin_ypos;
+ fbox->pgy = sal::static_int_cast<short>(nTemp);
+ }
+ }
+ return hbox;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hpara.h b/hwpfilter/source/hpara.h
new file mode 100644
index 000000000..58694899e
--- /dev/null
+++ b/hwpfilter/source/hpara.h
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HPARA_H
+#define INCLUDED_HWPFILTER_SOURCE_HPARA_H
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hinfo.h"
+#include <tools/long.hxx>
+#include <map>
+#include <memory>
+#include <vector>
+
+struct HBox;
+
+/**
+ * etc flag
+ * 0 bit : Use page columns
+ * 1 bit : Use page lows
+ * 2 bit : Use section break
+ * 3 bit : Block start
+ * 4 bit : In Block
+ * 5 bit : Block end
+ * 6 bit : Preserve widow orphan
+ * 7 bit : Reserved
+ */
+enum
+{
+ PA_USER_COLUMN = 1,
+ PA_USER_PAGE = 2, /* p user_page definition */
+ PA_SECTION_BREAK = 4,
+ PA_BLOCK_BEGIN = 8,
+ PA_IN_BLOCK = 16,
+ PA_BLOCK_END = 32,
+ PA_WIDOW_ORPHAN = 64
+};
+
+class HWPPara;
+#define FIXED_SPACING_BIT (0x8000)
+
+struct LineInfo
+{
+/* the position of the starting character: the control has a different length */
+/**
+ * Starting character position
+ */
+ unsigned short pos;
+ hunit space_width;
+ hunit height;
+ hunit pgy; /* internal */
+ hunit sx; /* internal */
+ hunit psx; /* internal */
+ hunit pex; /* internal */
+// for formatting
+ hunit height_sp;
+ unsigned short softbreak; // column, page, section
+
+ void Read(HWPFile &hwpf, HWPPara const *para);
+};
+/**
+ * It represents the paragraph.
+ * @short Paragraph
+ */
+class DLLEXPORT HWPPara
+{
+ private:
+ HWPPara *_next;
+
+ public:
+// paragraph information
+/**
+ * Zero is for the new paragraph style.
+ */
+ unsigned char reuse_shape; /* the new shape if 0 */
+ unsigned short nch;
+ unsigned short nline;
+
+// realking
+ hunit begin_ypos;
+ unsigned char scflag;
+
+/**
+ * If the value is 0, all character of paragraph have same style given cshape
+ */
+ unsigned char contain_cshape; /* if it's 0, all the characters are representing with representative shape */
+ unsigned char etcflag;
+/**
+ * Checks the special characters in the paragraph
+ */
+ uint ctrlflag;
+ unsigned char pstyno;
+ std::shared_ptr<CharShape> cshape; /* When characters are all the same shape */
+ std::shared_ptr<ParaShape> pshape; /* if reuse flag is 0, */
+
+ std::unique_ptr<LineInfo[]> linfo;
+ std::vector<std::shared_ptr<CharShape>> cshapep;
+/**
+ * Box object list
+ */
+ std::map<unsigned short, std::unique_ptr<HBox>> hhstr;
+
+ HWPPara(void);
+ ~HWPPara(void);
+
+ bool Read(HWPFile &hwpf, unsigned char flag);
+
+ void SetNext(HWPPara *n) { _next = n; };
+
+/* Functions for layout */
+/**
+ * Returns the character style of paragraph.
+ */
+ CharShape *GetCharShape(int pos);
+/**
+ * Returns the style of paragraph.
+ */
+ ParaShape& GetParaShape(void) { return *pshape; }
+
+/**
+ * Returns next paragraph.
+ */
+ HWPPara *Next(void) { return _next;}
+
+ private:
+ std::unique_ptr<HBox> readHBox(HWPFile &);
+};
+
+#endif // INCLUDED_HWPFILTER_SOURCE_HPARA_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx
new file mode 100644
index 000000000..a4ef16885
--- /dev/null
+++ b/hwpfilter/source/hstream.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include "hstream.hxx"
+
+HStream::HStream()
+ : pos(0)
+{
+}
+
+void HStream::addData(const byte* buf, size_t aToAdd) { seq.insert(seq.end(), buf, buf + aToAdd); }
+
+size_t HStream::readBytes(byte* buf, size_t aToRead)
+{
+ auto size = seq.size();
+ if (aToRead >= (size - pos))
+ aToRead = size - pos;
+ for (size_t i = 0; i < aToRead; ++i)
+ buf[i] = seq[pos++];
+ return aToRead;
+}
+
+size_t HStream::skipBytes(size_t aToSkip)
+{
+ auto size = seq.size();
+ if (aToSkip >= (size - pos))
+ aToSkip = size - pos;
+ pos += aToSkip;
+ return aToSkip;
+}
+
+size_t HStream::available() const { return seq.size() - pos; }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstream.hxx b/hwpfilter/source/hstream.hxx
new file mode 100644
index 000000000..bf0d55442
--- /dev/null
+++ b/hwpfilter/source/hstream.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <vector>
+
+typedef unsigned char byte;
+
+class HStream
+{
+ public:
+ HStream();
+
+ void addData( const byte *buf, size_t aToAdd);
+ /**
+ * Read some byte to buf as given size
+ */
+ size_t readBytes( byte *buf, size_t aToRead);
+ /**
+ * Skip some byte from stream as given size
+ */
+ size_t skipBytes( size_t aToSkip );
+ /**
+ * @returns Size of remained stream
+ */
+ size_t available() const;
+
+ private:
+ std::vector<byte> seq;
+ size_t pos;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx
new file mode 100644
index 000000000..bf4538d68
--- /dev/null
+++ b/hwpfilter/source/hstyle.cxx
@@ -0,0 +1,146 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include <comphelper/newarray.hxx>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hstyle.h"
+
+enum
+{
+ MAXSTYLENAME = 20
+};
+
+namespace hwpfilter
+{
+struct StyleData
+{
+ char name[MAXSTYLENAME + 1];
+ CharShape cshape;
+ ParaShape pshape;
+};
+}
+
+static char buffer[MAXSTYLENAME + 1];
+
+HWPStyle::HWPStyle()
+{
+ nstyles = 0;
+ style = nullptr;
+}
+
+HWPStyle::~HWPStyle()
+{
+ delete[] style;
+ nstyles = 0;
+}
+
+char* HWPStyle::GetName(int n) const
+{
+ if (n < 0 || n >= nstyles)
+ return nullptr;
+ return style[n].name;
+}
+
+void HWPStyle::SetName(int n, char const* name)
+{
+ if (n < 0 || n >= nstyles)
+ return;
+
+ if (name)
+ {
+#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 12) && !defined __clang__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
+ auto const p = style[n].name;
+ strncpy(p, name, MAXSTYLENAME);
+ p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized
+#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 12) && !defined __clang__
+#pragma GCC diagnostic pop
+#endif
+ }
+ else
+ style[n].name[0] = 0;
+}
+
+CharShape* HWPStyle::GetCharShape(int n) const
+{
+ if (n < 0 || n >= nstyles)
+ return nullptr;
+ return &style[n].cshape;
+}
+
+void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
+{
+ if (n >= 0 && n < nstyles)
+ {
+ if (cshapep)
+ style[n].cshape = *cshapep;
+ else
+ style[n].cshape = CharShape();
+ }
+}
+
+ParaShape* HWPStyle::GetParaShape(int n) const
+{
+ if (n < 0 || n >= nstyles)
+ return nullptr;
+ return &style[n].pshape;
+}
+
+void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
+{
+ if (n >= 0 && n < nstyles)
+ {
+ if (pshapep)
+ style[n].pshape = *pshapep;
+ else
+ style[n].pshape = ParaShape();
+ }
+}
+
+void HWPStyle::Read(HWPFile& hwpf)
+{
+ CharShape cshape;
+ ParaShape pshape;
+
+ hwpf.Read2b(&nstyles, 1);
+ style = ::comphelper::newArray_null<hwpfilter::StyleData>(nstyles);
+ if (!style)
+ return;
+
+ for (int ii = 0; ii < nstyles; ii++)
+ {
+ hwpf.ReadBlock(buffer, MAXSTYLENAME);
+ cshape.Read(hwpf);
+ pshape.Read(hwpf);
+
+ SetName(ii, buffer);
+ SetCharShape(ii, &cshape);
+ SetParaShape(ii, &pshape);
+ if (hwpf.State())
+ return;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstyle.h b/hwpfilter/source/hstyle.h
new file mode 100644
index 000000000..851bd8d4d
--- /dev/null
+++ b/hwpfilter/source/hstyle.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HSTYLE_H
+#define INCLUDED_HWPFILTER_SOURCE_HSTYLE_H
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "hwplib.h"
+#include "hinfo.h"
+
+namespace hwpfilter { struct StyleData; }
+
+/**
+ * @short Using for global style object like "Standard"
+ */
+class DLLEXPORT HWPStyle
+{
+ short nstyles;
+ hwpfilter::StyleData *style;
+ public:
+ HWPStyle( void );
+ ~HWPStyle( void );
+
+ int Num( void ) const { return nstyles;}
+ char *GetName( int n ) const;
+ CharShape *GetCharShape( int n ) const;
+ ParaShape *GetParaShape( int n ) const;
+
+ void SetName( int n, char const *name );
+ void SetCharShape( int n, CharShape const *cshapep );
+ void SetParaShape( int n, ParaShape const *pshapep );
+
+ void Read( HWPFile &hwpf );
+};
+#endif
+/* _HWPSTYLE+H_ */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx
new file mode 100644
index 000000000..33e0c252f
--- /dev/null
+++ b/hwpfilter/source/htags.cxx
@@ -0,0 +1,133 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include <o3tl/char16_t2wchar_t.hxx>
+#include <unotools/tempfile.hxx>
+
+#include <string.h>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "htags.h"
+
+bool HyperText::Read(HWPFile& hwpf)
+{
+ size_t nRead = hwpf.ReadBlock(filename, 256);
+ nRead += hwpf.Read2b(bookmark, 16);
+ nRead += hwpf.ReadBlock(macro, 325);
+ if (hwpf.Read1b(type))
+ ++nRead;
+ else
+ type = 0;
+ nRead += hwpf.ReadBlock(reserve, 3);
+ if( type == 2 )
+ {
+ for( int i = 1; i < 256; i++)
+ {
+ filename[i-1] = filename[i];
+ if( filename[i] == 0 )
+ break;
+ }
+ }
+ return nRead == 617;
+}
+
+EmPicture::EmPicture(size_t tsize)
+ : size(tsize >= 32 ? tsize - 32 : 0)
+{
+ if (size != 0)
+ data.reset( new uchar[size] );
+}
+
+EmPicture::~EmPicture()
+{
+};
+
+bool EmPicture::Read(HWPFile & hwpf)
+{
+ if (size == 0)
+ return false;
+ hwpf.ReadBlock(name, 16);
+ hwpf.ReadBlock(type, 16);
+ name[0] = 'H';
+ name[1] = 'W';
+ name[2] = 'P';
+ return hwpf.ReadBlock(data.get(), size) != 0;
+}
+
+
+OlePicture::OlePicture(int tsize)
+ : signature(0)
+#ifdef _WIN32
+ , pis(nullptr)
+#endif
+{
+ size = tsize - 4;
+ if (size <= 0)
+ return;
+};
+
+#ifdef _WIN32
+OlePicture::~OlePicture()
+{
+ if( pis )
+ pis->Release();
+};
+#endif
+
+#define FILESTG_SIGNATURE_NORMAL 0xF8995568
+
+void OlePicture::Read(HWPFile & hwpf)
+{
+ if (size <= 0)
+ return;
+
+// We process only FILESTG_SIGNATURE_NORMAL.
+ hwpf.Read4b(signature);
+ if (signature != FILESTG_SIGNATURE_NORMAL)
+ return;
+#ifdef _WIN32
+ char *data = new char[size];
+ if (hwpf.ReadBlock(data,size) == 0)
+ {
+ delete [] data;
+ return;
+ }
+
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+
+ SvFileStream aOutputStream(aTempFile.GetURL(), StreamMode::WRITE);
+ aOutputStream.WriteBytes(data, size);
+ delete [] data;
+ aOutputStream.Close();
+ if( StgOpenStorage(o3tl::toW(aTempFile.GetFileName().getStr()), nullptr,
+ STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED,
+ nullptr, 0, &pis) != S_OK ) {
+ pis = nullptr;
+ return;
+ }
+#else
+ hwpf.SkipBlock(size);
+#endif
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/htags.h b/hwpfilter/source/htags.h
new file mode 100644
index 000000000..0a302bf18
--- /dev/null
+++ b/hwpfilter/source/htags.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HTAGS_H
+#define INCLUDED_HWPFILTER_SOURCE_HTAGS_H
+
+#include <memory>
+#ifdef _WIN32
+#include <objidl.h>
+#endif
+
+class HWPFile;
+/**
+ * @short Embedded image
+ */
+struct EmPicture
+{
+ size_t size;
+ char name[16];
+ char type[16];
+ std::unique_ptr<uchar[]> data;
+
+ explicit EmPicture(size_t size);
+ ~EmPicture(void);
+
+ bool Read(HWPFile& hwpf);
+};
+/**
+ * @short HyperText
+ */
+struct HyperText
+{
+ kchar filename[256];
+ hchar bookmark[16];
+ char macro[325];
+ uchar type;
+ char reserve[3];
+ bool Read(HWPFile& hwpf);
+};
+/**
+ * @short Win32 OLE object
+ */
+struct OlePicture
+{
+ int size;
+ uint signature;
+#ifdef _WIN32
+ IStorage* pis;
+#endif
+ explicit OlePicture(int tsize);
+#ifdef _WIN32
+ ~OlePicture(void);
+#endif
+ void Read(HWPFile& hwpf);
+};
+#endif // INCLUDED_HWPFILTER_SOURCE_HTAGS_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hutil.cxx b/hwpfilter/source/hutil.cxx
new file mode 100644
index 000000000..30d176d46
--- /dev/null
+++ b/hwpfilter/source/hutil.cxx
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include "hwpfile.h"
+#include "hbox.h"
+#include "hutil.h"
+
+static char *get_one_roman(int num, char one, char five, char ten, char *str)
+{
+ static const char *one_strs[] =
+ {
+ "", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"
+ };
+
+ strcpy(str, one_strs[num]);
+ while (*str)
+ {
+ switch (*str)
+ {
+ case 'i':
+ *str = one;
+ break;
+ case 'v':
+ *str = five;
+ break;
+ case 'x':
+ *str = ten;
+ }
+ str++;
+ }
+ return str;
+}
+
+
+void num2roman(int num, char *buf)
+{
+ char *pt;
+
+ pt = get_one_roman((num / 100) % 10, 'c', 'd', 'm', buf);
+ pt = get_one_roman((num / 10) % 10, 'x', 'l', 'c', pt);
+ get_one_roman(num % 10, 'i', 'v', 'x', pt);
+}
+
+
+void str2hstr(const char *c, hchar * i)
+{
+ hchar ch;
+
+ while( 0 != (ch = *c++))
+ {
+ if (ch & 0x80)
+ {
+ if (*c > 32)
+ {
+ *i++ = (ch << 8) | *c;
+ c++;
+ }
+ }
+ else
+ *i++ = ch;
+ }
+ *i = 0;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hutil.h b/hwpfilter/source/hutil.h
new file mode 100644
index 000000000..d856b74de
--- /dev/null
+++ b/hwpfilter/source/hutil.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HUTIL_H
+#define INCLUDED_HWPFILTER_SOURCE_HUTIL_H
+
+#include "hbox.h"
+/**
+ * Transfer number to roman character
+ */
+void num2roman(int num, char *buf);
+/**
+ * Transfer 8bit string to 16bit string used internally in hwp
+ */
+void str2hstr(const char *c, hchar *i);
+
+#endif /* UTIL_H_*/
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwp.component b/hwpfilter/source/hwp.component
new file mode 100644
index 000000000..961d6b7d7
--- /dev/null
+++ b/hwpfilter/source/hwp.component
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ -->
+
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.comp.hwpimport.HwpImportFilter"
+ constructor="hwpfilter_HwpImportFilter_get_implementation">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+</component>
diff --git a/hwpfilter/source/hwpeq.cxx b/hwpfilter/source/hwpeq.cxx
new file mode 100644
index 000000000..a19bee24a
--- /dev/null
+++ b/hwpfilter/source/hwpeq.cxx
@@ -0,0 +1,800 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+// DVO: always use standard headers:
+#include <istream>
+#include <sstream>
+
+#include "mzstring.h"
+#include "hwpeq.h"
+#include <sal/types.h>
+#include <sal/macros.h>
+
+#include <rtl/character.hxx>
+
+/* @Man: change the hwp formula to LaTeX */
+#ifdef _WIN32
+# define ENDL "\r\n"
+#else /* !_WIN32 */
+# define ENDL "\n"
+#endif
+
+#define EQ_CASE 0x01 // case sensitive cmd
+#define EQ_ENV 0x02 // equiv to latex environment
+#define EQ_ATOP 0x04 // must revert order
+
+static bool IS_WS(std::istream::int_type ch) {
+ return ch != std::istream::traits_type::eof()
+ && rtl::isAsciiWhiteSpace(
+ static_cast<unsigned char>(
+ std::istream::traits_type::to_char_type(ch)));
+}
+
+static bool IS_BINARY(std::istream::int_type ch) {
+ return ch != std::istream::traits_type::eof()
+ && strchr("+-<=>", std::istream::traits_type::to_char_type(ch));
+}
+
+#ifdef _WIN32
+#define STRICMP stricmp
+#else
+#define STRICMP strcasecmp
+#endif
+
+// sub and sup script status
+enum { SCRIPT_NONE, SCRIPT_SUB, SCRIPT_SUP, SCRIPT_ALL};
+
+static int eq_word(MzString& outs, std::istream *strm, int script = SCRIPT_NONE);
+static bool eq_sentence(MzString& outs, std::istream *strm, const char *end = nullptr);
+
+namespace {
+
+struct hwpeq {
+ const char *key; // hwp math keyword
+ const char *latex; // corresponding latex keyword
+ int nargs; // # of argument
+ unsigned char flag; // case sensitive?
+};
+
+}
+
+const hwpeq eq_tbl[] = {
+ { "!=", "\\equiv ", 0, 0 },
+ { "#", "\\\\", 0, 0 },
+ { "+-", "\\pm ", 0, 0 },
+ { "-+", "\\mp ", 0, 0 },
+ { "<=", "\\leq ", 0, 0 },
+ { "==", "\\equiv ", 0, 0 },
+ { ">=", "\\geq ", 0, 0 },
+ { "Pr", nullptr, 0, 0 },
+ { "^", "^", 1, 0 },
+ { "_", "_", 1, 0 },
+ { "`", "\\;", 0, 0 },
+ { "acute", nullptr, 1, 0 },
+ { "aleph", nullptr, 0, 0 },
+ { "alpha", nullptr, 0, EQ_CASE },
+ { "amalg", nullptr, 0, 0 },
+ { "and", nullptr, 0, 0 },
+ { "angle", nullptr, 0, 0 },
+ { "angstrom", nullptr, 0, 0 },
+ { "approx", nullptr, 0, 0 },
+ { "arc", nullptr, 0, 0 },
+ { "arccos", nullptr, 0, 0 },
+ { "arch", nullptr, 0, 0 },
+ { "arcsin", nullptr, 0, 0 },
+ { "arctan", nullptr, 0, 0 },
+ { "arg", nullptr, 0, 0 },
+ { "assert", "\\vdash", 0, 0 },
+ { "ast", nullptr, 0, 0 },
+ { "asymp", nullptr, 0, 0 },
+ { "atop", nullptr, 1, EQ_ATOP },
+ { "backslash", nullptr, 0, 0 },
+ { "bar", nullptr, 1, 0 },
+ { "because", nullptr, 0, 0 },
+ { "beta", nullptr, 0, EQ_CASE },
+ { "big", nullptr, 0, EQ_CASE },
+ { "bigcap", nullptr, 0, 0 },
+ { "bigcirc", nullptr, 0, 0 },
+ { "bigcup", nullptr, 0, 0 },
+ { "bigg", nullptr, 0, EQ_CASE },
+ { "bigodiv", nullptr, 0, 0 },
+ { "bigodot", nullptr, 0, 0 },
+ { "bigominus", nullptr, 0, 0 },
+ { "bigoplus", nullptr, 0, 0 },
+ { "bigotimes", nullptr, 0, 0 },
+ { "bigsqcap", nullptr, 0, 0 },
+ { "bigsqcup", nullptr, 0, 0 },
+ { "biguplus", nullptr, 0, 0 },
+ { "bigvee", nullptr, 0, 0 },
+ { "bigwedge", nullptr, 0, 0 },
+ { "binom", nullptr, 2, 0 },
+ { "bmatrix", nullptr, 0, EQ_ENV },
+ { "bold", nullptr, 0, 0 },
+ { "bot", nullptr, 0, 0 },
+ { "breve", nullptr, 1, 0 },
+ { "buildrel", nullptr, 0, 0 }, // LATER
+ { "bullet", nullptr, 0, 0 },
+ { "cap", nullptr, 0, 0 },
+ { "cases", nullptr, 0, EQ_ENV },
+ { "ccol", nullptr, 0, 0 }, /* Center vertically */
+ { "cdot", nullptr, 0, 0 },
+ { "cdots", nullptr, 0, 0 },
+ { "check", nullptr, 1, 0 },
+ { "chi", nullptr, 0, EQ_CASE },
+ { "choose", nullptr, 0, EQ_ATOP },
+ { "circ", nullptr, 0, 0 },
+ { "col", nullptr, 0, 0 }, // LATER
+ { "cong", nullptr, 0, 0 },
+ { "coprod", nullptr, 0, 0 },
+ { "cos", nullptr, 0, 0 },
+ { "cosec", nullptr, 0, 0 },
+ { "cosh", nullptr, 0, 0 },
+ { "cot", nullptr, 0, 0 },
+ { "coth", nullptr, 0, 0 },
+ { "cpile", nullptr, 0, 0 }, // LATER
+ { "csc", nullptr, 0, 0 },
+ { "cup", nullptr, 0, 0 },
+ { "dagger", nullptr, 0, 0 },
+ { "dashv", nullptr, 0, 0 },
+ { "ddagger", nullptr, 0, 0 },
+ { "ddot", nullptr, 1, 0 },
+ { "ddots", nullptr, 0, 0 },
+ { "def", nullptr, 0, 0 },
+ { "deg", nullptr, 0, 0 },
+ { "del", nullptr, 0, 0 },
+ { "delta", nullptr, 0, EQ_CASE },
+ { "diamond", nullptr, 0, 0 },
+ { "dim", nullptr, 0, 0 },
+ { "div", nullptr, 0, 0 },
+ { "divide", nullptr, 0, 0 },
+ { "dline", nullptr, 0, 0 },
+ { "dmatrix", nullptr, 0, EQ_ENV },
+ { "dot", nullptr, 1, 0 },
+ { "doteq", nullptr, 0, 0 },
+ { "dotsaxis", nullptr, 0, 0 },
+ { "dotsdiag", nullptr, 0, 0 },
+ { "dotslow", "\\ldots", 0, 0 },
+ { "dotsvert", "\\vdots", 0, 0 },
+ { "downarrow", nullptr, 0, EQ_CASE },
+ { "dsum", "+", 0, 0 },
+ { "dyad", nullptr, 0, 0 }, // LATER
+ { "ell", nullptr, 0, 0 },
+ { "emptyset", nullptr, 0, 0 },
+ { "epsilon", nullptr, 0, EQ_CASE },
+ { "eqalign", nullptr, 0, EQ_ENV },
+ { "equiv", nullptr, 0, 0 },
+ { "eta", nullptr, 0, EQ_CASE },
+ { "exarrow", nullptr, 0, 0 },
+ { "exist", "\\exists", 0, 0 },
+ { "exists", nullptr, 0, 0 },
+ { "exp", nullptr, 0, EQ_CASE },
+ { "for", nullptr, 0, 0 },
+ { "forall", nullptr, 0, 0 },
+ { "from", "_", 1, 0 },
+ { "gamma", nullptr, 0, EQ_CASE },
+ { "gcd", nullptr, 0, 0 },
+ { "ge", "\\geq", 0, 0 },
+ { "geq", nullptr, 0, 0 },
+ { "ggg", nullptr, 0, 0 },
+ { "grad", nullptr, 0, 0 },
+ { "grave", nullptr, 1, 0 },
+ { "hat", "\\widehat", 1, 0 },
+ { "hbar", nullptr, 0, 0 },
+ { "hom", nullptr, 0, 0 },
+ { "hookleft", nullptr, 0, 0 },
+ { "hookright", nullptr, 0, 0 },
+ { "identical", nullptr, 0, 0 }, // LATER
+ { "if", nullptr, 0, 0 },
+ { "imag", nullptr, 0, 0 },
+ { "image", nullptr, 0, 0 },
+ { "imath", nullptr, 0, 0 },
+ { "in", nullptr, 0, 0 },
+ { "inf", "\\infty", 0, 0 },
+ { "infinity", "\\infty", 0, 0 },
+ { "infty", nullptr, 0, 0 },
+ { "int", nullptr, 0, 0 },
+ { "integral", "\\int", 0, 0 },
+ { "inter", "\\bigcap", 0, 0 },
+ { "iota", nullptr, 0, EQ_CASE },
+ { "iso", nullptr, 0, 0 }, // ams
+ { "it", nullptr, 0, 0 },
+ { "jmath", nullptr, 0, 0 },
+ { "kappa", nullptr, 0, EQ_CASE },
+ { "ker", nullptr, 0, 0 },
+ { "lambda", nullptr, 0, EQ_CASE },
+ { "land", nullptr, 0, 0 }, // LATER
+ { "langle", nullptr, 0, 0 },
+ { "larrow", "\\leftarrow", 0, EQ_CASE },
+ { "lbrace", nullptr, 0, 0 },
+ { "lbrack", "[", 0, 0 },
+ { "lceil", nullptr, 0, 0 },
+ { "lcol", nullptr, 0, 0 }, // LATER
+ { "ldots", nullptr, 0, 0 },
+ { "le", nullptr, 0, 0 },
+ { "left", nullptr, 0, 0 },
+ { "leftarrow", nullptr, 0, EQ_CASE },
+ { "leq", nullptr, 0, 0 },
+ { "lfloor", nullptr, 0, 0 },
+ { "lg", nullptr, 0, 0 },
+ { "lim", nullptr, 0, EQ_CASE },
+ { "line", "\\vert", 0, 0 },
+ { "liter", "\\ell", 0, 0 },
+ { "lll", nullptr, 0, 0 }, // ams
+ { "ln", nullptr, 0, 0 },
+ { "log", nullptr, 0, 0 },
+ { "lor", "\\vee", 0, 0 },
+ { "lparen", "(", 0, 0 },
+ { "lpile", nullptr, 0, 0 }, // LATER
+ { "lrarrow", "\\leftrightarrow", 0, EQ_CASE },
+ { "lrharpoons", "\\leftrightharpoons",0, 0 },
+ { "mapsto", nullptr, 0, 0 },
+ { "massert", "\\dashv", 0, 0 },
+ { "matrix", nullptr, 0, EQ_ENV },
+ { "max", nullptr, 0, 0 },
+ { "mho", nullptr, 0, 0 }, // ams
+ { "min", nullptr, 0, 0 },
+ { "minusplus", nullptr, 0, 0 },
+ { "mit", "", 0, 0 }, // font
+ { "mod", "\\bmod", 0, 0 },
+ { "models", nullptr, 0, 0 },
+ { "msangle", nullptr, 0, 0 }, // LATER
+ { "mu", nullptr, 0, EQ_CASE },
+ { "nabla", nullptr, 0, 0 },
+ { "ne", nullptr, 0, 0 },
+ { "nearrow", nullptr, 0, 0 },
+ { "neg", nullptr, 0, 0 },
+ { "neq", nullptr, 0, 0 },
+ { "nequiv", nullptr, 0, 0 },
+ { "ni", nullptr, 0, 0 },
+ { "not", nullptr, 0, 0 },
+ { "notin", nullptr, 0, 0 },
+ { "nu", nullptr, 0, EQ_CASE },
+ { "nwarrow", nullptr, 0, 0 },
+ { "odiv", nullptr, 0, 0 },
+ { "odot", nullptr, 0, 0 },
+ { "oint", nullptr, 0, 0 },
+ { "omega", nullptr, 0, EQ_CASE },
+ { "omicron", nullptr, 0, EQ_CASE },
+ { "ominus", nullptr, 0, 0 },
+ { "oplus", nullptr, 0, 0 },
+ { "or ", nullptr, 0, 0 },
+ { "oslash", nullptr, 0, 0 },
+ { "otimes", nullptr, 0, 0 },
+ { "over", nullptr, 1, EQ_ATOP },
+ { "overline", nullptr, 1, 0 },
+ { "owns", "\\ni", 0, 0 },
+ { "parallel", nullptr, 0, 0 },
+ { "partial", nullptr, 0, 0 },
+ { "phantom", nullptr, 0, 0 },
+ { "phi", nullptr, 0, EQ_CASE },
+ { "pi", nullptr, 0, EQ_CASE },
+ { "pile", nullptr, 0, 0 }, // LATER
+ { "plusminus", "\\pm", 0, 0 },
+ { "pmatrix", nullptr, 0, EQ_ENV },
+ { "prec", nullptr, 0, 0 },
+ { "prep", nullptr, 0, 0 },
+ { "prime", nullptr, 0, 0 },
+ { "prod", nullptr, 0, 0 },
+ { "propto", nullptr, 0, 0 },
+ { "psi", nullptr, 0, EQ_CASE },
+ { "rangle", nullptr, 0, 0 },
+ { "rarrow", "\\rightarrow", 0, EQ_CASE },
+ { "rbrace", "]", 0, 0 },
+ { "rbrace", nullptr, 0, 0 },
+ { "rceil", nullptr, 0, 0 },
+ { "rcol", nullptr, 0, 0 }, // LATER
+ { "real", "\\Re", 0, 0 },
+ { "reimage", nullptr, 0, 0 },
+ { "rel", nullptr, 0, 0 },
+ { "rfloor", nullptr, 0, 0 },
+ { "rho", nullptr, 0, EQ_CASE },
+ { "right", nullptr, 0, 0 },
+ { "rightarrow", nullptr, 0, EQ_CASE },
+ { "rlharpoons", nullptr, 0, 0 },
+ { "rm", nullptr, 0, 0 },
+ { "root", "\\sqrt", 1, 0 },
+ { "rparen", ")", 0, 0 },
+ { "rpile", nullptr, 0, 0 }, // LATER
+ { "rtangle", nullptr, 0, 0 },
+ { "sangle", nullptr, 0, 0 },
+ { "scale", nullptr, 0, 0 },
+ { "searrow", nullptr, 0, 0 },
+ { "sec", nullptr, 0, 0 },
+ { "sigma", nullptr, 0, EQ_CASE },
+ { "sim", nullptr, 0, 0 },
+ { "simeq", nullptr, 0, 0 },
+ { "sin", nullptr, 0, 0 },
+ { "sinh", nullptr, 0, 0 },
+ { "slash", nullptr, 0, 0 },
+ { "smallint", nullptr, 0, 0 },
+ { "smallinter", nullptr, 0, 0 },
+ { "smalloint", nullptr, 0, 0 },
+ { "smallprod", nullptr, 0, 0 },
+ { "smallsum", nullptr, 0, 0 },
+ { "smallunion", nullptr, 0, 0 },
+ { "smcoprod", nullptr, 0, 0 },
+ { "sqcap", nullptr, 0, 0 },
+ { "sqcup", nullptr, 0, 0 },
+ { "sqrt", nullptr, 1, 0 },
+ { "sqsubset", nullptr, 0, 0 },
+ { "sqsubseteq", nullptr, 0, 0 },
+ { "sqsupset", nullptr, 0, 0 },
+ { "sqsupseteq", nullptr, 0, 0 },
+ { "star", nullptr, 0, 0 },
+ { "sub", "_", 0, 0 },
+ { "subset", nullptr, 0, 0 },
+ { "subseteq", nullptr, 0, 0 },
+ { "succ", nullptr, 0, 0 },
+ { "sum", nullptr, 0, 0 },
+ { "sup", "^", 0, 0 },
+ { "superset", nullptr, 0, 0 },
+ { "supset", nullptr, 0, 0 },
+ { "supseteq", nullptr, 0, 0 },
+ { "swarrow", nullptr, 0, 0 },
+ { "tan", nullptr, 0, 0 },
+ { "tanh", nullptr, 0, 0 },
+ { "tau", nullptr, 0, EQ_CASE },
+ { "therefore", nullptr, 0, 0 },
+ { "theta", nullptr, 0, EQ_CASE },
+ { "tilde", "\\widetilde", 1, 0 },
+ { "times", nullptr, 0, 0 },
+ { "to", "^", 1, 0 },
+ { "top", nullptr, 0, 0 },
+ { "triangle", nullptr, 0, 0 },
+ { "triangled", nullptr, 0, 0 },
+ { "trianglel", nullptr, 0, 0 },
+ { "triangler", nullptr, 0, 0 },
+ { "triangleu", nullptr, 0, 0 },
+ { "udarrow", "\\updownarrow",0, EQ_CASE },
+ { "under", "\\underline", 1, 0 },
+ { "underline", "\\underline", 1, 0 },
+ { "union", "\\bigcup", 0, 0 },
+ { "uparrow", nullptr, 0, EQ_CASE },
+ { "uplus", nullptr, 0, 0 },
+ { "upsilon", nullptr, 0, EQ_CASE },
+ { "varepsilon", nullptr, 0, 0 },
+ { "varphi", nullptr, 0, 0 },
+ { "varpi", nullptr, 0, 0 },
+ { "varrho", nullptr, 0, 0 },
+ { "varsigma", nullptr, 0, 0 },
+ { "vartheta", nullptr, 0, 0 },
+ { "varupsilon", nullptr, 0, 0 },
+ { "vdash", nullptr, 0, 0 },
+ { "vdots", nullptr, 0, 0 },
+ { "vec", nullptr, 1, 0 },
+ { "vee", nullptr, 0, 0 },
+ { "vert", nullptr, 0, 0 },
+ { "wedge", nullptr, 0, 0 },
+ { "wp", nullptr, 0, 0 },
+ { "xi", nullptr, 0, EQ_CASE },
+ { "xor", nullptr, 0, 0 },
+ { "zeta", nullptr, 0, EQ_CASE }
+};
+
+static const hwpeq *lookup_eqn(char const *str)
+{
+ static const int eqCount = SAL_N_ELEMENTS(eq_tbl);
+ int l = 0, r = eqCount;
+ const hwpeq *result = nullptr;
+
+ while( l < r ) {
+ const int m = (l + r) / 2;
+ const int k = strcmp(eq_tbl[m].key, str);
+ if( k == 0 ) {
+ result = eq_tbl + m;
+ break;
+ }
+ else if( k < 0 )
+ l = m + 1;
+ else
+ r = m;
+ }
+ return result;
+}
+
+/* If only the first character is uppercase or all characters are uppercase, change to lowercase */
+static void make_keyword( char *keyword, const char *token)
+{
+ char* ptr;
+ bool result = true;
+ int len = strlen(token);
+ assert(keyword);
+
+ if( 255 < len )
+ {
+ len = 255;
+ }
+ memcpy(keyword, token, len);
+ keyword[len] = 0;
+
+ if( (token[0] & 0x80) || rtl::isAsciiLowerCase(static_cast<unsigned char>(token[0])) || strlen(token) < 2 )
+ return;
+
+ bool capital = rtl::isAsciiUpperCase(
+ static_cast<unsigned char>(keyword[1]));
+ for( ptr = keyword + 2; *ptr && result; ptr++ )
+ {
+ if( (*ptr & 0x80) ||
+ (!capital && rtl::isAsciiUpperCase(static_cast<unsigned char>(*ptr))) ||
+ (capital && rtl::isAsciiLowerCase(static_cast<unsigned char>(*ptr))) )
+ {
+ result = false;
+ }
+ }
+
+ if( result )
+ {
+ ptr = keyword;
+ while( *ptr )
+ {
+ if( rtl::isAsciiUpperCase(static_cast<unsigned char>(*ptr)) )
+ *ptr = sal::static_int_cast<char>(
+ rtl::toAsciiLowerCase(static_cast<unsigned char>(*ptr)));
+ ptr++;
+ }
+ }
+}
+
+namespace {
+
+// token reading function
+struct eq_stack {
+ MzString white;
+ MzString token;
+ std::istream *strm;
+
+ eq_stack() { strm = nullptr; };
+ bool state(std::istream const *s) {
+ if( strm != s) { white = nullptr; token = nullptr; }
+ return token.length() != 0;
+ }
+};
+
+}
+
+static eq_stack *stk = nullptr;
+
+static void push_token(MzString const &white, MzString const &token, std::istream *strm)
+{
+ // one time stack
+ assert(stk->token.length() == 0);
+
+ stk->white = white;
+ stk->token = token;
+ stk->strm = strm;
+}
+
+/*
+ * It returns the length of the read tokens.
+ *
+ * control char, control sequence, binary sequence,
+ * alphabet string, single character */
+static int next_token(MzString &white, MzString &token, std::istream *strm)
+{
+ std::istream::int_type ch = 0;
+
+ if( stk->state(strm) ) {
+ white = stk->white;
+ token = stk->token;
+ stk->token = nullptr;
+ stk->white = nullptr;
+ return token.length();
+ }
+
+ token = nullptr;
+ white = nullptr;
+ if( !strm->good() )
+ return 0;
+ ch = strm->get();
+ if( ch == std::istream::traits_type::eof() )
+ return 0;
+
+ // read preceding ws
+ if( IS_WS(ch) ) {
+ do
+ {
+ white << static_cast<char>(ch);
+ ch = strm->get();
+ } while (IS_WS(ch));
+ }
+
+ if( ch == '\\' || ch & 0x80
+ || (ch != std::istream::traits_type::eof() && rtl::isAsciiAlpha(ch)) )
+ {
+ if( ch == '\\' ) {
+ token << static_cast<char>(ch);
+ ch = strm->get();
+ }
+ do {
+ token << static_cast<char>(ch);
+ ch = strm->get();
+ } while( ch != std::istream::traits_type::eof()
+ && (ch & 0x80 || rtl::isAsciiAlpha(ch)) ) ;
+ strm->putback(static_cast<char>(ch));
+ /* special treatment of sub, sub, over, atop
+ The reason for this is that affect next_state().
+ */
+ if( !STRICMP("sub", token) || !STRICMP("from", token) ||
+ !STRICMP("sup", token) || !STRICMP("to", token) ||
+ !STRICMP("over", token) || !STRICMP("atop", token) ||
+ !STRICMP("left", token) || !STRICMP("right", token) )
+ {
+ char buf[256];
+ make_keyword(buf, token);
+ token = buf;
+ }
+ if( !token.compare("sub") || !token.compare("from") )
+ token = "_";
+ if( !token.compare("sup") || !token.compare("to") )
+ token = "^";
+ }
+ else if( IS_BINARY(ch) ) {
+ do
+ {
+ token << static_cast<char>(ch);
+ ch = strm->get();
+ }
+ while( IS_BINARY(ch) );
+ strm->putback(static_cast<char>(ch));
+ }
+ else if( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) ) {
+ do {
+ token << static_cast<char>(ch);
+ ch = strm->get();
+ } while( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) );
+ strm->putback(static_cast<char>(ch));
+ }
+ else
+ token << static_cast<char>(ch);
+
+ return token.length();
+}
+
+static std::istream::int_type read_white_space(MzString& outs, std::istream *strm)
+{
+ std::istream::int_type result;
+
+ if( stk->state(strm) ) {
+ outs << stk->white;
+ stk->white = nullptr;
+ result = std::istream::traits_type::to_int_type(stk->token[0]);
+ }
+ else {
+ std::istream::int_type ch;
+ for (;;)
+ {
+ ch = strm->get();
+ if (!IS_WS(ch))
+ break;
+ outs << static_cast<char>(ch);
+ }
+ strm->putback(static_cast<char>(ch));
+ result = ch;
+ }
+ return result;
+}
+
+/* If the argument is not required, delimiters are space and brace for each items.
+ sqrt {ab} c = sqrt {ab} c
+ (,} are for grouping
+ ^ ,_ are for combination
+
+ Sorting of formats with arguments, such as sqrt
+ sqrt a -> sqrt {a}
+ sqrt {a} -> sqrt {a}
+ If there is more than one argument, it eliminates backslash between arguments.
+ \frac a b -> frac {a} {b}
+ Clean the form of over
+ a over b -> {a} over {b}
+ */
+
+static int eq_word(MzString& outs, std::istream *strm, int status)
+{
+ MzString token, white, state;
+ int result;
+ char keyword[256];
+ const hwpeq *eq;
+
+ next_token(white, token, strm);
+ if (token.length() <= 0)
+ return 0;
+ result = token[0];
+
+ if( token.compare("{") == 0 ) {
+ state << white << token;
+ eq_sentence(state, strm, "}");
+ }
+ else if( token.compare("left") == 0 ) {
+ state << white << token;
+ next_token(white, token, strm);
+ state << white << token;
+
+ eq_sentence(state, strm, "right");
+
+ next_token(white, token, strm);
+ state << white << token;
+ }
+ else {
+ /* Normal token */
+ int script_status = SCRIPT_NONE;
+ while( true ) {
+ state << white << token;
+ make_keyword(keyword, token);
+ if( token[0] == '^' )
+ script_status |= SCRIPT_SUP;
+ else if( token[0] == '_' )
+ script_status |= SCRIPT_SUB;
+ else
+ script_status = SCRIPT_NONE;
+
+ if( nullptr != (eq = lookup_eqn(keyword)) ) {
+ int nargs = eq->nargs;
+ while( nargs-- ) {
+ const std::istream::int_type ch = read_white_space(state, strm);
+ if( ch != '{' ) state << '{';
+ eq_word(state, strm, script_status);
+ if( ch != '{' ) state << '}';
+ }
+ }
+
+ if( !next_token(white, token, strm) )
+ break;
+ // end loop and restart with this
+ if( (token[0] == '^' && status && !(status & SCRIPT_SUP)) ||
+ (token[0] == '_' && status && !(status & SCRIPT_SUB)) ||
+ strcmp("over", token) == 0 || strcmp("atop", token) == 0 ||
+ strchr("{}#&`", token[0]) ||
+ (!strchr("^_", token[0]) && white.length()) )
+ {
+ push_token(white, token, strm);
+ break;
+ }
+ }
+ }
+ outs << state;
+
+ return result;
+}
+
+static bool eq_sentence(MzString& outs, std::istream *strm, const char *end)
+{
+ MzString state;
+ MzString white, token;
+ bool multiline = false;
+
+ read_white_space(outs, strm);
+ while( eq_word(state, strm) ) {
+ if( !next_token(white, token, strm) ||
+ (end && strcmp(token.c_str(), end) == 0) )
+ {
+ state << white << token;
+ break;
+ }
+ push_token(white, token, strm);
+ if( !token.compare("atop") || !token.compare("over") )
+ outs << '{' << state << '}';
+ else {
+ if( !token.compare("#") )
+ multiline = true;
+ outs << state;
+ }
+ state = nullptr;
+ read_white_space(outs, strm);
+ }
+ outs << state;
+ return multiline;
+}
+
+static char eq2ltxconv(MzString& sstr, std::istream *strm, const char *sentinel)
+{
+ MzString white, token;
+ char key[256];
+ std::istream::int_type ch;
+ int result;
+
+ while( 0 != (result = next_token(white, token, strm)) ) {
+ if( sentinel && (result == 1) && strchr(sentinel, token[0]) )
+ break;
+ make_keyword(key, token);
+ const hwpeq *eq = nullptr;
+ if( (eq = lookup_eqn(key)) != nullptr ) {
+ if( eq->latex )
+ strcpy(key, eq->latex);
+ else {
+ key[0] = '\\';
+ strcpy(key + 1, eq->key);
+ }
+ if( (eq->flag & EQ_CASE)
+ && rtl::isAsciiUpperCase(static_cast<unsigned char>(token[0])) )
+ key[1] = sal::static_int_cast<char>(
+ rtl::toAsciiUpperCase(static_cast<unsigned char>(key[1])));
+ token = key;
+ }
+
+ if( token[0] == '{' ) { // grouping
+ sstr << white << token;
+ eq2ltxconv(sstr, strm, "}");
+ sstr << '}';
+ }
+ else if( eq && (eq->flag & EQ_ENV) ) {
+ next_token(white, token, strm);
+ if( token[0] != '{' )
+ return 0;
+ sstr << "\\begin" << "{" << eq->key << "}" << ENDL ;
+ eq2ltxconv(sstr, strm, "}");
+ if( sstr[sstr.length() - 1] != '\n' )
+ sstr << ENDL ;
+ sstr << "\\end" << "{" << eq->key << "}" << ENDL ;
+ }
+ else if( eq && (eq->flag & EQ_ATOP) ) {
+ if( sstr.length() == 0 )
+ sstr << '{';
+ else {
+ int pos = sstr.rfind('}');
+ if( 0 < pos)
+ sstr.replace(pos, ' ');
+ }
+ sstr << token;
+ for (;;)
+ {
+ ch = strm->get();
+ if ( ch == std::istream::traits_type::eof() || !IS_WS(ch) )
+ break;
+ sstr << static_cast<char>(ch);
+ }
+ if( ch != '{' )
+ sstr << "{}";
+ else {
+ eq2ltxconv(sstr, strm, "}");
+ sstr << '}';
+ }
+ }
+ else
+ sstr << white << token;
+ }
+ return token[0];
+}
+
+void eq2latex(MzString& outs, char const *s)
+{
+ assert(s);
+ if( stk == nullptr )
+ stk = new eq_stack;
+
+ MzString tstr;
+
+ std::istringstream tstrm(s);
+ bool eqnarray = eq_sentence(tstr, &tstrm);
+ std::istringstream strm(tstr.c_str());
+
+ if( eqnarray )
+ outs << "\\begin{array}{rllll}" << ENDL;
+ eq2ltxconv(outs, &strm, nullptr);
+ outs << ENDL;
+ if( eqnarray )
+ outs << "\\end{array}" << ENDL;
+ delete stk;
+ stk = nullptr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpeq.h b/hwpfilter/source/hwpeq.h
new file mode 100644
index 000000000..cc96743c2
--- /dev/null
+++ b/hwpfilter/source/hwpeq.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HWPEQ_H
+#define INCLUDED_HWPFILTER_SOURCE_HWPEQ_H
+
+#include "mzstring.h"
+
+void eq2latex(MzString& mstr, char const* str);
+
+#endif // INCLUDED_HWPFILTER_SOURCE_HWPEQ_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
new file mode 100644
index 000000000..58d6c4849
--- /dev/null
+++ b/hwpfilter/source/hwpfile.cxx
@@ -0,0 +1,671 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <memory>
+#include "precompile.h"
+
+#include <algorithm>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <o3tl/safeint.hxx>
+
+#include "hwplib.h"
+#include "hwpfile.h"
+#include "hiodev.h"
+#include "hfont.h"
+#include "hstyle.h"
+#include "hbox.h"
+#include "hpara.h"
+#include "htags.h"
+#include "hcode.h"
+#include "hstream.hxx"
+
+
+HWPFile *HWPFile::cur_doc = nullptr;
+static int ccount = 0;
+static int pcount = 0;
+static int datecodecount = 0;
+
+HWPFile::HWPFile()
+ : version(HWP_V30)
+ , compressed(false)
+ , encrypted(false)
+ , linenumber(0)
+ , info_block_len(0)
+ , error_code(HWP_NoError)
+ , readdepth(0)
+ , m_nCurrentPage(1)
+ , m_nMaxSettedPage(0)
+ , currenthyper(0)
+{
+ SetCurrentDoc(this);
+}
+
+HWPFile::~HWPFile()
+{
+ oledata.reset();
+ hiodev.reset();
+}
+
+int HWPFile::ReadHwpFile(std::unique_ptr<HStream> stream)
+{
+ if (Open(std::move(stream)) != HWP_NoError)
+ return State();
+ InfoRead();
+ FontRead();
+ StyleRead();
+ AddColumnInfo();
+ ParaListRead();
+ TagsRead();
+
+ return State();
+}
+
+int detect_hwp_version(const char *str)
+{
+ if (memcmp(V20SIGNATURE, str, HWPIDLen) == 0)
+ return HWP_V20;
+ else if (memcmp(V21SIGNATURE, str, HWPIDLen) == 0)
+ return HWP_V21;
+ else if (memcmp(V30SIGNATURE, str, HWPIDLen) == 0)
+ return HWP_V30;
+ return 0;
+}
+
+// HIODev wrapper
+
+int HWPFile::Open(std::unique_ptr<HStream> stream)
+{
+ std::unique_ptr<HStreamIODev> hstreamio(new HStreamIODev(std::move(stream)));
+
+ if (!hstreamio->open())
+ {
+ return SetState(HWP_EMPTY_FILE);
+ }
+
+ SetIODevice(std::move(hstreamio));
+
+ char idstr[HWPIDLen];
+
+ if (ReadBlock(idstr, HWPIDLen) < HWPIDLen)
+ return SetState(HWP_UNSUPPORTED_VERSION);
+ version = detect_hwp_version(idstr);
+ if (HWP_V30 != version)
+ return SetState(HWP_UNSUPPORTED_VERSION);
+ return HWP_NoError;
+}
+
+int HWPFile::SetState(int errcode)
+{
+ error_code = errcode;
+ return error_code;
+}
+
+bool HWPFile::Read1b(unsigned char &out)
+{
+ return hiodev && hiodev->read1b(out);
+}
+
+bool HWPFile::Read1b(char &out)
+{
+ unsigned char tmp8;
+ if (!hiodev || !hiodev->read1b(tmp8))
+ return false;
+ out = tmp8;
+ return true;
+}
+
+bool HWPFile::Read2b(unsigned short &out)
+{
+ return hiodev && hiodev->read2b(out);
+}
+
+bool HWPFile::Read4b(unsigned int &out)
+{
+ return hiodev && hiodev->read4b(out);
+}
+
+bool HWPFile::Read4b(int &out)
+{
+ unsigned int tmp32;
+ if (!Read4b(tmp32))
+ return false;
+ out = tmp32;
+ return true;
+}
+
+size_t HWPFile::Read2b(void *ptr, size_t nmemb)
+{
+ return hiodev ? hiodev->read2b(ptr, nmemb) : 0;
+}
+
+size_t HWPFile::ReadBlock(void *ptr, size_t size)
+{
+ return hiodev ? hiodev->readBlock(ptr, size) : 0;
+}
+
+size_t HWPFile::SkipBlock(size_t size)
+{
+ return hiodev ? hiodev->skipBlock(size) : 0;
+}
+
+void HWPFile::SetCompressed(bool flag)
+{
+ if (hiodev)
+ hiodev->setCompressed(flag);
+}
+
+
+std::unique_ptr<HIODev> HWPFile::SetIODevice(std::unique_ptr<HIODev> new_hiodev)
+{
+ std::swap(hiodev, new_hiodev);
+ return new_hiodev;
+}
+
+
+// end of HIODev wrapper
+
+void HWPFile::InfoRead()
+{
+ _hwpInfo.Read(*this);
+}
+
+
+void HWPFile::FontRead()
+{
+ _hwpFont.Read(*this);
+}
+
+
+void HWPFile::StyleRead()
+{
+ _hwpStyle.Read(*this);
+}
+
+
+void HWPFile::ParaListRead()
+{
+ ReadParaList(plist);
+}
+
+void HWPFile::ReadParaList(std::vector < HWPPara* > &aplist)
+{
+ std::unique_ptr<HWPPara> spNode( new HWPPara );
+ unsigned char tmp_etcflag;
+ unsigned char prev_etcflag = 0;
+ while (spNode->Read(*this, 0))
+ {
+ if( !(spNode->etcflag & 0x04) ){
+ tmp_etcflag = spNode->etcflag;
+ spNode->etcflag = prev_etcflag;
+ prev_etcflag = tmp_etcflag;
+ }
+ if (spNode->nch && spNode->reuse_shape)
+ {
+ if (!aplist.empty()){
+ spNode->pshape = aplist.back()->pshape;
+ }
+ else{
+ spNode->nch = 0;
+ spNode->reuse_shape = 0;
+ }
+ }
+ spNode->pshape->pagebreak = spNode->etcflag;
+ if (spNode->nch)
+ AddParaShape(spNode->pshape);
+
+ if (!aplist.empty())
+ aplist.back()->SetNext(spNode.get());
+ aplist.push_back(spNode.release());
+ spNode.reset( new HWPPara );
+ }
+ move_to_failed(std::move(spNode));
+}
+
+void HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsigned char flag)
+{
+ std::unique_ptr<HWPPara> spNode( new HWPPara );
+ unsigned char tmp_etcflag;
+ unsigned char prev_etcflag = 0;
+ while (spNode->Read(*this, flag))
+ {
+ if( !(spNode->etcflag & 0x04) ){
+ tmp_etcflag = spNode->etcflag;
+ spNode->etcflag = prev_etcflag;
+ prev_etcflag = tmp_etcflag;
+ }
+ if (spNode->nch && spNode->reuse_shape)
+ {
+ if (!aplist.empty()){
+ spNode->pshape = aplist.back()->pshape;
+ }
+ else{
+ spNode->nch = 0;
+ spNode->reuse_shape = 0;
+ }
+ }
+ spNode->pshape->pagebreak = spNode->etcflag;
+ if (spNode->nch)
+ AddParaShape(spNode->pshape);
+
+ if (!aplist.empty())
+ aplist.back()->SetNext(spNode.get());
+ aplist.push_back(std::move(spNode));
+ spNode.reset( new HWPPara );
+ }
+ move_to_failed(std::move(spNode));
+}
+
+void HWPFile::move_to_failed(std::unique_ptr<HWPPara> xPara)
+{
+ pfailedlist.push_back(std::move(xPara));
+}
+
+void HWPFile::TagsRead()
+{
+ while (true)
+ {
+ uint tag;
+ if (!Read4b(tag))
+ return;
+ int size;
+ if (!Read4b(size))
+ return;
+ if (size <= 0 && tag > 0){
+ continue;
+ }
+
+ if (tag == FILETAG_END_OF_COMPRESSED ||
+ tag == FILETAG_END_OF_UNCOMPRESSED)
+ return;
+ switch (tag)
+ {
+ case FILETAG_EMBEDDED_PICTURE:
+ {
+ std::unique_ptr<EmPicture> emb(new EmPicture(size));
+
+ if (emb->Read(*this))
+ emblist.push_back(std::move(emb));
+ }
+ break;
+ case FILETAG_OLE_OBJECT:
+ oledata.reset( new OlePicture(size) );
+ oledata->Read(*this);
+ break;
+ case FILETAG_HYPERTEXT:
+ {
+ const int nRecordLen = 617;
+ if( (size % nRecordLen) != 0 )
+ SkipBlock( size );
+ else
+ {
+ const int nRecords = size / nRecordLen;
+ for (int i = 0 ; i < nRecords; ++i)
+ {
+ std::unique_ptr<HyperText> hypert(new HyperText);
+ if (hypert->Read(*this))
+ hyperlist.push_back(std::move(hypert));
+ else
+ break;
+ }
+ }
+ break;
+ }
+ case 6:
+ {
+ ReadBlock(_hwpInfo.back_info.reserved1, 8);
+ if (!Read4b(_hwpInfo.back_info.luminance))
+ return;
+ if (!Read4b(_hwpInfo.back_info.contrast))
+ return;
+ if (!Read1b(_hwpInfo.back_info.effect))
+ return;
+ ReadBlock(_hwpInfo.back_info.reserved2, 7);
+ ReadBlock(_hwpInfo.back_info.filename, 260);
+ ReadBlock(_hwpInfo.back_info.color, 3);
+ unsigned short nFlag;
+ if (!Read2b(nFlag))
+ return;
+ _hwpInfo.back_info.flag = nFlag >> 8 ;
+ int nRange;
+ if (!Read4b(nRange))
+ return;
+ _hwpInfo.back_info.range = nRange >> 24;
+ ReadBlock(_hwpInfo.back_info.reserved3, 27);
+ if (!Read4b(_hwpInfo.back_info.size))
+ return;
+
+ if (_hwpInfo.back_info.size < 0)
+ {
+ _hwpInfo.back_info.size = 0;
+ return;
+ }
+
+ _hwpInfo.back_info.data.clear();
+
+ //read potentially compressed data in blocks as it's more
+ //likely large values are simply broken and we'll run out
+ //of data before we need to realloc
+ for (int i = 0; i < _hwpInfo.back_info.size; i+= SAL_MAX_UINT16)
+ {
+ int nOldSize = _hwpInfo.back_info.data.size();
+ size_t nBlock = std::min<int>(SAL_MAX_UINT16, _hwpInfo.back_info.size - nOldSize);
+ _hwpInfo.back_info.data.resize(nOldSize + nBlock);
+ size_t nReadBlock = ReadBlock(_hwpInfo.back_info.data.data() + nOldSize, nBlock);
+ if (nBlock != nReadBlock)
+ {
+ _hwpInfo.back_info.data.resize(nOldSize + nReadBlock);
+ break;
+ }
+ }
+ _hwpInfo.back_info.size = _hwpInfo.back_info.data.size();
+
+ if( _hwpInfo.back_info.size > 0 )
+ _hwpInfo.back_info.type = 2;
+ else if( _hwpInfo.back_info.filename[0] )
+ _hwpInfo.back_info.type = 1;
+ else
+ _hwpInfo.back_info.type = 0;
+
+
+ _hwpInfo.back_info.isset = true;
+
+ break;
+ }
+ case FILETAG_PRESENTATION:
+ case FILETAG_PREVIEW_IMAGE:
+ case FILETAG_PREVIEW_TEXT:
+ default:
+ SkipBlock(size);
+ }
+ }
+}
+
+
+ColumnDef *HWPFile::GetColumnDef(int num)
+{
+ if (o3tl::make_unsigned(num) < columnlist.size())
+ return columnlist[num]->xColdef.get();
+ else
+ return nullptr;
+}
+
+/* Index of @return starts from 1 */
+int HWPFile::GetPageMasterNum(int page)
+{
+ int i = 0;
+ for (auto const& column : columnlist)
+ {
+ if( page < column->start_page )
+ return i;
+ ++i;
+ }
+ return i;
+}
+
+HyperText *HWPFile::GetHyperText()
+{
+ ++currenthyper;
+ if (o3tl::make_unsigned(currenthyper) <= hyperlist.size())
+ return hyperlist[currenthyper-1].get();
+ else
+ return nullptr;
+}
+
+EmPicture *HWPFile::GetEmPicture(Picture * pic)
+{
+ char *name = pic->picinfo.picembed.embname;
+
+ name[0] = 'H';
+ name[1] = 'W';
+ name[2] = 'P';
+
+ for (auto const& emb : emblist)
+ if (strcmp(name, emb->name) == 0)
+ return emb.get();
+ return nullptr;
+}
+
+EmPicture *HWPFile::GetEmPictureByName(char * name)
+{
+ name[0] = 'H';
+ name[1] = 'W';
+ name[2] = 'P';
+
+ for (auto const& emb : emblist)
+ if (strcmp(name, emb->name) == 0)
+ return emb.get();
+ return nullptr;
+}
+
+ParaShape *HWPFile::getParaShape(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= pslist.size())
+ return nullptr;
+ return pslist[index].get();
+}
+
+CharShape *HWPFile::getCharShape(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= cslist.size())
+ return nullptr;
+ return cslist[index].get();
+}
+
+FBoxStyle *HWPFile::getFBoxStyle(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= fbslist.size())
+ return nullptr;
+ return fbslist[index];
+}
+
+DateCode *HWPFile::getDateCode(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= datecodes.size())
+ return nullptr;
+ return datecodes[index];
+}
+
+HeaderFooter *HWPFile::getHeaderFooter(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= headerfooters.size())
+ return nullptr;
+ return headerfooters[index];
+}
+
+ShowPageNum *HWPFile::getPageNumber(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= pagenumbers.size())
+ return nullptr;
+ return pagenumbers[index];
+}
+
+Table *HWPFile::getTable(int index)
+{
+ if (index < 0 || o3tl::make_unsigned(index) >= tables.size())
+ return nullptr;
+ return tables[index].get();
+}
+
+void HWPFile::AddParaShape(std::shared_ptr<ParaShape> const & pshape)
+{
+ int nscount = 0;
+ for(int j = 0 ; j < MAXTABS-1 ; j++)
+ {
+ if( j > 0 && pshape->tabs[j].position == 0 )
+ break;
+ if( pshape->tabs[0].position == 0 ){
+ if( pshape->tabs[j].type || pshape->tabs[j].dot_continue ||
+ (pshape->tabs[j].position != 1000 *j) )
+ nscount = j;
+ }
+ else {
+ if( pshape->tabs[j].type || pshape->tabs[j].dot_continue ||
+ (pshape->tabs[j].position != 1000 * (j + 1)) )
+ nscount = j;
+ }
+ }
+ if( nscount )
+ {
+ pshape->tabs[MAXTABS-1].type = sal::static_int_cast<char>(nscount);
+ pshape->index = ++pcount;
+ pslist.push_back(pshape);
+ return;
+ }
+
+ int value = compareParaShape(pshape.get());
+ if (value == 0)
+ {
+ pshape->index = ++pcount;
+ pslist.push_back(pshape);
+ return;
+ }
+ pshape->index = value;
+}
+
+void HWPFile::AddCharShape(std::shared_ptr<CharShape> const & cshape)
+{
+ int value = compareCharShape(cshape.get());
+ if (value == 0)
+ {
+ cshape->index = ++ccount;
+ cslist.push_back(cshape);
+ }
+ else
+ cshape->index = value;
+}
+
+void HWPFile::AddColumnInfo()
+{
+ columnlist.emplace_back(new ColumnInfo(m_nCurrentPage));
+ setMaxSettedPage();
+}
+
+void HWPFile::SetColumnDef(const std::shared_ptr<ColumnDef>& rColdef)
+{
+ ColumnInfo *cinfo = columnlist.back().get();
+ if( cinfo->bIsSet )
+ return;
+ cinfo->xColdef = rColdef;
+ cinfo->bIsSet = true;
+}
+
+void HWPFile::AddDateFormat(DateCode * hbox)
+{
+ hbox->key = sal::static_int_cast<char>(++datecodecount);
+ datecodes.push_back(hbox);
+}
+
+void HWPFile::AddPageNumber(ShowPageNum * hbox)
+{
+ pagenumbers.push_back(hbox);
+}
+
+void HWPFile::AddHeaderFooter(HeaderFooter * hbox)
+{
+ headerfooters.push_back(hbox);
+}
+
+void HWPFile::AddTable(std::unique_ptr<Table> hbox)
+{
+ tables.push_back(std::move(hbox));
+}
+
+void HWPFile::AddFBoxStyle(FBoxStyle * fbstyle)
+{
+ fbslist.push_back(fbstyle);
+}
+
+int HWPFile::compareCharShape(CharShape const *shape)
+{
+ int count = cslist.size();
+ for(int i = 0; i< count; i++)
+ {
+ CharShape *cshape = getCharShape(i);
+
+ if( shape->size == cshape->size &&
+ shape->font[0] == cshape->font[0] &&
+ shape->ratio[0] == cshape->ratio[0] &&
+ shape->space[0] == cshape->space[0] &&
+ shape->color[1] == cshape->color[1] &&
+ shape->color[0] == cshape->color[0] &&
+ shape->shade == cshape->shade &&
+ shape->attr == cshape->attr )
+ {
+ return cshape->index;
+ }
+ }
+ return 0;
+}
+
+int HWPFile::compareParaShape(const ParaShape* shape)
+{
+ if (!shape->cshape)
+ return 0;
+
+ int count = pslist.size();
+ for (int i = 0; i < count; ++i)
+ {
+ ParaShape *pshape = pslist[i].get();
+ if (!pshape->cshape)
+ continue;
+ if (shape->left_margin == pshape->left_margin &&
+ shape->right_margin == pshape->right_margin &&
+ shape->pspacing_prev == pshape->pspacing_prev &&
+ shape->pspacing_next == pshape->pspacing_next &&
+ shape->indent == pshape->indent &&
+ shape->lspacing == pshape->lspacing &&
+ shape->arrange_type == pshape->arrange_type &&
+ shape->outline == pshape->outline &&
+ shape->pagebreak == pshape->pagebreak)
+ {
+ if (shape->cshape->size == pshape->cshape->size &&
+ shape->cshape->font[0] == pshape->cshape->font[0] &&
+ shape->cshape->ratio[0] == pshape->cshape->ratio[0] &&
+ shape->cshape->space[0] == pshape->cshape->space[0] &&
+ shape->cshape->color[1] == pshape->cshape->color[1] &&
+ shape->cshape->color[0] == pshape->cshape->color[0] &&
+ shape->cshape->shade == pshape->cshape->shade &&
+ shape->cshape->attr == pshape->cshape->attr)
+ {
+ return pshape->index;
+ }
+ }
+ }
+ return 0;
+}
+
+HWPFile *GetCurrentDoc()
+{
+ return HWPFile::cur_doc;
+}
+
+
+HWPFile *SetCurrentDoc(HWPFile * hwpfp)
+{
+ HWPFile *org = HWPFile::cur_doc;
+
+ HWPFile::cur_doc = hwpfp;
+ return org;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
new file mode 100644
index 000000000..72d22a5ae
--- /dev/null
+++ b/hwpfilter/source/hwpfile.h
@@ -0,0 +1,332 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+// hwpfile.h
+// (C) 1998 Mizi Research, All rights are reserved
+
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
+#define INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
+
+#include <algorithm>
+#include <memory>
+#include <vector>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sal/types.h>
+#include "hwplib.h"
+#include "hfont.h"
+#include "hstyle.h"
+#include "hpara.h"
+
+#define HWPIDLen 30
+#define V20SIGNATURE "HWP Document File V2.00 \032\1\2\3\4\5"
+#define V21SIGNATURE "HWP Document File V2.10 \032\1\2\3\4\5"
+#define V30SIGNATURE "HWP Document File V3.00 \032\1\2\3\4\5"
+
+#define HWP_V20 20
+#define HWP_V21 21
+#define HWP_V30 30
+
+int detect_hwp_version(const char *str);
+
+struct FBox;
+struct EmPicture;
+struct HyperText;
+struct FBoxStyle;
+struct CellLine;
+struct Cell;
+struct OlePicture;
+struct Picture;
+struct HeaderFooter;
+struct ShowPageNum;
+struct DateCode;
+struct Table;
+
+class HIODev;
+class HWPInfo;
+class HWPFont;
+class HWPStyle;
+class HWPPara;
+class HStream;
+
+struct ColumnInfo{
+ int start_page;
+ bool bIsSet;
+ std::shared_ptr<ColumnDef> xColdef;
+ explicit ColumnInfo(int num){
+ start_page = num;
+ bIsSet = false;
+ }
+};
+
+/**
+ * The HWPFile class is the main class of hwp for reading file
+ * information from stream
+ *
+ * The example is as below:
+ * <pre>
+ * HWPFile f;
+ * f.ReadHwpFile( stream );
+ * </pre>
+ *
+ * There are two way to read hwp information from stream, one is to read all at a time
+ * to use @ref ReadhwpFile() method like above example, other is to read partial information
+ * to use @ref Open(), @ref InfoRead(), @ref FontRead(), @ref StyleRead(), @ref ParaListRead(), @ref TagsRead(),
+ *
+ * @short HWP file management object
+ */
+class DLLEXPORT HWPFile
+{
+ public:
+/**
+ * Default constructor
+ */
+ HWPFile();
+ ~HWPFile();
+
+ public:
+
+/**
+ * Opens HStream to use it.
+ * @returns 0 if success, otherwise error code
+ * @see State()
+ */
+ int Open( std::unique_ptr<HStream> );
+
+/**
+ * Say current state
+ * @returns 0 if normal, otherwise error code. If it's bigger than USER_ERROR_BIT, it is internally using error, otherwise it's system error which is able to get the message @ref strerror() method.
+ */
+ int State( void ) const { return error_code;}
+/**
+ * Sets the current state
+ */
+ int SetState(int errcode);
+/**
+ * Reads one byte from HIODev
+ */
+ bool Read1b(unsigned char &out);
+ bool Read1b(char &out);
+/**
+ * Reads two byte from HIODev
+ */
+ bool Read2b(unsigned short &out);
+/**
+ * Reads four byte from HIODev
+ */
+ bool Read4b(unsigned int &out);
+ bool Read4b(int &out);
+/**
+ * Reads nmemb short type array from HIODev
+ */
+ size_t Read2b(void *ptr, size_t nmemb);
+
+/**
+ * Reads some bytes from HIODev not regarding endian's way
+ * @param size Amount for reading
+ */
+ size_t ReadBlock( void *ptr, size_t size );
+/**
+ * Skips some bytes from HIODev
+ */
+ size_t SkipBlock( size_t size );
+/**
+ * Reads main paragraph list
+ */
+ void ReadParaList(std::vector<std::unique_ptr<HWPPara>> &aplist, unsigned char flag = 0);
+ void ReadParaList(std::vector<HWPPara*> &aplist);
+/**
+ * Sets if the stream is compressed
+ */
+ void SetCompressed( bool );
+/**
+ * Sets current HIODev
+ */
+ std::unique_ptr<HIODev> SetIODevice( std::unique_ptr<HIODev> hiodev );
+
+/**
+ * Reads all information of hwp file from stream
+ */
+ int ReadHwpFile( std::unique_ptr<HStream> );
+/**
+ * Reads document information of hwp file from HIODev
+ */
+ void InfoRead(void);
+/**
+ * Reads font list of hwp file from HIODev
+ */
+ void FontRead(void);
+/**
+ * Reads style list of hwp file from HIODev
+ */
+ void StyleRead(void);
+/**
+ * Reads paragraph list of hwp file from HIODev
+ */
+ void ParaListRead();
+/* 그림 등의 추가 정보를 읽는다. */
+/**
+ * Reads additional information like embedded image of hwp file from HIODev
+ */
+ void TagsRead();
+
+ enum Paper
+ {
+ UserPaper = 0,
+ Col80Paper = 1,
+ Col132Paper = 2,
+ A4Paper = 3,
+ LetterPaper = 4,
+ B5Paper = 5,
+ B4Paper = 6,
+ LegalPaper = 7,
+ A3Paper = 8
+ };
+
+ void AddPage(){ m_nCurrentPage++;}
+ void AddColumnInfo();
+ void SetColumnDef(std::shared_ptr<ColumnDef> const &);
+ void AddParaShape(std::shared_ptr<ParaShape> const &);
+ void AddCharShape(std::shared_ptr<CharShape> const &);
+ void AddFBoxStyle(FBoxStyle *);
+ void AddDateFormat(DateCode *);
+ void AddHeaderFooter(HeaderFooter *);
+ void AddPageNumber(ShowPageNum *);
+ void AddTable(std::unique_ptr<Table>);
+
+ ColumnDef* GetColumnDef(int);
+ int GetPageMasterNum(int page);
+
+ int getCurrentPage() const{ return m_nCurrentPage;}
+ HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
+ HWPFont& GetHWPFont(void) { return _hwpFont; }
+ HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
+ HWPPara *GetFirstPara(void) { return !plist.empty() ? plist.front().get() : nullptr; }
+
+ EmPicture *GetEmPicture(Picture *pic);
+ EmPicture *GetEmPictureByName(char * name);
+ HyperText *GetHyperText();
+ ParaShape *getParaShape(int);
+ CharShape *getCharShape(int);
+ FBoxStyle *getFBoxStyle(int);
+ DateCode *getDateCode(int);
+ HeaderFooter *getHeaderFooter(int);
+ ShowPageNum *getPageNumber(int);
+ Table *getTable(int);
+
+ int getParaShapeCount() const{ return pslist.size(); }
+ int getCharShapeCount() const{ return cslist.size(); }
+ int getFBoxStyleCount() const{ return fbslist.size(); }
+ int getDateFormatCount() const{ return datecodes.size(); }
+ int getHeaderFooterCount() const{ return headerfooters.size(); }
+ int getPageNumberCount() const{ return pagenumbers.size(); }
+ int getTableCount() const{ return tables.size(); }
+ int getColumnCount() const{ return columnlist.size(); }
+
+ int getMaxSettedPage() const{ return m_nMaxSettedPage; }
+ void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
+
+ void push_hpara_type(unsigned char scflag) { element_import_stack.push_back(scflag); }
+ bool already_importing_type(unsigned char scflag) const
+ {
+ return std::find(element_import_stack.begin(), element_import_stack.end(), scflag) != element_import_stack.end();
+ }
+ void pop_hpara_type() { element_import_stack.pop_back(); }
+
+ void move_to_failed(std::unique_ptr<HWPPara> rPara);
+
+ private:
+ int compareCharShape(CharShape const *shape);
+ int compareParaShape(ParaShape const *shape);
+
+ public:
+ int version;
+ bool compressed;
+ bool encrypted;
+ unsigned char linenumber;
+ int info_block_len;
+ int error_code;
+ std::unique_ptr<OlePicture> oledata;
+ unsigned char scratch[SAL_MAX_UINT16];
+ int readdepth;
+
+ private:
+/* hwp 파일 이름 */
+ int m_nCurrentPage;
+ int m_nMaxSettedPage;
+ std::unique_ptr<HIODev> hiodev;
+// read hwp contents
+ HWPInfo _hwpInfo;
+ HWPFont _hwpFont;
+ HWPStyle _hwpStyle;
+ std::vector<std::unique_ptr<ColumnInfo>> columnlist;
+ // paragraph list
+ std::vector<std::unique_ptr<HWPPara>> plist;
+ // keep paragraph's that failed to load until
+ // import is complete to avoid dangling references
+ // elsewhere
+ std::vector<std::unique_ptr<HWPPara>> pfailedlist;
+ // embedded picture list(tag data)
+ std::vector<std::unique_ptr<EmPicture>> emblist;
+ std::vector<std::unique_ptr<HyperText>> hyperlist;
+ int currenthyper;
+ std::vector<std::shared_ptr<ParaShape>> pslist;
+ std::vector<std::shared_ptr<CharShape>> cslist;
+ std::vector<FBoxStyle*> fbslist;
+ std::vector<DateCode*> datecodes;
+ std::vector<HeaderFooter*> headerfooters;
+ std::vector<ShowPageNum*> pagenumbers;
+ std::vector<std::unique_ptr<Table>> tables;
+ //track the stack of HParas types we're currently importing
+ std::vector<unsigned char> element_import_stack;
+
+// for global document handling
+ static HWPFile *cur_doc;
+ friend HWPFile *GetCurrentDoc(void);
+ friend HWPFile *SetCurrentDoc(HWPFile *);
+};
+
+class DLLEXPORT DepthGuard
+{
+private:
+ HWPFile& m_rFile;
+public:
+ DepthGuard(HWPFile &rFile)
+ : m_rFile(rFile)
+ {
+ ++m_rFile.readdepth;
+ }
+ bool toodeep() const
+ {
+ return m_rFile.readdepth == 512;
+ }
+ ~DepthGuard()
+ {
+ --m_rFile.readdepth;
+ }
+};
+
+HWPFile *GetCurrentDoc(void);
+HWPFile *SetCurrentDoc(HWPFile *hwpfp);
+#endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwplib.h b/hwpfilter/source/hwplib.h
new file mode 100644
index 000000000..ec438d361
--- /dev/null
+++ b/hwpfilter/source/hwplib.h
@@ -0,0 +1,226 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HWPLIB_H
+#define INCLUDED_HWPFILTER_SOURCE_HWPLIB_H
+#include "precompile.h"
+
+#include <limits>
+#include <new>
+#include <string>
+
+#include <o3tl/safeint.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+
+/* hwp96부터 hunit가 4byte가 되었다. */
+/**
+ * size of hunit is 4 since hwp96 version
+ */
+typedef unsigned short hchar;
+typedef int hunit;
+typedef unsigned char kchar;
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+
+typedef ::std::basic_string<hchar> hchar_string;
+
+inline OUString fromHcharStringToOUString(hchar_string const & s) {
+ if (s.length() > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) {
+ throw std::bad_alloc();
+ }
+ return {reinterpret_cast<char16_t const *>(s.c_str()), sal_Int32(s.length())};
+}
+
+/**
+ * @short Point
+ */
+typedef struct
+{
+ int x, y;
+} ZZPoint;
+
+/**
+ * @short Size
+ */
+typedef struct
+{
+ int w, h;
+} ZZSize;
+
+/**
+ * @short Rectangle
+ */
+typedef struct
+{
+ int x, y;
+ int w, h;
+} ZZRect;
+
+/**
+ * @short Parall
+ */
+typedef struct
+{
+ ZZPoint pt[3];
+} ZZParall;
+
+/**
+ * @short Scale
+ */
+typedef struct
+{
+ int mulX, divX;
+ int mulY, divY;
+} ZZScaleXY;
+
+#if !defined(_WIN32) && !defined(MAX_PATH)
+# define MAX_PATH 260
+#endif /* MAX_PATH */
+
+#ifndef TRUE
+# define TRUE 1
+# define FALSE 0
+#endif
+
+// HWP unit information
+/**
+ * HWP unit information
+ */
+#define ONE_POINT 25
+#define ONE_ENG_CH_WIDTH (ONE_POINT*(10/2))
+#define ONE_MILI (71)
+#define ONE_DOT (19)
+
+/* HWP 3.0 문서 정보 */
+
+#define NLanguage 7
+
+/* 제어 문자 */
+/**
+ * Control character
+ */
+#define CH_ALIGNSPACE 0
+#define CH_FIELD 5
+#define CH_BOOKMARK 6
+
+#define CH_DATE_FORM 7
+#define CH_DATE_CODE 8
+#define CH_TAB 9
+#define CH_TEXT_BOX 10
+#define CH_PICTURE 11
+
+#define CH_END_PARA 13
+#define CH_LINE 14
+#define CH_HIDDEN 15
+#define CH_HEADER_FOOTER 16
+#define CH_FOOTNOTE 17
+#define CH_AUTO_NUM 18 /* pgnum, footnote/endnote, picture num */
+#define CH_NEW_NUM 19 /* pgnum, footnote/endnote, picture num */
+
+#define CH_SHOW_PAGE_NUM 20
+#define CH_PAGE_NUM_CTRL 21 /* new chapter, hide pagenum */
+#define CH_MAIL_MERGE 22
+#define CH_COMPOSE 23
+#define CH_HYPHEN 24
+
+#define CH_TOC_MARK 25 /* CONT_MARK, TBL_MARK, PIC_MARK */
+#define CH_INDEX_MARK 26
+
+#define CH_COL_DEF 27
+#define CH_OUTLINE 28
+#define CH_CROSSREF 29
+
+#define CH_KEEP_SPACE 30
+#define CH_FIXED_SPACE 31
+#define CH_SPACE 32
+
+#define HAVE_SUBPARA_MASK ((1<<CH_TEXT_BOX) | (1<<CH_PICTURE) | (1<<CH_HIDDEN) | (1<<CH_HEADER_FOOTER) | (1<<CH_FOOTNOTE))
+
+#define IS_SP_SKIP_BLOCK(hch) ((hch<5) || (hch==12) || (hch==27) || (hch == 29))
+
+// file tag
+#define FILETAG_END_OF_COMPRESSED 0x00000000
+
+#define FILETAG_EMBEDDED_PICTURE 0x00000001
+#define FILETAG_OLE_OBJECT 0x00000002
+#define FILETAG_HYPERTEXT 0x00000003
+#define FILETAG_PRESENTATION 0x00000004
+
+#define FILETAG_END_OF_UNCOMPRESSED 0x80000000
+#define FILETAG_PREVIEW_IMAGE 0x80000001
+#define FILETAG_PREVIEW_TEXT 0x80000002
+
+// user error code
+enum ErrorCode
+{
+ HWP_NoError,
+// system error = errno
+// USER_ERROR_BIT = (1 << 16),
+ HWP_InvalidFileName,
+ HWP_InvalidFileFormat,
+ HWP_BrokenFile,
+ HWP_UNSUPPORTED_VERSION,
+ HWP_EMPTY_FILE
+};
+
+// debug code
+enum DebugMask
+{
+ DBG_READ = 0x01,
+ DBG_DISPLAY = 0x02
+};
+
+#ifdef _WIN32
+#ifdef HWPLIB_DLL
+//# define DLLEXPORT __declspec(dllexport)
+# define DLLEXPORT
+#else
+//# define DLLEXPORT __declspec(dllimport)
+# define DLLEXPORT
+#endif
+#else
+# define DLLEXPORT
+#endif
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#ifdef _WIN32
+# include <direct.h>
+# include <io.h>
+# define access _access
+# define stat _stat
+# define mkdir(x,y) _mkdir(x)
+# define rmdir _rmdir
+# define open _open
+# define write _write
+# define close _close
+# define unlink _unlink
+# define DIRSEP '\\'
+#else
+# include <unistd.h>
+# define DIRSEP '/'
+#endif
+#endif // INCLUDED_HWPFILTER_SOURCE_HWPLIB_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx
new file mode 100644
index 000000000..a77f380b5
--- /dev/null
+++ b/hwpfilter/source/hwpread.cxx
@@ -0,0 +1,930 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "precompile.h"
+
+#include <comphelper/newarray.hxx>
+#include <unotools/configmgr.hxx>
+#include <tools/long.hxx>
+
+#include <assert.h>
+
+#include "hwpfile.h"
+#include "hbox.h"
+#include "hpara.h"
+#include "drawing.h"
+#include "htags.h"
+#include "hcode.h"
+
+static short fboxnum = 1;
+static int zindex = 1;
+static int lnnumber = 0;
+
+bool HBox::Read(HWPFile & )
+{
+ // already read
+ return true;
+}
+
+// skip block
+bool SkipData::Read(HWPFile & hwpf)
+{
+ uint data_block_len;
+ hwpf.Read4b(data_block_len);
+
+ hchar dummy;
+ if (!hwpf.Read2b(dummy))
+ return hwpf.SetState(HWP_InvalidFileFormat);
+
+ if (!(IS_SP_SKIP_BLOCK(hh) && (hh == dummy))){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ return hwpf.SkipBlock(data_block_len);
+}
+
+// Field code(5)
+bool FieldCode::Read(HWPFile & hwpf)
+{
+ uint size;
+ hchar dummy;
+ uint len1; /* Length of hchar type string DATA #1 */
+ uint len2; /* Length of hchar type string DATA #2 */
+ uint len3; /* Length of hchar type string DATA #3 */
+ uint binlen; /* Length of any binary data format */
+
+ hwpf.Read4b(size);
+ if (!hwpf.Read2b(dummy))
+ return false;
+ hwpf.ReadBlock(&type, 2);
+ hwpf.ReadBlock(reserved1.data(), 4);
+ if (!hwpf.Read2b(location_info))
+ return false;
+ hwpf.ReadBlock(reserved2.data(), 22);
+ hwpf.Read4b(len1);
+ hwpf.Read4b(len2);
+ hwpf.Read4b(len3);
+ if (!hwpf.Read4b(binlen))
+ return false;
+
+ uint const len1_ = std::min<uint>(len1, 1024) / sizeof(hchar);
+ uint const len2_ = std::min<uint>(len2, 1024) / sizeof(hchar);
+ uint const len3_ = std::min<uint>(len3, 1024) / sizeof(hchar);
+
+ str1.reset( new hchar[len1_ ? len1_ : 1] );
+ str2.reset( new hchar[len2_ ? len2_ : 1] );
+ str3.reset( new hchar[len3_ ? len3_ : 1] );
+
+ if (hwpf.Read2b(str1.get(), len1_) != len1_)
+ return false;
+ hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
+ str1[len1_ ? (len1_ - 1) : 0] = 0;
+ if (hwpf.Read2b(str2.get(), len2_) != len2_)
+ return false;
+ hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
+ str2[len2_ ? (len2_ - 1) : 0] = 0;
+ if (hwpf.Read2b(str3.get(), len3_) != len3_)
+ return false;
+ hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
+ str3[len3_ ? (len3_ - 1) : 0] = 0;
+
+ hwpf.SkipBlock(binlen);
+
+ if( type[0] == 3 && type[1] == 2 ){ /* It must create a format as created date. */
+ DateCode *pDate = new DateCode;
+ for (uint i = 0 ; i < len3_; i++) {
+ if(str3[i] == 0 ) break;
+ if( i >= DATE_SIZE ) break;
+ pDate->format[i] = str3[i];
+ }
+ hwpf.AddDateFormat(pDate);
+ m_pDate.reset( pDate );
+ }
+
+ return true;
+}
+
+// book mark(6)
+bool Bookmark::Read(HWPFile & hwpf)
+{
+ uint len;
+
+ hwpf.Read4b(len);
+ if (!hwpf.Read2b(dummy))
+ return false;
+
+ if (len != 34)// 2 * (BMK_COMMENT_LEN + 1) + 2
+ {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ if (hh != dummy || dummy != CH_BOOKMARK) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ hwpf.Read2b(id, BMK_COMMENT_LEN + 1);
+ hwpf.Read2b(&type, 1);
+ return true;
+}
+
+// date format(7)
+bool DateFormat::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(format, DATE_SIZE);
+ if (!hwpf.Read2b(dummy))
+ return false;
+ if (hh != dummy || CH_DATE_FORM != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return true;
+}
+
+// date code(8)
+bool DateCode::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(format, DATE_SIZE);
+ hwpf.Read2b(date, 6);
+ if (!hwpf.Read2b(dummy))
+ return false;
+ if (hh != dummy || CH_DATE_CODE != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ hwpf.AddDateFormat(this);
+ return true;
+}
+
+// tab(9)
+bool Tab::Read(HWPFile & hwpf)
+{
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return false;
+ width = tmp16;
+ if (!hwpf.Read2b(leader))
+ return false;
+ if (!hwpf.Read2b(dummy))
+ return false;
+ if (hh != dummy || CH_TAB != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return true;
+}
+
+// tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
+static void UpdateBBox(FBox * fbox)
+{
+ fbox->boundsy = fbox->pgy;
+ fbox->boundey = fbox->pgy + fbox->ys - 1;
+}
+
+bool Cell::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&p, 1);
+ hwpf.Read2b(&color, 1);
+ hwpf.Read2b(&x, 1);
+ hwpf.Read2b(&y, 1);
+ hwpf.Read2b(&w, 1);
+ hwpf.Read2b(&h, 1);
+ hwpf.Read2b(&txthigh, 1);
+ hwpf.Read2b(&cellhigh, 1);
+
+ hwpf.Read1b(flag);
+ hwpf.Read1b(changed);
+ hwpf.Read1b(used);
+ hwpf.Read1b(ver_align);
+ hwpf.ReadBlock(linetype, 4);
+ hwpf.Read1b(shade);
+ hwpf.Read1b(diagonal);
+ return hwpf.Read1b(protect);
+}
+
+bool TxtBox::Read(HWPFile & hwpf)
+{
+ int ii, ncell;
+
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy || CH_TEXT_BOX != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ hwpf.Read2b(&style.cap_len, 1);
+ hwpf.Read2b(&dummy1, 1);
+ unsigned short next;
+ hwpf.Read2b(&next, 1);
+ hwpf.Read2b(&dummy2, 1);
+
+ style.boxnum = fboxnum++;
+ zorder = zindex++;
+ hwpf.Read1b(style.anchor_type);
+ hwpf.Read1b(style.txtflow);
+ hwpf.Read2b(&style.xpos, 1);
+ hwpf.Read2b(&style.ypos, 1);
+ hwpf.Read2b(&option, 1);
+ hwpf.Read2b(&ctrl_ch, 1);
+ hwpf.Read2b(style.margin, 12);
+ hwpf.Read2b(&box_xs, 1);
+ hwpf.Read2b(&box_ys, 1);
+ hwpf.Read2b(&cap_xs, 1);
+ hwpf.Read2b(&cap_ys, 1);
+ hwpf.Read2b(&style.cap_len, 1);
+ hwpf.Read2b(&xs, 1);
+ hwpf.Read2b(&ys, 1);
+ hwpf.Read2b(&cap_margin, 1);
+ hwpf.Read1b(xpos_type);
+ hwpf.Read1b(ypos_type);
+ hwpf.Read1b(smart_linesp);
+ hwpf.Read1b(reserved1);
+ hwpf.Read2b(&pgx, 1);
+ hwpf.Read2b(&pgy, 1);
+ hwpf.Read2b(&pgno, 1);
+ if( ( pgno +1 ) != hwpf.getCurrentPage() )
+ pgno = sal::static_int_cast<short>(hwpf.getCurrentPage() -1) ;
+
+ hwpf.Read2b(&showpg, 1);
+ hwpf.Read2b(&cap_pos, 1);
+ hwpf.Read2b(&num, 1);
+ hwpf.Read2b(&dummy3, 1);
+ hwpf.Read2b(&baseline, 1);
+ hwpf.Read2b(&type, 1);
+ hwpf.Read2b(&nCell, 1);
+ hwpf.Read2b(&protect, 1);
+ switch (type)
+ {
+ case 0: //table
+ style.boxtype = 'T';
+ break;
+ case 1: // text-box
+ style.boxtype = 'X';
+ break;
+ case 2: // equation
+ style.boxtype = 'E';
+ break;
+ case 3: // button
+ style.boxtype = 'B';
+ break;
+ default: // other
+ style.boxtype = 'O';
+ break;
+ }
+
+ UpdateBBox(this);
+
+ ncell = nCell;
+ if (ncell <= 0) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ if (ncell > 4096 && utl::ConfigManager::IsFuzzing()) {
+ // cut off at an arbitrary size to speed up fuzzing
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ cell.reset( ::comphelper::newArray_null<Cell>(ncell) );
+ if (!cell) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ bool bSuccess = true;
+ for (ii = 0; ii < ncell && bSuccess; ii++)
+ {
+ bSuccess = cell[ii].Read(hwpf);
+ cell[ii].key = sal::static_int_cast<unsigned char>(ii);
+ }
+ if (!bSuccess)
+ return false;
+ if (ncell == 1)
+ style.cell = &cell[0];
+ plists.resize(ncell);
+ for (ii = 0; ii < ncell; ii++)
+ hwpf.ReadParaList(plists[ii]);
+ // caption
+ hwpf.ReadParaList(caption);
+
+ if( type == 0 ){ // if table?
+ std::unique_ptr<TCell*[]> pArr(new TCell*[ncell]);
+ std::fill(pArr.get(), pArr.get() + ncell, nullptr);
+ if (!pArr) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ std::unique_ptr<Table> tbl(new Table);
+ for( ii = 0 ; ii < ncell; ii++)
+ {
+ tbl->columns.insert(cell[ii].x);
+ tbl->columns.insert(cell[ii].x + cell[ii].w);
+ tbl->rows.insert(cell[ii].y);
+ tbl->rows.insert(cell[ii].y + cell[ii].h);
+ }
+ for( ii = 0 ; ii < ncell; ii++)
+ {
+ TCell *tcell = new TCell;
+ tcell->nColumnIndex = tbl->columns.getIndex(cell[ii].x);
+ tcell->nColumnSpan = tbl->columns.getIndex(cell[ii].x + cell[ii].w) -
+ tcell->nColumnIndex;
+ tcell->nRowIndex = tbl->rows.getIndex(cell[ii].y);
+ tcell->nRowSpan = tbl->rows.getIndex(cell[ii].y + cell[ii].h) -
+ tcell->nRowIndex;
+ tcell->pCell = &cell[ii];
+ pArr[ii] = tcell;
+ }
+
+ // Sort by row and column
+ for( ii = 0 ; ii < ncell - 1; ii++ ){
+ for( int jj = ii ; jj < ncell ; jj++){
+ if( pArr[ii]->nRowIndex > pArr[jj]->nRowIndex ){
+ std::swap(pArr[ii], pArr[jj]);
+ }
+ }
+ for( int kk = ii ; kk > 0 ; kk--){
+ if( ( pArr[kk]->nRowIndex == pArr[kk-1]->nRowIndex ) &&
+ (pArr[kk]->nColumnIndex < pArr[kk-1]->nColumnIndex )){
+ std::swap(pArr[kk], pArr[kk-1]);
+ }
+ }
+ }
+ for( ii = 0 ; ii < ncell ; ii++ ){
+ tbl->cells.emplace_back(pArr[ii]);
+ }
+ tbl->box = this;
+ m_pTable = tbl.get();
+ hwpf.AddTable(std::move(tbl));
+ }
+ else
+ m_pTable = nullptr;
+
+ bSuccess = !hwpf.State();
+ if (bSuccess)
+ hwpf.AddFBoxStyle(&style);
+ return bSuccess;
+}
+
+namespace
+{
+ class ChangeMemGuard
+ {
+ private:
+ HIODev* m_pOldMem;
+ std::unique_ptr<HMemIODev> m_xNewMem;
+ public:
+ ChangeMemGuard(unsigned char* data, size_t nLen)
+ : m_pOldMem(hmem)
+ , m_xNewMem(std::make_unique<HMemIODev>(reinterpret_cast<char*>(data), nLen))
+ {
+ hmem = m_xNewMem.get();
+ }
+ ~ChangeMemGuard()
+ {
+ assert(hmem == m_xNewMem.get());
+ hmem = m_pOldMem;
+ }
+ };
+}
+
+// picture(11)
+bool Picture::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy || CH_PICTURE != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ hwpf.Read4b(follow_block_size);
+
+ //when fuzzing with a max len set, max decompress to 10 times that limit
+ static size_t nMaxAllowedDecompression = [](const char* pEnv) { size_t nRet = pEnv ? std::atoi(pEnv) : 0; return nRet * 10; }(std::getenv("FUZZ_MAX_INPUT_LEN"));
+
+ hwpf.Read2b(&dummy1, 1); /* Reserved 4 bytes */
+ hwpf.Read2b(&dummy2, 1);
+
+ style.boxnum = fboxnum++;
+ zorder = zindex++;
+ hwpf.Read1b(style.anchor_type); /* Reference position */
+ hwpf.Read1b(style.txtflow); /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
+ hwpf.Read2b(&style.xpos, 1); /* Horizontal position: 1=left, 2=right, 3=center, and others=any */
+ hwpf.Read2b(&style.ypos, 1); /* Vertical position: 1=top, 2=down, 3=middle, and others=any */
+ hwpf.Read2b(&option, 1); /* Other options: Borders, reverse picture, and so on. Save as bit. */
+ hwpf.Read2b(&ctrl_ch, 1); /* Always 11 */
+ hwpf.Read2b(style.margin, 12); /* Margin: [0-2] [] out / in / cell, [], [0-3] left / right / top / bottom margins */
+ hwpf.Read2b(&box_xs, 1); /* Box Size Width */
+ hwpf.Read2b(&box_ys, 1); /* Vertical */
+ hwpf.Read2b(&cap_xs, 1); /* Caption Size Width */
+ hwpf.Read2b(&cap_ys, 1); /* Vertical */
+ hwpf.Read2b(&style.cap_len, 1); /* Length */
+ hwpf.Read2b(&xs, 1); /* The total size (box size + caption + margin) Horizontal */
+ hwpf.Read2b(&ys, 1); /* Vertical */
+ hwpf.Read2b(&cap_margin, 1); /* Caption margins */
+ hwpf.Read1b(xpos_type);
+ hwpf.Read1b(ypos_type);
+ hwpf.Read1b(smart_linesp); /* Line Spacing protection: 0 unprotected 1 protected */
+ hwpf.Read1b(reserved1);
+ hwpf.Read2b(&pgx, 1); /* Real Calculated box width */
+ hwpf.Read2b(&pgy, 1); /* Height */
+ hwpf.Read2b(&pgno, 1); /* Page number: starts from 0 */
+ hwpf.Read2b(&showpg, 1); /* Show the Box */
+ hwpf.Read2b(&cap_pos, 1); /* Caption positions 0-7 Menu Order. */
+ hwpf.Read2b(&num, 1); /* Box number, serial number which starts from 0 */
+
+ hwpf.Read1b(pictype); /* Picture type */
+
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16)) /* the real horizontal starting point where shows the picture */
+ return false;
+ skip[0] = tmp16;
+ if (!hwpf.Read2b(tmp16)) /* Vertical */
+ return false;
+ skip[1] = tmp16;
+ if (!hwpf.Read2b(tmp16)) /* Zoom Ratio: 0:fixed, others are percentage for horizontal */
+ return false;
+ scale[0] = tmp16;
+ if (!hwpf.Read2b(tmp16)) /* Vertical */
+ return false;
+ scale[1] = tmp16;
+
+ hwpf.ReadBlock(picinfo.picun.path, 256); /* Picture File Name: when type is not a Drawing. */
+ picinfo.picun.path[255] = 0; // ensure null terminated
+ hwpf.ReadBlock(reserved3, 9); /* Brightness / Contrast / Picture Effect, etc. */
+
+ UpdateBBox(this);
+ if( pictype != PICTYPE_DRAW )
+ style.cell = reserved3;
+ else
+ {
+ //picinfo.picun read above is unioned with
+ //picinfo.picdraw and so wrote to the hdo pointer
+ //value, which is definitely not useful to us
+ picinfo.picdraw.hdo = nullptr;
+ }
+
+ if (follow_block_size != 0)
+ {
+ follow.clear();
+
+ //read potentially compressed data in blocks as it's more
+ //likely large values are simply broken and we'll run out
+ //of data before we need to realloc
+ for (size_t i = 0; i < follow_block_size; i+= SAL_N_ELEMENTS(hwpf.scratch))
+ {
+ size_t nOldSize = follow.size();
+ size_t nBlock = std::min(SAL_N_ELEMENTS(hwpf.scratch), follow_block_size - nOldSize);
+ size_t nReadBlock = hwpf.ReadBlock(hwpf.scratch, nBlock);
+ if (nReadBlock)
+ {
+ follow.insert(follow.end(), hwpf.scratch, hwpf.scratch + nReadBlock);
+ }
+ if (nBlock != nReadBlock)
+ break;
+ if (nMaxAllowedDecompression && follow.size() > nMaxAllowedDecompression)
+ break;
+ }
+ follow_block_size = follow.size();
+
+ if (pictype == PICTYPE_DRAW)
+ {
+ auto xGuard(std::make_unique<ChangeMemGuard>(follow.data(), follow_block_size));
+ LoadDrawingObjectBlock(this, hwpf);
+ style.cell = picinfo.picdraw.hdo;
+ xGuard.reset();
+ }
+ else if (follow_block_size >= 4)
+ {
+ if ((follow[3] << 24 | follow[2] << 16 | follow[1] << 8 | follow[0]) == 0x269)
+ {
+ ishyper = true;
+ }
+ }
+ }
+
+ if( pictype != 3 )
+ style.boxtype = 'G';
+ else
+ style.boxtype = 'D';
+
+// caption
+ hwpf.ReadParaList(caption);
+
+ bool bSuccess = !hwpf.State();
+ if (bSuccess)
+ hwpf.AddFBoxStyle(&style);
+ return bSuccess;
+}
+
+// line(15)
+Line::Line()
+ : FBox(CH_LINE)
+ , dummy(0)
+ , sx(0)
+ , sy(0)
+ , ex(0)
+ , ey(0)
+ , width(0)
+ , shade(0)
+ , color(0)
+{
+}
+
+bool Line::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy || CH_LINE != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ style.boxnum = fboxnum++;
+ zorder = zindex++;
+ style.boxtype = 'L';
+ hwpf.ReadBlock(&reserved2, 8);
+ hwpf.Read1b(style.anchor_type);
+ hwpf.Read1b(style.txtflow);
+ hwpf.Read2b(&style.xpos, 1);
+ hwpf.Read2b(&style.ypos, 1);
+ hwpf.Read2b(&option, 1);
+ hwpf.Read2b(&ctrl_ch, 1);
+ hwpf.Read2b(style.margin, 12);
+ hwpf.Read2b(&box_xs, 1);
+ hwpf.Read2b(&box_ys, 1);
+ hwpf.Read2b(&cap_xs, 1);
+ hwpf.Read2b(&cap_ys, 1);
+ hwpf.Read2b(&style.cap_len, 1);
+ hwpf.Read2b(&xs, 1);
+ hwpf.Read2b(&ys, 1);
+ lnnumber = style.boxnum;
+ hwpf.linenumber = 1;
+ hwpf.Read2b(&boundsy, 1);
+ hwpf.Read2b(&boundey, 1);
+ hwpf.Read1b(boundx);
+ hwpf.Read1b(draw);
+
+ hwpf.Read2b(&pgx, 1);
+ hwpf.Read2b(&pgy, 1);
+ hwpf.Read2b(&pgno, 1);
+ hwpf.Read2b(&showpg, 1);
+
+ hwpf.Read2b(&sx, 1);
+ hwpf.Read2b(&sy, 1);
+ hwpf.Read2b(&ex, 1);
+ hwpf.Read2b(&sy, 1);
+ hwpf.Read2b(&width, 1);
+ hwpf.Read2b(&shade, 1);
+ hwpf.Read2b(&color, 1);
+ style.xpos = width;
+
+ bool bSuccess = !hwpf.State();
+ if (bSuccess)
+ hwpf.AddFBoxStyle(&style);
+ return bSuccess;
+}
+
+// hidden(15)
+Hidden::Hidden()
+ : HBox(CH_HIDDEN)
+ , dummy(0)
+{
+}
+
+bool Hidden::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+ if (hh != dummy || CH_HIDDEN != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ hwpf.ReadBlock(info, 8);
+ hwpf.ReadParaList(plist);
+
+ return !hwpf.State();
+}
+
+// header/footer(16)
+HeaderFooter::HeaderFooter()
+ : HBox(CH_HEADER_FOOTER)
+ , dummy(0)
+ , type(0)
+ , where(0)
+ , linenumber(0)
+ , m_nPageNumber(0)
+{
+}
+
+bool HeaderFooter::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+ if (hh != dummy || CH_HEADER_FOOTER != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ hwpf.ReadBlock(info, 8);
+ hwpf.Read1b(type);
+ hwpf.Read1b(where);
+ lnnumber = 0;
+ hwpf.ReadParaList(plist, CH_HEADER_FOOTER);
+ linenumber = sal::static_int_cast<unsigned char>(lnnumber);
+ m_nPageNumber = hwpf.getCurrentPage();
+ hwpf.setMaxSettedPage();
+ hwpf.AddHeaderFooter(this);
+
+ return !hwpf.State();
+}
+
+
+// footnote(17)
+Footnote::Footnote()
+ : HBox(CH_FOOTNOTE)
+ , dummy(0)
+ , number(0)
+ , type(0)
+ , width(0)
+{
+}
+
+bool Footnote::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(reserved, 2);
+ hwpf.Read2b(&dummy, 1);
+ if (hh != dummy || CH_FOOTNOTE != dummy) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+
+ hwpf.ReadBlock(info, 8);
+ hwpf.Read2b(&number, 1);
+ hwpf.Read2b(&type, 1);
+ unsigned short tmp16;
+ if (!hwpf.Read2b(tmp16))
+ return false;
+ width = tmp16;
+ hwpf.ReadParaList(plist, CH_FOOTNOTE);
+
+ return !hwpf.State();
+}
+
+// auto number(18)
+AutoNum::AutoNum()
+ : HBox(CH_AUTO_NUM)
+ , type(0)
+ , number(0)
+ , dummy(0)
+{
+}
+
+bool AutoNum::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&type, 1);
+ hwpf.Read2b(&number, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+
+// new number(19)
+NewNum::NewNum()
+ : HBox(CH_NEW_NUM)
+ , type(0)
+ , number(0)
+ , dummy(0)
+{
+}
+
+
+bool NewNum::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&type, 1);
+ hwpf.Read2b(&number, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// show page number (20)
+ShowPageNum::ShowPageNum()
+ : HBox(CH_SHOW_PAGE_NUM)
+ , where(0)
+ , m_nPageNumber(0)
+ , shape(0)
+ , dummy(0)
+{
+}
+
+bool ShowPageNum::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&where, 1);
+ hwpf.Read2b(&shape, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ m_nPageNumber = hwpf.getCurrentPage();
+ hwpf.setMaxSettedPage();
+ hwpf.AddPageNumber(this);
+ return !hwpf.State();
+}
+
+/* 홀수쪽시작/감추기 (21) */
+PageNumCtrl::PageNumCtrl()
+ : HBox(CH_PAGE_NUM_CTRL)
+ , kind(0)
+ , what(0)
+ , dummy(0)
+{
+}
+
+bool PageNumCtrl::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&kind, 1);
+ hwpf.Read2b(&what, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// mail merge(22)
+MailMerge::MailMerge()
+ : HBox(CH_MAIL_MERGE)
+ , dummy(0)
+{
+}
+
+bool MailMerge::Read(HWPFile & hwpf)
+{
+ hwpf.ReadBlock(field_name, 20);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// char composition(23)
+Compose::Compose()
+ : HBox(CH_COMPOSE)
+ , dummy(0)
+{
+}
+
+bool Compose::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(compose, 3);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// hyphen(24)
+Hyphen::Hyphen()
+ : HBox(CH_HYPHEN)
+ , width(0)
+ , dummy(0)
+{
+}
+
+bool Hyphen::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&width, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+
+// toc mark(25)
+TocMark::TocMark()
+ : HBox(CH_TOC_MARK)
+ , kind(0)
+ , dummy(0)
+{
+}
+
+
+bool TocMark::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&kind, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// index mark(26)
+IndexMark::IndexMark()
+ : HBox(CH_INDEX_MARK)
+ , pgno(0)
+ , dummy(0)
+{
+}
+
+bool IndexMark::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&keyword1, 60);
+ hwpf.Read2b(&keyword2, 60);
+ hwpf.Read2b(&pgno, 1);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+// outline(28)
+Outline::Outline()
+ : HBox(CH_OUTLINE)
+ , kind(0)
+ , shape(0)
+ , level(0)
+ , dummy(0)
+{
+}
+
+bool Outline::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&kind, 1);
+ hwpf.Read1b(shape);
+ hwpf.Read1b(level);
+ hwpf.Read2b(number, 7);
+ hwpf.Read2b(user_shape, 7);
+ hwpf.Read2b(deco, 14);
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+
+/* Bundle of spaces (30)*/
+KeepSpace::KeepSpace()
+ : HBox(CH_KEEP_SPACE)
+ , dummy(0)
+{
+}
+
+
+bool KeepSpace::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+
+/* Fixed-width spaces (31) */
+FixedSpace::FixedSpace()
+ : HBox(CH_FIXED_SPACE)
+ , dummy(0)
+{
+}
+
+
+bool FixedSpace::Read(HWPFile & hwpf)
+{
+ hwpf.Read2b(&dummy, 1);
+
+ if (hh != dummy){
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
+ return !hwpf.State();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
new file mode 100644
index 000000000..87c2e6412
--- /dev/null
+++ b/hwpfilter/source/hwpreader.cxx
@@ -0,0 +1,4816 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <deque>
+#include <memory>
+#include <string_view>
+
+#include "hwpreader.hxx"
+#include <cmath>
+
+#include <o3tl/safeint.hxx>
+#include <osl/diagnose.h>
+#include <tools/stream.hxx>
+#include <basegfx/numeric/ftools.hxx>
+#include <basegfx/point/b2dpoint.hxx>
+#include <unotools/configmgr.hxx>
+
+#include "fontmap.hxx"
+#include "formula.h"
+#include "cspline.h"
+#include "datecode.h"
+
+#include <iostream>
+#include <locale.h>
+#include <sal/types.h>
+#include <rtl/character.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <sal/log.hxx>
+
+// xmloff/xmlkyd.hxx
+constexpr OUStringLiteral sXML_CDATA = u"CDATA";
+
+namespace
+{
+double WTI(double x) { return x / 1800.; } // unit => inch
+double WTMM(double x) { return x / 1800. * 25.4; } // unit => mm
+int WTSM(double x) { return x / 1800. * 2540; } // unit ==> 1/100 mm
+
+constexpr OUStringLiteral sBeginOfDoc(u"[\uBB38\uC11C\uC758 \uCC98\uC74C]");
+ // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO,
+ // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO,
+ // U+C74C HANGUL SYLLABLE EUM: "Begin of Document"
+}
+
+struct HwpReaderPrivate
+{
+ HwpReaderPrivate()
+ {
+ bFirstPara = true;
+ bInBody = false;
+ bInHeader = false;
+ nPnPos = 0;
+ pPn = nullptr;
+ pField = nullptr;
+ }
+ bool bFirstPara;
+ bool bInBody;
+ bool bInHeader;
+ ShowPageNum *pPn;
+ hchar *pField;
+ int nPnPos;
+ char buf[1024];
+};
+
+HwpReader::HwpReader() : mxList(new AttributeListImpl), d(new HwpReaderPrivate)
+{
+}
+
+
+HwpReader::~HwpReader()
+{
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportHWP(SvStream &rStream)
+{
+ try
+ {
+ std::unique_ptr<HStream> stream(new HStream);
+ byte aData[32768];
+
+ while (true)
+ {
+ std::size_t nRead = rStream.ReadBytes(aData, 32768);
+ if (nRead == 0)
+ break;
+ stream->addData(aData, static_cast<int>(nRead));
+ }
+
+ rtl::Reference<HwpReader> hwpreader(new HwpReader);
+ return hwpreader->importHStream(std::move(stream));
+ }
+ catch (...)
+ {
+ }
+ return false;
+}
+
+bool HwpReader::importHStream(std::unique_ptr<HStream> stream)
+{
+ if (hwpfile.ReadHwpFile(std::move(stream)))
+ return false;
+
+ if (m_rxDocumentHandler.is())
+ m_rxDocumentHandler->startDocument();
+
+ mxList->addAttribute("office:class", sXML_CDATA, "text");
+ mxList->addAttribute("office:version", sXML_CDATA, "0.9");
+
+ mxList->addAttribute("xmlns:office", "CDATA", "http://openoffice.org/2000/office");
+ mxList->addAttribute("xmlns:style", "CDATA", "http://openoffice.org/2000/style");
+ mxList->addAttribute("xmlns:text", "CDATA", "http://openoffice.org/2000/text");
+ mxList->addAttribute("xmlns:table", "CDATA", "http://openoffice.org/2000/table");
+ mxList->addAttribute("xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing");
+ mxList->addAttribute("xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format");
+ mxList->addAttribute("xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink");
+ mxList->addAttribute("xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/");
+ mxList->addAttribute("xmlns:meta", "CDATA", "http://openoffice.org/2000/meta");
+ mxList->addAttribute("xmlns:number", "CDATA", "http://openoffice.org/2000/datastyle");
+ mxList->addAttribute("xmlns:svg", "CDATA", "http://www.w3.org/2000/svg");
+ mxList->addAttribute("xmlns:chart", "CDATA", "http://openoffice.org/2000/chart");
+ mxList->addAttribute("xmlns:dr3d", "CDATA", "http://openoffice.org/2000/dr3d");
+ mxList->addAttribute("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML");
+ mxList->addAttribute("xmlns:form", "CDATA", "http://openoffice.org/2000/form");
+ mxList->addAttribute("xmlns:script", "CDATA", "http://openoffice.org/2000/script");
+
+ startEl("office:document");
+ mxList->clear();
+
+ makeMeta();
+ makeStyles();
+ makeAutoStyles();
+ makeMasterStyles();
+ makeBody();
+
+ endEl("office:document");
+
+ if (m_rxDocumentHandler.is())
+ m_rxDocumentHandler->endDocument();
+ return true;
+}
+
+sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor)
+{
+ utl::MediaDescriptor aDescriptor(rDescriptor);
+ aDescriptor.addInputStream();
+
+ Reference< XInputStream > xInputStream(
+ aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM], UNO_QUERY_THROW);
+
+ std::unique_ptr<HStream> stream(new HStream);
+ Sequence < sal_Int8 > aBuffer;
+ sal_Int32 nRead, nTotal = 0;
+ while( true )
+ {
+ nRead = xInputStream->readBytes(aBuffer, 32768);
+ if( nRead == 0 )
+ break;
+ stream->addData( reinterpret_cast<const byte *>(aBuffer.getConstArray()), nRead );
+ nTotal += nRead;
+ }
+
+ if( nTotal == 0 ) return false;
+
+ return importHStream(std::move(stream));
+}
+
+/**
+ * make office:body
+ */
+void HwpReader::makeBody()
+{
+ startEl("office:body");
+ makeTextDecls();
+ HWPPara *hwppara = hwpfile.GetFirstPara();
+ d->bInBody = true;
+ parsePara(hwppara);
+ endEl("office:body");
+ d->bInBody = false;
+}
+
+
+/**
+ * make text decls
+ */
+void HwpReader::makeTextDecls()
+{
+ startEl("text:sequence-decls");
+ mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0");
+ mxList->addAttribute("text:name", sXML_CDATA, "Illustration");
+ startEl("text:sequence-decl");
+ mxList->clear();
+ endEl("text:sequence-decl");
+ mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0");
+ mxList->addAttribute("text:name", sXML_CDATA, "Table");
+ startEl("text:sequence-decl");
+ mxList->clear();
+ endEl("text:sequence-decl");
+ mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0");
+ mxList->addAttribute("text:name", sXML_CDATA, "Text");
+ startEl("text:sequence-decl");
+ mxList->clear();
+ endEl("text:sequence-decl");
+ mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0");
+ mxList->addAttribute("text:name", sXML_CDATA, "Drawing");
+ startEl("text:sequence-decl");
+ mxList->clear();
+ endEl("text:sequence-decl");
+ endEl("text:sequence-decls");
+}
+
+
+/**
+ * make office:meta
+ * Completed
+ */
+void HwpReader::makeMeta()
+{
+ HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
+
+ startEl("office:meta");
+
+ if (hwpinfo.summary.title[0])
+ {
+ startEl("dc:title");
+ chars(hstr2OUString(hwpinfo.summary.title));
+ endEl("dc:title");
+ }
+
+ if (hwpinfo.summary.subject[0])
+ {
+ startEl("dc:subject");
+ chars(hstr2OUString(hwpinfo.summary.subject));
+ endEl("dc:subject");
+ }
+
+ if (hwpinfo.summary.author[0])
+ {
+ startEl("meta:initial-creator");
+ chars(hstr2OUString(hwpinfo.summary.author));
+ endEl("meta:initial-creator");
+ }
+
+ if (hwpinfo.summary.date[0])
+ {
+ unsigned short *pDate = hwpinfo.summary.date;
+ int year,month,day,hour,minute;
+ int gab = 0;
+ if( rtl::isAsciiDigit( pDate[0] ) && rtl::isAsciiDigit( pDate[1] ) &&
+ rtl::isAsciiDigit( pDate[2] ) && rtl::isAsciiDigit( pDate[3] ))
+ {
+ year = (pDate[0]-0x30) * 1000 + (pDate[1]-0x30) * 100 +
+ (pDate[2]-0x30) * 10 + (pDate[3]-0x30);
+ }
+ else {
+ year = 0;
+ }
+ if( rtl::isAsciiDigit( pDate[6] ))
+ {
+ if( rtl::isAsciiDigit( pDate[7] ) )
+ month = (pDate[6] - 0x30) * 10 + (pDate[6+ ++gab]-0x30);
+ else
+ month = (pDate[6] - 0x30);
+ }
+ else {
+ month = 0;
+ }
+ if( rtl::isAsciiDigit( pDate[9 + gab] ) )
+ {
+ if( rtl::isAsciiDigit( pDate[10 + gab])) {
+ day = ( pDate[9 + gab] - 0x30 ) * 10 + (pDate[9+ gab + 1]-0x30);
+ ++gab;
+ } else
+ day = (pDate[9+gab]-0x30);
+ }
+ else {
+ day = 0;
+ }
+ if( rtl::isAsciiDigit( pDate[17 + gab] ) )
+ {
+ if( rtl::isAsciiDigit( pDate[18 + gab])) {
+ hour = ( pDate[17 + gab] - 0x30 ) * 10 + (pDate[17+ gab + 1]-0x30);
+ ++gab;
+ } else
+ hour = (pDate[17+gab]-0x30);
+ }
+ else {
+ hour = 0;
+ }
+ if( rtl::isAsciiDigit( pDate[20 + gab] ) )
+ {
+ if( rtl::isAsciiDigit( pDate[21 + gab])) {
+ minute = ( pDate[20 + gab] - 0x30 ) * 10 + (pDate[20+ gab + 1]-0x30);
+ ++gab;
+ } else
+ minute = (pDate[20+gab]-0x30);
+ }
+ else {
+ minute = 0;
+ }
+ sprintf(d->buf,"%d-%02d-%02dT%02d:%02d:00",year,month,day,hour,minute);
+
+ startEl("meta:creation-date");
+ chars( OUString::createFromAscii(d->buf));
+ endEl("meta:creation-date");
+ }
+
+ if (hwpinfo.summary.keyword[0][0] || hwpinfo.summary.etc[0][0])
+ {
+ startEl("meta:keywords");
+ if (hwpinfo.summary.keyword[0][0])
+ {
+ startEl("meta:keyword");
+ chars(hstr2OUString(hwpinfo.summary.keyword[0]));
+ endEl("meta:keyword");
+ }
+ if (hwpinfo.summary.keyword[1][0])
+ {
+ startEl("meta:keyword");
+ chars(hstr2OUString(hwpinfo.summary.keyword[1]));
+ endEl("meta:keyword");
+ }
+ if (hwpinfo.summary.etc[0][0])
+ {
+ startEl("meta:keyword");
+ chars(hstr2OUString(hwpinfo.summary.etc[0]));
+ endEl("meta:keyword");
+ }
+ if (hwpinfo.summary.etc[1][0])
+ {
+ startEl("meta:keyword");
+ chars(hstr2OUString(hwpinfo.summary.etc[1]));
+ endEl("meta:keyword");
+ }
+ if (hwpinfo.summary.etc[2][0])
+ {
+ startEl("meta:keyword");
+ chars(hstr2OUString(hwpinfo.summary.etc[2]));
+ endEl("meta:keyword");
+ }
+ endEl("meta:keywords");
+ }
+ endEl("office:meta");
+}
+
+
+static struct
+{
+ const char *name;
+ bool bMade;
+}
+ArrowShape[] =
+{
+ { "", false },
+ { "Arrow", false },
+ { "Line Arrow", false },
+ { "Square", false }
+};
+
+struct
+{
+ double dots1;
+ double dots2;
+ double distance;
+}
+
+
+const LineStyle[] =
+{
+ { 0.0, 0.0, 0.0 },
+ {
+ 0.34, 0., 0.272
+ },
+ { 0.17, 0., 0.136},
+ {
+ 0.612, 0.17, 0.136
+ },
+ { 0.85, 0.17, 0.136}
+};
+
+void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
+{
+ while( hdo )
+ {
+ if( hdo->child )
+ makeDrawMiscStyle( hdo->child.get() );
+
+ HWPDOProperty *prop = &hdo->property;
+ if( hdo->type == HWPDO_CONTAINER )
+ {
+ hdo = hdo->next.get();
+ continue;
+ }
+
+ if( prop->line_pstyle > 0 && prop->line_pstyle < 5 && prop->line_color <= 0xffffff)
+ {
+ mxList->addAttribute( "draw:name", sXML_CDATA, "LineType" + OUString::number(hdo->index));
+ mxList->addAttribute( "draw:style", sXML_CDATA, "round");
+ mxList->addAttribute( "draw:dots1", sXML_CDATA, "1");
+ mxList->addAttribute( "draw:dots1-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots1 * WTMM(prop->line_width) ) + "cm");
+ if( prop->line_pstyle == 3 )
+ {
+ mxList->addAttribute( "draw:dots2", sXML_CDATA, "1");
+ mxList->addAttribute( "draw:dots2-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width) ) + "cm");
+ }
+ else if( prop->line_pstyle == 4 )
+ {
+ mxList->addAttribute( "draw:dots2", sXML_CDATA, "2");
+ mxList->addAttribute( "draw:dots2-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width)) + "cm");
+ }
+ mxList->addAttribute( "draw:distance", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].distance * WTMM(prop->line_width)) + "cm");
+ startEl("draw:stroke-dash");
+ mxList->clear();
+ endEl("draw:stroke-dash");
+ }
+
+ if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC || hdo->type == HWPDO_FREEFORM ||
+ hdo->type == HWPDO_ADVANCED_ARC )
+ {
+ if( prop->line_tstyle > 0 &&
+ o3tl::make_unsigned(prop->line_tstyle) < std::size(ArrowShape) &&
+ !ArrowShape[prop->line_tstyle].bMade )
+ {
+ ArrowShape[prop->line_tstyle].bMade = true;
+ mxList->addAttribute("draw:name", sXML_CDATA,
+ OUString::createFromAscii(ArrowShape[prop->line_tstyle].name));
+ if( prop->line_tstyle == 1 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 30");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m10 0-10 30h20z");
+ }
+ else if( prop->line_tstyle == 2 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 1122 2243");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z");
+ }
+ else if( prop->line_tstyle == 3 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 30 30");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m0 0h30v30h-30z");
+ }
+ startEl("draw:marker");
+ mxList->clear();
+ endEl("draw:marker");
+ }
+ if (prop->line_hstyle > 0 &&
+ o3tl::make_unsigned(prop->line_hstyle) < std::size(ArrowShape) &&
+ !ArrowShape[prop->line_hstyle].bMade)
+ {
+ ArrowShape[prop->line_hstyle].bMade = true;
+ mxList->addAttribute("draw:name", sXML_CDATA,
+ OUString::createFromAscii(ArrowShape[prop->line_hstyle].name));
+ if( prop->line_hstyle == 1 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 30");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m10 0-10 30h20z");
+ }
+ else if( prop->line_hstyle == 2 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 1122 2243");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z");
+ }
+ else if( prop->line_hstyle == 3 )
+ {
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 20");
+ mxList->addAttribute("svg:d", sXML_CDATA, "m0 0h20v20h-20z");
+ }
+ startEl("draw:marker");
+ mxList->clear();
+ endEl("draw:marker");
+ }
+ }
+
+ if( hdo->type != HWPDO_LINE )
+ {
+ if( prop->flag >> 18 & 0x01 )
+ {
+ mxList->addAttribute( "draw:name", sXML_CDATA, "fillimage" + OUString::number(hdo->index));
+
+ EmPicture *emp = nullptr;
+ if (prop->pictype && strlen(prop->szPatternFile) > 3)
+ emp = hwpfile.GetEmPictureByName(prop->szPatternFile);
+ if (!emp)
+ {
+ mxList->addAttribute( "xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str()));
+ mxList->addAttribute( "xlink:type", sXML_CDATA, "simple");
+ mxList->addAttribute( "xlink:show", sXML_CDATA, "embed");
+ mxList->addAttribute( "xlink:actuate", sXML_CDATA, "onLoad");
+ }
+
+ startEl("draw:fill-image");
+ mxList->clear();
+ if (emp)
+ {
+ startEl("office:binary-data");
+ chars(base64_encode_string(emp->data.get(), emp->size));
+ endEl("office:binary-data");
+ }
+ endEl("draw:fill-image");
+ }
+/* If there is a gradient, when a bitmap file is present, this is the first. */
+ else if( prop->flag >> 16 & 0x01 ) /* existence gradient */
+ {
+ mxList->addAttribute( "draw:name", sXML_CDATA, "Grad" + OUString::number(hdo->index));
+ switch( prop->gstyle )
+ {
+ case 1 :
+ if( prop->center_y == 50 )
+ mxList->addAttribute( "draw:style", sXML_CDATA, "axial");
+ else
+ mxList->addAttribute( "draw:style", sXML_CDATA, "linear");
+ break;
+ case 2:
+ case 3:
+ mxList->addAttribute( "draw:style", sXML_CDATA, "radial");
+ break;
+ case 4:
+ mxList->addAttribute( "draw:style", sXML_CDATA, "square");
+ break;
+ default:
+ mxList->addAttribute( "draw:style", sXML_CDATA, "linear");
+ break;
+ }
+ mxList->addAttribute( "draw:cx", sXML_CDATA, OUString::number(prop->center_x) + "%");
+ mxList->addAttribute( "draw:cy", sXML_CDATA, OUString::number(prop->center_y) + "%");
+
+ HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
+ int default_color = 0xffffff;
+ if( hwpinfo.back_info.isset )
+ {
+ if( hwpinfo.back_info.color[0] > 0 || hwpinfo.back_info.color[1] > 0
+ || hwpinfo.back_info.color[2] > 0 )
+ default_color = hwpinfo.back_info.color[0] << 16 |
+ hwpinfo.back_info.color[1] << 8 | hwpinfo.back_info.color[2];
+ }
+
+ if( prop->fromcolor > 0xffffff )
+ prop->fromcolor = default_color;
+ if( prop->tocolor > 0xffffff )
+ prop->tocolor = default_color;
+
+ if( prop->gstyle == 1)
+ {
+ if( prop->center_y == 100 )
+ {
+ mxList->addAttribute( "draw:start-color", sXML_CDATA, rgb2str( prop->tocolor ));
+ mxList->addAttribute( "draw:end-color", sXML_CDATA, rgb2str( prop->fromcolor ));
+ }
+ else
+ {
+ mxList->addAttribute( "draw:start-color", sXML_CDATA, rgb2str( prop->fromcolor ));
+ mxList->addAttribute( "draw:end-color", sXML_CDATA, rgb2str( prop->tocolor ));
+ }
+ }
+ else
+ {
+ mxList->addAttribute( "draw:start-color", sXML_CDATA,rgb2str( prop->tocolor ));
+ mxList->addAttribute( "draw:end-color", sXML_CDATA,rgb2str( prop->fromcolor ));
+ }
+ if( prop->angle > 0 && ( prop->gstyle == 1 || prop->gstyle == 4))
+ {
+ int angle = 1800 - prop->angle * 10;
+ mxList->addAttribute( "draw:angle", sXML_CDATA, OUString::number(angle));
+ }
+ startEl("draw:gradient");
+ mxList->clear();
+ endEl("draw:gradient");
+ }
+ /* hatch */
+ else if( prop->pattern_type >> 24 & 0x01 )
+ {
+ int type = prop->pattern_type & 0xffffff;
+ mxList->addAttribute( "draw:name", sXML_CDATA, "Hatch" + OUString::number(hdo->index));
+ if( type < 4 )
+ mxList->addAttribute( "draw:style", sXML_CDATA, "single" );
+ else
+ mxList->addAttribute( "draw:style", sXML_CDATA, "double" );
+ mxList->addAttribute( "draw:color", sXML_CDATA, rgb2str( static_cast<int32_t>(prop->pattern_color) ));
+ mxList->addAttribute( "draw:distance", sXML_CDATA, "0.12cm");
+ switch( type )
+ {
+ case 0 :
+ case 4 :
+ mxList->addAttribute( "draw:rotation", sXML_CDATA, "0");
+ break;
+ case 1 :
+ mxList->addAttribute( "draw:rotation", sXML_CDATA, "900");
+ break;
+ case 2 :
+ mxList->addAttribute( "draw:rotation", sXML_CDATA, "1350");
+ break;
+ case 3 :
+ case 5 :
+ mxList->addAttribute( "draw:rotation", sXML_CDATA, "450");
+ break;
+ }
+ startEl("draw:hatch");
+ mxList->clear();
+ endEl("draw:hatch");
+ }
+ }
+ hdo = hdo->next.get();
+ }
+}
+
+
+void HwpReader::makeStyles()
+{
+ HWPStyle& hwpstyle = hwpfile.GetHWPStyle();
+
+ startEl("office:styles");
+
+ int i;
+ for (i = 0; i < hwpfile.getFBoxStyleCount(); i++)
+ {
+ if( hwpfile.getFBoxStyle(i)->boxtype == 'D' )
+ {
+ makeDrawMiscStyle(static_cast<HWPDrawingObject *>(hwpfile.getFBoxStyle(i)->cell) );
+ }
+ }
+
+ mxList->addAttribute("style:name", sXML_CDATA, "Standard");
+ mxList->addAttribute("style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:class", sXML_CDATA, "text");
+ startEl("style:style");
+ mxList->clear();
+
+ mxList->addAttribute("fo:line-height", sXML_CDATA, "160%");
+ mxList->addAttribute("fo:text-align", sXML_CDATA, "justify");
+ startEl("style:properties");
+ mxList->clear();
+ startEl("style:tab-stops");
+
+ for( i = 1 ; i < 40 ; i++)
+ {
+ mxList->addAttribute("style:position", sXML_CDATA,
+ OUString::number( WTI(1000 * i)) + "inch");
+ startEl("style:tab-stop");
+ mxList->clear();
+ endEl("style:tab-stop");
+ }
+ endEl("style:tab-stops");
+ endEl("style:properties");
+
+ endEl("style:style");
+
+ for (int ii = 0; ii < hwpstyle.Num(); ii++)
+ {
+ unsigned char *stylename = reinterpret_cast<unsigned char *>(hwpstyle.GetName(ii));
+ mxList->addAttribute("style:name", sXML_CDATA, hstr2OUString(kstr2hstr(stylename).c_str()));
+ mxList->addAttribute("style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:parent-style-name", sXML_CDATA, "Standard");
+
+ startEl("style:style");
+
+ mxList->clear();
+
+ parseCharShape(hwpstyle.GetCharShape(ii));
+ parseParaShape(hwpstyle.GetParaShape(ii));
+
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+
+ endEl("style:style");
+ }
+
+ {
+ mxList->addAttribute( "style:name", sXML_CDATA, "Header");
+ mxList->addAttribute( "style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard");
+ mxList->addAttribute( "style:class", sXML_CDATA, "extra");
+ startEl("style:style");
+ mxList->clear();
+ endEl("style:style");
+ }
+
+ {
+ mxList->addAttribute( "style:name", sXML_CDATA, "Footer");
+ mxList->addAttribute( "style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard");
+ mxList->addAttribute( "style:class", sXML_CDATA, "extra");
+ startEl("style:style");
+ mxList->clear();
+
+ endEl("style:style");
+ }
+
+ if( hwpfile.linenumber > 0)
+ {
+ mxList->addAttribute( "style:name", sXML_CDATA, "Horizontal Line");
+ mxList->addAttribute( "style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard");
+ mxList->addAttribute( "style:class", sXML_CDATA, "html");
+ startEl("style:style");
+ mxList->clear();
+ mxList->addAttribute( "fo:font-size", sXML_CDATA, "6pt");
+ mxList->addAttribute( "fo:margin-top", sXML_CDATA, "0cm");
+ mxList->addAttribute( "fo:margin-bottom", sXML_CDATA, "0cm");
+ mxList->addAttribute( "style:border-line-width-bottom", sXML_CDATA, "0.02cm 0.035cm 0.002cm");
+ mxList->addAttribute( "fo:padding", sXML_CDATA, "0cm");
+ mxList->addAttribute( "fo:border-bottom", sXML_CDATA, "0.039cm double #808080");
+ mxList->addAttribute( "text:number-lines", sXML_CDATA, "false");
+ mxList->addAttribute( "text:line-number", sXML_CDATA, "0");
+ mxList->addAttribute("fo:line-height", sXML_CDATA, "100%");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+ }
+
+ HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
+
+ mxList->addAttribute("text:num-suffix", sXML_CDATA, ")");
+ mxList->addAttribute("text:num-format", sXML_CDATA, "1");
+ if( hwpinfo.beginfnnum != 1)
+ mxList->addAttribute("text:offset", sXML_CDATA, OUString::number(hwpinfo.beginfnnum - 1));
+ startEl("text:footnotes-configuration");
+ mxList->clear();
+ endEl("text:footnotes-configuration");
+
+ endEl("office:styles");
+}
+
+
+/**
+ * parse automatic styles from hwpfile
+ * Define a style that is automatically reflected. For example, defining styles of each paragraph, tables, header, and etc,. at here. In Body, use the defined style.
+ * 1. supports for the styles of paragraph, text, fbox, and page.
+ */
+void HwpReader::makeAutoStyles()
+{
+ int i;
+
+ startEl("office:automatic-styles");
+
+ for (i = 0; i < hwpfile.getParaShapeCount(); i++)
+ makePStyle(hwpfile.getParaShape(i));
+
+ for (i = 0; i < hwpfile.getCharShapeCount(); i++)
+ makeTStyle(hwpfile.getCharShape(i));
+
+ for( i = 0 ; i < hwpfile.getTableCount(); i++)
+ makeTableStyle(hwpfile.getTable(i));
+
+ for (i = 0; i < hwpfile.getFBoxStyleCount(); i++)
+ {
+ if( hwpfile.getFBoxStyle(i)->boxtype == 'D' )
+ makeDrawStyle(static_cast<HWPDrawingObject *>(hwpfile.getFBoxStyle(i)->cell), hwpfile.getFBoxStyle(i));
+ else
+ makeFStyle(hwpfile.getFBoxStyle(i));
+ }
+
+ bool bIsLeft = false, bIsMiddle = false, bIsRight = false;
+ for( i = 0 ; i < hwpfile.getPageNumberCount() ; i++ )
+ {
+ ShowPageNum *pn = hwpfile.getPageNumber(i);
+ if( pn->where == 7 || pn->where == 8 )
+ {
+ bIsLeft = true;
+ bIsRight = true;
+ }
+ else if( pn->where == 1 || pn->where == 4 )
+ {
+ bIsLeft = true;
+ }
+ else if( pn->where == 2 || pn->where == 5 )
+ {
+ bIsMiddle = true;
+ }
+ else if( pn->where == 3 || pn->where == 6 )
+ {
+ bIsRight = true;
+ }
+ }
+
+ for( i = 1; i <= 3 ; i++ )
+ {
+ if( i == 1 && !bIsLeft )
+ continue;
+ if( i == 2 && !bIsMiddle )
+ continue;
+ if( i == 3 && !bIsRight )
+ continue;
+ mxList->addAttribute("style:name", sXML_CDATA, "PNPara" + OUString::number(i));
+ mxList->addAttribute("style:family", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:parent-style-name", sXML_CDATA, "Standard");
+ startEl("style:style");
+ mxList->clear();
+ if( i == 1 )
+ mxList->addAttribute("fo:text-align", sXML_CDATA, "start");
+ else if ( i == 2 )
+ mxList->addAttribute("fo:text-align", sXML_CDATA, "center");
+ else if ( i == 3 )
+ mxList->addAttribute("fo:text-align", sXML_CDATA, "end");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+
+ mxList->addAttribute("style:name", sXML_CDATA, "PNBox" + OUString::number(i));
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+ startEl("style:style");
+ mxList->clear();
+
+ mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm");
+ mxList->addAttribute("style:wrap", sXML_CDATA, "run-through");
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top");
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph");
+
+ if( i == 1 )
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "left");
+ else if ( i == 2 )
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center");
+ else if ( i == 3 )
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ mxList->addAttribute("fo:padding", sXML_CDATA, "0cm");
+ mxList->addAttribute("stylefamily", sXML_CDATA, "graphics");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+ }
+
+ for (i = 0; i < hwpfile.getDateFormatCount(); i++)
+ makeDateFormat(hwpfile.getDateCode(i));
+
+ makePageStyle();
+
+ endEl("office:automatic-styles");
+}
+
+namespace {
+
+struct PageSetting
+{
+ PageSetting()
+ {
+ header = nullptr;
+ header_odd = nullptr;
+ header_even = nullptr;
+ footer = nullptr;
+ footer_odd = nullptr;
+ footer_even = nullptr;
+ pagenumber=nullptr;
+ bIsSet = false;
+ }
+ HeaderFooter *header ;
+ HeaderFooter *header_odd ;
+ HeaderFooter *header_even ;
+ HeaderFooter *footer ;
+ HeaderFooter *footer_odd ;
+ HeaderFooter *footer_even ;
+ ShowPageNum *pagenumber;
+ bool bIsSet;
+};
+
+}
+
+void HwpReader::makeMasterStyles()
+{
+ startEl("office:master-styles");
+
+ int i;
+ int nMax = hwpfile.getMaxSettedPage();
+ std::vector<PageSetting> aSet(nMax + 1);
+
+ for( i = 0 ; i < hwpfile.getPageNumberCount() ; i++ )
+ {
+ ShowPageNum *pn = hwpfile.getPageNumber(i);
+ aSet[pn->m_nPageNumber].pagenumber = pn;
+ aSet[pn->m_nPageNumber].bIsSet = true;
+ }
+ for( i = 0 ; i < hwpfile.getHeaderFooterCount() ; i++ )
+ {
+ HeaderFooter* hf = hwpfile.getHeaderFooter(i);
+ aSet[hf->m_nPageNumber].bIsSet = true;
+ if( hf->type == 0 ) // header
+ {
+ switch( hf->where )
+ {
+ case 0 :
+ aSet[hf->m_nPageNumber].header = hf;
+ aSet[hf->m_nPageNumber].header_even = nullptr;
+ aSet[hf->m_nPageNumber].header_odd = nullptr;
+ break;
+ case 1:
+ aSet[hf->m_nPageNumber].header_even = hf;
+ if( aSet[hf->m_nPageNumber].header )
+ {
+ aSet[hf->m_nPageNumber].header_odd =
+ aSet[hf->m_nPageNumber].header;
+ aSet[hf->m_nPageNumber].header = nullptr;
+ }
+ break;
+ case 2:
+ aSet[hf->m_nPageNumber].header_odd = hf;
+ if( aSet[hf->m_nPageNumber].header )
+ {
+ aSet[hf->m_nPageNumber].header_even =
+ aSet[hf->m_nPageNumber].header;
+ aSet[hf->m_nPageNumber].header = nullptr;
+ }
+ break;
+ }
+ }
+ else // footer
+ {
+ switch( hf->where )
+ {
+ case 0 :
+ aSet[hf->m_nPageNumber].footer = hf;
+ aSet[hf->m_nPageNumber].footer_even = nullptr;
+ aSet[hf->m_nPageNumber].footer_odd = nullptr;
+ break;
+ case 1:
+ aSet[hf->m_nPageNumber].footer_even = hf;
+ if( aSet[hf->m_nPageNumber].footer )
+ {
+ aSet[hf->m_nPageNumber].footer_odd =
+ aSet[hf->m_nPageNumber].footer;
+ aSet[hf->m_nPageNumber].footer = nullptr;
+ }
+ break;
+ case 2:
+ aSet[hf->m_nPageNumber].footer_odd = hf;
+ if( aSet[hf->m_nPageNumber].footer )
+ {
+ aSet[hf->m_nPageNumber].footer_even =
+ aSet[hf->m_nPageNumber].footer;
+ aSet[hf->m_nPageNumber].footer = nullptr;
+ }
+ break;
+ }
+ }
+ }
+
+ PageSetting *pPrevSet = nullptr;
+ PageSetting *pPage = nullptr;
+
+ if (nMax > SAL_MAX_UINT16 && utl::ConfigManager::IsFuzzing())
+ {
+ SAL_WARN("filter.hwp", "too many pages: " << nMax << " clip to " << SAL_MAX_UINT16);
+ nMax = SAL_MAX_UINT16;
+ }
+
+ for( i = 1; i <= nMax ; i++ )
+ {
+ if( i == 1 )
+ mxList->addAttribute("style:name", sXML_CDATA, "Standard");
+ else
+ mxList->addAttribute("style:name", sXML_CDATA, "p" + OUString::number(i));
+ mxList->addAttribute("style:page-master-name", sXML_CDATA,
+ "pm" + OUString::number(hwpfile.GetPageMasterNum(i)));
+ if( i < nMax )
+ mxList->addAttribute("style:next-style-name", sXML_CDATA, "p" + OUString::number(i + 1));
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "master" + OUString::number(i));
+ startEl("style:master-page");
+ mxList->clear();
+
+ if( aSet[i].bIsSet ) /* If you've changed the current setting */
+ {
+ if( !aSet[i].pagenumber ){
+ if( pPrevSet && pPrevSet->pagenumber )
+ aSet[i].pagenumber = pPrevSet->pagenumber;
+ }
+ if( aSet[i].pagenumber )
+ {
+ if( aSet[i].pagenumber->where == 7 && aSet[i].header )
+ {
+ aSet[i].header_even = aSet[i].header;
+ aSet[i].header_odd = aSet[i].header;
+ aSet[i].header = nullptr;
+ }
+ if( aSet[i].pagenumber->where == 8 && aSet[i].footer )
+ {
+ aSet[i].footer_even = aSet[i].footer;
+ aSet[i].footer_odd = aSet[i].footer;
+ aSet[i].footer = nullptr;
+ }
+ }
+
+ if( !aSet[i].header_even && pPrevSet && pPrevSet->header_even )
+ {
+ aSet[i].header_even = pPrevSet->header_even;
+ }
+ if( !aSet[i].header_odd && pPrevSet && pPrevSet->header_odd )
+ {
+ aSet[i].header_odd = pPrevSet->header_odd;
+ }
+ if( !aSet[i].footer_even && pPrevSet && pPrevSet->footer_even )
+ {
+ aSet[i].footer_even = pPrevSet->footer_even;
+ }
+ if( !aSet[i].footer_odd && pPrevSet && pPrevSet->footer_odd )
+ {
+ aSet[i].footer_odd = pPrevSet->footer_odd;
+ }
+
+ pPage = &aSet[i];
+ pPrevSet = &aSet[i];
+ }
+ else if( pPrevSet ) /* If the previous setting exists */
+ {
+ pPage = pPrevSet;
+ }
+ else /* If the previous settings doesn't exist, set to the default settings */
+ {
+ startEl("style:header");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ endEl("text:p");
+ endEl("style:header");
+
+ startEl("style:footer");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ endEl("text:p");
+ endEl("style:footer");
+
+ endEl("style:master-page");
+
+ continue;
+ }
+// header
+ if( pPage->header )
+ {
+ startEl("style:header");
+ if( pPage->pagenumber && pPage->pagenumber->where < 4 )
+ {
+ d->bInHeader = true;
+ d->pPn = pPage->pagenumber;
+ }
+ if (!pPage->header->plist.empty())
+ parsePara(pPage->header->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ endEl("style:header");
+ }
+ if( pPage->header_even )
+ {
+ startEl("style:header");
+ if( pPage->pagenumber && ( pPage->pagenumber->where < 4
+ || pPage->pagenumber->where == 7 ) )
+ {
+ d->bInHeader = true;
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 3;
+ }
+ if (!pPage->header_even->plist.empty())
+ parsePara(pPage->header_even->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ endEl("style:header");
+ }
+ /* Will be the default. */
+ else if (pPage->header_odd)
+ {
+ startEl("style:header");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && ( pPage->pagenumber->where < 4 ||
+ pPage->pagenumber->where == 7 ) )
+ {
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 3;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ }
+ endEl("text:p");
+ endEl("style:header");
+ }
+ if( pPage->header_odd )
+ {
+ startEl("style:header-left");
+ if( pPage->pagenumber && ( pPage->pagenumber->where < 4
+ || pPage->pagenumber->where == 7 ) )
+ {
+ d->bInHeader = true;
+ d->nPnPos = 1;
+ d->pPn = pPage->pagenumber;
+ }
+ if (!pPage->header_odd->plist.empty())
+ parsePara(pPage->header_odd->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ endEl("style:header-left");
+ }
+ /* Will be the default. */
+ else if (pPage->header_even)
+ {
+ startEl("style:header-left");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && ( pPage->pagenumber->where < 4 ||
+ pPage->pagenumber->where == 7 ) )
+ {
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 1;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ }
+ endEl("text:p");
+ endEl("style:header-left");
+ }
+ if( !pPage->header && !pPage->header_even && !pPage->header_odd )
+ {
+ startEl("style:header");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && (pPage->pagenumber->where < 4 ||
+ pPage->pagenumber->where == 7 ) )
+ {
+ d->pPn = pPage->pagenumber;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ }
+ endEl("text:p");
+ endEl("style:header");
+ }
+// footer
+ if( pPage->footer )
+ {
+ startEl("style:footer");
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->bInHeader = true;
+ d->pPn = pPage->pagenumber;
+ }
+ if (!pPage->footer->plist.empty())
+ parsePara(pPage->footer->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ endEl("style:footer");
+ }
+ if( pPage->footer_even )
+ {
+ startEl("style:footer");
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->bInHeader = true;
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 3;
+ }
+ if (!pPage->footer_even->plist.empty())
+ parsePara(pPage->footer_even->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ endEl("style:footer");
+ }
+ /* Will be the default. */
+ else if (pPage->footer_odd)
+ {
+ startEl("style:footer");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 3;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ }
+ endEl("text:p");
+ endEl("style:footer");
+ }
+ if( pPage->footer_odd )
+ {
+ startEl("style:footer-left");
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->bInHeader = true;
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 1;
+ }
+ if (!pPage->footer_odd->plist.empty())
+ parsePara(pPage->footer_odd->plist.front().get());
+ d->bInHeader = false;
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ endEl("style:footer-left");
+ }
+ /* Will be the default. */
+ else if (pPage->footer_even)
+ {
+ startEl("style:footer-left");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->pPn = pPage->pagenumber;
+ d->nPnPos = 1;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ d->nPnPos = 0;
+ }
+ endEl("text:p");
+ endEl("style:footer-left");
+ }
+ if( !pPage->footer && !pPage->footer_even && !pPage->footer_odd )
+ {
+ startEl("style:footer");
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ if( pPage->pagenumber && pPage->pagenumber->where >= 4
+ && pPage->pagenumber->where != 7 )
+ {
+ d->pPn = pPage->pagenumber;
+ makeShowPageNum();
+ d->pPn = nullptr;
+ }
+ endEl("text:p");
+ endEl("style:footer");
+ }
+
+ endEl("style:master-page");
+ }
+ endEl("office:master-styles");
+}
+
+
+/**
+ * Create the properties for text styles.
+ * 1. fo:font-size, fo:font-family, fo:letter-spacing, fo:color,
+ * style:text-background-color, fo:font-style, fo:font-weight,
+ * style:text-underline,style:text-outline,fo:text-shadow,style:text-position
+ * Support them.
+ */
+void HwpReader::parseCharShape(CharShape const * cshape)
+{
+ HWPFont& hwpfont = hwpfile.GetHWPFont();
+
+ mxList->addAttribute("fo:font-size", sXML_CDATA, OUString::number(cshape->size / 25) + "pt");
+ mxList->addAttribute("style:font-size-asian", sXML_CDATA, OUString::number(cshape->size / 25) + "pt");
+
+ ::std::string const tmp = hstr2ksstr(kstr2hstr(
+ reinterpret_cast<unsigned char const *>(hwpfont.GetFontName(0, cshape->font[0]))).c_str());
+ double fRatio = 1.0;
+ int size = getRepFamilyName(tmp.c_str(), d->buf, fRatio);
+
+ mxList->addAttribute("fo:font-family", sXML_CDATA,
+ OUString(d->buf, size, RTL_TEXTENCODING_EUC_KR));
+ mxList->addAttribute("style:font-family-asian", sXML_CDATA,
+ OUString(d->buf, size, RTL_TEXTENCODING_EUC_KR));
+
+ mxList->addAttribute("style:text-scale", sXML_CDATA,
+ OUString::number(static_cast<int>(cshape->ratio[0] * fRatio)) + "%");
+
+ double sspace = (cshape->size / 25) * cshape->space[0] / 100.;
+
+ if (sspace != 0.)
+ {
+ mxList->addAttribute("fo:letter-spacing", sXML_CDATA,
+ OUString::number(sspace) + "pt");
+ }
+ if (cshape->color[1] != 0)
+ mxList->addAttribute("fo:color", sXML_CDATA,
+ hcolor2str(cshape->color[1], 100, true));
+ if (cshape->shade != 0)
+ mxList->addAttribute("style:text-background-color", sXML_CDATA,
+ hcolor2str(cshape->color[0], cshape->shade));
+ if (cshape->attr & 0x01)
+ {
+ mxList->addAttribute("fo:font-style", sXML_CDATA, "italic");
+ mxList->addAttribute("style:font-style-asian", sXML_CDATA, "italic");
+ }
+ else{
+ mxList->addAttribute("fo:font-style", sXML_CDATA, "normal");
+ mxList->addAttribute("style:font-style-asian", sXML_CDATA, "normal");
+ }
+ if (cshape->attr >> 1 & 0x01)
+ {
+ mxList->addAttribute("fo:font-weight", sXML_CDATA, "bold");
+ mxList->addAttribute("style:font-weight-asian", sXML_CDATA, "bold");
+ }
+ else{
+ mxList->addAttribute("fo:font-weight", sXML_CDATA, "normal");
+ mxList->addAttribute("style:font-weight-asian", sXML_CDATA, "normal");
+ }
+ if (cshape->attr >> 2 & 0x01)
+ mxList->addAttribute("style:text-underline", sXML_CDATA, "single");
+ if (cshape->attr >> 3 & 0x01)
+ mxList->addAttribute("style:text-outline", sXML_CDATA, "true");
+ if (cshape->attr >> 4 & 0x01)
+ mxList->addAttribute("fo:text-shadow", sXML_CDATA, "1pt 1pt");
+ if (cshape->attr >> 5 & 0x01)
+ mxList->addAttribute("style:text-position", sXML_CDATA, "super 58%");
+ if (cshape->attr >> 6 & 0x01)
+ mxList->addAttribute("style:text-position", sXML_CDATA, "sub 58%");
+
+}
+
+
+/**
+ * Create the properties that correspond to the real Paragraph.
+ * 1. fo:margin-left,fo:margin-right,fo:margin-top, fo:margin-bottom,
+ * fo:text-indent, fo:line-height, fo:text-align, fo:border
+ * are implemented.
+ * TODO: Tab Settings => set values of properties only which doesn't have the default value
+ */
+void HwpReader::parseParaShape(ParaShape const * pshape)
+{
+
+ if (pshape->left_margin != 0)
+ mxList->addAttribute("fo:margin-left", sXML_CDATA, OUString::number
+ (WTI(pshape->left_margin )) + "inch");
+ if (pshape->right_margin != 0)
+ mxList->addAttribute("fo:margin-right", sXML_CDATA, OUString::number
+ (WTI(pshape->right_margin)) + "inch");
+ if (pshape->pspacing_prev != 0)
+ mxList->addAttribute("fo:margin-top", sXML_CDATA, OUString::number
+ (WTI(pshape->pspacing_prev)) + "inch");
+ if (pshape->pspacing_next != 0)
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA, OUString::number
+ (WTI(pshape->pspacing_next)) + "inch");
+ if (pshape->indent != 0)
+ mxList->addAttribute("fo:text-indent", sXML_CDATA, OUString::number
+ (WTI(pshape->indent)) + "inch");
+ if (pshape->lspacing != 0)
+ mxList->addAttribute("fo:line-height", sXML_CDATA, OUString::number(pshape->lspacing) + "%");
+
+ const char* align = nullptr;
+
+ switch (static_cast<int>(pshape->arrange_type))
+ {
+ case 1:
+ align = "start";
+ break;
+ case 2:
+ align = "end";
+ break;
+ case 3:
+ align = "center";
+ break;
+ case 4:
+ case 5:
+ case 6:
+ align = "justify";
+ break;
+ }
+
+ if (align)
+ mxList->addAttribute("fo:text-align", sXML_CDATA, OUString::createFromAscii(align));
+
+ if (pshape->outline)
+ mxList->addAttribute("fo:border", sXML_CDATA, "0.002cm solid #000000");
+ if( pshape->shade > 0 )
+ {
+ mxList->addAttribute("fo:background-color", sXML_CDATA,
+ hcolor2str(0, pshape->shade));
+ }
+
+ if( pshape->pagebreak & 0x02 || pshape->pagebreak & 0x04)
+ mxList->addAttribute("fo:break-before", sXML_CDATA, "page");
+ else if( pshape->pagebreak & 0x01 )
+ mxList->addAttribute("fo:break-before", sXML_CDATA, "column");
+
+}
+
+
+/**
+ * Make the style of the Paragraph.
+ */
+void HwpReader::makePStyle(ParaShape const * pshape)
+{
+ int nscount = pshape->tabs[MAXTABS -1].type;
+ mxList->addAttribute("style:name", sXML_CDATA, "P" + OUString::number(pshape->index));
+ mxList->addAttribute("style:family", sXML_CDATA, "paragraph");
+ startEl("style:style");
+ mxList->clear();
+ parseParaShape(pshape);
+ if (pshape->cshape)
+ parseCharShape(pshape->cshape.get());
+ startEl("style:properties");
+ mxList->clear();
+
+ if( nscount )
+ {
+ unsigned char tf = 0;
+ startEl("style:tab-stops");
+
+ int tab_margin = pshape->left_margin + pshape->indent;
+ if( tab_margin < 0 )
+ tab_margin = 0;
+ for( int i = 0 ; i < MAXTABS -1 ; i++)
+ {
+ if( i > 0 && pshape->tabs[i].position == 0. )
+ break;
+ if( pshape->tabs[i].position <= tab_margin )
+ continue;
+ mxList->addAttribute("style:position", sXML_CDATA,
+ OUString::number(WTMM(pshape->tabs[i].position - tab_margin )) + "mm");
+ if( pshape->tabs[i].type )
+ {
+ tf = 1;
+ switch(pshape->tabs[i].type)
+ {
+ case 1 :
+ mxList->addAttribute("style:type", sXML_CDATA, "right");
+ break;
+ case 2:
+ mxList->addAttribute("style:type", sXML_CDATA, "center");
+ break;
+ case 3:
+ mxList->addAttribute("style:type", sXML_CDATA, "char");
+ mxList->addAttribute("style:char", sXML_CDATA, ".");
+ break;
+ }
+ }
+ if( pshape->tabs[i].dot_continue )
+ {
+ tf = 1;
+ mxList->addAttribute("style:leader-char", sXML_CDATA, ".");
+ }
+ startEl("style:tab-stop");
+ mxList->clear();
+ endEl("style:tab-stop");
+
+ if( (pshape->tabs[i].position != 1000 * i ) || tf )
+ {
+ if( !--nscount ) break;
+ }
+ }
+ endEl("style:tab-stops");
+ }
+ endEl("style:properties");
+ endEl("style:style");
+}
+
+
+/**
+ * Create a style for the page. This includes the header/footer, footnote and more.
+ * TODO: fo: background-color (no information)
+ */
+void HwpReader::makePageStyle()
+{
+ HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
+ int pmCount = hwpfile.getColumnCount();
+
+ for( int i = 0 ; i < pmCount ; i++ ){
+ mxList->addAttribute("style:name", sXML_CDATA, "pm" + OUString::number(i + 1));
+ startEl("style:page-master");
+ mxList->clear();
+
+
+ switch( hwpinfo.paper.paper_kind )
+ {
+ case 3: // A4
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "210mm");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "297mm");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "210mm");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "297mm");
+ }
+ break;
+ case 4: // 80 column
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "8.5inch");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "11inch");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "8.5inch");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "11inch");
+ }
+ break;
+ case 5: // B5
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "176mm");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "250mm");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "176mm");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "250mm");
+ }
+ break;
+ case 6: // B4
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "250mm");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "353mm");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "250mm");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "353mm");
+ }
+ break;
+ case 7:
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "8.5inch");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "14inch");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "8.5inch");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "14inch");
+ }
+ break;
+ case 8:
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "297mm");
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "420mm");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA, "297mm");
+ mxList->addAttribute("fo:page-height",sXML_CDATA, "420mm");
+ }
+ break;
+ case 0:
+ case 1:
+ case 2:
+ default:
+ if( hwpinfo.paper.paper_direction )
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.paper_height)) + "inch");
+ mxList->addAttribute("fo:page-height",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.paper_width)) + "inch");
+ }
+ else
+ {
+ mxList->addAttribute("fo:page-width",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.paper_width)) + "inch");
+ mxList->addAttribute("fo:page-height",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.paper_height)) + "inch");
+ }
+ break;
+
+ }
+
+ mxList->addAttribute("style:print-orientation",sXML_CDATA,
+ OUString::createFromAscii(hwpinfo.paper.paper_direction ? "landscape" : "portrait"));
+ if( hwpinfo.beginpagenum != 1)
+ mxList->addAttribute("style:first-page-number",sXML_CDATA, OUString::number(hwpinfo.beginpagenum));
+
+ if( hwpinfo.borderline ){
+ mxList->addAttribute("fo:margin-left",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.left_margin - hwpinfo.bordermargin[0] + hwpinfo.paper.gutter_length)) + "inch");
+ mxList->addAttribute("fo:margin-right",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.right_margin - hwpinfo.bordermargin[1])) + "inch");
+ mxList->addAttribute("fo:margin-top",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.top_margin - hwpinfo.bordermargin[2])) + "inch");
+ mxList->addAttribute("fo:margin-bottom",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.bottom_margin - hwpinfo.bordermargin[3])) + "inch");
+ }
+ else{
+ mxList->addAttribute("fo:margin-left",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.left_margin + hwpinfo.paper.gutter_length)) + "inch");
+ mxList->addAttribute("fo:margin-right",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.right_margin)) + "inch");
+ mxList->addAttribute("fo:margin-top",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.top_margin)) + "inch");
+ mxList->addAttribute("fo:margin-bottom",sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.bottom_margin)) + "inch");
+ }
+
+ switch( hwpinfo.borderline )
+ {
+ case 1:
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 3:
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm dotted #000000");
+ break;
+ case 2:
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4:
+ mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+
+ mxList->addAttribute("fo:padding-left", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.bordermargin[0])) + "inch");
+ mxList->addAttribute("fo:padding-right", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.bordermargin[1])) + "inch");
+ mxList->addAttribute("fo:padding-top", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.bordermargin[2])) + "inch");
+ mxList->addAttribute("fo:padding-bottom", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.bordermargin[3])) + "inch");
+
+ /* background color */
+ if( hwpinfo.back_info.isset )
+ {
+ if( hwpinfo.back_info.color[0] > 0 || hwpinfo.back_info.color[1] > 0
+ || hwpinfo.back_info.color[2] > 0 ){
+ mxList->addAttribute("fo:background-color", sXML_CDATA,
+ rgb2str(hwpinfo.back_info.color[0],
+ hwpinfo.back_info.color[1],
+ hwpinfo.back_info.color[2]));
+ }
+ }
+
+ startEl("style:properties");
+ mxList->clear();
+
+ /* background image */
+ if( hwpinfo.back_info.isset && hwpinfo.back_info.type > 0 )
+ {
+ if( hwpinfo.back_info.type == 1 ){
+#ifdef _WIN32
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltowin(hwpinfo.back_info.filename).c_str())).c_str()));
+#else
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(hwpinfo.back_info.filename).c_str())).c_str()));
+#endif
+ mxList->addAttribute("xlink:type", sXML_CDATA, "simple");
+ mxList->addAttribute("xlink:actuate", sXML_CDATA, "onLoad");
+ }
+ if( hwpinfo.back_info.flag >= 2)
+ mxList->addAttribute("style:repeat", sXML_CDATA, "stretch");
+ else if( hwpinfo.back_info.flag == 1 ){
+ mxList->addAttribute("style:repeat", sXML_CDATA, "no-repeat");
+ mxList->addAttribute("style:position", sXML_CDATA, "center");
+ }
+ startEl("style:background-image");
+
+ if( hwpinfo.back_info.type == 2 ){
+ startEl("office:binary-data");
+ mxList->clear();
+ chars(base64_encode_string(reinterpret_cast<unsigned char*>(hwpinfo.back_info.data.data()), hwpinfo.back_info.size));
+ endEl("office:binary-data");
+ }
+ endEl("style:background-image");
+ }
+
+ makeColumns( hwpfile.GetColumnDef(i) );
+
+ endEl("style:properties");
+
+ /* header style */
+ startEl("style:header-style");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.header_length)) + "inch");
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0mm");
+
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:header-style");
+
+ /* footer style */
+ startEl("style:footer-style");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.paper.footer_length)) + "inch");
+ mxList->addAttribute("fo:margin-top", sXML_CDATA, "0mm");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:footer-style");
+
+ /* Footnote style */
+ startEl("style:page-layout-properties");
+
+ mxList->addAttribute("style:distance-before-sep", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.splinetext)) + "inch");
+ mxList->addAttribute("style:distance-after-sep", sXML_CDATA,
+ OUString::number(WTI(hwpinfo.splinefn)) + "inch");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ if ( hwpinfo.fnlinetype == 2 )
+ mxList->addAttribute("style:width", sXML_CDATA, "15cm");
+ else if ( hwpinfo.fnlinetype == 1)
+ mxList->addAttribute("style:width", sXML_CDATA, "2cm");
+ else if ( hwpinfo.fnlinetype == 3)
+ mxList->addAttribute("style:width", sXML_CDATA, "0cm");
+ else
+ mxList->addAttribute("style:width", sXML_CDATA, "5cm");
+
+ startEl("style:footnote-sep");
+ mxList->clear();
+ endEl("style:footnote-sep");
+
+ endEl("style:page-layout-properties");
+
+ endEl("style:page-master");
+ }
+}
+
+void HwpReader::makeColumns(ColumnDef const *coldef)
+{
+ if( !coldef ) return;
+ mxList->addAttribute("fo:column-count", sXML_CDATA, OUString::number(coldef->ncols));
+ startEl("style:columns");
+ mxList->clear();
+ if( coldef->separator != 0 )
+ {
+ switch( coldef->separator )
+ {
+ case 1: /* thin line */
+ mxList->addAttribute("style:width", sXML_CDATA, "0.02mm");
+ [[fallthrough]];
+ case 3: /* dotted line */
+ mxList->addAttribute("style:style", sXML_CDATA, "dotted");
+ mxList->addAttribute("style:width", sXML_CDATA, "0.02mm");
+ break;
+ case 2: /* thick line */
+ case 4: /* double line */
+ mxList->addAttribute("style:width", sXML_CDATA, "0.35mm");
+ break;
+ case 0: /* None */
+ default:
+ mxList->addAttribute("style:style", sXML_CDATA, "none");
+ break;
+ }
+ startEl("style:column-sep");
+ mxList->clear();
+ endEl("style:column-sep");
+ }
+ double spacing = WTI(coldef->spacing)/ 2. ;
+ for(int ii = 0 ; ii < coldef->ncols ; ii++)
+ {
+ if( ii == 0 )
+ mxList->addAttribute("fo:margin-left", sXML_CDATA, "0mm");
+ else
+ mxList->addAttribute("fo:margin-left", sXML_CDATA,
+ OUString::number( spacing) + "inch");
+ if( ii == ( coldef->ncols -1) )
+ mxList->addAttribute("fo:margin-right", sXML_CDATA,"0mm");
+ else
+ mxList->addAttribute("fo:margin-right", sXML_CDATA,
+ OUString::number( spacing) + "inch");
+ startEl("style:column");
+ mxList->clear();
+ endEl("style:column");
+ }
+ endEl("style:columns");
+}
+
+void HwpReader::makeTStyle(CharShape const * cshape)
+{
+ mxList->addAttribute("style:name", sXML_CDATA, "T" + OUString::number(cshape->index));
+ mxList->addAttribute("style:family", sXML_CDATA, "text");
+ startEl("style:style");
+ mxList->clear();
+ parseCharShape(cshape);
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+}
+
+
+void HwpReader::makeTableStyle(Table *tbl)
+{
+// table
+ TxtBox *hbox = tbl->box;
+
+ mxList->addAttribute("style:name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("style:family", sXML_CDATA,"table");
+ startEl("style:style");
+ mxList->clear();
+ mxList->addAttribute("style:width", sXML_CDATA,
+ OUString::number(WTMM(hbox->box_xs)) + "mm");
+ mxList->addAttribute("table:align", sXML_CDATA,"left");
+ mxList->addAttribute("fo:keep-with-next", sXML_CDATA,"false");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+
+// column
+ for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
+ {
+ sprintf(d->buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
+ mxList->addAttribute("style:name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ mxList->addAttribute("style:family", sXML_CDATA,"table-column");
+ startEl("style:style");
+ mxList->clear();
+ mxList->addAttribute("style:column-width", sXML_CDATA,
+ OUString::number(WTMM(tbl->columns.data[i+1] - tbl->columns.data[i])) + "mm");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+ }
+
+// row
+ for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++)
+ {
+ sprintf(d->buf,"Table%d.row%" SAL_PRI_SIZET "u",hbox->style.boxnum, i + 1);
+ mxList->addAttribute("style:name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ mxList->addAttribute("style:family", sXML_CDATA,"table-row");
+ startEl("style:style");
+ mxList->clear();
+ mxList->addAttribute("style:row-height", sXML_CDATA,
+ OUString::number(WTMM(tbl->rows.data[i+1] - tbl->rows.data[i])) + "mm");
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+ }
+
+// cell
+ for (auto const& tcell : tbl->cells)
+ {
+ sprintf(d->buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
+ mxList->addAttribute("style:name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ mxList->addAttribute("style:family", sXML_CDATA,"table-cell");
+ startEl("style:style");
+ mxList->clear();
+ Cell *cl = tcell->pCell;
+ if( cl->ver_align == 1 )
+ mxList->addAttribute("fo:vertical-align", sXML_CDATA,"middle");
+
+ if(cl->linetype[2] == cl->linetype[3] && cl->linetype[2] == cl->linetype[0]
+ && cl->linetype[2] == cl->linetype[1])
+ {
+ switch( cl->linetype[2] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+ else
+ {
+ switch( cl->linetype[0] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cl->linetype[1] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cl->linetype[2] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cl->linetype[3] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+ if(cl->shade != 0)
+ mxList->addAttribute("fo:background-color", sXML_CDATA,
+ hcolor2str(sal::static_int_cast<uchar>(cl->color),
+ sal::static_int_cast<uchar>(cl->shade)));
+
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+
+ endEl("style:style");
+ }
+}
+
+
+void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle)
+{
+ while( hdo )
+ {
+ mxList->addAttribute("style:name", sXML_CDATA, "Draw" + OUString::number(hdo->index));
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+
+ startEl("style:style");
+ mxList->clear();
+
+ switch (fstyle->txtflow)
+ {
+ case 0:
+ break;
+ case 1:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "run-through");
+ break;
+ case 2:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic");
+ break;
+ }
+ tools::Long color;
+// invisible line
+ if( hdo->property.line_color > 0xffffff )
+ {
+ mxList->addAttribute("draw:stroke", sXML_CDATA, "none" );
+ }
+ else
+ {
+
+ if( hdo->property.line_pstyle == 0 )
+ mxList->addAttribute("draw:stroke", sXML_CDATA, "solid" );
+ else if( hdo->property.line_pstyle < 5 )
+ {
+ mxList->addAttribute("draw:stroke", sXML_CDATA, "dash" );
+ mxList->addAttribute("draw:stroke-dash", sXML_CDATA, "LineType" + OUString::number(hdo->index));
+ }
+ mxList->addAttribute("svg:stroke-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width)) + "mm");
+ mxList->addAttribute("svg:stroke-color", sXML_CDATA,
+ rgb2str(static_cast<int32_t>(hdo->property.line_color)));
+ }
+
+ if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC ||
+ hdo->type == HWPDO_FREEFORM || hdo->type == HWPDO_ADVANCED_ARC )
+ {
+
+ if( hdo->property.line_tstyle > 0 &&
+ o3tl::make_unsigned(hdo->property.line_tstyle) < std::size(ArrowShape) )
+ {
+ mxList->addAttribute("draw:marker-start", sXML_CDATA,
+ OUString::createFromAscii(ArrowShape[hdo->property.line_tstyle].name) );
+ if( hdo->property.line_width > 100 )
+ mxList->addAttribute("draw:marker-start-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 3)) + "mm");
+ else if( hdo->property.line_width > 80 )
+ mxList->addAttribute("draw:marker-start-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 4)) + "mm");
+ else if( hdo->property.line_width > 60 )
+ mxList->addAttribute("draw:marker-start-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 5)) + "mm");
+ else if( hdo->property.line_width > 40 )
+ mxList->addAttribute("draw:marker-start-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 6)) + "mm");
+ else
+ mxList->addAttribute("draw:marker-start-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 7)) + "mm");
+ }
+
+ if( hdo->property.line_hstyle > 0 &&
+ o3tl::make_unsigned(hdo->property.line_hstyle) < std::size(ArrowShape) )
+ {
+ mxList->addAttribute("draw:marker-end", sXML_CDATA,
+ OUString::createFromAscii(ArrowShape[hdo->property.line_hstyle].name) );
+ if( hdo->property.line_width > 100 )
+ mxList->addAttribute("draw:marker-end-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 3)) + "mm");
+ else if( hdo->property.line_width > 80 )
+ mxList->addAttribute("draw:marker-end-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 4)) + "mm");
+ else if( hdo->property.line_width > 60 )
+ mxList->addAttribute("draw:marker-end-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 5)) + "mm");
+ else if( hdo->property.line_width > 40 )
+ mxList->addAttribute("draw:marker-end-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 6)) + "mm");
+ else
+ mxList->addAttribute("draw:marker-end-width", sXML_CDATA,
+ OUString::number( WTMM(hdo->property.line_width * 7)) + "mm");
+ }
+ }
+
+ if(hdo->type != HWPDO_LINE )
+ {
+ if( hdo->property.flag >> 19 & 0x01 )
+ {
+ mxList->addAttribute( "draw:textarea-horizontal-align", sXML_CDATA, "center");
+ }
+
+ color = hdo->property.fill_color;
+
+ if( hdo->property.flag >> 18 & 0x01 ) // bitmap pattern
+ {
+ mxList->addAttribute("draw:fill", sXML_CDATA, "bitmap");
+ mxList->addAttribute("draw:fill-image-name", sXML_CDATA,
+ "fillimage" + OUString::number(hdo->index));
+ // bitmap resizing
+ if( hdo->property.flag >> 3 & 0x01 )
+ {
+ mxList->addAttribute("style:repeat", sXML_CDATA, "stretch");
+ }
+ else
+ {
+ mxList->addAttribute("style:repeat", sXML_CDATA, "repeat");
+ mxList->addAttribute("draw:fill-image-ref-point", sXML_CDATA, "top-left");
+ }
+ if( hdo->property.flag >> 20 & 0x01 )
+ {
+ if( hdo->property.luminance > 0 )
+ {
+ mxList->addAttribute("draw:transparency", sXML_CDATA,
+ OUString::number(hdo->property.luminance) + "%");
+ }
+ }
+
+ }
+ // Gradation
+ else if( hdo->property.flag >> 16 & 0x01 )
+ {
+ mxList->addAttribute("draw:fill", sXML_CDATA, "gradient");
+ mxList->addAttribute("draw:fill-gradient-name", sXML_CDATA, "Grad" + OUString::number(hdo->index));
+ mxList->addAttribute("draw:gradient-step-count", sXML_CDATA, OUString::number(hdo->property.nstep));
+
+ }
+ // Hatching
+ else if( hdo->property.pattern_type >> 24 & 0x01 )
+ {
+ mxList->addAttribute("draw:fill", sXML_CDATA, "hatch");
+ mxList->addAttribute("draw:fill-hatch-name", sXML_CDATA, "Hatch" + OUString::number(hdo->index));
+ if( color < 0xffffff )
+ {
+ mxList->addAttribute("draw:fill-color", sXML_CDATA,
+ rgb2str(static_cast<int32_t>(color)));
+ mxList->addAttribute("draw:fill-hatch-solid", sXML_CDATA, "true");
+ }
+ }
+ else if( color <= 0xffffff )
+ {
+ mxList->addAttribute("draw:fill", sXML_CDATA, "solid");
+ mxList->addAttribute("draw:fill-color", sXML_CDATA,
+ rgb2str(static_cast<int32_t>(color)));
+ }
+ else
+ mxList->addAttribute("draw:fill", sXML_CDATA, "none");
+ }
+
+ if( fstyle->anchor_type == CHAR_ANCHOR )
+ {
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top");
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline");
+ }
+
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+
+ if( hdo->type == 0 )
+ {
+ makeDrawStyle( hdo->child.get(), fstyle );
+ }
+ hdo = hdo->next.get();
+ }
+}
+
+
+void HwpReader::makeCaptionStyle(FBoxStyle * fstyle)
+{
+ mxList->addAttribute("style:name", sXML_CDATA, "CapBox" + OUString::number(fstyle->boxnum));
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+ startEl("style:style");
+ mxList->clear();
+ mxList->addAttribute("fo:margin-left", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-right", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:padding", sXML_CDATA, "0cm");
+ switch (fstyle->txtflow)
+ {
+ case 0:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "none");
+ break;
+ case 1:
+ if( fstyle->boxtype == 'G' )
+ mxList->addAttribute("style:run-through", sXML_CDATA, "background");
+ mxList->addAttribute("style:wrap", sXML_CDATA, "run-through");
+ break;
+ case 2:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic");
+ break;
+ }
+ if (fstyle->anchor_type == CHAR_ANCHOR)
+ {
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top");
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline");
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ }
+ else
+ {
+
+ switch (-(fstyle->xpos))
+ {
+ case 2:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right");
+ break;
+ case 3:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center");
+ break;
+ case 1:
+ default:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left");
+ break;
+ }
+ switch (-(fstyle->ypos))
+ {
+ case 2:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "bottom");
+ break;
+ case 3:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "middle");
+ break;
+ case 1:
+ default:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top");
+ break;
+ }
+ if ( fstyle->anchor_type == PARA_ANCHOR )
+ {
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ }
+ else
+ {
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "page-content");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "page-content");
+ }
+ }
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+ if( fstyle->boxtype == 'G' )
+ {
+ mxList->addAttribute("style:name", sXML_CDATA, "G" + OUString::number(fstyle->boxnum));
+ }
+ else
+ {
+ mxList->addAttribute("style:name", sXML_CDATA, "Txtbox" + OUString::number(fstyle->boxnum));
+ }
+
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+ startEl("style:style");
+ mxList->clear();
+
+ mxList->addAttribute("fo:margin-left", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-right", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm");
+ mxList->addAttribute("fo:padding", sXML_CDATA, "0cm");
+ mxList->addAttribute("style:wrap", sXML_CDATA, "none");
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top");
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ if (fstyle->boxtype == 'G' && fstyle->cell)
+ {
+ char *cell = static_cast<char *>(fstyle->cell);
+ mxList->addAttribute("draw:luminance", sXML_CDATA, OUString::number(cell[0]) + "%");
+ mxList->addAttribute("draw:contrast", sXML_CDATA, OUString::number(cell[1]) + "%");
+ if( cell[2] == 0 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "standard");
+ else if( cell[2] == 1 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "greyscale");
+ else if( cell[2] == 2 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "mono");
+ }
+ else if (fstyle->cell)
+ {
+ Cell *cell = static_cast<Cell *>(fstyle->cell);
+ if(cell->linetype[0] == cell->linetype[1] &&
+ cell->linetype[0] == cell->linetype[2] &&
+ cell->linetype[0] == cell->linetype[3])
+ {
+ switch( cell->linetype[0] )
+ {
+ case 0:
+ mxList->addAttribute("fo:padding", sXML_CDATA,"0mm");
+ break;
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+ else
+ {
+ switch( cell->linetype[0] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[1] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[2] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[3] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+ if(cell->shade != 0)
+ mxList->addAttribute("fo:background-color", sXML_CDATA, hcolor2str(
+ sal::static_int_cast<uchar>(cell->color),
+ sal::static_int_cast<uchar>(cell->shade)));
+ }
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+}
+
+
+/**
+ * Create a style for the Floating objects.
+ */
+void HwpReader::makeFStyle(FBoxStyle * fstyle)
+{
+ /* caption exist */
+ if( ( fstyle->boxtype == 'G' || fstyle->boxtype == 'X' ) && fstyle->cap_len > 0 )
+ {
+ makeCaptionStyle(fstyle);
+ return;
+ }
+ switch( fstyle->boxtype )
+ {
+ case 'X' : // txtbox
+ case 'E' : // equation
+ case 'B' : // button
+ case 'O' : // other
+ case 'T' : // table
+ mxList->addAttribute("style:name", sXML_CDATA, "Txtbox" + OUString::number(fstyle->boxnum));
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+ break;
+ case 'G' : // graphics
+ mxList->addAttribute("style:name", sXML_CDATA, "G" + OUString::number(fstyle->boxnum));
+ mxList->addAttribute("style:family", sXML_CDATA, "graphics");
+ break;
+ case 'L' : // line TODO : all
+ mxList->addAttribute("style:name", sXML_CDATA, "L" + OUString::number(fstyle->boxnum));
+ mxList->addAttribute( "style:family" , sXML_CDATA , "paragraph" );
+ break;
+ }
+
+ startEl("style:style");
+ mxList->clear();
+
+ if ( fstyle->boxtype == 'T')
+ {
+ mxList->addAttribute("fo:padding", sXML_CDATA, "0cm");
+ }
+
+ if( fstyle->boxtype != 'G' || fstyle->cap_len <= 0 )
+ {
+ mxList->addAttribute("fo:margin-left", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[0][0]) ) + "mm");
+ mxList->addAttribute("fo:margin-right", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[0][1])) + "mm");
+ mxList->addAttribute("fo:margin-top", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[0][2])) + "mm");
+ mxList->addAttribute("fo:margin-bottom", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[0][3])) + "mm");
+ }
+
+ switch (fstyle->txtflow)
+ {
+ case 0:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "none");
+ break;
+ case 1:
+ if( fstyle->boxtype == 'G' || fstyle->boxtype == 'B' || fstyle->boxtype == 'O')
+ mxList->addAttribute("style:run-through", sXML_CDATA, "background");
+ mxList->addAttribute("style:wrap", sXML_CDATA, "run-through");
+ break;
+ case 2:
+ mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic");
+ break;
+ }
+ if (fstyle->anchor_type == CHAR_ANCHOR)
+ {
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top");
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline");
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ }
+ else
+ {
+
+ switch (-(fstyle->xpos))
+ {
+ case 2:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right");
+ break;
+ case 3:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center");
+ break;
+ case 1:
+ default:
+ mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left");
+ break;
+ }
+ switch (-(fstyle->ypos))
+ {
+ case 2:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "bottom");
+ break;
+ case 3:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "middle");
+ break;
+ case 1:
+ default:
+ mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top");
+ break;
+ }
+ if ( fstyle->anchor_type == PARA_ANCHOR )
+ {
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph");
+ }
+ else
+ {
+ mxList->addAttribute("style:vertical-rel", sXML_CDATA, "page-content");
+ mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "page-content");
+ }
+ }
+ if (fstyle->cell && (fstyle->boxtype == 'X' || fstyle->boxtype == 'B'))
+ {
+ Cell *cell = static_cast<Cell *>(fstyle->cell);
+ if(cell->linetype[0] == cell->linetype[1] &&
+ cell->linetype[0] == cell->linetype[2] &&
+ cell->linetype[0] == cell->linetype[3])
+ {
+ switch( cell->linetype[0] )
+ {
+ case 0:
+ mxList->addAttribute("fo:border", sXML_CDATA, "none");
+ break;
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+ else
+ {
+ switch( cell->linetype[0] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[1] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[2] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ switch( cell->linetype[3] )
+ {
+ case 1: /* A thin solid line */
+ case 3: /* Dotted line -> LibreOffice, there is no dotted line */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000");
+ break;
+ case 2: /* Bold lines */
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000");
+ break;
+ case 4: /* Double line */
+ mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm");
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000");
+ break;
+ }
+ }
+
+ if( cell->linetype[0] == 0 && cell->linetype[1] == 0 &&
+ cell->linetype[2] == 0 && cell->linetype[3] == 0 ){
+ mxList->addAttribute("fo:padding", sXML_CDATA,"0mm");
+ }
+ else{
+ mxList->addAttribute("fo:padding-left", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[1][0])) + "mm");
+ mxList->addAttribute("fo:padding-right", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[1][1])) + "mm");
+ mxList->addAttribute("fo:padding-top", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[1][2])) + "mm");
+ mxList->addAttribute("fo:padding-bottom", sXML_CDATA,
+ OUString::number(WTMM(fstyle->margin[1][3])) + "mm");
+ }
+ if(cell->shade != 0)
+ mxList->addAttribute("fo:background-color", sXML_CDATA,
+ hcolor2str(
+ sal::static_int_cast<uchar>(cell->color),
+ sal::static_int_cast<uchar>(cell->shade)));
+ }
+ else if( fstyle->boxtype == 'E' )
+ {
+ mxList->addAttribute("fo:padding", sXML_CDATA,"0mm");
+ }
+ else if( fstyle->boxtype == 'L' )
+ {
+ mxList->addAttribute( "style:border-line-width-bottom", sXML_CDATA, "0.02mm 0.35mm 0.02mm");
+ mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #808080");
+ }
+ else if( fstyle->boxtype == 'G' && fstyle->cell )
+ {
+ if( fstyle->margin[1][0] || fstyle->margin[1][1] || fstyle->margin[1][2] || fstyle->margin[1][3] ){
+ OUString clip = "rect(" +
+ OUString::number(WTMM(-fstyle->margin[1][0]) ) + "mm " +
+ OUString::number(WTMM(-fstyle->margin[1][1]) ) + "mm " +
+ OUString::number(WTMM(-fstyle->margin[1][2]) ) + "mm " +
+ OUString::number(WTMM(-fstyle->margin[1][3]) ) + "mm)";
+ mxList->addAttribute("style:mirror", sXML_CDATA, "none");
+ mxList->addAttribute("fo:clip", sXML_CDATA, clip);
+ }
+ char *cell = static_cast<char *>(fstyle->cell);
+ mxList->addAttribute("draw:luminance", sXML_CDATA, OUString::number(cell[0]) + "%");
+ mxList->addAttribute("draw:contrast", sXML_CDATA, OUString::number(cell[1]) + "%");
+ if( cell[2] == 0 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "standard");
+ else if( cell[2] == 1 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "greyscale");
+ else if( cell[2] == 2 )
+ mxList->addAttribute("draw:color-mode", sXML_CDATA, "mono");
+
+ }
+ startEl("style:properties");
+ mxList->clear();
+ endEl("style:properties");
+ endEl("style:style");
+}
+
+
+OUString HwpReader::getTStyleName(int index)
+{
+ return "T" + OUString::number(index);
+}
+
+
+OUString HwpReader::getPStyleName(int index)
+{
+ return "P" + OUString::number(index);
+}
+
+
+void HwpReader::makeChars(hchar_string & rStr)
+{
+ chars(fromHcharStringToOUString(rStr));
+ rStr.clear();
+}
+
+
+/**
+ * If no special characters in the paragraph and all characters use the same CharShape
+ */
+void HwpReader::make_text_p0(HWPPara * para, bool bParaStart)
+{
+ hchar_string str;
+ int res;
+ hchar dest[3];
+ unsigned char firstspace = 0;
+ if( !bParaStart)
+ {
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getPStyleName(para->GetParaShape().index));
+ startEl("text:p");
+ mxList->clear();
+ }
+ if( d->bFirstPara && d->bInBody )
+ {
+ mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc);
+ startEl("text:bookmark");
+ mxList->clear();
+ endEl("text:bookmark");
+ d->bFirstPara = false;
+ }
+ if( d->bInHeader )
+ {
+ makeShowPageNum();
+ d->bInHeader = false;
+ }
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getTStyleName(para->cshape->index));
+ startEl("text:span");
+ mxList->clear();
+
+ int n = 0;
+ while (n < para->nch)
+ {
+ const auto& box = para->hhstr[n];
+
+ if (!box->hh)
+ break;
+
+ if (box->hh == CH_SPACE && !firstspace)
+ {
+ makeChars(str);
+ startEl("text:s");
+ endEl("text:s");
+ }
+ else if (box->hh == CH_END_PARA)
+ {
+ makeChars(str);
+ endEl("text:span");
+ endEl("text:p");
+ break;
+ }
+ else
+ {
+ if (box->hh == CH_SPACE)
+ firstspace = 0;
+ else
+ firstspace = 1;
+ res = hcharconv(box->hh, dest, UNICODE);
+ for( int j = 0 ; j < res; j++ )
+ {
+ str.push_back(dest[j]);
+ }
+ }
+ n += box->WSize();
+ }
+}
+
+
+/*
+ * There is no special characters in the paragraph, but characters use different CharShapes
+ */
+void HwpReader::make_text_p1(HWPPara * para,bool bParaStart)
+{
+ hchar_string str;
+ int n;
+ int res;
+ hchar dest[3];
+ int curr = para->cshape->index;
+ unsigned char firstspace = 0;
+
+ if( !bParaStart )
+ {
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getPStyleName(para->GetParaShape().index));
+ startEl("text:p");
+ mxList->clear();
+ }
+ if( d->bFirstPara && d->bInBody )
+ {
+/* for HWP's Bookmark */
+ mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc);
+ startEl("text:bookmark");
+ mxList->clear();
+ endEl("text:bookmark");
+ d->bFirstPara = false;
+ }
+ if( d->bInHeader )
+ {
+ makeShowPageNum();
+ d->bInHeader = false;
+ }
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getTStyleName(curr));
+ startEl("text:span");
+ mxList->clear();
+
+ for (n = 0; n < para->nch && para->hhstr[n]->hh;
+ n += para->hhstr[n]->WSize())
+ {
+ if (para->GetCharShape(n)->index != curr)
+ {
+ makeChars(str);
+ endEl("text:span");
+ curr = para->GetCharShape(n)->index;
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getTStyleName(curr));
+ startEl("text:span");
+ mxList->clear();
+ }
+ if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
+ {
+ makeChars(str);
+ startEl("text:s");
+ endEl("text:s");
+ }
+ else if (para->hhstr[n]->hh == CH_END_PARA)
+ {
+ makeChars(str);
+ endEl("text:span");
+ endEl("text:p");
+ break;
+ }
+ else
+ {
+ if( para->hhstr[n]->hh < CH_SPACE )
+ continue;
+ if (para->hhstr[n]->hh == CH_SPACE)
+ firstspace = 0;
+ else
+ firstspace = 1;
+ res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
+ for( int j = 0 ; j < res; j++ )
+ {
+ str.push_back(dest[j]);
+ }
+ }
+ }
+}
+
+
+/**
+ * Special characters are in the paragraph and characters use different CharShapes
+ */
+void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
+{
+ hchar_string str;
+ int res;
+ hchar dest[3];
+ unsigned char firstspace = 0;
+ bool pstart = bParaStart;
+ bool tstart = false;
+ bool infield = false;
+
+ const auto STARTP = [this, para, &pstart]()
+ {
+ mxList->addAttribute("text:style-name", "CDATA",
+ getPStyleName(para->GetParaShape().index));
+ startEl("text:p");
+ mxList->clear();
+ pstart = true;
+ };
+ const auto STARTT = [this, para, &tstart](int pos)
+ {
+ auto curr = para->GetCharShape(pos > 0 ? pos - 1 : 0)->index;
+ mxList->addAttribute("text:style-name", "CDATA", getTStyleName(curr));
+ startEl("text:span");
+ mxList->clear();
+ tstart = true;
+ };
+ const auto ENDP = [this, &pstart]()
+ {
+ endEl("text:p");
+ pstart = false;
+ };
+ const auto ENDT = [this, &tstart]()
+ {
+ endEl("text:span");
+ tstart = false;
+ };
+
+ if( d->bFirstPara && d->bInBody )
+ {
+ if ( !pstart ) {
+ STARTP();
+ }
+ mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc);
+ startEl("text:bookmark");
+ mxList->clear();
+ endEl("text:bookmark");
+ d->bFirstPara = false;
+ }
+ if( d->bInHeader )
+ {
+ if ( !pstart ) {
+ STARTP();
+ }
+ makeShowPageNum();
+ d->bInHeader = false;
+ }
+
+ int n = 0;
+ while (n < para->nch)
+ {
+ const auto& box = para->hhstr[n];
+
+ if (!box->hh)
+ break;
+
+ if (box->hh == CH_END_PARA)
+ {
+ if (!str.empty())
+ {
+ if( !pstart ){ STARTP(); }
+ if( !tstart ){ STARTT(n);}
+ makeChars(str);
+ }
+ if( tstart ){ ENDT();}
+ if( !pstart ){ STARTP(); }
+ if( pstart ){ ENDP(); }
+ break;
+ }
+ else if (box->hh == CH_SPACE && !firstspace)
+ {
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ startEl("text:s");
+ mxList->clear();
+ endEl("text:s");
+ }
+ else if (box->hh >= CH_SPACE)
+ {
+ if( n > 0 )
+ if( para->GetCharShape(n)->index != para->GetCharShape(n-1)->index && !infield )
+ {
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ ENDT();
+ }
+ if (box->hh == CH_SPACE)
+ firstspace = 0;
+ else
+ firstspace = 1;
+ res = hcharconv(box->hh, dest, UNICODE);
+ for( int j = 0 ; j < res; j++ )
+ {
+ str.push_back(dest[j]);
+ }
+ }
+ else if (box->hh == CH_FIELD)
+ {
+ FieldCode *hbox = static_cast<FieldCode*>(box.get());
+ if( hbox->location_info == 1)
+ {
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ firstspace = 1;
+ if( hbox->type[0] == 4 && hbox->type[1] == 0 )
+ {
+ d->pField = hbox->str3.get();
+ }
+ else{
+ makeFieldCode(str, hbox);
+ }
+ infield = true;
+ }
+ else
+ {
+ firstspace = 1;
+ if( hbox->type[0] == 4 && hbox->type[1] == 0 )
+ {
+ makeFieldCode(str, hbox);
+ d->pField = nullptr;
+ }
+ infield = false;
+ str.clear();
+ }
+ }
+ else
+ {
+ switch (box->hh)
+ {
+ case CH_BOOKMARK:
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeBookmark(static_cast<Bookmark*>(box.get()));
+ break;
+ case CH_DATE_FORM: // 7
+ break;
+ case CH_DATE_CODE: // 8
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeDateCode(static_cast<DateCode*>(box.get()));
+ break;
+ case CH_TAB: // 9
+ if( !pstart ) {STARTP(); }
+ if (!str.empty())
+ {
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ makeTab();
+ break;
+ case CH_TEXT_BOX: /* 10 - ordered by Table/text box/formula/button/hypertext */
+ {
+ /* produce tables first, and treat formula as being in text:p. */
+ TxtBox *hbox = static_cast<TxtBox*>(box.get());
+
+ if( hbox->style.anchor_type == 0 )
+ {
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ else
+ {
+ if( !pstart ) {STARTP(); }
+ if (!str.empty())
+ {
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ if( tstart ) {ENDT();}
+ }
+ switch (hbox->type)
+ {
+ case TBL_TYPE: // table
+ case TXT_TYPE: // text box
+ case EQU_TYPE: // formula
+ makeTextBox(hbox);
+ break;
+ case BUTTON_TYPE: // text button
+ case HYPERTEXT_TYPE: // hypertext
+ makeHyperText(hbox);
+ break;
+ }
+ break;
+ }
+ case CH_PICTURE: // 11
+ {
+ Picture *hbox = static_cast<Picture*>(box.get());
+ if( hbox->style.anchor_type == 0 )
+ {
+ if( !pstart ) {STARTP(); }
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ else
+ {
+ if( !pstart ) {STARTP(); }
+ if (!str.empty())
+ {
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ if( tstart ) {ENDT();}
+ }
+ makePicture(hbox);
+ break;
+ }
+ case CH_LINE: // 14
+ {
+ if (!str.empty())
+ {
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ }
+ if( tstart ) {ENDT();}
+ if( pstart ) {ENDP();}
+ makeLine();
+ pstart = true;
+ break;
+ }
+ case CH_HIDDEN: // 15
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeHidden(static_cast<Hidden*>(box.get()));
+ break;
+ case CH_FOOTNOTE: // 17
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeFootnote(static_cast<Footnote*>(box.get()));
+ break;
+ case CH_AUTO_NUM: // 18
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeAutoNum(static_cast<AutoNum*>(box.get()));
+ break;
+ case CH_NEW_NUM: // 19 -skip
+ break;
+ case CH_PAGE_NUM_CTRL: // 21
+ break;
+ case CH_MAIL_MERGE: // 22
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeMailMerge(static_cast<MailMerge*>(box.get()));
+ break;
+ case CH_COMPOSE: /* 23 - overlapping letters */
+ break;
+ case CH_HYPHEN: // 24
+ break;
+ case CH_TOC_MARK: /* 25 Need to fix below 3 */
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ break;
+ case CH_INDEX_MARK: // 26
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ break;
+ case CH_OUTLINE: // 28
+ if( !pstart ) {STARTP();}
+ if( !tstart ) {STARTT(n);}
+ makeChars(str);
+ makeOutline(static_cast<Outline *>(box.get()));
+ break;
+ case CH_FIXED_SPACE:
+ case CH_KEEP_SPACE:
+ str.push_back(0x0020);
+ break;
+ }
+ }
+ n += box->WSize();
+ }
+}
+
+
+void HwpReader::makeFieldCode(hchar_string const & rStr, FieldCode const *hbox)
+{
+/* Push frame */
+ if( hbox->type[0] == 4 && hbox->type[1] == 0 )
+ {
+ mxList->addAttribute("text:placeholder-type", sXML_CDATA, "text");
+ if (d->pField)
+ mxList->addAttribute("text:description", sXML_CDATA, hstr2OUString(d->pField));
+ startEl("text:placeholder");
+ mxList->clear();
+ chars( fromHcharStringToOUString(rStr) );
+ endEl("text:placeholder");
+ }
+/* Document Summary */
+ else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
+ {
+ const OUString uStr3 = hstr2OUString(hbox->str3.get());
+ if (uStr3 == "title")
+ {
+ startEl("text:title");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:title");
+ }
+ else if (uStr3 == "subject")
+ {
+ startEl("text:subject");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:subject");
+ }
+ else if (uStr3 == "author")
+ {
+ startEl("text:author-name");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:author-name");
+ }
+ else if (uStr3 == "keywords")
+ {
+ startEl("text:keywords");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:keywords");
+ }
+ }
+/* Personal Information */
+ else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
+ {
+ const OUString uStr3 = hstr2OUString(hbox->str3.get());
+ if (uStr3 == "User")
+ {
+ startEl("text:sender-lastname");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-lastname");
+ }
+ else if (uStr3 == "Company")
+ {
+ startEl("text:sender-company");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-company");
+ }
+ else if (uStr3 == "Position")
+ {
+ startEl("text:sender-title");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-title");
+ }
+ else if (uStr3 == "Division")
+ {
+ startEl("text:sender-position");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-position");
+ }
+ else if (uStr3 == "Fax")
+ {
+ startEl("text:sender-fax");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-fax");
+ }
+ else if (uStr3 == "Pager")
+ {
+ startEl("text:phone-private");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:phone-private");
+ }
+ else if (uStr3 == "E-mail")
+ {
+ startEl("text:sender-email");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-email");
+ }
+ else if (uStr3 == "Zipcode(office)")
+ {
+ startEl("text:sender-postal-code");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-postal-code");
+ }
+ else if (uStr3 == "Phone(office)")
+ {
+ startEl("text:sender-phone-work");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-phone-work");
+ }
+ else if (uStr3 == "Address(office)")
+ {
+ startEl("text:sender-street");
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:sender-street");
+ }
+
+ }
+ else if( hbox->type[0] == 3 && hbox->type[1] == 2 ) /* creation date */
+ {
+ if( hbox->m_pDate )
+ mxList->addAttribute("style:data-style-name", sXML_CDATA, "N" + OUString::number(hbox->m_pDate->key));
+ startEl("text:creation-date");
+ mxList->clear();
+ chars( hstr2OUString(hbox->str2.get()) );
+ endEl("text:creation-date");
+ }
+}
+
+
+/**
+ * Completed
+ * In LibreOffice, refer bookmarks as reference, but hwp doesn't have the sort of feature.
+ */
+void HwpReader::makeBookmark(Bookmark const * hbox)
+{
+ if (hbox->type == 0)
+ {
+ mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id));
+ startEl("text:bookmark");
+ mxList->clear();
+ endEl("text:bookmark");
+ }
+ else if (hbox->type == 1) /* Block bookmarks days begin and end there if */
+ {
+ mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id));
+ startEl("text:bookmark-start");
+ mxList->clear();
+ endEl("text:bookmark-start");
+ }
+ else if (hbox->type == 2)
+ {
+ mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id));
+ startEl("text:bookmark-end");
+ mxList->clear();
+ endEl("text:bookmark-end");
+ }
+}
+
+
+void HwpReader::makeDateFormat(DateCode * hbox)
+{
+ mxList->addAttribute("style:name", sXML_CDATA, "N" + OUString::number(hbox->key));
+ mxList->addAttribute("style:family", sXML_CDATA,"data-style");
+ mxList->addAttribute("number:language", sXML_CDATA,"ko");
+ mxList->addAttribute("number:country", sXML_CDATA,"KR");
+
+ startEl("number:date-style");
+ mxList->clear();
+
+ bool add_zero = false;
+ int zero_check = 0;
+ hbox->format[DATE_SIZE -1] = 0;
+
+ const hchar *fmt = hbox->format[0] ? hbox->format : defaultform;
+
+ for( ; *fmt ; fmt++ )
+ {
+ if( zero_check == 1 )
+ {
+ zero_check = 0;
+ }
+ else
+ add_zero = false;
+
+ switch( *fmt )
+ {
+ case '0':
+ zero_check = 1;
+ add_zero = true;
+ break;
+ case '1':
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:year");
+ mxList->clear();
+ endEl("number:year");
+ break;
+ case '!':
+ startEl("number:year");
+ mxList->clear();
+ endEl("number:year");
+ break;
+ case '2':
+ if( add_zero )
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:month");
+ mxList->clear();
+ endEl("number:month");
+ break;
+ case '@':
+ mxList->addAttribute("number:textual", sXML_CDATA, "true");
+ startEl("number:month");
+ mxList->clear();
+ endEl("number:month");
+ break;
+ case '*':
+ mxList->addAttribute("number:textual", sXML_CDATA, "true");
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:month");
+ mxList->clear();
+ endEl("number:month");
+ break;
+ case '3':
+ if( add_zero )
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:day");
+ mxList->clear();
+ endEl("number:day");
+ break;
+ case '#':
+ if( add_zero )
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:day");
+ mxList->clear();
+ endEl("number:day");
+ switch( hbox->date[DateCode::DAY] % 10)
+ {
+ case 1:
+ startEl("number:text");
+ chars("st");
+ endEl("number:text");
+ break;
+ case 2:
+ startEl("number:text");
+ chars("nd");
+ endEl("number:text");
+ break;
+ case 3:
+ startEl("number:text");
+ chars("rd");
+ endEl("number:text");
+ break;
+ default:
+ startEl("number:text");
+ chars("th");
+ endEl("number:text");
+ break;
+ }
+ break;
+ case '4':
+ case '$':
+ if( add_zero )
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:hours");
+ mxList->clear();
+ endEl("number:hours");
+ break;
+ case '5':
+ case '%':
+ if( add_zero )
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ startEl("number:minutes");
+ mxList->clear();
+ endEl("number:minutes");
+ break;
+ case '_':
+ mxList->addAttribute("number:style", sXML_CDATA, "long");
+ [[fallthrough]];
+ case '6':
+ case '^':
+ startEl("number:day-of-week");
+ mxList->clear();
+ endEl("number:day-of-week");
+ break;
+ case '7':
+ case '&':
+ case '+':
+ startEl("number:am-pm");
+ mxList->clear();
+ endEl("number:am-pm");
+ break;
+ case '~': // Chinese Locale
+ break;
+ default:
+ hchar sbuf[2];
+ sbuf[0] = *fmt;
+ sbuf[1] = 0;
+ startEl("number:text");
+ chars(hstr2OUString(sbuf));
+ endEl("number:text");
+ break;
+ }
+ }
+ mxList->clear();
+ endEl("number:date-style");
+}
+
+
+void HwpReader::makeDateCode(DateCode * hbox)
+{
+ mxList->addAttribute("style:data-style-name", sXML_CDATA, "N" + OUString::number(hbox->key));
+ startEl("text:date");
+ mxList->clear();
+ hchar_string const boxstr = hbox->GetString();
+ chars(hstr2OUString(boxstr.c_str()));
+ endEl("text:date");
+}
+
+
+void HwpReader::makeTab()
+{
+ startEl("text:tab-stop");
+ endEl("text:tab-stop");
+}
+
+
+void HwpReader::makeTable(TxtBox * hbox)
+{
+ mxList->addAttribute("table:name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("table:style-name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum));
+ startEl("table:table");
+ mxList->clear();
+
+ Table *tbl = hbox->m_pTable;
+// column
+ for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
+ {
+ sprintf(d->buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
+ mxList->addAttribute("table:style-name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ startEl("table:table-column");
+ mxList->clear();
+ endEl("table:table-column");
+ }
+
+// cell
+ int j = -1, k = -1;
+ for (auto const& tcell : tbl->cells)
+ {
+ if( tcell->nRowIndex > j )
+ {
+ if( j > k )
+ {
+ endEl("table:table-row");
+ k = j;
+ }
+// row
+ sprintf(d->buf,"Table%d.row%d",hbox->style.boxnum, tcell->nRowIndex + 1);
+ mxList->addAttribute("table:style-name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ startEl("table:table-row");
+ mxList->clear();
+ j = tcell->nRowIndex;
+ }
+
+ sprintf(d->buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
+ mxList->addAttribute("table:style-name", sXML_CDATA, OUString::createFromAscii(d->buf));
+ if( tcell->nColumnSpan > 1 )
+ mxList->addAttribute("table:number-columns-spanned", sXML_CDATA, OUString::number(tcell->nColumnSpan));
+ if( tcell->nRowSpan > 1 )
+ mxList->addAttribute("table:number-rows-spanned", sXML_CDATA, OUString::number(tcell->nRowSpan));
+ mxList->addAttribute("table:value-type", sXML_CDATA,"string");
+ if( tcell->pCell->protect )
+ mxList->addAttribute("table:protected", sXML_CDATA,"true");
+ startEl("table:table-cell");
+ mxList->clear();
+ TxtBox::plist_t& rVec = hbox->plists[tcell->pCell->key];
+ if (!rVec.empty())
+ parsePara(rVec.front().get());
+ endEl("table:table-cell");
+ }
+ endEl("table:table-row");
+ endEl("table:table");
+}
+
+
+/**
+ * Parses the text boxes and tables.
+ * 1. draw: style-name, draw: name, text: anchor-type, svg: width,
+ * Fo: min-height, svg: x, svg: y
+ * TODO: fo:background-color <= no idea whether the value of color setting->style is in it or not
+ */
+void HwpReader::makeTextBox(TxtBox * hbox)
+{
+ if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
+ {
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "CapBox" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:name", sXML_CDATA, "CaptionBox" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder));
+ switch (hbox->style.anchor_type)
+ {
+ case CHAR_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ break;
+ case PARA_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ break;
+ case PAGE_ANCHOR:
+ case PAPER_ANCHOR:
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "page");
+ mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1));
+ break;
+ }
+ }
+ if (hbox->style.anchor_type != CHAR_ANCHOR)
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_xs + hbox->cap_xs )) + "mm");
+ mxList->addAttribute("fo:min-height", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_ys + hbox->cap_ys )) + "mm");
+ startEl("draw:text-box");
+ mxList->clear();
+ if (!hbox->caption.empty() && hbox->cap_pos % 2) /* The caption is on the top */
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ mxList->addAttribute( "text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ }
+ else{
+ mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder));
+ }
+
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "Txtbox" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:name", sXML_CDATA, "Frame" + OUString::number(hbox->style.boxnum));
+
+ if( hbox->style.cap_len <= 0 || hbox->type != TXT_TYPE )
+ {
+ int x = 0;
+ int y = 0;
+ switch (hbox->style.anchor_type)
+ {
+ case CHAR_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ break;
+ case PARA_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ break;
+ case PAGE_ANCHOR:
+ case PAPER_ANCHOR:
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "page");
+ mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1));
+ break;
+ }
+ }
+ if( hbox->style.anchor_type != CHAR_ANCHOR )
+ {
+ x += hbox->style.margin[0][0];
+ y += hbox->style.margin[0][2];
+ }
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgx + x )) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgy + y )) + "mm");
+ }
+ else
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ mxList->addAttribute("svg:y", sXML_CDATA, "0cm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_xs )) + "mm");
+ if( hbox->style.cap_len > 0 && hbox->type != TXT_TYPE)
+ mxList->addAttribute("fo:min-height", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_ys + hbox->cap_ys)) + "mm");
+ else
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number(WTMM(hbox->box_ys )) + "mm");
+
+ if( hbox->type != EQU_TYPE )
+ {
+ startEl("draw:text-box");
+ mxList->clear();
+/* If captions are present and it is on the top */
+ if (hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE && !hbox->caption.empty())
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ if( hbox->type == TBL_TYPE) // Is Table
+ {
+ makeTable(hbox);
+ }
+ else if (!hbox->plists[0].empty()) // Is TextBox
+ {
+ parsePara(hbox->plists[0].front().get());
+ }
+/* If captions are present and it is on the bottom */
+ if (hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE && !hbox->caption.empty())
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ endEl("draw:text-box");
+// Caption exist and it is text-box
+ if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE)
+ {
+ endEl("text:p");
+ if (!(hbox->cap_pos % 2) && !hbox->caption.empty())
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ endEl("draw:text-box");
+ }
+ }
+ else // is Formula
+ {
+ startEl("draw:object");
+ mxList->clear();
+ makeFormula(hbox);
+ endEl("draw:object");
+ }
+}
+
+
+/**
+ * It must be converted into MathML.
+ *
+ */
+void HwpReader::makeFormula(TxtBox * hbox)
+{
+ char mybuf[3000];
+ HWPPara* pPar;
+
+ int n, c, res;
+ hchar dest[3];
+ size_t l = 0;
+
+ pPar = hbox->plists[0].empty() ? nullptr : hbox->plists[0].front().get();
+ while( pPar )
+ {
+ for( n = 0; n < pPar->nch && pPar->hhstr.count(n) && pPar->hhstr[n]->hh;
+ n += pPar->hhstr[n]->WSize() )
+ {
+ if (l >= sizeof(mybuf)-7)
+ break;
+ res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
+ for( int j = 0 ; j < res; j++ ){
+ c = dest[j];
+ if( c < 32 )
+ c = ' ';
+ if( c < 256 )
+ mybuf[l++] = sal::static_int_cast<char>(c);
+ else
+ {
+ mybuf[l++] = sal::static_int_cast<char>((c >> 8) & 0xff);
+ mybuf[l++] = sal::static_int_cast<char>(c & 0xff);
+ }
+ }
+ }
+ if (l >= sizeof(mybuf)-7)
+ break;
+ mybuf[l++] = '\n';
+ pPar = pPar->Next();
+ }
+ mybuf[l] = '\0';
+
+ Formula form( mybuf );
+ form.setDocumentHandler(m_rxDocumentHandler);
+ form.setAttributeListImpl(mxList.get());
+ form.parse();
+}
+
+/**
+ * Read the platform information. if the platform is Linux or Solaris, it needs to change
+ * C: \ => Home, D: \ => changed to root (/). Because HWP uses DOS emulator.
+ */
+
+void HwpReader::makeHyperText(TxtBox * hbox)
+{
+ HyperText *hypert = hwpfile.GetHyperText();
+ if( !hypert ) return;
+
+ if (hypert->filename[0] != '\0') {
+ ::std::string const tmp = hstr2ksstr(hypert->bookmark);
+ ::std::string const tmp2 = hstr2ksstr(kstr2hstr(
+#ifdef _WIN32
+ reinterpret_cast<uchar const *>(urltowin(reinterpret_cast<char *>(hypert->filename)).c_str())).c_str());
+#else
+ reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hypert->filename)).c_str())).c_str());
+#endif
+ mxList->addAttribute("xlink:type", sXML_CDATA, "simple");
+ if (!tmp.empty() && strcmp(tmp.c_str(), "[HTML]")) {
+ ::std::string tmp3(tmp2);
+ tmp3.push_back('#');
+ tmp3.append(tmp);
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR));
+ }
+ else{
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR));
+
+ }
+ }
+ else
+ {
+ mxList->addAttribute("xlink:type", sXML_CDATA, "simple");
+ ::std::string tmp;
+ tmp.push_back('#');
+ tmp.append(hstr2ksstr(hypert->bookmark));
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR));
+ }
+ startEl("draw:a");
+ mxList->clear();
+ makeTextBox(hbox);
+ endEl("draw:a");
+}
+
+
+/**
+ * Read the platform information. if the platform is Linux or Solaris, it needs to change
+ * C: \ => Home, D: \ => changed to root (/). Because HWP uses DOS emulator.
+ */
+
+void HwpReader::makePicture(Picture * hbox)
+{
+ switch (hbox->pictype)
+ {
+ case PICTYPE_OLE:
+ case PICTYPE_EMBED:
+ case PICTYPE_FILE:
+ {
+ if( hbox->style.cap_len > 0 )
+ {
+ mxList->addAttribute("draw:style-name", sXML_CDATA,
+ "CapBox" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:name", sXML_CDATA, "CaptionBox" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder));
+ switch (hbox->style.anchor_type)
+ {
+ case CHAR_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ break;
+ case PARA_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ break;
+ case PAGE_ANCHOR:
+ case PAPER_ANCHOR:
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "page");
+ mxList->addAttribute("text:anchor-page-number", sXML_CDATA,
+ OUString::number(hbox->pgno + 1));
+ break;
+ }
+ }
+ if (hbox->style.anchor_type != CHAR_ANCHOR)
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1] )) + "mm");
+ mxList->addAttribute("fo:min-height", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3] + hbox->cap_ys )) + "mm");
+ startEl("draw:text-box");
+ mxList->clear();
+ if (!hbox->caption.empty() && hbox->cap_pos % 2) /* Caption is on the top */
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ mxList->addAttribute( "text:style-name", sXML_CDATA, "Standard");
+ startEl("text:p");
+ mxList->clear();
+ }
+ if( hbox->ishyper )
+ {
+ mxList->addAttribute("xlink:type", sXML_CDATA, "simple");
+#ifdef _WIN32
+ if( hbox->follow[4] != 0 )
+ mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(hbox->follow.data() + 4).c_str()));
+ else
+ mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(hbox->follow.data() + 5).c_str()));
+#else
+ if( hbox->follow[4] != 0 )
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 4)).c_str())).c_str()));
+ else
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 5)).c_str())).c_str()));
+#endif
+ startEl("draw:a");
+ mxList->clear();
+ }
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "G" + OUString::number(hbox->style.boxnum));
+ mxList->addAttribute("draw:name", sXML_CDATA, "Image" + OUString::number(hbox->style.boxnum));
+
+ if( hbox->style.cap_len <= 0 )
+ {
+ mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder));
+ switch (hbox->style.anchor_type)
+ {
+ case CHAR_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ break;
+ case PARA_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ break;
+ case PAGE_ANCHOR:
+ case PAPER_ANCHOR:
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "page");
+ mxList->addAttribute("text:anchor-page-number", sXML_CDATA,
+ OUString::number(hbox->pgno + 1));
+ break;
+ }
+ }
+ if (hbox->style.anchor_type != CHAR_ANCHOR)
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm");
+ }
+ }
+ else
+ {
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ mxList->addAttribute("svg:y", sXML_CDATA, "0cm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1])) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3])) + "mm");
+
+ if ( hbox->pictype == PICTYPE_FILE ){
+#ifdef _WIN32
+ sprintf(d->buf, "file:///%s", hbox->picinfo.picun.path );
+ mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(reinterpret_cast<uchar *>(d->buf)).c_str()));
+#else
+ mxList->addAttribute("xlink:href", sXML_CDATA,
+ hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(hbox->picinfo.picun.path).c_str())).c_str()));
+#endif
+ mxList->addAttribute("xlink:type", sXML_CDATA, "simple");
+ mxList->addAttribute("xlink:show", sXML_CDATA, "embed");
+ mxList->addAttribute("xlink:actuate", sXML_CDATA, "onLoad");
+ }
+
+ if( hbox->pictype == PICTYPE_OLE )
+ startEl("draw:object-ole");
+ else
+ startEl("draw:image");
+ mxList->clear();
+ if (hbox->pictype == PICTYPE_EMBED || hbox->pictype == PICTYPE_OLE)
+ {
+ startEl("office:binary-data");
+ mxList->clear();
+ if( hbox->pictype == PICTYPE_EMBED ){
+ EmPicture *emp = hwpfile.GetEmPicture(hbox);
+ if( emp )
+ {
+ chars(base64_encode_string(emp->data.get(), emp->size));
+ }
+ }
+ else{
+ if( hwpfile.oledata ){
+#ifdef _WIN32
+ LPSTORAGE srcsto;
+ LPUNKNOWN pObj;
+ wchar_t pathname[200];
+
+ MultiByteToWideChar(CP_ACP, 0, hbox->picinfo.picole.embname, -1, pathname, 200);
+ int rc = hwpfile.oledata->pis->OpenStorage(pathname, nullptr,
+ STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, nullptr, 0, &srcsto);
+ if (rc != S_OK) {
+ chars("");
+ }
+ else{
+ rc = OleLoad(srcsto, IID_IUnknown, nullptr, reinterpret_cast<LPVOID*>(&pObj));
+ if( rc != S_OK ){
+ srcsto->Release();
+ chars("");
+ }
+ else{
+ chars(base64_encode_string(reinterpret_cast<uchar*>(pObj), strlen(reinterpret_cast<char*>(pObj))));
+ pObj->Release();
+ srcsto->Release();
+ }
+ }
+#else
+ chars("");
+#endif
+ }
+ }
+ endEl("office:binary-data");
+ }
+ if( hbox->pictype == PICTYPE_OLE )
+ endEl("draw:object-ole");
+ else
+ endEl("draw:image");
+ if( hbox->ishyper )
+ {
+ endEl("draw:a");
+ }
+ if( hbox->style.cap_len > 0 )
+ {
+ endEl("text:p");
+ if (!hbox->caption.empty() && !(hbox->cap_pos % 2)) /* Caption is at the bottom, */
+ {
+ parsePara(hbox->caption.front().get());
+ }
+ endEl("draw:text-box");
+ }
+ break;
+ }
+ case PICTYPE_DRAW:
+ if( hbox->picinfo.picdraw.zorder > 0 )
+ mxList->addAttribute("draw:z-index", sXML_CDATA,
+ OUString::number(hbox->picinfo.picdraw.zorder + 10000));
+ makePictureDRAW(hbox->picinfo.picdraw.hdo, hbox);
+ break;
+ case PICTYPE_UNKNOWN:
+ break;
+ }
+}
+
+void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, const Picture* hbox)
+{
+ bool bIsRotate = false;
+
+ while (drawobj)
+ {
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "Draw" + OUString::number(drawobj->index));
+ int a = 0;
+ int b = 0;
+
+ switch (hbox->style.anchor_type)
+ {
+ case CHAR_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char");
+ break;
+ case PARA_ANCHOR:
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ break;
+ case PAGE_ANCHOR:
+ case PAPER_ANCHOR:
+ {
+ HWPInfo& hwpinfo = hwpfile.GetHWPInfo();
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "page");
+ mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1));
+ a = hwpinfo.paper.left_margin;
+ b = hwpinfo.paper.top_margin + hwpinfo.paper.header_length;
+ break;
+ }
+ }
+
+ if (drawobj->type == HWPDO_CONTAINER)
+ {
+ startEl("draw:g");
+ mxList->clear();
+ makePictureDRAW(drawobj->child.get(), hbox);
+ endEl("draw:g");
+ }
+ else
+ {
+ double x = hbox->pgx;
+ double y = hbox->pgy;
+
+ bIsRotate = false;
+ if( (drawobj->property.flag & HWPDO_FLAG_ROTATION) &&
+ (drawobj->property.parall.pt[0].y != drawobj->property.parall.pt[1].y) &&
+ //(drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE || drawobj->type == HWPDO_ADVANCED_ARC )
+ (drawobj->type == HWPDO_RECT || drawobj->type == HWPDO_ADVANCED_ELLIPSE )
+ )
+ {
+
+ int i;
+ ZZParall& pal = drawobj->property.parall;
+
+ basegfx::B2DPoint pt[3], r_pt[3];
+ for(i = 0 ; i < 3 ; i++ ){
+ basegfx::B2DPoint rot_origin(drawobj->property.rot_originx, drawobj->property.rot_originy);
+ pt[i].setX(pal.pt[i].x - rot_origin.getX());
+ /* Convert to a physical coordinate */
+ pt[i].setY(-(pal.pt[i].y - rot_origin.getY()));
+ }
+
+ double skewX;
+
+ /* 2 - rotation angle calculation */
+ double rotate = atan2(pt[1].getY() - pt[0].getY(), pt[1].getX() - pt[0].getX());
+
+ for( i = 0 ; i < 3 ; i++){
+ r_pt[i].setX(pt[i].getX() * cos(-rotate) - pt[i].getY() * sin(-rotate));
+ r_pt[i].setY(pt[i].getY() * cos(-rotate) + pt[i].getX() * sin(-rotate));
+ }
+
+ /* 4 - Calculation of reflex angle */
+ if (r_pt[2].getY() == r_pt[1].getY())
+ skewX = 0;
+ else
+ skewX = atan((r_pt[2].getX() - r_pt[1].getX()) / (r_pt[2].getY() - r_pt[1].getY()));
+ if( skewX >= M_PI_2 )
+ skewX -= M_PI;
+ if( skewX <= -M_PI_2 )
+ skewX += M_PI;
+
+ OUString trans;
+ if( skewX != 0.0 && rotate != 0.0 ){
+ trans = "skewX (" + OUString::number(skewX)
+ + ") rotate (" + OUString::number(rotate)
+ + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm "
+ + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)";
+ bIsRotate = true;
+ }
+ else if( skewX != 0.0 ){
+ trans = "skewX (" + OUString::number(skewX)
+ + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm "
+ + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)";
+ bIsRotate = true;
+ }
+ else if( rotate != 0.0 ){
+ trans = "rotate (" + OUString::number(rotate)
+ + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm "
+ + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)";
+ bIsRotate = true;
+ }
+ if( bIsRotate ){
+ drawobj->extent.w = static_cast<int>(std::hypot(pt[1].getX() - pt[0].getX(), pt[1].getY() - pt[0].getY()));
+ drawobj->extent.h = static_cast<int>(std::hypot(pt[2].getX() - pt[1].getX(), pt[2].getY() - pt[1].getY()));
+ mxList->addAttribute("draw:transform", sXML_CDATA, trans);
+ }
+ }
+ switch (drawobj->type)
+ {
+ case HWPDO_LINE: /* Line-starting coordinates, ending coordinates. */
+ if( drawobj->u.line_arc.flip & 0x01 )
+ {
+ mxList->addAttribute("svg:x1", sXML_CDATA,
+ OUString::number (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm");
+ mxList->addAttribute("svg:x2", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x )) + "mm");
+ }
+ else
+ {
+ mxList->addAttribute("svg:x1", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x )) + "mm");
+ mxList->addAttribute("svg:x2", sXML_CDATA,
+ OUString::number (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm");
+ }
+ if( drawobj->u.line_arc.flip & 0x02 )
+ {
+ mxList->addAttribute("svg:y1", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y + drawobj->extent.h ) ) + "mm");
+ mxList->addAttribute("svg:y2", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y )) + "mm");
+ }
+ else
+ {
+ mxList->addAttribute("svg:y1", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ mxList->addAttribute("svg:y2", sXML_CDATA,
+ OUString::number (WTMM(y + b + drawobj->offset2.y + drawobj->extent.h)) + "mm");
+ }
+
+ startEl("draw:line");
+ mxList->clear();
+ endEl("draw:line");
+ break;
+ case HWPDO_RECT: /* rectangle - the starting position, vertical/horizontal */
+ if( !bIsRotate )
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w )) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h )) + "mm");
+ if( drawobj->property.flag & 0x01 )
+ {
+ int value = drawobj->extent.w < drawobj->extent.h ?
+ drawobj->extent.w : drawobj->extent.h ;
+ mxList->addAttribute("draw:corner-radius", sXML_CDATA,
+ OUString::number (WTMM( value/10 )) + "mm");
+ }
+ else if( drawobj->property.flag & 0x04 )
+ {
+ int value = drawobj->extent.w < drawobj->extent.h ?
+ drawobj->extent.w : drawobj->extent.h ;
+ mxList->addAttribute("draw:corner-radius", sXML_CDATA,
+ OUString::number (WTMM( value / 2)) + "mm");
+ }
+
+ startEl("draw:rect");
+ mxList->clear();
+ if( (drawobj->property.flag & HWPDO_FLAG_AS_TEXTBOX) &&
+ drawobj->property.pPara ) // As Textbox
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ //parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:rect");
+ break;
+ case HWPDO_ELLIPSE: /* Ellipse - the starting position, vertical/horizontal */
+ case HWPDO_ADVANCED_ELLIPSE: /* modified ellipse */
+ {
+ if( !bIsRotate )
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ }
+
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w )) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h )) + "mm");
+ if( drawobj->type == HWPDO_ADVANCED_ELLIPSE ){
+ if (drawobj->u.arc.radial[0].x != drawobj->u.arc.radial[1].x ||
+ drawobj->u.arc.radial[0].y != drawobj->u.arc.radial[1].y) {
+
+ int Cx, Cy;
+ if (!o3tl::checked_add(drawobj->offset2.x, drawobj->extent.w, Cx) &&
+ !o3tl::checked_add(drawobj->offset2.y, drawobj->extent.h, Cy))
+ {
+ Cx /= 2;
+ Cy /= 2;
+
+ double start_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[0].x, drawobj->u.arc.radial[0].y );
+ double end_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[1].x, drawobj->u.arc.radial[1].y );
+ if( drawobj->property.fill_color < 0xffffff )
+ mxList->addAttribute("draw:kind", sXML_CDATA, "section");
+ else
+ mxList->addAttribute("draw:kind", sXML_CDATA, "arc");
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, OUString::number(start_angle ));
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, OUString::number(end_angle));
+ }
+ }
+ }
+ startEl("draw:ellipse");
+ mxList->clear();
+ if( drawobj->property.flag >> 19 & 0x01 &&
+ drawobj->property.pPara ) // As Textbox
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ //parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:ellipse");
+ break;
+
+ }
+ case HWPDO_ARC: /* Arc */
+ case HWPDO_ADVANCED_ARC:
+ {
+ /* If it is the arc, LibreOffice assumes the size as the entire ellipse size */
+ uint flip = drawobj->u.line_arc.flip;
+ if( !bIsRotate )
+ {
+ if( ( flip == 0 || flip == 2 ) && drawobj->type == HWPDO_ARC)
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x - drawobj->extent.w)) + "mm");
+ else
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ if( ( flip == 0 || flip == 1 ) && drawobj->type == HWPDO_ARC)
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y - drawobj->extent.h)) + "mm");
+ else
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ }
+
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w * 2)) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h * 2)) + "mm");
+ if( drawobj->property.flag & HWPDO_FLAG_DRAW_PIE ||
+ drawobj->property.fill_color < 0xffffff )
+ mxList->addAttribute("draw:kind", sXML_CDATA, "section");
+ else
+ mxList->addAttribute("draw:kind", sXML_CDATA, "arc");
+
+ if( drawobj->type == HWPDO_ADVANCED_ARC ){
+ double start_angle, end_angle;
+ ZZParall& pal = drawobj->property.parall;
+
+ start_angle = atan2(pal.pt[0].y - pal.pt[1].y,pal.pt[1].x - pal.pt[0].x );
+ end_angle = atan2(pal.pt[2].y - pal.pt[1].y, pal.pt[1].x - pal.pt[2].x);
+
+ if( ( start_angle > end_angle ) && (start_angle - end_angle < M_PI )){
+ double tmp_angle = start_angle;
+ start_angle = end_angle;
+ end_angle = tmp_angle;
+ }
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, OUString::number(basegfx::rad2deg(start_angle)));
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, OUString::number(basegfx::rad2deg(end_angle)));
+
+ }
+ else
+ {
+ if( drawobj->u.line_arc.flip == 0 )
+ {
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, "270");
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, "0");
+ }
+ else if( drawobj->u.line_arc.flip == 1 )
+ {
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, "180");
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, "270");
+ }
+ else if( drawobj->u.line_arc.flip == 2 )
+ {
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, "0");
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, "90");
+ }
+ else
+ {
+ mxList->addAttribute("draw:start-angle", sXML_CDATA, "90");
+ mxList->addAttribute("draw:end-angle", sXML_CDATA, "180");
+ }
+ }
+ startEl("draw:ellipse");
+ mxList->clear();
+ if( drawobj->property.flag >> 19 & 0x01 &&
+ drawobj->property.pPara ) // As Textbox
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ //parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:ellipse");
+ break;
+
+ }
+ case HWPDO_CURVE: /* Curve: converts to polygons. */
+ {
+ bool bIsNatural = true;
+ if( drawobj->property.flag >> 5 & 0x01){
+ bIsNatural = false;
+ }
+ if( !bIsRotate )
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w )) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h )) + "mm");
+ sprintf(d->buf, "0 0 %d %d", WTSM(drawobj->extent.w) , WTSM(drawobj->extent.h) );
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, OUString::createFromAscii(d->buf));
+
+ OUStringBuffer oustr;
+
+ if ((drawobj->u.freeform.npt > 2) &&
+ (o3tl::make_unsigned(drawobj->u.freeform.npt) <
+ (::std::numeric_limits<int>::max() / sizeof(double))))
+ {
+ int n, i;
+ n = drawobj->u.freeform.npt;
+
+ std::unique_ptr<double[]> xarr( new double[n+1] );
+ std::unique_ptr<double[]> yarr( new double[n+1] );
+ std::unique_ptr<double[]> tarr( new double[n+1] );
+
+ std::unique_ptr<double[]> xb;
+ std::unique_ptr<double[]> yb;
+
+ std::unique_ptr<double[]> carr;
+ std::unique_ptr<double[]> darr;
+
+
+ for( i = 0 ; i < n ; i++ ){
+ xarr[i] = drawobj->u.freeform.pt[i].x;
+ yarr[i] = drawobj->u.freeform.pt[i].y;
+ tarr[i] = i;
+ }
+ xarr[n] = xarr[0];
+ yarr[n] = yarr[0];
+ tarr[n] = n;
+
+ if( !bIsNatural ){
+ PeriodicSpline(n, tarr.get(), xarr.get(), xb, carr, darr);
+ // prevent memory leak
+ carr.reset();
+ darr.reset();
+ PeriodicSpline(n, tarr.get(), yarr.get(), yb, carr, darr);
+ }
+ else{
+ NaturalSpline(n, tarr.get(), xarr.get(), xb, carr, darr);
+ // prevent memory leak
+ carr.reset();
+ darr.reset();
+ NaturalSpline(n, tarr.get(), yarr.get(), yb, carr, darr);
+ }
+
+ sprintf(d->buf, "M%d %dC%d %d", WTSM(xarr[0]), WTSM(yarr[0]),
+ WTSM(xarr[0] + xb[0]/3), WTSM(yarr[0] + yb[0]/3) );
+ oustr.appendAscii(d->buf);
+
+ for( i = 1 ; i < n ; i++ ){
+ if( i == n -1 ){
+ sprintf(d->buf, " %d %d %d %dz",
+ WTSM(xarr[i] - xb[i]/3), WTSM(yarr[i] - yb[i]/3),
+ WTSM(xarr[i]), WTSM(yarr[i]) );
+ }
+ else{
+ sprintf(d->buf, " %d %d %d %d %d %d",
+ WTSM(xarr[i] - xb[i]/3), WTSM(yarr[i] - yb[i]/3),
+ WTSM(xarr[i]), WTSM(yarr[i]),
+ WTSM(xarr[i] + xb[i]/3), WTSM(yarr[i] + yb[i]/3) );
+ }
+
+ oustr.appendAscii(d->buf);
+ }
+ }
+
+ mxList->addAttribute("svg:d", sXML_CDATA, oustr.makeStringAndClear());
+
+ startEl("draw:path");
+ mxList->clear();
+ // As Textbox
+ if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara )
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:path");
+ break;
+ }
+ case HWPDO_CLOSED_FREEFORM:
+ case HWPDO_FREEFORM: /* polygon */
+ {
+ bool bIsPolygon = false;
+
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w )) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h )) + "mm");
+
+ sprintf(d->buf, "0 0 %d %d", WTSM(drawobj->extent.w), WTSM(drawobj->extent.h));
+ mxList->addAttribute("svg:viewBox", sXML_CDATA, OUString::createFromAscii(d->buf));
+
+ OUStringBuffer oustr;
+
+ if (drawobj->u.freeform.npt > 0)
+ {
+ sprintf(d->buf, "%d,%d", WTSM(drawobj->u.freeform.pt[0].x), WTSM(drawobj->u.freeform.pt[0].y));
+ oustr.appendAscii(d->buf);
+ int i;
+ for (i = 1; i < drawobj->u.freeform.npt ; i++)
+ {
+ sprintf(d->buf, " %d,%d",
+ WTSM(drawobj->u.freeform.pt[i].x),
+ WTSM(drawobj->u.freeform.pt[i].y));
+ oustr.appendAscii(d->buf);
+ }
+ if( drawobj->u.freeform.pt[0].x == drawobj->u.freeform.pt[i-1].x &&
+ drawobj->u.freeform.pt[0].y == drawobj->u.freeform.pt[i-1].y )
+ {
+ bIsPolygon = true;
+ }
+ }
+ mxList->addAttribute("draw:points", sXML_CDATA, oustr.makeStringAndClear());
+
+ if( drawobj->property.fill_color <= 0xffffff ||
+ drawobj->property.pattern_type != 0)
+ {
+ bIsPolygon = true;
+ }
+
+ if(bIsPolygon)
+ {
+ startEl("draw:polygon");
+ mxList->clear();
+ if( drawobj->property.flag >> 19 & 0x01 &&
+ // As Textbox
+ drawobj->property.pPara )
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ // parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:polygon");
+ }
+ else
+ {
+ startEl("draw:polyline");
+ mxList->clear();
+ if( drawobj->property.flag >> 19 & 0x01 &&
+ // As Textbox
+ drawobj->property.pPara )
+ {
+ HWPPara *pPara = drawobj->property.pPara;
+ //parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+ }
+ endEl("draw:polyline");
+ }
+ break;
+ }
+ case HWPDO_TEXTBOX:
+ if( !bIsRotate )
+ {
+ mxList->addAttribute("svg:x", sXML_CDATA,
+ OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm");
+ mxList->addAttribute("svg:y", sXML_CDATA,
+ OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm");
+ }
+ mxList->addAttribute("svg:width", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.w )) + "mm");
+ mxList->addAttribute("svg:height", sXML_CDATA,
+ OUString::number (WTMM( drawobj->extent.h )) + "mm");
+ if( drawobj->property.flag & 0x01 )
+ {
+ int value = drawobj->extent.w < drawobj->extent.h ?
+ drawobj->extent.w : drawobj->extent.h ;
+ mxList->addAttribute("draw:corner-radius", sXML_CDATA,
+ OUString::number (WTMM( value/10 )) + "mm");
+ }
+ else if( drawobj->property.flag & 0x04 )
+ {
+ int value = drawobj->extent.w < drawobj->extent.h ?
+ drawobj->extent.w : drawobj->extent.h ;
+ mxList->addAttribute("draw:corner-radius", sXML_CDATA,
+ OUString::number (WTMM( value / 2)) + "mm");
+ }
+
+ startEl("draw:text-box");
+ mxList->clear();
+
+ HWPPara *pPara = drawobj->u.textbox.h;
+ //parsePara(pPara);
+ while(pPara)
+ {
+ make_text_p1( pPara, false );
+ pPara = pPara->Next();
+ }
+
+ endEl("draw:text-box");
+ break;
+ }
+ }
+ mxList->clear();
+ drawobj = drawobj->next.get();
+ }
+}
+
+void HwpReader::makeLine()
+{
+ mxList->addAttribute("text:style-name", sXML_CDATA, "Horizontal Line");
+ startEl("text:p");
+ mxList->clear();
+}
+
+/**
+ * Input-comment-hidden description: shows a hidden explanation to the users.
+ * Parse out only strings, but it may contain paragraphs.
+ */
+void HwpReader::makeHidden(Hidden * hbox)
+{
+ hchar_string str;
+ int res;
+ hchar dest[3];
+
+ mxList->addAttribute("text:condition", sXML_CDATA, "");
+ mxList->addAttribute("text:string-value", sXML_CDATA, "");
+ startEl("text:hidden-text");
+ mxList->clear();
+ HWPPara *para = !hbox->plist.empty() ? hbox->plist.front().get() : nullptr;
+
+ while (para)
+ {
+ for (int n = 0; n < para->nch && para->hhstr.count(n) && para->hhstr[n]->hh;
+ n += para->hhstr[n]->WSize())
+ {
+ res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
+ for( int j = 0 ; j < res ; j++ )
+ {
+ str.push_back(dest[j]);
+ }
+ }
+ para = para->Next();
+ }
+ makeChars(str);
+ endEl("text:hidden-text");
+}
+
+
+/**
+ * Converts footnote to text:footnote, endnote to text:endnote
+ */
+void HwpReader::makeFootnote(Footnote * hbox)
+{
+ if (hbox->type)
+ {
+ mxList->addAttribute("text:id", sXML_CDATA, "edn" + OUString::number(hbox->number));
+ startEl("text:endnote");
+ mxList->clear();
+ mxList->addAttribute("text:label", sXML_CDATA, OUString::number(hbox->number));
+ startEl("text:endnote-citation");
+ mxList->clear();
+ chars(OUString::number(hbox->number));
+ endEl("text:endnote-citation");
+ startEl("text:endnote-body");
+ if (!hbox->plist.empty())
+ parsePara(hbox->plist.front().get());
+ endEl("text:endnote-body");
+ endEl("text:endnote");
+ }
+ else
+ {
+ mxList->addAttribute("text:id", sXML_CDATA, "ftn" + OUString::number(hbox->number));
+ startEl("text:footnote");
+ mxList->clear();
+ mxList->addAttribute("text:label", sXML_CDATA, OUString::number(hbox->number));
+ startEl("text:footnote-citation");
+ mxList->clear();
+ chars(OUString::number(hbox->number));
+ endEl("text:footnote-citation");
+ startEl("text:footnote-body");
+ if (!hbox->plist.empty())
+ parsePara(hbox->plist.front().get());
+ endEl("text:footnote-body");
+ endEl("text:footnote");
+ }
+}
+
+
+/**
+ * page/footnote/endnote/picture/table/formula number
+ */
+void HwpReader::makeAutoNum(AutoNum const * hbox)
+{
+ switch (hbox->type)
+ {
+ case PGNUM_AUTO:
+ startEl("text:page-number");
+ chars(OUString::number(hbox->number));
+ endEl("text:page-number");
+ break;
+ case FNNUM_AUTO:
+ break;
+ case ENNUM_AUTO:
+ break;
+ case EQUNUM_AUTO:
+ case PICNUM_AUTO:
+ mxList->addAttribute("text:ref-name",sXML_CDATA, "refIllustration" + OUString::number(hbox->number));
+ mxList->addAttribute("text:name",sXML_CDATA, "Illustration");
+ mxList->addAttribute("style:num-format",sXML_CDATA, "1");
+ startEl("text:sequence");
+ chars(OUString::number(hbox->number));
+ endEl("text:sequence");
+ break;
+ case TBLNUM_AUTO:
+ mxList->addAttribute("text:ref-name",sXML_CDATA, "refTable" + OUString::number(hbox->number));
+ mxList->addAttribute("text:name",sXML_CDATA, "Table");
+ mxList->addAttribute("style:num-format",sXML_CDATA, "1");
+ startEl("text:sequence");
+ chars(OUString::number(hbox->number));
+ endEl("text:sequence");
+ break;
+ }
+}
+
+
+void HwpReader::makeShowPageNum()
+{
+ ShowPageNum *hbox = d->pPn;
+ int nPos = 0;
+ if( hbox->where == 1 || hbox->where == 4 )
+ nPos = 1;
+ else if( hbox->where == 2 || hbox->where == 5 )
+ nPos = 2;
+ else if( hbox->where == 3 || hbox->where == 6 )
+ nPos = 3;
+ else /* should not exist in this case. */
+ {
+ if( d->nPnPos == 1 )
+ nPos = 1;
+ else if( d->nPnPos == 3 )
+ nPos = 3;
+ }
+
+ mxList->addAttribute("draw:style-name", sXML_CDATA, "PNBox" + OUString::number(nPos));
+ mxList->addAttribute("draw:name", sXML_CDATA, "PageNumber" + OUString::number(nPos));
+ mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph");
+ mxList->addAttribute("svg:y", sXML_CDATA, "0cm");
+ mxList->addAttribute("svg:width", sXML_CDATA, "2.0cm");
+ mxList->addAttribute("fo:min-height", sXML_CDATA, "0.5cm");
+ startEl("draw:text-box");
+ mxList->clear();
+
+ mxList->addAttribute("text:style-name", sXML_CDATA, "PNPara" + OUString::number(nPos));
+ startEl("text:p");
+ mxList->clear();
+ if( hbox->shape > 2 )
+ chars("- ");
+ if( hbox->shape % 3 == 0 )
+ mxList->addAttribute("style:num-format", sXML_CDATA, "1");
+ else if( hbox->shape % 3 == 1 )
+ mxList->addAttribute("style:num-format", sXML_CDATA, "I");
+ else
+ mxList->addAttribute("style:num-format", sXML_CDATA, "i");
+ mxList->addAttribute("text:select-page", sXML_CDATA, "current");
+ startEl("text:page-number");
+ mxList->clear();
+ chars("2");
+ endEl("text:page-number");
+ if( hbox->shape > 2 )
+ chars(" -");
+ endEl("text:p");
+ endEl("draw:text-box");
+}
+
+
+/**
+ * mail merge operation using hwp addressbook and hwp data form.
+ * not support operation in OO writer.
+ */
+void HwpReader::makeMailMerge(MailMerge *)
+{
+ hchar_string const boxstr = MailMerge::GetString();
+ chars(hstr2OUString(boxstr.c_str()));
+}
+
+
+void HwpReader::makeOutline(Outline const * hbox)
+{
+ if( hbox->kind == 1 )
+ chars( hbox->GetUnicode() );
+}
+
+
+void HwpReader::parsePara(HWPPara * para)
+{
+ bool bParaStart = false;
+ while (para)
+ {
+ if( para->nch == 1)
+ {
+ if( !bParaStart )
+ {
+ mxList->addAttribute("text:style-name", sXML_CDATA,
+ getPStyleName(para->GetParaShape().index));
+ startEl("text:p");
+ mxList->clear();
+ }
+ if( d->bFirstPara && d->bInBody )
+ {
+/* for HWP's Bookmark */
+ mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc);
+ startEl("text:bookmark");
+ mxList->clear();
+ endEl("text:bookmark");
+ d->bFirstPara = false;
+ }
+ if( d->bInHeader )
+ {
+ makeShowPageNum();
+ d->bInHeader = false;
+ }
+
+ endEl("text:p");
+ }
+ else
+ {
+ if (!para->ctrlflag)
+ {
+ if (para->contain_cshape)
+ make_text_p1(para, bParaStart);
+ else
+ make_text_p0(para, bParaStart);
+ }
+ else
+ make_text_p3(para, bParaStart);
+ }
+ bParaStart = false;
+ para = para->Next();
+ }
+}
+
+
+void HwpReader::startEl(const OUString& el)
+{
+ if (m_rxDocumentHandler)
+ m_rxDocumentHandler->startElement(el, mxList);
+}
+
+
+void HwpReader::endEl(const OUString& el)
+{
+ if (m_rxDocumentHandler)
+ m_rxDocumentHandler->endElement(el);
+}
+
+
+void HwpReader::chars(const OUString& s)
+{
+ if (m_rxDocumentHandler)
+ m_rxDocumentHandler->characters(s);
+}
+
+
+namespace
+{
+
+constexpr OUStringLiteral IMPLEMENTATION_NAME = u"com.sun.comp.hwpimport.HwpImportFilter";
+constexpr OUStringLiteral SERVICE_NAME1 = u"com.sun.star.document.ImportFilter";
+constexpr OUStringLiteral SERVICE_NAME2 = u"com.sun.star.document.ExtendedTypeDetection";
+
+class HwpImportFilter : public WeakImplHelper< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
+{
+public:
+ explicit HwpImportFilter(const Reference< XComponentContext >& );
+
+public:
+ // XFilter
+ virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override;
+ virtual void SAL_CALL cancel() override;
+
+ // XImporter
+ virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc) override;
+
+ // XServiceInfo
+ OUString SAL_CALL getImplementationName() override;
+ Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
+ sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+
+ //XExtendedFilterDetection
+ virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor ) override;
+
+private:
+ Reference< XFilter > rFilter;
+ Reference< XImporter > rImporter;
+};
+
+
+HwpImportFilter::HwpImportFilter(const Reference< XComponentContext >& rxContext)
+{
+ try {
+ Reference< XDocumentHandler > xHandler( rxContext->getServiceManager()->createInstanceWithContext( WRITER_IMPORTER_NAME, rxContext ), UNO_QUERY );
+
+ rtl::Reference<HwpReader> p = new HwpReader;
+ p->setDocumentHandler( xHandler );
+
+ Reference< XImporter > xImporter( xHandler, UNO_QUERY );
+ rImporter = xImporter;
+ rFilter = p;
+ }
+ catch( Exception & )
+ {
+ printf(" fail to instantiate %s\n", OUString(WRITER_IMPORTER_NAME).toUtf8().getStr() );
+ exit( 1 );
+ }
+}
+
+sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
+{
+ // delegate to IchitaroImporter
+ return rFilter->filter( aDescriptor );
+}
+
+void HwpImportFilter::cancel()
+{
+ rFilter->cancel();
+}
+
+void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
+{
+ // delegate
+ rImporter->setTargetDocument( xDoc );
+}
+
+OUString HwpImportFilter::getImplementationName()
+{
+ return IMPLEMENTATION_NAME;
+}
+
+sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+//XExtendedFilterDetection
+OUString HwpImportFilter::detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor )
+{
+ OUString sTypeName;
+
+ utl::MediaDescriptor aDescriptor(rDescriptor);
+ aDescriptor.addInputStream();
+
+ Reference< XInputStream > xInputStream(
+ aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM], UNO_QUERY);
+
+ if (xInputStream.is())
+ {
+ Sequence< sal_Int8 > aData;
+ sal_Int32 nLen = HWPIDLen;
+ if (
+ nLen == xInputStream->readBytes(aData, nLen) &&
+ detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
+ )
+ {
+ sTypeName = "writer_MIZI_Hwp_97";
+ }
+ }
+
+ return sTypeName;
+}
+
+Sequence< OUString> HwpImportFilter::getSupportedServiceNames()
+{
+ return { SERVICE_NAME1, SERVICE_NAME2 };
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+hwpfilter_HwpImportFilter_get_implementation(
+ css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire(new HwpImportFilter(context));
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx
new file mode 100644
index 000000000..0cb9e62c0
--- /dev/null
+++ b/hwpfilter/source/hwpreader.hxx
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
+#define INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
+
+#include <sal/config.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtl/ustring.hxx>
+#include <sal/alloca.h>
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XActiveDataControl.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <cppuhelper/weak.hxx>
+#include <memory>
+
+using namespace ::cppu;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::xml::sax;
+
+#include <assert.h>
+
+#include <unotools/mediadescriptor.hxx>
+
+#include "hwpfile.h"
+#include "hcode.h"
+#include "hbox.h"
+#include "htags.h"
+#include "hstream.hxx"
+#include "drawdef.h"
+#include "attributes.hxx"
+
+inline constexpr OUStringLiteral WRITER_IMPORTER_NAME = u"com.sun.star.comp.Writer.XMLImporter";
+
+struct HwpReaderPrivate;
+/**
+ * This class implements the external Parser interface
+ */
+class HwpReader : public WeakImplHelper<XFilter>
+{
+
+public:
+ HwpReader();
+ virtual ~HwpReader() override;
+
+public:
+ /**
+ * parseStream does Parser-startup initializations
+ */
+ virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue >& aDescriptor) override;
+ virtual void SAL_CALL cancel() override {}
+ void setDocumentHandler(Reference< XDocumentHandler > const & xHandler)
+ {
+ m_rxDocumentHandler = xHandler;
+ }
+
+ bool importHStream(std::unique_ptr<HStream> stream);
+private:
+ Reference< XDocumentHandler > m_rxDocumentHandler;
+ rtl::Reference<AttributeListImpl> mxList;
+ HWPFile hwpfile;
+ std::unique_ptr<HwpReaderPrivate> d;
+private:
+ /* -------- Document Parsing --------- */
+ void makeMeta();
+ void makeStyles();
+ void makeDrawMiscStyle(HWPDrawingObject *);
+ void makeAutoStyles();
+ void makeMasterStyles();
+ void makeBody();
+
+ void makeTextDecls();
+
+ /* -------- Paragraph Parsing --------- */
+ void parsePara(HWPPara *para);
+ void make_text_p0(HWPPara *para, bool bParaStart);
+ void make_text_p1(HWPPara *para, bool bParaStart);
+ void make_text_p3(HWPPara *para, bool bParaStart);
+
+ /* -------- rDocument->characters(x) --------- */
+ void makeChars(hchar_string & rStr);
+
+ /* -------- Special Char Parsing --------- */
+ void makeFieldCode(hchar_string const & rStr, FieldCode const *hbox); //6
+ void makeBookmark(Bookmark const *hbox); //6
+ void makeDateFormat(DateCode *hbox); //7
+ void makeDateCode(DateCode *hbox); //8
+ void makeTab(); //9
+ void makeTable(TxtBox *hbox);
+ void makeTextBox(TxtBox *hbox);
+ void makeFormula(TxtBox *hbox);
+ void makeHyperText(TxtBox *hbox);
+ void makePicture(Picture *hbox);
+ void makePictureDRAW(HWPDrawingObject *drawobj, const Picture *hbox);
+ void makeLine();
+ void makeHidden(Hidden *hbox);
+ void makeFootnote(Footnote *hbox);
+ void makeAutoNum(AutoNum const *hbox);
+ void makeShowPageNum();
+ void makeMailMerge(MailMerge *hbox);
+ void makeOutline(Outline const *hbox);
+
+ /* --------- Styles Parsing ------------ */
+ void makePageStyle();
+ void makeColumns(ColumnDef const *);
+ void makeTStyle(CharShape const *);
+ void makePStyle(ParaShape const *);
+ void makeFStyle(FBoxStyle *);
+ void makeCaptionStyle(FBoxStyle *);
+ void makeDrawStyle(HWPDrawingObject *,FBoxStyle *);
+ void makeTableStyle(Table *);
+ void parseCharShape(CharShape const *);
+ void parseParaShape(ParaShape const *);
+ static OUString getTStyleName(int);
+ static OUString getPStyleName(int);
+
+ void startEl(const OUString& el);
+ void endEl(const OUString& el);
+ void chars(const OUString& s);
+};
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/ksc5601.h b/hwpfilter/source/ksc5601.h
new file mode 100644
index 000000000..e4d60b32f
--- /dev/null
+++ b/hwpfilter/source/ksc5601.h
@@ -0,0 +1,863 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* $XFree86: xc/lib/X11/lcUniConv/ksc5601.h,v 1.4tsi Exp
+
+ Copyright (c) 1999-2000 Free Software Foundation, Inc.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ FREE SOFTWARE FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * KSC5601.1987-0
+ */
+
+const hchar ksc5601_2uni_page21[1115] = {
+ /* 0x21 */
+ 0x3000, 0x3001, 0x3002, 0x00b7, 0x2025, 0x2026, 0x00a8, 0x3003,
+ 0x00ad, 0x2015, 0x2225, 0xff3c, 0x223c, 0x2018, 0x2019, 0x201c,
+ 0x201d, 0x3014, 0x3015, 0x3008, 0x3009, 0x300a, 0x300b, 0x300c,
+ 0x300d, 0x300e, 0x300f, 0x3010, 0x3011, 0x00b1, 0x00d7, 0x00f7,
+ 0x2260, 0x2264, 0x2265, 0x221e, 0x2234, 0x00b0, 0x2032, 0x2033,
+ 0x2103, 0x212b, 0xffe0, 0xffe1, 0xffe5, 0x2642, 0x2640, 0x2220,
+ 0x22a5, 0x2312, 0x2202, 0x2207, 0x2261, 0x2252, 0x00a7, 0x203b,
+ 0x2606, 0x2605, 0x25cb, 0x25cf, 0x25ce, 0x25c7, 0x25c6, 0x25a1,
+ 0x25a0, 0x25b3, 0x25b2, 0x25bd, 0x25bc, 0x2192, 0x2190, 0x2191,
+ 0x2193, 0x2194, 0x3013, 0x226a, 0x226b, 0x221a, 0x223d, 0x221d,
+ 0x2235, 0x222b, 0x222c, 0x2208, 0x220b, 0x2286, 0x2287, 0x2282,
+ 0x2283, 0x222a, 0x2229, 0x2227, 0x2228, 0xffe2,
+ /* 0x22 */
+ 0x21d2, 0x21d4, 0x2200, 0x2203, 0x00b4, 0xff5e, 0x02c7, 0x02d8,
+ 0x02dd, 0x02da, 0x02d9, 0x00b8, 0x02db, 0x00a1, 0x00bf, 0x02d0,
+ 0x222e, 0x2211, 0x220f, 0x00a4, 0x2109, 0x2030, 0x25c1, 0x25c0,
+ 0x25b7, 0x25b6, 0x2664, 0x2660, 0x2661, 0x2665, 0x2667, 0x2663,
+ 0x2299, 0x25c8, 0x25a3, 0x25d0, 0x25d1, 0x2592, 0x25a4, 0x25a5,
+ 0x25a8, 0x25a7, 0x25a6, 0x25a9, 0x2668, 0x260f, 0x260e, 0x261c,
+ 0x261e, 0x00b6, 0x2020, 0x2021, 0x2195, 0x2197, 0x2199, 0x2196,
+ 0x2198, 0x266d, 0x2669, 0x266a, 0x266c, 0x327f, 0x321c, 0x2116,
+ 0x33c7, 0x2122, 0x33c2, 0x33d8, 0x2121, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x23 */
+ 0xff01, 0xff02, 0xff03, 0xff04, 0xff05, 0xff06, 0xff07, 0xff08,
+ 0xff09, 0xff0a, 0xff0b, 0xff0c, 0xff0d, 0xff0e, 0xff0f, 0xff10,
+ 0xff11, 0xff12, 0xff13, 0xff14, 0xff15, 0xff16, 0xff17, 0xff18,
+ 0xff19, 0xff1a, 0xff1b, 0xff1c, 0xff1d, 0xff1e, 0xff1f, 0xff20,
+ 0xff21, 0xff22, 0xff23, 0xff24, 0xff25, 0xff26, 0xff27, 0xff28,
+ 0xff29, 0xff2a, 0xff2b, 0xff2c, 0xff2d, 0xff2e, 0xff2f, 0xff30,
+ 0xff31, 0xff32, 0xff33, 0xff34, 0xff35, 0xff36, 0xff37, 0xff38,
+ 0xff39, 0xff3a, 0xff3b, 0xffe6, 0xff3d, 0xff3e, 0xff3f, 0xff40,
+ 0xff41, 0xff42, 0xff43, 0xff44, 0xff45, 0xff46, 0xff47, 0xff48,
+ 0xff49, 0xff4a, 0xff4b, 0xff4c, 0xff4d, 0xff4e, 0xff4f, 0xff50,
+ 0xff51, 0xff52, 0xff53, 0xff54, 0xff55, 0xff56, 0xff57, 0xff58,
+ 0xff59, 0xff5a, 0xff5b, 0xff5c, 0xff5d, 0xffe3,
+ /* 0x24 */
+ 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, 0x3138,
+ 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f, 0x3140,
+ 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147, 0x3148,
+ 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x314f, 0x3150,
+ 0x3151, 0x3152, 0x3153, 0x3154, 0x3155, 0x3156, 0x3157, 0x3158,
+ 0x3159, 0x315a, 0x315b, 0x315c, 0x315d, 0x315e, 0x315f, 0x3160,
+ 0x3161, 0x3162, 0x3163, 0x3164, 0x3165, 0x3166, 0x3167, 0x3168,
+ 0x3169, 0x316a, 0x316b, 0x316c, 0x316d, 0x316e, 0x316f, 0x3170,
+ 0x3171, 0x3172, 0x3173, 0x3174, 0x3175, 0x3176, 0x3177, 0x3178,
+ 0x3179, 0x317a, 0x317b, 0x317c, 0x317d, 0x317e, 0x317f, 0x3180,
+ 0x3181, 0x3182, 0x3183, 0x3184, 0x3185, 0x3186, 0x3187, 0x3188,
+ 0x3189, 0x318a, 0x318b, 0x318c, 0x318d, 0x318e,
+ /* 0x25 */
+ 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177,
+ 0x2178, 0x2179, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x2160,
+ 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168,
+ 0x2169, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
+ 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, 0x03a0,
+ 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8,
+ 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0,
+ 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x26 */
+ 0x2500, 0x2502, 0x250c, 0x2510, 0x2518, 0x2514, 0x251c, 0x252c,
+ 0x2524, 0x2534, 0x253c, 0x2501, 0x2503, 0x250f, 0x2513, 0x251b,
+ 0x2517, 0x2523, 0x2533, 0x252b, 0x253b, 0x254b, 0x2520, 0x252f,
+ 0x2528, 0x2537, 0x253f, 0x251d, 0x2530, 0x2525, 0x2538, 0x2542,
+ 0x2512, 0x2511, 0x251a, 0x2519, 0x2516, 0x2515, 0x250e, 0x250d,
+ 0x251e, 0x251f, 0x2521, 0x2522, 0x2526, 0x2527, 0x2529, 0x252a,
+ 0x252d, 0x252e, 0x2531, 0x2532, 0x2535, 0x2536, 0x2539, 0x253a,
+ 0x253d, 0x253e, 0x2540, 0x2541, 0x2543, 0x2544, 0x2545, 0x2546,
+ 0x2547, 0x2548, 0x2549, 0x254a, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x27 */
+ 0x3395, 0x3396, 0x3397, 0x2113, 0x3398, 0x33c4, 0x33a3, 0x33a4,
+ 0x33a5, 0x33a6, 0x3399, 0x339a, 0x339b, 0x339c, 0x339d, 0x339e,
+ 0x339f, 0x33a0, 0x33a1, 0x33a2, 0x33ca, 0x338d, 0x338e, 0x338f,
+ 0x33cf, 0x3388, 0x3389, 0x33c8, 0x33a7, 0x33a8, 0x33b0, 0x33b1,
+ 0x33b2, 0x33b3, 0x33b4, 0x33b5, 0x33b6, 0x33b7, 0x33b8, 0x33b9,
+ 0x3380, 0x3381, 0x3382, 0x3383, 0x3384, 0x33ba, 0x33bb, 0x33bc,
+ 0x33bd, 0x33be, 0x33bf, 0x3390, 0x3391, 0x3392, 0x3393, 0x3394,
+ 0x2126, 0x33c0, 0x33c1, 0x338a, 0x338b, 0x338c, 0x33d6, 0x33c5,
+ 0x33ad, 0x33ae, 0x33af, 0x33db, 0x33a9, 0x33aa, 0x33ab, 0x33ac,
+ 0x33dd, 0x33d0, 0x33d3, 0x33c3, 0x33c9, 0x33dc, 0x33c6, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x28 */
+ 0x00c6, 0x00d0, 0x00aa, 0x0126, 0xfffd, 0x0132, 0xfffd, 0x013f,
+ 0x0141, 0x00d8, 0x0152, 0x00ba, 0x00de, 0x0166, 0x014a, 0xfffd,
+ 0x3260, 0x3261, 0x3262, 0x3263, 0x3264, 0x3265, 0x3266, 0x3267,
+ 0x3268, 0x3269, 0x326a, 0x326b, 0x326c, 0x326d, 0x326e, 0x326f,
+ 0x3270, 0x3271, 0x3272, 0x3273, 0x3274, 0x3275, 0x3276, 0x3277,
+ 0x3278, 0x3279, 0x327a, 0x327b, 0x24d0, 0x24d1, 0x24d2, 0x24d3,
+ 0x24d4, 0x24d5, 0x24d6, 0x24d7, 0x24d8, 0x24d9, 0x24da, 0x24db,
+ 0x24dc, 0x24dd, 0x24de, 0x24df, 0x24e0, 0x24e1, 0x24e2, 0x24e3,
+ 0x24e4, 0x24e5, 0x24e6, 0x24e7, 0x24e8, 0x24e9, 0x2460, 0x2461,
+ 0x2462, 0x2463, 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469,
+ 0x246a, 0x246b, 0x246c, 0x246d, 0x246e, 0x00bd, 0x2153, 0x2154,
+ 0x00bc, 0x00be, 0x215b, 0x215c, 0x215d, 0x215e,
+ /* 0x29 */
+ 0x00e6, 0x0111, 0x00f0, 0x0127, 0x0131, 0x0133, 0x0138, 0x0140,
+ 0x0142, 0x00f8, 0x0153, 0x00df, 0x00fe, 0x0167, 0x014b, 0x0149,
+ 0x3200, 0x3201, 0x3202, 0x3203, 0x3204, 0x3205, 0x3206, 0x3207,
+ 0x3208, 0x3209, 0x320a, 0x320b, 0x320c, 0x320d, 0x320e, 0x320f,
+ 0x3210, 0x3211, 0x3212, 0x3213, 0x3214, 0x3215, 0x3216, 0x3217,
+ 0x3218, 0x3219, 0x321a, 0x321b, 0x249c, 0x249d, 0x249e, 0x249f,
+ 0x24a0, 0x24a1, 0x24a2, 0x24a3, 0x24a4, 0x24a5, 0x24a6, 0x24a7,
+ 0x24a8, 0x24a9, 0x24aa, 0x24ab, 0x24ac, 0x24ad, 0x24ae, 0x24af,
+ 0x24b0, 0x24b1, 0x24b2, 0x24b3, 0x24b4, 0x24b5, 0x2474, 0x2475,
+ 0x2476, 0x2477, 0x2478, 0x2479, 0x247a, 0x247b, 0x247c, 0x247d,
+ 0x247e, 0x247f, 0x2480, 0x2481, 0x2482, 0x00b9, 0x00b2, 0x00b3,
+ 0x2074, 0x207f, 0x2081, 0x2082, 0x2083, 0x2084,
+ /* 0x2a */
+ 0x3041, 0x3042, 0x3043, 0x3044, 0x3045, 0x3046, 0x3047, 0x3048,
+ 0x3049, 0x304a, 0x304b, 0x304c, 0x304d, 0x304e, 0x304f, 0x3050,
+ 0x3051, 0x3052, 0x3053, 0x3054, 0x3055, 0x3056, 0x3057, 0x3058,
+ 0x3059, 0x305a, 0x305b, 0x305c, 0x305d, 0x305e, 0x305f, 0x3060,
+ 0x3061, 0x3062, 0x3063, 0x3064, 0x3065, 0x3066, 0x3067, 0x3068,
+ 0x3069, 0x306a, 0x306b, 0x306c, 0x306d, 0x306e, 0x306f, 0x3070,
+ 0x3071, 0x3072, 0x3073, 0x3074, 0x3075, 0x3076, 0x3077, 0x3078,
+ 0x3079, 0x307a, 0x307b, 0x307c, 0x307d, 0x307e, 0x307f, 0x3080,
+ 0x3081, 0x3082, 0x3083, 0x3084, 0x3085, 0x3086, 0x3087, 0x3088,
+ 0x3089, 0x308a, 0x308b, 0x308c, 0x308d, 0x308e, 0x308f, 0x3090,
+ 0x3091, 0x3092, 0x3093, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x2b */
+ 0x30a1, 0x30a2, 0x30a3, 0x30a4, 0x30a5, 0x30a6, 0x30a7, 0x30a8,
+ 0x30a9, 0x30aa, 0x30ab, 0x30ac, 0x30ad, 0x30ae, 0x30af, 0x30b0,
+ 0x30b1, 0x30b2, 0x30b3, 0x30b4, 0x30b5, 0x30b6, 0x30b7, 0x30b8,
+ 0x30b9, 0x30ba, 0x30bb, 0x30bc, 0x30bd, 0x30be, 0x30bf, 0x30c0,
+ 0x30c1, 0x30c2, 0x30c3, 0x30c4, 0x30c5, 0x30c6, 0x30c7, 0x30c8,
+ 0x30c9, 0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf, 0x30d0,
+ 0x30d1, 0x30d2, 0x30d3, 0x30d4, 0x30d5, 0x30d6, 0x30d7, 0x30d8,
+ 0x30d9, 0x30da, 0x30db, 0x30dc, 0x30dd, 0x30de, 0x30df, 0x30e0,
+ 0x30e1, 0x30e2, 0x30e3, 0x30e4, 0x30e5, 0x30e6, 0x30e7, 0x30e8,
+ 0x30e9, 0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ee, 0x30ef, 0x30f0,
+ 0x30f1, 0x30f2, 0x30f3, 0x30f4, 0x30f5, 0x30f6, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ /* 0x2c */
+ 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0401, 0x0416,
+ 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
+ 0x041f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426,
+ 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e,
+ 0x042f, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
+ 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0451, 0x0436,
+ 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e,
+ 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446,
+ 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e,
+ 0x044f,
+};
+
+
+const hchar ksc5601_2uni_page4a[4888] = {
+ /* 0x4a */
+ 0x4f3d, 0x4f73, 0x5047, 0x50f9, 0x52a0, 0x53ef, 0x5475, 0x54e5,
+ 0x5609, 0x5ac1, 0x5bb6, 0x6687, 0x67b6, 0x67b7, 0x67ef, 0x6b4c,
+ 0x73c2, 0x75c2, 0x7a3c, 0x82db, 0x8304, 0x8857, 0x8888, 0x8a36,
+ 0x8cc8, 0x8dcf, 0x8efb, 0x8fe6, 0x99d5, 0x523b, 0x5374, 0x5404,
+ 0x606a, 0x6164, 0x6bbc, 0x73cf, 0x811a, 0x89ba, 0x89d2, 0x95a3,
+ 0x4f83, 0x520a, 0x58be, 0x5978, 0x59e6, 0x5e72, 0x5e79, 0x61c7,
+ 0x63c0, 0x6746, 0x67ec, 0x687f, 0x6f97, 0x764e, 0x770b, 0x78f5,
+ 0x7a08, 0x7aff, 0x7c21, 0x809d, 0x826e, 0x8271, 0x8aeb, 0x9593,
+ 0x4e6b, 0x559d, 0x66f7, 0x6e34, 0x78a3, 0x7aed, 0x845b, 0x8910,
+ 0x874e, 0x97a8, 0x52d8, 0x574e, 0x582a, 0x5d4c, 0x611f, 0x61be,
+ 0x6221, 0x6562, 0x67d1, 0x6a44, 0x6e1b, 0x7518, 0x75b3, 0x76e3,
+ 0x77b0, 0x7d3a, 0x90af, 0x9451, 0x9452, 0x9f95,
+ /* 0x4b */
+ 0x5323, 0x5cac, 0x7532, 0x80db, 0x9240, 0x9598, 0x525b, 0x5808,
+ 0x59dc, 0x5ca1, 0x5d17, 0x5eb7, 0x5f3a, 0x5f4a, 0x6177, 0x6c5f,
+ 0x757a, 0x7586, 0x7ce0, 0x7d73, 0x7db1, 0x7f8c, 0x8154, 0x8221,
+ 0x8591, 0x8941, 0x8b1b, 0x92fc, 0x964d, 0x9c47, 0x4ecb, 0x4ef7,
+ 0x500b, 0x51f1, 0x584f, 0x6137, 0x613e, 0x6168, 0x6539, 0x69ea,
+ 0x6f11, 0x75a5, 0x7686, 0x76d6, 0x7b87, 0x82a5, 0x84cb, 0xf900,
+ 0x93a7, 0x958b, 0x5580, 0x5ba2, 0x5751, 0xf901, 0x7cb3, 0x7fb9,
+ 0x91b5, 0x5028, 0x53bb, 0x5c45, 0x5de8, 0x62d2, 0x636e, 0x64da,
+ 0x64e7, 0x6e20, 0x70ac, 0x795b, 0x8ddd, 0x8e1e, 0xf902, 0x907d,
+ 0x9245, 0x92f8, 0x4e7e, 0x4ef6, 0x5065, 0x5dfe, 0x5efa, 0x6106,
+ 0x6957, 0x8171, 0x8654, 0x8e47, 0x9375, 0x9a2b, 0x4e5e, 0x5091,
+ 0x6770, 0x6840, 0x5109, 0x528d, 0x5292, 0x6aa2,
+ /* 0x4c */
+ 0x77bc, 0x9210, 0x9ed4, 0x52ab, 0x602f, 0x8ff2, 0x5048, 0x61a9,
+ 0x63ed, 0x64ca, 0x683c, 0x6a84, 0x6fc0, 0x8188, 0x89a1, 0x9694,
+ 0x5805, 0x727d, 0x72ac, 0x7504, 0x7d79, 0x7e6d, 0x80a9, 0x898b,
+ 0x8b74, 0x9063, 0x9d51, 0x6289, 0x6c7a, 0x6f54, 0x7d50, 0x7f3a,
+ 0x8a23, 0x517c, 0x614a, 0x7b9d, 0x8b19, 0x9257, 0x938c, 0x4eac,
+ 0x4fd3, 0x501e, 0x50be, 0x5106, 0x52c1, 0x52cd, 0x537f, 0x5770,
+ 0x5883, 0x5e9a, 0x5f91, 0x6176, 0x61ac, 0x64ce, 0x656c, 0x666f,
+ 0x66bb, 0x66f4, 0x6897, 0x6d87, 0x7085, 0x70f1, 0x749f, 0x74a5,
+ 0x74ca, 0x75d9, 0x786c, 0x78ec, 0x7adf, 0x7af6, 0x7d45, 0x7d93,
+ 0x8015, 0x803f, 0x811b, 0x8396, 0x8b66, 0x8f15, 0x9015, 0x93e1,
+ 0x9803, 0x9838, 0x9a5a, 0x9be8, 0x4fc2, 0x5553, 0x583a, 0x5951,
+ 0x5b63, 0x5c46, 0x60b8, 0x6212, 0x6842, 0x68b0,
+ /* 0x4d */
+ 0x68e8, 0x6eaa, 0x754c, 0x7678, 0x78ce, 0x7a3d, 0x7cfb, 0x7e6b,
+ 0x7e7c, 0x8a08, 0x8aa1, 0x8c3f, 0x968e, 0x9dc4, 0x53e4, 0x53e9,
+ 0x544a, 0x5471, 0x56fa, 0x59d1, 0x5b64, 0x5c3b, 0x5eab, 0x62f7,
+ 0x6537, 0x6545, 0x6572, 0x66a0, 0x67af, 0x69c1, 0x6cbd, 0x75fc,
+ 0x7690, 0x777e, 0x7a3f, 0x7f94, 0x8003, 0x80a1, 0x818f, 0x82e6,
+ 0x82fd, 0x83f0, 0x85c1, 0x8831, 0x88b4, 0x8aa5, 0xf903, 0x8f9c,
+ 0x932e, 0x96c7, 0x9867, 0x9ad8, 0x9f13, 0x54ed, 0x659b, 0x66f2,
+ 0x688f, 0x7a40, 0x8c37, 0x9d60, 0x56f0, 0x5764, 0x5d11, 0x6606,
+ 0x68b1, 0x68cd, 0x6efe, 0x7428, 0x889e, 0x9be4, 0x6c68, 0xf904,
+ 0x9aa8, 0x4f9b, 0x516c, 0x5171, 0x529f, 0x5b54, 0x5de5, 0x6050,
+ 0x606d, 0x62f1, 0x63a7, 0x653b, 0x73d9, 0x7a7a, 0x86a3, 0x8ca2,
+ 0x978f, 0x4e32, 0x5be1, 0x6208, 0x679c, 0x74dc,
+ /* 0x4e */
+ 0x79d1, 0x83d3, 0x8a87, 0x8ab2, 0x8de8, 0x904e, 0x934b, 0x9846,
+ 0x5ed3, 0x69e8, 0x85ff, 0x90ed, 0xf905, 0x51a0, 0x5b98, 0x5bec,
+ 0x6163, 0x68fa, 0x6b3e, 0x704c, 0x742f, 0x74d8, 0x7ba1, 0x7f50,
+ 0x83c5, 0x89c0, 0x8cab, 0x95dc, 0x9928, 0x522e, 0x605d, 0x62ec,
+ 0x9002, 0x4f8a, 0x5149, 0x5321, 0x58d9, 0x5ee3, 0x66e0, 0x6d38,
+ 0x709a, 0x72c2, 0x73d6, 0x7b50, 0x80f1, 0x945b, 0x5366, 0x639b,
+ 0x7f6b, 0x4e56, 0x5080, 0x584a, 0x58de, 0x602a, 0x6127, 0x62d0,
+ 0x69d0, 0x9b41, 0x5b8f, 0x7d18, 0x80b1, 0x8f5f, 0x4ea4, 0x50d1,
+ 0x54ac, 0x55ac, 0x5b0c, 0x5da0, 0x5de7, 0x652a, 0x654e, 0x6821,
+ 0x6a4b, 0x72e1, 0x768e, 0x77ef, 0x7d5e, 0x7ff9, 0x81a0, 0x854e,
+ 0x86df, 0x8f03, 0x8f4e, 0x90ca, 0x9903, 0x9a55, 0x9bab, 0x4e18,
+ 0x4e45, 0x4e5d, 0x4ec7, 0x4ff1, 0x5177, 0x52fe,
+ /* 0x4f */
+ 0x5340, 0x53e3, 0x53e5, 0x548e, 0x5614, 0x5775, 0x57a2, 0x5bc7,
+ 0x5d87, 0x5ed0, 0x61fc, 0x62d8, 0x6551, 0x67b8, 0x67e9, 0x69cb,
+ 0x6b50, 0x6bc6, 0x6bec, 0x6c42, 0x6e9d, 0x7078, 0x72d7, 0x7396,
+ 0x7403, 0x77bf, 0x77e9, 0x7a76, 0x7d7f, 0x8009, 0x81fc, 0x8205,
+ 0x820a, 0x82df, 0x8862, 0x8b33, 0x8cfc, 0x8ec0, 0x9011, 0x90b1,
+ 0x9264, 0x92b6, 0x99d2, 0x9a45, 0x9ce9, 0x9dd7, 0x9f9c, 0x570b,
+ 0x5c40, 0x83ca, 0x97a0, 0x97ab, 0x9eb4, 0x541b, 0x7a98, 0x7fa4,
+ 0x88d9, 0x8ecd, 0x90e1, 0x5800, 0x5c48, 0x6398, 0x7a9f, 0x5bae,
+ 0x5f13, 0x7a79, 0x7aae, 0x828e, 0x8eac, 0x5026, 0x5238, 0x52f8,
+ 0x5377, 0x5708, 0x62f3, 0x6372, 0x6b0a, 0x6dc3, 0x7737, 0x53a5,
+ 0x7357, 0x8568, 0x8e76, 0x95d5, 0x673a, 0x6ac3, 0x6f70, 0x8a6d,
+ 0x8ecc, 0x994b, 0xf906, 0x6677, 0x6b78, 0x8cb4,
+ /* 0x50 */
+ 0x9b3c, 0xf907, 0x53eb, 0x572d, 0x594e, 0x63c6, 0x69fb, 0x73ea,
+ 0x7845, 0x7aba, 0x7ac5, 0x7cfe, 0x8475, 0x898f, 0x8d73, 0x9035,
+ 0x95a8, 0x52fb, 0x5747, 0x7547, 0x7b60, 0x83cc, 0x921e, 0xf908,
+ 0x6a58, 0x514b, 0x524b, 0x5287, 0x621f, 0x68d8, 0x6975, 0x9699,
+ 0x50c5, 0x52a4, 0x52e4, 0x61c3, 0x65a4, 0x6839, 0x69ff, 0x747e,
+ 0x7b4b, 0x82b9, 0x83eb, 0x89b2, 0x8b39, 0x8fd1, 0x9949, 0xf909,
+ 0x4eca, 0x5997, 0x64d2, 0x6611, 0x6a8e, 0x7434, 0x7981, 0x79bd,
+ 0x82a9, 0x887e, 0x887f, 0x895f, 0xf90a, 0x9326, 0x4f0b, 0x53ca,
+ 0x6025, 0x6271, 0x6c72, 0x7d1a, 0x7d66, 0x4e98, 0x5162, 0x77dc,
+ 0x80af, 0x4f01, 0x4f0e, 0x5176, 0x5180, 0x55dc, 0x5668, 0x573b,
+ 0x57fa, 0x57fc, 0x5914, 0x5947, 0x5993, 0x5bc4, 0x5c90, 0x5d0e,
+ 0x5df1, 0x5e7e, 0x5fcc, 0x6280, 0x65d7, 0x65e3,
+ /* 0x51 */
+ 0x671e, 0x671f, 0x675e, 0x68cb, 0x68c4, 0x6a5f, 0x6b3a, 0x6c23,
+ 0x6c7d, 0x6c82, 0x6dc7, 0x7398, 0x7426, 0x742a, 0x7482, 0x74a3,
+ 0x7578, 0x757f, 0x7881, 0x78ef, 0x7941, 0x7947, 0x7948, 0x797a,
+ 0x7b95, 0x7d00, 0x7dba, 0x7f88, 0x8006, 0x802d, 0x808c, 0x8a18,
+ 0x8b4f, 0x8c48, 0x8d77, 0x9321, 0x9324, 0x98e2, 0x9951, 0x9a0e,
+ 0x9a0f, 0x9a65, 0x9e92, 0x7dca, 0x4f76, 0x5409, 0x62ee, 0x6854,
+ 0x91d1, 0x55ab, 0x513a, 0xf90b, 0xf90c, 0x5a1c, 0x61e6, 0xf90d,
+ 0x62cf, 0x62ff, 0xf90e, 0xf90f, 0xf910, 0xf911, 0xf912, 0xf913,
+ 0x90a3, 0xf914, 0xf915, 0xf916, 0xf917, 0xf918, 0x8afe, 0xf919,
+ 0xf91a, 0xf91b, 0xf91c, 0x6696, 0xf91d, 0x7156, 0xf91e, 0xf91f,
+ 0x96e3, 0xf920, 0x634f, 0x637a, 0x5357, 0xf921, 0x678f, 0x6960,
+ 0x6e73, 0xf922, 0x7537, 0xf923, 0xf924, 0xf925,
+ /* 0x52 */
+ 0x7d0d, 0xf926, 0xf927, 0x8872, 0x56ca, 0x5a18, 0xf928, 0xf929,
+ 0xf92a, 0xf92b, 0xf92c, 0x4e43, 0xf92d, 0x5167, 0x5948, 0x67f0,
+ 0x8010, 0xf92e, 0x5973, 0x5e74, 0x649a, 0x79ca, 0x5ff5, 0x606c,
+ 0x62c8, 0x637b, 0x5be7, 0x5bd7, 0x52aa, 0xf92f, 0x5974, 0x5f29,
+ 0x6012, 0xf930, 0xf931, 0xf932, 0x7459, 0xf933, 0xf934, 0xf935,
+ 0xf936, 0xf937, 0xf938, 0x99d1, 0xf939, 0xf93a, 0xf93b, 0xf93c,
+ 0xf93d, 0xf93e, 0xf93f, 0xf940, 0xf941, 0xf942, 0xf943, 0x6fc3,
+ 0xf944, 0xf945, 0x81bf, 0x8fb2, 0x60f1, 0xf946, 0xf947, 0x8166,
+ 0xf948, 0xf949, 0x5c3f, 0xf94a, 0xf94b, 0xf94c, 0xf94d, 0xf94e,
+ 0xf94f, 0xf950, 0xf951, 0x5ae9, 0x8a25, 0x677b, 0x7d10, 0xf952,
+ 0xf953, 0xf954, 0xf955, 0xf956, 0xf957, 0x80fd, 0xf958, 0xf959,
+ 0x5c3c, 0x6ce5, 0x533f, 0x6eba, 0x591a, 0x8336,
+ /* 0x53 */
+ 0x4e39, 0x4eb6, 0x4f46, 0x55ae, 0x5718, 0x58c7, 0x5f56, 0x65b7,
+ 0x65e6, 0x6a80, 0x6bb5, 0x6e4d, 0x77ed, 0x7aef, 0x7c1e, 0x7dde,
+ 0x86cb, 0x8892, 0x9132, 0x935b, 0x64bb, 0x6fbe, 0x737a, 0x75b8,
+ 0x9054, 0x5556, 0x574d, 0x61ba, 0x64d4, 0x66c7, 0x6de1, 0x6e5b,
+ 0x6f6d, 0x6fb9, 0x75f0, 0x8043, 0x81bd, 0x8541, 0x8983, 0x8ac7,
+ 0x8b5a, 0x931f, 0x6c93, 0x7553, 0x7b54, 0x8e0f, 0x905d, 0x5510,
+ 0x5802, 0x5858, 0x5e62, 0x6207, 0x649e, 0x68e0, 0x7576, 0x7cd6,
+ 0x87b3, 0x9ee8, 0x4ee3, 0x5788, 0x576e, 0x5927, 0x5c0d, 0x5cb1,
+ 0x5e36, 0x5f85, 0x6234, 0x64e1, 0x73b3, 0x81fa, 0x888b, 0x8cb8,
+ 0x968a, 0x9edb, 0x5b85, 0x5fb7, 0x60b3, 0x5012, 0x5200, 0x5230,
+ 0x5716, 0x5835, 0x5857, 0x5c0e, 0x5c60, 0x5cf6, 0x5d8b, 0x5ea6,
+ 0x5f92, 0x60bc, 0x6311, 0x6389, 0x6417, 0x6843,
+ /* 0x54 */
+ 0x68f9, 0x6ac2, 0x6dd8, 0x6e21, 0x6ed4, 0x6fe4, 0x71fe, 0x76dc,
+ 0x7779, 0x79b1, 0x7a3b, 0x8404, 0x89a9, 0x8ced, 0x8df3, 0x8e48,
+ 0x9003, 0x9014, 0x9053, 0x90fd, 0x934d, 0x9676, 0x97dc, 0x6bd2,
+ 0x7006, 0x7258, 0x72a2, 0x7368, 0x7763, 0x79bf, 0x7be4, 0x7e9b,
+ 0x8b80, 0x58a9, 0x60c7, 0x6566, 0x65fd, 0x66be, 0x6c8c, 0x711e,
+ 0x71c9, 0x8c5a, 0x9813, 0x4e6d, 0x7a81, 0x4edd, 0x51ac, 0x51cd,
+ 0x52d5, 0x540c, 0x61a7, 0x6771, 0x6850, 0x68df, 0x6d1e, 0x6f7c,
+ 0x75bc, 0x77b3, 0x7ae5, 0x80f4, 0x8463, 0x9285, 0x515c, 0x6597,
+ 0x675c, 0x6793, 0x75d8, 0x7ac7, 0x8373, 0xf95a, 0x8c46, 0x9017,
+ 0x982d, 0x5c6f, 0x81c0, 0x829a, 0x9041, 0x906f, 0x920d, 0x5f97,
+ 0x5d9d, 0x6a59, 0x71c8, 0x767b, 0x7b49, 0x85e4, 0x8b04, 0x9127,
+ 0x9a30, 0x5587, 0x61f6, 0xf95b, 0x7669, 0x7f85,
+ /* 0x55 */
+ 0x863f, 0x87ba, 0x88f8, 0x908f, 0xf95c, 0x6d1b, 0x70d9, 0x73de,
+ 0x7d61, 0x843d, 0xf95d, 0x916a, 0x99f1, 0xf95e, 0x4e82, 0x5375,
+ 0x6b04, 0x6b12, 0x703e, 0x721b, 0x862d, 0x9e1e, 0x524c, 0x8fa3,
+ 0x5d50, 0x64e5, 0x652c, 0x6b16, 0x6feb, 0x7c43, 0x7e9c, 0x85cd,
+ 0x8964, 0x89bd, 0x62c9, 0x81d8, 0x881f, 0x5eca, 0x6717, 0x6d6a,
+ 0x72fc, 0x7405, 0x746f, 0x8782, 0x90de, 0x4f86, 0x5d0d, 0x5fa0,
+ 0x840a, 0x51b7, 0x63a0, 0x7565, 0x4eae, 0x5006, 0x5169, 0x51c9,
+ 0x6881, 0x6a11, 0x7cae, 0x7cb1, 0x7ce7, 0x826f, 0x8ad2, 0x8f1b,
+ 0x91cf, 0x4fb6, 0x5137, 0x52f5, 0x5442, 0x5eec, 0x616e, 0x623e,
+ 0x65c5, 0x6ada, 0x6ffe, 0x792a, 0x85dc, 0x8823, 0x95ad, 0x9a62,
+ 0x9a6a, 0x9e97, 0x9ece, 0x529b, 0x66c6, 0x6b77, 0x701d, 0x792b,
+ 0x8f62, 0x9742, 0x6190, 0x6200, 0x6523, 0x6f23,
+ /* 0x56 */
+ 0x7149, 0x7489, 0x7df4, 0x806f, 0x84ee, 0x8f26, 0x9023, 0x934a,
+ 0x51bd, 0x5217, 0x52a3, 0x6d0c, 0x70c8, 0x88c2, 0x5ec9, 0x6582,
+ 0x6bae, 0x6fc2, 0x7c3e, 0x7375, 0x4ee4, 0x4f36, 0x56f9, 0xf95f,
+ 0x5cba, 0x5dba, 0x601c, 0x73b2, 0x7b2d, 0x7f9a, 0x7fce, 0x8046,
+ 0x901e, 0x9234, 0x96f6, 0x9748, 0x9818, 0x9f61, 0x4f8b, 0x6fa7,
+ 0x79ae, 0x91b4, 0x96b7, 0x52de, 0xf960, 0x6488, 0x64c4, 0x6ad3,
+ 0x6f5e, 0x7018, 0x7210, 0x76e7, 0x8001, 0x8606, 0x865c, 0x8def,
+ 0x8f05, 0x9732, 0x9b6f, 0x9dfa, 0x9e75, 0x788c, 0x797f, 0x7da0,
+ 0x83c9, 0x9304, 0x9e7f, 0x9e93, 0x8ad6, 0x58df, 0x5f04, 0x6727,
+ 0x7027, 0x74cf, 0x7c60, 0x807e, 0x5121, 0x7028, 0x7262, 0x78ca,
+ 0x8cc2, 0x8cda, 0x8cf4, 0x96f7, 0x4e86, 0x50da, 0x5bee, 0x5ed6,
+ 0x6599, 0x71ce, 0x7642, 0x77ad, 0x804a, 0x84fc,
+ /* 0x57 */
+ 0x907c, 0x9b27, 0x9f8d, 0x58d8, 0x5a41, 0x5c62, 0x6a13, 0x6dda,
+ 0x6f0f, 0x763b, 0x7d2f, 0x7e37, 0x851e, 0x8938, 0x93e4, 0x964b,
+ 0x5289, 0x65d2, 0x67f3, 0x69b4, 0x6d41, 0x6e9c, 0x700f, 0x7409,
+ 0x7460, 0x7559, 0x7624, 0x786b, 0x8b2c, 0x985e, 0x516d, 0x622e,
+ 0x9678, 0x4f96, 0x502b, 0x5d19, 0x6dea, 0x7db8, 0x8f2a, 0x5f8b,
+ 0x6144, 0x6817, 0xf961, 0x9686, 0x52d2, 0x808b, 0x51dc, 0x51cc,
+ 0x695e, 0x7a1c, 0x7dbe, 0x83f1, 0x9675, 0x4fda, 0x5229, 0x5398,
+ 0x540f, 0x550e, 0x5c65, 0x60a7, 0x674e, 0x68a8, 0x6d6c, 0x7281,
+ 0x72f8, 0x7406, 0x7483, 0xf962, 0x75e2, 0x7c6c, 0x7f79, 0x7fb8,
+ 0x8389, 0x88cf, 0x88e1, 0x91cc, 0x91d0, 0x96e2, 0x9bc9, 0x541d,
+ 0x6f7e, 0x71d0, 0x7498, 0x85fa, 0x8eaa, 0x96a3, 0x9c57, 0x9e9f,
+ 0x6797, 0x6dcb, 0x7433, 0x81e8, 0x9716, 0x782c,
+ /* 0x58 */
+ 0x7acb, 0x7b20, 0x7c92, 0x6469, 0x746a, 0x75f2, 0x78bc, 0x78e8,
+ 0x99ac, 0x9b54, 0x9ebb, 0x5bde, 0x5e55, 0x6f20, 0x819c, 0x83ab,
+ 0x9088, 0x4e07, 0x534d, 0x5a29, 0x5dd2, 0x5f4e, 0x6162, 0x633d,
+ 0x6669, 0x66fc, 0x6eff, 0x6f2b, 0x7063, 0x779e, 0x842c, 0x8513,
+ 0x883b, 0x8f13, 0x9945, 0x9c3b, 0x551c, 0x62b9, 0x672b, 0x6cab,
+ 0x8309, 0x896a, 0x977a, 0x4ea1, 0x5984, 0x5fd8, 0x5fd9, 0x671b,
+ 0x7db2, 0x7f54, 0x8292, 0x832b, 0x83bd, 0x8f1e, 0x9099, 0x57cb,
+ 0x59b9, 0x5a92, 0x5bd0, 0x6627, 0x679a, 0x6885, 0x6bcf, 0x7164,
+ 0x7f75, 0x8cb7, 0x8ce3, 0x9081, 0x9b45, 0x8108, 0x8c8a, 0x964c,
+ 0x9a40, 0x9ea5, 0x5b5f, 0x6c13, 0x731b, 0x76f2, 0x76df, 0x840c,
+ 0x51aa, 0x8993, 0x514d, 0x5195, 0x52c9, 0x68c9, 0x6c94, 0x7704,
+ 0x7720, 0x7dbf, 0x7dec, 0x9762, 0x9eb5, 0x6ec5,
+ /* 0x59 */
+ 0x8511, 0x51a5, 0x540d, 0x547d, 0x660e, 0x669d, 0x6927, 0x6e9f,
+ 0x76bf, 0x7791, 0x8317, 0x84c2, 0x879f, 0x9169, 0x9298, 0x9cf4,
+ 0x8882, 0x4fae, 0x5192, 0x52df, 0x59c6, 0x5e3d, 0x6155, 0x6478,
+ 0x6479, 0x66ae, 0x67d0, 0x6a21, 0x6bcd, 0x6bdb, 0x725f, 0x7261,
+ 0x7441, 0x7738, 0x77db, 0x8017, 0x82bc, 0x8305, 0x8b00, 0x8b28,
+ 0x8c8c, 0x6728, 0x6c90, 0x7267, 0x76ee, 0x7766, 0x7a46, 0x9da9,
+ 0x6b7f, 0x6c92, 0x5922, 0x6726, 0x8499, 0x536f, 0x5893, 0x5999,
+ 0x5edf, 0x63cf, 0x6634, 0x6773, 0x6e3a, 0x732b, 0x7ad7, 0x82d7,
+ 0x9328, 0x52d9, 0x5deb, 0x61ae, 0x61cb, 0x620a, 0x62c7, 0x64ab,
+ 0x65e0, 0x6959, 0x6b66, 0x6bcb, 0x7121, 0x73f7, 0x755d, 0x7e46,
+ 0x821e, 0x8302, 0x856a, 0x8aa3, 0x8cbf, 0x9727, 0x9d61, 0x58a8,
+ 0x9ed8, 0x5011, 0x520e, 0x543b, 0x554f, 0x6587,
+ /* 0x5a */
+ 0x6c76, 0x7d0a, 0x7d0b, 0x805e, 0x868a, 0x9580, 0x96ef, 0x52ff,
+ 0x6c95, 0x7269, 0x5473, 0x5a9a, 0x5c3e, 0x5d4b, 0x5f4c, 0x5fae,
+ 0x672a, 0x68b6, 0x6963, 0x6e3c, 0x6e44, 0x7709, 0x7c73, 0x7f8e,
+ 0x8587, 0x8b0e, 0x8ff7, 0x9761, 0x9ef4, 0x5cb7, 0x60b6, 0x610d,
+ 0x61ab, 0x654f, 0x65fb, 0x65fc, 0x6c11, 0x6cef, 0x739f, 0x73c9,
+ 0x7de1, 0x9594, 0x5bc6, 0x871c, 0x8b10, 0x525d, 0x535a, 0x62cd,
+ 0x640f, 0x64b2, 0x6734, 0x6a38, 0x6cca, 0x73c0, 0x749e, 0x7b94,
+ 0x7c95, 0x7e1b, 0x818a, 0x8236, 0x8584, 0x8feb, 0x96f9, 0x99c1,
+ 0x4f34, 0x534a, 0x53cd, 0x53db, 0x62cc, 0x642c, 0x6500, 0x6591,
+ 0x69c3, 0x6cee, 0x6f58, 0x73ed, 0x7554, 0x7622, 0x76e4, 0x76fc,
+ 0x78d0, 0x78fb, 0x792c, 0x7d46, 0x822c, 0x87e0, 0x8fd4, 0x9812,
+ 0x98ef, 0x52c3, 0x62d4, 0x64a5, 0x6e24, 0x6f51,
+ /* 0x5b */
+ 0x767c, 0x8dcb, 0x91b1, 0x9262, 0x9aee, 0x9b43, 0x5023, 0x508d,
+ 0x574a, 0x59a8, 0x5c28, 0x5e47, 0x5f77, 0x623f, 0x653e, 0x65b9,
+ 0x65c1, 0x6609, 0x678b, 0x699c, 0x6ec2, 0x78c5, 0x7d21, 0x80aa,
+ 0x8180, 0x822b, 0x82b3, 0x84a1, 0x868c, 0x8a2a, 0x8b17, 0x90a6,
+ 0x9632, 0x9f90, 0x500d, 0x4ff3, 0xf963, 0x57f9, 0x5f98, 0x62dc,
+ 0x6392, 0x676f, 0x6e43, 0x7119, 0x76c3, 0x80cc, 0x80da, 0x88f4,
+ 0x88f5, 0x8919, 0x8ce0, 0x8f29, 0x914d, 0x966a, 0x4f2f, 0x4f70,
+ 0x5e1b, 0x67cf, 0x6822, 0x767d, 0x767e, 0x9b44, 0x5e61, 0x6a0a,
+ 0x7169, 0x71d4, 0x756a, 0xf964, 0x7e41, 0x8543, 0x85e9, 0x98dc,
+ 0x4f10, 0x7b4f, 0x7f70, 0x95a5, 0x51e1, 0x5e06, 0x68b5, 0x6c3e,
+ 0x6c4e, 0x6cdb, 0x72af, 0x7bc4, 0x8303, 0x6cd5, 0x743a, 0x50fb,
+ 0x5288, 0x58c1, 0x64d8, 0x6a97, 0x74a7, 0x7656,
+ /* 0x5c */
+ 0x78a7, 0x8617, 0x95e2, 0x9739, 0xf965, 0x535e, 0x5f01, 0x8b8a,
+ 0x8fa8, 0x8faf, 0x908a, 0x5225, 0x77a5, 0x9c49, 0x9f08, 0x4e19,
+ 0x5002, 0x5175, 0x5c5b, 0x5e77, 0x661e, 0x663a, 0x67c4, 0x68c5,
+ 0x70b3, 0x7501, 0x75c5, 0x79c9, 0x7add, 0x8f27, 0x9920, 0x9a08,
+ 0x4fdd, 0x5821, 0x5831, 0x5bf6, 0x666e, 0x6b65, 0x6d11, 0x6e7a,
+ 0x6f7d, 0x73e4, 0x752b, 0x83e9, 0x88dc, 0x8913, 0x8b5c, 0x8f14,
+ 0x4f0f, 0x50d5, 0x5310, 0x535c, 0x5b93, 0x5fa9, 0x670d, 0x798f,
+ 0x8179, 0x832f, 0x8514, 0x8907, 0x8986, 0x8f39, 0x8f3b, 0x99a5,
+ 0x9c12, 0x672c, 0x4e76, 0x4ff8, 0x5949, 0x5c01, 0x5cef, 0x5cf0,
+ 0x6367, 0x68d2, 0x70fd, 0x71a2, 0x742b, 0x7e2b, 0x84ec, 0x8702,
+ 0x9022, 0x92d2, 0x9cf3, 0x4e0d, 0x4ed8, 0x4fef, 0x5085, 0x5256,
+ 0x526f, 0x5426, 0x5490, 0x57e0, 0x592b, 0x5a66,
+ /* 0x5d */
+ 0x5b5a, 0x5b75, 0x5bcc, 0x5e9c, 0xf966, 0x6276, 0x6577, 0x65a7,
+ 0x6d6e, 0x6ea5, 0x7236, 0x7b26, 0x7c3f, 0x7f36, 0x8150, 0x8151,
+ 0x819a, 0x8240, 0x8299, 0x83a9, 0x8a03, 0x8ca0, 0x8ce6, 0x8cfb,
+ 0x8d74, 0x8dba, 0x90e8, 0x91dc, 0x961c, 0x9644, 0x99d9, 0x9ce7,
+ 0x5317, 0x5206, 0x5429, 0x5674, 0x58b3, 0x5954, 0x596e, 0x5fff,
+ 0x61a4, 0x626e, 0x6610, 0x6c7e, 0x711a, 0x76c6, 0x7c89, 0x7cde,
+ 0x7d1b, 0x82ac, 0x8cc1, 0x96f0, 0xf967, 0x4f5b, 0x5f17, 0x5f7f,
+ 0x62c2, 0x5d29, 0x670b, 0x68da, 0x787c, 0x7e43, 0x9d6c, 0x4e15,
+ 0x5099, 0x5315, 0x532a, 0x5351, 0x5983, 0x5a62, 0x5e87, 0x60b2,
+ 0x618a, 0x6249, 0x6279, 0x6590, 0x6787, 0x69a7, 0x6bd4, 0x6bd6,
+ 0x6bd7, 0x6bd8, 0x6cb8, 0xf968, 0x7435, 0x75fa, 0x7812, 0x7891,
+ 0x79d5, 0x79d8, 0x7c83, 0x7dcb, 0x7fe1, 0x80a5,
+ /* 0x5e */
+ 0x813e, 0x81c2, 0x83f2, 0x871a, 0x88e8, 0x8ab9, 0x8b6c, 0x8cbb,
+ 0x9119, 0x975e, 0x98db, 0x9f3b, 0x56ac, 0x5b2a, 0x5f6c, 0x658c,
+ 0x6ab3, 0x6baf, 0x6d5c, 0x6ff1, 0x7015, 0x725d, 0x73ad, 0x8ca7,
+ 0x8cd3, 0x983b, 0x6191, 0x6c37, 0x8058, 0x9a01, 0x4e4d, 0x4e8b,
+ 0x4e9b, 0x4ed5, 0x4f3a, 0x4f3c, 0x4f7f, 0x4fdf, 0x50ff, 0x53f2,
+ 0x53f8, 0x5506, 0x55e3, 0x56db, 0x58eb, 0x5962, 0x5a11, 0x5beb,
+ 0x5bfa, 0x5c04, 0x5df3, 0x5e2b, 0x5f99, 0x601d, 0x6368, 0x659c,
+ 0x65af, 0x67f6, 0x67fb, 0x68ad, 0x6b7b, 0x6c99, 0x6cd7, 0x6e23,
+ 0x7009, 0x7345, 0x7802, 0x793e, 0x7940, 0x7960, 0x79c1, 0x7be9,
+ 0x7d17, 0x7d72, 0x8086, 0x820d, 0x838e, 0x84d1, 0x86c7, 0x88df,
+ 0x8a50, 0x8a5e, 0x8b1d, 0x8cdc, 0x8d66, 0x8fad, 0x90aa, 0x98fc,
+ 0x99df, 0x9e9d, 0x524a, 0xf969, 0x6714, 0xf96a,
+ /* 0x5f */
+ 0x5098, 0x522a, 0x5c71, 0x6563, 0x6c55, 0x73ca, 0x7523, 0x759d,
+ 0x7b97, 0x849c, 0x9178, 0x9730, 0x4e77, 0x6492, 0x6bba, 0x715e,
+ 0x85a9, 0x4e09, 0xf96b, 0x6749, 0x68ee, 0x6e17, 0x829f, 0x8518,
+ 0x886b, 0x63f7, 0x6f81, 0x9212, 0x98af, 0x4e0a, 0x50b7, 0x50cf,
+ 0x511f, 0x5546, 0x55aa, 0x5617, 0x5b40, 0x5c19, 0x5ce0, 0x5e38,
+ 0x5e8a, 0x5ea0, 0x5ec2, 0x60f3, 0x6851, 0x6a61, 0x6e58, 0x723d,
+ 0x7240, 0x72c0, 0x76f8, 0x7965, 0x7bb1, 0x7fd4, 0x88f3, 0x89f4,
+ 0x8a73, 0x8c61, 0x8cde, 0x971c, 0x585e, 0x74bd, 0x8cfd, 0x55c7,
+ 0xf96c, 0x7a61, 0x7d22, 0x8272, 0x7272, 0x751f, 0x7525, 0xf96d,
+ 0x7b19, 0x5885, 0x58fb, 0x5dbc, 0x5e8f, 0x5eb6, 0x5f90, 0x6055,
+ 0x6292, 0x637f, 0x654d, 0x6691, 0x66d9, 0x66f8, 0x6816, 0x68f2,
+ 0x7280, 0x745e, 0x7b6e, 0x7d6e, 0x7dd6, 0x7f72,
+ /* 0x60 */
+ 0x80e5, 0x8212, 0x85af, 0x897f, 0x8a93, 0x901d, 0x92e4, 0x9ecd,
+ 0x9f20, 0x5915, 0x596d, 0x5e2d, 0x60dc, 0x6614, 0x6673, 0x6790,
+ 0x6c50, 0x6dc5, 0x6f5f, 0x77f3, 0x78a9, 0x84c6, 0x91cb, 0x932b,
+ 0x4ed9, 0x50ca, 0x5148, 0x5584, 0x5b0b, 0x5ba3, 0x6247, 0x657e,
+ 0x65cb, 0x6e32, 0x717d, 0x7401, 0x7444, 0x7487, 0x74bf, 0x766c,
+ 0x79aa, 0x7dda, 0x7e55, 0x7fa8, 0x817a, 0x81b3, 0x8239, 0x861a,
+ 0x87ec, 0x8a75, 0x8de3, 0x9078, 0x9291, 0x9425, 0x994d, 0x9bae,
+ 0x5368, 0x5c51, 0x6954, 0x6cc4, 0x6d29, 0x6e2b, 0x820c, 0x859b,
+ 0x893b, 0x8a2d, 0x8aaa, 0x96ea, 0x9f67, 0x5261, 0x66b9, 0x6bb2,
+ 0x7e96, 0x87fe, 0x8d0d, 0x9583, 0x965d, 0x651d, 0x6d89, 0x71ee,
+ 0xf96e, 0x57ce, 0x59d3, 0x5bac, 0x6027, 0x60fa, 0x6210, 0x661f,
+ 0x665f, 0x7329, 0x73f9, 0x76db, 0x7701, 0x7b6c,
+ /* 0x61 */
+ 0x8056, 0x8072, 0x8165, 0x8aa0, 0x9192, 0x4e16, 0x52e2, 0x6b72,
+ 0x6d17, 0x7a05, 0x7b39, 0x7d30, 0xf96f, 0x8cb0, 0x53ec, 0x562f,
+ 0x5851, 0x5bb5, 0x5c0f, 0x5c11, 0x5de2, 0x6240, 0x6383, 0x6414,
+ 0x662d, 0x68b3, 0x6cbc, 0x6d88, 0x6eaf, 0x701f, 0x70a4, 0x71d2,
+ 0x7526, 0x758f, 0x758e, 0x7619, 0x7b11, 0x7be0, 0x7c2b, 0x7d20,
+ 0x7d39, 0x852c, 0x856d, 0x8607, 0x8a34, 0x900d, 0x9061, 0x90b5,
+ 0x92b7, 0x97f6, 0x9a37, 0x4fd7, 0x5c6c, 0x675f, 0x6d91, 0x7c9f,
+ 0x7e8c, 0x8b16, 0x8d16, 0x901f, 0x5b6b, 0x5dfd, 0x640d, 0x84c0,
+ 0x905c, 0x98e1, 0x7387, 0x5b8b, 0x609a, 0x677e, 0x6dde, 0x8a1f,
+ 0x8aa6, 0x9001, 0x980c, 0x5237, 0xf970, 0x7051, 0x788e, 0x9396,
+ 0x8870, 0x91d7, 0x4fee, 0x53d7, 0x55fd, 0x56da, 0x5782, 0x58fd,
+ 0x5ac2, 0x5b88, 0x5cab, 0x5cc0, 0x5e25, 0x6101,
+ /* 0x62 */
+ 0x620d, 0x624b, 0x6388, 0x641c, 0x6536, 0x6578, 0x6a39, 0x6b8a,
+ 0x6c34, 0x6d19, 0x6f31, 0x71e7, 0x72e9, 0x7378, 0x7407, 0x74b2,
+ 0x7626, 0x7761, 0x79c0, 0x7a57, 0x7aea, 0x7cb9, 0x7d8f, 0x7dac,
+ 0x7e61, 0x7f9e, 0x8129, 0x8331, 0x8490, 0x84da, 0x85ea, 0x8896,
+ 0x8ab0, 0x8b90, 0x8f38, 0x9042, 0x9083, 0x916c, 0x9296, 0x92b9,
+ 0x968b, 0x96a7, 0x96a8, 0x96d6, 0x9700, 0x9808, 0x9996, 0x9ad3,
+ 0x9b1a, 0x53d4, 0x587e, 0x5919, 0x5b70, 0x5bbf, 0x6dd1, 0x6f5a,
+ 0x719f, 0x7421, 0x74b9, 0x8085, 0x83fd, 0x5de1, 0x5f87, 0x5faa,
+ 0x6042, 0x65ec, 0x6812, 0x696f, 0x6a53, 0x6b89, 0x6d35, 0x6df3,
+ 0x73e3, 0x76fe, 0x77ac, 0x7b4d, 0x7d14, 0x8123, 0x821c, 0x8340,
+ 0x84f4, 0x8563, 0x8a62, 0x8ac4, 0x9187, 0x931e, 0x9806, 0x99b4,
+ 0x620c, 0x8853, 0x8ff0, 0x9265, 0x5d07, 0x5d27,
+ /* 0x63 */
+ 0x5d69, 0x745f, 0x819d, 0x8768, 0x6fd5, 0x62fe, 0x7fd2, 0x8936,
+ 0x8972, 0x4e1e, 0x4e58, 0x50e7, 0x52dd, 0x5347, 0x627f, 0x6607,
+ 0x7e69, 0x8805, 0x965e, 0x4f8d, 0x5319, 0x5636, 0x59cb, 0x5aa4,
+ 0x5c38, 0x5c4e, 0x5c4d, 0x5e02, 0x5f11, 0x6043, 0x65bd, 0x662f,
+ 0x6642, 0x67be, 0x67f4, 0x731c, 0x77e2, 0x793a, 0x7fc5, 0x8494,
+ 0x84cd, 0x8996, 0x8a66, 0x8a69, 0x8ae1, 0x8c55, 0x8c7a, 0x57f4,
+ 0x5bd4, 0x5f0f, 0x606f, 0x62ed, 0x690d, 0x6b96, 0x6e5c, 0x7184,
+ 0x7bd2, 0x8755, 0x8b58, 0x8efe, 0x98df, 0x98fe, 0x4f38, 0x4f81,
+ 0x4fe1, 0x547b, 0x5a20, 0x5bb8, 0x613c, 0x65b0, 0x6668, 0x71fc,
+ 0x7533, 0x795e, 0x7d33, 0x814e, 0x81e3, 0x8398, 0x85aa, 0x85ce,
+ 0x8703, 0x8a0a, 0x8eab, 0x8f9b, 0xf971, 0x8fc5, 0x5931, 0x5ba4,
+ 0x5be6, 0x6089, 0x5be9, 0x5c0b, 0x5fc3, 0x6c81,
+ /* 0x64 */
+ 0xf972, 0x6df1, 0x700b, 0x751a, 0x82af, 0x8af6, 0x4ec0, 0x5341,
+ 0xf973, 0x96d9, 0x6c0f, 0x4e9e, 0x4fc4, 0x5152, 0x555e, 0x5a25,
+ 0x5ce8, 0x6211, 0x7259, 0x82bd, 0x83aa, 0x86fe, 0x8859, 0x8a1d,
+ 0x963f, 0x96c5, 0x9913, 0x9d09, 0x9d5d, 0x580a, 0x5cb3, 0x5dbd,
+ 0x5e44, 0x60e1, 0x6115, 0x63e1, 0x6a02, 0x6e25, 0x9102, 0x9354,
+ 0x984e, 0x9c10, 0x9f77, 0x5b89, 0x5cb8, 0x6309, 0x664f, 0x6848,
+ 0x773c, 0x96c1, 0x978d, 0x9854, 0x9b9f, 0x65a1, 0x8b01, 0x8ecb,
+ 0x95bc, 0x5535, 0x5ca9, 0x5dd6, 0x5eb5, 0x6697, 0x764c, 0x83f4,
+ 0x95c7, 0x58d3, 0x62bc, 0x72ce, 0x9d28, 0x4ef0, 0x592e, 0x600f,
+ 0x663b, 0x6b83, 0x79e7, 0x9d26, 0x5393, 0x54c0, 0x57c3, 0x5d16,
+ 0x611b, 0x66d6, 0x6daf, 0x788d, 0x827e, 0x9698, 0x9744, 0x5384,
+ 0x627c, 0x6396, 0x6db2, 0x7e0a, 0x814b, 0x984d,
+ /* 0x65 */
+ 0x6afb, 0x7f4c, 0x9daf, 0x9e1a, 0x4e5f, 0x503b, 0x51b6, 0x591c,
+ 0x60f9, 0x63f6, 0x6930, 0x723a, 0x8036, 0xf974, 0x91ce, 0x5f31,
+ 0xf975, 0xf976, 0x7d04, 0x82e5, 0x846f, 0x84bb, 0x85e5, 0x8e8d,
+ 0xf977, 0x4f6f, 0xf978, 0xf979, 0x58e4, 0x5b43, 0x6059, 0x63da,
+ 0x6518, 0x656d, 0x6698, 0xf97a, 0x694a, 0x6a23, 0x6d0b, 0x7001,
+ 0x716c, 0x75d2, 0x760d, 0x79b3, 0x7a70, 0xf97b, 0x7f8a, 0xf97c,
+ 0x8944, 0xf97d, 0x8b93, 0x91c0, 0x967d, 0xf97e, 0x990a, 0x5704,
+ 0x5fa1, 0x65bc, 0x6f01, 0x7600, 0x79a6, 0x8a9e, 0x99ad, 0x9b5a,
+ 0x9f6c, 0x5104, 0x61b6, 0x6291, 0x6a8d, 0x81c6, 0x5043, 0x5830,
+ 0x5f66, 0x7109, 0x8a00, 0x8afa, 0x5b7c, 0x8616, 0x4ffa, 0x513c,
+ 0x56b4, 0x5944, 0x63a9, 0x6df9, 0x5daa, 0x696d, 0x5186, 0x4e88,
+ 0x4f59, 0xf97f, 0xf980, 0xf981, 0x5982, 0xf982,
+ /* 0x66 */
+ 0xf983, 0x6b5f, 0x6c5d, 0xf984, 0x74b5, 0x7916, 0xf985, 0x8207,
+ 0x8245, 0x8339, 0x8f3f, 0x8f5d, 0xf986, 0x9918, 0xf987, 0xf988,
+ 0xf989, 0x4ea6, 0xf98a, 0x57df, 0x5f79, 0x6613, 0xf98b, 0xf98c,
+ 0x75ab, 0x7e79, 0x8b6f, 0xf98d, 0x9006, 0x9a5b, 0x56a5, 0x5827,
+ 0x59f8, 0x5a1f, 0x5bb4, 0xf98e, 0x5ef6, 0xf98f, 0xf990, 0x6350,
+ 0x633b, 0xf991, 0x693d, 0x6c87, 0x6cbf, 0x6d8e, 0x6d93, 0x6df5,
+ 0x6f14, 0xf992, 0x70df, 0x7136, 0x7159, 0xf993, 0x71c3, 0x71d5,
+ 0xf994, 0x784f, 0x786f, 0xf995, 0x7b75, 0x7de3, 0xf996, 0x7e2f,
+ 0xf997, 0x884d, 0x8edf, 0xf998, 0xf999, 0xf99a, 0x925b, 0xf99b,
+ 0x9cf6, 0xf99c, 0xf99d, 0xf99e, 0x6085, 0x6d85, 0xf99f, 0x71b1,
+ 0xf9a0, 0xf9a1, 0x95b1, 0x53ad, 0xf9a2, 0xf9a3, 0xf9a4, 0x67d3,
+ 0xf9a5, 0x708e, 0x7130, 0x7430, 0x8276, 0x82d2,
+ /* 0x67 */
+ 0xf9a6, 0x95bb, 0x9ae5, 0x9e7d, 0x66c4, 0xf9a7, 0x71c1, 0x8449,
+ 0xf9a8, 0xf9a9, 0x584b, 0xf9aa, 0xf9ab, 0x5db8, 0x5f71, 0xf9ac,
+ 0x6620, 0x668e, 0x6979, 0x69ae, 0x6c38, 0x6cf3, 0x6e36, 0x6f41,
+ 0x6fda, 0x701b, 0x702f, 0x7150, 0x71df, 0x7370, 0xf9ad, 0x745b,
+ 0xf9ae, 0x74d4, 0x76c8, 0x7a4e, 0x7e93, 0xf9af, 0xf9b0, 0x82f1,
+ 0x8a60, 0x8fce, 0xf9b1, 0x9348, 0xf9b2, 0x9719, 0xf9b3, 0xf9b4,
+ 0x4e42, 0x502a, 0xf9b5, 0x5208, 0x53e1, 0x66f3, 0x6c6d, 0x6fca,
+ 0x730a, 0x777f, 0x7a62, 0x82ae, 0x85dd, 0x8602, 0xf9b6, 0x88d4,
+ 0x8a63, 0x8b7d, 0x8c6b, 0xf9b7, 0x92b3, 0xf9b8, 0x9713, 0x9810,
+ 0x4e94, 0x4f0d, 0x4fc9, 0x50b2, 0x5348, 0x543e, 0x5433, 0x55da,
+ 0x5862, 0x58ba, 0x5967, 0x5a1b, 0x5be4, 0x609f, 0xf9b9, 0x61ca,
+ 0x6556, 0x65ff, 0x6664, 0x68a7, 0x6c5a, 0x6fb3,
+ /* 0x68 */
+ 0x70cf, 0x71ac, 0x7352, 0x7b7d, 0x8708, 0x8aa4, 0x9c32, 0x9f07,
+ 0x5c4b, 0x6c83, 0x7344, 0x7389, 0x923a, 0x6eab, 0x7465, 0x761f,
+ 0x7a69, 0x7e15, 0x860a, 0x5140, 0x58c5, 0x64c1, 0x74ee, 0x7515,
+ 0x7670, 0x7fc1, 0x9095, 0x96cd, 0x9954, 0x6e26, 0x74e6, 0x7aa9,
+ 0x7aaa, 0x81e5, 0x86d9, 0x8778, 0x8a1b, 0x5a49, 0x5b8c, 0x5b9b,
+ 0x68a1, 0x6900, 0x6d63, 0x73a9, 0x7413, 0x742c, 0x7897, 0x7de9,
+ 0x7feb, 0x8118, 0x8155, 0x839e, 0x8c4c, 0x962e, 0x9811, 0x66f0,
+ 0x5f80, 0x65fa, 0x6789, 0x6c6a, 0x738b, 0x502d, 0x5a03, 0x6b6a,
+ 0x77ee, 0x5916, 0x5d6c, 0x5dcd, 0x7325, 0x754f, 0xf9ba, 0xf9bb,
+ 0x50e5, 0x51f9, 0x582f, 0x592d, 0x5996, 0x59da, 0x5be5, 0xf9bc,
+ 0xf9bd, 0x5da2, 0x62d7, 0x6416, 0x6493, 0x64fe, 0xf9be, 0x66dc,
+ 0xf9bf, 0x6a48, 0xf9c0, 0x71ff, 0x7464, 0xf9c1,
+ /* 0x69 */
+ 0x7a88, 0x7aaf, 0x7e47, 0x7e5e, 0x8000, 0x8170, 0xf9c2, 0x87ef,
+ 0x8981, 0x8b20, 0x9059, 0xf9c3, 0x9080, 0x9952, 0x617e, 0x6b32,
+ 0x6d74, 0x7e1f, 0x8925, 0x8fb1, 0x4fd1, 0x50ad, 0x5197, 0x52c7,
+ 0x57c7, 0x5889, 0x5bb9, 0x5eb8, 0x6142, 0x6995, 0x6d8c, 0x6e67,
+ 0x6eb6, 0x7194, 0x7462, 0x7528, 0x752c, 0x8073, 0x8338, 0x84c9,
+ 0x8e0a, 0x9394, 0x93de, 0xf9c4, 0x4e8e, 0x4f51, 0x5076, 0x512a,
+ 0x53c8, 0x53cb, 0x53f3, 0x5b87, 0x5bd3, 0x5c24, 0x611a, 0x6182,
+ 0x65f4, 0x725b, 0x7397, 0x7440, 0x76c2, 0x7950, 0x7991, 0x79b9,
+ 0x7d06, 0x7fbd, 0x828b, 0x85d5, 0x865e, 0x8fc2, 0x9047, 0x90f5,
+ 0x91ea, 0x9685, 0x96e8, 0x96e9, 0x52d6, 0x5f67, 0x65ed, 0x6631,
+ 0x682f, 0x715c, 0x7a36, 0x90c1, 0x980a, 0x4e91, 0xf9c5, 0x6a52,
+ 0x6b9e, 0x6f90, 0x7189, 0x8018, 0x82b8, 0x8553,
+ /* 0x6a */
+ 0x904b, 0x9695, 0x96f2, 0x97fb, 0x851a, 0x9b31, 0x4e90, 0x718a,
+ 0x96c4, 0x5143, 0x539f, 0x54e1, 0x5713, 0x5712, 0x57a3, 0x5a9b,
+ 0x5ac4, 0x5bc3, 0x6028, 0x613f, 0x63f4, 0x6c85, 0x6d39, 0x6e72,
+ 0x6e90, 0x7230, 0x733f, 0x7457, 0x82d1, 0x8881, 0x8f45, 0x9060,
+ 0xf9c6, 0x9662, 0x9858, 0x9d1b, 0x6708, 0x8d8a, 0x925e, 0x4f4d,
+ 0x5049, 0x50de, 0x5371, 0x570d, 0x59d4, 0x5a01, 0x5c09, 0x6170,
+ 0x6690, 0x6e2d, 0x7232, 0x744b, 0x7def, 0x80c3, 0x840e, 0x8466,
+ 0x853f, 0x875f, 0x885b, 0x8918, 0x8b02, 0x9055, 0x97cb, 0x9b4f,
+ 0x4e73, 0x4f91, 0x5112, 0x516a, 0xf9c7, 0x552f, 0x55a9, 0x5b7a,
+ 0x5ba5, 0x5e7c, 0x5e7d, 0x5ebe, 0x60a0, 0x60df, 0x6108, 0x6109,
+ 0x63c4, 0x6538, 0x6709, 0xf9c8, 0x67d4, 0x67da, 0xf9c9, 0x6961,
+ 0x6962, 0x6cb9, 0x6d27, 0xf9ca, 0x6e38, 0xf9cb,
+ /* 0x6b */
+ 0x6fe1, 0x7336, 0x7337, 0xf9cc, 0x745c, 0x7531, 0xf9cd, 0x7652,
+ 0xf9ce, 0xf9cf, 0x7dad, 0x81fe, 0x8438, 0x88d5, 0x8a98, 0x8adb,
+ 0x8aed, 0x8e30, 0x8e42, 0x904a, 0x903e, 0x907a, 0x9149, 0x91c9,
+ 0x936e, 0xf9d0, 0xf9d1, 0x5809, 0xf9d2, 0x6bd3, 0x8089, 0x80b2,
+ 0xf9d3, 0xf9d4, 0x5141, 0x596b, 0x5c39, 0xf9d5, 0xf9d6, 0x6f64,
+ 0x73a7, 0x80e4, 0x8d07, 0xf9d7, 0x9217, 0x958f, 0xf9d8, 0xf9d9,
+ 0xf9da, 0xf9db, 0x807f, 0x620e, 0x701c, 0x7d68, 0x878d, 0xf9dc,
+ 0x57a0, 0x6069, 0x6147, 0x6bb7, 0x8abe, 0x9280, 0x96b1, 0x4e59,
+ 0x541f, 0x6deb, 0x852d, 0x9670, 0x97f3, 0x98ee, 0x63d6, 0x6ce3,
+ 0x9091, 0x51dd, 0x61c9, 0x81ba, 0x9df9, 0x4f9d, 0x501a, 0x5100,
+ 0x5b9c, 0x610f, 0x61ff, 0x64ec, 0x6905, 0x6bc5, 0x7591, 0x77e3,
+ 0x7fa9, 0x8264, 0x858f, 0x87fb, 0x8863, 0x8abc,
+ /* 0x6c */
+ 0x8b70, 0x91ab, 0x4e8c, 0x4ee5, 0x4f0a, 0xf9dd, 0xf9de, 0x5937,
+ 0x59e8, 0xf9df, 0x5df2, 0x5f1b, 0x5f5b, 0x6021, 0xf9e0, 0xf9e1,
+ 0xf9e2, 0xf9e3, 0x723e, 0x73e5, 0xf9e4, 0x7570, 0x75cd, 0xf9e5,
+ 0x79fb, 0xf9e6, 0x800c, 0x8033, 0x8084, 0x82e1, 0x8351, 0xf9e7,
+ 0xf9e8, 0x8cbd, 0x8cb3, 0x9087, 0xf9e9, 0xf9ea, 0x98f4, 0x990c,
+ 0xf9eb, 0xf9ec, 0x7037, 0x76ca, 0x7fca, 0x7fcc, 0x7ffc, 0x8b1a,
+ 0x4eba, 0x4ec1, 0x5203, 0x5370, 0xf9ed, 0x54bd, 0x56e0, 0x59fb,
+ 0x5bc5, 0x5f15, 0x5fcd, 0x6e6e, 0xf9ee, 0xf9ef, 0x7d6a, 0x8335,
+ 0xf9f0, 0x8693, 0x8a8d, 0xf9f1, 0x976d, 0x9777, 0xf9f2, 0xf9f3,
+ 0x4e00, 0x4f5a, 0x4f7e, 0x58f9, 0x65e5, 0x6ea2, 0x9038, 0x93b0,
+ 0x99b9, 0x4efb, 0x58ec, 0x598a, 0x59d9, 0x6041, 0xf9f4, 0xf9f5,
+ 0x7a14, 0xf9f6, 0x834f, 0x8cc3, 0x5165, 0x5344,
+ /* 0x6d */
+ 0xf9f7, 0xf9f8, 0xf9f9, 0x4ecd, 0x5269, 0x5b55, 0x82bf, 0x4ed4,
+ 0x523a, 0x54a8, 0x59c9, 0x59ff, 0x5b50, 0x5b57, 0x5b5c, 0x6063,
+ 0x6148, 0x6ecb, 0x7099, 0x716e, 0x7386, 0x74f7, 0x75b5, 0x78c1,
+ 0x7d2b, 0x8005, 0x81ea, 0x8328, 0x8517, 0x85c9, 0x8aee, 0x8cc7,
+ 0x96cc, 0x4f5c, 0x52fa, 0x56bc, 0x65ab, 0x6628, 0x707c, 0x70b8,
+ 0x7235, 0x7dbd, 0x828d, 0x914c, 0x96c0, 0x9d72, 0x5b71, 0x68e7,
+ 0x6b98, 0x6f7a, 0x76de, 0x5c91, 0x66ab, 0x6f5b, 0x7bb4, 0x7c2a,
+ 0x8836, 0x96dc, 0x4e08, 0x4ed7, 0x5320, 0x5834, 0x58bb, 0x58ef,
+ 0x596c, 0x5c07, 0x5e33, 0x5e84, 0x5f35, 0x638c, 0x66b2, 0x6756,
+ 0x6a1f, 0x6aa3, 0x6b0c, 0x6f3f, 0x7246, 0xf9fa, 0x7350, 0x748b,
+ 0x7ae0, 0x7ca7, 0x8178, 0x81df, 0x81e7, 0x838a, 0x846c, 0x8523,
+ 0x8594, 0x85cf, 0x88dd, 0x8d13, 0x91ac, 0x9577,
+ /* 0x6e */
+ 0x969c, 0x518d, 0x54c9, 0x5728, 0x5bb0, 0x624d, 0x6750, 0x683d,
+ 0x6893, 0x6e3d, 0x6ed3, 0x707d, 0x7e21, 0x88c1, 0x8ca1, 0x8f09,
+ 0x9f4b, 0x9f4e, 0x722d, 0x7b8f, 0x8acd, 0x931a, 0x4f47, 0x4f4e,
+ 0x5132, 0x5480, 0x59d0, 0x5e95, 0x62b5, 0x6775, 0x696e, 0x6a17,
+ 0x6cae, 0x6e1a, 0x72d9, 0x732a, 0x75bd, 0x7bb8, 0x7d35, 0x82e7,
+ 0x83f9, 0x8457, 0x85f7, 0x8a5b, 0x8caf, 0x8e87, 0x9019, 0x90b8,
+ 0x96ce, 0x9f5f, 0x52e3, 0x540a, 0x5ae1, 0x5bc2, 0x6458, 0x6575,
+ 0x6ef4, 0x72c4, 0xf9fb, 0x7684, 0x7a4d, 0x7b1b, 0x7c4d, 0x7e3e,
+ 0x7fdf, 0x837b, 0x8b2b, 0x8cca, 0x8d64, 0x8de1, 0x8e5f, 0x8fea,
+ 0x8ff9, 0x9069, 0x93d1, 0x4f43, 0x4f7a, 0x50b3, 0x5168, 0x5178,
+ 0x524d, 0x526a, 0x5861, 0x587c, 0x5960, 0x5c08, 0x5c55, 0x5edb,
+ 0x609b, 0x6230, 0x6813, 0x6bbf, 0x6c08, 0x6fb1,
+ /* 0x6f */
+ 0x714e, 0x7420, 0x7530, 0x7538, 0x7551, 0x7672, 0x7b4c, 0x7b8b,
+ 0x7bad, 0x7bc6, 0x7e8f, 0x8a6e, 0x8f3e, 0x8f49, 0x923f, 0x9293,
+ 0x9322, 0x942b, 0x96fb, 0x985a, 0x986b, 0x991e, 0x5207, 0x622a,
+ 0x6298, 0x6d59, 0x7664, 0x7aca, 0x7bc0, 0x7d76, 0x5360, 0x5cbe,
+ 0x5e97, 0x6f38, 0x70b9, 0x7c98, 0x9711, 0x9b8e, 0x9ede, 0x63a5,
+ 0x647a, 0x8776, 0x4e01, 0x4e95, 0x4ead, 0x505c, 0x5075, 0x5448,
+ 0x59c3, 0x5b9a, 0x5e40, 0x5ead, 0x5ef7, 0x5f81, 0x60c5, 0x633a,
+ 0x653f, 0x6574, 0x65cc, 0x6676, 0x6678, 0x67fe, 0x6968, 0x6a89,
+ 0x6b63, 0x6c40, 0x6dc0, 0x6de8, 0x6e1f, 0x6e5e, 0x701e, 0x70a1,
+ 0x738e, 0x73fd, 0x753a, 0x775b, 0x7887, 0x798e, 0x7a0b, 0x7a7d,
+ 0x7cbe, 0x7d8e, 0x8247, 0x8a02, 0x8aea, 0x8c9e, 0x912d, 0x914a,
+ 0x91d8, 0x9266, 0x92cc, 0x9320, 0x9706, 0x9756,
+ /* 0x70 */
+ 0x975c, 0x9802, 0x9f0e, 0x5236, 0x5291, 0x557c, 0x5824, 0x5e1d,
+ 0x5f1f, 0x608c, 0x63d0, 0x68af, 0x6fdf, 0x796d, 0x7b2c, 0x81cd,
+ 0x85ba, 0x88fd, 0x8af8, 0x8e44, 0x918d, 0x9664, 0x969b, 0x973d,
+ 0x984c, 0x9f4a, 0x4fce, 0x5146, 0x51cb, 0x52a9, 0x5632, 0x5f14,
+ 0x5f6b, 0x63aa, 0x64cd, 0x65e9, 0x6641, 0x66fa, 0x66f9, 0x671d,
+ 0x689d, 0x68d7, 0x69fd, 0x6f15, 0x6f6e, 0x7167, 0x71e5, 0x722a,
+ 0x74aa, 0x773a, 0x7956, 0x795a, 0x79df, 0x7a20, 0x7a95, 0x7c97,
+ 0x7cdf, 0x7d44, 0x7e70, 0x8087, 0x85fb, 0x86a4, 0x8a54, 0x8abf,
+ 0x8d99, 0x8e81, 0x9020, 0x906d, 0x91e3, 0x963b, 0x96d5, 0x9ce5,
+ 0x65cf, 0x7c07, 0x8db3, 0x93c3, 0x5b58, 0x5c0a, 0x5352, 0x62d9,
+ 0x731d, 0x5027, 0x5b97, 0x5f9e, 0x60b0, 0x616b, 0x68d5, 0x6dd9,
+ 0x742e, 0x7a2e, 0x7d42, 0x7d9c, 0x7e31, 0x816b,
+ /* 0x71 */
+ 0x8e2a, 0x8e35, 0x937e, 0x9418, 0x4f50, 0x5750, 0x5de6, 0x5ea7,
+ 0x632b, 0x7f6a, 0x4e3b, 0x4f4f, 0x4f8f, 0x505a, 0x59dd, 0x80c4,
+ 0x546a, 0x5468, 0x55fe, 0x594f, 0x5b99, 0x5dde, 0x5eda, 0x665d,
+ 0x6731, 0x67f1, 0x682a, 0x6ce8, 0x6d32, 0x6e4a, 0x6f8d, 0x70b7,
+ 0x73e0, 0x7587, 0x7c4c, 0x7d02, 0x7d2c, 0x7da2, 0x821f, 0x86db,
+ 0x8a3b, 0x8a85, 0x8d70, 0x8e8a, 0x8f33, 0x9031, 0x914e, 0x9152,
+ 0x9444, 0x99d0, 0x7af9, 0x7ca5, 0x4fca, 0x5101, 0x51c6, 0x57c8,
+ 0x5bef, 0x5cfb, 0x6659, 0x6a3d, 0x6d5a, 0x6e96, 0x6fec, 0x710c,
+ 0x756f, 0x7ae3, 0x8822, 0x9021, 0x9075, 0x96cb, 0x99ff, 0x8301,
+ 0x4e2d, 0x4ef2, 0x8846, 0x91cd, 0x537d, 0x6adb, 0x696b, 0x6c41,
+ 0x847a, 0x589e, 0x618e, 0x66fe, 0x62ef, 0x70dd, 0x7511, 0x75c7,
+ 0x7e52, 0x84b8, 0x8b49, 0x8d08, 0x4e4b, 0x53ea,
+ /* 0x72 */
+ 0x54ab, 0x5730, 0x5740, 0x5fd7, 0x6301, 0x6307, 0x646f, 0x652f,
+ 0x65e8, 0x667a, 0x679d, 0x67b3, 0x6b62, 0x6c60, 0x6c9a, 0x6f2c,
+ 0x77e5, 0x7825, 0x7949, 0x7957, 0x7d19, 0x80a2, 0x8102, 0x81f3,
+ 0x829d, 0x82b7, 0x8718, 0x8a8c, 0xf9fc, 0x8d04, 0x8dbe, 0x9072,
+ 0x76f4, 0x7a19, 0x7a37, 0x7e54, 0x8077, 0x5507, 0x55d4, 0x5875,
+ 0x632f, 0x6422, 0x6649, 0x664b, 0x686d, 0x699b, 0x6b84, 0x6d25,
+ 0x6eb1, 0x73cd, 0x7468, 0x74a1, 0x755b, 0x75b9, 0x76e1, 0x771e,
+ 0x778b, 0x79e6, 0x7e09, 0x7e1d, 0x81fb, 0x852f, 0x8897, 0x8a3a,
+ 0x8cd1, 0x8eeb, 0x8fb0, 0x9032, 0x93ad, 0x9663, 0x9673, 0x9707,
+ 0x4f84, 0x53f1, 0x59ea, 0x5ac9, 0x5e19, 0x684e, 0x74c6, 0x75be,
+ 0x79e9, 0x7a92, 0x81a3, 0x86ed, 0x8cea, 0x8dcc, 0x8fed, 0x659f,
+ 0x6715, 0xf9fd, 0x57f7, 0x6f57, 0x7ddd, 0x8f2f,
+ /* 0x73 */
+ 0x93f6, 0x96c6, 0x5fb5, 0x61f2, 0x6f84, 0x4e14, 0x4f98, 0x501f,
+ 0x53c9, 0x55df, 0x5d6f, 0x5dee, 0x6b21, 0x6b64, 0x78cb, 0x7b9a,
+ 0xf9fe, 0x8e49, 0x8eca, 0x906e, 0x6349, 0x643e, 0x7740, 0x7a84,
+ 0x932f, 0x947f, 0x9f6a, 0x64b0, 0x6faf, 0x71e6, 0x74a8, 0x74da,
+ 0x7ac4, 0x7c12, 0x7e82, 0x7cb2, 0x7e98, 0x8b9a, 0x8d0a, 0x947d,
+ 0x9910, 0x994c, 0x5239, 0x5bdf, 0x64e6, 0x672d, 0x7d2e, 0x50ed,
+ 0x53c3, 0x5879, 0x6158, 0x6159, 0x61fa, 0x65ac, 0x7ad9, 0x8b92,
+ 0x8b96, 0x5009, 0x5021, 0x5275, 0x5531, 0x5a3c, 0x5ee0, 0x5f70,
+ 0x6134, 0x655e, 0x660c, 0x6636, 0x66a2, 0x69cd, 0x6ec4, 0x6f32,
+ 0x7316, 0x7621, 0x7a93, 0x8139, 0x8259, 0x83d6, 0x84bc, 0x50b5,
+ 0x57f0, 0x5bc0, 0x5be8, 0x5f69, 0x63a1, 0x7826, 0x7db5, 0x83dc,
+ 0x8521, 0x91c7, 0x91f5, 0x518a, 0x67f5, 0x7b56,
+ /* 0x74 */
+ 0x8cac, 0x51c4, 0x59bb, 0x60bd, 0x8655, 0x501c, 0xf9ff, 0x5254,
+ 0x5c3a, 0x617d, 0x621a, 0x62d3, 0x64f2, 0x65a5, 0x6ecc, 0x7620,
+ 0x810a, 0x8e60, 0x965f, 0x96bb, 0x4edf, 0x5343, 0x5598, 0x5929,
+ 0x5ddd, 0x64c5, 0x6cc9, 0x6dfa, 0x7394, 0x7a7f, 0x821b, 0x85a6,
+ 0x8ce4, 0x8e10, 0x9077, 0x91e7, 0x95e1, 0x9621, 0x97c6, 0x51f8,
+ 0x54f2, 0x5586, 0x5fb9, 0x64a4, 0x6f88, 0x7db4, 0x8f1f, 0x8f4d,
+ 0x9435, 0x50c9, 0x5c16, 0x6cbe, 0x6dfb, 0x751b, 0x77bb, 0x7c3d,
+ 0x7c64, 0x8a79, 0x8ac2, 0x581e, 0x59be, 0x5e16, 0x6377, 0x7252,
+ 0x758a, 0x776b, 0x8adc, 0x8cbc, 0x8f12, 0x5ef3, 0x6674, 0x6df8,
+ 0x807d, 0x83c1, 0x8acb, 0x9751, 0x9bd6, 0xfa00, 0x5243, 0x66ff,
+ 0x6d95, 0x6eef, 0x7de0, 0x8ae6, 0x902e, 0x905e, 0x9ad4, 0x521d,
+ 0x527f, 0x54e8, 0x6194, 0x6284, 0x62db, 0x68a2,
+ /* 0x75 */
+ 0x6912, 0x695a, 0x6a35, 0x7092, 0x7126, 0x785d, 0x7901, 0x790e,
+ 0x79d2, 0x7a0d, 0x8096, 0x8278, 0x82d5, 0x8349, 0x8549, 0x8c82,
+ 0x8d85, 0x9162, 0x918b, 0x91ae, 0x4fc3, 0x56d1, 0x71ed, 0x77d7,
+ 0x8700, 0x89f8, 0x5bf8, 0x5fd6, 0x6751, 0x90a8, 0x53e2, 0x585a,
+ 0x5bf5, 0x60a4, 0x6181, 0x6460, 0x7e3d, 0x8070, 0x8525, 0x9283,
+ 0x64ae, 0x50ac, 0x5d14, 0x6700, 0x589c, 0x62bd, 0x63a8, 0x690e,
+ 0x6978, 0x6a1e, 0x6e6b, 0x76ba, 0x79cb, 0x82bb, 0x8429, 0x8acf,
+ 0x8da8, 0x8ffd, 0x9112, 0x914b, 0x919c, 0x9310, 0x9318, 0x939a,
+ 0x96db, 0x9a36, 0x9c0d, 0x4e11, 0x755c, 0x795d, 0x7afa, 0x7b51,
+ 0x7bc9, 0x7e2e, 0x84c4, 0x8e59, 0x8e74, 0x8ef8, 0x9010, 0x6625,
+ 0x693f, 0x7443, 0x51fa, 0x672e, 0x9edc, 0x5145, 0x5fe0, 0x6c96,
+ 0x87f2, 0x885d, 0x8877, 0x60b4, 0x81b5, 0x8403,
+ /* 0x76 */
+ 0x8d05, 0x53d6, 0x5439, 0x5634, 0x5a36, 0x5c31, 0x708a, 0x7fe0,
+ 0x805a, 0x8106, 0x81ed, 0x8da3, 0x9189, 0x9a5f, 0x9df2, 0x5074,
+ 0x4ec4, 0x53a0, 0x60fb, 0x6e2c, 0x5c64, 0x4f88, 0x5024, 0x55e4,
+ 0x5cd9, 0x5e5f, 0x6065, 0x6894, 0x6cbb, 0x6dc4, 0x71be, 0x75d4,
+ 0x75f4, 0x7661, 0x7a1a, 0x7a49, 0x7dc7, 0x7dfb, 0x7f6e, 0x81f4,
+ 0x86a9, 0x8f1c, 0x96c9, 0x99b3, 0x9f52, 0x5247, 0x52c5, 0x98ed,
+ 0x89aa, 0x4e03, 0x67d2, 0x6f06, 0x4fb5, 0x5be2, 0x6795, 0x6c88,
+ 0x6d78, 0x741b, 0x7827, 0x91dd, 0x937c, 0x87c4, 0x79e4, 0x7a31,
+ 0x5feb, 0x4ed6, 0x54a4, 0x553e, 0x58ae, 0x59a5, 0x60f0, 0x6253,
+ 0x62d6, 0x6736, 0x6955, 0x8235, 0x9640, 0x99b1, 0x99dd, 0x502c,
+ 0x5353, 0x5544, 0x577c, 0xfa01, 0x6258, 0xfa02, 0x64e2, 0x666b,
+ 0x67dd, 0x6fc1, 0x6fef, 0x7422, 0x7438, 0x8a17,
+ /* 0x77 */
+ 0x9438, 0x5451, 0x5606, 0x5766, 0x5f48, 0x619a, 0x6b4e, 0x7058,
+ 0x70ad, 0x7dbb, 0x8a95, 0x596a, 0x812b, 0x63a2, 0x7708, 0x803d,
+ 0x8caa, 0x5854, 0x642d, 0x69bb, 0x5b95, 0x5e11, 0x6e6f, 0xfa03,
+ 0x8569, 0x514c, 0x53f0, 0x592a, 0x6020, 0x614b, 0x6b86, 0x6c70,
+ 0x6cf0, 0x7b1e, 0x80ce, 0x82d4, 0x8dc6, 0x90b0, 0x98b1, 0xfa04,
+ 0x64c7, 0x6fa4, 0x6491, 0x6504, 0x514e, 0x5410, 0x571f, 0x8a0e,
+ 0x615f, 0x6876, 0xfa05, 0x75db, 0x7b52, 0x7d71, 0x901a, 0x5806,
+ 0x69cc, 0x817f, 0x892a, 0x9000, 0x9839, 0x5078, 0x5957, 0x59ac,
+ 0x6295, 0x900f, 0x9b2a, 0x615d, 0x7279, 0x95d6, 0x5761, 0x5a46,
+ 0x5df4, 0x628a, 0x64ad, 0x64fa, 0x6777, 0x6ce2, 0x6d3e, 0x722c,
+ 0x7436, 0x7834, 0x7f77, 0x82ad, 0x8ddb, 0x9817, 0x5224, 0x5742,
+ 0x677f, 0x7248, 0x74e3, 0x8ca9, 0x8fa6, 0x9211,
+ /* 0x78 */
+ 0x962a, 0x516b, 0x53ed, 0x634c, 0x4f69, 0x5504, 0x6096, 0x6557,
+ 0x6c9b, 0x6d7f, 0x724c, 0x72fd, 0x7a17, 0x8987, 0x8c9d, 0x5f6d,
+ 0x6f8e, 0x70f9, 0x81a8, 0x610e, 0x4fbf, 0x504f, 0x6241, 0x7247,
+ 0x7bc7, 0x7de8, 0x7fe9, 0x904d, 0x97ad, 0x9a19, 0x8cb6, 0x576a,
+ 0x5e73, 0x67b0, 0x840d, 0x8a55, 0x5420, 0x5b16, 0x5e63, 0x5ee2,
+ 0x5f0a, 0x6583, 0x80ba, 0x853d, 0x9589, 0x965b, 0x4f48, 0x5305,
+ 0x530d, 0x530f, 0x5486, 0x54fa, 0x5703, 0x5e03, 0x6016, 0x629b,
+ 0x62b1, 0x6355, 0xfa06, 0x6ce1, 0x6d66, 0x75b1, 0x7832, 0x80de,
+ 0x812f, 0x82de, 0x8461, 0x84b2, 0x888d, 0x8912, 0x900b, 0x92ea,
+ 0x98fd, 0x9b91, 0x5e45, 0x66b4, 0x66dd, 0x7011, 0x7206, 0xfa07,
+ 0x4ff5, 0x527d, 0x5f6a, 0x6153, 0x6753, 0x6a19, 0x6f02, 0x74e2,
+ 0x7968, 0x8868, 0x8c79, 0x98c7, 0x98c4, 0x9a43,
+ /* 0x79 */
+ 0x54c1, 0x7a1f, 0x6953, 0x8af7, 0x8c4a, 0x98a8, 0x99ae, 0x5f7c,
+ 0x62ab, 0x75b2, 0x76ae, 0x88ab, 0x907f, 0x9642, 0x5339, 0x5f3c,
+ 0x5fc5, 0x6ccc, 0x73cc, 0x7562, 0x758b, 0x7b46, 0x82fe, 0x999d,
+ 0x4e4f, 0x903c, 0x4e0b, 0x4f55, 0x53a6, 0x590f, 0x5ec8, 0x6630,
+ 0x6cb3, 0x7455, 0x8377, 0x8766, 0x8cc0, 0x9050, 0x971e, 0x9c15,
+ 0x58d1, 0x5b78, 0x8650, 0x8b14, 0x9db4, 0x5bd2, 0x6068, 0x608d,
+ 0x65f1, 0x6c57, 0x6f22, 0x6fa3, 0x701a, 0x7f55, 0x7ff0, 0x9591,
+ 0x9592, 0x9650, 0x97d3, 0x5272, 0x8f44, 0x51fd, 0x542b, 0x54b8,
+ 0x5563, 0x558a, 0x6abb, 0x6db5, 0x7dd8, 0x8266, 0x929c, 0x9677,
+ 0x9e79, 0x5408, 0x54c8, 0x76d2, 0x86e4, 0x95a4, 0x95d4, 0x965c,
+ 0x4ea2, 0x4f09, 0x59ee, 0x5ae6, 0x5df7, 0x6052, 0x6297, 0x676d,
+ 0x6841, 0x6c86, 0x6e2f, 0x7f38, 0x809b, 0x822a,
+ /* 0x7a */
+ 0xfa08, 0xfa09, 0x9805, 0x4ea5, 0x5055, 0x54b3, 0x5793, 0x595a,
+ 0x5b69, 0x5bb3, 0x61c8, 0x6977, 0x6d77, 0x7023, 0x87f9, 0x89e3,
+ 0x8a72, 0x8ae7, 0x9082, 0x99ed, 0x9ab8, 0x52be, 0x6838, 0x5016,
+ 0x5e78, 0x674f, 0x8347, 0x884c, 0x4eab, 0x5411, 0x56ae, 0x73e6,
+ 0x9115, 0x97ff, 0x9909, 0x9957, 0x9999, 0x5653, 0x589f, 0x865b,
+ 0x8a31, 0x61b2, 0x6af6, 0x737b, 0x8ed2, 0x6b47, 0x96aa, 0x9a57,
+ 0x5955, 0x7200, 0x8d6b, 0x9769, 0x4fd4, 0x5cf4, 0x5f26, 0x61f8,
+ 0x665b, 0x6ceb, 0x70ab, 0x7384, 0x73b9, 0x73fe, 0x7729, 0x774d,
+ 0x7d43, 0x7d62, 0x7e23, 0x8237, 0x8852, 0xfa0a, 0x8ce2, 0x9249,
+ 0x986f, 0x5b51, 0x7a74, 0x8840, 0x9801, 0x5acc, 0x4fe0, 0x5354,
+ 0x593e, 0x5cfd, 0x633e, 0x6d79, 0x72f9, 0x8105, 0x8107, 0x83a2,
+ 0x92cf, 0x9830, 0x4ea8, 0x5144, 0x5211, 0x578b,
+ /* 0x7b */
+ 0x5f62, 0x6cc2, 0x6ece, 0x7005, 0x7050, 0x70af, 0x7192, 0x73e9,
+ 0x7469, 0x834a, 0x87a2, 0x8861, 0x9008, 0x90a2, 0x93a3, 0x99a8,
+ 0x516e, 0x5f57, 0x60e0, 0x6167, 0x66b3, 0x8559, 0x8e4a, 0x91af,
+ 0x978b, 0x4e4e, 0x4e92, 0x547c, 0x58d5, 0x58fa, 0x597d, 0x5cb5,
+ 0x5f27, 0x6236, 0x6248, 0x660a, 0x6667, 0x6beb, 0x6d69, 0x6dcf,
+ 0x6e56, 0x6ef8, 0x6f94, 0x6fe0, 0x6fe9, 0x705d, 0x72d0, 0x7425,
+ 0x745a, 0x74e0, 0x7693, 0x795c, 0x7cca, 0x7e1e, 0x80e1, 0x82a6,
+ 0x846b, 0x84bf, 0x864e, 0x865f, 0x8774, 0x8b77, 0x8c6a, 0x93ac,
+ 0x9800, 0x9865, 0x60d1, 0x6216, 0x9177, 0x5a5a, 0x660f, 0x6df7,
+ 0x6e3e, 0x743f, 0x9b42, 0x5ffd, 0x60da, 0x7b0f, 0x54c4, 0x5f18,
+ 0x6c5e, 0x6cd3, 0x6d2a, 0x70d8, 0x7d05, 0x8679, 0x8a0c, 0x9d3b,
+ 0x5316, 0x548c, 0x5b05, 0x6a3a, 0x706b, 0x7575,
+ /* 0x7c */
+ 0x798d, 0x79be, 0x82b1, 0x83ef, 0x8a71, 0x8b41, 0x8ca8, 0x9774,
+ 0xfa0b, 0x64f4, 0x652b, 0x78ba, 0x78bb, 0x7a6b, 0x4e38, 0x559a,
+ 0x5950, 0x5ba6, 0x5e7b, 0x60a3, 0x63db, 0x6b61, 0x6665, 0x6853,
+ 0x6e19, 0x7165, 0x74b0, 0x7d08, 0x9084, 0x9a69, 0x9c25, 0x6d3b,
+ 0x6ed1, 0x733e, 0x8c41, 0x95ca, 0x51f0, 0x5e4c, 0x5fa8, 0x604d,
+ 0x60f6, 0x6130, 0x614c, 0x6643, 0x6644, 0x69a5, 0x6cc1, 0x6e5f,
+ 0x6ec9, 0x6f62, 0x714c, 0x749c, 0x7687, 0x7bc1, 0x7c27, 0x8352,
+ 0x8757, 0x9051, 0x968d, 0x9ec3, 0x532f, 0x56de, 0x5efb, 0x5f8a,
+ 0x6062, 0x6094, 0x61f7, 0x6666, 0x6703, 0x6a9c, 0x6dee, 0x6fae,
+ 0x7070, 0x736a, 0x7e6a, 0x81be, 0x8334, 0x86d4, 0x8aa8, 0x8cc4,
+ 0x5283, 0x7372, 0x5b96, 0x6a6b, 0x9404, 0x54ee, 0x5686, 0x5b5d,
+ 0x6548, 0x6585, 0x66c9, 0x689f, 0x6d8d, 0x6dc6,
+ /* 0x7d */
+ 0x723b, 0x80b4, 0x9175, 0x9a4d, 0x4faf, 0x5019, 0x539a, 0x540e,
+ 0x543c, 0x5589, 0x55c5, 0x5e3f, 0x5f8c, 0x673d, 0x7166, 0x73dd,
+ 0x9005, 0x52db, 0x52f3, 0x5864, 0x58ce, 0x7104, 0x718f, 0x71fb,
+ 0x85b0, 0x8a13, 0x6688, 0x85a8, 0x55a7, 0x6684, 0x714a, 0x8431,
+ 0x5349, 0x5599, 0x6bc1, 0x5f59, 0x5fbd, 0x63ee, 0x6689, 0x7147,
+ 0x8af1, 0x8f1d, 0x9ebe, 0x4f11, 0x643a, 0x70cb, 0x7566, 0x8667,
+ 0x6064, 0x8b4e, 0x9df8, 0x5147, 0x51f6, 0x5308, 0x6d36, 0x80f8,
+ 0x9ed1, 0x6615, 0x6b23, 0x7098, 0x75d5, 0x5403, 0x5c79, 0x7d07,
+ 0x8a16, 0x6b20, 0x6b3d, 0x6b46, 0x5438, 0x6070, 0x6d3d, 0x7fd5,
+ 0x8208, 0x50d6, 0x51de, 0x559c, 0x566b, 0x56cd, 0x59ec, 0x5b09,
+ 0x5e0c, 0x6199, 0x6198, 0x6231, 0x665e, 0x66e6, 0x7199, 0x71b9,
+ 0x71ba, 0x72a7, 0x79a7, 0x7a00, 0x7fb2, 0x8a70,
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/lexer.cxx b/hwpfilter/source/lexer.cxx
new file mode 100644
index 000000000..5f28ff2ee
--- /dev/null
+++ b/hwpfilter/source/lexer.cxx
@@ -0,0 +1,2129 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ */
+#ifndef YY_STACK_USED
+#define YY_STACK_USED 0
+#endif
+#ifndef YY_ALWAYS_INTERACTIVE
+#define YY_ALWAYS_INTERACTIVE 0
+#endif
+#ifndef YY_NEVER_INTERACTIVE
+#define YY_NEVER_INTERACTIVE 0
+#endif
+#ifndef YY_MAIN
+#define YY_MAIN 0
+#endif
+
+#include <stdio.h>
+
+#include <stdlib.h>
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) (static_cast<unsigned int>(static_cast<unsigned char>(c)))
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state.
+ */
+#define YY_START ((yy_start - 1) / 2)
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+namespace {
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+}
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+//#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+namespace {
+
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ bool yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+ };
+
+}
+
+static YY_BUFFER_STATE yy_current_buffer = nullptr;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+
+
+static int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = nullptr;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+static void yyrestart YY_PROTO(( FILE *input_file ));
+
+static void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+static void yy_load_buffer_state YY_PROTO(( ));
+static YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+static void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+static void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+static void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+
+static YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+static YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+static YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+typedef unsigned char YY_CHAR;
+static FILE *yyin = nullptr, *yyout = nullptr;
+typedef int yy_state_type;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = static_cast<int>(yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_END_OF_BUFFER 46
+yyconst short int yy_accept[994] =
+ { 0,
+ 0, 0, 46, 44, 41, 41, 44, 42, 39, 37,
+ 37, 36, 39, 39, 44, 44, 38, 40, 35, 43,
+ 13, 21, 36, 36, 22, 16, 17, 0, 34, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 24, 0, 24, 0, 0, 0, 0, 0,
+ 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 42, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 4, 31, 5, 43,
+ 36, 20, 14, 15, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 24, 0, 0, 0,
+
+ 0, 0, 0, 10, 0, 0, 27, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 12, 12, 0, 0,
+ 0, 0, 0, 0, 0, 12, 0, 0, 0, 0,
+ 0, 0, 0, 0, 12, 0, 27, 0, 0, 0,
+ 0, 0, 0, 0, 0, 11, 0, 9, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 23, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 19, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 8, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 27,
+ 27, 0, 0, 0, 0, 12, 0, 0, 8, 0,
+
+ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 27, 26, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 27,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 12, 27,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 27,
+ 0, 0, 27, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 11, 0, 0, 0, 0, 0, 0, 8, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 29,
+ 0, 0, 0, 0, 0, 0, 24, 0, 0, 0,
+ 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 30, 0, 0,
+ 12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 28, 0, 0, 12, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 19, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 25, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 12, 0, 12, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 11, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 33, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 19, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 12, 12, 0, 24, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 19, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0
+
+ } ;
+
+yyconst int yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 4, 1, 1, 1, 1, 5, 1, 6,
+ 7, 8, 8, 9, 10, 11, 8, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 13, 14, 15,
+ 16, 17, 1, 1, 18, 19, 20, 21, 22, 1,
+ 23, 1, 24, 25, 26, 27, 28, 29, 30, 31,
+ 1, 32, 33, 34, 35, 36, 1, 37, 1, 38,
+ 39, 40, 41, 42, 42, 1, 43, 44, 45, 46,
+
+ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 69, 70, 71, 72, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+ 73, 73, 73, 73, 1
+ } ;
+
+yyconst int yy_meta[74] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1
+ } ;
+
+yyconst short int yy_base[995] =
+ { 0,
+ 0, 72, 1314, 1315, 1315, 1315, 1297, 1315, 1315, 1315,
+ 1295, 2, 8, 1294, 1281, 142, 1315, 1315, 1315, 1236,
+ 1315, 1315, 1296, 8, 1290, 1291, 1288, 1274, 1315, 0,
+ 0, 1253, 1, 1, 1259, 7, 1244, 1257, 8, 1236,
+ 1235, 1242, 35, 43, 1245, 0, 1237, 1251, 1242, 1245,
+ 1315, 46, 72, 171, 79, 62, 77, 184, 192, 92,
+ 1236, 2, 207, 216, 225, 234, 250, 46, 269, 278,
+ 295, 10, 111, 255, 10, 1243, 1315, 1315, 1315, 1216,
+ 1276, 1315, 1315, 1315, 1253, 1228, 1225, 1222, 1217, 1231,
+ 1227, 1237, 1214, 1217, 1234, 1221, 1315, 1213, 1223, 1215,
+
+ 1217, 1223, 1214, 1315, 168, 1218, 1315, 1217, 1210, 1217,
+ 1216, 1201, 1216, 177, 1202, 1199, 1197, 34, 1216, 1209,
+ 1199, 181, 36, 164, 198, 1207, 119, 199, 1201, 1196,
+ 1196, 218, 1192, 1188, 225, 1205, 1191, 78, 40, 245,
+ 280, 1197, 175, 1184, 1192, 1187, 1198, 1182, 1179, 1198,
+ 101, 1197, 1179, 227, 1183, 1191, 1177, 1315, 1192, 1172,
+ 1190, 1189, 53, 1184, 1187, 260, 1167, 1171, 1184, 1168,
+ 1165, 248, 1177, 1166, 291, 1168, 1161, 1174, 1164, 1161,
+ 222, 268, 1160, 0, 1170, 1315, 1172, 1315, 247, 299,
+ 1152, 1170, 1155, 1155, 300, 1156, 1155, 1157, 1160, 1146,
+
+ 1145, 1153, 302, 1152, 1139, 1158, 1144, 1152, 1147, 1143,
+ 1136, 308, 1146, 1137, 1150, 1136, 317, 1148, 308, 318,
+ 1147, 311, 1146, 322, 1145, 312, 1140, 319, 1128, 1134,
+ 324, 340, 1124, 333, 340, 1137, 1136, 1121, 1118, 1315,
+ 1129, 1121, 1134, 1114, 1120, 1118, 1122, 1117, 1128, 1114,
+ 1111, 1124, 1105, 1117, 1116, 1119, 1113, 1107, 1099, 1100,
+ 1102, 1107, 344, 1114, 1094, 1097, 1104, 1099, 327, 1092,
+ 347, 1094, 1095, 1096, 1315, 1105, 1096, 1103, 350, 1083,
+ 1099, 1079, 1088, 1079, 1095, 1094, 1094, 1088, 1076, 1085,
+ 1084, 1084, 1082, 1082, 1068, 1067, 1073, 1071, 1079, 1069,
+
+ 1069, 1061, 1315, 1071, 1070, 1059, 1057, 1075, 1072, 1051,
+ 1060, 1050, 1053, 1052, 1058, 1054, 348, 1047, 1315, 1065,
+ 1045, 1048, 1061, 1055, 1052, 1040, 1039, 1043, 1042, 338,
+ 1035, 1048, 1035, 1048, 1038, 1039, 1029, 1031, 276, 1030,
+ 1027, 1026, 1038, 371, 1023, 1042, 1029, 1023, 355, 1024,
+ 1036, 1025, 372, 1036, 1032, 1028, 1025, 1020, 1017, 1016,
+ 1022, 1008, 1014, 1020, 1008, 1012, 1006, 1010, 1017, 1013,
+ 1008, 1007, 1014, 360, 997, 995, 997, 995, 1010, 372,
+ 1008, 993, 1002, 156, 1005, 1003, 1006, 1001, 997, 996,
+ 985, 987, 980, 991, 374, 980, 978, 977, 989, 990,
+
+ 993, 992, 969, 990, 975, 988, 976, 986, 985, 981,
+ 379, 191, 983, 965, 962, 980, 979, 961, 955, 965,
+ 960, 374, 967, 965, 965, 967, 963, 969, 962, 963,
+ 947, 951, 950, 955, 962, 939, 945, 941, 938, 944,
+ 377, 383, 940, 938, 939, 949, 948, 943, 946, 945,
+ 944, 929, 936, 927, 930, 939, 921, 935, 922, 939,
+ 924, 933, 920, 935, 910, 922, 911, 912, 919, 1315,
+ 916, 928, 923, 907, 388, 906, 920, 916, 898, 914,
+ 920, 916, 907, 906, 898, 400, 901, 894, 900, 892,
+ 893, 392, 891, 898, 902, 907, 889, 888, 891, 895,
+
+ 885, 901, 883, 879, 880, 879, 892, 405, 884, 886,
+ 889, 888, 872, 887, 878, 877, 887, 872, 865, 865,
+ 865, 876, 870, 863, 871, 863, 877, 860, 864, 870,
+ 869, 857, 856, 1315, 400, 866, 865, 851, 863, 849,
+ 861, 864, 859, 844, 848, 843, 856, 855, 840, 834,
+ 837, 843, 838, 403, 845, 843, 843, 834, 841, 829,
+ 1315, 842, 401, 824, 831, 826, 828, 841, 823, 831,
+ 834, 829, 822, 835, 820, 820, 818, 813, 822, 815,
+ 822, 823, 809, 802, 806, 810, 809, 800, 809, 801,
+ 1315, 803, 800, 801, 404, 807, 803, 805, 810, 803,
+
+ 799, 805, 805, 803, 785, 786, 1315, 784, 800, 785,
+ 797, 787, 782, 780, 783, 778, 784, 776, 789, 784,
+ 783, 790, 785, 771, 787, 778, 768, 769, 778, 767,
+ 762, 776, 779, 770, 763, 758, 764, 774, 759, 93,
+ 126, 187, 225, 269, 333, 415, 345, 372, 388, 397,
+ 400, 417, 418, 408, 411, 427, 409, 418, 426, 417,
+ 419, 415, 417, 418, 419, 419, 423, 422, 422, 428,
+ 438, 438, 444, 432, 434, 434, 431, 442, 437, 446,
+ 449, 436, 456, 449, 454, 456, 443, 448, 445, 457,
+ 459, 459, 453, 450, 446, 469, 457, 463, 460, 454,
+
+ 460, 471, 476, 473, 476, 458, 461, 468, 462, 471,
+ 484, 485, 466, 481, 484, 481, 473, 488, 475, 489,
+ 481, 475, 491, 491, 496, 482, 483, 495, 1315, 502,
+ 498, 490, 500, 503, 497, 487, 488, 498, 512, 508,
+ 501, 509, 512, 506, 514, 502, 520, 521, 518, 501,
+ 504, 505, 506, 523, 524, 525, 526, 527, 510, 519,
+ 523, 518, 528, 515, 538, 526, 532, 529, 523, 535,
+ 525, 534, 529, 533, 534, 542, 531, 544, 535, 536,
+ 543, 555, 556, 545, 541, 541, 540, 543, 558, 548,
+ 549, 552, 548, 563, 551, 550, 552, 557, 553, 565,
+
+ 555, 568, 576, 563, 563, 572, 578, 562, 564, 576,
+ 582, 566, 582, 580, 577, 572, 573, 589, 574, 581,
+ 586, 576, 577, 581, 579, 583, 583, 597, 602, 590,
+ 587, 594, 606, 607, 597, 1315, 606, 591, 589, 590,
+ 594, 614, 596, 602, 600, 604, 600, 613, 603, 604,
+ 617, 605, 605, 604, 608, 628, 610, 619, 610, 619,
+ 615, 628, 636, 618, 619, 635, 640, 622, 628, 628,
+ 637, 626, 642, 643, 644, 646, 648, 647, 635, 640,
+ 641, 652, 658, 642, 652, 661, 640, 650, 652, 655,
+ 659, 651, 669, 656, 671, 668, 656, 666, 661, 676,
+
+ 660, 678, 657, 666, 677, 666, 667, 680, 677, 682,
+ 673, 675, 676, 673, 674, 686, 676, 672, 691, 677,
+ 680, 681, 686, 683, 684, 696, 686, 687, 688, 692,
+ 702, 702, 687, 693, 697, 705, 696, 711, 701, 699,
+ 714, 701, 705, 713, 704, 708, 706, 711, 706, 719,
+ 713, 706, 710, 716, 718, 718, 713, 722, 723, 723,
+ 725, 718, 722, 728, 721, 730, 742, 727, 725, 748,
+ 727, 728, 729, 730, 731, 754, 733, 734, 743, 743,
+ 742, 747, 748, 746, 742, 748, 749, 754, 754, 755,
+ 748, 749, 1315, 814
+
+ } ;
+
+yyconst short int yy_def[995] =
+ { 0,
+ 994, 994, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 0, 993
+
+ } ;
+
+yyconst short int yy_nxt[1389] =
+ { 0,
+ 993, 5, 6, 7, 8, 9, 9, 10, 993, 11,
+ 993, 12, 23, 24, 13, 10, 14, 25, 23, 24,
+ 993, 993, 26, 993, 993, 993, 15, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 9, 16,
+ 9, 17, 112, 993, 170, 158, 88, 91, 171, 113,
+ 101, 92, 993, 86, 102, 107, 89, 93, 94, 87,
+ 188, 97, 95, 98, 103, 231, 238, 232, 9, 18,
+ 9, 19, 20, 5, 6, 7, 8, 9, 9, 10,
+ 266, 11, 294, 12, 106, 104, 13, 10, 14, 97,
+ 117, 267, 109, 110, 107, 108, 295, 186, 15, 118,
+
+ 119, 120, 273, 121, 205, 122, 123, 107, 206, 315,
+ 9, 16, 9, 17, 124, 145, 146, 147, 125, 148,
+ 149, 138, 126, 150, 139, 140, 292, 151, 127, 141,
+ 152, 128, 142, 153, 129, 143, 154, 164, 293, 144,
+ 9, 18, 9, 19, 20, 29, 165, 166, 167, 737,
+ 29, 306, 168, 233, 29, 29, 234, 235, 107, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
+ 97, 51, 738, 280, 52, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
+
+ 68, 69, 70, 71, 72, 73, 74, 75, 274, 76,
+ 77, 78, 79, 130, 255, 541, 131, 542, 256, 260,
+ 132, 133, 261, 275, 134, 271, 155, 135, 156, 107,
+ 157, 136, 158, 137, 160, 161, 299, 262, 162, 300,
+ 272, 281, 276, 159, 571, 282, 277, 186, 163, 172,
+ 572, 173, 174, 175, 176, 177, 178, 179, 182, 278,
+ 158, 180, 107, 181, 285, 183, 184, 189, 188, 309,
+ 107, 190, 185, 186, 186, 158, 187, 332, 188, 193,
+ 288, 191, 289, 310, 194, 290, 291, 188, 195, 192,
+ 336, 196, 200, 107, 197, 198, 201, 199, 296, 202,
+
+ 188, 236, 323, 324, 186, 237, 107, 318, 337, 203,
+ 204, 207, 97, 208, 186, 209, 210, 211, 212, 213,
+ 216, 319, 297, 214, 217, 333, 499, 218, 219, 186,
+ 215, 500, 220, 107, 107, 221, 222, 226, 327, 223,
+ 224, 338, 225, 186, 227, 228, 343, 97, 351, 158,
+ 344, 229, 352, 186, 230, 374, 368, 158, 353, 365,
+ 371, 107, 369, 370, 188, 378, 379, 383, 372, 388,
+ 375, 376, 385, 386, 188, 396, 319, 389, 366, 380,
+ 430, 381, 391, 390, 275, 392, 186, 431, 489, 397,
+ 421, 433, 739, 393, 441, 742, 477, 509, 490, 398,
+
+ 394, 422, 532, 423, 424, 425, 442, 434, 435, 478,
+ 443, 444, 445, 446, 447, 503, 510, 319, 538, 592,
+ 553, 569, 533, 579, 104, 743, 504, 593, 595, 513,
+ 744, 554, 539, 555, 556, 557, 558, 596, 570, 594,
+ 597, 619, 624, 664, 598, 632, 633, 620, 645, 625,
+ 683, 634, 678, 188, 706, 158, 158, 665, 646, 626,
+ 707, 740, 684, 79, 647, 741, 745, 79, 729, 746,
+ 748, 749, 97, 750, 751, 752, 747, 753, 754, 755,
+ 756, 158, 757, 758, 759, 760, 761, 762, 764, 765,
+ 766, 767, 188, 188, 768, 769, 770, 763, 771, 772,
+
+ 773, 97, 774, 104, 775, 776, 777, 778, 104, 779,
+ 561, 780, 104, 781, 782, 783, 784, 785, 786, 158,
+ 186, 319, 319, 787, 788, 789, 790, 792, 793, 794,
+ 795, 796, 186, 797, 798, 799, 188, 800, 801, 802,
+ 803, 804, 805, 806, 807, 808, 791, 809, 810, 97,
+ 97, 561, 561, 188, 811, 812, 813, 814, 815, 97,
+ 158, 816, 817, 818, 97, 561, 819, 820, 821, 822,
+ 823, 824, 825, 826, 561, 827, 828, 829, 830, 561,
+ 831, 188, 832, 833, 834, 835, 836, 837, 838, 839,
+ 840, 841, 842, 843, 844, 845, 846, 104, 104, 97,
+
+ 847, 848, 849, 319, 850, 319, 319, 851, 319, 319,
+ 852, 97, 853, 854, 97, 855, 856, 857, 858, 859,
+ 860, 861, 862, 863, 864, 865, 866, 867, 836, 868,
+ 158, 869, 870, 871, 186, 319, 872, 873, 874, 158,
+ 158, 158, 875, 876, 877, 878, 879, 880, 188, 188,
+ 881, 882, 729, 561, 561, 883, 884, 886, 887, 888,
+ 889, 729, 78, 319, 319, 890, 729, 891, 561, 97,
+ 892, 893, 158, 885, 561, 894, 895, 896, 897, 899,
+ 900, 836, 901, 902, 903, 904, 905, 97, 906, 907,
+ 158, 97, 910, 836, 911, 898, 912, 913, 836, 908,
+
+ 914, 915, 916, 917, 561, 909, 918, 104, 919, 920,
+ 921, 922, 923, 924, 729, 925, 926, 561, 927, 928,
+ 929, 561, 930, 729, 158, 158, 931, 932, 836, 933,
+ 188, 188, 934, 935, 936, 937, 561, 938, 97, 939,
+ 940, 941, 942, 943, 944, 945, 946, 947, 948, 949,
+ 950, 561, 951, 952, 953, 954, 955, 957, 958, 959,
+ 961, 962, 963, 964, 965, 966, 967, 186, 968, 969,
+ 561, 970, 971, 956, 972, 186, 960, 561, 973, 974,
+ 561, 975, 561, 976, 977, 836, 978, 979, 186, 561,
+ 981, 561, 982, 561, 983, 561, 984, 561, 836, 985,
+
+ 561, 986, 186, 561, 980, 987, 988, 989, 990, 561,
+ 991, 992, 561, 561, 4, 736, 735, 734, 158, 561,
+ 733, 732, 731, 730, 107, 107, 729, 77, 728, 727,
+ 726, 77, 188, 725, 724, 723, 722, 97, 97, 721,
+ 720, 719, 718, 717, 186, 319, 716, 186, 715, 158,
+ 714, 319, 713, 712, 711, 710, 709, 708, 319, 705,
+ 319, 704, 703, 702, 107, 107, 107, 158, 701, 700,
+ 699, 104, 104, 698, 697, 696, 695, 694, 693, 692,
+ 691, 690, 689, 104, 688, 687, 686, 685, 186, 607,
+ 158, 682, 681, 680, 679, 677, 676, 186, 675, 674,
+
+ 186, 186, 673, 672, 186, 275, 188, 671, 670, 669,
+ 668, 667, 666, 186, 186, 663, 158, 662, 158, 188,
+ 97, 661, 660, 659, 658, 657, 656, 655, 654, 653,
+ 79, 652, 29, 651, 97, 650, 649, 648, 644, 643,
+ 186, 642, 641, 188, 640, 158, 158, 639, 638, 97,
+ 637, 636, 635, 631, 630, 629, 628, 627, 607, 77,
+ 623, 622, 188, 97, 607, 97, 158, 621, 618, 275,
+ 188, 158, 617, 616, 158, 615, 614, 613, 158, 561,
+ 612, 188, 607, 611, 158, 610, 609, 608, 275, 607,
+ 606, 275, 605, 604, 603, 602, 601, 600, 599, 591,
+
+ 590, 589, 158, 588, 587, 586, 585, 584, 583, 97,
+ 186, 188, 97, 275, 582, 581, 580, 578, 577, 576,
+ 575, 104, 104, 574, 573, 104, 568, 104, 104, 567,
+ 566, 565, 104, 564, 104, 188, 563, 562, 561, 560,
+ 559, 552, 551, 550, 549, 548, 547, 546, 545, 544,
+ 543, 107, 540, 97, 537, 536, 186, 535, 534, 531,
+ 530, 529, 107, 528, 527, 526, 525, 524, 523, 522,
+ 521, 520, 519, 518, 517, 516, 515, 29, 514, 512,
+ 511, 158, 508, 507, 506, 505, 502, 319, 186, 501,
+ 498, 497, 496, 495, 494, 493, 492, 491, 488, 487,
+
+ 486, 485, 484, 483, 482, 481, 480, 188, 479, 476,
+ 475, 474, 97, 473, 472, 471, 470, 469, 97, 468,
+ 467, 466, 465, 186, 464, 463, 462, 461, 460, 459,
+ 458, 457, 456, 107, 107, 455, 158, 454, 186, 453,
+ 452, 451, 450, 449, 448, 188, 440, 439, 438, 437,
+ 436, 432, 429, 428, 427, 426, 104, 420, 419, 418,
+ 417, 416, 415, 414, 413, 412, 411, 410, 409, 158,
+ 104, 408, 407, 406, 405, 404, 104, 403, 402, 401,
+ 158, 400, 399, 395, 387, 97, 384, 382, 377, 373,
+ 367, 364, 363, 362, 361, 360, 359, 358, 357, 356,
+
+ 355, 354, 188, 188, 350, 349, 348, 347, 346, 345,
+ 342, 341, 340, 339, 335, 334, 97, 331, 330, 186,
+ 329, 328, 326, 325, 107, 322, 321, 158, 320, 317,
+ 316, 314, 313, 275, 312, 158, 107, 311, 308, 307,
+ 188, 305, 304, 303, 302, 97, 301, 298, 186, 107,
+ 287, 286, 284, 186, 283, 279, 270, 269, 268, 265,
+ 264, 263, 259, 104, 258, 257, 104, 104, 104, 254,
+ 253, 252, 251, 250, 249, 248, 104, 247, 246, 245,
+ 244, 104, 97, 243, 242, 241, 240, 81, 80, 239,
+ 169, 116, 104, 115, 114, 111, 105, 104, 104, 100,
+
+ 99, 96, 90, 85, 84, 83, 82, 81, 80, 28,
+ 27, 22, 21, 993, 3, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993
+ } ;
+
+yyconst short int yy_chk[1389] =
+ { 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 0, 1,
+ 0, 1, 12, 12, 1, 1, 1, 13, 24, 24,
+ 0, 0, 13, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 1, 46, 0, 62, 184, 31, 33, 62, 46,
+ 39, 33, 0, 30, 39, 184, 31, 33, 34, 30,
+ 75, 36, 34, 36, 39, 72, 75, 72, 1, 1,
+ 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
+ 118, 2, 139, 2, 43, 43, 2, 2, 2, 44,
+ 52, 118, 44, 44, 43, 43, 139, 123, 2, 52,
+
+ 52, 52, 123, 52, 68, 52, 52, 163, 68, 163,
+ 2, 2, 2, 2, 53, 56, 56, 56, 53, 56,
+ 56, 55, 53, 56, 55, 55, 138, 56, 53, 55,
+ 57, 53, 55, 57, 53, 55, 57, 60, 138, 55,
+ 2, 2, 2, 2, 2, 16, 60, 60, 60, 640,
+ 16, 151, 60, 73, 16, 16, 73, 73, 151, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 127, 16, 641, 127, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+
+ 16, 16, 16, 16, 16, 16, 16, 16, 124, 16,
+ 16, 16, 16, 54, 105, 384, 54, 384, 105, 114,
+ 54, 54, 114, 124, 54, 122, 58, 54, 58, 122,
+ 58, 54, 58, 54, 59, 59, 143, 114, 59, 143,
+ 122, 128, 125, 58, 412, 128, 125, 642, 59, 63,
+ 412, 63, 63, 63, 63, 63, 63, 63, 64, 125,
+ 63, 63, 63, 63, 132, 64, 64, 65, 132, 154,
+ 181, 65, 64, 64, 643, 65, 64, 181, 64, 66,
+ 135, 65, 135, 154, 66, 135, 135, 65, 66, 65,
+ 189, 66, 67, 140, 66, 66, 67, 66, 140, 67,
+
+ 67, 74, 172, 172, 67, 74, 140, 166, 189, 67,
+ 67, 69, 74, 69, 74, 69, 69, 69, 69, 69,
+ 70, 166, 141, 69, 70, 182, 339, 70, 70, 644,
+ 69, 339, 70, 182, 141, 70, 70, 71, 175, 70,
+ 70, 190, 70, 141, 71, 71, 195, 190, 203, 175,
+ 195, 71, 203, 212, 71, 222, 219, 190, 203, 217,
+ 220, 217, 219, 219, 212, 224, 224, 226, 220, 231,
+ 222, 222, 228, 228, 226, 234, 224, 231, 217, 224,
+ 269, 224, 232, 231, 235, 232, 235, 269, 330, 234,
+ 263, 271, 645, 232, 279, 647, 317, 349, 330, 235,
+
+ 232, 263, 374, 263, 263, 263, 279, 271, 271, 317,
+ 279, 279, 279, 279, 279, 344, 349, 353, 380, 441,
+ 395, 411, 374, 422, 422, 648, 344, 441, 442, 353,
+ 649, 395, 380, 395, 395, 395, 395, 442, 411, 441,
+ 442, 475, 486, 535, 442, 492, 492, 475, 508, 486,
+ 563, 492, 554, 554, 595, 650, 651, 535, 508, 486,
+ 595, 646, 563, 652, 508, 646, 653, 654, 655, 656,
+ 657, 658, 659, 660, 661, 662, 656, 663, 664, 665,
+ 666, 667, 668, 669, 670, 671, 672, 673, 674, 675,
+ 676, 677, 678, 679, 680, 681, 682, 673, 683, 684,
+
+ 685, 686, 687, 688, 689, 690, 691, 692, 693, 694,
+ 695, 696, 697, 698, 699, 700, 701, 702, 703, 704,
+ 705, 706, 707, 708, 709, 710, 711, 712, 713, 714,
+ 715, 716, 717, 718, 719, 720, 721, 722, 723, 724,
+ 725, 726, 727, 728, 730, 731, 711, 732, 733, 734,
+ 735, 736, 737, 738, 739, 740, 741, 742, 743, 744,
+ 745, 746, 747, 748, 749, 750, 751, 752, 753, 754,
+ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764,
+ 765, 766, 767, 768, 769, 770, 771, 772, 773, 774,
+ 775, 776, 777, 778, 779, 780, 781, 782, 783, 784,
+
+ 785, 786, 787, 788, 789, 790, 791, 792, 793, 794,
+ 795, 796, 797, 798, 799, 800, 801, 802, 803, 804,
+ 805, 806, 807, 808, 809, 810, 811, 812, 813, 814,
+ 815, 816, 817, 818, 819, 820, 821, 822, 823, 824,
+ 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
+ 835, 837, 838, 839, 840, 841, 842, 843, 844, 845,
+ 846, 847, 848, 849, 850, 851, 852, 853, 854, 855,
+ 856, 857, 858, 842, 859, 860, 861, 862, 863, 864,
+ 865, 866, 867, 868, 869, 870, 871, 872, 873, 874,
+ 875, 876, 877, 878, 879, 863, 880, 881, 882, 876,
+
+ 883, 884, 885, 886, 887, 876, 888, 889, 890, 891,
+ 892, 893, 894, 895, 896, 897, 898, 899, 900, 901,
+ 902, 903, 904, 905, 906, 907, 908, 909, 910, 911,
+ 912, 913, 914, 915, 916, 917, 918, 919, 920, 921,
+ 922, 923, 924, 925, 926, 927, 928, 929, 930, 931,
+ 932, 933, 934, 935, 936, 937, 938, 939, 940, 941,
+ 942, 943, 944, 945, 946, 947, 948, 949, 950, 951,
+ 952, 953, 954, 938, 955, 956, 941, 957, 958, 959,
+ 960, 961, 962, 963, 964, 965, 966, 967, 968, 969,
+ 970, 971, 972, 973, 974, 975, 976, 977, 978, 979,
+
+ 980, 981, 982, 983, 967, 984, 985, 986, 987, 988,
+ 989, 990, 991, 992, 994, 639, 638, 637, 636, 635,
+ 634, 633, 632, 631, 630, 629, 628, 627, 626, 625,
+ 624, 623, 622, 621, 620, 619, 618, 617, 616, 615,
+ 614, 613, 612, 611, 610, 609, 608, 606, 605, 604,
+ 603, 602, 601, 600, 599, 598, 597, 596, 594, 593,
+ 592, 590, 589, 588, 587, 586, 585, 584, 583, 582,
+ 581, 580, 579, 578, 577, 576, 575, 574, 573, 572,
+ 571, 570, 569, 568, 567, 566, 565, 564, 562, 560,
+ 559, 558, 557, 556, 555, 553, 552, 551, 550, 549,
+
+ 548, 547, 546, 545, 544, 543, 542, 541, 540, 539,
+ 538, 537, 536, 533, 532, 531, 530, 529, 528, 527,
+ 526, 525, 524, 523, 522, 521, 520, 519, 518, 517,
+ 516, 515, 514, 513, 512, 511, 510, 509, 507, 506,
+ 505, 504, 503, 502, 501, 500, 499, 498, 497, 496,
+ 495, 494, 493, 491, 490, 489, 488, 487, 485, 484,
+ 483, 482, 481, 480, 479, 478, 477, 476, 474, 473,
+ 472, 471, 469, 468, 467, 466, 465, 464, 463, 462,
+ 461, 460, 459, 458, 457, 456, 455, 454, 453, 452,
+ 451, 450, 449, 448, 447, 446, 445, 444, 443, 440,
+
+ 439, 438, 437, 436, 435, 434, 433, 432, 431, 430,
+ 429, 428, 427, 426, 425, 424, 423, 421, 420, 419,
+ 418, 417, 416, 415, 414, 413, 410, 409, 408, 407,
+ 406, 405, 404, 403, 402, 401, 400, 399, 398, 397,
+ 396, 394, 393, 392, 391, 390, 389, 388, 387, 386,
+ 385, 383, 382, 381, 379, 378, 377, 376, 375, 373,
+ 372, 371, 370, 369, 368, 367, 366, 365, 364, 363,
+ 362, 361, 360, 359, 358, 357, 356, 355, 354, 352,
+ 351, 350, 348, 347, 346, 345, 343, 342, 341, 340,
+ 338, 337, 336, 335, 334, 333, 332, 331, 329, 328,
+
+ 327, 326, 325, 324, 323, 322, 321, 320, 318, 316,
+ 315, 314, 313, 312, 311, 310, 309, 308, 307, 306,
+ 305, 304, 302, 301, 300, 299, 298, 297, 296, 295,
+ 294, 293, 292, 291, 290, 289, 288, 287, 286, 285,
+ 284, 283, 282, 281, 280, 278, 277, 276, 274, 273,
+ 272, 270, 268, 267, 266, 265, 264, 262, 261, 260,
+ 259, 258, 257, 256, 255, 254, 253, 252, 251, 250,
+ 249, 248, 247, 246, 245, 244, 243, 242, 241, 239,
+ 238, 237, 236, 233, 230, 229, 227, 225, 223, 221,
+ 218, 216, 215, 214, 213, 211, 210, 209, 208, 207,
+
+ 206, 205, 204, 202, 201, 200, 199, 198, 197, 196,
+ 194, 193, 192, 191, 187, 185, 183, 180, 179, 178,
+ 177, 176, 174, 173, 171, 170, 169, 168, 167, 165,
+ 164, 162, 161, 160, 159, 157, 156, 155, 153, 152,
+ 150, 149, 148, 147, 146, 145, 144, 142, 137, 136,
+ 134, 133, 131, 130, 129, 126, 121, 120, 119, 117,
+ 116, 115, 113, 112, 111, 110, 109, 108, 106, 103,
+ 102, 101, 100, 99, 98, 96, 95, 94, 93, 92,
+ 91, 90, 89, 88, 87, 86, 85, 81, 80, 76,
+ 61, 50, 49, 48, 47, 45, 42, 41, 40, 38,
+
+ 37, 35, 32, 28, 27, 26, 25, 23, 20, 15,
+ 14, 11, 7, 3, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993, 993, 993,
+ 993, 993, 993, 993, 993, 993, 993, 993
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+static char *yytext;
+#define INITIAL 0
+#include <string.h>
+#include "nodes.h"
+
+#ifdef _WIN32
+#define fileno _fileno
+#define isatty _isatty
+#endif
+
+extern "C" {
+#include "grammar.h"
+static int yywrap();
+}
+
+#ifdef TOKEN_DEBUG
+#define token_debug printf
+#else
+static int token_debug(const char *format, ...);
+#endif
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_NO_UNPUT
+//static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if !(defined __STDC__ && __STDC__)
+/* Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+#include "lexer.hxx"
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { fwrite( yytext, yyleng, 1, yyout ); } while (false)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = static_cast<char>(c); \
+ if ( c == '\n' ) \
+ buf[n++] = static_cast<char>(c); \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+ && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+ {
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+
+ if ( yy_init )
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yy_start )
+ yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! yy_current_buffer )
+ yy_current_buffer =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_load_buffer_state();
+ }
+
+ while ( true ) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+yy_match:
+ do
+ {
+ YY_CHAR yy_c = sal::static_int_cast<YY_CHAR>(yy_ec[YY_SC_TO_UI(*yy_cp)]);
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = static_cast<int>(yy_def[yy_current_state]);
+ if ( yy_current_state >= 994 )
+ yy_c = sal::static_int_cast<YY_CHAR>(yy_meta[static_cast<unsigned int>(yy_c)]);
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + static_cast<unsigned int>(yy_c)];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 1315 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+
+do_action: /* This label is used only to access EOF actions. */
+
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Begin[%s]\n",yytext+1); return EQBEGIN; }
+ //YY_BREAK
+case 2:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>End[%s]\n",yytext+1); return EQEND; }
+ //YY_BREAK
+case 3:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Left[%s]\n",yytext+1); return EQLEFT; }
+ //YY_BREAK
+case 4:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>LeftDelim[%s]\n",yytext+1); return LEFT_DELIM; }
+ //YY_BREAK
+case 5:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>RightDelim[%s]\n",yytext+1); return RIGHT_DELIM; }
+ //YY_BREAK
+case 6:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Right[%s]\n",yytext+1); return EQRIGHT; }
+ //YY_BREAK
+case 7:
+YY_RULE_SETUP
+{ yylval.str = yytext; token_debug(" ==>NewLine[%s]\n",yytext); return NEWLINE; }
+ //YY_BREAK
+case 8:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Accent[%s]\n",yytext+1); return ACCENT; }
+ //YY_BREAK
+case 9:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Small_Greek[%s]\n",yytext+1); return SMALL_GREEK; }
+ //YY_BREAK
+case 10:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Capital_Greek[%s]\n",yytext+1); return CAPITAL_GREEK; }
+ //YY_BREAK
+case 11:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Binary_Operator[%s]\n",yytext+1); return BINARY_OPERATOR; }
+ //YY_BREAK
+case 12:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Relation_Symbol[%s]\n",yytext+1); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 13:
+YY_RULE_SETUP
+{ yylval.str = "neq"; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 14:
+YY_RULE_SETUP
+{ yylval.str = "vmlt"; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 15:
+YY_RULE_SETUP
+{ yylval.str = "vmgt"; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 16:
+YY_RULE_SETUP
+{ yylval.str = "mlt"; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 17:
+YY_RULE_SETUP
+{ yylval.str = "mgt"; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 18:
+YY_RULE_SETUP
+{ yylval.str = yytext; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; }
+ //YY_BREAK
+case 19:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Arrow[%s]\n",yytext+1); return ARROW; }
+ //YY_BREAK
+case 20:
+YY_RULE_SETUP
+{ yylval.str = "leftrightarrow"; token_debug(" ==>Arrow[leftrightarrow]\n"); return ARROW; }
+ //YY_BREAK
+case 21:
+YY_RULE_SETUP
+{ yylval.str = "rightarrow"; token_debug(" ==>Arrow[rightarrow]\n"); return ARROW; }
+ //YY_BREAK
+case 22:
+YY_RULE_SETUP
+{ yylval.str = "leftarrow"; token_debug(" ==>Arrow[leftarrow]\n"); return ARROW; }
+ //YY_BREAK
+
+case 23:
+YY_RULE_SETUP
+{ token_debug(" ==>Ignore[\\rm]\n"); }
+ //YY_BREAK
+[[fallthrough]];
+case 24:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>General_Iden[%s]\n",yytext+1); return GENERAL_IDEN; }
+ //YY_BREAK
+case 25:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>General_Oper[%s]\n",yytext+1); return GENERAL_OPER; }
+ //YY_BREAK
+case 26:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Big_Symbol[%s]\n",yytext+1); return BIG_SYMBOL; }
+ //YY_BREAK
+case 27:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Function[%s]\n",yytext+1); return FUNCTION; }
+ //YY_BREAK
+case 28:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Root[%s]\n",yytext+1); return ROOT; }
+ //YY_BREAK
+case 29:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Fraction[%s]\n",yytext+1); return FRACTION; }
+ //YY_BREAK
+case 30:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Over[%s]\n",yytext+1); return EQOVER; }
+ //YY_BREAK
+case 31:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Delimeter[%s]\n",yytext+1); return DELIMETER; }
+ //YY_BREAK
+case 32:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Large_Delim[%s]\n",yytext+1); return LARGE_DELIM; }
+ //YY_BREAK
+case 33:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Decoration[%s]\n",yytext+1); return DECORATION; }
+ //YY_BREAK
+case 34:
+YY_RULE_SETUP
+{ yylval.str = yytext+1; token_debug(" ==>Space_Symbol[%s]\n",yytext+1); /*return SPACE_SYMBOL;*/ }
+ //YY_BREAK
+[[fallthrough]];
+case 35:
+YY_RULE_SETUP
+{ yylval.str = "quad"; token_debug(" ==>Space_Symbol[quad]\n"); /* return SPACE_SYMBOL;*/ }
+ //YY_BREAK
+[[fallthrough]];
+case 36:
+YY_RULE_SETUP
+{ yylval.dval = yytext; token_debug(" ==>Digit[%s]\n",yytext); return DIGIT; }
+ //YY_BREAK
+case 37:
+YY_RULE_SETUP
+{ yylval.str = yytext; token_debug(" ==>Operator[%s]\n",yytext); return OPERATOR; }
+ //YY_BREAK
+case 38:
+YY_RULE_SETUP
+{ token_debug(" ==>SubSup[%s]\n",yytext); return yytext[0]; }
+ //YY_BREAK
+case 39:
+YY_RULE_SETUP
+{ token_debug(" ==>Paren[%s]\n",yytext); return yytext[0];}
+ //YY_BREAK
+case 40:
+YY_RULE_SETUP
+{ token_debug(" ==>Abs[%s]\n",yytext); return yytext[0];}
+ //YY_BREAK
+case 41:
+YY_RULE_SETUP
+{ token_debug(" ==>Space[0x%2x]\n",yytext[0]); }
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+{ token_debug(" ==>Ignore[0x%2x]\n",yytext[0]); }
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+{ yylval.str = yytext; token_debug(" ==>String[%s]\n",yytext); return STRING; }
+ //YY_BREAK
+case 44:
+YY_RULE_SETUP
+{ yylval.str = yytext; token_debug(" ==>Else[%s]\n",yytext); return CHARACTER; }
+ //YY_BREAK
+case 45:
+YY_RULE_SETUP
+ECHO;
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = static_cast<int>(yy_cp - yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between yy_current_buffer and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer() )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if ( yywrap() )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ }
+ break;
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+ break;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ break;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+ {
+ char *dest = yy_current_buffer->yy_ch_buf;
+ char *source = yytext_ptr;
+ int number_to_move, i;
+ int ret_val;
+
+ if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( yy_current_buffer->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = static_cast<int>(yy_c_buf_p - yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset =
+ static_cast<int>(yy_c_buf_p - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = static_cast<char *>(
+ /* Include room in for 2 EOB chars. */
+ yy_flex_realloc( static_cast<void *>(b->yy_ch_buf),
+ b->yy_buf_size + 2 ));
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = nullptr;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read );
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if ( yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+ }
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+ {
+ yy_state_type yy_current_state;
+ char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+ {
+ YY_CHAR yy_c = sal::static_int_cast<YY_CHAR>(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = static_cast<int>(yy_def[yy_current_state]);
+ if ( yy_current_state >= 994 )
+ yy_c = sal::static_int_cast<YY_CHAR>(yy_meta[static_cast<unsigned int>(yy_c)]);
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + static_cast<unsigned int>(yy_c)];
+ }
+
+ return yy_current_state;
+ }
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+ {
+ bool yy_is_jam;
+ char *yy_cp = yy_c_buf_p;
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = static_cast<int>(yy_def[yy_current_state]);
+ if ( yy_current_state >= 994 )
+ yy_c = sal::static_int_cast<YY_CHAR>(yy_meta[static_cast<unsigned int>(yy_c)]);
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + static_cast<unsigned int>(yy_c)];
+ yy_is_jam = (yy_current_state == 993);
+
+ return yy_is_jam ? 0 : yy_current_state;
+ }
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+ {
+ if ( ! yy_current_buffer )
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_init_buffer( yy_current_buffer, input_file );
+ yy_load_buffer_state();
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+ {
+ if ( yy_current_buffer == new_buffer )
+ return;
+
+ if ( yy_current_buffer )
+ {
+ /* Flush out information for old buffer. */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state()
+#else
+void yy_load_buffer_state()
+#endif
+ {
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+ }
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ b = static_cast<YY_BUFFER_STATE>(yy_flex_alloc( sizeof( struct yy_buffer_state ) ));
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = static_cast<char *>(yy_flex_alloc( b->yy_buf_size + 2 ));
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+ {
+ if ( ! b )
+ return;
+
+ if ( b == yy_current_buffer )
+ yy_current_buffer = nullptr;
+
+ if ( b->yy_is_our_buffer )
+ yy_flex_free( static_cast<void *>(b->yy_ch_buf) );
+
+ yy_flex_free( static_cast<void *>(b) );
+ }
+
+
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO(( int ));
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+ {
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = true;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = false;
+#else
+ b->yy_is_interactive = file && isatty( fileno(file) ) > 0;
+#endif
+#endif
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+ {
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == yy_current_buffer )
+ yy_load_buffer_state();
+ }
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return nullptr;
+
+ b = static_cast<YY_BUFFER_STATE>(yy_flex_alloc( sizeof( struct yy_buffer_state ) ));
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = nullptr;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = false;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer( b );
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+ {
+ int len;
+ for ( len = 0; yy_str[len]; ++len )
+ ;
+
+ return yy_scan_bytes( yy_str, len );
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+ {
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = len + 2;
+ buf = static_cast<char *>(yy_flex_alloc( n ));
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < len; ++i )
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer( buf, n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+ {
+ if ( yy_start_stack_ptr >= yy_start_stack_depth )
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof( int );
+
+ if ( ! yy_start_stack )
+ yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size );
+
+ if ( ! yy_start_stack )
+ YY_FATAL_ERROR(
+ "out of memory expanding start-condition stack" );
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+ }
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+ {
+ if ( --yy_start_stack_ptr < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+ }
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+ {
+ return yy_start_stack[yy_start_stack_ptr - 1];
+ }
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+ {
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+ }
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+ {
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+ }
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+ {
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+ }
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+ {
+ return malloc( size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+ {
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return realloc( ptr, size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+ {
+ free( ptr );
+ }
+
+#if YY_MAIN
+int main()
+ {
+ yylex();
+ return 0;
+ }
+#endif
+
+
+void initFlex(const char *_code )
+{
+ yy_switch_to_buffer( yy_scan_string(_code) );
+}
+
+void deinitFlex()
+{
+ // flex faq-memory-leak
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+ yy_init = 1;
+}
+
+int yywrap()
+{
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ return 1;
+}
+
+#ifndef TOKEN_DEBUG
+int token_debug(const char * /*format*/, ...)
+{
+ return 0;
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/lexer.hxx b/hwpfilter/source/lexer.hxx
new file mode 100644
index 000000000..41835f13b
--- /dev/null
+++ b/hwpfilter/source/lexer.hxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+void initFlex(char const* s);
+void deinitFlex();
+
+int yylex();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/mapping.h b/hwpfilter/source/mapping.h
new file mode 100644
index 000000000..2b573cb80
--- /dev/null
+++ b/hwpfilter/source/mapping.h
@@ -0,0 +1,395 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_MAPPING_H
+#define INCLUDED_HWPFILTER_SOURCE_MAPPING_H
+
+#include <string.h>
+#include <stdio.h>
+#include <sal/macros.h>
+
+#include "hwplib.h"
+
+
+struct FormulaEntry{
+ const char *tex;
+ hchar ucs;
+};
+
+// empty square
+#define DEFAULT_VALUE 0x25a1
+const struct FormulaEntry FormulaMapTab[] = {
+/* Capital Greek */
+{"Alpha", 0x0391},
+{"Beta", 0x0392},
+{"Gamma", 0x0393},
+{"Delta", 0x0394},
+{"Epsilon", 0x0395},
+{"Zeta", 0x0396},
+{"Eta", 0x0397},
+{"Theta", 0x0398},
+{"Iota", 0x0399},
+{"Kappa", 0x039a},
+{"Lambda",0x039b },
+{"Mu", 0x039c},
+{"Nu", 0x039d},
+{"Xi", 0x039e},
+{"Omicron", 0x039f},
+{"Pi", 0x03a0},
+{"Rho", 0x03a1},
+{"Sigma", 0x03a3},
+{"Tau", 0x03a4},
+{"Upsilon", 0x03a5},
+{"Phi", 0x03a6},
+{"Chi", 0x03a7},
+{"Psi", 0x03a8},
+{"Omega", 0x03a9},
+
+/* Small Greek */
+{"alpha", 0x03b1},
+{"beta", 0x03b2},
+{"gamma", 0x03b3},
+{"delta", 0x03b4},
+{"epsilon", 0x03b5},
+{"zeta", 0x03b6},
+{"eta", 0x03b7},
+{"theta", 0x03b8},
+{"iota", 0x03b9},
+{"kappa", 0x03ba},
+{"lambda",0x03bb },
+{"mu", 0x03bc},
+{"nu", 0x03bd},
+{"xi", 0x03be},
+{"omicron", 0x03bf},
+{"pi", 0x03c0},
+{"rho", 0x03c1},
+{"varrho", 0},
+{"sigma", 0x03c3},
+{"tau", 0x03c4},
+{"upsilon", 0x03c5},
+{"phi", 0x03d5},
+{"chi", 0x03c7},
+{"psi", 0x03c8},
+{"omega", 0x03c9},
+
+/* General Symbol */
+{"aleph", 0x2135},
+{"hbar", 0x045b},
+{"imath", 0x2129},
+{"jmath", 0x2110},
+{"mho", 0x2127},
+{"ell", 0x2113},
+{"wp", 0x2118},
+{"imag", 0x2111},
+{"angstrom", 0x212b},
+{"vartheta", 0x03d1},
+{"varpi", 0x03d6},
+{"varsigma", 0x04aa},
+{"varupsilon", 0x03d2},
+{"varphi", 0x03c6},
+
+
+// Big Symbol
+{"sum", 0x2211},
+{"smallsum", 0x03a3},
+{"prod", 0x220f},
+{"amalg", 0x2210},
+{"int", 0x222b},
+{"oint", 0x222e},
+{"cap", 0x22c2},
+{"cup", 0x22c3},
+{"uplus", 0x2282},
+{"vee", 0x22c1},
+{"wedge", 0x22c0},
+{"bigcap", 0x22c2},
+{"bigcup", 0x22c3},
+{"bigsqcap", 0x2293},
+{"bigsqcup", 0x2294},
+{"bigoplus", 0x2295},
+{"bigominus", 0x2296},
+{"bigotimes", 0x2297},
+{"bigodiv", 0x2298},
+{"bigodot", 0x2299},
+{"oplus", 0x2295},
+{"ominus", 0x2296},
+{"otimes", 0x2297},
+{"oslash", 0x2298},
+{"odot", 0x2299},
+{"bigvee", 0x22c1},
+{"bigwedge", 0x22c0},
+{"subset", 0x2282},
+{"superset", 0x2283},
+{"supset", 0x2283},
+{"subseteq", 0x2286},
+{"supseteq", 0x2287},
+{"in", 0x2208},
+{"ni", 0x220b},
+{"notin", 0x2209},
+{"notni", 0x220c},
+{"leq", 0x2264},
+{"geq", 0x2265},
+{"sqsubset", 0x228f},
+{"sqsupset", 0x2290},
+{"sqsubseteq", 0x2291},
+{"sqsupseteq", 0x2292},
+{"mlt", 0x2292}, // much less than
+{"mgt", 0x2292}, // much greater than
+{"vmlt", 0x22d8}, // much less than
+{"vmgt", 0x22d9}, // much greater than
+{"prec", 0x227a},
+{"succ", 0x227b},
+{"biguplus", 0x228e},
+
+// Binary Operator
+{"pm", 0x00b1},
+{"mp", 0x2213},
+{"times", 0x00d7},
+{"div", 0x00f7},
+{"circ", 0x2218},
+{"cdot", 0x2219},
+{"bullet", 0x2022},
+{"deg", 0x00b0},
+{"ast", 0x002a},
+{"star", 0x2205},
+{"bigcirc", 0x25cb},
+{"emptyset", 0x2205},
+{"therefore", 0x2234},
+{"because", 0x2235},
+{"identical", 0x2237},
+{"exists", 0x2203},
+{"noteq", 0x2260}, // !=
+{"neq", 0x2260},
+{"doteq", 0x2250},
+{"image", 0x2252},
+{"reimage", 0x2253},
+{"sim", 0x223c},
+{"approx", 0x2248},
+{"simeq", 0x2243},
+{"cong", 0x2245},
+{"equiv", 0x2261},
+{"asymp", 0x224d},
+{"iso", 0x224e},
+{"diamond", 0x22c4},
+{"dsum", 0x2214}, // add
+{"forall", 0x2200},
+{"prime", DEFAULT_VALUE}, // '
+{"partial", 0x2202},
+{"infty", 0x221e},
+{"propto", 0x221d},
+{"xor", 0x22bb},
+{"del", 0x2207},
+{"dagger", 0x2020},
+{"ddagger", 0x2021},
+{"LNOT", DEFAULT_VALUE},
+
+// Arrows
+{"leftarrow", 0x2190},
+{"uparrow", 0x2191},
+{"rightarrow", 0x2192},
+{"downarrow", 0x2193},
+{"Leftarrow", 0x21d0},
+{"Uparrow", 0x21d1},
+{"Rightarrow", 0x21d2},
+{"Downarrow", 0x21d3},
+{"updownarrow", 0x2195},
+{"Updownarrow", 0x21d5},
+{"leftrightarrow", 0x2194},
+{"Leftrightarrow", 0x21d4},
+{"nwarrow", 0x2196},
+{"searrow", 0x2198},
+{"nearrow", 0x2197},
+{"swarrow", 0x2199},
+{"hookleft", 0x21a9},
+{"hookleftarrow", 0x21a9},
+{"hookright", 0x21aa},
+{"hookrightarrow", 0x21aa},
+{"mapsto", 0x21a6},
+{"vert", 0x2223},
+{"dline", 0x2225},
+
+{"cdots", 0x22ef},
+{"ldots", 0x2026},
+{"vdots", 0x22ee},
+{"ddots", 0x22f1},
+{"triangle", 0x2206},
+{"triangled", 0x2207},
+{"angle", 0x2220},
+{"msangle", 0x2221},
+{"sangle", 0x2222},
+{"rtangle", 0x22be},
+{"vdash", 0x22a2},
+{"dashv", 0x22a3},
+{"bot", 0x22a5},
+{"top", 0x22a4},
+{"models", 0x22a8},
+
+{"coprod", DEFAULT_VALUE},
+{"varepsilon", DEFAULT_VALUE},
+{"setminus", DEFAULT_VALUE},
+{"sqcap", DEFAULT_VALUE},
+{"sqcup", DEFAULT_VALUE},
+{"wr", DEFAULT_VALUE},
+{"bigtriangleup", DEFAULT_VALUE},
+{"bigtriangledown", DEFAULT_VALUE},
+{"triangleleft", DEFAULT_VALUE},
+{"triangleright", DEFAULT_VALUE},
+{"lhd", DEFAULT_VALUE},
+{"rhd", DEFAULT_VALUE},
+{"unlhd", DEFAULT_VALUE},
+{"unrhd", DEFAULT_VALUE},
+{"nabla", DEFAULT_VALUE},
+{"surd", DEFAULT_VALUE},
+{"Box", DEFAULT_VALUE},
+{"Diamond", DEFAULT_VALUE},
+{"neg", DEFAULT_VALUE},
+{"flat", DEFAULT_VALUE},
+{"natural", DEFAULT_VALUE},
+{"sharp", DEFAULT_VALUE},
+{"clubsuit", DEFAULT_VALUE},
+{"diamondsuit", DEFAULT_VALUE},
+{"heartsuit", DEFAULT_VALUE},
+{"spadesuit", DEFAULT_VALUE},
+{"Re", DEFAULT_VALUE},
+{"Im", DEFAULT_VALUE},
+{"S", DEFAULT_VALUE},
+{"P", DEFAULT_VALUE},
+{"smallint", DEFAULT_VALUE},
+{"backslash", DEFAULT_VALUE},
+
+// Relation Operator
+{"le", DEFAULT_VALUE},
+{"ge", DEFAULT_VALUE},
+{"perp", DEFAULT_VALUE},
+{"preceq", DEFAULT_VALUE},
+{"succeq", DEFAULT_VALUE},
+{"mid", DEFAULT_VALUE},
+{"ll", DEFAULT_VALUE},
+{"gg", DEFAULT_VALUE},
+{"parallel", DEFAULT_VALUE},
+{"bowtie", DEFAULT_VALUE},
+{"Join", DEFAULT_VALUE},
+{"smile", DEFAULT_VALUE},
+{"frown", DEFAULT_VALUE},
+{"not", DEFAULT_VALUE},
+{"mapsto", DEFAULT_VALUE},
+
+// Arrows
+{"to", DEFAULT_VALUE},
+
+{"leftharpoonup", DEFAULT_VALUE},
+{"leftharpoondown", DEFAULT_VALUE},
+{"longleftarrow", DEFAULT_VALUE},
+{"Longleftarrow", DEFAULT_VALUE},
+{"longrightarrow", DEFAULT_VALUE},
+{"Longrightarrow", DEFAULT_VALUE},
+{"longleftrightarrow", DEFAULT_VALUE},
+{"Longleftrightarrow", DEFAULT_VALUE},
+{"longmapsto", DEFAULT_VALUE},
+{"rightharpoonup", DEFAULT_VALUE},
+{"rightharpoondown", DEFAULT_VALUE},
+
+// Delimeter
+{"(", DEFAULT_VALUE},
+{")", DEFAULT_VALUE},
+{"[", DEFAULT_VALUE},
+{"]", DEFAULT_VALUE},
+{"{", DEFAULT_VALUE},
+{"}", DEFAULT_VALUE},
+{"lfloor", DEFAULT_VALUE},
+{"rfloor", DEFAULT_VALUE},
+{"lceil", DEFAULT_VALUE},
+{"rceil", DEFAULT_VALUE},
+{"langle", DEFAULT_VALUE},
+{"rangle", DEFAULT_VALUE},
+{"mid", DEFAULT_VALUE},
+
+// Large Delimeter
+{"rmoustache", DEFAULT_VALUE},
+{"lmoustache", DEFAULT_VALUE},
+{"rgroup", DEFAULT_VALUE},
+{"lgroup", DEFAULT_VALUE},
+{"arrowvert", DEFAULT_VALUE},
+{"Arrowvert", DEFAULT_VALUE},
+{"bracevert", DEFAULT_VALUE},
+
+// Accent
+{"hat", DEFAULT_VALUE},
+{"breve", DEFAULT_VALUE},
+{"grave", DEFAULT_VALUE},
+{"bar", DEFAULT_VALUE},
+{"ddot", DEFAULT_VALUE},
+{"check", DEFAULT_VALUE},
+{"acute", DEFAULT_VALUE},
+{"tilde", DEFAULT_VALUE},
+{"dot", DEFAULT_VALUE},
+{"vec", DEFAULT_VALUE},
+
+// Decoration
+{"overline", DEFAULT_VALUE},
+{"underline", DEFAULT_VALUE},
+{"overbrace", DEFAULT_VALUE},
+{"underbrace", DEFAULT_VALUE},
+{"widehat", DEFAULT_VALUE},
+{"widetilde", DEFAULT_VALUE},
+{"overleftarrow", DEFAULT_VALUE},
+{"overrightarrow", DEFAULT_VALUE},
+
+// Space Symbol
+{",", DEFAULT_VALUE},
+{":", DEFAULT_VALUE},
+{";", DEFAULT_VALUE},
+{"!", DEFAULT_VALUE},
+{"quad", DEFAULT_VALUE},
+{"qquad", DEFAULT_VALUE}, // double size of character
+
+};
+
+#ifndef DEBUG
+hchar_string getMathMLEntity(const char *tex)
+{
+ static const size_t tabSize = SAL_N_ELEMENTS(FormulaMapTab);
+
+ hchar_string buf;
+ for (size_t i = 0 ; i < tabSize ; i++) {
+ if( !strcmp(tex, FormulaMapTab[i].tex ) ) {
+ buf.push_back(FormulaMapTab[i].ucs);
+ return buf;
+ }
+ }
+
+ size_t const len = strlen(tex);
+ for (size_t i = 0 ; i < len ; i++)
+ {
+ buf.push_back(tex[i]);
+ }
+ return buf;
+}
+
+#else
+::std::string getMathMLEntity(const char *tex)
+{
+ ::std::string buf;
+ buf.append(tex);
+ return buf;
+}
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/mzstring.cxx b/hwpfilter/source/mzstring.cxx
new file mode 100644
index 000000000..462ed91ad
--- /dev/null
+++ b/hwpfilter/source/mzstring.cxx
@@ -0,0 +1,268 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/* PURPOSE
+ * supposed to be used instead of std::string
+ */
+
+#include "mzstring.h"
+
+#ifdef _WIN32
+# if !defined WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef _WIN32
+# define wsprintfA sprintf
+#endif
+
+const int AllocSize = 8;
+
+static int get_alloc_size(int len)
+{
+ return (len + AllocSize - 1) / AllocSize * AllocSize;
+}
+
+
+MzString::MzString()
+{
+ Length = 0;
+ Allocated = 0;
+ Data = nullptr;
+}
+
+
+MzString::~MzString()
+{
+ if (Data)
+ free(Data);
+}
+
+
+MzString &MzString::operator=(const MzString &s)
+{
+ if(this == &s)
+ return *this;
+
+ int n = s.length();
+ if (allocate(n))
+ {
+ if (n > 0) memcpy(Data, s.Data, n);
+ Length = n;
+ }
+ return *this;
+}
+
+
+MzString &MzString::operator = (const char *s)
+{
+ if (s == nullptr)
+ s = "";
+ int n = strlen(s);
+ if (allocate(n))
+ {
+ if (n > 0) memcpy(Data, s, n);
+ Length = n;
+ }
+ return *this;
+}
+
+
+void MzString::append(const char *s, int slen)
+{
+ if(!s || slen <= 0)
+ return;
+
+ int new_len = Length + slen;
+ if (allocate(new_len))
+ {
+ memcpy(Data + Length, s, slen);
+ Length = new_len;
+ }
+}
+
+
+void MzString::append(MzString const &s)
+{
+ if (s.Data)
+ append(s.Data, s.length());
+}
+
+
+void MzString::append(const char *s)
+{
+ if (!s) return;
+ append(s, strlen(s));
+}
+
+
+int MzString::compare(const char *s)
+{
+ if (!Data) return -1;
+ if (s==nullptr) return 1;
+
+ Data[Length] = 0;
+ return strcmp(Data, s);
+}
+
+
+int MzString::find(char ch)
+{
+ return find(ch,0);
+}
+
+
+int MzString::find(char ch, int pos)
+{
+ for (int i = pos; i < Length; i++)
+ {
+ if (Data[i] == ch)
+ return i;
+ }
+ return -1;
+}
+
+
+int MzString::rfind(char ch)
+{
+ return rfind(ch, Length - 1);
+}
+
+
+int MzString::rfind(char ch, int pos)
+{
+ if (pos >= Length)
+ return -1;
+
+ while (pos >= 0)
+ {
+ if (Data[pos] == ch)
+ return pos;
+ pos--;
+ }
+ return -1;
+}
+
+
+// << operator
+MzString &MzString::operator << (const char *str)
+{
+ append(str);
+ return *this;
+}
+
+
+MzString &MzString::operator << (char ch)
+{
+ append(&ch, 1);
+ return *this;
+}
+
+
+MzString &MzString::operator << (int i)
+{
+ char str[80];
+
+ wsprintfA(str, "%d", i);
+ append(str);
+ return *this;
+}
+
+
+MzString &MzString::operator << (tools::Long l)
+{
+ char str[80];
+
+ wsprintfA(str, "%ld", l);
+ append(str);
+ return *this;
+}
+
+
+MzString &MzString::operator << (MzString const &s)
+{
+ append(s);
+ return *this;
+}
+
+
+char MzString::operator [] (int n)
+{
+ if (Data && 0 <= n && n < Length)
+ return Data[n];
+
+ return 0;
+}
+
+
+void MzString::replace(int pos, char ch)
+{
+ if (Data && 0 <= pos && pos < Length)
+ Data[pos] = ch;
+}
+
+
+// Private Methods.
+
+
+bool MzString::allocate(int len)
+{
+ len++; // In case we want to add a null.
+
+ if (len < 0)
+ return false;
+
+ if (Data)
+ {
+ if (len < Allocated)
+ return true;
+ else
+ {
+ int n = get_alloc_size(len);
+ char *p = static_cast<char *>(realloc(Data, n));
+ if (p)
+ {
+ Data = p;
+ Allocated = n;
+ return true;
+ }
+ }
+ }
+ else
+ {
+// In case we want to add a null.
+ int n = get_alloc_size(len);
+ Data = static_cast<char *>(malloc(n));
+ if (Data)
+ {
+ Allocated = n;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/mzstring.h b/hwpfilter/source/mzstring.h
new file mode 100644
index 000000000..475ab31e2
--- /dev/null
+++ b/hwpfilter/source/mzstring.h
@@ -0,0 +1,167 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
+#define INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <tools/long.hxx>
+
+/** @name MzString class
+
+ It was supposed to be used instead of std::string.
+
+ Notes for usage:
+
+ When you declare an MzString, it is initially empty. There is no need to
+ do things like #MzString a = "";#, especially not in constructors.
+
+ If you want to use a default empty MzString as a parameter, use
+
+#void foo(MzString par = MzString()); // Correct#
+
+rather than
+
+#void foo(MzString par = ""); // WRONG!#
+#void foo(MzString par = 0); // WRONG!#
+
+(The last one is only wrong because some compilers can't handle it.)
+
+Methods that take an index as parameter all follow this rule: Valid indexes
+go from 0 to length()-1.
+\begin{tabular}{rl}
+Correct: & #foo.substr(0, length()-1);# \\
+Wrong: & #bar.substr(0, length());#
+\end{tabular}
+
+It is important that you declare MzStrings as const if possible, because
+some methods are much more efficient in const versions.
+
+If you want to check whether a string is empty, do
+
+#if (foo.empty()) something right#
+
+rather than something along the lines of
+
+#if (!foo) completely wrong#
+
+When you use the #.copy()# method, MzString calls "#new []#", so you have to
+release the memory with #delete[]#. Don't preallocate memory.
+
+When you want to copy an MzString, just do
+
+#MzString a, b = "String";#
+#a = b; // That's it!#
+
+not something like
+
+#MzString a, b = "String";#
+#a = b.copy();#
+
+The class automatically handles deep copying when required.
+*/
+
+class MzString
+{
+ public:
+ MzString(); // Create an empty string
+ ~MzString();
+
+ int length() const;
+ const char* c_str() const;
+ operator char*() { return const_cast<char *>(c_str()); }
+
+// Assignment
+ MzString &operator = (const MzString &s);
+ MzString &operator = (const char *s);
+
+// Appending
+
+ MzString &operator << (const char *);
+ MzString &operator << (char);
+ MzString &operator << (unsigned char c) { return *this<<static_cast<char>(c); }
+ MzString &operator << (int);
+ MzString &operator << (tools::Long);
+ MzString &operator << (short i) { return *this<<static_cast<int>(i); }
+ MzString &operator << (MzString const &);
+/* MzString &operator << (MzString *s) { return *this<<*s; }
+
+ // Removing
+ char operator >> (char &c);
+*/
+// Access to specific characters
+//char &operator [] (int n);
+ char operator [] (int n);
+
+// Comparison
+// Return:
+// 0 : 'this' is equal to 's'.
+// -1 : 'this' is less than 's'.
+// 1 : 'this' is greater than 's'.
+ int compare(const char *s);
+
+// Searching for parts
+ int find (char c);
+ int find (char c, int pos);
+ int rfind (char c);
+ int rfind (char c, int pos);
+
+// Manipulation
+ void replace(int, char c);
+
+ void append (MzString const &s);
+ void append (const char *s);
+ void append (const char *s, int n);
+
+ private:
+ int Length; // Current Length
+ int Allocated; // Total space allocated
+ char *Data; // The actual contents
+
+// Allocate some space for the data.
+// Delete Data if it has been allocated.
+ bool allocate(int len);
+};
+
+inline int MzString::length() const
+{
+ return Length;
+}
+
+
+inline const char* MzString::c_str() const
+{
+ if (Data)
+ {
+ Data[Length] = '\0'; // We always leave room for this.
+ return Data;
+ }
+ else
+ return "";
+}
+
+
+
+// Non friend, non member operators
+
+#endif // INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/nodes.h b/hwpfilter/source/nodes.h
new file mode 100644
index 000000000..dce473e13
--- /dev/null
+++ b/hwpfilter/source/nodes.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_NODES_H
+#define INCLUDED_HWPFILTER_SOURCE_NODES_H
+
+#include <sal/config.h>
+
+#include <memory>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <o3tl/deleter.hxx>
+#include <osl/diagnose.h>
+
+enum IDLIST {
+ ID_MATHML,
+ ID_LINES,
+ ID_LINE,
+ ID_EXPRLIST,
+ ID_EXPR,
+ ID_BEGIN,
+ ID_END,
+ ID_LEFT,
+ ID_RIGHT,
+ ID_SUBEXPR,
+ ID_SUPEXPR,
+ ID_SUBSUPEXPR,
+ ID_FRACTIONEXPR,
+ ID_OVER,
+ ID_DECORATIONEXPR,
+ ID_SQRTEXPR,
+ ID_ROOTEXPR,
+ ID_ARROWEXPR,
+ ID_ACCENTEXPR,
+ ID_UNARYEXPR,
+ ID_PRIMARYEXPR,
+ ID_BRACKET,
+ ID_BLOCK,
+ ID_PARENTH,
+ ID_FENCE,
+ ID_ABS,
+ ID_IDENTIFIER,
+ ID_STRING,
+ ID_CHARACTER,
+ ID_NUMBER,
+ ID_OPERATOR,
+ ID_SPACE,
+ ID_DELIMITER
+};
+
+class Node{
+public:
+ explicit Node(int _id) : id(_id)
+ {
+ child = nullptr;
+ next = nullptr;
+#ifdef NODE_DEBUG
+ count++;
+ printf("Node count : [%d]\n",count);
+#endif
+ }
+ ~Node()
+ {
+ next = nullptr;
+ child = nullptr;
+#ifdef NODE_DEBUG
+ count--;
+ printf("Node count : [%d]\n",count);
+#endif
+ }
+public:
+ static int count; /* For memory debugging */
+ int id;
+ std::unique_ptr<char, o3tl::free_delete> value;
+ Node *child;
+ Node *next;
+};
+extern std::vector<std::unique_ptr<Node>> nodelist;
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/precompile.h b/hwpfilter/source/precompile.h
new file mode 100644
index 000000000..1c348f6b9
--- /dev/null
+++ b/hwpfilter/source/precompile.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <crtdbg.h>
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/solver.cxx b/hwpfilter/source/solver.cxx
new file mode 100644
index 000000000..7e2788f7f
--- /dev/null
+++ b/hwpfilter/source/solver.cxx
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <math.h>
+#include <memory>
+#include "solver.h"
+
+
+std::unique_ptr<std::unique_ptr<double[]>[]> mgcLinearSystemD::NewMatrix (int N)
+{
+ std::unique_ptr<std::unique_ptr<double[]>[]> A(new std::unique_ptr<double[]>);
+
+ for (int row = 0; row < N; row++)
+ {
+ A[row].reset(new double[N]);
+ for (int col = 0; col < N; col++)
+ A[row][col] = 0;
+ }
+ return A;
+}
+
+std::unique_ptr<double[]> mgcLinearSystemD::NewVector (int N)
+{
+ std::unique_ptr<double[]> B(new double[N]);
+
+ for (int row = 0; row < N; row++)
+ B[row] = 0;
+ return B;
+}
+
+bool mgcLinearSystemD::Solve (int n, std::unique_ptr<std::unique_ptr<double[]>[]> const & a, double* b)
+{
+ std::unique_ptr<int[]> indxc( new int[n] );
+ if ( !indxc )
+ return false;
+ std::unique_ptr<int[]> indxr( new int[n] );
+ if ( !indxr ) {
+ return false;
+ }
+ std::unique_ptr<int[]> ipiv( new int[n] );
+ if ( !ipiv ) {
+ return false;
+ }
+
+ int i, j, k;
+ int irow = 0;
+ int icol = 0;
+ double save;
+
+ for (j = 0; j < n; j++)
+ ipiv[j] = 0;
+
+ for (i = 0; i < n; i++)
+ {
+ double big = 0;
+ for (j = 0; j < n; j++)
+ {
+ if ( ipiv[j] != 1 )
+ {
+ for (k = 0; k < n; k++)
+ {
+ if ( ipiv[k] == 0 )
+ {
+ if ( fabs(a[j][k]) >= big )
+ {
+ big = fabs(a[j][k]);
+ irow = j;
+ icol = k;
+ }
+ }
+ else if ( ipiv[k] > 1 )
+ {
+ return false;
+ }
+ }
+ }
+ }
+ ipiv[icol]++;
+
+ if ( irow != icol )
+ {
+ std::swap(a[irow], a[icol]);
+
+ save = b[irow];
+ b[irow] = b[icol];
+ b[icol] = save;
+ }
+
+ indxr[i] = irow;
+ indxc[i] = icol;
+ if ( a[icol][icol] == 0 )
+ {
+ return false;
+ }
+
+ double pivinv = 1/a[icol][icol];
+ a[icol][icol] = 1;
+ for (k = 0; k < n; k++)
+ a[icol][k] *= pivinv;
+ b[icol] *= pivinv;
+
+ for (j = 0; j < n; j++)
+ {
+ if ( j != icol )
+ {
+ save = a[j][icol];
+ a[j][icol] = 0;
+ for (k = 0; k < n; k++)
+ a[j][k] -= a[icol][k]*save;
+ b[j] -= b[icol]*save;
+ }
+ }
+ }
+
+ for (j = n-1; j >= 0; j--)
+ {
+ if ( indxr[j] != indxc[j] )
+ {
+ for (k = 0; k < n; k++)
+ {
+ save = a[k][indxr[j]];
+ a[k][indxr[j]] = a[k][indxc[j]];
+ a[k][indxc[j]] = save;
+ }
+ }
+ }
+
+ return true;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/solver.h b/hwpfilter/source/solver.h
new file mode 100644
index 000000000..85467ff78
--- /dev/null
+++ b/hwpfilter/source/solver.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_HWPFILTER_SOURCE_SOLVER_H
+#define INCLUDED_HWPFILTER_SOURCE_SOLVER_H
+
+class mgcLinearSystemD
+{
+public:
+ static std::unique_ptr<std::unique_ptr<double[]>[]> NewMatrix(int N);
+ static std::unique_ptr<double[]> NewVector(int N);
+
+ static bool Solve(int N, std::unique_ptr<std::unique_ptr<double[]>[]> const& A, double* b);
+ // Input:
+ // A[N][N] coefficient matrix, entries are A[row][col]
+ // b[N] vector, entries are b[row]
+ // Output:
+ // return value is TRUE if successful, FALSE if pivoting failed
+ // A[N][N] is inverse matrix
+ // b[N] is solution x to Ax = b
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */