LibreOffice Module sw (master)  1
xmlfonte.cxx
Go to the documentation of this file.
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>
22 #include <editeng/fontitem.hxx>
23 #include <doc.hxx>
24 #include "xmlexp.hxx"
25 #include "xmlimp.hxx"
27 
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::text;
31 
32 namespace {
33 
34 class SwXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
35 {
36 public:
37  SwXMLFontAutoStylePool_Impl(SwXMLExport& rExport, bool bFontEmbedding);
38 };
39 
40 }
41 
42 SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(SwXMLExport& _rExport, bool bFontEmbedding)
43  : XMLFontAutoStylePool(_rExport, bFontEmbedding)
44 {
45  sal_uInt16 const aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
47 
48  const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
49  for(sal_uInt16 nWhichId : aWhichIds)
50  {
51  const SvxFontItem& rFont =
52  static_cast<const SvxFontItem&>(rPool.GetDefaultItem( nWhichId ));
53  Add( rFont.GetFamilyName(), rFont.GetStyleName(),
54  rFont.GetFamily(), rFont.GetPitch(),
55  rFont.GetCharSet() );
56  for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhichId))
57  {
58  auto pFont = static_cast<const SvxFontItem *>(pItem);
59  Add( pFont->GetFamilyName(), pFont->GetStyleName(),
60  pFont->GetFamily(), pFont->GetPitch(),
61  pFont->GetCharSet() );
62  }
63  }
64  auto const & pDocument = _rExport.getDoc();
65 
66  m_bEmbedUsedOnly = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_USED_FONTS);
67  m_bEmbedLatinScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_LATIN_SCRIPT_FONTS);
68  m_bEmbedAsianScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_ASIAN_SCRIPT_FONTS);
69  m_bEmbedComplexScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_COMPLEX_SCRIPT_FONTS);
70 
71 }
72 
74 {
75  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  if( !( getExportFlags() & SvXMLExportFlags::CONTENT) )
81  blockFontEmbedding = true;
82  if( !getDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
83  blockFontEmbedding = true;
84  return new SwXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
85 }
86 
88 {
90 }
91 
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwDoc * getDoc() const
Definition: xmlimp.cxx:1762
#define RES_CHRATR_FONT
Definition: hintids.hxx:76
#define RES_CHRATR_CJK_FONT
Definition: hintids.hxx:91
FontPitch GetPitch() const
FontFamily GetFamily() const
virtual void set(DocumentSettingId id, bool value)=0
Set the specified document setting.
rtl_TextEncoding GetCharSet() const
const OUString & GetStyleName() const
#define RES_CHRATR_CTL_FONT
Definition: hintids.hxx:96
const SwDoc * getDoc() const
Definition: xmlexp.cxx:512
virtual void NotifyEmbeddedFontRead() override
Definition: xmlfonte.cxx:87
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
const OUString & GetFamilyName() const
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:175
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
SvXMLExportFlags getExportFlags() const
virtual XMLFontAutoStylePool * CreateFontAutoStylePool() override
Definition: xmlfonte.cxx:73
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1313