LibreOffice Module vcl (master) 1
PhysicalFontFace.hxx
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#pragma once
21
22#include <sal/config.h>
23
25#include <rtl/ref.hxx>
27#include <tools/color.hxx>
28#include <tools/long.hxx>
29#include <vcl/dllapi.h>
31#include <vcl/fontcharmap.hxx>
32
33#include <fontattributes.hxx>
34#include <fontsubset.hxx>
35
36#include <hb.h>
37#include <hb-ot.h>
38
40struct FontMatchStatus;
41namespace vcl::font
42{
43class FontSelectPattern;
44}
45
46namespace vcl
47{
48class PhysicalFontFamily;
49}
50
51namespace vcl::font
52{
53class FontSelectPattern;
54
56{
57public:
59 const OUString* mpTargetStyleName;
60};
61
63{
64public:
65 RawFontData(hb_blob_t* pBlob = nullptr)
66 : mpBlob(pBlob ? pBlob : hb_blob_get_empty())
67 {
68 }
69
70 RawFontData(const RawFontData& rOther)
71 : mpBlob(hb_blob_reference(rOther.mpBlob))
72 {
73 }
74
75 ~RawFontData() { hb_blob_destroy(mpBlob); }
76
78 {
79 hb_blob_destroy(mpBlob);
80 mpBlob = hb_blob_reference(rOther.mpBlob);
81 return *this;
82 }
83
84 size_t size() const { return hb_blob_get_length(mpBlob); }
85 bool empty() const { return size() == 0; }
86 const uint8_t* data() const
87 {
88 return reinterpret_cast<const uint8_t*>(hb_blob_get_data(mpBlob, nullptr));
89 }
90
91private:
92 hb_blob_t* mpBlob;
93};
94
96{
98 uint32_t nColorIndex;
99};
100
101typedef std::vector<Color> ColorPalette;
102
103// https://learn.microsoft.com/en-us/typography/opentype/spec/name#name-ids
104typedef enum : hb_ot_name_id_t {
120 //NAME_ID_RESERVED = 15,
131} NameID;
132
133// TODO: no more direct access to members
134// TODO: get rid of height/width for scalable fonts
135// TODO: make cloning cheaper
136
145{
146public:
148
151
152 virtual sal_IntPtr GetFontId() const = 0;
153 virtual FontCharMapRef GetFontCharMap() const;
154 virtual bool GetFontCapabilities(vcl::FontCapabilities&) const;
155
156 RawFontData GetRawFontData(uint32_t) const;
157
158 bool IsBetterMatch(const vcl::font::FontSelectPattern&, FontMatchStatus&) const;
159 sal_Int32 CompareIgnoreSize(const PhysicalFontFace&) const;
160
161 // CreateFontSubset: a method to get a subset of glyphs of a font inside a
162 // new valid font file
163 // returns true if creation of subset was successful
164 // parameters: rOutBuffer: vector to write the subset to
165 // pGlyphIDs: the glyph ids to be extracted
166 // pEncoding: the character code corresponding to each glyph
167 // nGlyphs: the number of glyphs
168 // rInfo: additional outgoing information
169 // implementation note: encoding 0 with glyph id 0 should be added implicitly
170 // as "undefined character"
171 bool CreateFontSubset(std::vector<sal_uInt8>&, const sal_GlyphId*, const sal_uInt8*, const int,
172 FontSubsetInfo&) const;
173
174 bool IsColorFont() const { return HasColorLayers() || HasColorBitmaps(); }
175
176 bool HasColorLayers() const;
177 std::vector<ColorLayer> GetGlyphColorLayers(sal_GlyphId) const;
178
179 const std::vector<ColorPalette>& GetColorPalettes() const;
180
181 bool HasColorBitmaps() const;
182 RawFontData GetGlyphColorBitmap(sal_GlyphId, tools::Rectangle&) const;
183
184 OString GetGlyphName(sal_GlyphId, bool = false) const;
185
186 uint32_t UnitsPerEm() const { return hb_face_get_upem(GetHbFace()); }
187
188 OUString GetName(NameID, const LanguageTag&) const;
189 OUString GetName(NameID aNameID) const { return GetName(aNameID, LanguageTag(LANGUAGE_NONE)); }
190
191 virtual hb_face_t* GetHbFace() const;
192 virtual hb_blob_t* GetHbTable(hb_tag_t) const
193 {
194 assert(false);
195 return nullptr;
196 }
197
198 virtual const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const;
199
200protected:
201 mutable hb_face_t* mpHbFace;
202 mutable hb_font_t* mpHbUnscaledFont;
204 mutable std::optional<vcl::FontCapabilities> mxFontCapabilities;
205 mutable std::optional<std::vector<ColorPalette>> mxColorPalettes;
206 mutable std::optional<std::vector<hb_variation_t>> mxVariations;
207
208 explicit PhysicalFontFace(const FontAttributes&);
209
210 hb_font_t* GetHbUnscaledFont() const;
211};
212}
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
abstract base class for physical font faces
virtual hb_blob_t * GetHbTable(hb_tag_t) const
virtual rtl::Reference< LogicalFontInstance > CreateFontInstance(const vcl::font::FontSelectPattern &) const =0
OUString GetName(NameID aNameID) const
std::optional< std::vector< ColorPalette > > mxColorPalettes
virtual sal_IntPtr GetFontId() const =0
std::optional< vcl::FontCapabilities > mxFontCapabilities
std::optional< std::vector< hb_variation_t > > mxVariations
virtual OUString GetName() const override
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
uint32_t sal_GlyphId
Definition: glyphid.hxx:24
#define LANGUAGE_NONE
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
std::vector< Color > ColorPalette
@ NAME_ID_TYPOGRAPHIC_SUBFAMILY
@ NAME_ID_VARIATIONS_PS_PREFIX
const OUString * mpTargetStyleName
RawFontData(const RawFontData &rOther)
const uint8_t * data() const
RawFontData & operator=(const RawFontData &rOther)
RawFontData(hb_blob_t *pBlob=nullptr)
unsigned char sal_uInt8