Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLTextShapeImportHelper.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <com/sun/star/text/XTextContent.hpp>
21
#include <com/sun/star/text/TextContentAnchorType.hpp>
22
#include <comphelper/configuration.hxx>
23
24
#include <sax/tools/converter.hxx>
25
26
#include <xmloff/xmlimp.hxx>
27
#include <xmloff/txtimp.hxx>
28
#include <xmloff/xmluconv.hxx>
29
#include <xmloff/xmlnamespace.hxx>
30
#include "XMLAnchorTypePropHdl.hxx"
31
#include <com/sun/star/beans/XPropertySet.hpp>
32
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
33
#include <com/sun/star/drawing/XShapes.hpp>
34
#include <com/sun/star/frame/XModel.hpp>
35
#include <xmloff/XMLTextShapeImportHelper.hxx>
36
37
38
using namespace ::com::sun::star::uno;
39
using namespace ::com::sun::star::drawing;
40
using namespace ::com::sun::star::beans;
41
using namespace ::com::sun::star::text;
42
using namespace ::com::sun::star::container;
43
using namespace ::com::sun::star::xml::sax;
44
using namespace ::xmloff::token;
45
46
constexpr OUStringLiteral gsAnchorType(u"AnchorType");
47
constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
48
constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition");
49
50
XMLTextShapeImportHelper::XMLTextShapeImportHelper(
51
        SvXMLImport& rImp ) :
52
11.2k
    XMLShapeImportHelper( rImp, rImp.GetModel(),
53
11.2k
                          XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
54
11.2k
    m_rImport( rImp )
55
11.2k
{
56
11.2k
    Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
57
11.2k
    if( xDPS.is() )
58
11.2k
    {
59
11.2k
        Reference < XShapes > xShapes = xDPS->getDrawPage();
60
11.2k
        pushGroupForPostProcessing( xShapes );
61
11.2k
    }
62
63
11.2k
}
64
65
XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
66
11.2k
{
67
11.2k
    popGroupAndPostProcess();
68
11.2k
}
69
70
void XMLTextShapeImportHelper::addShape(
71
    Reference< XShape >& rShape,
72
    const Reference< XFastAttributeList >& xAttrList,
73
    Reference< XShapes >& rShapes )
74
6.83k
{
75
6.83k
    if( rShapes.is() )
76
0
    {
77
        // It's a group shape or 3DScene , so we have to call the base class method.
78
0
        XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
79
0
        return;
80
0
    }
81
82
6.83k
    TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
83
6.83k
    sal_Int16   nPage = 0;
84
6.83k
    sal_Int32   nY = 0;
85
86
6.83k
    rtl::Reference < XMLTextImportHelper > xTxtImport =
87
6.83k
        m_rImport.GetTextImport();
88
89
6.83k
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
90
22.2k
    {
91
22.2k
        switch( aIter.getToken() )
92
22.2k
        {
93
4.01k
        case XML_ELEMENT(TEXT, XML_ANCHOR_TYPE):
94
4.01k
            {
95
4.01k
                TextContentAnchorType eNew;
96
                // OD 2004-06-01 #i26791# - allow all anchor types
97
4.01k
                if ( XMLAnchorTypePropHdl::convert( aIter.toView(), eNew ) )
98
1.58k
                {
99
1.58k
                    eAnchorType = eNew;
100
1.58k
                }
101
4.01k
            }
102
4.01k
            break;
103
3
        case XML_ELEMENT(TEXT, XML_ANCHOR_PAGE_NUMBER):
104
3
            {
105
3
                sal_Int32 nTmp;
106
3
                sal_Int32 nMax = !comphelper::IsFuzzing() ? SHRT_MAX : 100;
107
3
                if (::sax::Converter::convertNumber(nTmp, aIter.toView(), 1, nMax))
108
3
                    nPage = static_cast<sal_Int16>(nTmp);
109
3
            }
110
3
            break;
111
0
        case XML_ELEMENT(SVG, XML_Y):
112
685
        case XML_ELEMENT(SVG_COMPAT, XML_Y):
113
685
            m_rImport.GetMM100UnitConverter().convertMeasureToCore( nY, aIter.toView() );
114
685
            break;
115
22.2k
        }
116
22.2k
    }
117
118
6.83k
    Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
119
120
    // anchor type
121
6.83k
    xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) );
122
123
    // page number must be set before the frame is inserted
124
6.83k
    switch( eAnchorType )
125
6.83k
    {
126
3
    case TextContentAnchorType_AT_PAGE:
127
        // only set positive page numbers
128
3
        if ( nPage > 0 )
129
3
        {
130
3
            xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) );
131
3
        }
132
3
        break;
133
6.83k
    default:
134
6.83k
        break;
135
6.83k
    }
136
137
6.83k
    Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
138
6.83k
    xTxtImport->InsertTextContent( xTxtCntnt );
139
140
6.83k
    switch( eAnchorType )
141
6.83k
    {
142
859
    case TextContentAnchorType_AS_CHARACTER:
143
859
        xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) );
144
859
        break;
145
4.17k
    default:
146
4.17k
        break;
147
6.83k
    }
148
6.83k
}
149
150
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */