25#include <osl/file.hxx>
26#include <osl/thread.h>
46 , mpHbUnscaledFont(nullptr)
90 if (rFontName.equalsIgnoreAsciiCase(sFontFamily))
133 int nReqWeight =
static_cast<int>(ePatternWeight);
137 int nGivenWeight =
static_cast<int>(eWeight);
141 int nWeightDiff = nReqWeight - nGivenWeight;
143 if (nWeightDiff == 0)
145 else if (nWeightDiff == +1 || nWeightDiff == -1)
147 else if (nWeightDiff < +50 && nWeightDiff > -50)
180 if (ePatternItalic == eItalic)
223 return RawFontData(hb_face_reference_blob(pHbFace));
224 return RawFontData(hb_face_reference_table(pHbFace, nTag));
227static hb_blob_t*
getTable(hb_face_t*, hb_tag_t nTag,
void* pUserData)
258 hb_set_t* pUnicodes = hb_set_create();
259 hb_face_collect_unicodes(pHbFace, pUnicodes);
261 if (hb_set_get_population(pUnicodes))
264 std::vector<sal_UCS4> aRangeCodes;
265 hb_codepoint_t nFirst, nLast = HB_SET_VALUE_INVALID;
266 while (hb_set_next_range(pUnicodes, &nFirst, &nLast))
268 aRangeCodes.push_back(nFirst);
269 aRangeCodes.push_back(nLast + 1);
275 hb_set_destroy(pUnicodes);
302 RawFace(hb_face_t* pFace)
303 :
mpFace(hb_face_reference(pFace))
307 RawFace(
const RawFace& rOther)
312 ~RawFace() { hb_face_destroy(
mpFace); }
314 RawFontData GetTable(uint32_t nTag)
const
316 return RawFontData(hb_face_reference_table(
mpFace, nTag));
323class TrueTypeFace final :
public AbstractTrueTypeFont
328 const RawFontData&
table(sal_uInt32 nIdx)
const
331 static const uint32_t aTags[
NUM_TAGS] = {
342 : AbstractTrueTypeFont(nullptr, rCharMap)
347 bool hasTable(sal_uInt32 nIdx)
const override {
return !
table(nIdx).empty(); }
348 const sal_uInt8*
table(sal_uInt32 nIdx, sal_uInt32& nSize)
const override
350 auto& rTable =
table(nIdx);
351 nSize = rTable.size();
352 return rTable.data();
367 return CreateTTFfontSubset(aSftFont, rOutBuffer, pGlyphIds, pEncoding, nGlyphCount, rInfo);
373 return hb_ot_color_has_layers(pHbFace) && hb_ot_color_has_palettes(pHbFace);
382 auto nPalettes = hb_ot_color_palette_get_count(pHbFace);
384 for (
auto nPalette = 0
u; nPalette < nPalettes; nPalette++)
386 auto nColors = hb_ot_color_palette_get_colors(pHbFace, nPalette, 0,
nullptr,
nullptr);
388 for (
auto nColor = 0
u; nColor < nColors; nColor++)
392 hb_ot_color_palette_get_colors(pHbFace, nPalette, nColor, &
nCount, &aColor);
393 auto a = hb_color_get_alpha(aColor);
394 auto r = hb_color_get_red(aColor);
395 auto g = hb_color_get_green(aColor);
396 auto b = hb_color_get_blue(aColor);
397 aPalette[nColor] =
Color(ColorAlphaTag::ColorAlpha,
a, r, g, b);
413 auto nLayers = hb_ot_color_glyph_get_layers(pHbFace, nGlyphIndex, 0,
nullptr,
nullptr);
414 std::vector<ColorLayer> aLayers(nLayers);
415 for (
auto nLayer = 0
u; nLayer < nLayers; nLayer++)
417 hb_ot_color_layer_t aLayer;
419 hb_ot_color_glyph_get_layers(pHbFace, nGlyphIndex, nLayer, &
nCount, &aLayer);
420 aLayers[nLayer] = { aLayer.glyph, aLayer.color_index };
435 auto aData =
RawFontData(hb_ot_color_glyph_reference_png(pHbFont, nGlyphIndex));
438 hb_glyph_extents_t aExtents;
439 if (hb_font_get_glyph_extents(pHbFont, nGlyphIndex, &aExtents))
441 auto aPoint =
Point(aExtents.x_bearing, aExtents.y_bearing + aExtents.height);
442 auto aSize =
Size(aExtents.width, -aExtents.height);
459 while ((*
p >=
'0' && *
p <=
'9') || (*
p >=
'A' && *
p <=
'Z') || (*
p >=
'a' && *
p <=
'z')
460 || *
p ==
'.' || *
p ==
'_')
463 return "g" + OString::number(nGlyphIndex);
473 auto aHbLang = HB_LANGUAGE_INVALID;
476 auto aLanguage(rLanguageTag.
getBcp47().toUtf8());
477 aHbLang = hb_language_from_string(aLanguage.getStr(), aLanguage.getLength());
480 auto nName = hb_ot_name_get_utf16(pHbFace, aNameID, aHbLang,
nullptr,
nullptr);
481 if (!nName && aHbLang == HB_LANGUAGE_INVALID)
484 aHbLang = hb_language_from_string(
"en", 2);
485 nName = hb_ot_name_get_utf16(pHbFace, aNameID, aHbLang,
nullptr,
nullptr);
491 std::vector<uint16_t>
aBuf(++nName);
492 hb_ot_name_get_utf16(pHbFace, aNameID, aHbLang, &nName,
aBuf.data());
503 SAL_WARN(
"vcl.fonts",
"Getting font variations is not supported.");
std::array< RawFontData, NUM_TAGS > m_aTableList
bool IsMicrosoftSymbolEncoded() const
FontItalic GetItalic() const
FontWeight GetWeight() const
const OUString & GetFamilyName() const
FontPitch GetPitch() const
const OUString & GetStyleName() const
FontWidth GetWidthType() const
static FontCharMapRef GetDefaultMap(bool bMicrosoftSymbolMap)
Get the default font character map.
LanguageType getLanguageType(bool bResolveSystem=true) const
const OUString & getBcp47(bool bResolveSystem=true) const
ItalicMatrix maItalicMatrix
abstract base class for physical font faces
virtual FontCharMapRef GetFontCharMap() const
RawFontData GetGlyphColorBitmap(sal_GlyphId, tools::Rectangle &) const
OUString GetName(NameID, const LanguageTag &) const
bool HasColorBitmaps() const
sal_Int32 CompareIgnoreSize(const PhysicalFontFace &) const
bool CreateFontSubset(std::vector< sal_uInt8 > &, const sal_GlyphId *, const sal_uInt8 *, const int, FontSubsetInfo &) const
std::vector< ColorLayer > GetGlyphColorLayers(sal_GlyphId) const
hb_font_t * GetHbUnscaledFont() const
virtual const std::vector< hb_variation_t > & GetVariations(const LogicalFontInstance &) const
const std::vector< ColorPalette > & GetColorPalettes() const
PhysicalFontFace(const FontAttributes &)
RawFontData GetRawFontData(uint32_t) const
virtual bool GetFontCapabilities(vcl::FontCapabilities &) const
hb_font_t * mpHbUnscaledFont
std::optional< std::vector< ColorPalette > > mxColorPalettes
bool IsBetterMatch(const vcl::font::FontSelectPattern &, FontMatchStatus &) const
std::optional< vcl::FontCapabilities > mxFontCapabilities
OString GetGlyphName(sal_GlyphId, bool=false) const
virtual hb_face_t * GetHbFace() const
std::optional< std::vector< hb_variation_t > > mxVariations
bool HasColorLayers() const
bool HasMicrosoftSymbolCmap(const unsigned char *pCmap, int nLength)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
static int ItalicMatchValue(FontSelectPattern const &rFSP, FontItalic eItalic)
static int WeightMatchValue(FontSelectPattern const &rFSP, FontWeight eWeight)
static hb_blob_t * getTable(hb_face_t *, hb_tag_t nTag, void *pUserData)
static int PreferNormalFontWidthMatchValue(FontWidth eWidthType)
static int PitchMatchValue(FontSelectPattern const &rFSP, FontPitch ePitch)
std::vector< Color > ColorPalette
static int FamilyNameMatchValue(FontSelectPattern const &rFSP, std::u16string_view sFontFamily)
static int StyleNameMatchValue(FontMatchStatus const &rStatus, std::u16string_view rStyle)
constexpr sal_uInt32 T_post
constexpr sal_uInt32 T_cvt
constexpr sal_uInt32 T_vhea
constexpr sal_uInt32 T_loca
constexpr sal_uInt32 T_prep
constexpr sal_uInt32 T_glyf
constexpr sal_uInt32 T_hhea
bool getTTCoverage(std::optional< std::bitset< UnicodeCoverage::MAX_UC_ENUM > > &rUnicodeRange, std::optional< std::bitset< CodePageCoverage::MAX_CP_ENUM > > &rCodePageRange, const unsigned char *pTable, size_t nLength)
constexpr sal_uInt32 T_head
bool CreateTTFfontSubset(vcl::AbstractTrueTypeFont &rTTF, std::vector< sal_uInt8 > &rOutBuffer, const sal_GlyphId *pGlyphIds, const sal_uInt8 *pEncoding, const int nOrigGlyphCount, FontSubsetInfo &rInfo)
constexpr sal_uInt32 T_maxp
constexpr sal_uInt32 T_OS2
constexpr sal_uInt32 T_CFF
constexpr sal_uInt32 T_hmtx
constexpr sal_uInt32 T_name
constexpr sal_uInt32 T_fpgm
constexpr sal_uInt32 T_cmap
constexpr sal_uInt32 T_vmtx
std::optional< std::bitset< CodePageCoverage::MAX_CP_ENUM > > oCodePageRange
std::optional< std::bitset< UnicodeCoverage::MAX_UC_ENUM > > oUnicodeRange
const OUString * mpTargetStyleName
std::unique_ptr< char[]> aBuffer