1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <unx/freetype_glyphcache.hxx>
22 #include <unx/gendata.hxx>
24 #include <fontinstance.hxx>
26 #include <rtl/ustring.hxx>
27 #include <sal/log.hxx>
29 FreetypeManager::FreetypeManager()
35 FreetypeManager::~FreetypeManager()
40 void FreetypeManager::ClearFontCache()
42 m_aFontInfoList
.clear();
45 FreetypeManager
& FreetypeManager::get()
47 GenericUnixSalData
* const pSalData(GetGenericUnixSalData());
49 return *pSalData
->GetFreetypeManager();
52 FreetypeFontFile
* FreetypeManager::FindFontFile(const OString
& rNativeFileName
)
54 // font file already known? (e.g. for ttc, synthetic, aliased fonts)
55 const char* pFileName
= rNativeFileName
.getStr();
56 FontFileList::const_iterator it
= m_aFontFileList
.find(pFileName
);
57 if (it
!= m_aFontFileList
.end())
58 return it
->second
.get();
60 // no => create new one
61 FreetypeFontFile
* pFontFile
= new FreetypeFontFile(rNativeFileName
);
62 pFileName
= pFontFile
->maNativeFileName
.getStr();
63 m_aFontFileList
[pFileName
].reset(pFontFile
);
67 FreetypeFontInstance::FreetypeFontInstance(const PhysicalFontFace
& rPFF
, const FontSelectPattern
& rFSP
)
68 : LogicalFontInstance(rPFF
, rFSP
)
69 , mxFreetypeFont(FreetypeManager::get().CreateFont(this))
73 FreetypeFontInstance::~FreetypeFontInstance()
77 static hb_blob_t
* getFontTable(hb_face_t
* /*face*/, hb_tag_t nTableTag
, void* pUserData
)
80 LogicalFontInstance::DecodeOpenTypeTag( nTableTag
, pTagName
);
82 sal_uLong nLength
= 0;
83 FreetypeFontInstance
* pFontInstance
= static_cast<FreetypeFontInstance
*>( pUserData
);
84 FreetypeFont
& rFont
= pFontInstance
->GetFreetypeFont();
85 const char* pBuffer
= reinterpret_cast<const char*>(
86 rFont
.GetTable(pTagName
, &nLength
) );
88 hb_blob_t
* pBlob
= nullptr;
89 if (pBuffer
!= nullptr)
90 pBlob
= hb_blob_create(pBuffer
, nLength
, HB_MEMORY_MODE_READONLY
, nullptr, nullptr);
95 hb_font_t
* FreetypeFontInstance::ImplInitHbFont()
97 hb_font_t
* pRet
= InitHbFont(hb_face_create_for_tables(getFontTable
, this, nullptr));
98 assert(mxFreetypeFont
);
99 mxFreetypeFont
->SetFontVariationsOnHBFont(pRet
);
103 bool FreetypeFontInstance::ImplGetGlyphBoundRect(sal_GlyphId nId
, tools::Rectangle
& rRect
, bool bVertical
) const
105 assert(mxFreetypeFont
);
108 return mxFreetypeFont
->GetGlyphBoundRect(nId
, rRect
, bVertical
);
111 bool FreetypeFontInstance::GetGlyphOutline(sal_GlyphId nId
, basegfx::B2DPolyPolygon
& rPoly
, bool bVertical
) const
113 assert(mxFreetypeFont
);
116 return mxFreetypeFont
->GetGlyphOutline(nId
, rPoly
, bVertical
);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */