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 .
22 #include <sal/config.h>
24 #include <i18nlangtag/languagetag.hxx>
25 #include <rtl/ref.hxx>
26 #include <salhelper/simplereferenceobject.hxx>
27 #include <tools/color.hxx>
28 #include <tools/long.hxx>
29 #include <vcl/dllapi.h>
30 #include <vcl/fontcapabilities.hxx>
31 #include <vcl/fontcharmap.hxx>
33 #include <fontattributes.hxx>
34 #include <fontsubset.hxx>
39 class LogicalFontInstance
;
40 struct FontMatchStatus
;
43 class FontSelectPattern
;
48 class PhysicalFontFamily
;
53 class FontSelectPattern
;
55 struct FontMatchStatus
59 const OUString
* mpTargetStyleName
;
65 RawFontData(hb_blob_t
* pBlob
= nullptr)
66 : mpBlob(pBlob
? pBlob
: hb_blob_get_empty())
70 RawFontData(const RawFontData
& rOther
)
71 : mpBlob(hb_blob_reference(rOther
.mpBlob
))
75 ~RawFontData() { hb_blob_destroy(mpBlob
); }
77 RawFontData
& operator=(const RawFontData
& rOther
)
79 hb_blob_destroy(mpBlob
);
80 mpBlob
= hb_blob_reference(rOther
.mpBlob
);
84 size_t size() const { return hb_blob_get_length(mpBlob
); }
85 bool empty() const { return size() == 0; }
86 const uint8_t* data() const
88 return reinterpret_cast<const uint8_t*>(hb_blob_get_data(mpBlob
, nullptr));
97 sal_GlyphId nGlyphIndex
;
101 typedef std::vector
<Color
> ColorPalette
;
103 // https://learn.microsoft.com/en-us/typography/opentype/spec/name#name-ids
104 typedef enum : hb_ot_name_id_t
{
105 NAME_ID_COPYRIGHT
= 0,
106 NAME_ID_FONT_FAMILY
= 1,
107 NAME_ID_FONT_SUBFAMILY
= 2,
108 NAME_ID_UNIQUE_ID
= 3,
109 NAME_ID_FULL_NAME
= 4,
110 NAME_ID_VERSION_STRING
= 5,
111 NAME_ID_POSTSCRIPT_NAME
= 6,
112 NAME_ID_TRADEMARK
= 7,
113 NAME_ID_MANUFACTURER
= 8,
114 NAME_ID_DESIGNER
= 9,
115 NAME_ID_DESCRIPTION
= 10,
116 NAME_ID_VENDOR_URL
= 11,
117 NAME_ID_DESIGNER_URL
= 12,
118 NAME_ID_LICENSE
= 13,
119 NAME_ID_LICENSE_URL
= 14,
120 //NAME_ID_RESERVED = 15,
121 NAME_ID_TYPOGRAPHIC_FAMILY
= 16,
122 NAME_ID_TYPOGRAPHIC_SUBFAMILY
= 17,
123 NAME_ID_MAC_FULL_NAME
= 18,
124 NAME_ID_SAMPLE_TEXT
= 19,
125 NAME_ID_CID_FINDFONT_NAME
= 20,
126 NAME_ID_WWS_FAMILY
= 21,
127 NAME_ID_WWS_SUBFAMILY
= 22,
128 NAME_ID_LIGHT_BACKGROUND
= 23,
129 NAME_ID_DARK_BACKGROUND
= 24,
130 NAME_ID_VARIATIONS_PS_PREFIX
= 25,
133 // TODO: no more direct access to members
134 // TODO: get rid of height/width for scalable fonts
135 // TODO: make cloning cheaper
138 * abstract base class for physical font faces
140 * It acts as a factory for its corresponding LogicalFontInstances and
141 * can be extended to cache device and font instance specific data.
143 class VCL_PLUGIN_PUBLIC PhysicalFontFace
: public FontAttributes
,
144 public salhelper::SimpleReferenceObject
149 virtual rtl::Reference
<LogicalFontInstance
>
150 CreateFontInstance(const vcl::font::FontSelectPattern
&) const = 0;
152 virtual sal_IntPtr
GetFontId() const = 0;
153 virtual FontCharMapRef
GetFontCharMap() const;
154 virtual bool GetFontCapabilities(vcl::FontCapabilities
&) const;
156 RawFontData
GetRawFontData(uint32_t) const;
158 bool IsBetterMatch(const vcl::font::FontSelectPattern
&, FontMatchStatus
&) const;
159 sal_Int32
CompareIgnoreSize(const PhysicalFontFace
&) const;
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;
174 bool IsColorFont() const { return HasColorLayers() || HasColorBitmaps(); }
176 bool HasColorLayers() const;
177 std::vector
<ColorLayer
> GetGlyphColorLayers(sal_GlyphId
) const;
179 const std::vector
<ColorPalette
>& GetColorPalettes() const;
181 bool HasColorBitmaps() const;
182 RawFontData
GetGlyphColorBitmap(sal_GlyphId
, tools::Rectangle
&) const;
184 OString
GetGlyphName(sal_GlyphId
, bool = false) const;
186 uint32_t UnitsPerEm() const { return hb_face_get_upem(GetHbFace()); }
188 OUString
GetName(NameID
, const LanguageTag
&) const;
189 OUString
GetName(NameID aNameID
) const { return GetName(aNameID
, LanguageTag(LANGUAGE_NONE
)); }
191 virtual hb_face_t
* GetHbFace() const;
192 virtual hb_blob_t
* GetHbTable(hb_tag_t
) const
198 virtual const std::vector
<hb_variation_t
>& GetVariations(const LogicalFontInstance
&) const;
201 mutable hb_face_t
* mpHbFace
;
202 mutable hb_font_t
* mpHbUnscaledFont
;
203 mutable FontCharMapRef mxCharMap
;
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
;
208 explicit PhysicalFontFace(const FontAttributes
&);
210 hb_font_t
* GetHbUnscaledFont() const;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */