Line data Source code
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 "hintids.hxx"
21 : #include <com/sun/star/text/XTextDocument.hpp>
22 : #include <xmloff/XMLFontAutoStylePool.hxx>
23 : #include <editeng/fontitem.hxx>
24 : #include <unotext.hxx>
25 : #include <doc.hxx>
26 : #include <xmlexp.hxx>
27 : #include <xmlimp.hxx>
28 : #include <IDocumentSettingAccess.hxx>
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::lang;
32 : using namespace ::com::sun::star::text;
33 :
34 240 : class SwXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
35 : {
36 : public:
37 : SwXMLFontAutoStylePool_Impl( SwXMLExport& rExport, bool blockFontEmbedding );
38 : };
39 :
40 120 : SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(
41 : SwXMLExport& _rExport, bool blockFontEmbedding ) :
42 120 : XMLFontAutoStylePool( _rExport, blockFontEmbedding )
43 : {
44 : sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
45 120 : RES_CHRATR_CTL_FONT };
46 :
47 120 : const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
48 : const SfxPoolItem* pItem;
49 480 : for( size_t i=0; i < SAL_N_ELEMENTS(aWhichIds); ++i )
50 : {
51 360 : const sal_uInt16 nWhichId = aWhichIds[i];
52 :
53 : const SvxFontItem& rFont =
54 360 : (const SvxFontItem&)rPool.GetDefaultItem( nWhichId );
55 360 : Add( rFont.GetFamilyName(), rFont.GetStyleName(),
56 : rFont.GetFamily(), rFont.GetPitch(),
57 720 : rFont.GetCharSet() );
58 360 : sal_uInt32 nItems = rPool.GetItemCount2( nWhichId );
59 1408 : for( sal_uInt32 j = 0; j < nItems; ++j )
60 : {
61 1048 : if( 0 != (pItem = rPool.GetItem2( nWhichId, j ) ) )
62 : {
63 : const SvxFontItem *pFont =
64 864 : (const SvxFontItem *)pItem;
65 864 : Add( pFont->GetFamilyName(), pFont->GetStyleName(),
66 : pFont->GetFamily(), pFont->GetPitch(),
67 1728 : pFont->GetCharSet() );
68 : }
69 : }
70 : }
71 120 : }
72 :
73 120 : XMLFontAutoStylePool* SwXMLExport::CreateFontAutoStylePool()
74 : {
75 120 : bool blockFontEmbedding = false;
76 : // We write font info to both content.xml and styles.xml, but they are both
77 : // written by different SwXMLExport instance, and would therefore write each
78 : // font file twice without complicated checking for duplicates, so handle
79 : // the embedding only in one of them.
80 120 : if(( getExportFlags() & EXPORT_CONTENT ) == 0 )
81 60 : blockFontEmbedding = true;
82 120 : if( !getDoc()->getIDocumentSettingAccess().get( IDocumentSettingAccess::EMBED_FONTS ))
83 120 : blockFontEmbedding = true;
84 120 : return new SwXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
85 : }
86 :
87 0 : void SwXMLImport::NotifyEmbeddedFontRead()
88 : {
89 0 : getDoc()->getIDocumentSettingAccess().set( IDocumentSettingAccess::EMBED_FONTS, true );
90 270 : }
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
93 :
|